@shellicar/core-di 0.0.4 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -4
- package/dist/index.d.mts +59 -12
- package/dist/{index.d.cts → index.d.ts} +59 -12
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +27 -28
- package/dist/index.cjs +0 -2
- package/dist/index.cjs.map +0 -1
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ const services = createServiceCollection();
|
|
|
20
20
|
abstract class IAbstract { abstract method(): void; }
|
|
21
21
|
abstract class Concrete {}
|
|
22
22
|
services.register(IAbstract).to(Concrete);
|
|
23
|
-
//
|
|
23
|
+
// ^ Error
|
|
24
24
|
```
|
|
25
25
|
* Type-safe resolution.
|
|
26
26
|
```ts
|
|
@@ -75,13 +75,41 @@ const provider = services.buildProvider();
|
|
|
75
75
|
const options = provider.resolve(IOptions);
|
|
76
76
|
ok(options instanceof MockOptions);
|
|
77
77
|
```
|
|
78
|
+
* Logging options
|
|
79
|
+
```ts
|
|
80
|
+
class CustomLogger extends ILogger {
|
|
81
|
+
public override debug(message?: any, ...optionalParams: any[]): void {
|
|
82
|
+
// custom implementation
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// Override default logger
|
|
86
|
+
const services1 = createServiceCollection({ logger: new CustomLogger() });
|
|
87
|
+
// Override default log level
|
|
88
|
+
const services2 = createServiceCollection({ logLevel: LogLevel.Debug });
|
|
89
|
+
```
|
|
90
|
+
* Service modules
|
|
91
|
+
```ts
|
|
92
|
+
class IAbstract {}
|
|
93
|
+
class Concrete extends IAbstract {}
|
|
94
|
+
|
|
95
|
+
class MyModule implements IServiceModule {
|
|
96
|
+
public registerServices(services: IServiceCollection): void {
|
|
97
|
+
services.register(IAbstract).to(Concrete);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const services = createServiceCollection();
|
|
102
|
+
services.registerModules(MyModule);
|
|
103
|
+
const provider = services.buildProvider();
|
|
104
|
+
const svc = provider.resolve(IAbstract);
|
|
105
|
+
```
|
|
78
106
|
|
|
79
107
|
## Usage
|
|
80
108
|
|
|
81
109
|
Check the test files for different usage scenarios.
|
|
82
110
|
|
|
83
111
|
```ts
|
|
84
|
-
import { dependsOn, createServiceCollection,
|
|
112
|
+
import { dependsOn, createServiceCollection, IServiceModule, type IServiceCollection } from '@shellicar/core-di';
|
|
85
113
|
|
|
86
114
|
// Define the dependency interface
|
|
87
115
|
abstract class IClock {
|
|
@@ -107,10 +135,16 @@ class DatePrinter implements IDatePrinter {
|
|
|
107
135
|
}
|
|
108
136
|
}
|
|
109
137
|
|
|
138
|
+
class TimeModule extends IServiceModule {
|
|
139
|
+
public registerServices(services: IServiceCollection): void {
|
|
140
|
+
services.register(IClock).to(DefaultClock).singleton();
|
|
141
|
+
services.register(IDatePrinter).to(DatePrinter).scoped();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
110
145
|
// Register and build provider
|
|
111
146
|
const services = createServiceCollection();
|
|
112
|
-
services.
|
|
113
|
-
services.register(IDatePrinter).to(DatePrinter).scoped();
|
|
147
|
+
services.registerModules([TimeModule]);
|
|
114
148
|
const sp = services.buildProvider();
|
|
115
149
|
|
|
116
150
|
// Optionally create a scope
|
package/dist/index.d.mts
CHANGED
|
@@ -5,6 +5,13 @@ declare enum Lifetime {
|
|
|
5
5
|
Singleton = "SINGLETON"
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
declare abstract class ILogger {
|
|
9
|
+
debug(message?: any, ...optionalParams: any[]): void;
|
|
10
|
+
info(message?: any, ...optionalParams: any[]): void;
|
|
11
|
+
error(message?: any, ...optionalParams: any[]): void;
|
|
12
|
+
warn(message?: any, ...optionalParams: any[]): void;
|
|
13
|
+
}
|
|
14
|
+
|
|
8
15
|
type SourceType = object;
|
|
9
16
|
type AbstractNewable<T> = abstract new (...args: any[]) => T;
|
|
10
17
|
type Newable<T> = new (...args: any[]) => T;
|
|
@@ -42,19 +49,49 @@ declare const ResolveMultipleMode: {
|
|
|
42
49
|
readonly LastRegistered: "LAST_REGISTERED";
|
|
43
50
|
};
|
|
44
51
|
type ResolveMultipleMode = (typeof ResolveMultipleMode)[keyof typeof ResolveMultipleMode];
|
|
52
|
+
declare enum LogLevel {
|
|
53
|
+
Debug = 0,
|
|
54
|
+
Info = 1,
|
|
55
|
+
Warn = 2,
|
|
56
|
+
Error = 3,
|
|
57
|
+
None = 4
|
|
58
|
+
}
|
|
45
59
|
declare const DefaultServiceCollectionOptions: ServiceCollectionOptions;
|
|
46
60
|
type ServiceCollectionOptions = {
|
|
61
|
+
/**
|
|
62
|
+
* Whether calling `resolve` when there are multiple registrations
|
|
63
|
+
* will result in an error or resolve the last registered service.
|
|
64
|
+
* @default ResolveMultipleMode.Error
|
|
65
|
+
*/
|
|
47
66
|
registrationMode: ResolveMultipleMode;
|
|
67
|
+
/**
|
|
68
|
+
* The default log level for the console logger.
|
|
69
|
+
* @defaultValue {@link LogLevel.Warn}
|
|
70
|
+
*/
|
|
71
|
+
logLevel: LogLevel;
|
|
72
|
+
/**
|
|
73
|
+
* Custom implementation for logger. Ignores log level.
|
|
74
|
+
* @defaultValue {@link ConsoleLogger}
|
|
75
|
+
*/
|
|
76
|
+
logger?: ILogger;
|
|
48
77
|
};
|
|
49
78
|
|
|
50
79
|
declare abstract class IDisposable {
|
|
51
|
-
abstract [Symbol.dispose]
|
|
80
|
+
abstract [Symbol.dispose](): void;
|
|
52
81
|
}
|
|
53
82
|
declare abstract class IServiceModule {
|
|
54
83
|
abstract registerServices(services: IServiceCollection): void;
|
|
55
84
|
}
|
|
56
85
|
declare abstract class IServiceScope {
|
|
86
|
+
/**
|
|
87
|
+
* Resolves a single implementation for the identifier.
|
|
88
|
+
* When finding multiple implementations, it will either
|
|
89
|
+
* throw a {@link MultipleRegistrationError} or resolve the latest depending on the provided options.
|
|
90
|
+
*/
|
|
57
91
|
abstract resolve<T extends SourceType>(identifier: ServiceIdentifier<T>): T;
|
|
92
|
+
/**
|
|
93
|
+
* Resolves all implementations for the identifier.
|
|
94
|
+
*/
|
|
58
95
|
abstract resolveAll<T extends SourceType>(identifier: ServiceIdentifier<T>): T[];
|
|
59
96
|
}
|
|
60
97
|
declare abstract class IServiceProvider extends IServiceScope {
|
|
@@ -65,20 +102,26 @@ declare abstract class IServiceCollection {
|
|
|
65
102
|
abstract readonly options: ServiceCollectionOptions;
|
|
66
103
|
abstract get<T extends SourceType>(key: ServiceIdentifier<T>): ServiceDescriptor<T>[];
|
|
67
104
|
abstract register<T extends SourceType>(identifier: ServiceIdentifier<T>): ServiceBuilder<T>;
|
|
68
|
-
abstract registerModules(modules: ServiceModuleType[]): void;
|
|
105
|
+
abstract registerModules(...modules: ServiceModuleType[]): void;
|
|
69
106
|
abstract buildProvider(): IServiceProvider;
|
|
70
107
|
abstract clone(): IServiceCollection;
|
|
108
|
+
abstract clone(scoped: true): IServiceCollection;
|
|
71
109
|
}
|
|
72
110
|
|
|
111
|
+
/**
|
|
112
|
+
* Creates a service collection with the (optionally) provided options
|
|
113
|
+
* @param options - Optional configuration for the service collection.
|
|
114
|
+
* @defaultValue Default options are taken from {@link DefaultServiceCollectionOptions}.
|
|
115
|
+
*/
|
|
73
116
|
declare const createServiceCollection: (options?: Partial<ServiceCollectionOptions>) => IServiceCollection;
|
|
74
117
|
|
|
118
|
+
/**
|
|
119
|
+
* declares a dependency, use on a class field
|
|
120
|
+
* @param identifier the identifier to depend on, i.e. the interface
|
|
121
|
+
*/
|
|
75
122
|
declare const dependsOn: <T extends SourceType>(identifier: ServiceIdentifier<T>) => (value: undefined, ctx: ClassFieldDecoratorContext) => (this: object, initialValue: any) => any;
|
|
76
123
|
|
|
77
|
-
declare const enable: () => void;
|
|
78
|
-
declare const disable: () => void;
|
|
79
|
-
|
|
80
124
|
declare abstract class ServiceError extends Error {
|
|
81
|
-
constructor(message: string);
|
|
82
125
|
}
|
|
83
126
|
declare class UnregisteredServiceError<T extends object> extends ServiceError {
|
|
84
127
|
name: string;
|
|
@@ -99,25 +142,29 @@ declare class SelfDependencyError extends ServiceError {
|
|
|
99
142
|
}
|
|
100
143
|
|
|
101
144
|
declare class ServiceCollection implements IServiceCollection {
|
|
145
|
+
private readonly logger;
|
|
102
146
|
readonly options: ServiceCollectionOptions;
|
|
147
|
+
private readonly isScoped;
|
|
103
148
|
private readonly services;
|
|
104
|
-
constructor(options: ServiceCollectionOptions, services?: Map<ServiceIdentifier<any>, ServiceDescriptor<any>[]>);
|
|
105
|
-
registerModules(modules:
|
|
149
|
+
constructor(logger: ILogger, options: ServiceCollectionOptions, isScoped: boolean, services?: Map<ServiceIdentifier<any>, ServiceDescriptor<any>[]>);
|
|
150
|
+
registerModules(...modules: ServiceModuleType[]): void;
|
|
106
151
|
get<T extends SourceType>(key: ServiceIdentifier<T>): ServiceDescriptor<T>[];
|
|
107
152
|
register<T extends SourceType>(identifier: ServiceIdentifier<T>): ServiceBuilder<T>;
|
|
108
153
|
private addService;
|
|
109
154
|
clone(): IServiceCollection;
|
|
155
|
+
clone(scoped: true): IServiceCollection;
|
|
110
156
|
buildProvider(): IServiceProvider;
|
|
111
157
|
}
|
|
112
158
|
|
|
113
159
|
type Id<T extends SourceType> = ServiceIdentifier<T> | ServiceImplementation<T>;
|
|
114
160
|
type ResolveMap<T extends SourceType> = Map<ServiceIdentifier<T>, Map<Id<T>, T>>;
|
|
115
161
|
declare class ServiceProvider implements IServiceProvider, IServiceScope {
|
|
116
|
-
private
|
|
117
|
-
private
|
|
162
|
+
private readonly logger;
|
|
163
|
+
private readonly services;
|
|
164
|
+
private readonly singletons;
|
|
118
165
|
private scoped;
|
|
119
166
|
private created;
|
|
120
|
-
constructor(services: IServiceCollection, singletons?: ResolveMap<object>);
|
|
167
|
+
constructor(logger: ILogger, services: IServiceCollection, singletons?: ResolveMap<object>);
|
|
121
168
|
get Services(): IServiceCollection;
|
|
122
169
|
[Symbol.dispose](): void;
|
|
123
170
|
private resolveFrom;
|
|
@@ -129,4 +176,4 @@ declare class ServiceProvider implements IServiceProvider, IServiceScope {
|
|
|
129
176
|
private setDependencies;
|
|
130
177
|
}
|
|
131
178
|
|
|
132
|
-
export { type AbstractNewable, DefaultServiceCollectionOptions, IDisposable, IServiceCollection, IServiceModule, IServiceProvider, IServiceScope, type InstanceFactory, type LifetimeBuilder, type MetadataType, MultipleRegistrationError, type Newable, ResolveMultipleMode, SelfDependencyError, type ServiceBuilder, ServiceCollection, type ServiceCollectionOptions, ServiceCreationError, type ServiceDescriptor, type ServiceDescriptorConcrete, type ServiceDescriptorFactory, ServiceError, type ServiceIdentifier, type ServiceImplementation, type ServiceModuleType, ServiceProvider, type SourceType, UnregisteredServiceError, createServiceCollection, dependsOn
|
|
179
|
+
export { type AbstractNewable, DefaultServiceCollectionOptions, IDisposable, ILogger, IServiceCollection, IServiceModule, IServiceProvider, IServiceScope, type InstanceFactory, type LifetimeBuilder, LogLevel, type MetadataType, MultipleRegistrationError, type Newable, ResolveMultipleMode, SelfDependencyError, type ServiceBuilder, ServiceCollection, type ServiceCollectionOptions, ServiceCreationError, type ServiceDescriptor, type ServiceDescriptorConcrete, type ServiceDescriptorFactory, ServiceError, type ServiceIdentifier, type ServiceImplementation, type ServiceModuleType, ServiceProvider, type SourceType, UnregisteredServiceError, createServiceCollection, dependsOn };
|
|
@@ -5,6 +5,13 @@ declare enum Lifetime {
|
|
|
5
5
|
Singleton = "SINGLETON"
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
declare abstract class ILogger {
|
|
9
|
+
debug(message?: any, ...optionalParams: any[]): void;
|
|
10
|
+
info(message?: any, ...optionalParams: any[]): void;
|
|
11
|
+
error(message?: any, ...optionalParams: any[]): void;
|
|
12
|
+
warn(message?: any, ...optionalParams: any[]): void;
|
|
13
|
+
}
|
|
14
|
+
|
|
8
15
|
type SourceType = object;
|
|
9
16
|
type AbstractNewable<T> = abstract new (...args: any[]) => T;
|
|
10
17
|
type Newable<T> = new (...args: any[]) => T;
|
|
@@ -42,19 +49,49 @@ declare const ResolveMultipleMode: {
|
|
|
42
49
|
readonly LastRegistered: "LAST_REGISTERED";
|
|
43
50
|
};
|
|
44
51
|
type ResolveMultipleMode = (typeof ResolveMultipleMode)[keyof typeof ResolveMultipleMode];
|
|
52
|
+
declare enum LogLevel {
|
|
53
|
+
Debug = 0,
|
|
54
|
+
Info = 1,
|
|
55
|
+
Warn = 2,
|
|
56
|
+
Error = 3,
|
|
57
|
+
None = 4
|
|
58
|
+
}
|
|
45
59
|
declare const DefaultServiceCollectionOptions: ServiceCollectionOptions;
|
|
46
60
|
type ServiceCollectionOptions = {
|
|
61
|
+
/**
|
|
62
|
+
* Whether calling `resolve` when there are multiple registrations
|
|
63
|
+
* will result in an error or resolve the last registered service.
|
|
64
|
+
* @default ResolveMultipleMode.Error
|
|
65
|
+
*/
|
|
47
66
|
registrationMode: ResolveMultipleMode;
|
|
67
|
+
/**
|
|
68
|
+
* The default log level for the console logger.
|
|
69
|
+
* @defaultValue {@link LogLevel.Warn}
|
|
70
|
+
*/
|
|
71
|
+
logLevel: LogLevel;
|
|
72
|
+
/**
|
|
73
|
+
* Custom implementation for logger. Ignores log level.
|
|
74
|
+
* @defaultValue {@link ConsoleLogger}
|
|
75
|
+
*/
|
|
76
|
+
logger?: ILogger;
|
|
48
77
|
};
|
|
49
78
|
|
|
50
79
|
declare abstract class IDisposable {
|
|
51
|
-
abstract [Symbol.dispose]
|
|
80
|
+
abstract [Symbol.dispose](): void;
|
|
52
81
|
}
|
|
53
82
|
declare abstract class IServiceModule {
|
|
54
83
|
abstract registerServices(services: IServiceCollection): void;
|
|
55
84
|
}
|
|
56
85
|
declare abstract class IServiceScope {
|
|
86
|
+
/**
|
|
87
|
+
* Resolves a single implementation for the identifier.
|
|
88
|
+
* When finding multiple implementations, it will either
|
|
89
|
+
* throw a {@link MultipleRegistrationError} or resolve the latest depending on the provided options.
|
|
90
|
+
*/
|
|
57
91
|
abstract resolve<T extends SourceType>(identifier: ServiceIdentifier<T>): T;
|
|
92
|
+
/**
|
|
93
|
+
* Resolves all implementations for the identifier.
|
|
94
|
+
*/
|
|
58
95
|
abstract resolveAll<T extends SourceType>(identifier: ServiceIdentifier<T>): T[];
|
|
59
96
|
}
|
|
60
97
|
declare abstract class IServiceProvider extends IServiceScope {
|
|
@@ -65,20 +102,26 @@ declare abstract class IServiceCollection {
|
|
|
65
102
|
abstract readonly options: ServiceCollectionOptions;
|
|
66
103
|
abstract get<T extends SourceType>(key: ServiceIdentifier<T>): ServiceDescriptor<T>[];
|
|
67
104
|
abstract register<T extends SourceType>(identifier: ServiceIdentifier<T>): ServiceBuilder<T>;
|
|
68
|
-
abstract registerModules(modules: ServiceModuleType[]): void;
|
|
105
|
+
abstract registerModules(...modules: ServiceModuleType[]): void;
|
|
69
106
|
abstract buildProvider(): IServiceProvider;
|
|
70
107
|
abstract clone(): IServiceCollection;
|
|
108
|
+
abstract clone(scoped: true): IServiceCollection;
|
|
71
109
|
}
|
|
72
110
|
|
|
111
|
+
/**
|
|
112
|
+
* Creates a service collection with the (optionally) provided options
|
|
113
|
+
* @param options - Optional configuration for the service collection.
|
|
114
|
+
* @defaultValue Default options are taken from {@link DefaultServiceCollectionOptions}.
|
|
115
|
+
*/
|
|
73
116
|
declare const createServiceCollection: (options?: Partial<ServiceCollectionOptions>) => IServiceCollection;
|
|
74
117
|
|
|
118
|
+
/**
|
|
119
|
+
* declares a dependency, use on a class field
|
|
120
|
+
* @param identifier the identifier to depend on, i.e. the interface
|
|
121
|
+
*/
|
|
75
122
|
declare const dependsOn: <T extends SourceType>(identifier: ServiceIdentifier<T>) => (value: undefined, ctx: ClassFieldDecoratorContext) => (this: object, initialValue: any) => any;
|
|
76
123
|
|
|
77
|
-
declare const enable: () => void;
|
|
78
|
-
declare const disable: () => void;
|
|
79
|
-
|
|
80
124
|
declare abstract class ServiceError extends Error {
|
|
81
|
-
constructor(message: string);
|
|
82
125
|
}
|
|
83
126
|
declare class UnregisteredServiceError<T extends object> extends ServiceError {
|
|
84
127
|
name: string;
|
|
@@ -99,25 +142,29 @@ declare class SelfDependencyError extends ServiceError {
|
|
|
99
142
|
}
|
|
100
143
|
|
|
101
144
|
declare class ServiceCollection implements IServiceCollection {
|
|
145
|
+
private readonly logger;
|
|
102
146
|
readonly options: ServiceCollectionOptions;
|
|
147
|
+
private readonly isScoped;
|
|
103
148
|
private readonly services;
|
|
104
|
-
constructor(options: ServiceCollectionOptions, services?: Map<ServiceIdentifier<any>, ServiceDescriptor<any>[]>);
|
|
105
|
-
registerModules(modules:
|
|
149
|
+
constructor(logger: ILogger, options: ServiceCollectionOptions, isScoped: boolean, services?: Map<ServiceIdentifier<any>, ServiceDescriptor<any>[]>);
|
|
150
|
+
registerModules(...modules: ServiceModuleType[]): void;
|
|
106
151
|
get<T extends SourceType>(key: ServiceIdentifier<T>): ServiceDescriptor<T>[];
|
|
107
152
|
register<T extends SourceType>(identifier: ServiceIdentifier<T>): ServiceBuilder<T>;
|
|
108
153
|
private addService;
|
|
109
154
|
clone(): IServiceCollection;
|
|
155
|
+
clone(scoped: true): IServiceCollection;
|
|
110
156
|
buildProvider(): IServiceProvider;
|
|
111
157
|
}
|
|
112
158
|
|
|
113
159
|
type Id<T extends SourceType> = ServiceIdentifier<T> | ServiceImplementation<T>;
|
|
114
160
|
type ResolveMap<T extends SourceType> = Map<ServiceIdentifier<T>, Map<Id<T>, T>>;
|
|
115
161
|
declare class ServiceProvider implements IServiceProvider, IServiceScope {
|
|
116
|
-
private
|
|
117
|
-
private
|
|
162
|
+
private readonly logger;
|
|
163
|
+
private readonly services;
|
|
164
|
+
private readonly singletons;
|
|
118
165
|
private scoped;
|
|
119
166
|
private created;
|
|
120
|
-
constructor(services: IServiceCollection, singletons?: ResolveMap<object>);
|
|
167
|
+
constructor(logger: ILogger, services: IServiceCollection, singletons?: ResolveMap<object>);
|
|
121
168
|
get Services(): IServiceCollection;
|
|
122
169
|
[Symbol.dispose](): void;
|
|
123
170
|
private resolveFrom;
|
|
@@ -129,4 +176,4 @@ declare class ServiceProvider implements IServiceProvider, IServiceScope {
|
|
|
129
176
|
private setDependencies;
|
|
130
177
|
}
|
|
131
178
|
|
|
132
|
-
export { type AbstractNewable, DefaultServiceCollectionOptions, IDisposable, IServiceCollection, IServiceModule, IServiceProvider, IServiceScope, type InstanceFactory, type LifetimeBuilder, type MetadataType, MultipleRegistrationError, type Newable, ResolveMultipleMode, SelfDependencyError, type ServiceBuilder, ServiceCollection, type ServiceCollectionOptions, ServiceCreationError, type ServiceDescriptor, type ServiceDescriptorConcrete, type ServiceDescriptorFactory, ServiceError, type ServiceIdentifier, type ServiceImplementation, type ServiceModuleType, ServiceProvider, type SourceType, UnregisteredServiceError, createServiceCollection, dependsOn
|
|
179
|
+
export { type AbstractNewable, DefaultServiceCollectionOptions, IDisposable, ILogger, IServiceCollection, IServiceModule, IServiceProvider, IServiceScope, type InstanceFactory, type LifetimeBuilder, LogLevel, type MetadataType, MultipleRegistrationError, type Newable, ResolveMultipleMode, SelfDependencyError, type ServiceBuilder, ServiceCollection, type ServiceCollectionOptions, ServiceCreationError, type ServiceDescriptor, type ServiceDescriptorConcrete, type ServiceDescriptorFactory, ServiceError, type ServiceIdentifier, type ServiceImplementation, type ServiceModuleType, ServiceProvider, type SourceType, UnregisteredServiceError, createServiceCollection, dependsOn };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";function e(e,t){return null!=e?e:t()}var t,r,s,i,o,n;Object.defineProperty(exports,"__esModule",{value:!0});var c=Object.defineProperty,l=(e,t)=>c(e,"name",{value:t,configurable:!0}),a="design:dependencies",p=class extends Error{static{l(this,"ServiceError")}},h=t=class extends p{static{l(this,"UnregisteredServiceError")}__init(){this.name="UnregisteredServiceError"}constructor(e){super(`Resolving service that has not been registered: ${e}`),t.prototype.__init.call(this),Object.setPrototypeOf(this,new.target.prototype)}},g=r=class extends p{static{l(this,"MultipleRegistrationError")}__init2(){this.name="MultipleRegistrationError"}constructor(e){super(`Multiple services have been registered: ${e}`),r.prototype.__init2.call(this),Object.setPrototypeOf(this,new.target.prototype)}},v=s=class extends p{constructor(e,t){super(`Error creating service: ${e}`),s.prototype.__init3.call(this),this.innerError=t,Object.setPrototypeOf(this,new.target.prototype)}static{l(this,"ServiceCreationError")}__init3(){this.name="ServiceCreationError"}},d=i=class extends p{static{l(this,"SelfDependencyError")}__init4(){this.name="SelfDependencyError"}constructor(){super("Service depending on itself"),i.prototype.__init4.call(this),Object.setPrototypeOf(this,new.target.prototype)}},u=o=class extends p{static{l(this,"ScopedSingletonRegistrationError")}__init5(){this.name="ScopedSingletonRegistrationError"}constructor(){super("Cannot register a singleton in a scoped service collection"),o.prototype.__init5.call(this),Object.setPrototypeOf(this,new.target.prototype)}},S=class{static{l(this,"IDisposable")}},f=class{static{l(this,"IServiceModule")}},m=class{static{l(this,"IServiceScope")}},E=class extends m{static{l(this,"IServiceProvider")}},y=class{static{l(this,"IServiceCollection")}};require("@abraham/reflection");var w=l(((e,t)=>Reflect.getMetadata(e,t)),"getMetadata"),_=l(((e,t,r)=>Reflect.defineMetadata(e,t,r)),"defineMetadata"),x={Error:"ERROR",LastRegistered:"LAST_REGISTERED"},b=(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))(b||{}),O={registrationMode:x.Error,logLevel:2},I=l((()=>new Map),"createResolveMap"),M=n=class t{constructor(e,t,r=I()){n.prototype.__init6.call(this),n.prototype.__init7.call(this),this.logger=e,this.services=t,this.singletons=r}static{l(this,"ServiceProvider")}__init6(){this.scoped=I()}__init7(){this.created=[]}get Services(){return this.services}[Symbol.dispose](){for(const e of this.created)e[Symbol.dispose]()}resolveFrom(e,t,r,s){let i=r.get(e);void 0===i&&(i=new Map,r.set(e,i));let o=i.get(t.implementation);return void 0===o&&(o=this.createInstance(t,s),i.set(t.implementation,o),this.setDependencies(t.implementation,o,s)),o}resolveInternal(e,t,r){const s={SINGLETON:this.singletons,SCOPED:this.scoped,RESOLVE:r}[t.lifetime];if(void 0===s){const e=this.createInstance(t,r);return this.setDependencies(t.implementation,e,r),e}return this.resolveFrom(e,t,s,r)}resolveAll(e,t=I()){return this.services.get(e).map((r=>this.resolveInternal(e,r,t)))}resolve(e,t=I()){if(e.prototype===m.prototype||e.prototype===E.prototype)return this;const r=this.services.get(e);if(0===r.length)throw new h(e);if(r.length>1&&this.Services.options.registrationMode===x.Error)throw new g(e);const s=r[r.length-1];return this.resolveInternal(e,s,t)}createInstance(e,t){let r;if("factory"in e){const s=e.factory,i=l((e=>this.resolve(e,t)),"resolve"),o=l((e=>this.resolveAll(e,t)),"resolveAll"),n=this.createScope.bind(this);try{r=s({resolve:i,resolveAll:o,createScope:n,get Services(){return this.Services}})}catch(t){throw this.logger.error(t),new v(e.implementation,t)}}else try{r=new e.implementation}catch(t){throw this.logger.error(t),new v(e.implementation,t)}return"SINGLETON"!==e.lifetime&&Symbol.dispose in r&&this.created.push(r),r}createScope(){return new t(this.logger,this.services.clone(!0),this.singletons)}setDependencies(t,r,s){const i=e(w(a,t),(()=>({})));this.logger.debug("Dependencies",t.name,i);for(const[e,o]of Object.entries(i)){if(o===t)throw new d;{this.logger.debug("Resolving",o,"for",t.name);const i=this.resolve(o,s);r[e]=i}}return r}},R=class t{constructor(e,t,r,s=new Map){this.logger=e,this.options=t,this.isScoped=r,this.services=s}static{l(this,"ServiceCollection")}registerModules(...e){for(const t of e){(new t).registerServices(this)}}get(t){return e(this.services.get(t),(()=>[]))}register(e){return{to:l(((t,r)=>{const s=void 0===r?{implementation:t,lifetime:"RESOLVE"}:{implementation:t,factory:r,lifetime:"RESOLVE"};this.addService(e,s);const i={singleton:l((()=>{if(this.isScoped)throw new u;return s.lifetime="SINGLETON",i}),"singleton"),scoped:l((()=>(s.lifetime="SCOPED",i)),"scoped"),transient:l((()=>(s.lifetime="TRANSIENT",i)),"transient")};return i}),"to")}}addService(e,t){this.logger.info("Adding service",{identifier:e,descriptor:t});let r=this.services.get(e);null==r&&(r=[],this.services.set(e,r)),r.push(t)}clone(e){const r=new Map;for(const[e,t]of this.services){const s=t.map((e=>({...e})));r.set(e,s)}return new t(this.logger,this.options,!0===e,r)}buildProvider(){const e=this.clone();return new M(this.logger,e)}},L=class{static{l(this,"ILogger")}debug(e,...t){}info(e,...t){}error(e,...t){}warn(e,...t){}},D=class extends L{constructor(e){super(),this.options=e}static{l(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)}},P=l((e=>({...O,...e})),"mergeOptions"),C=l((t=>{const r=P(t),s=e(r.logger,(()=>new D(r)));return new R(s,r,!1)}),"createServiceCollection"),N=l(((e,t,r,s)=>{let i=w(e,t);void 0===i&&(i={},_(e,i,t)),i[r]=s}),"tagProperty"),j=l((e=>(t,r)=>function(t){const s=this.constructor;return N(a,s,r.name,e),t}),"dependsOn");exports.DefaultServiceCollectionOptions=O,exports.IDisposable=S,exports.ILogger=L,exports.IServiceCollection=y,exports.IServiceModule=f,exports.IServiceProvider=E,exports.IServiceScope=m,exports.LogLevel=b,exports.MultipleRegistrationError=g,exports.ResolveMultipleMode=x,exports.SelfDependencyError=d,exports.ServiceCollection=R,exports.ServiceCreationError=v,exports.ServiceError=p,exports.ServiceProvider=M,exports.UnregisteredServiceError=h,exports.createServiceCollection=C,exports.dependsOn=j;//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/stephen/repos/shellicar/core-di/dist/index.js","../src/constants.ts","../src/errors.ts","../src/interfaces.ts","../src/metadata.ts","../src/types.ts","../src/ServiceProvider.ts","../src/ServiceCollection.ts","../src/logger.ts","../src/consoleLogger.ts","../src/createServiceC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B,IAAA;AAC1B,EAAA;AAImD,EAAA;AAC2B,IAAA;AAC5B,IAAA;AACkB,MAAA;AAC5B,MAAA;AACtC,IAAA;AAEmE,IAAA;AACrE,EAAA;AAEyC,EAAA;AACb,IAAA;AACoB,IAAA;AAChD,EAAA;AACF;APgOwE;AACA;AQ/S1C;AAAA,EAAA;AAAA,IAAA;AAAA,EAAA;AAC0B,EAAA;AAAC,EAAA;AACF,EAAA;AAAC,EAAA;AACA,EAAA;AAAC,EAAA;AACF,EAAA;AAAC,EAAA;AACxD;ARwTwE;AACA;AS7T7B;AACuB,EAAA;AACxD,IAAA;AADqB,IAAA;AAE7B,EAAA;AAHyC,EAAA;AAAA,IAAA;AAAA,EAAA;AAK4B,EAAA;AACtB,IAAA;AACH,MAAA;AAC1C,IAAA;AACF,EAAA;AAEoE,EAAA;AACtB,IAAA;AACH,MAAA;AACzC,IAAA;AACF,EAAA;AAEoE,EAAA;AACtB,IAAA;AACH,MAAA;AACzC,IAAA;AACF,EAAA;AAEqE,EAAA;AACtB,IAAA;AACH,MAAA;AAC1C,IAAA;AACF,EAAA;AACF;AT+TwE;AACA;AUzVoC;AACvG,EAAA;AACA,EAAA;AAFgB;AAUuF;AAChE,EAAA;AAC4B,EAAA;AACb,EAAA;AAHpB;AVyViC;AACA;AWtWR;AACH,EAAA;AAC/B,EAAA;AACd,IAAA;AAC0C,IAAA;AACxD,EAAA;AACiB,EAAA;AANC;AAaiE;AACrB,EAAA;AACV,IAAA;AAC5B,MAAA;AAC2C,MAAA;AACxD,MAAA;AACT,IAAA;AACF,EAAA;AAPuB;AX2W+C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/stephen/repos/shellicar/core-di/dist/index.js","sourcesContent":[null,"export enum Lifetime {\n Resolve = 'RESOLVE',\n Transient = 'TRANSIENT',\n Scoped = 'SCOPED',\n Singleton = 'SINGLETON',\n}\n\nexport const DesignDependenciesKey = 'design:dependencies';\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}`);\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}`);\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}`);\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","// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport type { MultipleRegistrationError } from './errors';\nimport type { ServiceBuilder, ServiceCollectionOptions, ServiceDescriptor, ServiceIdentifier, ServiceModuleType, SourceType } 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 IServiceScope {\n /**\n * Resolves a single implementation for the identifier.\n * When finding multiple implementations, it will either\n * throw a {@link MultipleRegistrationError} or resolve the latest depending on the provided options.\n */\n public abstract resolve<T extends SourceType>(identifier: ServiceIdentifier<T>): T;\n /**\n * Resolves all implementations for the identifier.\n */\n public abstract resolveAll<T extends SourceType>(identifier: ServiceIdentifier<T>): T[];\n}\n\nexport abstract class IServiceProvider extends IServiceScope {\n public abstract get Services(): IServiceCollection;\n public abstract createScope(): IServiceProvider & IDisposable;\n}\n\nexport abstract class IServiceCollection {\n public abstract readonly options: ServiceCollectionOptions;\n public abstract get<T extends SourceType>(key: ServiceIdentifier<T>): ServiceDescriptor<T>[];\n public abstract register<T extends SourceType>(identifier: ServiceIdentifier<T>): ServiceBuilder<T>;\n public abstract registerModules(...modules: ServiceModuleType[]): void;\n public abstract buildProvider(): IServiceProvider;\n public abstract clone(): IServiceCollection;\n public abstract clone(scoped: true): IServiceCollection;\n}\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 type { ConsoleLogger } from './consoleLogger';\nimport type { Lifetime } from './constants';\nimport type { IServiceModule, IServiceProvider, IServiceScope } from './interfaces';\nimport type { ILogger } from './logger';\n\nexport type SourceType = object;\n\nexport type AbstractNewable<T> = abstract new (...args: any[]) => T;\nexport type Newable<T> = new (...args: any[]) => T;\n\nexport type ServiceIdentifier<T extends SourceType> = { prototype: T; name: string }; //AbstractNewable<T>;\nexport type ServiceImplementation<T extends SourceType> = Newable<T>;\n\nexport type InstanceFactory<T extends SourceType> = (x: IServiceScope & IServiceProvider) => T;\n\nexport type ServiceModuleType = Newable<IServiceModule>;\n\nexport type ServiceDescriptorFactory<T extends SourceType> = {\n implementation: ServiceIdentifier<T>;\n factory: InstanceFactory<T>;\n lifetime: Lifetime;\n};\nexport type ServiceDescriptorConcrete<T extends SourceType> = {\n implementation: ServiceImplementation<T>;\n lifetime: Lifetime;\n};\n\nexport type ServiceDescriptor<T extends SourceType> = ServiceDescriptorConcrete<T> | ServiceDescriptorFactory<T>;\n\nexport type LifetimeBuilder = {\n singleton: () => LifetimeBuilder;\n scoped: () => LifetimeBuilder;\n transient: () => LifetimeBuilder;\n};\nexport type ServiceBuilder<T extends SourceType> = {\n to: {\n (implementation: ServiceImplementation<T>): LifetimeBuilder;\n (implementation: ServiceIdentifier<T>, factory: InstanceFactory<T>): LifetimeBuilder;\n };\n};\n\nexport type MetadataType<T extends SourceType> = Record<string | symbol, ServiceIdentifier<T>>;\n\nexport const ResolveMultipleMode = {\n Error: 'ERROR',\n LastRegistered: 'LAST_REGISTERED',\n} as const;\nexport type ResolveMultipleMode = (typeof ResolveMultipleMode)[keyof typeof ResolveMultipleMode];\n\nexport enum LogLevel {\n Debug = 0,\n Info = 1,\n Warn = 2,\n Error = 3,\n None = 4,\n}\n\n// export const LogLevel = {\n// Debug: 0,\n// Info: 1,\n// Warn: 2,\n// Error: 3,\n// None: 4,\n// } as const;\n// export type LogLevel = (typeof LogLevel)[keyof typeof LogLevel];\n\nexport const DefaultServiceCollectionOptions: ServiceCollectionOptions = {\n registrationMode: ResolveMultipleMode.Error,\n logLevel: LogLevel.Warn,\n};\n\nexport type ServiceCollectionOptions = {\n /**\n * Whether calling `resolve` when there are multiple registrations\n * will result in an error or resolve the last registered service.\n * @default ResolveMultipleMode.Error\n */\n registrationMode: ResolveMultipleMode;\n /**\n * The default log level for the console logger.\n * @defaultValue {@link LogLevel.Warn}\n */\n logLevel: LogLevel;\n /**\n * Custom implementation for logger. Ignores log level.\n * @defaultValue {@link ConsoleLogger}\n */\n logger?: ILogger;\n};\n","import { DesignDependenciesKey, Lifetime } from './constants';\nimport { MultipleRegistrationError, SelfDependencyError, ServiceCreationError, UnregisteredServiceError } from './errors';\nimport type { IDisposable, IServiceCollection } from './interfaces';\nimport { IServiceProvider, IServiceScope } from './interfaces';\nimport type { ILogger } from './logger';\nimport { getMetadata } from './metadata';\nimport type { ServiceDescriptor, ServiceIdentifier, ServiceImplementation, SourceType } from './types';\nimport { ResolveMultipleMode } from './types';\n\ntype Id<T extends SourceType> = ServiceIdentifier<T> | ServiceImplementation<T>;\n\ntype ResolveMap<T extends SourceType> = Map<ServiceIdentifier<T>, Map<Id<T>, T>>;\n\nconst createResolveMap = <T extends SourceType>(): ResolveMap<T> => new Map<ServiceIdentifier<T>, Map<ServiceImplementation<T>, T>>();\n\nexport class ServiceProvider implements IServiceProvider, IServiceScope {\n private scoped = createResolveMap();\n private created: IDisposable[] = [];\n\n constructor(\n private readonly logger: ILogger,\n private readonly services: IServiceCollection,\n private readonly singletons = createResolveMap(),\n ) {}\n\n public get Services(): IServiceCollection {\n return this.services;\n }\n\n [Symbol.dispose]() {\n for (const x of this.created) {\n x[Symbol.dispose]();\n }\n }\n\n private resolveFrom<T extends SourceType>(identifier: ServiceIdentifier<T>, descriptor: ServiceDescriptor<T>, lifetimeMap: ResolveMap<T>, currentResolve: ResolveMap<T>): T {\n let resolvedInstances = lifetimeMap.get(identifier);\n if (resolvedInstances === undefined) {\n resolvedInstances = new Map();\n lifetimeMap.set(identifier, resolvedInstances);\n }\n\n let instance = resolvedInstances.get(descriptor.implementation);\n if (instance === undefined) {\n instance = this.createInstance(descriptor, currentResolve);\n resolvedInstances.set(descriptor.implementation, instance);\n this.setDependencies<T>(descriptor.implementation, instance, currentResolve);\n }\n return instance;\n }\n\n private resolveInternal<T extends SourceType>(identifier: ServiceIdentifier<T>, descriptor: ServiceDescriptor<T>, currentResolve: ResolveMap<T>): T {\n const mapping: Partial<Record<Lifetime, ResolveMap<any>>> = {\n [Lifetime.Singleton]: this.singletons,\n [Lifetime.Scoped]: this.scoped,\n [Lifetime.Resolve]: currentResolve,\n };\n const sourceMap = mapping[descriptor.lifetime];\n if (sourceMap === undefined) {\n const instance = this.createInstance(descriptor, currentResolve);\n this.setDependencies<T>(descriptor.implementation, instance, currentResolve);\n return instance;\n }\n return this.resolveFrom(identifier, descriptor, sourceMap, currentResolve);\n }\n\n public resolveAll<T extends SourceType>(identifier: ServiceIdentifier<T>, currentResolve = createResolveMap<T>()): T[] {\n const descriptors = this.services.get(identifier);\n return descriptors.map((descriptor) => this.resolveInternal<T>(identifier, descriptor, currentResolve));\n }\n\n public resolve<T extends SourceType>(identifier: ServiceIdentifier<T>, currentResolve = createResolveMap<T>()): T {\n if (identifier.prototype === IServiceScope.prototype || identifier.prototype === IServiceProvider.prototype) {\n return this as unknown as T;\n }\n\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 this.resolveInternal(identifier, descriptor, currentResolve);\n }\n\n private createInstance<T extends SourceType>(descriptor: ServiceDescriptor<T>, currentResolve: ResolveMap<T>): T {\n let instance: T;\n if ('factory' in descriptor) {\n const factory = descriptor.factory;\n const resolve = (identifier: ServiceIdentifier<any>) => this.resolve(identifier, currentResolve);\n const resolveAll = (identifier: ServiceIdentifier<any>) => this.resolveAll(identifier, currentResolve);\n const createScope = this.createScope.bind(this);\n\n // proxy requests to keep current resolved types\n try {\n instance = factory({\n resolve,\n resolveAll,\n createScope,\n get Services() {\n return this.Services;\n },\n });\n } catch (err) {\n this.logger.error(err);\n throw new ServiceCreationError(descriptor.implementation, err);\n }\n } else {\n try {\n instance = new descriptor.implementation();\n } catch (err) {\n this.logger.error(err);\n throw new ServiceCreationError(descriptor.implementation, err);\n }\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(): IServiceProvider & IDisposable {\n return new ServiceProvider(this.logger, this.services.clone(true), this.singletons);\n }\n\n private setDependencies<T extends SourceType>(type: Id<T>, instance: T, currentResolve: ResolveMap<T>): T {\n const dependencies = getMetadata<T>(DesignDependenciesKey, type) ?? {};\n this.logger.debug('Dependencies', type.name, dependencies);\n for (const [key, identifier] of Object.entries(dependencies)) {\n if (identifier !== type) {\n this.logger.debug('Resolving', identifier, 'for', type.name);\n const dep = this.resolve(identifier, currentResolve);\n (instance as Record<string, unknown>)[key] = dep;\n } else {\n throw new SelfDependencyError();\n }\n }\n return instance;\n }\n}\n","import { ServiceProvider } from './ServiceProvider';\nimport { Lifetime } from './constants';\nimport { ScopedSingletonRegistrationError } from './errors';\nimport type { IServiceCollection, IServiceProvider } from './interfaces';\nimport type { ILogger } from './logger';\nimport type { InstanceFactory, ServiceBuilder, ServiceCollectionOptions, ServiceDescriptor, ServiceIdentifier, ServiceImplementation, ServiceModuleType, SourceType } from './types';\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 register<T extends SourceType>(identifier: ServiceIdentifier<T>): ServiceBuilder<T> {\n return {\n // to: (implementation: ServiceImplementation<T>, func?: InstanceFactory<T>) => {\n to: (implementation: ServiceImplementation<T> | ServiceIdentifier<T>, factory?: InstanceFactory<T>) => {\n const descriptor: ServiceDescriptor<T> = factory === undefined ? { implementation: implementation as ServiceImplementation<T>, lifetime: Lifetime.Resolve } : { implementation, factory, lifetime: Lifetime.Resolve };\n this.addService(identifier, descriptor);\n const builder = {\n singleton: () => {\n if (this.isScoped) {\n throw new ScopedSingletonRegistrationError();\n }\n descriptor.lifetime = Lifetime.Singleton;\n return builder;\n },\n scoped: () => {\n descriptor.lifetime = Lifetime.Scoped;\n return builder;\n },\n transient: () => {\n descriptor.lifetime = Lifetime.Transient;\n return builder;\n },\n };\n return builder;\n },\n };\n }\n\n private addService<T extends SourceType>(identifier: ServiceIdentifier<T>, descriptor: ServiceDescriptor<T>) {\n this.logger.info('Adding service', { identifier, 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(): IServiceCollection;\n public clone(scoped: true): IServiceCollection;\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 const cloned = this.clone();\n return new ServiceProvider(this.logger, cloned);\n }\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unused-vars */\nexport 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 { ILogger } from './logger';\nimport { LogLevel, 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 { ServiceCollection } from './ServiceCollection';\nimport { ConsoleLogger } from './consoleLogger';\nimport type { IServiceCollection } from './interfaces';\nimport type { ServiceCollectionOptions } from './types';\nimport { DefaultServiceCollectionOptions } 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 { DesignDependenciesKey } from './constants';\nimport { defineMetadata, getMetadata } from './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 * @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,2 +1 @@
|
|
|
1
|
-
var
|
|
2
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
var e=Object.defineProperty,t=(t,r)=>e(t,"name",{value:r,configurable:!0}),r="design:dependencies",s=class extends Error{static{t(this,"ServiceError")}},i=class extends s{static{t(this,"UnregisteredServiceError")}name="UnregisteredServiceError";constructor(e){super(`Resolving service that has not been registered: ${e}`),Object.setPrototypeOf(this,new.target.prototype)}},o=class extends s{static{t(this,"MultipleRegistrationError")}name="MultipleRegistrationError";constructor(e){super(`Multiple services have been registered: ${e}`),Object.setPrototypeOf(this,new.target.prototype)}},n=class extends s{constructor(e,t){super(`Error creating service: ${e}`),this.innerError=t,Object.setPrototypeOf(this,new.target.prototype)}static{t(this,"ServiceCreationError")}name="ServiceCreationError"},c=class extends s{static{t(this,"SelfDependencyError")}name="SelfDependencyError";constructor(){super("Service depending on itself"),Object.setPrototypeOf(this,new.target.prototype)}},l=class extends s{static{t(this,"ScopedSingletonRegistrationError")}name="ScopedSingletonRegistrationError";constructor(){super("Cannot register a singleton in a scoped service collection"),Object.setPrototypeOf(this,new.target.prototype)}},a=class{static{t(this,"IDisposable")}},h=class{static{t(this,"IServiceModule")}},p=class{static{t(this,"IServiceScope")}},g=class extends p{static{t(this,"IServiceProvider")}},d=class{static{t(this,"IServiceCollection")}};import"@abraham/reflection";var v=t(((e,t)=>Reflect.getMetadata(e,t)),"getMetadata"),u=t(((e,t,r)=>Reflect.defineMetadata(e,t,r)),"defineMetadata"),f={Error:"ERROR",LastRegistered:"LAST_REGISTERED"},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||{}),m={registrationMode:f.Error,logLevel:2},E=t((()=>new Map),"createResolveMap"),w=class e{constructor(e,t,r=E()){this.logger=e,this.services=t,this.singletons=r}static{t(this,"ServiceProvider")}scoped=E();created=[];get Services(){return this.services}[Symbol.dispose](){for(const e of this.created)e[Symbol.dispose]()}resolveFrom(e,t,r,s){let i=r.get(e);void 0===i&&(i=new Map,r.set(e,i));let o=i.get(t.implementation);return void 0===o&&(o=this.createInstance(t,s),i.set(t.implementation,o),this.setDependencies(t.implementation,o,s)),o}resolveInternal(e,t,r){const s={SINGLETON:this.singletons,SCOPED:this.scoped,RESOLVE:r}[t.lifetime];if(void 0===s){const e=this.createInstance(t,r);return this.setDependencies(t.implementation,e,r),e}return this.resolveFrom(e,t,s,r)}resolveAll(e,t=E()){return this.services.get(e).map((r=>this.resolveInternal(e,r,t)))}resolve(e,t=E()){if(e.prototype===p.prototype||e.prototype===g.prototype)return this;const r=this.services.get(e);if(0===r.length)throw new i(e);if(r.length>1&&this.Services.options.registrationMode===f.Error)throw new o(e);const s=r[r.length-1];return this.resolveInternal(e,s,t)}createInstance(e,r){let s;if("factory"in e){const i=e.factory,o=t((e=>this.resolve(e,r)),"resolve"),c=t((e=>this.resolveAll(e,r)),"resolveAll"),l=this.createScope.bind(this);try{s=i({resolve:o,resolveAll:c,createScope:l,get Services(){return this.Services}})}catch(t){throw this.logger.error(t),new n(e.implementation,t)}}else try{s=new e.implementation}catch(t){throw this.logger.error(t),new n(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 i=v(r,e)??{};this.logger.debug("Dependencies",e.name,i);for(const[r,o]of Object.entries(i)){if(o===e)throw new c;{this.logger.debug("Resolving",o,"for",e.name);const i=this.resolve(o,s);t[r]=i}}return t}},y=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)??[]}register(e){return{to:t(((r,s)=>{const i=void 0===s?{implementation:r,lifetime:"RESOLVE"}:{implementation:r,factory:s,lifetime:"RESOLVE"};this.addService(e,i);const o={singleton:t((()=>{if(this.isScoped)throw new l;return i.lifetime="SINGLETON",o}),"singleton"),scoped:t((()=>(i.lifetime="SCOPED",o)),"scoped"),transient:t((()=>(i.lifetime="TRANSIENT",o)),"transient")};return o}),"to")}}addService(e,t){this.logger.info("Adding service",{identifier:e,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(){const e=this.clone();return new w(this.logger,e)}},b=class{static{t(this,"ILogger")}debug(e,...t){}info(e,...t){}error(e,...t){}warn(e,...t){}},O=class extends b{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=>({...m,...e})),"mergeOptions"),R=t((e=>{const t=I(e),r=t.logger??new O(t);return new y(r,t,!1)}),"createServiceCollection"),M=t(((e,t,r,s)=>{let i=v(e,t);void 0===i&&(i={},u(e,i,t)),i[r]=s}),"tagProperty"),L=t((e=>(t,s)=>function(t){const i=this.constructor;return M(r,i,s.name,e),t}),"dependsOn");export{m as DefaultServiceCollectionOptions,a as IDisposable,b as ILogger,d as IServiceCollection,h as IServiceModule,g as IServiceProvider,p as IServiceScope,S as LogLevel,o as MultipleRegistrationError,f as ResolveMultipleMode,c as SelfDependencyError,y as ServiceCollection,n as ServiceCreationError,s as ServiceError,w as ServiceProvider,i as UnregisteredServiceError,R as createServiceCollection,L as dependsOn};//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/debug.ts","../src/constants.ts","../src/interfaces.ts","../src/metadata.ts","../src/types.ts","../src/errors.ts","../src/ServiceProvider.ts","../src/ServiceCollection.ts","../src/createServiceCollection.ts","../src/dependsOn.ts"],"sourcesContent":["// TODO: Allow configuration of logger in options\nclass DebugLogger {\n private debugging = false;\n\n public enable() { this.debugging = true; }\n public disable() { this.debugging = false; }\n public log(message?: string, ...optionalParams: unknown[]) {\n if(this.debugging) {\n console.log(message, ...optionalParams);\n }\n }\n}\n\nconst logger = new DebugLogger();\n\nexport const log = logger.log.bind(logger);\nexport const enable = logger.enable.bind(logger);\nexport const disable = logger.disable.bind(logger);\n","export enum Lifetime {\n Resolve = 'RESOLVE',\n Transient = 'TRANSIENT',\n Scoped = 'SCOPED',\n Singleton = 'SINGLETON',\n}\n\nexport const DesignDependenciesKey = 'design:dependencies';\n","import type { SourceType, ServiceBuilder, ServiceDescriptor, ServiceIdentifier, ServiceModuleType, ServiceCollectionOptions } 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 IServiceScope {\n public abstract resolve<T extends SourceType>(identifier: ServiceIdentifier<T>): T;\n public abstract resolveAll<T extends SourceType>(identifier: ServiceIdentifier<T>): T[];\n}\n\nexport abstract class IServiceProvider extends IServiceScope {\n public abstract get Services(): IServiceCollection;\n public abstract createScope(): IServiceProvider & IDisposable;\n}\n\nexport abstract class IServiceCollection {\n public abstract readonly options: ServiceCollectionOptions;\n public abstract get<T extends SourceType>(key: ServiceIdentifier<T>): ServiceDescriptor<T>[];\n public abstract register<T extends SourceType>(identifier: ServiceIdentifier<T>): ServiceBuilder<T>;\n public abstract registerModules(modules: ServiceModuleType[]): void;\n public abstract buildProvider(): IServiceProvider;\n public abstract clone(): IServiceCollection;\n}\n","import '@abraham/reflection';\nimport type { MetadataType, SourceType } from './types';\n\nexport const getMetadata = <T extends SourceType>(key: string, obj: object): MetadataType<T> | undefined => {\n if (Reflect.getMetadata === undefined) {\n throw new Error('Please import \"reflect-metadata\"');\n }\n const result = Reflect.getMetadata(key, obj);\n if (result === undefined) {\n return undefined;\n }\n return result as MetadataType<T>;\n};\n\nexport const defineMetadata = <T extends SourceType>(key: string, metadata: MetadataType<T>, obj: object) => {\n if (Reflect.defineMetadata === undefined) {\n throw new Error('Please import \"reflect-metadata\"');\n }\n Reflect.defineMetadata(key, metadata, obj);\n};\n","import type { Lifetime } from './constants';\nimport type { IServiceModule, IServiceProvider, IServiceScope } from './interfaces';\n\nexport type SourceType = object;\n\nexport type AbstractNewable<T> = abstract new (...args: any[]) => T;\nexport type Newable<T> = new (...args: any[]) => T;\n\nexport type ServiceIdentifier<T extends SourceType> = { prototype: T; name: string }; //AbstractNewable<T>;\nexport type ServiceImplementation<T extends SourceType> = Newable<T>;\n\nexport type InstanceFactory<T extends SourceType> = (x: IServiceScope & IServiceProvider) => T;\n\nexport type ServiceModuleType = Newable<IServiceModule>;\n\nexport type ServiceDescriptorFactory<T extends SourceType> = {\n implementation: ServiceIdentifier<T>;\n factory: InstanceFactory<T>;\n lifetime: Lifetime;\n};\nexport type ServiceDescriptorConcrete<T extends SourceType> = {\n implementation: ServiceImplementation<T>;\n lifetime: Lifetime;\n};\n\nexport type ServiceDescriptor<T extends SourceType> = ServiceDescriptorConcrete<T> | ServiceDescriptorFactory<T>;\n// export type ServiceDescriptor<T extends SourceType> = {\n// implementation: ServiceImplementation<T>;\n// factory?: InstanceFactory<T>;\n// lifetime: Lifetime;\n// };\n\nexport type LifetimeBuilder = {\n singleton: () => LifetimeBuilder;\n scoped: () => LifetimeBuilder;\n transient: () => LifetimeBuilder;\n};\nexport type ServiceBuilder<T extends SourceType> = {\n to: {\n (implementation: ServiceImplementation<T>): LifetimeBuilder;\n (implementation: ServiceIdentifier<T>, factory: InstanceFactory<T>): LifetimeBuilder;\n };\n};\n\nexport type MetadataType<T extends SourceType> = Record<string | symbol, ServiceIdentifier<T>>;\n\nexport const ResolveMultipleMode = {\n Error: 'ERROR',\n LastRegistered: 'LAST_REGISTERED',\n} as const;\nexport type ResolveMultipleMode = (typeof ResolveMultipleMode)[keyof typeof ResolveMultipleMode];\n\nexport const DefaultServiceCollectionOptions: ServiceCollectionOptions = {\n registrationMode: ResolveMultipleMode.Error,\n};\n\nexport type ServiceCollectionOptions = {\n registrationMode: ResolveMultipleMode;\n};\n","import type { ServiceIdentifier } from './types';\n\nexport abstract class ServiceError extends Error {\n constructor(message: string) {\n super(message);\n }\n}\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}`);\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}`);\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class ServiceCreationError<T extends object> extends ServiceError {\n name = 'ServiceCreationError';\n constructor(identifier: ServiceIdentifier<T>, public readonly innerError: any) {\n super(`Error creating service: ${identifier}`);\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","import { log } from './debug';\nimport { DesignDependenciesKey, Lifetime } from './constants';\nimport type { IDisposable, IServiceCollection} from './interfaces';\nimport { IServiceScope, IServiceProvider} from './interfaces';\nimport { getMetadata } from './metadata';\nimport type { ServiceIdentifier, ServiceDescriptor, ServiceImplementation, SourceType} from './types';\nimport { ResolveMultipleMode } from './types';\nimport { SelfDependencyError, MultipleRegistrationError, UnregisteredServiceError, ServiceCreationError } from './errors';\n\ntype Id<T extends SourceType> = ServiceIdentifier<T> | ServiceImplementation<T>;\n\ntype ResolveMap<T extends SourceType> = Map<ServiceIdentifier<T>, Map<Id<T>, T>>;\n\nconst createResolveMap = <T extends SourceType>(): ResolveMap<T> => new Map<ServiceIdentifier<T>, Map<ServiceImplementation<T>, T>>();\n\nexport class ServiceProvider implements IServiceProvider, IServiceScope {\n private scoped = createResolveMap();\n private created: IDisposable[] = [];\n\n constructor(\n private services: IServiceCollection,\n private singletons = createResolveMap(),\n ) {}\n \n public get Services(): IServiceCollection {\n return this.services;\n }\n\n [Symbol.dispose]() {\n this.created.forEach(x => x[Symbol.dispose]());\n }\n\n private resolveFrom<T extends SourceType>(\n identifier: ServiceIdentifier<T>,\n descriptor: ServiceDescriptor<T>,\n lifetimeMap: ResolveMap<T>,\n currentResolve: ResolveMap<T>\n ): T {\n let resolvedInstances = lifetimeMap.get(identifier);\n if (resolvedInstances === undefined) {\n resolvedInstances = new Map();\n lifetimeMap.set(identifier, resolvedInstances);\n }\n\n let instance = resolvedInstances.get(descriptor.implementation);\n if (instance === undefined) {\n instance = this.createInstance(descriptor, currentResolve);\n resolvedInstances.set(descriptor.implementation, instance);\n this.setDependencies<T>(descriptor.implementation, instance, currentResolve);\n }\n return instance;\n }\n\n private resolveInternal<T extends SourceType>(\n identifier: ServiceIdentifier<T>,\n descriptor: ServiceDescriptor<T>,\n currentResolve: ResolveMap<T>,\n ): T {\n const mapping: Partial<Record<Lifetime, ResolveMap<any>>> = {\n [Lifetime.Singleton]: this.singletons,\n [Lifetime.Scoped]: this.scoped,\n [Lifetime.Resolve]: currentResolve,\n };\n const sourceMap = mapping[descriptor.lifetime];\n if (sourceMap === undefined) {\n const instance = this.createInstance(descriptor, currentResolve);\n this.setDependencies<T>(descriptor.implementation, instance, currentResolve);\n return instance;\n }\n return this.resolveFrom(identifier, descriptor, sourceMap, currentResolve);\n }\n\n public resolveAll<T extends SourceType>(\n identifier: ServiceIdentifier<T>,\n currentResolve = createResolveMap<T>(),\n ): T[] {\n const descriptors = this.services.get(identifier);\n return descriptors.map(descriptor => this.resolveInternal<T>(identifier, descriptor, currentResolve));\n }\n\n public resolve<T extends SourceType>(\n identifier: ServiceIdentifier<T>,\n currentResolve = createResolveMap<T>(),\n ): T {\n if (identifier.prototype === IServiceScope.prototype || identifier.prototype === IServiceProvider.prototype) {\n return this as unknown as T;\n }\n\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 this.resolveInternal(identifier, descriptor, currentResolve);\n }\n\n private createInstance<T extends SourceType>(descriptor: ServiceDescriptor<T>, currentResolve: ResolveMap<T>): T {\n let instance: T;\n if ('factory' in descriptor) {\n const factory = descriptor.factory;\n const resolve = (identifier: ServiceIdentifier<any>) => this.resolve(identifier, currentResolve);\n const resolveAll = (identifier: ServiceIdentifier<any>) => this.resolveAll(identifier, currentResolve);\n const createScope = this.createScope.bind(this);\n\n // proxy requests to keep current resolved types\n instance = factory({\n resolve,\n resolveAll,\n createScope,\n get Services() { return this.Services; },\n });\n }\n else {\n try {\n instance = new descriptor.implementation();\n }\n catch (err) {\n throw new ServiceCreationError(descriptor.implementation, err);\n }\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(): IServiceProvider & IDisposable {\n return new ServiceProvider(this.services.clone(), this.singletons);\n }\n\n private setDependencies<T extends SourceType>(\n type: Id<T>,\n instance: T,\n currentResolve: ResolveMap<T>,\n ): T {\n const dependencies = getMetadata<T>(DesignDependenciesKey, type) ?? {};\n log('Dependencies', type.name, dependencies);\n for (const [key, identifier] of Object.entries(dependencies)) {\n if (identifier !== type) {\n log('Resolving', identifier, 'for', type.name);\n const dep = this.resolve(identifier, currentResolve);\n (instance as Record<string, unknown>)[key] = dep;\n } else {\n throw new SelfDependencyError();\n }\n }\n return instance;\n }\n}\n","import { ServiceProvider } from './ServiceProvider';\nimport type { SourceType, InstanceFactory, ServiceBuilder, ServiceDescriptor, ServiceIdentifier, ServiceImplementation, Newable, ServiceCollectionOptions } from './types';\nimport type { IServiceCollection, IServiceModule, IServiceProvider } from './interfaces';\nimport { Lifetime } from './constants';\nimport { log } from './debug';\n\nexport class ServiceCollection implements IServiceCollection {\n constructor(public readonly options: ServiceCollectionOptions, private readonly services = new Map<ServiceIdentifier<any>, ServiceDescriptor<any>[]>()) {\n }\n \n public registerModules(modules: Newable<IServiceModule>[]): void {\n modules.forEach(x => {\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 register<T extends SourceType>(identifier: ServiceIdentifier<T>): ServiceBuilder<T> {\n return {\n // to: (implementation: ServiceImplementation<T>, func?: InstanceFactory<T>) => {\n to: (implementation: ServiceImplementation<T> | ServiceIdentifier<T>, factory?: InstanceFactory<T>) => {\n const descriptor: ServiceDescriptor<T>= (factory === undefined) ? { implementation: implementation as ServiceImplementation<T>, lifetime: Lifetime.Resolve } : { implementation, factory, lifetime: Lifetime.Resolve };\n this.addService(identifier, descriptor);\n const builder = {\n singleton: () => { descriptor.lifetime = Lifetime.Singleton; return builder; },\n scoped: () => { descriptor.lifetime = Lifetime.Scoped; return builder; },\n transient: () => { descriptor.lifetime = Lifetime.Transient; return builder; },\n };\n return builder;\n },\n };\n }\n\n private addService<T extends SourceType>(identifier: ServiceIdentifier<T>, descriptor: ServiceDescriptor<T>) {\n log('Adding service', { identifier, 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(): 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.options, clonedMap);\n }\n\n public buildProvider(): IServiceProvider {\n const cloned = this.clone(); \n return new ServiceProvider(cloned);\n }\n}\n","import type { IServiceCollection } from './interfaces';\nimport { ServiceCollection } from './ServiceCollection';\nimport type { ServiceCollectionOptions } from './types';\nimport { DefaultServiceCollectionOptions } from './types';\n\nconst mergeOptions = (options: Partial<ServiceCollectionOptions> | undefined): ServiceCollectionOptions => ({\n ...DefaultServiceCollectionOptions,\n ...options,\n});\n\nexport const createServiceCollection = (options?: Partial<ServiceCollectionOptions>): IServiceCollection => new ServiceCollection(mergeOptions(options)) as IServiceCollection;\n","import { DesignDependenciesKey } from './constants';\nimport type { ServiceIdentifier, SourceType } from './types';\nimport { defineMetadata, getMetadata } from './metadata';\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\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"],"names":["__defProp","__defNormalProp","__publicField"],"mappings":";;AACA,IAAIA,WAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAIC,iBAAe,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,KAAK,GAAG,IAAI,GAAG,GAAGD,WAAS,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAChK,IAAIE,eAAa,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,KAAKD,iBAAe,CAAC,GAAG,EAA4B,GAAG,GAAG,EAAE,CAAM,EAAE,KAAK,CAAC,CAAC;AAC/G,MAAM,WAAW,CAAC;AAClB,EAAE,WAAW,GAAG;AAChB,IAAIC,eAAa,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;AAC5C,GAAG;AACH,EAAE,MAAM,GAAG;AACX,IAAI,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;AAC1B,GAAG;AACH,EAAE,OAAO,GAAG;AACZ,IAAI,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;AAC3B,G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AG,IAAI,CAAC,KAAK,EAAE,CAAC;AAChC,IAAI,OAAO,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC;AACvC,GAAG;AACH;;AC7DA,MAAM,YAAY,GAAG,CAAC,OAAO,MAAM;AACnC,EAAE,GAAG,+BAA+B;AACpC,EAAE,GAAG,OAAO;AACZ,CAAC,CAAC,CAAC;AACS,MAAC,uBAAuB,GAAG,CAAC,OAAO,KAAK,IAAI,iBAAiB,CAAC,YAAY,CAAC,OAAO,CAAC;;ACJ/F,MAAM,WAAW,GAAG,CAAC,WAAW,EAAE,gBAAgB,EAAE,IAAI,EAAE,UAAU,KAAK;AACzE,EAAE,IAAI,QAAQ,GAAG,WAAW,CAAC,WAAW,EAAE,gBAAgB,CAAC,CAAC;AAC5D,EAAE,IAAI,QAAQ,KAAK,KAAK,CAAC,EAAE;AAC3B,IAAI,QAAQ,GAAG,EAAE,CAAC;AAClB,IAAI,cAAc,CAAC,WAAW,EAAE,QAAQ,EAAE,gBAAgB,CAAC,CAAC;AAC5D,GAAG;AACH,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC;AAC9B,CAAC,CAAC;AACU,MAAC,SAAS,GAAG,CAAC,UAAU,KAAK;AACzC,EAAE,OAAO,CAAC,KAAK,EAAE,GAAG,KAAK;AACzB,IAAI,OAAO,SAAS,YAAY,EAAE;AAClC,MAAM,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC;AACtC,MAAM,WAAW,CAAC,qBAAqB,EAAE,MAAM,EAAE,GAAG,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;AACvE,MAAM,OAAO,YAAY,CAAC;AAC1B,KAAK,CAAC;AACN,GAAG,CAAC;AACJ;;;;"}
|
|
1
|
+
{"version":3,"sources":["../src/constants.ts","../src/errors.ts","../src/interfaces.ts","../src/metadata.ts","../src/types.ts","../src/ServiceProvider.ts","../src/ServiceCollection.ts","../src/logger.ts","../src/consoleLogger.ts","../src/createServiceCollection.ts","../src/dependsOn.ts"],"sourcesContent":["export enum Lifetime {\n Resolve = 'RESOLVE',\n Transient = 'TRANSIENT',\n Scoped = 'SCOPED',\n Singleton = 'SINGLETON',\n}\n\nexport const DesignDependenciesKey = 'design:dependencies';\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}`);\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}`);\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}`);\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","// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport type { MultipleRegistrationError } from './errors';\nimport type { ServiceBuilder, ServiceCollectionOptions, ServiceDescriptor, ServiceIdentifier, ServiceModuleType, SourceType } 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 IServiceScope {\n /**\n * Resolves a single implementation for the identifier.\n * When finding multiple implementations, it will either\n * throw a {@link MultipleRegistrationError} or resolve the latest depending on the provided options.\n */\n public abstract resolve<T extends SourceType>(identifier: ServiceIdentifier<T>): T;\n /**\n * Resolves all implementations for the identifier.\n */\n public abstract resolveAll<T extends SourceType>(identifier: ServiceIdentifier<T>): T[];\n}\n\nexport abstract class IServiceProvider extends IServiceScope {\n public abstract get Services(): IServiceCollection;\n public abstract createScope(): IServiceProvider & IDisposable;\n}\n\nexport abstract class IServiceCollection {\n public abstract readonly options: ServiceCollectionOptions;\n public abstract get<T extends SourceType>(key: ServiceIdentifier<T>): ServiceDescriptor<T>[];\n public abstract register<T extends SourceType>(identifier: ServiceIdentifier<T>): ServiceBuilder<T>;\n public abstract registerModules(...modules: ServiceModuleType[]): void;\n public abstract buildProvider(): IServiceProvider;\n public abstract clone(): IServiceCollection;\n public abstract clone(scoped: true): IServiceCollection;\n}\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 type { ConsoleLogger } from './consoleLogger';\nimport type { Lifetime } from './constants';\nimport type { IServiceModule, IServiceProvider, IServiceScope } from './interfaces';\nimport type { ILogger } from './logger';\n\nexport type SourceType = object;\n\nexport type AbstractNewable<T> = abstract new (...args: any[]) => T;\nexport type Newable<T> = new (...args: any[]) => T;\n\nexport type ServiceIdentifier<T extends SourceType> = { prototype: T; name: string }; //AbstractNewable<T>;\nexport type ServiceImplementation<T extends SourceType> = Newable<T>;\n\nexport type InstanceFactory<T extends SourceType> = (x: IServiceScope & IServiceProvider) => T;\n\nexport type ServiceModuleType = Newable<IServiceModule>;\n\nexport type ServiceDescriptorFactory<T extends SourceType> = {\n implementation: ServiceIdentifier<T>;\n factory: InstanceFactory<T>;\n lifetime: Lifetime;\n};\nexport type ServiceDescriptorConcrete<T extends SourceType> = {\n implementation: ServiceImplementation<T>;\n lifetime: Lifetime;\n};\n\nexport type ServiceDescriptor<T extends SourceType> = ServiceDescriptorConcrete<T> | ServiceDescriptorFactory<T>;\n\nexport type LifetimeBuilder = {\n singleton: () => LifetimeBuilder;\n scoped: () => LifetimeBuilder;\n transient: () => LifetimeBuilder;\n};\nexport type ServiceBuilder<T extends SourceType> = {\n to: {\n (implementation: ServiceImplementation<T>): LifetimeBuilder;\n (implementation: ServiceIdentifier<T>, factory: InstanceFactory<T>): LifetimeBuilder;\n };\n};\n\nexport type MetadataType<T extends SourceType> = Record<string | symbol, ServiceIdentifier<T>>;\n\nexport const ResolveMultipleMode = {\n Error: 'ERROR',\n LastRegistered: 'LAST_REGISTERED',\n} as const;\nexport type ResolveMultipleMode = (typeof ResolveMultipleMode)[keyof typeof ResolveMultipleMode];\n\nexport enum LogLevel {\n Debug = 0,\n Info = 1,\n Warn = 2,\n Error = 3,\n None = 4,\n}\n\n// export const LogLevel = {\n// Debug: 0,\n// Info: 1,\n// Warn: 2,\n// Error: 3,\n// None: 4,\n// } as const;\n// export type LogLevel = (typeof LogLevel)[keyof typeof LogLevel];\n\nexport const DefaultServiceCollectionOptions: ServiceCollectionOptions = {\n registrationMode: ResolveMultipleMode.Error,\n logLevel: LogLevel.Warn,\n};\n\nexport type ServiceCollectionOptions = {\n /**\n * Whether calling `resolve` when there are multiple registrations\n * will result in an error or resolve the last registered service.\n * @default ResolveMultipleMode.Error\n */\n registrationMode: ResolveMultipleMode;\n /**\n * The default log level for the console logger.\n * @defaultValue {@link LogLevel.Warn}\n */\n logLevel: LogLevel;\n /**\n * Custom implementation for logger. Ignores log level.\n * @defaultValue {@link ConsoleLogger}\n */\n logger?: ILogger;\n};\n","import { DesignDependenciesKey, Lifetime } from './constants';\nimport { MultipleRegistrationError, SelfDependencyError, ServiceCreationError, UnregisteredServiceError } from './errors';\nimport type { IDisposable, IServiceCollection } from './interfaces';\nimport { IServiceProvider, IServiceScope } from './interfaces';\nimport type { ILogger } from './logger';\nimport { getMetadata } from './metadata';\nimport type { ServiceDescriptor, ServiceIdentifier, ServiceImplementation, SourceType } from './types';\nimport { ResolveMultipleMode } from './types';\n\ntype Id<T extends SourceType> = ServiceIdentifier<T> | ServiceImplementation<T>;\n\ntype ResolveMap<T extends SourceType> = Map<ServiceIdentifier<T>, Map<Id<T>, T>>;\n\nconst createResolveMap = <T extends SourceType>(): ResolveMap<T> => new Map<ServiceIdentifier<T>, Map<ServiceImplementation<T>, T>>();\n\nexport class ServiceProvider implements IServiceProvider, IServiceScope {\n private scoped = createResolveMap();\n private created: IDisposable[] = [];\n\n constructor(\n private readonly logger: ILogger,\n private readonly services: IServiceCollection,\n private readonly singletons = createResolveMap(),\n ) {}\n\n public get Services(): IServiceCollection {\n return this.services;\n }\n\n [Symbol.dispose]() {\n for (const x of this.created) {\n x[Symbol.dispose]();\n }\n }\n\n private resolveFrom<T extends SourceType>(identifier: ServiceIdentifier<T>, descriptor: ServiceDescriptor<T>, lifetimeMap: ResolveMap<T>, currentResolve: ResolveMap<T>): T {\n let resolvedInstances = lifetimeMap.get(identifier);\n if (resolvedInstances === undefined) {\n resolvedInstances = new Map();\n lifetimeMap.set(identifier, resolvedInstances);\n }\n\n let instance = resolvedInstances.get(descriptor.implementation);\n if (instance === undefined) {\n instance = this.createInstance(descriptor, currentResolve);\n resolvedInstances.set(descriptor.implementation, instance);\n this.setDependencies<T>(descriptor.implementation, instance, currentResolve);\n }\n return instance;\n }\n\n private resolveInternal<T extends SourceType>(identifier: ServiceIdentifier<T>, descriptor: ServiceDescriptor<T>, currentResolve: ResolveMap<T>): T {\n const mapping: Partial<Record<Lifetime, ResolveMap<any>>> = {\n [Lifetime.Singleton]: this.singletons,\n [Lifetime.Scoped]: this.scoped,\n [Lifetime.Resolve]: currentResolve,\n };\n const sourceMap = mapping[descriptor.lifetime];\n if (sourceMap === undefined) {\n const instance = this.createInstance(descriptor, currentResolve);\n this.setDependencies<T>(descriptor.implementation, instance, currentResolve);\n return instance;\n }\n return this.resolveFrom(identifier, descriptor, sourceMap, currentResolve);\n }\n\n public resolveAll<T extends SourceType>(identifier: ServiceIdentifier<T>, currentResolve = createResolveMap<T>()): T[] {\n const descriptors = this.services.get(identifier);\n return descriptors.map((descriptor) => this.resolveInternal<T>(identifier, descriptor, currentResolve));\n }\n\n public resolve<T extends SourceType>(identifier: ServiceIdentifier<T>, currentResolve = createResolveMap<T>()): T {\n if (identifier.prototype === IServiceScope.prototype || identifier.prototype === IServiceProvider.prototype) {\n return this as unknown as T;\n }\n\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 this.resolveInternal(identifier, descriptor, currentResolve);\n }\n\n private createInstance<T extends SourceType>(descriptor: ServiceDescriptor<T>, currentResolve: ResolveMap<T>): T {\n let instance: T;\n if ('factory' in descriptor) {\n const factory = descriptor.factory;\n const resolve = (identifier: ServiceIdentifier<any>) => this.resolve(identifier, currentResolve);\n const resolveAll = (identifier: ServiceIdentifier<any>) => this.resolveAll(identifier, currentResolve);\n const createScope = this.createScope.bind(this);\n\n // proxy requests to keep current resolved types\n try {\n instance = factory({\n resolve,\n resolveAll,\n createScope,\n get Services() {\n return this.Services;\n },\n });\n } catch (err) {\n this.logger.error(err);\n throw new ServiceCreationError(descriptor.implementation, err);\n }\n } else {\n try {\n instance = new descriptor.implementation();\n } catch (err) {\n this.logger.error(err);\n throw new ServiceCreationError(descriptor.implementation, err);\n }\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(): IServiceProvider & IDisposable {\n return new ServiceProvider(this.logger, this.services.clone(true), this.singletons);\n }\n\n private setDependencies<T extends SourceType>(type: Id<T>, instance: T, currentResolve: ResolveMap<T>): T {\n const dependencies = getMetadata<T>(DesignDependenciesKey, type) ?? {};\n this.logger.debug('Dependencies', type.name, dependencies);\n for (const [key, identifier] of Object.entries(dependencies)) {\n if (identifier !== type) {\n this.logger.debug('Resolving', identifier, 'for', type.name);\n const dep = this.resolve(identifier, currentResolve);\n (instance as Record<string, unknown>)[key] = dep;\n } else {\n throw new SelfDependencyError();\n }\n }\n return instance;\n }\n}\n","import { ServiceProvider } from './ServiceProvider';\nimport { Lifetime } from './constants';\nimport { ScopedSingletonRegistrationError } from './errors';\nimport type { IServiceCollection, IServiceProvider } from './interfaces';\nimport type { ILogger } from './logger';\nimport type { InstanceFactory, ServiceBuilder, ServiceCollectionOptions, ServiceDescriptor, ServiceIdentifier, ServiceImplementation, ServiceModuleType, SourceType } from './types';\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 register<T extends SourceType>(identifier: ServiceIdentifier<T>): ServiceBuilder<T> {\n return {\n // to: (implementation: ServiceImplementation<T>, func?: InstanceFactory<T>) => {\n to: (implementation: ServiceImplementation<T> | ServiceIdentifier<T>, factory?: InstanceFactory<T>) => {\n const descriptor: ServiceDescriptor<T> = factory === undefined ? { implementation: implementation as ServiceImplementation<T>, lifetime: Lifetime.Resolve } : { implementation, factory, lifetime: Lifetime.Resolve };\n this.addService(identifier, descriptor);\n const builder = {\n singleton: () => {\n if (this.isScoped) {\n throw new ScopedSingletonRegistrationError();\n }\n descriptor.lifetime = Lifetime.Singleton;\n return builder;\n },\n scoped: () => {\n descriptor.lifetime = Lifetime.Scoped;\n return builder;\n },\n transient: () => {\n descriptor.lifetime = Lifetime.Transient;\n return builder;\n },\n };\n return builder;\n },\n };\n }\n\n private addService<T extends SourceType>(identifier: ServiceIdentifier<T>, descriptor: ServiceDescriptor<T>) {\n this.logger.info('Adding service', { identifier, 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(): IServiceCollection;\n public clone(scoped: true): IServiceCollection;\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 const cloned = this.clone();\n return new ServiceProvider(this.logger, cloned);\n }\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unused-vars */\nexport 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 { ILogger } from './logger';\nimport { LogLevel, 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 { ServiceCollection } from './ServiceCollection';\nimport { ConsoleLogger } from './consoleLogger';\nimport type { IServiceCollection } from './interfaces';\nimport type { ServiceCollectionOptions } from './types';\nimport { DefaultServiceCollectionOptions } 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 { DesignDependenciesKey } from './constants';\nimport { defineMetadata, getMetadata } from './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 * @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"],"mappings":";;;;AAOO,IAAM,wBAAwB;;;ACL9B,IAAe,eAAf,cAAoC,MAAM;AAAA,EAFjD,OAEiD;AAAA;AAAA;AAAC;AAE3C,IAAM,2BAAN,cAAyD,aAAa;AAAA,EAJ7E,OAI6E;AAAA;AAAA;AAAA,EAC3E,OAAO;AAAA,EACP,YAAY,YAAkC;AAC5C,UAAM,mDAAmD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AAAA,EACF;AAAA,EAEgB,MAAM,YAAkB,gBAA6B;AACnE,QAAI,KAAK,QAAQ,2BAA4B;AAC3C,cAAQ,MAAM,SAAS,GAAG,cAAc;AAAA,IAC1C;AAAA,EACF;AACF;;;ACzBA,IAAM,eAAe,wBAAC,aAAsF;AAAA,EAC1G,GAAG;AAAA,EACH,GAAG;AACL,IAHqB;AAUd,IAAM,0BAA0B,wBAAC,YAAoE;AAC1G,QAAM,gBAAgB,aAAa,OAAO;AAC1C,QAAM,SAAS,cAAc,UAAU,IAAI,cAAc,aAAa;AACtE,SAAO,IAAI,kBAAkB,QAAQ,eAAe,KAAK;AAC3D,GAJuC;;;ACZvC,IAAM,cAAc,wBAAuB,aAAqB,kBAA0B,MAAuB,eAAqC;AACpJ,MAAI,WAAW,YAAe,aAAa,gBAAgB;AAC3D,MAAI,aAAa,QAAW;AAC1B,eAAW,CAAC;AACZ,mBAAe,aAAa,UAAU,gBAAgB;AAAA,EACxD;AACA,WAAS,IAAI,IAAI;AACnB,GAPoB;AAab,IAAM,YAAY,wBAAuB,eAAqC;AACnF,SAAO,CAAC,OAAkB,QAAoC;AAC5D,WAAO,SAAwB,cAAmB;AAChD,YAAM,SAAS,KAAK;AACpB,kBAAY,uBAAuB,QAAQ,IAAI,MAAM,UAAU;AAC/D,aAAO;AAAA,IACT;AAAA,EACF;AACF,GARyB;","names":["LogLevel"]}
|
package/package.json
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shellicar/core-di",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "A basic dependency injection library",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/shellicar/core-di.git"
|
|
8
8
|
},
|
|
9
9
|
"private": false,
|
|
10
|
-
"main": "./dist/index.
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
11
|
"module": "./dist/index.mjs",
|
|
12
|
-
"types": "./dist/index.d.
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
13
|
"exports": {
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
|
|
14
|
+
".": {
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"import": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"default": "./dist/index.mjs"
|
|
22
|
+
}
|
|
21
23
|
}
|
|
22
24
|
},
|
|
23
25
|
"files": [
|
|
@@ -36,30 +38,27 @@
|
|
|
36
38
|
},
|
|
37
39
|
"homepage": "https://github.com/shellicar/core-di#readme",
|
|
38
40
|
"devDependencies": {
|
|
39
|
-
"@
|
|
40
|
-
"@types/mocha": "^10.0.
|
|
41
|
-
"@types/node": "^22.
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"eslint-plugin-prefer-arrow-functions": "^3.4.1",
|
|
45
|
-
"eslint-plugin-turbo": "^2.1.2",
|
|
46
|
-
"eslint-plugin-unicorn": "^55.0.0",
|
|
47
|
-
"mocha": "^10.7.3",
|
|
48
|
-
"npm-run-all2": "^6.2.3",
|
|
49
|
-
"pkgroll": "^2.5.0",
|
|
41
|
+
"@biomejs/biome": "^1.9.4",
|
|
42
|
+
"@types/mocha": "^10.0.9",
|
|
43
|
+
"@types/node": "^22.8.4",
|
|
44
|
+
"mocha": "^10.8.1",
|
|
45
|
+
"npm-run-all2": "^7.0.1",
|
|
50
46
|
"rimraf": "^6.0.1",
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
47
|
+
"terser": "^5.36.0",
|
|
48
|
+
"tsup": "^8.3.5",
|
|
49
|
+
"tsx": "^4.19.2",
|
|
50
|
+
"typescript": "^5.6.3"
|
|
54
51
|
},
|
|
55
52
|
"dependencies": {
|
|
56
53
|
"@abraham/reflection": "^0.12.0"
|
|
57
54
|
},
|
|
58
55
|
"scripts": {
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"check": "tsc --noEmit --composite false --skipLibCheck",
|
|
56
|
+
"build": "tsup-node",
|
|
57
|
+
"ci:fix": "biome check --fix --diagnostic-level=error",
|
|
62
58
|
"test": "mocha",
|
|
63
|
-
"lint": "
|
|
59
|
+
"lint": "biome lint",
|
|
60
|
+
"format": "biome format",
|
|
61
|
+
"check": "biome check",
|
|
62
|
+
"ci": "biome ci"
|
|
64
63
|
}
|
|
65
64
|
}
|
package/dist/index.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var Q=Object.defineProperty;var r=(s,e)=>Q(s,"name",{value:e,configurable:!0});require("@abraham/reflection");var U=Object.defineProperty,W=r((s,e,t)=>e in s?U(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,"__defNormalProp$2"),X=r((s,e,t)=>W(s,e+"",t),"__publicField$2");const A=class A{constructor(){X(this,"debugging",!1)}enable(){this.debugging=!0}disable(){this.debugging=!1}log(e,...t){this.debugging&&console.log(e,...t)}};r(A,"DebugLogger");let R=A;const d=new R,y=d.log.bind(d),Y=d.enable.bind(d),Z=d.disable.bind(d);var l=(s=>(s.Resolve="RESOLVE",s.Transient="TRANSIENT",s.Scoped="SCOPED",s.Singleton="SINGLETON",s))(l||{});const B="design:dependencies",T=class T{};r(T,"IDisposable");let $=T;const _=class _{};r(_,"IServiceModule");let x=_;const F=class F{};r(F,"IServiceScope");let h=F;const I=class I extends h{};r(I,"IServiceProvider");let g=I;const C=class C{};r(C,"IServiceCollection");let D=C;const H=r((s,e)=>{if(Reflect.getMetadata===void 0)throw new Error('Please import "reflect-metadata"');const t=Reflect.getMetadata(s,e);if(t!==void 0)return t},"getMetadata"),L=r((s,e,t)=>{if(Reflect.defineMetadata===void 0)throw new Error('Please import "reflect-metadata"');Reflect.defineMetadata(s,e,t)},"defineMetadata"),N={Error:"ERROR",LastRegistered:"LAST_REGISTERED"},J={registrationMode:N.Error};var k=Object.defineProperty,ee=r((s,e,t)=>e in s?k(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,"__defNormalProp$1"),v=r((s,e,t)=>ee(s,e+"",t),"__publicField$1");const j=class j extends Error{constructor(e){super(e)}};r(j,"ServiceError");let a=j;const G=class G extends a{constructor(e){super(`Resolving service that has not been registered: ${e}`),v(this,"name","UnregisteredServiceError"),Object.setPrototypeOf(this,new.target.prototype)}};r(G,"UnregisteredServiceError");let f=G;const q=class q extends a{constructor(e){super(`Multiple services have been registered: ${e}`),v(this,"name","MultipleRegistrationError"),Object.setPrototypeOf(this,new.target.prototype)}};r(q,"MultipleRegistrationError");let m=q;const V=class V extends a{constructor(e,t){super(`Error creating service: ${e}`),this.innerError=t,v(this,"name","ServiceCreationError"),Object.setPrototypeOf(this,new.target.prototype)}};r(V,"ServiceCreationError");let b=V;const z=class z extends a{constructor(){super("Service depending on itself"),v(this,"name","SelfDependencyError"),Object.setPrototypeOf(this,new.target.prototype)}};r(z,"SelfDependencyError");let w=z;var te=Object.defineProperty,se=r((s,e,t)=>e in s?te(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,"__defNormalProp"),K=r((s,e,t)=>se(s,typeof e!="symbol"?e+"":e,t),"__publicField");const S=r(()=>new Map,"createResolveMap"),E=class E{constructor(e,t=S()){this.services=e,this.singletons=t,K(this,"scoped",S()),K(this,"created",[])}get Services(){return this.services}[Symbol.dispose](){this.created.forEach(e=>e[Symbol.dispose]())}resolveFrom(e,t,n,o){let i=n.get(e);i===void 0&&(i=new Map,n.set(e,i));let c=i.get(t.implementation);return c===void 0&&(c=this.createInstance(t,o),i.set(t.implementation,c),this.setDependencies(t.implementation,c,o)),c}resolveInternal(e,t,n){const i={[l.Singleton]:this.singletons,[l.Scoped]:this.scoped,[l.Resolve]:n}[t.lifetime];if(i===void 0){const c=this.createInstance(t,n);return this.setDependencies(t.implementation,c,n),c}return this.resolveFrom(e,t,i,n)}resolveAll(e,t=S()){return this.services.get(e).map(o=>this.resolveInternal(e,o,t))}resolve(e,t=S()){if(e.prototype===h.prototype||e.prototype===g.prototype)return this;const n=this.services.get(e);if(n.length===0)throw new f(e);if(n.length>1&&this.Services.options.registrationMode===N.Error)throw new m(e);const o=n[n.length-1];return this.resolveInternal(e,o,t)}createInstance(e,t){let n;if("factory"in e){const o=e.factory,i=r(u=>this.resolve(u,t),"resolve"),c=r(u=>this.resolveAll(u,t),"resolveAll"),p=this.createScope.bind(this);n=o({resolve:i,resolveAll:c,createScope:p,get Services(){return this.Services}})}else try{n=new e.implementation}catch(o){throw new b(e.implementation,o)}return e.lifetime!==l.Singleton&&Symbol.dispose in n&&this.created.push(n),n}createScope(){return new E(this.services.clone(),this.singletons)}setDependencies(e,t,n){var o;const i=(o=H(B,e))!=null?o:{};y("Dependencies",e.name,i);for(const[c,p]of Object.entries(i))if(p!==e){y("Resolving",p,"for",e.name);const u=this.resolve(p,n);t[c]=u}else throw new w;return t}};r(E,"ServiceProvider");let O=E;const P=class P{constructor(e,t=new Map){this.options=e,this.services=t}registerModules(e){e.forEach(t=>{new t().registerServices(this)})}get(e){var t;return(t=this.services.get(e))!=null?t:[]}register(e){return{to:r((t,n)=>{const o=n===void 0?{implementation:t,lifetime:l.Resolve}:{implementation:t,factory:n,lifetime:l.Resolve};this.addService(e,o);const i={singleton:r(()=>(o.lifetime=l.Singleton,i),"singleton"),scoped:r(()=>(o.lifetime=l.Scoped,i),"scoped"),transient:r(()=>(o.lifetime=l.Transient,i),"transient")};return i},"to")}}addService(e,t){y("Adding service",{identifier:e,descriptor:t});let n=this.services.get(e);n==null&&(n=[],this.services.set(e,n)),n.push(t)}clone(){const e=new Map;for(const[t,n]of this.services){const o=n.map(i=>({...i}));e.set(t,o)}return new P(this.options,e)}buildProvider(){const e=this.clone();return new O(e)}};r(P,"ServiceCollection");let M=P;const ne=r(s=>({...J,...s}),"mergeOptions"),re=r(s=>new M(ne(s)),"createServiceCollection"),oe=r((s,e,t,n)=>{let o=H(s,e);o===void 0&&(o={},L(s,o,e)),o[t]=n},"tagProperty"),ie=r(s=>(e,t)=>function(n){const o=this.constructor;return oe(B,o,t.name,s),n},"dependsOn");exports.DefaultServiceCollectionOptions=J,exports.IDisposable=$,exports.IServiceCollection=D,exports.IServiceModule=x,exports.IServiceProvider=g,exports.IServiceScope=h,exports.MultipleRegistrationError=m,exports.ResolveMultipleMode=N,exports.SelfDependencyError=w,exports.ServiceCollection=M,exports.ServiceCreationError=b,exports.ServiceError=a,exports.ServiceProvider=O,exports.UnregisteredServiceError=f,exports.createServiceCollection=re,exports.dependsOn=ie,exports.disable=Z,exports.enable=Y;
|
|
2
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/debug.ts","../src/constants.ts","../src/interfaces.ts","../src/metadata.ts","../src/types.ts","../src/errors.ts","../src/ServiceProvider.ts","../src/ServiceCollection.ts","../src/createServiceCollection.ts","../src/dependsOn.ts"],"sourcesContent":["// TODO: Allow configuration of logger in options\nclass DebugLogger {\n private debugging = false;\n\n public enable() { this.debugging = true; }\n public disable() { this.debugging = false; }\n public log(message?: string, ...optionalParams: unknown[]) {\n if(this.debugging) {\n console.log(message, ...optionalParams);\n }\n }\n}\n\nconst logger = new DebugLogger();\n\nexport const log = logger.log.bind(logger);\nexport const enable = logger.enable.bind(logger);\nexport const disable = logger.disable.bind(logger);\n","export enum Lifetime {\n Resolve = 'RESOLVE',\n Transient = 'TRANSIENT',\n Scoped = 'SCOPED',\n Singleton = 'SINGLETON',\n}\n\nexport const DesignDependenciesKey = 'design:dependencies';\n","import type { SourceType, ServiceBuilder, ServiceDescriptor, ServiceIdentifier, ServiceModuleType, ServiceCollectionOptions } 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 IServiceScope {\n public abstract resolve<T extends SourceType>(identifier: ServiceIdentifier<T>): T;\n public abstract resolveAll<T extends SourceType>(identifier: ServiceIdentifier<T>): T[];\n}\n\nexport abstract class IServiceProvider extends IServiceScope {\n public abstract get Services(): IServiceCollection;\n public abstract createScope(): IServiceProvider & IDisposable;\n}\n\nexport abstract class IServiceCollection {\n public abstract readonly options: ServiceCollectionOptions;\n public abstract get<T extends SourceType>(key: ServiceIdentifier<T>): ServiceDescriptor<T>[];\n public abstract register<T extends SourceType>(identifier: ServiceIdentifier<T>): ServiceBuilder<T>;\n public abstract registerModules(modules: ServiceModuleType[]): void;\n public abstract buildProvider(): IServiceProvider;\n public abstract clone(): IServiceCollection;\n}\n","import '@abraham/reflection';\nimport type { MetadataType, SourceType } from './types';\n\nexport const getMetadata = <T extends SourceType>(key: string, obj: object): MetadataType<T> | undefined => {\n if (Reflect.getMetadata === undefined) {\n throw new Error('Please import \"reflect-metadata\"');\n }\n const result = Reflect.getMetadata(key, obj);\n if (result === undefined) {\n return undefined;\n }\n return result as MetadataType<T>;\n};\n\nexport const defineMetadata = <T extends SourceType>(key: string, metadata: MetadataType<T>, obj: object) => {\n if (Reflect.defineMetadata === undefined) {\n throw new Error('Please import \"reflect-metadata\"');\n }\n Reflect.defineMetadata(key, metadata, obj);\n};\n","import type { Lifetime } from './constants';\nimport type { IServiceModule, IServiceProvider, IServiceScope } from './interfaces';\n\nexport type SourceType = object;\n\nexport type AbstractNewable<T> = abstract new (...args: any[]) => T;\nexport type Newable<T> = new (...args: any[]) => T;\n\nexport type ServiceIdentifier<T extends SourceType> = { prototype: T; name: string }; //AbstractNewable<T>;\nexport type ServiceImplementation<T extends SourceType> = Newable<T>;\n\nexport type InstanceFactory<T extends SourceType> = (x: IServiceScope & IServiceProvider) => T;\n\nexport type ServiceModuleType = Newable<IServiceModule>;\n\nexport type ServiceDescriptorFactory<T extends SourceType> = {\n implementation: ServiceIdentifier<T>;\n factory: InstanceFactory<T>;\n lifetime: Lifetime;\n};\nexport type ServiceDescriptorConcrete<T extends SourceType> = {\n implementation: ServiceImplementation<T>;\n lifetime: Lifetime;\n};\n\nexport type ServiceDescriptor<T extends SourceType> = ServiceDescriptorConcrete<T> | ServiceDescriptorFactory<T>;\n// export type ServiceDescriptor<T extends SourceType> = {\n// implementation: ServiceImplementation<T>;\n// factory?: InstanceFactory<T>;\n// lifetime: Lifetime;\n// };\n\nexport type LifetimeBuilder = {\n singleton: () => LifetimeBuilder;\n scoped: () => LifetimeBuilder;\n transient: () => LifetimeBuilder;\n};\nexport type ServiceBuilder<T extends SourceType> = {\n to: {\n (implementation: ServiceImplementation<T>): LifetimeBuilder;\n (implementation: ServiceIdentifier<T>, factory: InstanceFactory<T>): LifetimeBuilder;\n };\n};\n\nexport type MetadataType<T extends SourceType> = Record<string | symbol, ServiceIdentifier<T>>;\n\nexport const ResolveMultipleMode = {\n Error: 'ERROR',\n LastRegistered: 'LAST_REGISTERED',\n} as const;\nexport type ResolveMultipleMode = (typeof ResolveMultipleMode)[keyof typeof ResolveMultipleMode];\n\nexport const DefaultServiceCollectionOptions: ServiceCollectionOptions = {\n registrationMode: ResolveMultipleMode.Error,\n};\n\nexport type ServiceCollectionOptions = {\n registrationMode: ResolveMultipleMode;\n};\n","import type { ServiceIdentifier } from './types';\n\nexport abstract class ServiceError extends Error {\n constructor(message: string) {\n super(message);\n }\n}\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}`);\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}`);\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class ServiceCreationError<T extends object> extends ServiceError {\n name = 'ServiceCreationError';\n constructor(identifier: ServiceIdentifier<T>, public readonly innerError: any) {\n super(`Error creating service: ${identifier}`);\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","import { log } from './debug';\nimport { DesignDependenciesKey, Lifetime } from './constants';\nimport type { IDisposable, IServiceCollection} from './interfaces';\nimport { IServiceScope, IServiceProvider} from './interfaces';\nimport { getMetadata } from './metadata';\nimport type { ServiceIdentifier, ServiceDescriptor, ServiceImplementation, SourceType} from './types';\nimport { ResolveMultipleMode } from './types';\nimport { SelfDependencyError, MultipleRegistrationError, UnregisteredServiceError, ServiceCreationError } from './errors';\n\ntype Id<T extends SourceType> = ServiceIdentifier<T> | ServiceImplementation<T>;\n\ntype ResolveMap<T extends SourceType> = Map<ServiceIdentifier<T>, Map<Id<T>, T>>;\n\nconst createResolveMap = <T extends SourceType>(): ResolveMap<T> => new Map<ServiceIdentifier<T>, Map<ServiceImplementation<T>, T>>();\n\nexport class ServiceProvider implements IServiceProvider, IServiceScope {\n private scoped = createResolveMap();\n private created: IDisposable[] = [];\n\n constructor(\n private services: IServiceCollection,\n private singletons = createResolveMap(),\n ) {}\n \n public get Services(): IServiceCollection {\n return this.services;\n }\n\n [Symbol.dispose]() {\n this.created.forEach(x => x[Symbol.dispose]());\n }\n\n private resolveFrom<T extends SourceType>(\n identifier: ServiceIdentifier<T>,\n descriptor: ServiceDescriptor<T>,\n lifetimeMap: ResolveMap<T>,\n currentResolve: ResolveMap<T>\n ): T {\n let resolvedInstances = lifetimeMap.get(identifier);\n if (resolvedInstances === undefined) {\n resolvedInstances = new Map();\n lifetimeMap.set(identifier, resolvedInstances);\n }\n\n let instance = resolvedInstances.get(descriptor.implementation);\n if (instance === undefined) {\n instance = this.createInstance(descriptor, currentResolve);\n resolvedInstances.set(descriptor.implementation, instance);\n this.setDependencies<T>(descriptor.implementation, instance, currentResolve);\n }\n return instance;\n }\n\n private resolveInternal<T extends SourceType>(\n identifier: ServiceIdentifier<T>,\n descriptor: ServiceDescriptor<T>,\n currentResolve: ResolveMap<T>,\n ): T {\n const mapping: Partial<Record<Lifetime, ResolveMap<any>>> = {\n [Lifetime.Singleton]: this.singletons,\n [Lifetime.Scoped]: this.scoped,\n [Lifetime.Resolve]: currentResolve,\n };\n const sourceMap = mapping[descriptor.lifetime];\n if (sourceMap === undefined) {\n const instance = this.createInstance(descriptor, currentResolve);\n this.setDependencies<T>(descriptor.implementation, instance, currentResolve);\n return instance;\n }\n return this.resolveFrom(identifier, descriptor, sourceMap, currentResolve);\n }\n\n public resolveAll<T extends SourceType>(\n identifier: ServiceIdentifier<T>,\n currentResolve = createResolveMap<T>(),\n ): T[] {\n const descriptors = this.services.get(identifier);\n return descriptors.map(descriptor => this.resolveInternal<T>(identifier, descriptor, currentResolve));\n }\n\n public resolve<T extends SourceType>(\n identifier: ServiceIdentifier<T>,\n currentResolve = createResolveMap<T>(),\n ): T {\n if (identifier.prototype === IServiceScope.prototype || identifier.prototype === IServiceProvider.prototype) {\n return this as unknown as T;\n }\n\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 this.resolveInternal(identifier, descriptor, currentResolve);\n }\n\n private createInstance<T extends SourceType>(descriptor: ServiceDescriptor<T>, currentResolve: ResolveMap<T>): T {\n let instance: T;\n if ('factory' in descriptor) {\n const factory = descriptor.factory;\n const resolve = (identifier: ServiceIdentifier<any>) => this.resolve(identifier, currentResolve);\n const resolveAll = (identifier: ServiceIdentifier<any>) => this.resolveAll(identifier, currentResolve);\n const createScope = this.createScope.bind(this);\n\n // proxy requests to keep current resolved types\n instance = factory({\n resolve,\n resolveAll,\n createScope,\n get Services() { return this.Services; },\n });\n }\n else {\n try {\n instance = new descriptor.implementation();\n }\n catch (err) {\n throw new ServiceCreationError(descriptor.implementation, err);\n }\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(): IServiceProvider & IDisposable {\n return new ServiceProvider(this.services.clone(), this.singletons);\n }\n\n private setDependencies<T extends SourceType>(\n type: Id<T>,\n instance: T,\n currentResolve: ResolveMap<T>,\n ): T {\n const dependencies = getMetadata<T>(DesignDependenciesKey, type) ?? {};\n log('Dependencies', type.name, dependencies);\n for (const [key, identifier] of Object.entries(dependencies)) {\n if (identifier !== type) {\n log('Resolving', identifier, 'for', type.name);\n const dep = this.resolve(identifier, currentResolve);\n (instance as Record<string, unknown>)[key] = dep;\n } else {\n throw new SelfDependencyError();\n }\n }\n return instance;\n }\n}\n","import { ServiceProvider } from './ServiceProvider';\nimport type { SourceType, InstanceFactory, ServiceBuilder, ServiceDescriptor, ServiceIdentifier, ServiceImplementation, Newable, ServiceCollectionOptions } from './types';\nimport type { IServiceCollection, IServiceModule, IServiceProvider } from './interfaces';\nimport { Lifetime } from './constants';\nimport { log } from './debug';\n\nexport class ServiceCollection implements IServiceCollection {\n constructor(public readonly options: ServiceCollectionOptions, private readonly services = new Map<ServiceIdentifier<any>, ServiceDescriptor<any>[]>()) {\n }\n \n public registerModules(modules: Newable<IServiceModule>[]): void {\n modules.forEach(x => {\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 register<T extends SourceType>(identifier: ServiceIdentifier<T>): ServiceBuilder<T> {\n return {\n // to: (implementation: ServiceImplementation<T>, func?: InstanceFactory<T>) => {\n to: (implementation: ServiceImplementation<T> | ServiceIdentifier<T>, factory?: InstanceFactory<T>) => {\n const descriptor: ServiceDescriptor<T>= (factory === undefined) ? { implementation: implementation as ServiceImplementation<T>, lifetime: Lifetime.Resolve } : { implementation, factory, lifetime: Lifetime.Resolve };\n this.addService(identifier, descriptor);\n const builder = {\n singleton: () => { descriptor.lifetime = Lifetime.Singleton; return builder; },\n scoped: () => { descriptor.lifetime = Lifetime.Scoped; return builder; },\n transient: () => { descriptor.lifetime = Lifetime.Transient; return builder; },\n };\n return builder;\n },\n };\n }\n\n private addService<T extends SourceType>(identifier: ServiceIdentifier<T>, descriptor: ServiceDescriptor<T>) {\n log('Adding service', { identifier, 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(): 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.options, clonedMap);\n }\n\n public buildProvider(): IServiceProvider {\n const cloned = this.clone(); \n return new ServiceProvider(cloned);\n }\n}\n","import type { IServiceCollection } from './interfaces';\nimport { ServiceCollection } from './ServiceCollection';\nimport type { ServiceCollectionOptions } from './types';\nimport { DefaultServiceCollectionOptions } from './types';\n\nconst mergeOptions = (options: Partial<ServiceCollectionOptions> | undefined): ServiceCollectionOptions => ({\n ...DefaultServiceCollectionOptions,\n ...options,\n});\n\nexport const createServiceCollection = (options?: Partial<ServiceCollectionOptions>): IServiceCollection => new ServiceCollection(mergeOptions(options)) as IServiceCollection;\n","import { DesignDependenciesKey } from './constants';\nimport type { ServiceIdentifier, SourceType } from './types';\nimport { defineMetadata, getMetadata } from './metadata';\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\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"],"names":["__defProp","__defNormalProp","__publicField"],"mappings":";;;;AACA,IAAIA,WAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAIC,iBAAe,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,KAAK,GAAG,IAAI,GAAG,GAAGD,WAAS,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAChK,IAAIE,eAAa,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,KAAKD,iBAAe,CAAC,GAAG,EAA4B,GAAG,GAAG,EAAE,CAAM,EAAE,KAAK,CAAC,CAAC;AAC/G,MAAM,WAAW,CAAC;AAClB,EAAE,WAAW,GAAG;AAChB,IAAIC,eAAa,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;AAC5C,GAAG;AACH,EAAE,MAAM,GAAG;AACX,IAAI,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;AAC1B,GAAG;AACH,EAAE,OAAO,GAAG;AACZ,IAAI,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;AAC3B,GAAG;AACH,EAAE,GAAG,CAAC,OAAO,EAAE,GAAG,cAAc,EAAE;AAClC,IAAI,IAAI,IAAI,CAAC,SAAS,EAAE;AACxB,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,cAAc,CAAC,CAAC;AAC9C,KAAK;AACL,GAAG;AACH,CAAC;AACD,MAAM,MAAM,GAAG,IAAI,WAAW,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