Repository navigation
Add registration policies, typed registration metadata and public operations. Factory resolvers now
keep their lifetime checks after await, which changes some runtime behavior; review the breaking
changes before upgrading.
Breaking changes:
- Pass factories a resolver bound to the requesting registration instead of the scope itself. It exposes
onlyresolve,tryResolve,resolveAllandtryResolveAll. - Keep the singleton restriction on that resolver after the factory returns. A resolver stored by a
singleton factory, or by a factory resolved while building a singleton, and alazy()view created from
such a resolver, now throw a captive-dependencyContainerErrorwhen they resolve a scoped token later. - Return Katagami's own Promise when a factory returns a native Promise, including async factories,
instead of the Promise the factory returned. Its identity and custom properties are not preserved.
Without abeforeReturnpolicy, repeated resolutions of a cached result still return the same Promise. - Detect cycles along each resolution chain, including while an async creation is pending. The factories
still building a pending creation, through their resolvers or by calling the same scope synchronously,
can no longer resolve its token again, even without waiting for it: this throws a circular-dependency
ContainerError. In 3.x it recursed without end, rejected with aTypeError, never settled or returned
the pending Promise, depending on the lifetime and on whether it was awaited. A resolver kept by a
dependency that has finished building still returns the pending Promise to later callers; a creation
that waits for its own Promise that way never settles, as in 3.x. Synchronous cycles are reported
whichever resolver or scope they pass through. - Skip a cached async creation that rejected when disposing, instead of reporting it in the disposal
AggregateError. The failure stays with the caller that resolved the token. - Throw
ContainerErrorwhen registering on, or composing into, a disposed container. - Use new shared runtime keys. Containers, scopes and disposable views from 3.x cannot be mixed with 4.x
in the same process. - Require TypeScript 5.0 or later: the published declarations use
consttype parameters.
Additions:
- Share a
policyobject across modules withcreateContainer({ policy }):requiredMetadatais checked
at compile time and at runtime, including.use(), and modules with a different policy are rejected. - Define typed metadata keys with
createMetadataKey, attach them through the{ metadata }registration
option and read them withcontainer.getMetadata(token). - Mark function-valued factories with
entrypoint()and call them through
createScope(container, { access: 'operations' }). Operations resolve on each call, always return a
Promise, and are awaited by disposal. Unknownaccessvalues are rejected. - Check each resolution synchronously with the
beforeResolvescope option, which receives the
requesting registration and the resolution path. - Check values leaving top-level resolution and operation results with
policy.beforeReturn, using the
registrations each value was observed through. The records keep neither containers nor factories alive. - Export
RegisteredTokensand the policy, metadata, resolution-event and operations-scope types, so
consumers can emit declarations for code that builds operations scopes. - Give the new type parameters defaults; the 3.0.3 documentation examples and type tests compile unchanged.
See CHANGELOG.md and the registration policies guide.
What's Changed
Full Changelog: v3.0.3...v4.0.0