Generator (all four structural gaps):
- harness service pages now render public properties/accessors, not just
methods (ctx.codeRuntime.language/isolation were missing);
- the class page merges the same-named interface half, so ctx.root/baseUrl/
events/logger/reflect/registry appear on Context (vendor root JSDoc gains
prose alongside @experimental);
- Pick<…> heritage on a Context merge resolves to the picked class members,
giving ctx.effect a documented signature on the Fiber page;
- {@link} tags normalize to code spans; merge sections get their own h2 so
reflect members no longer nest under 'Static members'.
verify-website-yaml: reject the unloadable 'group:' pseudo-name (tree.import
only special-cases 'cordis:'; no builtin is registered here) and recurse into
@cordisjs/plugin-group nested entry lists instead.
Prose corrected against loader/cordis source: service.md isolation example
uses the real group plugin + group: true + the required isolate map;
config.md documents concurrent entry startup (Promise.all; order via inject)
and the real hmr defaults (root ['.'], base/ignored/debounce); events.md
fixes emit (synchronous, not parallel), bail (null/false also delegate), and
serial (stops at the first bail value).
8.8 KiB
Context
The context is the core cordis object: every service, event, and lifecycle API is reached through ctx. Event methods (ctx.on, ctx.emit, …) are documented on Events; ctx.effect and ctx.fiber on Fiber; ctx.plugin and ctx.inject on Registry.
Root and child dependency containers for Cordis plugins.
A context is a proxy: normal property reads go through the service resolver, while extend(), isolate(), and intercept() create scoped child contexts without mutating their parent.
ctx.extend(meta?)
extend(meta = {}): this
Create a child context with extra metadata on top of the current scope.
The child prototypally inherits every property of this context; own properties of meta shadow the inherited ones. The parent is not mutated.
meta— own properties (including symbol keys) to define on the child.
Returns a child context inheriting from this one.
ctx.isolate(name, label?)
isolate(name: string, label?: symbol)
Create a child context with an independent service scope for name.
Below the returned context, reads and writes of the service name resolve against the new label instead of the parent's, so a different implementation can be provided without affecting the parent scope. Passing the same label to two isolate() calls joins their scopes.
name— the service name to isolate.label— scope label to join; defaults to a fresh unique symbol.
Returns a child context whose name service resolves in the new scope.
ctx.intercept(name, config)
intercept<K extends InjectKey>(name: K, config: Context[K] extends { [symbols.config]: infer T } ? T : never): this
intercept(name: string, config: any): this
Add service-specific intercept config for plugins started below this context.
Plugins loaded under the returned context see config merged into the service's resolved config (ancestor entries first; see Service[symbols.resolveConfig]). The parent context is not affected.
name— the service name whose config to intercept.config— the intercept config to merge for that service.
Returns a child context carrying the additional intercept entry.
ctx.root
root: this
The root context of the application (every child context shares it). @experimental
ctx.baseUrl
baseUrl?: string
Base URL used to resolve relative plugin/module specifiers, if the runtime sets one.
ctx.events
events: EventsService
The event bus. Its methods are also mixed onto ctx (ctx.on, ctx.emit, ...).
ctx.logger
logger: LoggerService
The logging service. Call ctx.logger(name) for a named logger.
ctx.reflect
reflect: ReflectService
The reflection layer backing the context proxy (ctx.get, ctx.provide, ...).
ctx.registry
registry: RegistryService
The plugin registry. Its methods are mixed onto ctx (ctx.plugin, ctx.inject).
Static members
Context.effect
static readonly effect: unique symbol
Symbol key under which a disposer exposes its EffectMeta diagnostics tree.
Context.filter
static readonly filter: unique symbol
Symbol key for a context's listener filter, consulted on every event dispatch.
Context.isolate
static readonly isolate: unique symbol
Symbol key of the isolation map (see the Context[symbols.isolate] property).
Context.intercept
static readonly intercept: unique symbol
Symbol key of the intercept map (see the Context[symbols.intercept] property).
Context.is(value)
static is(value: any): value is Context
Returns true for Cordis context proxies and context prototypes.
Works across realms and across multiple copies of cordis, because the brand is keyed by a global symbol rather than by instanceof.
value— the value to test.
Returns true if value is a Cordis context, narrowing its type.
Service store and mixins
ctx.get(name, strict?)
get<K extends string & keyof this>(name: K, strict?: boolean): undefined | this[K]
get(name: string, strict?: boolean): any
Read a service from the store without the inject requirement.
name— the service name.strict— whentrue(default), only return implementations whose providing fiber is currently active.
Returns the service value, or undefined when not (yet) provided.
ctx.set(name, value)
set<K extends string & keyof this>(name: K, value: undefined | this[K]): void
set(name: string, value: any): void
Overwrite a provided service's value. Only the fiber that provided the service may set it; setting an unprovided name throws.
name— the service name.value— the new service value.
ctx.provide(name, value)
provide<K extends string & keyof this>(name: K, value: undefined | this[K]): () => void
provide(name: string, value?: any): () => void
Register a service implementation owned by the current fiber. The service becomes visible to dependents in the same isolation scope once the fiber is active; it is unregistered (waking dependents) when the returned disposer runs or the fiber unloads. Throws if the name is already provided in this scope or declared as an accessor.
name— the service name.value— the service value.
Returns a disposer that unregisters the service.
ctx.accessor(name, options)
accessor(name: string, options: Omit<Property.Accessor, 'type'>): void
Define a computed context property backed by get/set hooks. The accessor is removed when the current fiber unloads. Throws if the name is already declared.
name— the context property name.options— thegethook and optionalsethook.
ctx.mixin(name, mixins)
mixin<K extends string & keyof this>(name: K, mixins: (keyof this & keyof this[K])[] | Dict<string>): void
mixin<T extends {}>(source: T, mixins: (keyof this & keyof T)[] | Dict<string>): void
Expose selected members of a service directly on ctx.
Each mixed-in key becomes an accessor that forwards to the service (binding methods to it), so e.g. ctx.on forwards to ctx.events.on. Mixins are removed when the current fiber unloads.
name— the context property holding the source service.mixins— keys to forward, or a source-key → ctx-key map.