@hile/model
Put reusable business logic behind typed models with services and pipeline middleware.Choose This Package When
Use When
Use@hile/model for reusable business logic. Use @hile/context to create immutable, versioned context data that an application explicitly carries through HTTP ingress, models, Micro calls, RSC, and queue jobs.
@hile/context has no ambient store and owns no AsyncLocalStorage. Context identity is protocol data, not module-instance identity.
Do Not Use When
- Do not use context as a mutable application state container.
- Do not put business fields into a framework-owned global schema; each application owns its context values.
- Do not use ambient state to cross a bundle, Worker, VM, plugin, or transport boundary.
Install
Imports
Copy-Paste Example
parseExecutionContext() validates untrusted or transported values and rejects unsupported protocol versions.
More Examples
Pipelines receive the same value asctx.invocation:
Runtime And Lifecycle Notes
- Every business invocation has an explicit
ExecutionContextandAbortSignal. - Establishment, derivation, transport, and consumption operate on versioned data rather than a shared module singleton.
- Independently evaluated copies of
@hile/contextinteroperate structurally. - Context is immutable and cannot leak between concurrent requests.
- Missing or unsupported context fails with a stable diagnostic error instead of becoming
{}. - Model pipeline and
mainreceive the same invocation object.
Anti-Patterns
- Hiding context in module globals, singleton containers, or
AsyncLocalStorage. - Calling
loadModel()without an invocation. - Adding context fields to business payloads merely to compensate for missing transport support.
- Sending the whole context when only a subset is required.
- Logging entire context objects by default.
Verification Checklist
- Create context once at each ingress boundary.
- Pass it explicitly to Model, Micro, RSC, Queue, and Logger APIs.
- Validate transported context with
parseExecutionContext(). - Use structured-cloneable, JSON-compatible values only.
- Assert missing context fails before side effects.
- Test independent module instances and concurrent invocations.
Related Recipes
HTTP API + Model + TypeORM
Complete Example
Controller:Package-Local AI Guide
This package also shipsAI.md in npm so agents can read accurate examples after installation.