@lppedd/di-wise-neo 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/dist/cjs/index.js +10 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/index.mjs +10 -2
- package/dist/es/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
@@ -442,7 +442,7 @@ export class ExtensionContext {
|
|
442
442
|
|
443
443
|
## Behavioral decorators
|
444
444
|
|
445
|
-
The library includes
|
445
|
+
The library includes three behavioral decorators that influence how classes are registered in the container.
|
446
446
|
These decorators attach metadata to the class type, which is then interpreted by the container during registration.
|
447
447
|
|
448
448
|
### `@Scoped`
|
@@ -503,6 +503,10 @@ export class ExtensionContext {
|
|
503
503
|
container.register(ExtensionContext);
|
504
504
|
```
|
505
505
|
|
506
|
+
> [!WARNING]
|
507
|
+
> Eager instantiation requires that all dependencies of the class are already registered in the container.
|
508
|
+
> If they are not, registration will fail.
|
509
|
+
|
506
510
|
## Testing support
|
507
511
|
|
508
512
|
Testing is an important part of software development, and dependency injection is meant to make it easier.
|
package/dist/cjs/index.js
CHANGED
@@ -641,8 +641,16 @@ function isDisposable(value) {
|
|
641
641
|
instantiateClass(Class, optional) {
|
642
642
|
const metadata = getMetadata(Class);
|
643
643
|
if (metadata.autoRegister ?? this.myOptions.autoRegister) {
|
644
|
-
|
645
|
-
|
644
|
+
// Temporarily set eagerInstantiate to false to avoid resolving the class two times:
|
645
|
+
// one inside register(), and the other just below
|
646
|
+
const eagerInstantiate = metadata.eagerInstantiate;
|
647
|
+
metadata.eagerInstantiate = false;
|
648
|
+
try {
|
649
|
+
this.register(Class);
|
650
|
+
return this.resolve(Class);
|
651
|
+
} finally{
|
652
|
+
metadata.eagerInstantiate = eagerInstantiate;
|
653
|
+
}
|
646
654
|
}
|
647
655
|
const scope = this.resolveScope(metadata.scope);
|
648
656
|
if (optional && scope === Scope.Container) {
|
package/dist/cjs/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/errors.ts","../../src/utils/context.ts","../../src/utils/invariant.ts","../../src/utils/keyedStack.ts","../../src/utils/weakRefMap.ts","../../src/injectionContext.ts","../../src/inject.ts","../../src/injectAll.ts","../../src/metadata.ts","../../src/optional.ts","../../src/optionalAll.ts","../../src/provider.ts","../../src/scope.ts","../../src/token.ts","../../src/utils/typeName.ts","../../src/tokenRegistry.ts","../../src/utils/disposable.ts","../../src/containerImpl.ts","../../src/container.ts","../../src/decorators/autoRegister.ts","../../src/decorators/eagerInstantiate.ts","../../src/tokensRef.ts","../../src/decorators/decorators.ts","../../src/decorators/inject.ts","../../src/decorators/injectable.ts","../../src/decorators/injectAll.ts","../../src/decorators/optional.ts","../../src/decorators/optionalAll.ts","../../src/decorators/scoped.ts","../../src/injector.ts","../../src/middleware.ts"],"sourcesContent":["import type { Token } from \"./token\";\n\n// @internal\nexport function assert(condition: unknown, message: string | (() => string)): asserts condition {\n if (!condition) {\n const resolvedMessage = typeof message === \"string\" ? message : message();\n throw new Error(tag(resolvedMessage));\n }\n}\n\n// @internal\nexport function expectNever(value: never): never {\n throw new TypeError(tag(`unexpected value ${String(value)}`));\n}\n\n// @internal\nexport function throwUnregisteredError(token: Token): never {\n throw new Error(tag(`unregistered token ${token.name}`));\n}\n\n// @internal\nexport function throwExistingUnregisteredError(sourceToken: Token, targetTokenOrError: Token | Error): never {\n let message = tag(`token resolution error encountered while resolving ${sourceToken.name}`);\n\n if (isError(targetTokenOrError)) {\n message += `\\n [cause] ${untag(targetTokenOrError.message)}`;\n } else {\n message += `\\n [cause] the aliased token ${targetTokenOrError.name} is not registered`;\n }\n\n throw new Error(message);\n}\n\nfunction isError(value: any): value is Error {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return value && value.stack && value.message && typeof value.message === \"string\";\n}\n\nfunction tag(message: string): string {\n return `[di-wise-neo] ${message}`;\n}\n\nfunction untag(message: string): string {\n return message.startsWith(\"[di-wise-neo]\") //\n ? message.substring(13).trimStart()\n : message;\n}\n","// @internal\nexport function createInjectionContext<T extends {}>(): readonly [\n (next: T) => () => T | null,\n () => T | null,\n] {\n let current: T | null = null;\n\n function provide(next: T): () => T | null {\n const prev = current;\n current = next;\n return () => (current = prev);\n }\n\n function use(): T | null {\n return current;\n }\n\n return [provide, use] as const;\n}\n","// @internal\nexport function invariant(condition: unknown): asserts condition {\n if (!condition) {\n throw new Error(\"invariant violation\");\n }\n}\n","import { invariant } from \"./invariant\";\n\n// @internal\nexport class KeyedStack<K extends object, V> {\n private readonly myEntries = new Array<{ key: K; value: V }>();\n private readonly myKeys = new WeakSet<K>();\n\n has(key: K): boolean {\n return this.myKeys.has(key);\n }\n\n peek(): V | undefined {\n const entry = this.myEntries.at(-1);\n return entry?.value;\n }\n\n push(key: K, value: V): () => void {\n invariant(!this.has(key));\n this.myKeys.add(key);\n this.myEntries.push({ key, value });\n return () => {\n this.myEntries.pop();\n this.myKeys.delete(key);\n };\n }\n}\n","import { invariant } from \"./invariant\";\n\n// @internal\nexport class WeakRefMap<K extends WeakKey, V extends object> {\n private readonly myMap = new WeakMap<K, WeakRef<V>>();\n\n get(key: K): V | undefined {\n const ref = this.myMap.get(key);\n\n if (ref) {\n const value = ref.deref();\n\n if (value) {\n return value;\n }\n\n this.myMap.delete(key);\n }\n }\n\n set(key: K, value: V): () => void {\n invariant(!this.get(key));\n this.myMap.set(key, new WeakRef(value));\n return () => {\n this.myMap.delete(key);\n };\n }\n}\n","import type { Container } from \"./container\";\nimport { assert } from \"./errors\";\nimport type { Provider } from \"./provider\";\nimport type { Scope } from \"./scope\";\nimport { createInjectionContext } from \"./utils/context\";\nimport { KeyedStack } from \"./utils/keyedStack\";\nimport { WeakRefMap } from \"./utils/weakRefMap\";\nimport type { ValueRef } from \"./valueRef\";\n\n// @internal\nexport interface ResolutionFrame {\n readonly scope: Exclude<Scope, typeof Scope.Inherited>;\n readonly provider: Provider;\n}\n\n// @internal\nexport interface Resolution {\n readonly stack: KeyedStack<Provider, ResolutionFrame>;\n readonly values: WeakRefMap<Provider, ValueRef>;\n readonly dependents: WeakRefMap<Provider, ValueRef>;\n}\n\n// @internal\nexport interface InjectionContext {\n readonly container: Container;\n readonly resolution: Resolution;\n}\n\n// @internal\nexport function createResolution(): Resolution {\n return {\n stack: new KeyedStack(),\n values: new WeakRefMap(),\n dependents: new WeakRefMap(),\n };\n}\n\n// @internal\nexport const [provideInjectionContext, useInjectionContext] = createInjectionContext<InjectionContext>();\n\n// @internal\nexport function ensureInjectionContext(fn: Function): InjectionContext {\n const context = useInjectionContext();\n assert(context, `${fn.name}() can only be invoked within an injection context`);\n return context;\n}\n","import { ensureInjectionContext } from \"./injectionContext\";\nimport type { Constructor, Token } from \"./token\";\n\n/**\n * Injects the instance associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\nexport function inject<Instance extends object>(Class: Constructor<Instance>): Instance;\n\n/**\n * Injects the value associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\nexport function inject<Value>(token: Token<Value>): Value;\n\nexport function inject<T>(token: Token<T>): T {\n const context = ensureInjectionContext(inject);\n return context.container.resolve(token);\n}\n\n/**\n * Injects the instance associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n *\n * Compared to {@link inject}, `injectBy` accepts a `thisArg` argument\n * (the containing class) which is used to resolve circular dependencies.\n *\n * @example\n * ```ts\n * class Wand {\n * owner = inject(Wizard);\n * }\n *\n * class Wizard {\n * wand = injectBy(this, Wand);\n * }\n * ```\n *\n * @param thisArg - The containing instance, used to help resolve circular dependencies.\n * @param Class - The class to resolve.\n */\nexport function injectBy<Instance extends object>(thisArg: any, Class: Constructor<Instance>): Instance;\n\n/**\n * Injects the value associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n *\n * Compared to {@link inject}, `injectBy` accepts a `thisArg` argument\n * (the containing class) which is used to resolve circular dependencies.\n *\n * @example\n * ```ts\n * class Wand {\n * owner = inject(Wizard);\n * }\n *\n * class Wizard {\n * wand = injectBy(this, Wand);\n * }\n * ```\n *\n * @param thisArg - The containing instance, used to help resolve circular dependencies.\n * @param token - The token to resolve.\n */\nexport function injectBy<Value>(thisArg: any, token: Token<Value>): Value;\n\nexport function injectBy<T>(thisArg: any, token: Token<T>): T {\n const context = ensureInjectionContext(injectBy);\n const resolution = context.resolution;\n const currentFrame = resolution.stack.peek();\n\n if (!currentFrame) {\n return inject(token);\n }\n\n const currentRef = { current: thisArg };\n const cleanup = resolution.dependents.set(currentFrame.provider, currentRef);\n\n try {\n return inject(token);\n } finally {\n cleanup();\n }\n}\n","import { ensureInjectionContext } from \"./injectionContext\";\nimport type { Constructor, Token } from \"./token\";\n\n/**\n * Injects all instances provided by the registrations associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\nexport function injectAll<Instance extends object>(Class: Constructor<Instance>): Instance[];\n\n/**\n * Injects all values provided by the registrations associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\nexport function injectAll<Value>(token: Token<Value>): NonNullable<Value>[];\n\nexport function injectAll<T>(token: Token<T>): NonNullable<T>[] {\n const context = ensureInjectionContext(injectAll);\n return context.container.resolveAll(token);\n}\n","import type { ClassProvider } from \"./provider\";\nimport type { Scope } from \"./scope\";\nimport type { Constructor } from \"./token\";\nimport type { Dependencies } from \"./tokenRegistry\";\nimport type { TokensRef } from \"./tokensRef\";\n\n// @internal\nexport interface Metadata<This extends object = any> {\n eagerInstantiate?: boolean;\n autoRegister?: boolean;\n scope?: Scope;\n tokensRef: TokensRef<This>;\n provider: ClassProvider<This>;\n dependencies: Dependencies;\n}\n\n// @internal\nexport function getMetadata<T extends object>(Class: Constructor<T>): Metadata<T> {\n let metadata = metadataMap.get(Class);\n\n if (!metadata) {\n metadataMap.set(\n Class,\n (metadata = {\n tokensRef: {\n getRefTokens: () => new Set(),\n },\n provider: {\n useClass: Class,\n },\n dependencies: {\n constructor: [],\n methods: new Map(),\n },\n }),\n );\n }\n\n return metadata;\n}\n\nconst metadataMap = new WeakMap<Constructor<object>, Metadata>();\n","import { ensureInjectionContext } from \"./injectionContext\";\nimport type { Constructor, Token } from \"./token\";\n\n/**\n * Injects the instance associated with the given class,\n * or `undefined` if the class is not registered in the container.\n */\nexport function optional<Instance extends object>(Class: Constructor<Instance>): Instance | undefined;\n\n/**\n * Injects the value associated with the given token,\n * or `undefined` if the token is not registered in the container.\n */\nexport function optional<Value>(token: Token<Value>): Value | undefined;\n\nexport function optional<T>(token: Token<T>): T | undefined {\n const context = ensureInjectionContext(optional);\n return context.container.resolve(token, true);\n}\n\n/**\n * Injects the instance associated with the given class,\n * or `undefined` if the class is not registered in the container.\n *\n * Compared to {@link optional}, `optionalBy` accepts a `thisArg` argument\n * (the containing class) which is used to resolve circular dependencies.\n *\n * @param thisArg - The containing instance, used to help resolve circular dependencies.\n * @param Class - The class to resolve.\n */\nexport function optionalBy<Instance extends object>(\n thisArg: any,\n Class: Constructor<Instance>,\n): Instance | undefined;\n\n/**\n * Injects the value associated with the given token,\n * or `undefined` if the token is not registered in the container.\n *\n * Compared to {@link optional}, `optionalBy` accepts a `thisArg` argument\n * (the containing class) which is used to resolve circular dependencies.\n *\n * @param thisArg - The containing instance, used to help resolve circular dependencies.\n * @param token - The token to resolve.\n */\nexport function optionalBy<Value>(thisArg: any, token: Token<Value>): Value | undefined;\n\nexport function optionalBy<T>(thisArg: any, token: Token<T>): T | undefined {\n const context = ensureInjectionContext(optionalBy);\n const resolution = context.resolution;\n const currentFrame = resolution.stack.peek();\n\n if (!currentFrame) {\n return optional(token);\n }\n\n const currentRef = { current: thisArg };\n const cleanup = resolution.dependents.set(currentFrame.provider, currentRef);\n\n try {\n return optional(token);\n } finally {\n cleanup();\n }\n}\n","import { ensureInjectionContext } from \"./injectionContext\";\nimport type { Constructor, Token } from \"./token\";\n\n/**\n * Injects all instances provided by the registrations associated with the given class,\n * or an empty array if the class is not registered in the container.\n */\nexport function optionalAll<Instance extends object>(Class: Constructor<Instance>): Instance[];\n\n/**\n * Injects all values provided by the registrations associated with the given token,\n * or an empty array if the token is not registered in the container.\n */\nexport function optionalAll<Value>(token: Token<Value>): NonNullable<Value>[];\n\nexport function optionalAll<T>(token: Token<T>): NonNullable<T>[] {\n const context = ensureInjectionContext(optionalAll);\n return context.container.resolveAll(token, true);\n}\n","import type { Constructor, Token } from \"./token\";\n\n/**\n * Provides a class instance for a token via a class constructor.\n */\nexport interface ClassProvider<Instance extends object> {\n readonly useClass: Constructor<Instance>;\n}\n\n/**\n * Provides a value for a token via a factory function.\n *\n * The factory function runs inside the injection context and can\n * thus access dependencies via {@link inject}-like functions.\n */\nexport interface FactoryProvider<Value> {\n readonly useFactory: (...args: []) => Value;\n}\n\n/**\n * Provides a static - already constructed - value for a token.\n */\nexport interface ValueProvider<T> {\n readonly useValue: T;\n}\n\n/**\n * Aliases another registered token.\n *\n * Resolving this token will return the value of the aliased one.\n */\nexport interface ExistingProvider<Value> {\n readonly useExisting: Token<Value>;\n}\n\n/**\n * A token provider.\n */\nexport type Provider<Value = any> =\n | ClassProvider<Value & object>\n | FactoryProvider<Value>\n | ValueProvider<Value>\n | ExistingProvider<Value>;\n\n// @internal\nexport function isClassProvider<T>(provider: Provider<T>): provider is ClassProvider<T & object> {\n return \"useClass\" in provider;\n}\n\n// @internal\nexport function isFactoryProvider<T>(provider: Provider<T>): provider is FactoryProvider<T> {\n return \"useFactory\" in provider;\n}\n\n// @internal\nexport function isValueProvider<T>(provider: Provider<T>): provider is ValueProvider<T> {\n return \"useValue\" in provider;\n}\n\n// @internal\nexport function isExistingProvider<T>(provider: Provider<T>): provider is ExistingProvider<T> {\n return \"useExisting\" in provider;\n}\n","export const Scope = {\n Inherited: \"Inherited\",\n Transient: \"Transient\",\n Resolution: \"Resolution\",\n Container: \"Container\",\n} as const;\n\nexport type Scope = (typeof Scope)[keyof typeof Scope];\n","/**\n * Type API.\n */\nexport interface Type<A> {\n /**\n * The name of the type.\n */\n readonly name: string;\n\n /**\n * Creates an intersection type from another type.\n *\n * @example\n * ```ts\n * const A = createType<A>(\"A\");\n * const B = createType<B>(\"B\");\n *\n * A.inter(\"I\", B); // => Type<A & B>\n * ```\n */\n inter<B>(typeName: string, B: Type<B>): Type<A & B>;\n\n /**\n * Creates a union type from another type.\n *\n * @example\n * ```ts\n * const A = createType<A>(\"A\");\n * const B = createType<B>(\"B\");\n *\n * A.union(\"U\", B); // => Type<A | B>\n * ```\n */\n union<B>(typeName: string, B: Type<B>): Type<A | B>;\n}\n\n/**\n * Constructor type.\n */\nexport interface Constructor<Instance extends object> {\n new (...args: any[]): Instance;\n readonly name: string;\n}\n\n/**\n * Token type.\n */\nexport type Token<Value = any> = [Value] extends [object] // Avoids distributive union behavior\n ? Type<Value> | Constructor<Value>\n : Type<Value>;\n\n/**\n * Describes a {@link Token} array with at least one element.\n */\nexport type Tokens<Value = any> = [Token<Value>, ...Token<Value>[]];\n\n/**\n * Creates a type token.\n *\n * @example\n * ```ts\n * const ISpell = createType<Spell>(\"Spell\");\n * ```\n *\n * @__NO_SIDE_EFFECTS__\n */\nexport function createType<T>(typeName: string): Type<T> {\n const type = {\n name: `Type<${typeName}>`,\n inter: createType,\n union: createType,\n toString(): string {\n return type.name;\n },\n };\n\n return type;\n}\n\n// @internal\nexport function isConstructor<T>(token: Type<T> | Constructor<T & object>): token is Constructor<T & object> {\n return typeof token == \"function\";\n}\n","// @internal\nexport function getTypeName(value: unknown): string {\n if (typeof value == \"string\") {\n return `\"${value}\"`;\n }\n\n if (typeof value == \"function\") {\n return (value.name && `typeof ${value.name}`) || \"Function\";\n }\n\n if (typeof value == \"object\") {\n if (value === null) {\n return \"null\";\n }\n\n const proto: object | null = Object.getPrototypeOf(value);\n\n if (proto && proto !== Object.prototype) {\n const constructor: unknown = proto.constructor;\n\n if (typeof constructor == \"function\" && constructor.name) {\n return constructor.name;\n }\n }\n }\n\n return typeof value;\n}\n","import { assert } from \"./errors\";\nimport type { FactoryProvider, Provider } from \"./provider\";\nimport { Scope } from \"./scope\";\nimport { type Constructor, createType, type Token, type Type } from \"./token\";\nimport type { TokenRef } from \"./tokensRef\";\nimport { getTypeName } from \"./utils/typeName\";\nimport type { ValueRef } from \"./valueRef\";\n\n/**\n * Token registration options.\n */\nexport interface RegistrationOptions {\n /**\n * The scope of the registration.\n */\n readonly scope?: Scope;\n}\n\n// @internal\nexport type Decorator = \"Inject\" | \"InjectAll\" | \"Optional\" | \"OptionalAll\";\n\n// @internal\nexport interface MethodDependency {\n readonly decorator: Decorator;\n readonly tokenRef: TokenRef;\n\n // The index of the annotated parameter (zero-based)\n readonly index: number;\n}\n\n// @internal\nexport interface Dependencies {\n readonly constructor: MethodDependency[];\n readonly methods: Map<string | symbol, MethodDependency[]>;\n}\n\n// @internal\nexport interface Registration<T = any> {\n value?: ValueRef<T>;\n readonly provider: Provider<T>;\n readonly options?: RegistrationOptions;\n readonly dependencies?: Dependencies;\n}\n\n// @internal\nexport class TokenRegistry {\n private readonly myParent?: TokenRegistry;\n private readonly myMap = new Map<Token, Registration[]>();\n\n constructor(parent: TokenRegistry | undefined) {\n this.myParent = parent;\n }\n\n get<T>(token: Token<T>): Registration<T> | undefined {\n // To clarify, at(-1) means we take the last added registration for this token\n return this.getAll(token)?.at(-1);\n }\n\n getAll<T>(token: Token<T>): Registration<T>[] | undefined {\n const internal = internals.get(token);\n return (internal && [internal]) || this.getAllFromParent(token);\n }\n\n //\n // set(...) overloads added because of TS distributive conditional types.\n //\n // TODO(Edoardo): is there a better way? Maybe refactor the Token<T> type\n // into two types, TokenObject<T extends object> | Token<T>\n //\n\n set<T extends object>(token: Type<T> | Constructor<T>, registration: Registration<T>): void;\n set<T>(token: Token<T>, registration: Registration<T>): void;\n set<T>(token: Token<T>, registration: Registration<T>): void {\n assert(!internals.has(token), `cannot register reserved token ${token.name}`);\n\n let registrations = this.myMap.get(token);\n\n if (!registrations) {\n this.myMap.set(token, (registrations = []));\n }\n\n registrations.push(registration);\n }\n\n delete<T>(token: Token<T>): Registration<T>[] | undefined {\n const registrations = this.myMap.get(token);\n this.myMap.delete(token);\n return registrations;\n }\n\n deleteAll(): [Token[], Registration[]] {\n const tokens = Array.from(this.myMap.keys());\n const registrations = Array.from(this.myMap.values()).flat();\n this.myMap.clear();\n return [tokens, registrations];\n }\n\n clearRegistrations(): unknown[] {\n const values = new Set<unknown>();\n\n for (const registrations of this.myMap.values()) {\n for (let i = 0; i < registrations.length; i++) {\n const registration = registrations[i]!;\n const value = registration.value;\n\n if (value) {\n values.add(value.current);\n }\n\n registrations[i] = {\n ...registration,\n value: undefined,\n };\n }\n }\n\n return Array.from(values);\n }\n\n private getAllFromParent<T>(token: Token<T>): Registration<T>[] | undefined {\n const registrations = this.myMap.get(token);\n return registrations || this.myParent?.getAllFromParent(token);\n }\n}\n\n// @internal\nexport function isBuilder(provider: Provider): boolean {\n return builders.has(provider);\n}\n\n/**\n * Create a one-off type token from a factory function.\n *\n * @example\n * ```ts\n * class Wizard {\n * wand = inject(\n * build(() => {\n * const wand = inject(Wand);\n * wand.owner = this;\n * // ...\n * return wand;\n * }),\n * );\n * }\n * ```\n *\n * @__NO_SIDE_EFFECTS__\n */\nexport function build<Value>(factory: (...args: []) => Value): Type<Value> {\n const token = createType<Value>(`Build<${getTypeName(factory)}>`);\n const provider: FactoryProvider<Value> = {\n useFactory: factory,\n };\n\n internals.set(token, {\n provider: provider,\n options: {\n scope: Scope.Transient,\n },\n });\n\n builders.add(provider);\n return token;\n}\n\nconst internals = new WeakMap<Token, Registration>();\nconst builders = new WeakSet<Provider>();\n","// @internal\nexport interface Disposable {\n dispose(): void;\n}\n\n// @internal\nexport function isDisposable(value: any): value is Disposable {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return value && typeof value === \"object\" && typeof value.dispose === \"function\";\n}\n","import type { Container, ContainerOptions } from \"./container\";\nimport { assert, expectNever, throwExistingUnregisteredError, throwUnregisteredError } from \"./errors\";\nimport { injectBy } from \"./inject\";\nimport { injectAll } from \"./injectAll\";\nimport { createResolution, provideInjectionContext, useInjectionContext } from \"./injectionContext\";\nimport { getMetadata } from \"./metadata\";\nimport { optionalBy } from \"./optional\";\nimport { optionalAll } from \"./optionalAll\";\nimport {\n isClassProvider,\n isExistingProvider,\n isFactoryProvider,\n isValueProvider,\n type Provider,\n} from \"./provider\";\nimport { Scope } from \"./scope\";\nimport { type Constructor, isConstructor, type Token, type Tokens } from \"./token\";\nimport { isBuilder, type Registration, type RegistrationOptions, TokenRegistry } from \"./tokenRegistry\";\nimport { isDisposable } from \"./utils/disposable\";\n\n/**\n * The default implementation of a di-wise-neo {@link Container}.\n */\nexport class ContainerImpl implements Container {\n private readonly myParent?: ContainerImpl;\n private readonly myChildren: Set<ContainerImpl> = new Set();\n private readonly myOptions: ContainerOptions;\n private readonly myTokenRegistry: TokenRegistry;\n private myDisposed: boolean = false;\n\n constructor(parent: ContainerImpl | undefined, options: Partial<ContainerOptions>) {\n this.myParent = parent;\n this.myOptions = {\n autoRegister: false,\n defaultScope: Scope.Inherited,\n ...options,\n };\n\n this.myTokenRegistry = new TokenRegistry(this.myParent?.myTokenRegistry);\n }\n\n get registry(): TokenRegistry {\n return this.myTokenRegistry;\n }\n\n get options(): ContainerOptions {\n return {\n ...this.myOptions,\n };\n }\n\n get parent(): Container | undefined {\n return this.myParent;\n }\n\n get isDisposed(): boolean {\n return this.myDisposed;\n }\n\n createChild(options?: Partial<ContainerOptions>): Container {\n this.checkDisposed();\n const container = new ContainerImpl(this, {\n ...this.myOptions,\n ...options,\n });\n\n this.myChildren.add(container);\n return container;\n }\n\n clearCache(): unknown[] {\n this.checkDisposed();\n return this.myTokenRegistry.clearRegistrations();\n }\n\n getCached<T>(token: Token<T>): T | undefined {\n this.checkDisposed();\n const registration = this.myTokenRegistry.get(token);\n return registration?.value?.current;\n }\n\n getAllCached<T>(token: Token<T>): T[] {\n this.checkDisposed();\n const registrations = this.myTokenRegistry.getAll(token);\n\n if (!registrations) {\n return [];\n }\n\n const values = new Set<T>();\n\n for (const registration of registrations) {\n const value = registration.value;\n\n if (value) {\n values.add(value.current);\n }\n }\n\n return Array.from(values);\n }\n\n resetRegistry(): unknown[] {\n this.checkDisposed();\n const [, registrations] = this.myTokenRegistry.deleteAll();\n const values = new Set<unknown>();\n\n for (const registration of registrations) {\n const value = registration.value;\n\n if (value) {\n values.add(value.current);\n }\n }\n\n return Array.from(values);\n }\n\n isRegistered(token: Token): boolean {\n this.checkDisposed();\n return this.myTokenRegistry.get(token) !== undefined;\n }\n\n registerClass<T extends object, V extends T>(\n token: Token<T>,\n Class?: Constructor<V>,\n options?: RegistrationOptions,\n ): void {\n // This mess will go away once/if we remove the register method\n // in favor of the multiple specialized ones\n if (Class) {\n const ctor = (Class ?? token) as Constructor<any>;\n this.register(token, { useClass: ctor }, options);\n } else {\n this.register(token as Constructor<any>);\n }\n }\n\n registerFactory<T, V extends T>(\n token: Token<T>,\n factory: (...args: []) => V,\n options?: RegistrationOptions,\n ): void {\n this.register(token, { useFactory: factory }, options);\n }\n\n registerValue<T, V extends T>(token: Token<T>, value: V): void {\n this.register(token, { useValue: value });\n }\n\n registerAlias<T, V extends T>(targetToken: Token<V>, aliasTokens: Tokens<T>): void {\n // De-duplicate tokens\n for (const alias of new Set(aliasTokens)) {\n this.register(alias, { useExisting: targetToken });\n }\n }\n\n register<T>(...args: [Constructor<T & object>] | [Token<T>, Provider<T>, RegistrationOptions?]): Container {\n this.checkDisposed();\n\n if (args.length == 1) {\n const Class = args[0];\n const metadata = getMetadata(Class);\n const registration: Registration = {\n // The provider is of type ClassProvider, initialized by getMetadata\n provider: metadata.provider,\n options: {\n scope: metadata.scope ?? this.myOptions.defaultScope,\n },\n dependencies: metadata.dependencies,\n };\n\n // Register the class itself\n this.myTokenRegistry.set(Class, registration);\n\n // Register the additional tokens specified via class decorators.\n // These tokens will point to the original Class token and will have the same scope.\n for (const token of metadata.tokensRef.getRefTokens()) {\n this.myTokenRegistry.set(token, {\n provider: {\n useExisting: Class,\n },\n });\n }\n\n // Eager-instantiate only if the class is container-scoped\n if (metadata.eagerInstantiate && registration.options?.scope === Scope.Container) {\n this.resolve(Class);\n }\n } else {\n const [token, provider, options] = args;\n\n if (isClassProvider(provider)) {\n const metadata = getMetadata(provider.useClass);\n const registration: Registration = {\n provider: metadata.provider,\n options: {\n // The explicit registration options override what is specified\n // via class decorators (e.g., @Scoped)\n scope: metadata.scope ?? this.myOptions.defaultScope,\n ...options,\n },\n dependencies: metadata.dependencies,\n };\n\n this.myTokenRegistry.set(token, registration);\n\n // Eager-instantiate only if the provided class is container-scoped\n if (metadata.eagerInstantiate && registration.options?.scope === Scope.Container) {\n this.resolve(token);\n }\n } else {\n if (isExistingProvider(provider)) {\n assert(\n token !== provider.useExisting,\n `the useExisting token ${token.name} cannot be the same as the token being registered`,\n );\n }\n\n this.myTokenRegistry.set(token, {\n provider: provider,\n options: options,\n });\n }\n }\n\n return this;\n }\n\n unregister<T>(token: Token<T>): T[] {\n this.checkDisposed();\n const registrations = this.myTokenRegistry.delete(token);\n\n if (!registrations) {\n return [];\n }\n\n const values = new Set<T>();\n\n for (const registration of registrations) {\n const value = registration.value;\n\n if (value) {\n values.add(value.current);\n }\n }\n\n return Array.from(values);\n }\n\n resolve<T>(token: Token<T>, optional?: boolean): T | undefined {\n this.checkDisposed();\n const registration = this.myTokenRegistry.get(token);\n\n if (registration) {\n return this.resolveRegistration(token, registration);\n }\n\n if (isConstructor(token)) {\n return this.instantiateClass(token, optional);\n }\n\n return optional ? undefined : throwUnregisteredError(token);\n }\n\n resolveAll<T>(token: Token<T>, optional?: boolean): NonNullable<T>[] {\n this.checkDisposed();\n const registrations = this.myTokenRegistry.getAll(token);\n\n if (registrations) {\n return registrations\n .map((registration) => this.resolveRegistration(token, registration))\n .filter((value) => value != null);\n }\n\n if (isConstructor(token)) {\n const instance = this.instantiateClass(token, optional);\n return instance === undefined // = could not resolve, but since it is optional\n ? []\n : [instance];\n }\n\n return optional ? [] : throwUnregisteredError(token);\n }\n\n dispose(): void {\n if (this.myDisposed) {\n return;\n }\n\n // Dispose children containers first\n for (const child of this.myChildren) {\n child.dispose();\n }\n\n this.myChildren.clear();\n\n // Remove ourselves from our parent container\n this.myParent?.myChildren?.delete(this);\n this.myDisposed = true;\n\n const [, registrations] = this.myTokenRegistry.deleteAll();\n const disposedRefs = new Set<any>();\n\n // Dispose all resolved (aka instantiated) tokens that implement the Disposable interface\n for (const registration of registrations) {\n const value = registration.value?.current;\n\n if (isDisposable(value) && !disposedRefs.has(value)) {\n disposedRefs.add(value);\n value.dispose();\n }\n }\n\n // Allow values to be GCed\n disposedRefs.clear();\n }\n\n private resolveRegistration<T>(token: Token<T>, registration: Registration<T>): T {\n let currRegistration: Registration<T> | undefined = registration;\n let currProvider = currRegistration.provider;\n\n while (isExistingProvider(currProvider)) {\n const targetToken = currProvider.useExisting;\n currRegistration = this.myTokenRegistry.get(targetToken);\n\n if (!currRegistration) {\n throwExistingUnregisteredError(token, targetToken);\n }\n\n currProvider = currRegistration.provider;\n }\n\n try {\n return this.resolveProviderValue(currRegistration, currProvider);\n } catch (e) {\n // If we were trying to resolve a token registered via ExistingProvider,\n // we must add the cause of the error to the message\n if (isExistingProvider(registration.provider)) {\n throwExistingUnregisteredError(token, e as Error);\n }\n\n throw e;\n }\n }\n\n private instantiateClass<T extends object>(Class: Constructor<T>, optional?: boolean): T | undefined {\n const metadata = getMetadata(Class);\n\n if (metadata.autoRegister ?? this.myOptions.autoRegister) {\n this.register(Class);\n return (this as Container).resolve(Class);\n }\n\n const scope = this.resolveScope(metadata.scope);\n\n if (optional && scope === Scope.Container) {\n // It would not be possible to resolve the class in container scope,\n // as that would require prior registration.\n // However, since resolution is marked optional, we simply return undefined.\n return undefined;\n }\n\n assert(\n scope !== Scope.Container,\n `unregistered class ${Class.name} cannot be resolved in container scope`,\n );\n\n const registration: Registration<T> = {\n provider: metadata.provider,\n options: {\n scope: scope,\n },\n dependencies: metadata.dependencies,\n };\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n return this.resolveScopedValue(registration, (args) => new Class(...args));\n }\n\n private resolveProviderValue<T>(registration: Registration<T>, provider: Provider<T>): T {\n assert(registration.provider === provider, \"internal error: mismatching provider\");\n\n if (isClassProvider(provider)) {\n const Class = provider.useClass;\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n return this.resolveScopedValue(registration, (args) => new Class(...args));\n }\n\n if (isFactoryProvider(provider)) {\n const factory = provider.useFactory;\n return this.resolveScopedValue(registration, factory);\n }\n\n if (isValueProvider(provider)) {\n return provider.useValue;\n }\n\n if (isExistingProvider(provider)) {\n assert(false, \"internal error: unexpected ExistingProvider\");\n }\n\n expectNever(provider);\n }\n\n private resolveScopedValue<T>(registration: Registration<T>, factory: (...args: any[]) => T): T {\n let context = useInjectionContext();\n\n if (!context || context.container !== this) {\n context = {\n container: this,\n resolution: createResolution(),\n };\n }\n\n const resolution = context.resolution;\n const provider = registration.provider;\n const options = registration.options;\n\n if (resolution.stack.has(provider)) {\n const dependentRef = resolution.dependents.get(provider);\n assert(dependentRef, \"circular dependency detected\");\n return dependentRef.current;\n }\n\n const scope = this.resolveScope(options?.scope, context);\n const cleanups = [\n provideInjectionContext(context),\n !isBuilder(provider) && resolution.stack.push(provider, { provider, scope }),\n ];\n\n try {\n switch (scope) {\n case Scope.Container: {\n const valueRef = registration.value;\n\n if (valueRef) {\n return valueRef.current;\n }\n\n const args = this.resolveConstructorDependencies(registration);\n const value = this.injectDependencies(registration, factory(args));\n registration.value = { current: value };\n return value;\n }\n case Scope.Resolution: {\n const valueRef = resolution.values.get(provider);\n\n if (valueRef) {\n return valueRef.current;\n }\n\n const args = this.resolveConstructorDependencies(registration);\n const value = this.injectDependencies(registration, factory(args));\n resolution.values.set(provider, { current: value });\n return value;\n }\n case Scope.Transient: {\n const args = this.resolveConstructorDependencies(registration);\n return this.injectDependencies(registration, factory(args));\n }\n }\n } finally {\n cleanups.forEach((cleanup) => cleanup && cleanup());\n }\n }\n\n private resolveScope(\n scope = this.myOptions.defaultScope,\n context = useInjectionContext(),\n ): Exclude<Scope, typeof Scope.Inherited> {\n if (scope == Scope.Inherited) {\n const dependentFrame = context?.resolution.stack.peek();\n return dependentFrame?.scope || Scope.Transient;\n }\n\n return scope;\n }\n\n private resolveConstructorDependencies<T>(registration: Registration<T>): any[] {\n const dependencies = registration.dependencies;\n\n if (dependencies) {\n assert(isClassProvider(registration.provider), `internal error: not a ClassProvider`);\n const ctorDeps = dependencies.constructor;\n\n if (ctorDeps.length > 0) {\n // Let's check if all necessary constructor parameters are decorated.\n // If not, we cannot safely create an instance.\n const ctor = registration.provider.useClass;\n assert(ctor.length === ctorDeps.length, () => {\n const msg = `expected ${ctor.length} decorated constructor parameters in ${ctor.name}`;\n return msg + `, but found ${ctorDeps.length}`;\n });\n\n return ctorDeps\n .sort((a, b) => a.index - b.index)\n .map((dep) => {\n const token = dep.tokenRef.getRefToken();\n switch (dep.decorator) {\n case \"Inject\":\n return this.resolve(token);\n case \"InjectAll\":\n return this.resolveAll(token);\n case \"Optional\":\n return this.resolve(token, true);\n case \"OptionalAll\":\n return this.resolveAll(token, true);\n }\n });\n }\n }\n\n return [];\n }\n\n private injectDependencies<T>(registration: Registration<T>, instance: T): T {\n const dependencies = registration.dependencies;\n\n if (dependencies) {\n assert(isClassProvider(registration.provider), `internal error: not a ClassProvider`);\n const ctor = registration.provider.useClass;\n\n // Perform method injection\n for (const [key, methodDeps] of dependencies.methods) {\n // Let's check if all necessary method parameters are decorated.\n // If not, we cannot safely invoke the method.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const method = (instance as any)[key] as Function;\n assert(methodDeps.length === method.length, () => {\n const msg = `expected ${method.length} decorated method parameters`;\n return msg + ` in ${ctor.name}.${String(key)}, but found ${methodDeps.length}`;\n });\n\n const args = methodDeps\n .sort((a, b) => a.index - b.index)\n .map((dep) => {\n const token = dep.tokenRef.getRefToken();\n switch (dep.decorator) {\n case \"Inject\":\n return injectBy(instance, token);\n case \"InjectAll\":\n return injectAll(token);\n case \"Optional\":\n return optionalBy(instance, token);\n case \"OptionalAll\":\n return optionalAll(token);\n }\n });\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n method.bind(instance)(...args);\n }\n }\n\n return instance;\n }\n\n private checkDisposed(): void {\n assert(!this.myDisposed, \"the container is disposed\");\n }\n}\n","import { ContainerImpl } from \"./containerImpl\";\nimport type { ClassProvider, ExistingProvider, FactoryProvider, ValueProvider } from \"./provider\";\nimport { Scope } from \"./scope\";\nimport type { Constructor, Token, Tokens } from \"./token\";\nimport type { RegistrationOptions, TokenRegistry } from \"./tokenRegistry\";\n\n/**\n * Container creation options.\n */\nexport interface ContainerOptions {\n /**\n * Whether to automatically register an unregistered class when resolving it as a token.\n *\n * @defaultValue false\n */\n readonly autoRegister: boolean;\n\n /**\n * The default scope for registrations.\n *\n * @defaultValue Scope.Inherited\n */\n readonly defaultScope: Scope;\n}\n\n/**\n * Container API.\n */\nexport interface Container {\n /**\n * @internal\n */\n api?: Readonly<Container>;\n\n /**\n * @internal\n */\n readonly registry: TokenRegistry;\n\n /**\n * The options used to create this container.\n */\n readonly options: ContainerOptions;\n\n /**\n * The parent container, or `undefined` if this is the root container.\n */\n readonly parent: Container | undefined;\n\n /**\n * Whether this container is disposed.\n */\n readonly isDisposed: boolean;\n\n /**\n * Creates a new child container that inherits this container's options.\n *\n * You can pass specific options to override the inherited ones.\n */\n createChild(options?: Partial<ContainerOptions>): Container;\n\n /**\n * Clears and returns all distinct cached values from this container's internal registry.\n * Values from {@link ValueProvider} registrations are not included, as they are never cached.\n *\n * Note that only this container is affected. Parent containers, if any, remain unchanged.\n */\n clearCache(): unknown[];\n\n /**\n * Returns the cached value from the most recent registration of the token,\n * or `undefined` if no value has been cached yet (the token has not been resolved yet).\n *\n * If the token has at least one registration in this container,\n * the cached value is taken from the most recent of those registrations.\n * Otherwise, it may be retrieved from parent containers, if any.\n *\n * Values are never cached for tokens with _transient_ or _resolution_ scope,\n * or for {@link ValueProvider} registrations.\n */\n getCached<Value>(token: Token<Value>): Value | undefined;\n\n /**\n * Returns all cached values associated with registrations of the token,\n * in the order they were registered, or an empty array if none have been cached.\n *\n * If the token has at least one registration in the current container,\n * cached values are taken from those registrations.\n * Otherwise, cached values may be retrieved from parent containers, if any.\n *\n * Values are never cached for tokens with _transient_ or _resolution_ scope,\n * or for {@link ValueProvider} registrations.\n */\n getAllCached<Value>(token: Token<Value>): Value[];\n\n /**\n * Removes all registrations from this container's internal registry.\n *\n * Returns an array of distinct cached values that were stored within the removed registrations.\n * Values from {@link ValueProvider} registrations are not included, as they are not cached.\n *\n * Note that only this container is affected. Parent containers, if any, remain unchanged.\n */\n resetRegistry(): unknown[];\n\n /**\n * Returns whether the token is registered in this container or in parent containers, if any.\n */\n isRegistered(token: Token): boolean;\n\n /**\n * Registers a concrete class, where the class acts as its own token.\n *\n * Tokens provided via the {@link Injectable} decorator applied to the class\n * are also registered as aliases.\n *\n * The default registration scope is determined by the {@link Scoped} decorator,\n * if present.\n */\n registerClass<Instance extends object>(Class: Constructor<Instance>): void;\n\n /**\n * Registers a concrete class with a token.\n *\n * The default registration scope is determined by the {@link Scoped} decorator\n * applied to the class, if present, but it can be overridden by passing explicit\n * registration options.\n */\n registerClass<Instance extends object, ProvidedInstance extends Instance>(\n token: Token<Instance>,\n Class: Constructor<ProvidedInstance>,\n options?: RegistrationOptions,\n ): void;\n\n /**\n * Registers a token whose value is produced by a factory function.\n *\n * The factory function runs inside the injection context and can\n * thus access dependencies via {@link inject}-like functions.\n */\n registerFactory<Value, ProvidedValue extends Value>(\n token: Token<Value>,\n factory: (...args: []) => ProvidedValue,\n options?: RegistrationOptions,\n ): void;\n\n /**\n * Registers a token with a fixed value.\n *\n * The provided value is returned as-is when the token is resolved (scopes do not apply).\n */\n registerValue<Value, ProvidedValue extends Value>(token: Token<Value>, value: ProvidedValue): void;\n\n /**\n * Registers one or more tokens as aliases for a target token.\n *\n * When an alias is resolved, the target token is resolved instead.\n */\n registerAlias<Value, ProvidedValue extends Value>(\n targetToken: Token<ProvidedValue>,\n aliasTokens: Tokens<Value>,\n ): void;\n\n /**\n * Registers a {@link ClassProvider}, using the class itself as its token.\n *\n * Tokens provided via the {@link Injectable} decorator applied to the class\n * are also registered as aliases.\n *\n * The scope is determined by the {@link Scoped} decorator, if present.\n *\n * @see registerClass\n */\n register<Instance extends object>(Class: Constructor<Instance>): Container;\n\n /**\n * Registers a {@link ClassProvider} with a token.\n *\n * The default registration scope is determined by the {@link Scoped} decorator\n * applied to the provided class, if present, but it can be overridden by\n * passing explicit registration options.\n *\n * @see registerClass\n */\n register<Instance extends object, ProviderInstance extends Instance>(\n token: Token<Instance>,\n provider: ClassProvider<ProviderInstance>,\n options?: RegistrationOptions,\n ): Container;\n\n /**\n * Registers a {@link FactoryProvider} with a token.\n *\n * @see registerFactory\n */\n register<Value, ProviderValue extends Value>(\n token: Token<Value>,\n provider: FactoryProvider<ProviderValue>,\n options?: RegistrationOptions,\n ): Container;\n\n /**\n * Registers an {@link ExistingProvider} with a token.\n *\n * The token will alias the one set in `useExisting`.\n *\n * @see registerAlias\n */\n register<Value, ProviderValue extends Value>(\n token: Token<Value>,\n provider: ExistingProvider<ProviderValue>,\n ): Container;\n\n /**\n * Registers a {@link ValueProvider} with a token.\n *\n * Values provided via `useValue` are never cached (scopes do not apply)\n * and are simply returned as-is.\n *\n * @see registerValue\n */\n register<Value, ProviderValue extends Value>(\n token: Token<Value>,\n provider: ValueProvider<ProviderValue>,\n ): Container;\n\n /**\n * Removes all registrations for the given token from the container's internal registry.\n *\n * Returns an array of distinct cached values that were stored within the removed registrations.\n * Values from {@link ValueProvider} registrations are not included, as they are not cached.\n *\n * Note that only this container is affected. Parent containers, if any, remain unchanged.\n */\n unregister<Value>(token: Token<Value>): Value[];\n\n /**\n * Resolves the given class to the instance associated with it.\n *\n * If the class is registered in this container or any of its parent containers,\n * an instance is created using the most recent registration.\n *\n * If the class is not registered, but it is decorated with {@link AutoRegister},\n * or {@link ContainerOptions.autoRegister} is true, the class is registered automatically.\n * Otherwise, resolution fails.\n * The scope for the automatic registration is determined by either\n * the {@link Scoped} decorator on the class, or {@link ContainerOptions.defaultScope}.\n *\n * If `optional` is false or is not passed and the class is not registered in the container\n * (and could not be auto-registered), an error is thrown.\n * Otherwise, if `optional` is true, `undefined` is returned.\n *\n * The resolution behavior depends on the {@link Provider} used during registration:\n * - For {@link ValueProvider}, the explicitly provided instance is returned.\n * - For {@link FactoryProvider}, the factory function is invoked to create the instance.\n * - For {@link ClassProvider}, a new instance of the class is created according to its scope.\n * - For {@link ExistingProvider}, the instance is resolved by referring to another registered token.\n *\n * If the class is registered with _container_ scope, the resolved instance is cached\n * in the container's internal registry.\n */\n resolve<Instance extends object>(Class: Constructor<Instance>, optional?: false): Instance;\n resolve<Instance extends object>(Class: Constructor<Instance>, optional: true): Instance | undefined;\n resolve<Instance extends object>(Class: Constructor<Instance>, optional?: boolean): Instance | undefined;\n\n /**\n * Resolves the given token to the value associated with it.\n *\n * If the token is registered in this container or any of its parent containers,\n * its value is resolved using the most recent registration.\n *\n * If `optional` is false or not passed and the token is not registered in the container,\n * an error is thrown. Otherwise, if `optional` is true, `undefined` is returned.\n *\n * The resolution behavior depends on the {@link Provider} used during registration:\n * - For {@link ValueProvider}, the explicitly provided value is returned.\n * - For {@link FactoryProvider}, the factory function is invoked to create the value.\n * - For {@link ClassProvider}, a new instance of the class is created according to its scope.\n * - For {@link ExistingProvider}, the value is resolved by referring to another registered token.\n *\n * If the token is registered with _container_ scope, the resolved value is cached\n * in the container's internal registry.\n */\n resolve<Value>(token: Token<Value>, optional?: false): Value;\n resolve<Value>(token: Token<Value>, optional: true): Value | undefined;\n resolve<Value>(token: Token<Value>, optional?: boolean): Value | undefined;\n\n /**\n * Resolves the given class to all instances provided by the registrations associated with it.\n *\n * If the class is not registered, but it is decorated with {@link AutoRegister},\n * or {@link ContainerOptions.autoRegister} is true, the class is registered automatically.\n * Otherwise, resolution fails.\n * The scope for the automatic registration is determined by either\n * the {@link Scoped} decorator on the class, or {@link ContainerOptions.defaultScope}.\n *\n * If `optional` is false or is not passed and the class is not registered in the container\n * (and could not be auto-registered), an error is thrown.\n * Otherwise, if `optional` is true, an empty array is returned.\n *\n * The resolution behavior depends on the {@link Provider} used during registration:\n * - For {@link ValueProvider}, the explicitly provided instance is returned.\n * - For {@link FactoryProvider}, the factory function is invoked to create the instance.\n * - For {@link ClassProvider}, a new instance of the class is created according to its scope.\n * - For {@link ExistingProvider}, the instance is resolved by referring to another registered token.\n *\n * If the class is registered with _container_ scope, the resolved instances are cached\n * in the container's internal registry.\n *\n * A separate instance of the class is created for each provider.\n *\n * @see The documentation for `resolve(Class: Constructor)`\n */\n resolveAll<Instance extends object>(Class: Constructor<Instance>, optional?: false): Instance[];\n resolveAll<Instance extends object>(Class: Constructor<Instance>, optional: true): Instance[];\n resolveAll<Instance extends object>(Class: Constructor<Instance>, optional?: boolean): Instance[];\n\n /**\n * Resolves the given token to all values provided by the registrations associated with it.\n *\n * If `optional` is false or not passed and the token is not registered in the container,\n * an error is thrown. Otherwise, if `optional` is true, an empty array is returned.\n *\n * The resolution behavior depends on the {@link Provider} used during registration:\n * - For {@link ValueProvider}, the explicitly provided value is returned.\n * - For {@link FactoryProvider}, the factory function is invoked to create the value.\n * - For {@link ClassProvider}, a new instance of the class is created according to its scope.\n * - For {@link ExistingProvider}, the value is resolved by referring to another registered token.\n *\n * If the token is registered with _container_ scope, the resolved values are cached\n * in the container's internal registry.\n *\n * @see The documentation for `resolve(token: Token)`\n */\n resolveAll<Value>(token: Token<Value>, optional?: false): NonNullable<Value>[];\n resolveAll<Value>(token: Token<Value>, optional: true): NonNullable<Value>[];\n resolveAll<Value>(token: Token<Value>, optional?: boolean): NonNullable<Value>[];\n\n /**\n * Disposes this container and all its cached values.\n *\n * Token values implementing a `Disposable` interface (e.g., objects with a `dispose()` function)\n * are automatically disposed during this process.\n *\n * Note that children containers are disposed first, in creation order.\n */\n dispose(): void;\n}\n\n/**\n * Creates a new container.\n */\nexport function createContainer(\n options: Partial<ContainerOptions> = {\n autoRegister: false,\n defaultScope: Scope.Inherited,\n },\n): Container {\n return new ContainerImpl(undefined, options);\n}\n","import { getMetadata } from \"../metadata\";\nimport type { Constructor } from \"../token\";\n\n/**\n * Class decorator that enables auto-registration of an unregistered class,\n * when the class is first resolved from the container.\n *\n * @example\n * ```ts\n * @AutoRegister\n * class Wizard {}\n *\n * const wizard = container.resolve(Wizard);\n * container.isRegistered(Wizard); // => true\n * ```\n *\n * @__NO_SIDE_EFFECTS__\n */\nexport function AutoRegister<Ctor extends Constructor<any>>(Class: Ctor): void {\n const metadata = getMetadata(Class);\n metadata.autoRegister = true;\n}\n","import { getMetadata } from \"../metadata\";\nimport type { Constructor } from \"../token\";\n\n/**\n * Class decorator that enables eager instantiation of a class when it is registered\n * in the container with `Scope.Container`.\n *\n * This causes the container to immediately create and cache the instance of the class,\n * instead of deferring instantiation until the first resolution.\n *\n * @example\n * ```ts\n * @EagerInstantiate\n * @Scoped(Scope.Container)\n * class Wizard {}\n *\n * // A Wizard instance is immediately created and cached by the container\n * const wizard = container.register(Wizard);\n * ```\n *\n * @__NO_SIDE_EFFECTS__\n */\nexport function EagerInstantiate<Ctor extends Constructor<any>>(Class: Ctor): void {\n const metadata = getMetadata(Class);\n metadata.eagerInstantiate = true;\n}\n","import { assert } from \"./errors\";\nimport type { Token, Tokens } from \"./token\";\n\nexport interface TokensRef<Value = any> {\n readonly getRefTokens: () => Set<Token<Value>>;\n}\n\nexport interface TokenRef<Value = any> {\n readonly getRefToken: () => Token<Value>;\n}\n\n/**\n * Allows referencing tokens that are declared later in the file by wrapping them\n * in a lazily evaluated function.\n */\nexport function forwardRef<Value>(token: () => Tokens<Value>): TokensRef<Value>;\n\n/**\n * Allows referencing a token that is declared later in the file by wrapping it\n * in a lazily evaluated function.\n */\nexport function forwardRef<Value>(token: () => Token<Value>): TokenRef<Value>;\n\nexport function forwardRef<Value>(\n token: () => Token<Value> | Tokens<Value>,\n): TokensRef<Value> & TokenRef<Value> {\n return {\n getRefTokens: (): Set<Token<Value>> => {\n // Normalize the single token here, so that we don't have\n // to do it at every getRefTokens call site\n const tokenOrTokens = token();\n const tokensArray = Array.isArray(tokenOrTokens) ? tokenOrTokens : [tokenOrTokens];\n return new Set(tokensArray);\n },\n getRefToken: () => {\n const tokenOrTokens = token();\n assert(!Array.isArray(tokenOrTokens), \"internal error: ref tokens should be a single token\");\n return tokenOrTokens;\n },\n };\n}\n\n// @internal\nexport function isTokensRef(value: any): value is TokensRef {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return value && typeof value === \"object\" && typeof value.getRefTokens === \"function\";\n}\n\n// @internal\nexport function isTokenRef(value: any): value is TokenRef {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return value && typeof value === \"object\" && typeof value.getRefToken === \"function\";\n}\n","import { assert } from \"../errors\";\nimport { getMetadata } from \"../metadata\";\nimport type { Constructor, Token } from \"../token\";\nimport type { Decorator } from \"../tokenRegistry\";\nimport { forwardRef, isTokenRef, type TokenRef } from \"../tokensRef\";\n\nexport function processDecoratedParameter(\n decorator: Decorator,\n token: Token | TokenRef,\n target: object,\n propertyKey: string | symbol | undefined,\n parameterIndex: number,\n): void {\n // Error out immediately if the decorator has been applied\n // to a static property or a static method\n if (propertyKey !== undefined && typeof target === \"function\") {\n assert(false, `@${decorator} cannot be used on static member ${target.name}.${String(propertyKey)}`);\n }\n\n const tokenRef = isTokenRef(token) ? token : forwardRef(() => token);\n\n if (propertyKey === undefined) {\n // Constructor\n const metadata = getMetadata(target as Constructor<any>);\n metadata.dependencies.constructor.push({\n decorator: decorator,\n tokenRef: tokenRef,\n index: parameterIndex,\n });\n } else {\n // Normal instance method\n const metadata = getMetadata(target.constructor as Constructor<any>);\n const methods = metadata.dependencies.methods;\n let dep = methods.get(propertyKey);\n\n if (dep === undefined) {\n dep = [];\n methods.set(propertyKey, dep);\n }\n\n dep.push({\n decorator: decorator,\n tokenRef: tokenRef,\n index: parameterIndex,\n });\n }\n}\n","import type { Constructor, Token } from \"../token\";\nimport type { TokenRef } from \"../tokensRef\";\nimport { processDecoratedParameter } from \"./decorators\";\n\n/**\n * Parameter decorator that injects the instance associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\nexport function Inject<Instance extends object>(Class: Constructor<Instance>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects the value associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\nexport function Inject<Value>(token: Token<Value>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects the value associated with the given token.\n *\n * Allows referencing a token that is declared later in the file by using\n * the {@link forwardRef} helper function.\n *\n * Throws an error if the token is not registered in the container.\n *\n * @example\n * ```ts\n * class Wizard {\n * constructor(@Inject(forwardRef(() => Wand)) readonly wand: Wand) {}\n * }\n * // Other code...\n * class Wand {}\n * ```\n */\nexport function Inject<Value>(tokens: TokenRef<Value>): ParameterDecorator;\n\nexport function Inject<T>(token: Token<T> | TokenRef<T>): ParameterDecorator {\n return function (target, propertyKey, parameterIndex: number): void {\n processDecoratedParameter(\"Inject\", token, target, propertyKey, parameterIndex);\n };\n}\n","import { getMetadata } from \"../metadata\";\nimport type { Constructor, Tokens } from \"../token\";\nimport { forwardRef, isTokensRef, type TokenRef, type TokensRef } from \"../tokensRef\";\n\n/**\n * Class decorator that registers additional aliasing tokens for the decorated type,\n * when the type is first registered in the container.\n *\n * The container uses {@link ExistingProvider} under the hood.\n *\n * @example\n * ```ts\n * @Injectable(Weapon)\n * class Wand {}\n * ```\n */\nexport function Injectable<This extends object, Value extends This>(...tokens: Tokens<Value>): ClassDecorator;\n\n/**\n * Class decorator that registers additional aliasing tokens for the decorated type,\n * when the type is first registered in the container.\n *\n * The container uses {@link ExistingProvider} under the hood.\n *\n * Allows referencing tokens that are declared later in the file by using\n * the {@link forwardRef} helper function.\n *\n * @example\n * ```ts\n * @Injectable(forwardRef() => Weapon) // Weapon is declared after Wand\n * class Wizard {}\n * // Other code...\n * class Weapon {}\n * ```\n */\nexport function Injectable<This extends object, Value extends This>(\n tokens: TokenRef<Value> | TokensRef<Value>,\n): ClassDecorator;\n\n/**\n * @__NO_SIDE_EFFECTS__\n */\nexport function Injectable(...args: unknown[]): ClassDecorator {\n return function (Class): void {\n const metadata = getMetadata(Class as any as Constructor<any>);\n const arg0 = args[0];\n const tokensRef = isTokensRef(arg0) ? arg0 : forwardRef(() => args as Tokens);\n const existingTokensRef = metadata.tokensRef;\n metadata.tokensRef = {\n getRefTokens: () => {\n const existingTokens = existingTokensRef.getRefTokens();\n\n for (const token of tokensRef.getRefTokens()) {\n existingTokens.add(token);\n }\n\n return existingTokens;\n },\n };\n };\n}\n","import type { Constructor, Token } from \"../token\";\nimport type { TokenRef } from \"../tokensRef\";\nimport { processDecoratedParameter } from \"./decorators\";\n\n/**\n * Parameter decorator that injects all instances provided by the registrations\n * associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\nexport function InjectAll<Instance extends object>(Class: Constructor<Instance>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects all values provided by the registrations\n * associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\nexport function InjectAll<Value>(token: Token<Value>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects all values provided by the registrations\n * associated with the given token.\n *\n * Allows referencing a token that is declared later in the file by using\n * the {@link forwardRef} helper function.\n *\n * Throws an error if the token is not registered in the container.\n *\n * @example\n * ```ts\n * class Wizard {\n * constructor(@InjectAll(forwardRef(() => Wand)) readonly wands: Wand[]) {}\n * }\n * // Other code...\n * class Wand {}\n * ```\n */\nexport function InjectAll<Value>(tokens: TokenRef<Value>): ParameterDecorator;\n\nexport function InjectAll<T>(token: Token<T> | TokenRef<T>): ParameterDecorator {\n return function (target, propertyKey, parameterIndex: number): void {\n processDecoratedParameter(\"InjectAll\", token, target, propertyKey, parameterIndex);\n };\n}\n","import type { Constructor, Token } from \"../token\";\nimport type { TokenRef } from \"../tokensRef\";\nimport { processDecoratedParameter } from \"./decorators\";\n\n/**\n * Parameter decorator that injects the instance associated with the given class,\n * or `undefined` if the class is not registered in the container.\n */\nexport function Optional<Instance extends object>(Class: Constructor<Instance>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects the value associated with the given token,\n * or `undefined` if the token is not registered in the container.\n */\nexport function Optional<Value>(token: Token<Value>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects the value associated with the given token,\n * or `undefined` if the token is not registered in the container.\n *\n * Allows referencing a token that is declared later in the file by using\n * the {@link forwardRef} helper function.\n *\n * @example\n * ```ts\n * class Wizard {\n * constructor(@Optional(forwardRef(() => Wand)) readonly wand: Wand | undefined) {}\n * }\n * // Other code...\n * class Wand {}\n * ```\n */\nexport function Optional<Value>(tokens: TokenRef<Value>): ParameterDecorator;\n\nexport function Optional<T>(token: Token<T> | TokenRef<T>): ParameterDecorator {\n return function (target, propertyKey, parameterIndex: number): void {\n processDecoratedParameter(\"Optional\", token, target, propertyKey, parameterIndex);\n };\n}\n","import type { Constructor, Token } from \"../token\";\nimport type { TokenRef } from \"../tokensRef\";\nimport { processDecoratedParameter } from \"./decorators\";\n\n/**\n * Parameter decorator that injects all instances provided by the registrations\n * associated with the given class, or an empty array if the class is not registered\n * in the container.\n */\nexport function OptionalAll<Instance extends object>(Class: Constructor<Instance>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects all values provided by the registrations\n * associated with the given token, or an empty array if the token is not registered\n * in the container.\n */\nexport function OptionalAll<Value>(token: Token<Value>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects all values provided by the registrations\n * associated with the given token, or an empty array if the token is not registered\n * in the container.\n *\n * Allows referencing a token that is declared later in the file by using\n * the {@link forwardRef} helper function.\n *\n * @example\n * ```ts\n * class Wizard {\n * constructor(@OptionalAll(forwardRef(() => Wand)) readonly wands: Wand[]) {}\n * }\n * // Other code...\n * class Wand {}\n * ```\n */\nexport function OptionalAll<Value>(tokens: TokenRef<Value>): ParameterDecorator;\n\nexport function OptionalAll<T>(token: Token<T> | TokenRef<T>): ParameterDecorator {\n return function (target, propertyKey, parameterIndex: number): void {\n processDecoratedParameter(\"OptionalAll\", token, target, propertyKey, parameterIndex);\n };\n}\n","import { getMetadata } from \"../metadata\";\nimport type { Scope } from \"../scope\";\nimport type { Constructor } from \"../token\";\n\n/**\n * Class decorator for setting the scope of the decorated type when registering it.\n *\n * The scope set by this decorator can be overridden by explicit registration options, if provided.\n *\n * @example\n * ```ts\n * @Scoped(Scope.Container)\n * class Wizard {}\n *\n * container.register(Wizard);\n *\n * // Under the hood\n * container.register(\n * Wizard,\n * { useClass: Wizard },\n * { scope: Scope.Container },\n * );\n * ```\n *\n * @__NO_SIDE_EFFECTS__\n */\nexport function Scoped(scope: Scope): ClassDecorator {\n return function (Class): void {\n const metadata = getMetadata(Class as any as Constructor<any>);\n metadata.scope = scope;\n };\n}\n","import { inject } from \"./inject\";\nimport { injectAll } from \"./injectAll\";\nimport { ensureInjectionContext, provideInjectionContext, useInjectionContext } from \"./injectionContext\";\nimport { optional } from \"./optional\";\nimport { optionalAll } from \"./optionalAll\";\nimport type { Constructor, Token, Type } from \"./token\";\nimport { build } from \"./tokenRegistry\";\n\n/**\n * Injector API.\n */\nexport interface Injector {\n /**\n * Injects the instance associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\n inject<Instance extends object>(Class: Constructor<Instance>): Instance;\n\n /**\n * Injects the value associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\n inject<Value>(token: Token<Value>): Value;\n\n /**\n * Injects all instances provided by the registrations associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\n injectAll<Instance extends object>(Class: Constructor<Instance>): Instance[];\n\n /**\n * Injects all values provided by the registrations associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\n injectAll<Value>(token: Token<Value>): NonNullable<Value>[];\n\n /**\n * Injects the instance associated with the given class,\n * or `undefined` if the class is not registered in the container.\n */\n optional<Instance extends object>(Class: Constructor<Instance>): Instance | undefined;\n\n /**\n * Injects the value associated with the given token,\n * or `undefined` if the token is not registered in the container.\n */\n optional<Value>(token: Token<Value>): Value | undefined;\n\n /**\n * Injects all instances provided by the registrations associated with the given class,\n * or an empty array if the class is not registered in the container.\n */\n optionalAll<Instance extends object>(Class: Constructor<Instance>): Instance[];\n\n /**\n * Injects all values provided by the registrations associated with the given token,\n * or an empty array if the token is not registered in the container.\n */\n optionalAll<Value>(token: Token<Value>): NonNullable<Value>[];\n}\n\n/**\n * Injector token for dynamic injections.\n *\n * @example\n * ```ts\n * class Wizard {\n * private injector = inject(Injector);\n * private wand?: Wand;\n *\n * getWand(): Wand {\n * return (this.wand ??= this.injector.inject(Wand));\n * }\n * }\n *\n * const wizard = container.resolve(Wizard);\n * wizard.getWand(); // => Wand\n * ```\n */\nexport const Injector: Type<Injector> = /*@__PURE__*/ build(function Injector() {\n const context = ensureInjectionContext(Injector);\n const resolution = context.resolution;\n\n const dependentFrame = resolution.stack.peek();\n const dependentRef = dependentFrame && resolution.dependents.get(dependentFrame.provider);\n\n function withCurrentContext<R>(fn: () => R): R {\n if (useInjectionContext()) {\n return fn();\n }\n\n const cleanups = [\n provideInjectionContext(context),\n dependentFrame && resolution.stack.push(dependentFrame.provider, dependentFrame),\n dependentRef && resolution.dependents.set(dependentFrame.provider, dependentRef),\n ];\n\n try {\n return fn();\n } finally {\n for (const cleanup of cleanups) {\n cleanup?.();\n }\n }\n }\n\n return {\n inject: <T>(token: Token<T>) => withCurrentContext(() => inject(token)),\n injectAll: <T>(token: Token<T>) => withCurrentContext(() => injectAll(token)),\n optional: <T>(token: Token<T>) => withCurrentContext(() => optional(token)),\n optionalAll: <T>(token: Token<T>) => withCurrentContext(() => optionalAll(token)),\n };\n});\n","import type { Container } from \"./container\";\n\n/**\n * Composer API for middleware functions.\n */\nexport interface MiddlewareComposer {\n /**\n * Adds a middleware function to the composer.\n */\n use<MethodKey extends keyof Container>(\n key: MethodKey,\n wrap: Container[MethodKey] extends Function\n ? (next: Container[MethodKey]) => Container[MethodKey]\n : never,\n ): MiddlewareComposer;\n}\n\n/**\n * Middleware function that can be used to extend the container.\n *\n * @example\n * ```ts\n * const logger: Middleware = (composer, _api) => {\n * composer\n * .use(\"resolve\", (next) => (...args) => {\n * console.log(\"resolve\", args);\n * return next(...args);\n * })\n * .use(\"resolveAll\", (next) => (...args) => {\n * console.log(\"resolveAll\", args);\n * return next(...args);\n * });\n * };\n * ```\n */\nexport interface Middleware {\n (composer: MiddlewareComposer, api: Readonly<Container>): void;\n}\n\n/**\n * Applies middleware functions to a container.\n *\n * Middlewares are applied in array order, but execute in reverse order.\n *\n * @example\n * ```ts\n * const container = applyMiddleware(\n * createContainer(),\n * [A, B],\n * );\n * ```\n *\n * The execution order will be:\n *\n * 1. B before\n * 2. A before\n * 3. original function\n * 4. A after\n * 5. B after\n *\n * This allows outer middlewares to wrap and control the behavior of inner middlewares.\n */\nexport function applyMiddleware(container: Container, middlewares: Middleware[]): Container {\n const composer: MiddlewareComposer = {\n use(key, wrap): MiddlewareComposer {\n // We need to bind the 'this' context of the function to the container\n // before passing it to the middleware wrapper.\n //\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call\n const fn = (container[key] as any).bind(container);\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n container[key] = wrap(fn);\n return composer;\n },\n };\n\n const api = (container.api ||= { ...container });\n\n for (const middleware of middlewares) {\n middleware(composer, api);\n }\n\n return container;\n}\n"],"names":["assert","condition","message","resolvedMessage","Error","tag","expectNever","value","TypeError","String","throwUnregisteredError","token","name","throwExistingUnregisteredError","sourceToken","targetTokenOrError","isError","untag","stack","startsWith","substring","trimStart","createInjectionContext","current","provide","next","prev","use","invariant","KeyedStack","has","key","myKeys","peek","entry","myEntries","at","push","add","pop","delete","Array","WeakSet","WeakRefMap","get","ref","myMap","deref","set","WeakRef","WeakMap","createResolution","values","dependents","provideInjectionContext","useInjectionContext","ensureInjectionContext","fn","context","inject","container","resolve","injectBy","thisArg","resolution","currentFrame","currentRef","cleanup","provider","injectAll","resolveAll","getMetadata","Class","metadata","metadataMap","tokensRef","getRefTokens","Set","useClass","dependencies","methods","Map","optional","optionalBy","optionalAll","isClassProvider","isFactoryProvider","isValueProvider","isExistingProvider","Scope","Inherited","Transient","Resolution","Container","createType","typeName","type","inter","union","toString","isConstructor","getTypeName","proto","Object","getPrototypeOf","prototype","constructor","TokenRegistry","parent","myParent","getAll","internal","internals","getAllFromParent","registration","registrations","deleteAll","tokens","from","keys","flat","clear","clearRegistrations","i","length","undefined","isBuilder","builders","build","factory","useFactory","options","scope","isDisposable","dispose","ContainerImpl","myChildren","myDisposed","myOptions","autoRegister","defaultScope","myTokenRegistry","registry","isDisposed","createChild","checkDisposed","clearCache","getCached","getAllCached","resetRegistry","isRegistered","registerClass","ctor","register","registerFactory","registerValue","useValue","registerAlias","targetToken","aliasTokens","alias","useExisting","args","eagerInstantiate","unregister","resolveRegistration","instantiateClass","map","filter","instance","child","disposedRefs","currRegistration","currProvider","resolveProviderValue","e","resolveScope","resolveScopedValue","dependentRef","cleanups","valueRef","resolveConstructorDependencies","injectDependencies","forEach","dependentFrame","ctorDeps","msg","sort","a","b","index","dep","tokenRef","getRefToken","decorator","methodDeps","method","bind","createContainer","AutoRegister","EagerInstantiate","forwardRef","tokenOrTokens","tokensArray","isArray","isTokensRef","isTokenRef","processDecoratedParameter","target","propertyKey","parameterIndex","Inject","Injectable","arg0","existingTokensRef","existingTokens","InjectAll","Optional","OptionalAll","Scoped","Injector","withCurrentContext","applyMiddleware","middlewares","composer","wrap","api","middleware"],"mappings":";;AAEA;AACO,SAASA,MAAAA,CAAOC,SAAkB,EAAEC,OAAgC,EAAA;AACzE,IAAA,IAAI,CAACD,SAAAA,EAAW;AACd,QAAA,MAAME,eAAAA,GAAkB,OAAOD,OAAAA,KAAY,QAAA,GAAWA,OAAAA,GAAUA,OAAAA,EAAAA;QAChE,MAAM,IAAIE,MAAMC,GAAAA,CAAIF,eAAAA,CAAAA,CAAAA;AACtB;AAC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/utils/keyedStack.ts","../../src/utils/weakRefMap.ts","../../src/injectionContext.ts","../../src/inject.ts","../../src/injectAll.ts","../../src/metadata.ts","../../src/optional.ts","../../src/optionalAll.ts","../../src/provider.ts","../../src/scope.ts","../../src/token.ts","../../src/utils/typeName.ts","../../src/tokenRegistry.ts","../../src/utils/disposable.ts","../../src/containerImpl.ts","../../src/container.ts","../../src/decorators/autoRegister.ts","../../src/decorators/eagerInstantiate.ts","../../src/tokensRef.ts","../../src/decorators/decorators.ts","../../src/decorators/inject.ts","../../src/decorators/injectable.ts","../../src/decorators/injectAll.ts","../../src/decorators/optional.ts","../../src/decorators/optionalAll.ts","../../src/decorators/scoped.ts","../../src/injector.ts","../../src/middleware.ts"],"sourcesContent":["import type { Token } from \"./token\";\n\n// @internal\nexport function assert(condition: unknown, message: string | (() => string)): asserts condition {\n if (!condition) {\n const resolvedMessage = typeof message === \"string\" ? message : message();\n throw new Error(tag(resolvedMessage));\n }\n}\n\n// @internal\nexport function expectNever(value: never): never {\n throw new TypeError(tag(`unexpected value ${String(value)}`));\n}\n\n// @internal\nexport function throwUnregisteredError(token: Token): never {\n throw new Error(tag(`unregistered token ${token.name}`));\n}\n\n// @internal\nexport function throwExistingUnregisteredError(sourceToken: Token, targetTokenOrError: Token | Error): never {\n let message = tag(`token resolution error encountered while resolving ${sourceToken.name}`);\n\n if (isError(targetTokenOrError)) {\n message += `\\n [cause] ${untag(targetTokenOrError.message)}`;\n } else {\n message += `\\n [cause] the aliased token ${targetTokenOrError.name} is not registered`;\n }\n\n throw new Error(message);\n}\n\nfunction isError(value: any): value is Error {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return value && value.stack && value.message && typeof value.message === \"string\";\n}\n\nfunction tag(message: string): string {\n return `[di-wise-neo] ${message}`;\n}\n\nfunction untag(message: string): string {\n return message.startsWith(\"[di-wise-neo]\") //\n ? message.substring(13).trimStart()\n : message;\n}\n","// @internal\nexport function createInjectionContext<T extends {}>(): readonly [\n (next: T) => () => T | null,\n () => T | null,\n] {\n let current: T | null = null;\n\n function provide(next: T): () => T | null {\n const prev = current;\n current = next;\n return () => (current = prev);\n }\n\n function use(): T | null {\n return current;\n }\n\n return [provide, use] as const;\n}\n","// @internal\nexport function invariant(condition: unknown): asserts condition {\n if (!condition) {\n throw new Error(\"invariant violation\");\n }\n}\n","import { invariant } from \"./invariant\";\n\n// @internal\nexport class KeyedStack<K extends object, V> {\n private readonly myEntries = new Array<{ key: K; value: V }>();\n private readonly myKeys = new WeakSet<K>();\n\n has(key: K): boolean {\n return this.myKeys.has(key);\n }\n\n peek(): V | undefined {\n const entry = this.myEntries.at(-1);\n return entry?.value;\n }\n\n push(key: K, value: V): () => void {\n invariant(!this.has(key));\n this.myKeys.add(key);\n this.myEntries.push({ key, value });\n return () => {\n this.myEntries.pop();\n this.myKeys.delete(key);\n };\n }\n}\n","import { invariant } from \"./invariant\";\n\n// @internal\nexport class WeakRefMap<K extends WeakKey, V extends object> {\n private readonly myMap = new WeakMap<K, WeakRef<V>>();\n\n get(key: K): V | undefined {\n const ref = this.myMap.get(key);\n\n if (ref) {\n const value = ref.deref();\n\n if (value) {\n return value;\n }\n\n this.myMap.delete(key);\n }\n }\n\n set(key: K, value: V): () => void {\n invariant(!this.get(key));\n this.myMap.set(key, new WeakRef(value));\n return () => {\n this.myMap.delete(key);\n };\n }\n}\n","import type { Container } from \"./container\";\nimport { assert } from \"./errors\";\nimport type { Provider } from \"./provider\";\nimport type { Scope } from \"./scope\";\nimport { createInjectionContext } from \"./utils/context\";\nimport { KeyedStack } from \"./utils/keyedStack\";\nimport { WeakRefMap } from \"./utils/weakRefMap\";\nimport type { ValueRef } from \"./valueRef\";\n\n// @internal\nexport interface ResolutionFrame {\n readonly scope: Exclude<Scope, typeof Scope.Inherited>;\n readonly provider: Provider;\n}\n\n// @internal\nexport interface Resolution {\n readonly stack: KeyedStack<Provider, ResolutionFrame>;\n readonly values: WeakRefMap<Provider, ValueRef>;\n readonly dependents: WeakRefMap<Provider, ValueRef>;\n}\n\n// @internal\nexport interface InjectionContext {\n readonly container: Container;\n readonly resolution: Resolution;\n}\n\n// @internal\nexport function createResolution(): Resolution {\n return {\n stack: new KeyedStack(),\n values: new WeakRefMap(),\n dependents: new WeakRefMap(),\n };\n}\n\n// @internal\nexport const [provideInjectionContext, useInjectionContext] = createInjectionContext<InjectionContext>();\n\n// @internal\nexport function ensureInjectionContext(fn: Function): InjectionContext {\n const context = useInjectionContext();\n assert(context, `${fn.name}() can only be invoked within an injection context`);\n return context;\n}\n","import { ensureInjectionContext } from \"./injectionContext\";\nimport type { Constructor, Token } from \"./token\";\n\n/**\n * Injects the instance associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\nexport function inject<Instance extends object>(Class: Constructor<Instance>): Instance;\n\n/**\n * Injects the value associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\nexport function inject<Value>(token: Token<Value>): Value;\n\nexport function inject<T>(token: Token<T>): T {\n const context = ensureInjectionContext(inject);\n return context.container.resolve(token);\n}\n\n/**\n * Injects the instance associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n *\n * Compared to {@link inject}, `injectBy` accepts a `thisArg` argument\n * (the containing class) which is used to resolve circular dependencies.\n *\n * @example\n * ```ts\n * class Wand {\n * owner = inject(Wizard);\n * }\n *\n * class Wizard {\n * wand = injectBy(this, Wand);\n * }\n * ```\n *\n * @param thisArg - The containing instance, used to help resolve circular dependencies.\n * @param Class - The class to resolve.\n */\nexport function injectBy<Instance extends object>(thisArg: any, Class: Constructor<Instance>): Instance;\n\n/**\n * Injects the value associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n *\n * Compared to {@link inject}, `injectBy` accepts a `thisArg` argument\n * (the containing class) which is used to resolve circular dependencies.\n *\n * @example\n * ```ts\n * class Wand {\n * owner = inject(Wizard);\n * }\n *\n * class Wizard {\n * wand = injectBy(this, Wand);\n * }\n * ```\n *\n * @param thisArg - The containing instance, used to help resolve circular dependencies.\n * @param token - The token to resolve.\n */\nexport function injectBy<Value>(thisArg: any, token: Token<Value>): Value;\n\nexport function injectBy<T>(thisArg: any, token: Token<T>): T {\n const context = ensureInjectionContext(injectBy);\n const resolution = context.resolution;\n const currentFrame = resolution.stack.peek();\n\n if (!currentFrame) {\n return inject(token);\n }\n\n const currentRef = { current: thisArg };\n const cleanup = resolution.dependents.set(currentFrame.provider, currentRef);\n\n try {\n return inject(token);\n } finally {\n cleanup();\n }\n}\n","import { ensureInjectionContext } from \"./injectionContext\";\nimport type { Constructor, Token } from \"./token\";\n\n/**\n * Injects all instances provided by the registrations associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\nexport function injectAll<Instance extends object>(Class: Constructor<Instance>): Instance[];\n\n/**\n * Injects all values provided by the registrations associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\nexport function injectAll<Value>(token: Token<Value>): NonNullable<Value>[];\n\nexport function injectAll<T>(token: Token<T>): NonNullable<T>[] {\n const context = ensureInjectionContext(injectAll);\n return context.container.resolveAll(token);\n}\n","import type { ClassProvider } from \"./provider\";\nimport type { Scope } from \"./scope\";\nimport type { Constructor } from \"./token\";\nimport type { Dependencies } from \"./tokenRegistry\";\nimport type { TokensRef } from \"./tokensRef\";\n\n// @internal\nexport interface Metadata<This extends object = any> {\n eagerInstantiate?: boolean;\n autoRegister?: boolean;\n scope?: Scope;\n tokensRef: TokensRef<This>;\n provider: ClassProvider<This>;\n dependencies: Dependencies;\n}\n\n// @internal\nexport function getMetadata<T extends object>(Class: Constructor<T>): Metadata<T> {\n let metadata = metadataMap.get(Class);\n\n if (!metadata) {\n metadataMap.set(\n Class,\n (metadata = {\n tokensRef: {\n getRefTokens: () => new Set(),\n },\n provider: {\n useClass: Class,\n },\n dependencies: {\n constructor: [],\n methods: new Map(),\n },\n }),\n );\n }\n\n return metadata;\n}\n\nconst metadataMap = new WeakMap<Constructor<object>, Metadata>();\n","import { ensureInjectionContext } from \"./injectionContext\";\nimport type { Constructor, Token } from \"./token\";\n\n/**\n * Injects the instance associated with the given class,\n * or `undefined` if the class is not registered in the container.\n */\nexport function optional<Instance extends object>(Class: Constructor<Instance>): Instance | undefined;\n\n/**\n * Injects the value associated with the given token,\n * or `undefined` if the token is not registered in the container.\n */\nexport function optional<Value>(token: Token<Value>): Value | undefined;\n\nexport function optional<T>(token: Token<T>): T | undefined {\n const context = ensureInjectionContext(optional);\n return context.container.resolve(token, true);\n}\n\n/**\n * Injects the instance associated with the given class,\n * or `undefined` if the class is not registered in the container.\n *\n * Compared to {@link optional}, `optionalBy` accepts a `thisArg` argument\n * (the containing class) which is used to resolve circular dependencies.\n *\n * @param thisArg - The containing instance, used to help resolve circular dependencies.\n * @param Class - The class to resolve.\n */\nexport function optionalBy<Instance extends object>(\n thisArg: any,\n Class: Constructor<Instance>,\n): Instance | undefined;\n\n/**\n * Injects the value associated with the given token,\n * or `undefined` if the token is not registered in the container.\n *\n * Compared to {@link optional}, `optionalBy` accepts a `thisArg` argument\n * (the containing class) which is used to resolve circular dependencies.\n *\n * @param thisArg - The containing instance, used to help resolve circular dependencies.\n * @param token - The token to resolve.\n */\nexport function optionalBy<Value>(thisArg: any, token: Token<Value>): Value | undefined;\n\nexport function optionalBy<T>(thisArg: any, token: Token<T>): T | undefined {\n const context = ensureInjectionContext(optionalBy);\n const resolution = context.resolution;\n const currentFrame = resolution.stack.peek();\n\n if (!currentFrame) {\n return optional(token);\n }\n\n const currentRef = { current: thisArg };\n const cleanup = resolution.dependents.set(currentFrame.provider, currentRef);\n\n try {\n return optional(token);\n } finally {\n cleanup();\n }\n}\n","import { ensureInjectionContext } from \"./injectionContext\";\nimport type { Constructor, Token } from \"./token\";\n\n/**\n * Injects all instances provided by the registrations associated with the given class,\n * or an empty array if the class is not registered in the container.\n */\nexport function optionalAll<Instance extends object>(Class: Constructor<Instance>): Instance[];\n\n/**\n * Injects all values provided by the registrations associated with the given token,\n * or an empty array if the token is not registered in the container.\n */\nexport function optionalAll<Value>(token: Token<Value>): NonNullable<Value>[];\n\nexport function optionalAll<T>(token: Token<T>): NonNullable<T>[] {\n const context = ensureInjectionContext(optionalAll);\n return context.container.resolveAll(token, true);\n}\n","import type { Constructor, Token } from \"./token\";\n\n/**\n * Provides a class instance for a token via a class constructor.\n */\nexport interface ClassProvider<Instance extends object> {\n readonly useClass: Constructor<Instance>;\n}\n\n/**\n * Provides a value for a token via a factory function.\n *\n * The factory function runs inside the injection context and can\n * thus access dependencies via {@link inject}-like functions.\n */\nexport interface FactoryProvider<Value> {\n readonly useFactory: (...args: []) => Value;\n}\n\n/**\n * Provides a static - already constructed - value for a token.\n */\nexport interface ValueProvider<T> {\n readonly useValue: T;\n}\n\n/**\n * Aliases another registered token.\n *\n * Resolving this token will return the value of the aliased one.\n */\nexport interface ExistingProvider<Value> {\n readonly useExisting: Token<Value>;\n}\n\n/**\n * A token provider.\n */\nexport type Provider<Value = any> =\n | ClassProvider<Value & object>\n | FactoryProvider<Value>\n | ValueProvider<Value>\n | ExistingProvider<Value>;\n\n// @internal\nexport function isClassProvider<T>(provider: Provider<T>): provider is ClassProvider<T & object> {\n return \"useClass\" in provider;\n}\n\n// @internal\nexport function isFactoryProvider<T>(provider: Provider<T>): provider is FactoryProvider<T> {\n return \"useFactory\" in provider;\n}\n\n// @internal\nexport function isValueProvider<T>(provider: Provider<T>): provider is ValueProvider<T> {\n return \"useValue\" in provider;\n}\n\n// @internal\nexport function isExistingProvider<T>(provider: Provider<T>): provider is ExistingProvider<T> {\n return \"useExisting\" in provider;\n}\n","export const Scope = {\n Inherited: \"Inherited\",\n Transient: \"Transient\",\n Resolution: \"Resolution\",\n Container: \"Container\",\n} as const;\n\nexport type Scope = (typeof Scope)[keyof typeof Scope];\n","/**\n * Type API.\n */\nexport interface Type<A> {\n /**\n * The name of the type.\n */\n readonly name: string;\n\n /**\n * Creates an intersection type from another type.\n *\n * @example\n * ```ts\n * const A = createType<A>(\"A\");\n * const B = createType<B>(\"B\");\n *\n * A.inter(\"I\", B); // => Type<A & B>\n * ```\n */\n inter<B>(typeName: string, B: Type<B>): Type<A & B>;\n\n /**\n * Creates a union type from another type.\n *\n * @example\n * ```ts\n * const A = createType<A>(\"A\");\n * const B = createType<B>(\"B\");\n *\n * A.union(\"U\", B); // => Type<A | B>\n * ```\n */\n union<B>(typeName: string, B: Type<B>): Type<A | B>;\n}\n\n/**\n * Constructor type.\n */\nexport interface Constructor<Instance extends object> {\n new (...args: any[]): Instance;\n readonly name: string;\n}\n\n/**\n * Token type.\n */\nexport type Token<Value = any> = [Value] extends [object] // Avoids distributive union behavior\n ? Type<Value> | Constructor<Value>\n : Type<Value>;\n\n/**\n * Describes a {@link Token} array with at least one element.\n */\nexport type Tokens<Value = any> = [Token<Value>, ...Token<Value>[]];\n\n/**\n * Creates a type token.\n *\n * @example\n * ```ts\n * const ISpell = createType<Spell>(\"Spell\");\n * ```\n *\n * @__NO_SIDE_EFFECTS__\n */\nexport function createType<T>(typeName: string): Type<T> {\n const type = {\n name: `Type<${typeName}>`,\n inter: createType,\n union: createType,\n toString(): string {\n return type.name;\n },\n };\n\n return type;\n}\n\n// @internal\nexport function isConstructor<T>(token: Type<T> | Constructor<T & object>): token is Constructor<T & object> {\n return typeof token == \"function\";\n}\n","// @internal\nexport function getTypeName(value: unknown): string {\n if (typeof value == \"string\") {\n return `\"${value}\"`;\n }\n\n if (typeof value == \"function\") {\n return (value.name && `typeof ${value.name}`) || \"Function\";\n }\n\n if (typeof value == \"object\") {\n if (value === null) {\n return \"null\";\n }\n\n const proto: object | null = Object.getPrototypeOf(value);\n\n if (proto && proto !== Object.prototype) {\n const constructor: unknown = proto.constructor;\n\n if (typeof constructor == \"function\" && constructor.name) {\n return constructor.name;\n }\n }\n }\n\n return typeof value;\n}\n","import { assert } from \"./errors\";\nimport type { FactoryProvider, Provider } from \"./provider\";\nimport { Scope } from \"./scope\";\nimport { type Constructor, createType, type Token, type Type } from \"./token\";\nimport type { TokenRef } from \"./tokensRef\";\nimport { getTypeName } from \"./utils/typeName\";\nimport type { ValueRef } from \"./valueRef\";\n\n/**\n * Token registration options.\n */\nexport interface RegistrationOptions {\n /**\n * The scope of the registration.\n */\n readonly scope?: Scope;\n}\n\n// @internal\nexport type Decorator = \"Inject\" | \"InjectAll\" | \"Optional\" | \"OptionalAll\";\n\n// @internal\nexport interface MethodDependency {\n readonly decorator: Decorator;\n readonly tokenRef: TokenRef;\n\n // The index of the annotated parameter (zero-based)\n readonly index: number;\n}\n\n// @internal\nexport interface Dependencies {\n readonly constructor: MethodDependency[];\n readonly methods: Map<string | symbol, MethodDependency[]>;\n}\n\n// @internal\nexport interface Registration<T = any> {\n value?: ValueRef<T>;\n readonly provider: Provider<T>;\n readonly options?: RegistrationOptions;\n readonly dependencies?: Dependencies;\n}\n\n// @internal\nexport class TokenRegistry {\n private readonly myParent?: TokenRegistry;\n private readonly myMap = new Map<Token, Registration[]>();\n\n constructor(parent: TokenRegistry | undefined) {\n this.myParent = parent;\n }\n\n get<T>(token: Token<T>): Registration<T> | undefined {\n // To clarify, at(-1) means we take the last added registration for this token\n return this.getAll(token)?.at(-1);\n }\n\n getAll<T>(token: Token<T>): Registration<T>[] | undefined {\n const internal = internals.get(token);\n return (internal && [internal]) || this.getAllFromParent(token);\n }\n\n //\n // set(...) overloads added because of TS distributive conditional types.\n //\n // TODO(Edoardo): is there a better way? Maybe refactor the Token<T> type\n // into two types, TokenObject<T extends object> | Token<T>\n //\n\n set<T extends object>(token: Type<T> | Constructor<T>, registration: Registration<T>): void;\n set<T>(token: Token<T>, registration: Registration<T>): void;\n set<T>(token: Token<T>, registration: Registration<T>): void {\n assert(!internals.has(token), `cannot register reserved token ${token.name}`);\n\n let registrations = this.myMap.get(token);\n\n if (!registrations) {\n this.myMap.set(token, (registrations = []));\n }\n\n registrations.push(registration);\n }\n\n delete<T>(token: Token<T>): Registration<T>[] | undefined {\n const registrations = this.myMap.get(token);\n this.myMap.delete(token);\n return registrations;\n }\n\n deleteAll(): [Token[], Registration[]] {\n const tokens = Array.from(this.myMap.keys());\n const registrations = Array.from(this.myMap.values()).flat();\n this.myMap.clear();\n return [tokens, registrations];\n }\n\n clearRegistrations(): unknown[] {\n const values = new Set<unknown>();\n\n for (const registrations of this.myMap.values()) {\n for (let i = 0; i < registrations.length; i++) {\n const registration = registrations[i]!;\n const value = registration.value;\n\n if (value) {\n values.add(value.current);\n }\n\n registrations[i] = {\n ...registration,\n value: undefined,\n };\n }\n }\n\n return Array.from(values);\n }\n\n private getAllFromParent<T>(token: Token<T>): Registration<T>[] | undefined {\n const registrations = this.myMap.get(token);\n return registrations || this.myParent?.getAllFromParent(token);\n }\n}\n\n// @internal\nexport function isBuilder(provider: Provider): boolean {\n return builders.has(provider);\n}\n\n/**\n * Create a one-off type token from a factory function.\n *\n * @example\n * ```ts\n * class Wizard {\n * wand = inject(\n * build(() => {\n * const wand = inject(Wand);\n * wand.owner = this;\n * // ...\n * return wand;\n * }),\n * );\n * }\n * ```\n *\n * @__NO_SIDE_EFFECTS__\n */\nexport function build<Value>(factory: (...args: []) => Value): Type<Value> {\n const token = createType<Value>(`Build<${getTypeName(factory)}>`);\n const provider: FactoryProvider<Value> = {\n useFactory: factory,\n };\n\n internals.set(token, {\n provider: provider,\n options: {\n scope: Scope.Transient,\n },\n });\n\n builders.add(provider);\n return token;\n}\n\nconst internals = new WeakMap<Token, Registration>();\nconst builders = new WeakSet<Provider>();\n","// @internal\nexport interface Disposable {\n dispose(): void;\n}\n\n// @internal\nexport function isDisposable(value: any): value is Disposable {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return value && typeof value === \"object\" && typeof value.dispose === \"function\";\n}\n","import type { Container, ContainerOptions } from \"./container\";\nimport { assert, expectNever, throwExistingUnregisteredError, throwUnregisteredError } from \"./errors\";\nimport { injectBy } from \"./inject\";\nimport { injectAll } from \"./injectAll\";\nimport { createResolution, provideInjectionContext, useInjectionContext } from \"./injectionContext\";\nimport { getMetadata } from \"./metadata\";\nimport { optionalBy } from \"./optional\";\nimport { optionalAll } from \"./optionalAll\";\nimport {\n isClassProvider,\n isExistingProvider,\n isFactoryProvider,\n isValueProvider,\n type Provider,\n} from \"./provider\";\nimport { Scope } from \"./scope\";\nimport { type Constructor, isConstructor, type Token, type Tokens } from \"./token\";\nimport { isBuilder, type Registration, type RegistrationOptions, TokenRegistry } from \"./tokenRegistry\";\nimport { isDisposable } from \"./utils/disposable\";\n\n/**\n * The default implementation of a di-wise-neo {@link Container}.\n */\nexport class ContainerImpl implements Container {\n private readonly myParent?: ContainerImpl;\n private readonly myChildren: Set<ContainerImpl> = new Set();\n private readonly myOptions: ContainerOptions;\n private readonly myTokenRegistry: TokenRegistry;\n private myDisposed: boolean = false;\n\n constructor(parent: ContainerImpl | undefined, options: Partial<ContainerOptions>) {\n this.myParent = parent;\n this.myOptions = {\n autoRegister: false,\n defaultScope: Scope.Inherited,\n ...options,\n };\n\n this.myTokenRegistry = new TokenRegistry(this.myParent?.myTokenRegistry);\n }\n\n get registry(): TokenRegistry {\n return this.myTokenRegistry;\n }\n\n get options(): ContainerOptions {\n return {\n ...this.myOptions,\n };\n }\n\n get parent(): Container | undefined {\n return this.myParent;\n }\n\n get isDisposed(): boolean {\n return this.myDisposed;\n }\n\n createChild(options?: Partial<ContainerOptions>): Container {\n this.checkDisposed();\n const container = new ContainerImpl(this, {\n ...this.myOptions,\n ...options,\n });\n\n this.myChildren.add(container);\n return container;\n }\n\n clearCache(): unknown[] {\n this.checkDisposed();\n return this.myTokenRegistry.clearRegistrations();\n }\n\n getCached<T>(token: Token<T>): T | undefined {\n this.checkDisposed();\n const registration = this.myTokenRegistry.get(token);\n return registration?.value?.current;\n }\n\n getAllCached<T>(token: Token<T>): T[] {\n this.checkDisposed();\n const registrations = this.myTokenRegistry.getAll(token);\n\n if (!registrations) {\n return [];\n }\n\n const values = new Set<T>();\n\n for (const registration of registrations) {\n const value = registration.value;\n\n if (value) {\n values.add(value.current);\n }\n }\n\n return Array.from(values);\n }\n\n resetRegistry(): unknown[] {\n this.checkDisposed();\n const [, registrations] = this.myTokenRegistry.deleteAll();\n const values = new Set<unknown>();\n\n for (const registration of registrations) {\n const value = registration.value;\n\n if (value) {\n values.add(value.current);\n }\n }\n\n return Array.from(values);\n }\n\n isRegistered(token: Token): boolean {\n this.checkDisposed();\n return this.myTokenRegistry.get(token) !== undefined;\n }\n\n registerClass<T extends object, V extends T>(\n token: Token<T>,\n Class?: Constructor<V>,\n options?: RegistrationOptions,\n ): void {\n // This mess will go away once/if we remove the register method\n // in favor of the multiple specialized ones\n if (Class) {\n const ctor = (Class ?? token) as Constructor<any>;\n this.register(token, { useClass: ctor }, options);\n } else {\n this.register(token as Constructor<any>);\n }\n }\n\n registerFactory<T, V extends T>(\n token: Token<T>,\n factory: (...args: []) => V,\n options?: RegistrationOptions,\n ): void {\n this.register(token, { useFactory: factory }, options);\n }\n\n registerValue<T, V extends T>(token: Token<T>, value: V): void {\n this.register(token, { useValue: value });\n }\n\n registerAlias<T, V extends T>(targetToken: Token<V>, aliasTokens: Tokens<T>): void {\n // De-duplicate tokens\n for (const alias of new Set(aliasTokens)) {\n this.register(alias, { useExisting: targetToken });\n }\n }\n\n register<T>(...args: [Constructor<T & object>] | [Token<T>, Provider<T>, RegistrationOptions?]): Container {\n this.checkDisposed();\n\n if (args.length == 1) {\n const Class = args[0];\n const metadata = getMetadata(Class);\n const registration: Registration = {\n // The provider is of type ClassProvider, initialized by getMetadata\n provider: metadata.provider,\n options: {\n scope: metadata.scope ?? this.myOptions.defaultScope,\n },\n dependencies: metadata.dependencies,\n };\n\n // Register the class itself\n this.myTokenRegistry.set(Class, registration);\n\n // Register the additional tokens specified via class decorators.\n // These tokens will point to the original Class token and will have the same scope.\n for (const token of metadata.tokensRef.getRefTokens()) {\n this.myTokenRegistry.set(token, {\n provider: {\n useExisting: Class,\n },\n });\n }\n\n // Eager-instantiate only if the class is container-scoped\n if (metadata.eagerInstantiate && registration.options?.scope === Scope.Container) {\n this.resolve(Class);\n }\n } else {\n const [token, provider, options] = args;\n\n if (isClassProvider(provider)) {\n const metadata = getMetadata(provider.useClass);\n const registration: Registration = {\n provider: metadata.provider,\n options: {\n // The explicit registration options override what is specified\n // via class decorators (e.g., @Scoped)\n scope: metadata.scope ?? this.myOptions.defaultScope,\n ...options,\n },\n dependencies: metadata.dependencies,\n };\n\n this.myTokenRegistry.set(token, registration);\n\n // Eager-instantiate only if the provided class is container-scoped\n if (metadata.eagerInstantiate && registration.options?.scope === Scope.Container) {\n this.resolve(token);\n }\n } else {\n if (isExistingProvider(provider)) {\n assert(\n token !== provider.useExisting,\n `the useExisting token ${token.name} cannot be the same as the token being registered`,\n );\n }\n\n this.myTokenRegistry.set(token, {\n provider: provider,\n options: options,\n });\n }\n }\n\n return this;\n }\n\n unregister<T>(token: Token<T>): T[] {\n this.checkDisposed();\n const registrations = this.myTokenRegistry.delete(token);\n\n if (!registrations) {\n return [];\n }\n\n const values = new Set<T>();\n\n for (const registration of registrations) {\n const value = registration.value;\n\n if (value) {\n values.add(value.current);\n }\n }\n\n return Array.from(values);\n }\n\n resolve<T>(token: Token<T>, optional?: boolean): T | undefined {\n this.checkDisposed();\n const registration = this.myTokenRegistry.get(token);\n\n if (registration) {\n return this.resolveRegistration(token, registration);\n }\n\n if (isConstructor(token)) {\n return this.instantiateClass(token, optional);\n }\n\n return optional ? undefined : throwUnregisteredError(token);\n }\n\n resolveAll<T>(token: Token<T>, optional?: boolean): NonNullable<T>[] {\n this.checkDisposed();\n const registrations = this.myTokenRegistry.getAll(token);\n\n if (registrations) {\n return registrations\n .map((registration) => this.resolveRegistration(token, registration))\n .filter((value) => value != null);\n }\n\n if (isConstructor(token)) {\n const instance = this.instantiateClass(token, optional);\n return instance === undefined // = could not resolve, but since it is optional\n ? []\n : [instance];\n }\n\n return optional ? [] : throwUnregisteredError(token);\n }\n\n dispose(): void {\n if (this.myDisposed) {\n return;\n }\n\n // Dispose children containers first\n for (const child of this.myChildren) {\n child.dispose();\n }\n\n this.myChildren.clear();\n\n // Remove ourselves from our parent container\n this.myParent?.myChildren?.delete(this);\n this.myDisposed = true;\n\n const [, registrations] = this.myTokenRegistry.deleteAll();\n const disposedRefs = new Set<any>();\n\n // Dispose all resolved (aka instantiated) tokens that implement the Disposable interface\n for (const registration of registrations) {\n const value = registration.value?.current;\n\n if (isDisposable(value) && !disposedRefs.has(value)) {\n disposedRefs.add(value);\n value.dispose();\n }\n }\n\n // Allow values to be GCed\n disposedRefs.clear();\n }\n\n private resolveRegistration<T>(token: Token<T>, registration: Registration<T>): T {\n let currRegistration: Registration<T> | undefined = registration;\n let currProvider = currRegistration.provider;\n\n while (isExistingProvider(currProvider)) {\n const targetToken = currProvider.useExisting;\n currRegistration = this.myTokenRegistry.get(targetToken);\n\n if (!currRegistration) {\n throwExistingUnregisteredError(token, targetToken);\n }\n\n currProvider = currRegistration.provider;\n }\n\n try {\n return this.resolveProviderValue(currRegistration, currProvider);\n } catch (e) {\n // If we were trying to resolve a token registered via ExistingProvider,\n // we must add the cause of the error to the message\n if (isExistingProvider(registration.provider)) {\n throwExistingUnregisteredError(token, e as Error);\n }\n\n throw e;\n }\n }\n\n private instantiateClass<T extends object>(Class: Constructor<T>, optional?: boolean): T | undefined {\n const metadata = getMetadata(Class);\n\n if (metadata.autoRegister ?? this.myOptions.autoRegister) {\n // Temporarily set eagerInstantiate to false to avoid resolving the class two times:\n // one inside register(), and the other just below\n const eagerInstantiate = metadata.eagerInstantiate;\n metadata.eagerInstantiate = false;\n\n try {\n this.register(Class);\n return (this as Container).resolve(Class);\n } finally {\n metadata.eagerInstantiate = eagerInstantiate;\n }\n }\n\n const scope = this.resolveScope(metadata.scope);\n\n if (optional && scope === Scope.Container) {\n // It would not be possible to resolve the class in container scope,\n // as that would require prior registration.\n // However, since resolution is marked optional, we simply return undefined.\n return undefined;\n }\n\n assert(\n scope !== Scope.Container,\n `unregistered class ${Class.name} cannot be resolved in container scope`,\n );\n\n const registration: Registration<T> = {\n provider: metadata.provider,\n options: {\n scope: scope,\n },\n dependencies: metadata.dependencies,\n };\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n return this.resolveScopedValue(registration, (args) => new Class(...args));\n }\n\n private resolveProviderValue<T>(registration: Registration<T>, provider: Provider<T>): T {\n assert(registration.provider === provider, \"internal error: mismatching provider\");\n\n if (isClassProvider(provider)) {\n const Class = provider.useClass;\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n return this.resolveScopedValue(registration, (args) => new Class(...args));\n }\n\n if (isFactoryProvider(provider)) {\n const factory = provider.useFactory;\n return this.resolveScopedValue(registration, factory);\n }\n\n if (isValueProvider(provider)) {\n return provider.useValue;\n }\n\n if (isExistingProvider(provider)) {\n assert(false, \"internal error: unexpected ExistingProvider\");\n }\n\n expectNever(provider);\n }\n\n private resolveScopedValue<T>(registration: Registration<T>, factory: (...args: any[]) => T): T {\n let context = useInjectionContext();\n\n if (!context || context.container !== this) {\n context = {\n container: this,\n resolution: createResolution(),\n };\n }\n\n const resolution = context.resolution;\n const provider = registration.provider;\n const options = registration.options;\n\n if (resolution.stack.has(provider)) {\n const dependentRef = resolution.dependents.get(provider);\n assert(dependentRef, \"circular dependency detected\");\n return dependentRef.current;\n }\n\n const scope = this.resolveScope(options?.scope, context);\n const cleanups = [\n provideInjectionContext(context),\n !isBuilder(provider) && resolution.stack.push(provider, { provider, scope }),\n ];\n\n try {\n switch (scope) {\n case Scope.Container: {\n const valueRef = registration.value;\n\n if (valueRef) {\n return valueRef.current;\n }\n\n const args = this.resolveConstructorDependencies(registration);\n const value = this.injectDependencies(registration, factory(args));\n registration.value = { current: value };\n return value;\n }\n case Scope.Resolution: {\n const valueRef = resolution.values.get(provider);\n\n if (valueRef) {\n return valueRef.current;\n }\n\n const args = this.resolveConstructorDependencies(registration);\n const value = this.injectDependencies(registration, factory(args));\n resolution.values.set(provider, { current: value });\n return value;\n }\n case Scope.Transient: {\n const args = this.resolveConstructorDependencies(registration);\n return this.injectDependencies(registration, factory(args));\n }\n }\n } finally {\n cleanups.forEach((cleanup) => cleanup && cleanup());\n }\n }\n\n private resolveScope(\n scope = this.myOptions.defaultScope,\n context = useInjectionContext(),\n ): Exclude<Scope, typeof Scope.Inherited> {\n if (scope == Scope.Inherited) {\n const dependentFrame = context?.resolution.stack.peek();\n return dependentFrame?.scope || Scope.Transient;\n }\n\n return scope;\n }\n\n private resolveConstructorDependencies<T>(registration: Registration<T>): any[] {\n const dependencies = registration.dependencies;\n\n if (dependencies) {\n assert(isClassProvider(registration.provider), `internal error: not a ClassProvider`);\n const ctorDeps = dependencies.constructor;\n\n if (ctorDeps.length > 0) {\n // Let's check if all necessary constructor parameters are decorated.\n // If not, we cannot safely create an instance.\n const ctor = registration.provider.useClass;\n assert(ctor.length === ctorDeps.length, () => {\n const msg = `expected ${ctor.length} decorated constructor parameters in ${ctor.name}`;\n return msg + `, but found ${ctorDeps.length}`;\n });\n\n return ctorDeps\n .sort((a, b) => a.index - b.index)\n .map((dep) => {\n const token = dep.tokenRef.getRefToken();\n switch (dep.decorator) {\n case \"Inject\":\n return this.resolve(token);\n case \"InjectAll\":\n return this.resolveAll(token);\n case \"Optional\":\n return this.resolve(token, true);\n case \"OptionalAll\":\n return this.resolveAll(token, true);\n }\n });\n }\n }\n\n return [];\n }\n\n private injectDependencies<T>(registration: Registration<T>, instance: T): T {\n const dependencies = registration.dependencies;\n\n if (dependencies) {\n assert(isClassProvider(registration.provider), `internal error: not a ClassProvider`);\n const ctor = registration.provider.useClass;\n\n // Perform method injection\n for (const [key, methodDeps] of dependencies.methods) {\n // Let's check if all necessary method parameters are decorated.\n // If not, we cannot safely invoke the method.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const method = (instance as any)[key] as Function;\n assert(methodDeps.length === method.length, () => {\n const msg = `expected ${method.length} decorated method parameters`;\n return msg + ` in ${ctor.name}.${String(key)}, but found ${methodDeps.length}`;\n });\n\n const args = methodDeps\n .sort((a, b) => a.index - b.index)\n .map((dep) => {\n const token = dep.tokenRef.getRefToken();\n switch (dep.decorator) {\n case \"Inject\":\n return injectBy(instance, token);\n case \"InjectAll\":\n return injectAll(token);\n case \"Optional\":\n return optionalBy(instance, token);\n case \"OptionalAll\":\n return optionalAll(token);\n }\n });\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n method.bind(instance)(...args);\n }\n }\n\n return instance;\n }\n\n private checkDisposed(): void {\n assert(!this.myDisposed, \"the container is disposed\");\n }\n}\n","import { ContainerImpl } from \"./containerImpl\";\nimport type { ClassProvider, ExistingProvider, FactoryProvider, ValueProvider } from \"./provider\";\nimport { Scope } from \"./scope\";\nimport type { Constructor, Token, Tokens } from \"./token\";\nimport type { RegistrationOptions, TokenRegistry } from \"./tokenRegistry\";\n\n/**\n * Container creation options.\n */\nexport interface ContainerOptions {\n /**\n * Whether to automatically register an unregistered class when resolving it as a token.\n *\n * @defaultValue false\n */\n readonly autoRegister: boolean;\n\n /**\n * The default scope for registrations.\n *\n * @defaultValue Scope.Inherited\n */\n readonly defaultScope: Scope;\n}\n\n/**\n * Container API.\n */\nexport interface Container {\n /**\n * @internal\n */\n api?: Readonly<Container>;\n\n /**\n * @internal\n */\n readonly registry: TokenRegistry;\n\n /**\n * The options used to create this container.\n */\n readonly options: ContainerOptions;\n\n /**\n * The parent container, or `undefined` if this is the root container.\n */\n readonly parent: Container | undefined;\n\n /**\n * Whether this container is disposed.\n */\n readonly isDisposed: boolean;\n\n /**\n * Creates a new child container that inherits this container's options.\n *\n * You can pass specific options to override the inherited ones.\n */\n createChild(options?: Partial<ContainerOptions>): Container;\n\n /**\n * Clears and returns all distinct cached values from this container's internal registry.\n * Values from {@link ValueProvider} registrations are not included, as they are never cached.\n *\n * Note that only this container is affected. Parent containers, if any, remain unchanged.\n */\n clearCache(): unknown[];\n\n /**\n * Returns the cached value from the most recent registration of the token,\n * or `undefined` if no value has been cached yet (the token has not been resolved yet).\n *\n * If the token has at least one registration in this container,\n * the cached value is taken from the most recent of those registrations.\n * Otherwise, it may be retrieved from parent containers, if any.\n *\n * Values are never cached for tokens with _transient_ or _resolution_ scope,\n * or for {@link ValueProvider} registrations.\n */\n getCached<Value>(token: Token<Value>): Value | undefined;\n\n /**\n * Returns all cached values associated with registrations of the token,\n * in the order they were registered, or an empty array if none have been cached.\n *\n * If the token has at least one registration in the current container,\n * cached values are taken from those registrations.\n * Otherwise, cached values may be retrieved from parent containers, if any.\n *\n * Values are never cached for tokens with _transient_ or _resolution_ scope,\n * or for {@link ValueProvider} registrations.\n */\n getAllCached<Value>(token: Token<Value>): Value[];\n\n /**\n * Removes all registrations from this container's internal registry.\n *\n * Returns an array of distinct cached values that were stored within the removed registrations.\n * Values from {@link ValueProvider} registrations are not included, as they are not cached.\n *\n * Note that only this container is affected. Parent containers, if any, remain unchanged.\n */\n resetRegistry(): unknown[];\n\n /**\n * Returns whether the token is registered in this container or in parent containers, if any.\n */\n isRegistered(token: Token): boolean;\n\n /**\n * Registers a concrete class, where the class acts as its own token.\n *\n * Tokens provided via the {@link Injectable} decorator applied to the class\n * are also registered as aliases.\n *\n * The default registration scope is determined by the {@link Scoped} decorator,\n * if present.\n */\n registerClass<Instance extends object>(Class: Constructor<Instance>): void;\n\n /**\n * Registers a concrete class with a token.\n *\n * The default registration scope is determined by the {@link Scoped} decorator\n * applied to the class, if present, but it can be overridden by passing explicit\n * registration options.\n */\n registerClass<Instance extends object, ProvidedInstance extends Instance>(\n token: Token<Instance>,\n Class: Constructor<ProvidedInstance>,\n options?: RegistrationOptions,\n ): void;\n\n /**\n * Registers a token whose value is produced by a factory function.\n *\n * The factory function runs inside the injection context and can\n * thus access dependencies via {@link inject}-like functions.\n */\n registerFactory<Value, ProvidedValue extends Value>(\n token: Token<Value>,\n factory: (...args: []) => ProvidedValue,\n options?: RegistrationOptions,\n ): void;\n\n /**\n * Registers a token with a fixed value.\n *\n * The provided value is returned as-is when the token is resolved (scopes do not apply).\n */\n registerValue<Value, ProvidedValue extends Value>(token: Token<Value>, value: ProvidedValue): void;\n\n /**\n * Registers one or more tokens as aliases for a target token.\n *\n * When an alias is resolved, the target token is resolved instead.\n */\n registerAlias<Value, ProvidedValue extends Value>(\n targetToken: Token<ProvidedValue>,\n aliasTokens: Tokens<Value>,\n ): void;\n\n /**\n * Registers a {@link ClassProvider}, using the class itself as its token.\n *\n * Tokens provided via the {@link Injectable} decorator applied to the class\n * are also registered as aliases.\n *\n * The scope is determined by the {@link Scoped} decorator, if present.\n *\n * @see registerClass\n */\n register<Instance extends object>(Class: Constructor<Instance>): Container;\n\n /**\n * Registers a {@link ClassProvider} with a token.\n *\n * The default registration scope is determined by the {@link Scoped} decorator\n * applied to the provided class, if present, but it can be overridden by\n * passing explicit registration options.\n *\n * @see registerClass\n */\n register<Instance extends object, ProviderInstance extends Instance>(\n token: Token<Instance>,\n provider: ClassProvider<ProviderInstance>,\n options?: RegistrationOptions,\n ): Container;\n\n /**\n * Registers a {@link FactoryProvider} with a token.\n *\n * @see registerFactory\n */\n register<Value, ProviderValue extends Value>(\n token: Token<Value>,\n provider: FactoryProvider<ProviderValue>,\n options?: RegistrationOptions,\n ): Container;\n\n /**\n * Registers an {@link ExistingProvider} with a token.\n *\n * The token will alias the one set in `useExisting`.\n *\n * @see registerAlias\n */\n register<Value, ProviderValue extends Value>(\n token: Token<Value>,\n provider: ExistingProvider<ProviderValue>,\n ): Container;\n\n /**\n * Registers a {@link ValueProvider} with a token.\n *\n * Values provided via `useValue` are never cached (scopes do not apply)\n * and are simply returned as-is.\n *\n * @see registerValue\n */\n register<Value, ProviderValue extends Value>(\n token: Token<Value>,\n provider: ValueProvider<ProviderValue>,\n ): Container;\n\n /**\n * Removes all registrations for the given token from the container's internal registry.\n *\n * Returns an array of distinct cached values that were stored within the removed registrations.\n * Values from {@link ValueProvider} registrations are not included, as they are not cached.\n *\n * Note that only this container is affected. Parent containers, if any, remain unchanged.\n */\n unregister<Value>(token: Token<Value>): Value[];\n\n /**\n * Resolves the given class to the instance associated with it.\n *\n * If the class is registered in this container or any of its parent containers,\n * an instance is created using the most recent registration.\n *\n * If the class is not registered, but it is decorated with {@link AutoRegister},\n * or {@link ContainerOptions.autoRegister} is true, the class is registered automatically.\n * Otherwise, resolution fails.\n * The scope for the automatic registration is determined by either\n * the {@link Scoped} decorator on the class, or {@link ContainerOptions.defaultScope}.\n *\n * If `optional` is false or is not passed and the class is not registered in the container\n * (and could not be auto-registered), an error is thrown.\n * Otherwise, if `optional` is true, `undefined` is returned.\n *\n * The resolution behavior depends on the {@link Provider} used during registration:\n * - For {@link ValueProvider}, the explicitly provided instance is returned.\n * - For {@link FactoryProvider}, the factory function is invoked to create the instance.\n * - For {@link ClassProvider}, a new instance of the class is created according to its scope.\n * - For {@link ExistingProvider}, the instance is resolved by referring to another registered token.\n *\n * If the class is registered with _container_ scope, the resolved instance is cached\n * in the container's internal registry.\n */\n resolve<Instance extends object>(Class: Constructor<Instance>, optional?: false): Instance;\n resolve<Instance extends object>(Class: Constructor<Instance>, optional: true): Instance | undefined;\n resolve<Instance extends object>(Class: Constructor<Instance>, optional?: boolean): Instance | undefined;\n\n /**\n * Resolves the given token to the value associated with it.\n *\n * If the token is registered in this container or any of its parent containers,\n * its value is resolved using the most recent registration.\n *\n * If `optional` is false or not passed and the token is not registered in the container,\n * an error is thrown. Otherwise, if `optional` is true, `undefined` is returned.\n *\n * The resolution behavior depends on the {@link Provider} used during registration:\n * - For {@link ValueProvider}, the explicitly provided value is returned.\n * - For {@link FactoryProvider}, the factory function is invoked to create the value.\n * - For {@link ClassProvider}, a new instance of the class is created according to its scope.\n * - For {@link ExistingProvider}, the value is resolved by referring to another registered token.\n *\n * If the token is registered with _container_ scope, the resolved value is cached\n * in the container's internal registry.\n */\n resolve<Value>(token: Token<Value>, optional?: false): Value;\n resolve<Value>(token: Token<Value>, optional: true): Value | undefined;\n resolve<Value>(token: Token<Value>, optional?: boolean): Value | undefined;\n\n /**\n * Resolves the given class to all instances provided by the registrations associated with it.\n *\n * If the class is not registered, but it is decorated with {@link AutoRegister},\n * or {@link ContainerOptions.autoRegister} is true, the class is registered automatically.\n * Otherwise, resolution fails.\n * The scope for the automatic registration is determined by either\n * the {@link Scoped} decorator on the class, or {@link ContainerOptions.defaultScope}.\n *\n * If `optional` is false or is not passed and the class is not registered in the container\n * (and could not be auto-registered), an error is thrown.\n * Otherwise, if `optional` is true, an empty array is returned.\n *\n * The resolution behavior depends on the {@link Provider} used during registration:\n * - For {@link ValueProvider}, the explicitly provided instance is returned.\n * - For {@link FactoryProvider}, the factory function is invoked to create the instance.\n * - For {@link ClassProvider}, a new instance of the class is created according to its scope.\n * - For {@link ExistingProvider}, the instance is resolved by referring to another registered token.\n *\n * If the class is registered with _container_ scope, the resolved instances are cached\n * in the container's internal registry.\n *\n * A separate instance of the class is created for each provider.\n *\n * @see The documentation for `resolve(Class: Constructor)`\n */\n resolveAll<Instance extends object>(Class: Constructor<Instance>, optional?: false): Instance[];\n resolveAll<Instance extends object>(Class: Constructor<Instance>, optional: true): Instance[];\n resolveAll<Instance extends object>(Class: Constructor<Instance>, optional?: boolean): Instance[];\n\n /**\n * Resolves the given token to all values provided by the registrations associated with it.\n *\n * If `optional` is false or not passed and the token is not registered in the container,\n * an error is thrown. Otherwise, if `optional` is true, an empty array is returned.\n *\n * The resolution behavior depends on the {@link Provider} used during registration:\n * - For {@link ValueProvider}, the explicitly provided value is returned.\n * - For {@link FactoryProvider}, the factory function is invoked to create the value.\n * - For {@link ClassProvider}, a new instance of the class is created according to its scope.\n * - For {@link ExistingProvider}, the value is resolved by referring to another registered token.\n *\n * If the token is registered with _container_ scope, the resolved values are cached\n * in the container's internal registry.\n *\n * @see The documentation for `resolve(token: Token)`\n */\n resolveAll<Value>(token: Token<Value>, optional?: false): NonNullable<Value>[];\n resolveAll<Value>(token: Token<Value>, optional: true): NonNullable<Value>[];\n resolveAll<Value>(token: Token<Value>, optional?: boolean): NonNullable<Value>[];\n\n /**\n * Disposes this container and all its cached values.\n *\n * Token values implementing a `Disposable` interface (e.g., objects with a `dispose()` function)\n * are automatically disposed during this process.\n *\n * Note that children containers are disposed first, in creation order.\n */\n dispose(): void;\n}\n\n/**\n * Creates a new container.\n */\nexport function createContainer(\n options: Partial<ContainerOptions> = {\n autoRegister: false,\n defaultScope: Scope.Inherited,\n },\n): Container {\n return new ContainerImpl(undefined, options);\n}\n","import { getMetadata } from \"../metadata\";\nimport type { Constructor } from \"../token\";\n\n/**\n * Class decorator that enables auto-registration of an unregistered class,\n * when the class is first resolved from the container.\n *\n * @example\n * ```ts\n * @AutoRegister\n * class Wizard {}\n *\n * const wizard = container.resolve(Wizard);\n * container.isRegistered(Wizard); // => true\n * ```\n *\n * @__NO_SIDE_EFFECTS__\n */\nexport function AutoRegister<Ctor extends Constructor<any>>(Class: Ctor): void {\n const metadata = getMetadata(Class);\n metadata.autoRegister = true;\n}\n","import { getMetadata } from \"../metadata\";\nimport type { Constructor } from \"../token\";\n\n/**\n * Class decorator that enables eager instantiation of a class when it is registered\n * in the container with `Scope.Container`.\n *\n * This causes the container to immediately create and cache the instance of the class,\n * instead of deferring instantiation until the first resolution.\n *\n * @example\n * ```ts\n * @EagerInstantiate\n * @Scoped(Scope.Container)\n * class Wizard {}\n *\n * // A Wizard instance is immediately created and cached by the container\n * const wizard = container.register(Wizard);\n * ```\n *\n * @__NO_SIDE_EFFECTS__\n */\nexport function EagerInstantiate<Ctor extends Constructor<any>>(Class: Ctor): void {\n const metadata = getMetadata(Class);\n metadata.eagerInstantiate = true;\n}\n","import { assert } from \"./errors\";\nimport type { Token, Tokens } from \"./token\";\n\nexport interface TokensRef<Value = any> {\n readonly getRefTokens: () => Set<Token<Value>>;\n}\n\nexport interface TokenRef<Value = any> {\n readonly getRefToken: () => Token<Value>;\n}\n\n/**\n * Allows referencing tokens that are declared later in the file by wrapping them\n * in a lazily evaluated function.\n */\nexport function forwardRef<Value>(token: () => Tokens<Value>): TokensRef<Value>;\n\n/**\n * Allows referencing a token that is declared later in the file by wrapping it\n * in a lazily evaluated function.\n */\nexport function forwardRef<Value>(token: () => Token<Value>): TokenRef<Value>;\n\nexport function forwardRef<Value>(\n token: () => Token<Value> | Tokens<Value>,\n): TokensRef<Value> & TokenRef<Value> {\n return {\n getRefTokens: (): Set<Token<Value>> => {\n // Normalize the single token here, so that we don't have\n // to do it at every getRefTokens call site\n const tokenOrTokens = token();\n const tokensArray = Array.isArray(tokenOrTokens) ? tokenOrTokens : [tokenOrTokens];\n return new Set(tokensArray);\n },\n getRefToken: () => {\n const tokenOrTokens = token();\n assert(!Array.isArray(tokenOrTokens), \"internal error: ref tokens should be a single token\");\n return tokenOrTokens;\n },\n };\n}\n\n// @internal\nexport function isTokensRef(value: any): value is TokensRef {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return value && typeof value === \"object\" && typeof value.getRefTokens === \"function\";\n}\n\n// @internal\nexport function isTokenRef(value: any): value is TokenRef {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return value && typeof value === \"object\" && typeof value.getRefToken === \"function\";\n}\n","import { assert } from \"../errors\";\nimport { getMetadata } from \"../metadata\";\nimport type { Constructor, Token } from \"../token\";\nimport type { Decorator } from \"../tokenRegistry\";\nimport { forwardRef, isTokenRef, type TokenRef } from \"../tokensRef\";\n\nexport function processDecoratedParameter(\n decorator: Decorator,\n token: Token | TokenRef,\n target: object,\n propertyKey: string | symbol | undefined,\n parameterIndex: number,\n): void {\n // Error out immediately if the decorator has been applied\n // to a static property or a static method\n if (propertyKey !== undefined && typeof target === \"function\") {\n assert(false, `@${decorator} cannot be used on static member ${target.name}.${String(propertyKey)}`);\n }\n\n const tokenRef = isTokenRef(token) ? token : forwardRef(() => token);\n\n if (propertyKey === undefined) {\n // Constructor\n const metadata = getMetadata(target as Constructor<any>);\n metadata.dependencies.constructor.push({\n decorator: decorator,\n tokenRef: tokenRef,\n index: parameterIndex,\n });\n } else {\n // Normal instance method\n const metadata = getMetadata(target.constructor as Constructor<any>);\n const methods = metadata.dependencies.methods;\n let dep = methods.get(propertyKey);\n\n if (dep === undefined) {\n dep = [];\n methods.set(propertyKey, dep);\n }\n\n dep.push({\n decorator: decorator,\n tokenRef: tokenRef,\n index: parameterIndex,\n });\n }\n}\n","import type { Constructor, Token } from \"../token\";\nimport type { TokenRef } from \"../tokensRef\";\nimport { processDecoratedParameter } from \"./decorators\";\n\n/**\n * Parameter decorator that injects the instance associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\nexport function Inject<Instance extends object>(Class: Constructor<Instance>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects the value associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\nexport function Inject<Value>(token: Token<Value>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects the value associated with the given token.\n *\n * Allows referencing a token that is declared later in the file by using\n * the {@link forwardRef} helper function.\n *\n * Throws an error if the token is not registered in the container.\n *\n * @example\n * ```ts\n * class Wizard {\n * constructor(@Inject(forwardRef(() => Wand)) readonly wand: Wand) {}\n * }\n * // Other code...\n * class Wand {}\n * ```\n */\nexport function Inject<Value>(tokens: TokenRef<Value>): ParameterDecorator;\n\nexport function Inject<T>(token: Token<T> | TokenRef<T>): ParameterDecorator {\n return function (target, propertyKey, parameterIndex: number): void {\n processDecoratedParameter(\"Inject\", token, target, propertyKey, parameterIndex);\n };\n}\n","import { getMetadata } from \"../metadata\";\nimport type { Constructor, Tokens } from \"../token\";\nimport { forwardRef, isTokensRef, type TokenRef, type TokensRef } from \"../tokensRef\";\n\n/**\n * Class decorator that registers additional aliasing tokens for the decorated type,\n * when the type is first registered in the container.\n *\n * The container uses {@link ExistingProvider} under the hood.\n *\n * @example\n * ```ts\n * @Injectable(Weapon)\n * class Wand {}\n * ```\n */\nexport function Injectable<This extends object, Value extends This>(...tokens: Tokens<Value>): ClassDecorator;\n\n/**\n * Class decorator that registers additional aliasing tokens for the decorated type,\n * when the type is first registered in the container.\n *\n * The container uses {@link ExistingProvider} under the hood.\n *\n * Allows referencing tokens that are declared later in the file by using\n * the {@link forwardRef} helper function.\n *\n * @example\n * ```ts\n * @Injectable(forwardRef() => Weapon) // Weapon is declared after Wand\n * class Wizard {}\n * // Other code...\n * class Weapon {}\n * ```\n */\nexport function Injectable<This extends object, Value extends This>(\n tokens: TokenRef<Value> | TokensRef<Value>,\n): ClassDecorator;\n\n/**\n * @__NO_SIDE_EFFECTS__\n */\nexport function Injectable(...args: unknown[]): ClassDecorator {\n return function (Class): void {\n const metadata = getMetadata(Class as any as Constructor<any>);\n const arg0 = args[0];\n const tokensRef = isTokensRef(arg0) ? arg0 : forwardRef(() => args as Tokens);\n const existingTokensRef = metadata.tokensRef;\n metadata.tokensRef = {\n getRefTokens: () => {\n const existingTokens = existingTokensRef.getRefTokens();\n\n for (const token of tokensRef.getRefTokens()) {\n existingTokens.add(token);\n }\n\n return existingTokens;\n },\n };\n };\n}\n","import type { Constructor, Token } from \"../token\";\nimport type { TokenRef } from \"../tokensRef\";\nimport { processDecoratedParameter } from \"./decorators\";\n\n/**\n * Parameter decorator that injects all instances provided by the registrations\n * associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\nexport function InjectAll<Instance extends object>(Class: Constructor<Instance>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects all values provided by the registrations\n * associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\nexport function InjectAll<Value>(token: Token<Value>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects all values provided by the registrations\n * associated with the given token.\n *\n * Allows referencing a token that is declared later in the file by using\n * the {@link forwardRef} helper function.\n *\n * Throws an error if the token is not registered in the container.\n *\n * @example\n * ```ts\n * class Wizard {\n * constructor(@InjectAll(forwardRef(() => Wand)) readonly wands: Wand[]) {}\n * }\n * // Other code...\n * class Wand {}\n * ```\n */\nexport function InjectAll<Value>(tokens: TokenRef<Value>): ParameterDecorator;\n\nexport function InjectAll<T>(token: Token<T> | TokenRef<T>): ParameterDecorator {\n return function (target, propertyKey, parameterIndex: number): void {\n processDecoratedParameter(\"InjectAll\", token, target, propertyKey, parameterIndex);\n };\n}\n","import type { Constructor, Token } from \"../token\";\nimport type { TokenRef } from \"../tokensRef\";\nimport { processDecoratedParameter } from \"./decorators\";\n\n/**\n * Parameter decorator that injects the instance associated with the given class,\n * or `undefined` if the class is not registered in the container.\n */\nexport function Optional<Instance extends object>(Class: Constructor<Instance>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects the value associated with the given token,\n * or `undefined` if the token is not registered in the container.\n */\nexport function Optional<Value>(token: Token<Value>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects the value associated with the given token,\n * or `undefined` if the token is not registered in the container.\n *\n * Allows referencing a token that is declared later in the file by using\n * the {@link forwardRef} helper function.\n *\n * @example\n * ```ts\n * class Wizard {\n * constructor(@Optional(forwardRef(() => Wand)) readonly wand: Wand | undefined) {}\n * }\n * // Other code...\n * class Wand {}\n * ```\n */\nexport function Optional<Value>(tokens: TokenRef<Value>): ParameterDecorator;\n\nexport function Optional<T>(token: Token<T> | TokenRef<T>): ParameterDecorator {\n return function (target, propertyKey, parameterIndex: number): void {\n processDecoratedParameter(\"Optional\", token, target, propertyKey, parameterIndex);\n };\n}\n","import type { Constructor, Token } from \"../token\";\nimport type { TokenRef } from \"../tokensRef\";\nimport { processDecoratedParameter } from \"./decorators\";\n\n/**\n * Parameter decorator that injects all instances provided by the registrations\n * associated with the given class, or an empty array if the class is not registered\n * in the container.\n */\nexport function OptionalAll<Instance extends object>(Class: Constructor<Instance>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects all values provided by the registrations\n * associated with the given token, or an empty array if the token is not registered\n * in the container.\n */\nexport function OptionalAll<Value>(token: Token<Value>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects all values provided by the registrations\n * associated with the given token, or an empty array if the token is not registered\n * in the container.\n *\n * Allows referencing a token that is declared later in the file by using\n * the {@link forwardRef} helper function.\n *\n * @example\n * ```ts\n * class Wizard {\n * constructor(@OptionalAll(forwardRef(() => Wand)) readonly wands: Wand[]) {}\n * }\n * // Other code...\n * class Wand {}\n * ```\n */\nexport function OptionalAll<Value>(tokens: TokenRef<Value>): ParameterDecorator;\n\nexport function OptionalAll<T>(token: Token<T> | TokenRef<T>): ParameterDecorator {\n return function (target, propertyKey, parameterIndex: number): void {\n processDecoratedParameter(\"OptionalAll\", token, target, propertyKey, parameterIndex);\n };\n}\n","import { getMetadata } from \"../metadata\";\nimport type { Scope } from \"../scope\";\nimport type { Constructor } from \"../token\";\n\n/**\n * Class decorator for setting the scope of the decorated type when registering it.\n *\n * The scope set by this decorator can be overridden by explicit registration options, if provided.\n *\n * @example\n * ```ts\n * @Scoped(Scope.Container)\n * class Wizard {}\n *\n * container.register(Wizard);\n *\n * // Under the hood\n * container.register(\n * Wizard,\n * { useClass: Wizard },\n * { scope: Scope.Container },\n * );\n * ```\n *\n * @__NO_SIDE_EFFECTS__\n */\nexport function Scoped(scope: Scope): ClassDecorator {\n return function (Class): void {\n const metadata = getMetadata(Class as any as Constructor<any>);\n metadata.scope = scope;\n };\n}\n","import { inject } from \"./inject\";\nimport { injectAll } from \"./injectAll\";\nimport { ensureInjectionContext, provideInjectionContext, useInjectionContext } from \"./injectionContext\";\nimport { optional } from \"./optional\";\nimport { optionalAll } from \"./optionalAll\";\nimport type { Constructor, Token, Type } from \"./token\";\nimport { build } from \"./tokenRegistry\";\n\n/**\n * Injector API.\n */\nexport interface Injector {\n /**\n * Injects the instance associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\n inject<Instance extends object>(Class: Constructor<Instance>): Instance;\n\n /**\n * Injects the value associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\n inject<Value>(token: Token<Value>): Value;\n\n /**\n * Injects all instances provided by the registrations associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\n injectAll<Instance extends object>(Class: Constructor<Instance>): Instance[];\n\n /**\n * Injects all values provided by the registrations associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\n injectAll<Value>(token: Token<Value>): NonNullable<Value>[];\n\n /**\n * Injects the instance associated with the given class,\n * or `undefined` if the class is not registered in the container.\n */\n optional<Instance extends object>(Class: Constructor<Instance>): Instance | undefined;\n\n /**\n * Injects the value associated with the given token,\n * or `undefined` if the token is not registered in the container.\n */\n optional<Value>(token: Token<Value>): Value | undefined;\n\n /**\n * Injects all instances provided by the registrations associated with the given class,\n * or an empty array if the class is not registered in the container.\n */\n optionalAll<Instance extends object>(Class: Constructor<Instance>): Instance[];\n\n /**\n * Injects all values provided by the registrations associated with the given token,\n * or an empty array if the token is not registered in the container.\n */\n optionalAll<Value>(token: Token<Value>): NonNullable<Value>[];\n}\n\n/**\n * Injector token for dynamic injections.\n *\n * @example\n * ```ts\n * class Wizard {\n * private injector = inject(Injector);\n * private wand?: Wand;\n *\n * getWand(): Wand {\n * return (this.wand ??= this.injector.inject(Wand));\n * }\n * }\n *\n * const wizard = container.resolve(Wizard);\n * wizard.getWand(); // => Wand\n * ```\n */\nexport const Injector: Type<Injector> = /*@__PURE__*/ build(function Injector() {\n const context = ensureInjectionContext(Injector);\n const resolution = context.resolution;\n\n const dependentFrame = resolution.stack.peek();\n const dependentRef = dependentFrame && resolution.dependents.get(dependentFrame.provider);\n\n function withCurrentContext<R>(fn: () => R): R {\n if (useInjectionContext()) {\n return fn();\n }\n\n const cleanups = [\n provideInjectionContext(context),\n dependentFrame && resolution.stack.push(dependentFrame.provider, dependentFrame),\n dependentRef && resolution.dependents.set(dependentFrame.provider, dependentRef),\n ];\n\n try {\n return fn();\n } finally {\n for (const cleanup of cleanups) {\n cleanup?.();\n }\n }\n }\n\n return {\n inject: <T>(token: Token<T>) => withCurrentContext(() => inject(token)),\n injectAll: <T>(token: Token<T>) => withCurrentContext(() => injectAll(token)),\n optional: <T>(token: Token<T>) => withCurrentContext(() => optional(token)),\n optionalAll: <T>(token: Token<T>) => withCurrentContext(() => optionalAll(token)),\n };\n});\n","import type { Container } from \"./container\";\n\n/**\n * Composer API for middleware functions.\n */\nexport interface MiddlewareComposer {\n /**\n * Adds a middleware function to the composer.\n */\n use<MethodKey extends keyof Container>(\n key: MethodKey,\n wrap: Container[MethodKey] extends Function\n ? (next: Container[MethodKey]) => Container[MethodKey]\n : never,\n ): MiddlewareComposer;\n}\n\n/**\n * Middleware function that can be used to extend the container.\n *\n * @example\n * ```ts\n * const logger: Middleware = (composer, _api) => {\n * composer\n * .use(\"resolve\", (next) => (...args) => {\n * console.log(\"resolve\", args);\n * return next(...args);\n * })\n * .use(\"resolveAll\", (next) => (...args) => {\n * console.log(\"resolveAll\", args);\n * return next(...args);\n * });\n * };\n * ```\n */\nexport interface Middleware {\n (composer: MiddlewareComposer, api: Readonly<Container>): void;\n}\n\n/**\n * Applies middleware functions to a container.\n *\n * Middlewares are applied in array order, but execute in reverse order.\n *\n * @example\n * ```ts\n * const container = applyMiddleware(\n * createContainer(),\n * [A, B],\n * );\n * ```\n *\n * The execution order will be:\n *\n * 1. B before\n * 2. A before\n * 3. original function\n * 4. A after\n * 5. B after\n *\n * This allows outer middlewares to wrap and control the behavior of inner middlewares.\n */\nexport function applyMiddleware(container: Container, middlewares: Middleware[]): Container {\n const composer: MiddlewareComposer = {\n use(key, wrap): MiddlewareComposer {\n // We need to bind the 'this' context of the function to the container\n // before passing it to the middleware wrapper.\n //\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call\n const fn = (container[key] as any).bind(container);\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n container[key] = wrap(fn);\n return composer;\n },\n };\n\n const api = (container.api ||= { ...container });\n\n for (const middleware of middlewares) {\n middleware(composer, api);\n }\n\n return container;\n}\n"],"names":["assert","condition","message","resolvedMessage","Error","tag","expectNever","value","TypeError","String","throwUnregisteredError","token","name","throwExistingUnregisteredError","sourceToken","targetTokenOrError","isError","untag","stack","startsWith","substring","trimStart","createInjectionContext","current","provide","next","prev","use","invariant","KeyedStack","has","key","myKeys","peek","entry","myEntries","at","push","add","pop","delete","Array","WeakSet","WeakRefMap","get","ref","myMap","deref","set","WeakRef","WeakMap","createResolution","values","dependents","provideInjectionContext","useInjectionContext","ensureInjectionContext","fn","context","inject","container","resolve","injectBy","thisArg","resolution","currentFrame","currentRef","cleanup","provider","injectAll","resolveAll","getMetadata","Class","metadata","metadataMap","tokensRef","getRefTokens","Set","useClass","dependencies","methods","Map","optional","optionalBy","optionalAll","isClassProvider","isFactoryProvider","isValueProvider","isExistingProvider","Scope","Inherited","Transient","Resolution","Container","createType","typeName","type","inter","union","toString","isConstructor","getTypeName","proto","Object","getPrototypeOf","prototype","constructor","TokenRegistry","parent","myParent","getAll","internal","internals","getAllFromParent","registration","registrations","deleteAll","tokens","from","keys","flat","clear","clearRegistrations","i","length","undefined","isBuilder","builders","build","factory","useFactory","options","scope","isDisposable","dispose","ContainerImpl","myChildren","myDisposed","myOptions","autoRegister","defaultScope","myTokenRegistry","registry","isDisposed","createChild","checkDisposed","clearCache","getCached","getAllCached","resetRegistry","isRegistered","registerClass","ctor","register","registerFactory","registerValue","useValue","registerAlias","targetToken","aliasTokens","alias","useExisting","args","eagerInstantiate","unregister","resolveRegistration","instantiateClass","map","filter","instance","child","disposedRefs","currRegistration","currProvider","resolveProviderValue","e","resolveScope","resolveScopedValue","dependentRef","cleanups","valueRef","resolveConstructorDependencies","injectDependencies","forEach","dependentFrame","ctorDeps","msg","sort","a","b","index","dep","tokenRef","getRefToken","decorator","methodDeps","method","bind","createContainer","AutoRegister","EagerInstantiate","forwardRef","tokenOrTokens","tokensArray","isArray","isTokensRef","isTokenRef","processDecoratedParameter","target","propertyKey","parameterIndex","Inject","Injectable","arg0","existingTokensRef","existingTokens","InjectAll","Optional","OptionalAll","Scoped","Injector","withCurrentContext","applyMiddleware","middlewares","composer","wrap","api","middleware"],"mappings":";;AAEA;AACO,SAASA,MAAAA,CAAOC,SAAkB,EAAEC,OAAgC,EAAA;AACzE,IAAA,IAAI,CAACD,SAAAA,EAAW;AACd,QAAA,MAAME,eAAAA,GAAkB,OAAOD,OAAAA,KAAY,QAAA,GAAWA,OAAAA,GAAUA,OAAAA,EAAAA;QAChE,MAAM,IAAIE,MAAMC,GAAAA,CAAI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AMuK,cAAcJ,WAAAA,CAAa;AACpCI,QAAAA,UAAAA,CAAWH,QAAAA,EAAUE,GAAAA,CAAAA;AACvB;IAEA,OAAOtK,SAAAA;AACT;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/es/index.mjs
CHANGED
@@ -639,8 +639,16 @@ function isDisposable(value) {
|
|
639
639
|
instantiateClass(Class, optional) {
|
640
640
|
const metadata = getMetadata(Class);
|
641
641
|
if (metadata.autoRegister ?? this.myOptions.autoRegister) {
|
642
|
-
|
643
|
-
|
642
|
+
// Temporarily set eagerInstantiate to false to avoid resolving the class two times:
|
643
|
+
// one inside register(), and the other just below
|
644
|
+
const eagerInstantiate = metadata.eagerInstantiate;
|
645
|
+
metadata.eagerInstantiate = false;
|
646
|
+
try {
|
647
|
+
this.register(Class);
|
648
|
+
return this.resolve(Class);
|
649
|
+
} finally{
|
650
|
+
metadata.eagerInstantiate = eagerInstantiate;
|
651
|
+
}
|
644
652
|
}
|
645
653
|
const scope = this.resolveScope(metadata.scope);
|
646
654
|
if (optional && scope === Scope.Container) {
|
package/dist/es/index.mjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../src/errors.ts","../../src/utils/context.ts","../../src/utils/invariant.ts","../../src/utils/keyedStack.ts","../../src/utils/weakRefMap.ts","../../src/injectionContext.ts","../../src/inject.ts","../../src/injectAll.ts","../../src/metadata.ts","../../src/optional.ts","../../src/optionalAll.ts","../../src/provider.ts","../../src/scope.ts","../../src/token.ts","../../src/utils/typeName.ts","../../src/tokenRegistry.ts","../../src/utils/disposable.ts","../../src/containerImpl.ts","../../src/container.ts","../../src/decorators/autoRegister.ts","../../src/decorators/eagerInstantiate.ts","../../src/tokensRef.ts","../../src/decorators/decorators.ts","../../src/decorators/inject.ts","../../src/decorators/injectable.ts","../../src/decorators/injectAll.ts","../../src/decorators/optional.ts","../../src/decorators/optionalAll.ts","../../src/decorators/scoped.ts","../../src/injector.ts","../../src/middleware.ts"],"sourcesContent":["import type { Token } from \"./token\";\n\n// @internal\nexport function assert(condition: unknown, message: string | (() => string)): asserts condition {\n if (!condition) {\n const resolvedMessage = typeof message === \"string\" ? message : message();\n throw new Error(tag(resolvedMessage));\n }\n}\n\n// @internal\nexport function expectNever(value: never): never {\n throw new TypeError(tag(`unexpected value ${String(value)}`));\n}\n\n// @internal\nexport function throwUnregisteredError(token: Token): never {\n throw new Error(tag(`unregistered token ${token.name}`));\n}\n\n// @internal\nexport function throwExistingUnregisteredError(sourceToken: Token, targetTokenOrError: Token | Error): never {\n let message = tag(`token resolution error encountered while resolving ${sourceToken.name}`);\n\n if (isError(targetTokenOrError)) {\n message += `\\n [cause] ${untag(targetTokenOrError.message)}`;\n } else {\n message += `\\n [cause] the aliased token ${targetTokenOrError.name} is not registered`;\n }\n\n throw new Error(message);\n}\n\nfunction isError(value: any): value is Error {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return value && value.stack && value.message && typeof value.message === \"string\";\n}\n\nfunction tag(message: string): string {\n return `[di-wise-neo] ${message}`;\n}\n\nfunction untag(message: string): string {\n return message.startsWith(\"[di-wise-neo]\") //\n ? message.substring(13).trimStart()\n : message;\n}\n","// @internal\nexport function createInjectionContext<T extends {}>(): readonly [\n (next: T) => () => T | null,\n () => T | null,\n] {\n let current: T | null = null;\n\n function provide(next: T): () => T | null {\n const prev = current;\n current = next;\n return () => (current = prev);\n }\n\n function use(): T | null {\n return current;\n }\n\n return [provide, use] as const;\n}\n","// @internal\nexport function invariant(condition: unknown): asserts condition {\n if (!condition) {\n throw new Error(\"invariant violation\");\n }\n}\n","import { invariant } from \"./invariant\";\n\n// @internal\nexport class KeyedStack<K extends object, V> {\n private readonly myEntries = new Array<{ key: K; value: V }>();\n private readonly myKeys = new WeakSet<K>();\n\n has(key: K): boolean {\n return this.myKeys.has(key);\n }\n\n peek(): V | undefined {\n const entry = this.myEntries.at(-1);\n return entry?.value;\n }\n\n push(key: K, value: V): () => void {\n invariant(!this.has(key));\n this.myKeys.add(key);\n this.myEntries.push({ key, value });\n return () => {\n this.myEntries.pop();\n this.myKeys.delete(key);\n };\n }\n}\n","import { invariant } from \"./invariant\";\n\n// @internal\nexport class WeakRefMap<K extends WeakKey, V extends object> {\n private readonly myMap = new WeakMap<K, WeakRef<V>>();\n\n get(key: K): V | undefined {\n const ref = this.myMap.get(key);\n\n if (ref) {\n const value = ref.deref();\n\n if (value) {\n return value;\n }\n\n this.myMap.delete(key);\n }\n }\n\n set(key: K, value: V): () => void {\n invariant(!this.get(key));\n this.myMap.set(key, new WeakRef(value));\n return () => {\n this.myMap.delete(key);\n };\n }\n}\n","import type { Container } from \"./container\";\nimport { assert } from \"./errors\";\nimport type { Provider } from \"./provider\";\nimport type { Scope } from \"./scope\";\nimport { createInjectionContext } from \"./utils/context\";\nimport { KeyedStack } from \"./utils/keyedStack\";\nimport { WeakRefMap } from \"./utils/weakRefMap\";\nimport type { ValueRef } from \"./valueRef\";\n\n// @internal\nexport interface ResolutionFrame {\n readonly scope: Exclude<Scope, typeof Scope.Inherited>;\n readonly provider: Provider;\n}\n\n// @internal\nexport interface Resolution {\n readonly stack: KeyedStack<Provider, ResolutionFrame>;\n readonly values: WeakRefMap<Provider, ValueRef>;\n readonly dependents: WeakRefMap<Provider, ValueRef>;\n}\n\n// @internal\nexport interface InjectionContext {\n readonly container: Container;\n readonly resolution: Resolution;\n}\n\n// @internal\nexport function createResolution(): Resolution {\n return {\n stack: new KeyedStack(),\n values: new WeakRefMap(),\n dependents: new WeakRefMap(),\n };\n}\n\n// @internal\nexport const [provideInjectionContext, useInjectionContext] = createInjectionContext<InjectionContext>();\n\n// @internal\nexport function ensureInjectionContext(fn: Function): InjectionContext {\n const context = useInjectionContext();\n assert(context, `${fn.name}() can only be invoked within an injection context`);\n return context;\n}\n","import { ensureInjectionContext } from \"./injectionContext\";\nimport type { Constructor, Token } from \"./token\";\n\n/**\n * Injects the instance associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\nexport function inject<Instance extends object>(Class: Constructor<Instance>): Instance;\n\n/**\n * Injects the value associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\nexport function inject<Value>(token: Token<Value>): Value;\n\nexport function inject<T>(token: Token<T>): T {\n const context = ensureInjectionContext(inject);\n return context.container.resolve(token);\n}\n\n/**\n * Injects the instance associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n *\n * Compared to {@link inject}, `injectBy` accepts a `thisArg` argument\n * (the containing class) which is used to resolve circular dependencies.\n *\n * @example\n * ```ts\n * class Wand {\n * owner = inject(Wizard);\n * }\n *\n * class Wizard {\n * wand = injectBy(this, Wand);\n * }\n * ```\n *\n * @param thisArg - The containing instance, used to help resolve circular dependencies.\n * @param Class - The class to resolve.\n */\nexport function injectBy<Instance extends object>(thisArg: any, Class: Constructor<Instance>): Instance;\n\n/**\n * Injects the value associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n *\n * Compared to {@link inject}, `injectBy` accepts a `thisArg` argument\n * (the containing class) which is used to resolve circular dependencies.\n *\n * @example\n * ```ts\n * class Wand {\n * owner = inject(Wizard);\n * }\n *\n * class Wizard {\n * wand = injectBy(this, Wand);\n * }\n * ```\n *\n * @param thisArg - The containing instance, used to help resolve circular dependencies.\n * @param token - The token to resolve.\n */\nexport function injectBy<Value>(thisArg: any, token: Token<Value>): Value;\n\nexport function injectBy<T>(thisArg: any, token: Token<T>): T {\n const context = ensureInjectionContext(injectBy);\n const resolution = context.resolution;\n const currentFrame = resolution.stack.peek();\n\n if (!currentFrame) {\n return inject(token);\n }\n\n const currentRef = { current: thisArg };\n const cleanup = resolution.dependents.set(currentFrame.provider, currentRef);\n\n try {\n return inject(token);\n } finally {\n cleanup();\n }\n}\n","import { ensureInjectionContext } from \"./injectionContext\";\nimport type { Constructor, Token } from \"./token\";\n\n/**\n * Injects all instances provided by the registrations associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\nexport function injectAll<Instance extends object>(Class: Constructor<Instance>): Instance[];\n\n/**\n * Injects all values provided by the registrations associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\nexport function injectAll<Value>(token: Token<Value>): NonNullable<Value>[];\n\nexport function injectAll<T>(token: Token<T>): NonNullable<T>[] {\n const context = ensureInjectionContext(injectAll);\n return context.container.resolveAll(token);\n}\n","import type { ClassProvider } from \"./provider\";\nimport type { Scope } from \"./scope\";\nimport type { Constructor } from \"./token\";\nimport type { Dependencies } from \"./tokenRegistry\";\nimport type { TokensRef } from \"./tokensRef\";\n\n// @internal\nexport interface Metadata<This extends object = any> {\n eagerInstantiate?: boolean;\n autoRegister?: boolean;\n scope?: Scope;\n tokensRef: TokensRef<This>;\n provider: ClassProvider<This>;\n dependencies: Dependencies;\n}\n\n// @internal\nexport function getMetadata<T extends object>(Class: Constructor<T>): Metadata<T> {\n let metadata = metadataMap.get(Class);\n\n if (!metadata) {\n metadataMap.set(\n Class,\n (metadata = {\n tokensRef: {\n getRefTokens: () => new Set(),\n },\n provider: {\n useClass: Class,\n },\n dependencies: {\n constructor: [],\n methods: new Map(),\n },\n }),\n );\n }\n\n return metadata;\n}\n\nconst metadataMap = new WeakMap<Constructor<object>, Metadata>();\n","import { ensureInjectionContext } from \"./injectionContext\";\nimport type { Constructor, Token } from \"./token\";\n\n/**\n * Injects the instance associated with the given class,\n * or `undefined` if the class is not registered in the container.\n */\nexport function optional<Instance extends object>(Class: Constructor<Instance>): Instance | undefined;\n\n/**\n * Injects the value associated with the given token,\n * or `undefined` if the token is not registered in the container.\n */\nexport function optional<Value>(token: Token<Value>): Value | undefined;\n\nexport function optional<T>(token: Token<T>): T | undefined {\n const context = ensureInjectionContext(optional);\n return context.container.resolve(token, true);\n}\n\n/**\n * Injects the instance associated with the given class,\n * or `undefined` if the class is not registered in the container.\n *\n * Compared to {@link optional}, `optionalBy` accepts a `thisArg` argument\n * (the containing class) which is used to resolve circular dependencies.\n *\n * @param thisArg - The containing instance, used to help resolve circular dependencies.\n * @param Class - The class to resolve.\n */\nexport function optionalBy<Instance extends object>(\n thisArg: any,\n Class: Constructor<Instance>,\n): Instance | undefined;\n\n/**\n * Injects the value associated with the given token,\n * or `undefined` if the token is not registered in the container.\n *\n * Compared to {@link optional}, `optionalBy` accepts a `thisArg` argument\n * (the containing class) which is used to resolve circular dependencies.\n *\n * @param thisArg - The containing instance, used to help resolve circular dependencies.\n * @param token - The token to resolve.\n */\nexport function optionalBy<Value>(thisArg: any, token: Token<Value>): Value | undefined;\n\nexport function optionalBy<T>(thisArg: any, token: Token<T>): T | undefined {\n const context = ensureInjectionContext(optionalBy);\n const resolution = context.resolution;\n const currentFrame = resolution.stack.peek();\n\n if (!currentFrame) {\n return optional(token);\n }\n\n const currentRef = { current: thisArg };\n const cleanup = resolution.dependents.set(currentFrame.provider, currentRef);\n\n try {\n return optional(token);\n } finally {\n cleanup();\n }\n}\n","import { ensureInjectionContext } from \"./injectionContext\";\nimport type { Constructor, Token } from \"./token\";\n\n/**\n * Injects all instances provided by the registrations associated with the given class,\n * or an empty array if the class is not registered in the container.\n */\nexport function optionalAll<Instance extends object>(Class: Constructor<Instance>): Instance[];\n\n/**\n * Injects all values provided by the registrations associated with the given token,\n * or an empty array if the token is not registered in the container.\n */\nexport function optionalAll<Value>(token: Token<Value>): NonNullable<Value>[];\n\nexport function optionalAll<T>(token: Token<T>): NonNullable<T>[] {\n const context = ensureInjectionContext(optionalAll);\n return context.container.resolveAll(token, true);\n}\n","import type { Constructor, Token } from \"./token\";\n\n/**\n * Provides a class instance for a token via a class constructor.\n */\nexport interface ClassProvider<Instance extends object> {\n readonly useClass: Constructor<Instance>;\n}\n\n/**\n * Provides a value for a token via a factory function.\n *\n * The factory function runs inside the injection context and can\n * thus access dependencies via {@link inject}-like functions.\n */\nexport interface FactoryProvider<Value> {\n readonly useFactory: (...args: []) => Value;\n}\n\n/**\n * Provides a static - already constructed - value for a token.\n */\nexport interface ValueProvider<T> {\n readonly useValue: T;\n}\n\n/**\n * Aliases another registered token.\n *\n * Resolving this token will return the value of the aliased one.\n */\nexport interface ExistingProvider<Value> {\n readonly useExisting: Token<Value>;\n}\n\n/**\n * A token provider.\n */\nexport type Provider<Value = any> =\n | ClassProvider<Value & object>\n | FactoryProvider<Value>\n | ValueProvider<Value>\n | ExistingProvider<Value>;\n\n// @internal\nexport function isClassProvider<T>(provider: Provider<T>): provider is ClassProvider<T & object> {\n return \"useClass\" in provider;\n}\n\n// @internal\nexport function isFactoryProvider<T>(provider: Provider<T>): provider is FactoryProvider<T> {\n return \"useFactory\" in provider;\n}\n\n// @internal\nexport function isValueProvider<T>(provider: Provider<T>): provider is ValueProvider<T> {\n return \"useValue\" in provider;\n}\n\n// @internal\nexport function isExistingProvider<T>(provider: Provider<T>): provider is ExistingProvider<T> {\n return \"useExisting\" in provider;\n}\n","export const Scope = {\n Inherited: \"Inherited\",\n Transient: \"Transient\",\n Resolution: \"Resolution\",\n Container: \"Container\",\n} as const;\n\nexport type Scope = (typeof Scope)[keyof typeof Scope];\n","/**\n * Type API.\n */\nexport interface Type<A> {\n /**\n * The name of the type.\n */\n readonly name: string;\n\n /**\n * Creates an intersection type from another type.\n *\n * @example\n * ```ts\n * const A = createType<A>(\"A\");\n * const B = createType<B>(\"B\");\n *\n * A.inter(\"I\", B); // => Type<A & B>\n * ```\n */\n inter<B>(typeName: string, B: Type<B>): Type<A & B>;\n\n /**\n * Creates a union type from another type.\n *\n * @example\n * ```ts\n * const A = createType<A>(\"A\");\n * const B = createType<B>(\"B\");\n *\n * A.union(\"U\", B); // => Type<A | B>\n * ```\n */\n union<B>(typeName: string, B: Type<B>): Type<A | B>;\n}\n\n/**\n * Constructor type.\n */\nexport interface Constructor<Instance extends object> {\n new (...args: any[]): Instance;\n readonly name: string;\n}\n\n/**\n * Token type.\n */\nexport type Token<Value = any> = [Value] extends [object] // Avoids distributive union behavior\n ? Type<Value> | Constructor<Value>\n : Type<Value>;\n\n/**\n * Describes a {@link Token} array with at least one element.\n */\nexport type Tokens<Value = any> = [Token<Value>, ...Token<Value>[]];\n\n/**\n * Creates a type token.\n *\n * @example\n * ```ts\n * const ISpell = createType<Spell>(\"Spell\");\n * ```\n *\n * @__NO_SIDE_EFFECTS__\n */\nexport function createType<T>(typeName: string): Type<T> {\n const type = {\n name: `Type<${typeName}>`,\n inter: createType,\n union: createType,\n toString(): string {\n return type.name;\n },\n };\n\n return type;\n}\n\n// @internal\nexport function isConstructor<T>(token: Type<T> | Constructor<T & object>): token is Constructor<T & object> {\n return typeof token == \"function\";\n}\n","// @internal\nexport function getTypeName(value: unknown): string {\n if (typeof value == \"string\") {\n return `\"${value}\"`;\n }\n\n if (typeof value == \"function\") {\n return (value.name && `typeof ${value.name}`) || \"Function\";\n }\n\n if (typeof value == \"object\") {\n if (value === null) {\n return \"null\";\n }\n\n const proto: object | null = Object.getPrototypeOf(value);\n\n if (proto && proto !== Object.prototype) {\n const constructor: unknown = proto.constructor;\n\n if (typeof constructor == \"function\" && constructor.name) {\n return constructor.name;\n }\n }\n }\n\n return typeof value;\n}\n","import { assert } from \"./errors\";\nimport type { FactoryProvider, Provider } from \"./provider\";\nimport { Scope } from \"./scope\";\nimport { type Constructor, createType, type Token, type Type } from \"./token\";\nimport type { TokenRef } from \"./tokensRef\";\nimport { getTypeName } from \"./utils/typeName\";\nimport type { ValueRef } from \"./valueRef\";\n\n/**\n * Token registration options.\n */\nexport interface RegistrationOptions {\n /**\n * The scope of the registration.\n */\n readonly scope?: Scope;\n}\n\n// @internal\nexport type Decorator = \"Inject\" | \"InjectAll\" | \"Optional\" | \"OptionalAll\";\n\n// @internal\nexport interface MethodDependency {\n readonly decorator: Decorator;\n readonly tokenRef: TokenRef;\n\n // The index of the annotated parameter (zero-based)\n readonly index: number;\n}\n\n// @internal\nexport interface Dependencies {\n readonly constructor: MethodDependency[];\n readonly methods: Map<string | symbol, MethodDependency[]>;\n}\n\n// @internal\nexport interface Registration<T = any> {\n value?: ValueRef<T>;\n readonly provider: Provider<T>;\n readonly options?: RegistrationOptions;\n readonly dependencies?: Dependencies;\n}\n\n// @internal\nexport class TokenRegistry {\n private readonly myParent?: TokenRegistry;\n private readonly myMap = new Map<Token, Registration[]>();\n\n constructor(parent: TokenRegistry | undefined) {\n this.myParent = parent;\n }\n\n get<T>(token: Token<T>): Registration<T> | undefined {\n // To clarify, at(-1) means we take the last added registration for this token\n return this.getAll(token)?.at(-1);\n }\n\n getAll<T>(token: Token<T>): Registration<T>[] | undefined {\n const internal = internals.get(token);\n return (internal && [internal]) || this.getAllFromParent(token);\n }\n\n //\n // set(...) overloads added because of TS distributive conditional types.\n //\n // TODO(Edoardo): is there a better way? Maybe refactor the Token<T> type\n // into two types, TokenObject<T extends object> | Token<T>\n //\n\n set<T extends object>(token: Type<T> | Constructor<T>, registration: Registration<T>): void;\n set<T>(token: Token<T>, registration: Registration<T>): void;\n set<T>(token: Token<T>, registration: Registration<T>): void {\n assert(!internals.has(token), `cannot register reserved token ${token.name}`);\n\n let registrations = this.myMap.get(token);\n\n if (!registrations) {\n this.myMap.set(token, (registrations = []));\n }\n\n registrations.push(registration);\n }\n\n delete<T>(token: Token<T>): Registration<T>[] | undefined {\n const registrations = this.myMap.get(token);\n this.myMap.delete(token);\n return registrations;\n }\n\n deleteAll(): [Token[], Registration[]] {\n const tokens = Array.from(this.myMap.keys());\n const registrations = Array.from(this.myMap.values()).flat();\n this.myMap.clear();\n return [tokens, registrations];\n }\n\n clearRegistrations(): unknown[] {\n const values = new Set<unknown>();\n\n for (const registrations of this.myMap.values()) {\n for (let i = 0; i < registrations.length; i++) {\n const registration = registrations[i]!;\n const value = registration.value;\n\n if (value) {\n values.add(value.current);\n }\n\n registrations[i] = {\n ...registration,\n value: undefined,\n };\n }\n }\n\n return Array.from(values);\n }\n\n private getAllFromParent<T>(token: Token<T>): Registration<T>[] | undefined {\n const registrations = this.myMap.get(token);\n return registrations || this.myParent?.getAllFromParent(token);\n }\n}\n\n// @internal\nexport function isBuilder(provider: Provider): boolean {\n return builders.has(provider);\n}\n\n/**\n * Create a one-off type token from a factory function.\n *\n * @example\n * ```ts\n * class Wizard {\n * wand = inject(\n * build(() => {\n * const wand = inject(Wand);\n * wand.owner = this;\n * // ...\n * return wand;\n * }),\n * );\n * }\n * ```\n *\n * @__NO_SIDE_EFFECTS__\n */\nexport function build<Value>(factory: (...args: []) => Value): Type<Value> {\n const token = createType<Value>(`Build<${getTypeName(factory)}>`);\n const provider: FactoryProvider<Value> = {\n useFactory: factory,\n };\n\n internals.set(token, {\n provider: provider,\n options: {\n scope: Scope.Transient,\n },\n });\n\n builders.add(provider);\n return token;\n}\n\nconst internals = new WeakMap<Token, Registration>();\nconst builders = new WeakSet<Provider>();\n","// @internal\nexport interface Disposable {\n dispose(): void;\n}\n\n// @internal\nexport function isDisposable(value: any): value is Disposable {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return value && typeof value === \"object\" && typeof value.dispose === \"function\";\n}\n","import type { Container, ContainerOptions } from \"./container\";\nimport { assert, expectNever, throwExistingUnregisteredError, throwUnregisteredError } from \"./errors\";\nimport { injectBy } from \"./inject\";\nimport { injectAll } from \"./injectAll\";\nimport { createResolution, provideInjectionContext, useInjectionContext } from \"./injectionContext\";\nimport { getMetadata } from \"./metadata\";\nimport { optionalBy } from \"./optional\";\nimport { optionalAll } from \"./optionalAll\";\nimport {\n isClassProvider,\n isExistingProvider,\n isFactoryProvider,\n isValueProvider,\n type Provider,\n} from \"./provider\";\nimport { Scope } from \"./scope\";\nimport { type Constructor, isConstructor, type Token, type Tokens } from \"./token\";\nimport { isBuilder, type Registration, type RegistrationOptions, TokenRegistry } from \"./tokenRegistry\";\nimport { isDisposable } from \"./utils/disposable\";\n\n/**\n * The default implementation of a di-wise-neo {@link Container}.\n */\nexport class ContainerImpl implements Container {\n private readonly myParent?: ContainerImpl;\n private readonly myChildren: Set<ContainerImpl> = new Set();\n private readonly myOptions: ContainerOptions;\n private readonly myTokenRegistry: TokenRegistry;\n private myDisposed: boolean = false;\n\n constructor(parent: ContainerImpl | undefined, options: Partial<ContainerOptions>) {\n this.myParent = parent;\n this.myOptions = {\n autoRegister: false,\n defaultScope: Scope.Inherited,\n ...options,\n };\n\n this.myTokenRegistry = new TokenRegistry(this.myParent?.myTokenRegistry);\n }\n\n get registry(): TokenRegistry {\n return this.myTokenRegistry;\n }\n\n get options(): ContainerOptions {\n return {\n ...this.myOptions,\n };\n }\n\n get parent(): Container | undefined {\n return this.myParent;\n }\n\n get isDisposed(): boolean {\n return this.myDisposed;\n }\n\n createChild(options?: Partial<ContainerOptions>): Container {\n this.checkDisposed();\n const container = new ContainerImpl(this, {\n ...this.myOptions,\n ...options,\n });\n\n this.myChildren.add(container);\n return container;\n }\n\n clearCache(): unknown[] {\n this.checkDisposed();\n return this.myTokenRegistry.clearRegistrations();\n }\n\n getCached<T>(token: Token<T>): T | undefined {\n this.checkDisposed();\n const registration = this.myTokenRegistry.get(token);\n return registration?.value?.current;\n }\n\n getAllCached<T>(token: Token<T>): T[] {\n this.checkDisposed();\n const registrations = this.myTokenRegistry.getAll(token);\n\n if (!registrations) {\n return [];\n }\n\n const values = new Set<T>();\n\n for (const registration of registrations) {\n const value = registration.value;\n\n if (value) {\n values.add(value.current);\n }\n }\n\n return Array.from(values);\n }\n\n resetRegistry(): unknown[] {\n this.checkDisposed();\n const [, registrations] = this.myTokenRegistry.deleteAll();\n const values = new Set<unknown>();\n\n for (const registration of registrations) {\n const value = registration.value;\n\n if (value) {\n values.add(value.current);\n }\n }\n\n return Array.from(values);\n }\n\n isRegistered(token: Token): boolean {\n this.checkDisposed();\n return this.myTokenRegistry.get(token) !== undefined;\n }\n\n registerClass<T extends object, V extends T>(\n token: Token<T>,\n Class?: Constructor<V>,\n options?: RegistrationOptions,\n ): void {\n // This mess will go away once/if we remove the register method\n // in favor of the multiple specialized ones\n if (Class) {\n const ctor = (Class ?? token) as Constructor<any>;\n this.register(token, { useClass: ctor }, options);\n } else {\n this.register(token as Constructor<any>);\n }\n }\n\n registerFactory<T, V extends T>(\n token: Token<T>,\n factory: (...args: []) => V,\n options?: RegistrationOptions,\n ): void {\n this.register(token, { useFactory: factory }, options);\n }\n\n registerValue<T, V extends T>(token: Token<T>, value: V): void {\n this.register(token, { useValue: value });\n }\n\n registerAlias<T, V extends T>(targetToken: Token<V>, aliasTokens: Tokens<T>): void {\n // De-duplicate tokens\n for (const alias of new Set(aliasTokens)) {\n this.register(alias, { useExisting: targetToken });\n }\n }\n\n register<T>(...args: [Constructor<T & object>] | [Token<T>, Provider<T>, RegistrationOptions?]): Container {\n this.checkDisposed();\n\n if (args.length == 1) {\n const Class = args[0];\n const metadata = getMetadata(Class);\n const registration: Registration = {\n // The provider is of type ClassProvider, initialized by getMetadata\n provider: metadata.provider,\n options: {\n scope: metadata.scope ?? this.myOptions.defaultScope,\n },\n dependencies: metadata.dependencies,\n };\n\n // Register the class itself\n this.myTokenRegistry.set(Class, registration);\n\n // Register the additional tokens specified via class decorators.\n // These tokens will point to the original Class token and will have the same scope.\n for (const token of metadata.tokensRef.getRefTokens()) {\n this.myTokenRegistry.set(token, {\n provider: {\n useExisting: Class,\n },\n });\n }\n\n // Eager-instantiate only if the class is container-scoped\n if (metadata.eagerInstantiate && registration.options?.scope === Scope.Container) {\n this.resolve(Class);\n }\n } else {\n const [token, provider, options] = args;\n\n if (isClassProvider(provider)) {\n const metadata = getMetadata(provider.useClass);\n const registration: Registration = {\n provider: metadata.provider,\n options: {\n // The explicit registration options override what is specified\n // via class decorators (e.g., @Scoped)\n scope: metadata.scope ?? this.myOptions.defaultScope,\n ...options,\n },\n dependencies: metadata.dependencies,\n };\n\n this.myTokenRegistry.set(token, registration);\n\n // Eager-instantiate only if the provided class is container-scoped\n if (metadata.eagerInstantiate && registration.options?.scope === Scope.Container) {\n this.resolve(token);\n }\n } else {\n if (isExistingProvider(provider)) {\n assert(\n token !== provider.useExisting,\n `the useExisting token ${token.name} cannot be the same as the token being registered`,\n );\n }\n\n this.myTokenRegistry.set(token, {\n provider: provider,\n options: options,\n });\n }\n }\n\n return this;\n }\n\n unregister<T>(token: Token<T>): T[] {\n this.checkDisposed();\n const registrations = this.myTokenRegistry.delete(token);\n\n if (!registrations) {\n return [];\n }\n\n const values = new Set<T>();\n\n for (const registration of registrations) {\n const value = registration.value;\n\n if (value) {\n values.add(value.current);\n }\n }\n\n return Array.from(values);\n }\n\n resolve<T>(token: Token<T>, optional?: boolean): T | undefined {\n this.checkDisposed();\n const registration = this.myTokenRegistry.get(token);\n\n if (registration) {\n return this.resolveRegistration(token, registration);\n }\n\n if (isConstructor(token)) {\n return this.instantiateClass(token, optional);\n }\n\n return optional ? undefined : throwUnregisteredError(token);\n }\n\n resolveAll<T>(token: Token<T>, optional?: boolean): NonNullable<T>[] {\n this.checkDisposed();\n const registrations = this.myTokenRegistry.getAll(token);\n\n if (registrations) {\n return registrations\n .map((registration) => this.resolveRegistration(token, registration))\n .filter((value) => value != null);\n }\n\n if (isConstructor(token)) {\n const instance = this.instantiateClass(token, optional);\n return instance === undefined // = could not resolve, but since it is optional\n ? []\n : [instance];\n }\n\n return optional ? [] : throwUnregisteredError(token);\n }\n\n dispose(): void {\n if (this.myDisposed) {\n return;\n }\n\n // Dispose children containers first\n for (const child of this.myChildren) {\n child.dispose();\n }\n\n this.myChildren.clear();\n\n // Remove ourselves from our parent container\n this.myParent?.myChildren?.delete(this);\n this.myDisposed = true;\n\n const [, registrations] = this.myTokenRegistry.deleteAll();\n const disposedRefs = new Set<any>();\n\n // Dispose all resolved (aka instantiated) tokens that implement the Disposable interface\n for (const registration of registrations) {\n const value = registration.value?.current;\n\n if (isDisposable(value) && !disposedRefs.has(value)) {\n disposedRefs.add(value);\n value.dispose();\n }\n }\n\n // Allow values to be GCed\n disposedRefs.clear();\n }\n\n private resolveRegistration<T>(token: Token<T>, registration: Registration<T>): T {\n let currRegistration: Registration<T> | undefined = registration;\n let currProvider = currRegistration.provider;\n\n while (isExistingProvider(currProvider)) {\n const targetToken = currProvider.useExisting;\n currRegistration = this.myTokenRegistry.get(targetToken);\n\n if (!currRegistration) {\n throwExistingUnregisteredError(token, targetToken);\n }\n\n currProvider = currRegistration.provider;\n }\n\n try {\n return this.resolveProviderValue(currRegistration, currProvider);\n } catch (e) {\n // If we were trying to resolve a token registered via ExistingProvider,\n // we must add the cause of the error to the message\n if (isExistingProvider(registration.provider)) {\n throwExistingUnregisteredError(token, e as Error);\n }\n\n throw e;\n }\n }\n\n private instantiateClass<T extends object>(Class: Constructor<T>, optional?: boolean): T | undefined {\n const metadata = getMetadata(Class);\n\n if (metadata.autoRegister ?? this.myOptions.autoRegister) {\n this.register(Class);\n return (this as Container).resolve(Class);\n }\n\n const scope = this.resolveScope(metadata.scope);\n\n if (optional && scope === Scope.Container) {\n // It would not be possible to resolve the class in container scope,\n // as that would require prior registration.\n // However, since resolution is marked optional, we simply return undefined.\n return undefined;\n }\n\n assert(\n scope !== Scope.Container,\n `unregistered class ${Class.name} cannot be resolved in container scope`,\n );\n\n const registration: Registration<T> = {\n provider: metadata.provider,\n options: {\n scope: scope,\n },\n dependencies: metadata.dependencies,\n };\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n return this.resolveScopedValue(registration, (args) => new Class(...args));\n }\n\n private resolveProviderValue<T>(registration: Registration<T>, provider: Provider<T>): T {\n assert(registration.provider === provider, \"internal error: mismatching provider\");\n\n if (isClassProvider(provider)) {\n const Class = provider.useClass;\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n return this.resolveScopedValue(registration, (args) => new Class(...args));\n }\n\n if (isFactoryProvider(provider)) {\n const factory = provider.useFactory;\n return this.resolveScopedValue(registration, factory);\n }\n\n if (isValueProvider(provider)) {\n return provider.useValue;\n }\n\n if (isExistingProvider(provider)) {\n assert(false, \"internal error: unexpected ExistingProvider\");\n }\n\n expectNever(provider);\n }\n\n private resolveScopedValue<T>(registration: Registration<T>, factory: (...args: any[]) => T): T {\n let context = useInjectionContext();\n\n if (!context || context.container !== this) {\n context = {\n container: this,\n resolution: createResolution(),\n };\n }\n\n const resolution = context.resolution;\n const provider = registration.provider;\n const options = registration.options;\n\n if (resolution.stack.has(provider)) {\n const dependentRef = resolution.dependents.get(provider);\n assert(dependentRef, \"circular dependency detected\");\n return dependentRef.current;\n }\n\n const scope = this.resolveScope(options?.scope, context);\n const cleanups = [\n provideInjectionContext(context),\n !isBuilder(provider) && resolution.stack.push(provider, { provider, scope }),\n ];\n\n try {\n switch (scope) {\n case Scope.Container: {\n const valueRef = registration.value;\n\n if (valueRef) {\n return valueRef.current;\n }\n\n const args = this.resolveConstructorDependencies(registration);\n const value = this.injectDependencies(registration, factory(args));\n registration.value = { current: value };\n return value;\n }\n case Scope.Resolution: {\n const valueRef = resolution.values.get(provider);\n\n if (valueRef) {\n return valueRef.current;\n }\n\n const args = this.resolveConstructorDependencies(registration);\n const value = this.injectDependencies(registration, factory(args));\n resolution.values.set(provider, { current: value });\n return value;\n }\n case Scope.Transient: {\n const args = this.resolveConstructorDependencies(registration);\n return this.injectDependencies(registration, factory(args));\n }\n }\n } finally {\n cleanups.forEach((cleanup) => cleanup && cleanup());\n }\n }\n\n private resolveScope(\n scope = this.myOptions.defaultScope,\n context = useInjectionContext(),\n ): Exclude<Scope, typeof Scope.Inherited> {\n if (scope == Scope.Inherited) {\n const dependentFrame = context?.resolution.stack.peek();\n return dependentFrame?.scope || Scope.Transient;\n }\n\n return scope;\n }\n\n private resolveConstructorDependencies<T>(registration: Registration<T>): any[] {\n const dependencies = registration.dependencies;\n\n if (dependencies) {\n assert(isClassProvider(registration.provider), `internal error: not a ClassProvider`);\n const ctorDeps = dependencies.constructor;\n\n if (ctorDeps.length > 0) {\n // Let's check if all necessary constructor parameters are decorated.\n // If not, we cannot safely create an instance.\n const ctor = registration.provider.useClass;\n assert(ctor.length === ctorDeps.length, () => {\n const msg = `expected ${ctor.length} decorated constructor parameters in ${ctor.name}`;\n return msg + `, but found ${ctorDeps.length}`;\n });\n\n return ctorDeps\n .sort((a, b) => a.index - b.index)\n .map((dep) => {\n const token = dep.tokenRef.getRefToken();\n switch (dep.decorator) {\n case \"Inject\":\n return this.resolve(token);\n case \"InjectAll\":\n return this.resolveAll(token);\n case \"Optional\":\n return this.resolve(token, true);\n case \"OptionalAll\":\n return this.resolveAll(token, true);\n }\n });\n }\n }\n\n return [];\n }\n\n private injectDependencies<T>(registration: Registration<T>, instance: T): T {\n const dependencies = registration.dependencies;\n\n if (dependencies) {\n assert(isClassProvider(registration.provider), `internal error: not a ClassProvider`);\n const ctor = registration.provider.useClass;\n\n // Perform method injection\n for (const [key, methodDeps] of dependencies.methods) {\n // Let's check if all necessary method parameters are decorated.\n // If not, we cannot safely invoke the method.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const method = (instance as any)[key] as Function;\n assert(methodDeps.length === method.length, () => {\n const msg = `expected ${method.length} decorated method parameters`;\n return msg + ` in ${ctor.name}.${String(key)}, but found ${methodDeps.length}`;\n });\n\n const args = methodDeps\n .sort((a, b) => a.index - b.index)\n .map((dep) => {\n const token = dep.tokenRef.getRefToken();\n switch (dep.decorator) {\n case \"Inject\":\n return injectBy(instance, token);\n case \"InjectAll\":\n return injectAll(token);\n case \"Optional\":\n return optionalBy(instance, token);\n case \"OptionalAll\":\n return optionalAll(token);\n }\n });\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n method.bind(instance)(...args);\n }\n }\n\n return instance;\n }\n\n private checkDisposed(): void {\n assert(!this.myDisposed, \"the container is disposed\");\n }\n}\n","import { ContainerImpl } from \"./containerImpl\";\nimport type { ClassProvider, ExistingProvider, FactoryProvider, ValueProvider } from \"./provider\";\nimport { Scope } from \"./scope\";\nimport type { Constructor, Token, Tokens } from \"./token\";\nimport type { RegistrationOptions, TokenRegistry } from \"./tokenRegistry\";\n\n/**\n * Container creation options.\n */\nexport interface ContainerOptions {\n /**\n * Whether to automatically register an unregistered class when resolving it as a token.\n *\n * @defaultValue false\n */\n readonly autoRegister: boolean;\n\n /**\n * The default scope for registrations.\n *\n * @defaultValue Scope.Inherited\n */\n readonly defaultScope: Scope;\n}\n\n/**\n * Container API.\n */\nexport interface Container {\n /**\n * @internal\n */\n api?: Readonly<Container>;\n\n /**\n * @internal\n */\n readonly registry: TokenRegistry;\n\n /**\n * The options used to create this container.\n */\n readonly options: ContainerOptions;\n\n /**\n * The parent container, or `undefined` if this is the root container.\n */\n readonly parent: Container | undefined;\n\n /**\n * Whether this container is disposed.\n */\n readonly isDisposed: boolean;\n\n /**\n * Creates a new child container that inherits this container's options.\n *\n * You can pass specific options to override the inherited ones.\n */\n createChild(options?: Partial<ContainerOptions>): Container;\n\n /**\n * Clears and returns all distinct cached values from this container's internal registry.\n * Values from {@link ValueProvider} registrations are not included, as they are never cached.\n *\n * Note that only this container is affected. Parent containers, if any, remain unchanged.\n */\n clearCache(): unknown[];\n\n /**\n * Returns the cached value from the most recent registration of the token,\n * or `undefined` if no value has been cached yet (the token has not been resolved yet).\n *\n * If the token has at least one registration in this container,\n * the cached value is taken from the most recent of those registrations.\n * Otherwise, it may be retrieved from parent containers, if any.\n *\n * Values are never cached for tokens with _transient_ or _resolution_ scope,\n * or for {@link ValueProvider} registrations.\n */\n getCached<Value>(token: Token<Value>): Value | undefined;\n\n /**\n * Returns all cached values associated with registrations of the token,\n * in the order they were registered, or an empty array if none have been cached.\n *\n * If the token has at least one registration in the current container,\n * cached values are taken from those registrations.\n * Otherwise, cached values may be retrieved from parent containers, if any.\n *\n * Values are never cached for tokens with _transient_ or _resolution_ scope,\n * or for {@link ValueProvider} registrations.\n */\n getAllCached<Value>(token: Token<Value>): Value[];\n\n /**\n * Removes all registrations from this container's internal registry.\n *\n * Returns an array of distinct cached values that were stored within the removed registrations.\n * Values from {@link ValueProvider} registrations are not included, as they are not cached.\n *\n * Note that only this container is affected. Parent containers, if any, remain unchanged.\n */\n resetRegistry(): unknown[];\n\n /**\n * Returns whether the token is registered in this container or in parent containers, if any.\n */\n isRegistered(token: Token): boolean;\n\n /**\n * Registers a concrete class, where the class acts as its own token.\n *\n * Tokens provided via the {@link Injectable} decorator applied to the class\n * are also registered as aliases.\n *\n * The default registration scope is determined by the {@link Scoped} decorator,\n * if present.\n */\n registerClass<Instance extends object>(Class: Constructor<Instance>): void;\n\n /**\n * Registers a concrete class with a token.\n *\n * The default registration scope is determined by the {@link Scoped} decorator\n * applied to the class, if present, but it can be overridden by passing explicit\n * registration options.\n */\n registerClass<Instance extends object, ProvidedInstance extends Instance>(\n token: Token<Instance>,\n Class: Constructor<ProvidedInstance>,\n options?: RegistrationOptions,\n ): void;\n\n /**\n * Registers a token whose value is produced by a factory function.\n *\n * The factory function runs inside the injection context and can\n * thus access dependencies via {@link inject}-like functions.\n */\n registerFactory<Value, ProvidedValue extends Value>(\n token: Token<Value>,\n factory: (...args: []) => ProvidedValue,\n options?: RegistrationOptions,\n ): void;\n\n /**\n * Registers a token with a fixed value.\n *\n * The provided value is returned as-is when the token is resolved (scopes do not apply).\n */\n registerValue<Value, ProvidedValue extends Value>(token: Token<Value>, value: ProvidedValue): void;\n\n /**\n * Registers one or more tokens as aliases for a target token.\n *\n * When an alias is resolved, the target token is resolved instead.\n */\n registerAlias<Value, ProvidedValue extends Value>(\n targetToken: Token<ProvidedValue>,\n aliasTokens: Tokens<Value>,\n ): void;\n\n /**\n * Registers a {@link ClassProvider}, using the class itself as its token.\n *\n * Tokens provided via the {@link Injectable} decorator applied to the class\n * are also registered as aliases.\n *\n * The scope is determined by the {@link Scoped} decorator, if present.\n *\n * @see registerClass\n */\n register<Instance extends object>(Class: Constructor<Instance>): Container;\n\n /**\n * Registers a {@link ClassProvider} with a token.\n *\n * The default registration scope is determined by the {@link Scoped} decorator\n * applied to the provided class, if present, but it can be overridden by\n * passing explicit registration options.\n *\n * @see registerClass\n */\n register<Instance extends object, ProviderInstance extends Instance>(\n token: Token<Instance>,\n provider: ClassProvider<ProviderInstance>,\n options?: RegistrationOptions,\n ): Container;\n\n /**\n * Registers a {@link FactoryProvider} with a token.\n *\n * @see registerFactory\n */\n register<Value, ProviderValue extends Value>(\n token: Token<Value>,\n provider: FactoryProvider<ProviderValue>,\n options?: RegistrationOptions,\n ): Container;\n\n /**\n * Registers an {@link ExistingProvider} with a token.\n *\n * The token will alias the one set in `useExisting`.\n *\n * @see registerAlias\n */\n register<Value, ProviderValue extends Value>(\n token: Token<Value>,\n provider: ExistingProvider<ProviderValue>,\n ): Container;\n\n /**\n * Registers a {@link ValueProvider} with a token.\n *\n * Values provided via `useValue` are never cached (scopes do not apply)\n * and are simply returned as-is.\n *\n * @see registerValue\n */\n register<Value, ProviderValue extends Value>(\n token: Token<Value>,\n provider: ValueProvider<ProviderValue>,\n ): Container;\n\n /**\n * Removes all registrations for the given token from the container's internal registry.\n *\n * Returns an array of distinct cached values that were stored within the removed registrations.\n * Values from {@link ValueProvider} registrations are not included, as they are not cached.\n *\n * Note that only this container is affected. Parent containers, if any, remain unchanged.\n */\n unregister<Value>(token: Token<Value>): Value[];\n\n /**\n * Resolves the given class to the instance associated with it.\n *\n * If the class is registered in this container or any of its parent containers,\n * an instance is created using the most recent registration.\n *\n * If the class is not registered, but it is decorated with {@link AutoRegister},\n * or {@link ContainerOptions.autoRegister} is true, the class is registered automatically.\n * Otherwise, resolution fails.\n * The scope for the automatic registration is determined by either\n * the {@link Scoped} decorator on the class, or {@link ContainerOptions.defaultScope}.\n *\n * If `optional` is false or is not passed and the class is not registered in the container\n * (and could not be auto-registered), an error is thrown.\n * Otherwise, if `optional` is true, `undefined` is returned.\n *\n * The resolution behavior depends on the {@link Provider} used during registration:\n * - For {@link ValueProvider}, the explicitly provided instance is returned.\n * - For {@link FactoryProvider}, the factory function is invoked to create the instance.\n * - For {@link ClassProvider}, a new instance of the class is created according to its scope.\n * - For {@link ExistingProvider}, the instance is resolved by referring to another registered token.\n *\n * If the class is registered with _container_ scope, the resolved instance is cached\n * in the container's internal registry.\n */\n resolve<Instance extends object>(Class: Constructor<Instance>, optional?: false): Instance;\n resolve<Instance extends object>(Class: Constructor<Instance>, optional: true): Instance | undefined;\n resolve<Instance extends object>(Class: Constructor<Instance>, optional?: boolean): Instance | undefined;\n\n /**\n * Resolves the given token to the value associated with it.\n *\n * If the token is registered in this container or any of its parent containers,\n * its value is resolved using the most recent registration.\n *\n * If `optional` is false or not passed and the token is not registered in the container,\n * an error is thrown. Otherwise, if `optional` is true, `undefined` is returned.\n *\n * The resolution behavior depends on the {@link Provider} used during registration:\n * - For {@link ValueProvider}, the explicitly provided value is returned.\n * - For {@link FactoryProvider}, the factory function is invoked to create the value.\n * - For {@link ClassProvider}, a new instance of the class is created according to its scope.\n * - For {@link ExistingProvider}, the value is resolved by referring to another registered token.\n *\n * If the token is registered with _container_ scope, the resolved value is cached\n * in the container's internal registry.\n */\n resolve<Value>(token: Token<Value>, optional?: false): Value;\n resolve<Value>(token: Token<Value>, optional: true): Value | undefined;\n resolve<Value>(token: Token<Value>, optional?: boolean): Value | undefined;\n\n /**\n * Resolves the given class to all instances provided by the registrations associated with it.\n *\n * If the class is not registered, but it is decorated with {@link AutoRegister},\n * or {@link ContainerOptions.autoRegister} is true, the class is registered automatically.\n * Otherwise, resolution fails.\n * The scope for the automatic registration is determined by either\n * the {@link Scoped} decorator on the class, or {@link ContainerOptions.defaultScope}.\n *\n * If `optional` is false or is not passed and the class is not registered in the container\n * (and could not be auto-registered), an error is thrown.\n * Otherwise, if `optional` is true, an empty array is returned.\n *\n * The resolution behavior depends on the {@link Provider} used during registration:\n * - For {@link ValueProvider}, the explicitly provided instance is returned.\n * - For {@link FactoryProvider}, the factory function is invoked to create the instance.\n * - For {@link ClassProvider}, a new instance of the class is created according to its scope.\n * - For {@link ExistingProvider}, the instance is resolved by referring to another registered token.\n *\n * If the class is registered with _container_ scope, the resolved instances are cached\n * in the container's internal registry.\n *\n * A separate instance of the class is created for each provider.\n *\n * @see The documentation for `resolve(Class: Constructor)`\n */\n resolveAll<Instance extends object>(Class: Constructor<Instance>, optional?: false): Instance[];\n resolveAll<Instance extends object>(Class: Constructor<Instance>, optional: true): Instance[];\n resolveAll<Instance extends object>(Class: Constructor<Instance>, optional?: boolean): Instance[];\n\n /**\n * Resolves the given token to all values provided by the registrations associated with it.\n *\n * If `optional` is false or not passed and the token is not registered in the container,\n * an error is thrown. Otherwise, if `optional` is true, an empty array is returned.\n *\n * The resolution behavior depends on the {@link Provider} used during registration:\n * - For {@link ValueProvider}, the explicitly provided value is returned.\n * - For {@link FactoryProvider}, the factory function is invoked to create the value.\n * - For {@link ClassProvider}, a new instance of the class is created according to its scope.\n * - For {@link ExistingProvider}, the value is resolved by referring to another registered token.\n *\n * If the token is registered with _container_ scope, the resolved values are cached\n * in the container's internal registry.\n *\n * @see The documentation for `resolve(token: Token)`\n */\n resolveAll<Value>(token: Token<Value>, optional?: false): NonNullable<Value>[];\n resolveAll<Value>(token: Token<Value>, optional: true): NonNullable<Value>[];\n resolveAll<Value>(token: Token<Value>, optional?: boolean): NonNullable<Value>[];\n\n /**\n * Disposes this container and all its cached values.\n *\n * Token values implementing a `Disposable` interface (e.g., objects with a `dispose()` function)\n * are automatically disposed during this process.\n *\n * Note that children containers are disposed first, in creation order.\n */\n dispose(): void;\n}\n\n/**\n * Creates a new container.\n */\nexport function createContainer(\n options: Partial<ContainerOptions> = {\n autoRegister: false,\n defaultScope: Scope.Inherited,\n },\n): Container {\n return new ContainerImpl(undefined, options);\n}\n","import { getMetadata } from \"../metadata\";\nimport type { Constructor } from \"../token\";\n\n/**\n * Class decorator that enables auto-registration of an unregistered class,\n * when the class is first resolved from the container.\n *\n * @example\n * ```ts\n * @AutoRegister\n * class Wizard {}\n *\n * const wizard = container.resolve(Wizard);\n * container.isRegistered(Wizard); // => true\n * ```\n *\n * @__NO_SIDE_EFFECTS__\n */\nexport function AutoRegister<Ctor extends Constructor<any>>(Class: Ctor): void {\n const metadata = getMetadata(Class);\n metadata.autoRegister = true;\n}\n","import { getMetadata } from \"../metadata\";\nimport type { Constructor } from \"../token\";\n\n/**\n * Class decorator that enables eager instantiation of a class when it is registered\n * in the container with `Scope.Container`.\n *\n * This causes the container to immediately create and cache the instance of the class,\n * instead of deferring instantiation until the first resolution.\n *\n * @example\n * ```ts\n * @EagerInstantiate\n * @Scoped(Scope.Container)\n * class Wizard {}\n *\n * // A Wizard instance is immediately created and cached by the container\n * const wizard = container.register(Wizard);\n * ```\n *\n * @__NO_SIDE_EFFECTS__\n */\nexport function EagerInstantiate<Ctor extends Constructor<any>>(Class: Ctor): void {\n const metadata = getMetadata(Class);\n metadata.eagerInstantiate = true;\n}\n","import { assert } from \"./errors\";\nimport type { Token, Tokens } from \"./token\";\n\nexport interface TokensRef<Value = any> {\n readonly getRefTokens: () => Set<Token<Value>>;\n}\n\nexport interface TokenRef<Value = any> {\n readonly getRefToken: () => Token<Value>;\n}\n\n/**\n * Allows referencing tokens that are declared later in the file by wrapping them\n * in a lazily evaluated function.\n */\nexport function forwardRef<Value>(token: () => Tokens<Value>): TokensRef<Value>;\n\n/**\n * Allows referencing a token that is declared later in the file by wrapping it\n * in a lazily evaluated function.\n */\nexport function forwardRef<Value>(token: () => Token<Value>): TokenRef<Value>;\n\nexport function forwardRef<Value>(\n token: () => Token<Value> | Tokens<Value>,\n): TokensRef<Value> & TokenRef<Value> {\n return {\n getRefTokens: (): Set<Token<Value>> => {\n // Normalize the single token here, so that we don't have\n // to do it at every getRefTokens call site\n const tokenOrTokens = token();\n const tokensArray = Array.isArray(tokenOrTokens) ? tokenOrTokens : [tokenOrTokens];\n return new Set(tokensArray);\n },\n getRefToken: () => {\n const tokenOrTokens = token();\n assert(!Array.isArray(tokenOrTokens), \"internal error: ref tokens should be a single token\");\n return tokenOrTokens;\n },\n };\n}\n\n// @internal\nexport function isTokensRef(value: any): value is TokensRef {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return value && typeof value === \"object\" && typeof value.getRefTokens === \"function\";\n}\n\n// @internal\nexport function isTokenRef(value: any): value is TokenRef {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return value && typeof value === \"object\" && typeof value.getRefToken === \"function\";\n}\n","import { assert } from \"../errors\";\nimport { getMetadata } from \"../metadata\";\nimport type { Constructor, Token } from \"../token\";\nimport type { Decorator } from \"../tokenRegistry\";\nimport { forwardRef, isTokenRef, type TokenRef } from \"../tokensRef\";\n\nexport function processDecoratedParameter(\n decorator: Decorator,\n token: Token | TokenRef,\n target: object,\n propertyKey: string | symbol | undefined,\n parameterIndex: number,\n): void {\n // Error out immediately if the decorator has been applied\n // to a static property or a static method\n if (propertyKey !== undefined && typeof target === \"function\") {\n assert(false, `@${decorator} cannot be used on static member ${target.name}.${String(propertyKey)}`);\n }\n\n const tokenRef = isTokenRef(token) ? token : forwardRef(() => token);\n\n if (propertyKey === undefined) {\n // Constructor\n const metadata = getMetadata(target as Constructor<any>);\n metadata.dependencies.constructor.push({\n decorator: decorator,\n tokenRef: tokenRef,\n index: parameterIndex,\n });\n } else {\n // Normal instance method\n const metadata = getMetadata(target.constructor as Constructor<any>);\n const methods = metadata.dependencies.methods;\n let dep = methods.get(propertyKey);\n\n if (dep === undefined) {\n dep = [];\n methods.set(propertyKey, dep);\n }\n\n dep.push({\n decorator: decorator,\n tokenRef: tokenRef,\n index: parameterIndex,\n });\n }\n}\n","import type { Constructor, Token } from \"../token\";\nimport type { TokenRef } from \"../tokensRef\";\nimport { processDecoratedParameter } from \"./decorators\";\n\n/**\n * Parameter decorator that injects the instance associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\nexport function Inject<Instance extends object>(Class: Constructor<Instance>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects the value associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\nexport function Inject<Value>(token: Token<Value>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects the value associated with the given token.\n *\n * Allows referencing a token that is declared later in the file by using\n * the {@link forwardRef} helper function.\n *\n * Throws an error if the token is not registered in the container.\n *\n * @example\n * ```ts\n * class Wizard {\n * constructor(@Inject(forwardRef(() => Wand)) readonly wand: Wand) {}\n * }\n * // Other code...\n * class Wand {}\n * ```\n */\nexport function Inject<Value>(tokens: TokenRef<Value>): ParameterDecorator;\n\nexport function Inject<T>(token: Token<T> | TokenRef<T>): ParameterDecorator {\n return function (target, propertyKey, parameterIndex: number): void {\n processDecoratedParameter(\"Inject\", token, target, propertyKey, parameterIndex);\n };\n}\n","import { getMetadata } from \"../metadata\";\nimport type { Constructor, Tokens } from \"../token\";\nimport { forwardRef, isTokensRef, type TokenRef, type TokensRef } from \"../tokensRef\";\n\n/**\n * Class decorator that registers additional aliasing tokens for the decorated type,\n * when the type is first registered in the container.\n *\n * The container uses {@link ExistingProvider} under the hood.\n *\n * @example\n * ```ts\n * @Injectable(Weapon)\n * class Wand {}\n * ```\n */\nexport function Injectable<This extends object, Value extends This>(...tokens: Tokens<Value>): ClassDecorator;\n\n/**\n * Class decorator that registers additional aliasing tokens for the decorated type,\n * when the type is first registered in the container.\n *\n * The container uses {@link ExistingProvider} under the hood.\n *\n * Allows referencing tokens that are declared later in the file by using\n * the {@link forwardRef} helper function.\n *\n * @example\n * ```ts\n * @Injectable(forwardRef() => Weapon) // Weapon is declared after Wand\n * class Wizard {}\n * // Other code...\n * class Weapon {}\n * ```\n */\nexport function Injectable<This extends object, Value extends This>(\n tokens: TokenRef<Value> | TokensRef<Value>,\n): ClassDecorator;\n\n/**\n * @__NO_SIDE_EFFECTS__\n */\nexport function Injectable(...args: unknown[]): ClassDecorator {\n return function (Class): void {\n const metadata = getMetadata(Class as any as Constructor<any>);\n const arg0 = args[0];\n const tokensRef = isTokensRef(arg0) ? arg0 : forwardRef(() => args as Tokens);\n const existingTokensRef = metadata.tokensRef;\n metadata.tokensRef = {\n getRefTokens: () => {\n const existingTokens = existingTokensRef.getRefTokens();\n\n for (const token of tokensRef.getRefTokens()) {\n existingTokens.add(token);\n }\n\n return existingTokens;\n },\n };\n };\n}\n","import type { Constructor, Token } from \"../token\";\nimport type { TokenRef } from \"../tokensRef\";\nimport { processDecoratedParameter } from \"./decorators\";\n\n/**\n * Parameter decorator that injects all instances provided by the registrations\n * associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\nexport function InjectAll<Instance extends object>(Class: Constructor<Instance>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects all values provided by the registrations\n * associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\nexport function InjectAll<Value>(token: Token<Value>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects all values provided by the registrations\n * associated with the given token.\n *\n * Allows referencing a token that is declared later in the file by using\n * the {@link forwardRef} helper function.\n *\n * Throws an error if the token is not registered in the container.\n *\n * @example\n * ```ts\n * class Wizard {\n * constructor(@InjectAll(forwardRef(() => Wand)) readonly wands: Wand[]) {}\n * }\n * // Other code...\n * class Wand {}\n * ```\n */\nexport function InjectAll<Value>(tokens: TokenRef<Value>): ParameterDecorator;\n\nexport function InjectAll<T>(token: Token<T> | TokenRef<T>): ParameterDecorator {\n return function (target, propertyKey, parameterIndex: number): void {\n processDecoratedParameter(\"InjectAll\", token, target, propertyKey, parameterIndex);\n };\n}\n","import type { Constructor, Token } from \"../token\";\nimport type { TokenRef } from \"../tokensRef\";\nimport { processDecoratedParameter } from \"./decorators\";\n\n/**\n * Parameter decorator that injects the instance associated with the given class,\n * or `undefined` if the class is not registered in the container.\n */\nexport function Optional<Instance extends object>(Class: Constructor<Instance>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects the value associated with the given token,\n * or `undefined` if the token is not registered in the container.\n */\nexport function Optional<Value>(token: Token<Value>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects the value associated with the given token,\n * or `undefined` if the token is not registered in the container.\n *\n * Allows referencing a token that is declared later in the file by using\n * the {@link forwardRef} helper function.\n *\n * @example\n * ```ts\n * class Wizard {\n * constructor(@Optional(forwardRef(() => Wand)) readonly wand: Wand | undefined) {}\n * }\n * // Other code...\n * class Wand {}\n * ```\n */\nexport function Optional<Value>(tokens: TokenRef<Value>): ParameterDecorator;\n\nexport function Optional<T>(token: Token<T> | TokenRef<T>): ParameterDecorator {\n return function (target, propertyKey, parameterIndex: number): void {\n processDecoratedParameter(\"Optional\", token, target, propertyKey, parameterIndex);\n };\n}\n","import type { Constructor, Token } from \"../token\";\nimport type { TokenRef } from \"../tokensRef\";\nimport { processDecoratedParameter } from \"./decorators\";\n\n/**\n * Parameter decorator that injects all instances provided by the registrations\n * associated with the given class, or an empty array if the class is not registered\n * in the container.\n */\nexport function OptionalAll<Instance extends object>(Class: Constructor<Instance>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects all values provided by the registrations\n * associated with the given token, or an empty array if the token is not registered\n * in the container.\n */\nexport function OptionalAll<Value>(token: Token<Value>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects all values provided by the registrations\n * associated with the given token, or an empty array if the token is not registered\n * in the container.\n *\n * Allows referencing a token that is declared later in the file by using\n * the {@link forwardRef} helper function.\n *\n * @example\n * ```ts\n * class Wizard {\n * constructor(@OptionalAll(forwardRef(() => Wand)) readonly wands: Wand[]) {}\n * }\n * // Other code...\n * class Wand {}\n * ```\n */\nexport function OptionalAll<Value>(tokens: TokenRef<Value>): ParameterDecorator;\n\nexport function OptionalAll<T>(token: Token<T> | TokenRef<T>): ParameterDecorator {\n return function (target, propertyKey, parameterIndex: number): void {\n processDecoratedParameter(\"OptionalAll\", token, target, propertyKey, parameterIndex);\n };\n}\n","import { getMetadata } from \"../metadata\";\nimport type { Scope } from \"../scope\";\nimport type { Constructor } from \"../token\";\n\n/**\n * Class decorator for setting the scope of the decorated type when registering it.\n *\n * The scope set by this decorator can be overridden by explicit registration options, if provided.\n *\n * @example\n * ```ts\n * @Scoped(Scope.Container)\n * class Wizard {}\n *\n * container.register(Wizard);\n *\n * // Under the hood\n * container.register(\n * Wizard,\n * { useClass: Wizard },\n * { scope: Scope.Container },\n * );\n * ```\n *\n * @__NO_SIDE_EFFECTS__\n */\nexport function Scoped(scope: Scope): ClassDecorator {\n return function (Class): void {\n const metadata = getMetadata(Class as any as Constructor<any>);\n metadata.scope = scope;\n };\n}\n","import { inject } from \"./inject\";\nimport { injectAll } from \"./injectAll\";\nimport { ensureInjectionContext, provideInjectionContext, useInjectionContext } from \"./injectionContext\";\nimport { optional } from \"./optional\";\nimport { optionalAll } from \"./optionalAll\";\nimport type { Constructor, Token, Type } from \"./token\";\nimport { build } from \"./tokenRegistry\";\n\n/**\n * Injector API.\n */\nexport interface Injector {\n /**\n * Injects the instance associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\n inject<Instance extends object>(Class: Constructor<Instance>): Instance;\n\n /**\n * Injects the value associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\n inject<Value>(token: Token<Value>): Value;\n\n /**\n * Injects all instances provided by the registrations associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\n injectAll<Instance extends object>(Class: Constructor<Instance>): Instance[];\n\n /**\n * Injects all values provided by the registrations associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\n injectAll<Value>(token: Token<Value>): NonNullable<Value>[];\n\n /**\n * Injects the instance associated with the given class,\n * or `undefined` if the class is not registered in the container.\n */\n optional<Instance extends object>(Class: Constructor<Instance>): Instance | undefined;\n\n /**\n * Injects the value associated with the given token,\n * or `undefined` if the token is not registered in the container.\n */\n optional<Value>(token: Token<Value>): Value | undefined;\n\n /**\n * Injects all instances provided by the registrations associated with the given class,\n * or an empty array if the class is not registered in the container.\n */\n optionalAll<Instance extends object>(Class: Constructor<Instance>): Instance[];\n\n /**\n * Injects all values provided by the registrations associated with the given token,\n * or an empty array if the token is not registered in the container.\n */\n optionalAll<Value>(token: Token<Value>): NonNullable<Value>[];\n}\n\n/**\n * Injector token for dynamic injections.\n *\n * @example\n * ```ts\n * class Wizard {\n * private injector = inject(Injector);\n * private wand?: Wand;\n *\n * getWand(): Wand {\n * return (this.wand ??= this.injector.inject(Wand));\n * }\n * }\n *\n * const wizard = container.resolve(Wizard);\n * wizard.getWand(); // => Wand\n * ```\n */\nexport const Injector: Type<Injector> = /*@__PURE__*/ build(function Injector() {\n const context = ensureInjectionContext(Injector);\n const resolution = context.resolution;\n\n const dependentFrame = resolution.stack.peek();\n const dependentRef = dependentFrame && resolution.dependents.get(dependentFrame.provider);\n\n function withCurrentContext<R>(fn: () => R): R {\n if (useInjectionContext()) {\n return fn();\n }\n\n const cleanups = [\n provideInjectionContext(context),\n dependentFrame && resolution.stack.push(dependentFrame.provider, dependentFrame),\n dependentRef && resolution.dependents.set(dependentFrame.provider, dependentRef),\n ];\n\n try {\n return fn();\n } finally {\n for (const cleanup of cleanups) {\n cleanup?.();\n }\n }\n }\n\n return {\n inject: <T>(token: Token<T>) => withCurrentContext(() => inject(token)),\n injectAll: <T>(token: Token<T>) => withCurrentContext(() => injectAll(token)),\n optional: <T>(token: Token<T>) => withCurrentContext(() => optional(token)),\n optionalAll: <T>(token: Token<T>) => withCurrentContext(() => optionalAll(token)),\n };\n});\n","import type { Container } from \"./container\";\n\n/**\n * Composer API for middleware functions.\n */\nexport interface MiddlewareComposer {\n /**\n * Adds a middleware function to the composer.\n */\n use<MethodKey extends keyof Container>(\n key: MethodKey,\n wrap: Container[MethodKey] extends Function\n ? (next: Container[MethodKey]) => Container[MethodKey]\n : never,\n ): MiddlewareComposer;\n}\n\n/**\n * Middleware function that can be used to extend the container.\n *\n * @example\n * ```ts\n * const logger: Middleware = (composer, _api) => {\n * composer\n * .use(\"resolve\", (next) => (...args) => {\n * console.log(\"resolve\", args);\n * return next(...args);\n * })\n * .use(\"resolveAll\", (next) => (...args) => {\n * console.log(\"resolveAll\", args);\n * return next(...args);\n * });\n * };\n * ```\n */\nexport interface Middleware {\n (composer: MiddlewareComposer, api: Readonly<Container>): void;\n}\n\n/**\n * Applies middleware functions to a container.\n *\n * Middlewares are applied in array order, but execute in reverse order.\n *\n * @example\n * ```ts\n * const container = applyMiddleware(\n * createContainer(),\n * [A, B],\n * );\n * ```\n *\n * The execution order will be:\n *\n * 1. B before\n * 2. A before\n * 3. original function\n * 4. A after\n * 5. B after\n *\n * This allows outer middlewares to wrap and control the behavior of inner middlewares.\n */\nexport function applyMiddleware(container: Container, middlewares: Middleware[]): Container {\n const composer: MiddlewareComposer = {\n use(key, wrap): MiddlewareComposer {\n // We need to bind the 'this' context of the function to the container\n // before passing it to the middleware wrapper.\n //\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call\n const fn = (container[key] as any).bind(container);\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n container[key] = wrap(fn);\n return composer;\n },\n };\n\n const api = (container.api ||= { ...container });\n\n for (const middleware of middlewares) {\n middleware(composer, api);\n }\n\n return container;\n}\n"],"names":["assert","condition","message","resolvedMessage","Error","tag","expectNever","value","TypeError","String","throwUnregisteredError","token","name","throwExistingUnregisteredError","sourceToken","targetTokenOrError","isError","untag","stack","startsWith","substring","trimStart","createInjectionContext","current","provide","next","prev","use","invariant","KeyedStack","has","key","myKeys","peek","entry","myEntries","at","push","add","pop","delete","Array","WeakSet","WeakRefMap","get","ref","myMap","deref","set","WeakRef","WeakMap","createResolution","values","dependents","provideInjectionContext","useInjectionContext","ensureInjectionContext","fn","context","inject","container","resolve","injectBy","thisArg","resolution","currentFrame","currentRef","cleanup","provider","injectAll","resolveAll","getMetadata","Class","metadata","metadataMap","tokensRef","getRefTokens","Set","useClass","dependencies","methods","Map","optional","optionalBy","optionalAll","isClassProvider","isFactoryProvider","isValueProvider","isExistingProvider","Scope","Inherited","Transient","Resolution","Container","createType","typeName","type","inter","union","toString","isConstructor","getTypeName","proto","Object","getPrototypeOf","prototype","constructor","TokenRegistry","parent","myParent","getAll","internal","internals","getAllFromParent","registration","registrations","deleteAll","tokens","from","keys","flat","clear","clearRegistrations","i","length","undefined","isBuilder","builders","build","factory","useFactory","options","scope","isDisposable","dispose","ContainerImpl","myChildren","myDisposed","myOptions","autoRegister","defaultScope","myTokenRegistry","registry","isDisposed","createChild","checkDisposed","clearCache","getCached","getAllCached","resetRegistry","isRegistered","registerClass","ctor","register","registerFactory","registerValue","useValue","registerAlias","targetToken","aliasTokens","alias","useExisting","args","eagerInstantiate","unregister","resolveRegistration","instantiateClass","map","filter","instance","child","disposedRefs","currRegistration","currProvider","resolveProviderValue","e","resolveScope","resolveScopedValue","dependentRef","cleanups","valueRef","resolveConstructorDependencies","injectDependencies","forEach","dependentFrame","ctorDeps","msg","sort","a","b","index","dep","tokenRef","getRefToken","decorator","methodDeps","method","bind","createContainer","AutoRegister","EagerInstantiate","forwardRef","tokenOrTokens","tokensArray","isArray","isTokensRef","isTokenRef","processDecoratedParameter","target","propertyKey","parameterIndex","Inject","Injectable","arg0","existingTokensRef","existingTokens","InjectAll","Optional","OptionalAll","Scoped","Injector","withCurrentContext","applyMiddleware","middlewares","composer","wrap","api","middleware"],"mappings":"AAEA;AACO,SAASA,MAAAA,CAAOC,SAAkB,EAAEC,OAAgC,EAAA;AACzE,IAAA,IAAI,CAACD,SAAAA,EAAW;AACd,QAAA,MAAME,eAAAA,GAAkB,OAAOD,OAAAA,KAAY,QAAA,GAAWA,OAAAA,GAAUA,OAAAA,EAAAA;QAChE,MAAM,IAAIE,MAAMC,GAAAA,CAAIF,eAAAA,CAAAA,CAAAA;AACtB;AACF;AAEA;AACO,SAASG,YAAYC,KAAY,EAAA;AACtC,IAAA,MAAM,IAAIC,SAAAA,CAAUH,GAAAA,CAAI,CAAC,iBAAiB,EAAEI,OAAOF,KAAAA,CAAAA,CAAAA,CAAQ,CAAA,CAAA;AAC7D;AAEA;AACO,SAASG,uBAAuBC,KAAY,EAAA;IACjD,MAAM,IAAIP,MAAMC,GAAAA,CAAI,CAAC,mBAAmB,EAAEM,KAAAA,CAAMC,IAAI,CAAA,CAAE,CAAA,CAAA;AACxD;AAEA;AACO,SAASC,8BAAAA,CAA+BC,WAAkB,EAAEC,kBAAiC,EAAA;AAClG,IAAA,IAAIb,UAAUG,GAAAA,CAAI,CAAC,mDAAmD,EAAES,WAAAA,CAAYF,IAAI,CAAA,CAAE,CAAA;AAE1F,IAAA,IAAII,QAAQD,kBAAAA,CAAAA,EAAqB;AAC/Bb,QAAAA,OAAAA,IAAW,CAAC,YA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,CAAgBlK,SAAoB,EAAEmK,WAAyB,EAAA;AAC7E,IAAA,MAAMC,QAAAA,GAA+B;QACnCrM,GAAAA,CAAAA,CAAII,GAAG,EAAEkM,IAAI,EAAA;;;;;AAKX,YAAA,MAAMxK,KAAK,SAAU,CAAC1B,GAAAA,CAAI,CAASsK,IAAI,CAACzI,SAAAA,CAAAA;;YAGxCA,SAAS,CAAC7B,GAAAA,CAAI,GAAGkM,IAAAA,CAAKxK,EAAAA,CAAAA;YACtB,OAAOuK,QAAAA;AACT;AACF,KAAA;IAEA,MAAME,GAAAA,GAAOtK,SAAAA,CAAUsK,GAAG,KAAK;AAAE,QAAA,GAAGtK;AAAU,KAAA;IAE9C,KAAK,MAAMuK,cAAcJ,WAAAA,CAAa;AACpCI,QAAAA,UAAAA,CAAWH,QAAAA,EAAUE,GAAAA,CAAAA;AACvB;IAEA,OAAOtK,SAAAA;AACT;;;;"}
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/errors.ts","../../src/utils/context.ts","../../src/utils/invariant.ts","../../src/utils/keyedStack.ts","../../src/utils/weakRefMap.ts","../../src/injectionContext.ts","../../src/inject.ts","../../src/injectAll.ts","../../src/metadata.ts","../../src/optional.ts","../../src/optionalAll.ts","../../src/provider.ts","../../src/scope.ts","../../src/token.ts","../../src/utils/typeName.ts","../../src/tokenRegistry.ts","../../src/utils/disposable.ts","../../src/containerImpl.ts","../../src/container.ts","../../src/decorators/autoRegister.ts","../../src/decorators/eagerInstantiate.ts","../../src/tokensRef.ts","../../src/decorators/decorators.ts","../../src/decorators/inject.ts","../../src/decorators/injectable.ts","../../src/decorators/injectAll.ts","../../src/decorators/optional.ts","../../src/decorators/optionalAll.ts","../../src/decorators/scoped.ts","../../src/injector.ts","../../src/middleware.ts"],"sourcesContent":["import type { Token } from \"./token\";\n\n// @internal\nexport function assert(condition: unknown, message: string | (() => string)): asserts condition {\n if (!condition) {\n const resolvedMessage = typeof message === \"string\" ? message : message();\n throw new Error(tag(resolvedMessage));\n }\n}\n\n// @internal\nexport function expectNever(value: never): never {\n throw new TypeError(tag(`unexpected value ${String(value)}`));\n}\n\n// @internal\nexport function throwUnregisteredError(token: Token): never {\n throw new Error(tag(`unregistered token ${token.name}`));\n}\n\n// @internal\nexport function throwExistingUnregisteredError(sourceToken: Token, targetTokenOrError: Token | Error): never {\n let message = tag(`token resolution error encountered while resolving ${sourceToken.name}`);\n\n if (isError(targetTokenOrError)) {\n message += `\\n [cause] ${untag(targetTokenOrError.message)}`;\n } else {\n message += `\\n [cause] the aliased token ${targetTokenOrError.name} is not registered`;\n }\n\n throw new Error(message);\n}\n\nfunction isError(value: any): value is Error {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return value && value.stack && value.message && typeof value.message === \"string\";\n}\n\nfunction tag(message: string): string {\n return `[di-wise-neo] ${message}`;\n}\n\nfunction untag(message: string): string {\n return message.startsWith(\"[di-wise-neo]\") //\n ? message.substring(13).trimStart()\n : message;\n}\n","// @internal\nexport function createInjectionContext<T extends {}>(): readonly [\n (next: T) => () => T | null,\n () => T | null,\n] {\n let current: T | null = null;\n\n function provide(next: T): () => T | null {\n const prev = current;\n current = next;\n return () => (current = prev);\n }\n\n function use(): T | null {\n return current;\n }\n\n return [provide, use] as const;\n}\n","// @internal\nexport function invariant(condition: unknown): asserts condition {\n if (!condition) {\n throw new Error(\"invariant violation\");\n }\n}\n","import { invariant } from \"./invariant\";\n\n// @internal\nexport class KeyedStack<K extends object, V> {\n private readonly myEntries = new Array<{ key: K; value: V }>();\n private readonly myKeys = new WeakSet<K>();\n\n has(key: K): boolean {\n return this.myKeys.has(key);\n }\n\n peek(): V | undefined {\n const entry = this.myEntries.at(-1);\n return entry?.value;\n }\n\n push(key: K, value: V): () => void {\n invariant(!this.has(key));\n this.myKeys.add(key);\n this.myEntries.push({ key, value });\n return () => {\n this.myEntries.pop();\n this.myKeys.delete(key);\n };\n }\n}\n","import { invariant } from \"./invariant\";\n\n// @internal\nexport class WeakRefMap<K extends WeakKey, V extends object> {\n private readonly myMap = new WeakMap<K, WeakRef<V>>();\n\n get(key: K): V | undefined {\n const ref = this.myMap.get(key);\n\n if (ref) {\n const value = ref.deref();\n\n if (value) {\n return value;\n }\n\n this.myMap.delete(key);\n }\n }\n\n set(key: K, value: V): () => void {\n invariant(!this.get(key));\n this.myMap.set(key, new WeakRef(value));\n return () => {\n this.myMap.delete(key);\n };\n }\n}\n","import type { Container } from \"./container\";\nimport { assert } from \"./errors\";\nimport type { Provider } from \"./provider\";\nimport type { Scope } from \"./scope\";\nimport { createInjectionContext } from \"./utils/context\";\nimport { KeyedStack } from \"./utils/keyedStack\";\nimport { WeakRefMap } from \"./utils/weakRefMap\";\nimport type { ValueRef } from \"./valueRef\";\n\n// @internal\nexport interface ResolutionFrame {\n readonly scope: Exclude<Scope, typeof Scope.Inherited>;\n readonly provider: Provider;\n}\n\n// @internal\nexport interface Resolution {\n readonly stack: KeyedStack<Provider, ResolutionFrame>;\n readonly values: WeakRefMap<Provider, ValueRef>;\n readonly dependents: WeakRefMap<Provider, ValueRef>;\n}\n\n// @internal\nexport interface InjectionContext {\n readonly container: Container;\n readonly resolution: Resolution;\n}\n\n// @internal\nexport function createResolution(): Resolution {\n return {\n stack: new KeyedStack(),\n values: new WeakRefMap(),\n dependents: new WeakRefMap(),\n };\n}\n\n// @internal\nexport const [provideInjectionContext, useInjectionContext] = createInjectionContext<InjectionContext>();\n\n// @internal\nexport function ensureInjectionContext(fn: Function): InjectionContext {\n const context = useInjectionContext();\n assert(context, `${fn.name}() can only be invoked within an injection context`);\n return context;\n}\n","import { ensureInjectionContext } from \"./injectionContext\";\nimport type { Constructor, Token } from \"./token\";\n\n/**\n * Injects the instance associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\nexport function inject<Instance extends object>(Class: Constructor<Instance>): Instance;\n\n/**\n * Injects the value associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\nexport function inject<Value>(token: Token<Value>): Value;\n\nexport function inject<T>(token: Token<T>): T {\n const context = ensureInjectionContext(inject);\n return context.container.resolve(token);\n}\n\n/**\n * Injects the instance associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n *\n * Compared to {@link inject}, `injectBy` accepts a `thisArg` argument\n * (the containing class) which is used to resolve circular dependencies.\n *\n * @example\n * ```ts\n * class Wand {\n * owner = inject(Wizard);\n * }\n *\n * class Wizard {\n * wand = injectBy(this, Wand);\n * }\n * ```\n *\n * @param thisArg - The containing instance, used to help resolve circular dependencies.\n * @param Class - The class to resolve.\n */\nexport function injectBy<Instance extends object>(thisArg: any, Class: Constructor<Instance>): Instance;\n\n/**\n * Injects the value associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n *\n * Compared to {@link inject}, `injectBy` accepts a `thisArg` argument\n * (the containing class) which is used to resolve circular dependencies.\n *\n * @example\n * ```ts\n * class Wand {\n * owner = inject(Wizard);\n * }\n *\n * class Wizard {\n * wand = injectBy(this, Wand);\n * }\n * ```\n *\n * @param thisArg - The containing instance, used to help resolve circular dependencies.\n * @param token - The token to resolve.\n */\nexport function injectBy<Value>(thisArg: any, token: Token<Value>): Value;\n\nexport function injectBy<T>(thisArg: any, token: Token<T>): T {\n const context = ensureInjectionContext(injectBy);\n const resolution = context.resolution;\n const currentFrame = resolution.stack.peek();\n\n if (!currentFrame) {\n return inject(token);\n }\n\n const currentRef = { current: thisArg };\n const cleanup = resolution.dependents.set(currentFrame.provider, currentRef);\n\n try {\n return inject(token);\n } finally {\n cleanup();\n }\n}\n","import { ensureInjectionContext } from \"./injectionContext\";\nimport type { Constructor, Token } from \"./token\";\n\n/**\n * Injects all instances provided by the registrations associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\nexport function injectAll<Instance extends object>(Class: Constructor<Instance>): Instance[];\n\n/**\n * Injects all values provided by the registrations associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\nexport function injectAll<Value>(token: Token<Value>): NonNullable<Value>[];\n\nexport function injectAll<T>(token: Token<T>): NonNullable<T>[] {\n const context = ensureInjectionContext(injectAll);\n return context.container.resolveAll(token);\n}\n","import type { ClassProvider } from \"./provider\";\nimport type { Scope } from \"./scope\";\nimport type { Constructor } from \"./token\";\nimport type { Dependencies } from \"./tokenRegistry\";\nimport type { TokensRef } from \"./tokensRef\";\n\n// @internal\nexport interface Metadata<This extends object = any> {\n eagerInstantiate?: boolean;\n autoRegister?: boolean;\n scope?: Scope;\n tokensRef: TokensRef<This>;\n provider: ClassProvider<This>;\n dependencies: Dependencies;\n}\n\n// @internal\nexport function getMetadata<T extends object>(Class: Constructor<T>): Metadata<T> {\n let metadata = metadataMap.get(Class);\n\n if (!metadata) {\n metadataMap.set(\n Class,\n (metadata = {\n tokensRef: {\n getRefTokens: () => new Set(),\n },\n provider: {\n useClass: Class,\n },\n dependencies: {\n constructor: [],\n methods: new Map(),\n },\n }),\n );\n }\n\n return metadata;\n}\n\nconst metadataMap = new WeakMap<Constructor<object>, Metadata>();\n","import { ensureInjectionContext } from \"./injectionContext\";\nimport type { Constructor, Token } from \"./token\";\n\n/**\n * Injects the instance associated with the given class,\n * or `undefined` if the class is not registered in the container.\n */\nexport function optional<Instance extends object>(Class: Constructor<Instance>): Instance | undefined;\n\n/**\n * Injects the value associated with the given token,\n * or `undefined` if the token is not registered in the container.\n */\nexport function optional<Value>(token: Token<Value>): Value | undefined;\n\nexport function optional<T>(token: Token<T>): T | undefined {\n const context = ensureInjectionContext(optional);\n return context.container.resolve(token, true);\n}\n\n/**\n * Injects the instance associated with the given class,\n * or `undefined` if the class is not registered in the container.\n *\n * Compared to {@link optional}, `optionalBy` accepts a `thisArg` argument\n * (the containing class) which is used to resolve circular dependencies.\n *\n * @param thisArg - The containing instance, used to help resolve circular dependencies.\n * @param Class - The class to resolve.\n */\nexport function optionalBy<Instance extends object>(\n thisArg: any,\n Class: Constructor<Instance>,\n): Instance | undefined;\n\n/**\n * Injects the value associated with the given token,\n * or `undefined` if the token is not registered in the container.\n *\n * Compared to {@link optional}, `optionalBy` accepts a `thisArg` argument\n * (the containing class) which is used to resolve circular dependencies.\n *\n * @param thisArg - The containing instance, used to help resolve circular dependencies.\n * @param token - The token to resolve.\n */\nexport function optionalBy<Value>(thisArg: any, token: Token<Value>): Value | undefined;\n\nexport function optionalBy<T>(thisArg: any, token: Token<T>): T | undefined {\n const context = ensureInjectionContext(optionalBy);\n const resolution = context.resolution;\n const currentFrame = resolution.stack.peek();\n\n if (!currentFrame) {\n return optional(token);\n }\n\n const currentRef = { current: thisArg };\n const cleanup = resolution.dependents.set(currentFrame.provider, currentRef);\n\n try {\n return optional(token);\n } finally {\n cleanup();\n }\n}\n","import { ensureInjectionContext } from \"./injectionContext\";\nimport type { Constructor, Token } from \"./token\";\n\n/**\n * Injects all instances provided by the registrations associated with the given class,\n * or an empty array if the class is not registered in the container.\n */\nexport function optionalAll<Instance extends object>(Class: Constructor<Instance>): Instance[];\n\n/**\n * Injects all values provided by the registrations associated with the given token,\n * or an empty array if the token is not registered in the container.\n */\nexport function optionalAll<Value>(token: Token<Value>): NonNullable<Value>[];\n\nexport function optionalAll<T>(token: Token<T>): NonNullable<T>[] {\n const context = ensureInjectionContext(optionalAll);\n return context.container.resolveAll(token, true);\n}\n","import type { Constructor, Token } from \"./token\";\n\n/**\n * Provides a class instance for a token via a class constructor.\n */\nexport interface ClassProvider<Instance extends object> {\n readonly useClass: Constructor<Instance>;\n}\n\n/**\n * Provides a value for a token via a factory function.\n *\n * The factory function runs inside the injection context and can\n * thus access dependencies via {@link inject}-like functions.\n */\nexport interface FactoryProvider<Value> {\n readonly useFactory: (...args: []) => Value;\n}\n\n/**\n * Provides a static - already constructed - value for a token.\n */\nexport interface ValueProvider<T> {\n readonly useValue: T;\n}\n\n/**\n * Aliases another registered token.\n *\n * Resolving this token will return the value of the aliased one.\n */\nexport interface ExistingProvider<Value> {\n readonly useExisting: Token<Value>;\n}\n\n/**\n * A token provider.\n */\nexport type Provider<Value = any> =\n | ClassProvider<Value & object>\n | FactoryProvider<Value>\n | ValueProvider<Value>\n | ExistingProvider<Value>;\n\n// @internal\nexport function isClassProvider<T>(provider: Provider<T>): provider is ClassProvider<T & object> {\n return \"useClass\" in provider;\n}\n\n// @internal\nexport function isFactoryProvider<T>(provider: Provider<T>): provider is FactoryProvider<T> {\n return \"useFactory\" in provider;\n}\n\n// @internal\nexport function isValueProvider<T>(provider: Provider<T>): provider is ValueProvider<T> {\n return \"useValue\" in provider;\n}\n\n// @internal\nexport function isExistingProvider<T>(provider: Provider<T>): provider is ExistingProvider<T> {\n return \"useExisting\" in provider;\n}\n","export const Scope = {\n Inherited: \"Inherited\",\n Transient: \"Transient\",\n Resolution: \"Resolution\",\n Container: \"Container\",\n} as const;\n\nexport type Scope = (typeof Scope)[keyof typeof Scope];\n","/**\n * Type API.\n */\nexport interface Type<A> {\n /**\n * The name of the type.\n */\n readonly name: string;\n\n /**\n * Creates an intersection type from another type.\n *\n * @example\n * ```ts\n * const A = createType<A>(\"A\");\n * const B = createType<B>(\"B\");\n *\n * A.inter(\"I\", B); // => Type<A & B>\n * ```\n */\n inter<B>(typeName: string, B: Type<B>): Type<A & B>;\n\n /**\n * Creates a union type from another type.\n *\n * @example\n * ```ts\n * const A = createType<A>(\"A\");\n * const B = createType<B>(\"B\");\n *\n * A.union(\"U\", B); // => Type<A | B>\n * ```\n */\n union<B>(typeName: string, B: Type<B>): Type<A | B>;\n}\n\n/**\n * Constructor type.\n */\nexport interface Constructor<Instance extends object> {\n new (...args: any[]): Instance;\n readonly name: string;\n}\n\n/**\n * Token type.\n */\nexport type Token<Value = any> = [Value] extends [object] // Avoids distributive union behavior\n ? Type<Value> | Constructor<Value>\n : Type<Value>;\n\n/**\n * Describes a {@link Token} array with at least one element.\n */\nexport type Tokens<Value = any> = [Token<Value>, ...Token<Value>[]];\n\n/**\n * Creates a type token.\n *\n * @example\n * ```ts\n * const ISpell = createType<Spell>(\"Spell\");\n * ```\n *\n * @__NO_SIDE_EFFECTS__\n */\nexport function createType<T>(typeName: string): Type<T> {\n const type = {\n name: `Type<${typeName}>`,\n inter: createType,\n union: createType,\n toString(): string {\n return type.name;\n },\n };\n\n return type;\n}\n\n// @internal\nexport function isConstructor<T>(token: Type<T> | Constructor<T & object>): token is Constructor<T & object> {\n return typeof token == \"function\";\n}\n","// @internal\nexport function getTypeName(value: unknown): string {\n if (typeof value == \"string\") {\n return `\"${value}\"`;\n }\n\n if (typeof value == \"function\") {\n return (value.name && `typeof ${value.name}`) || \"Function\";\n }\n\n if (typeof value == \"object\") {\n if (value === null) {\n return \"null\";\n }\n\n const proto: object | null = Object.getPrototypeOf(value);\n\n if (proto && proto !== Object.prototype) {\n const constructor: unknown = proto.constructor;\n\n if (typeof constructor == \"function\" && constructor.name) {\n return constructor.name;\n }\n }\n }\n\n return typeof value;\n}\n","import { assert } from \"./errors\";\nimport type { FactoryProvider, Provider } from \"./provider\";\nimport { Scope } from \"./scope\";\nimport { type Constructor, createType, type Token, type Type } from \"./token\";\nimport type { TokenRef } from \"./tokensRef\";\nimport { getTypeName } from \"./utils/typeName\";\nimport type { ValueRef } from \"./valueRef\";\n\n/**\n * Token registration options.\n */\nexport interface RegistrationOptions {\n /**\n * The scope of the registration.\n */\n readonly scope?: Scope;\n}\n\n// @internal\nexport type Decorator = \"Inject\" | \"InjectAll\" | \"Optional\" | \"OptionalAll\";\n\n// @internal\nexport interface MethodDependency {\n readonly decorator: Decorator;\n readonly tokenRef: TokenRef;\n\n // The index of the annotated parameter (zero-based)\n readonly index: number;\n}\n\n// @internal\nexport interface Dependencies {\n readonly constructor: MethodDependency[];\n readonly methods: Map<string | symbol, MethodDependency[]>;\n}\n\n// @internal\nexport interface Registration<T = any> {\n value?: ValueRef<T>;\n readonly provider: Provider<T>;\n readonly options?: RegistrationOptions;\n readonly dependencies?: Dependencies;\n}\n\n// @internal\nexport class TokenRegistry {\n private readonly myParent?: TokenRegistry;\n private readonly myMap = new Map<Token, Registration[]>();\n\n constructor(parent: TokenRegistry | undefined) {\n this.myParent = parent;\n }\n\n get<T>(token: Token<T>): Registration<T> | undefined {\n // To clarify, at(-1) means we take the last added registration for this token\n return this.getAll(token)?.at(-1);\n }\n\n getAll<T>(token: Token<T>): Registration<T>[] | undefined {\n const internal = internals.get(token);\n return (internal && [internal]) || this.getAllFromParent(token);\n }\n\n //\n // set(...) overloads added because of TS distributive conditional types.\n //\n // TODO(Edoardo): is there a better way? Maybe refactor the Token<T> type\n // into two types, TokenObject<T extends object> | Token<T>\n //\n\n set<T extends object>(token: Type<T> | Constructor<T>, registration: Registration<T>): void;\n set<T>(token: Token<T>, registration: Registration<T>): void;\n set<T>(token: Token<T>, registration: Registration<T>): void {\n assert(!internals.has(token), `cannot register reserved token ${token.name}`);\n\n let registrations = this.myMap.get(token);\n\n if (!registrations) {\n this.myMap.set(token, (registrations = []));\n }\n\n registrations.push(registration);\n }\n\n delete<T>(token: Token<T>): Registration<T>[] | undefined {\n const registrations = this.myMap.get(token);\n this.myMap.delete(token);\n return registrations;\n }\n\n deleteAll(): [Token[], Registration[]] {\n const tokens = Array.from(this.myMap.keys());\n const registrations = Array.from(this.myMap.values()).flat();\n this.myMap.clear();\n return [tokens, registrations];\n }\n\n clearRegistrations(): unknown[] {\n const values = new Set<unknown>();\n\n for (const registrations of this.myMap.values()) {\n for (let i = 0; i < registrations.length; i++) {\n const registration = registrations[i]!;\n const value = registration.value;\n\n if (value) {\n values.add(value.current);\n }\n\n registrations[i] = {\n ...registration,\n value: undefined,\n };\n }\n }\n\n return Array.from(values);\n }\n\n private getAllFromParent<T>(token: Token<T>): Registration<T>[] | undefined {\n const registrations = this.myMap.get(token);\n return registrations || this.myParent?.getAllFromParent(token);\n }\n}\n\n// @internal\nexport function isBuilder(provider: Provider): boolean {\n return builders.has(provider);\n}\n\n/**\n * Create a one-off type token from a factory function.\n *\n * @example\n * ```ts\n * class Wizard {\n * wand = inject(\n * build(() => {\n * const wand = inject(Wand);\n * wand.owner = this;\n * // ...\n * return wand;\n * }),\n * );\n * }\n * ```\n *\n * @__NO_SIDE_EFFECTS__\n */\nexport function build<Value>(factory: (...args: []) => Value): Type<Value> {\n const token = createType<Value>(`Build<${getTypeName(factory)}>`);\n const provider: FactoryProvider<Value> = {\n useFactory: factory,\n };\n\n internals.set(token, {\n provider: provider,\n options: {\n scope: Scope.Transient,\n },\n });\n\n builders.add(provider);\n return token;\n}\n\nconst internals = new WeakMap<Token, Registration>();\nconst builders = new WeakSet<Provider>();\n","// @internal\nexport interface Disposable {\n dispose(): void;\n}\n\n// @internal\nexport function isDisposable(value: any): value is Disposable {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return value && typeof value === \"object\" && typeof value.dispose === \"function\";\n}\n","import type { Container, ContainerOptions } from \"./container\";\nimport { assert, expectNever, throwExistingUnregisteredError, throwUnregisteredError } from \"./errors\";\nimport { injectBy } from \"./inject\";\nimport { injectAll } from \"./injectAll\";\nimport { createResolution, provideInjectionContext, useInjectionContext } from \"./injectionContext\";\nimport { getMetadata } from \"./metadata\";\nimport { optionalBy } from \"./optional\";\nimport { optionalAll } from \"./optionalAll\";\nimport {\n isClassProvider,\n isExistingProvider,\n isFactoryProvider,\n isValueProvider,\n type Provider,\n} from \"./provider\";\nimport { Scope } from \"./scope\";\nimport { type Constructor, isConstructor, type Token, type Tokens } from \"./token\";\nimport { isBuilder, type Registration, type RegistrationOptions, TokenRegistry } from \"./tokenRegistry\";\nimport { isDisposable } from \"./utils/disposable\";\n\n/**\n * The default implementation of a di-wise-neo {@link Container}.\n */\nexport class ContainerImpl implements Container {\n private readonly myParent?: ContainerImpl;\n private readonly myChildren: Set<ContainerImpl> = new Set();\n private readonly myOptions: ContainerOptions;\n private readonly myTokenRegistry: TokenRegistry;\n private myDisposed: boolean = false;\n\n constructor(parent: ContainerImpl | undefined, options: Partial<ContainerOptions>) {\n this.myParent = parent;\n this.myOptions = {\n autoRegister: false,\n defaultScope: Scope.Inherited,\n ...options,\n };\n\n this.myTokenRegistry = new TokenRegistry(this.myParent?.myTokenRegistry);\n }\n\n get registry(): TokenRegistry {\n return this.myTokenRegistry;\n }\n\n get options(): ContainerOptions {\n return {\n ...this.myOptions,\n };\n }\n\n get parent(): Container | undefined {\n return this.myParent;\n }\n\n get isDisposed(): boolean {\n return this.myDisposed;\n }\n\n createChild(options?: Partial<ContainerOptions>): Container {\n this.checkDisposed();\n const container = new ContainerImpl(this, {\n ...this.myOptions,\n ...options,\n });\n\n this.myChildren.add(container);\n return container;\n }\n\n clearCache(): unknown[] {\n this.checkDisposed();\n return this.myTokenRegistry.clearRegistrations();\n }\n\n getCached<T>(token: Token<T>): T | undefined {\n this.checkDisposed();\n const registration = this.myTokenRegistry.get(token);\n return registration?.value?.current;\n }\n\n getAllCached<T>(token: Token<T>): T[] {\n this.checkDisposed();\n const registrations = this.myTokenRegistry.getAll(token);\n\n if (!registrations) {\n return [];\n }\n\n const values = new Set<T>();\n\n for (const registration of registrations) {\n const value = registration.value;\n\n if (value) {\n values.add(value.current);\n }\n }\n\n return Array.from(values);\n }\n\n resetRegistry(): unknown[] {\n this.checkDisposed();\n const [, registrations] = this.myTokenRegistry.deleteAll();\n const values = new Set<unknown>();\n\n for (const registration of registrations) {\n const value = registration.value;\n\n if (value) {\n values.add(value.current);\n }\n }\n\n return Array.from(values);\n }\n\n isRegistered(token: Token): boolean {\n this.checkDisposed();\n return this.myTokenRegistry.get(token) !== undefined;\n }\n\n registerClass<T extends object, V extends T>(\n token: Token<T>,\n Class?: Constructor<V>,\n options?: RegistrationOptions,\n ): void {\n // This mess will go away once/if we remove the register method\n // in favor of the multiple specialized ones\n if (Class) {\n const ctor = (Class ?? token) as Constructor<any>;\n this.register(token, { useClass: ctor }, options);\n } else {\n this.register(token as Constructor<any>);\n }\n }\n\n registerFactory<T, V extends T>(\n token: Token<T>,\n factory: (...args: []) => V,\n options?: RegistrationOptions,\n ): void {\n this.register(token, { useFactory: factory }, options);\n }\n\n registerValue<T, V extends T>(token: Token<T>, value: V): void {\n this.register(token, { useValue: value });\n }\n\n registerAlias<T, V extends T>(targetToken: Token<V>, aliasTokens: Tokens<T>): void {\n // De-duplicate tokens\n for (const alias of new Set(aliasTokens)) {\n this.register(alias, { useExisting: targetToken });\n }\n }\n\n register<T>(...args: [Constructor<T & object>] | [Token<T>, Provider<T>, RegistrationOptions?]): Container {\n this.checkDisposed();\n\n if (args.length == 1) {\n const Class = args[0];\n const metadata = getMetadata(Class);\n const registration: Registration = {\n // The provider is of type ClassProvider, initialized by getMetadata\n provider: metadata.provider,\n options: {\n scope: metadata.scope ?? this.myOptions.defaultScope,\n },\n dependencies: metadata.dependencies,\n };\n\n // Register the class itself\n this.myTokenRegistry.set(Class, registration);\n\n // Register the additional tokens specified via class decorators.\n // These tokens will point to the original Class token and will have the same scope.\n for (const token of metadata.tokensRef.getRefTokens()) {\n this.myTokenRegistry.set(token, {\n provider: {\n useExisting: Class,\n },\n });\n }\n\n // Eager-instantiate only if the class is container-scoped\n if (metadata.eagerInstantiate && registration.options?.scope === Scope.Container) {\n this.resolve(Class);\n }\n } else {\n const [token, provider, options] = args;\n\n if (isClassProvider(provider)) {\n const metadata = getMetadata(provider.useClass);\n const registration: Registration = {\n provider: metadata.provider,\n options: {\n // The explicit registration options override what is specified\n // via class decorators (e.g., @Scoped)\n scope: metadata.scope ?? this.myOptions.defaultScope,\n ...options,\n },\n dependencies: metadata.dependencies,\n };\n\n this.myTokenRegistry.set(token, registration);\n\n // Eager-instantiate only if the provided class is container-scoped\n if (metadata.eagerInstantiate && registration.options?.scope === Scope.Container) {\n this.resolve(token);\n }\n } else {\n if (isExistingProvider(provider)) {\n assert(\n token !== provider.useExisting,\n `the useExisting token ${token.name} cannot be the same as the token being registered`,\n );\n }\n\n this.myTokenRegistry.set(token, {\n provider: provider,\n options: options,\n });\n }\n }\n\n return this;\n }\n\n unregister<T>(token: Token<T>): T[] {\n this.checkDisposed();\n const registrations = this.myTokenRegistry.delete(token);\n\n if (!registrations) {\n return [];\n }\n\n const values = new Set<T>();\n\n for (const registration of registrations) {\n const value = registration.value;\n\n if (value) {\n values.add(value.current);\n }\n }\n\n return Array.from(values);\n }\n\n resolve<T>(token: Token<T>, optional?: boolean): T | undefined {\n this.checkDisposed();\n const registration = this.myTokenRegistry.get(token);\n\n if (registration) {\n return this.resolveRegistration(token, registration);\n }\n\n if (isConstructor(token)) {\n return this.instantiateClass(token, optional);\n }\n\n return optional ? undefined : throwUnregisteredError(token);\n }\n\n resolveAll<T>(token: Token<T>, optional?: boolean): NonNullable<T>[] {\n this.checkDisposed();\n const registrations = this.myTokenRegistry.getAll(token);\n\n if (registrations) {\n return registrations\n .map((registration) => this.resolveRegistration(token, registration))\n .filter((value) => value != null);\n }\n\n if (isConstructor(token)) {\n const instance = this.instantiateClass(token, optional);\n return instance === undefined // = could not resolve, but since it is optional\n ? []\n : [instance];\n }\n\n return optional ? [] : throwUnregisteredError(token);\n }\n\n dispose(): void {\n if (this.myDisposed) {\n return;\n }\n\n // Dispose children containers first\n for (const child of this.myChildren) {\n child.dispose();\n }\n\n this.myChildren.clear();\n\n // Remove ourselves from our parent container\n this.myParent?.myChildren?.delete(this);\n this.myDisposed = true;\n\n const [, registrations] = this.myTokenRegistry.deleteAll();\n const disposedRefs = new Set<any>();\n\n // Dispose all resolved (aka instantiated) tokens that implement the Disposable interface\n for (const registration of registrations) {\n const value = registration.value?.current;\n\n if (isDisposable(value) && !disposedRefs.has(value)) {\n disposedRefs.add(value);\n value.dispose();\n }\n }\n\n // Allow values to be GCed\n disposedRefs.clear();\n }\n\n private resolveRegistration<T>(token: Token<T>, registration: Registration<T>): T {\n let currRegistration: Registration<T> | undefined = registration;\n let currProvider = currRegistration.provider;\n\n while (isExistingProvider(currProvider)) {\n const targetToken = currProvider.useExisting;\n currRegistration = this.myTokenRegistry.get(targetToken);\n\n if (!currRegistration) {\n throwExistingUnregisteredError(token, targetToken);\n }\n\n currProvider = currRegistration.provider;\n }\n\n try {\n return this.resolveProviderValue(currRegistration, currProvider);\n } catch (e) {\n // If we were trying to resolve a token registered via ExistingProvider,\n // we must add the cause of the error to the message\n if (isExistingProvider(registration.provider)) {\n throwExistingUnregisteredError(token, e as Error);\n }\n\n throw e;\n }\n }\n\n private instantiateClass<T extends object>(Class: Constructor<T>, optional?: boolean): T | undefined {\n const metadata = getMetadata(Class);\n\n if (metadata.autoRegister ?? this.myOptions.autoRegister) {\n // Temporarily set eagerInstantiate to false to avoid resolving the class two times:\n // one inside register(), and the other just below\n const eagerInstantiate = metadata.eagerInstantiate;\n metadata.eagerInstantiate = false;\n\n try {\n this.register(Class);\n return (this as Container).resolve(Class);\n } finally {\n metadata.eagerInstantiate = eagerInstantiate;\n }\n }\n\n const scope = this.resolveScope(metadata.scope);\n\n if (optional && scope === Scope.Container) {\n // It would not be possible to resolve the class in container scope,\n // as that would require prior registration.\n // However, since resolution is marked optional, we simply return undefined.\n return undefined;\n }\n\n assert(\n scope !== Scope.Container,\n `unregistered class ${Class.name} cannot be resolved in container scope`,\n );\n\n const registration: Registration<T> = {\n provider: metadata.provider,\n options: {\n scope: scope,\n },\n dependencies: metadata.dependencies,\n };\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n return this.resolveScopedValue(registration, (args) => new Class(...args));\n }\n\n private resolveProviderValue<T>(registration: Registration<T>, provider: Provider<T>): T {\n assert(registration.provider === provider, \"internal error: mismatching provider\");\n\n if (isClassProvider(provider)) {\n const Class = provider.useClass;\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n return this.resolveScopedValue(registration, (args) => new Class(...args));\n }\n\n if (isFactoryProvider(provider)) {\n const factory = provider.useFactory;\n return this.resolveScopedValue(registration, factory);\n }\n\n if (isValueProvider(provider)) {\n return provider.useValue;\n }\n\n if (isExistingProvider(provider)) {\n assert(false, \"internal error: unexpected ExistingProvider\");\n }\n\n expectNever(provider);\n }\n\n private resolveScopedValue<T>(registration: Registration<T>, factory: (...args: any[]) => T): T {\n let context = useInjectionContext();\n\n if (!context || context.container !== this) {\n context = {\n container: this,\n resolution: createResolution(),\n };\n }\n\n const resolution = context.resolution;\n const provider = registration.provider;\n const options = registration.options;\n\n if (resolution.stack.has(provider)) {\n const dependentRef = resolution.dependents.get(provider);\n assert(dependentRef, \"circular dependency detected\");\n return dependentRef.current;\n }\n\n const scope = this.resolveScope(options?.scope, context);\n const cleanups = [\n provideInjectionContext(context),\n !isBuilder(provider) && resolution.stack.push(provider, { provider, scope }),\n ];\n\n try {\n switch (scope) {\n case Scope.Container: {\n const valueRef = registration.value;\n\n if (valueRef) {\n return valueRef.current;\n }\n\n const args = this.resolveConstructorDependencies(registration);\n const value = this.injectDependencies(registration, factory(args));\n registration.value = { current: value };\n return value;\n }\n case Scope.Resolution: {\n const valueRef = resolution.values.get(provider);\n\n if (valueRef) {\n return valueRef.current;\n }\n\n const args = this.resolveConstructorDependencies(registration);\n const value = this.injectDependencies(registration, factory(args));\n resolution.values.set(provider, { current: value });\n return value;\n }\n case Scope.Transient: {\n const args = this.resolveConstructorDependencies(registration);\n return this.injectDependencies(registration, factory(args));\n }\n }\n } finally {\n cleanups.forEach((cleanup) => cleanup && cleanup());\n }\n }\n\n private resolveScope(\n scope = this.myOptions.defaultScope,\n context = useInjectionContext(),\n ): Exclude<Scope, typeof Scope.Inherited> {\n if (scope == Scope.Inherited) {\n const dependentFrame = context?.resolution.stack.peek();\n return dependentFrame?.scope || Scope.Transient;\n }\n\n return scope;\n }\n\n private resolveConstructorDependencies<T>(registration: Registration<T>): any[] {\n const dependencies = registration.dependencies;\n\n if (dependencies) {\n assert(isClassProvider(registration.provider), `internal error: not a ClassProvider`);\n const ctorDeps = dependencies.constructor;\n\n if (ctorDeps.length > 0) {\n // Let's check if all necessary constructor parameters are decorated.\n // If not, we cannot safely create an instance.\n const ctor = registration.provider.useClass;\n assert(ctor.length === ctorDeps.length, () => {\n const msg = `expected ${ctor.length} decorated constructor parameters in ${ctor.name}`;\n return msg + `, but found ${ctorDeps.length}`;\n });\n\n return ctorDeps\n .sort((a, b) => a.index - b.index)\n .map((dep) => {\n const token = dep.tokenRef.getRefToken();\n switch (dep.decorator) {\n case \"Inject\":\n return this.resolve(token);\n case \"InjectAll\":\n return this.resolveAll(token);\n case \"Optional\":\n return this.resolve(token, true);\n case \"OptionalAll\":\n return this.resolveAll(token, true);\n }\n });\n }\n }\n\n return [];\n }\n\n private injectDependencies<T>(registration: Registration<T>, instance: T): T {\n const dependencies = registration.dependencies;\n\n if (dependencies) {\n assert(isClassProvider(registration.provider), `internal error: not a ClassProvider`);\n const ctor = registration.provider.useClass;\n\n // Perform method injection\n for (const [key, methodDeps] of dependencies.methods) {\n // Let's check if all necessary method parameters are decorated.\n // If not, we cannot safely invoke the method.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const method = (instance as any)[key] as Function;\n assert(methodDeps.length === method.length, () => {\n const msg = `expected ${method.length} decorated method parameters`;\n return msg + ` in ${ctor.name}.${String(key)}, but found ${methodDeps.length}`;\n });\n\n const args = methodDeps\n .sort((a, b) => a.index - b.index)\n .map((dep) => {\n const token = dep.tokenRef.getRefToken();\n switch (dep.decorator) {\n case \"Inject\":\n return injectBy(instance, token);\n case \"InjectAll\":\n return injectAll(token);\n case \"Optional\":\n return optionalBy(instance, token);\n case \"OptionalAll\":\n return optionalAll(token);\n }\n });\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n method.bind(instance)(...args);\n }\n }\n\n return instance;\n }\n\n private checkDisposed(): void {\n assert(!this.myDisposed, \"the container is disposed\");\n }\n}\n","import { ContainerImpl } from \"./containerImpl\";\nimport type { ClassProvider, ExistingProvider, FactoryProvider, ValueProvider } from \"./provider\";\nimport { Scope } from \"./scope\";\nimport type { Constructor, Token, Tokens } from \"./token\";\nimport type { RegistrationOptions, TokenRegistry } from \"./tokenRegistry\";\n\n/**\n * Container creation options.\n */\nexport interface ContainerOptions {\n /**\n * Whether to automatically register an unregistered class when resolving it as a token.\n *\n * @defaultValue false\n */\n readonly autoRegister: boolean;\n\n /**\n * The default scope for registrations.\n *\n * @defaultValue Scope.Inherited\n */\n readonly defaultScope: Scope;\n}\n\n/**\n * Container API.\n */\nexport interface Container {\n /**\n * @internal\n */\n api?: Readonly<Container>;\n\n /**\n * @internal\n */\n readonly registry: TokenRegistry;\n\n /**\n * The options used to create this container.\n */\n readonly options: ContainerOptions;\n\n /**\n * The parent container, or `undefined` if this is the root container.\n */\n readonly parent: Container | undefined;\n\n /**\n * Whether this container is disposed.\n */\n readonly isDisposed: boolean;\n\n /**\n * Creates a new child container that inherits this container's options.\n *\n * You can pass specific options to override the inherited ones.\n */\n createChild(options?: Partial<ContainerOptions>): Container;\n\n /**\n * Clears and returns all distinct cached values from this container's internal registry.\n * Values from {@link ValueProvider} registrations are not included, as they are never cached.\n *\n * Note that only this container is affected. Parent containers, if any, remain unchanged.\n */\n clearCache(): unknown[];\n\n /**\n * Returns the cached value from the most recent registration of the token,\n * or `undefined` if no value has been cached yet (the token has not been resolved yet).\n *\n * If the token has at least one registration in this container,\n * the cached value is taken from the most recent of those registrations.\n * Otherwise, it may be retrieved from parent containers, if any.\n *\n * Values are never cached for tokens with _transient_ or _resolution_ scope,\n * or for {@link ValueProvider} registrations.\n */\n getCached<Value>(token: Token<Value>): Value | undefined;\n\n /**\n * Returns all cached values associated with registrations of the token,\n * in the order they were registered, or an empty array if none have been cached.\n *\n * If the token has at least one registration in the current container,\n * cached values are taken from those registrations.\n * Otherwise, cached values may be retrieved from parent containers, if any.\n *\n * Values are never cached for tokens with _transient_ or _resolution_ scope,\n * or for {@link ValueProvider} registrations.\n */\n getAllCached<Value>(token: Token<Value>): Value[];\n\n /**\n * Removes all registrations from this container's internal registry.\n *\n * Returns an array of distinct cached values that were stored within the removed registrations.\n * Values from {@link ValueProvider} registrations are not included, as they are not cached.\n *\n * Note that only this container is affected. Parent containers, if any, remain unchanged.\n */\n resetRegistry(): unknown[];\n\n /**\n * Returns whether the token is registered in this container or in parent containers, if any.\n */\n isRegistered(token: Token): boolean;\n\n /**\n * Registers a concrete class, where the class acts as its own token.\n *\n * Tokens provided via the {@link Injectable} decorator applied to the class\n * are also registered as aliases.\n *\n * The default registration scope is determined by the {@link Scoped} decorator,\n * if present.\n */\n registerClass<Instance extends object>(Class: Constructor<Instance>): void;\n\n /**\n * Registers a concrete class with a token.\n *\n * The default registration scope is determined by the {@link Scoped} decorator\n * applied to the class, if present, but it can be overridden by passing explicit\n * registration options.\n */\n registerClass<Instance extends object, ProvidedInstance extends Instance>(\n token: Token<Instance>,\n Class: Constructor<ProvidedInstance>,\n options?: RegistrationOptions,\n ): void;\n\n /**\n * Registers a token whose value is produced by a factory function.\n *\n * The factory function runs inside the injection context and can\n * thus access dependencies via {@link inject}-like functions.\n */\n registerFactory<Value, ProvidedValue extends Value>(\n token: Token<Value>,\n factory: (...args: []) => ProvidedValue,\n options?: RegistrationOptions,\n ): void;\n\n /**\n * Registers a token with a fixed value.\n *\n * The provided value is returned as-is when the token is resolved (scopes do not apply).\n */\n registerValue<Value, ProvidedValue extends Value>(token: Token<Value>, value: ProvidedValue): void;\n\n /**\n * Registers one or more tokens as aliases for a target token.\n *\n * When an alias is resolved, the target token is resolved instead.\n */\n registerAlias<Value, ProvidedValue extends Value>(\n targetToken: Token<ProvidedValue>,\n aliasTokens: Tokens<Value>,\n ): void;\n\n /**\n * Registers a {@link ClassProvider}, using the class itself as its token.\n *\n * Tokens provided via the {@link Injectable} decorator applied to the class\n * are also registered as aliases.\n *\n * The scope is determined by the {@link Scoped} decorator, if present.\n *\n * @see registerClass\n */\n register<Instance extends object>(Class: Constructor<Instance>): Container;\n\n /**\n * Registers a {@link ClassProvider} with a token.\n *\n * The default registration scope is determined by the {@link Scoped} decorator\n * applied to the provided class, if present, but it can be overridden by\n * passing explicit registration options.\n *\n * @see registerClass\n */\n register<Instance extends object, ProviderInstance extends Instance>(\n token: Token<Instance>,\n provider: ClassProvider<ProviderInstance>,\n options?: RegistrationOptions,\n ): Container;\n\n /**\n * Registers a {@link FactoryProvider} with a token.\n *\n * @see registerFactory\n */\n register<Value, ProviderValue extends Value>(\n token: Token<Value>,\n provider: FactoryProvider<ProviderValue>,\n options?: RegistrationOptions,\n ): Container;\n\n /**\n * Registers an {@link ExistingProvider} with a token.\n *\n * The token will alias the one set in `useExisting`.\n *\n * @see registerAlias\n */\n register<Value, ProviderValue extends Value>(\n token: Token<Value>,\n provider: ExistingProvider<ProviderValue>,\n ): Container;\n\n /**\n * Registers a {@link ValueProvider} with a token.\n *\n * Values provided via `useValue` are never cached (scopes do not apply)\n * and are simply returned as-is.\n *\n * @see registerValue\n */\n register<Value, ProviderValue extends Value>(\n token: Token<Value>,\n provider: ValueProvider<ProviderValue>,\n ): Container;\n\n /**\n * Removes all registrations for the given token from the container's internal registry.\n *\n * Returns an array of distinct cached values that were stored within the removed registrations.\n * Values from {@link ValueProvider} registrations are not included, as they are not cached.\n *\n * Note that only this container is affected. Parent containers, if any, remain unchanged.\n */\n unregister<Value>(token: Token<Value>): Value[];\n\n /**\n * Resolves the given class to the instance associated with it.\n *\n * If the class is registered in this container or any of its parent containers,\n * an instance is created using the most recent registration.\n *\n * If the class is not registered, but it is decorated with {@link AutoRegister},\n * or {@link ContainerOptions.autoRegister} is true, the class is registered automatically.\n * Otherwise, resolution fails.\n * The scope for the automatic registration is determined by either\n * the {@link Scoped} decorator on the class, or {@link ContainerOptions.defaultScope}.\n *\n * If `optional` is false or is not passed and the class is not registered in the container\n * (and could not be auto-registered), an error is thrown.\n * Otherwise, if `optional` is true, `undefined` is returned.\n *\n * The resolution behavior depends on the {@link Provider} used during registration:\n * - For {@link ValueProvider}, the explicitly provided instance is returned.\n * - For {@link FactoryProvider}, the factory function is invoked to create the instance.\n * - For {@link ClassProvider}, a new instance of the class is created according to its scope.\n * - For {@link ExistingProvider}, the instance is resolved by referring to another registered token.\n *\n * If the class is registered with _container_ scope, the resolved instance is cached\n * in the container's internal registry.\n */\n resolve<Instance extends object>(Class: Constructor<Instance>, optional?: false): Instance;\n resolve<Instance extends object>(Class: Constructor<Instance>, optional: true): Instance | undefined;\n resolve<Instance extends object>(Class: Constructor<Instance>, optional?: boolean): Instance | undefined;\n\n /**\n * Resolves the given token to the value associated with it.\n *\n * If the token is registered in this container or any of its parent containers,\n * its value is resolved using the most recent registration.\n *\n * If `optional` is false or not passed and the token is not registered in the container,\n * an error is thrown. Otherwise, if `optional` is true, `undefined` is returned.\n *\n * The resolution behavior depends on the {@link Provider} used during registration:\n * - For {@link ValueProvider}, the explicitly provided value is returned.\n * - For {@link FactoryProvider}, the factory function is invoked to create the value.\n * - For {@link ClassProvider}, a new instance of the class is created according to its scope.\n * - For {@link ExistingProvider}, the value is resolved by referring to another registered token.\n *\n * If the token is registered with _container_ scope, the resolved value is cached\n * in the container's internal registry.\n */\n resolve<Value>(token: Token<Value>, optional?: false): Value;\n resolve<Value>(token: Token<Value>, optional: true): Value | undefined;\n resolve<Value>(token: Token<Value>, optional?: boolean): Value | undefined;\n\n /**\n * Resolves the given class to all instances provided by the registrations associated with it.\n *\n * If the class is not registered, but it is decorated with {@link AutoRegister},\n * or {@link ContainerOptions.autoRegister} is true, the class is registered automatically.\n * Otherwise, resolution fails.\n * The scope for the automatic registration is determined by either\n * the {@link Scoped} decorator on the class, or {@link ContainerOptions.defaultScope}.\n *\n * If `optional` is false or is not passed and the class is not registered in the container\n * (and could not be auto-registered), an error is thrown.\n * Otherwise, if `optional` is true, an empty array is returned.\n *\n * The resolution behavior depends on the {@link Provider} used during registration:\n * - For {@link ValueProvider}, the explicitly provided instance is returned.\n * - For {@link FactoryProvider}, the factory function is invoked to create the instance.\n * - For {@link ClassProvider}, a new instance of the class is created according to its scope.\n * - For {@link ExistingProvider}, the instance is resolved by referring to another registered token.\n *\n * If the class is registered with _container_ scope, the resolved instances are cached\n * in the container's internal registry.\n *\n * A separate instance of the class is created for each provider.\n *\n * @see The documentation for `resolve(Class: Constructor)`\n */\n resolveAll<Instance extends object>(Class: Constructor<Instance>, optional?: false): Instance[];\n resolveAll<Instance extends object>(Class: Constructor<Instance>, optional: true): Instance[];\n resolveAll<Instance extends object>(Class: Constructor<Instance>, optional?: boolean): Instance[];\n\n /**\n * Resolves the given token to all values provided by the registrations associated with it.\n *\n * If `optional` is false or not passed and the token is not registered in the container,\n * an error is thrown. Otherwise, if `optional` is true, an empty array is returned.\n *\n * The resolution behavior depends on the {@link Provider} used during registration:\n * - For {@link ValueProvider}, the explicitly provided value is returned.\n * - For {@link FactoryProvider}, the factory function is invoked to create the value.\n * - For {@link ClassProvider}, a new instance of the class is created according to its scope.\n * - For {@link ExistingProvider}, the value is resolved by referring to another registered token.\n *\n * If the token is registered with _container_ scope, the resolved values are cached\n * in the container's internal registry.\n *\n * @see The documentation for `resolve(token: Token)`\n */\n resolveAll<Value>(token: Token<Value>, optional?: false): NonNullable<Value>[];\n resolveAll<Value>(token: Token<Value>, optional: true): NonNullable<Value>[];\n resolveAll<Value>(token: Token<Value>, optional?: boolean): NonNullable<Value>[];\n\n /**\n * Disposes this container and all its cached values.\n *\n * Token values implementing a `Disposable` interface (e.g., objects with a `dispose()` function)\n * are automatically disposed during this process.\n *\n * Note that children containers are disposed first, in creation order.\n */\n dispose(): void;\n}\n\n/**\n * Creates a new container.\n */\nexport function createContainer(\n options: Partial<ContainerOptions> = {\n autoRegister: false,\n defaultScope: Scope.Inherited,\n },\n): Container {\n return new ContainerImpl(undefined, options);\n}\n","import { getMetadata } from \"../metadata\";\nimport type { Constructor } from \"../token\";\n\n/**\n * Class decorator that enables auto-registration of an unregistered class,\n * when the class is first resolved from the container.\n *\n * @example\n * ```ts\n * @AutoRegister\n * class Wizard {}\n *\n * const wizard = container.resolve(Wizard);\n * container.isRegistered(Wizard); // => true\n * ```\n *\n * @__NO_SIDE_EFFECTS__\n */\nexport function AutoRegister<Ctor extends Constructor<any>>(Class: Ctor): void {\n const metadata = getMetadata(Class);\n metadata.autoRegister = true;\n}\n","import { getMetadata } from \"../metadata\";\nimport type { Constructor } from \"../token\";\n\n/**\n * Class decorator that enables eager instantiation of a class when it is registered\n * in the container with `Scope.Container`.\n *\n * This causes the container to immediately create and cache the instance of the class,\n * instead of deferring instantiation until the first resolution.\n *\n * @example\n * ```ts\n * @EagerInstantiate\n * @Scoped(Scope.Container)\n * class Wizard {}\n *\n * // A Wizard instance is immediately created and cached by the container\n * const wizard = container.register(Wizard);\n * ```\n *\n * @__NO_SIDE_EFFECTS__\n */\nexport function EagerInstantiate<Ctor extends Constructor<any>>(Class: Ctor): void {\n const metadata = getMetadata(Class);\n metadata.eagerInstantiate = true;\n}\n","import { assert } from \"./errors\";\nimport type { Token, Tokens } from \"./token\";\n\nexport interface TokensRef<Value = any> {\n readonly getRefTokens: () => Set<Token<Value>>;\n}\n\nexport interface TokenRef<Value = any> {\n readonly getRefToken: () => Token<Value>;\n}\n\n/**\n * Allows referencing tokens that are declared later in the file by wrapping them\n * in a lazily evaluated function.\n */\nexport function forwardRef<Value>(token: () => Tokens<Value>): TokensRef<Value>;\n\n/**\n * Allows referencing a token that is declared later in the file by wrapping it\n * in a lazily evaluated function.\n */\nexport function forwardRef<Value>(token: () => Token<Value>): TokenRef<Value>;\n\nexport function forwardRef<Value>(\n token: () => Token<Value> | Tokens<Value>,\n): TokensRef<Value> & TokenRef<Value> {\n return {\n getRefTokens: (): Set<Token<Value>> => {\n // Normalize the single token here, so that we don't have\n // to do it at every getRefTokens call site\n const tokenOrTokens = token();\n const tokensArray = Array.isArray(tokenOrTokens) ? tokenOrTokens : [tokenOrTokens];\n return new Set(tokensArray);\n },\n getRefToken: () => {\n const tokenOrTokens = token();\n assert(!Array.isArray(tokenOrTokens), \"internal error: ref tokens should be a single token\");\n return tokenOrTokens;\n },\n };\n}\n\n// @internal\nexport function isTokensRef(value: any): value is TokensRef {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return value && typeof value === \"object\" && typeof value.getRefTokens === \"function\";\n}\n\n// @internal\nexport function isTokenRef(value: any): value is TokenRef {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return value && typeof value === \"object\" && typeof value.getRefToken === \"function\";\n}\n","import { assert } from \"../errors\";\nimport { getMetadata } from \"../metadata\";\nimport type { Constructor, Token } from \"../token\";\nimport type { Decorator } from \"../tokenRegistry\";\nimport { forwardRef, isTokenRef, type TokenRef } from \"../tokensRef\";\n\nexport function processDecoratedParameter(\n decorator: Decorator,\n token: Token | TokenRef,\n target: object,\n propertyKey: string | symbol | undefined,\n parameterIndex: number,\n): void {\n // Error out immediately if the decorator has been applied\n // to a static property or a static method\n if (propertyKey !== undefined && typeof target === \"function\") {\n assert(false, `@${decorator} cannot be used on static member ${target.name}.${String(propertyKey)}`);\n }\n\n const tokenRef = isTokenRef(token) ? token : forwardRef(() => token);\n\n if (propertyKey === undefined) {\n // Constructor\n const metadata = getMetadata(target as Constructor<any>);\n metadata.dependencies.constructor.push({\n decorator: decorator,\n tokenRef: tokenRef,\n index: parameterIndex,\n });\n } else {\n // Normal instance method\n const metadata = getMetadata(target.constructor as Constructor<any>);\n const methods = metadata.dependencies.methods;\n let dep = methods.get(propertyKey);\n\n if (dep === undefined) {\n dep = [];\n methods.set(propertyKey, dep);\n }\n\n dep.push({\n decorator: decorator,\n tokenRef: tokenRef,\n index: parameterIndex,\n });\n }\n}\n","import type { Constructor, Token } from \"../token\";\nimport type { TokenRef } from \"../tokensRef\";\nimport { processDecoratedParameter } from \"./decorators\";\n\n/**\n * Parameter decorator that injects the instance associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\nexport function Inject<Instance extends object>(Class: Constructor<Instance>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects the value associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\nexport function Inject<Value>(token: Token<Value>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects the value associated with the given token.\n *\n * Allows referencing a token that is declared later in the file by using\n * the {@link forwardRef} helper function.\n *\n * Throws an error if the token is not registered in the container.\n *\n * @example\n * ```ts\n * class Wizard {\n * constructor(@Inject(forwardRef(() => Wand)) readonly wand: Wand) {}\n * }\n * // Other code...\n * class Wand {}\n * ```\n */\nexport function Inject<Value>(tokens: TokenRef<Value>): ParameterDecorator;\n\nexport function Inject<T>(token: Token<T> | TokenRef<T>): ParameterDecorator {\n return function (target, propertyKey, parameterIndex: number): void {\n processDecoratedParameter(\"Inject\", token, target, propertyKey, parameterIndex);\n };\n}\n","import { getMetadata } from \"../metadata\";\nimport type { Constructor, Tokens } from \"../token\";\nimport { forwardRef, isTokensRef, type TokenRef, type TokensRef } from \"../tokensRef\";\n\n/**\n * Class decorator that registers additional aliasing tokens for the decorated type,\n * when the type is first registered in the container.\n *\n * The container uses {@link ExistingProvider} under the hood.\n *\n * @example\n * ```ts\n * @Injectable(Weapon)\n * class Wand {}\n * ```\n */\nexport function Injectable<This extends object, Value extends This>(...tokens: Tokens<Value>): ClassDecorator;\n\n/**\n * Class decorator that registers additional aliasing tokens for the decorated type,\n * when the type is first registered in the container.\n *\n * The container uses {@link ExistingProvider} under the hood.\n *\n * Allows referencing tokens that are declared later in the file by using\n * the {@link forwardRef} helper function.\n *\n * @example\n * ```ts\n * @Injectable(forwardRef() => Weapon) // Weapon is declared after Wand\n * class Wizard {}\n * // Other code...\n * class Weapon {}\n * ```\n */\nexport function Injectable<This extends object, Value extends This>(\n tokens: TokenRef<Value> | TokensRef<Value>,\n): ClassDecorator;\n\n/**\n * @__NO_SIDE_EFFECTS__\n */\nexport function Injectable(...args: unknown[]): ClassDecorator {\n return function (Class): void {\n const metadata = getMetadata(Class as any as Constructor<any>);\n const arg0 = args[0];\n const tokensRef = isTokensRef(arg0) ? arg0 : forwardRef(() => args as Tokens);\n const existingTokensRef = metadata.tokensRef;\n metadata.tokensRef = {\n getRefTokens: () => {\n const existingTokens = existingTokensRef.getRefTokens();\n\n for (const token of tokensRef.getRefTokens()) {\n existingTokens.add(token);\n }\n\n return existingTokens;\n },\n };\n };\n}\n","import type { Constructor, Token } from \"../token\";\nimport type { TokenRef } from \"../tokensRef\";\nimport { processDecoratedParameter } from \"./decorators\";\n\n/**\n * Parameter decorator that injects all instances provided by the registrations\n * associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\nexport function InjectAll<Instance extends object>(Class: Constructor<Instance>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects all values provided by the registrations\n * associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\nexport function InjectAll<Value>(token: Token<Value>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects all values provided by the registrations\n * associated with the given token.\n *\n * Allows referencing a token that is declared later in the file by using\n * the {@link forwardRef} helper function.\n *\n * Throws an error if the token is not registered in the container.\n *\n * @example\n * ```ts\n * class Wizard {\n * constructor(@InjectAll(forwardRef(() => Wand)) readonly wands: Wand[]) {}\n * }\n * // Other code...\n * class Wand {}\n * ```\n */\nexport function InjectAll<Value>(tokens: TokenRef<Value>): ParameterDecorator;\n\nexport function InjectAll<T>(token: Token<T> | TokenRef<T>): ParameterDecorator {\n return function (target, propertyKey, parameterIndex: number): void {\n processDecoratedParameter(\"InjectAll\", token, target, propertyKey, parameterIndex);\n };\n}\n","import type { Constructor, Token } from \"../token\";\nimport type { TokenRef } from \"../tokensRef\";\nimport { processDecoratedParameter } from \"./decorators\";\n\n/**\n * Parameter decorator that injects the instance associated with the given class,\n * or `undefined` if the class is not registered in the container.\n */\nexport function Optional<Instance extends object>(Class: Constructor<Instance>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects the value associated with the given token,\n * or `undefined` if the token is not registered in the container.\n */\nexport function Optional<Value>(token: Token<Value>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects the value associated with the given token,\n * or `undefined` if the token is not registered in the container.\n *\n * Allows referencing a token that is declared later in the file by using\n * the {@link forwardRef} helper function.\n *\n * @example\n * ```ts\n * class Wizard {\n * constructor(@Optional(forwardRef(() => Wand)) readonly wand: Wand | undefined) {}\n * }\n * // Other code...\n * class Wand {}\n * ```\n */\nexport function Optional<Value>(tokens: TokenRef<Value>): ParameterDecorator;\n\nexport function Optional<T>(token: Token<T> | TokenRef<T>): ParameterDecorator {\n return function (target, propertyKey, parameterIndex: number): void {\n processDecoratedParameter(\"Optional\", token, target, propertyKey, parameterIndex);\n };\n}\n","import type { Constructor, Token } from \"../token\";\nimport type { TokenRef } from \"../tokensRef\";\nimport { processDecoratedParameter } from \"./decorators\";\n\n/**\n * Parameter decorator that injects all instances provided by the registrations\n * associated with the given class, or an empty array if the class is not registered\n * in the container.\n */\nexport function OptionalAll<Instance extends object>(Class: Constructor<Instance>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects all values provided by the registrations\n * associated with the given token, or an empty array if the token is not registered\n * in the container.\n */\nexport function OptionalAll<Value>(token: Token<Value>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects all values provided by the registrations\n * associated with the given token, or an empty array if the token is not registered\n * in the container.\n *\n * Allows referencing a token that is declared later in the file by using\n * the {@link forwardRef} helper function.\n *\n * @example\n * ```ts\n * class Wizard {\n * constructor(@OptionalAll(forwardRef(() => Wand)) readonly wands: Wand[]) {}\n * }\n * // Other code...\n * class Wand {}\n * ```\n */\nexport function OptionalAll<Value>(tokens: TokenRef<Value>): ParameterDecorator;\n\nexport function OptionalAll<T>(token: Token<T> | TokenRef<T>): ParameterDecorator {\n return function (target, propertyKey, parameterIndex: number): void {\n processDecoratedParameter(\"OptionalAll\", token, target, propertyKey, parameterIndex);\n };\n}\n","import { getMetadata } from \"../metadata\";\nimport type { Scope } from \"../scope\";\nimport type { Constructor } from \"../token\";\n\n/**\n * Class decorator for setting the scope of the decorated type when registering it.\n *\n * The scope set by this decorator can be overridden by explicit registration options, if provided.\n *\n * @example\n * ```ts\n * @Scoped(Scope.Container)\n * class Wizard {}\n *\n * container.register(Wizard);\n *\n * // Under the hood\n * container.register(\n * Wizard,\n * { useClass: Wizard },\n * { scope: Scope.Container },\n * );\n * ```\n *\n * @__NO_SIDE_EFFECTS__\n */\nexport function Scoped(scope: Scope): ClassDecorator {\n return function (Class): void {\n const metadata = getMetadata(Class as any as Constructor<any>);\n metadata.scope = scope;\n };\n}\n","import { inject } from \"./inject\";\nimport { injectAll } from \"./injectAll\";\nimport { ensureInjectionContext, provideInjectionContext, useInjectionContext } from \"./injectionContext\";\nimport { optional } from \"./optional\";\nimport { optionalAll } from \"./optionalAll\";\nimport type { Constructor, Token, Type } from \"./token\";\nimport { build } from \"./tokenRegistry\";\n\n/**\n * Injector API.\n */\nexport interface Injector {\n /**\n * Injects the instance associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\n inject<Instance extends object>(Class: Constructor<Instance>): Instance;\n\n /**\n * Injects the value associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\n inject<Value>(token: Token<Value>): Value;\n\n /**\n * Injects all instances provided by the registrations associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\n injectAll<Instance extends object>(Class: Constructor<Instance>): Instance[];\n\n /**\n * Injects all values provided by the registrations associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\n injectAll<Value>(token: Token<Value>): NonNullable<Value>[];\n\n /**\n * Injects the instance associated with the given class,\n * or `undefined` if the class is not registered in the container.\n */\n optional<Instance extends object>(Class: Constructor<Instance>): Instance | undefined;\n\n /**\n * Injects the value associated with the given token,\n * or `undefined` if the token is not registered in the container.\n */\n optional<Value>(token: Token<Value>): Value | undefined;\n\n /**\n * Injects all instances provided by the registrations associated with the given class,\n * or an empty array if the class is not registered in the container.\n */\n optionalAll<Instance extends object>(Class: Constructor<Instance>): Instance[];\n\n /**\n * Injects all values provided by the registrations associated with the given token,\n * or an empty array if the token is not registered in the container.\n */\n optionalAll<Value>(token: Token<Value>): NonNullable<Value>[];\n}\n\n/**\n * Injector token for dynamic injections.\n *\n * @example\n * ```ts\n * class Wizard {\n * private injector = inject(Injector);\n * private wand?: Wand;\n *\n * getWand(): Wand {\n * return (this.wand ??= this.injector.inject(Wand));\n * }\n * }\n *\n * const wizard = container.resolve(Wizard);\n * wizard.getWand(); // => Wand\n * ```\n */\nexport const Injector: Type<Injector> = /*@__PURE__*/ build(function Injector() {\n const context = ensureInjectionContext(Injector);\n const resolution = context.resolution;\n\n const dependentFrame = resolution.stack.peek();\n const dependentRef = dependentFrame && resolution.dependents.get(dependentFrame.provider);\n\n function withCurrentContext<R>(fn: () => R): R {\n if (useInjectionContext()) {\n return fn();\n }\n\n const cleanups = [\n provideInjectionContext(context),\n dependentFrame && resolution.stack.push(dependentFrame.provider, dependentFrame),\n dependentRef && resolution.dependents.set(dependentFrame.provider, dependentRef),\n ];\n\n try {\n return fn();\n } finally {\n for (const cleanup of cleanups) {\n cleanup?.();\n }\n }\n }\n\n return {\n inject: <T>(token: Token<T>) => withCurrentContext(() => inject(token)),\n injectAll: <T>(token: Token<T>) => withCurrentContext(() => injectAll(token)),\n optional: <T>(token: Token<T>) => withCurrentContext(() => optional(token)),\n optionalAll: <T>(token: Token<T>) => withCurrentContext(() => optionalAll(token)),\n };\n});\n","import type { Container } from \"./container\";\n\n/**\n * Composer API for middleware functions.\n */\nexport interface MiddlewareComposer {\n /**\n * Adds a middleware function to the composer.\n */\n use<MethodKey extends keyof Container>(\n key: MethodKey,\n wrap: Container[MethodKey] extends Function\n ? (next: Container[MethodKey]) => Container[MethodKey]\n : never,\n ): MiddlewareComposer;\n}\n\n/**\n * Middleware function that can be used to extend the container.\n *\n * @example\n * ```ts\n * const logger: Middleware = (composer, _api) => {\n * composer\n * .use(\"resolve\", (next) => (...args) => {\n * console.log(\"resolve\", args);\n * return next(...args);\n * })\n * .use(\"resolveAll\", (next) => (...args) => {\n * console.log(\"resolveAll\", args);\n * return next(...args);\n * });\n * };\n * ```\n */\nexport interface Middleware {\n (composer: MiddlewareComposer, api: Readonly<Container>): void;\n}\n\n/**\n * Applies middleware functions to a container.\n *\n * Middlewares are applied in array order, but execute in reverse order.\n *\n * @example\n * ```ts\n * const container = applyMiddleware(\n * createContainer(),\n * [A, B],\n * );\n * ```\n *\n * The execution order will be:\n *\n * 1. B before\n * 2. A before\n * 3. original function\n * 4. A after\n * 5. B after\n *\n * This allows outer middlewares to wrap and control the behavior of inner middlewares.\n */\nexport function applyMiddleware(container: Container, middlewares: Middleware[]): Container {\n const composer: MiddlewareComposer = {\n use(key, wrap): MiddlewareComposer {\n // We need to bind the 'this' context of the function to the container\n // before passing it to the middleware wrapper.\n //\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call\n const fn = (container[key] as any).bind(container);\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n container[key] = wrap(fn);\n return composer;\n },\n };\n\n const api = (container.api ||= { ...container });\n\n for (const middleware of middlewares) {\n middleware(composer, api);\n }\n\n return container;\n}\n"],"names":["assert","condition","message","resolvedMessage","Error","tag","expectNever","value","TypeError","String","throwUnregisteredError","token","name","throwExistingUnregisteredError","sourceToken","targetTokenOrError","isError","untag","stack","startsWith","substring","trimStart","createInjectionContext","current","provide","next","prev","use","invariant","KeyedStack","has","key","myKeys","peek","entry","myEntries","at","push","add","pop","delete","Array","WeakSet","WeakRefMap","get","ref","myMap","deref","set","WeakRef","WeakMap","createResolution","values","dependents","provideInjectionContext","useInjectionContext","ensureInjectionContext","fn","context","inject","container","resolve","injectBy","thisArg","resolution","currentFrame","currentRef","cleanup","provider","injectAll","resolveAll","getMetadata","Class","metadata","metadataMap","tokensRef","getRefTokens","Set","useClass","dependencies","methods","Map","optional","optionalBy","optionalAll","isClassProvider","isFactoryProvider","isValueProvider","isExistingProvider","Scope","Inherited","Transient","Resolution","Container","createType","typeName","type","inter","union","toString","isConstructor","getTypeName","proto","Object","getPrototypeOf","prototype","constructor","TokenRegistry","parent","myParent","getAll","internal","internals","getAllFromParent","registration","registrations","deleteAll","tokens","from","keys","flat","clear","clearRegistrations","i","length","undefined","isBuilder","builders","build","factory","useFactory","options","scope","isDisposable","dispose","ContainerImpl","myChildren","myDisposed","myOptions","autoRegister","defaultScope","myTokenRegistry","registry","isDisposed","createChild","checkDisposed","clearCache","getCached","getAllCached","resetRegistry","isRegistered","registerClass","ctor","register","registerFactory","registerValue","useValue","registerAlias","targetToken","aliasTokens","alias","useExisting","args","eagerInstantiate","unregister","resolveRegistration","instantiateClass","map","filter","instance","child","disposedRefs","currRegistration","currProvider","resolveProviderValue","e","resolveScope","resolveScopedValue","dependentRef","cleanups","valueRef","resolveConstructorDependencies","injectDependencies","forEach","dependentFrame","ctorDeps","msg","sort","a","b","index","dep","tokenRef","getRefToken","decorator","methodDeps","method","bind","createContainer","AutoRegister","EagerInstantiate","forwardRef","tokenOrTokens","tokensArray","isArray","isTokensRef","isTokenRef","processDecoratedParameter","target","propertyKey","parameterIndex","Inject","Injectable","arg0","existingTokensRef","existingTokens","InjectAll","Optional","OptionalAll","Scoped","Injector","withCurrentContext","applyMiddleware","middlewares","composer","wrap","api","middleware"],"mappings":"AAEA;AACO,SAASA,MAAAA,CAAOC,SAAkB,EAAEC,OAAgC,EAAA;AACzE,IAAA,IAAI,CAACD,SAAAA,EAAW;AACd,QAAA,MAAME,eAAAA,GAAkB,OAAOD,OAAAA,KAAY,QAAA,GAAWA,OAAAA,GAAUA,OAAAA,EAAAA;QAChE,MAAM,IAAIE,MAAMC,GAAAA,CAAIF,eAAAA,CAAAA,CAAAA;AACtB;AACF;AAEA;AACO,SAASG,YAAYC,KAAY,EAAA;AACtC,IAAA,MAAM,IAAIC,SAAAA,CAAUH,GAAAA,CAAI,CAAC,iBAAiB,EAAEI,OAAOF,KAAAA,CAAAA,CAAAA,CAAQ,CAAA,CAAA;AAC7D;AAEA;AACO,SAASG,uBAAuBC,KAAY,EAAA;IACjD,MAAM,IAAIP,MAAMC,GAAAA,CAAI,CAAC,mBAAmB,EAAEM,KAAAA,CAAMC,IAAI,CAAA,CAAE,CAAA,CAAA;AACxD;AAEA;AACO,SAASC,8BAAAA,CAA+BC,WAAkB,EAAEC,kBAAiC,EAAA;AAClG,IAAA,IAAIb,UAAUG,GAAAA,CAAI,CAAC,mDAAmD,EAAES,WAAAA,CAAYF,IAAI,CAAA,CAAE,CAAA;AAE1F,IAAA,IAAII,QAAQD,kBAAAA,CAAAA,EAAqB;AAC/Bb,QAAAA,OAAAA,I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