Middleware API

defineMiddleware and built-in middleware factories for caching, transforms, and edge detection.

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

Prop

Type

Prop

Type

Prop

Type

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

FactoryPurpose
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

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()],
});