Handler wiring
How a transport relates a handler back to its usecase without a dependency.
package @smitejs/domain
A domain handler and the transport that runs it live in different packages. So how does @smitejs/http trace a route handback to the domain.usecase it runs?
The answer is a symbol handshake that avoids a package dependency entirely.
domain.handler(usecase, deps, options) returns a function that reads usecase[usecaseDescriptorSymbol] (the non-enumerable IR node a usecase stores on itself) and attaches it to the returned handler under Symbol.for("@smitejs/domain/handler"). The metadata is non-enumerable, so it never leaks through Object.keys into transported responses.
The domain side attaches the metadata; the transport side reads it:
const app = http.app();
const route = http.router();
const place = usecase({
name: "place",
handle: () => Result.ok(undefined),
});
route.accept("POST", "/orders").handler(handler(place, {}));
app.use(route);1
"place"Two things make this safe:
- The
Symbol.forstring is the contract between the packages, so neither one imports the other. - The carried node is used directly — no registry
lookup— so the production bundle tree-shakes exactly as if the domain glue were never there.
The result: the compiler IC with no cost at runtime.