# Middleware API URL: /docs/api/middleware Middleware API [#middleware-api] Use the middleware API when extending kernel behavior with caching, coordinate transforms, or geometry post-processing. Middleware wraps kernel operations in an onion-model pipeline. Types [#types] since update() may be called with partial data\nor not called at all.", "tags": [], "type": "PartialDeep", "simplifiedType": "PartialDeep", "required": true, "deprecated": false }, { "name": "update", "description": "Update the state with partial data.\nValues are validated against the Zod schema before being merged.", "tags": [ { "name": "param", "text": "partial - Partial data to merge into the state" } ], "type": "(partial: Partial) => void", "simplifiedType": "function", "required": true, "deprecated": false } ] }} /> ", "simplifiedType": "MiddlewareState", "required": true, "deprecated": false }, { "name": "options", "description": "Resolved options (optionsSchema defaults merged with caller overrides)", "tags": [], "type": "Options", "simplifiedType": "Options", "required": true, "deprecated": false }, { "name": "dependencies", "description": "Dependencies for cache key computation.\nIncludes file dependencies (source files, fonts), middleware signatures,\nframework version, and kernel options.", "tags": [], "type": "readonly Dependency[]", "simplifiedType": "array", "required": true, "deprecated": false }, { "name": "dependencyHash", "description": "Pre-computed SHA-256 hash of all dependencies.\nCan be used as a cache key or unique geometry identifier.\nThis is a 64-character hex string.", "tags": [], "type": "string", "simplifiedType": "string", "required": true, "deprecated": false }, { "name": "registerWatchPath", "description": "Register a file path for the kernel's watch set with an optional debounce tier.\nPaths registered here are included in the kernel's filesystem watcher.\nThe debounce tier controls how quickly changes to this path trigger a re-render\n(e.g., 50ms for parameter files vs 500ms default for source code).\n\nIdempotent — re-registering the same path updates the debounce value.", "tags": [ { "name": "param", "text": "absolutePath - Absolute filesystem path to watch" }, { "name": "param", "text": "options - Optional configuration with debounceMs override" } ], "type": "(absolutePath: string, options?: { debounceMs?: number; }) => void", "simplifiedType": "function", "required": true, "deprecated": false } ] }} /> | undefined", "simplifiedType": "Record", "required": false, "deprecated": false } ] }} /> defineMiddleware [#definemiddleware] `defineMiddleware` creates a middleware instance from a configuration object. Provide optional wrap hooks: `wrapGetParameters`, `wrapCreateGeometry`, `wrapExportGeometry`. Each hook receives `(input, handler, runtime)` where `runtime` is `KernelMiddlewareRuntime`. Built-in Factories [#built-in-factories] | Factory | Purpose | | --------------------------- | ------------------------------------------------- | | `parameterCache()` | Cache parameter definitions by dependency hash | | `geometryCache()` | Cache geometry output by dependency hash | | `gltfCoordinateTransform()` | Apply coordinate system transforms to glTF output | | `gltfEdgeDetection()` | Add edge geometry to glTF meshes | Usage [#usage] ```typescript import { createRuntimeClient, fromMemoryFS } from '@taucad/runtime'; import { replicad } from '@taucad/runtime/kernels'; import { esbuild } from '@taucad/runtime/bundler'; import { parameterCache, geometryCache, gltfCoordinateTransform, gltfEdgeDetection } from '@taucad/runtime/middleware'; const client = createRuntimeClient({ kernels: [replicad()], bundlers: [esbuild()], fileSystem: fromMemoryFS(), middleware: [parameterCache(), geometryCache(), gltfCoordinateTransform(), gltfEdgeDetection()], }); ``` Related [#related] * [Use Middleware](../guides/using-middleware) * [Create Custom Middleware](../guides/custom-middleware) * [Middleware Model](../concepts/middleware-model)