@lppedd/di-wise-neo 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +64 -8
- package/dist/cjs/index.d.ts +26 -26
- package/dist/cjs/index.js +10 -10
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/index.d.mts +26 -26
- package/dist/es/index.mjs +9 -9
- package/dist/es/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/es/index.mjs
CHANGED
@@ -233,15 +233,15 @@ const Scope = {
|
|
233
233
|
*
|
234
234
|
* @example
|
235
235
|
* ```ts
|
236
|
-
* const Spell =
|
236
|
+
* const Spell = createType<Spell>("Spell");
|
237
237
|
* ```
|
238
238
|
*
|
239
239
|
* @__NO_SIDE_EFFECTS__
|
240
|
-
*/ function
|
240
|
+
*/ function createType(typeName) {
|
241
241
|
const type = {
|
242
242
|
name: `Type<${typeName}>`,
|
243
|
-
inter:
|
244
|
-
union:
|
243
|
+
inter: createType,
|
244
|
+
union: createType,
|
245
245
|
toString () {
|
246
246
|
return type.name;
|
247
247
|
}
|
@@ -347,7 +347,7 @@ function isBuilder(provider) {
|
|
347
347
|
* ```ts
|
348
348
|
* class Wizard {
|
349
349
|
* wand = inject(
|
350
|
-
*
|
350
|
+
* build(() => {
|
351
351
|
* const wand = inject(Wand);
|
352
352
|
* wand.owner = this;
|
353
353
|
* // ...
|
@@ -358,8 +358,8 @@ function isBuilder(provider) {
|
|
358
358
|
* ```
|
359
359
|
*
|
360
360
|
* @__NO_SIDE_EFFECTS__
|
361
|
-
*/ function
|
362
|
-
const token =
|
361
|
+
*/ function build(factory) {
|
362
|
+
const token = createType(`Build<${getTypeName(factory)}>`);
|
363
363
|
const provider = {
|
364
364
|
useFactory: factory
|
365
365
|
};
|
@@ -959,7 +959,7 @@ function OptionalAll(token) {
|
|
959
959
|
* const wizard = container.resolve(Wizard);
|
960
960
|
* wizard.getWand(); // => Wand
|
961
961
|
* ```
|
962
|
-
*/ const Injector = /*@__PURE__*/
|
962
|
+
*/ const Injector = /*@__PURE__*/ build(function Injector() {
|
963
963
|
const context = ensureInjectionContext(Injector);
|
964
964
|
const resolution = context.resolution;
|
965
965
|
const dependentFrame = resolution.stack.peek();
|
@@ -1033,5 +1033,5 @@ function OptionalAll(token) {
|
|
1033
1033
|
return container;
|
1034
1034
|
}
|
1035
1035
|
|
1036
|
-
export { AutoRegister,
|
1036
|
+
export { AutoRegister, Inject, InjectAll, Injectable, Injector, Optional, OptionalAll, Scope, Scoped, applyMiddleware, build, createContainer, createType, forwardRef, inject, injectAll, injectBy };
|
1037
1037
|
//# sourceMappingURL=index.mjs.map
|
package/dist/es/index.mjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../src/errors.ts","../../src/utils/context.ts","../../src/utils/invariant.ts","../../src/utils/keyedStack.ts","../../src/utils/weakRefMap.ts","../../src/injectionContext.ts","../../src/inject.ts","../../src/injectAll.ts","../../src/metadata.ts","../../src/optional.ts","../../src/optionalAll.ts","../../src/provider.ts","../../src/scope.ts","../../src/token.ts","../../src/utils/typeName.ts","../../src/tokenRegistry.ts","../../src/utils/disposable.ts","../../src/defaultContainer.ts","../../src/container.ts","../../src/decorators/autoRegister.ts","../../src/tokensRef.ts","../../src/decorators/decorators.ts","../../src/decorators/inject.ts","../../src/decorators/injectable.ts","../../src/decorators/injectAll.ts","../../src/decorators/optional.ts","../../src/decorators/optionalAll.ts","../../src/decorators/scoped.ts","../../src/injector.ts","../../src/middleware.ts"],"sourcesContent":["import type { Token } from \"./token\";\n\n// @internal\nexport function assert(condition: unknown, message: string | (() => string)): asserts condition {\n if (!condition) {\n const resolvedMessage = typeof message === \"string\" ? message : message();\n throw new Error(tag(resolvedMessage));\n }\n}\n\n// @internal\nexport function expectNever(value: never): never {\n throw new TypeError(tag(`unexpected value ${String(value)}`));\n}\n\n// @internal\nexport function throwUnregisteredError(token: Token): never {\n throw new Error(tag(`unregistered token ${token.name}`));\n}\n\n// @internal\nexport function throwExistingUnregisteredError(sourceToken: Token, targetTokenOrError: Token | Error): never {\n let message = tag(`token resolution error encountered while resolving ${sourceToken.name}`);\n\n if (isError(targetTokenOrError)) {\n message += `\\n [cause] ${untag(targetTokenOrError.message)}`;\n } else {\n message += `\\n [cause] the aliased token ${targetTokenOrError.name} is not registered`;\n }\n\n throw new Error(message);\n}\n\nfunction isError(value: any): value is Error {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return value && value.stack && value.message && typeof value.message === \"string\";\n}\n\nfunction tag(message: string): string {\n return `[di-wise-neo] ${message}`;\n}\n\nfunction untag(message: string): string {\n return message.startsWith(\"[di-wise-neo]\") //\n ? message.substring(13).trimStart()\n : message;\n}\n","// @internal\nexport function createInjectionContext<T extends {}>(): readonly [\n (next: T) => () => T | null,\n () => T | null,\n] {\n let current: T | null = null;\n\n function provide(next: T): () => T | null {\n const prev = current;\n current = next;\n return () => (current = prev);\n }\n\n function use(): T | null {\n return current;\n }\n\n return [provide, use] as const;\n}\n","// @internal\nexport function invariant(condition: unknown): asserts condition {\n if (!condition) {\n throw new Error(\"invariant violation\");\n }\n}\n","import { invariant } from \"./invariant\";\n\n// @internal\nexport class KeyedStack<K extends object, V> {\n private readonly myEntries = new Array<{ key: K; value: V }>();\n private readonly myKeys = new WeakSet<K>();\n\n has(key: K): boolean {\n return this.myKeys.has(key);\n }\n\n peek(): V | undefined {\n const entry = this.myEntries.at(-1);\n return entry?.value;\n }\n\n push(key: K, value: V): () => void {\n invariant(!this.has(key));\n this.myKeys.add(key);\n this.myEntries.push({ key, value });\n return () => {\n this.myEntries.pop();\n this.myKeys.delete(key);\n };\n }\n}\n","import { invariant } from \"./invariant\";\n\n// @internal\nexport class WeakRefMap<K extends WeakKey, V extends object> {\n private readonly myMap = new WeakMap<K, WeakRef<V>>();\n\n get(key: K): V | undefined {\n const ref = this.myMap.get(key);\n\n if (ref) {\n const value = ref.deref();\n\n if (value) {\n return value;\n }\n\n this.myMap.delete(key);\n }\n }\n\n set(key: K, value: V): () => void {\n invariant(!this.get(key));\n this.myMap.set(key, new WeakRef(value));\n return () => {\n this.myMap.delete(key);\n };\n }\n}\n","import type { Container } from \"./container\";\nimport { assert } from \"./errors\";\nimport type { Provider } from \"./provider\";\nimport type { Scope } from \"./scope\";\nimport { createInjectionContext } from \"./utils/context\";\nimport { KeyedStack } from \"./utils/keyedStack\";\nimport { WeakRefMap } from \"./utils/weakRefMap\";\nimport type { ValueRef } from \"./valueRef\";\n\n// @internal\nexport interface ResolutionFrame {\n readonly scope: Exclude<Scope, typeof Scope.Inherited>;\n readonly provider: Provider;\n}\n\n// @internal\nexport interface Resolution {\n readonly stack: KeyedStack<Provider, ResolutionFrame>;\n readonly values: WeakRefMap<Provider, ValueRef>;\n readonly dependents: WeakRefMap<Provider, ValueRef>;\n}\n\n// @internal\nexport interface InjectionContext {\n readonly container: Container;\n readonly resolution: Resolution;\n}\n\n// @internal\nexport function createResolution(): Resolution {\n return {\n stack: new KeyedStack(),\n values: new WeakRefMap(),\n dependents: new WeakRefMap(),\n };\n}\n\n// @internal\nexport const [provideInjectionContext, useInjectionContext] = createInjectionContext<InjectionContext>();\n\n// @internal\nexport function ensureInjectionContext(fn: Function): InjectionContext {\n const context = useInjectionContext();\n assert(context, `${fn.name}() can only be invoked within an injection context`);\n return context;\n}\n","import { ensureInjectionContext } from \"./injectionContext\";\nimport type { Constructor, Token } from \"./token\";\n\n/**\n * Injects the instance associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\nexport function inject<Instance extends object>(Class: Constructor<Instance>): Instance;\n\n/**\n * Injects the value associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\nexport function inject<Value>(token: Token<Value>): Value;\n\nexport function inject<T>(token: Token<T>): T {\n const context = ensureInjectionContext(inject);\n return context.container.resolve(token);\n}\n\n/**\n * Injects the instance associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n *\n * Compared to {@link inject}, `injectBy` accepts a `thisArg` argument\n * (the containing class) which is used to resolve circular dependencies.\n *\n * @example\n * ```ts\n * class Wand {\n * owner = inject(Wizard);\n * }\n *\n * class Wizard {\n * wand = injectBy(this, Wand);\n * }\n * ```\n *\n * @param thisArg - The containing instance, used to help resolve circular dependencies.\n * @param Class - The class to resolve.\n */\nexport function injectBy<Instance extends object>(thisArg: any, Class: Constructor<Instance>): Instance;\n\n/**\n * Injects the value associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n *\n * Compared to {@link inject}, `injectBy` accepts a `thisArg` argument\n * (the containing class) which is used to resolve circular dependencies.\n *\n * @example\n * ```ts\n * class Wand {\n * owner = inject(Wizard);\n * }\n *\n * class Wizard {\n * wand = injectBy(this, Wand);\n * }\n * ```\n *\n * @param thisArg - The containing instance, used to help resolve circular dependencies.\n * @param token - The token to resolve.\n */\nexport function injectBy<Value>(thisArg: any, token: Token<Value>): Value;\n\nexport function injectBy<T>(thisArg: any, token: Token<T>): T {\n const context = ensureInjectionContext(injectBy);\n const resolution = context.resolution;\n const currentFrame = resolution.stack.peek();\n\n if (!currentFrame) {\n return inject(token);\n }\n\n const currentRef = { current: thisArg };\n const cleanup = resolution.dependents.set(currentFrame.provider, currentRef);\n\n try {\n return inject(token);\n } finally {\n cleanup();\n }\n}\n","import { ensureInjectionContext } from \"./injectionContext\";\nimport type { Constructor, Token } from \"./token\";\n\n/**\n * Injects all instances provided by the registrations associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\nexport function injectAll<Instance extends object>(Class: Constructor<Instance>): Instance[];\n\n/**\n * Injects all values provided by the registrations associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\nexport function injectAll<Value>(token: Token<Value>): NonNullable<Value>[];\n\nexport function injectAll<T>(token: Token<T>): NonNullable<T>[] {\n const context = ensureInjectionContext(injectAll);\n return context.container.resolveAll(token);\n}\n","import type { ClassProvider } from \"./provider\";\nimport type { Scope } from \"./scope\";\nimport type { Constructor } from \"./token\";\nimport type { Dependencies } from \"./tokenRegistry\";\nimport type { TokensRef } from \"./tokensRef\";\n\n// @internal\nexport interface Metadata<This extends object = any> {\n autoRegister?: boolean;\n scope?: Scope;\n tokensRef: TokensRef<This>;\n provider: ClassProvider<This>;\n dependencies: Dependencies;\n}\n\n// @internal\nexport function getMetadata<T extends object>(Class: Constructor<T>): Metadata<T> {\n let metadata = metadataMap.get(Class);\n\n if (!metadata) {\n metadataMap.set(\n Class,\n (metadata = {\n tokensRef: {\n getRefTokens: () => new Set(),\n },\n provider: {\n useClass: Class,\n },\n dependencies: {\n constructor: [],\n methods: new Map(),\n },\n }),\n );\n }\n\n return metadata;\n}\n\nconst metadataMap = new WeakMap<Constructor<object>, Metadata>();\n","import { ensureInjectionContext } from \"./injectionContext\";\nimport type { Constructor, Token } from \"./token\";\n\n/**\n * Injects the instance associated with the given class,\n * or `undefined` if the class is not registered in the container.\n */\nexport function optional<Instance extends object>(Class: Constructor<Instance>): Instance | undefined;\n\n/**\n * Injects the value associated with the given token,\n * or `undefined` if the token is not registered in the container.\n */\nexport function optional<Value>(token: Token<Value>): Value | undefined;\n\nexport function optional<T>(token: Token<T>): T | undefined {\n const context = ensureInjectionContext(optional);\n return context.container.resolve(token, true);\n}\n\n/**\n * Injects the instance associated with the given class,\n * or `undefined` if the class is not registered in the container.\n *\n * Compared to {@link optional}, `optionalBy` accepts a `thisArg` argument\n * (the containing class) which is used to resolve circular dependencies.\n *\n * @param thisArg - The containing instance, used to help resolve circular dependencies.\n * @param Class - The class to resolve.\n */\nexport function optionalBy<Instance extends object>(\n thisArg: any,\n Class: Constructor<Instance>,\n): Instance | undefined;\n\n/**\n * Injects the value associated with the given token,\n * or `undefined` if the token is not registered in the container.\n *\n * Compared to {@link optional}, `optionalBy` accepts a `thisArg` argument\n * (the containing class) which is used to resolve circular dependencies.\n *\n * @param thisArg - The containing instance, used to help resolve circular dependencies.\n * @param token - The token to resolve.\n */\nexport function optionalBy<Value>(thisArg: any, token: Token<Value>): Value | undefined;\n\nexport function optionalBy<T>(thisArg: any, token: Token<T>): T | undefined {\n const context = ensureInjectionContext(optionalBy);\n const resolution = context.resolution;\n const currentFrame = resolution.stack.peek();\n\n if (!currentFrame) {\n return optional(token);\n }\n\n const currentRef = { current: thisArg };\n const cleanup = resolution.dependents.set(currentFrame.provider, currentRef);\n\n try {\n return optional(token);\n } finally {\n cleanup();\n }\n}\n","import { ensureInjectionContext } from \"./injectionContext\";\nimport type { Constructor, Token } from \"./token\";\n\n/**\n * Injects all instances provided by the registrations associated with the given class,\n * or an empty array if the class is not registered in the container.\n */\nexport function optionalAll<Instance extends object>(Class: Constructor<Instance>): Instance[];\n\n/**\n * Injects all values provided by the registrations associated with the given token,\n * or an empty array if the token is not registered in the container.\n */\nexport function optionalAll<Value>(token: Token<Value>): NonNullable<Value>[];\n\nexport function optionalAll<T>(token: Token<T>): NonNullable<T>[] {\n const context = ensureInjectionContext(optionalAll);\n return context.container.resolveAll(token, true);\n}\n","import type { Constructor, Token } from \"./token\";\n\n/**\n * Provides a class instance for a token via a class constructor.\n */\nexport interface ClassProvider<Instance extends object> {\n readonly useClass: Constructor<Instance>;\n}\n\n/**\n * Provides a value for a token via another existing token.\n */\nexport interface ExistingProvider<Value> {\n readonly useExisting: Token<Value>;\n}\n\n/**\n * Provides a value for a token via a factory function.\n *\n * The factory function runs inside the injection context\n * and can thus access dependencies via {@link inject}.\n */\nexport interface FactoryProvider<Value> {\n readonly useFactory: (...args: []) => Value;\n}\n\n/**\n * Provides a direct - already constructed - value for a token.\n */\nexport interface ValueProvider<T> {\n readonly useValue: T;\n}\n\n/**\n * A token provider.\n */\nexport type Provider<Value = any> =\n | ClassProvider<Value & object>\n | ExistingProvider<Value>\n | FactoryProvider<Value>\n | ValueProvider<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 isExistingProvider<T>(provider: Provider<T>): provider is ExistingProvider<T> {\n return \"useExisting\" 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","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 * Name of the type.\n */\n readonly name: string;\n\n /**\n * Create an intersection type from another type.\n *\n * @example\n * ```ts\n * const A = Type<A>(\"A\");\n * const B = Type<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 * Create a union type from another type.\n *\n * @example\n * ```ts\n * const A = Type<A>(\"A\");\n * const B = Type<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 readonly length: number;\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 * Create a type token.\n *\n * @example\n * ```ts\n * const Spell = Type<Spell>(\"Spell\");\n * ```\n *\n * @__NO_SIDE_EFFECTS__\n */\nexport function Type<T>(typeName: string): Type<T> {\n const type = {\n name: `Type<${typeName}>`,\n inter: Type,\n union: Type,\n toString(): string {\n return type.name;\n },\n };\n\n return type;\n}\n\n// @internal\nexport function isConstructor<T>(token: Type<T> | Constructor<T & object>): token is Constructor<T & object> {\n return typeof token == \"function\";\n}\n","// @internal\nexport function getTypeName(value: unknown): string {\n if (typeof value == \"string\") {\n return `\"${value}\"`;\n }\n\n if (typeof value == \"function\") {\n return (value.name && `typeof ${value.name}`) || \"Function\";\n }\n\n if (typeof value == \"object\") {\n if (value === null) {\n return \"null\";\n }\n\n const proto: object | null = Object.getPrototypeOf(value);\n\n if (proto && proto !== Object.prototype) {\n const constructor: unknown = proto.constructor;\n\n if (typeof constructor == \"function\" && constructor.name) {\n return constructor.name;\n }\n }\n }\n\n return typeof value;\n}\n","import { assert } from \"./errors\";\nimport type { FactoryProvider, Provider } from \"./provider\";\nimport { Scope } from \"./scope\";\nimport { type Constructor, type Token, Type } from \"./token\";\nimport type { TokenRef } from \"./tokensRef\";\nimport { getTypeName } from \"./utils/typeName\";\nimport type { ValueRef } from \"./valueRef\";\n\n/**\n * Token registration options.\n */\nexport interface RegistrationOptions {\n /**\n * The scope of the registration.\n */\n readonly scope?: Scope;\n}\n\n// @internal\nexport type Decorator = \"Inject\" | \"InjectAll\" | \"Optional\" | \"OptionalAll\";\n\n// @internal\nexport interface MethodDependency {\n readonly decorator: Decorator;\n readonly tokenRef: TokenRef;\n\n // The index of the annotated parameter (zero-based)\n readonly index: number;\n}\n\n// @internal\nexport interface Dependencies {\n readonly constructor: MethodDependency[];\n readonly methods: Map<string | symbol, MethodDependency[]>;\n}\n\n// @internal\nexport interface Registration<T = any> {\n value?: ValueRef<T>;\n readonly provider: Provider<T>;\n readonly options?: RegistrationOptions;\n readonly dependencies?: Dependencies;\n}\n\n// @internal\nexport class TokenRegistry {\n private readonly myMap = new Map<Token, Registration[]>();\n\n constructor(private readonly parent: TokenRegistry | undefined) {}\n\n get<T>(token: Token<T>): Registration<T> | undefined {\n // To clarify, at(-1) means we take the last added registration for this token\n return this.getAll(token)?.at(-1);\n }\n\n getAll<T>(token: Token<T>): Registration<T>[] | undefined {\n const internal = internals.get(token);\n return (internal && [internal]) || this.getAllFromParent(token);\n }\n\n //\n // set(...) overloads added because of TS distributive conditional types.\n //\n // TODO(Edoardo): is there a better way? Maybe refactor the Token<T> type\n // into two types, TokenObject<T extends object> | Token<T>\n //\n\n set<T extends object>(token: Type<T> | Constructor<T>, registration: Registration<T>): void;\n set<T>(token: Token<T>, registration: Registration<T>): void;\n set<T>(token: Token<T>, registration: Registration<T>): void {\n assert(!internals.has(token), `cannot register reserved token ${token.name}`);\n\n let registrations = this.myMap.get(token);\n\n if (!registrations) {\n this.myMap.set(token, (registrations = []));\n }\n\n registrations.push(registration);\n }\n\n delete<T>(token: Token<T>): Registration<T>[] | undefined {\n const registrations = this.myMap.get(token);\n this.myMap.delete(token);\n return registrations;\n }\n\n deleteAll(): [Token[], Registration[]] {\n const tokens = Array.from(this.myMap.keys());\n const registrations = Array.from(this.myMap.values()).flat();\n this.myMap.clear();\n return [tokens, registrations];\n }\n\n clearRegistrations(): unknown[] {\n const values = new Set<unknown>();\n\n for (const registrations of this.myMap.values()) {\n for (let i = 0; i < registrations.length; i++) {\n const registration = registrations[i]!;\n const value = registration.value;\n\n if (value) {\n values.add(value.current);\n }\n\n registrations[i] = {\n ...registration,\n value: undefined,\n };\n }\n }\n\n return Array.from(values);\n }\n\n private getAllFromParent<T>(token: Token<T>): Registration<T>[] | undefined {\n const registrations = this.myMap.get(token);\n return registrations || this.parent?.getAllFromParent(token);\n }\n}\n\n// @internal\nexport function isBuilder(provider: Provider): boolean {\n return builders.has(provider);\n}\n\n/**\n * Create a one-off type token from a factory function.\n *\n * @example\n * ```ts\n * class Wizard {\n * wand = inject(\n * Build(() => {\n * const wand = inject(Wand);\n * wand.owner = this;\n * // ...\n * return wand;\n * }),\n * );\n * }\n * ```\n *\n * @__NO_SIDE_EFFECTS__\n */\nexport function Build<Value>(factory: (...args: []) => Value): Type<Value> {\n const token = Type<Value>(`Build<${getTypeName(factory)}>`);\n const provider: FactoryProvider<Value> = {\n useFactory: factory,\n };\n\n internals.set(token, {\n provider: provider,\n options: {\n scope: Scope.Transient,\n },\n });\n\n builders.add(provider);\n return token;\n}\n\nconst internals = new WeakMap<Token, Registration>();\nconst builders = new WeakSet<Provider>();\n","// @internal\nexport interface Disposable {\n dispose(): void;\n}\n\n// @internal\nexport function isDisposable(value: any): value is Disposable {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return value && typeof value === \"object\" && typeof value.dispose === \"function\";\n}\n","import type { Container, ContainerOptions } from \"./container\";\nimport { assert, expectNever, throwExistingUnregisteredError, throwUnregisteredError } from \"./errors\";\nimport { injectBy } from \"./inject\";\nimport { injectAll } from \"./injectAll\";\nimport { createResolution, provideInjectionContext, useInjectionContext } from \"./injectionContext\";\nimport { getMetadata } from \"./metadata\";\nimport { optionalBy } from \"./optional\";\nimport { optionalAll } from \"./optionalAll\";\nimport {\n isClassProvider,\n isExistingProvider,\n isFactoryProvider,\n isValueProvider,\n type Provider,\n} from \"./provider\";\nimport { Scope } from \"./scope\";\nimport { type Constructor, isConstructor, type Token } 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 DefaultContainer implements Container {\n // eslint-disable-next-line no-use-before-define\n private readonly myChildren: Set<DefaultContainer> = new Set();\n private readonly myOptions: ContainerOptions;\n private readonly myTokenRegistry: TokenRegistry;\n private myDisposed: boolean = false;\n\n constructor(\n private readonly myParent: DefaultContainer | undefined,\n options: Partial<ContainerOptions>,\n ) {\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 DefaultContainer(this, {\n ...this.myOptions,\n ...options,\n });\n\n this.myChildren.add(container);\n return container;\n }\n\n clearCache(): unknown[] {\n this.checkDisposed();\n return this.myTokenRegistry.clearRegistrations();\n }\n\n getCached<T>(token: Token<T>): T | undefined {\n this.checkDisposed();\n const registration = this.myTokenRegistry.get(token);\n return registration?.value?.current;\n }\n\n getAllCached<T>(token: Token<T>): T[] {\n this.checkDisposed();\n const registrations = this.myTokenRegistry.getAll(token);\n\n if (!registrations) {\n return [];\n }\n\n const values = new Set<T>();\n\n for (const registration of registrations) {\n const value = registration.value;\n\n if (value) {\n values.add(value.current);\n }\n }\n\n return Array.from(values);\n }\n\n resetRegistry(): unknown[] {\n this.checkDisposed();\n const [, registrations] = this.myTokenRegistry.deleteAll();\n const values = new Set<unknown>();\n\n for (const registration of registrations) {\n const value = registration.value;\n\n if (value) {\n values.add(value.current);\n }\n }\n\n return Array.from(values);\n }\n\n isRegistered(token: Token): boolean {\n this.checkDisposed();\n return this.myTokenRegistry.get(token) !== undefined;\n }\n\n register<T>(...args: [Constructor<T & object>] | [Token<T>, Provider<T>, RegistrationOptions?]): this {\n this.checkDisposed();\n\n if (args.length == 1) {\n const Class = args[0];\n const metadata = getMetadata(Class);\n\n // Register the class itself\n this.myTokenRegistry.set(Class, {\n // The provider is of type ClassProvider, initialized by getMetadata\n provider: metadata.provider,\n options: {\n scope: metadata.scope,\n },\n dependencies: metadata.dependencies,\n });\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 } else {\n const [token, provider, options] = args;\n\n if (isClassProvider(provider)) {\n const Class = provider.useClass;\n const metadata = getMetadata(Class);\n this.myTokenRegistry.set(token, {\n provider: metadata.provider,\n options: {\n // The explicit registration options override what is specified\n // via class decorators (e.g., @Scoped)\n scope: metadata.scope,\n ...options,\n },\n dependencies: metadata.dependencies,\n });\n } else {\n if (isExistingProvider(provider)) {\n assert(\n token !== provider.useExisting,\n `the useExisting token ${token.name} cannot be the same as the token being registered`,\n );\n }\n\n this.myTokenRegistry.set(token, {\n provider: provider,\n options: options,\n });\n }\n }\n\n return this;\n }\n\n unregister<T>(token: Token<T>): T[] {\n this.checkDisposed();\n const registrations = this.myTokenRegistry.delete(token);\n\n if (!registrations) {\n return [];\n }\n\n const values = new Set<T>();\n\n for (const registration of registrations) {\n const value = registration.value;\n\n if (value) {\n values.add(value.current);\n }\n }\n\n return Array.from(values);\n }\n\n resolve<T>(token: Token<T>, optional?: boolean): T | undefined {\n this.checkDisposed();\n const registration = this.myTokenRegistry.get(token);\n\n if (registration) {\n return this.resolveRegistration(token, registration);\n }\n\n if (isConstructor(token)) {\n return this.instantiateClass(token, optional);\n }\n\n return optional ? undefined : throwUnregisteredError(token);\n }\n\n resolveAll<T>(token: Token<T>, optional?: boolean): NonNullable<T>[] {\n this.checkDisposed();\n const registrations = this.myTokenRegistry.getAll(token);\n\n if (registrations) {\n return registrations\n .map((registration) => this.resolveRegistration(token, registration))\n .filter((value) => value != null);\n }\n\n if (isConstructor(token)) {\n const instance = this.instantiateClass(token, optional);\n return instance === undefined // = could not resolve, but since it is optional\n ? []\n : [instance];\n }\n\n return optional ? [] : throwUnregisteredError(token);\n }\n\n dispose(): void {\n if (this.myDisposed) {\n return;\n }\n\n // Dispose children containers first\n for (const child of this.myChildren) {\n child.dispose();\n }\n\n this.myChildren.clear();\n\n // Remove ourselves from our parent container\n this.myParent?.myChildren?.delete(this);\n this.myDisposed = true;\n\n const [, registrations] = this.myTokenRegistry.deleteAll();\n const disposedRefs = new Set<any>();\n\n // Dispose all resolved (aka instantiated) tokens that implement the Disposable interface\n for (const registration of registrations) {\n const value = registration.value?.current;\n\n if (isDisposable(value) && !disposedRefs.has(value)) {\n disposedRefs.add(value);\n value.dispose();\n }\n }\n\n // Allow values to be GCed\n disposedRefs.clear();\n }\n\n private resolveRegistration<T>(token: Token<T>, registration: Registration<T>): T {\n let currRegistration: Registration<T> | undefined = registration;\n let currProvider = currRegistration.provider;\n\n while (isExistingProvider(currProvider)) {\n const targetToken = currProvider.useExisting;\n currRegistration = this.myTokenRegistry.get(targetToken);\n\n if (!currRegistration) {\n throwExistingUnregisteredError(token, targetToken);\n }\n\n currProvider = currRegistration.provider;\n }\n\n try {\n return this.resolveProviderValue(currRegistration, currProvider);\n } catch (e) {\n // If we were trying to resolve a token registered via ExistingProvider,\n // we must add the cause of the error to the message\n if (isExistingProvider(registration.provider)) {\n throwExistingUnregisteredError(token, e as Error);\n }\n\n throw e;\n }\n }\n\n private instantiateClass<T extends object>(Class: Constructor<T>, optional?: boolean): T | undefined {\n const metadata = getMetadata(Class);\n\n if (metadata.autoRegister ?? this.myOptions.autoRegister) {\n this.register(Class);\n return (this as Container).resolve(Class);\n }\n\n const scope = this.resolveScope(metadata.scope);\n\n if (optional && scope === Scope.Container) {\n // It would not be possible to resolve the class in container scope,\n // as that would require prior registration.\n // However, since resolution is marked optional, we simply return undefined.\n return undefined;\n }\n\n assert(\n scope !== Scope.Container,\n `unregistered class ${Class.name} cannot be resolved in container scope`,\n );\n\n const registration: Registration<T> = {\n provider: metadata.provider,\n options: {\n scope: scope,\n },\n dependencies: metadata.dependencies,\n };\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n return this.resolveScopedValue(registration, (args) => new Class(...args));\n }\n\n private resolveProviderValue<T>(registration: Registration<T>, provider: Provider<T>): T {\n assert(registration.provider === provider, \"internal error: mismatching provider\");\n\n if (isClassProvider(provider)) {\n const Class = provider.useClass;\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n return this.resolveScopedValue(registration, (args) => new Class(...args));\n }\n\n if (isFactoryProvider(provider)) {\n const factory = provider.useFactory;\n return this.resolveScopedValue(registration, factory);\n }\n\n if (isValueProvider(provider)) {\n return provider.useValue;\n }\n\n if (isExistingProvider(provider)) {\n assert(false, \"internal error: unexpected ExistingProvider\");\n }\n\n expectNever(provider);\n }\n\n private resolveScopedValue<T>(registration: Registration<T>, factory: (...args: any[]) => T): T {\n let context = useInjectionContext();\n\n if (!context || context.container !== this) {\n context = {\n container: this,\n resolution: createResolution(),\n };\n }\n\n const resolution = context.resolution;\n const provider = registration.provider;\n const options = registration.options;\n\n if (resolution.stack.has(provider)) {\n const dependentRef = resolution.dependents.get(provider);\n assert(dependentRef, \"circular dependency detected\");\n return dependentRef.current;\n }\n\n const scope = this.resolveScope(options?.scope, context);\n const cleanups = [\n provideInjectionContext(context),\n !isBuilder(provider) && resolution.stack.push(provider, { provider, scope }),\n ];\n\n try {\n switch (scope) {\n case Scope.Container: {\n const valueRef = registration.value;\n\n if (valueRef) {\n return valueRef.current;\n }\n\n const args = this.resolveConstructorDependencies(registration);\n const value = this.injectDependencies(registration, factory(args));\n registration.value = { current: value };\n return value;\n }\n case Scope.Resolution: {\n const valueRef = resolution.values.get(provider);\n\n if (valueRef) {\n return valueRef.current;\n }\n\n const args = this.resolveConstructorDependencies(registration);\n const value = this.injectDependencies(registration, factory(args));\n resolution.values.set(provider, { current: value });\n return value;\n }\n case Scope.Transient: {\n const args = this.resolveConstructorDependencies(registration);\n return this.injectDependencies(registration, factory(args));\n }\n }\n } finally {\n cleanups.forEach((cleanup) => cleanup && cleanup());\n }\n }\n\n private resolveScope(\n scope = this.myOptions.defaultScope,\n context = useInjectionContext(),\n ): Exclude<Scope, typeof Scope.Inherited> {\n if (scope == Scope.Inherited) {\n const dependentFrame = context?.resolution.stack.peek();\n return dependentFrame?.scope || Scope.Transient;\n }\n\n return scope;\n }\n\n private resolveConstructorDependencies<T>(registration: Registration<T>): any[] {\n const dependencies = registration.dependencies;\n\n if (dependencies) {\n assert(isClassProvider(registration.provider), `internal error: not a ClassProvider`);\n const ctorDeps = dependencies.constructor;\n\n if (ctorDeps.length > 0) {\n // Let's check if all necessary constructor parameters are decorated.\n // If not, we cannot safely create an instance.\n const ctor = registration.provider.useClass;\n assert(ctor.length === ctorDeps.length, () => {\n const msg = `expected ${ctor.length} decorated constructor parameters in ${ctor.name}`;\n return msg + `, but found ${ctorDeps.length}`;\n });\n\n return ctorDeps\n .sort((a, b) => a.index - b.index)\n .map((dep) => {\n const token = dep.tokenRef.getRefToken();\n switch (dep.decorator) {\n case \"Inject\":\n return this.resolve(token);\n case \"InjectAll\":\n return this.resolveAll(token);\n case \"Optional\":\n return this.resolve(token, true);\n case \"OptionalAll\":\n return this.resolveAll(token, true);\n }\n });\n }\n }\n\n return [];\n }\n\n private injectDependencies<T>(registration: Registration<T>, instance: T): T {\n const dependencies = registration.dependencies;\n\n if (dependencies) {\n assert(isClassProvider(registration.provider), `internal error: not a ClassProvider`);\n const ctor = registration.provider.useClass;\n\n // Perform method injection\n for (const [key, methodDeps] of dependencies.methods) {\n // Let's check if all necessary method parameters are decorated.\n // If not, we cannot safely invoke the method.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const method = (instance as any)[key] as Function;\n assert(methodDeps.length === method.length, () => {\n const msg = `expected ${method.length} decorated method parameters`;\n return msg + ` in ${ctor.name}.${String(key)}, but found ${methodDeps.length}`;\n });\n\n const args = methodDeps\n .sort((a, b) => a.index - b.index)\n .map((dep) => {\n const token = dep.tokenRef.getRefToken();\n switch (dep.decorator) {\n case \"Inject\":\n return injectBy(instance, token);\n case \"InjectAll\":\n return injectAll(token);\n case \"Optional\":\n return optionalBy(instance, token);\n case \"OptionalAll\":\n return optionalAll(token);\n }\n });\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n method.bind(instance)(...args);\n }\n }\n\n return instance;\n }\n\n private checkDisposed(): void {\n assert(!this.myDisposed, \"the container is disposed\");\n }\n}\n","import { DefaultContainer } from \"./defaultContainer\";\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): boolean;\n\n /**\n * Registers a {@link ClassProvider}, using the class itself as its token.\n *\n * Tokens provided to the {@link Injectable} decorator applied to the class\n * are also registered as aliases. The scope is determined by the {@link Scoped}\n * decorator, if present.\n */\n register<Instance extends object>(Class: Constructor<Instance>): this;\n\n /**\n * Registers a {@link ClassProvider} with a token.\n */\n register<Instance extends object, ProviderInstance extends Instance>(\n token: Token<Instance>,\n provider: ClassProvider<ProviderInstance>,\n options?: RegistrationOptions,\n ): this;\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 ): this;\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>(\n token: Token<Value>,\n provider: ExistingProvider<ProviderValue>,\n ): this;\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>(\n token: Token<Value>,\n provider: ValueProvider<ProviderValue>,\n ): this;\n\n /**\n * Removes all registrations for the given token from the container's internal registry.\n *\n * Returns an array of distinct cached values that were stored within the removed registrations.\n * Values from {@link ValueProvider} registrations are not included, as they are not cached.\n *\n * Note that only this container is affected. Parent containers, if any, remain unchanged.\n */\n unregister<Value>(token: Token<Value>): Value[];\n\n /**\n * Resolves the given class to the instance associated with it.\n *\n * If the class is registered in this container or any of its parent containers,\n * an instance is created using the most recent registration.\n *\n * If the class is not registered, but it is decorated with {@link AutoRegister},\n * or {@link ContainerOptions.autoRegister} is true, the class is registered automatically.\n * Otherwise, resolution fails.\n * The scope for the automatic registration is determined by either\n * the {@link Scoped} decorator on the class, or {@link ContainerOptions.defaultScope}.\n *\n * If `optional` is false or is not passed and the class is not registered in the container\n * (and could not be auto-registered), an error is thrown.\n * Otherwise, if `optional` is true, `undefined` is returned.\n *\n * The resolution behavior depends on the {@link Provider} used during registration:\n * - For {@link ValueProvider}, the explicitly provided instance is returned.\n * - For {@link FactoryProvider}, the factory function is invoked to create the instance.\n * - For {@link ClassProvider}, a new instance of the class is created according to its scope.\n * - For {@link ExistingProvider}, the instance is resolved by referring to another registered token.\n *\n * If the class is registered with _container_ scope, the resolved instance is cached\n * in the container's internal registry.\n */\n resolve<Instance extends object>(Class: Constructor<Instance>, optional?: false): Instance;\n resolve<Instance extends object>(Class: Constructor<Instance>, optional: true): Instance | undefined;\n resolve<Instance extends object>(Class: Constructor<Instance>, optional?: boolean): Instance | undefined;\n\n /**\n * Resolves the given token to the value associated with it.\n *\n * If the token is registered in this container or any of its parent containers,\n * its value is resolved using the most recent registration.\n *\n * If `optional` is false or not passed and the token is not registered in the container,\n * an error is thrown. Otherwise, if `optional` is true, `undefined` is returned.\n *\n * The resolution behavior depends on the {@link Provider} used during registration:\n * - For {@link ValueProvider}, the explicitly provided value is returned.\n * - For {@link FactoryProvider}, the factory function is invoked to create the value.\n * - For {@link ClassProvider}, a new instance of the class is created according to its scope.\n * - For {@link ExistingProvider}, the value is resolved by referring to another registered token.\n *\n * If the token is registered with _container_ scope, the resolved value is cached\n * in the container's internal registry.\n */\n resolve<Value>(token: Token<Value>, optional?: false): Value;\n resolve<Value>(token: Token<Value>, optional: true): Value | undefined;\n resolve<Value>(token: Token<Value>, optional?: boolean): Value | undefined;\n\n /**\n * Resolves the given class to all instances provided by the registrations associated with it.\n *\n * If the class is not registered, but it is decorated with {@link AutoRegister},\n * or {@link ContainerOptions.autoRegister} is true, the class is registered automatically.\n * Otherwise, resolution fails.\n * The scope for the automatic registration is determined by either\n * the {@link Scoped} decorator on the class, or {@link ContainerOptions.defaultScope}.\n *\n * If `optional` is false or is not passed and the class is not registered in the container\n * (and could not be auto-registered), an error is thrown.\n * Otherwise, if `optional` is true, an empty array is returned.\n *\n * The resolution behavior depends on the {@link Provider} used during registration:\n * - For {@link ValueProvider}, the explicitly provided instance is returned.\n * - For {@link FactoryProvider}, the factory function is invoked to create the instance.\n * - For {@link ClassProvider}, a new instance of the class is created according to its scope.\n * - For {@link ExistingProvider}, the instance is resolved by referring to another registered token.\n *\n * If the class is registered with _container_ scope, the resolved instances are cached\n * in the container's internal registry.\n *\n * A separate instance of the class is created for each provider.\n *\n * @see The documentation for `resolve(Class: Constructor)`\n */\n resolveAll<Instance extends object>(Class: Constructor<Instance>, optional?: false): Instance[];\n resolveAll<Instance extends object>(Class: Constructor<Instance>, optional: true): Instance[];\n resolveAll<Instance extends object>(Class: Constructor<Instance>, optional?: boolean): Instance[];\n\n /**\n * Resolves the given token to all values provided by the registrations associated with it.\n *\n * If `optional` is false or not passed and the token is not registered in the container,\n * an error is thrown. Otherwise, if `optional` is true, an empty array is returned.\n *\n * The resolution behavior depends on the {@link Provider} used during registration:\n * - For {@link ValueProvider}, the explicitly provided value is returned.\n * - For {@link FactoryProvider}, the factory function is invoked to create the value.\n * - For {@link ClassProvider}, a new instance of the class is created according to its scope.\n * - For {@link ExistingProvider}, the value is resolved by referring to another registered token.\n *\n * If the token is registered with _container_ scope, the resolved values are cached\n * in the container's internal registry.\n *\n * @see The documentation for `resolve(token: Token)`\n */\n resolveAll<Value>(token: Token<Value>, optional?: false): NonNullable<Value>[];\n resolveAll<Value>(token: Token<Value>, optional: true): NonNullable<Value>[];\n resolveAll<Value>(token: Token<Value>, optional?: boolean): NonNullable<Value>[];\n\n /**\n * Disposes this container and all its cached values.\n *\n * Token values implementing a `Disposable` interface (e.g., objects with a `dispose()` function)\n * are automatically disposed during this process.\n *\n * Note that children containers are disposed first, in creation order.\n */\n dispose(): void;\n}\n\n/**\n * Creates a new container.\n */\nexport function createContainer(\n options: Partial<ContainerOptions> = {\n autoRegister: false,\n defaultScope: Scope.Inherited,\n },\n): Container {\n return new DefaultContainer(undefined, options);\n}\n","import { getMetadata } from \"../metadata\";\nimport type { Constructor } from \"../token\";\n\n/**\n * Class decorator for enabling auto-registration of an unregistered class\n * when first resolving it 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(enable: boolean = true): ClassDecorator {\n return function (Class) {\n const metadata = getMetadata(Class as any as Constructor<any>);\n metadata.autoRegister = enable;\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 a token that is declared later in the file by wrapping it in a function.\n */\nexport function forwardRef<Value>(token: () => Tokens<Value>): TokensRef<Value>;\nexport function forwardRef<Value>(token: () => Token<Value>): TokenRef<Value>;\nexport function forwardRef<Value>(\n token: () => Token<Value> | Tokens<Value>,\n): TokensRef<Value> & TokenRef<Value> {\n return {\n getRefTokens: (): Set<Token<Value>> => {\n // Normalize the single token here, so that we don't have\n // to do it at every getRefTokens call site\n const tokenOrTokens = token();\n const tokensArray = Array.isArray(tokenOrTokens) ? tokenOrTokens : [tokenOrTokens];\n return new Set(tokensArray);\n },\n getRefToken: () => {\n const tokenOrTokens = token();\n assert(!Array.isArray(tokenOrTokens), \"internal error: ref tokens should be a single token\");\n return tokenOrTokens;\n },\n };\n}\n\n// @internal\nexport function isTokensRef(value: any): value is TokensRef {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return value && typeof value === \"object\" && typeof value.getRefTokens === \"function\";\n}\n\n// @internal\nexport function isTokenRef(value: any): value is TokenRef {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return value && typeof value === \"object\" && typeof value.getRefToken === \"function\";\n}\n","import { assert } from \"../errors\";\nimport { getMetadata } from \"../metadata\";\nimport type { Constructor, Token } from \"../token\";\nimport type { Decorator } from \"../tokenRegistry\";\nimport { forwardRef, isTokenRef, type TokenRef } from \"../tokensRef\";\n\nexport function processDecoratedParameter(\n decorator: Decorator,\n token: Token | TokenRef,\n target: object,\n propertyKey: string | symbol | undefined,\n parameterIndex: number,\n): void {\n // Error out immediately if the decorator has been applied\n // to a static property or a static method\n if (propertyKey !== undefined && typeof target === \"function\") {\n assert(false, `@${decorator} cannot be used on static member ${target.name}.${String(propertyKey)}`);\n }\n\n const tokenRef = isTokenRef(token) ? token : forwardRef(() => token);\n\n if (propertyKey === undefined) {\n // Constructor\n const metadata = getMetadata(target as Constructor<any>);\n metadata.dependencies.constructor.push({\n decorator: decorator,\n tokenRef: tokenRef,\n index: parameterIndex,\n });\n } else {\n // Normal instance method\n const metadata = getMetadata(target.constructor as Constructor<any>);\n const methods = metadata.dependencies.methods;\n let dep = methods.get(propertyKey);\n\n if (dep === undefined) {\n dep = [];\n methods.set(propertyKey, dep);\n }\n\n dep.push({\n decorator: decorator,\n tokenRef: tokenRef,\n index: parameterIndex,\n });\n }\n}\n","import type { Constructor, Token } from \"../token\";\nimport type { TokenRef } from \"../tokensRef\";\nimport { processDecoratedParameter } from \"./decorators\";\n\n/**\n * Parameter decorator that injects the instance associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\nexport function Inject<Instance extends object>(Class: Constructor<Instance>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects the value associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\nexport function Inject<Value>(token: Token<Value>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects the value associated with the given token.\n *\n * Allows referencing a token that is declared later in the file by using\n * the {@link forwardRef} helper function.\n *\n * Throws an error if the token is not registered in the container.\n *\n * @example\n * ```ts\n * class Wizard {\n * constructor(@Inject(forwardRef(() => Wand)) readonly wand: Wand) {}\n * }\n * // Other code...\n * class Wand {}\n * ```\n */\nexport function Inject<Value>(tokens: TokenRef<Value>): ParameterDecorator;\n\nexport function Inject<T>(token: Token<T> | TokenRef<T>): ParameterDecorator {\n return function (target, propertyKey, parameterIndex: number): void {\n processDecoratedParameter(\"Inject\", token, target, propertyKey, parameterIndex);\n };\n}\n","import { getMetadata } from \"../metadata\";\nimport type { Constructor, Tokens } from \"../token\";\nimport { forwardRef, isTokensRef, type TokenRef, type TokensRef } from \"../tokensRef\";\n\n/**\n * Class decorator for registering additional aliasing tokens for the decorated type\n * when registering it.\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 for registering additional aliasing tokens for the decorated type\n * when registering it.\n *\n * The container uses {@link ExistingProvider} under the hood.\n *\n * Allows referencing tokens that are declared later in the file by using\n * the {@link forwardRef} helper function.\n *\n * @example\n * ```ts\n * @Injectable(forwardRef() => Weapon) // Weapon is declared after Wand\n * class Wizard {}\n * // Other code...\n * class Weapon {}\n * ```\n */\nexport function Injectable<This extends object, Value extends This>(\n tokens: TokenRef<Value> | TokensRef<Value>,\n): ClassDecorator;\n\n/**\n * @__NO_SIDE_EFFECTS__\n */\nexport function Injectable(...args: unknown[]): ClassDecorator {\n return function (Class): void {\n const metadata = getMetadata(Class as any as Constructor<any>);\n const arg0 = args[0];\n const tokensRef = isTokensRef(arg0) ? arg0 : forwardRef(() => args as Tokens);\n const existingTokensRef = metadata.tokensRef;\n metadata.tokensRef = {\n getRefTokens: () => {\n const existingTokens = existingTokensRef.getRefTokens();\n\n for (const token of tokensRef.getRefTokens()) {\n existingTokens.add(token);\n }\n\n return existingTokens;\n },\n };\n };\n}\n","import type { Constructor, Token } from \"../token\";\nimport type { TokenRef } from \"../tokensRef\";\nimport { processDecoratedParameter } from \"./decorators\";\n\n/**\n * Parameter decorator that injects all instances provided by the registrations\n * associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\nexport function InjectAll<Instance extends object>(Class: Constructor<Instance>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects all values provided by the registrations\n * associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\nexport function InjectAll<Value>(token: Token<Value>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects all values provided by the registrations\n * associated with the given token.\n *\n * Allows referencing a token that is declared later in the file by using\n * the {@link forwardRef} helper function.\n *\n * Throws an error if the token is not registered in the container.\n *\n * @example\n * ```ts\n * class Wizard {\n * constructor(@InjectAll(forwardRef(() => Wand)) readonly wands: Wand[]) {}\n * }\n * // Other code...\n * class Wand {}\n * ```\n */\nexport function InjectAll<Value>(tokens: TokenRef<Value>): ParameterDecorator;\n\nexport function InjectAll<T>(token: Token<T> | TokenRef<T>): ParameterDecorator {\n return function (target, propertyKey, parameterIndex: number): void {\n processDecoratedParameter(\"InjectAll\", token, target, propertyKey, parameterIndex);\n };\n}\n","import type { Constructor, Token } from \"../token\";\nimport type { TokenRef } from \"../tokensRef\";\nimport { processDecoratedParameter } from \"./decorators\";\n\n/**\n * Parameter decorator that injects the instance associated with the given class,\n * or `undefined` if the class is not registered in the container.\n */\nexport function Optional<Instance extends object>(Class: Constructor<Instance>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects the value associated with the given token,\n * or `undefined` if the token is not registered in the container.\n */\nexport function Optional<Value>(token: Token<Value>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects the value associated with the given token,\n * or `undefined` if the token is not registered in the container.\n *\n * Allows referencing a token that is declared later in the file by using\n * the {@link forwardRef} helper function.\n *\n * @example\n * ```ts\n * class Wizard {\n * constructor(@Optional(forwardRef(() => Wand)) readonly wand: Wand | undefined) {}\n * }\n * // Other code...\n * class Wand {}\n * ```\n */\nexport function Optional<Value>(tokens: TokenRef<Value>): ParameterDecorator;\n\nexport function Optional<T>(token: Token<T> | TokenRef<T>): ParameterDecorator {\n return function (target, propertyKey, parameterIndex: number): void {\n processDecoratedParameter(\"Optional\", token, target, propertyKey, parameterIndex);\n };\n}\n","import type { Constructor, Token } from \"../token\";\nimport type { TokenRef } from \"../tokensRef\";\nimport { processDecoratedParameter } from \"./decorators\";\n\n/**\n * Parameter decorator that injects all instances provided by the registrations\n * associated with the given class, or an empty array if the class is not registered\n * in the container.\n */\nexport function OptionalAll<Instance extends object>(Class: Constructor<Instance>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects all values provided by the registrations\n * associated with the given token, or an empty array if the token is not registered\n * in the container.\n */\nexport function OptionalAll<Value>(token: Token<Value>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects all values provided by the registrations\n * associated with the given token, or an empty array if the token is not registered\n * in the container.\n *\n * Allows referencing a token that is declared later in the file by using\n * the {@link forwardRef} helper function.\n *\n * @example\n * ```ts\n * class Wizard {\n * constructor(@OptionalAll(forwardRef(() => Wand)) readonly wands: Wand[]) {}\n * }\n * // Other code...\n * class Wand {}\n * ```\n */\nexport function OptionalAll<Value>(tokens: TokenRef<Value>): ParameterDecorator;\n\nexport function OptionalAll<T>(token: Token<T> | TokenRef<T>): ParameterDecorator {\n return function (target, propertyKey, parameterIndex: number): void {\n processDecoratedParameter(\"OptionalAll\", token, target, propertyKey, parameterIndex);\n };\n}\n","import { getMetadata } from \"../metadata\";\nimport type { Scope } from \"../scope\";\nimport type { Constructor } from \"../token\";\n\n/**\n * Class decorator for setting the scope of the decorated type when registering it.\n *\n * The scope set by this decorator can be overridden by explicit registration options, if provided.\n *\n * @example\n * ```ts\n * @Scoped(Scope.Container)\n * class Wizard {}\n *\n * container.register(Wizard);\n *\n * // Under the hood\n * container.register(\n * Wizard,\n * { useClass: Wizard },\n * { scope: Scope.Container },\n * );\n * ```\n *\n * @__NO_SIDE_EFFECTS__\n */\nexport function Scoped(scope: Scope): ClassDecorator {\n return function (Class): void {\n const metadata = getMetadata(Class as any as Constructor<any>);\n metadata.scope = scope;\n };\n}\n","import { inject } from \"./inject\";\nimport { injectAll } from \"./injectAll\";\nimport { ensureInjectionContext, provideInjectionContext, useInjectionContext } from \"./injectionContext\";\nimport { optional } from \"./optional\";\nimport { optionalAll } from \"./optionalAll\";\nimport type { Constructor, Token, Type } from \"./token\";\nimport { Build } from \"./tokenRegistry\";\n\n/**\n * Injector API.\n */\nexport interface Injector {\n /**\n * Injects the instance associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\n inject<Instance extends object>(Class: Constructor<Instance>): Instance;\n\n /**\n * Injects the value associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\n inject<Value>(token: Token<Value>): Value;\n\n /**\n * Injects all instances provided by the registrations associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\n injectAll<Instance extends object>(Class: Constructor<Instance>): Instance[];\n\n /**\n * Injects all values provided by the registrations associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\n injectAll<Value>(token: Token<Value>): NonNullable<Value>[];\n\n /**\n * Injects the instance associated with the given class,\n * or `undefined` if the class is not registered in the container.\n */\n optional<Instance extends object>(Class: Constructor<Instance>): Instance | undefined;\n\n /**\n * Injects the value associated with the given token,\n * or `undefined` if the token is not registered in the container.\n */\n optional<Value>(token: Token<Value>): Value | undefined;\n\n /**\n * Injects all instances provided by the registrations associated with the given class,\n * or an empty array if the class is not registered in the container.\n */\n optionalAll<Instance extends object>(Class: Constructor<Instance>): Instance[];\n\n /**\n * Injects all values provided by the registrations associated with the given token,\n * or an empty array if the token is not registered in the container.\n */\n optionalAll<Value>(token: Token<Value>): NonNullable<Value>[];\n}\n\n/**\n * Injector token for dynamic injections.\n *\n * @example\n * ```ts\n * class Wizard {\n * private injector = inject(Injector);\n * private wand?: Wand;\n *\n * getWand(): Wand {\n * return (this.wand ??= this.injector.inject(Wand));\n * }\n * }\n *\n * const wizard = container.resolve(Wizard);\n * wizard.getWand(); // => Wand\n * ```\n */\nexport const Injector: Type<Injector> = /*@__PURE__*/ Build(function Injector() {\n const context = ensureInjectionContext(Injector);\n const resolution = context.resolution;\n\n const dependentFrame = resolution.stack.peek();\n const dependentRef = dependentFrame && resolution.dependents.get(dependentFrame.provider);\n\n function withCurrentContext<R>(fn: () => R): R {\n if (useInjectionContext()) {\n return fn();\n }\n\n const cleanups = [\n provideInjectionContext(context),\n dependentFrame && resolution.stack.push(dependentFrame.provider, dependentFrame),\n dependentRef && resolution.dependents.set(dependentFrame.provider, dependentRef),\n ];\n\n try {\n return fn();\n } finally {\n for (const cleanup of cleanups) {\n cleanup?.();\n }\n }\n }\n\n return {\n inject: <T>(token: Token<T>) => withCurrentContext(() => inject(token)),\n injectAll: <T>(token: Token<T>) => withCurrentContext(() => injectAll(token)),\n optional: <T>(token: Token<T>) => withCurrentContext(() => optional(token)),\n optionalAll: <T>(token: Token<T>) => withCurrentContext(() => optionalAll(token)),\n };\n});\n","import type { Container } from \"./container\";\n\n/**\n * Composer API for middleware functions.\n */\nexport interface MiddlewareComposer {\n /**\n * Add a middleware function to the composer.\n */\n use<MethodKey extends keyof Container>(\n key: MethodKey,\n wrap: Container[MethodKey] extends Function\n ? (next: Container[MethodKey]) => Container[MethodKey]\n : never,\n ): MiddlewareComposer;\n}\n\n/**\n * Middleware function that can be used to extend the container.\n *\n * @example\n * ```ts\n * const logger: Middleware = (composer, _api) => {\n * composer\n * .use(\"resolve\", (next) => (...args) => {\n * console.log(\"resolve\", args);\n * return next(...args);\n * })\n * .use(\"resolveAll\", (next) => (...args) => {\n * console.log(\"resolveAll\", args);\n * return next(...args);\n * });\n * };\n * ```\n */\nexport interface Middleware {\n (composer: MiddlewareComposer, api: Readonly<Container>): void;\n}\n\n/**\n * Apply middleware functions to a container.\n *\n * Middlewares are applied in array order, but execute in reverse order.\n *\n * @example\n * ```ts\n * const container = applyMiddleware(\n * createContainer(),\n * [A, B],\n * );\n * ```\n *\n * The execution order will be:\n *\n * 1. B before\n * 2. A before\n * 3. original function\n * 4. A after\n * 5. B after\n *\n * This allows outer middlewares to wrap and control the behavior of inner middlewares.\n */\nexport function applyMiddleware(container: Container, middlewares: Middleware[]): Container {\n const composer: MiddlewareComposer = {\n use(key, wrap): MiddlewareComposer {\n // We need to bind the 'this' context of the function to the container\n // before passing it to the middleware wrapper.\n //\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call\n const fn = (container[key] as any).bind(container);\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n container[key] = wrap(fn);\n return composer;\n },\n };\n\n const api = (container.api ||= { ...container });\n\n for (const middleware of middlewares) {\n middleware(composer, api);\n }\n\n return container;\n}\n"],"names":["assert","condition","message","resolvedMessage","Error","tag","expectNever","value","TypeError","String","throwUnregisteredError","token","name","throwExistingUnregisteredError","sourceToken","targetTokenOrError","isError","untag","stack","startsWith","substring","trimStart","createInjectionContext","current","provide","next","prev","use","invariant","KeyedStack","has","key","myKeys","peek","entry","myEntries","at","push","add","pop","delete","Array","WeakSet","WeakRefMap","get","ref","myMap","deref","set","WeakRef","WeakMap","createResolution","values","dependents","provideInjectionContext","useInjectionContext","ensureInjectionContext","fn","context","inject","container","resolve","injectBy","thisArg","resolution","currentFrame","currentRef","cleanup","provider","injectAll","resolveAll","getMetadata","Class","metadata","metadataMap","tokensRef","getRefTokens","Set","useClass","dependencies","methods","Map","optional","optionalBy","optionalAll","isClassProvider","isExistingProvider","isFactoryProvider","isValueProvider","Scope","Inherited","Transient","Resolution","Container","Type","typeName","type","inter","union","toString","isConstructor","getTypeName","proto","Object","getPrototypeOf","prototype","constructor","TokenRegistry","parent","getAll","internal","internals","getAllFromParent","registration","registrations","deleteAll","tokens","from","keys","flat","clear","clearRegistrations","i","length","undefined","isBuilder","builders","Build","factory","useFactory","options","scope","isDisposable","dispose","DefaultContainer","myParent","myChildren","myDisposed","myOptions","autoRegister","defaultScope","myTokenRegistry","registry","isDisposed","createChild","checkDisposed","clearCache","getCached","getAllCached","resetRegistry","isRegistered","register","args","useExisting","unregister","resolveRegistration","instantiateClass","map","filter","instance","child","disposedRefs","currRegistration","currProvider","targetToken","resolveProviderValue","e","resolveScope","resolveScopedValue","useValue","dependentRef","cleanups","valueRef","resolveConstructorDependencies","injectDependencies","forEach","dependentFrame","ctorDeps","ctor","msg","sort","a","b","index","dep","tokenRef","getRefToken","decorator","methodDeps","method","bind","createContainer","AutoRegister","enable","forwardRef","tokenOrTokens","tokensArray","isArray","isTokensRef","isTokenRef","processDecoratedParameter","target","propertyKey","parameterIndex","Inject","Injectable","arg0","existingTokensRef","existingTokens","InjectAll","Optional","OptionalAll","Scoped","Injector","withCurrentContext","applyMiddleware","middlewares","composer","wrap","api","middleware"],"mappings":"AAEA;AACO,SAASA,MAAAA,CAAOC,SAAkB,EAAEC,OAAgC,EAAA;AACzE,IAAA,IAAI,CAACD,SAAAA,EAAW;AACd,QAAA,MAAME,eAAAA,GAAkB,OAAOD,OAAAA,KAAY,QAAA,GAAWA,OAAAA,GAAUA,OAAAA,EAAAA;QAChE,MAAM,IAAIE,MAAMC,GAAAA,CAAIF,eAAAA,CAAAA,CAAAA;AACtB;AACF;AAEA;AACO,SAASG,YAAYC,KAAY,EAAA;AACtC,IAAA,MAAM,IAAIC,SAAAA,CAAUH,GAAAA,CAAI,CAAC,iBAAiB,EAAEI,OAAOF,KAAAA,CAAAA,CAAAA,CAAQ,CAAA,CAAA;AAC7D;AAEA;AACO,SAASG,uBAAuBC,KAAY,EAAA;IACjD,MAAM,IAAIP,MAAMC,GAAAA,CAAI,CAAC,mBAAmB,EAAEM,KAAAA,CAAMC,IAAI,CAAA,CAAE,CAAA,CAAA;AACxD;AAEA;AACO,SAASC,8BAAAA,CAA+BC,WAAkB,EAAEC,kBAAiC,EAAA;AAClG,IAAA,IAAIb,UAAUG,GAAAA,CAAI,CAAC,mDAAmD,EAAES,WAAAA,CAAYF,IAAI,CAAA,CAAE,CAAA;AAE1F,IAAA,IAAII,QAAQD,kBAAAA,CAAAA,EAAqB;AAC/Bb,QAAAA,OAAAA,IAAW,CAAC,YAAY,EAAEe,KAAAA,CAAMF,kBAAAA,CAAmBb,OAAO,CAAA,CAAA,CAAG;KAC/D,MAAO;AACLA,QAAAA,OAAAA,IAAW,CAAC,8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,GAAG/J;AAAU,KAAA;IAE9C,KAAK,MAAMgK,cAAcJ,WAAAA,CAAa;AACpCI,QAAAA,UAAAA,CAAWH,QAAAA,EAAUE,GAAAA,CAAAA;AACvB;IAEA,OAAO/J,SAAAA;AACT;;;;"}
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/errors.ts","../../src/utils/context.ts","../../src/utils/invariant.ts","../../src/utils/keyedStack.ts","../../src/utils/weakRefMap.ts","../../src/injectionContext.ts","../../src/inject.ts","../../src/injectAll.ts","../../src/metadata.ts","../../src/optional.ts","../../src/optionalAll.ts","../../src/provider.ts","../../src/scope.ts","../../src/token.ts","../../src/utils/typeName.ts","../../src/tokenRegistry.ts","../../src/utils/disposable.ts","../../src/defaultContainer.ts","../../src/container.ts","../../src/decorators/autoRegister.ts","../../src/tokensRef.ts","../../src/decorators/decorators.ts","../../src/decorators/inject.ts","../../src/decorators/injectable.ts","../../src/decorators/injectAll.ts","../../src/decorators/optional.ts","../../src/decorators/optionalAll.ts","../../src/decorators/scoped.ts","../../src/injector.ts","../../src/middleware.ts"],"sourcesContent":["import type { Token } from \"./token\";\n\n// @internal\nexport function assert(condition: unknown, message: string | (() => string)): asserts condition {\n if (!condition) {\n const resolvedMessage = typeof message === \"string\" ? message : message();\n throw new Error(tag(resolvedMessage));\n }\n}\n\n// @internal\nexport function expectNever(value: never): never {\n throw new TypeError(tag(`unexpected value ${String(value)}`));\n}\n\n// @internal\nexport function throwUnregisteredError(token: Token): never {\n throw new Error(tag(`unregistered token ${token.name}`));\n}\n\n// @internal\nexport function throwExistingUnregisteredError(sourceToken: Token, targetTokenOrError: Token | Error): never {\n let message = tag(`token resolution error encountered while resolving ${sourceToken.name}`);\n\n if (isError(targetTokenOrError)) {\n message += `\\n [cause] ${untag(targetTokenOrError.message)}`;\n } else {\n message += `\\n [cause] the aliased token ${targetTokenOrError.name} is not registered`;\n }\n\n throw new Error(message);\n}\n\nfunction isError(value: any): value is Error {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return value && value.stack && value.message && typeof value.message === \"string\";\n}\n\nfunction tag(message: string): string {\n return `[di-wise-neo] ${message}`;\n}\n\nfunction untag(message: string): string {\n return message.startsWith(\"[di-wise-neo]\") //\n ? message.substring(13).trimStart()\n : message;\n}\n","// @internal\nexport function createInjectionContext<T extends {}>(): readonly [\n (next: T) => () => T | null,\n () => T | null,\n] {\n let current: T | null = null;\n\n function provide(next: T): () => T | null {\n const prev = current;\n current = next;\n return () => (current = prev);\n }\n\n function use(): T | null {\n return current;\n }\n\n return [provide, use] as const;\n}\n","// @internal\nexport function invariant(condition: unknown): asserts condition {\n if (!condition) {\n throw new Error(\"invariant violation\");\n }\n}\n","import { invariant } from \"./invariant\";\n\n// @internal\nexport class KeyedStack<K extends object, V> {\n private readonly myEntries = new Array<{ key: K; value: V }>();\n private readonly myKeys = new WeakSet<K>();\n\n has(key: K): boolean {\n return this.myKeys.has(key);\n }\n\n peek(): V | undefined {\n const entry = this.myEntries.at(-1);\n return entry?.value;\n }\n\n push(key: K, value: V): () => void {\n invariant(!this.has(key));\n this.myKeys.add(key);\n this.myEntries.push({ key, value });\n return () => {\n this.myEntries.pop();\n this.myKeys.delete(key);\n };\n }\n}\n","import { invariant } from \"./invariant\";\n\n// @internal\nexport class WeakRefMap<K extends WeakKey, V extends object> {\n private readonly myMap = new WeakMap<K, WeakRef<V>>();\n\n get(key: K): V | undefined {\n const ref = this.myMap.get(key);\n\n if (ref) {\n const value = ref.deref();\n\n if (value) {\n return value;\n }\n\n this.myMap.delete(key);\n }\n }\n\n set(key: K, value: V): () => void {\n invariant(!this.get(key));\n this.myMap.set(key, new WeakRef(value));\n return () => {\n this.myMap.delete(key);\n };\n }\n}\n","import type { Container } from \"./container\";\nimport { assert } from \"./errors\";\nimport type { Provider } from \"./provider\";\nimport type { Scope } from \"./scope\";\nimport { createInjectionContext } from \"./utils/context\";\nimport { KeyedStack } from \"./utils/keyedStack\";\nimport { WeakRefMap } from \"./utils/weakRefMap\";\nimport type { ValueRef } from \"./valueRef\";\n\n// @internal\nexport interface ResolutionFrame {\n readonly scope: Exclude<Scope, typeof Scope.Inherited>;\n readonly provider: Provider;\n}\n\n// @internal\nexport interface Resolution {\n readonly stack: KeyedStack<Provider, ResolutionFrame>;\n readonly values: WeakRefMap<Provider, ValueRef>;\n readonly dependents: WeakRefMap<Provider, ValueRef>;\n}\n\n// @internal\nexport interface InjectionContext {\n readonly container: Container;\n readonly resolution: Resolution;\n}\n\n// @internal\nexport function createResolution(): Resolution {\n return {\n stack: new KeyedStack(),\n values: new WeakRefMap(),\n dependents: new WeakRefMap(),\n };\n}\n\n// @internal\nexport const [provideInjectionContext, useInjectionContext] = createInjectionContext<InjectionContext>();\n\n// @internal\nexport function ensureInjectionContext(fn: Function): InjectionContext {\n const context = useInjectionContext();\n assert(context, `${fn.name}() can only be invoked within an injection context`);\n return context;\n}\n","import { ensureInjectionContext } from \"./injectionContext\";\nimport type { Constructor, Token } from \"./token\";\n\n/**\n * Injects the instance associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\nexport function inject<Instance extends object>(Class: Constructor<Instance>): Instance;\n\n/**\n * Injects the value associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\nexport function inject<Value>(token: Token<Value>): Value;\n\nexport function inject<T>(token: Token<T>): T {\n const context = ensureInjectionContext(inject);\n return context.container.resolve(token);\n}\n\n/**\n * Injects the instance associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n *\n * Compared to {@link inject}, `injectBy` accepts a `thisArg` argument\n * (the containing class) which is used to resolve circular dependencies.\n *\n * @example\n * ```ts\n * class Wand {\n * owner = inject(Wizard);\n * }\n *\n * class Wizard {\n * wand = injectBy(this, Wand);\n * }\n * ```\n *\n * @param thisArg - The containing instance, used to help resolve circular dependencies.\n * @param Class - The class to resolve.\n */\nexport function injectBy<Instance extends object>(thisArg: any, Class: Constructor<Instance>): Instance;\n\n/**\n * Injects the value associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n *\n * Compared to {@link inject}, `injectBy` accepts a `thisArg` argument\n * (the containing class) which is used to resolve circular dependencies.\n *\n * @example\n * ```ts\n * class Wand {\n * owner = inject(Wizard);\n * }\n *\n * class Wizard {\n * wand = injectBy(this, Wand);\n * }\n * ```\n *\n * @param thisArg - The containing instance, used to help resolve circular dependencies.\n * @param token - The token to resolve.\n */\nexport function injectBy<Value>(thisArg: any, token: Token<Value>): Value;\n\nexport function injectBy<T>(thisArg: any, token: Token<T>): T {\n const context = ensureInjectionContext(injectBy);\n const resolution = context.resolution;\n const currentFrame = resolution.stack.peek();\n\n if (!currentFrame) {\n return inject(token);\n }\n\n const currentRef = { current: thisArg };\n const cleanup = resolution.dependents.set(currentFrame.provider, currentRef);\n\n try {\n return inject(token);\n } finally {\n cleanup();\n }\n}\n","import { ensureInjectionContext } from \"./injectionContext\";\nimport type { Constructor, Token } from \"./token\";\n\n/**\n * Injects all instances provided by the registrations associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\nexport function injectAll<Instance extends object>(Class: Constructor<Instance>): Instance[];\n\n/**\n * Injects all values provided by the registrations associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\nexport function injectAll<Value>(token: Token<Value>): NonNullable<Value>[];\n\nexport function injectAll<T>(token: Token<T>): NonNullable<T>[] {\n const context = ensureInjectionContext(injectAll);\n return context.container.resolveAll(token);\n}\n","import type { ClassProvider } from \"./provider\";\nimport type { Scope } from \"./scope\";\nimport type { Constructor } from \"./token\";\nimport type { Dependencies } from \"./tokenRegistry\";\nimport type { TokensRef } from \"./tokensRef\";\n\n// @internal\nexport interface Metadata<This extends object = any> {\n autoRegister?: boolean;\n scope?: Scope;\n tokensRef: TokensRef<This>;\n provider: ClassProvider<This>;\n dependencies: Dependencies;\n}\n\n// @internal\nexport function getMetadata<T extends object>(Class: Constructor<T>): Metadata<T> {\n let metadata = metadataMap.get(Class);\n\n if (!metadata) {\n metadataMap.set(\n Class,\n (metadata = {\n tokensRef: {\n getRefTokens: () => new Set(),\n },\n provider: {\n useClass: Class,\n },\n dependencies: {\n constructor: [],\n methods: new Map(),\n },\n }),\n );\n }\n\n return metadata;\n}\n\nconst metadataMap = new WeakMap<Constructor<object>, Metadata>();\n","import { ensureInjectionContext } from \"./injectionContext\";\nimport type { Constructor, Token } from \"./token\";\n\n/**\n * Injects the instance associated with the given class,\n * or `undefined` if the class is not registered in the container.\n */\nexport function optional<Instance extends object>(Class: Constructor<Instance>): Instance | undefined;\n\n/**\n * Injects the value associated with the given token,\n * or `undefined` if the token is not registered in the container.\n */\nexport function optional<Value>(token: Token<Value>): Value | undefined;\n\nexport function optional<T>(token: Token<T>): T | undefined {\n const context = ensureInjectionContext(optional);\n return context.container.resolve(token, true);\n}\n\n/**\n * Injects the instance associated with the given class,\n * or `undefined` if the class is not registered in the container.\n *\n * Compared to {@link optional}, `optionalBy` accepts a `thisArg` argument\n * (the containing class) which is used to resolve circular dependencies.\n *\n * @param thisArg - The containing instance, used to help resolve circular dependencies.\n * @param Class - The class to resolve.\n */\nexport function optionalBy<Instance extends object>(\n thisArg: any,\n Class: Constructor<Instance>,\n): Instance | undefined;\n\n/**\n * Injects the value associated with the given token,\n * or `undefined` if the token is not registered in the container.\n *\n * Compared to {@link optional}, `optionalBy` accepts a `thisArg` argument\n * (the containing class) which is used to resolve circular dependencies.\n *\n * @param thisArg - The containing instance, used to help resolve circular dependencies.\n * @param token - The token to resolve.\n */\nexport function optionalBy<Value>(thisArg: any, token: Token<Value>): Value | undefined;\n\nexport function optionalBy<T>(thisArg: any, token: Token<T>): T | undefined {\n const context = ensureInjectionContext(optionalBy);\n const resolution = context.resolution;\n const currentFrame = resolution.stack.peek();\n\n if (!currentFrame) {\n return optional(token);\n }\n\n const currentRef = { current: thisArg };\n const cleanup = resolution.dependents.set(currentFrame.provider, currentRef);\n\n try {\n return optional(token);\n } finally {\n cleanup();\n }\n}\n","import { ensureInjectionContext } from \"./injectionContext\";\nimport type { Constructor, Token } from \"./token\";\n\n/**\n * Injects all instances provided by the registrations associated with the given class,\n * or an empty array if the class is not registered in the container.\n */\nexport function optionalAll<Instance extends object>(Class: Constructor<Instance>): Instance[];\n\n/**\n * Injects all values provided by the registrations associated with the given token,\n * or an empty array if the token is not registered in the container.\n */\nexport function optionalAll<Value>(token: Token<Value>): NonNullable<Value>[];\n\nexport function optionalAll<T>(token: Token<T>): NonNullable<T>[] {\n const context = ensureInjectionContext(optionalAll);\n return context.container.resolveAll(token, true);\n}\n","import type { Constructor, Token } from \"./token\";\n\n/**\n * Provides a class instance for a token via a class constructor.\n */\nexport interface ClassProvider<Instance extends object> {\n readonly useClass: Constructor<Instance>;\n}\n\n/**\n * Provides a value for a token via another existing token.\n */\nexport interface ExistingProvider<Value> {\n readonly useExisting: Token<Value>;\n}\n\n/**\n * Provides a value for a token via a factory function.\n *\n * The factory function runs inside the injection context\n * and can thus access dependencies via {@link inject}.\n */\nexport interface FactoryProvider<Value> {\n readonly useFactory: (...args: []) => Value;\n}\n\n/**\n * Provides a direct - already constructed - value for a token.\n */\nexport interface ValueProvider<T> {\n readonly useValue: T;\n}\n\n/**\n * A token provider.\n */\nexport type Provider<Value = any> =\n | ClassProvider<Value & object>\n | ExistingProvider<Value>\n | FactoryProvider<Value>\n | ValueProvider<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 isExistingProvider<T>(provider: Provider<T>): provider is ExistingProvider<T> {\n return \"useExisting\" 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","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 * Name of the type.\n */\n readonly name: string;\n\n /**\n * Create 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 * Create 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 readonly length: number;\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 * Create a type token.\n *\n * @example\n * ```ts\n * const Spell = createType<Spell>(\"Spell\");\n * ```\n *\n * @__NO_SIDE_EFFECTS__\n */\nexport function createType<T>(typeName: string): Type<T> {\n const type = {\n name: `Type<${typeName}>`,\n inter: createType,\n union: createType,\n toString(): string {\n return type.name;\n },\n };\n\n return type;\n}\n\n// @internal\nexport function isConstructor<T>(token: Type<T> | Constructor<T & object>): token is Constructor<T & object> {\n return typeof token == \"function\";\n}\n","// @internal\nexport function getTypeName(value: unknown): string {\n if (typeof value == \"string\") {\n return `\"${value}\"`;\n }\n\n if (typeof value == \"function\") {\n return (value.name && `typeof ${value.name}`) || \"Function\";\n }\n\n if (typeof value == \"object\") {\n if (value === null) {\n return \"null\";\n }\n\n const proto: object | null = Object.getPrototypeOf(value);\n\n if (proto && proto !== Object.prototype) {\n const constructor: unknown = proto.constructor;\n\n if (typeof constructor == \"function\" && constructor.name) {\n return constructor.name;\n }\n }\n }\n\n return typeof value;\n}\n","import { assert } from \"./errors\";\nimport type { FactoryProvider, Provider } from \"./provider\";\nimport { Scope } from \"./scope\";\nimport { type Constructor, createType, type Token, type Type } from \"./token\";\nimport type { TokenRef } from \"./tokensRef\";\nimport { getTypeName } from \"./utils/typeName\";\nimport type { ValueRef } from \"./valueRef\";\n\n/**\n * Token registration options.\n */\nexport interface RegistrationOptions {\n /**\n * The scope of the registration.\n */\n readonly scope?: Scope;\n}\n\n// @internal\nexport type Decorator = \"Inject\" | \"InjectAll\" | \"Optional\" | \"OptionalAll\";\n\n// @internal\nexport interface MethodDependency {\n readonly decorator: Decorator;\n readonly tokenRef: TokenRef;\n\n // The index of the annotated parameter (zero-based)\n readonly index: number;\n}\n\n// @internal\nexport interface Dependencies {\n readonly constructor: MethodDependency[];\n readonly methods: Map<string | symbol, MethodDependency[]>;\n}\n\n// @internal\nexport interface Registration<T = any> {\n value?: ValueRef<T>;\n readonly provider: Provider<T>;\n readonly options?: RegistrationOptions;\n readonly dependencies?: Dependencies;\n}\n\n// @internal\nexport class TokenRegistry {\n private readonly myMap = new Map<Token, Registration[]>();\n\n constructor(private readonly parent: TokenRegistry | undefined) {}\n\n get<T>(token: Token<T>): Registration<T> | undefined {\n // To clarify, at(-1) means we take the last added registration for this token\n return this.getAll(token)?.at(-1);\n }\n\n getAll<T>(token: Token<T>): Registration<T>[] | undefined {\n const internal = internals.get(token);\n return (internal && [internal]) || this.getAllFromParent(token);\n }\n\n //\n // set(...) overloads added because of TS distributive conditional types.\n //\n // TODO(Edoardo): is there a better way? Maybe refactor the Token<T> type\n // into two types, TokenObject<T extends object> | Token<T>\n //\n\n set<T extends object>(token: Type<T> | Constructor<T>, registration: Registration<T>): void;\n set<T>(token: Token<T>, registration: Registration<T>): void;\n set<T>(token: Token<T>, registration: Registration<T>): void {\n assert(!internals.has(token), `cannot register reserved token ${token.name}`);\n\n let registrations = this.myMap.get(token);\n\n if (!registrations) {\n this.myMap.set(token, (registrations = []));\n }\n\n registrations.push(registration);\n }\n\n delete<T>(token: Token<T>): Registration<T>[] | undefined {\n const registrations = this.myMap.get(token);\n this.myMap.delete(token);\n return registrations;\n }\n\n deleteAll(): [Token[], Registration[]] {\n const tokens = Array.from(this.myMap.keys());\n const registrations = Array.from(this.myMap.values()).flat();\n this.myMap.clear();\n return [tokens, registrations];\n }\n\n clearRegistrations(): unknown[] {\n const values = new Set<unknown>();\n\n for (const registrations of this.myMap.values()) {\n for (let i = 0; i < registrations.length; i++) {\n const registration = registrations[i]!;\n const value = registration.value;\n\n if (value) {\n values.add(value.current);\n }\n\n registrations[i] = {\n ...registration,\n value: undefined,\n };\n }\n }\n\n return Array.from(values);\n }\n\n private getAllFromParent<T>(token: Token<T>): Registration<T>[] | undefined {\n const registrations = this.myMap.get(token);\n return registrations || this.parent?.getAllFromParent(token);\n }\n}\n\n// @internal\nexport function isBuilder(provider: Provider): boolean {\n return builders.has(provider);\n}\n\n/**\n * Create a one-off type token from a factory function.\n *\n * @example\n * ```ts\n * class Wizard {\n * wand = inject(\n * build(() => {\n * const wand = inject(Wand);\n * wand.owner = this;\n * // ...\n * return wand;\n * }),\n * );\n * }\n * ```\n *\n * @__NO_SIDE_EFFECTS__\n */\nexport function build<Value>(factory: (...args: []) => Value): Type<Value> {\n const token = createType<Value>(`Build<${getTypeName(factory)}>`);\n const provider: FactoryProvider<Value> = {\n useFactory: factory,\n };\n\n internals.set(token, {\n provider: provider,\n options: {\n scope: Scope.Transient,\n },\n });\n\n builders.add(provider);\n return token;\n}\n\nconst internals = new WeakMap<Token, Registration>();\nconst builders = new WeakSet<Provider>();\n","// @internal\nexport interface Disposable {\n dispose(): void;\n}\n\n// @internal\nexport function isDisposable(value: any): value is Disposable {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return value && typeof value === \"object\" && typeof value.dispose === \"function\";\n}\n","import type { Container, ContainerOptions } from \"./container\";\nimport { assert, expectNever, throwExistingUnregisteredError, throwUnregisteredError } from \"./errors\";\nimport { injectBy } from \"./inject\";\nimport { injectAll } from \"./injectAll\";\nimport { createResolution, provideInjectionContext, useInjectionContext } from \"./injectionContext\";\nimport { getMetadata } from \"./metadata\";\nimport { optionalBy } from \"./optional\";\nimport { optionalAll } from \"./optionalAll\";\nimport {\n isClassProvider,\n isExistingProvider,\n isFactoryProvider,\n isValueProvider,\n type Provider,\n} from \"./provider\";\nimport { Scope } from \"./scope\";\nimport { type Constructor, isConstructor, type Token } 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 DefaultContainer implements Container {\n // eslint-disable-next-line no-use-before-define\n private readonly myChildren: Set<DefaultContainer> = new Set();\n private readonly myOptions: ContainerOptions;\n private readonly myTokenRegistry: TokenRegistry;\n private myDisposed: boolean = false;\n\n constructor(\n private readonly myParent: DefaultContainer | undefined,\n options: Partial<ContainerOptions>,\n ) {\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 DefaultContainer(this, {\n ...this.myOptions,\n ...options,\n });\n\n this.myChildren.add(container);\n return container;\n }\n\n clearCache(): unknown[] {\n this.checkDisposed();\n return this.myTokenRegistry.clearRegistrations();\n }\n\n getCached<T>(token: Token<T>): T | undefined {\n this.checkDisposed();\n const registration = this.myTokenRegistry.get(token);\n return registration?.value?.current;\n }\n\n getAllCached<T>(token: Token<T>): T[] {\n this.checkDisposed();\n const registrations = this.myTokenRegistry.getAll(token);\n\n if (!registrations) {\n return [];\n }\n\n const values = new Set<T>();\n\n for (const registration of registrations) {\n const value = registration.value;\n\n if (value) {\n values.add(value.current);\n }\n }\n\n return Array.from(values);\n }\n\n resetRegistry(): unknown[] {\n this.checkDisposed();\n const [, registrations] = this.myTokenRegistry.deleteAll();\n const values = new Set<unknown>();\n\n for (const registration of registrations) {\n const value = registration.value;\n\n if (value) {\n values.add(value.current);\n }\n }\n\n return Array.from(values);\n }\n\n isRegistered(token: Token): boolean {\n this.checkDisposed();\n return this.myTokenRegistry.get(token) !== undefined;\n }\n\n register<T>(...args: [Constructor<T & object>] | [Token<T>, Provider<T>, RegistrationOptions?]): this {\n this.checkDisposed();\n\n if (args.length == 1) {\n const Class = args[0];\n const metadata = getMetadata(Class);\n\n // Register the class itself\n this.myTokenRegistry.set(Class, {\n // The provider is of type ClassProvider, initialized by getMetadata\n provider: metadata.provider,\n options: {\n scope: metadata.scope,\n },\n dependencies: metadata.dependencies,\n });\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 } else {\n const [token, provider, options] = args;\n\n if (isClassProvider(provider)) {\n const Class = provider.useClass;\n const metadata = getMetadata(Class);\n this.myTokenRegistry.set(token, {\n provider: metadata.provider,\n options: {\n // The explicit registration options override what is specified\n // via class decorators (e.g., @Scoped)\n scope: metadata.scope,\n ...options,\n },\n dependencies: metadata.dependencies,\n });\n } else {\n if (isExistingProvider(provider)) {\n assert(\n token !== provider.useExisting,\n `the useExisting token ${token.name} cannot be the same as the token being registered`,\n );\n }\n\n this.myTokenRegistry.set(token, {\n provider: provider,\n options: options,\n });\n }\n }\n\n return this;\n }\n\n unregister<T>(token: Token<T>): T[] {\n this.checkDisposed();\n const registrations = this.myTokenRegistry.delete(token);\n\n if (!registrations) {\n return [];\n }\n\n const values = new Set<T>();\n\n for (const registration of registrations) {\n const value = registration.value;\n\n if (value) {\n values.add(value.current);\n }\n }\n\n return Array.from(values);\n }\n\n resolve<T>(token: Token<T>, optional?: boolean): T | undefined {\n this.checkDisposed();\n const registration = this.myTokenRegistry.get(token);\n\n if (registration) {\n return this.resolveRegistration(token, registration);\n }\n\n if (isConstructor(token)) {\n return this.instantiateClass(token, optional);\n }\n\n return optional ? undefined : throwUnregisteredError(token);\n }\n\n resolveAll<T>(token: Token<T>, optional?: boolean): NonNullable<T>[] {\n this.checkDisposed();\n const registrations = this.myTokenRegistry.getAll(token);\n\n if (registrations) {\n return registrations\n .map((registration) => this.resolveRegistration(token, registration))\n .filter((value) => value != null);\n }\n\n if (isConstructor(token)) {\n const instance = this.instantiateClass(token, optional);\n return instance === undefined // = could not resolve, but since it is optional\n ? []\n : [instance];\n }\n\n return optional ? [] : throwUnregisteredError(token);\n }\n\n dispose(): void {\n if (this.myDisposed) {\n return;\n }\n\n // Dispose children containers first\n for (const child of this.myChildren) {\n child.dispose();\n }\n\n this.myChildren.clear();\n\n // Remove ourselves from our parent container\n this.myParent?.myChildren?.delete(this);\n this.myDisposed = true;\n\n const [, registrations] = this.myTokenRegistry.deleteAll();\n const disposedRefs = new Set<any>();\n\n // Dispose all resolved (aka instantiated) tokens that implement the Disposable interface\n for (const registration of registrations) {\n const value = registration.value?.current;\n\n if (isDisposable(value) && !disposedRefs.has(value)) {\n disposedRefs.add(value);\n value.dispose();\n }\n }\n\n // Allow values to be GCed\n disposedRefs.clear();\n }\n\n private resolveRegistration<T>(token: Token<T>, registration: Registration<T>): T {\n let currRegistration: Registration<T> | undefined = registration;\n let currProvider = currRegistration.provider;\n\n while (isExistingProvider(currProvider)) {\n const targetToken = currProvider.useExisting;\n currRegistration = this.myTokenRegistry.get(targetToken);\n\n if (!currRegistration) {\n throwExistingUnregisteredError(token, targetToken);\n }\n\n currProvider = currRegistration.provider;\n }\n\n try {\n return this.resolveProviderValue(currRegistration, currProvider);\n } catch (e) {\n // If we were trying to resolve a token registered via ExistingProvider,\n // we must add the cause of the error to the message\n if (isExistingProvider(registration.provider)) {\n throwExistingUnregisteredError(token, e as Error);\n }\n\n throw e;\n }\n }\n\n private instantiateClass<T extends object>(Class: Constructor<T>, optional?: boolean): T | undefined {\n const metadata = getMetadata(Class);\n\n if (metadata.autoRegister ?? this.myOptions.autoRegister) {\n this.register(Class);\n return (this as Container).resolve(Class);\n }\n\n const scope = this.resolveScope(metadata.scope);\n\n if (optional && scope === Scope.Container) {\n // It would not be possible to resolve the class in container scope,\n // as that would require prior registration.\n // However, since resolution is marked optional, we simply return undefined.\n return undefined;\n }\n\n assert(\n scope !== Scope.Container,\n `unregistered class ${Class.name} cannot be resolved in container scope`,\n );\n\n const registration: Registration<T> = {\n provider: metadata.provider,\n options: {\n scope: scope,\n },\n dependencies: metadata.dependencies,\n };\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n return this.resolveScopedValue(registration, (args) => new Class(...args));\n }\n\n private resolveProviderValue<T>(registration: Registration<T>, provider: Provider<T>): T {\n assert(registration.provider === provider, \"internal error: mismatching provider\");\n\n if (isClassProvider(provider)) {\n const Class = provider.useClass;\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n return this.resolveScopedValue(registration, (args) => new Class(...args));\n }\n\n if (isFactoryProvider(provider)) {\n const factory = provider.useFactory;\n return this.resolveScopedValue(registration, factory);\n }\n\n if (isValueProvider(provider)) {\n return provider.useValue;\n }\n\n if (isExistingProvider(provider)) {\n assert(false, \"internal error: unexpected ExistingProvider\");\n }\n\n expectNever(provider);\n }\n\n private resolveScopedValue<T>(registration: Registration<T>, factory: (...args: any[]) => T): T {\n let context = useInjectionContext();\n\n if (!context || context.container !== this) {\n context = {\n container: this,\n resolution: createResolution(),\n };\n }\n\n const resolution = context.resolution;\n const provider = registration.provider;\n const options = registration.options;\n\n if (resolution.stack.has(provider)) {\n const dependentRef = resolution.dependents.get(provider);\n assert(dependentRef, \"circular dependency detected\");\n return dependentRef.current;\n }\n\n const scope = this.resolveScope(options?.scope, context);\n const cleanups = [\n provideInjectionContext(context),\n !isBuilder(provider) && resolution.stack.push(provider, { provider, scope }),\n ];\n\n try {\n switch (scope) {\n case Scope.Container: {\n const valueRef = registration.value;\n\n if (valueRef) {\n return valueRef.current;\n }\n\n const args = this.resolveConstructorDependencies(registration);\n const value = this.injectDependencies(registration, factory(args));\n registration.value = { current: value };\n return value;\n }\n case Scope.Resolution: {\n const valueRef = resolution.values.get(provider);\n\n if (valueRef) {\n return valueRef.current;\n }\n\n const args = this.resolveConstructorDependencies(registration);\n const value = this.injectDependencies(registration, factory(args));\n resolution.values.set(provider, { current: value });\n return value;\n }\n case Scope.Transient: {\n const args = this.resolveConstructorDependencies(registration);\n return this.injectDependencies(registration, factory(args));\n }\n }\n } finally {\n cleanups.forEach((cleanup) => cleanup && cleanup());\n }\n }\n\n private resolveScope(\n scope = this.myOptions.defaultScope,\n context = useInjectionContext(),\n ): Exclude<Scope, typeof Scope.Inherited> {\n if (scope == Scope.Inherited) {\n const dependentFrame = context?.resolution.stack.peek();\n return dependentFrame?.scope || Scope.Transient;\n }\n\n return scope;\n }\n\n private resolveConstructorDependencies<T>(registration: Registration<T>): any[] {\n const dependencies = registration.dependencies;\n\n if (dependencies) {\n assert(isClassProvider(registration.provider), `internal error: not a ClassProvider`);\n const ctorDeps = dependencies.constructor;\n\n if (ctorDeps.length > 0) {\n // Let's check if all necessary constructor parameters are decorated.\n // If not, we cannot safely create an instance.\n const ctor = registration.provider.useClass;\n assert(ctor.length === ctorDeps.length, () => {\n const msg = `expected ${ctor.length} decorated constructor parameters in ${ctor.name}`;\n return msg + `, but found ${ctorDeps.length}`;\n });\n\n return ctorDeps\n .sort((a, b) => a.index - b.index)\n .map((dep) => {\n const token = dep.tokenRef.getRefToken();\n switch (dep.decorator) {\n case \"Inject\":\n return this.resolve(token);\n case \"InjectAll\":\n return this.resolveAll(token);\n case \"Optional\":\n return this.resolve(token, true);\n case \"OptionalAll\":\n return this.resolveAll(token, true);\n }\n });\n }\n }\n\n return [];\n }\n\n private injectDependencies<T>(registration: Registration<T>, instance: T): T {\n const dependencies = registration.dependencies;\n\n if (dependencies) {\n assert(isClassProvider(registration.provider), `internal error: not a ClassProvider`);\n const ctor = registration.provider.useClass;\n\n // Perform method injection\n for (const [key, methodDeps] of dependencies.methods) {\n // Let's check if all necessary method parameters are decorated.\n // If not, we cannot safely invoke the method.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const method = (instance as any)[key] as Function;\n assert(methodDeps.length === method.length, () => {\n const msg = `expected ${method.length} decorated method parameters`;\n return msg + ` in ${ctor.name}.${String(key)}, but found ${methodDeps.length}`;\n });\n\n const args = methodDeps\n .sort((a, b) => a.index - b.index)\n .map((dep) => {\n const token = dep.tokenRef.getRefToken();\n switch (dep.decorator) {\n case \"Inject\":\n return injectBy(instance, token);\n case \"InjectAll\":\n return injectAll(token);\n case \"Optional\":\n return optionalBy(instance, token);\n case \"OptionalAll\":\n return optionalAll(token);\n }\n });\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n method.bind(instance)(...args);\n }\n }\n\n return instance;\n }\n\n private checkDisposed(): void {\n assert(!this.myDisposed, \"the container is disposed\");\n }\n}\n","import { DefaultContainer } from \"./defaultContainer\";\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): boolean;\n\n /**\n * Registers a {@link ClassProvider}, using the class itself as its token.\n *\n * Tokens provided to the {@link Injectable} decorator applied to the class\n * are also registered as aliases. The scope is determined by the {@link Scoped}\n * decorator, if present.\n */\n register<Instance extends object>(Class: Constructor<Instance>): this;\n\n /**\n * Registers a {@link ClassProvider} with a token.\n */\n register<Instance extends object, ProviderInstance extends Instance>(\n token: Token<Instance>,\n provider: ClassProvider<ProviderInstance>,\n options?: RegistrationOptions,\n ): this;\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 ): this;\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>(\n token: Token<Value>,\n provider: ExistingProvider<ProviderValue>,\n ): this;\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>(\n token: Token<Value>,\n provider: ValueProvider<ProviderValue>,\n ): this;\n\n /**\n * Removes all registrations for the given token from the container's internal registry.\n *\n * Returns an array of distinct cached values that were stored within the removed registrations.\n * Values from {@link ValueProvider} registrations are not included, as they are not cached.\n *\n * Note that only this container is affected. Parent containers, if any, remain unchanged.\n */\n unregister<Value>(token: Token<Value>): Value[];\n\n /**\n * Resolves the given class to the instance associated with it.\n *\n * If the class is registered in this container or any of its parent containers,\n * an instance is created using the most recent registration.\n *\n * If the class is not registered, but it is decorated with {@link AutoRegister},\n * or {@link ContainerOptions.autoRegister} is true, the class is registered automatically.\n * Otherwise, resolution fails.\n * The scope for the automatic registration is determined by either\n * the {@link Scoped} decorator on the class, or {@link ContainerOptions.defaultScope}.\n *\n * If `optional` is false or is not passed and the class is not registered in the container\n * (and could not be auto-registered), an error is thrown.\n * Otherwise, if `optional` is true, `undefined` is returned.\n *\n * The resolution behavior depends on the {@link Provider} used during registration:\n * - For {@link ValueProvider}, the explicitly provided instance is returned.\n * - For {@link FactoryProvider}, the factory function is invoked to create the instance.\n * - For {@link ClassProvider}, a new instance of the class is created according to its scope.\n * - For {@link ExistingProvider}, the instance is resolved by referring to another registered token.\n *\n * If the class is registered with _container_ scope, the resolved instance is cached\n * in the container's internal registry.\n */\n resolve<Instance extends object>(Class: Constructor<Instance>, optional?: false): Instance;\n resolve<Instance extends object>(Class: Constructor<Instance>, optional: true): Instance | undefined;\n resolve<Instance extends object>(Class: Constructor<Instance>, optional?: boolean): Instance | undefined;\n\n /**\n * Resolves the given token to the value associated with it.\n *\n * If the token is registered in this container or any of its parent containers,\n * its value is resolved using the most recent registration.\n *\n * If `optional` is false or not passed and the token is not registered in the container,\n * an error is thrown. Otherwise, if `optional` is true, `undefined` is returned.\n *\n * The resolution behavior depends on the {@link Provider} used during registration:\n * - For {@link ValueProvider}, the explicitly provided value is returned.\n * - For {@link FactoryProvider}, the factory function is invoked to create the value.\n * - For {@link ClassProvider}, a new instance of the class is created according to its scope.\n * - For {@link ExistingProvider}, the value is resolved by referring to another registered token.\n *\n * If the token is registered with _container_ scope, the resolved value is cached\n * in the container's internal registry.\n */\n resolve<Value>(token: Token<Value>, optional?: false): Value;\n resolve<Value>(token: Token<Value>, optional: true): Value | undefined;\n resolve<Value>(token: Token<Value>, optional?: boolean): Value | undefined;\n\n /**\n * Resolves the given class to all instances provided by the registrations associated with it.\n *\n * If the class is not registered, but it is decorated with {@link AutoRegister},\n * or {@link ContainerOptions.autoRegister} is true, the class is registered automatically.\n * Otherwise, resolution fails.\n * The scope for the automatic registration is determined by either\n * the {@link Scoped} decorator on the class, or {@link ContainerOptions.defaultScope}.\n *\n * If `optional` is false or is not passed and the class is not registered in the container\n * (and could not be auto-registered), an error is thrown.\n * Otherwise, if `optional` is true, an empty array is returned.\n *\n * The resolution behavior depends on the {@link Provider} used during registration:\n * - For {@link ValueProvider}, the explicitly provided instance is returned.\n * - For {@link FactoryProvider}, the factory function is invoked to create the instance.\n * - For {@link ClassProvider}, a new instance of the class is created according to its scope.\n * - For {@link ExistingProvider}, the instance is resolved by referring to another registered token.\n *\n * If the class is registered with _container_ scope, the resolved instances are cached\n * in the container's internal registry.\n *\n * A separate instance of the class is created for each provider.\n *\n * @see The documentation for `resolve(Class: Constructor)`\n */\n resolveAll<Instance extends object>(Class: Constructor<Instance>, optional?: false): Instance[];\n resolveAll<Instance extends object>(Class: Constructor<Instance>, optional: true): Instance[];\n resolveAll<Instance extends object>(Class: Constructor<Instance>, optional?: boolean): Instance[];\n\n /**\n * Resolves the given token to all values provided by the registrations associated with it.\n *\n * If `optional` is false or not passed and the token is not registered in the container,\n * an error is thrown. Otherwise, if `optional` is true, an empty array is returned.\n *\n * The resolution behavior depends on the {@link Provider} used during registration:\n * - For {@link ValueProvider}, the explicitly provided value is returned.\n * - For {@link FactoryProvider}, the factory function is invoked to create the value.\n * - For {@link ClassProvider}, a new instance of the class is created according to its scope.\n * - For {@link ExistingProvider}, the value is resolved by referring to another registered token.\n *\n * If the token is registered with _container_ scope, the resolved values are cached\n * in the container's internal registry.\n *\n * @see The documentation for `resolve(token: Token)`\n */\n resolveAll<Value>(token: Token<Value>, optional?: false): NonNullable<Value>[];\n resolveAll<Value>(token: Token<Value>, optional: true): NonNullable<Value>[];\n resolveAll<Value>(token: Token<Value>, optional?: boolean): NonNullable<Value>[];\n\n /**\n * Disposes this container and all its cached values.\n *\n * Token values implementing a `Disposable` interface (e.g., objects with a `dispose()` function)\n * are automatically disposed during this process.\n *\n * Note that children containers are disposed first, in creation order.\n */\n dispose(): void;\n}\n\n/**\n * Creates a new container.\n */\nexport function createContainer(\n options: Partial<ContainerOptions> = {\n autoRegister: false,\n defaultScope: Scope.Inherited,\n },\n): Container {\n return new DefaultContainer(undefined, options);\n}\n","import { getMetadata } from \"../metadata\";\nimport type { Constructor } from \"../token\";\n\n/**\n * Class decorator for enabling auto-registration of an unregistered class\n * when first resolving it 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(enable: boolean = true): ClassDecorator {\n return function (Class) {\n const metadata = getMetadata(Class as any as Constructor<any>);\n metadata.autoRegister = enable;\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 a token that is declared later in the file by wrapping it in a function.\n */\nexport function forwardRef<Value>(token: () => Tokens<Value>): TokensRef<Value>;\nexport function forwardRef<Value>(token: () => Token<Value>): TokenRef<Value>;\nexport function forwardRef<Value>(\n token: () => Token<Value> | Tokens<Value>,\n): TokensRef<Value> & TokenRef<Value> {\n return {\n getRefTokens: (): Set<Token<Value>> => {\n // Normalize the single token here, so that we don't have\n // to do it at every getRefTokens call site\n const tokenOrTokens = token();\n const tokensArray = Array.isArray(tokenOrTokens) ? tokenOrTokens : [tokenOrTokens];\n return new Set(tokensArray);\n },\n getRefToken: () => {\n const tokenOrTokens = token();\n assert(!Array.isArray(tokenOrTokens), \"internal error: ref tokens should be a single token\");\n return tokenOrTokens;\n },\n };\n}\n\n// @internal\nexport function isTokensRef(value: any): value is TokensRef {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return value && typeof value === \"object\" && typeof value.getRefTokens === \"function\";\n}\n\n// @internal\nexport function isTokenRef(value: any): value is TokenRef {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return value && typeof value === \"object\" && typeof value.getRefToken === \"function\";\n}\n","import { assert } from \"../errors\";\nimport { getMetadata } from \"../metadata\";\nimport type { Constructor, Token } from \"../token\";\nimport type { Decorator } from \"../tokenRegistry\";\nimport { forwardRef, isTokenRef, type TokenRef } from \"../tokensRef\";\n\nexport function processDecoratedParameter(\n decorator: Decorator,\n token: Token | TokenRef,\n target: object,\n propertyKey: string | symbol | undefined,\n parameterIndex: number,\n): void {\n // Error out immediately if the decorator has been applied\n // to a static property or a static method\n if (propertyKey !== undefined && typeof target === \"function\") {\n assert(false, `@${decorator} cannot be used on static member ${target.name}.${String(propertyKey)}`);\n }\n\n const tokenRef = isTokenRef(token) ? token : forwardRef(() => token);\n\n if (propertyKey === undefined) {\n // Constructor\n const metadata = getMetadata(target as Constructor<any>);\n metadata.dependencies.constructor.push({\n decorator: decorator,\n tokenRef: tokenRef,\n index: parameterIndex,\n });\n } else {\n // Normal instance method\n const metadata = getMetadata(target.constructor as Constructor<any>);\n const methods = metadata.dependencies.methods;\n let dep = methods.get(propertyKey);\n\n if (dep === undefined) {\n dep = [];\n methods.set(propertyKey, dep);\n }\n\n dep.push({\n decorator: decorator,\n tokenRef: tokenRef,\n index: parameterIndex,\n });\n }\n}\n","import type { Constructor, Token } from \"../token\";\nimport type { TokenRef } from \"../tokensRef\";\nimport { processDecoratedParameter } from \"./decorators\";\n\n/**\n * Parameter decorator that injects the instance associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\nexport function Inject<Instance extends object>(Class: Constructor<Instance>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects the value associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\nexport function Inject<Value>(token: Token<Value>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects the value associated with the given token.\n *\n * Allows referencing a token that is declared later in the file by using\n * the {@link forwardRef} helper function.\n *\n * Throws an error if the token is not registered in the container.\n *\n * @example\n * ```ts\n * class Wizard {\n * constructor(@Inject(forwardRef(() => Wand)) readonly wand: Wand) {}\n * }\n * // Other code...\n * class Wand {}\n * ```\n */\nexport function Inject<Value>(tokens: TokenRef<Value>): ParameterDecorator;\n\nexport function Inject<T>(token: Token<T> | TokenRef<T>): ParameterDecorator {\n return function (target, propertyKey, parameterIndex: number): void {\n processDecoratedParameter(\"Inject\", token, target, propertyKey, parameterIndex);\n };\n}\n","import { getMetadata } from \"../metadata\";\nimport type { Constructor, Tokens } from \"../token\";\nimport { forwardRef, isTokensRef, type TokenRef, type TokensRef } from \"../tokensRef\";\n\n/**\n * Class decorator for registering additional aliasing tokens for the decorated type\n * when registering it.\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 for registering additional aliasing tokens for the decorated type\n * when registering it.\n *\n * The container uses {@link ExistingProvider} under the hood.\n *\n * Allows referencing tokens that are declared later in the file by using\n * the {@link forwardRef} helper function.\n *\n * @example\n * ```ts\n * @Injectable(forwardRef() => Weapon) // Weapon is declared after Wand\n * class Wizard {}\n * // Other code...\n * class Weapon {}\n * ```\n */\nexport function Injectable<This extends object, Value extends This>(\n tokens: TokenRef<Value> | TokensRef<Value>,\n): ClassDecorator;\n\n/**\n * @__NO_SIDE_EFFECTS__\n */\nexport function Injectable(...args: unknown[]): ClassDecorator {\n return function (Class): void {\n const metadata = getMetadata(Class as any as Constructor<any>);\n const arg0 = args[0];\n const tokensRef = isTokensRef(arg0) ? arg0 : forwardRef(() => args as Tokens);\n const existingTokensRef = metadata.tokensRef;\n metadata.tokensRef = {\n getRefTokens: () => {\n const existingTokens = existingTokensRef.getRefTokens();\n\n for (const token of tokensRef.getRefTokens()) {\n existingTokens.add(token);\n }\n\n return existingTokens;\n },\n };\n };\n}\n","import type { Constructor, Token } from \"../token\";\nimport type { TokenRef } from \"../tokensRef\";\nimport { processDecoratedParameter } from \"./decorators\";\n\n/**\n * Parameter decorator that injects all instances provided by the registrations\n * associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\nexport function InjectAll<Instance extends object>(Class: Constructor<Instance>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects all values provided by the registrations\n * associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\nexport function InjectAll<Value>(token: Token<Value>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects all values provided by the registrations\n * associated with the given token.\n *\n * Allows referencing a token that is declared later in the file by using\n * the {@link forwardRef} helper function.\n *\n * Throws an error if the token is not registered in the container.\n *\n * @example\n * ```ts\n * class Wizard {\n * constructor(@InjectAll(forwardRef(() => Wand)) readonly wands: Wand[]) {}\n * }\n * // Other code...\n * class Wand {}\n * ```\n */\nexport function InjectAll<Value>(tokens: TokenRef<Value>): ParameterDecorator;\n\nexport function InjectAll<T>(token: Token<T> | TokenRef<T>): ParameterDecorator {\n return function (target, propertyKey, parameterIndex: number): void {\n processDecoratedParameter(\"InjectAll\", token, target, propertyKey, parameterIndex);\n };\n}\n","import type { Constructor, Token } from \"../token\";\nimport type { TokenRef } from \"../tokensRef\";\nimport { processDecoratedParameter } from \"./decorators\";\n\n/**\n * Parameter decorator that injects the instance associated with the given class,\n * or `undefined` if the class is not registered in the container.\n */\nexport function Optional<Instance extends object>(Class: Constructor<Instance>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects the value associated with the given token,\n * or `undefined` if the token is not registered in the container.\n */\nexport function Optional<Value>(token: Token<Value>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects the value associated with the given token,\n * or `undefined` if the token is not registered in the container.\n *\n * Allows referencing a token that is declared later in the file by using\n * the {@link forwardRef} helper function.\n *\n * @example\n * ```ts\n * class Wizard {\n * constructor(@Optional(forwardRef(() => Wand)) readonly wand: Wand | undefined) {}\n * }\n * // Other code...\n * class Wand {}\n * ```\n */\nexport function Optional<Value>(tokens: TokenRef<Value>): ParameterDecorator;\n\nexport function Optional<T>(token: Token<T> | TokenRef<T>): ParameterDecorator {\n return function (target, propertyKey, parameterIndex: number): void {\n processDecoratedParameter(\"Optional\", token, target, propertyKey, parameterIndex);\n };\n}\n","import type { Constructor, Token } from \"../token\";\nimport type { TokenRef } from \"../tokensRef\";\nimport { processDecoratedParameter } from \"./decorators\";\n\n/**\n * Parameter decorator that injects all instances provided by the registrations\n * associated with the given class, or an empty array if the class is not registered\n * in the container.\n */\nexport function OptionalAll<Instance extends object>(Class: Constructor<Instance>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects all values provided by the registrations\n * associated with the given token, or an empty array if the token is not registered\n * in the container.\n */\nexport function OptionalAll<Value>(token: Token<Value>): ParameterDecorator;\n\n/**\n * Parameter decorator that injects all values provided by the registrations\n * associated with the given token, or an empty array if the token is not registered\n * in the container.\n *\n * Allows referencing a token that is declared later in the file by using\n * the {@link forwardRef} helper function.\n *\n * @example\n * ```ts\n * class Wizard {\n * constructor(@OptionalAll(forwardRef(() => Wand)) readonly wands: Wand[]) {}\n * }\n * // Other code...\n * class Wand {}\n * ```\n */\nexport function OptionalAll<Value>(tokens: TokenRef<Value>): ParameterDecorator;\n\nexport function OptionalAll<T>(token: Token<T> | TokenRef<T>): ParameterDecorator {\n return function (target, propertyKey, parameterIndex: number): void {\n processDecoratedParameter(\"OptionalAll\", token, target, propertyKey, parameterIndex);\n };\n}\n","import { getMetadata } from \"../metadata\";\nimport type { Scope } from \"../scope\";\nimport type { Constructor } from \"../token\";\n\n/**\n * Class decorator for setting the scope of the decorated type when registering it.\n *\n * The scope set by this decorator can be overridden by explicit registration options, if provided.\n *\n * @example\n * ```ts\n * @Scoped(Scope.Container)\n * class Wizard {}\n *\n * container.register(Wizard);\n *\n * // Under the hood\n * container.register(\n * Wizard,\n * { useClass: Wizard },\n * { scope: Scope.Container },\n * );\n * ```\n *\n * @__NO_SIDE_EFFECTS__\n */\nexport function Scoped(scope: Scope): ClassDecorator {\n return function (Class): void {\n const metadata = getMetadata(Class as any as Constructor<any>);\n metadata.scope = scope;\n };\n}\n","import { inject } from \"./inject\";\nimport { injectAll } from \"./injectAll\";\nimport { ensureInjectionContext, provideInjectionContext, useInjectionContext } from \"./injectionContext\";\nimport { optional } from \"./optional\";\nimport { optionalAll } from \"./optionalAll\";\nimport type { Constructor, Token, Type } from \"./token\";\nimport { build } from \"./tokenRegistry\";\n\n/**\n * Injector API.\n */\nexport interface Injector {\n /**\n * Injects the instance associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\n inject<Instance extends object>(Class: Constructor<Instance>): Instance;\n\n /**\n * Injects the value associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\n inject<Value>(token: Token<Value>): Value;\n\n /**\n * Injects all instances provided by the registrations associated with the given class.\n *\n * Throws an error if the class is not registered in the container.\n */\n injectAll<Instance extends object>(Class: Constructor<Instance>): Instance[];\n\n /**\n * Injects all values provided by the registrations associated with the given token.\n *\n * Throws an error if the token is not registered in the container.\n */\n injectAll<Value>(token: Token<Value>): NonNullable<Value>[];\n\n /**\n * Injects the instance associated with the given class,\n * or `undefined` if the class is not registered in the container.\n */\n optional<Instance extends object>(Class: Constructor<Instance>): Instance | undefined;\n\n /**\n * Injects the value associated with the given token,\n * or `undefined` if the token is not registered in the container.\n */\n optional<Value>(token: Token<Value>): Value | undefined;\n\n /**\n * Injects all instances provided by the registrations associated with the given class,\n * or an empty array if the class is not registered in the container.\n */\n optionalAll<Instance extends object>(Class: Constructor<Instance>): Instance[];\n\n /**\n * Injects all values provided by the registrations associated with the given token,\n * or an empty array if the token is not registered in the container.\n */\n optionalAll<Value>(token: Token<Value>): NonNullable<Value>[];\n}\n\n/**\n * Injector token for dynamic injections.\n *\n * @example\n * ```ts\n * class Wizard {\n * private injector = inject(Injector);\n * private wand?: Wand;\n *\n * getWand(): Wand {\n * return (this.wand ??= this.injector.inject(Wand));\n * }\n * }\n *\n * const wizard = container.resolve(Wizard);\n * wizard.getWand(); // => Wand\n * ```\n */\nexport const Injector: Type<Injector> = /*@__PURE__*/ build(function Injector() {\n const context = ensureInjectionContext(Injector);\n const resolution = context.resolution;\n\n const dependentFrame = resolution.stack.peek();\n const dependentRef = dependentFrame && resolution.dependents.get(dependentFrame.provider);\n\n function withCurrentContext<R>(fn: () => R): R {\n if (useInjectionContext()) {\n return fn();\n }\n\n const cleanups = [\n provideInjectionContext(context),\n dependentFrame && resolution.stack.push(dependentFrame.provider, dependentFrame),\n dependentRef && resolution.dependents.set(dependentFrame.provider, dependentRef),\n ];\n\n try {\n return fn();\n } finally {\n for (const cleanup of cleanups) {\n cleanup?.();\n }\n }\n }\n\n return {\n inject: <T>(token: Token<T>) => withCurrentContext(() => inject(token)),\n injectAll: <T>(token: Token<T>) => withCurrentContext(() => injectAll(token)),\n optional: <T>(token: Token<T>) => withCurrentContext(() => optional(token)),\n optionalAll: <T>(token: Token<T>) => withCurrentContext(() => optionalAll(token)),\n };\n});\n","import type { Container } from \"./container\";\n\n/**\n * Composer API for middleware functions.\n */\nexport interface MiddlewareComposer {\n /**\n * Add a middleware function to the composer.\n */\n use<MethodKey extends keyof Container>(\n key: MethodKey,\n wrap: Container[MethodKey] extends Function\n ? (next: Container[MethodKey]) => Container[MethodKey]\n : never,\n ): MiddlewareComposer;\n}\n\n/**\n * Middleware function that can be used to extend the container.\n *\n * @example\n * ```ts\n * const logger: Middleware = (composer, _api) => {\n * composer\n * .use(\"resolve\", (next) => (...args) => {\n * console.log(\"resolve\", args);\n * return next(...args);\n * })\n * .use(\"resolveAll\", (next) => (...args) => {\n * console.log(\"resolveAll\", args);\n * return next(...args);\n * });\n * };\n * ```\n */\nexport interface Middleware {\n (composer: MiddlewareComposer, api: Readonly<Container>): void;\n}\n\n/**\n * Apply middleware functions to a container.\n *\n * Middlewares are applied in array order, but execute in reverse order.\n *\n * @example\n * ```ts\n * const container = applyMiddleware(\n * createContainer(),\n * [A, B],\n * );\n * ```\n *\n * The execution order will be:\n *\n * 1. B before\n * 2. A before\n * 3. original function\n * 4. A after\n * 5. B after\n *\n * This allows outer middlewares to wrap and control the behavior of inner middlewares.\n */\nexport function applyMiddleware(container: Container, middlewares: Middleware[]): Container {\n const composer: MiddlewareComposer = {\n use(key, wrap): MiddlewareComposer {\n // We need to bind the 'this' context of the function to the container\n // before passing it to the middleware wrapper.\n //\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call\n const fn = (container[key] as any).bind(container);\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n container[key] = wrap(fn);\n return composer;\n },\n };\n\n const api = (container.api ||= { ...container });\n\n for (const middleware of middlewares) {\n middleware(composer, api);\n }\n\n return container;\n}\n"],"names":["assert","condition","message","resolvedMessage","Error","tag","expectNever","value","TypeError","String","throwUnregisteredError","token","name","throwExistingUnregisteredError","sourceToken","targetTokenOrError","isError","untag","stack","startsWith","substring","trimStart","createInjectionContext","current","provide","next","prev","use","invariant","KeyedStack","has","key","myKeys","peek","entry","myEntries","at","push","add","pop","delete","Array","WeakSet","WeakRefMap","get","ref","myMap","deref","set","WeakRef","WeakMap","createResolution","values","dependents","provideInjectionContext","useInjectionContext","ensureInjectionContext","fn","context","inject","container","resolve","injectBy","thisArg","resolution","currentFrame","currentRef","cleanup","provider","injectAll","resolveAll","getMetadata","Class","metadata","metadataMap","tokensRef","getRefTokens","Set","useClass","dependencies","methods","Map","optional","optionalBy","optionalAll","isClassProvider","isExistingProvider","isFactoryProvider","isValueProvider","Scope","Inherited","Transient","Resolution","Container","createType","typeName","type","inter","union","toString","isConstructor","getTypeName","proto","Object","getPrototypeOf","prototype","constructor","TokenRegistry","parent","getAll","internal","internals","getAllFromParent","registration","registrations","deleteAll","tokens","from","keys","flat","clear","clearRegistrations","i","length","undefined","isBuilder","builders","build","factory","useFactory","options","scope","isDisposable","dispose","DefaultContainer","myParent","myChildren","myDisposed","myOptions","autoRegister","defaultScope","myTokenRegistry","registry","isDisposed","createChild","checkDisposed","clearCache","getCached","getAllCached","resetRegistry","isRegistered","register","args","useExisting","unregister","resolveRegistration","instantiateClass","map","filter","instance","child","disposedRefs","currRegistration","currProvider","targetToken","resolveProviderValue","e","resolveScope","resolveScopedValue","useValue","dependentRef","cleanups","valueRef","resolveConstructorDependencies","injectDependencies","forEach","dependentFrame","ctorDeps","ctor","msg","sort","a","b","index","dep","tokenRef","getRefToken","decorator","methodDeps","method","bind","createContainer","AutoRegister","enable","forwardRef","tokenOrTokens","tokensArray","isArray","isTokensRef","isTokenRef","processDecoratedParameter","target","propertyKey","parameterIndex","Inject","Injectable","arg0","existingTokensRef","existingTokens","InjectAll","Optional","OptionalAll","Scoped","Injector","withCurrentContext","applyMiddleware","middlewares","composer","wrap","api","middleware"],"mappings":"AAEA;AAC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
"license": "MIT",
|
5
5
|
"description": "Lightweight, type-safe, flexible dependency injection library for TypeScript and JavaScript",
|
6
6
|
"author": "Edoardo Luppi <lp.edoardo@gmail.com>",
|
@@ -47,7 +47,7 @@
|
|
47
47
|
},
|
48
48
|
"scripts": {
|
49
49
|
"build": "tsc --noEmit && bunchee --sourcemap",
|
50
|
-
"test": "vitest --coverage",
|
50
|
+
"test": "npm run build && vitest --coverage",
|
51
51
|
"lint": "eslint . --fix --cache",
|
52
52
|
"lint:ci": "eslint . --max-warnings 0 --cache --cache-location ./node_modules/.cache/eslint/.eslintcache",
|
53
53
|
"format": "prettier \"**/*.{json,md,yml}\" --write --log-level warn --cache",
|