@lppedd/di-wise-neo 0.8.0 → 0.9.0
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/dist/cjs/index.js +75 -71
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/index.mjs +75 -71
- package/dist/es/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/cjs/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/errors.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/utils.ts","../../src/decorators/inject.ts","../../src/decorators/injectable.ts","../../src/decorators/injectAll.ts","../../src/decorators/named.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 throw new Error(tag(typeof message === \"string\" ? message : message()));\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 message += isError(targetTokenOrError)\n ? `\\n [cause] ${untag(targetTokenOrError.message)}`\n : `\\n [cause] the aliased token ${targetTokenOrError.name} is not registered`;\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]\") ? message.substring(13).trimStart() : message;\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 { 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(name: string): InjectionContext {\n const context = useInjectionContext();\n assert(context, `${name} can only be invoked within an injection context`);\n return context;\n}\n\nfunction createInjectionContext<T extends {}>(): readonly [(next: T) => () => T | null, () => T | null] {\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","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>, name?: string): 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>, name?: string): Value;\n\nexport function inject<T>(token: Token<T>, name?: string): T {\n const context = ensureInjectionContext(\"inject()\");\n return context.container.resolve(token, name);\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 * @param name - The name qualifier of the class to resolve.\n */\nexport function injectBy<Instance extends object>(thisArg: any, Class: Constructor<Instance>, name?: string): 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 * @param name - The name qualifier of the token to resolve.\n */\nexport function injectBy<Value>(thisArg: any, token: Token<Value>, name?: string): Value;\n\nexport function injectBy<T>(thisArg: any, token: Token<T>, name?: string): 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, name);\n }\n\n const currentRef = { current: thisArg };\n const cleanup = resolution.dependents.set(currentFrame.provider, currentRef);\n\n try {\n return inject(token, name);\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, MethodDependency } from \"./tokenRegistry\";\nimport type { TokensRef } from \"./tokensRef\";\n\n// @internal\nexport type Writable<T> = {\n -readonly [P in keyof T]: T[P];\n};\n\n// @internal\nexport interface ScopeMetadata {\n readonly value: Scope;\n readonly appliedBy: \"Scoped\" | \"EagerInstantiate\";\n}\n\n// @internal\nexport class Metadata<This extends object = any> {\n readonly provider: Writable<ClassProvider<This>>;\n readonly dependencies: Dependencies = {\n constructor: [],\n methods: new Map(),\n };\n\n eagerInstantiate?: boolean;\n autoRegister?: boolean;\n scope?: ScopeMetadata;\n tokensRef: TokensRef<This> = {\n getRefTokens: () => new Set(),\n };\n\n constructor(Class: Constructor<This>) {\n this.provider = {\n useClass: Class,\n };\n }\n\n get name(): string | undefined {\n return this.provider.name;\n }\n\n set name(name: string) {\n this.provider.name = name;\n }\n\n getConstructorDependency(index: number): MethodDependency {\n const i = this.dependencies.constructor.findIndex((d) => d.index === index);\n\n if (i > -1) {\n return this.dependencies.constructor[i]!;\n }\n\n const dependency: MethodDependency = {\n index: index,\n };\n\n this.dependencies.constructor.push(dependency);\n return dependency;\n }\n\n getMethodDependency(method: string | symbol, index: number): MethodDependency {\n let methodDeps = this.dependencies.methods.get(method);\n\n if (!methodDeps) {\n this.dependencies.methods.set(method, (methodDeps = []));\n }\n\n const i = methodDeps.findIndex((d) => d.index === index);\n\n if (i > -1) {\n return methodDeps[i]!;\n }\n\n const dependency: MethodDependency = {\n index: index,\n };\n\n methodDeps.push(dependency);\n return dependency;\n }\n}\n\n// @internal\nexport function getMetadata<T extends object>(Class: Constructor<T>): Metadata<T> {\n const originalClass = classIdentityMap.get(Class) ?? Class;\n let metadata = metadataMap.get(originalClass);\n\n if (!metadata) {\n metadataMap.set(originalClass, (metadata = new Metadata(originalClass)));\n }\n\n if (metadata.provider.useClass !== Class) {\n // This is part of the class identity mapping API (see setClassIdentityMapping).\n //\n // Scenario:\n // 1. Metadata is created for class A (the original class) because of a parameter decorator.\n // 2. Later, because of a class decorator that extends the decorated class, a third-party\n // registers a class identity mapping from class B to class A, where B is the class\n // generated from the class decorator by extending A.\n //\n // We must update useClass to be the extender class B so that instances created by the\n // DI container match the consumer's registered class. Without this update, the DI\n // system would instantiate the original class A, causing behavior inconsistencies.\n metadata.provider.useClass = Class;\n }\n\n return metadata;\n}\n\n/**\n * Registers a mapping between a generated (e.g., decorated or proxied) constructor\n * and its original, underlying constructor.\n *\n * This allows libraries or consumers that manipulate constructors, such as through\n * class decorators, to inform the DI system about the real \"identity\" of a class.\n *\n * @param transformedClass The constructor function returned by a class decorator or factory.\n * @param originalClass The original constructor function.\n *\n * @remarks\n * This API affects the core class identity resolution mechanism of the DI system.\n * Incorrect usage may cause metadata to be misassociated, leading to subtle errors.\n * Use only when manipulating constructors (e.g., via decorators or proxies),\n * and ensure the mapping is correct.\n */\nexport function setClassIdentityMapping<T extends object>(transformedClass: Constructor<T>, originalClass: Constructor<T>): void {\n classIdentityMap.set(transformedClass, originalClass);\n}\n\nconst classIdentityMap = new WeakMap<Constructor<object>, Constructor<object>>();\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>, name?: string): 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>, name?: string): Value | undefined;\n\nexport function optional<T>(token: Token<T>, name?: string): T | undefined {\n const context = ensureInjectionContext(\"optional()\");\n return context.container.resolve(token, true, name);\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 * @param name - The name qualifier of the class to resolve.\n */\nexport function optionalBy<Instance extends object>(\n thisArg: any,\n Class: Constructor<Instance>,\n name?: string,\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 * @param name - The name qualifier of the token to resolve.\n */\nexport function optionalBy<Value>(thisArg: any, token: Token<Value>, name?: string): Value | undefined;\n\nexport function optionalBy<T>(thisArg: any, token: Token<T>, name?: string): 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, name);\n }\n\n const currentRef = { current: thisArg };\n const cleanup = resolution.dependents.set(currentFrame.provider, currentRef);\n\n try {\n return optional(token, name);\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 /**\n * The class to instantiate for the token.\n */\n readonly useClass: Constructor<Instance>;\n\n /**\n * An optional name to qualify this provider.\n * If specified, the token must be resolved using the same name.\n *\n * Equivalent to decorating the class with `@Named(...)`.\n *\n * @example\n * ```ts\n * export class ExtensionContext {\n * // Decorator-based injection\n * constructor(@Inject(ISecretStorage) @Named(\"persistent\") secretStorage: SecretStorage) {}\n *\n * // Function-based injection\n * constructor(secretStorage = inject(ISecretStorage, \"persistent\")) {}\n * }\n * ```\n */\n readonly name?: string;\n}\n\n/**\n * Provides a value for a token via a factory function.\n */\nexport interface FactoryProvider<Value> {\n /**\n * A function that produces the value at resolution time.\n *\n * The function runs inside the injection context and can\n * access dependencies via {@link inject}-like helpers.\n */\n readonly useFactory: (...args: []) => Value;\n\n /**\n * An optional name to qualify this provider.\n * If specified, the token must be resolved using the same name.\n *\n * @example\n * ```ts\n * export class ExtensionContext {\n * // Decorator-based injection\n * constructor(@Inject(ISecretStorage) @Named(\"persistent\") secretStorage: SecretStorage) {}\n *\n * // Function-based injection\n * constructor(secretStorage = inject(ISecretStorage, \"persistent\")) {}\n * }\n * ```\n */\n readonly name?: string;\n}\n\n/**\n * Provides a static - already constructed - value for a token.\n */\nexport interface ValueProvider<T> {\n /**\n * The static value to associate with the token.\n */\n readonly useValue: T;\n\n /**\n * An optional name to qualify this provider.\n * If specified, the token must be resolved using the same name.\n *\n * @example\n * ```ts\n * export class ExtensionContext {\n * // Decorator-based injection\n * constructor(@Inject(ISecretStorage) @Named(\"persistent\") secretStorage: SecretStorage) {}\n *\n * // Function-based injection\n * constructor(secretStorage = inject(ISecretStorage, \"persistent\")) {}\n * }\n * ```\n */\n readonly name?: string;\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 /**\n * The existing token to alias.\n */\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 switch (typeof value) {\n case \"string\":\n return `\"${value}\"`;\n case \"function\":\n return (value.name && `typeof ${value.name}`) || \"Function\";\n case \"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\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 interface MethodDependency {\n // The index of the annotated parameter (zero-based)\n readonly index: number;\n\n appliedBy?: \"Inject\" | \"InjectAll\" | \"Optional\" | \"OptionalAll\";\n tokenRef?: TokenRef;\n name?: string;\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 readonly name?: string;\n readonly provider: Provider<T>;\n readonly options?: RegistrationOptions;\n readonly dependencies?: Dependencies;\n\n value?: ValueRef<T>;\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>, name?: string): Registration<T> | undefined {\n // To clarify, at(-1) means we take the last added registration for this token\n return this.getAll(token, name).at(-1);\n }\n\n getAll<T>(token: Token<T>, name?: string): Registration<T>[] {\n // Internal registrations cannot have a name\n const internal = name !== undefined ? undefined : internals.get(token);\n return (internal && [internal]) || this.getAllFromParent(token, name);\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 let registrations = this.myMap.get(token);\n\n if (!registrations) {\n this.myMap.set(token, (registrations = []));\n } else if (registration.name !== undefined) {\n const existing = registrations.filter((r) => r.name === registration.name);\n assert(existing.length === 0, `a ${token.name} token named '${registration.name}' is already registered`);\n }\n\n registrations.push(registration);\n }\n\n delete<T>(token: Token<T>, name?: string): Registration<T>[] {\n const registrations = this.myMap.get(token);\n\n if (registrations) {\n if (name !== undefined) {\n const removedRegistrations: Registration[] = [];\n const newRegistrations: Registration[] = [];\n\n for (const registration of registrations) {\n const array = registration.name === name ? removedRegistrations : newRegistrations;\n array.push(registration);\n }\n\n if (removedRegistrations.length > 0) {\n this.myMap.set(token, newRegistrations);\n return removedRegistrations;\n }\n }\n\n this.myMap.delete(token);\n }\n\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>, name?: string): Registration<T>[] {\n const thisRegistrations = this.myMap.get(token);\n let registrations = thisRegistrations || this.myParent?.getAllFromParent(token, name);\n\n if (registrations && name !== undefined) {\n registrations = registrations.filter((r) => r.name === name);\n assert(registrations.length < 2, `internal error: more than one registration named '${name}'`);\n }\n\n return registrations ?? [];\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 */\nexport function build<Value>(factory: (...args: []) => Value): Type<Value>;\n\n// @internal\nexport function build<Value>(factory: (...args: []) => Value, name: string): Type<Value>;\n\n// @__NO_SIDE_EFFECTS__\nexport function build<Value>(factory: (...args: []) => Value, name?: string): Type<Value> {\n const token = createType<Value>(name ?? `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 { isClassProvider, isExistingProvider, isFactoryProvider, isValueProvider, type Provider } from \"./provider\";\nimport { Scope } from \"./scope\";\nimport { type Constructor, isConstructor, type Token } 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\n const registrations = this.myTokenRegistry.getAll(token);\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\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, name?: string): boolean {\n this.checkDisposed();\n return this.myTokenRegistry.get(token, name) !== undefined;\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 name: metadata.name,\n // The provider is of type ClassProvider, initialized by getMetadata\n provider: metadata.provider,\n options: {\n scope: metadata.scope?.value ?? 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.resolveProviderValue(registration, registration.provider);\n }\n } else {\n const [token, provider, options] = args;\n const existingProvider = isExistingProvider(provider);\n const name = existingProvider ? undefined : provider.name;\n assert(name === undefined || name.trim(), \"the provider name qualifier cannot be empty or blank\");\n\n if (isClassProvider(provider)) {\n const metadata = getMetadata(provider.useClass);\n const registration: Registration = {\n // An explicit provider name overrides what is specified via @Named\n name: metadata.name ?? provider.name,\n provider: metadata.provider,\n options: {\n // Explicit registration options override what is specified via class decorators (e.g., @Scoped)\n scope: metadata.scope?.value ?? 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.resolveProviderValue(registration, registration.provider);\n }\n } else {\n if (existingProvider) {\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 name: name,\n provider: provider,\n options: options,\n });\n }\n }\n\n return this;\n }\n\n unregister<T>(token: Token<T>, name?: string): T[] {\n this.checkDisposed();\n\n const registrations = this.myTokenRegistry.delete(token, name);\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>, optionalOrName?: boolean | string, name?: string): T | undefined {\n this.checkDisposed();\n\n let localOptional: boolean | undefined;\n let localName: string | undefined;\n\n if (typeof optionalOrName === \"string\") {\n localName = optionalOrName;\n } else {\n localOptional = optionalOrName;\n localName = name;\n }\n\n const registration = this.myTokenRegistry.get(token, localName);\n\n if (registration) {\n return this.resolveRegistration(token, registration, localName);\n }\n\n if (isConstructor(token)) {\n return this.instantiateClass(token, localOptional);\n }\n\n return optionalOrName ? 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.length > 0) {\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>, name?: string): 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, name);\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?.value);\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(scope !== Scope.Container, `unregistered class ${Class.name} cannot be resolved in container scope`);\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.filter((d) => d.appliedBy);\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.appliedBy) {\n case \"Inject\":\n return this.resolve(token, dep.name);\n case \"InjectAll\":\n return this.resolveAll(token);\n case \"Optional\":\n return this.resolve(token, true, dep.name);\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 entry of dependencies.methods) {\n const key = entry[0];\n const methodDeps = entry[1].filter((d) => d.appliedBy);\n\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.appliedBy) {\n case \"Inject\":\n return injectBy(instance, token, dep.name);\n case \"InjectAll\":\n return injectAll(token);\n case \"Optional\":\n return optionalBy(instance, token, dep.name);\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 } 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, name?: string): boolean;\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 * or by the {@link ContainerOptions.defaultScope} value.\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 - or by the {@link ContainerOptions.defaultScope}\n * value, but it can be overridden by passing explicit registration options.\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 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 register<Value, ProviderValue extends Value>(token: Token<Value>, provider: ExistingProvider<ProviderValue>): 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 register<Value, ProviderValue extends Value>(token: Token<Value>, provider: ValueProvider<ProviderValue>): 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>, name?: string): 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>, name?: string): Instance;\n resolve<Instance extends object>(Class: Constructor<Instance>, optional?: false, name?: string): Instance;\n resolve<Instance extends object>(Class: Constructor<Instance>, optional: true, name?: string): Instance | undefined;\n resolve<Instance extends object>(Class: Constructor<Instance>, optional?: boolean, name?: string): 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>, name?: string): Value;\n resolve<Value>(token: Token<Value>, optional?: false, name?: string): Value;\n resolve<Value>(token: Token<Value>, optional: true, name?: string): Value | undefined;\n resolve<Value>(token: Token<Value>, optional?: boolean, name?: string): 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(): ClassDecorator {\n return function (Class): void {\n const metadata = getMetadata(Class as any as Constructor<any>);\n metadata.autoRegister = true;\n };\n}\n","import { assert } from \"../errors\";\nimport { getMetadata } from \"../metadata\";\nimport { Scope } from \"../scope\";\nimport type { Constructor } from \"../token\";\n\n/**\n * Class decorator that sets the class scope to **Container** and enables\n * eager instantiation when the class is registered in the 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 * class Wizard {}\n *\n * // Wizard is registered with Container scope, and an instance\n * // is immediately created and cached by the container\n * container.register(Wizard);\n * ```\n *\n * @__NO_SIDE_EFFECTS__\n */\nexport function EagerInstantiate(): ClassDecorator {\n return function (Class): void {\n const metadata = getMetadata(Class as any as Constructor<any>);\n const currentScope = metadata.scope;\n\n assert(!currentScope || currentScope.value === Scope.Container, () => {\n const { value, appliedBy } = currentScope!;\n return (\n `class ${Class.name}: Scope.${value} was already set by @${appliedBy},\\n ` +\n `but @EagerInstantiate is trying to set a conflicting Scope.Container.\\n ` +\n `Only one decorator should set the class scope, or all must agree on the same value.`\n );\n });\n\n metadata.eagerInstantiate = true;\n metadata.scope = {\n value: Scope.Container,\n appliedBy: \"EagerInstantiate\",\n };\n };\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>(token: () => Token<Value> | Tokens<Value>): 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 } from \"../token\";\nimport type { MethodDependency } from \"../tokenRegistry\";\n\n// @internal\nexport function updateParameterMetadata(\n decorator: string,\n target: object,\n propertyKey: string | symbol | undefined,\n parameterIndex: number,\n updateFn: (dependency: MethodDependency) => void,\n): void {\n // Error out immediately if the decorator has been applied to a static method\n if (propertyKey !== undefined && typeof target === \"function\") {\n assert(false, `@${decorator} cannot be used on static method ${target.name}.${String(propertyKey)}`);\n }\n\n if (propertyKey === undefined) {\n // Constructor\n const metadata = getMetadata(target as Constructor<any>);\n const dependency = metadata.getConstructorDependency(parameterIndex);\n updateFn(dependency);\n } else {\n // Instance method\n const metadata = getMetadata(target.constructor as Constructor<any>);\n const dependency = metadata.getMethodDependency(propertyKey, parameterIndex);\n updateFn(dependency);\n }\n}\n","import type { Constructor, Token } from \"../token\";\nimport { forwardRef, isTokenRef, type TokenRef } from \"../tokensRef\";\nimport { updateParameterMetadata } from \"./utils\";\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): void {\n updateParameterMetadata(\"Inject\", target, propertyKey, parameterIndex, (dependency) => {\n dependency.appliedBy = \"Inject\";\n dependency.tokenRef = isTokenRef(token) ? token : forwardRef(() => token);\n });\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>(tokens: TokenRef<Value> | TokensRef<Value>): 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 { forwardRef, isTokenRef, type TokenRef } from \"../tokensRef\";\nimport { updateParameterMetadata } from \"./utils\";\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): void {\n updateParameterMetadata(\"InjectAll\", target, propertyKey, parameterIndex, (dependency) => {\n dependency.appliedBy = \"InjectAll\";\n dependency.tokenRef = isTokenRef(token) ? token : forwardRef(() => token);\n });\n };\n}\n","import { assert } from \"../errors\";\nimport { getMetadata } from \"../metadata\";\nimport type { Constructor } from \"../token\";\nimport { updateParameterMetadata } from \"./utils\";\n\n/**\n * Qualifies a class or an injected parameter with a unique name.\n *\n * This allows the container to distinguish between multiple implementations\n * of the same interface or type during registration and injection.\n *\n * @example\n * ```ts\n * @Named(\"dumbledore\")\n * class Dumbledore implements Wizard {}\n *\n * // Register Dumbledore with Type<Wizard>\n * container.register(IWizard, { useClass: Dumbledore });\n * const dumbledore = container.resolve(IWizard, \"dumbledore\");\n * ```\n *\n * @__NO_SIDE_EFFECTS__\n */\nexport function Named(name: string): ClassDecorator & ParameterDecorator {\n if (!name.trim()) {\n assert(false, \"the @Named qualifier cannot be empty or blank\");\n }\n\n return function (target: object, propertyKey?: string | symbol, parameterIndex?: number): void {\n if (parameterIndex === undefined) {\n // The decorator has been applied to the class\n const ctor = target as any as Constructor<any>;\n const metadata = getMetadata(ctor);\n assert(!metadata.name, `a @Named('${metadata.name}') qualifier has already been applied to ${ctor.name}`);\n metadata.name = name;\n } else {\n // The decorator has been applied to a method parameter\n updateParameterMetadata(\"Named\", target, propertyKey, parameterIndex, (dependency) => {\n assert(!dependency.name, `a @Named('${dependency.name}') qualifier has already been applied to the parameter`);\n dependency.name = name;\n });\n }\n };\n}\n","import type { Constructor, Token } from \"../token\";\nimport { forwardRef, isTokenRef, type TokenRef } from \"../tokensRef\";\nimport { updateParameterMetadata } from \"./utils\";\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): void {\n updateParameterMetadata(\"Optional\", target, propertyKey, parameterIndex, (dependency) => {\n dependency.appliedBy = \"Optional\";\n dependency.tokenRef = isTokenRef(token) ? token : forwardRef(() => token);\n });\n };\n}\n","import type { Constructor, Token } from \"../token\";\nimport { forwardRef, isTokenRef, type TokenRef } from \"../tokensRef\";\nimport { updateParameterMetadata } from \"./utils\";\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): void {\n updateParameterMetadata(\"OptionalAll\", target, propertyKey, parameterIndex, (dependency) => {\n dependency.appliedBy = \"OptionalAll\";\n dependency.tokenRef = isTokenRef(token) ? token : forwardRef(() => token);\n });\n };\n}\n","import { assert } from \"../errors\";\nimport { 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 const currentScope = metadata.scope;\n\n assert(!currentScope || currentScope.value === scope, () => {\n const { value, appliedBy } = currentScope!;\n const by = appliedBy === \"Scoped\" ? `another @${appliedBy} decorator` : `@${appliedBy}`;\n return (\n `class ${Class.name}: Scope.${value} was already set by ${by},\\n ` +\n `but @Scoped is trying to set a conflicting Scope.${scope}.\\n ` +\n `Only one decorator should set the class scope, or all must agree on the same value.`\n );\n });\n\n metadata.scope = {\n value: scope,\n appliedBy: \"Scoped\",\n };\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>, name?: string): 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>, name?: string): 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>, name?: string): 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>, name?: string): 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 * Runs a function inside the injection context of this injector.\n *\n * Note that injection functions (`inject`, `injectAll`, `optional`, `optionalAll`)\n * are only usable synchronously: they cannot be called from asynchronous callbacks\n * or after any `await` points.\n *\n * @param fn The function to be run in the context of this injector.\n * @returns The return value of the function, if any.\n */\n runInContext<ReturnType>(fn: () => ReturnType): ReturnType;\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<Injector>(() => {\n const context = ensureInjectionContext(\"Injector factory\");\n const resolution = context.resolution;\n\n const dependentFrame = resolution.stack.peek();\n const dependentRef = dependentFrame && resolution.dependents.get(dependentFrame.provider);\n\n function withContext<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 cleanups.forEach((cleanup) => cleanup?.());\n }\n }\n\n return {\n inject: <T>(token: Token<T>, name?: string) => withContext(() => inject(token, name)),\n injectAll: <T>(token: Token<T>) => withContext(() => injectAll(token)),\n optional: <T>(token: Token<T>, name?: string) => withContext(() => optional(token, name)),\n optionalAll: <T>(token: Token<T>) => withContext(() => optionalAll(token)),\n runInContext: withContext,\n };\n}, \"Injector\");\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 ? (next: Container[MethodKey]) => Container[MethodKey] : 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","Error","tag","expectNever","value","TypeError","String","throwUnregisteredError","token","name","throwExistingUnregisteredError","sourceToken","targetTokenOrError","isError","untag","stack","startsWith","substring","trimStart","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","createInjectionContext","ensureInjectionContext","context","current","provide","next","prev","use","inject","container","resolve","injectBy","thisArg","resolution","currentFrame","currentRef","cleanup","provider","injectAll","resolveAll","Metadata","Class","dependencies","methods","Map","tokensRef","getRefTokens","Set","useClass","getConstructorDependency","index","i","findIndex","d","dependency","getMethodDependency","method","methodDeps","getMetadata","originalClass","classIdentityMap","metadata","metadataMap","setClassIdentityMapping","transformedClass","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","undefined","internals","getAllFromParent","registration","registrations","existing","filter","r","length","removedRegistrations","newRegistrations","array","deleteAll","tokens","from","keys","flat","clear","clearRegistrations","thisRegistrations","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","register","args","useExisting","eagerInstantiate","resolveProviderValue","existingProvider","trim","unregister","optionalOrName","localOptional","localName","resolveRegistration","instantiateClass","map","instance","child","disposedRefs","currRegistration","currProvider","targetToken","e","resolveScope","resolveScopedValue","useValue","dependentRef","cleanups","valueRef","resolveConstructorDependencies","injectDependencies","forEach","dependentFrame","ctorDeps","appliedBy","ctor","msg","sort","a","b","dep","tokenRef","getRefToken","bind","createContainer","AutoRegister","EagerInstantiate","currentScope","forwardRef","tokenOrTokens","tokensArray","isArray","isTokensRef","isTokenRef","updateParameterMetadata","decorator","target","propertyKey","parameterIndex","updateFn","Inject","Injectable","arg0","existingTokensRef","existingTokens","InjectAll","Named","Optional","OptionalAll","Scoped","by","Injector","withContext","fn","runInContext","applyMiddleware","middlewares","composer","wrap","api","middleware"],"mappings":";;AAEA;AACO,SAASA,MAAAA,CAAOC,SAAkB,EAAEC,OAAgC,EAAA;AACzE,IAAA,IAAI,CAACD,SAAAA,EAAW;AACd,QAAA,MAAM,IAAIE,KAAAA,CAAMC,GAAAA,CAAI,OAAOF,OAAAA,KAAY,WAAWA,OAAAA,GAAUA,OAAAA,EAAAA,CAAAA,CAAAA;AAC9D;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,IAAIZ,UAAUE,GAAAA,CAAI,CAAC,mDAAmD,EAAES,WAAAA,CAAYF,IAAI,CAAA,CAAE,CAAA;AAC1FT,IAAAA,OAAAA,IAAWa,QAAQD,kBAAAA,CAAAA,GACf,CAAC,YAAY,EAAEE,MAAMF,kBAAAA,CAAmBZ,OAAO,CAAA,CAAA,CAAG,GAClD,CAAC,8BAA8B,EAAEY,mBAAmBH,IAAI,CAAC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A;;AC1FH;;;;;;;;;;;;;;;;;;;;;;AAsBC,IACM,SAASG,eAAAA,CAAgBxL,SAAoB,EAAEyL,WAAyB,EAAA;AAC7E,IAAA,MAAMC,QAAAA,GAA+B;QACnC5L,GAAAA,CAAAA,CAAIhC,GAAG,EAAE6N,IAAI,EAAA;;;;;AAKX,YAAA,MAAML,KAAK,SAAU,CAACxN,GAAAA,CAAI,CAAS0L,IAAI,CAACxJ,SAAAA,CAAAA;;YAGxCA,SAAS,CAAClC,GAAAA,CAAI,GAAG6N,IAAAA,CAAKL,EAAAA,CAAAA;YACtB,OAAOI,QAAAA;AACT;AACF,KAAA;IAEA,MAAME,GAAAA,GAAO5L,SAAAA,CAAU4L,GAAG,KAAK;AAAE,QAAA,GAAG5L;AAAU,KAAA;IAE9C,KAAK,MAAM6L,cAAcJ,WAAAA,CAAa;AACpCI,QAAAA,UAAAA,CAAWH,QAAAA,EAAUE,GAAAA,CAAAA;AACvB;IAEA,OAAO5L,SAAAA;AACT;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/token.ts","../../src/errors.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/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/utils.ts","../../src/decorators/inject.ts","../../src/decorators/injectable.ts","../../src/decorators/injectAll.ts","../../src/decorators/named.ts","../../src/decorators/optional.ts","../../src/decorators/optionalAll.ts","../../src/decorators/scoped.ts","../../src/injector.ts","../../src/middleware.ts"],"sourcesContent":["/**\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","import { isConstructor, type Token } from \"./token\";\n\n// @internal\nexport function assert(condition: unknown, message: string | (() => string)): asserts condition {\n if (!condition) {\n throw new Error(tag(typeof message === \"string\" ? message : message()));\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, name?: string): never {\n const type = isConstructor(token) ? \"class\" : \"token\";\n const spec = name !== undefined ? `[name=${name}]` : \"\";\n throw new Error(tag(`unregistered ${type} ${token.name}${spec}`));\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 message += isError(targetTokenOrError)\n ? `\\n [cause] ${untag(targetTokenOrError.message)}`\n : `\\n [cause] the aliased token ${targetTokenOrError.name} is not registered`;\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]\") ? message.substring(13).trimStart() : message;\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 return undefined;\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 { 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(name: string): InjectionContext {\n const context = useInjectionContext();\n assert(context, `${name} can only be invoked within an injection context`);\n return context;\n}\n\nfunction createInjectionContext<T extends {}>(): readonly [(next: T) => () => T | null, () => T | null] {\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","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>, name?: string): 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>, name?: string): Value;\n\nexport function inject<T>(token: Token<T>, name?: string): T {\n const context = ensureInjectionContext(\"inject()\");\n return context.container.resolve(token, name);\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 * @param name - The name qualifier of the class to resolve.\n */\nexport function injectBy<Instance extends object>(thisArg: any, Class: Constructor<Instance>, name?: string): 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 * @param name - The name qualifier of the token to resolve.\n */\nexport function injectBy<Value>(thisArg: any, token: Token<Value>, name?: string): Value;\n\nexport function injectBy<T>(thisArg: any, token: Token<T>, name?: string): 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, name);\n }\n\n const currentRef = { current: thisArg };\n const cleanup = resolution.dependents.set(currentFrame.provider, currentRef);\n\n try {\n return inject(token, name);\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, MethodDependency } from \"./tokenRegistry\";\nimport type { TokensRef } from \"./tokensRef\";\n\n// @internal\nexport type Writable<T> = {\n -readonly [P in keyof T]: T[P];\n};\n\n// @internal\nexport interface ScopeMetadata {\n readonly value: Scope;\n readonly appliedBy: \"Scoped\" | \"EagerInstantiate\";\n}\n\n// @internal\nexport class Metadata<This extends object = any> {\n readonly provider: Writable<ClassProvider<This>>;\n readonly dependencies: Dependencies = {\n constructor: [],\n methods: new Map(),\n };\n\n eagerInstantiate?: boolean;\n autoRegister?: boolean;\n scope?: ScopeMetadata;\n tokensRef: TokensRef<This> = {\n getRefTokens: () => new Set(),\n };\n\n constructor(Class: Constructor<This>) {\n this.provider = {\n useClass: Class,\n };\n }\n\n get name(): string | undefined {\n return this.provider.name;\n }\n\n set name(name: string) {\n this.provider.name = name;\n }\n\n getConstructorDependency(index: number): MethodDependency {\n const i = this.dependencies.constructor.findIndex((d) => d.index === index);\n\n if (i > -1) {\n return this.dependencies.constructor[i]!;\n }\n\n const dependency: MethodDependency = {\n index: index,\n };\n\n this.dependencies.constructor.push(dependency);\n return dependency;\n }\n\n getMethodDependency(method: string | symbol, index: number): MethodDependency {\n let methodDeps = this.dependencies.methods.get(method);\n\n if (!methodDeps) {\n this.dependencies.methods.set(method, (methodDeps = []));\n }\n\n const i = methodDeps.findIndex((d) => d.index === index);\n\n if (i > -1) {\n return methodDeps[i]!;\n }\n\n const dependency: MethodDependency = {\n index: index,\n };\n\n methodDeps.push(dependency);\n return dependency;\n }\n}\n\n// @internal\nexport function getMetadata<T extends object>(Class: Constructor<T>): Metadata<T> {\n const originalClass = classIdentityMap.get(Class) ?? Class;\n let metadata = metadataMap.get(originalClass);\n\n if (!metadata) {\n metadataMap.set(originalClass, (metadata = new Metadata(originalClass)));\n }\n\n if (metadata.provider.useClass !== Class) {\n // This is part of the class identity mapping API (see setClassIdentityMapping).\n //\n // Scenario:\n // 1. Metadata is created for class A (the original class) because of a parameter decorator.\n // 2. Later, because of a class decorator that extends the decorated class, a third-party\n // registers a class identity mapping from class B to class A, where B is the class\n // generated from the class decorator by extending A.\n //\n // We must update useClass to be the extender class B so that instances created by the\n // DI container match the consumer's registered class. Without this update, the DI\n // system would instantiate the original class A, causing behavior inconsistencies.\n metadata.provider.useClass = Class;\n }\n\n return metadata;\n}\n\n/**\n * Registers a mapping between a generated (e.g., decorated or proxied) constructor\n * and its original, underlying constructor.\n *\n * This allows libraries or consumers that manipulate constructors, such as through\n * class decorators, to inform the DI system about the real \"identity\" of a class.\n *\n * @param transformedClass The constructor function returned by a class decorator or factory.\n * @param originalClass The original constructor function.\n *\n * @remarks\n * This API affects the core class identity resolution mechanism of the DI system.\n * Incorrect usage may cause metadata to be misassociated, leading to subtle errors.\n * Use only when manipulating constructors (e.g., via decorators or proxies),\n * and ensure the mapping is correct.\n */\nexport function setClassIdentityMapping<T extends object>(transformedClass: Constructor<T>, originalClass: Constructor<T>): void {\n classIdentityMap.set(transformedClass, originalClass);\n}\n\nconst classIdentityMap = new WeakMap<Constructor<object>, Constructor<object>>();\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>, name?: string): 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>, name?: string): Value | undefined;\n\nexport function optional<T>(token: Token<T>, name?: string): T | undefined {\n const context = ensureInjectionContext(\"optional()\");\n return context.container.resolve(token, true, name);\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 * @param name - The name qualifier of the class to resolve.\n */\nexport function optionalBy<Instance extends object>(\n thisArg: any,\n Class: Constructor<Instance>,\n name?: string,\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 * @param name - The name qualifier of the token to resolve.\n */\nexport function optionalBy<Value>(thisArg: any, token: Token<Value>, name?: string): Value | undefined;\n\nexport function optionalBy<T>(thisArg: any, token: Token<T>, name?: string): 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, name);\n }\n\n const currentRef = { current: thisArg };\n const cleanup = resolution.dependents.set(currentFrame.provider, currentRef);\n\n try {\n return optional(token, name);\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 /**\n * The class to instantiate for the token.\n */\n readonly useClass: Constructor<Instance>;\n\n /**\n * An optional name to qualify this provider.\n * If specified, the token must be resolved using the same name.\n *\n * Equivalent to decorating the class with `@Named(...)`.\n *\n * @example\n * ```ts\n * export class ExtensionContext {\n * // Decorator-based injection\n * constructor(@Inject(ISecretStorage) @Named(\"persistent\") secretStorage: SecretStorage) {}\n *\n * // Function-based injection\n * constructor(secretStorage = inject(ISecretStorage, \"persistent\")) {}\n * }\n * ```\n */\n readonly name?: string;\n}\n\n/**\n * Provides a value for a token via a factory function.\n */\nexport interface FactoryProvider<Value> {\n /**\n * A function that produces the value at resolution time.\n *\n * The function runs inside the injection context and can\n * access dependencies via {@link inject}-like helpers.\n */\n readonly useFactory: (...args: []) => Value;\n\n /**\n * An optional name to qualify this provider.\n * If specified, the token must be resolved using the same name.\n *\n * @example\n * ```ts\n * export class ExtensionContext {\n * // Decorator-based injection\n * constructor(@Inject(ISecretStorage) @Named(\"persistent\") secretStorage: SecretStorage) {}\n *\n * // Function-based injection\n * constructor(secretStorage = inject(ISecretStorage, \"persistent\")) {}\n * }\n * ```\n */\n readonly name?: string;\n}\n\n/**\n * Provides a static - already constructed - value for a token.\n */\nexport interface ValueProvider<T> {\n /**\n * The static value to associate with the token.\n */\n readonly useValue: T;\n\n /**\n * An optional name to qualify this provider.\n * If specified, the token must be resolved using the same name.\n *\n * @example\n * ```ts\n * export class ExtensionContext {\n * // Decorator-based injection\n * constructor(@Inject(ISecretStorage) @Named(\"persistent\") secretStorage: SecretStorage) {}\n *\n * // Function-based injection\n * constructor(secretStorage = inject(ISecretStorage, \"persistent\")) {}\n * }\n * ```\n */\n readonly name?: string;\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 /**\n * The existing token to alias.\n */\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","// @internal\nexport function getTypeName(value: unknown): string {\n switch (typeof value) {\n case \"string\":\n return `\"${value}\"`;\n case \"function\":\n return (value.name && `typeof ${value.name}`) || \"Function\";\n case \"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\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 InjectDecorator = \"Inject\" | \"InjectAll\" | \"Optional\" | \"OptionalAll\";\n\n// @internal\nexport interface MethodDependency {\n // The index of the annotated parameter (zero-based)\n readonly index: number;\n\n appliedBy?: InjectDecorator;\n tokenRef?: TokenRef;\n name?: string;\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 readonly name?: string;\n readonly provider: Provider<T>;\n readonly options?: RegistrationOptions;\n readonly dependencies?: Dependencies;\n\n value?: ValueRef<T>;\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 extends object>(token: Constructor<T>, name?: string): Registration<T> | undefined;\n get<T>(token: Token<T>, name?: string): Registration<T> | undefined;\n get<T>(token: Token<T>, name?: string): Registration<T> | undefined {\n // To clarify, at(-1) means we take the last added registration for this token\n return this.getAll(token, name).at(-1);\n }\n\n getAll<T>(token: Token<T>, name?: string): Registration<T>[] {\n // Internal registrations cannot have a name\n const internal = name !== undefined ? undefined : internals.get(token);\n return (internal && [internal]) || this.getAllFromParent(token, name);\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 let registrations = this.myMap.get(token);\n\n if (!registrations) {\n this.myMap.set(token, (registrations = []));\n } else if (registration.name !== undefined) {\n const existing = registrations.filter((r) => r.name === registration.name);\n assert(existing.length === 0, `a ${token.name} token named '${registration.name}' is already registered`);\n }\n\n registrations.push(registration);\n }\n\n delete<T>(token: Token<T>, name?: string): Registration<T>[] {\n const registrations = this.myMap.get(token);\n\n if (registrations) {\n if (name !== undefined) {\n const removedRegistrations: Registration[] = [];\n const newRegistrations: Registration[] = [];\n\n for (const registration of registrations) {\n const array = registration.name === name ? removedRegistrations : newRegistrations;\n array.push(registration);\n }\n\n if (removedRegistrations.length > 0) {\n this.myMap.set(token, newRegistrations);\n return removedRegistrations;\n }\n }\n\n this.myMap.delete(token);\n }\n\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>, name?: string): Registration<T>[] {\n const thisRegistrations = this.myMap.get(token);\n let registrations = thisRegistrations || this.myParent?.getAllFromParent(token, name);\n\n if (registrations && name !== undefined) {\n registrations = registrations.filter((r) => r.name === name);\n assert(registrations.length < 2, `internal error: more than one registration named '${name}'`);\n }\n\n return registrations ?? [];\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 */\nexport function build<Value>(factory: (...args: []) => Value): Type<Value>;\n\n// @internal\nexport function build<Value>(factory: (...args: []) => Value, name: string): Type<Value>;\n\n// @__NO_SIDE_EFFECTS__\nexport function build<Value>(factory: (...args: []) => Value, name?: string): Type<Value> {\n const token = createType<Value>(name ?? `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 { isClassProvider, isExistingProvider, isFactoryProvider, isValueProvider, type Provider } from \"./provider\";\nimport { Scope } from \"./scope\";\nimport { type Constructor, isConstructor, type Token } 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\n const registrations = this.myTokenRegistry.getAll(token);\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\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, name?: string): boolean {\n this.checkDisposed();\n return this.myTokenRegistry.get(token, name) !== undefined;\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 name: metadata.name,\n // The provider is of type ClassProvider, initialized by getMetadata\n provider: metadata.provider,\n options: {\n scope: metadata.scope?.value ?? 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.resolveProviderValue(registration, registration.provider);\n }\n } else {\n const [token, provider, options] = args;\n const existingProvider = isExistingProvider(provider);\n const name = existingProvider ? undefined : provider.name;\n assert(name === undefined || name.trim(), \"the provider name qualifier cannot be empty or blank\");\n\n if (isClassProvider(provider)) {\n const metadata = getMetadata(provider.useClass);\n const registration: Registration = {\n // An explicit provider name overrides what is specified via @Named\n name: metadata.name ?? provider.name,\n provider: metadata.provider,\n options: {\n // Explicit registration options override what is specified via class decorators (e.g., @Scoped)\n scope: metadata.scope?.value ?? 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.resolveProviderValue(registration, registration.provider);\n }\n } else {\n if (existingProvider) {\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 name: name,\n provider: provider,\n options: options,\n });\n }\n }\n\n return this;\n }\n\n unregister<T>(token: Token<T>, name?: string): T[] {\n this.checkDisposed();\n\n const registrations = this.myTokenRegistry.delete(token, name);\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>, optionalOrName?: boolean | string, name?: string): T | undefined {\n this.checkDisposed();\n\n let localOptional: boolean | undefined;\n let localName: string | undefined;\n\n if (typeof optionalOrName === \"string\") {\n localName = optionalOrName;\n } else {\n localOptional = optionalOrName;\n localName = name;\n }\n\n let registration = this.myTokenRegistry.get(token, localName);\n\n if (!registration && isConstructor(token)) {\n registration = this.autoRegisterClass(token, localName);\n }\n\n if (registration) {\n return this.resolveRegistration(token, registration, localName);\n }\n\n return localOptional ? undefined : throwUnregisteredError(token, localName);\n }\n\n resolveAll<T>(token: Token<T>, optional?: boolean): NonNullable<T>[] {\n this.checkDisposed();\n let registrations = this.myTokenRegistry.getAll(token);\n\n if (registrations.length === 0 && isConstructor(token)) {\n const registration = this.autoRegisterClass(token);\n\n if (registration) {\n registrations = [registration];\n }\n }\n\n if (registrations.length > 0) {\n return registrations //\n .map((registration) => this.resolveRegistration(token, registration))\n .filter((value) => value != null);\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>, name?: string): 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, name);\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 autoRegisterClass<T extends object>(Class: Constructor<T>, name?: string): Registration<T> | undefined {\n const metadata = getMetadata(Class);\n const autoRegister = metadata.autoRegister ?? this.myOptions.autoRegister;\n\n if (autoRegister && (name === undefined || metadata.name === name)) {\n // Temporarily set eagerInstantiate to false to avoid potentially resolving\n // the class inside register()\n const eagerInstantiate = metadata.eagerInstantiate;\n metadata.eagerInstantiate = false;\n\n try {\n this.register(Class);\n return this.myTokenRegistry.get(Class, name ?? metadata.name);\n } finally {\n metadata.eagerInstantiate = eagerInstantiate;\n }\n }\n\n return undefined;\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.filter((d) => d.appliedBy);\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.appliedBy) {\n case \"Inject\":\n return this.resolve(token, dep.name);\n case \"InjectAll\":\n return this.resolveAll(token);\n case \"Optional\":\n return this.resolve(token, true, dep.name);\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 entry of dependencies.methods) {\n const key = entry[0];\n const methodDeps = entry[1].filter((d) => d.appliedBy);\n\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.appliedBy) {\n case \"Inject\":\n return injectBy(instance, token, dep.name);\n case \"InjectAll\":\n return injectAll(token);\n case \"Optional\":\n return optionalBy(instance, token, dep.name);\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 } 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, name?: string): boolean;\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 * or by the {@link ContainerOptions.defaultScope} value.\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 - or by the {@link ContainerOptions.defaultScope}\n * value, but it can be overridden by passing explicit registration options.\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 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 register<Value, ProviderValue extends Value>(token: Token<Value>, provider: ExistingProvider<ProviderValue>): 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 register<Value, ProviderValue extends Value>(token: Token<Value>, provider: ValueProvider<ProviderValue>): 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>, name?: string): 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>, name?: string): Instance;\n resolve<Instance extends object>(Class: Constructor<Instance>, optional?: false, name?: string): Instance;\n resolve<Instance extends object>(Class: Constructor<Instance>, optional: true, name?: string): Instance | undefined;\n resolve<Instance extends object>(Class: Constructor<Instance>, optional?: boolean, name?: string): 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>, name?: string): Value;\n resolve<Value>(token: Token<Value>, optional?: false, name?: string): Value;\n resolve<Value>(token: Token<Value>, optional: true, name?: string): Value | undefined;\n resolve<Value>(token: Token<Value>, optional?: boolean, name?: string): 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(): ClassDecorator {\n return function (Class): void {\n const metadata = getMetadata(Class as any as Constructor<any>);\n metadata.autoRegister = true;\n };\n}\n","import { assert } from \"../errors\";\nimport { getMetadata } from \"../metadata\";\nimport { Scope } from \"../scope\";\nimport type { Constructor } from \"../token\";\n\n/**\n * Class decorator that sets the class scope to **Container** and enables\n * eager instantiation when the class is registered in the 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 * class Wizard {}\n *\n * // Wizard is registered with Container scope, and an instance\n * // is immediately created and cached by the container\n * container.register(Wizard);\n * ```\n *\n * @__NO_SIDE_EFFECTS__\n */\nexport function EagerInstantiate(): ClassDecorator {\n return function (Class): void {\n const metadata = getMetadata(Class as any as Constructor<any>);\n const currentScope = metadata.scope;\n\n assert(!currentScope || currentScope.value === Scope.Container, () => {\n const { value, appliedBy } = currentScope!;\n return (\n `class ${Class.name}: Scope.${value} was already set by @${appliedBy},\\n ` +\n `but @EagerInstantiate is trying to set a conflicting Scope.Container.\\n ` +\n `Only one decorator should set the class scope, or all must agree on the same value.`\n );\n });\n\n metadata.eagerInstantiate = true;\n metadata.scope = {\n value: Scope.Container,\n appliedBy: \"EagerInstantiate\",\n };\n };\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>(token: () => Token<Value> | Tokens<Value>): 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 } from \"../token\";\nimport type { InjectDecorator, MethodDependency } from \"../tokenRegistry\";\n\n// @internal\nexport function updateParameterMetadata(\n decorator: InjectDecorator | \"Named\",\n target: object,\n propertyKey: string | symbol | undefined,\n parameterIndex: number,\n updateFn: (dependency: MethodDependency) => void,\n): void {\n // Error out immediately if the decorator has been applied to a static method\n if (propertyKey !== undefined && typeof target === \"function\") {\n assert(false, `@${decorator} cannot be used on static method ${target.name}.${String(propertyKey)}`);\n }\n\n if (propertyKey === undefined) {\n // Constructor\n const metadata = getMetadata(target as Constructor<any>);\n const dependency = metadata.getConstructorDependency(parameterIndex);\n updateFn(dependency);\n } else {\n // Instance method\n const metadata = getMetadata(target.constructor as Constructor<any>);\n const dependency = metadata.getMethodDependency(propertyKey, parameterIndex);\n updateFn(dependency);\n }\n}\n\n// Checks that a constructor or method parameter has only one injection decorator.\n// For example, if both `@Inject` and `@Optional` are used, it becomes difficult to\n// understand which one \"wins\", unless the user is aware of the decorator evaluation order.\n//\n// @internal\nexport function checkSingleDecorator(\n dependency: MethodDependency,\n target: object,\n propertyKey: string | symbol | undefined,\n parameterIndex: number,\n): void {\n assert(!dependency.appliedBy, () => {\n const where =\n propertyKey === undefined\n ? `${(target as Constructor<any>).name} constructor`\n : `${(target.constructor as Constructor<any>).name}.${String(propertyKey)}`;\n return `${where} parameter ${parameterIndex} declares multiple injection decorators, but only one is allowed`;\n });\n}\n","import type { Constructor, Token } from \"../token\";\nimport { forwardRef, isTokenRef, type TokenRef } from \"../tokensRef\";\nimport { checkSingleDecorator, updateParameterMetadata } from \"./utils\";\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): void {\n updateParameterMetadata(\"Inject\", target, propertyKey, parameterIndex, (dependency) => {\n checkSingleDecorator(dependency, target, propertyKey, parameterIndex);\n dependency.appliedBy = \"Inject\";\n dependency.tokenRef = isTokenRef(token) ? token : forwardRef(() => token);\n });\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>(tokens: TokenRef<Value> | TokensRef<Value>): 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 { forwardRef, isTokenRef, type TokenRef } from \"../tokensRef\";\nimport { checkSingleDecorator, updateParameterMetadata } from \"./utils\";\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): void {\n updateParameterMetadata(\"InjectAll\", target, propertyKey, parameterIndex, (dependency) => {\n checkSingleDecorator(dependency, target, propertyKey, parameterIndex);\n dependency.appliedBy = \"InjectAll\";\n dependency.tokenRef = isTokenRef(token) ? token : forwardRef(() => token);\n });\n };\n}\n","import { assert } from \"../errors\";\nimport { getMetadata } from \"../metadata\";\nimport type { Constructor } from \"../token\";\nimport { updateParameterMetadata } from \"./utils\";\n\n/**\n * Qualifies a class or an injected parameter with a unique name.\n *\n * This allows the container to distinguish between multiple implementations\n * of the same interface or type during registration and injection.\n *\n * @example\n * ```ts\n * @Named(\"dumbledore\")\n * class Dumbledore implements Wizard {}\n *\n * // Register Dumbledore with Type<Wizard>\n * container.register(IWizard, { useClass: Dumbledore });\n * const dumbledore = container.resolve(IWizard, \"dumbledore\");\n * ```\n *\n * @__NO_SIDE_EFFECTS__\n */\nexport function Named(name: string): ClassDecorator & ParameterDecorator {\n if (!name.trim()) {\n assert(false, \"the @Named qualifier cannot be empty or blank\");\n }\n\n return function (target: object, propertyKey?: string | symbol, parameterIndex?: number): void {\n if (parameterIndex === undefined) {\n // The decorator has been applied to the class\n const ctor = target as any as Constructor<any>;\n const metadata = getMetadata(ctor);\n assert(!metadata.name, `a @Named('${metadata.name}') qualifier has already been applied to ${ctor.name}`);\n metadata.name = name;\n } else {\n // The decorator has been applied to a method parameter\n updateParameterMetadata(\"Named\", target, propertyKey, parameterIndex, (dependency) => {\n assert(!dependency.name, `a @Named('${dependency.name}') qualifier has already been applied to the parameter`);\n dependency.name = name;\n });\n }\n };\n}\n","import type { Constructor, Token } from \"../token\";\nimport { forwardRef, isTokenRef, type TokenRef } from \"../tokensRef\";\nimport { checkSingleDecorator, updateParameterMetadata } from \"./utils\";\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): void {\n updateParameterMetadata(\"Optional\", target, propertyKey, parameterIndex, (dependency) => {\n checkSingleDecorator(dependency, target, propertyKey, parameterIndex);\n dependency.appliedBy = \"Optional\";\n dependency.tokenRef = isTokenRef(token) ? token : forwardRef(() => token);\n });\n };\n}\n","import type { Constructor, Token } from \"../token\";\nimport { forwardRef, isTokenRef, type TokenRef } from \"../tokensRef\";\nimport { checkSingleDecorator, updateParameterMetadata } from \"./utils\";\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): void {\n updateParameterMetadata(\"OptionalAll\", target, propertyKey, parameterIndex, (dependency) => {\n checkSingleDecorator(dependency, target, propertyKey, parameterIndex);\n dependency.appliedBy = \"OptionalAll\";\n dependency.tokenRef = isTokenRef(token) ? token : forwardRef(() => token);\n });\n };\n}\n","import { assert } from \"../errors\";\nimport { 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 const currentScope = metadata.scope;\n\n assert(!currentScope || currentScope.value === scope, () => {\n const { value, appliedBy } = currentScope!;\n const by = appliedBy === \"Scoped\" ? `another @${appliedBy} decorator` : `@${appliedBy}`;\n return (\n `class ${Class.name}: Scope.${value} was already set by ${by},\\n ` +\n `but @Scoped is trying to set a conflicting Scope.${scope}.\\n ` +\n `Only one decorator should set the class scope, or all must agree on the same value.`\n );\n });\n\n metadata.scope = {\n value: scope,\n appliedBy: \"Scoped\",\n };\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>, name?: string): 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>, name?: string): 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>, name?: string): 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>, name?: string): 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 * Runs a function inside the injection context of this injector.\n *\n * Note that injection functions (`inject`, `injectAll`, `optional`, `optionalAll`)\n * are only usable synchronously: they cannot be called from asynchronous callbacks\n * or after any `await` points.\n *\n * @param fn The function to be run in the context of this injector.\n * @returns The return value of the function, if any.\n */\n runInContext<ReturnType>(fn: () => ReturnType): ReturnType;\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<Injector>(() => {\n const context = ensureInjectionContext(\"Injector factory\");\n const resolution = context.resolution;\n\n const dependentFrame = resolution.stack.peek();\n const dependentRef = dependentFrame && resolution.dependents.get(dependentFrame.provider);\n\n const runInContext = <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 cleanups.forEach((cleanup) => cleanup?.());\n }\n };\n\n return {\n inject: <T>(token: Token<T>, name?: string) => runInContext(() => inject(token, name)),\n injectAll: <T>(token: Token<T>) => runInContext(() => injectAll(token)),\n optional: <T>(token: Token<T>, name?: string) => runInContext(() => optional(token, name)),\n optionalAll: <T>(token: Token<T>) => runInContext(() => optionalAll(token)),\n runInContext,\n };\n}, \"Injector\");\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 ? (next: Container[MethodKey]) => Container[MethodKey] : 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":["createType","typeName","type","name","inter","union","toString","isConstructor","token","assert","condition","message","Error","tag","expectNever","value","TypeError","String","throwUnregisteredError","spec","undefined","throwExistingUnregisteredError","sourceToken","targetTokenOrError","isError","untag","stack","startsWith","substring","trimStart","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","createInjectionContext","ensureInjectionContext","context","current","provide","next","prev","use","inject","container","resolve","injectBy","thisArg","resolution","currentFrame","currentRef","cleanup","provider","injectAll","resolveAll","Metadata","Class","dependencies","methods","Map","tokensRef","getRefTokens","Set","useClass","getConstructorDependency","index","i","findIndex","d","dependency","getMethodDependency","method","methodDeps","getMetadata","originalClass","classIdentityMap","metadata","metadataMap","setClassIdentityMapping","transformedClass","optional","optionalBy","optionalAll","isClassProvider","isFactoryProvider","isValueProvider","isExistingProvider","Scope","Inherited","Transient","Resolution","Container","getTypeName","proto","Object","getPrototypeOf","prototype","constructor","TokenRegistry","parent","myParent","getAll","internal","internals","getAllFromParent","registration","registrations","existing","filter","r","length","removedRegistrations","newRegistrations","array","deleteAll","tokens","from","keys","flat","clear","clearRegistrations","thisRegistrations","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","register","args","useExisting","eagerInstantiate","resolveProviderValue","existingProvider","trim","unregister","optionalOrName","localOptional","localName","autoRegisterClass","resolveRegistration","map","child","disposedRefs","currRegistration","currProvider","targetToken","e","resolveScopedValue","useValue","dependentRef","resolveScope","cleanups","valueRef","resolveConstructorDependencies","injectDependencies","forEach","dependentFrame","ctorDeps","appliedBy","ctor","msg","sort","a","b","dep","tokenRef","getRefToken","instance","bind","createContainer","AutoRegister","EagerInstantiate","currentScope","forwardRef","tokenOrTokens","tokensArray","isArray","isTokensRef","isTokenRef","updateParameterMetadata","decorator","target","propertyKey","parameterIndex","updateFn","checkSingleDecorator","where","Inject","Injectable","arg0","existingTokensRef","existingTokens","InjectAll","Named","Optional","OptionalAll","Scoped","by","Injector","runInContext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