@js-injection/service-provider 1.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md ADDED
@@ -0,0 +1,15 @@
1
+ The ISC License
2
+
3
+ Copyright (c) Peter Flannery and Contributors
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
15
+ IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # Type-Safe Dependency Injection Container
2
+
3
+ [![Pipeline status](https://gitlab.com/js-injection/service-provider/badges/master/pipeline.svg)](https://gitlab.com/js-injection/service-provider/-/pipelines)
4
+ [![NPM version](https://img.shields.io/npm/v/%40js-injection/service-provider.svg)](https://www.npmjs.org/package/%40js-injection/service-provider)
5
+ [![NPM downloads](https://img.shields.io/npm/dm/%40js-injection/service-provider.svg)](https://npmjs.org/package/%40js-injection/service-provider "View this project on NPM")
6
+
7
+ [![BuyMeACoffee](https://www.buymeacoffee.com/assets/img/custom_images/purple_img.png)](https://www.buymeacoffee.com/peterf)
8
+
9
+ A lightweight, fully type-safe Dependency Injection (DI) container for TypeScript. Designed for reliability, developer experience, and minification safety.
10
+
11
+ ## Table of Contents
12
+ - [Overview](#overview)
13
+ - [Key Features](#key-features)
14
+ - [Basic Usage](#basic-usage)
15
+ - [Cheatsheet](docs/CHEATSHEET.md)
16
+ - [Development](#development)
17
+ - [License](#license)
18
+
19
+ ## Overview
20
+
21
+ This project provides a robust DI container that leverages TypeScript's powerful type system to ensure that your dependencies are always resolved correctly. It focuses on a "Pure DI" approach, where dependencies are ideally resolved at the composition root.
22
+
23
+ ## Key Features
24
+
25
+ - **Strict Type Safety**: Full Intellisense and compile-time validation for all registered services.
26
+ - **Multiple Lifetimes**: Support for `Singleton` (global) and `Scoped` (per-context) services.
27
+ - **Async Support**: Seamless integration with asynchronous factories and functions, including async disposal.
28
+ - **Circular Dependency Detection**: Immediate, descriptive errors if a circular dependency is detected during resolution.
29
+ - **Minification Proof**: Built-in stable identity system ensures that resolution by Class reference works even when class names are mangled.
30
+ - **Zero Runtime Dependencies**: A lean implementation with no external dependencies.
31
+
32
+ ## Basic Usage
33
+
34
+ ```typescript
35
+ import { ServiceCollection } from '@js-injection/service-provider';
36
+
37
+ interface ILogger { log(msg: string): void; }
38
+
39
+ class ConsoleLogger implements ILogger { log(msg: string) { console.log(msg); } }
40
+
41
+ class UserService {
42
+ constructor(public logger: ILogger) {}
43
+ }
44
+
45
+ // 1. Define your container structure
46
+ interface MyMap {
47
+ logger: ILogger;
48
+ userService: UserService;
49
+ }
50
+
51
+ // 2. Register services
52
+ const sp = new ServiceCollection<MyMap>()
53
+ .addSingletonFactory('logger', () => new ConsoleLogger())
54
+ .addSingletonClass(UserService, 'logger') // Injecting by key
55
+ .build();
56
+
57
+ // 3. Resolve services
58
+ const userService = sp.getService(UserService);
59
+ const logger = sp.getService('logger');
60
+ ```
61
+
62
+ ## Development
63
+
64
+ - **Build**: `npm run bundle`
65
+ - **Test**: `npm test`
66
+ - **Smoke Tests**: `npm start` (Runs end-to-end scenarios against bundled code)
67
+
68
+ ## License
69
+
70
+ Licensed under [ISC](http://opensource.org/licenses/ISC).
71
+
72
+ Copyright &copy; 2026+ [contributors](https://gitlab.com/js-injection/service-provider/-/graphs/master)
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ var h=class extends Error{constructor(e){super(`Circular dependency detected: ${e}`),this.name="CircularDependencyError"}},p=class extends Error{constructor(e){super(`Service not registered for identifier: ${e}`),this.name="ServiceNotFoundError"}},l=class extends Error{constructor(e){super(e),this.name="RegistrationError"}},m=class extends Error{constructor(){super("ServiceProvider has been disposed and cannot resolve services."),this.name="ServiceProviderDisposedError"}},f=class extends Error{constructor(e){super(`Service "${e}" requires asynchronous disposal but a synchronous dispose was called. Please use await disposeAsync() instead.`),this.name="AsyncDisposalError"}};var v=new WeakMap;function c(y){let e=v.get(y);return e||(e=Symbol(y.name||"AnonymousClass"),v.set(y,e)),e}var u=class y{constructor(e,t,s,n=!1){this.name=e;this.definitions=t;this.parent=s;this.isAsyncScope=n}instances=new Map;resolving=new Set;path=[];disposed=!1;createScope(e="scope"){let t=this.parent||this;return new y(e,this.definitions,t,!1)}createAsyncScope(e="async-scope"){let t=this.parent||this;return new y(e,this.definitions,t,!0)}getService(e){if(this.disposed)throw new m;let t=this.getKey(e);if(this.parent&&this.definitions[t]?.lifetime==="singleton")return this.parent.getService(t);let s=this.definitions[t];if(!s){let i=typeof e=="string"||typeof e=="symbol"?String(e):e.name||String(e);throw new p(i)}let n=s.uid;if(this.instances.has(n))return this.instances.get(n);if(this.resolving.has(n)){let i=this.path.map(r=>typeof r=="symbol"?r.description||String(r):r).concat(typeof t=="symbol"?t.description||String(t):t).join(" -> ");throw new h(i)}this.resolving.add(n),this.path.push(t);try{return s.kind==="value"?this.resolveValue(n,s.value):Array.isArray(s.type)?this.resolveArray(n,s.type):s.kind==="function"&&s.func?this.resolveFunc(n,s.func,s.params):s.factory?this.resolveFactory(n,s.factory):this.resolveClass(n,s.type,s.params)}finally{this.resolving.delete(n),this.path.pop()}}dispose(){if(this.disposed)return;if(this.isAsyncScope)throw new f(this.name);this.disposed=!0;let e=Array.from(this.instances.entries()).reverse();for(let[t,s]of e)if(s&&typeof s.dispose=="function"){if(s.dispose()instanceof Promise)throw new f(typeof t=="symbol"&&t.description||String(t))}else if(s&&typeof s.disposeAsync=="function")throw new f(typeof t=="symbol"&&t.description||String(t));this.instances.clear()}async disposeAsync(){if(this.disposed)return;this.disposed=!0;let e=Array.from(this.instances.values()).reverse();for(let t of e)if(t&&typeof t.disposeAsync=="function")await t.disposeAsync();else if(t&&typeof t.dispose=="function"){let s=t.dispose();s instanceof Promise&&await s}this.instances.clear()}resolveValue(e,t){return this.instances.set(e,t),t}resolveArray(e,t){let s=t.map(n=>this.getService(n));return this.instances.set(e,s),s}resolveFactory(e,t){let s=this.createContainerProxy(),n=t(s,this);return this.instances.set(e,n),n}resolveFunc(e,t,s){let i=(s||[]).map(o=>{let a=this.tryGetKey(o);return a?this.getService(a):o}),r=t(...i);return this.instances.set(e,r),r}resolveClass(e,t,s){let i=(s||[]).map(o=>{let a=this.tryGetKey(o);return a?this.getService(a):o}),r=new t(...i);return this.instances.set(e,r),r}createContainerProxy(){return new Proxy({},{get:(e,t)=>{if(!(typeof t!="string"&&typeof t!="symbol"))return this.getService(t)}})}getKey(e){if(typeof e=="string"||typeof e=="symbol")return e;let t=this.tryGetKey(e);if(t)return t;let s=Array.isArray(e)?`[${e.map(n=>n.name).join(", ")}]`:e.name||String(e);throw new p(s)}tryGetKey(e){if(typeof e=="string"||typeof e=="symbol"){if(e in this.definitions)return e;if(typeof e=="string"){let t=Reflect.ownKeys(this.definitions).find(s=>{let n=this.definitions[s];return n.kind==="service"&&!Array.isArray(n.type)&&n.type?.name===e});if(t)return t}return}if(typeof e=="function"||Array.isArray(e)){let t=c(e);if(t in this.definitions)return t;let s=Reflect.ownKeys(this.definitions).find(n=>{let i=this.definitions[n];return i.kind==="service"&&i.type===e});if(s)return s}}};var K=class{definitions={};typeMap;constructor(){this.typeMap={}}addSingletonFactory(e,t){let s,n,i=!1;if(typeof e=="string"||typeof e=="symbol")s=e,n=this.typeMap[s],i=!0;else{let a=this.resolveKeyAndType(e);s=a.key,n=a.type}let r=i?s:c(n),o={kind:"service",lifetime:"singleton",uid:r,type:n,factory:t};return this.definitions[s]=o,s!==r&&(this.definitions[r]=o),this}addServiceProvider(e){return this.addSingletonFactory(e,(t,s)=>s)}addScopedFactory(e,t){let s,n,i=!1;if(typeof e=="string"||typeof e=="symbol")s=e,n=this.typeMap[s],i=!0;else{let a=this.resolveKeyAndType(e);s=a.key,n=a.type}let r=i?s:c(n),o={kind:"service",lifetime:"scoped",uid:r,type:n,factory:t};return this.definitions[s]=o,s!==r&&(this.definitions[r]=o),this}addSingletonClass(e,...t){let{key:s,type:n}=this.resolveKeyAndType(e),i=c(n),r={kind:"service",lifetime:"singleton",uid:i,type:n,params:t};return this.definitions[s]=r,this.definitions[i]=r,this}addScopedClass(e,...t){let{key:s,type:n}=this.resolveKeyAndType(e),i=c(n),r={kind:"service",lifetime:"scoped",uid:i,type:n,params:t};return this.definitions[s]=r,this.definitions[i]=r,this}addSingletonArray(e,...t){let s={kind:"service",lifetime:"singleton",uid:e,type:t};this.typeMap[e]=t,this.definitions[e]=s;let n=t;for(let i of n){if(Reflect.ownKeys(this.typeMap).find(g=>this.typeMap[g]===i))continue;let o=i.name;if(!o)throw new l(`Class in array "${String(e)}" is missing a name and cannot be auto-registered.`);let a=c(i),d={kind:"service",lifetime:"singleton",uid:a,type:i,params:[]};this.typeMap[o]=i,this.definitions[o]=d,this.definitions[a]=d}return this}addScopedArray(e,...t){let s={kind:"service",lifetime:"scoped",uid:e,type:t};this.typeMap[e]=t,this.definitions[e]=s;let n=t;for(let i of n){if(Reflect.ownKeys(this.typeMap).find(g=>this.typeMap[g]===i))continue;let o=i.name;if(!o)throw new l(`Class in array "${String(e)}" is missing a name and cannot be auto-registered.`);let a=c(i),d={kind:"service",lifetime:"scoped",uid:a,type:i,params:[]};this.typeMap[o]=i,this.definitions[o]=d,this.definitions[a]=d}return this}addSingletonFunc(e,t,...s){return this.definitions[e]={kind:"function",lifetime:"singleton",uid:e,func:t,params:s},this}addScopedFunc(e,t,...s){return this.definitions[e]={kind:"function",lifetime:"scoped",uid:e,func:t,params:s},this}addSingletonValue(e,t){return this.definitions[e]={kind:"value",lifetime:"singleton",uid:e,value:t},this}addScopedValue(e,t){return this.definitions[e]={kind:"value",lifetime:"scoped",uid:e,value:t},this}resolveKeyAndType(e){let t,s=Reflect.ownKeys(this.typeMap).find(n=>this.typeMap[n]===e);return s?t=s:(t=e.name||c(e),this.typeMap[t]=e),{key:t,type:e}}build(e="root"){for(let t of Reflect.ownKeys(this.definitions)){let s=this.definitions[t];if(!(s.kind!=="service"||!Array.isArray(s.type)))for(let n of s.type){let i=n.name,r=this.definitions[i];if(r&&r.params&&r.params.length===0&&n.length>0)throw new l(`Class "${i}" in array "${String(t)}" requires constructor arguments and must be registered independently using addSingletonClass or addScopedClass.`)}}return new u(e,this.definitions)}};export{f as AsyncDisposalError,h as CircularDependencyError,l as RegistrationError,K as ServiceCollection,p as ServiceNotFoundError,u as ServiceProvider,m as ServiceProviderDisposedError};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/errors.ts", "../src/registry.ts", "../src/service-provider.ts", "../src/service-collection.ts"],
4
+ "sourcesContent": ["/**\n * Thrown when a circular dependency is detected.\n */\nexport class CircularDependencyError extends Error {\n constructor(path: string) {\n super(`Circular dependency detected: ${path}`);\n this.name = 'CircularDependencyError';\n }\n}\n\n/**\n * Thrown when a service cannot be resolved.\n */\nexport class ServiceNotFoundError extends Error {\n constructor(identifier: string) {\n super(`Service not registered for identifier: ${identifier}`);\n this.name = 'ServiceNotFoundError';\n }\n}\n\n/**\n * Thrown when a registration is invalid.\n */\nexport class RegistrationError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'RegistrationError';\n }\n}\n\n/**\n * Thrown when a service provider has been disposed.\n */\nexport class ServiceProviderDisposedError extends Error {\n constructor() {\n super('ServiceProvider has been disposed and cannot resolve services.');\n this.name = 'ServiceProviderDisposedError';\n }\n}\n\n/**\n * Thrown when a synchronous dispose is called on a scope containing services that require asynchronous disposal.\n */\nexport class AsyncDisposalError extends Error {\n constructor(serviceKey: string) {\n super(`Service \"${serviceKey}\" requires asynchronous disposal but a synchronous dispose was called. Please use await disposeAsync() instead.`);\n this.name = 'AsyncDisposalError';\n }\n}\n", "import type { Class } from './types.js';\r\n\r\nconst classKeyRegistry = new WeakMap<Class, symbol>();\r\n\r\n/**\r\n * Resolves a stable Symbol for a given class constructor.\r\n * This is used to ensure that DI resolution remains stable even after minification.\r\n * @param type The class constructor.\r\n */\r\nexport function getStableKey(type: Class): symbol {\r\n let key = classKeyRegistry.get(type);\r\n if (!key) {\r\n key = Symbol(type.name || 'AnonymousClass');\r\n classKeyRegistry.set(type, key);\r\n }\r\n return key;\r\n}\r\n", "import {\n AsyncDisposalError,\n CircularDependencyError,\n ServiceNotFoundError,\n ServiceProviderDisposedError,\n} from './errors.js';\nimport { getStableKey } from './registry.js';\nimport type {\n Class,\n ConcreteClass,\n ImplementationFactory,\n IServiceProvider,\n MapToInstance,\n ResolvedTypeMap,\n ServiceDefinitionMap,\n TypeMap,\n} from './types.js';\n\nexport class ServiceProvider<T extends TypeMap> implements IServiceProvider<T> {\n private instances = new Map<string | symbol, any>();\n private resolving = new Set<string | symbol>();\n private path: (string | symbol)[] = [];\n private disposed = false;\n\n /**\n * @param name The name of the service provider.\n * @param definitions The service definitions map.\n * @param parent The parent service provider, if any.\n * @param isAsyncScope Whether this is an asynchronous scope.\n */\n constructor(\n public readonly name: string,\n private definitions: ServiceDefinitionMap,\n private parent?: ServiceProvider<T>,\n private readonly isAsyncScope: boolean = false\n ) { }\n\n /**\n * Creates a new scoped ServiceProvider.\n * @param name The name of the scope.\n * @example\n * const scope = di.createScope('request-scope');\n */\n createScope(name: string = 'scope'): IServiceProvider<T> {\n const root = this.parent || this;\n return new ServiceProvider<T>(name, this.definitions, root, false);\n }\n\n /**\n * Creates a new scoped ServiceProvider that supports asynchronous disposal.\n * @param name The name of the scope.\n * @example\n * const scope = di.createAsyncScope('worker-scope');\n */\n createAsyncScope(name: string = 'async-scope'): IServiceProvider<T> {\n const root = this.parent || this;\n return new ServiceProvider<T>(name, this.definitions, root, true);\n }\n\n /**\n * Resolves a service by its key.\n * @param key The key to resolve.\n * @example\n * const logger = di.getService('Logger');\n */\n getService<K extends keyof T & (string | symbol)>(key: K): MapToInstance<T[K]>;\n\n /**\n * Resolves a service by its Class type.\n * @param type The class type to resolve.\n * @example\n * const logger = di.getService(Logger);\n */\n getService<C extends Class>(type: C): InstanceType<C>;\n\n getService<K extends keyof T & (string | symbol)>(keyOrType: K | T[K]): MapToInstance<T[K]> {\n if (this.disposed) {\n throw new ServiceProviderDisposedError();\n }\n\n const key = this.getKey(keyOrType);\n\n if (this.parent && this.definitions[key]?.lifetime === 'singleton') {\n return this.parent.getService(key as any);\n }\n\n const item = this.definitions[key];\n if (!item) {\n const name = (typeof keyOrType === 'string' || typeof keyOrType === 'symbol')\n ? String(keyOrType)\n : (keyOrType as any).name || String(keyOrType);\n throw new ServiceNotFoundError(name);\n }\n\n const uid = item.uid;\n\n if (this.instances.has(uid)) {\n return this.instances.get(uid);\n }\n\n if (this.resolving.has(uid)) {\n const pathStr = this.path.map(k => (typeof k === 'symbol' ? k.description || String(k) : k)).concat(typeof key === 'symbol' ? key.description || String(key) : key).join(' -> ');\n throw new CircularDependencyError(pathStr);\n }\n\n this.resolving.add(uid);\n this.path.push(key);\n\n try {\n if (item.kind === 'value') return this.resolveValue(uid, item.value);\n\n if (Array.isArray(item.type)) return this.resolveArray(uid, item.type);\n\n if (item.kind === 'function' && item.func) return this.resolveFunc(uid, item.func, item.params);\n\n if (item.factory) return this.resolveFactory(uid, item.factory);\n\n return this.resolveClass(uid, item.type as Class, item.params);\n } finally {\n this.resolving.delete(uid);\n this.path.pop();\n }\n }\n\n /**\n * Synchronously disposes of all resolved services.\n * Throws AsyncDisposalError if this is an async scope or if any service disposal returns a Promise.\n */\n dispose(): void {\n if (this.disposed) return;\n\n if (this.isAsyncScope) {\n throw new AsyncDisposalError(this.name);\n }\n\n this.disposed = true;\n\n const entries = Array.from(this.instances.entries()).reverse();\n\n for (const [uid, inst] of entries) {\n if (inst && typeof inst.dispose === 'function') {\n const result = inst.dispose();\n if (result instanceof Promise) {\n throw new AsyncDisposalError(typeof uid === 'symbol' ? uid.description || String(uid) : String(uid));\n }\n } else if (inst && typeof inst.disposeAsync === 'function') {\n throw new AsyncDisposalError(typeof uid === 'symbol' ? uid.description || String(uid) : String(uid));\n }\n }\n\n this.instances.clear();\n }\n\n /**\n * Asynchronously disposes of all resolved services.\n */\n async disposeAsync(): Promise<void> {\n if (this.disposed) return;\n this.disposed = true;\n\n const entries = Array.from(this.instances.values()).reverse();\n\n for (const inst of entries) {\n if (inst && typeof inst.disposeAsync === 'function') {\n await inst.disposeAsync();\n } else if (inst && typeof inst.dispose === 'function') {\n const result = inst.dispose();\n if (result instanceof Promise) {\n await result;\n }\n }\n }\n\n this.instances.clear();\n }\n\n /**\n * Resolves a singleton value.\n * @param uid The unique ID of the value.\n * @param value The value to resolve.\n */\n private resolveValue(uid: string | symbol, value: any): any {\n this.instances.set(uid, value);\n return value;\n }\n\n /**\n * Resolves an array of services.\n * @param uid The unique ID of the service array.\n * @param types The class types to resolve for the array.\n */\n private resolveArray(uid: string | symbol, types: Class[]): any {\n const instances = types.map((cls) => {\n const inst = this.getService(cls);\n return inst;\n });\n\n this.instances.set(uid, instances);\n return instances;\n }\n\n /**\n * Resolves a service via a factory.\n * @param uid The unique ID of the service.\n * @param factory The factory to use for resolution.\n */\n private resolveFactory(uid: string | symbol, factory: ImplementationFactory<any, any>): any {\n const container = this.createContainerProxy();\n const result = factory(container, this);\n this.instances.set(uid, result);\n return result;\n }\n\n /**\n * Resolves a service via a function.\n * @param uid The unique ID of the service.\n * @param func The function to use for resolution.\n * @param params The arguments for the function.\n */\n private resolveFunc(uid: string | symbol, func: (...args: any[]) => any, params?: any[]): any {\n const rawParams = params || [];\n const resolvedParams = rawParams.map((param) => {\n const paramKey = this.tryGetKey(param);\n const inst = paramKey ? this.getService(paramKey) : param;\n return inst;\n });\n\n const result = func(...resolvedParams);\n this.instances.set(uid, result);\n return result;\n }\n\n /**\n * Resolves a service via its class type.\n * @param uid The unique ID of the service.\n * @param type The class type to instantiate.\n * @param params The constructor arguments.\n */\n private resolveClass(uid: string | symbol, type: Class, params?: any[]): any {\n const rawParams = params || [];\n const resolvedParams = rawParams.map((param) => {\n const paramKey = this.tryGetKey(param);\n const inst = paramKey ? this.getService(paramKey) : param;\n return inst;\n });\n\n const instance = new (type as ConcreteClass)(...resolvedParams);\n this.instances.set(uid, instance);\n return instance;\n }\n\n /**\n * Creates a proxy for the type map to allow resolving services by property access.\n */\n private createContainerProxy(): ResolvedTypeMap<T> {\n return new Proxy({} as ResolvedTypeMap<T>, {\n get: (_, prop) => {\n if (typeof prop !== 'string' && typeof prop !== 'symbol') return undefined;\n return this.getService(prop as any);\n }\n });\n }\n\n /**\n * Gets the key for a given key or class type.\n * @param keyOrType The key or class type.\n */\n private getKey<K extends keyof T & (string | symbol)>(keyOrType: K | T[K]): string | symbol {\n if (typeof keyOrType === 'string' || typeof keyOrType === 'symbol') return keyOrType;\n\n const key = this.tryGetKey(keyOrType);\n if (key) return key;\n\n const name = Array.isArray(keyOrType)\n ? `[${keyOrType.map((c: any) => (c as any).name).join(', ')}]`\n : (keyOrType as any).name || String(keyOrType);\n throw new ServiceNotFoundError(name);\n }\n\n /**\n * Attempts to get the key for a given key or class type without throwing.\n * @param keyOrType The key or class type.\n */\n private tryGetKey(keyOrType: any): string | symbol | undefined {\n if (typeof keyOrType === 'string' || typeof keyOrType === 'symbol') {\n if (keyOrType in this.definitions) return keyOrType;\n \n // Fallback for string names (backward compatibility)\n if (typeof keyOrType === 'string') {\n const entry = Reflect.ownKeys(this.definitions).find((k) => {\n const v = this.definitions[k as any];\n return v.kind === 'service' && !Array.isArray(v.type) && (v.type as any)?.name === keyOrType;\n });\n if (entry) return entry as string | symbol;\n }\n return undefined;\n }\n\n if (typeof keyOrType === 'function' || Array.isArray(keyOrType)) {\n // Check the stable registry first (minification proof)\n const stableKey = getStableKey(keyOrType as any);\n if (stableKey in this.definitions) return stableKey;\n\n // Fallback to searching by reference (for explicit symbols or non-auto registrations)\n const entry = Reflect.ownKeys(this.definitions).find((k) => {\n const v = this.definitions[k as any];\n return v.kind === 'service' && v.type === keyOrType;\n });\n if (entry) return entry as string | symbol;\n }\n\n return undefined;\n }\n}\n", "import {\n RegistrationError,\n} from './errors.js';\nimport { getStableKey } from './registry.js';\nimport { ServiceProvider } from './service-provider.js';\nimport type {\n Class,\n ClassArgs,\n FilterKeys,\n FilterValueKeys,\n FilterFuncKeys,\n FuncArgs,\n ImplementationFactory,\n MapToInstance,\n ServiceDefinitionMap,\n TypeMap,\n ServiceDefinition\n} from './types.js';\n\n/**\n * Fluent builder for service collections using a lookup map.\n */\nexport class ServiceCollection<T extends TypeMap> {\n private definitions: ServiceDefinitionMap = {};\n private typeMap: T;\n\n /**\n * Initializes a new instance of the ServiceCollection class.\n */\n constructor() {\n this.typeMap = {} as T;\n }\n\n /**\n * Adds a singleton service using a factory function.\n * Key is derived from the class.\n * @param type The class to register.\n * @param factory The factory function to create the service instance.\n * @example\n * .addSingletonFactory(UserRepo, (c) => new UserRepo(c.UserService))\n */\n addSingletonFactory<Key extends keyof T & (string | symbol), C extends Class>(\n type: C,\n factory: ImplementationFactory<T, InstanceType<C>>\n ): this;\n\n /**\n * Adds a singleton service using a factory function and a key.\n * @param key The key to register the service under.\n * @param factory The factory function to create the service instance.\n * @example\n * .addSingletonFactory(\"UserRepo\", (c) => new UserRepo(c.UserService))\n */\n addSingletonFactory<Key extends keyof T & (string | symbol)>(\n key: Key,\n factory: ImplementationFactory<T, MapToInstance<T[Key]>>\n ): this;\n\n addSingletonFactory<Key extends keyof T & (string | symbol)>(\n keyOrType: Key | Class,\n factory: ImplementationFactory<T, any>\n ): this {\n let key: string | symbol;\n let type: any;\n let isExplicitKey = false;\n\n if (typeof keyOrType === 'string' || typeof keyOrType === 'symbol') {\n key = keyOrType;\n type = this.typeMap[key];\n isExplicitKey = true;\n } else {\n const resolved = this.resolveKeyAndType<Key>(keyOrType as any);\n key = resolved.key;\n type = resolved.type;\n }\n\n const uid = isExplicitKey ? key : getStableKey(type);\n const def: ServiceDefinition<any> = { kind: 'service', lifetime: 'singleton', uid, type, factory };\n this.definitions[key] = def;\n if (key !== uid) this.definitions[uid] = def;\n\n return this;\n }\n\n /**\n * Registers the ServiceProvider itself as a service.\n * This allows services to depend on the ServiceProvider to resolve other services dynamically.\n * @param key The key to register the ServiceProvider under.\n * @example\n * .addServiceProvider(\"ServiceProvider\")\n */\n addServiceProvider<Key extends keyof T & (string | symbol)>(key: Key) {\n return this.addSingletonFactory(key as any, (_, sp) => sp)\n }\n\n /**\n * Adds a scoped service using a factory function.\n * Key is derived from the class.\n * @param type The class to register.\n * @param factory The factory function to create the service instance.\n * @example\n * .addScopedFactory(UserRepo, (c) => new UserRepo(c.UserService))\n */\n addScopedFactory<Key extends keyof T & (string | symbol), C extends Class>(\n type: C,\n factory: ImplementationFactory<T, InstanceType<C>>\n ): this;\n\n /**\n * Adds a scoped service using a factory function and a key.\n * @param key The key to register the service under.\n * @param factory The factory function to create the service instance.\n * @example\n * .addScopedFactory(\"UserRepo\", (c) => new UserRepo(c.UserService))\n */\n addScopedFactory<Key extends keyof T & (string | symbol)>(\n key: Key,\n factory: ImplementationFactory<T, MapToInstance<T[Key]>>\n ): this;\n\n addScopedFactory<Key extends keyof T & (string | symbol)>(\n keyOrType: Key | Class,\n factory: ImplementationFactory<T, any>\n ): this {\n let key: string | symbol;\n let type: any;\n let isExplicitKey = false;\n\n if (typeof keyOrType === 'string' || typeof keyOrType === 'symbol') {\n key = keyOrType;\n type = this.typeMap[key];\n isExplicitKey = true;\n } else {\n const resolved = this.resolveKeyAndType<Key>(keyOrType as any);\n key = resolved.key;\n type = resolved.type;\n }\n\n const uid = isExplicitKey ? key : getStableKey(type);\n const def: ServiceDefinition<any> = { kind: 'service', lifetime: 'scoped', uid, type, factory };\n this.definitions[key] = def;\n if (key !== uid) this.definitions[uid] = def;\n\n return this;\n }\n\n /**\n * Adds a singleton service using constructor injection.\n * Key is derived from the container map based on the Class.\n * @param type The class to register.\n * @param params The constructor arguments.\n * @example\n * .addSingletonClass(UserService, \"admin\", \"password\")\n */\n addSingletonClass<C extends Class>(\n type: C,\n ...params: ClassArgs<C, keyof T & (string | symbol)>\n ): this {\n const { key, type: typeRef } = this.resolveKeyAndType(type as any);\n const uid = getStableKey(typeRef);\n const def: ServiceDefinition<any> = { kind: 'service', lifetime: 'singleton', uid, type: typeRef, params };\n this.definitions[key] = def;\n this.definitions[uid] = def;\n return this;\n }\n\n /**\n * Adds a scoped service using constructor injection.\n * Key is derived from the container map based on the Class.\n * @param type The class to register.\n * @param params The constructor arguments.\n * @example\n * .addScopedClass(UserService, \"admin\", \"password\")\n */\n addScopedClass<C extends Class>(\n type: C,\n ...params: ClassArgs<C, keyof T & (string | symbol)>\n ): this {\n const { key, type: typeRef } = this.resolveKeyAndType(type as any);\n const uid = getStableKey(typeRef);\n const def: ServiceDefinition<any> = { kind: 'service', lifetime: 'scoped', uid, type: typeRef, params };\n this.definitions[key] = def;\n this.definitions[uid] = def;\n return this;\n }\n\n /**\n * Adds an array of singleton services.\n * Automatically registers individual classes if not already registered.\n * @param key The key for the service array.\n * @param types The classes to register in the array.\n * @example\n * .addSingletonArray(\"MessageCommand\", HelloCommand, ByeCommand)\n */\n addSingletonArray<\n Key extends FilterKeys<T, any[]>,\n C extends (new (...args: any[]) => MapToInstance<T[Key]>[number])[]\n >(\n key: Key,\n ...types: C\n ): this {\n const def: ServiceDefinition<any> = { kind: 'service', lifetime: 'singleton', uid: key, type: types };\n (this.typeMap as any)[key] = types;\n this.definitions[key] = def;\n\n // Auto-register individual classes if not already registered\n const typeArray = types as Class[];\n for (const type of typeArray) {\n const foundKey = Reflect.ownKeys(this.typeMap).find(k => this.typeMap[k as any] === type);\n if (foundKey) continue;\n\n const name = type.name;\n if (!name) {\n throw new RegistrationError(`Class in array \"${String(key)}\" is missing a name and cannot be auto-registered.`);\n }\n\n const uid = getStableKey(type);\n const classDef: ServiceDefinition<any> = { kind: 'service', lifetime: 'singleton', uid, type, params: [] };\n (this.typeMap as any)[name] = type;\n this.definitions[name] = classDef;\n this.definitions[uid] = classDef;\n }\n\n return this;\n }\n\n /**\n * Adds an array of scoped services.\n * Automatically registers individual classes as scoped if not already registered.\n * @param key The key for the service array.\n * @param types The classes to register in the array.\n * @example\n * .addScopedArray(\"MessageCommand\", HelloCommand, ByeCommand)\n */\n addScopedArray<\n Key extends FilterKeys<T, any[]>,\n C extends (new (...args: any[]) => MapToInstance<T[Key]>[number])[]\n >(\n key: Key,\n ...types: C\n ): this {\n const def: ServiceDefinition<any> = { kind: 'service', lifetime: 'scoped', uid: key, type: types };\n (this.typeMap as any)[key] = types;\n this.definitions[key] = def;\n\n // Auto-register individual classes if not already registered\n const typeArray = types as Class[];\n for (const type of typeArray) {\n const foundKey = Reflect.ownKeys(this.typeMap).find(k => this.typeMap[k as any] === type);\n if (foundKey) continue;\n\n const name = type.name;\n if (!name) {\n throw new RegistrationError(`Class in array \"${String(key)}\" is missing a name and cannot be auto-registered.`);\n }\n\n const uid = getStableKey(type);\n const classDef: ServiceDefinition<any> = { kind: 'service', lifetime: 'scoped', uid, type, params: [] };\n (this.typeMap as any)[name] = type;\n this.definitions[name] = classDef;\n this.definitions[uid] = classDef;\n }\n\n return this;\n }\n\n /**\n * Adds a singleton service using a function.\n * @param key The key for the service.\n * @param func The function to register.\n * @param params The function arguments.\n * @example\n * .addSingletonFunc(\"Logger\", createLogger, \"Config\")\n */\n addSingletonFunc<Key extends FilterFuncKeys<T>, F extends (...args: any[]) => T[Key]>(\n key: Key,\n func: F,\n ...params: FuncArgs<F, T>\n ): this {\n this.definitions[key] = { kind: 'function', lifetime: 'singleton', uid: key, func, params };\n return this;\n }\n\n /**\n * Adds a scoped service using a function.\n * @param key The key for the service.\n * @param func The function to register.\n * @param params The function arguments.\n * @example\n * .addScopedFunc(\"Logger\", createLogger, \"Config\")\n */\n addScopedFunc<Key extends FilterFuncKeys<T>, F extends (...args: any[]) => T[Key]>(\n key: Key,\n func: F,\n ...params: FuncArgs<F, T>\n ): this {\n this.definitions[key] = { kind: 'function', lifetime: 'scoped', uid: key, func, params };\n return this;\n }\n\n /**\n * Adds a singleton value.\n * @param key The key for the value.\n * @param value The value to register.\n * @example\n * .addSingletonValue(\"connectionString\", \"test connection string\")\n */\n addSingletonValue<Key extends FilterValueKeys<T>>(\n key: Key,\n value: T[Key]\n ): this {\n this.definitions[key] = { kind: 'value', lifetime: 'singleton', uid: key, value };\n return this;\n }\n\n /**\n * Adds a scoped value.\n * @param key The key for the value.\n * @param value The value to register.\n * @example\n * .addScopedValue(\"connectionString\", \"test connection string\")\n */\n addScopedValue<Key extends FilterValueKeys<T>>(\n key: Key,\n value: T[Key]\n ): this {\n this.definitions[key] = { kind: 'value', lifetime: 'scoped', uid: key, value };\n return this;\n }\n\n /**\n * Resolves the string key and Class reference for a given type.\n * If the type is already mapped in the TypeMap, the existing key is used.\n * Otherwise, it auto-registers the type using its class name as the key.\n * @param type The class reference to resolve.\n * @throws RegistrationError if the class name cannot be determined (e.g. anonymous class).\n * @example\n * const { key, type } = this.resolveKeyAndType(UserService);\n */\n private resolveKeyAndType<Key extends keyof T & (string | symbol)>(type: T[Key] & Class): { key: Key, type: T[Key] } {\n let key: Key;\n\n const foundKey = Reflect.ownKeys(this.typeMap).find(\n (k) => this.typeMap[k as any] === type\n );\n if (foundKey) {\n key = foundKey as Key;\n } else {\n // Auto-register using class name for backward compatibility\n key = (type.name || getStableKey(type)) as any as Key;\n (this.typeMap as any)[key] = type;\n }\n\n return { key, type };\n }\n\n /**\n * Builds the ServiceProvider.\n * @param name The name of the service provider.\n * @example\n * const di = new ServiceCollection<LocalMap>()\n * .addSingletonClass(MyService)\n * .build();\n */\n build(name: string = 'root'): ServiceProvider<T> {\n // Validate all registered services\n for (const key of Reflect.ownKeys(this.definitions)) {\n const item = this.definitions[key as any];\n if (item.kind !== 'service' || !Array.isArray(item.type)) continue;\n\n // This is an array of services\n for (const type of item.type as Class[]) {\n const name = type.name;\n const definitionsItem = this.definitions[name];\n\n // Check if this class was auto-registered (params is empty array) but requires arguments\n if (definitionsItem && definitionsItem.params && definitionsItem.params.length === 0 && type.length > 0) {\n throw new RegistrationError(`Class \"${name}\" in array \"${String(key)}\" requires constructor arguments and must be registered independently using addSingletonClass or addScopedClass.`);\n }\n }\n }\n\n return new ServiceProvider<T>(name, this.definitions);\n }\n}\n"],
5
+ "mappings": "AAGO,IAAMA,EAAN,cAAsC,KAAM,CACjD,YAAYC,EAAc,CACxB,MAAM,iCAAiCA,CAAI,EAAE,EAC7C,KAAK,KAAO,yBACd,CACF,EAKaC,EAAN,cAAmC,KAAM,CAC9C,YAAYC,EAAoB,CAC9B,MAAM,0CAA0CA,CAAU,EAAE,EAC5D,KAAK,KAAO,sBACd,CACF,EAKaC,EAAN,cAAgC,KAAM,CAC3C,YAAYC,EAAiB,CAC3B,MAAMA,CAAO,EACb,KAAK,KAAO,mBACd,CACF,EAKaC,EAAN,cAA2C,KAAM,CACtD,aAAc,CACZ,MAAM,gEAAgE,EACtE,KAAK,KAAO,8BACd,CACF,EAKaC,EAAN,cAAiC,KAAM,CAC5C,YAAYC,EAAoB,CAC9B,MAAM,YAAYA,CAAU,iHAAiH,EAC7I,KAAK,KAAO,oBACd,CACF,EC9CA,IAAMC,EAAmB,IAAI,QAOtB,SAASC,EAAaC,EAAqB,CAChD,IAAIC,EAAMH,EAAiB,IAAIE,CAAI,EACnC,OAAKC,IACHA,EAAM,OAAOD,EAAK,MAAQ,gBAAgB,EAC1CF,EAAiB,IAAIE,EAAMC,CAAG,GAEzBA,CACT,CCEO,IAAMC,EAAN,MAAMC,CAAkE,CAY7E,Y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AAAD,EAAK,KAAAC,CAAK,CACrB,CAUA,MAAMa,EAAe,OAA4B,CAE/C,QAAWd,KAAO,QAAQ,QAAQ,KAAK,WAAW,EAAG,CACnD,IAAMoB,EAAO,KAAK,YAAYpB,CAAU,EACxC,GAAI,EAAAoB,EAAK,OAAS,WAAa,CAAC,MAAM,QAAQA,EAAK,IAAI,GAGvD,QAAWnB,KAAQmB,EAAK,KAAiB,CACvC,IAAMN,EAAOb,EAAK,KACZoB,EAAkB,KAAK,YAAYP,CAAI,EAG7C,GAAIO,GAAmBA,EAAgB,QAAUA,EAAgB,OAAO,SAAW,GAAKpB,EAAK,OAAS,EACpG,MAAM,IAAIc,EAAkB,UAAUD,CAAI,eAAe,OAAOd,CAAG,CAAC,kHAAkH,CAE1L,CACF,CAEA,OAAO,IAAIsB,EAAmBR,EAAM,KAAK,WAAW,CACtD,CACF",
6
+ "names": ["CircularDependencyError", "path", "ServiceNotFoundError", "identifier", "RegistrationError", "message", "ServiceProviderDisposedError", "AsyncDisposalError", "serviceKey", "classKeyRegistry", "getStableKey", "type", "key", "ServiceProvider", "_ServiceProvider", "name", "definitions", "parent", "isAsyncScope", "root", "keyOrType", "ServiceProviderDisposedError", "key", "item", "ServiceNotFoundError", "uid", "pathStr", "k", "CircularDependencyError", "AsyncDisposalError", "entries", "inst", "result", "value", "types", "instances", "cls", "factory", "container", "func", "params", "resolvedParams", "param", "paramKey", "type", "instance", "_", "prop", "c", "entry", "v", "stableKey", "getStableKey", "ServiceCollection", "keyOrType", "factory", "key", "type", "isExplicitKey", "resolved", "uid", "getStableKey", "def", "_", "sp", "params", "typeRef", "types", "typeArray", "k", "name", "RegistrationError", "classDef", "func", "value", "foundKey", "item", "definitionsItem", "ServiceProvider"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var v=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var x=(o,e)=>{for(var t in e)v(o,t,{get:e[t],enumerable:!0})},w=(o,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of b(e))!T.call(o,n)&&n!==t&&v(o,n,{get:()=>e[n],enumerable:!(s=C(e,n))||s.enumerable});return o};var F=o=>w(v({},"__esModule",{value:!0}),o);var A={};x(A,{AsyncDisposalError:()=>f,CircularDependencyError:()=>h,RegistrationError:()=>l,ServiceCollection:()=>K,ServiceNotFoundError:()=>p,ServiceProvider:()=>u,ServiceProviderDisposedError:()=>m});module.exports=F(A);var h=class extends Error{constructor(e){super(`Circular dependency detected: ${e}`),this.name="CircularDependencyError"}},p=class extends Error{constructor(e){super(`Service not registered for identifier: ${e}`),this.name="ServiceNotFoundError"}},l=class extends Error{constructor(e){super(e),this.name="RegistrationError"}},m=class extends Error{constructor(){super("ServiceProvider has been disposed and cannot resolve services."),this.name="ServiceProviderDisposedError"}},f=class extends Error{constructor(e){super(`Service "${e}" requires asynchronous disposal but a synchronous dispose was called. Please use await disposeAsync() instead.`),this.name="AsyncDisposalError"}};var S=new WeakMap;function c(o){let e=S.get(o);return e||(e=Symbol(o.name||"AnonymousClass"),S.set(o,e)),e}var u=class o{constructor(e,t,s,n=!1){this.name=e;this.definitions=t;this.parent=s;this.isAsyncScope=n}instances=new Map;resolving=new Set;path=[];disposed=!1;createScope(e="scope"){let t=this.parent||this;return new o(e,this.definitions,t,!1)}createAsyncScope(e="async-scope"){let t=this.parent||this;return new o(e,this.definitions,t,!0)}getService(e){if(this.disposed)throw new m;let t=this.getKey(e);if(this.parent&&this.definitions[t]?.lifetime==="singleton")return this.parent.getService(t);let s=this.definitions[t];if(!s){let i=typeof e=="string"||typeof e=="symbol"?String(e):e.name||String(e);throw new p(i)}let n=s.uid;if(this.instances.has(n))return this.instances.get(n);if(this.resolving.has(n)){let i=this.path.map(r=>typeof r=="symbol"?r.description||String(r):r).concat(typeof t=="symbol"?t.description||String(t):t).join(" -> ");throw new h(i)}this.resolving.add(n),this.path.push(t);try{return s.kind==="value"?this.resolveValue(n,s.value):Array.isArray(s.type)?this.resolveArray(n,s.type):s.kind==="function"&&s.func?this.resolveFunc(n,s.func,s.params):s.factory?this.resolveFactory(n,s.factory):this.resolveClass(n,s.type,s.params)}finally{this.resolving.delete(n),this.path.pop()}}dispose(){if(this.disposed)return;if(this.isAsyncScope)throw new f(this.name);this.disposed=!0;let e=Array.from(this.instances.entries()).reverse();for(let[t,s]of e)if(s&&typeof s.dispose=="function"){if(s.dispose()instanceof Promise)throw new f(typeof t=="symbol"&&t.description||String(t))}else if(s&&typeof s.disposeAsync=="function")throw new f(typeof t=="symbol"&&t.description||String(t));this.instances.clear()}async disposeAsync(){if(this.disposed)return;this.disposed=!0;let e=Array.from(this.instances.values()).reverse();for(let t of e)if(t&&typeof t.disposeAsync=="function")await t.disposeAsync();else if(t&&typeof t.dispose=="function"){let s=t.dispose();s instanceof Promise&&await s}this.instances.clear()}resolveValue(e,t){return this.instances.set(e,t),t}resolveArray(e,t){let s=t.map(n=>this.getService(n));return this.instances.set(e,s),s}resolveFactory(e,t){let s=this.createContainerProxy(),n=t(s,this);return this.instances.set(e,n),n}resolveFunc(e,t,s){let i=(s||[]).map(a=>{let y=this.tryGetKey(a);return y?this.getService(y):a}),r=t(...i);return this.instances.set(e,r),r}resolveClass(e,t,s){let i=(s||[]).map(a=>{let y=this.tryGetKey(a);return y?this.getService(y):a}),r=new t(...i);return this.instances.set(e,r),r}createContainerProxy(){return new Proxy({},{get:(e,t)=>{if(!(typeof t!="string"&&typeof t!="symbol"))return this.getService(t)}})}getKey(e){if(typeof e=="string"||typeof e=="symbol")return e;let t=this.tryGetKey(e);if(t)return t;let s=Array.isArray(e)?`[${e.map(n=>n.name).join(", ")}]`:e.name||String(e);throw new p(s)}tryGetKey(e){if(typeof e=="string"||typeof e=="symbol"){if(e in this.definitions)return e;if(typeof e=="string"){let t=Reflect.ownKeys(this.definitions).find(s=>{let n=this.definitions[s];return n.kind==="service"&&!Array.isArray(n.type)&&n.type?.name===e});if(t)return t}return}if(typeof e=="function"||Array.isArray(e)){let t=c(e);if(t in this.definitions)return t;let s=Reflect.ownKeys(this.definitions).find(n=>{let i=this.definitions[n];return i.kind==="service"&&i.type===e});if(s)return s}}};var K=class{definitions={};typeMap;constructor(){this.typeMap={}}addSingletonFactory(e,t){let s,n,i=!1;if(typeof e=="string"||typeof e=="symbol")s=e,n=this.typeMap[s],i=!0;else{let y=this.resolveKeyAndType(e);s=y.key,n=y.type}let r=i?s:c(n),a={kind:"service",lifetime:"singleton",uid:r,type:n,factory:t};return this.definitions[s]=a,s!==r&&(this.definitions[r]=a),this}addServiceProvider(e){return this.addSingletonFactory(e,(t,s)=>s)}addScopedFactory(e,t){let s,n,i=!1;if(typeof e=="string"||typeof e=="symbol")s=e,n=this.typeMap[s],i=!0;else{let y=this.resolveKeyAndType(e);s=y.key,n=y.type}let r=i?s:c(n),a={kind:"service",lifetime:"scoped",uid:r,type:n,factory:t};return this.definitions[s]=a,s!==r&&(this.definitions[r]=a),this}addSingletonClass(e,...t){let{key:s,type:n}=this.resolveKeyAndType(e),i=c(n),r={kind:"service",lifetime:"singleton",uid:i,type:n,params:t};return this.definitions[s]=r,this.definitions[i]=r,this}addScopedClass(e,...t){let{key:s,type:n}=this.resolveKeyAndType(e),i=c(n),r={kind:"service",lifetime:"scoped",uid:i,type:n,params:t};return this.definitions[s]=r,this.definitions[i]=r,this}addSingletonArray(e,...t){let s={kind:"service",lifetime:"singleton",uid:e,type:t};this.typeMap[e]=t,this.definitions[e]=s;let n=t;for(let i of n){if(Reflect.ownKeys(this.typeMap).find(g=>this.typeMap[g]===i))continue;let a=i.name;if(!a)throw new l(`Class in array "${String(e)}" is missing a name and cannot be auto-registered.`);let y=c(i),d={kind:"service",lifetime:"singleton",uid:y,type:i,params:[]};this.typeMap[a]=i,this.definitions[a]=d,this.definitions[y]=d}return this}addScopedArray(e,...t){let s={kind:"service",lifetime:"scoped",uid:e,type:t};this.typeMap[e]=t,this.definitions[e]=s;let n=t;for(let i of n){if(Reflect.ownKeys(this.typeMap).find(g=>this.typeMap[g]===i))continue;let a=i.name;if(!a)throw new l(`Class in array "${String(e)}" is missing a name and cannot be auto-registered.`);let y=c(i),d={kind:"service",lifetime:"scoped",uid:y,type:i,params:[]};this.typeMap[a]=i,this.definitions[a]=d,this.definitions[y]=d}return this}addSingletonFunc(e,t,...s){return this.definitions[e]={kind:"function",lifetime:"singleton",uid:e,func:t,params:s},this}addScopedFunc(e,t,...s){return this.definitions[e]={kind:"function",lifetime:"scoped",uid:e,func:t,params:s},this}addSingletonValue(e,t){return this.definitions[e]={kind:"value",lifetime:"singleton",uid:e,value:t},this}addScopedValue(e,t){return this.definitions[e]={kind:"value",lifetime:"scoped",uid:e,value:t},this}resolveKeyAndType(e){let t,s=Reflect.ownKeys(this.typeMap).find(n=>this.typeMap[n]===e);return s?t=s:(t=e.name||c(e),this.typeMap[t]=e),{key:t,type:e}}build(e="root"){for(let t of Reflect.ownKeys(this.definitions)){let s=this.definitions[t];if(!(s.kind!=="service"||!Array.isArray(s.type)))for(let n of s.type){let i=n.name,r=this.definitions[i];if(r&&r.params&&r.params.length===0&&n.length>0)throw new l(`Class "${i}" in array "${String(t)}" requires constructor arguments and must be registered independently using addSingletonClass or addScopedClass.`)}}return new u(e,this.definitions)}};0&&(module.exports={AsyncDisposalError,CircularDependencyError,RegistrationError,ServiceCollection,ServiceNotFoundError,ServiceProvider,ServiceProviderDisposedError});
2
+ //# sourceMappingURL=legacy.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts", "../src/errors.ts", "../src/registry.ts", "../src/service-provider.ts", "../src/service-collection.ts"],
4
+ "sourcesContent": ["export * from './errors.js';\nexport * from './service-collection.js';\nexport * from './service-provider.js';\nexport * from './types.js';\n", "/**\n * Thrown when a circular dependency is detected.\n */\nexport class CircularDependencyError extends Error {\n constructor(path: string) {\n super(`Circular dependency detected: ${path}`);\n this.name = 'CircularDependencyError';\n }\n}\n\n/**\n * Thrown when a service cannot be resolved.\n */\nexport class ServiceNotFoundError extends Error {\n constructor(identifier: string) {\n super(`Service not registered for identifier: ${identifier}`);\n this.name = 'ServiceNotFoundError';\n }\n}\n\n/**\n * Thrown when a registration is invalid.\n */\nexport class RegistrationError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'RegistrationError';\n }\n}\n\n/**\n * Thrown when a service provider has been disposed.\n */\nexport class ServiceProviderDisposedError extends Error {\n constructor() {\n super('ServiceProvider has been disposed and cannot resolve services.');\n this.name = 'ServiceProviderDisposedError';\n }\n}\n\n/**\n * Thrown when a synchronous dispose is called on a scope containing services that require asynchronous disposal.\n */\nexport class AsyncDisposalError extends Error {\n constructor(serviceKey: string) {\n super(`Service \"${serviceKey}\" requires asynchronous disposal but a synchronous dispose was called. Please use await disposeAsync() instead.`);\n this.name = 'AsyncDisposalError';\n }\n}\n", "import type { Class } from './types.js';\r\n\r\nconst classKeyRegistry = new WeakMap<Class, symbol>();\r\n\r\n/**\r\n * Resolves a stable Symbol for a given class constructor.\r\n * This is used to ensure that DI resolution remains stable even after minification.\r\n * @param type The class constructor.\r\n */\r\nexport function getStableKey(type: Class): symbol {\r\n let key = classKeyRegistry.get(type);\r\n if (!key) {\r\n key = Symbol(type.name || 'AnonymousClass');\r\n classKeyRegistry.set(type, key);\r\n }\r\n return key;\r\n}\r\n", "import {\n AsyncDisposalError,\n CircularDependencyError,\n ServiceNotFoundError,\n ServiceProviderDisposedError,\n} from './errors.js';\nimport { getStableKey } from './registry.js';\nimport type {\n Class,\n ConcreteClass,\n ImplementationFactory,\n IServiceProvider,\n MapToInstance,\n ResolvedTypeMap,\n ServiceDefinitionMap,\n TypeMap,\n} from './types.js';\n\nexport class ServiceProvider<T extends TypeMap> implements IServiceProvider<T> {\n private instances = new Map<string | symbol, any>();\n private resolving = new Set<string | symbol>();\n private path: (string | symbol)[] = [];\n private disposed = false;\n\n /**\n * @param name The name of the service provider.\n * @param definitions The service definitions map.\n * @param parent The parent service provider, if any.\n * @param isAsyncScope Whether this is an asynchronous scope.\n */\n constructor(\n public readonly name: string,\n private definitions: ServiceDefinitionMap,\n private parent?: ServiceProvider<T>,\n private readonly isAsyncScope: boolean = false\n ) { }\n\n /**\n * Creates a new scoped ServiceProvider.\n * @param name The name of the scope.\n * @example\n * const scope = di.createScope('request-scope');\n */\n createScope(name: string = 'scope'): IServiceProvider<T> {\n const root = this.parent || this;\n return new ServiceProvider<T>(name, this.definitions, root, false);\n }\n\n /**\n * Creates a new scoped ServiceProvider that supports asynchronous disposal.\n * @param name The name of the scope.\n * @example\n * const scope = di.createAsyncScope('worker-scope');\n */\n createAsyncScope(name: string = 'async-scope'): IServiceProvider<T> {\n const root = this.parent || this;\n return new ServiceProvider<T>(name, this.definitions, root, true);\n }\n\n /**\n * Resolves a service by its key.\n * @param key The key to resolve.\n * @example\n * const logger = di.getService('Logger');\n */\n getService<K extends keyof T & (string | symbol)>(key: K): MapToInstance<T[K]>;\n\n /**\n * Resolves a service by its Class type.\n * @param type The class type to resolve.\n * @example\n * const logger = di.getService(Logger);\n */\n getService<C extends Class>(type: C): InstanceType<C>;\n\n getService<K extends keyof T & (string | symbol)>(keyOrType: K | T[K]): MapToInstance<T[K]> {\n if (this.disposed) {\n throw new ServiceProviderDisposedError();\n }\n\n const key = this.getKey(keyOrType);\n\n if (this.parent && this.definitions[key]?.lifetime === 'singleton') {\n return this.parent.getService(key as any);\n }\n\n const item = this.definitions[key];\n if (!item) {\n const name = (typeof keyOrType === 'string' || typeof keyOrType === 'symbol')\n ? String(keyOrType)\n : (keyOrType as any).name || String(keyOrType);\n throw new ServiceNotFoundError(name);\n }\n\n const uid = item.uid;\n\n if (this.instances.has(uid)) {\n return this.instances.get(uid);\n }\n\n if (this.resolving.has(uid)) {\n const pathStr = this.path.map(k => (typeof k === 'symbol' ? k.description || String(k) : k)).concat(typeof key === 'symbol' ? key.description || String(key) : key).join(' -> ');\n throw new CircularDependencyError(pathStr);\n }\n\n this.resolving.add(uid);\n this.path.push(key);\n\n try {\n if (item.kind === 'value') return this.resolveValue(uid, item.value);\n\n if (Array.isArray(item.type)) return this.resolveArray(uid, item.type);\n\n if (item.kind === 'function' && item.func) return this.resolveFunc(uid, item.func, item.params);\n\n if (item.factory) return this.resolveFactory(uid, item.factory);\n\n return this.resolveClass(uid, item.type as Class, item.params);\n } finally {\n this.resolving.delete(uid);\n this.path.pop();\n }\n }\n\n /**\n * Synchronously disposes of all resolved services.\n * Throws AsyncDisposalError if this is an async scope or if any service disposal returns a Promise.\n */\n dispose(): void {\n if (this.disposed) return;\n\n if (this.isAsyncScope) {\n throw new AsyncDisposalError(this.name);\n }\n\n this.disposed = true;\n\n const entries = Array.from(this.instances.entries()).reverse();\n\n for (const [uid, inst] of entries) {\n if (inst && typeof inst.dispose === 'function') {\n const result = inst.dispose();\n if (result instanceof Promise) {\n throw new AsyncDisposalError(typeof uid === 'symbol' ? uid.description || String(uid) : String(uid));\n }\n } else if (inst && typeof inst.disposeAsync === 'function') {\n throw new AsyncDisposalError(typeof uid === 'symbol' ? uid.description || String(uid) : String(uid));\n }\n }\n\n this.instances.clear();\n }\n\n /**\n * Asynchronously disposes of all resolved services.\n */\n async disposeAsync(): Promise<void> {\n if (this.disposed) return;\n this.disposed = true;\n\n const entries = Array.from(this.instances.values()).reverse();\n\n for (const inst of entries) {\n if (inst && typeof inst.disposeAsync === 'function') {\n await inst.disposeAsync();\n } else if (inst && typeof inst.dispose === 'function') {\n const result = inst.dispose();\n if (result instanceof Promise) {\n await result;\n }\n }\n }\n\n this.instances.clear();\n }\n\n /**\n * Resolves a singleton value.\n * @param uid The unique ID of the value.\n * @param value The value to resolve.\n */\n private resolveValue(uid: string | symbol, value: any): any {\n this.instances.set(uid, value);\n return value;\n }\n\n /**\n * Resolves an array of services.\n * @param uid The unique ID of the service array.\n * @param types The class types to resolve for the array.\n */\n private resolveArray(uid: string | symbol, types: Class[]): any {\n const instances = types.map((cls) => {\n const inst = this.getService(cls);\n return inst;\n });\n\n this.instances.set(uid, instances);\n return instances;\n }\n\n /**\n * Resolves a service via a factory.\n * @param uid The unique ID of the service.\n * @param factory The factory to use for resolution.\n */\n private resolveFactory(uid: string | symbol, factory: ImplementationFactory<any, any>): any {\n const container = this.createContainerProxy();\n const result = factory(container, this);\n this.instances.set(uid, result);\n return result;\n }\n\n /**\n * Resolves a service via a function.\n * @param uid The unique ID of the service.\n * @param func The function to use for resolution.\n * @param params The arguments for the function.\n */\n private resolveFunc(uid: string | symbol, func: (...args: any[]) => any, params?: any[]): any {\n const rawParams = params || [];\n const resolvedParams = rawParams.map((param) => {\n const paramKey = this.tryGetKey(param);\n const inst = paramKey ? this.getService(paramKey) : param;\n return inst;\n });\n\n const result = func(...resolvedParams);\n this.instances.set(uid, result);\n return result;\n }\n\n /**\n * Resolves a service via its class type.\n * @param uid The unique ID of the service.\n * @param type The class type to instantiate.\n * @param params The constructor arguments.\n */\n private resolveClass(uid: string | symbol, type: Class, params?: any[]): any {\n const rawParams = params || [];\n const resolvedParams = rawParams.map((param) => {\n const paramKey = this.tryGetKey(param);\n const inst = paramKey ? this.getService(paramKey) : param;\n return inst;\n });\n\n const instance = new (type as ConcreteClass)(...resolvedParams);\n this.instances.set(uid, instance);\n return instance;\n }\n\n /**\n * Creates a proxy for the type map to allow resolving services by property access.\n */\n private createContainerProxy(): ResolvedTypeMap<T> {\n return new Proxy({} as ResolvedTypeMap<T>, {\n get: (_, prop) => {\n if (typeof prop !== 'string' && typeof prop !== 'symbol') return undefined;\n return this.getService(prop as any);\n }\n });\n }\n\n /**\n * Gets the key for a given key or class type.\n * @param keyOrType The key or class type.\n */\n private getKey<K extends keyof T & (string | symbol)>(keyOrType: K | T[K]): string | symbol {\n if (typeof keyOrType === 'string' || typeof keyOrType === 'symbol') return keyOrType;\n\n const key = this.tryGetKey(keyOrType);\n if (key) return key;\n\n const name = Array.isArray(keyOrType)\n ? `[${keyOrType.map((c: any) => (c as any).name).join(', ')}]`\n : (keyOrType as any).name || String(keyOrType);\n throw new ServiceNotFoundError(name);\n }\n\n /**\n * Attempts to get the key for a given key or class type without throwing.\n * @param keyOrType The key or class type.\n */\n private tryGetKey(keyOrType: any): string | symbol | undefined {\n if (typeof keyOrType === 'string' || typeof keyOrType === 'symbol') {\n if (keyOrType in this.definitions) return keyOrType;\n \n // Fallback for string names (backward compatibility)\n if (typeof keyOrType === 'string') {\n const entry = Reflect.ownKeys(this.definitions).find((k) => {\n const v = this.definitions[k as any];\n return v.kind === 'service' && !Array.isArray(v.type) && (v.type as any)?.name === keyOrType;\n });\n if (entry) return entry as string | symbol;\n }\n return undefined;\n }\n\n if (typeof keyOrType === 'function' || Array.isArray(keyOrType)) {\n // Check the stable registry first (minification proof)\n const stableKey = getStableKey(keyOrType as any);\n if (stableKey in this.definitions) return stableKey;\n\n // Fallback to searching by reference (for explicit symbols or non-auto registrations)\n const entry = Reflect.ownKeys(this.definitions).find((k) => {\n const v = this.definitions[k as any];\n return v.kind === 'service' && v.type === keyOrType;\n });\n if (entry) return entry as string | symbol;\n }\n\n return undefined;\n }\n}\n", "import {\n RegistrationError,\n} from './errors.js';\nimport { getStableKey } from './registry.js';\nimport { ServiceProvider } from './service-provider.js';\nimport type {\n Class,\n ClassArgs,\n FilterKeys,\n FilterValueKeys,\n FilterFuncKeys,\n FuncArgs,\n ImplementationFactory,\n MapToInstance,\n ServiceDefinitionMap,\n TypeMap,\n ServiceDefinition\n} from './types.js';\n\n/**\n * Fluent builder for service collections using a lookup map.\n */\nexport class ServiceCollection<T extends TypeMap> {\n private definitions: ServiceDefinitionMap = {};\n private typeMap: T;\n\n /**\n * Initializes a new instance of the ServiceCollection class.\n */\n constructor() {\n this.typeMap = {} as T;\n }\n\n /**\n * Adds a singleton service using a factory function.\n * Key is derived from the class.\n * @param type The class to register.\n * @param factory The factory function to create the service instance.\n * @example\n * .addSingletonFactory(UserRepo, (c) => new UserRepo(c.UserService))\n */\n addSingletonFactory<Key extends keyof T & (string | symbol), C extends Class>(\n type: C,\n factory: ImplementationFactory<T, InstanceType<C>>\n ): this;\n\n /**\n * Adds a singleton service using a factory function and a key.\n * @param key The key to register the service under.\n * @param factory The factory function to create the service instance.\n * @example\n * .addSingletonFactory(\"UserRepo\", (c) => new UserRepo(c.UserService))\n */\n addSingletonFactory<Key extends keyof T & (string | symbol)>(\n key: Key,\n factory: ImplementationFactory<T, MapToInstance<T[Key]>>\n ): this;\n\n addSingletonFactory<Key extends keyof T & (string | symbol)>(\n keyOrType: Key | Class,\n factory: ImplementationFactory<T, any>\n ): this {\n let key: string | symbol;\n let type: any;\n let isExplicitKey = false;\n\n if (typeof keyOrType === 'string' || typeof keyOrType === 'symbol') {\n key = keyOrType;\n type = this.typeMap[key];\n isExplicitKey = true;\n } else {\n const resolved = this.resolveKeyAndType<Key>(keyOrType as any);\n key = resolved.key;\n type = resolved.type;\n }\n\n const uid = isExplicitKey ? key : getStableKey(type);\n const def: ServiceDefinition<any> = { kind: 'service', lifetime: 'singleton', uid, type, factory };\n this.definitions[key] = def;\n if (key !== uid) this.definitions[uid] = def;\n\n return this;\n }\n\n /**\n * Registers the ServiceProvider itself as a service.\n * This allows services to depend on the ServiceProvider to resolve other services dynamically.\n * @param key The key to register the ServiceProvider under.\n * @example\n * .addServiceProvider(\"ServiceProvider\")\n */\n addServiceProvider<Key extends keyof T & (string | symbol)>(key: Key) {\n return this.addSingletonFactory(key as any, (_, sp) => sp)\n }\n\n /**\n * Adds a scoped service using a factory function.\n * Key is derived from the class.\n * @param type The class to register.\n * @param factory The factory function to create the service instance.\n * @example\n * .addScopedFactory(UserRepo, (c) => new UserRepo(c.UserService))\n */\n addScopedFactory<Key extends keyof T & (string | symbol), C extends Class>(\n type: C,\n factory: ImplementationFactory<T, InstanceType<C>>\n ): this;\n\n /**\n * Adds a scoped service using a factory function and a key.\n * @param key The key to register the service under.\n * @param factory The factory function to create the service instance.\n * @example\n * .addScopedFactory(\"UserRepo\", (c) => new UserRepo(c.UserService))\n */\n addScopedFactory<Key extends keyof T & (string | symbol)>(\n key: Key,\n factory: ImplementationFactory<T, MapToInstance<T[Key]>>\n ): this;\n\n addScopedFactory<Key extends keyof T & (string | symbol)>(\n keyOrType: Key | Class,\n factory: ImplementationFactory<T, any>\n ): this {\n let key: string | symbol;\n let type: any;\n let isExplicitKey = false;\n\n if (typeof keyOrType === 'string' || typeof keyOrType === 'symbol') {\n key = keyOrType;\n type = this.typeMap[key];\n isExplicitKey = true;\n } else {\n const resolved = this.resolveKeyAndType<Key>(keyOrType as any);\n key = resolved.key;\n type = resolved.type;\n }\n\n const uid = isExplicitKey ? key : getStableKey(type);\n const def: ServiceDefinition<any> = { kind: 'service', lifetime: 'scoped', uid, type, factory };\n this.definitions[key] = def;\n if (key !== uid) this.definitions[uid] = def;\n\n return this;\n }\n\n /**\n * Adds a singleton service using constructor injection.\n * Key is derived from the container map based on the Class.\n * @param type The class to register.\n * @param params The constructor arguments.\n * @example\n * .addSingletonClass(UserService, \"admin\", \"password\")\n */\n addSingletonClass<C extends Class>(\n type: C,\n ...params: ClassArgs<C, keyof T & (string | symbol)>\n ): this {\n const { key, type: typeRef } = this.resolveKeyAndType(type as any);\n const uid = getStableKey(typeRef);\n const def: ServiceDefinition<any> = { kind: 'service', lifetime: 'singleton', uid, type: typeRef, params };\n this.definitions[key] = def;\n this.definitions[uid] = def;\n return this;\n }\n\n /**\n * Adds a scoped service using constructor injection.\n * Key is derived from the container map based on the Class.\n * @param type The class to register.\n * @param params The constructor arguments.\n * @example\n * .addScopedClass(UserService, \"admin\", \"password\")\n */\n addScopedClass<C extends Class>(\n type: C,\n ...params: ClassArgs<C, keyof T & (string | symbol)>\n ): this {\n const { key, type: typeRef } = this.resolveKeyAndType(type as any);\n const uid = getStableKey(typeRef);\n const def: ServiceDefinition<any> = { kind: 'service', lifetime: 'scoped', uid, type: typeRef, params };\n this.definitions[key] = def;\n this.definitions[uid] = def;\n return this;\n }\n\n /**\n * Adds an array of singleton services.\n * Automatically registers individual classes if not already registered.\n * @param key The key for the service array.\n * @param types The classes to register in the array.\n * @example\n * .addSingletonArray(\"MessageCommand\", HelloCommand, ByeCommand)\n */\n addSingletonArray<\n Key extends FilterKeys<T, any[]>,\n C extends (new (...args: any[]) => MapToInstance<T[Key]>[number])[]\n >(\n key: Key,\n ...types: C\n ): this {\n const def: ServiceDefinition<any> = { kind: 'service', lifetime: 'singleton', uid: key, type: types };\n (this.typeMap as any)[key] = types;\n this.definitions[key] = def;\n\n // Auto-register individual classes if not already registered\n const typeArray = types as Class[];\n for (const type of typeArray) {\n const foundKey = Reflect.ownKeys(this.typeMap).find(k => this.typeMap[k as any] === type);\n if (foundKey) continue;\n\n const name = type.name;\n if (!name) {\n throw new RegistrationError(`Class in array \"${String(key)}\" is missing a name and cannot be auto-registered.`);\n }\n\n const uid = getStableKey(type);\n const classDef: ServiceDefinition<any> = { kind: 'service', lifetime: 'singleton', uid, type, params: [] };\n (this.typeMap as any)[name] = type;\n this.definitions[name] = classDef;\n this.definitions[uid] = classDef;\n }\n\n return this;\n }\n\n /**\n * Adds an array of scoped services.\n * Automatically registers individual classes as scoped if not already registered.\n * @param key The key for the service array.\n * @param types The classes to register in the array.\n * @example\n * .addScopedArray(\"MessageCommand\", HelloCommand, ByeCommand)\n */\n addScopedArray<\n Key extends FilterKeys<T, any[]>,\n C extends (new (...args: any[]) => MapToInstance<T[Key]>[number])[]\n >(\n key: Key,\n ...types: C\n ): this {\n const def: ServiceDefinition<any> = { kind: 'service', lifetime: 'scoped', uid: key, type: types };\n (this.typeMap as any)[key] = types;\n this.definitions[key] = def;\n\n // Auto-register individual classes if not already registered\n const typeArray = types as Class[];\n for (const type of typeArray) {\n const foundKey = Reflect.ownKeys(this.typeMap).find(k => this.typeMap[k as any] === type);\n if (foundKey) continue;\n\n const name = type.name;\n if (!name) {\n throw new RegistrationError(`Class in array \"${String(key)}\" is missing a name and cannot be auto-registered.`);\n }\n\n const uid = getStableKey(type);\n const classDef: ServiceDefinition<any> = { kind: 'service', lifetime: 'scoped', uid, type, params: [] };\n (this.typeMap as any)[name] = type;\n this.definitions[name] = classDef;\n this.definitions[uid] = classDef;\n }\n\n return this;\n }\n\n /**\n * Adds a singleton service using a function.\n * @param key The key for the service.\n * @param func The function to register.\n * @param params The function arguments.\n * @example\n * .addSingletonFunc(\"Logger\", createLogger, \"Config\")\n */\n addSingletonFunc<Key extends FilterFuncKeys<T>, F extends (...args: any[]) => T[Key]>(\n key: Key,\n func: F,\n ...params: FuncArgs<F, T>\n ): this {\n this.definitions[key] = { kind: 'function', lifetime: 'singleton', uid: key, func, params };\n return this;\n }\n\n /**\n * Adds a scoped service using a function.\n * @param key The key for the service.\n * @param func The function to register.\n * @param params The function arguments.\n * @example\n * .addScopedFunc(\"Logger\", createLogger, \"Config\")\n */\n addScopedFunc<Key extends FilterFuncKeys<T>, F extends (...args: any[]) => T[Key]>(\n key: Key,\n func: F,\n ...params: FuncArgs<F, T>\n ): this {\n this.definitions[key] = { kind: 'function', lifetime: 'scoped', uid: key, func, params };\n return this;\n }\n\n /**\n * Adds a singleton value.\n * @param key The key for the value.\n * @param value The value to register.\n * @example\n * .addSingletonValue(\"connectionString\", \"test connection string\")\n */\n addSingletonValue<Key extends FilterValueKeys<T>>(\n key: Key,\n value: T[Key]\n ): this {\n this.definitions[key] = { kind: 'value', lifetime: 'singleton', uid: key, value };\n return this;\n }\n\n /**\n * Adds a scoped value.\n * @param key The key for the value.\n * @param value The value to register.\n * @example\n * .addScopedValue(\"connectionString\", \"test connection string\")\n */\n addScopedValue<Key extends FilterValueKeys<T>>(\n key: Key,\n value: T[Key]\n ): this {\n this.definitions[key] = { kind: 'value', lifetime: 'scoped', uid: key, value };\n return this;\n }\n\n /**\n * Resolves the string key and Class reference for a given type.\n * If the type is already mapped in the TypeMap, the existing key is used.\n * Otherwise, it auto-registers the type using its class name as the key.\n * @param type The class reference to resolve.\n * @throws RegistrationError if the class name cannot be determined (e.g. anonymous class).\n * @example\n * const { key, type } = this.resolveKeyAndType(UserService);\n */\n private resolveKeyAndType<Key extends keyof T & (string | symbol)>(type: T[Key] & Class): { key: Key, type: T[Key] } {\n let key: Key;\n\n const foundKey = Reflect.ownKeys(this.typeMap).find(\n (k) => this.typeMap[k as any] === type\n );\n if (foundKey) {\n key = foundKey as Key;\n } else {\n // Auto-register using class name for backward compatibility\n key = (type.name || getStableKey(type)) as any as Key;\n (this.typeMap as any)[key] = type;\n }\n\n return { key, type };\n }\n\n /**\n * Builds the ServiceProvider.\n * @param name The name of the service provider.\n * @example\n * const di = new ServiceCollection<LocalMap>()\n * .addSingletonClass(MyService)\n * .build();\n */\n build(name: string = 'root'): ServiceProvider<T> {\n // Validate all registered services\n for (const key of Reflect.ownKeys(this.definitions)) {\n const item = this.definitions[key as any];\n if (item.kind !== 'service' || !Array.isArray(item.type)) continue;\n\n // This is an array of services\n for (const type of item.type as Class[]) {\n const name = type.name;\n const definitionsItem = this.definitions[name];\n\n // Check if this class was auto-registered (params is empty array) but requires arguments\n if (definitionsItem && definitionsItem.params && definitionsItem.params.length === 0 && type.length > 0) {\n throw new RegistrationError(`Class \"${name}\" in array \"${String(key)}\" requires constructor arguments and must be registered independently using addSingletonClass or addScopedClass.`);\n }\n }\n }\n\n return new ServiceProvider<T>(name, this.definitions);\n }\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,wBAAAE,EAAA,4BAAAC,EAAA,sBAAAC,EAAA,sBAAAC,EAAA,yBAAAC,EAAA,oBAAAC,EAAA,iCAAAC,IAAA,eAAAC,EAAAT,GCGO,IAAMU,EAAN,cAAsC,KAAM,CACjD,YAAYC,EAAc,CACxB,MAAM,iCAAiCA,CAAI,EAAE,EAC7C,KAAK,KAAO,yBACd,CACF,EAKaC,EAAN,cAAmC,KAAM,CAC9C,YAAYC,EAAoB,CAC9B,MAAM,0CAA0CA,CAAU,EAAE,EAC5D,KAAK,KAAO,sBACd,CACF,EAKaC,EAAN,cAAgC,KAAM,CAC3C,YAAYC,EAAiB,CAC3B,MAAMA,CAAO,EACb,KAAK,KAAO,mB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EAAI,CAAE,KAAM,QAAS,SAAU,YAAa,IAAKA,EAAK,MAAAkB,CAAM,EACzE,IACT,CASA,eACElB,EACAkB,EACM,CACN,YAAK,YAAYlB,CAAG,EAAI,CAAE,KAAM,QAAS,SAAU,SAAU,IAAKA,EAAK,MAAAkB,CAAM,EACtE,IACT,CAWQ,kBAA2DjB,EAAkD,CACnH,IAAID,EAEEmB,EAAW,QAAQ,QAAQ,KAAK,OAAO,EAAE,KAC5CN,GAAM,KAAK,QAAQA,CAAQ,IAAMZ,CACpC,EACA,OAAIkB,EACFnB,EAAMmB,GAGNnB,EAAOC,EAAK,MAAQI,EAAaJ,CAAI,EACpC,KAAK,QAAgBD,CAAG,EAAIC,GAGxB,CAAE,IAAAD,EAAK,KAAAC,CAAK,CACrB,CAUA,MAAMa,EAAe,OAA4B,CAE/C,QAAWd,KAAO,QAAQ,QAAQ,KAAK,WAAW,EAAG,CACnD,IAAMoB,EAAO,KAAK,YAAYpB,CAAU,EACxC,GAAI,EAAAoB,EAAK,OAAS,WAAa,CAAC,MAAM,QAAQA,EAAK,IAAI,GAGvD,QAAWnB,KAAQmB,EAAK,KAAiB,CACvC,IAAMN,EAAOb,EAAK,KACZoB,EAAkB,KAAK,YAAYP,CAAI,EAG7C,GAAIO,GAAmBA,EAAgB,QAAUA,EAAgB,OAAO,SAAW,GAAKpB,EAAK,OAAS,EACpG,MAAM,IAAIc,EAAkB,UAAUD,CAAI,eAAe,OAAOd,CAAG,CAAC,kHAAkH,CAE1L,CACF,CAEA,OAAO,IAAIsB,EAAmBR,EAAM,KAAK,WAAW,CACtD,CACF",
6
+ "names": ["index_exports", "__export", "AsyncDisposalError", "CircularDependencyError", "RegistrationError", "ServiceCollection", "ServiceNotFoundError", "ServiceProvider", "ServiceProviderDisposedError", "__toCommonJS", "CircularDependencyError", "path", "ServiceNotFoundError", "identifier", "RegistrationError", "message", "ServiceProviderDisposedError", "AsyncDisposalError", "serviceKey", "classKeyRegistry", "getStableKey", "type", "key", "ServiceProvider", "_ServiceProvider", "name", "definitions", "parent", "isAsyncScope", "root", "keyOrType", "ServiceProviderDisposedError", "key", "item", "ServiceNotFoundError", "uid", "pathStr", "k", "CircularDependencyError", "AsyncDisposalError", "entries", "inst", "result", "value", "types", "instances", "cls", "factory", "container", "func", "params", "resolvedParams", "param", "paramKey", "type", "instance", "_", "prop", "c", "entry", "v", "stableKey", "getStableKey", "ServiceCollection", "keyOrType", "factory", "key", "type", "isExplicitKey", "resolved", "uid", "getStableKey", "def", "_", "sp", "params", "typeRef", "types", "typeArray", "k", "name", "RegistrationError", "classDef", "func", "value", "foundKey", "item", "definitionsItem", "ServiceProvider"]
7
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Thrown when a circular dependency is detected.
3
+ */
4
+ export declare class CircularDependencyError extends Error {
5
+ constructor(path: string);
6
+ }
7
+ /**
8
+ * Thrown when a service cannot be resolved.
9
+ */
10
+ export declare class ServiceNotFoundError extends Error {
11
+ constructor(identifier: string);
12
+ }
13
+ /**
14
+ * Thrown when a registration is invalid.
15
+ */
16
+ export declare class RegistrationError extends Error {
17
+ constructor(message: string);
18
+ }
19
+ /**
20
+ * Thrown when a service provider has been disposed.
21
+ */
22
+ export declare class ServiceProviderDisposedError extends Error {
23
+ constructor();
24
+ }
25
+ /**
26
+ * Thrown when a synchronous dispose is called on a scope containing services that require asynchronous disposal.
27
+ */
28
+ export declare class AsyncDisposalError extends Error {
29
+ constructor(serviceKey: string);
30
+ }
31
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,KAAK;gBACpC,IAAI,EAAE,MAAM;CAIzB;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;gBACjC,UAAU,EAAE,MAAM;CAI/B;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;gBAC9B,OAAO,EAAE,MAAM;CAI5B;AAED;;GAEG;AACH,qBAAa,4BAA6B,SAAQ,KAAK;;CAKtD;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;gBAC/B,UAAU,EAAE,MAAM;CAI/B"}
@@ -0,0 +1,5 @@
1
+ export * from './errors.js';
2
+ export * from './service-collection.js';
3
+ export * from './service-provider.js';
4
+ export * from './types.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,YAAY,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { Class } from './types.js';
2
+ /**
3
+ * Resolves a stable Symbol for a given class constructor.
4
+ * This is used to ensure that DI resolution remains stable even after minification.
5
+ * @param type The class constructor.
6
+ */
7
+ export declare function getStableKey(type: Class): symbol;
8
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAIxC;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,KAAK,GAAG,MAAM,CAOhD"}
@@ -0,0 +1,145 @@
1
+ import { ServiceProvider } from './service-provider.js';
2
+ import type { Class, ClassArgs, FilterKeys, FilterValueKeys, FilterFuncKeys, FuncArgs, ImplementationFactory, MapToInstance, TypeMap } from './types.js';
3
+ /**
4
+ * Fluent builder for service collections using a lookup map.
5
+ */
6
+ export declare class ServiceCollection<T extends TypeMap> {
7
+ private definitions;
8
+ private typeMap;
9
+ /**
10
+ * Initializes a new instance of the ServiceCollection class.
11
+ */
12
+ constructor();
13
+ /**
14
+ * Adds a singleton service using a factory function.
15
+ * Key is derived from the class.
16
+ * @param type The class to register.
17
+ * @param factory The factory function to create the service instance.
18
+ * @example
19
+ * .addSingletonFactory(UserRepo, (c) => new UserRepo(c.UserService))
20
+ */
21
+ addSingletonFactory<Key extends keyof T & (string | symbol), C extends Class>(type: C, factory: ImplementationFactory<T, InstanceType<C>>): this;
22
+ /**
23
+ * Adds a singleton service using a factory function and a key.
24
+ * @param key The key to register the service under.
25
+ * @param factory The factory function to create the service instance.
26
+ * @example
27
+ * .addSingletonFactory("UserRepo", (c) => new UserRepo(c.UserService))
28
+ */
29
+ addSingletonFactory<Key extends keyof T & (string | symbol)>(key: Key, factory: ImplementationFactory<T, MapToInstance<T[Key]>>): this;
30
+ /**
31
+ * Registers the ServiceProvider itself as a service.
32
+ * This allows services to depend on the ServiceProvider to resolve other services dynamically.
33
+ * @param key The key to register the ServiceProvider under.
34
+ * @example
35
+ * .addServiceProvider("ServiceProvider")
36
+ */
37
+ addServiceProvider<Key extends keyof T & (string | symbol)>(key: Key): this;
38
+ /**
39
+ * Adds a scoped service using a factory function.
40
+ * Key is derived from the class.
41
+ * @param type The class to register.
42
+ * @param factory The factory function to create the service instance.
43
+ * @example
44
+ * .addScopedFactory(UserRepo, (c) => new UserRepo(c.UserService))
45
+ */
46
+ addScopedFactory<Key extends keyof T & (string | symbol), C extends Class>(type: C, factory: ImplementationFactory<T, InstanceType<C>>): this;
47
+ /**
48
+ * Adds a scoped service using a factory function and a key.
49
+ * @param key The key to register the service under.
50
+ * @param factory The factory function to create the service instance.
51
+ * @example
52
+ * .addScopedFactory("UserRepo", (c) => new UserRepo(c.UserService))
53
+ */
54
+ addScopedFactory<Key extends keyof T & (string | symbol)>(key: Key, factory: ImplementationFactory<T, MapToInstance<T[Key]>>): this;
55
+ /**
56
+ * Adds a singleton service using constructor injection.
57
+ * Key is derived from the container map based on the Class.
58
+ * @param type The class to register.
59
+ * @param params The constructor arguments.
60
+ * @example
61
+ * .addSingletonClass(UserService, "admin", "password")
62
+ */
63
+ addSingletonClass<C extends Class>(type: C, ...params: ClassArgs<C, keyof T & (string | symbol)>): this;
64
+ /**
65
+ * Adds a scoped service using constructor injection.
66
+ * Key is derived from the container map based on the Class.
67
+ * @param type The class to register.
68
+ * @param params The constructor arguments.
69
+ * @example
70
+ * .addScopedClass(UserService, "admin", "password")
71
+ */
72
+ addScopedClass<C extends Class>(type: C, ...params: ClassArgs<C, keyof T & (string | symbol)>): this;
73
+ /**
74
+ * Adds an array of singleton services.
75
+ * Automatically registers individual classes if not already registered.
76
+ * @param key The key for the service array.
77
+ * @param types The classes to register in the array.
78
+ * @example
79
+ * .addSingletonArray("MessageCommand", HelloCommand, ByeCommand)
80
+ */
81
+ addSingletonArray<Key extends FilterKeys<T, any[]>, C extends (new (...args: any[]) => MapToInstance<T[Key]>[number])[]>(key: Key, ...types: C): this;
82
+ /**
83
+ * Adds an array of scoped services.
84
+ * Automatically registers individual classes as scoped if not already registered.
85
+ * @param key The key for the service array.
86
+ * @param types The classes to register in the array.
87
+ * @example
88
+ * .addScopedArray("MessageCommand", HelloCommand, ByeCommand)
89
+ */
90
+ addScopedArray<Key extends FilterKeys<T, any[]>, C extends (new (...args: any[]) => MapToInstance<T[Key]>[number])[]>(key: Key, ...types: C): this;
91
+ /**
92
+ * Adds a singleton service using a function.
93
+ * @param key The key for the service.
94
+ * @param func The function to register.
95
+ * @param params The function arguments.
96
+ * @example
97
+ * .addSingletonFunc("Logger", createLogger, "Config")
98
+ */
99
+ addSingletonFunc<Key extends FilterFuncKeys<T>, F extends (...args: any[]) => T[Key]>(key: Key, func: F, ...params: FuncArgs<F, T>): this;
100
+ /**
101
+ * Adds a scoped service using a function.
102
+ * @param key The key for the service.
103
+ * @param func The function to register.
104
+ * @param params The function arguments.
105
+ * @example
106
+ * .addScopedFunc("Logger", createLogger, "Config")
107
+ */
108
+ addScopedFunc<Key extends FilterFuncKeys<T>, F extends (...args: any[]) => T[Key]>(key: Key, func: F, ...params: FuncArgs<F, T>): this;
109
+ /**
110
+ * Adds a singleton value.
111
+ * @param key The key for the value.
112
+ * @param value The value to register.
113
+ * @example
114
+ * .addSingletonValue("connectionString", "test connection string")
115
+ */
116
+ addSingletonValue<Key extends FilterValueKeys<T>>(key: Key, value: T[Key]): this;
117
+ /**
118
+ * Adds a scoped value.
119
+ * @param key The key for the value.
120
+ * @param value The value to register.
121
+ * @example
122
+ * .addScopedValue("connectionString", "test connection string")
123
+ */
124
+ addScopedValue<Key extends FilterValueKeys<T>>(key: Key, value: T[Key]): this;
125
+ /**
126
+ * Resolves the string key and Class reference for a given type.
127
+ * If the type is already mapped in the TypeMap, the existing key is used.
128
+ * Otherwise, it auto-registers the type using its class name as the key.
129
+ * @param type The class reference to resolve.
130
+ * @throws RegistrationError if the class name cannot be determined (e.g. anonymous class).
131
+ * @example
132
+ * const { key, type } = this.resolveKeyAndType(UserService);
133
+ */
134
+ private resolveKeyAndType;
135
+ /**
136
+ * Builds the ServiceProvider.
137
+ * @param name The name of the service provider.
138
+ * @example
139
+ * const di = new ServiceCollection<LocalMap>()
140
+ * .addSingletonClass(MyService)
141
+ * .build();
142
+ */
143
+ build(name?: string): ServiceProvider<T>;
144
+ }
145
+ //# sourceMappingURL=service-collection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service-collection.d.ts","sourceRoot":"","sources":["../../../src/service-collection.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EACV,KAAK,EACL,SAAS,EACT,UAAU,EACV,eAAe,EACf,cAAc,EACd,QAAQ,EACR,qBAAqB,EACrB,aAAa,EAEb,OAAO,EAER,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,qBAAa,iBAAiB,CAAC,CAAC,SAAS,OAAO;IAC9C,OAAO,CAAC,WAAW,CAA4B;IAC/C,OAAO,CAAC,OAAO,CAAI;IAEnB;;OAEG;;IAKH;;;;;;;OAOG;IACH,mBAAmB,CAAC,GAAG,SAAS,MAAM,C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