@noego/ioc 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/framework/decorators/Component.cjs.map +1 -1
- package/dist/framework/decorators/Component.js.map +1 -1
- package/dist/framework/decorators/Inject.cjs.map +1 -1
- package/dist/framework/decorators/Inject.js.map +1 -1
- package/dist/framework/decorators/index.cjs.map +1 -1
- package/dist/framework/decorators/index.js.map +1 -1
- package/dist/framework/implementation/Container.cjs.map +1 -1
- package/dist/framework/implementation/Container.js +1 -1
- package/dist/framework/implementation/Container.js.map +1 -1
- package/dist/framework/implementation/DecoratorSupport.cjs.map +1 -1
- package/dist/framework/implementation/DecoratorSupport.js.map +1 -1
- package/dist/framework/interface/Container.cjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +5 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../framework/decorators/Component.ts"],"sourcesContent":["// framework/decorators/Component.ts\nimport 'reflect-metadata';\nimport { COMPONENT_OPTIONS_METADATA_KEY } from './metadataKeys';\nimport { LoadAs } from '../implementation/LoadAs';\n\nexport interface ComponentOptions {\n scope?: LoadAs;\n}\n\n/**\n * Marks a class as a component managed by the IOC container.\n * @param options Configuration options, primarily the scope (lifetime). Defaults to Transient.\n */\nexport function Component(options: ComponentOptions = {}): ClassDecorator {\n return (target: Function) => {\n // Ensure default scope if not provided\n const finalOptions: Required<ComponentOptions> = {\n scope: options.scope ?? LoadAs.Transient, // Default to Transient\n };\n \n // Define metadata on the class constructor - use both Symbol and string versions\n Reflect.defineMetadata(COMPONENT_OPTIONS_METADATA_KEY, finalOptions, target);\n \n // Also define with string key for easier debugging\n Reflect.defineMetadata('ComponentOptions', finalOptions, target);\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,8BAAO;AACP,0BAA+C;AAC/C,oBAAuB;AAUhB,SAAS,UAAU,UAA4B,CAAC,GAAmB;AACtE,SAAO,CAAC,WAAqB;AAEzB,UAAM,eAA2C;AAAA,MAC7C,OAAO,QAAQ,SAAS,qBAAO;AAAA;AAAA,IACnC;AAGA,YAAQ,eAAe,oDAAgC,cAAc,MAAM;AAG3E,YAAQ,eAAe,oBAAoB,cAAc,MAAM;AAAA,EACnE;AACJ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../framework/decorators/Component.ts"],"sourcesContent":["// framework/decorators/Component.ts\nimport 'reflect-metadata';\nimport { COMPONENT_OPTIONS_METADATA_KEY } from './metadataKeys.cjs';\nimport { LoadAs } from '../implementation/LoadAs.cjs';\n\nexport interface ComponentOptions {\n scope?: LoadAs;\n}\n\n/**\n * Marks a class as a component managed by the IOC container.\n * @param options Configuration options, primarily the scope (lifetime). Defaults to Transient.\n */\nexport function Component(options: ComponentOptions = {}): ClassDecorator {\n return (target: Function) => {\n // Ensure default scope if not provided\n const finalOptions: Required<ComponentOptions> = {\n scope: options.scope ?? LoadAs.Transient, // Default to Transient\n };\n \n // Define metadata on the class constructor - use both Symbol and string versions\n Reflect.defineMetadata(COMPONENT_OPTIONS_METADATA_KEY, finalOptions, target);\n \n // Also define with string key for easier debugging\n Reflect.defineMetadata('ComponentOptions', finalOptions, target);\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,8BAAO;AACP,0BAA+C;AAC/C,oBAAuB;AAUhB,SAAS,UAAU,UAA4B,CAAC,GAAmB;AACtE,SAAO,CAAC,WAAqB;AAEzB,UAAM,eAA2C;AAAA,MAC7C,OAAO,QAAQ,SAAS,qBAAO;AAAA;AAAA,IACnC;AAGA,YAAQ,eAAe,oDAAgC,cAAc,MAAM;AAG3E,YAAQ,eAAe,oBAAoB,cAAc,MAAM;AAAA,EACnE;AACJ;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../framework/decorators/Component.ts"],"sourcesContent":["// framework/decorators/Component.ts\nimport 'reflect-metadata';\nimport { COMPONENT_OPTIONS_METADATA_KEY } from './metadataKeys';\nimport { LoadAs } from '../implementation/LoadAs';\n\nexport interface ComponentOptions {\n scope?: LoadAs;\n}\n\n/**\n * Marks a class as a component managed by the IOC container.\n * @param options Configuration options, primarily the scope (lifetime). Defaults to Transient.\n */\nexport function Component(options: ComponentOptions = {}): ClassDecorator {\n return (target: Function) => {\n // Ensure default scope if not provided\n const finalOptions: Required<ComponentOptions> = {\n scope: options.scope ?? LoadAs.Transient, // Default to Transient\n };\n \n // Define metadata on the class constructor - use both Symbol and string versions\n Reflect.defineMetadata(COMPONENT_OPTIONS_METADATA_KEY, finalOptions, target);\n \n // Also define with string key for easier debugging\n Reflect.defineMetadata('ComponentOptions', finalOptions, target);\n };\n}\n"],"mappings":"AACA,OAAO;AACP,SAAS,sCAAsC;AAC/C,SAAS,cAAc;AAUhB,SAAS,UAAU,UAA4B,CAAC,GAAmB;AACtE,SAAO,CAAC,WAAqB;AAEzB,UAAM,eAA2C;AAAA,MAC7C,OAAO,QAAQ,SAAS,OAAO;AAAA;AAAA,IACnC;AAGA,YAAQ,eAAe,gCAAgC,cAAc,MAAM;AAG3E,YAAQ,eAAe,oBAAoB,cAAc,MAAM;AAAA,EACnE;AACJ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../framework/decorators/Component.ts"],"sourcesContent":["// framework/decorators/Component.ts\nimport 'reflect-metadata';\nimport { COMPONENT_OPTIONS_METADATA_KEY } from './metadataKeys.js';\nimport { LoadAs } from '../implementation/LoadAs.js';\n\nexport interface ComponentOptions {\n scope?: LoadAs;\n}\n\n/**\n * Marks a class as a component managed by the IOC container.\n * @param options Configuration options, primarily the scope (lifetime). Defaults to Transient.\n */\nexport function Component(options: ComponentOptions = {}): ClassDecorator {\n return (target: Function) => {\n // Ensure default scope if not provided\n const finalOptions: Required<ComponentOptions> = {\n scope: options.scope ?? LoadAs.Transient, // Default to Transient\n };\n \n // Define metadata on the class constructor - use both Symbol and string versions\n Reflect.defineMetadata(COMPONENT_OPTIONS_METADATA_KEY, finalOptions, target);\n \n // Also define with string key for easier debugging\n Reflect.defineMetadata('ComponentOptions', finalOptions, target);\n };\n}\n"],"mappings":"AACA,OAAO;AACP,SAAS,sCAAsC;AAC/C,SAAS,cAAc;AAUhB,SAAS,UAAU,UAA4B,CAAC,GAAmB;AACtE,SAAO,CAAC,WAAqB;AAEzB,UAAM,eAA2C;AAAA,MAC7C,OAAO,QAAQ,SAAS,OAAO;AAAA;AAAA,IACnC;AAGA,YAAQ,eAAe,gCAAgC,cAAc,MAAM;AAG3E,YAAQ,eAAe,oBAAoB,cAAc,MAAM;AAAA,EACnE;AACJ;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../framework/decorators/Inject.ts"],"sourcesContent":["// framework/decorators/Inject.ts\nimport 'reflect-metadata';\nimport { INJECT_TOKEN_METADATA_KEY } from './metadataKeys';\n\n/**\n * Decorator to explicitly specify the token/identifier for a constructor parameter dependency.\n * Necessary for interfaces or when multiple implementations exist for a type.\n * @param token The identifier (Symbol, string, or class) to inject.\n */\nexport function Inject(token: any): ParameterDecorator {\n return (target: Object, propertyKey: string | symbol | undefined, parameterIndex: number) => {\n // Get existing injection tokens array or initialize if not present\n const injectionTokens: Map<number, any> = Reflect.getOwnMetadata(INJECT_TOKEN_METADATA_KEY, target) || new Map<number, any>();\n\n // Store the token at the specific parameter index\n injectionTokens.set(parameterIndex, token);\n\n // Define the metadata on the target (class constructor)\n Reflect.defineMetadata(INJECT_TOKEN_METADATA_KEY, injectionTokens, target);\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,8BAAO;AACP,0BAA0C;AAOnC,SAAS,OAAO,OAAgC;AACnD,SAAO,CAAC,QAAgB,aAA0C,mBAA2B;AAEzF,UAAM,kBAAoC,QAAQ,eAAe,+CAA2B,MAAM,KAAK,oBAAI,IAAiB;AAG5H,oBAAgB,IAAI,gBAAgB,KAAK;AAGzC,YAAQ,eAAe,+CAA2B,iBAAiB,MAAM;AAAA,EAC7E;AACJ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../framework/decorators/Inject.ts"],"sourcesContent":["// framework/decorators/Inject.ts\nimport 'reflect-metadata';\nimport { INJECT_TOKEN_METADATA_KEY } from './metadataKeys.cjs';\n\n/**\n * Decorator to explicitly specify the token/identifier for a constructor parameter dependency.\n * Necessary for interfaces or when multiple implementations exist for a type.\n * @param token The identifier (Symbol, string, or class) to inject.\n */\nexport function Inject(token: any): ParameterDecorator {\n return (target: Object, propertyKey: string | symbol | undefined, parameterIndex: number) => {\n // Get existing injection tokens array or initialize if not present\n const injectionTokens: Map<number, any> = Reflect.getOwnMetadata(INJECT_TOKEN_METADATA_KEY, target) || new Map<number, any>();\n\n // Store the token at the specific parameter index\n injectionTokens.set(parameterIndex, token);\n\n // Define the metadata on the target (class constructor)\n Reflect.defineMetadata(INJECT_TOKEN_METADATA_KEY, injectionTokens, target);\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,8BAAO;AACP,0BAA0C;AAOnC,SAAS,OAAO,OAAgC;AACnD,SAAO,CAAC,QAAgB,aAA0C,mBAA2B;AAEzF,UAAM,kBAAoC,QAAQ,eAAe,+CAA2B,MAAM,KAAK,oBAAI,IAAiB;AAG5H,oBAAgB,IAAI,gBAAgB,KAAK;AAGzC,YAAQ,eAAe,+CAA2B,iBAAiB,MAAM;AAAA,EAC7E;AACJ;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../framework/decorators/Inject.ts"],"sourcesContent":["// framework/decorators/Inject.ts\nimport 'reflect-metadata';\nimport { INJECT_TOKEN_METADATA_KEY } from './metadataKeys';\n\n/**\n * Decorator to explicitly specify the token/identifier for a constructor parameter dependency.\n * Necessary for interfaces or when multiple implementations exist for a type.\n * @param token The identifier (Symbol, string, or class) to inject.\n */\nexport function Inject(token: any): ParameterDecorator {\n return (target: Object, propertyKey: string | symbol | undefined, parameterIndex: number) => {\n // Get existing injection tokens array or initialize if not present\n const injectionTokens: Map<number, any> = Reflect.getOwnMetadata(INJECT_TOKEN_METADATA_KEY, target) || new Map<number, any>();\n\n // Store the token at the specific parameter index\n injectionTokens.set(parameterIndex, token);\n\n // Define the metadata on the target (class constructor)\n Reflect.defineMetadata(INJECT_TOKEN_METADATA_KEY, injectionTokens, target);\n };\n}\n"],"mappings":"AACA,OAAO;AACP,SAAS,iCAAiC;AAOnC,SAAS,OAAO,OAAgC;AACnD,SAAO,CAAC,QAAgB,aAA0C,mBAA2B;AAEzF,UAAM,kBAAoC,QAAQ,eAAe,2BAA2B,MAAM,KAAK,oBAAI,IAAiB;AAG5H,oBAAgB,IAAI,gBAAgB,KAAK;AAGzC,YAAQ,eAAe,2BAA2B,iBAAiB,MAAM;AAAA,EAC7E;AACJ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../framework/decorators/Inject.ts"],"sourcesContent":["// framework/decorators/Inject.ts\nimport 'reflect-metadata';\nimport { INJECT_TOKEN_METADATA_KEY } from './metadataKeys.js';\n\n/**\n * Decorator to explicitly specify the token/identifier for a constructor parameter dependency.\n * Necessary for interfaces or when multiple implementations exist for a type.\n * @param token The identifier (Symbol, string, or class) to inject.\n */\nexport function Inject(token: any): ParameterDecorator {\n return (target: Object, propertyKey: string | symbol | undefined, parameterIndex: number) => {\n // Get existing injection tokens array or initialize if not present\n const injectionTokens: Map<number, any> = Reflect.getOwnMetadata(INJECT_TOKEN_METADATA_KEY, target) || new Map<number, any>();\n\n // Store the token at the specific parameter index\n injectionTokens.set(parameterIndex, token);\n\n // Define the metadata on the target (class constructor)\n Reflect.defineMetadata(INJECT_TOKEN_METADATA_KEY, injectionTokens, target);\n };\n}\n"],"mappings":"AACA,OAAO;AACP,SAAS,iCAAiC;AAOnC,SAAS,OAAO,OAAgC;AACnD,SAAO,CAAC,QAAgB,aAA0C,mBAA2B;AAEzF,UAAM,kBAAoC,QAAQ,eAAe,2BAA2B,MAAM,KAAK,oBAAI,IAAiB;AAG5H,oBAAgB,IAAI,gBAAgB,KAAK;AAGzC,YAAQ,eAAe,2BAA2B,iBAAiB,MAAM;AAAA,EAC7E;AACJ;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../framework/decorators/index.ts"],"sourcesContent":["// Export decorators\nexport { Component } from './Component';\nexport { Inject } from './Inject';\nexport * from './metadataKeys';\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAA0B;AAC1B,oBAAuB;AACvB,+BAAc
|
|
1
|
+
{"version":3,"sources":["../../../framework/decorators/index.ts"],"sourcesContent":["// Export decorators\nexport { Component } from './Component.cjs';\nexport { Inject } from './Inject.cjs';\nexport * from './metadataKeys.cjs';\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAA0B;AAC1B,oBAAuB;AACvB,+BAAc,+BAHd;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../framework/decorators/index.ts"],"sourcesContent":["// Export decorators\nexport { Component } from './Component';\nexport { Inject } from './Inject';\nexport * from './metadataKeys';\n"],"mappings":"AACA,SAAS,iBAAiB;AAC1B,SAAS,cAAc;AACvB,cAAc;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../framework/decorators/index.ts"],"sourcesContent":["// Export decorators\nexport { Component } from './Component.js';\nexport { Inject } from './Inject.js';\nexport * from './metadataKeys.js';\n"],"mappings":"AACA,SAAS,iBAAiB;AAC1B,SAAS,cAAc;AACvB,cAAc;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../framework/implementation/Container.ts"],"sourcesContent":["import 'reflect-metadata'; // Ensure polyfill is loaded conceptually\nimport type { ContainerOptions, IContainerClient, IContainerFunctionDefinition, IContainerSetup } from \"../interface/Container\";\nimport { LoadAs } from \"./LoadAs\";\nimport { Parameter } from \"./Parameter\";\nimport type { ParameterValue } from \"./Parameter\";\nimport { NotAClassDefinitionError, ParameterNotFoundError, DependencyNotFoundError, InstanceNotCreatedError, CircularDependencyError } from \"../errors/ContainerErrors\";\nimport {\n getScope,\n getComponentOptions, // Use helper\n getResolvedDependencies // Use helper\n} from './DecoratorSupport'; // Assume helpers exist or create them\n\nenum ContainerRouting {\n FUNCTIONAL = \"FUNCTIONAL\",\n CLASS = \"CLASS\"\n // No need for COMPONENT route, just check metadata if CLASS/FUNCTIONAL fails\n}\n\ntype StorageType = 'singleton' | 'scoped' | 'transient';\n\nexport class Container implements IContainerClient, IContainerSetup {\n // Routing and definition maps\n private _routing: Map<any, ContainerRouting> = new Map();\n private _functionDefinition: Map<any, IContainerFunctionDefinition> = new Map();\n private _classDefinition: Map<Function, Partial<ContainerOptions>> = new Map();\n\n // Storage maps\n private _functionStorageSingleton: Map<any, any> = new Map();\n private _functionStorageScoped: Map<any, any> = new Map();\n private _classStorageSingleton: Map<Function, any> = new Map();\n private _classStorageScoped: Map<Function, any> = new Map();\n\n // Registration methods\n registerClass<T>(classDefinition: new (...args: any[]) => T, options?: Partial<ContainerOptions>): void {\n // Basic validation\n if (typeof classDefinition !== 'function' || !classDefinition.prototype) {\n console.warn(`[IOC] Attempted to register non-class: ${String(classDefinition)}`);\n // Optional: throw error instead?\n // throw new NotAClassDefinitionError(`Attempted to register non-class: ${String(classDefinition)}`);\n return; // Don't proceed if not a class constructor\n }\n\n // Always clear previous definitions for this exact class constructor\n this.clearDefinitions(classDefinition);\n\n // Always set the routing type so 'isClassDefinition' works\n this._routing.set(classDefinition, ContainerRouting.CLASS);\n\n // Store manual options *only if they are actually provided and have content*\n if (options && Object.keys(options).length > 0) {\n this._classDefinition.set(classDefinition, options);\n // console.log(`[IOC RegClass] Manually registered ${classDefinition.name} with options:`, options);\n } else {\n // console.log(`[IOC RegClass] Manually registered ${classDefinition.name} with no specific options (will use decorators if present).`);\n // If no options are provided, we don't store anything in _classDefinition,\n // effectively clearing any previous manual config and letting decorators take over if present.\n }\n }\n\n registerFunction<T extends (...arg: any[]) => any>(label: any, func: T, options: Partial<ContainerOptions> = {} as any): void {\n this.clearDefinitions(label);\n this._routing.set(label, ContainerRouting.FUNCTIONAL);\n this._functionDefinition.set(label, { function: func, options });\n // console.log(`[IOC RegFunc] Registered function with label ${String(label)} and options:`, options);\n }\n\n // Instance resolution methods - Simplify to just call loadInstance\n instance<T, Args extends any[]>(classDefinition: new (...args: Args) => T, params: ParameterValue<any>[] = []): Promise<T> {\n // Basic check upfront\n if (typeof classDefinition !== 'function' || !classDefinition.prototype) {\n throw new NotAClassDefinitionError(`Cannot resolve instance for non-class: ${String(classDefinition)}`);\n }\n return this.loadInstance(classDefinition, params) as Promise<T>;\n }\n\n get<T>(label: any, param: ParameterValue<any>[] = []): Promise<T> | T {\n // Just delegate to loadInstance, which handles routing and auto-registration\n return this.loadInstance(label, param);\n }\n\n extend(): IContainerClient & IContainerSetup {\n const childContainer = createContainer() as Container;\n\n // Copy routing and definition maps (share the registration knowledge)\n childContainer._routing = new Map(this._routing);\n childContainer._functionDefinition = new Map(this._functionDefinition);\n childContainer._classDefinition = new Map(this._classDefinition);\n\n // Share singleton storage (singletons are shared across all containers)\n childContainer._functionStorageSingleton = this._functionStorageSingleton;\n childContainer._classStorageSingleton = this._classStorageSingleton;\n\n // Do NOT share scoped storage (new container = new scope)\n // Child gets its own empty scoped storage\n\n // console.log('[IOC Extend] Created child container.');\n return childContainer;\n }\n\n // Private helper methods\n private clearDefinitions(label: any): void {\n this._routing.delete(label);\n this._functionDefinition.delete(label);\n // Only delete from classDefinition if the label is actually a function constructor\n if (typeof label === 'function') {\n this._classDefinition.delete(label);\n }\n }\n\n // Checks if the label is *currently* registered as a class\n private isRegisteredAsClass(label: any): boolean {\n return this._routing.get(label) === ContainerRouting.CLASS;\n }\n\n // Checks if the label is *currently* registered as a function\n private isRegisteredAsFunction(label: any): boolean {\n return this._routing.get(label) === ContainerRouting.FUNCTIONAL;\n }\n\n\n private hasInstance(label: any): boolean {\n const storageType = this.getStorageType(label); // This checks decorators if needed\n\n if (!storageType) {\n // Transient instances are never stored\n return false;\n }\n\n // Determine if it's treated as a class (registered or decorated) *after* getting type\n const isClass = this.isClassType(label); // Use a helper that checks routing OR decorator\n\n if (isClass) {\n return storageType === 'singleton'\n ? this._classStorageSingleton.has(label)\n : this._classStorageScoped.has(label);\n } else { // Must be a function if not a class\n return storageType === 'singleton'\n ? this._functionStorageSingleton.has(label)\n : this._functionStorageScoped.has(label);\n }\n }\n\n // Helper to determine if something should be treated as a class (registered or decorated)\n private isClassType(label: any): boolean {\n if (this.isRegisteredAsClass(label)) {\n return true;\n }\n // If not explicitly registered as a class, check if it's a function with @Component\n if (typeof label === 'function' && label.prototype && !this.isRegisteredAsFunction(label)) {\n return getComponentOptions(label) !== null;\n }\n return false;\n }\n\n private getInstance(label: any): any {\n const storageType = this.getStorageType(label); // Checks decorators if needed\n\n if (!storageType) {\n // This should ideally not be reached if called after hasInstance check\n console.error(`[IOC GetInstance] Attempted to get instance for non-stored type: ${String(label)}`);\n throw new InstanceNotCreatedError();\n }\n\n const isClass = this.isClassType(label); // Check routing OR decorator\n\n if (isClass) {\n return storageType === 'singleton'\n ? this._classStorageSingleton.get(label)\n : this._classStorageScoped.get(label);\n } else { // Must be a function\n return storageType === 'singleton'\n ? this._functionStorageSingleton.get(label)\n : this._functionStorageScoped.get(label);\n }\n }\n\n private setInstance(label: any, instance: any, storageType?: StorageType): void { // Made storageType non-optional\n const isClass = this.isClassType(label); // Determine type based on routing OR decorator\n\n if (isClass) {\n if (storageType === 'singleton') {\n this._classStorageSingleton.set(label, instance);\n } else if (storageType == 'scoped'){ // storageType === 'scoped'\n this._classStorageScoped.set(label, instance);\n }\n } else { // Must be a function\n if (storageType === 'singleton') {\n this._functionStorageSingleton.set(label, instance);\n } else if(storageType === \"scoped\"){ // storageType === 'scoped'\n this._functionStorageScoped.set(label, instance);\n }\n }\n }\n\n private getStorageType(label: any): StorageType {\n let manualLoadAs: LoadAs | undefined;\n let decoratorScope: LoadAs | undefined;\n const isPotentialClass = typeof label === 'function' && label.prototype;\n\n // Get manual registration options if available\n if (this.isRegisteredAsClass(label)) { // Use helper\n manualLoadAs = this._classDefinition.get(label)?.loadAs;\n } else if (this.isRegisteredAsFunction(label)) { // Use helper\n manualLoadAs = this._functionDefinition.get(label)?.options?.loadAs;\n }\n\n // Get decorator scope only if it's potentially a class *and not explicitly registered as a function*\n if (isPotentialClass && !this.isRegisteredAsFunction(label)) {\n decoratorScope = getScope(label); // Uses getComponentOptions internally\n }\n\n // Determine final scope: Manual > Decorator > Default (Transient)\n const finalScope = manualLoadAs ?? decoratorScope ?? LoadAs.Transient;\n\n if (finalScope === LoadAs.Singleton) {\n return 'singleton';\n } else if (finalScope === LoadAs.Scoped) {\n return 'scoped';\n }else{\n return 'transient'; // Transient\n }\n }\n\n // Central resolution logic\n protected async loadInstance(\n label: any,\n params: ParameterValue<any>[] = [],\n resolutionChain: string[] = [] // Track resolution path\n ): Promise<any> {\n\n // --- Circular Dependency Check ---\n const currentLabelStr = (typeof label === 'function' && label.name) ? label.name : String(label);\n if (resolutionChain.includes(currentLabelStr)) {\n console.error(`[IOC LoadInstance] Circular dependency detected: ${[...resolutionChain, currentLabelStr].join(' -> ')}`);\n throw new CircularDependencyError([...resolutionChain, currentLabelStr]);\n }\n const nextResolutionChain = [...resolutionChain, currentLabelStr];\n // --- End Circular Dependency Check ---\n\n // --- Handle Parameters ---\n if (label instanceof Parameter) {\n try {\n // Pass a *copy* of params to avoid side effects in resolveParameterValue\n return Promise.resolve(this.resolveParameterValue(label, [...params]));\n } catch (e) {\n // console.error(`[IOC LoadInstance] Error resolving parameter ${param.toString()}:`, e);\n return Promise.reject(e);\n }\n }\n // --- End Handle Parameters ---\n\n\n // --- Check Explicit Registrations ---\n if (this.isRegisteredAsClass(label)) {\n // console.log(`[IOC LoadInstance] Resolving explicitly registered class: ${currentLabelStr}`);\n return this.loadClassInstance(label, params, nextResolutionChain);\n }\n if (this.isRegisteredAsFunction(label)) {\n // console.log(`[IOC LoadInstance] Resolving explicitly registered function: ${currentLabelStr}`);\n return this.loadFunctionInstance(label, params, nextResolutionChain);\n }\n // --- End Check Explicit Registrations ---\n\n\n // --- Attempt Auto-Registration/Resolution for Decorated Classes ---\n if (typeof label === 'function' && label.prototype) {\n const componentOptions = getComponentOptions(label); // Check for @Component\n if (componentOptions !== null) {\n // console.log(`[IOC LoadInstance] Auto-resolving @Component class: ${currentLabelStr}`);\n // Set routing *now* so subsequent internal checks work correctly\n if (!this._routing.has(label)) { // Only set if not already set\n this._routing.set(label, ContainerRouting.CLASS);\n // console.log(`[IOC LoadInstance] Set routing for auto-resolved class: ${currentLabelStr}`);\n }\n // Proceed to load it as a class\n return this.loadClassInstance(label, params, nextResolutionChain);\n }\n }\n // --- End Auto-Registration ---\n\n\n // --- Dependency Not Found ---\n console.error(`[IOC LoadInstance] Dependency not found and cannot be resolved: ${currentLabelStr}`);\n throw new DependencyNotFoundError(currentLabelStr);\n }\n\n\n private resolveParameterValue(param: Parameter, params: ParameterValue<any>[]): any { // No mutation\n // Find the *last* provided value for the parameter\n const valueContainer = [...params].reverse().find((p) => p.belongsTo(param));\n if (!valueContainer) {\n // console.error(`[IOC ResolveParam] Parameter not found: ${param.toString()}`);\n throw new ParameterNotFoundError(param.toString());\n }\n // console.log(`[IOC ResolveParam] Resolved parameter ${param.toString()}`);\n return valueContainer.value;\n }\n\n private loadClassInstance(\n classDefinition: any, // Should be a class constructor here\n params: ParameterValue<any>[],\n resolutionChain: string[]\n ): Promise<any> {\n const storageType = this.getStorageType(classDefinition);\n const className = classDefinition.name || '[Anonymous Class]';\n\n // Check storage first (handle stored promises)\n if (storageType && this.hasInstance(classDefinition)) {\n const instance = this.getInstance(classDefinition);\n // console.log(`[IOC LoadClass] Found existing ${storageType} instance for ${className}. IsPromise: ${isPromise(instance)}`);\n return instance\n }\n // console.log(`[IOC LoadClass] Creating new ${storageType || 'transient'} instance for ${className}`);\n\n // --- Determine Dependencies ---\n const manualOptions = this._classDefinition.get(classDefinition) as ContainerOptions | undefined;\n let dependenciesToResolve: any[];\n\n if (manualOptions?.param && Array.isArray(manualOptions.param)) {\n dependenciesToResolve = manualOptions.param;\n // console.log(`[IOC LoadClass] Using manual dependencies for ${className}`);\n } else {\n // Use decorator-derived dependencies\n dependenciesToResolve = getResolvedDependencies(classDefinition);\n // console.log(`[IOC LoadClass] Using decorator/reflected dependencies for ${className}:`, dependenciesToResolve.map(d => typeof d === 'function' ? d.name : String(d)));\n }\n // --- End Determine Dependencies ---\n\n\n // --- Resolve Dependencies ---\n // Create a *copy* of params to pass down for dependency resolution\n const paramsCopy = [...params];\n const resolutionPromises = dependenciesToResolve.map(dependencyIdentifier =>\n this.loadInstance(dependencyIdentifier, paramsCopy, resolutionChain) // Recursive call handles auto-registration\n );\n\n let finalInstance = Promise.all(resolutionPromises)\n .catch((error)=>{\n console.error(`[IOC LoadClass] Failed to resolve one or more dependencies for ${className}:`, error);\n // Clean up potential partially stored promise if this was going to be singleton/scoped\n if (storageType && this.isRegisteredAsClass(classDefinition)) { // Check if it was actually *being* stored\n if (storageType === 'singleton') this._classStorageSingleton.delete(classDefinition);\n if (storageType === 'scoped') this._classStorageScoped.delete(classDefinition);\n }\n throw error; // Re-throw dependency resolution error\n }).then(async(resolvedDependencies)=>{\n // --- Instantiate Class ---\n // Store the promise *before* starting instantiation for concurrent requests\n let instancePromise: Promise<any> | undefined;\n if (storageType && !this.hasInstance(classDefinition)) { // Check again in case of race condition?\n // Create the promise wrapper immediately\n instancePromise = (async () => {\n try {\n // console.log(`[IOC LoadClass] Instantiating ${className} with ${resolvedDependencies.length} args.`);\n const instance = new classDefinition(...resolvedDependencies);\n // Overwrite the stored promise with the actual instance *after* it's created\n this.setInstance(classDefinition, instance, storageType); // Use the correct storageType\n // console.log(`[IOC LoadClass] Stored actual ${storageType} instance for ${className}`);\n return instance;\n } catch (err: any) {\n console.error(`[IOC LoadClass] Error during instantiation of ${className}: ${err.message}`, err.stack);\n // Clean up the stored promise on failure\n if (storageType === 'singleton') this._classStorageSingleton.delete(classDefinition);\n if (storageType === 'scoped') this._classStorageScoped.delete(classDefinition);\n throw err; // Re-throw instantiation error\n }\n })();\n // console.log(`[IOC LoadClass] Storing promise for concurrent requests (${storageType}) for ${className}`);\n this.setInstance(classDefinition, instancePromise, storageType);\n } else {\n // If already has instance (from storage check) or is transient, just instantiate directly\n instancePromise = (async () => {\n try {\n // console.log(`[IOC LoadClass] Instantiating transient ${className} with ${resolvedDependencies.length} args.`);\n const instance = new classDefinition(...resolvedDependencies);\n // No storing for transient\n return instance;\n } catch (err: any) {\n console.error(`[IOC LoadClass] Error during instantiation of transient ${className}: ${err.message}`, err.stack);\n throw err; // Re-throw instantiation error\n }\n })();\n }\n // --- End Instantiate Class ---\n // Await and return the final instance (either newly created or from the stored promise)\n return await instancePromise;\n });\n\n if(storageType && storageType !== 'transient'){\n this.setInstance(classDefinition, finalInstance, storageType); // Store the promise\n }\n return finalInstance\n }\n\n private loadFunctionInstance(\n funcLabel: any,\n params: ParameterValue<any>[],\n resolutionChain: string[]\n ): Promise<any> { // Always return Promise<any> since this is an async function\n const functionConfig = this._functionDefinition.get(funcLabel)!; // Assumed to exist by caller\n const storageType = this.getStorageType(funcLabel); // Only uses manual options for functions\n const labelStr = String(funcLabel);\n\n // Check storage first\n if (storageType && this.hasInstance(funcLabel)) {\n const instance = this.getInstance(funcLabel);\n // console.log(`[IOC LoadFunc] Found existing ${storageType} instance for ${labelStr}. IsPromise: ${isPromise(instance)}`);\n return instance;\n }\n // console.log(`[IOC LoadFunc] Creating new ${storageType || 'transient'} instance for ${labelStr}`);\n\n const ioc_func = functionConfig.function;\n const options = functionConfig.options;\n const dependenciesToResolve: any[] = options?.param || [];\n\n // --- Resolve Dependencies ---\n const paramsCopy = [...params]; // Create a copy\n const resolutionPromises = dependenciesToResolve.map(dependencyIdentifier =>\n this.loadInstance(dependencyIdentifier, paramsCopy, resolutionChain)\n );\n\n let finalInstance = Promise.all(resolutionPromises).catch((error)=>{\n console.error(`[IOC LoadFunc] Failed to resolve dependencies for function ${labelStr}:`, error);\n // Clean up potential partial storage\n if (storageType && this.isRegisteredAsFunction(funcLabel)) {\n if (storageType === 'singleton') this._functionStorageSingleton.delete(funcLabel);\n if (storageType === 'scoped') this._functionStorageScoped.delete(funcLabel);\n }\n throw error;\n }).then(async(resolvedArgs)=>{\n let instancePromise: Promise<any> | undefined;\n if (storageType && !this.hasInstance(funcLabel)) {\n instancePromise = (async () => {\n try {\n // console.log(`[IOC LoadFunc] Invoking ${labelStr} with ${resolvedArgs.length} args.`);\n const result = await ioc_func.apply(null, resolvedArgs); // Await in case function is async\n // Overwrite stored promise with actual result\n this.setInstance(funcLabel, result, storageType);\n // console.log(`[IOC LoadFunc] Stored actual ${storageType} instance for ${labelStr}`);\n return result;\n } catch (err: any) {\n console.error(`[IOC LoadFunc] Error executing function ${labelStr}: ${err.message}`, err.stack);\n // Clean up stored promise on failure\n if (storageType === 'singleton') this._functionStorageSingleton.delete(funcLabel);\n if (storageType === 'scoped') this._functionStorageScoped.delete(funcLabel);\n throw err;\n }\n })();\n // console.log(`[IOC LoadFunc] Storing promise for concurrent requests (${storageType}) for ${labelStr}`);\n this.setInstance(funcLabel, instancePromise, storageType);\n } else {\n // Transient or already resolved from storage check\n instancePromise = (async () => {\n try {\n // console.log(`[IOC LoadFunc] Invoking transient ${labelStr} with ${resolvedArgs.length} args.`);\n const result = await ioc_func.apply(null, resolvedArgs); // Await in case function is async\n // No storing for transient\n return result;\n } catch (err: any) {\n console.error(`[IOC LoadFunc] Error executing transient function ${labelStr}: ${err.message}`, err.stack);\n throw err;\n }\n })();\n }\n // --- End Invoke Function ---\n\n return await instancePromise; // Return the final (awaited) result\n });\n\n if(storageType && storageType !== 'transient'){\n this.setInstance(funcLabel, finalInstance, storageType); // Store the promise\n }\n\n return finalInstance;\n }\n}\n\n// Helper functions\nexport function isPromise(obj: any): obj is Promise<any> {\n // Simplified check - more robust check might be needed depending on environment\n return !!obj && typeof obj.then === 'function';\n}\n\nexport function createContainer(): IContainerClient & IContainerSetup {\n return new Container();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAAO;AAEP,oBAAuB;AACvB,uBAA0B;AAE1B,6BAA4I;AAC5I,8BAIO;AAEP,IAAK,mBAAL,kBAAKA,sBAAL;AACI,EAAAA,kBAAA,gBAAa;AACb,EAAAA,kBAAA,WAAQ;AAFP,SAAAA;AAAA,GAAA;AAQE,MAAM,UAAuD;AAAA,EAA7D;AAEH;AAAA,SAAQ,WAAuC,oBAAI,IAAI;AACvD,SAAQ,sBAA8D,oBAAI,IAAI;AAC9E,SAAQ,mBAA6D,oBAAI,IAAI;AAG7E;AAAA,SAAQ,4BAA2C,oBAAI,IAAI;AAC3D,SAAQ,yBAAwC,oBAAI,IAAI;AACxD,SAAQ,yBAA6C,oBAAI,IAAI;AAC7D,SAAQ,sBAA0C,oBAAI,IAAI;AAAA;AAAA;AAAA,EAG1D,cAAiB,iBAA4C,SAA2C;AAEpG,QAAI,OAAO,oBAAoB,cAAc,CAAC,gBAAgB,WAAW;AACpE,cAAQ,KAAK,0CAA0C,OAAO,eAAe,CAAC,EAAE;AAGhF;AAAA,IACL;AAGA,SAAK,iBAAiB,eAAe;AAGrC,SAAK,SAAS,IAAI,iBAAiB,mBAAsB;AAGzD,QAAI,WAAW,OAAO,KAAK,OAAO,EAAE,SAAS,GAAG;AAC5C,WAAK,iBAAiB,IAAI,iBAAiB,OAAO;AAAA,IAEtD,OAAO;AAAA,IAIP;AAAA,EACJ;AAAA,EAEA,iBAAmD,OAAY,MAAS,UAAqC,CAAC,GAAgB;AAC1H,SAAK,iBAAiB,KAAK;AAC3B,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,IAAI,KAAK;AAE9F,gBAAI,gBAAgB,YAAa,MAAK,0BAA0B,OAAO,SAAS;AAChF,gBAAI,gBAAgB,SAAU,MAAK,uBAAuB,OAAO,SAAS;AAC1E,kBAAM;AAAA,UACV;AAAA,QACJ,GAAG;AAEH,aAAK,YAAY,WAAW,iBAAiB,WAAW;AAAA,MAC7D,OAAO;AAEF,2BAAmB,YAAY;AAC1B,cAAI;AAEA,kBAAM,SAAS,MAAM,SAAS,MAAM,MAAM,YAAY;AAEtD,mBAAO;AAAA,UACX,SAAS,KAAU;AACf,oBAAQ,MAAM,qDAAqD,QAAQ,KAAK,IAAI,OAAO,IAAI,IAAI,KAAK;AACxG,kBAAM;AAAA,UACV;AAAA,QACL,GAAG;AAAA,MACR;AAGA,aAAO,MAAM;AAAA,IACb,CAAC;AAED,QAAG,eAAe,gBAAgB,aAAY;AAC1C,WAAK,YAAY,WAAW,eAAe,WAAW;AAAA,IAC1D;AAEA,WAAO;AAAA,EACX;AACJ;AAGO,SAAS,UAAU,KAA+B;AAErD,SAAO,CAAC,CAAC,OAAO,OAAO,IAAI,SAAS;AACxC;AAEO,SAAS,kBAAsD;AAClE,SAAO,IAAI,UAAU;AACzB;","names":["ContainerRouting"]}
|
|
1
|
+
{"version":3,"sources":["../../../framework/implementation/Container.ts"],"sourcesContent":["import 'reflect-metadata'; // Ensure polyfill is loaded conceptually\nimport type { ContainerOptions, IContainerClient, IContainerFunctionDefinition, IContainerSetup } from \"../interface/Container.cjs\";\nimport { LoadAs } from \"./LoadAs.cjs\";\nimport { Parameter } from \"./Parameter.cjs\";\nimport type { ParameterValue } from \"./Parameter.cjs\";\nimport { NotAClassDefinitionError, ParameterNotFoundError, DependencyNotFoundError, InstanceNotCreatedError, CircularDependencyError } from \"../errors/ContainerErrors.cjs\";\nimport {\n getScope,\n getComponentOptions, // Use helper\n getResolvedDependencies // Use helper\n} from './DecoratorSupport'; // Assume helpers exist or create them\n\nenum ContainerRouting {\n FUNCTIONAL = \"FUNCTIONAL\",\n CLASS = \"CLASS\"\n // No need for COMPONENT route, just check metadata if CLASS/FUNCTIONAL fails\n}\n\ntype StorageType = 'singleton' | 'scoped' | 'transient';\n\nexport class Container implements IContainerClient, IContainerSetup {\n // Routing and definition maps\n private _routing: Map<any, ContainerRouting> = new Map();\n private _functionDefinition: Map<any, IContainerFunctionDefinition> = new Map();\n private _classDefinition: Map<Function, Partial<ContainerOptions>> = new Map();\n\n // Storage maps\n private _functionStorageSingleton: Map<any, any> = new Map();\n private _functionStorageScoped: Map<any, any> = new Map();\n private _classStorageSingleton: Map<Function, any> = new Map();\n private _classStorageScoped: Map<Function, any> = new Map();\n\n // Registration methods\n registerClass<T>(classDefinition: new (...args: any[]) => T, options?: Partial<ContainerOptions>): void {\n // Basic validation\n if (typeof classDefinition !== 'function' || !classDefinition.prototype) {\n console.warn(`[IOC] Attempted to register non-class: ${String(classDefinition)}`);\n // Optional: throw error instead?\n // throw new NotAClassDefinitionError(`Attempted to register non-class: ${String(classDefinition)}`);\n return; // Don't proceed if not a class constructor\n }\n\n // Always clear previous definitions for this exact class constructor\n this.clearDefinitions(classDefinition);\n\n // Always set the routing type so 'isClassDefinition' works\n this._routing.set(classDefinition, ContainerRouting.CLASS);\n\n // Store manual options *only if they are actually provided and have content*\n if (options && Object.keys(options).length > 0) {\n this._classDefinition.set(classDefinition, options);\n // console.log(`[IOC RegClass] Manually registered ${classDefinition.name} with options:`, options);\n } else {\n // console.log(`[IOC RegClass] Manually registered ${classDefinition.name} with no specific options (will use decorators if present).`);\n // If no options are provided, we don't store anything in _classDefinition,\n // effectively clearing any previous manual config and letting decorators take over if present.\n }\n }\n\n registerFunction<T extends (...arg: any[]) => any>(label: any, func: T, options: Partial<ContainerOptions> = {} as any): void {\n this.clearDefinitions(label);\n this._routing.set(label, ContainerRouting.FUNCTIONAL);\n this._functionDefinition.set(label, { function: func, options });\n // console.log(`[IOC RegFunc] Registered function with label ${String(label)} and options:`, options);\n }\n\n // Instance resolution methods - Simplify to just call loadInstance\n instance<T, Args extends any[]>(classDefinition: new (...args: Args) => T, params: ParameterValue<any>[] = []): Promise<T> {\n // Basic check upfront\n if (typeof classDefinition !== 'function' || !classDefinition.prototype) {\n throw new NotAClassDefinitionError(`Cannot resolve instance for non-class: ${String(classDefinition)}`);\n }\n return this.loadInstance(classDefinition, params) as Promise<T>;\n }\n\n get<T>(label: any, param: ParameterValue<any>[] = []): Promise<T> | T {\n // Just delegate to loadInstance, which handles routing and auto-registration\n return this.loadInstance(label, param);\n }\n\n extend(): IContainerClient & IContainerSetup {\n const childContainer = createContainer() as Container;\n\n // Copy routing and definition maps (share the registration knowledge)\n childContainer._routing = new Map(this._routing);\n childContainer._functionDefinition = new Map(this._functionDefinition);\n childContainer._classDefinition = new Map(this._classDefinition);\n\n // Share singleton storage (singletons are shared across all containers)\n childContainer._functionStorageSingleton = this._functionStorageSingleton;\n childContainer._classStorageSingleton = this._classStorageSingleton;\n\n // Do NOT share scoped storage (new container = new scope)\n // Child gets its own empty scoped storage\n\n // console.log('[IOC Extend] Created child container.');\n return childContainer;\n }\n\n // Private helper methods\n private clearDefinitions(label: any): void {\n this._routing.delete(label);\n this._functionDefinition.delete(label);\n // Only delete from classDefinition if the label is actually a function constructor\n if (typeof label === 'function') {\n this._classDefinition.delete(label);\n }\n }\n\n // Checks if the label is *currently* registered as a class\n private isRegisteredAsClass(label: any): boolean {\n return this._routing.get(label) === ContainerRouting.CLASS;\n }\n\n // Checks if the label is *currently* registered as a function\n private isRegisteredAsFunction(label: any): boolean {\n return this._routing.get(label) === ContainerRouting.FUNCTIONAL;\n }\n\n\n private hasInstance(label: any): boolean {\n const storageType = this.getStorageType(label); // This checks decorators if needed\n\n if (!storageType) {\n // Transient instances are never stored\n return false;\n }\n\n // Determine if it's treated as a class (registered or decorated) *after* getting type\n const isClass = this.isClassType(label); // Use a helper that checks routing OR decorator\n\n if (isClass) {\n return storageType === 'singleton'\n ? this._classStorageSingleton.has(label)\n : this._classStorageScoped.has(label);\n } else { // Must be a function if not a class\n return storageType === 'singleton'\n ? this._functionStorageSingleton.has(label)\n : this._functionStorageScoped.has(label);\n }\n }\n\n // Helper to determine if something should be treated as a class (registered or decorated)\n private isClassType(label: any): boolean {\n if (this.isRegisteredAsClass(label)) {\n return true;\n }\n // If not explicitly registered as a class, check if it's a function with @Component\n if (typeof label === 'function' && label.prototype && !this.isRegisteredAsFunction(label)) {\n return getComponentOptions(label) !== null;\n }\n return false;\n }\n\n private getInstance(label: any): any {\n const storageType = this.getStorageType(label); // Checks decorators if needed\n\n if (!storageType) {\n // This should ideally not be reached if called after hasInstance check\n console.error(`[IOC GetInstance] Attempted to get instance for non-stored type: ${String(label)}`);\n throw new InstanceNotCreatedError();\n }\n\n const isClass = this.isClassType(label); // Check routing OR decorator\n\n if (isClass) {\n return storageType === 'singleton'\n ? this._classStorageSingleton.get(label)\n : this._classStorageScoped.get(label);\n } else { // Must be a function\n return storageType === 'singleton'\n ? this._functionStorageSingleton.get(label)\n : this._functionStorageScoped.get(label);\n }\n }\n\n private setInstance(label: any, instance: any, storageType?: StorageType): void { // Made storageType non-optional\n const isClass = this.isClassType(label); // Determine type based on routing OR decorator\n\n if (isClass) {\n if (storageType === 'singleton') {\n this._classStorageSingleton.set(label, instance);\n } else if (storageType == 'scoped'){ // storageType === 'scoped'\n this._classStorageScoped.set(label, instance);\n }\n } else { // Must be a function\n if (storageType === 'singleton') {\n this._functionStorageSingleton.set(label, instance);\n } else if(storageType === \"scoped\"){ // storageType === 'scoped'\n this._functionStorageScoped.set(label, instance);\n }\n }\n }\n\n private getStorageType(label: any): StorageType {\n let manualLoadAs: LoadAs | undefined;\n let decoratorScope: LoadAs | undefined;\n const isPotentialClass = typeof label === 'function' && label.prototype;\n\n // Get manual registration options if available\n if (this.isRegisteredAsClass(label)) { // Use helper\n manualLoadAs = this._classDefinition.get(label)?.loadAs;\n } else if (this.isRegisteredAsFunction(label)) { // Use helper\n manualLoadAs = this._functionDefinition.get(label)?.options?.loadAs;\n }\n\n // Get decorator scope only if it's potentially a class *and not explicitly registered as a function*\n if (isPotentialClass && !this.isRegisteredAsFunction(label)) {\n decoratorScope = getScope(label); // Uses getComponentOptions internally\n }\n\n // Determine final scope: Manual > Decorator > Default (Transient)\n const finalScope = manualLoadAs ?? decoratorScope ?? LoadAs.Transient;\n\n if (finalScope === LoadAs.Singleton) {\n return 'singleton';\n } else if (finalScope === LoadAs.Scoped) {\n return 'scoped';\n }else{\n return 'transient'; // Transient\n }\n }\n\n // Central resolution logic\n protected async loadInstance(\n label: any,\n params: ParameterValue<any>[] = [],\n resolutionChain: string[] = [] // Track resolution path\n ): Promise<any> {\n\n // --- Circular Dependency Check ---\n const currentLabelStr = (typeof label === 'function' && label.name) ? label.name : String(label);\n if (resolutionChain.includes(currentLabelStr)) {\n console.error(`[IOC LoadInstance] Circular dependency detected: ${[...resolutionChain, currentLabelStr].join(' -> ')}`);\n throw new CircularDependencyError([...resolutionChain, currentLabelStr]);\n }\n const nextResolutionChain = [...resolutionChain, currentLabelStr];\n // --- End Circular Dependency Check ---\n\n // --- Handle Parameters ---\n if (label instanceof Parameter) {\n try {\n // Pass a *copy* of params to avoid side effects in resolveParameterValue\n return Promise.resolve(this.resolveParameterValue(label, [...params]));\n } catch (e) {\n // console.error(`[IOC LoadInstance] Error resolving parameter ${param.toString()}:`, e);\n return Promise.reject(e);\n }\n }\n // --- End Handle Parameters ---\n\n\n // --- Check Explicit Registrations ---\n if (this.isRegisteredAsClass(label)) {\n // console.log(`[IOC LoadInstance] Resolving explicitly registered class: ${currentLabelStr}`);\n return this.loadClassInstance(label, params, nextResolutionChain);\n }\n if (this.isRegisteredAsFunction(label)) {\n // console.log(`[IOC LoadInstance] Resolving explicitly registered function: ${currentLabelStr}`);\n return this.loadFunctionInstance(label, params, nextResolutionChain);\n }\n // --- End Check Explicit Registrations ---\n\n\n // --- Attempt Auto-Registration/Resolution for Decorated Classes ---\n if (typeof label === 'function' && label.prototype) {\n const componentOptions = getComponentOptions(label); // Check for @Component\n if (componentOptions !== null) {\n // console.log(`[IOC LoadInstance] Auto-resolving @Component class: ${currentLabelStr}`);\n // Set routing *now* so subsequent internal checks work correctly\n if (!this._routing.has(label)) { // Only set if not already set\n this._routing.set(label, ContainerRouting.CLASS);\n // console.log(`[IOC LoadInstance] Set routing for auto-resolved class: ${currentLabelStr}`);\n }\n // Proceed to load it as a class\n return this.loadClassInstance(label, params, nextResolutionChain);\n }\n }\n // --- End Auto-Registration ---\n\n\n // --- Dependency Not Found ---\n console.error(`[IOC LoadInstance] Dependency not found and cannot be resolved: ${currentLabelStr}`);\n throw new DependencyNotFoundError(currentLabelStr);\n }\n\n\n private resolveParameterValue(param: Parameter, params: ParameterValue<any>[]): any { // No mutation\n // Find the *last* provided value for the parameter\n const valueContainer = [...params].reverse().find((p) => p.belongsTo(param));\n if (!valueContainer) {\n // console.error(`[IOC ResolveParam] Parameter not found: ${param.toString()}`);\n throw new ParameterNotFoundError(param.toString());\n }\n // console.log(`[IOC ResolveParam] Resolved parameter ${param.toString()}`);\n return valueContainer.value;\n }\n\n private loadClassInstance(\n classDefinition: any, // Should be a class constructor here\n params: ParameterValue<any>[],\n resolutionChain: string[]\n ): Promise<any> {\n const storageType = this.getStorageType(classDefinition);\n const className = classDefinition.name || '[Anonymous Class]';\n\n // Check storage first (handle stored promises)\n if (storageType && this.hasInstance(classDefinition)) {\n const instance = this.getInstance(classDefinition);\n // console.log(`[IOC LoadClass] Found existing ${storageType} instance for ${className}. IsPromise: ${isPromise(instance)}`);\n return instance\n }\n // console.log(`[IOC LoadClass] Creating new ${storageType || 'transient'} instance for ${className}`);\n\n // --- Determine Dependencies ---\n const manualOptions = this._classDefinition.get(classDefinition) as ContainerOptions | undefined;\n let dependenciesToResolve: any[];\n\n if (manualOptions?.param && Array.isArray(manualOptions.param)) {\n dependenciesToResolve = manualOptions.param;\n // console.log(`[IOC LoadClass] Using manual dependencies for ${className}`);\n } else {\n // Use decorator-derived dependencies\n dependenciesToResolve = getResolvedDependencies(classDefinition);\n // console.log(`[IOC LoadClass] Using decorator/reflected dependencies for ${className}:`, dependenciesToResolve.map(d => typeof d === 'function' ? d.name : String(d)));\n }\n // --- End Determine Dependencies ---\n\n\n // --- Resolve Dependencies ---\n // Create a *copy* of params to pass down for dependency resolution\n const paramsCopy = [...params];\n const resolutionPromises = dependenciesToResolve.map(dependencyIdentifier =>\n this.loadInstance(dependencyIdentifier, paramsCopy, resolutionChain) // Recursive call handles auto-registration\n );\n\n let finalInstance = Promise.all(resolutionPromises)\n .catch((error)=>{\n console.error(`[IOC LoadClass] Failed to resolve one or more dependencies for ${className}:`, error);\n // Clean up potential partially stored promise if this was going to be singleton/scoped\n if (storageType && this.isRegisteredAsClass(classDefinition)) { // Check if it was actually *being* stored\n if (storageType === 'singleton') this._classStorageSingleton.delete(classDefinition);\n if (storageType === 'scoped') this._classStorageScoped.delete(classDefinition);\n }\n throw error; // Re-throw dependency resolution error\n }).then(async(resolvedDependencies)=>{\n // --- Instantiate Class ---\n // Store the promise *before* starting instantiation for concurrent requests\n let instancePromise: Promise<any> | undefined;\n if (storageType && !this.hasInstance(classDefinition)) { // Check again in case of race condition?\n // Create the promise wrapper immediately\n instancePromise = (async () => {\n try {\n // console.log(`[IOC LoadClass] Instantiating ${className} with ${resolvedDependencies.length} args.`);\n const instance = new classDefinition(...resolvedDependencies);\n // Overwrite the stored promise with the actual instance *after* it's created\n this.setInstance(classDefinition, instance, storageType); // Use the correct storageType\n // console.log(`[IOC LoadClass] Stored actual ${storageType} instance for ${className}`);\n return instance;\n } catch (err: any) {\n console.error(`[IOC LoadClass] Error during instantiation of ${className}: ${err.message}`, err.stack);\n // Clean up the stored promise on failure\n if (storageType === 'singleton') this._classStorageSingleton.delete(classDefinition);\n if (storageType === 'scoped') this._classStorageScoped.delete(classDefinition);\n throw err; // Re-throw instantiation error\n }\n })();\n // console.log(`[IOC LoadClass] Storing promise for concurrent requests (${storageType}) for ${className}`);\n this.setInstance(classDefinition, instancePromise, storageType);\n } else {\n // If already has instance (from storage check) or is transient, just instantiate directly\n instancePromise = (async () => {\n try {\n // console.log(`[IOC LoadClass] Instantiating transient ${className} with ${resolvedDependencies.length} args.`);\n const instance = new classDefinition(...resolvedDependencies);\n // No storing for transient\n return instance;\n } catch (err: any) {\n console.error(`[IOC LoadClass] Error during instantiation of transient ${className}: ${err.message}`, err.stack);\n throw err; // Re-throw instantiation error\n }\n })();\n }\n // --- End Instantiate Class ---\n // Await and return the final instance (either newly created or from the stored promise)\n return await instancePromise;\n });\n\n if(storageType && storageType !== 'transient'){\n this.setInstance(classDefinition, finalInstance, storageType); // Store the promise\n }\n return finalInstance\n }\n\n private loadFunctionInstance(\n funcLabel: any,\n params: ParameterValue<any>[],\n resolutionChain: string[]\n ): Promise<any> { // Always return Promise<any> since this is an async function\n const functionConfig = this._functionDefinition.get(funcLabel)!; // Assumed to exist by caller\n const storageType = this.getStorageType(funcLabel); // Only uses manual options for functions\n const labelStr = String(funcLabel);\n\n // Check storage first\n if (storageType && this.hasInstance(funcLabel)) {\n const instance = this.getInstance(funcLabel);\n // console.log(`[IOC LoadFunc] Found existing ${storageType} instance for ${labelStr}. IsPromise: ${isPromise(instance)}`);\n return instance;\n }\n // console.log(`[IOC LoadFunc] Creating new ${storageType || 'transient'} instance for ${labelStr}`);\n\n const ioc_func = functionConfig.function;\n const options = functionConfig.options;\n const dependenciesToResolve: any[] = options?.param || [];\n\n // --- Resolve Dependencies ---\n const paramsCopy = [...params]; // Create a copy\n const resolutionPromises = dependenciesToResolve.map(dependencyIdentifier =>\n this.loadInstance(dependencyIdentifier, paramsCopy, resolutionChain)\n );\n\n let finalInstance = Promise.all(resolutionPromises).catch((error)=>{\n console.error(`[IOC LoadFunc] Failed to resolve dependencies for function ${labelStr}:`, error);\n // Clean up potential partial storage\n if (storageType && this.isRegisteredAsFunction(funcLabel)) {\n if (storageType === 'singleton') this._functionStorageSingleton.delete(funcLabel);\n if (storageType === 'scoped') this._functionStorageScoped.delete(funcLabel);\n }\n throw error;\n }).then(async(resolvedArgs)=>{\n let instancePromise: Promise<any> | undefined;\n if (storageType && !this.hasInstance(funcLabel)) {\n instancePromise = (async () => {\n try {\n // console.log(`[IOC LoadFunc] Invoking ${labelStr} with ${resolvedArgs.length} args.`);\n const result = await ioc_func.apply(null, resolvedArgs); // Await in case function is async\n // Overwrite stored promise with actual result\n this.setInstance(funcLabel, result, storageType);\n // console.log(`[IOC LoadFunc] Stored actual ${storageType} instance for ${labelStr}`);\n return result;\n } catch (err: any) {\n console.error(`[IOC LoadFunc] Error executing function ${labelStr}: ${err.message}`, err.stack);\n // Clean up stored promise on failure\n if (storageType === 'singleton') this._functionStorageSingleton.delete(funcLabel);\n if (storageType === 'scoped') this._functionStorageScoped.delete(funcLabel);\n throw err;\n }\n })();\n // console.log(`[IOC LoadFunc] Storing promise for concurrent requests (${storageType}) for ${labelStr}`);\n this.setInstance(funcLabel, instancePromise, storageType);\n } else {\n // Transient or already resolved from storage check\n instancePromise = (async () => {\n try {\n // console.log(`[IOC LoadFunc] Invoking transient ${labelStr} with ${resolvedArgs.length} args.`);\n const result = await ioc_func.apply(null, resolvedArgs); // Await in case function is async\n // No storing for transient\n return result;\n } catch (err: any) {\n console.error(`[IOC LoadFunc] Error executing transient function ${labelStr}: ${err.message}`, err.stack);\n throw err;\n }\n })();\n }\n // --- End Invoke Function ---\n\n return await instancePromise; // Return the final (awaited) result\n });\n\n if(storageType && storageType !== 'transient'){\n this.setInstance(funcLabel, finalInstance, storageType); // Store the promise\n }\n\n return finalInstance;\n }\n}\n\n// Helper functions\nexport function isPromise(obj: any): obj is Promise<any> {\n // Simplified check - more robust check might be needed depending on environment\n return !!obj && typeof obj.then === 'function';\n}\n\nexport function createContainer(): IContainerClient & IContainerSetup {\n return new Container();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAAO;AAEP,oBAAuB;AACvB,uBAA0B;AAE1B,6BAA4I;AAC5I,8B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AQ,MAAM,qDAAqD,QAAQ,KAAK,IAAI,OAAO,IAAI,IAAI,KAAK;AACxG,kBAAM;AAAA,UACV;AAAA,QACL,GAAG;AAAA,MACR;AAGA,aAAO,MAAM;AAAA,IACb,CAAC;AAED,QAAG,eAAe,gBAAgB,aAAY;AAC1C,WAAK,YAAY,WAAW,eAAe,WAAW;AAAA,IAC1D;AAEA,WAAO;AAAA,EACX;AACJ;AAGO,SAAS,UAAU,KAA+B;AAErD,SAAO,CAAC,CAAC,OAAO,OAAO,IAAI,SAAS;AACxC;AAEO,SAAS,kBAAsD;AAClE,SAAO,IAAI,UAAU;AACzB;","names":["ContainerRouting"]}
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
getScope,
|
|
7
7
|
getComponentOptions,
|
|
8
8
|
getResolvedDependencies
|
|
9
|
-
} from "./DecoratorSupport";
|
|
9
|
+
} from "./DecoratorSupport.js";
|
|
10
10
|
var ContainerRouting = /* @__PURE__ */ ((ContainerRouting2) => {
|
|
11
11
|
ContainerRouting2["FUNCTIONAL"] = "FUNCTIONAL";
|
|
12
12
|
ContainerRouting2["CLASS"] = "CLASS";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../framework/implementation/Container.ts"],"sourcesContent":["import 'reflect-metadata'; // Ensure polyfill is loaded conceptually\nimport type { ContainerOptions, IContainerClient, IContainerFunctionDefinition, IContainerSetup } from \"../interface/Container\";\nimport { LoadAs } from \"./LoadAs\";\nimport { Parameter } from \"./Parameter\";\nimport type { ParameterValue } from \"./Parameter\";\nimport { NotAClassDefinitionError, ParameterNotFoundError, DependencyNotFoundError, InstanceNotCreatedError, CircularDependencyError } from \"../errors/ContainerErrors\";\nimport {\n getScope,\n getComponentOptions, // Use helper\n getResolvedDependencies // Use helper\n} from './DecoratorSupport'; // Assume helpers exist or create them\n\nenum ContainerRouting {\n FUNCTIONAL = \"FUNCTIONAL\",\n CLASS = \"CLASS\"\n // No need for COMPONENT route, just check metadata if CLASS/FUNCTIONAL fails\n}\n\ntype StorageType = 'singleton' | 'scoped' | 'transient';\n\nexport class Container implements IContainerClient, IContainerSetup {\n // Routing and definition maps\n private _routing: Map<any, ContainerRouting> = new Map();\n private _functionDefinition: Map<any, IContainerFunctionDefinition> = new Map();\n private _classDefinition: Map<Function, Partial<ContainerOptions>> = new Map();\n\n // Storage maps\n private _functionStorageSingleton: Map<any, any> = new Map();\n private _functionStorageScoped: Map<any, any> = new Map();\n private _classStorageSingleton: Map<Function, any> = new Map();\n private _classStorageScoped: Map<Function, any> = new Map();\n\n // Registration methods\n registerClass<T>(classDefinition: new (...args: any[]) => T, options?: Partial<ContainerOptions>): void {\n // Basic validation\n if (typeof classDefinition !== 'function' || !classDefinition.prototype) {\n console.warn(`[IOC] Attempted to register non-class: ${String(classDefinition)}`);\n // Optional: throw error instead?\n // throw new NotAClassDefinitionError(`Attempted to register non-class: ${String(classDefinition)}`);\n return; // Don't proceed if not a class constructor\n }\n\n // Always clear previous definitions for this exact class constructor\n this.clearDefinitions(classDefinition);\n\n // Always set the routing type so 'isClassDefinition' works\n this._routing.set(classDefinition, ContainerRouting.CLASS);\n\n // Store manual options *only if they are actually provided and have content*\n if (options && Object.keys(options).length > 0) {\n this._classDefinition.set(classDefinition, options);\n // console.log(`[IOC RegClass] Manually registered ${classDefinition.name} with options:`, options);\n } else {\n // console.log(`[IOC RegClass] Manually registered ${classDefinition.name} with no specific options (will use decorators if present).`);\n // If no options are provided, we don't store anything in _classDefinition,\n // effectively clearing any previous manual config and letting decorators take over if present.\n }\n }\n\n registerFunction<T extends (...arg: any[]) => any>(label: any, func: T, options: Partial<ContainerOptions> = {} as any): void {\n this.clearDefinitions(label);\n this._routing.set(label, ContainerRouting.FUNCTIONAL);\n this._functionDefinition.set(label, { function: func, options });\n // console.log(`[IOC RegFunc] Registered function with label ${String(label)} and options:`, options);\n }\n\n // Instance resolution methods - Simplify to just call loadInstance\n instance<T, Args extends any[]>(classDefinition: new (...args: Args) => T, params: ParameterValue<any>[] = []): Promise<T> {\n // Basic check upfront\n if (typeof classDefinition !== 'function' || !classDefinition.prototype) {\n throw new NotAClassDefinitionError(`Cannot resolve instance for non-class: ${String(classDefinition)}`);\n }\n return this.loadInstance(classDefinition, params) as Promise<T>;\n }\n\n get<T>(label: any, param: ParameterValue<any>[] = []): Promise<T> | T {\n // Just delegate to loadInstance, which handles routing and auto-registration\n return this.loadInstance(label, param);\n }\n\n extend(): IContainerClient & IContainerSetup {\n const childContainer = createContainer() as Container;\n\n // Copy routing and definition maps (share the registration knowledge)\n childContainer._routing = new Map(this._routing);\n childContainer._functionDefinition = new Map(this._functionDefinition);\n childContainer._classDefinition = new Map(this._classDefinition);\n\n // Share singleton storage (singletons are shared across all containers)\n childContainer._functionStorageSingleton = this._functionStorageSingleton;\n childContainer._classStorageSingleton = this._classStorageSingleton;\n\n // Do NOT share scoped storage (new container = new scope)\n // Child gets its own empty scoped storage\n\n // console.log('[IOC Extend] Created child container.');\n return childContainer;\n }\n\n // Private helper methods\n private clearDefinitions(label: any): void {\n this._routing.delete(label);\n this._functionDefinition.delete(label);\n // Only delete from classDefinition if the label is actually a function constructor\n if (typeof label === 'function') {\n this._classDefinition.delete(label);\n }\n }\n\n // Checks if the label is *currently* registered as a class\n private isRegisteredAsClass(label: any): boolean {\n return this._routing.get(label) === ContainerRouting.CLASS;\n }\n\n // Checks if the label is *currently* registered as a function\n private isRegisteredAsFunction(label: any): boolean {\n return this._routing.get(label) === ContainerRouting.FUNCTIONAL;\n }\n\n\n private hasInstance(label: any): boolean {\n const storageType = this.getStorageType(label); // This checks decorators if needed\n\n if (!storageType) {\n // Transient instances are never stored\n return false;\n }\n\n // Determine if it's treated as a class (registered or decorated) *after* getting type\n const isClass = this.isClassType(label); // Use a helper that checks routing OR decorator\n\n if (isClass) {\n return storageType === 'singleton'\n ? this._classStorageSingleton.has(label)\n : this._classStorageScoped.has(label);\n } else { // Must be a function if not a class\n return storageType === 'singleton'\n ? this._functionStorageSingleton.has(label)\n : this._functionStorageScoped.has(label);\n }\n }\n\n // Helper to determine if something should be treated as a class (registered or decorated)\n private isClassType(label: any): boolean {\n if (this.isRegisteredAsClass(label)) {\n return true;\n }\n // If not explicitly registered as a class, check if it's a function with @Component\n if (typeof label === 'function' && label.prototype && !this.isRegisteredAsFunction(label)) {\n return getComponentOptions(label) !== null;\n }\n return false;\n }\n\n private getInstance(label: any): any {\n const storageType = this.getStorageType(label); // Checks decorators if needed\n\n if (!storageType) {\n // This should ideally not be reached if called after hasInstance check\n console.error(`[IOC GetInstance] Attempted to get instance for non-stored type: ${String(label)}`);\n throw new InstanceNotCreatedError();\n }\n\n const isClass = this.isClassType(label); // Check routing OR decorator\n\n if (isClass) {\n return storageType === 'singleton'\n ? this._classStorageSingleton.get(label)\n : this._classStorageScoped.get(label);\n } else { // Must be a function\n return storageType === 'singleton'\n ? this._functionStorageSingleton.get(label)\n : this._functionStorageScoped.get(label);\n }\n }\n\n private setInstance(label: any, instance: any, storageType?: StorageType): void { // Made storageType non-optional\n const isClass = this.isClassType(label); // Determine type based on routing OR decorator\n\n if (isClass) {\n if (storageType === 'singleton') {\n this._classStorageSingleton.set(label, instance);\n } else if (storageType == 'scoped'){ // storageType === 'scoped'\n this._classStorageScoped.set(label, instance);\n }\n } else { // Must be a function\n if (storageType === 'singleton') {\n this._functionStorageSingleton.set(label, instance);\n } else if(storageType === \"scoped\"){ // storageType === 'scoped'\n this._functionStorageScoped.set(label, instance);\n }\n }\n }\n\n private getStorageType(label: any): StorageType {\n let manualLoadAs: LoadAs | undefined;\n let decoratorScope: LoadAs | undefined;\n const isPotentialClass = typeof label === 'function' && label.prototype;\n\n // Get manual registration options if available\n if (this.isRegisteredAsClass(label)) { // Use helper\n manualLoadAs = this._classDefinition.get(label)?.loadAs;\n } else if (this.isRegisteredAsFunction(label)) { // Use helper\n manualLoadAs = this._functionDefinition.get(label)?.options?.loadAs;\n }\n\n // Get decorator scope only if it's potentially a class *and not explicitly registered as a function*\n if (isPotentialClass && !this.isRegisteredAsFunction(label)) {\n decoratorScope = getScope(label); // Uses getComponentOptions internally\n }\n\n // Determine final scope: Manual > Decorator > Default (Transient)\n const finalScope = manualLoadAs ?? decoratorScope ?? LoadAs.Transient;\n\n if (finalScope === LoadAs.Singleton) {\n return 'singleton';\n } else if (finalScope === LoadAs.Scoped) {\n return 'scoped';\n }else{\n return 'transient'; // Transient\n }\n }\n\n // Central resolution logic\n protected async loadInstance(\n label: any,\n params: ParameterValue<any>[] = [],\n resolutionChain: string[] = [] // Track resolution path\n ): Promise<any> {\n\n // --- Circular Dependency Check ---\n const currentLabelStr = (typeof label === 'function' && label.name) ? label.name : String(label);\n if (resolutionChain.includes(currentLabelStr)) {\n console.error(`[IOC LoadInstance] Circular dependency detected: ${[...resolutionChain, currentLabelStr].join(' -> ')}`);\n throw new CircularDependencyError([...resolutionChain, currentLabelStr]);\n }\n const nextResolutionChain = [...resolutionChain, currentLabelStr];\n // --- End Circular Dependency Check ---\n\n // --- Handle Parameters ---\n if (label instanceof Parameter) {\n try {\n // Pass a *copy* of params to avoid side effects in resolveParameterValue\n return Promise.resolve(this.resolveParameterValue(label, [...params]));\n } catch (e) {\n // console.error(`[IOC LoadInstance] Error resolving parameter ${param.toString()}:`, e);\n return Promise.reject(e);\n }\n }\n // --- End Handle Parameters ---\n\n\n // --- Check Explicit Registrations ---\n if (this.isRegisteredAsClass(label)) {\n // console.log(`[IOC LoadInstance] Resolving explicitly registered class: ${currentLabelStr}`);\n return this.loadClassInstance(label, params, nextResolutionChain);\n }\n if (this.isRegisteredAsFunction(label)) {\n // console.log(`[IOC LoadInstance] Resolving explicitly registered function: ${currentLabelStr}`);\n return this.loadFunctionInstance(label, params, nextResolutionChain);\n }\n // --- End Check Explicit Registrations ---\n\n\n // --- Attempt Auto-Registration/Resolution for Decorated Classes ---\n if (typeof label === 'function' && label.prototype) {\n const componentOptions = getComponentOptions(label); // Check for @Component\n if (componentOptions !== null) {\n // console.log(`[IOC LoadInstance] Auto-resolving @Component class: ${currentLabelStr}`);\n // Set routing *now* so subsequent internal checks work correctly\n if (!this._routing.has(label)) { // Only set if not already set\n this._routing.set(label, ContainerRouting.CLASS);\n // console.log(`[IOC LoadInstance] Set routing for auto-resolved class: ${currentLabelStr}`);\n }\n // Proceed to load it as a class\n return this.loadClassInstance(label, params, nextResolutionChain);\n }\n }\n // --- End Auto-Registration ---\n\n\n // --- Dependency Not Found ---\n console.error(`[IOC LoadInstance] Dependency not found and cannot be resolved: ${currentLabelStr}`);\n throw new DependencyNotFoundError(currentLabelStr);\n }\n\n\n private resolveParameterValue(param: Parameter, params: ParameterValue<any>[]): any { // No mutation\n // Find the *last* provided value for the parameter\n const valueContainer = [...params].reverse().find((p) => p.belongsTo(param));\n if (!valueContainer) {\n // console.error(`[IOC ResolveParam] Parameter not found: ${param.toString()}`);\n throw new ParameterNotFoundError(param.toString());\n }\n // console.log(`[IOC ResolveParam] Resolved parameter ${param.toString()}`);\n return valueContainer.value;\n }\n\n private loadClassInstance(\n classDefinition: any, // Should be a class constructor here\n params: ParameterValue<any>[],\n resolutionChain: string[]\n ): Promise<any> {\n const storageType = this.getStorageType(classDefinition);\n const className = classDefinition.name || '[Anonymous Class]';\n\n // Check storage first (handle stored promises)\n if (storageType && this.hasInstance(classDefinition)) {\n const instance = this.getInstance(classDefinition);\n // console.log(`[IOC LoadClass] Found existing ${storageType} instance for ${className}. IsPromise: ${isPromise(instance)}`);\n return instance\n }\n // console.log(`[IOC LoadClass] Creating new ${storageType || 'transient'} instance for ${className}`);\n\n // --- Determine Dependencies ---\n const manualOptions = this._classDefinition.get(classDefinition) as ContainerOptions | undefined;\n let dependenciesToResolve: any[];\n\n if (manualOptions?.param && Array.isArray(manualOptions.param)) {\n dependenciesToResolve = manualOptions.param;\n // console.log(`[IOC LoadClass] Using manual dependencies for ${className}`);\n } else {\n // Use decorator-derived dependencies\n dependenciesToResolve = getResolvedDependencies(classDefinition);\n // console.log(`[IOC LoadClass] Using decorator/reflected dependencies for ${className}:`, dependenciesToResolve.map(d => typeof d === 'function' ? d.name : String(d)));\n }\n // --- End Determine Dependencies ---\n\n\n // --- Resolve Dependencies ---\n // Create a *copy* of params to pass down for dependency resolution\n const paramsCopy = [...params];\n const resolutionPromises = dependenciesToResolve.map(dependencyIdentifier =>\n this.loadInstance(dependencyIdentifier, paramsCopy, resolutionChain) // Recursive call handles auto-registration\n );\n\n let finalInstance = Promise.all(resolutionPromises)\n .catch((error)=>{\n console.error(`[IOC LoadClass] Failed to resolve one or more dependencies for ${className}:`, error);\n // Clean up potential partially stored promise if this was going to be singleton/scoped\n if (storageType && this.isRegisteredAsClass(classDefinition)) { // Check if it was actually *being* stored\n if (storageType === 'singleton') this._classStorageSingleton.delete(classDefinition);\n if (storageType === 'scoped') this._classStorageScoped.delete(classDefinition);\n }\n throw error; // Re-throw dependency resolution error\n }).then(async(resolvedDependencies)=>{\n // --- Instantiate Class ---\n // Store the promise *before* starting instantiation for concurrent requests\n let instancePromise: Promise<any> | undefined;\n if (storageType && !this.hasInstance(classDefinition)) { // Check again in case of race condition?\n // Create the promise wrapper immediately\n instancePromise = (async () => {\n try {\n // console.log(`[IOC LoadClass] Instantiating ${className} with ${resolvedDependencies.length} args.`);\n const instance = new classDefinition(...resolvedDependencies);\n // Overwrite the stored promise with the actual instance *after* it's created\n this.setInstance(classDefinition, instance, storageType); // Use the correct storageType\n // console.log(`[IOC LoadClass] Stored actual ${storageType} instance for ${className}`);\n return instance;\n } catch (err: any) {\n console.error(`[IOC LoadClass] Error during instantiation of ${className}: ${err.message}`, err.stack);\n // Clean up the stored promise on failure\n if (storageType === 'singleton') this._classStorageSingleton.delete(classDefinition);\n if (storageType === 'scoped') this._classStorageScoped.delete(classDefinition);\n throw err; // Re-throw instantiation error\n }\n })();\n // console.log(`[IOC LoadClass] Storing promise for concurrent requests (${storageType}) for ${className}`);\n this.setInstance(classDefinition, instancePromise, storageType);\n } else {\n // If already has instance (from storage check) or is transient, just instantiate directly\n instancePromise = (async () => {\n try {\n // console.log(`[IOC LoadClass] Instantiating transient ${className} with ${resolvedDependencies.length} args.`);\n const instance = new classDefinition(...resolvedDependencies);\n // No storing for transient\n return instance;\n } catch (err: any) {\n console.error(`[IOC LoadClass] Error during instantiation of transient ${className}: ${err.message}`, err.stack);\n throw err; // Re-throw instantiation error\n }\n })();\n }\n // --- End Instantiate Class ---\n // Await and return the final instance (either newly created or from the stored promise)\n return await instancePromise;\n });\n\n if(storageType && storageType !== 'transient'){\n this.setInstance(classDefinition, finalInstance, storageType); // Store the promise\n }\n return finalInstance\n }\n\n private loadFunctionInstance(\n funcLabel: any,\n params: ParameterValue<any>[],\n resolutionChain: string[]\n ): Promise<any> { // Always return Promise<any> since this is an async function\n const functionConfig = this._functionDefinition.get(funcLabel)!; // Assumed to exist by caller\n const storageType = this.getStorageType(funcLabel); // Only uses manual options for functions\n const labelStr = String(funcLabel);\n\n // Check storage first\n if (storageType && this.hasInstance(funcLabel)) {\n const instance = this.getInstance(funcLabel);\n // console.log(`[IOC LoadFunc] Found existing ${storageType} instance for ${labelStr}. IsPromise: ${isPromise(instance)}`);\n return instance;\n }\n // console.log(`[IOC LoadFunc] Creating new ${storageType || 'transient'} instance for ${labelStr}`);\n\n const ioc_func = functionConfig.function;\n const options = functionConfig.options;\n const dependenciesToResolve: any[] = options?.param || [];\n\n // --- Resolve Dependencies ---\n const paramsCopy = [...params]; // Create a copy\n const resolutionPromises = dependenciesToResolve.map(dependencyIdentifier =>\n this.loadInstance(dependencyIdentifier, paramsCopy, resolutionChain)\n );\n\n let finalInstance = Promise.all(resolutionPromises).catch((error)=>{\n console.error(`[IOC LoadFunc] Failed to resolve dependencies for function ${labelStr}:`, error);\n // Clean up potential partial storage\n if (storageType && this.isRegisteredAsFunction(funcLabel)) {\n if (storageType === 'singleton') this._functionStorageSingleton.delete(funcLabel);\n if (storageType === 'scoped') this._functionStorageScoped.delete(funcLabel);\n }\n throw error;\n }).then(async(resolvedArgs)=>{\n let instancePromise: Promise<any> | undefined;\n if (storageType && !this.hasInstance(funcLabel)) {\n instancePromise = (async () => {\n try {\n // console.log(`[IOC LoadFunc] Invoking ${labelStr} with ${resolvedArgs.length} args.`);\n const result = await ioc_func.apply(null, resolvedArgs); // Await in case function is async\n // Overwrite stored promise with actual result\n this.setInstance(funcLabel, result, storageType);\n // console.log(`[IOC LoadFunc] Stored actual ${storageType} instance for ${labelStr}`);\n return result;\n } catch (err: any) {\n console.error(`[IOC LoadFunc] Error executing function ${labelStr}: ${err.message}`, err.stack);\n // Clean up stored promise on failure\n if (storageType === 'singleton') this._functionStorageSingleton.delete(funcLabel);\n if (storageType === 'scoped') this._functionStorageScoped.delete(funcLabel);\n throw err;\n }\n })();\n // console.log(`[IOC LoadFunc] Storing promise for concurrent requests (${storageType}) for ${labelStr}`);\n this.setInstance(funcLabel, instancePromise, storageType);\n } else {\n // Transient or already resolved from storage check\n instancePromise = (async () => {\n try {\n // console.log(`[IOC LoadFunc] Invoking transient ${labelStr} with ${resolvedArgs.length} args.`);\n const result = await ioc_func.apply(null, resolvedArgs); // Await in case function is async\n // No storing for transient\n return result;\n } catch (err: any) {\n console.error(`[IOC LoadFunc] Error executing transient function ${labelStr}: ${err.message}`, err.stack);\n throw err;\n }\n })();\n }\n // --- End Invoke Function ---\n\n return await instancePromise; // Return the final (awaited) result\n });\n\n if(storageType && storageType !== 'transient'){\n this.setInstance(funcLabel, finalInstance, storageType); // Store the promise\n }\n\n return finalInstance;\n }\n}\n\n// Helper functions\nexport function isPromise(obj: any): obj is Promise<any> {\n // Simplified check - more robust check might be needed depending on environment\n return !!obj && typeof obj.then === 'function';\n}\n\nexport function createContainer(): IContainerClient & IContainerSetup {\n return new Container();\n}\n"],"mappings":"AAAA,OAAO;AAEP,SAAS,cAAc;AACvB,SAAS,iBAAiB;AAE1B,SAAS,0BAA0B,wBAAwB,yBAAyB,yBAAyB,+BAA+B;AAC5I;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,OACG;AAEP,IAAK,mBAAL,kBAAKA,s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AO,IAAI,IAAI,KAAK;AACxG,kBAAM;AAAA,UACV;AAAA,QACL,GAAG;AAAA,MACR;AAGA,aAAO,MAAM;AAAA,IACb,CAAC;AAED,QAAG,eAAe,gBAAgB,aAAY;AAC1C,WAAK,YAAY,WAAW,eAAe,WAAW;AAAA,IAC1D;AAEA,WAAO;AAAA,EACX;AACJ;AAGO,SAAS,UAAU,KAA+B;AAErD,SAAO,CAAC,CAAC,OAAO,OAAO,IAAI,SAAS;AACxC;AAEO,SAAS,kBAAsD;AAClE,SAAO,IAAI,UAAU;AACzB;","names":["ContainerRouting"]}
|
|
1
|
+
{"version":3,"sources":["../../../framework/implementation/Container.ts"],"sourcesContent":["import 'reflect-metadata'; // Ensure polyfill is loaded conceptually\nimport type { ContainerOptions, IContainerClient, IContainerFunctionDefinition, IContainerSetup } from \"../interface/Container.js\";\nimport { LoadAs } from \"./LoadAs.js\";\nimport { Parameter } from \"./Parameter.js\";\nimport type { ParameterValue } from \"./Parameter.js\";\nimport { NotAClassDefinitionError, ParameterNotFoundError, DependencyNotFoundError, InstanceNotCreatedError, CircularDependencyError } from \"../errors/ContainerErrors.js\";\nimport {\n getScope,\n getComponentOptions, // Use helper\n getResolvedDependencies // Use helper\n} from './DecoratorSupport'; // Assume helpers exist or create them\n\nenum ContainerRouting {\n FUNCTIONAL = \"FUNCTIONAL\",\n CLASS = \"CLASS\"\n // No need for COMPONENT route, just check metadata if CLASS/FUNCTIONAL fails\n}\n\ntype StorageType = 'singleton' | 'scoped' | 'transient';\n\nexport class Container implements IContainerClient, IContainerSetup {\n // Routing and definition maps\n private _routing: Map<any, ContainerRouting> = new Map();\n private _functionDefinition: Map<any, IContainerFunctionDefinition> = new Map();\n private _classDefinition: Map<Function, Partial<ContainerOptions>> = new Map();\n\n // Storage maps\n private _functionStorageSingleton: Map<any, any> = new Map();\n private _functionStorageScoped: Map<any, any> = new Map();\n private _classStorageSingleton: Map<Function, any> = new Map();\n private _classStorageScoped: Map<Function, any> = new Map();\n\n // Registration methods\n registerClass<T>(classDefinition: new (...args: any[]) => T, options?: Partial<ContainerOptions>): void {\n // Basic validation\n if (typeof classDefinition !== 'function' || !classDefinition.prototype) {\n console.warn(`[IOC] Attempted to register non-class: ${String(classDefinition)}`);\n // Optional: throw error instead?\n // throw new NotAClassDefinitionError(`Attempted to register non-class: ${String(classDefinition)}`);\n return; // Don't proceed if not a class constructor\n }\n\n // Always clear previous definitions for this exact class constructor\n this.clearDefinitions(classDefinition);\n\n // Always set the routing type so 'isClassDefinition' works\n this._routing.set(classDefinition, ContainerRouting.CLASS);\n\n // Store manual options *only if they are actually provided and have content*\n if (options && Object.keys(options).length > 0) {\n this._classDefinition.set(classDefinition, options);\n // console.log(`[IOC RegClass] Manually registered ${classDefinition.name} with options:`, options);\n } else {\n // console.log(`[IOC RegClass] Manually registered ${classDefinition.name} with no specific options (will use decorators if present).`);\n // If no options are provided, we don't store anything in _classDefinition,\n // effectively clearing any previous manual config and letting decorators take over if present.\n }\n }\n\n registerFunction<T extends (...arg: any[]) => any>(label: any, func: T, options: Partial<ContainerOptions> = {} as any): void {\n this.clearDefinitions(label);\n this._routing.set(label, ContainerRouting.FUNCTIONAL);\n this._functionDefinition.set(label, { function: func, options });\n // console.log(`[IOC RegFunc] Registered function with label ${String(label)} and options:`, options);\n }\n\n // Instance resolution methods - Simplify to just call loadInstance\n instance<T, Args extends any[]>(classDefinition: new (...args: Args) => T, params: ParameterValue<any>[] = []): Promise<T> {\n // Basic check upfront\n if (typeof classDefinition !== 'function' || !classDefinition.prototype) {\n throw new NotAClassDefinitionError(`Cannot resolve instance for non-class: ${String(classDefinition)}`);\n }\n return this.loadInstance(classDefinition, params) as Promise<T>;\n }\n\n get<T>(label: any, param: ParameterValue<any>[] = []): Promise<T> | T {\n // Just delegate to loadInstance, which handles routing and auto-registration\n return this.loadInstance(label, param);\n }\n\n extend(): IContainerClient & IContainerSetup {\n const childContainer = createContainer() as Container;\n\n // Copy routing and definition maps (share the registration knowledge)\n childContainer._routing = new Map(this._routing);\n childContainer._functionDefinition = new Map(this._functionDefinition);\n childContainer._classDefinition = new Map(this._classDefinition);\n\n // Share singleton storage (singletons are shared across all containers)\n childContainer._functionStorageSingleton = this._functionStorageSingleton;\n childContainer._classStorageSingleton = this._classStorageSingleton;\n\n // Do NOT share scoped storage (new container = new scope)\n // Child gets its own empty scoped storage\n\n // console.log('[IOC Extend] Created child container.');\n return childContainer;\n }\n\n // Private helper methods\n private clearDefinitions(label: any): void {\n this._routing.delete(label);\n this._functionDefinition.delete(label);\n // Only delete from classDefinition if the label is actually a function constructor\n if (typeof label === 'function') {\n this._classDefinition.delete(label);\n }\n }\n\n // Checks if the label is *currently* registered as a class\n private isRegisteredAsClass(label: any): boolean {\n return this._routing.get(label) === ContainerRouting.CLASS;\n }\n\n // Checks if the label is *currently* registered as a function\n private isRegisteredAsFunction(label: any): boolean {\n return this._routing.get(label) === ContainerRouting.FUNCTIONAL;\n }\n\n\n private hasInstance(label: any): boolean {\n const storageType = this.getStorageType(label); // This checks decorators if needed\n\n if (!storageType) {\n // Transient instances are never stored\n return false;\n }\n\n // Determine if it's treated as a class (registered or decorated) *after* getting type\n const isClass = this.isClassType(label); // Use a helper that checks routing OR decorator\n\n if (isClass) {\n return storageType === 'singleton'\n ? this._classStorageSingleton.has(label)\n : this._classStorageScoped.has(label);\n } else { // Must be a function if not a class\n return storageType === 'singleton'\n ? this._functionStorageSingleton.has(label)\n : this._functionStorageScoped.has(label);\n }\n }\n\n // Helper to determine if something should be treated as a class (registered or decorated)\n private isClassType(label: any): boolean {\n if (this.isRegisteredAsClass(label)) {\n return true;\n }\n // If not explicitly registered as a class, check if it's a function with @Component\n if (typeof label === 'function' && label.prototype && !this.isRegisteredAsFunction(label)) {\n return getComponentOptions(label) !== null;\n }\n return false;\n }\n\n private getInstance(label: any): any {\n const storageType = this.getStorageType(label); // Checks decorators if needed\n\n if (!storageType) {\n // This should ideally not be reached if called after hasInstance check\n console.error(`[IOC GetInstance] Attempted to get instance for non-stored type: ${String(label)}`);\n throw new InstanceNotCreatedError();\n }\n\n const isClass = this.isClassType(label); // Check routing OR decorator\n\n if (isClass) {\n return storageType === 'singleton'\n ? this._classStorageSingleton.get(label)\n : this._classStorageScoped.get(label);\n } else { // Must be a function\n return storageType === 'singleton'\n ? this._functionStorageSingleton.get(label)\n : this._functionStorageScoped.get(label);\n }\n }\n\n private setInstance(label: any, instance: any, storageType?: StorageType): void { // Made storageType non-optional\n const isClass = this.isClassType(label); // Determine type based on routing OR decorator\n\n if (isClass) {\n if (storageType === 'singleton') {\n this._classStorageSingleton.set(label, instance);\n } else if (storageType == 'scoped'){ // storageType === 'scoped'\n this._classStorageScoped.set(label, instance);\n }\n } else { // Must be a function\n if (storageType === 'singleton') {\n this._functionStorageSingleton.set(label, instance);\n } else if(storageType === \"scoped\"){ // storageType === 'scoped'\n this._functionStorageScoped.set(label, instance);\n }\n }\n }\n\n private getStorageType(label: any): StorageType {\n let manualLoadAs: LoadAs | undefined;\n let decoratorScope: LoadAs | undefined;\n const isPotentialClass = typeof label === 'function' && label.prototype;\n\n // Get manual registration options if available\n if (this.isRegisteredAsClass(label)) { // Use helper\n manualLoadAs = this._classDefinition.get(label)?.loadAs;\n } else if (this.isRegisteredAsFunction(label)) { // Use helper\n manualLoadAs = this._functionDefinition.get(label)?.options?.loadAs;\n }\n\n // Get decorator scope only if it's potentially a class *and not explicitly registered as a function*\n if (isPotentialClass && !this.isRegisteredAsFunction(label)) {\n decoratorScope = getScope(label); // Uses getComponentOptions internally\n }\n\n // Determine final scope: Manual > Decorator > Default (Transient)\n const finalScope = manualLoadAs ?? decoratorScope ?? LoadAs.Transient;\n\n if (finalScope === LoadAs.Singleton) {\n return 'singleton';\n } else if (finalScope === LoadAs.Scoped) {\n return 'scoped';\n }else{\n return 'transient'; // Transient\n }\n }\n\n // Central resolution logic\n protected async loadInstance(\n label: any,\n params: ParameterValue<any>[] = [],\n resolutionChain: string[] = [] // Track resolution path\n ): Promise<any> {\n\n // --- Circular Dependency Check ---\n const currentLabelStr = (typeof label === 'function' && label.name) ? label.name : String(label);\n if (resolutionChain.includes(currentLabelStr)) {\n console.error(`[IOC LoadInstance] Circular dependency detected: ${[...resolutionChain, currentLabelStr].join(' -> ')}`);\n throw new CircularDependencyError([...resolutionChain, currentLabelStr]);\n }\n const nextResolutionChain = [...resolutionChain, currentLabelStr];\n // --- End Circular Dependency Check ---\n\n // --- Handle Parameters ---\n if (label instanceof Parameter) {\n try {\n // Pass a *copy* of params to avoid side effects in resolveParameterValue\n return Promise.resolve(this.resolveParameterValue(label, [...params]));\n } catch (e) {\n // console.error(`[IOC LoadInstance] Error resolving parameter ${param.toString()}:`, e);\n return Promise.reject(e);\n }\n }\n // --- End Handle Parameters ---\n\n\n // --- Check Explicit Registrations ---\n if (this.isRegisteredAsClass(label)) {\n // console.log(`[IOC LoadInstance] Resolving explicitly registered class: ${currentLabelStr}`);\n return this.loadClassInstance(label, params, nextResolutionChain);\n }\n if (this.isRegisteredAsFunction(label)) {\n // console.log(`[IOC LoadInstance] Resolving explicitly registered function: ${currentLabelStr}`);\n return this.loadFunctionInstance(label, params, nextResolutionChain);\n }\n // --- End Check Explicit Registrations ---\n\n\n // --- Attempt Auto-Registration/Resolution for Decorated Classes ---\n if (typeof label === 'function' && label.prototype) {\n const componentOptions = getComponentOptions(label); // Check for @Component\n if (componentOptions !== null) {\n // console.log(`[IOC LoadInstance] Auto-resolving @Component class: ${currentLabelStr}`);\n // Set routing *now* so subsequent internal checks work correctly\n if (!this._routing.has(label)) { // Only set if not already set\n this._routing.set(label, ContainerRouting.CLASS);\n // console.log(`[IOC LoadInstance] Set routing for auto-resolved class: ${currentLabelStr}`);\n }\n // Proceed to load it as a class\n return this.loadClassInstance(label, params, nextResolutionChain);\n }\n }\n // --- End Auto-Registration ---\n\n\n // --- Dependency Not Found ---\n console.error(`[IOC LoadInstance] Dependency not found and cannot be resolved: ${currentLabelStr}`);\n throw new DependencyNotFoundError(currentLabelStr);\n }\n\n\n private resolveParameterValue(param: Parameter, params: ParameterValue<any>[]): any { // No mutation\n // Find the *last* provided value for the parameter\n const valueContainer = [...params].reverse().find((p) => p.belongsTo(param));\n if (!valueContainer) {\n // console.error(`[IOC ResolveParam] Parameter not found: ${param.toString()}`);\n throw new ParameterNotFoundError(param.toString());\n }\n // console.log(`[IOC ResolveParam] Resolved parameter ${param.toString()}`);\n return valueContainer.value;\n }\n\n private loadClassInstance(\n classDefinition: any, // Should be a class constructor here\n params: ParameterValue<any>[],\n resolutionChain: string[]\n ): Promise<any> {\n const storageType = this.getStorageType(classDefinition);\n const className = classDefinition.name || '[Anonymous Class]';\n\n // Check storage first (handle stored promises)\n if (storageType && this.hasInstance(classDefinition)) {\n const instance = this.getInstance(classDefinition);\n // console.log(`[IOC LoadClass] Found existing ${storageType} instance for ${className}. IsPromise: ${isPromise(instance)}`);\n return instance\n }\n // console.log(`[IOC LoadClass] Creating new ${storageType || 'transient'} instance for ${className}`);\n\n // --- Determine Dependencies ---\n const manualOptions = this._classDefinition.get(classDefinition) as ContainerOptions | undefined;\n let dependenciesToResolve: any[];\n\n if (manualOptions?.param && Array.isArray(manualOptions.param)) {\n dependenciesToResolve = manualOptions.param;\n // console.log(`[IOC LoadClass] Using manual dependencies for ${className}`);\n } else {\n // Use decorator-derived dependencies\n dependenciesToResolve = getResolvedDependencies(classDefinition);\n // console.log(`[IOC LoadClass] Using decorator/reflected dependencies for ${className}:`, dependenciesToResolve.map(d => typeof d === 'function' ? d.name : String(d)));\n }\n // --- End Determine Dependencies ---\n\n\n // --- Resolve Dependencies ---\n // Create a *copy* of params to pass down for dependency resolution\n const paramsCopy = [...params];\n const resolutionPromises = dependenciesToResolve.map(dependencyIdentifier =>\n this.loadInstance(dependencyIdentifier, paramsCopy, resolutionChain) // Recursive call handles auto-registration\n );\n\n let finalInstance = Promise.all(resolutionPromises)\n .catch((error)=>{\n console.error(`[IOC LoadClass] Failed to resolve one or more dependencies for ${className}:`, error);\n // Clean up potential partially stored promise if this was going to be singleton/scoped\n if (storageType && this.isRegisteredAsClass(classDefinition)) { // Check if it was actually *being* stored\n if (storageType === 'singleton') this._classStorageSingleton.delete(classDefinition);\n if (storageType === 'scoped') this._classStorageScoped.delete(classDefinition);\n }\n throw error; // Re-throw dependency resolution error\n }).then(async(resolvedDependencies)=>{\n // --- Instantiate Class ---\n // Store the promise *before* starting instantiation for concurrent requests\n let instancePromise: Promise<any> | undefined;\n if (storageType && !this.hasInstance(classDefinition)) { // Check again in case of race condition?\n // Create the promise wrapper immediately\n instancePromise = (async () => {\n try {\n // console.log(`[IOC LoadClass] Instantiating ${className} with ${resolvedDependencies.length} args.`);\n const instance = new classDefinition(...resolvedDependencies);\n // Overwrite the stored promise with the actual instance *after* it's created\n this.setInstance(classDefinition, instance, storageType); // Use the correct storageType\n // console.log(`[IOC LoadClass] Stored actual ${storageType} instance for ${className}`);\n return instance;\n } catch (err: any) {\n console.error(`[IOC LoadClass] Error during instantiation of ${className}: ${err.message}`, err.stack);\n // Clean up the stored promise on failure\n if (storageType === 'singleton') this._classStorageSingleton.delete(classDefinition);\n if (storageType === 'scoped') this._classStorageScoped.delete(classDefinition);\n throw err; // Re-throw instantiation error\n }\n })();\n // console.log(`[IOC LoadClass] Storing promise for concurrent requests (${storageType}) for ${className}`);\n this.setInstance(classDefinition, instancePromise, storageType);\n } else {\n // If already has instance (from storage check) or is transient, just instantiate directly\n instancePromise = (async () => {\n try {\n // console.log(`[IOC LoadClass] Instantiating transient ${className} with ${resolvedDependencies.length} args.`);\n const instance = new classDefinition(...resolvedDependencies);\n // No storing for transient\n return instance;\n } catch (err: any) {\n console.error(`[IOC LoadClass] Error during instantiation of transient ${className}: ${err.message}`, err.stack);\n throw err; // Re-throw instantiation error\n }\n })();\n }\n // --- End Instantiate Class ---\n // Await and return the final instance (either newly created or from the stored promise)\n return await instancePromise;\n });\n\n if(storageType && storageType !== 'transient'){\n this.setInstance(classDefinition, finalInstance, storageType); // Store the promise\n }\n return finalInstance\n }\n\n private loadFunctionInstance(\n funcLabel: any,\n params: ParameterValue<any>[],\n resolutionChain: string[]\n ): Promise<any> { // Always return Promise<any> since this is an async function\n const functionConfig = this._functionDefinition.get(funcLabel)!; // Assumed to exist by caller\n const storageType = this.getStorageType(funcLabel); // Only uses manual options for functions\n const labelStr = String(funcLabel);\n\n // Check storage first\n if (storageType && this.hasInstance(funcLabel)) {\n const instance = this.getInstance(funcLabel);\n // console.log(`[IOC LoadFunc] Found existing ${storageType} instance for ${labelStr}. IsPromise: ${isPromise(instance)}`);\n return instance;\n }\n // console.log(`[IOC LoadFunc] Creating new ${storageType || 'transient'} instance for ${labelStr}`);\n\n const ioc_func = functionConfig.function;\n const options = functionConfig.options;\n const dependenciesToResolve: any[] = options?.param || [];\n\n // --- Resolve Dependencies ---\n const paramsCopy = [...params]; // Create a copy\n const resolutionPromises = dependenciesToResolve.map(dependencyIdentifier =>\n this.loadInstance(dependencyIdentifier, paramsCopy, resolutionChain)\n );\n\n let finalInstance = Promise.all(resolutionPromises).catch((error)=>{\n console.error(`[IOC LoadFunc] Failed to resolve dependencies for function ${labelStr}:`, error);\n // Clean up potential partial storage\n if (storageType && this.isRegisteredAsFunction(funcLabel)) {\n if (storageType === 'singleton') this._functionStorageSingleton.delete(funcLabel);\n if (storageType === 'scoped') this._functionStorageScoped.delete(funcLabel);\n }\n throw error;\n }).then(async(resolvedArgs)=>{\n let instancePromise: Promise<any> | undefined;\n if (storageType && !this.hasInstance(funcLabel)) {\n instancePromise = (async () => {\n try {\n // console.log(`[IOC LoadFunc] Invoking ${labelStr} with ${resolvedArgs.length} args.`);\n const result = await ioc_func.apply(null, resolvedArgs); // Await in case function is async\n // Overwrite stored promise with actual result\n this.setInstance(funcLabel, result, storageType);\n // console.log(`[IOC LoadFunc] Stored actual ${storageType} instance for ${labelStr}`);\n return result;\n } catch (err: any) {\n console.error(`[IOC LoadFunc] Error executing function ${labelStr}: ${err.message}`, err.stack);\n // Clean up stored promise on failure\n if (storageType === 'singleton') this._functionStorageSingleton.delete(funcLabel);\n if (storageType === 'scoped') this._functionStorageScoped.delete(funcLabel);\n throw err;\n }\n })();\n // console.log(`[IOC LoadFunc] Storing promise for concurrent requests (${storageType}) for ${labelStr}`);\n this.setInstance(funcLabel, instancePromise, storageType);\n } else {\n // Transient or already resolved from storage check\n instancePromise = (async () => {\n try {\n // console.log(`[IOC LoadFunc] Invoking transient ${labelStr} with ${resolvedArgs.length} args.`);\n const result = await ioc_func.apply(null, resolvedArgs); // Await in case function is async\n // No storing for transient\n return result;\n } catch (err: any) {\n console.error(`[IOC LoadFunc] Error executing transient function ${labelStr}: ${err.message}`, err.stack);\n throw err;\n }\n })();\n }\n // --- End Invoke Function ---\n\n return await instancePromise; // Return the final (awaited) result\n });\n\n if(storageType && storageType !== 'transient'){\n this.setInstance(funcLabel, finalInstance, storageType); // Store the promise\n }\n\n return finalInstance;\n }\n}\n\n// Helper functions\nexport function isPromise(obj: any): obj is Promise<any> {\n // Simplified check - more robust check might be needed depending on environment\n return !!obj && typeof obj.then === 'function';\n}\n\nexport function createContainer(): IContainerClient & IContainerSetup {\n return new Container();\n}\n"],"mappings":"AAAA,OAAO;AAEP,SAAS,cAAc;AACvB,SAAS,iBAAiB;AAE1B,SAAS,0BAA0B,wBAAwB,yBAAyB,yBAAyB,+BAA+B;AAC5I;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,OACG;AAEP,IAAK,mBAAL,kBAAKA,sBAAL;AACI,EAAAA,kBAAA,gBAAa;AACb,EAAAA,kBAAA,WAAQ;AAFP,SAAAA;AAAA,GAAA;AAQE,MAAM,UAAuD;AAAA,EAA7D;AAEH;AAAA,SAAQ,WAAuC,oBAAI,IAAI;AACvD,SAAQ,sBAA8D,oBAAI,IAAI;AAC9E,SAAQ,mBAA6D,oBAAI,IAAI;AAG7E;AAAA,SAAQ,4BAA2C,oBAAI,IAAI;AAC3D,SAAQ,yBAAwC,oBAAI,IAAI;AACxD,SAAQ,yBAA6C,oBAAI,IAAI;AAC7D,SA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names":["ContainerRouting"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../framework/implementation/DecoratorSupport.ts"],"sourcesContent":["// framework/implementation/DecoratorSupport.ts\nimport 'reflect-metadata';\nimport type { ComponentOptions } from '../decorators/Component';\nimport { COMPONENT_OPTIONS_METADATA_KEY, INJECT_TOKEN_METADATA_KEY, PARAM_TYPES_METADATA_KEY } from '../decorators/metadataKeys';\nimport { LoadAs } from './LoadAs';\n\n/**\n * Gets component options from a class decorated with @Component.\n * Checks both Symbol and string keys for compatibility/debugging.\n */\nexport function getComponentOptions(target: any): ComponentOptions | null {\n if (!target || typeof target !== 'function') return null;\n\n // Prioritize the Symbol key\n let options = Reflect.getMetadata(COMPONENT_OPTIONS_METADATA_KEY, target);\n\n // Fallback to the string key if Symbol key didn't return anything\n if (options === undefined || options === null) { // Check explicitly for undefined/null\n options = Reflect.getMetadata('ComponentOptions', target);\n }\n\n // console.log(`[DecoratorSupport getComponentOptions] for ${target.name}:`, options);\n return options || null; // Return null if no options found with either key\n}\n\n\n/**\n * Gets the scope from a class decorated with @Component.\n */\nexport function getScope(target: any): LoadAs {\n const options = getComponentOptions(target);\n // Default to Transient if no options or no scope specified\n const scope = options?.scope ?? LoadAs.Transient;\n // console.log(`[DecoratorSupport getScope] for ${target.name}:`, scope);\n return scope;\n}\n\n/**\n * Gets the parameter types for a class constructor using TypeScript metadata.\n */\nexport function getParameterTypes(target: any): any[] {\n if (!target || typeof target !== 'function') return [];\n const types = Reflect.getMetadata(PARAM_TYPES_METADATA_KEY, target) || [];\n // console.log(`[DecoratorSupport getParameterTypes] for ${target.name}:`, types);\n return types;\n}\n\n/**\n * Gets the explicitly injected tokens for a class constructor using @Inject.\n */\nexport function getInjectTokens(target: any): Map<number, any> {\n if (!target || typeof target !== 'function') return new Map();\n const tokens = Reflect.getOwnMetadata(INJECT_TOKEN_METADATA_KEY, target) || new Map();\n // console.log(`[DecoratorSupport getInjectTokens] for ${target.name}:`, tokens);\n return tokens;\n}\n\n/**\n * Gets the final list of dependencies to resolve for a constructor,\n * prioritizing @Inject tokens over reflected types.\n */\nexport function getResolvedDependencies(target: any): any[] {\n if (!target || typeof target !== 'function') return [];\n\n const paramTypes = getParameterTypes(target);\n const injectTokens = getInjectTokens(target);\n\n const size = Math.max(paramTypes.length, injectTokens.size);\n\n Array.from({ length: size })\n\n const dependencies = Array.from({ length: size }).map((_, index) => {\n // If an @Inject token exists for this parameter index, use it.\n if (injectTokens.has(index)) {\n return injectTokens.get(index);\n }\n\n let type = paramTypes.length > index ? paramTypes[index] : undefined;\n // Otherwise, use the reflected type.\n // Handle potential 'undefined' types from reflection if interfaces are used without @Inject\n if (type === undefined) {\n console.warn(`[IOC DecoratorSupport] Reflected parameter type at index ${index} for ${target.name} is undefined. This might indicate an interface used without @Inject.`);\n // Depending on strictness, could throw or return a special marker. Returning undefined for now.\n }\n return type;\n });\n // console.log(`[DecoratorSupport getResolvedDependencies] for ${target.name}:`, dependencies);\n return dependencies;\n}\n\n// Optional: Combine metadata fetching if needed frequently elsewhere\nexport interface ClassMetadata {\n hasComponent: boolean;\n scope: LoadAs;\n dependencies: any[];\n}\n\nexport function getClassMetadata(target: any): ClassMetadata {\n const options = getComponentOptions(target);\n return {\n hasComponent: !!options,\n scope: getScope(target), // Uses getComponentOptions internally\n dependencies: getResolvedDependencies(target) // Uses helpers internally\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,8BAAO;AAEP,0BAAoG;AACpG,oBAAuB;AAMhB,SAAS,oBAAoB,QAAsC;AACtE,MAAI,CAAC,UAAU,OAAO,WAAW,WAAY,QAAO;AAGpD,MAAI,UAAU,QAAQ,YAAY,oDAAgC,MAAM;AAGxE,MAAI,YAAY,UAAa,YAAY,MAAM;AAC3C,cAAU,QAAQ,YAAY,oBAAoB,MAAM;AAAA,EAC5D;AAGA,SAAO,WAAW;AACtB;A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AAA;AAAA,EAChD;AACJ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../framework/implementation/DecoratorSupport.ts"],"sourcesContent":["// framework/implementation/DecoratorSupport.ts\nimport 'reflect-metadata';\nimport type { ComponentOptions } from '../decorators/Component.cjs';\nimport { COMPONENT_OPTIONS_METADATA_KEY, INJECT_TOKEN_METADATA_KEY, PARAM_TYPES_METADATA_KEY } from '../decorators/metadataKeys.cjs';\nimport { LoadAs } from './LoadAs.cjs';\n\n/**\n * Gets component options from a class decorated with @Component.\n * Checks both Symbol and string keys for compatibility/debugging.\n */\nexport function getComponentOptions(target: any): ComponentOptions | null {\n if (!target || typeof target !== 'function') return null;\n\n // Prioritize the Symbol key\n let options = Reflect.getMetadata(COMPONENT_OPTIONS_METADATA_KEY, target);\n\n // Fallback to the string key if Symbol key didn't return anything\n if (options === undefined || options === null) { // Check explicitly for undefined/null\n options = Reflect.getMetadata('ComponentOptions', target);\n }\n\n // console.log(`[DecoratorSupport getComponentOptions] for ${target.name}:`, options);\n return options || null; // Return null if no options found with either key\n}\n\n\n/**\n * Gets the scope from a class decorated with @Component.\n */\nexport function getScope(target: any): LoadAs {\n const options = getComponentOptions(target);\n // Default to Transient if no options or no scope specified\n const scope = options?.scope ?? LoadAs.Transient;\n // console.log(`[DecoratorSupport getScope] for ${target.name}:`, scope);\n return scope;\n}\n\n/**\n * Gets the parameter types for a class constructor using TypeScript metadata.\n */\nexport function getParameterTypes(target: any): any[] {\n if (!target || typeof target !== 'function') return [];\n const types = Reflect.getMetadata(PARAM_TYPES_METADATA_KEY, target) || [];\n // console.log(`[DecoratorSupport getParameterTypes] for ${target.name}:`, types);\n return types;\n}\n\n/**\n * Gets the explicitly injected tokens for a class constructor using @Inject.\n */\nexport function getInjectTokens(target: any): Map<number, any> {\n if (!target || typeof target !== 'function') return new Map();\n const tokens = Reflect.getOwnMetadata(INJECT_TOKEN_METADATA_KEY, target) || new Map();\n // console.log(`[DecoratorSupport getInjectTokens] for ${target.name}:`, tokens);\n return tokens;\n}\n\n/**\n * Gets the final list of dependencies to resolve for a constructor,\n * prioritizing @Inject tokens over reflected types.\n */\nexport function getResolvedDependencies(target: any): any[] {\n if (!target || typeof target !== 'function') return [];\n\n const paramTypes = getParameterTypes(target);\n const injectTokens = getInjectTokens(target);\n\n const size = Math.max(paramTypes.length, injectTokens.size);\n\n Array.from({ length: size })\n\n const dependencies = Array.from({ length: size }).map((_, index) => {\n // If an @Inject token exists for this parameter index, use it.\n if (injectTokens.has(index)) {\n return injectTokens.get(index);\n }\n\n let type = paramTypes.length > index ? paramTypes[index] : undefined;\n // Otherwise, use the reflected type.\n // Handle potential 'undefined' types from reflection if interfaces are used without @Inject\n if (type === undefined) {\n console.warn(`[IOC DecoratorSupport] Reflected parameter type at index ${index} for ${target.name} is undefined. This might indicate an interface used without @Inject.`);\n // Depending on strictness, could throw or return a special marker. Returning undefined for now.\n }\n return type;\n });\n // console.log(`[DecoratorSupport getResolvedDependencies] for ${target.name}:`, dependencies);\n return dependencies;\n}\n\n// Optional: Combine metadata fetching if needed frequently elsewhere\nexport interface ClassMetadata {\n hasComponent: boolean;\n scope: LoadAs;\n dependencies: any[];\n}\n\nexport function getClassMetadata(target: any): ClassMetadata {\n const options = getComponentOptions(target);\n return {\n hasComponent: !!options,\n scope: getScope(target), // Uses getComponentOptions internally\n dependencies: getResolvedDependencies(target) // Uses helpers internally\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,8BAAO;AAEP,0BAAoG;AACpG,oBAAuB;AAMhB,SAAS,oBAAoB,QAAsC;AACtE,MAAI,CAAC,UAAU,OAAO,WAAW,WAAY,QAAO;AAGpD,MAAI,UAAU,QAAQ,YAAY,oDAAgC,MAAM;AAGxE,MAAI,YAAY,UAAa,YAAY,MAAM;AAC3C,cAAU,QAAQ,YAAY,oBAAoB,MAAM;AAAA,EAC5D;AAGA,SAAO,WAAW;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MAAM;AAAA;AAAA,EAChD;AACJ;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../framework/implementation/DecoratorSupport.ts"],"sourcesContent":["// framework/implementation/DecoratorSupport.ts\nimport 'reflect-metadata';\nimport type { ComponentOptions } from '../decorators/Component';\nimport { COMPONENT_OPTIONS_METADATA_KEY, INJECT_TOKEN_METADATA_KEY, PARAM_TYPES_METADATA_KEY } from '../decorators/metadataKeys';\nimport { LoadAs } from './LoadAs';\n\n/**\n * Gets component options from a class decorated with @Component.\n * Checks both Symbol and string keys for compatibility/debugging.\n */\nexport function getComponentOptions(target: any): ComponentOptions | null {\n if (!target || typeof target !== 'function') return null;\n\n // Prioritize the Symbol key\n let options = Reflect.getMetadata(COMPONENT_OPTIONS_METADATA_KEY, target);\n\n // Fallback to the string key if Symbol key didn't return anything\n if (options === undefined || options === null) { // Check explicitly for undefined/null\n options = Reflect.getMetadata('ComponentOptions', target);\n }\n\n // console.log(`[DecoratorSupport getComponentOptions] for ${target.name}:`, options);\n return options || null; // Return null if no options found with either key\n}\n\n\n/**\n * Gets the scope from a class decorated with @Component.\n */\nexport function getScope(target: any): LoadAs {\n const options = getComponentOptions(target);\n // Default to Transient if no options or no scope specified\n const scope = options?.scope ?? LoadAs.Transient;\n // console.log(`[DecoratorSupport getScope] for ${target.name}:`, scope);\n return scope;\n}\n\n/**\n * Gets the parameter types for a class constructor using TypeScript metadata.\n */\nexport function getParameterTypes(target: any): any[] {\n if (!target || typeof target !== 'function') return [];\n const types = Reflect.getMetadata(PARAM_TYPES_METADATA_KEY, target) || [];\n // console.log(`[DecoratorSupport getParameterTypes] for ${target.name}:`, types);\n return types;\n}\n\n/**\n * Gets the explicitly injected tokens for a class constructor using @Inject.\n */\nexport function getInjectTokens(target: any): Map<number, any> {\n if (!target || typeof target !== 'function') return new Map();\n const tokens = Reflect.getOwnMetadata(INJECT_TOKEN_METADATA_KEY, target) || new Map();\n // console.log(`[DecoratorSupport getInjectTokens] for ${target.name}:`, tokens);\n return tokens;\n}\n\n/**\n * Gets the final list of dependencies to resolve for a constructor,\n * prioritizing @Inject tokens over reflected types.\n */\nexport function getResolvedDependencies(target: any): any[] {\n if (!target || typeof target !== 'function') return [];\n\n const paramTypes = getParameterTypes(target);\n const injectTokens = getInjectTokens(target);\n\n const size = Math.max(paramTypes.length, injectTokens.size);\n\n Array.from({ length: size })\n\n const dependencies = Array.from({ length: size }).map((_, index) => {\n // If an @Inject token exists for this parameter index, use it.\n if (injectTokens.has(index)) {\n return injectTokens.get(index);\n }\n\n let type = paramTypes.length > index ? paramTypes[index] : undefined;\n // Otherwise, use the reflected type.\n // Handle potential 'undefined' types from reflection if interfaces are used without @Inject\n if (type === undefined) {\n console.warn(`[IOC DecoratorSupport] Reflected parameter type at index ${index} for ${target.name} is undefined. This might indicate an interface used without @Inject.`);\n // Depending on strictness, could throw or return a special marker. Returning undefined for now.\n }\n return type;\n });\n // console.log(`[DecoratorSupport getResolvedDependencies] for ${target.name}:`, dependencies);\n return dependencies;\n}\n\n// Optional: Combine metadata fetching if needed frequently elsewhere\nexport interface ClassMetadata {\n hasComponent: boolean;\n scope: LoadAs;\n dependencies: any[];\n}\n\nexport function getClassMetadata(target: any): ClassMetadata {\n const options = getComponentOptions(target);\n return {\n hasComponent: !!options,\n scope: getScope(target), // Uses getComponentOptions internally\n dependencies: getResolvedDependencies(target) // Uses helpers internally\n };\n}\n"],"mappings":"AACA,OAAO;AAEP,SAAS,gCAAgC,2BAA2B,gCAAgC;AACpG,SAAS,cAAc;AAMhB,SAAS,oBAAoB,QAAsC;AACtE,MAAI,CAAC,UAAU,OAAO,WAAW,WAAY,QAAO;AAGpD,MAAI,UAAU,QAAQ,YAAY,gCAAgC,MAAM;AAGxE,MAAI,YAAY,UAAa,YAAY,MAAM;AAC3C,cAAU,QAAQ,YAAY,oBAAoB,MAAM;AAAA,EAC5D;AAGA,SAAO,WAAW;AACtB;AAMO,SAAS,SAAS,QAAqB;AAC1C,QA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
1
|
+
{"version":3,"sources":["../../../framework/implementation/DecoratorSupport.ts"],"sourcesContent":["// framework/implementation/DecoratorSupport.ts\nimport 'reflect-metadata';\nimport type { ComponentOptions } from '../decorators/Component.js';\nimport { COMPONENT_OPTIONS_METADATA_KEY, INJECT_TOKEN_METADATA_KEY, PARAM_TYPES_METADATA_KEY } from '../decorators/metadataKeys.js';\nimport { LoadAs } from './LoadAs.js';\n\n/**\n * Gets component options from a class decorated with @Component.\n * Checks both Symbol and string keys for compatibility/debugging.\n */\nexport function getComponentOptions(target: any): ComponentOptions | null {\n if (!target || typeof target !== 'function') return null;\n\n // Prioritize the Symbol key\n let options = Reflect.getMetadata(COMPONENT_OPTIONS_METADATA_KEY, target);\n\n // Fallback to the string key if Symbol key didn't return anything\n if (options === undefined || options === null) { // Check explicitly for undefined/null\n options = Reflect.getMetadata('ComponentOptions', target);\n }\n\n // console.log(`[DecoratorSupport getComponentOptions] for ${target.name}:`, options);\n return options || null; // Return null if no options found with either key\n}\n\n\n/**\n * Gets the scope from a class decorated with @Component.\n */\nexport function getScope(target: any): LoadAs {\n const options = getComponentOptions(target);\n // Default to Transient if no options or no scope specified\n const scope = options?.scope ?? LoadAs.Transient;\n // console.log(`[DecoratorSupport getScope] for ${target.name}:`, scope);\n return scope;\n}\n\n/**\n * Gets the parameter types for a class constructor using TypeScript metadata.\n */\nexport function getParameterTypes(target: any): any[] {\n if (!target || typeof target !== 'function') return [];\n const types = Reflect.getMetadata(PARAM_TYPES_METADATA_KEY, target) || [];\n // console.log(`[DecoratorSupport getParameterTypes] for ${target.name}:`, types);\n return types;\n}\n\n/**\n * Gets the explicitly injected tokens for a class constructor using @Inject.\n */\nexport function getInjectTokens(target: any): Map<number, any> {\n if (!target || typeof target !== 'function') return new Map();\n const tokens = Reflect.getOwnMetadata(INJECT_TOKEN_METADATA_KEY, target) || new Map();\n // console.log(`[DecoratorSupport getInjectTokens] for ${target.name}:`, tokens);\n return tokens;\n}\n\n/**\n * Gets the final list of dependencies to resolve for a constructor,\n * prioritizing @Inject tokens over reflected types.\n */\nexport function getResolvedDependencies(target: any): any[] {\n if (!target || typeof target !== 'function') return [];\n\n const paramTypes = getParameterTypes(target);\n const injectTokens = getInjectTokens(target);\n\n const size = Math.max(paramTypes.length, injectTokens.size);\n\n Array.from({ length: size })\n\n const dependencies = Array.from({ length: size }).map((_, index) => {\n // If an @Inject token exists for this parameter index, use it.\n if (injectTokens.has(index)) {\n return injectTokens.get(index);\n }\n\n let type = paramTypes.length > index ? paramTypes[index] : undefined;\n // Otherwise, use the reflected type.\n // Handle potential 'undefined' types from reflection if interfaces are used without @Inject\n if (type === undefined) {\n console.warn(`[IOC DecoratorSupport] Reflected parameter type at index ${index} for ${target.name} is undefined. This might indicate an interface used without @Inject.`);\n // Depending on strictness, could throw or return a special marker. Returning undefined for now.\n }\n return type;\n });\n // console.log(`[DecoratorSupport getResolvedDependencies] for ${target.name}:`, dependencies);\n return dependencies;\n}\n\n// Optional: Combine metadata fetching if needed frequently elsewhere\nexport interface ClassMetadata {\n hasComponent: boolean;\n scope: LoadAs;\n dependencies: any[];\n}\n\nexport function getClassMetadata(target: any): ClassMetadata {\n const options = getComponentOptions(target);\n return {\n hasComponent: !!options,\n scope: getScope(target), // Uses getComponentOptions internally\n dependencies: getResolvedDependencies(target) // Uses helpers internally\n };\n}\n"],"mappings":"AACA,OAAO;AAEP,SAAS,gCAAgC,2BAA2B,gCAAgC;AACpG,SAAS,cAAc;AAMhB,SAAS,oBAAoB,QAAsC;AACtE,MAAI,CAAC,UAAU,OAAO,WAAW,WAAY,QAAO;AAGpD,MAAI,UAAU,QAAQ,YAAY,gCAAgC,MAAM;AAGxE,MAAI,YAAY,UAAa,YAAY,MAAM;AAC3C,cAAU,QAAQ,YAAY,oBAAoB,MAAM;AAAA,EAC5D;AAGA,SAAO,WAAW;AACtB;AAMO,SAAS,SAAS,QAAqB;AAC1C,QAAM,UAAU,oBAAoB,MAAM;AAE1C,QAAM,QAAQ,SAAS,SAAS,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.ts"],"sourcesContent":["import type { ParameterValue } from \"../implementation/Parameter\"\nimport type { LoadAs } from \"../implementation/LoadAs\"\n\r\nexport interface IContainerClient {\r\n instance<T, Args extends any[]>(classDefinition: new (...args: Args) => T,params?:ParameterValue<any>[]): Promise<T>\r\n get<T>(label:any,param?:ParameterValue<any>[]):Promise<T>|T\r\n extend(): IContainerClient\r\n}\r\n\r\n\r\nexport interface IContainerSetup{\r\n registerClass<T, Args extends any[]>(classDefinition: { new (...args: Args): T }, options?: Partial<ContainerOptions>): void\r\n registerFunction<T extends (...arg:any[])=>any>(label:any,func: T, options?: ContainerOptions): void\r\n}\r\n\r\n\r\nexport type IContainer = IContainerClient & IContainerSetup\r\n\r\nexport type ContainerOptions = {\r\n param?: any[]\r\n loadAs?: LoadAs\r\n}\r\n\r\n\r\nexport interface IContainerFunctionDefinition{\r\n function:Function\r\n options:Partial<ContainerOptions>\r\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../framework/interface/Container.ts"],"sourcesContent":["import type { ParameterValue } from \"../implementation/Parameter.cjs\"\nimport type { LoadAs } from \"../implementation/LoadAs.cjs\"\n\r\nexport interface IContainerClient {\r\n instance<T, Args extends any[]>(classDefinition: new (...args: Args) => T,params?:ParameterValue<any>[]): Promise<T>\r\n get<T>(label:any,param?:ParameterValue<any>[]):Promise<T>|T\r\n extend(): IContainerClient\r\n}\r\n\r\n\r\nexport interface IContainerSetup{\r\n registerClass<T, Args extends any[]>(classDefinition: { new (...args: Args): T }, options?: Partial<ContainerOptions>): void\r\n registerFunction<T extends (...arg:any[])=>any>(label:any,func: T, options?: ContainerOptions): void\r\n}\r\n\r\n\r\nexport type IContainer = IContainerClient & IContainerSetup\r\n\r\nexport type ContainerOptions = {\r\n param?: any[]\r\n loadAs?: LoadAs\r\n}\r\n\r\n\r\nexport interface IContainerFunctionDefinition{\r\n function:Function\r\n options:Partial<ContainerOptions>\r\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../index.ts"],"sourcesContent":["import 'reflect-metadata';\nimport { createContainer } from \"./framework/implementation/Container\"\nimport { Container } from \"./framework/implementation/Container\"\nimport { LoadAs } from \"./framework/implementation/LoadAs\"\nimport { Parameter } from \"./framework/implementation/Parameter\"\nimport type { IContainer, IContainerClient, IContainerSetup } from \"./framework/interface/Container\"\nimport { NotAClassDefinitionError, ParameterNotFoundError, DependencyNotFoundError, InstanceNotCreatedError, CircularDependencyError } from \"./framework/errors/ContainerErrors\"\nimport { Component, Inject } from \"./framework/decorators/index\"\n\nexport type { IContainer, IContainerClient, IContainerSetup }\nexport { LoadAs }\nexport { Parameter }\nexport { Container }\nexport { NotAClassDefinitionError, ParameterNotFoundError, DependencyNotFoundError, InstanceNotCreatedError, CircularDependencyError }\nexport { Component, Inject }\nexport { createContainer } from \"./framework/implementation/Container\"\nexport default createContainer\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAAO;AACP,uBAAgC;AAChC,IAAAA,oBAA0B;AAC1B,oBAAuB;AACvB,uBAA0B;AAE1B,6BAA4I;AAC5I,wBAAkC;AAQlC,IAAAA,oBAAgC;AAChC,IAAO,gBAAQ;","names":["import_Container"]}
|
|
1
|
+
{"version":3,"sources":["../index.ts"],"sourcesContent":["import 'reflect-metadata';\nimport { createContainer } from \"./framework/implementation/Container.cjs\"\nimport { Container } from \"./framework/implementation/Container.cjs\"\nimport { LoadAs } from \"./framework/implementation/LoadAs.cjs\"\nimport { Parameter } from \"./framework/implementation/Parameter.cjs\"\nimport type { IContainer, IContainerClient, IContainerSetup } from \"./framework/interface/Container.cjs\"\nimport { NotAClassDefinitionError, ParameterNotFoundError, DependencyNotFoundError, InstanceNotCreatedError, CircularDependencyError } from \"./framework/errors/ContainerErrors.cjs\"\nimport { Component, Inject } from \"./framework/decorators/index.cjs\"\n\nexport type { IContainer, IContainerClient, IContainerSetup }\nexport { LoadAs }\nexport { Parameter }\nexport { Container }\nexport { NotAClassDefinitionError, ParameterNotFoundError, DependencyNotFoundError, InstanceNotCreatedError, CircularDependencyError }\nexport { Component, Inject }\nexport { createContainer } from \"./framework/implementation/Container.cjs\"\nexport default createContainer\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAAO;AACP,uBAAgC;AAChC,IAAAA,oBAA0B;AAC1B,oBAAuB;AACvB,uBAA0B;AAE1B,6BAA4I;AAC5I,wBAAkC;AAQlC,IAAAA,oBAAgC;AAChC,IAAO,gBAAQ;","names":["import_Container"]}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../index.ts"],"sourcesContent":["import 'reflect-metadata';\nimport { createContainer } from \"./framework/implementation/Container\"\nimport { Container } from \"./framework/implementation/Container\"\nimport { LoadAs } from \"./framework/implementation/LoadAs\"\nimport { Parameter } from \"./framework/implementation/Parameter\"\nimport type { IContainer, IContainerClient, IContainerSetup } from \"./framework/interface/Container\"\nimport { NotAClassDefinitionError, ParameterNotFoundError, DependencyNotFoundError, InstanceNotCreatedError, CircularDependencyError } from \"./framework/errors/ContainerErrors\"\nimport { Component, Inject } from \"./framework/decorators/index\"\n\nexport type { IContainer, IContainerClient, IContainerSetup }\nexport { LoadAs }\nexport { Parameter }\nexport { Container }\nexport { NotAClassDefinitionError, ParameterNotFoundError, DependencyNotFoundError, InstanceNotCreatedError, CircularDependencyError }\nexport { Component, Inject }\nexport { createContainer } from \"./framework/implementation/Container\"\nexport default createContainer\n"],"mappings":"AAAA,OAAO;AACP,SAAS,uBAAuB;AAChC,SAAS,iBAAiB;AAC1B,SAAS,cAAc;AACvB,SAAS,iBAAiB;AAE1B,SAAS,0BAA0B,wBAAwB,yBAAyB,yBAAyB,+BAA+B;AAC5I,SAAS,WAAW,cAAc;AAQlC,SAAS,mBAAAA,wBAAuB;AAChC,IAAO,gBAAQ;","names":["createContainer"]}
|
|
1
|
+
{"version":3,"sources":["../index.ts"],"sourcesContent":["import 'reflect-metadata';\nimport { createContainer } from \"./framework/implementation/Container.js\"\nimport { Container } from \"./framework/implementation/Container.js\"\nimport { LoadAs } from \"./framework/implementation/LoadAs.js\"\nimport { Parameter } from \"./framework/implementation/Parameter.js\"\nimport type { IContainer, IContainerClient, IContainerSetup } from \"./framework/interface/Container.js\"\nimport { NotAClassDefinitionError, ParameterNotFoundError, DependencyNotFoundError, InstanceNotCreatedError, CircularDependencyError } from \"./framework/errors/ContainerErrors.js\"\nimport { Component, Inject } from \"./framework/decorators/index.js\"\n\nexport type { IContainer, IContainerClient, IContainerSetup }\nexport { LoadAs }\nexport { Parameter }\nexport { Container }\nexport { NotAClassDefinitionError, ParameterNotFoundError, DependencyNotFoundError, InstanceNotCreatedError, CircularDependencyError }\nexport { Component, Inject }\nexport { createContainer } from \"./framework/implementation/Container.js\"\nexport default createContainer\n"],"mappings":"AAAA,OAAO;AACP,SAAS,uBAAuB;AAChC,SAAS,iBAAiB;AAC1B,SAAS,cAAc;AACvB,SAAS,iBAAiB;AAE1B,SAAS,0BAA0B,wBAAwB,yBAAyB,yBAAyB,+BAA+B;AAC5I,SAAS,WAAW,cAAc;AAQlC,SAAS,mBAAAA,wBAAuB;AAChC,IAAO,gBAAQ;","names":["createContainer"]}
|
package/package.json
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noego/ioc",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "A self contained IoC container for Node.js",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "dist/index.
|
|
7
|
-
"module": "dist/index.js",
|
|
6
|
+
"main": "dist/index.js",
|
|
8
7
|
"types": "dist/index.d.ts",
|
|
9
8
|
"scripts": {
|
|
10
9
|
"test": "jest --silent",
|
|
11
10
|
"build": "tsup && node scripts/fix-import-extensions.mjs",
|
|
11
|
+
"verify:esm": "node scripts/verify-esm.mjs",
|
|
12
|
+
"verify:cjs": "node scripts/verify-cjs.cjs",
|
|
13
|
+
"ci": "npm run typecheck && npm test && npm run build && npm run verify:esm && npm run verify:cjs",
|
|
12
14
|
"prepublishOnly": "npm run build",
|
|
13
15
|
"typecheck": "tsc --noEmit"
|
|
14
16
|
},
|