@shellicar/core-di 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,6 +2,32 @@
2
2
 
3
3
  A basic dependency injection library.
4
4
 
5
+ <!-- BEGIN_ECOSYSTEM -->
6
+
7
+ ## @shellicar TypeScript Ecosystem
8
+
9
+ ### Core Libraries
10
+
11
+ - [`@shellicar/core-config`](https://github.com/shellicar/core-config) - A library for securely handling sensitive configuration values like connection strings, URLs, and secrets.
12
+ - [`@shellicar/core-di`](https://github.com/shellicar/core-di) - A basic dependency injection library.
13
+ - [`@shellicar/core-foundation`](https://github.com/shellicar/core-foundation) - A comprehensive starter repository.
14
+
15
+ ### Build Tools
16
+
17
+ - [`@shellicar/build-version`](https://github.com/shellicar/build-version) - Build plugin that calculates and exposes version information through a virtual module import.
18
+ - [`@shellicar/build-graphql`](https://github.com/shellicar/build-graphql) - Build plugin that loads GraphQL files and makes them available through a virtual module import.
19
+
20
+ ### Framework Adapters
21
+
22
+ - [`@shellicar/svelte-adapter-azure-functions`](https://github.com/shellicar/svelte-adapter-azure-functions) - A [SvelteKit adapter](https://kit.svelte.dev/docs/adapters) that builds your app into an Azure Function.
23
+
24
+ ### Logging & Monitoring
25
+
26
+ - [`@shellicar/winston-azure-application-insights`](https://github.com/shellicar/winston-azure-application-insights) - An [Azure Application Insights](https://azure.microsoft.com/en-us/services/application-insights/) transport for [Winston](https://github.com/winstonjs/winston) logging library.
27
+ - [`@shellicar/pino-applicationinsights-transport`](https://github.com/shellicar/pino-applicationinsights-transport) - [Azure Application Insights](https://azure.microsoft.com/en-us/services/application-insights) transport for [pino](https://github.com/pinojs/pino)
28
+
29
+ <!-- END_ECOSYSTEM -->
30
+
5
31
  ## Motivation
6
32
 
7
33
  Coming from .NET I am used to DI frameworks/libraries such as `Autofac`, `Ninject`, `StructureMap`, `Unity`, and Microsoft's own `DependencyInjection`.
package/dist/index.d.mts CHANGED
@@ -33,11 +33,11 @@ type ServiceIdentifier<T extends SourceType> = {
33
33
  type ServiceImplementation<T extends SourceType> = Newable<T>;
34
34
  type InstanceFactory<T extends SourceType> = (x: IResolutionScope) => T;
35
35
  type ServiceModuleType = Newable<IServiceModule>;
36
- interface ServiceDescriptor<T extends SourceType> {
36
+ type ServiceDescriptor<T extends SourceType> = {
37
37
  readonly implementation: ServiceImplementation<T>;
38
38
  lifetime: Lifetime;
39
39
  createInstance(context: IResolutionScope): T;
40
- }
40
+ };
41
41
  type MetadataType<T extends SourceType> = Record<string | symbol, ServiceIdentifier<T>>;
42
42
  type ServiceCollectionOptions = {
43
43
  /**
@@ -59,23 +59,16 @@ type ServiceCollectionOptions = {
59
59
  };
60
60
  type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
61
61
  type EnsureObject<T> = T extends object ? T : never;
62
- interface ILifetimeBuilder {
63
- singleton(): ILifetimeBuilder;
64
- scoped(): ILifetimeBuilder;
65
- transient(): ILifetimeBuilder;
66
- }
67
- interface IServiceBuilder<T extends SourceType> {
68
- to: {
69
- (implementation: ServiceImplementation<T>): ILifetimeBuilder;
70
- (implementation: ServiceImplementation<T>, factory: InstanceFactory<T>): ILifetimeBuilder;
71
- };
72
- }
62
+ type ServiceBuilderOptions<T extends SourceType> = {
63
+ (implementation: ServiceImplementation<T>): ILifetimeBuilder;
64
+ (implementation: ServiceImplementation<T>, factory: InstanceFactory<T>): ILifetimeBuilder;
65
+ };
73
66
 
74
- interface IDisposable {
75
- [Symbol.dispose](): void;
67
+ declare abstract class IDisposable {
68
+ abstract [Symbol.dispose](): void;
76
69
  }
77
- interface IServiceModule {
78
- registerServices(services: IServiceCollection): void;
70
+ declare abstract class IServiceModule {
71
+ abstract registerServices(services: IServiceCollection): void;
79
72
  }
80
73
  declare abstract class IResolutionScope {
81
74
  /**
@@ -96,23 +89,32 @@ declare abstract class IResolutionScope {
96
89
  abstract resolveAll<T extends SourceType>(identifier: ServiceIdentifier<T>): T[];
97
90
  }
98
91
  declare abstract class IScopedProvider extends IResolutionScope implements IDisposable {
92
+ abstract readonly Services: IServiceCollection;
99
93
  abstract [Symbol.dispose](): void;
100
94
  }
101
95
  declare abstract class IServiceProvider extends IResolutionScope {
102
96
  abstract readonly Services: IServiceCollection;
103
97
  abstract createScope(): IScopedProvider;
104
98
  }
105
- interface IServiceCollection {
106
- readonly options: ServiceCollectionOptions;
107
- get<T extends SourceType>(identifier: ServiceIdentifier<T>): ServiceDescriptor<T>[];
108
- register<Types extends SourceType[]>(...identifiers: {
99
+ declare abstract class IServiceCollection {
100
+ abstract readonly options: ServiceCollectionOptions;
101
+ abstract get<T extends SourceType>(identifier: ServiceIdentifier<T>): ServiceDescriptor<T>[];
102
+ abstract register<Types extends SourceType[]>(...identifiers: {
109
103
  [K in keyof Types]: ServiceIdentifier<Types[K]>;
110
104
  }): IServiceBuilder<EnsureObject<UnionToIntersection<Types[number]>>>;
111
- registerModules(...modules: ServiceModuleType[]): void;
112
- overrideLifetime<T extends SourceType>(identifier: ServiceIdentifier<T>, lifetime: Lifetime): void;
113
- buildProvider(): IServiceProvider;
114
- clone(): IServiceCollection;
115
- clone(scoped: true): IServiceCollection;
105
+ abstract registerModules(...modules: ServiceModuleType[]): void;
106
+ abstract overrideLifetime<T extends SourceType>(identifier: ServiceIdentifier<T>, lifetime: Lifetime): void;
107
+ abstract buildProvider(): IServiceProvider;
108
+ abstract clone(): IServiceCollection;
109
+ abstract clone(scoped: true): IServiceCollection;
110
+ }
111
+ declare abstract class ILifetimeBuilder {
112
+ abstract singleton(): ILifetimeBuilder;
113
+ abstract scoped(): ILifetimeBuilder;
114
+ abstract transient(): ILifetimeBuilder;
115
+ }
116
+ declare abstract class IServiceBuilder<T extends SourceType> {
117
+ abstract to: ServiceBuilderOptions<T>;
116
118
  }
117
119
 
118
120
  /**
@@ -155,4 +157,4 @@ declare class ScopedSingletonRegistrationError extends ServiceError {
155
157
  constructor();
156
158
  }
157
159
 
158
- export { type AbstractNewable, DefaultServiceCollectionOptions, type IDisposable, type ILifetimeBuilder, ILogger, IResolutionScope, IScopedProvider, type IServiceBuilder, type IServiceCollection, type IServiceModule, IServiceProvider, type InstanceFactory, Lifetime, LogLevel, type MetadataType, MultipleRegistrationError, type Newable, ResolveMultipleMode, ScopedSingletonRegistrationError, SelfDependencyError, type ServiceCollectionOptions, ServiceCreationError, type ServiceDescriptor, ServiceError, type ServiceIdentifier, type ServiceImplementation, type ServiceModuleType, type SourceType, UnregisteredServiceError, createServiceCollection, dependsOn };
160
+ export { type AbstractNewable, DefaultServiceCollectionOptions, IDisposable, ILifetimeBuilder, ILogger, IResolutionScope, IScopedProvider, IServiceBuilder, IServiceCollection, IServiceModule, IServiceProvider, type InstanceFactory, Lifetime, LogLevel, type MetadataType, MultipleRegistrationError, type Newable, ResolveMultipleMode, ScopedSingletonRegistrationError, SelfDependencyError, type ServiceCollectionOptions, ServiceCreationError, type ServiceDescriptor, ServiceError, type ServiceIdentifier, type ServiceImplementation, type ServiceModuleType, type SourceType, UnregisteredServiceError, createServiceCollection, dependsOn };
package/dist/index.d.ts CHANGED
@@ -33,11 +33,11 @@ type ServiceIdentifier<T extends SourceType> = {
33
33
  type ServiceImplementation<T extends SourceType> = Newable<T>;
34
34
  type InstanceFactory<T extends SourceType> = (x: IResolutionScope) => T;
35
35
  type ServiceModuleType = Newable<IServiceModule>;
36
- interface ServiceDescriptor<T extends SourceType> {
36
+ type ServiceDescriptor<T extends SourceType> = {
37
37
  readonly implementation: ServiceImplementation<T>;
38
38
  lifetime: Lifetime;
39
39
  createInstance(context: IResolutionScope): T;
40
- }
40
+ };
41
41
  type MetadataType<T extends SourceType> = Record<string | symbol, ServiceIdentifier<T>>;
42
42
  type ServiceCollectionOptions = {
43
43
  /**
@@ -59,23 +59,16 @@ type ServiceCollectionOptions = {
59
59
  };
60
60
  type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
61
61
  type EnsureObject<T> = T extends object ? T : never;
62
- interface ILifetimeBuilder {
63
- singleton(): ILifetimeBuilder;
64
- scoped(): ILifetimeBuilder;
65
- transient(): ILifetimeBuilder;
66
- }
67
- interface IServiceBuilder<T extends SourceType> {
68
- to: {
69
- (implementation: ServiceImplementation<T>): ILifetimeBuilder;
70
- (implementation: ServiceImplementation<T>, factory: InstanceFactory<T>): ILifetimeBuilder;
71
- };
72
- }
62
+ type ServiceBuilderOptions<T extends SourceType> = {
63
+ (implementation: ServiceImplementation<T>): ILifetimeBuilder;
64
+ (implementation: ServiceImplementation<T>, factory: InstanceFactory<T>): ILifetimeBuilder;
65
+ };
73
66
 
74
- interface IDisposable {
75
- [Symbol.dispose](): void;
67
+ declare abstract class IDisposable {
68
+ abstract [Symbol.dispose](): void;
76
69
  }
77
- interface IServiceModule {
78
- registerServices(services: IServiceCollection): void;
70
+ declare abstract class IServiceModule {
71
+ abstract registerServices(services: IServiceCollection): void;
79
72
  }
80
73
  declare abstract class IResolutionScope {
81
74
  /**
@@ -96,23 +89,32 @@ declare abstract class IResolutionScope {
96
89
  abstract resolveAll<T extends SourceType>(identifier: ServiceIdentifier<T>): T[];
97
90
  }
98
91
  declare abstract class IScopedProvider extends IResolutionScope implements IDisposable {
92
+ abstract readonly Services: IServiceCollection;
99
93
  abstract [Symbol.dispose](): void;
100
94
  }
101
95
  declare abstract class IServiceProvider extends IResolutionScope {
102
96
  abstract readonly Services: IServiceCollection;
103
97
  abstract createScope(): IScopedProvider;
104
98
  }
105
- interface IServiceCollection {
106
- readonly options: ServiceCollectionOptions;
107
- get<T extends SourceType>(identifier: ServiceIdentifier<T>): ServiceDescriptor<T>[];
108
- register<Types extends SourceType[]>(...identifiers: {
99
+ declare abstract class IServiceCollection {
100
+ abstract readonly options: ServiceCollectionOptions;
101
+ abstract get<T extends SourceType>(identifier: ServiceIdentifier<T>): ServiceDescriptor<T>[];
102
+ abstract register<Types extends SourceType[]>(...identifiers: {
109
103
  [K in keyof Types]: ServiceIdentifier<Types[K]>;
110
104
  }): IServiceBuilder<EnsureObject<UnionToIntersection<Types[number]>>>;
111
- registerModules(...modules: ServiceModuleType[]): void;
112
- overrideLifetime<T extends SourceType>(identifier: ServiceIdentifier<T>, lifetime: Lifetime): void;
113
- buildProvider(): IServiceProvider;
114
- clone(): IServiceCollection;
115
- clone(scoped: true): IServiceCollection;
105
+ abstract registerModules(...modules: ServiceModuleType[]): void;
106
+ abstract overrideLifetime<T extends SourceType>(identifier: ServiceIdentifier<T>, lifetime: Lifetime): void;
107
+ abstract buildProvider(): IServiceProvider;
108
+ abstract clone(): IServiceCollection;
109
+ abstract clone(scoped: true): IServiceCollection;
110
+ }
111
+ declare abstract class ILifetimeBuilder {
112
+ abstract singleton(): ILifetimeBuilder;
113
+ abstract scoped(): ILifetimeBuilder;
114
+ abstract transient(): ILifetimeBuilder;
115
+ }
116
+ declare abstract class IServiceBuilder<T extends SourceType> {
117
+ abstract to: ServiceBuilderOptions<T>;
116
118
  }
117
119
 
118
120
  /**
@@ -155,4 +157,4 @@ declare class ScopedSingletonRegistrationError extends ServiceError {
155
157
  constructor();
156
158
  }
157
159
 
158
- export { type AbstractNewable, DefaultServiceCollectionOptions, type IDisposable, type ILifetimeBuilder, ILogger, IResolutionScope, IScopedProvider, type IServiceBuilder, type IServiceCollection, type IServiceModule, IServiceProvider, type InstanceFactory, Lifetime, LogLevel, type MetadataType, MultipleRegistrationError, type Newable, ResolveMultipleMode, ScopedSingletonRegistrationError, SelfDependencyError, type ServiceCollectionOptions, ServiceCreationError, type ServiceDescriptor, ServiceError, type ServiceIdentifier, type ServiceImplementation, type ServiceModuleType, type SourceType, UnregisteredServiceError, createServiceCollection, dependsOn };
160
+ export { type AbstractNewable, DefaultServiceCollectionOptions, IDisposable, ILifetimeBuilder, ILogger, IResolutionScope, IScopedProvider, IServiceBuilder, IServiceCollection, IServiceModule, IServiceProvider, type InstanceFactory, Lifetime, LogLevel, type MetadataType, MultipleRegistrationError, type Newable, ResolveMultipleMode, ScopedSingletonRegistrationError, SelfDependencyError, type ServiceCollectionOptions, ServiceCreationError, type ServiceDescriptor, ServiceError, type ServiceIdentifier, type ServiceImplementation, type ServiceModuleType, type SourceType, UnregisteredServiceError, createServiceCollection, dependsOn };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";require("@abraham/reflection");var e=Object.defineProperty,t=(t,r)=>e(t,"name",{value:r,configurable:!0}),r=(e=>(e.Resolve="RESOLVE",e.Transient="TRANSIENT",e.Scoped="SCOPED",e.Singleton="SINGLETON",e))(r||{}),s=(e=>(e[e.Debug=0]="Debug",e[e.Info=1]="Info",e[e.Warn=2]="Warn",e[e.Error=3]="Error",e[e.None=4]="None",e))(s||{}),i=(e=>(e.Error="ERROR",e.LastRegistered="LAST_REGISTERED",e))(i||{}),o={registrationMode:"ERROR",logLevel:2},n=class extends Error{static{t(this,"ServiceError")}},c=class extends n{static{t(this,"UnregisteredServiceError")}name="UnregisteredServiceError";constructor(e){super(`Resolving service that has not been registered: ${e.name}`),Object.setPrototypeOf(this,new.target.prototype)}},l=class extends n{static{t(this,"MultipleRegistrationError")}name="MultipleRegistrationError";constructor(e){super(`Multiple services have been registered: ${e.name}`),Object.setPrototypeOf(this,new.target.prototype)}},a=class extends n{constructor(e,t){super(`Error creating service: ${e.name}`),this.innerError=t,Object.setPrototypeOf(this,new.target.prototype)}static{t(this,"ServiceCreationError")}name="ServiceCreationError"},p=class extends n{static{t(this,"SelfDependencyError")}name="SelfDependencyError";constructor(){super("Service depending on itself"),Object.setPrototypeOf(this,new.target.prototype)}},h=class extends n{static{t(this,"ScopedSingletonRegistrationError")}name="ScopedSingletonRegistrationError";constructor(){super("Cannot register a singleton in a scoped service collection"),Object.setPrototypeOf(this,new.target.prototype)}},g=class{constructor(e,t,r){this.identifiers=e,this.isScoped=t,this.addService=r}static{t(this,"ServiceBuilder")}descriptor;to(e,t){this.descriptor=this.createDescriptor(t,e);for(const e of this.identifiers)this.addService(e,this.descriptor);return this}createDescriptor(e,t){const r=e??(()=>new t);return{implementation:t,createInstance:r,lifetime:"RESOLVE"}}singleton(){if(this.isScoped)throw new h;return this.ensureDescriptor().lifetime="SINGLETON",this}scoped(){return this.ensureDescriptor().lifetime="SCOPED",this}transient(){return this.ensureDescriptor().lifetime="TRANSIENT",this}ensureDescriptor(){if(!this.descriptor)throw new Error("Must call to() before setting lifetime");return this.descriptor}},d=class{static{t(this,"IResolutionScope")}},u=class extends d{static{t(this,"IScopedProvider")}},v=class extends d{static{t(this,"IServiceProvider")}},S=class{constructor(e,t){this.singletons=e,this.scoped=t}static{t(this,"ResolutionContext")}transient=new Map;getFromLifetime(e,t){const r=this.getMapForLifetime(t);return r?.get(e)}setForLifetime(e,t,r){const s=this.getMapForLifetime(r);s?.set(e,t)}getMapForLifetime(e){return{SINGLETON:this.singletons,SCOPED:this.scoped,RESOLVE:this.transient}[e]}},f="design:dependencies",m=t(((e,t)=>Reflect.getMetadata(e,t)),"getMetadata"),E=t(((e,t,r)=>Reflect.defineMetadata(e,t,r)),"defineMetadata"),w=class e{constructor(e,t,r=new Map){this.logger=e,this.Services=t,this.singletons=r}static{t(this,"ServiceProvider")}scoped=new Map;created=[];[Symbol.dispose](){for(const e of this.created)e[Symbol.dispose]()}resolveInternal(e,t){let r=t.getFromLifetime(e.implementation,e.lifetime);return null==r&&(r=this.createInstance(e,t)),r}resolveAll(e,t){return this.Services.get(e).map((e=>this.resolveInternal(e,t??new S(this.singletons,this.scoped))))}resolve(e,t){if(e.prototype===d.prototype||e.prototype===u.prototype||e.prototype===v.prototype)return this;const r=this.getSingleDescriptor(e);return this.resolveInternal(r,t??new S(this.singletons,this.scoped))}getSingleDescriptor(e){const t=this.Services.get(e);if(0===t.length)throw new c(e);if(t.length>1&&"ERROR"===this.Services.options.registrationMode)throw new l(e);return t[t.length-1]}createInstance(e,t){const r=this.createInstanceInternal(e,t);return this.setDependencies(e.implementation,r,t),t.setForLifetime(e.implementation,r,e.lifetime),r}wrapContext(e){return{resolve:t((t=>this.resolve(t,e)),"resolve"),resolveAll:t((t=>this.resolveAll(t,e)),"resolveAll")}}createInstanceInternal(e,t){let r;try{r=e.createInstance(this.wrapContext(t))}catch(t){throw this.logger.error(t),new a(e.implementation,t)}return"SINGLETON"!==e.lifetime&&Symbol.dispose in r&&this.created.push(r),r}createScope(){return new e(this.logger,this.Services.clone(!0),this.singletons)}setDependencies(e,t,r){const s=m(f,e)??{};this.logger.debug("Dependencies",e.name,s);for(const[i,o]of Object.entries(s)){if(o===e)throw new p;{this.logger.debug("Resolving",o.name,"for",e.name);const s=this.resolve(o,r);t[i]=s}}return t}},R=class e{constructor(e,t,r,s=new Map){this.logger=e,this.options=t,this.isScoped=r,this.services=s}static{t(this,"ServiceCollection")}registerModules(...e){for(const t of e){(new t).registerServices(this)}}get(e){return this.services.get(e)??[]}overrideLifetime(e,t){for(const r of this.get(e))r.lifetime=t}register(...e){return new g(e,this.isScoped,((e,t)=>this.addService(e,t)))}addService(e,t){this.logger.info("Adding service",{identifier:e.name,descriptor:t});let r=this.services.get(e);null==r&&(r=[],this.services.set(e,r)),r.push(t)}clone(t){const r=new Map;for(const[e,t]of this.services){const s=t.map((e=>({...e})));r.set(e,s)}return new e(this.logger,this.options,!0===t,r)}buildProvider(){return new w(this.logger,this.clone())}},O=class{static{t(this,"ILogger")}debug(e,...t){}info(e,...t){}error(e,...t){}warn(e,...t){}},x=class extends O{constructor(e){super(),this.options=e}static{t(this,"ConsoleLogger")}debug(e,...t){this.options.logLevel<=0&&console.debug(e,...t)}info(e,...t){this.options.logLevel<=1&&console.info(e,...t)}warn(e,...t){this.options.logLevel<=2&&console.warn(e,...t)}error(e,...t){this.options.logLevel<=3&&console.error(e,...t)}},I=t((e=>({...o,...e})),"mergeOptions"),L=t((e=>{const t=I(e),r=t.logger??new x(t);return new R(r,t,!1)}),"createServiceCollection"),y=t(((e,t,r,s)=>{let i=m(e,t);void 0===i&&(i={},E(e,i,t)),i[r]=s}),"tagProperty"),b=t((e=>(t,r)=>function(t){const s=this.constructor;return y(f,s,r.name,e),t}),"dependsOn");exports.DefaultServiceCollectionOptions=o,exports.ILogger=O,exports.IResolutionScope=d,exports.IScopedProvider=u,exports.IServiceProvider=v,exports.Lifetime=r,exports.LogLevel=s,exports.MultipleRegistrationError=l,exports.ResolveMultipleMode=i,exports.ScopedSingletonRegistrationError=h,exports.SelfDependencyError=p,exports.ServiceCreationError=a,exports.ServiceError=n,exports.UnregisteredServiceError=c,exports.createServiceCollection=L,exports.dependsOn=b;//# sourceMappingURL=index.js.map
1
+ "use strict";require("@abraham/reflection");var e=Object.defineProperty,t=(t,r)=>e(t,"name",{value:r,configurable:!0}),r=(e=>(e.Resolve="RESOLVE",e.Transient="TRANSIENT",e.Scoped="SCOPED",e.Singleton="SINGLETON",e))(r||{}),s=(e=>(e[e.Debug=0]="Debug",e[e.Info=1]="Info",e[e.Warn=2]="Warn",e[e.Error=3]="Error",e[e.None=4]="None",e))(s||{}),i=(e=>(e.Error="ERROR",e.LastRegistered="LAST_REGISTERED",e))(i||{}),o={registrationMode:"ERROR",logLevel:2},n=class extends Error{static{t(this,"ServiceError")}},c=class extends n{static{t(this,"UnregisteredServiceError")}name="UnregisteredServiceError";constructor(e){super(`Resolving service that has not been registered: ${e.name}`),Object.setPrototypeOf(this,new.target.prototype)}},l=class extends n{static{t(this,"MultipleRegistrationError")}name="MultipleRegistrationError";constructor(e){super(`Multiple services have been registered: ${e.name}`),Object.setPrototypeOf(this,new.target.prototype)}},a=class extends n{constructor(e,t){super(`Error creating service: ${e.name}`),this.innerError=t,Object.setPrototypeOf(this,new.target.prototype)}static{t(this,"ServiceCreationError")}name="ServiceCreationError"},p=class extends n{static{t(this,"SelfDependencyError")}name="SelfDependencyError";constructor(){super("Service depending on itself"),Object.setPrototypeOf(this,new.target.prototype)}},h=class extends n{static{t(this,"ScopedSingletonRegistrationError")}name="ScopedSingletonRegistrationError";constructor(){super("Cannot register a singleton in a scoped service collection"),Object.setPrototypeOf(this,new.target.prototype)}},g=class{constructor(e,t,r){this.identifiers=e,this.isScoped=t,this.addService=r}static{t(this,"ServiceBuilder")}descriptor;to(e,t){this.descriptor=this.createDescriptor(t,e);for(const e of this.identifiers)this.addService(e,this.descriptor);return this}createDescriptor(e,t){const r=e??(()=>new t);return{implementation:t,createInstance:r,lifetime:"RESOLVE"}}singleton(){if(this.isScoped)throw new h;return this.ensureDescriptor().lifetime="SINGLETON",this}scoped(){return this.ensureDescriptor().lifetime="SCOPED",this}transient(){return this.ensureDescriptor().lifetime="TRANSIENT",this}ensureDescriptor(){if(!this.descriptor)throw new Error("Must call to() before setting lifetime");return this.descriptor}},d=class{static{t(this,"IDisposable")}},u=class{static{t(this,"IServiceModule")}},v=class{static{t(this,"IResolutionScope")}},S=class extends v{static{t(this,"IScopedProvider")}},f=class extends v{static{t(this,"IServiceProvider")}},m=class{static{t(this,"IServiceCollection")}},E=class{static{t(this,"ILifetimeBuilder")}},I=class{static{t(this,"IServiceBuilder")}},w=class{constructor(e,t){this.singletons=e,this.scoped=t}static{t(this,"ResolutionContext")}transient=new Map;getFromLifetime(e,t){const r=this.getMapForLifetime(t);return r?.get(e)}setForLifetime(e,t,r){const s=this.getMapForLifetime(r);s?.set(e,t)}getMapForLifetime(e){return{SINGLETON:this.singletons,SCOPED:this.scoped,RESOLVE:this.transient}[e]}},x="design:dependencies",R=t(((e,t)=>Reflect.getMetadata(e,t)),"getMetadata"),L=t(((e,t,r)=>Reflect.defineMetadata(e,t,r)),"defineMetadata"),O=class e{constructor(e,t,r=new Map){this.logger=e,this.Services=t,this.singletons=r}static{t(this,"ServiceProvider")}scoped=new Map;created=[];[Symbol.dispose](){for(const e of this.created)e[Symbol.dispose]()}resolveInternal(e,t){let r=t.getFromLifetime(e.implementation,e.lifetime);return null==r&&(r=this.createInstance(e,t)),r}resolveAll(e,t){return this.Services.get(e).map((e=>this.resolveInternal(e,t??new w(this.singletons,this.scoped))))}resolve(e,t){if(e.prototype===v.prototype||e.prototype===S.prototype||e.prototype===f.prototype)return this;const r=this.getSingleDescriptor(e);return this.resolveInternal(r,t??new w(this.singletons,this.scoped))}getSingleDescriptor(e){const t=this.Services.get(e);if(0===t.length)throw new c(e);if(t.length>1&&"ERROR"===this.Services.options.registrationMode)throw new l(e);return t[t.length-1]}createInstance(e,t){const r=this.createInstanceInternal(e,t);return this.setDependencies(e.implementation,r,t),t.setForLifetime(e.implementation,r,e.lifetime),r}wrapContext(e){return{resolve:t((t=>this.resolve(t,e)),"resolve"),resolveAll:t((t=>this.resolveAll(t,e)),"resolveAll")}}createInstanceInternal(e,t){let r;try{r=e.createInstance(this.wrapContext(t))}catch(t){throw this.logger.error(t),new a(e.implementation,t)}return"SINGLETON"!==e.lifetime&&Symbol.dispose in r&&this.created.push(r),r}createScope(){return new e(this.logger,this.Services.clone(!0),this.singletons)}setDependencies(e,t,r){const s=R(x,e)??{};this.logger.debug("Dependencies",e.name,s);for(const[i,o]of Object.entries(s)){if(o===e)throw new p;{this.logger.debug("Resolving",o.name,"for",e.name);const s=this.resolve(o,r);t[i]=s}}return t}},b=class e{constructor(e,t,r,s=new Map){this.logger=e,this.options=t,this.isScoped=r,this.services=s}static{t(this,"ServiceCollection")}registerModules(...e){for(const t of e){(new t).registerServices(this)}}get(e){return this.services.get(e)??[]}overrideLifetime(e,t){for(const r of this.get(e))r.lifetime=t}register(...e){return new g(e,this.isScoped,((e,t)=>this.addService(e,t)))}addService(e,t){this.logger.info("Adding service",{identifier:e.name,descriptor:t});let r=this.services.get(e);null==r&&(r=[],this.services.set(e,r)),r.push(t)}clone(t){const r=new Map;for(const[e,t]of this.services){const s=t.map((e=>({...e})));r.set(e,s)}return new e(this.logger,this.options,!0===t,r)}buildProvider(){return new O(this.logger,this.clone())}},y=class{static{t(this,"ILogger")}debug(e,...t){}info(e,...t){}error(e,...t){}warn(e,...t){}},M=class extends y{constructor(e){super(),this.options=e}static{t(this,"ConsoleLogger")}debug(e,...t){this.options.logLevel<=0&&console.debug(e,...t)}info(e,...t){this.options.logLevel<=1&&console.info(e,...t)}warn(e,...t){this.options.logLevel<=2&&console.warn(e,...t)}error(e,...t){this.options.logLevel<=3&&console.error(e,...t)}},D=t((e=>({...o,...e})),"mergeOptions"),C=t((e=>{const t=D(e),r=t.logger??new M(t);return new b(r,t,!1)}),"createServiceCollection"),P=t(((e,t,r,s)=>{let i=R(e,t);void 0===i&&(i={},L(e,i,t)),i[r]=s}),"tagProperty"),N=t((e=>(t,r)=>function(t){const s=this.constructor;return P(x,s,r.name,e),t}),"dependsOn");exports.DefaultServiceCollectionOptions=o,exports.IDisposable=d,exports.ILifetimeBuilder=E,exports.ILogger=y,exports.IResolutionScope=v,exports.IScopedProvider=S,exports.IServiceBuilder=I,exports.IServiceCollection=m,exports.IServiceModule=u,exports.IServiceProvider=f,exports.Lifetime=r,exports.LogLevel=s,exports.MultipleRegistrationError=l,exports.ResolveMultipleMode=i,exports.ScopedSingletonRegistrationError=h,exports.SelfDependencyError=p,exports.ServiceCreationError=a,exports.ServiceError=n,exports.UnregisteredServiceError=c,exports.createServiceCollection=C,exports.dependsOn=N;//# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/enums.ts","../src/defaults.ts","../src/errors.ts","../src/private/ServiceBuilder.ts","../src/interfaces.ts","../src/private/ResolutionContext.ts","../src/private/constants.ts","../src/private/metadata.ts","../src/private/ServiceProvider.ts","../src/private/ServiceCollection.ts","../src/logger.ts","../src/private/consoleLogger.ts","../src/createServiceCollection.ts","../src/dependsOn.ts"],"names":["Lifetime","LogLevel","ResolveMultipleMode"],"mappings":";;;;AAAY,IAAA,QAAA,qBAAAA,SAAL,KAAA;AACL,EAAAA,UAAA,SAAU,CAAA,GAAA,SAAA;AACV,EAAAA,UAAA,WAAY,CAAA,GAAA,WAAA;AACZ,EAAAA,UAAA,QAAS,CAAA,GAAA,QAAA;AACT,EAAAA,UAAA,WAAY,CAAA,GAAA,WAAA;AAJF,EAAAA,OAAAA,SAAAA;AAAA,CAA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A;;;ACXvC,IAAM,WAAc,mBAAA,MAAA,CAAA,CAAuB,WAAqB,EAAA,gBAAA,EAA0B,MAAuB,UAAqC,KAAA;AACpJ,EAAI,IAAA,QAAA,GAAW,WAAe,CAAA,WAAA,EAAa,gBAAgB,CAAA;AAC3D,EAAA,IAAI,aAAa,KAAW,CAAA,EAAA;AAC1B,IAAA,QAAA,GAAW,EAAC;AACZ,IAAe,cAAA,CAAA,WAAA,EAAa,UAAU,gBAAgB,CAAA;AAAA;AAExD,EAAA,QAAA,CAAS,IAAI,CAAI,GAAA,UAAA;AACnB,CAPoB,EAAA,aAAA,CAAA;AAcP,IAAA,SAAA,2BAAmC,UAAqC,KAAA;AACnF,EAAO,OAAA,CAAC,OAAkB,GAAoC,KAAA;AAC5D,IAAA,OAAO,SAAwB,YAAmB,EAAA;AAChD,MAAA,MAAM,SAAS,IAAK,CAAA,WAAA;AACpB,MAAA,WAAA,CAAY,qBAAuB,EAAA,MAAA,EAAQ,GAAI,CAAA,IAAA,EAAM,UAAU,CAAA;AAC/D,MAAO,OAAA,YAAA;AAAA,KACT;AAAA,GACF;AACF,CARyB,EAAA,WAAA","file":"index.js","sourcesContent":["export enum Lifetime {\n Resolve = 'RESOLVE',\n Transient = 'TRANSIENT',\n Scoped = 'SCOPED',\n Singleton = 'SINGLETON',\n}\n\nexport enum LogLevel {\n Debug = 0,\n Info = 1,\n Warn = 2,\n Error = 3,\n None = 4,\n}\n\nexport enum ResolveMultipleMode {\n Error = 'ERROR',\n LastRegistered = 'LAST_REGISTERED',\n}\n","import { LogLevel, ResolveMultipleMode } from './enums';\nimport type { ServiceCollectionOptions } from './types';\n\nexport const DefaultServiceCollectionOptions: ServiceCollectionOptions = {\n registrationMode: ResolveMultipleMode.Error,\n logLevel: LogLevel.Warn,\n};\n","import type { ServiceIdentifier } from './types';\n\nexport abstract class ServiceError extends Error {}\n\nexport class UnregisteredServiceError<T extends object> extends ServiceError {\n name = 'UnregisteredServiceError';\n constructor(identifier: ServiceIdentifier<T>) {\n super(`Resolving service that has not been registered: ${identifier.name}`);\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class MultipleRegistrationError<T extends object> extends ServiceError {\n name = 'MultipleRegistrationError';\n constructor(identifier: ServiceIdentifier<T>) {\n super(`Multiple services have been registered: ${identifier.name}`);\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class ServiceCreationError<T extends object> extends ServiceError {\n name = 'ServiceCreationError';\n constructor(\n identifier: ServiceIdentifier<T>,\n public readonly innerError: any,\n ) {\n super(`Error creating service: ${identifier.name}`);\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class SelfDependencyError extends ServiceError {\n name = 'SelfDependencyError';\n constructor() {\n super('Service depending on itself');\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class ScopedSingletonRegistrationError extends ServiceError {\n name = 'ScopedSingletonRegistrationError';\n constructor() {\n super('Cannot register a singleton in a scoped service collection');\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n","import { Lifetime } from '../enums';\nimport { ScopedSingletonRegistrationError } from '../errors';\nimport type { ILifetimeBuilder, IServiceBuilder, InstanceFactory, ServiceDescriptor, ServiceIdentifier, ServiceImplementation, SourceType } from '../types';\n\nexport class ServiceBuilder<T extends SourceType> implements IServiceBuilder<T> {\n private descriptor: ServiceDescriptor<T> | undefined;\n\n constructor(\n private readonly identifiers: ServiceIdentifier<T>[],\n private readonly isScoped: boolean,\n private readonly addService: (identifier: ServiceIdentifier<T>, descriptor: ServiceDescriptor<T>) => void,\n ) {}\n\n public to(implementation: ServiceImplementation<T>, factory?: InstanceFactory<T>): ILifetimeBuilder {\n this.descriptor = this.createDescriptor(factory, implementation);\n\n for (const identifier of this.identifiers) {\n this.addService(identifier, this.descriptor);\n }\n return this;\n }\n\n private createDescriptor(factory: InstanceFactory<T> | undefined, implementation: ServiceImplementation<T>): ServiceDescriptor<T> {\n const createInstance = factory ?? (() => new implementation());\n\n return {\n implementation,\n createInstance,\n lifetime: Lifetime.Resolve,\n };\n }\n\n public singleton(): this {\n if (this.isScoped) {\n throw new ScopedSingletonRegistrationError();\n }\n this.ensureDescriptor().lifetime = Lifetime.Singleton;\n return this;\n }\n\n public scoped(): this {\n this.ensureDescriptor().lifetime = Lifetime.Scoped;\n return this;\n }\n\n public transient(): this {\n this.ensureDescriptor().lifetime = Lifetime.Transient;\n return this;\n }\n\n private ensureDescriptor(): ServiceDescriptor<T> {\n if (!this.descriptor) {\n throw new Error('Must call to() before setting lifetime');\n }\n return this.descriptor;\n }\n}\n","import type { Lifetime } from './enums';\nimport { ResolveMultipleMode } from './enums';\nimport type { EnsureObject, IServiceBuilder, ServiceCollectionOptions, ServiceDescriptor, ServiceIdentifier, ServiceModuleType, SourceType, UnionToIntersection } from './types';\n\nexport interface IDisposable {\n [Symbol.dispose](): void;\n}\n\nexport interface IServiceModule {\n registerServices(services: IServiceCollection): void;\n}\n\nexport abstract class IResolutionScope {\n /**\n * Resolves a single implementation for the given identifier.\n * @template T The type of service to resolve\n * @param identifier The service identifier\n * @returns The resolved instance\n * @throws {MultipleRegistrationError} When multiple implementations exist (unless {@link ServiceCollectionOptions.registrationMode} is set to {@link ResolveMultipleMode.LastRegistered}).\n * @throws {UnregisteredServiceError} When no implementation exists\n */\n public abstract resolve<T extends SourceType>(identifier: ServiceIdentifier<T>): T;\n\n /**\n * Resolves all implementations for the given identifier.\n * @template T The type of service to resolve\n * @param identifier The service identifier\n * @returns Array of resolved instances\n */\n public abstract resolveAll<T extends SourceType>(identifier: ServiceIdentifier<T>): T[];\n}\n\nexport abstract class IScopedProvider extends IResolutionScope implements IDisposable {\n public abstract [Symbol.dispose](): void;\n}\n\nexport abstract class IServiceProvider extends IResolutionScope {\n public abstract readonly Services: IServiceCollection;\n public abstract createScope(): IScopedProvider;\n}\n\nexport interface IServiceCollection {\n readonly options: ServiceCollectionOptions;\n get<T extends SourceType>(identifier: ServiceIdentifier<T>): ServiceDescriptor<T>[];\n register<Types extends SourceType[]>(...identifiers: { [K in keyof Types]: ServiceIdentifier<Types[K]> }): IServiceBuilder<EnsureObject<UnionToIntersection<Types[number]>>>;\n registerModules(...modules: ServiceModuleType[]): void;\n overrideLifetime<T extends SourceType>(identifier: ServiceIdentifier<T>, lifetime: Lifetime): void;\n buildProvider(): IServiceProvider;\n clone(): IServiceCollection;\n clone(scoped: true): IServiceCollection;\n}\n","import { Lifetime } from '../enums';\nimport type { ServiceImplementation, SourceType } from '../types';\n\nexport class ResolutionContext {\n constructor(\n private readonly singletons: Map<ServiceImplementation<any>, any>,\n private readonly scoped: Map<ServiceImplementation<any>, any>,\n ) {}\n\n private readonly transient = new Map<ServiceImplementation<any>, any>();\n\n public getFromLifetime<T extends SourceType>(implementation: ServiceImplementation<T>, lifetime: Lifetime): T {\n const map = this.getMapForLifetime(lifetime);\n return map?.get(implementation);\n }\n\n public setForLifetime<T extends SourceType>(implementation: ServiceImplementation<T>, instance: T, lifetime: Lifetime): void {\n const map = this.getMapForLifetime(lifetime);\n map?.set(implementation, instance);\n }\n\n private getMapForLifetime(lifetime: Lifetime) {\n const map: Partial<Record<Lifetime, Map<ServiceImplementation<any>, any>>> = {\n [Lifetime.Singleton]: this.singletons,\n [Lifetime.Scoped]: this.scoped,\n [Lifetime.Resolve]: this.transient,\n };\n return map[lifetime];\n }\n}\n","export const DesignDependenciesKey = 'design:dependencies';\n","import '@abraham/reflection';\nimport type { MetadataType, SourceType } from '../types';\n\nexport const getMetadata = <T extends SourceType>(key: string, obj: object): MetadataType<T> | undefined => Reflect.getMetadata(key, obj);\nexport const defineMetadata = <T extends SourceType>(key: string, metadata: MetadataType<T>, obj: object) => Reflect.defineMetadata(key, metadata, obj);\n","import { Lifetime } from '../enums';\nimport { ResolveMultipleMode } from '../enums';\nimport { MultipleRegistrationError, SelfDependencyError, ServiceCreationError, UnregisteredServiceError } from '../errors';\nimport { type IDisposable, IResolutionScope, IScopedProvider, type IServiceCollection } from '../interfaces';\nimport { IServiceProvider } from '../interfaces';\nimport type { ILogger } from '../logger';\nimport type { ServiceDescriptor, ServiceIdentifier, ServiceImplementation, SourceType } from '../types';\nimport { ResolutionContext } from './ResolutionContext';\nimport { DesignDependenciesKey } from './constants';\nimport { getMetadata } from './metadata';\n\nexport class ServiceProvider implements IServiceProvider, IScopedProvider {\n private scoped = new Map<ServiceImplementation<any>, any>();\n private created: IDisposable[] = [];\n\n constructor(\n private readonly logger: ILogger,\n public readonly Services: IServiceCollection,\n private readonly singletons = new Map<ServiceImplementation<any>, any>(),\n ) {}\n\n [Symbol.dispose]() {\n for (const x of this.created) {\n x[Symbol.dispose]();\n }\n }\n\n private resolveInternal<T extends SourceType>(descriptor: ServiceDescriptor<T>, context: ResolutionContext): T {\n let instance = context.getFromLifetime(descriptor.implementation, descriptor.lifetime);\n if (instance == null) {\n instance = this.createInstance(descriptor, context);\n }\n return instance;\n }\n\n public resolveAll<T extends SourceType>(identifier: ServiceIdentifier<T>, context?: ResolutionContext): T[] {\n const descriptors = this.Services.get(identifier);\n return descriptors.map((descriptor) => this.resolveInternal<T>(descriptor, context ?? new ResolutionContext(this.singletons, this.scoped)));\n }\n\n public resolve<T extends SourceType>(identifier: ServiceIdentifier<T>, context?: ResolutionContext): T {\n if (identifier.prototype === IResolutionScope.prototype || identifier.prototype === IScopedProvider.prototype || identifier.prototype === IServiceProvider.prototype) {\n return this as IResolutionScope & IScopedProvider & IServiceProvider as T;\n }\n\n const descriptor = this.getSingleDescriptor(identifier);\n return this.resolveInternal(descriptor, context ?? new ResolutionContext(this.singletons, this.scoped));\n }\n\n private getSingleDescriptor<T extends SourceType>(identifier: ServiceIdentifier<T>) {\n const descriptors = this.Services.get(identifier);\n if (descriptors.length === 0) {\n throw new UnregisteredServiceError(identifier);\n }\n\n if (descriptors.length > 1) {\n if (this.Services.options.registrationMode === ResolveMultipleMode.Error) {\n throw new MultipleRegistrationError(identifier);\n }\n }\n const descriptor = descriptors[descriptors.length - 1];\n return descriptor;\n }\n\n private createInstance<T extends SourceType>(descriptor: ServiceDescriptor<T>, context: ResolutionContext): T {\n const instance = this.createInstanceInternal(descriptor, context);\n this.setDependencies(descriptor.implementation, instance, context);\n context.setForLifetime(descriptor.implementation, instance, descriptor.lifetime);\n return instance;\n }\n\n private wrapContext(context: ResolutionContext): IResolutionScope {\n const resolve = (identifier: ServiceIdentifier<any>) => this.resolve(identifier, context);\n const resolveAll = (identifier: ServiceIdentifier<any>) => this.resolveAll(identifier, context);\n\n return {\n resolve,\n resolveAll,\n };\n }\n\n private createInstanceInternal<T extends SourceType>(descriptor: ServiceDescriptor<T>, context: ResolutionContext) {\n let instance: T | undefined;\n try {\n instance = descriptor.createInstance(this.wrapContext(context));\n } catch (err) {\n this.logger.error(err);\n throw new ServiceCreationError(descriptor.implementation, err);\n }\n if (descriptor.lifetime !== Lifetime.Singleton && Symbol.dispose in instance) {\n this.created.push(instance as IDisposable);\n }\n return instance;\n }\n\n public createScope(): IScopedProvider {\n return new ServiceProvider(this.logger, this.Services.clone(true), this.singletons);\n }\n\n private setDependencies<T extends SourceType>(implementation: ServiceImplementation<T>, instance: T, context: ResolutionContext): T {\n const dependencies = getMetadata<T>(DesignDependenciesKey, implementation) ?? {};\n this.logger.debug('Dependencies', implementation.name, dependencies);\n for (const [key, identifier] of Object.entries(dependencies)) {\n if (identifier !== implementation) {\n this.logger.debug('Resolving', identifier.name, 'for', implementation.name);\n const dep = this.resolve(identifier, context);\n (instance as Record<string, T>)[key] = dep;\n } else {\n throw new SelfDependencyError();\n }\n }\n return instance;\n }\n}\n","import type { Lifetime } from '../enums';\nimport type { IServiceCollection, IServiceProvider } from '../interfaces';\nimport type { ILogger } from '../logger';\nimport type { EnsureObject, IServiceBuilder, ServiceCollectionOptions, ServiceDescriptor, ServiceIdentifier, ServiceModuleType, SourceType, UnionToIntersection } from '../types';\nimport { ServiceBuilder } from './ServiceBuilder';\nimport { ServiceProvider } from './ServiceProvider';\n\nexport class ServiceCollection implements IServiceCollection {\n constructor(\n private readonly logger: ILogger,\n public readonly options: ServiceCollectionOptions,\n private readonly isScoped: boolean,\n private readonly services = new Map<ServiceIdentifier<any>, ServiceDescriptor<any>[]>(),\n ) {}\n\n public registerModules(...modules: ServiceModuleType[]): void {\n for (const x of modules) {\n const module = new x();\n module.registerServices(this);\n }\n }\n\n get<T extends SourceType>(key: ServiceIdentifier<T>): ServiceDescriptor<T>[] {\n return this.services.get(key) ?? [];\n }\n\n public overrideLifetime<T extends SourceType>(identifier: ServiceIdentifier<T>, lifetime: Lifetime): void {\n for (const descriptor of this.get(identifier)) {\n descriptor.lifetime = lifetime;\n }\n }\n\n register<Types extends SourceType[]>(...identifiers: { [K in keyof Types]: ServiceIdentifier<Types[K]> }): IServiceBuilder<EnsureObject<UnionToIntersection<Types[number]>>> {\n return new ServiceBuilder(identifiers, this.isScoped, (identifier, descriptor) => this.addService(identifier, descriptor));\n }\n\n private addService<T extends SourceType>(identifier: ServiceIdentifier<T>, descriptor: ServiceDescriptor<T>) {\n this.logger.info('Adding service', { identifier: identifier.name, descriptor });\n let existing = this.services.get(identifier);\n if (existing == null) {\n existing = [];\n this.services.set(identifier, existing);\n }\n existing.push(descriptor);\n }\n\n public clone(scoped?: unknown): IServiceCollection {\n const clonedMap = new Map<ServiceIdentifier<any>, ServiceDescriptor<any>[]>();\n for (const [key, descriptors] of this.services) {\n const clonedDescriptors = descriptors.map((descriptor) => ({ ...descriptor }));\n clonedMap.set(key, clonedDescriptors);\n }\n\n return new ServiceCollection(this.logger, this.options, scoped === true, clonedMap);\n }\n\n public buildProvider(): IServiceProvider {\n return new ServiceProvider(this.logger, this.clone());\n }\n}\n","export abstract class ILogger {\n public debug(_message?: any, ..._optionalParams: any[]) {}\n public info(_message?: any, ..._optionalParams: any[]) {}\n public error(_message?: any, ..._optionalParams: any[]) {}\n public warn(_message?: any, ..._optionalParams: any[]) {}\n}\n","import { LogLevel } from '../enums';\nimport { ILogger } from '../logger';\nimport type { ServiceCollectionOptions } from '../types';\n\nexport class ConsoleLogger extends ILogger {\n constructor(private readonly options: ServiceCollectionOptions) {\n super();\n }\n\n public override debug(message?: any, ...optionalParams: any[]): void {\n if (this.options.logLevel <= LogLevel.Debug) {\n console.debug(message, ...optionalParams);\n }\n }\n\n public override info(message?: any, ...optionalParams: any[]): void {\n if (this.options.logLevel <= LogLevel.Info) {\n console.info(message, ...optionalParams);\n }\n }\n\n public override warn(message?: any, ...optionalParams: any[]): void {\n if (this.options.logLevel <= LogLevel.Warn) {\n console.warn(message, ...optionalParams);\n }\n }\n\n public override error(message?: any, ...optionalParams: any[]): void {\n if (this.options.logLevel <= LogLevel.Error) {\n console.error(message, ...optionalParams);\n }\n }\n}\n","import { DefaultServiceCollectionOptions } from './defaults';\nimport type { IServiceCollection } from './interfaces';\nimport { ServiceCollection } from './private/ServiceCollection';\nimport { ConsoleLogger } from './private/consoleLogger';\nimport type { ServiceCollectionOptions } from './types';\n\nconst mergeOptions = (options: Partial<ServiceCollectionOptions> | undefined): ServiceCollectionOptions => ({\n ...DefaultServiceCollectionOptions,\n ...options,\n});\n\n/**\n * Creates a service collection with the (optionally) provided options\n * @param options - Optional configuration for the service collection.\n * @defaultValue Default options are taken from {@link DefaultServiceCollectionOptions}.\n */\nexport const createServiceCollection = (options?: Partial<ServiceCollectionOptions>): IServiceCollection => {\n const mergedOptions = mergeOptions(options);\n const logger = mergedOptions.logger ?? new ConsoleLogger(mergedOptions);\n return new ServiceCollection(logger, mergedOptions, false);\n};\n","import { IResolutionScope, IScopedProvider, IServiceProvider } from './interfaces';\nimport { DesignDependenciesKey } from './private/constants';\nimport { defineMetadata, getMetadata } from './private/metadata';\nimport type { ServiceIdentifier, SourceType } from './types';\n\nconst tagProperty = <T extends SourceType>(metadataKey: string, annotationTarget: object, name: string | symbol, identifier: ServiceIdentifier<T>) => {\n let existing = getMetadata<T>(metadataKey, annotationTarget);\n if (existing === undefined) {\n existing = {};\n defineMetadata(metadataKey, existing, annotationTarget);\n }\n existing[name] = identifier;\n};\n\n/**\n * declares a dependency, use on a class field.\n * Can also depend on {@link IServiceProvider}, {@link IResolutionScope}, or {@link IScopedProvider}.\n * @param identifier the identifier to depend on, i.e. the interface\n */\nexport const dependsOn = <T extends SourceType>(identifier: ServiceIdentifier<T>) => {\n return (value: undefined, ctx: ClassFieldDecoratorContext) => {\n return function (this: object, initialValue: any) {\n const target = this.constructor;\n tagProperty(DesignDependenciesKey, target, ctx.name, identifier);\n return initialValue;\n };\n };\n};\n"]}
1
+ {"version":3,"sources":["../src/enums.ts","../src/defaults.ts","../src/errors.ts","../src/private/ServiceBuilder.ts","../src/interfaces.ts","../src/private/ResolutionContext.ts","../src/private/constants.ts","../src/private/metadata.ts","../src/private/ServiceProvider.ts","../src/private/ServiceCollection.ts","../src/logger.ts","../src/private/consoleLogger.ts","../src/createServiceCollection.ts","../src/dependsOn.ts"],"names":["Lifetime","LogLevel","ResolveMultipleMode"],"mappings":";;;;AAAY,IAAA,QAAA,qBAAAA,SAAL,KAAA;AACL,EAAAA,UAAA,SAAU,CAAA,GAAA,SAAA;AACV,EAAAA,UAAA,WAAY,CAAA,GAAA,WAAA;AACZ,EAAAA,UAAA,QAAS,CAAA,GAAA,QAAA;AACT,EAAAA,UAAA,WAAY,CAAA,GAAA,WAAA;AAJF,EAAAA,OAAAA,SAAAA;AAAA,CAAA,EAAA,QAAA,IAAA,EAAA;AAOA,IAAA,QAAA,qBAAAC,SAAL,KAAA;AACL,EAAAA,SAAAA,CAAAA,SAAAA,CAAA,WAAQ,CAAR,CAAA,GAAA,OAAA;AACA,EAAAA,SAAAA,CAAAA,SAAAA,CAAA,UAAO,CAAP,CAAA,GAAA,MAAA;AACA,EAAAA,SAAAA,CAAAA,SAAAA,CAAA,UAAO,CAAP,CAAA,GAAA,MAAA;AACA,EAAAA,SAAAA,CAAAA,SAAAA,CAAA,WAAQ,CAAR,CAAA,GAAA,OAAA;AACA,EAAAA,SAAAA,CAAAA,SAAAA,CAAA,UAAO,CAAP,CAAA,GAAA,MAAA;AALU,EAAAA,OAAAA,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AI,iBAAA,CAAkB,MAAQ,EAAA,aAAA,EAAe,KAAK,CAAA;AAC3D,CAJuC,EAAA,yBAAA;;;ACXvC,IAAM,WAAc,mBAAA,MAAA,CAAA,CAAuB,WAAqB,EAAA,gBAAA,EAA0B,MAAuB,UAAqC,KAAA;AACpJ,EAAI,IAAA,QAAA,GAAW,WAAe,CAAA,WAAA,EAAa,gBAAgB,CAAA;AAC3D,EAAA,IAAI,aAAa,KAAW,CAAA,EAAA;AAC1B,IAAA,QAAA,GAAW,EAAC;AACZ,IAAe,cAAA,CAAA,WAAA,EAAa,UAAU,gBAAgB,CAAA;AAAA;AAExD,EAAA,QAAA,CAAS,IAAI,CAAI,GAAA,UAAA;AACnB,CAPoB,EAAA,aAAA,CAAA;AAcP,IAAA,SAAA,2BAAmC,UAAqC,KAAA;AACnF,EAAO,OAAA,CAAC,OAAkB,GAAoC,KAAA;AAC5D,IAAA,OAAO,SAAwB,YAAmB,EAAA;AAChD,MAAA,MAAM,SAAS,IAAK,CAAA,WAAA;AACpB,MAAA,WAAA,CAAY,qBAAuB,EAAA,MAAA,EAAQ,GAAI,CAAA,IAAA,EAAM,UAAU,CAAA;AAC/D,MAAO,OAAA,YAAA;AAAA,KACT;AAAA,GACF;AACF,CARyB,EAAA,WAAA","file":"index.js","sourcesContent":["export enum Lifetime {\n Resolve = 'RESOLVE',\n Transient = 'TRANSIENT',\n Scoped = 'SCOPED',\n Singleton = 'SINGLETON',\n}\n\nexport enum LogLevel {\n Debug = 0,\n Info = 1,\n Warn = 2,\n Error = 3,\n None = 4,\n}\n\nexport enum ResolveMultipleMode {\n Error = 'ERROR',\n LastRegistered = 'LAST_REGISTERED',\n}\n","import { LogLevel, ResolveMultipleMode } from './enums';\nimport type { ServiceCollectionOptions } from './types';\n\nexport const DefaultServiceCollectionOptions: ServiceCollectionOptions = {\n registrationMode: ResolveMultipleMode.Error,\n logLevel: LogLevel.Warn,\n};\n","import type { ServiceIdentifier } from './types';\n\nexport abstract class ServiceError extends Error {}\n\nexport class UnregisteredServiceError<T extends object> extends ServiceError {\n name = 'UnregisteredServiceError';\n constructor(identifier: ServiceIdentifier<T>) {\n super(`Resolving service that has not been registered: ${identifier.name}`);\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class MultipleRegistrationError<T extends object> extends ServiceError {\n name = 'MultipleRegistrationError';\n constructor(identifier: ServiceIdentifier<T>) {\n super(`Multiple services have been registered: ${identifier.name}`);\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class ServiceCreationError<T extends object> extends ServiceError {\n name = 'ServiceCreationError';\n constructor(\n identifier: ServiceIdentifier<T>,\n public readonly innerError: any,\n ) {\n super(`Error creating service: ${identifier.name}`);\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class SelfDependencyError extends ServiceError {\n name = 'SelfDependencyError';\n constructor() {\n super('Service depending on itself');\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class ScopedSingletonRegistrationError extends ServiceError {\n name = 'ScopedSingletonRegistrationError';\n constructor() {\n super('Cannot register a singleton in a scoped service collection');\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n","import { Lifetime } from '../enums';\nimport { ScopedSingletonRegistrationError } from '../errors';\nimport type { ILifetimeBuilder, IServiceBuilder } from '../interfaces';\nimport type { InstanceFactory, ServiceDescriptor, ServiceIdentifier, ServiceImplementation, SourceType } from '../types';\n\nexport class ServiceBuilder<T extends SourceType> implements IServiceBuilder<T> {\n private descriptor: ServiceDescriptor<T> | undefined;\n\n constructor(\n private readonly identifiers: ServiceIdentifier<T>[],\n private readonly isScoped: boolean,\n private readonly addService: (identifier: ServiceIdentifier<T>, descriptor: ServiceDescriptor<T>) => void,\n ) {}\n\n public to(implementation: ServiceImplementation<T>, factory?: InstanceFactory<T>): ILifetimeBuilder {\n this.descriptor = this.createDescriptor(factory, implementation);\n\n for (const identifier of this.identifiers) {\n this.addService(identifier, this.descriptor);\n }\n return this;\n }\n\n private createDescriptor(factory: InstanceFactory<T> | undefined, implementation: ServiceImplementation<T>): ServiceDescriptor<T> {\n const createInstance = factory ?? (() => new implementation());\n\n return {\n implementation,\n createInstance,\n lifetime: Lifetime.Resolve,\n };\n }\n\n public singleton(): this {\n if (this.isScoped) {\n throw new ScopedSingletonRegistrationError();\n }\n this.ensureDescriptor().lifetime = Lifetime.Singleton;\n return this;\n }\n\n public scoped(): this {\n this.ensureDescriptor().lifetime = Lifetime.Scoped;\n return this;\n }\n\n public transient(): this {\n this.ensureDescriptor().lifetime = Lifetime.Transient;\n return this;\n }\n\n private ensureDescriptor(): ServiceDescriptor<T> {\n if (!this.descriptor) {\n throw new Error('Must call to() before setting lifetime');\n }\n return this.descriptor;\n }\n}\n","import type { Lifetime } from './enums';\nimport { ResolveMultipleMode } from './enums';\nimport type { EnsureObject, ServiceBuilderOptions, ServiceCollectionOptions, ServiceDescriptor, ServiceIdentifier, ServiceModuleType, SourceType, UnionToIntersection } from './types';\n\nexport abstract class IDisposable {\n public abstract [Symbol.dispose](): void;\n}\n\nexport abstract class IServiceModule {\n public abstract registerServices(services: IServiceCollection): void;\n}\n\nexport abstract class IResolutionScope {\n /**\n * Resolves a single implementation for the given identifier.\n * @template T The type of service to resolve\n * @param identifier The service identifier\n * @returns The resolved instance\n * @throws {MultipleRegistrationError} When multiple implementations exist (unless {@link ServiceCollectionOptions.registrationMode} is set to {@link ResolveMultipleMode.LastRegistered}).\n * @throws {UnregisteredServiceError} When no implementation exists\n */\n public abstract resolve<T extends SourceType>(identifier: ServiceIdentifier<T>): T;\n\n /**\n * Resolves all implementations for the given identifier.\n * @template T The type of service to resolve\n * @param identifier The service identifier\n * @returns Array of resolved instances\n */\n public abstract resolveAll<T extends SourceType>(identifier: ServiceIdentifier<T>): T[];\n}\n\nexport abstract class IScopedProvider extends IResolutionScope implements IDisposable {\n public abstract readonly Services: IServiceCollection;\n public abstract [Symbol.dispose](): void;\n}\n\nexport abstract class IServiceProvider extends IResolutionScope {\n public abstract readonly Services: IServiceCollection;\n public abstract createScope(): IScopedProvider;\n}\n\nexport abstract class IServiceCollection {\n public abstract readonly options: ServiceCollectionOptions;\n public abstract get<T extends SourceType>(identifier: ServiceIdentifier<T>): ServiceDescriptor<T>[];\n public abstract register<Types extends SourceType[]>(...identifiers: { [K in keyof Types]: ServiceIdentifier<Types[K]> }): IServiceBuilder<EnsureObject<UnionToIntersection<Types[number]>>>;\n public abstract registerModules(...modules: ServiceModuleType[]): void;\n public abstract overrideLifetime<T extends SourceType>(identifier: ServiceIdentifier<T>, lifetime: Lifetime): void;\n public abstract buildProvider(): IServiceProvider;\n public abstract clone(): IServiceCollection;\n public abstract clone(scoped: true): IServiceCollection;\n}\n\nexport abstract class ILifetimeBuilder {\n public abstract singleton(): ILifetimeBuilder;\n public abstract scoped(): ILifetimeBuilder;\n public abstract transient(): ILifetimeBuilder;\n}\n\nexport abstract class IServiceBuilder<T extends SourceType> {\n public abstract to: ServiceBuilderOptions<T>;\n}\n","import { Lifetime } from '../enums';\nimport type { ServiceImplementation, SourceType } from '../types';\n\nexport class ResolutionContext {\n constructor(\n private readonly singletons: Map<ServiceImplementation<any>, any>,\n private readonly scoped: Map<ServiceImplementation<any>, any>,\n ) {}\n\n private readonly transient = new Map<ServiceImplementation<any>, any>();\n\n public getFromLifetime<T extends SourceType>(implementation: ServiceImplementation<T>, lifetime: Lifetime): T {\n const map = this.getMapForLifetime(lifetime);\n return map?.get(implementation);\n }\n\n public setForLifetime<T extends SourceType>(implementation: ServiceImplementation<T>, instance: T, lifetime: Lifetime): void {\n const map = this.getMapForLifetime(lifetime);\n map?.set(implementation, instance);\n }\n\n private getMapForLifetime(lifetime: Lifetime) {\n const map: Partial<Record<Lifetime, Map<ServiceImplementation<any>, any>>> = {\n [Lifetime.Singleton]: this.singletons,\n [Lifetime.Scoped]: this.scoped,\n [Lifetime.Resolve]: this.transient,\n };\n return map[lifetime];\n }\n}\n","export const DesignDependenciesKey = 'design:dependencies';\n","import '@abraham/reflection';\nimport type { MetadataType, SourceType } from '../types';\n\nexport const getMetadata = <T extends SourceType>(key: string, obj: object): MetadataType<T> | undefined => Reflect.getMetadata(key, obj);\nexport const defineMetadata = <T extends SourceType>(key: string, metadata: MetadataType<T>, obj: object) => Reflect.defineMetadata(key, metadata, obj);\n","import { Lifetime } from '../enums';\nimport { ResolveMultipleMode } from '../enums';\nimport { MultipleRegistrationError, SelfDependencyError, ServiceCreationError, UnregisteredServiceError } from '../errors';\nimport { type IDisposable, IResolutionScope, IScopedProvider, type IServiceCollection } from '../interfaces';\nimport { IServiceProvider } from '../interfaces';\nimport type { ILogger } from '../logger';\nimport type { ServiceDescriptor, ServiceIdentifier, ServiceImplementation, SourceType } from '../types';\nimport { ResolutionContext } from './ResolutionContext';\nimport { DesignDependenciesKey } from './constants';\nimport { getMetadata } from './metadata';\n\nexport class ServiceProvider implements IServiceProvider, IScopedProvider {\n private scoped = new Map<ServiceImplementation<any>, any>();\n private created: IDisposable[] = [];\n\n constructor(\n private readonly logger: ILogger,\n public readonly Services: IServiceCollection,\n private readonly singletons = new Map<ServiceImplementation<any>, any>(),\n ) {}\n\n [Symbol.dispose]() {\n for (const x of this.created) {\n x[Symbol.dispose]();\n }\n }\n\n private resolveInternal<T extends SourceType>(descriptor: ServiceDescriptor<T>, context: ResolutionContext): T {\n let instance = context.getFromLifetime(descriptor.implementation, descriptor.lifetime);\n if (instance == null) {\n instance = this.createInstance(descriptor, context);\n }\n return instance;\n }\n\n public resolveAll<T extends SourceType>(identifier: ServiceIdentifier<T>, context?: ResolutionContext): T[] {\n const descriptors = this.Services.get(identifier);\n return descriptors.map((descriptor) => this.resolveInternal<T>(descriptor, context ?? new ResolutionContext(this.singletons, this.scoped)));\n }\n\n public resolve<T extends SourceType>(identifier: ServiceIdentifier<T>, context?: ResolutionContext): T {\n if (identifier.prototype === IResolutionScope.prototype || identifier.prototype === IScopedProvider.prototype || identifier.prototype === IServiceProvider.prototype) {\n return this as IResolutionScope & IScopedProvider & IServiceProvider as T;\n }\n\n const descriptor = this.getSingleDescriptor(identifier);\n return this.resolveInternal(descriptor, context ?? new ResolutionContext(this.singletons, this.scoped));\n }\n\n private getSingleDescriptor<T extends SourceType>(identifier: ServiceIdentifier<T>) {\n const descriptors = this.Services.get(identifier);\n if (descriptors.length === 0) {\n throw new UnregisteredServiceError(identifier);\n }\n\n if (descriptors.length > 1) {\n if (this.Services.options.registrationMode === ResolveMultipleMode.Error) {\n throw new MultipleRegistrationError(identifier);\n }\n }\n const descriptor = descriptors[descriptors.length - 1];\n return descriptor;\n }\n\n private createInstance<T extends SourceType>(descriptor: ServiceDescriptor<T>, context: ResolutionContext): T {\n const instance = this.createInstanceInternal(descriptor, context);\n this.setDependencies(descriptor.implementation, instance, context);\n context.setForLifetime(descriptor.implementation, instance, descriptor.lifetime);\n return instance;\n }\n\n private wrapContext(context: ResolutionContext): IResolutionScope {\n const resolve = (identifier: ServiceIdentifier<any>) => this.resolve(identifier, context);\n const resolveAll = (identifier: ServiceIdentifier<any>) => this.resolveAll(identifier, context);\n\n return {\n resolve,\n resolveAll,\n };\n }\n\n private createInstanceInternal<T extends SourceType>(descriptor: ServiceDescriptor<T>, context: ResolutionContext) {\n let instance: T | undefined;\n try {\n instance = descriptor.createInstance(this.wrapContext(context));\n } catch (err) {\n this.logger.error(err);\n throw new ServiceCreationError(descriptor.implementation, err);\n }\n if (descriptor.lifetime !== Lifetime.Singleton && Symbol.dispose in instance) {\n this.created.push(instance as IDisposable);\n }\n return instance;\n }\n\n public createScope(): IScopedProvider {\n return new ServiceProvider(this.logger, this.Services.clone(true), this.singletons);\n }\n\n private setDependencies<T extends SourceType>(implementation: ServiceImplementation<T>, instance: T, context: ResolutionContext): T {\n const dependencies = getMetadata<T>(DesignDependenciesKey, implementation) ?? {};\n this.logger.debug('Dependencies', implementation.name, dependencies);\n for (const [key, identifier] of Object.entries(dependencies)) {\n if (identifier !== implementation) {\n this.logger.debug('Resolving', identifier.name, 'for', implementation.name);\n const dep = this.resolve(identifier, context);\n (instance as Record<string, T>)[key] = dep;\n } else {\n throw new SelfDependencyError();\n }\n }\n return instance;\n }\n}\n","import type { Lifetime } from '../enums';\nimport type { IServiceBuilder, IServiceCollection, IServiceProvider } from '../interfaces';\nimport type { ILogger } from '../logger';\nimport type { EnsureObject, ServiceCollectionOptions, ServiceDescriptor, ServiceIdentifier, ServiceModuleType, SourceType, UnionToIntersection } from '../types';\nimport { ServiceBuilder } from './ServiceBuilder';\nimport { ServiceProvider } from './ServiceProvider';\n\nexport class ServiceCollection implements IServiceCollection {\n constructor(\n private readonly logger: ILogger,\n public readonly options: ServiceCollectionOptions,\n private readonly isScoped: boolean,\n private readonly services = new Map<ServiceIdentifier<any>, ServiceDescriptor<any>[]>(),\n ) {}\n\n public registerModules(...modules: ServiceModuleType[]): void {\n for (const x of modules) {\n const module = new x();\n module.registerServices(this);\n }\n }\n\n get<T extends SourceType>(key: ServiceIdentifier<T>): ServiceDescriptor<T>[] {\n return this.services.get(key) ?? [];\n }\n\n public overrideLifetime<T extends SourceType>(identifier: ServiceIdentifier<T>, lifetime: Lifetime): void {\n for (const descriptor of this.get(identifier)) {\n descriptor.lifetime = lifetime;\n }\n }\n\n register<Types extends SourceType[]>(...identifiers: { [K in keyof Types]: ServiceIdentifier<Types[K]> }): IServiceBuilder<EnsureObject<UnionToIntersection<Types[number]>>> {\n return new ServiceBuilder(identifiers, this.isScoped, (identifier, descriptor) => this.addService(identifier, descriptor));\n }\n\n private addService<T extends SourceType>(identifier: ServiceIdentifier<T>, descriptor: ServiceDescriptor<T>) {\n this.logger.info('Adding service', { identifier: identifier.name, descriptor });\n let existing = this.services.get(identifier);\n if (existing == null) {\n existing = [];\n this.services.set(identifier, existing);\n }\n existing.push(descriptor);\n }\n\n public clone(scoped?: unknown): IServiceCollection {\n const clonedMap = new Map<ServiceIdentifier<any>, ServiceDescriptor<any>[]>();\n for (const [key, descriptors] of this.services) {\n const clonedDescriptors = descriptors.map((descriptor) => ({ ...descriptor }));\n clonedMap.set(key, clonedDescriptors);\n }\n\n return new ServiceCollection(this.logger, this.options, scoped === true, clonedMap);\n }\n\n public buildProvider(): IServiceProvider {\n return new ServiceProvider(this.logger, this.clone());\n }\n}\n","export abstract class ILogger {\n public debug(_message?: any, ..._optionalParams: any[]) {}\n public info(_message?: any, ..._optionalParams: any[]) {}\n public error(_message?: any, ..._optionalParams: any[]) {}\n public warn(_message?: any, ..._optionalParams: any[]) {}\n}\n","import { LogLevel } from '../enums';\nimport { ILogger } from '../logger';\nimport type { ServiceCollectionOptions } from '../types';\n\nexport class ConsoleLogger extends ILogger {\n constructor(private readonly options: ServiceCollectionOptions) {\n super();\n }\n\n public override debug(message?: any, ...optionalParams: any[]): void {\n if (this.options.logLevel <= LogLevel.Debug) {\n console.debug(message, ...optionalParams);\n }\n }\n\n public override info(message?: any, ...optionalParams: any[]): void {\n if (this.options.logLevel <= LogLevel.Info) {\n console.info(message, ...optionalParams);\n }\n }\n\n public override warn(message?: any, ...optionalParams: any[]): void {\n if (this.options.logLevel <= LogLevel.Warn) {\n console.warn(message, ...optionalParams);\n }\n }\n\n public override error(message?: any, ...optionalParams: any[]): void {\n if (this.options.logLevel <= LogLevel.Error) {\n console.error(message, ...optionalParams);\n }\n }\n}\n","import { DefaultServiceCollectionOptions } from './defaults';\nimport type { IServiceCollection } from './interfaces';\nimport { ServiceCollection } from './private/ServiceCollection';\nimport { ConsoleLogger } from './private/consoleLogger';\nimport type { ServiceCollectionOptions } from './types';\n\nconst mergeOptions = (options: Partial<ServiceCollectionOptions> | undefined): ServiceCollectionOptions => ({\n ...DefaultServiceCollectionOptions,\n ...options,\n});\n\n/**\n * Creates a service collection with the (optionally) provided options\n * @param options - Optional configuration for the service collection.\n * @defaultValue Default options are taken from {@link DefaultServiceCollectionOptions}.\n */\nexport const createServiceCollection = (options?: Partial<ServiceCollectionOptions>): IServiceCollection => {\n const mergedOptions = mergeOptions(options);\n const logger = mergedOptions.logger ?? new ConsoleLogger(mergedOptions);\n return new ServiceCollection(logger, mergedOptions, false);\n};\n","import { IResolutionScope, IScopedProvider, IServiceProvider } from './interfaces';\nimport { DesignDependenciesKey } from './private/constants';\nimport { defineMetadata, getMetadata } from './private/metadata';\nimport type { ServiceIdentifier, SourceType } from './types';\n\nconst tagProperty = <T extends SourceType>(metadataKey: string, annotationTarget: object, name: string | symbol, identifier: ServiceIdentifier<T>) => {\n let existing = getMetadata<T>(metadataKey, annotationTarget);\n if (existing === undefined) {\n existing = {};\n defineMetadata(metadataKey, existing, annotationTarget);\n }\n existing[name] = identifier;\n};\n\n/**\n * declares a dependency, use on a class field.\n * Can also depend on {@link IServiceProvider}, {@link IResolutionScope}, or {@link IScopedProvider}.\n * @param identifier the identifier to depend on, i.e. the interface\n */\nexport const dependsOn = <T extends SourceType>(identifier: ServiceIdentifier<T>) => {\n return (value: undefined, ctx: ClassFieldDecoratorContext) => {\n return function (this: object, initialValue: any) {\n const target = this.constructor;\n tagProperty(DesignDependenciesKey, target, ctx.name, identifier);\n return initialValue;\n };\n };\n};\n"]}
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import"@abraham/reflection";var e=Object.defineProperty,t=(t,r)=>e(t,"name",{value:r,configurable:!0}),r=(e=>(e.Resolve="RESOLVE",e.Transient="TRANSIENT",e.Scoped="SCOPED",e.Singleton="SINGLETON",e))(r||{}),s=(e=>(e[e.Debug=0]="Debug",e[e.Info=1]="Info",e[e.Warn=2]="Warn",e[e.Error=3]="Error",e[e.None=4]="None",e))(s||{}),i=(e=>(e.Error="ERROR",e.LastRegistered="LAST_REGISTERED",e))(i||{}),o={registrationMode:"ERROR",logLevel:2},n=class extends Error{static{t(this,"ServiceError")}},c=class extends n{static{t(this,"UnregisteredServiceError")}name="UnregisteredServiceError";constructor(e){super(`Resolving service that has not been registered: ${e.name}`),Object.setPrototypeOf(this,new.target.prototype)}},a=class extends n{static{t(this,"MultipleRegistrationError")}name="MultipleRegistrationError";constructor(e){super(`Multiple services have been registered: ${e.name}`),Object.setPrototypeOf(this,new.target.prototype)}},l=class extends n{constructor(e,t){super(`Error creating service: ${e.name}`),this.innerError=t,Object.setPrototypeOf(this,new.target.prototype)}static{t(this,"ServiceCreationError")}name="ServiceCreationError"},h=class extends n{static{t(this,"SelfDependencyError")}name="SelfDependencyError";constructor(){super("Service depending on itself"),Object.setPrototypeOf(this,new.target.prototype)}},p=class extends n{static{t(this,"ScopedSingletonRegistrationError")}name="ScopedSingletonRegistrationError";constructor(){super("Cannot register a singleton in a scoped service collection"),Object.setPrototypeOf(this,new.target.prototype)}},g=class{constructor(e,t,r){this.identifiers=e,this.isScoped=t,this.addService=r}static{t(this,"ServiceBuilder")}descriptor;to(e,t){this.descriptor=this.createDescriptor(t,e);for(const e of this.identifiers)this.addService(e,this.descriptor);return this}createDescriptor(e,t){const r=e??(()=>new t);return{implementation:t,createInstance:r,lifetime:"RESOLVE"}}singleton(){if(this.isScoped)throw new p;return this.ensureDescriptor().lifetime="SINGLETON",this}scoped(){return this.ensureDescriptor().lifetime="SCOPED",this}transient(){return this.ensureDescriptor().lifetime="TRANSIENT",this}ensureDescriptor(){if(!this.descriptor)throw new Error("Must call to() before setting lifetime");return this.descriptor}},d=class{static{t(this,"IResolutionScope")}},u=class extends d{static{t(this,"IScopedProvider")}},f=class extends d{static{t(this,"IServiceProvider")}},v=class{constructor(e,t){this.singletons=e,this.scoped=t}static{t(this,"ResolutionContext")}transient=new Map;getFromLifetime(e,t){const r=this.getMapForLifetime(t);return r?.get(e)}setForLifetime(e,t,r){const s=this.getMapForLifetime(r);s?.set(e,t)}getMapForLifetime(e){return{SINGLETON:this.singletons,SCOPED:this.scoped,RESOLVE:this.transient}[e]}},S="design:dependencies",m=t(((e,t)=>Reflect.getMetadata(e,t)),"getMetadata"),E=t(((e,t,r)=>Reflect.defineMetadata(e,t,r)),"defineMetadata"),w=class e{constructor(e,t,r=new Map){this.logger=e,this.Services=t,this.singletons=r}static{t(this,"ServiceProvider")}scoped=new Map;created=[];[Symbol.dispose](){for(const e of this.created)e[Symbol.dispose]()}resolveInternal(e,t){let r=t.getFromLifetime(e.implementation,e.lifetime);return null==r&&(r=this.createInstance(e,t)),r}resolveAll(e,t){return this.Services.get(e).map((e=>this.resolveInternal(e,t??new v(this.singletons,this.scoped))))}resolve(e,t){if(e.prototype===d.prototype||e.prototype===u.prototype||e.prototype===f.prototype)return this;const r=this.getSingleDescriptor(e);return this.resolveInternal(r,t??new v(this.singletons,this.scoped))}getSingleDescriptor(e){const t=this.Services.get(e);if(0===t.length)throw new c(e);if(t.length>1&&"ERROR"===this.Services.options.registrationMode)throw new a(e);return t[t.length-1]}createInstance(e,t){const r=this.createInstanceInternal(e,t);return this.setDependencies(e.implementation,r,t),t.setForLifetime(e.implementation,r,e.lifetime),r}wrapContext(e){return{resolve:t((t=>this.resolve(t,e)),"resolve"),resolveAll:t((t=>this.resolveAll(t,e)),"resolveAll")}}createInstanceInternal(e,t){let r;try{r=e.createInstance(this.wrapContext(t))}catch(t){throw this.logger.error(t),new l(e.implementation,t)}return"SINGLETON"!==e.lifetime&&Symbol.dispose in r&&this.created.push(r),r}createScope(){return new e(this.logger,this.Services.clone(!0),this.singletons)}setDependencies(e,t,r){const s=m(S,e)??{};this.logger.debug("Dependencies",e.name,s);for(const[i,o]of Object.entries(s)){if(o===e)throw new h;{this.logger.debug("Resolving",o.name,"for",e.name);const s=this.resolve(o,r);t[i]=s}}return t}},R=class e{constructor(e,t,r,s=new Map){this.logger=e,this.options=t,this.isScoped=r,this.services=s}static{t(this,"ServiceCollection")}registerModules(...e){for(const t of e){(new t).registerServices(this)}}get(e){return this.services.get(e)??[]}overrideLifetime(e,t){for(const r of this.get(e))r.lifetime=t}register(...e){return new g(e,this.isScoped,((e,t)=>this.addService(e,t)))}addService(e,t){this.logger.info("Adding service",{identifier:e.name,descriptor:t});let r=this.services.get(e);null==r&&(r=[],this.services.set(e,r)),r.push(t)}clone(t){const r=new Map;for(const[e,t]of this.services){const s=t.map((e=>({...e})));r.set(e,s)}return new e(this.logger,this.options,!0===t,r)}buildProvider(){return new w(this.logger,this.clone())}},O=class{static{t(this,"ILogger")}debug(e,...t){}info(e,...t){}error(e,...t){}warn(e,...t){}},y=class extends O{constructor(e){super(),this.options=e}static{t(this,"ConsoleLogger")}debug(e,...t){this.options.logLevel<=0&&console.debug(e,...t)}info(e,...t){this.options.logLevel<=1&&console.info(e,...t)}warn(e,...t){this.options.logLevel<=2&&console.warn(e,...t)}error(e,...t){this.options.logLevel<=3&&console.error(e,...t)}},I=t((e=>({...o,...e})),"mergeOptions"),L=t((e=>{const t=I(e),r=t.logger??new y(t);return new R(r,t,!1)}),"createServiceCollection"),b=t(((e,t,r,s)=>{let i=m(e,t);void 0===i&&(i={},E(e,i,t)),i[r]=s}),"tagProperty"),D=t((e=>(t,r)=>function(t){const s=this.constructor;return b(S,s,r.name,e),t}),"dependsOn");export{o as DefaultServiceCollectionOptions,O as ILogger,d as IResolutionScope,u as IScopedProvider,f as IServiceProvider,r as Lifetime,s as LogLevel,a as MultipleRegistrationError,i as ResolveMultipleMode,p as ScopedSingletonRegistrationError,h as SelfDependencyError,l as ServiceCreationError,n as ServiceError,c as UnregisteredServiceError,L as createServiceCollection,D as dependsOn};//# sourceMappingURL=index.mjs.map
1
+ import"@abraham/reflection";var e=Object.defineProperty,t=(t,s)=>e(t,"name",{value:s,configurable:!0}),s=(e=>(e.Resolve="RESOLVE",e.Transient="TRANSIENT",e.Scoped="SCOPED",e.Singleton="SINGLETON",e))(s||{}),r=(e=>(e[e.Debug=0]="Debug",e[e.Info=1]="Info",e[e.Warn=2]="Warn",e[e.Error=3]="Error",e[e.None=4]="None",e))(r||{}),i=(e=>(e.Error="ERROR",e.LastRegistered="LAST_REGISTERED",e))(i||{}),o={registrationMode:"ERROR",logLevel:2},n=class extends Error{static{t(this,"ServiceError")}},c=class extends n{static{t(this,"UnregisteredServiceError")}name="UnregisteredServiceError";constructor(e){super(`Resolving service that has not been registered: ${e.name}`),Object.setPrototypeOf(this,new.target.prototype)}},a=class extends n{static{t(this,"MultipleRegistrationError")}name="MultipleRegistrationError";constructor(e){super(`Multiple services have been registered: ${e.name}`),Object.setPrototypeOf(this,new.target.prototype)}},l=class extends n{constructor(e,t){super(`Error creating service: ${e.name}`),this.innerError=t,Object.setPrototypeOf(this,new.target.prototype)}static{t(this,"ServiceCreationError")}name="ServiceCreationError"},h=class extends n{static{t(this,"SelfDependencyError")}name="SelfDependencyError";constructor(){super("Service depending on itself"),Object.setPrototypeOf(this,new.target.prototype)}},p=class extends n{static{t(this,"ScopedSingletonRegistrationError")}name="ScopedSingletonRegistrationError";constructor(){super("Cannot register a singleton in a scoped service collection"),Object.setPrototypeOf(this,new.target.prototype)}},g=class{constructor(e,t,s){this.identifiers=e,this.isScoped=t,this.addService=s}static{t(this,"ServiceBuilder")}descriptor;to(e,t){this.descriptor=this.createDescriptor(t,e);for(const e of this.identifiers)this.addService(e,this.descriptor);return this}createDescriptor(e,t){const s=e??(()=>new t);return{implementation:t,createInstance:s,lifetime:"RESOLVE"}}singleton(){if(this.isScoped)throw new p;return this.ensureDescriptor().lifetime="SINGLETON",this}scoped(){return this.ensureDescriptor().lifetime="SCOPED",this}transient(){return this.ensureDescriptor().lifetime="TRANSIENT",this}ensureDescriptor(){if(!this.descriptor)throw new Error("Must call to() before setting lifetime");return this.descriptor}},d=class{static{t(this,"IDisposable")}},u=class{static{t(this,"IServiceModule")}},f=class{static{t(this,"IResolutionScope")}},v=class extends f{static{t(this,"IScopedProvider")}},S=class extends f{static{t(this,"IServiceProvider")}},m=class{static{t(this,"IServiceCollection")}},E=class{static{t(this,"ILifetimeBuilder")}},w=class{static{t(this,"IServiceBuilder")}},I=class{constructor(e,t){this.singletons=e,this.scoped=t}static{t(this,"ResolutionContext")}transient=new Map;getFromLifetime(e,t){const s=this.getMapForLifetime(t);return s?.get(e)}setForLifetime(e,t,s){const r=this.getMapForLifetime(s);r?.set(e,t)}getMapForLifetime(e){return{SINGLETON:this.singletons,SCOPED:this.scoped,RESOLVE:this.transient}[e]}},R="design:dependencies",O=t(((e,t)=>Reflect.getMetadata(e,t)),"getMetadata"),L=t(((e,t,s)=>Reflect.defineMetadata(e,t,s)),"defineMetadata"),b=class e{constructor(e,t,s=new Map){this.logger=e,this.Services=t,this.singletons=s}static{t(this,"ServiceProvider")}scoped=new Map;created=[];[Symbol.dispose](){for(const e of this.created)e[Symbol.dispose]()}resolveInternal(e,t){let s=t.getFromLifetime(e.implementation,e.lifetime);return null==s&&(s=this.createInstance(e,t)),s}resolveAll(e,t){return this.Services.get(e).map((e=>this.resolveInternal(e,t??new I(this.singletons,this.scoped))))}resolve(e,t){if(e.prototype===f.prototype||e.prototype===v.prototype||e.prototype===S.prototype)return this;const s=this.getSingleDescriptor(e);return this.resolveInternal(s,t??new I(this.singletons,this.scoped))}getSingleDescriptor(e){const t=this.Services.get(e);if(0===t.length)throw new c(e);if(t.length>1&&"ERROR"===this.Services.options.registrationMode)throw new a(e);return t[t.length-1]}createInstance(e,t){const s=this.createInstanceInternal(e,t);return this.setDependencies(e.implementation,s,t),t.setForLifetime(e.implementation,s,e.lifetime),s}wrapContext(e){return{resolve:t((t=>this.resolve(t,e)),"resolve"),resolveAll:t((t=>this.resolveAll(t,e)),"resolveAll")}}createInstanceInternal(e,t){let s;try{s=e.createInstance(this.wrapContext(t))}catch(t){throw this.logger.error(t),new l(e.implementation,t)}return"SINGLETON"!==e.lifetime&&Symbol.dispose in s&&this.created.push(s),s}createScope(){return new e(this.logger,this.Services.clone(!0),this.singletons)}setDependencies(e,t,s){const r=O(R,e)??{};this.logger.debug("Dependencies",e.name,r);for(const[i,o]of Object.entries(r)){if(o===e)throw new h;{this.logger.debug("Resolving",o.name,"for",e.name);const r=this.resolve(o,s);t[i]=r}}return t}},y=class e{constructor(e,t,s,r=new Map){this.logger=e,this.options=t,this.isScoped=s,this.services=r}static{t(this,"ServiceCollection")}registerModules(...e){for(const t of e){(new t).registerServices(this)}}get(e){return this.services.get(e)??[]}overrideLifetime(e,t){for(const s of this.get(e))s.lifetime=t}register(...e){return new g(e,this.isScoped,((e,t)=>this.addService(e,t)))}addService(e,t){this.logger.info("Adding service",{identifier:e.name,descriptor:t});let s=this.services.get(e);null==s&&(s=[],this.services.set(e,s)),s.push(t)}clone(t){const s=new Map;for(const[e,t]of this.services){const r=t.map((e=>({...e})));s.set(e,r)}return new e(this.logger,this.options,!0===t,s)}buildProvider(){return new b(this.logger,this.clone())}},D=class{static{t(this,"ILogger")}debug(e,...t){}info(e,...t){}error(e,...t){}warn(e,...t){}},M=class extends D{constructor(e){super(),this.options=e}static{t(this,"ConsoleLogger")}debug(e,...t){this.options.logLevel<=0&&console.debug(e,...t)}info(e,...t){this.options.logLevel<=1&&console.info(e,...t)}warn(e,...t){this.options.logLevel<=2&&console.warn(e,...t)}error(e,...t){this.options.logLevel<=3&&console.error(e,...t)}},N=t((e=>({...o,...e})),"mergeOptions"),P=t((e=>{const t=N(e),s=t.logger??new M(t);return new y(s,t,!1)}),"createServiceCollection"),x=t(((e,t,s,r)=>{let i=O(e,t);void 0===i&&(i={},L(e,i,t)),i[s]=r}),"tagProperty"),C=t((e=>(t,s)=>function(t){const r=this.constructor;return x(R,r,s.name,e),t}),"dependsOn");export{o as DefaultServiceCollectionOptions,d as IDisposable,E as ILifetimeBuilder,D as ILogger,f as IResolutionScope,v as IScopedProvider,w as IServiceBuilder,m as IServiceCollection,u as IServiceModule,S as IServiceProvider,s as Lifetime,r as LogLevel,a as MultipleRegistrationError,i as ResolveMultipleMode,p as ScopedSingletonRegistrationError,h as SelfDependencyError,l as ServiceCreationError,n as ServiceError,c as UnregisteredServiceError,P as createServiceCollection,C as dependsOn};//# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/enums.ts","../src/defaults.ts","../src/errors.ts","../src/private/ServiceBuilder.ts","../src/interfaces.ts","../src/private/ResolutionContext.ts","../src/private/constants.ts","../src/private/metadata.ts","../src/private/ServiceProvider.ts","../src/private/ServiceCollection.ts","../src/logger.ts","../src/private/consoleLogger.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AAAA,EACH,GAAG;AACL,CAHqB,CAAA,EAAA,cAAA,CAAA;AAUR,IAAA,uBAAA,2BAA2B,OAAoE,KAAA;AAC1G,EAAM,MAAA,aAAA,GAAgB,aAAa,OAAO,CAAA;AAC1C,EAAA,MAAM,MAAS,GAAA,aAAA,CAAc,MAAU,IAAA,IAAI,cAAc,aAAa,CAAA;AACtE,EAAA,OAAO,IAAI,iBAAA,CAAkB,MAAQ,EAAA,aAAA,EAAe,KAAK,CAAA;AAC3D,CAJuC,EAAA,yBAAA;;;ACXvC,IAAM,WAAc,mBAAA,MAAA,CAAA,CAAuB,WAAqB,EAAA,gBAAA,EAA0B,MAAuB,UAAqC,KAAA;AACpJ,EAAI,IAAA,QAAA,GAAW,WAAe,CAAA,WAAA,EAAa,gBAAgB,CAAA;AAC3D,EAAA,IAAI,aAAa,KAAW,CAAA,EAAA;AAC1B,IAAA,QAAA,GAAW,EAAC;AACZ,IAAe,cAAA,CAAA,WAAA,EAAa,UAAU,gBAAgB,CAAA;AAAA;AAExD,EAAA,QAAA,CAAS,IAAI,CAAI,GAAA,UAAA;AACnB,CAPoB,EAAA,aAAA,CAAA;AAcP,IAAA,SAAA,2BAAmC,UAAqC,KAAA;AACnF,EAAO,OAAA,CAAC,OAAkB,GAAoC,KAAA;AAC5D,IAAA,OAAO,SAAwB,YAAmB,EAAA;AAChD,MAAA,MAAM,SAAS,IAAK,CAAA,WAAA;AACpB,MAAA,WAAA,CAAY,qBAAuB,EAAA,MAAA,EAAQ,GAAI,CAAA,IAAA,EAAM,UAAU,CAAA;AAC/D,MAAO,OAAA,YAAA;AAAA,KACT;AAAA,GACF;AACF,CARyB,EAAA,WAAA","file":"index.mjs","sourcesContent":["export enum Lifetime {\n Resolve = 'RESOLVE',\n Transient = 'TRANSIENT',\n Scoped = 'SCOPED',\n Singleton = 'SINGLETON',\n}\n\nexport enum LogLevel {\n Debug = 0,\n Info = 1,\n Warn = 2,\n Error = 3,\n None = 4,\n}\n\nexport enum ResolveMultipleMode {\n Error = 'ERROR',\n LastRegistered = 'LAST_REGISTERED',\n}\n","import { LogLevel, ResolveMultipleMode } from './enums';\nimport type { ServiceCollectionOptions } from './types';\n\nexport const DefaultServiceCollectionOptions: ServiceCollectionOptions = {\n registrationMode: ResolveMultipleMode.Error,\n logLevel: LogLevel.Warn,\n};\n","import type { ServiceIdentifier } from './types';\n\nexport abstract class ServiceError extends Error {}\n\nexport class UnregisteredServiceError<T extends object> extends ServiceError {\n name = 'UnregisteredServiceError';\n constructor(identifier: ServiceIdentifier<T>) {\n super(`Resolving service that has not been registered: ${identifier.name}`);\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class MultipleRegistrationError<T extends object> extends ServiceError {\n name = 'MultipleRegistrationError';\n constructor(identifier: ServiceIdentifier<T>) {\n super(`Multiple services have been registered: ${identifier.name}`);\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class ServiceCreationError<T extends object> extends ServiceError {\n name = 'ServiceCreationError';\n constructor(\n identifier: ServiceIdentifier<T>,\n public readonly innerError: any,\n ) {\n super(`Error creating service: ${identifier.name}`);\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class SelfDependencyError extends ServiceError {\n name = 'SelfDependencyError';\n constructor() {\n super('Service depending on itself');\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class ScopedSingletonRegistrationError extends ServiceError {\n name = 'ScopedSingletonRegistrationError';\n constructor() {\n super('Cannot register a singleton in a scoped service collection');\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n","import { Lifetime } from '../enums';\nimport { ScopedSingletonRegistrationError } from '../errors';\nimport type { ILifetimeBuilder, IServiceBuilder, InstanceFactory, ServiceDescriptor, ServiceIdentifier, ServiceImplementation, SourceType } from '../types';\n\nexport class ServiceBuilder<T extends SourceType> implements IServiceBuilder<T> {\n private descriptor: ServiceDescriptor<T> | undefined;\n\n constructor(\n private readonly identifiers: ServiceIdentifier<T>[],\n private readonly isScoped: boolean,\n private readonly addService: (identifier: ServiceIdentifier<T>, descriptor: ServiceDescriptor<T>) => void,\n ) {}\n\n public to(implementation: ServiceImplementation<T>, factory?: InstanceFactory<T>): ILifetimeBuilder {\n this.descriptor = this.createDescriptor(factory, implementation);\n\n for (const identifier of this.identifiers) {\n this.addService(identifier, this.descriptor);\n }\n return this;\n }\n\n private createDescriptor(factory: InstanceFactory<T> | undefined, implementation: ServiceImplementation<T>): ServiceDescriptor<T> {\n const createInstance = factory ?? (() => new implementation());\n\n return {\n implementation,\n createInstance,\n lifetime: Lifetime.Resolve,\n };\n }\n\n public singleton(): this {\n if (this.isScoped) {\n throw new ScopedSingletonRegistrationError();\n }\n this.ensureDescriptor().lifetime = Lifetime.Singleton;\n return this;\n }\n\n public scoped(): this {\n this.ensureDescriptor().lifetime = Lifetime.Scoped;\n return this;\n }\n\n public transient(): this {\n this.ensureDescriptor().lifetime = Lifetime.Transient;\n return this;\n }\n\n private ensureDescriptor(): ServiceDescriptor<T> {\n if (!this.descriptor) {\n throw new Error('Must call to() before setting lifetime');\n }\n return this.descriptor;\n }\n}\n","import type { Lifetime } from './enums';\nimport { ResolveMultipleMode } from './enums';\nimport type { EnsureObject, IServiceBuilder, ServiceCollectionOptions, ServiceDescriptor, ServiceIdentifier, ServiceModuleType, SourceType, UnionToIntersection } from './types';\n\nexport interface IDisposable {\n [Symbol.dispose](): void;\n}\n\nexport interface IServiceModule {\n registerServices(services: IServiceCollection): void;\n}\n\nexport abstract class IResolutionScope {\n /**\n * Resolves a single implementation for the given identifier.\n * @template T The type of service to resolve\n * @param identifier The service identifier\n * @returns The resolved instance\n * @throws {MultipleRegistrationError} When multiple implementations exist (unless {@link ServiceCollectionOptions.registrationMode} is set to {@link ResolveMultipleMode.LastRegistered}).\n * @throws {UnregisteredServiceError} When no implementation exists\n */\n public abstract resolve<T extends SourceType>(identifier: ServiceIdentifier<T>): T;\n\n /**\n * Resolves all implementations for the given identifier.\n * @template T The type of service to resolve\n * @param identifier The service identifier\n * @returns Array of resolved instances\n */\n public abstract resolveAll<T extends SourceType>(identifier: ServiceIdentifier<T>): T[];\n}\n\nexport abstract class IScopedProvider extends IResolutionScope implements IDisposable {\n public abstract [Symbol.dispose](): void;\n}\n\nexport abstract class IServiceProvider extends IResolutionScope {\n public abstract readonly Services: IServiceCollection;\n public abstract createScope(): IScopedProvider;\n}\n\nexport interface IServiceCollection {\n readonly options: ServiceCollectionOptions;\n get<T extends SourceType>(identifier: ServiceIdentifier<T>): ServiceDescriptor<T>[];\n register<Types extends SourceType[]>(...identifiers: { [K in keyof Types]: ServiceIdentifier<Types[K]> }): IServiceBuilder<EnsureObject<UnionToIntersection<Types[number]>>>;\n registerModules(...modules: ServiceModuleType[]): void;\n overrideLifetime<T extends SourceType>(identifier: ServiceIdentifier<T>, lifetime: Lifetime): void;\n buildProvider(): IServiceProvider;\n clone(): IServiceCollection;\n clone(scoped: true): IServiceCollection;\n}\n","import { Lifetime } from '../enums';\nimport type { ServiceImplementation, SourceType } from '../types';\n\nexport class ResolutionContext {\n constructor(\n private readonly singletons: Map<ServiceImplementation<any>, any>,\n private readonly scoped: Map<ServiceImplementation<any>, any>,\n ) {}\n\n private readonly transient = new Map<ServiceImplementation<any>, any>();\n\n public getFromLifetime<T extends SourceType>(implementation: ServiceImplementation<T>, lifetime: Lifetime): T {\n const map = this.getMapForLifetime(lifetime);\n return map?.get(implementation);\n }\n\n public setForLifetime<T extends SourceType>(implementation: ServiceImplementation<T>, instance: T, lifetime: Lifetime): void {\n const map = this.getMapForLifetime(lifetime);\n map?.set(implementation, instance);\n }\n\n private getMapForLifetime(lifetime: Lifetime) {\n const map: Partial<Record<Lifetime, Map<ServiceImplementation<any>, any>>> = {\n [Lifetime.Singleton]: this.singletons,\n [Lifetime.Scoped]: this.scoped,\n [Lifetime.Resolve]: this.transient,\n };\n return map[lifetime];\n }\n}\n","export const DesignDependenciesKey = 'design:dependencies';\n","import '@abraham/reflection';\nimport type { MetadataType, SourceType } from '../types';\n\nexport const getMetadata = <T extends SourceType>(key: string, obj: object): MetadataType<T> | undefined => Reflect.getMetadata(key, obj);\nexport const defineMetadata = <T extends SourceType>(key: string, metadata: MetadataType<T>, obj: object) => Reflect.defineMetadata(key, metadata, obj);\n","import { Lifetime } from '../enums';\nimport { ResolveMultipleMode } from '../enums';\nimport { MultipleRegistrationError, SelfDependencyError, ServiceCreationError, UnregisteredServiceError } from '../errors';\nimport { type IDisposable, IResolutionScope, IScopedProvider, type IServiceCollection } from '../interfaces';\nimport { IServiceProvider } from '../interfaces';\nimport type { ILogger } from '../logger';\nimport type { ServiceDescriptor, ServiceIdentifier, ServiceImplementation, SourceType } from '../types';\nimport { ResolutionContext } from './ResolutionContext';\nimport { DesignDependenciesKey } from './constants';\nimport { getMetadata } from './metadata';\n\nexport class ServiceProvider implements IServiceProvider, IScopedProvider {\n private scoped = new Map<ServiceImplementation<any>, any>();\n private created: IDisposable[] = [];\n\n constructor(\n private readonly logger: ILogger,\n public readonly Services: IServiceCollection,\n private readonly singletons = new Map<ServiceImplementation<any>, any>(),\n ) {}\n\n [Symbol.dispose]() {\n for (const x of this.created) {\n x[Symbol.dispose]();\n }\n }\n\n private resolveInternal<T extends SourceType>(descriptor: ServiceDescriptor<T>, context: ResolutionContext): T {\n let instance = context.getFromLifetime(descriptor.implementation, descriptor.lifetime);\n if (instance == null) {\n instance = this.createInstance(descriptor, context);\n }\n return instance;\n }\n\n public resolveAll<T extends SourceType>(identifier: ServiceIdentifier<T>, context?: ResolutionContext): T[] {\n const descriptors = this.Services.get(identifier);\n return descriptors.map((descriptor) => this.resolveInternal<T>(descriptor, context ?? new ResolutionContext(this.singletons, this.scoped)));\n }\n\n public resolve<T extends SourceType>(identifier: ServiceIdentifier<T>, context?: ResolutionContext): T {\n if (identifier.prototype === IResolutionScope.prototype || identifier.prototype === IScopedProvider.prototype || identifier.prototype === IServiceProvider.prototype) {\n return this as IResolutionScope & IScopedProvider & IServiceProvider as T;\n }\n\n const descriptor = this.getSingleDescriptor(identifier);\n return this.resolveInternal(descriptor, context ?? new ResolutionContext(this.singletons, this.scoped));\n }\n\n private getSingleDescriptor<T extends SourceType>(identifier: ServiceIdentifier<T>) {\n const descriptors = this.Services.get(identifier);\n if (descriptors.length === 0) {\n throw new UnregisteredServiceError(identifier);\n }\n\n if (descriptors.length > 1) {\n if (this.Services.options.registrationMode === ResolveMultipleMode.Error) {\n throw new MultipleRegistrationError(identifier);\n }\n }\n const descriptor = descriptors[descriptors.length - 1];\n return descriptor;\n }\n\n private createInstance<T extends SourceType>(descriptor: ServiceDescriptor<T>, context: ResolutionContext): T {\n const instance = this.createInstanceInternal(descriptor, context);\n this.setDependencies(descriptor.implementation, instance, context);\n context.setForLifetime(descriptor.implementation, instance, descriptor.lifetime);\n return instance;\n }\n\n private wrapContext(context: ResolutionContext): IResolutionScope {\n const resolve = (identifier: ServiceIdentifier<any>) => this.resolve(identifier, context);\n const resolveAll = (identifier: ServiceIdentifier<any>) => this.resolveAll(identifier, context);\n\n return {\n resolve,\n resolveAll,\n };\n }\n\n private createInstanceInternal<T extends SourceType>(descriptor: ServiceDescriptor<T>, context: ResolutionContext) {\n let instance: T | undefined;\n try {\n instance = descriptor.createInstance(this.wrapContext(context));\n } catch (err) {\n this.logger.error(err);\n throw new ServiceCreationError(descriptor.implementation, err);\n }\n if (descriptor.lifetime !== Lifetime.Singleton && Symbol.dispose in instance) {\n this.created.push(instance as IDisposable);\n }\n return instance;\n }\n\n public createScope(): IScopedProvider {\n return new ServiceProvider(this.logger, this.Services.clone(true), this.singletons);\n }\n\n private setDependencies<T extends SourceType>(implementation: ServiceImplementation<T>, instance: T, context: ResolutionContext): T {\n const dependencies = getMetadata<T>(DesignDependenciesKey, implementation) ?? {};\n this.logger.debug('Dependencies', implementation.name, dependencies);\n for (const [key, identifier] of Object.entries(dependencies)) {\n if (identifier !== implementation) {\n this.logger.debug('Resolving', identifier.name, 'for', implementation.name);\n const dep = this.resolve(identifier, context);\n (instance as Record<string, T>)[key] = dep;\n } else {\n throw new SelfDependencyError();\n }\n }\n return instance;\n }\n}\n","import type { Lifetime } from '../enums';\nimport type { IServiceCollection, IServiceProvider } from '../interfaces';\nimport type { ILogger } from '../logger';\nimport type { EnsureObject, IServiceBuilder, ServiceCollectionOptions, ServiceDescriptor, ServiceIdentifier, ServiceModuleType, SourceType, UnionToIntersection } from '../types';\nimport { ServiceBuilder } from './ServiceBuilder';\nimport { ServiceProvider } from './ServiceProvider';\n\nexport class ServiceCollection implements IServiceCollection {\n constructor(\n private readonly logger: ILogger,\n public readonly options: ServiceCollectionOptions,\n private readonly isScoped: boolean,\n private readonly services = new Map<ServiceIdentifier<any>, ServiceDescriptor<any>[]>(),\n ) {}\n\n public registerModules(...modules: ServiceModuleType[]): void {\n for (const x of modules) {\n const module = new x();\n module.registerServices(this);\n }\n }\n\n get<T extends SourceType>(key: ServiceIdentifier<T>): ServiceDescriptor<T>[] {\n return this.services.get(key) ?? [];\n }\n\n public overrideLifetime<T extends SourceType>(identifier: ServiceIdentifier<T>, lifetime: Lifetime): void {\n for (const descriptor of this.get(identifier)) {\n descriptor.lifetime = lifetime;\n }\n }\n\n register<Types extends SourceType[]>(...identifiers: { [K in keyof Types]: ServiceIdentifier<Types[K]> }): IServiceBuilder<EnsureObject<UnionToIntersection<Types[number]>>> {\n return new ServiceBuilder(identifiers, this.isScoped, (identifier, descriptor) => this.addService(identifier, descriptor));\n }\n\n private addService<T extends SourceType>(identifier: ServiceIdentifier<T>, descriptor: ServiceDescriptor<T>) {\n this.logger.info('Adding service', { identifier: identifier.name, descriptor });\n let existing = this.services.get(identifier);\n if (existing == null) {\n existing = [];\n this.services.set(identifier, existing);\n }\n existing.push(descriptor);\n }\n\n public clone(scoped?: unknown): IServiceCollection {\n const clonedMap = new Map<ServiceIdentifier<any>, ServiceDescriptor<any>[]>();\n for (const [key, descriptors] of this.services) {\n const clonedDescriptors = descriptors.map((descriptor) => ({ ...descriptor }));\n clonedMap.set(key, clonedDescriptors);\n }\n\n return new ServiceCollection(this.logger, this.options, scoped === true, clonedMap);\n }\n\n public buildProvider(): IServiceProvider {\n return new ServiceProvider(this.logger, this.clone());\n }\n}\n","export abstract class ILogger {\n public debug(_message?: any, ..._optionalParams: any[]) {}\n public info(_message?: any, ..._optionalParams: any[]) {}\n public error(_message?: any, ..._optionalParams: any[]) {}\n public warn(_message?: any, ..._optionalParams: any[]) {}\n}\n","import { LogLevel } from '../enums';\nimport { ILogger } from '../logger';\nimport type { ServiceCollectionOptions } from '../types';\n\nexport class ConsoleLogger extends ILogger {\n constructor(private readonly options: ServiceCollectionOptions) {\n super();\n }\n\n public override debug(message?: any, ...optionalParams: any[]): void {\n if (this.options.logLevel <= LogLevel.Debug) {\n console.debug(message, ...optionalParams);\n }\n }\n\n public override info(message?: any, ...optionalParams: any[]): void {\n if (this.options.logLevel <= LogLevel.Info) {\n console.info(message, ...optionalParams);\n }\n }\n\n public override warn(message?: any, ...optionalParams: any[]): void {\n if (this.options.logLevel <= LogLevel.Warn) {\n console.warn(message, ...optionalParams);\n }\n }\n\n public override error(message?: any, ...optionalParams: any[]): void {\n if (this.options.logLevel <= LogLevel.Error) {\n console.error(message, ...optionalParams);\n }\n }\n}\n","import { DefaultServiceCollectionOptions } from './defaults';\nimport type { IServiceCollection } from './interfaces';\nimport { ServiceCollection } from './private/ServiceCollection';\nimport { ConsoleLogger } from './private/consoleLogger';\nimport type { ServiceCollectionOptions } from './types';\n\nconst mergeOptions = (options: Partial<ServiceCollectionOptions> | undefined): ServiceCollectionOptions => ({\n ...DefaultServiceCollectionOptions,\n ...options,\n});\n\n/**\n * Creates a service collection with the (optionally) provided options\n * @param options - Optional configuration for the service collection.\n * @defaultValue Default options are taken from {@link DefaultServiceCollectionOptions}.\n */\nexport const createServiceCollection = (options?: Partial<ServiceCollectionOptions>): IServiceCollection => {\n const mergedOptions = mergeOptions(options);\n const logger = mergedOptions.logger ?? new ConsoleLogger(mergedOptions);\n return new ServiceCollection(logger, mergedOptions, false);\n};\n","import { IResolutionScope, IScopedProvider, IServiceProvider } from './interfaces';\nimport { DesignDependenciesKey } from './private/constants';\nimport { defineMetadata, getMetadata } from './private/metadata';\nimport type { ServiceIdentifier, SourceType } from './types';\n\nconst tagProperty = <T extends SourceType>(metadataKey: string, annotationTarget: object, name: string | symbol, identifier: ServiceIdentifier<T>) => {\n let existing = getMetadata<T>(metadataKey, annotationTarget);\n if (existing === undefined) {\n existing = {};\n defineMetadata(metadataKey, existing, annotationTarget);\n }\n existing[name] = identifier;\n};\n\n/**\n * declares a dependency, use on a class field.\n * Can also depend on {@link IServiceProvider}, {@link IResolutionScope}, or {@link IScopedProvider}.\n * @param identifier the identifier to depend on, i.e. the interface\n */\nexport const dependsOn = <T extends SourceType>(identifier: ServiceIdentifier<T>) => {\n return (value: undefined, ctx: ClassFieldDecoratorContext) => {\n return function (this: object, initialValue: any) {\n const target = this.constructor;\n tagProperty(DesignDependenciesKey, target, ctx.name, identifier);\n return initialValue;\n };\n };\n};\n"]}
1
+ {"version":3,"sources":["../src/enums.ts","../src/defaults.ts","../src/errors.ts","../src/private/ServiceBuilder.ts","../src/interfaces.ts","../src/private/ResolutionContext.ts","../src/private/constants.ts","../src/private/metadata.ts","../src/private/ServiceProvider.ts","../src/private/ServiceCollection.ts","../src/logger.ts","../src/private/consoleLogger.ts","../src/createServiceCollection.ts","../src/dependsOn.ts"],"names":["Lifetime","LogLevel","ResolveMultipleMode"],"mappings":";;;;AAAY,IAAA,QAAA,qBAAAA,SAAL,KAAA;AACL,EAAAA,UAAA,SAAU,CAAA,GAAA,SAAA;AACV,EAAAA,UAAA,WAAY,CAAA,GAAA,WAAA;AACZ,EAAAA,UAAA,QAAS,CAAA,GAAA,QAAA;AACT,EAAAA,UAAA,WAAY,CAAA,GAAA,WAAA;AAJF,EAAAA,OAAAA,SAAAA;AAAA,CAAA,EAAA,QAAA,IAAA,EAAA;AAOA,IAAA,QAAA,qBAAAC,SAAL,KAAA;AACL,EAAAA,SAAAA,CAAAA,SAAAA,CAAA,WAA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export enum LogLevel {\n Debug = 0,\n Info = 1,\n Warn = 2,\n Error = 3,\n None = 4,\n}\n\nexport enum ResolveMultipleMode {\n Error = 'ERROR',\n LastRegistered = 'LAST_REGISTERED',\n}\n","import { LogLevel, ResolveMultipleMode } from './enums';\nimport type { ServiceCollectionOptions } from './types';\n\nexport const DefaultServiceCollectionOptions: ServiceCollectionOptions = {\n registrationMode: ResolveMultipleMode.Error,\n logLevel: LogLevel.Warn,\n};\n","import type { ServiceIdentifier } from './types';\n\nexport abstract class ServiceError extends Error {}\n\nexport class UnregisteredServiceError<T extends object> extends ServiceError {\n name = 'UnregisteredServiceError';\n constructor(identifier: ServiceIdentifier<T>) {\n super(`Resolving service that has not been registered: ${identifier.name}`);\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class MultipleRegistrationError<T extends object> extends ServiceError {\n name = 'MultipleRegistrationError';\n constructor(identifier: ServiceIdentifier<T>) {\n super(`Multiple services have been registered: ${identifier.name}`);\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class ServiceCreationError<T extends object> extends ServiceError {\n name = 'ServiceCreationError';\n constructor(\n identifier: ServiceIdentifier<T>,\n public readonly innerError: any,\n ) {\n super(`Error creating service: ${identifier.name}`);\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class SelfDependencyError extends ServiceError {\n name = 'SelfDependencyError';\n constructor() {\n super('Service depending on itself');\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class ScopedSingletonRegistrationError extends ServiceError {\n name = 'ScopedSingletonRegistrationError';\n constructor() {\n super('Cannot register a singleton in a scoped service collection');\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n","import { Lifetime } from '../enums';\nimport { ScopedSingletonRegistrationError } from '../errors';\nimport type { ILifetimeBuilder, IServiceBuilder } from '../interfaces';\nimport type { InstanceFactory, ServiceDescriptor, ServiceIdentifier, ServiceImplementation, SourceType } from '../types';\n\nexport class ServiceBuilder<T extends SourceType> implements IServiceBuilder<T> {\n private descriptor: ServiceDescriptor<T> | undefined;\n\n constructor(\n private readonly identifiers: ServiceIdentifier<T>[],\n private readonly isScoped: boolean,\n private readonly addService: (identifier: ServiceIdentifier<T>, descriptor: ServiceDescriptor<T>) => void,\n ) {}\n\n public to(implementation: ServiceImplementation<T>, factory?: InstanceFactory<T>): ILifetimeBuilder {\n this.descriptor = this.createDescriptor(factory, implementation);\n\n for (const identifier of this.identifiers) {\n this.addService(identifier, this.descriptor);\n }\n return this;\n }\n\n private createDescriptor(factory: InstanceFactory<T> | undefined, implementation: ServiceImplementation<T>): ServiceDescriptor<T> {\n const createInstance = factory ?? (() => new implementation());\n\n return {\n implementation,\n createInstance,\n lifetime: Lifetime.Resolve,\n };\n }\n\n public singleton(): this {\n if (this.isScoped) {\n throw new ScopedSingletonRegistrationError();\n }\n this.ensureDescriptor().lifetime = Lifetime.Singleton;\n return this;\n }\n\n public scoped(): this {\n this.ensureDescriptor().lifetime = Lifetime.Scoped;\n return this;\n }\n\n public transient(): this {\n this.ensureDescriptor().lifetime = Lifetime.Transient;\n return this;\n }\n\n private ensureDescriptor(): ServiceDescriptor<T> {\n if (!this.descriptor) {\n throw new Error('Must call to() before setting lifetime');\n }\n return this.descriptor;\n }\n}\n","import type { Lifetime } from './enums';\nimport { ResolveMultipleMode } from './enums';\nimport type { EnsureObject, ServiceBuilderOptions, ServiceCollectionOptions, ServiceDescriptor, ServiceIdentifier, ServiceModuleType, SourceType, UnionToIntersection } from './types';\n\nexport abstract class IDisposable {\n public abstract [Symbol.dispose](): void;\n}\n\nexport abstract class IServiceModule {\n public abstract registerServices(services: IServiceCollection): void;\n}\n\nexport abstract class IResolutionScope {\n /**\n * Resolves a single implementation for the given identifier.\n * @template T The type of service to resolve\n * @param identifier The service identifier\n * @returns The resolved instance\n * @throws {MultipleRegistrationError} When multiple implementations exist (unless {@link ServiceCollectionOptions.registrationMode} is set to {@link ResolveMultipleMode.LastRegistered}).\n * @throws {UnregisteredServiceError} When no implementation exists\n */\n public abstract resolve<T extends SourceType>(identifier: ServiceIdentifier<T>): T;\n\n /**\n * Resolves all implementations for the given identifier.\n * @template T The type of service to resolve\n * @param identifier The service identifier\n * @returns Array of resolved instances\n */\n public abstract resolveAll<T extends SourceType>(identifier: ServiceIdentifier<T>): T[];\n}\n\nexport abstract class IScopedProvider extends IResolutionScope implements IDisposable {\n public abstract readonly Services: IServiceCollection;\n public abstract [Symbol.dispose](): void;\n}\n\nexport abstract class IServiceProvider extends IResolutionScope {\n public abstract readonly Services: IServiceCollection;\n public abstract createScope(): IScopedProvider;\n}\n\nexport abstract class IServiceCollection {\n public abstract readonly options: ServiceCollectionOptions;\n public abstract get<T extends SourceType>(identifier: ServiceIdentifier<T>): ServiceDescriptor<T>[];\n public abstract register<Types extends SourceType[]>(...identifiers: { [K in keyof Types]: ServiceIdentifier<Types[K]> }): IServiceBuilder<EnsureObject<UnionToIntersection<Types[number]>>>;\n public abstract registerModules(...modules: ServiceModuleType[]): void;\n public abstract overrideLifetime<T extends SourceType>(identifier: ServiceIdentifier<T>, lifetime: Lifetime): void;\n public abstract buildProvider(): IServiceProvider;\n public abstract clone(): IServiceCollection;\n public abstract clone(scoped: true): IServiceCollection;\n}\n\nexport abstract class ILifetimeBuilder {\n public abstract singleton(): ILifetimeBuilder;\n public abstract scoped(): ILifetimeBuilder;\n public abstract transient(): ILifetimeBuilder;\n}\n\nexport abstract class IServiceBuilder<T extends SourceType> {\n public abstract to: ServiceBuilderOptions<T>;\n}\n","import { Lifetime } from '../enums';\nimport type { ServiceImplementation, SourceType } from '../types';\n\nexport class ResolutionContext {\n constructor(\n private readonly singletons: Map<ServiceImplementation<any>, any>,\n private readonly scoped: Map<ServiceImplementation<any>, any>,\n ) {}\n\n private readonly transient = new Map<ServiceImplementation<any>, any>();\n\n public getFromLifetime<T extends SourceType>(implementation: ServiceImplementation<T>, lifetime: Lifetime): T {\n const map = this.getMapForLifetime(lifetime);\n return map?.get(implementation);\n }\n\n public setForLifetime<T extends SourceType>(implementation: ServiceImplementation<T>, instance: T, lifetime: Lifetime): void {\n const map = this.getMapForLifetime(lifetime);\n map?.set(implementation, instance);\n }\n\n private getMapForLifetime(lifetime: Lifetime) {\n const map: Partial<Record<Lifetime, Map<ServiceImplementation<any>, any>>> = {\n [Lifetime.Singleton]: this.singletons,\n [Lifetime.Scoped]: this.scoped,\n [Lifetime.Resolve]: this.transient,\n };\n return map[lifetime];\n }\n}\n","export const DesignDependenciesKey = 'design:dependencies';\n","import '@abraham/reflection';\nimport type { MetadataType, SourceType } from '../types';\n\nexport const getMetadata = <T extends SourceType>(key: string, obj: object): MetadataType<T> | undefined => Reflect.getMetadata(key, obj);\nexport const defineMetadata = <T extends SourceType>(key: string, metadata: MetadataType<T>, obj: object) => Reflect.defineMetadata(key, metadata, obj);\n","import { Lifetime } from '../enums';\nimport { ResolveMultipleMode } from '../enums';\nimport { MultipleRegistrationError, SelfDependencyError, ServiceCreationError, UnregisteredServiceError } from '../errors';\nimport { type IDisposable, IResolutionScope, IScopedProvider, type IServiceCollection } from '../interfaces';\nimport { IServiceProvider } from '../interfaces';\nimport type { ILogger } from '../logger';\nimport type { ServiceDescriptor, ServiceIdentifier, ServiceImplementation, SourceType } from '../types';\nimport { ResolutionContext } from './ResolutionContext';\nimport { DesignDependenciesKey } from './constants';\nimport { getMetadata } from './metadata';\n\nexport class ServiceProvider implements IServiceProvider, IScopedProvider {\n private scoped = new Map<ServiceImplementation<any>, any>();\n private created: IDisposable[] = [];\n\n constructor(\n private readonly logger: ILogger,\n public readonly Services: IServiceCollection,\n private readonly singletons = new Map<ServiceImplementation<any>, any>(),\n ) {}\n\n [Symbol.dispose]() {\n for (const x of this.created) {\n x[Symbol.dispose]();\n }\n }\n\n private resolveInternal<T extends SourceType>(descriptor: ServiceDescriptor<T>, context: ResolutionContext): T {\n let instance = context.getFromLifetime(descriptor.implementation, descriptor.lifetime);\n if (instance == null) {\n instance = this.createInstance(descriptor, context);\n }\n return instance;\n }\n\n public resolveAll<T extends SourceType>(identifier: ServiceIdentifier<T>, context?: ResolutionContext): T[] {\n const descriptors = this.Services.get(identifier);\n return descriptors.map((descriptor) => this.resolveInternal<T>(descriptor, context ?? new ResolutionContext(this.singletons, this.scoped)));\n }\n\n public resolve<T extends SourceType>(identifier: ServiceIdentifier<T>, context?: ResolutionContext): T {\n if (identifier.prototype === IResolutionScope.prototype || identifier.prototype === IScopedProvider.prototype || identifier.prototype === IServiceProvider.prototype) {\n return this as IResolutionScope & IScopedProvider & IServiceProvider as T;\n }\n\n const descriptor = this.getSingleDescriptor(identifier);\n return this.resolveInternal(descriptor, context ?? new ResolutionContext(this.singletons, this.scoped));\n }\n\n private getSingleDescriptor<T extends SourceType>(identifier: ServiceIdentifier<T>) {\n const descriptors = this.Services.get(identifier);\n if (descriptors.length === 0) {\n throw new UnregisteredServiceError(identifier);\n }\n\n if (descriptors.length > 1) {\n if (this.Services.options.registrationMode === ResolveMultipleMode.Error) {\n throw new MultipleRegistrationError(identifier);\n }\n }\n const descriptor = descriptors[descriptors.length - 1];\n return descriptor;\n }\n\n private createInstance<T extends SourceType>(descriptor: ServiceDescriptor<T>, context: ResolutionContext): T {\n const instance = this.createInstanceInternal(descriptor, context);\n this.setDependencies(descriptor.implementation, instance, context);\n context.setForLifetime(descriptor.implementation, instance, descriptor.lifetime);\n return instance;\n }\n\n private wrapContext(context: ResolutionContext): IResolutionScope {\n const resolve = (identifier: ServiceIdentifier<any>) => this.resolve(identifier, context);\n const resolveAll = (identifier: ServiceIdentifier<any>) => this.resolveAll(identifier, context);\n\n return {\n resolve,\n resolveAll,\n };\n }\n\n private createInstanceInternal<T extends SourceType>(descriptor: ServiceDescriptor<T>, context: ResolutionContext) {\n let instance: T | undefined;\n try {\n instance = descriptor.createInstance(this.wrapContext(context));\n } catch (err) {\n this.logger.error(err);\n throw new ServiceCreationError(descriptor.implementation, err);\n }\n if (descriptor.lifetime !== Lifetime.Singleton && Symbol.dispose in instance) {\n this.created.push(instance as IDisposable);\n }\n return instance;\n }\n\n public createScope(): IScopedProvider {\n return new ServiceProvider(this.logger, this.Services.clone(true), this.singletons);\n }\n\n private setDependencies<T extends SourceType>(implementation: ServiceImplementation<T>, instance: T, context: ResolutionContext): T {\n const dependencies = getMetadata<T>(DesignDependenciesKey, implementation) ?? {};\n this.logger.debug('Dependencies', implementation.name, dependencies);\n for (const [key, identifier] of Object.entries(dependencies)) {\n if (identifier !== implementation) {\n this.logger.debug('Resolving', identifier.name, 'for', implementation.name);\n const dep = this.resolve(identifier, context);\n (instance as Record<string, T>)[key] = dep;\n } else {\n throw new SelfDependencyError();\n }\n }\n return instance;\n }\n}\n","import type { Lifetime } from '../enums';\nimport type { IServiceBuilder, IServiceCollection, IServiceProvider } from '../interfaces';\nimport type { ILogger } from '../logger';\nimport type { EnsureObject, ServiceCollectionOptions, ServiceDescriptor, ServiceIdentifier, ServiceModuleType, SourceType, UnionToIntersection } from '../types';\nimport { ServiceBuilder } from './ServiceBuilder';\nimport { ServiceProvider } from './ServiceProvider';\n\nexport class ServiceCollection implements IServiceCollection {\n constructor(\n private readonly logger: ILogger,\n public readonly options: ServiceCollectionOptions,\n private readonly isScoped: boolean,\n private readonly services = new Map<ServiceIdentifier<any>, ServiceDescriptor<any>[]>(),\n ) {}\n\n public registerModules(...modules: ServiceModuleType[]): void {\n for (const x of modules) {\n const module = new x();\n module.registerServices(this);\n }\n }\n\n get<T extends SourceType>(key: ServiceIdentifier<T>): ServiceDescriptor<T>[] {\n return this.services.get(key) ?? [];\n }\n\n public overrideLifetime<T extends SourceType>(identifier: ServiceIdentifier<T>, lifetime: Lifetime): void {\n for (const descriptor of this.get(identifier)) {\n descriptor.lifetime = lifetime;\n }\n }\n\n register<Types extends SourceType[]>(...identifiers: { [K in keyof Types]: ServiceIdentifier<Types[K]> }): IServiceBuilder<EnsureObject<UnionToIntersection<Types[number]>>> {\n return new ServiceBuilder(identifiers, this.isScoped, (identifier, descriptor) => this.addService(identifier, descriptor));\n }\n\n private addService<T extends SourceType>(identifier: ServiceIdentifier<T>, descriptor: ServiceDescriptor<T>) {\n this.logger.info('Adding service', { identifier: identifier.name, descriptor });\n let existing = this.services.get(identifier);\n if (existing == null) {\n existing = [];\n this.services.set(identifier, existing);\n }\n existing.push(descriptor);\n }\n\n public clone(scoped?: unknown): IServiceCollection {\n const clonedMap = new Map<ServiceIdentifier<any>, ServiceDescriptor<any>[]>();\n for (const [key, descriptors] of this.services) {\n const clonedDescriptors = descriptors.map((descriptor) => ({ ...descriptor }));\n clonedMap.set(key, clonedDescriptors);\n }\n\n return new ServiceCollection(this.logger, this.options, scoped === true, clonedMap);\n }\n\n public buildProvider(): IServiceProvider {\n return new ServiceProvider(this.logger, this.clone());\n }\n}\n","export abstract class ILogger {\n public debug(_message?: any, ..._optionalParams: any[]) {}\n public info(_message?: any, ..._optionalParams: any[]) {}\n public error(_message?: any, ..._optionalParams: any[]) {}\n public warn(_message?: any, ..._optionalParams: any[]) {}\n}\n","import { LogLevel } from '../enums';\nimport { ILogger } from '../logger';\nimport type { ServiceCollectionOptions } from '../types';\n\nexport class ConsoleLogger extends ILogger {\n constructor(private readonly options: ServiceCollectionOptions) {\n super();\n }\n\n public override debug(message?: any, ...optionalParams: any[]): void {\n if (this.options.logLevel <= LogLevel.Debug) {\n console.debug(message, ...optionalParams);\n }\n }\n\n public override info(message?: any, ...optionalParams: any[]): void {\n if (this.options.logLevel <= LogLevel.Info) {\n console.info(message, ...optionalParams);\n }\n }\n\n public override warn(message?: any, ...optionalParams: any[]): void {\n if (this.options.logLevel <= LogLevel.Warn) {\n console.warn(message, ...optionalParams);\n }\n }\n\n public override error(message?: any, ...optionalParams: any[]): void {\n if (this.options.logLevel <= LogLevel.Error) {\n console.error(message, ...optionalParams);\n }\n }\n}\n","import { DefaultServiceCollectionOptions } from './defaults';\nimport type { IServiceCollection } from './interfaces';\nimport { ServiceCollection } from './private/ServiceCollection';\nimport { ConsoleLogger } from './private/consoleLogger';\nimport type { ServiceCollectionOptions } from './types';\n\nconst mergeOptions = (options: Partial<ServiceCollectionOptions> | undefined): ServiceCollectionOptions => ({\n ...DefaultServiceCollectionOptions,\n ...options,\n});\n\n/**\n * Creates a service collection with the (optionally) provided options\n * @param options - Optional configuration for the service collection.\n * @defaultValue Default options are taken from {@link DefaultServiceCollectionOptions}.\n */\nexport const createServiceCollection = (options?: Partial<ServiceCollectionOptions>): IServiceCollection => {\n const mergedOptions = mergeOptions(options);\n const logger = mergedOptions.logger ?? new ConsoleLogger(mergedOptions);\n return new ServiceCollection(logger, mergedOptions, false);\n};\n","import { IResolutionScope, IScopedProvider, IServiceProvider } from './interfaces';\nimport { DesignDependenciesKey } from './private/constants';\nimport { defineMetadata, getMetadata } from './private/metadata';\nimport type { ServiceIdentifier, SourceType } from './types';\n\nconst tagProperty = <T extends SourceType>(metadataKey: string, annotationTarget: object, name: string | symbol, identifier: ServiceIdentifier<T>) => {\n let existing = getMetadata<T>(metadataKey, annotationTarget);\n if (existing === undefined) {\n existing = {};\n defineMetadata(metadataKey, existing, annotationTarget);\n }\n existing[name] = identifier;\n};\n\n/**\n * declares a dependency, use on a class field.\n * Can also depend on {@link IServiceProvider}, {@link IResolutionScope}, or {@link IScopedProvider}.\n * @param identifier the identifier to depend on, i.e. the interface\n */\nexport const dependsOn = <T extends SourceType>(identifier: ServiceIdentifier<T>) => {\n return (value: undefined, ctx: ClassFieldDecoratorContext) => {\n return function (this: object, initialValue: any) {\n const target = this.constructor;\n tagProperty(DesignDependenciesKey, target, ctx.name, identifier);\n return initialValue;\n };\n };\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shellicar/core-di",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "A basic dependency injection library",
5
5
  "repository": {
6
6
  "type": "git",
@@ -41,6 +41,7 @@
41
41
  "@biomejs/biome": "^1.9.4",
42
42
  "@tsconfig/node20": "^20.1.4",
43
43
  "@types/node": "^22.10.5",
44
+ "lefthook": "^1.10.1",
44
45
  "npm-check-updates": "^17.1.13",
45
46
  "npm-run-all2": "^7.0.2",
46
47
  "rimraf": "^6.0.1",
@@ -60,8 +61,10 @@
60
61
  "lint": "biome lint",
61
62
  "format": "biome format",
62
63
  "check": "biome check",
64
+ "type-check": "tsc -p tsconfig.check.json",
63
65
  "ci": "biome ci",
64
66
  "ci:fix": "biome check --fix --diagnostic-level=error",
65
- "updates": "npm-check-updates"
67
+ "updates": "npm-check-updates",
68
+ "postinstall": "lefthook install"
66
69
  }
67
70
  }