Middleware API
Declare operation wrappers, file dependencies, content providers, and typed middleware state.
Middleware API
defineMiddleware wraps description, evaluation, view rendering, and exports. Hooks compose through an onion pipeline without owning the kernel's native handle.
Types
Prop
Type
Prop
Type
Prop
Type
Prop
Type
Prop
Type
Prop
Type
Prop
Type
Prop
Type
Prop
Type
defineMiddleware
Calling its MiddlewarePluginFactory yields serializable registration metadata and a private executable definition. WrapDescribeHook, WrapEvaluateHook, WrapRenderHook, and WrapExportHook receive (input, next, services). Await next(input) to continue; return the corresponding hook result.
Evaluation is independent of views. Render requests identify a view, MIME type, and optional instance. Export requests identify an export, extension, and MIME type. State and options schemas infer parsed output on services; do not forward unparsed caller options.
Middleware participates in cache identity. A pure telemetry tap may declare mutates: false, return successful results unchanged, and declare no dependencies. Other middleware is assumed to mutate results.
Content
MiddlewareContent declares view MIME types and export extensions. ViewContentKeys/ExportContentKeys extract supported keys; ViewContentMap/ExportContentMap preserve per-route inference. Hooks receive only selected-route content. A provider cannot add content support to unrelated media/routes.
Dependencies and Cancellation
MiddlewareResolveHook returns MiddlewareDependency records with canonical root-relative paths and explicit affects operations. Missing files remain unresolved dependencies so their creation can heal the model. Other filesystem failures propagate. Middleware never registers watchers imperatively.
Each hook receives a fresh operation-scoped signal; pass it to cancellable APIs and release operation state on settlement.
Usage
import { defineMiddleware } from '@taucad/runtime/middleware';
export const settingsFiles = defineMiddleware({
id: 'settings',
name: 'settings',
resolve({ entryPath }) {
return [{ path: `.tau/settings/${entryPath}.json`, affects: ['evaluate'], watchDebounce: 0 }];
},
});Factories
@taucad/middleware provides middleware() presets (default, cache, units) and role factories: parameterFileResolver(), parameterUnits(), geometryCache(), gltfEdgeDetection(). Compose them in the worker-owned runtime definition.
describeResultSchema validates a middleware description result at an untyped boundary.