@shellicar/core-di 1.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -0
- package/dist/index.d.mts +64 -83
- package/dist/index.d.ts +64 -83
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +16 -10
package/README.md
CHANGED
|
@@ -2,6 +2,32 @@
|
|
|
2
2
|
|
|
3
3
|
A basic dependency injection library.
|
|
4
4
|
|
|
5
|
+
<!-- BEGIN_ECOSYSTEM -->
|
|
6
|
+
|
|
7
|
+
## @shellicar TypeScript Ecosystem
|
|
8
|
+
|
|
9
|
+
### Core Libraries
|
|
10
|
+
|
|
11
|
+
- [`@shellicar/core-config`](https://github.com/shellicar/core-config) - A library for securely handling sensitive configuration values like connection strings, URLs, and secrets.
|
|
12
|
+
- [`@shellicar/core-di`](https://github.com/shellicar/core-di) - A basic dependency injection library.
|
|
13
|
+
- [`@shellicar/core-foundation`](https://github.com/shellicar/core-foundation) - A comprehensive starter repository.
|
|
14
|
+
|
|
15
|
+
### Build Tools
|
|
16
|
+
|
|
17
|
+
- [`@shellicar/build-version`](https://github.com/shellicar/build-version) - Build plugin that calculates and exposes version information through a virtual module import.
|
|
18
|
+
- [`@shellicar/build-graphql`](https://github.com/shellicar/build-graphql) - Build plugin that loads GraphQL files and makes them available through a virtual module import.
|
|
19
|
+
|
|
20
|
+
### Framework Adapters
|
|
21
|
+
|
|
22
|
+
- [`@shellicar/svelte-adapter-azure-functions`](https://github.com/shellicar/svelte-adapter-azure-functions) - A [SvelteKit adapter](https://kit.svelte.dev/docs/adapters) that builds your app into an Azure Function.
|
|
23
|
+
|
|
24
|
+
### Logging & Monitoring
|
|
25
|
+
|
|
26
|
+
- [`@shellicar/winston-azure-application-insights`](https://github.com/shellicar/winston-azure-application-insights) - An [Azure Application Insights](https://azure.microsoft.com/en-us/services/application-insights/) transport for [Winston](https://github.com/winstonjs/winston) logging library.
|
|
27
|
+
- [`@shellicar/pino-applicationinsights-transport`](https://github.com/shellicar/pino-applicationinsights-transport) - [Azure Application Insights](https://azure.microsoft.com/en-us/services/application-insights) transport for [pino](https://github.com/pinojs/pino)
|
|
28
|
+
|
|
29
|
+
<!-- END_ECOSYSTEM -->
|
|
30
|
+
|
|
5
31
|
## Motivation
|
|
6
32
|
|
|
7
33
|
Coming from .NET I am used to DI frameworks/libraries such as `Autofac`, `Ninject`, `StructureMap`, `Unity`, and Microsoft's own `DependencyInjection`.
|
|
@@ -15,6 +41,7 @@ With TypeScript 5.0 generally available with non-experimental decorators, most D
|
|
|
15
41
|
My set of features is simple, based on my current usage
|
|
16
42
|
|
|
17
43
|
* Type-safe registration.
|
|
44
|
+
|
|
18
45
|
```ts
|
|
19
46
|
const services = createServiceCollection();
|
|
20
47
|
abstract class IAbstract { abstract method(): void; }
|
|
@@ -22,13 +49,17 @@ abstract class Concrete {}
|
|
|
22
49
|
services.register(IAbstract).to(Concrete);
|
|
23
50
|
// ^ Error
|
|
24
51
|
```
|
|
52
|
+
|
|
25
53
|
* Type-safe resolution.
|
|
54
|
+
|
|
26
55
|
```ts
|
|
27
56
|
const provider = services.buildProvider();
|
|
28
57
|
const svc = provider.resolve(IMyService);
|
|
29
58
|
// ^ IMyService
|
|
30
59
|
```
|
|
60
|
+
|
|
31
61
|
* Provide factory methods for instantiating classes.
|
|
62
|
+
|
|
32
63
|
```ts
|
|
33
64
|
services.register(Redis).to(Redis, x => {
|
|
34
65
|
const options = x.resolve(IRedisOptions);
|
|
@@ -38,13 +69,16 @@ services.register(Redis).to(Redis, x => {
|
|
|
38
69
|
});
|
|
39
70
|
});
|
|
40
71
|
```
|
|
72
|
+
|
|
41
73
|
* Use property injection with decorators for simple dependency definition.
|
|
74
|
+
|
|
42
75
|
```ts
|
|
43
76
|
abstract class IDependency {}
|
|
44
77
|
class Service implements IService {
|
|
45
78
|
@dependsOn(IDependency) private readonly dependency!: IDependency;
|
|
46
79
|
}
|
|
47
80
|
```
|
|
81
|
+
|
|
48
82
|
* Provide multiple implementations for identifiers and provide a `resolveAll` method.
|
|
49
83
|
* Define instance lifetime with simple builder pattern.
|
|
50
84
|
|
|
@@ -53,6 +87,7 @@ services.register(IAbstract).to(Concrete).singleton();
|
|
|
53
87
|
```
|
|
54
88
|
|
|
55
89
|
* Create scopes to allow "per-request" lifetimes.
|
|
90
|
+
|
|
56
91
|
```ts
|
|
57
92
|
const services = createServiceCollection();
|
|
58
93
|
const provider = services.buildProvider();
|
|
@@ -60,11 +95,22 @@ using scope = provider.createScope();
|
|
|
60
95
|
```
|
|
61
96
|
|
|
62
97
|
* Register classes during a scope
|
|
98
|
+
|
|
63
99
|
```ts
|
|
64
100
|
using scope = provider.createScope();
|
|
65
101
|
scope.Services.register(IContext).to(Context);
|
|
66
102
|
```
|
|
103
|
+
|
|
104
|
+
* Multiple registrations
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
services.register(IAbstract1, IAbstract2).to(Concrete).singleton();
|
|
108
|
+
const provider = services.buildProvider();
|
|
109
|
+
provider.resolve(IAbstract1) === provider.resolve(IAbstract2);
|
|
110
|
+
```
|
|
111
|
+
|
|
67
112
|
* Override registrations (e.g.: for testing)
|
|
113
|
+
|
|
68
114
|
```ts
|
|
69
115
|
import { ok } from 'node:assert/strict';
|
|
70
116
|
const services = createServiceCollection({ registrationMode: ResolveMultipleMode.LastRegistered });
|
|
@@ -75,7 +121,19 @@ const provider = services.buildProvider();
|
|
|
75
121
|
const options = provider.resolve(IOptions);
|
|
76
122
|
ok(options instanceof MockOptions);
|
|
77
123
|
```
|
|
124
|
+
|
|
125
|
+
* Override lifetimes (e.g.: for testing)
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
const services = createServiceCollection({ logLevel: LogLevel.Debug });
|
|
129
|
+
services.register(IAbstract).to(Concrete).singleton();
|
|
130
|
+
const provider = services.buildProvider();
|
|
131
|
+
sp.Services.overrideLifetime(IAbstract, Lifetime.Transient);
|
|
132
|
+
sp.resolve(IAbstract) !== sp.resolve(IAbstract);
|
|
133
|
+
```
|
|
134
|
+
|
|
78
135
|
* Logging options
|
|
136
|
+
|
|
79
137
|
```ts
|
|
80
138
|
class CustomLogger extends ILogger {
|
|
81
139
|
public override debug(message?: any, ...optionalParams: any[]): void {
|
|
@@ -87,7 +145,9 @@ const services1 = createServiceCollection({ logger: new CustomLogger() });
|
|
|
87
145
|
// Override default log level
|
|
88
146
|
const services2 = createServiceCollection({ logLevel: LogLevel.Debug });
|
|
89
147
|
```
|
|
148
|
+
|
|
90
149
|
* Service modules
|
|
150
|
+
|
|
91
151
|
```ts
|
|
92
152
|
class IAbstract {}
|
|
93
153
|
class Concrete extends IAbstract {}
|
package/dist/index.d.mts
CHANGED
|
@@ -4,12 +4,23 @@ declare enum Lifetime {
|
|
|
4
4
|
Scoped = "SCOPED",
|
|
5
5
|
Singleton = "SINGLETON"
|
|
6
6
|
}
|
|
7
|
+
declare enum LogLevel {
|
|
8
|
+
Debug = 0,
|
|
9
|
+
Info = 1,
|
|
10
|
+
Warn = 2,
|
|
11
|
+
Error = 3,
|
|
12
|
+
None = 4
|
|
13
|
+
}
|
|
14
|
+
declare enum ResolveMultipleMode {
|
|
15
|
+
Error = "ERROR",
|
|
16
|
+
LastRegistered = "LAST_REGISTERED"
|
|
17
|
+
}
|
|
7
18
|
|
|
8
19
|
declare abstract class ILogger {
|
|
9
|
-
debug(
|
|
10
|
-
info(
|
|
11
|
-
error(
|
|
12
|
-
warn(
|
|
20
|
+
debug(_message?: any, ..._optionalParams: any[]): void;
|
|
21
|
+
info(_message?: any, ..._optionalParams: any[]): void;
|
|
22
|
+
error(_message?: any, ..._optionalParams: any[]): void;
|
|
23
|
+
warn(_message?: any, ..._optionalParams: any[]): void;
|
|
13
24
|
}
|
|
14
25
|
|
|
15
26
|
type SourceType = object;
|
|
@@ -20,43 +31,14 @@ type ServiceIdentifier<T extends SourceType> = {
|
|
|
20
31
|
name: string;
|
|
21
32
|
};
|
|
22
33
|
type ServiceImplementation<T extends SourceType> = Newable<T>;
|
|
23
|
-
type InstanceFactory<T extends SourceType> = (x:
|
|
34
|
+
type InstanceFactory<T extends SourceType> = (x: IResolutionScope) => T;
|
|
24
35
|
type ServiceModuleType = Newable<IServiceModule>;
|
|
25
|
-
type
|
|
26
|
-
implementation:
|
|
27
|
-
factory: InstanceFactory<T>;
|
|
36
|
+
type ServiceDescriptor<T extends SourceType> = {
|
|
37
|
+
readonly implementation: ServiceImplementation<T>;
|
|
28
38
|
lifetime: Lifetime;
|
|
29
|
-
|
|
30
|
-
type ServiceDescriptorConcrete<T extends SourceType> = {
|
|
31
|
-
implementation: ServiceImplementation<T>;
|
|
32
|
-
lifetime: Lifetime;
|
|
33
|
-
};
|
|
34
|
-
type ServiceDescriptor<T extends SourceType> = ServiceDescriptorConcrete<T> | ServiceDescriptorFactory<T>;
|
|
35
|
-
type LifetimeBuilder = {
|
|
36
|
-
singleton: () => LifetimeBuilder;
|
|
37
|
-
scoped: () => LifetimeBuilder;
|
|
38
|
-
transient: () => LifetimeBuilder;
|
|
39
|
-
};
|
|
40
|
-
type ServiceBuilder<T extends SourceType> = {
|
|
41
|
-
to: {
|
|
42
|
-
(implementation: ServiceImplementation<T>): LifetimeBuilder;
|
|
43
|
-
(implementation: ServiceIdentifier<T>, factory: InstanceFactory<T>): LifetimeBuilder;
|
|
44
|
-
};
|
|
39
|
+
createInstance(context: IResolutionScope): T;
|
|
45
40
|
};
|
|
46
41
|
type MetadataType<T extends SourceType> = Record<string | symbol, ServiceIdentifier<T>>;
|
|
47
|
-
declare const ResolveMultipleMode: {
|
|
48
|
-
readonly Error: "ERROR";
|
|
49
|
-
readonly LastRegistered: "LAST_REGISTERED";
|
|
50
|
-
};
|
|
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
|
-
}
|
|
59
|
-
declare const DefaultServiceCollectionOptions: ServiceCollectionOptions;
|
|
60
42
|
type ServiceCollectionOptions = {
|
|
61
43
|
/**
|
|
62
44
|
* Whether calling `resolve` when there are multiple registrations
|
|
@@ -75,6 +57,12 @@ type ServiceCollectionOptions = {
|
|
|
75
57
|
*/
|
|
76
58
|
logger?: ILogger;
|
|
77
59
|
};
|
|
60
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
61
|
+
type EnsureObject<T> = T extends object ? T : never;
|
|
62
|
+
type ServiceBuilderOptions<T extends SourceType> = {
|
|
63
|
+
(implementation: ServiceImplementation<T>): ILifetimeBuilder;
|
|
64
|
+
(implementation: ServiceImplementation<T>, factory: InstanceFactory<T>): ILifetimeBuilder;
|
|
65
|
+
};
|
|
78
66
|
|
|
79
67
|
declare abstract class IDisposable {
|
|
80
68
|
abstract [Symbol.dispose](): void;
|
|
@@ -82,31 +70,52 @@ declare abstract class IDisposable {
|
|
|
82
70
|
declare abstract class IServiceModule {
|
|
83
71
|
abstract registerServices(services: IServiceCollection): void;
|
|
84
72
|
}
|
|
85
|
-
declare abstract class
|
|
73
|
+
declare abstract class IResolutionScope {
|
|
86
74
|
/**
|
|
87
|
-
* Resolves a single implementation for the identifier.
|
|
88
|
-
*
|
|
89
|
-
*
|
|
75
|
+
* Resolves a single implementation for the given identifier.
|
|
76
|
+
* @template T The type of service to resolve
|
|
77
|
+
* @param identifier The service identifier
|
|
78
|
+
* @returns The resolved instance
|
|
79
|
+
* @throws {MultipleRegistrationError} When multiple implementations exist (unless {@link ServiceCollectionOptions.registrationMode} is set to {@link ResolveMultipleMode.LastRegistered}).
|
|
80
|
+
* @throws {UnregisteredServiceError} When no implementation exists
|
|
90
81
|
*/
|
|
91
82
|
abstract resolve<T extends SourceType>(identifier: ServiceIdentifier<T>): T;
|
|
92
83
|
/**
|
|
93
|
-
* Resolves all implementations for the identifier.
|
|
84
|
+
* Resolves all implementations for the given identifier.
|
|
85
|
+
* @template T The type of service to resolve
|
|
86
|
+
* @param identifier The service identifier
|
|
87
|
+
* @returns Array of resolved instances
|
|
94
88
|
*/
|
|
95
89
|
abstract resolveAll<T extends SourceType>(identifier: ServiceIdentifier<T>): T[];
|
|
96
90
|
}
|
|
97
|
-
declare abstract class
|
|
98
|
-
abstract
|
|
99
|
-
abstract
|
|
91
|
+
declare abstract class IScopedProvider extends IResolutionScope implements IDisposable {
|
|
92
|
+
abstract readonly Services: IServiceCollection;
|
|
93
|
+
abstract [Symbol.dispose](): void;
|
|
94
|
+
}
|
|
95
|
+
declare abstract class IServiceProvider extends IResolutionScope {
|
|
96
|
+
abstract readonly Services: IServiceCollection;
|
|
97
|
+
abstract createScope(): IScopedProvider;
|
|
100
98
|
}
|
|
101
99
|
declare abstract class IServiceCollection {
|
|
102
100
|
abstract readonly options: ServiceCollectionOptions;
|
|
103
|
-
abstract get<T extends SourceType>(
|
|
104
|
-
abstract register<
|
|
101
|
+
abstract get<T extends SourceType>(identifier: ServiceIdentifier<T>): ServiceDescriptor<T>[];
|
|
102
|
+
abstract register<Types extends SourceType[]>(...identifiers: {
|
|
103
|
+
[K in keyof Types]: ServiceIdentifier<Types[K]>;
|
|
104
|
+
}): IServiceBuilder<EnsureObject<UnionToIntersection<Types[number]>>>;
|
|
105
105
|
abstract registerModules(...modules: ServiceModuleType[]): void;
|
|
106
|
+
abstract overrideLifetime<T extends SourceType>(identifier: ServiceIdentifier<T>, lifetime: Lifetime): void;
|
|
106
107
|
abstract buildProvider(): IServiceProvider;
|
|
107
108
|
abstract clone(): IServiceCollection;
|
|
108
109
|
abstract clone(scoped: true): IServiceCollection;
|
|
109
110
|
}
|
|
111
|
+
declare abstract class ILifetimeBuilder {
|
|
112
|
+
abstract singleton(): ILifetimeBuilder;
|
|
113
|
+
abstract scoped(): ILifetimeBuilder;
|
|
114
|
+
abstract transient(): ILifetimeBuilder;
|
|
115
|
+
}
|
|
116
|
+
declare abstract class IServiceBuilder<T extends SourceType> {
|
|
117
|
+
abstract to: ServiceBuilderOptions<T>;
|
|
118
|
+
}
|
|
110
119
|
|
|
111
120
|
/**
|
|
112
121
|
* Creates a service collection with the (optionally) provided options
|
|
@@ -116,11 +125,14 @@ declare abstract class IServiceCollection {
|
|
|
116
125
|
declare const createServiceCollection: (options?: Partial<ServiceCollectionOptions>) => IServiceCollection;
|
|
117
126
|
|
|
118
127
|
/**
|
|
119
|
-
* declares a dependency, use on a class field
|
|
128
|
+
* declares a dependency, use on a class field.
|
|
129
|
+
* Can also depend on {@link IServiceProvider}, {@link IResolutionScope}, or {@link IScopedProvider}.
|
|
120
130
|
* @param identifier the identifier to depend on, i.e. the interface
|
|
121
131
|
*/
|
|
122
132
|
declare const dependsOn: <T extends SourceType>(identifier: ServiceIdentifier<T>) => (value: undefined, ctx: ClassFieldDecoratorContext) => (this: object, initialValue: any) => any;
|
|
123
133
|
|
|
134
|
+
declare const DefaultServiceCollectionOptions: ServiceCollectionOptions;
|
|
135
|
+
|
|
124
136
|
declare abstract class ServiceError extends Error {
|
|
125
137
|
}
|
|
126
138
|
declare class UnregisteredServiceError<T extends object> extends ServiceError {
|
|
@@ -140,40 +152,9 @@ declare class SelfDependencyError extends ServiceError {
|
|
|
140
152
|
name: string;
|
|
141
153
|
constructor();
|
|
142
154
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
readonly options: ServiceCollectionOptions;
|
|
147
|
-
private readonly isScoped;
|
|
148
|
-
private readonly services;
|
|
149
|
-
constructor(logger: ILogger, options: ServiceCollectionOptions, isScoped: boolean, services?: Map<ServiceIdentifier<any>, ServiceDescriptor<any>[]>);
|
|
150
|
-
registerModules(...modules: ServiceModuleType[]): void;
|
|
151
|
-
get<T extends SourceType>(key: ServiceIdentifier<T>): ServiceDescriptor<T>[];
|
|
152
|
-
register<T extends SourceType>(identifier: ServiceIdentifier<T>): ServiceBuilder<T>;
|
|
153
|
-
private addService;
|
|
154
|
-
clone(): IServiceCollection;
|
|
155
|
-
clone(scoped: true): IServiceCollection;
|
|
156
|
-
buildProvider(): IServiceProvider;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
type Id<T extends SourceType> = ServiceIdentifier<T> | ServiceImplementation<T>;
|
|
160
|
-
type ResolveMap<T extends SourceType> = Map<ServiceIdentifier<T>, Map<Id<T>, T>>;
|
|
161
|
-
declare class ServiceProvider implements IServiceProvider, IServiceScope {
|
|
162
|
-
private readonly logger;
|
|
163
|
-
private readonly services;
|
|
164
|
-
private readonly singletons;
|
|
165
|
-
private scoped;
|
|
166
|
-
private created;
|
|
167
|
-
constructor(logger: ILogger, services: IServiceCollection, singletons?: ResolveMap<object>);
|
|
168
|
-
get Services(): IServiceCollection;
|
|
169
|
-
[Symbol.dispose](): void;
|
|
170
|
-
private resolveFrom;
|
|
171
|
-
private resolveInternal;
|
|
172
|
-
resolveAll<T extends SourceType>(identifier: ServiceIdentifier<T>, currentResolve?: ResolveMap<T>): T[];
|
|
173
|
-
resolve<T extends SourceType>(identifier: ServiceIdentifier<T>, currentResolve?: ResolveMap<T>): T;
|
|
174
|
-
private createInstance;
|
|
175
|
-
createScope(): IServiceProvider & IDisposable;
|
|
176
|
-
private setDependencies;
|
|
155
|
+
declare class ScopedSingletonRegistrationError extends ServiceError {
|
|
156
|
+
name: string;
|
|
157
|
+
constructor();
|
|
177
158
|
}
|
|
178
159
|
|
|
179
|
-
export { type AbstractNewable, DefaultServiceCollectionOptions, IDisposable, ILogger, IServiceCollection, IServiceModule, IServiceProvider,
|
|
160
|
+
export { type AbstractNewable, DefaultServiceCollectionOptions, IDisposable, ILifetimeBuilder, ILogger, IResolutionScope, IScopedProvider, IServiceBuilder, IServiceCollection, IServiceModule, IServiceProvider, type InstanceFactory, Lifetime, LogLevel, type MetadataType, MultipleRegistrationError, type Newable, ResolveMultipleMode, ScopedSingletonRegistrationError, SelfDependencyError, type ServiceCollectionOptions, ServiceCreationError, type ServiceDescriptor, ServiceError, type ServiceIdentifier, type ServiceImplementation, type ServiceModuleType, type SourceType, UnregisteredServiceError, createServiceCollection, dependsOn };
|
package/dist/index.d.ts
CHANGED
|
@@ -4,12 +4,23 @@ declare enum Lifetime {
|
|
|
4
4
|
Scoped = "SCOPED",
|
|
5
5
|
Singleton = "SINGLETON"
|
|
6
6
|
}
|
|
7
|
+
declare enum LogLevel {
|
|
8
|
+
Debug = 0,
|
|
9
|
+
Info = 1,
|
|
10
|
+
Warn = 2,
|
|
11
|
+
Error = 3,
|
|
12
|
+
None = 4
|
|
13
|
+
}
|
|
14
|
+
declare enum ResolveMultipleMode {
|
|
15
|
+
Error = "ERROR",
|
|
16
|
+
LastRegistered = "LAST_REGISTERED"
|
|
17
|
+
}
|
|
7
18
|
|
|
8
19
|
declare abstract class ILogger {
|
|
9
|
-
debug(
|
|
10
|
-
info(
|
|
11
|
-
error(
|
|
12
|
-
warn(
|
|
20
|
+
debug(_message?: any, ..._optionalParams: any[]): void;
|
|
21
|
+
info(_message?: any, ..._optionalParams: any[]): void;
|
|
22
|
+
error(_message?: any, ..._optionalParams: any[]): void;
|
|
23
|
+
warn(_message?: any, ..._optionalParams: any[]): void;
|
|
13
24
|
}
|
|
14
25
|
|
|
15
26
|
type SourceType = object;
|
|
@@ -20,43 +31,14 @@ type ServiceIdentifier<T extends SourceType> = {
|
|
|
20
31
|
name: string;
|
|
21
32
|
};
|
|
22
33
|
type ServiceImplementation<T extends SourceType> = Newable<T>;
|
|
23
|
-
type InstanceFactory<T extends SourceType> = (x:
|
|
34
|
+
type InstanceFactory<T extends SourceType> = (x: IResolutionScope) => T;
|
|
24
35
|
type ServiceModuleType = Newable<IServiceModule>;
|
|
25
|
-
type
|
|
26
|
-
implementation:
|
|
27
|
-
factory: InstanceFactory<T>;
|
|
36
|
+
type ServiceDescriptor<T extends SourceType> = {
|
|
37
|
+
readonly implementation: ServiceImplementation<T>;
|
|
28
38
|
lifetime: Lifetime;
|
|
29
|
-
|
|
30
|
-
type ServiceDescriptorConcrete<T extends SourceType> = {
|
|
31
|
-
implementation: ServiceImplementation<T>;
|
|
32
|
-
lifetime: Lifetime;
|
|
33
|
-
};
|
|
34
|
-
type ServiceDescriptor<T extends SourceType> = ServiceDescriptorConcrete<T> | ServiceDescriptorFactory<T>;
|
|
35
|
-
type LifetimeBuilder = {
|
|
36
|
-
singleton: () => LifetimeBuilder;
|
|
37
|
-
scoped: () => LifetimeBuilder;
|
|
38
|
-
transient: () => LifetimeBuilder;
|
|
39
|
-
};
|
|
40
|
-
type ServiceBuilder<T extends SourceType> = {
|
|
41
|
-
to: {
|
|
42
|
-
(implementation: ServiceImplementation<T>): LifetimeBuilder;
|
|
43
|
-
(implementation: ServiceIdentifier<T>, factory: InstanceFactory<T>): LifetimeBuilder;
|
|
44
|
-
};
|
|
39
|
+
createInstance(context: IResolutionScope): T;
|
|
45
40
|
};
|
|
46
41
|
type MetadataType<T extends SourceType> = Record<string | symbol, ServiceIdentifier<T>>;
|
|
47
|
-
declare const ResolveMultipleMode: {
|
|
48
|
-
readonly Error: "ERROR";
|
|
49
|
-
readonly LastRegistered: "LAST_REGISTERED";
|
|
50
|
-
};
|
|
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
|
-
}
|
|
59
|
-
declare const DefaultServiceCollectionOptions: ServiceCollectionOptions;
|
|
60
42
|
type ServiceCollectionOptions = {
|
|
61
43
|
/**
|
|
62
44
|
* Whether calling `resolve` when there are multiple registrations
|
|
@@ -75,6 +57,12 @@ type ServiceCollectionOptions = {
|
|
|
75
57
|
*/
|
|
76
58
|
logger?: ILogger;
|
|
77
59
|
};
|
|
60
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
61
|
+
type EnsureObject<T> = T extends object ? T : never;
|
|
62
|
+
type ServiceBuilderOptions<T extends SourceType> = {
|
|
63
|
+
(implementation: ServiceImplementation<T>): ILifetimeBuilder;
|
|
64
|
+
(implementation: ServiceImplementation<T>, factory: InstanceFactory<T>): ILifetimeBuilder;
|
|
65
|
+
};
|
|
78
66
|
|
|
79
67
|
declare abstract class IDisposable {
|
|
80
68
|
abstract [Symbol.dispose](): void;
|
|
@@ -82,31 +70,52 @@ declare abstract class IDisposable {
|
|
|
82
70
|
declare abstract class IServiceModule {
|
|
83
71
|
abstract registerServices(services: IServiceCollection): void;
|
|
84
72
|
}
|
|
85
|
-
declare abstract class
|
|
73
|
+
declare abstract class IResolutionScope {
|
|
86
74
|
/**
|
|
87
|
-
* Resolves a single implementation for the identifier.
|
|
88
|
-
*
|
|
89
|
-
*
|
|
75
|
+
* Resolves a single implementation for the given identifier.
|
|
76
|
+
* @template T The type of service to resolve
|
|
77
|
+
* @param identifier The service identifier
|
|
78
|
+
* @returns The resolved instance
|
|
79
|
+
* @throws {MultipleRegistrationError} When multiple implementations exist (unless {@link ServiceCollectionOptions.registrationMode} is set to {@link ResolveMultipleMode.LastRegistered}).
|
|
80
|
+
* @throws {UnregisteredServiceError} When no implementation exists
|
|
90
81
|
*/
|
|
91
82
|
abstract resolve<T extends SourceType>(identifier: ServiceIdentifier<T>): T;
|
|
92
83
|
/**
|
|
93
|
-
* Resolves all implementations for the identifier.
|
|
84
|
+
* Resolves all implementations for the given identifier.
|
|
85
|
+
* @template T The type of service to resolve
|
|
86
|
+
* @param identifier The service identifier
|
|
87
|
+
* @returns Array of resolved instances
|
|
94
88
|
*/
|
|
95
89
|
abstract resolveAll<T extends SourceType>(identifier: ServiceIdentifier<T>): T[];
|
|
96
90
|
}
|
|
97
|
-
declare abstract class
|
|
98
|
-
abstract
|
|
99
|
-
abstract
|
|
91
|
+
declare abstract class IScopedProvider extends IResolutionScope implements IDisposable {
|
|
92
|
+
abstract readonly Services: IServiceCollection;
|
|
93
|
+
abstract [Symbol.dispose](): void;
|
|
94
|
+
}
|
|
95
|
+
declare abstract class IServiceProvider extends IResolutionScope {
|
|
96
|
+
abstract readonly Services: IServiceCollection;
|
|
97
|
+
abstract createScope(): IScopedProvider;
|
|
100
98
|
}
|
|
101
99
|
declare abstract class IServiceCollection {
|
|
102
100
|
abstract readonly options: ServiceCollectionOptions;
|
|
103
|
-
abstract get<T extends SourceType>(
|
|
104
|
-
abstract register<
|
|
101
|
+
abstract get<T extends SourceType>(identifier: ServiceIdentifier<T>): ServiceDescriptor<T>[];
|
|
102
|
+
abstract register<Types extends SourceType[]>(...identifiers: {
|
|
103
|
+
[K in keyof Types]: ServiceIdentifier<Types[K]>;
|
|
104
|
+
}): IServiceBuilder<EnsureObject<UnionToIntersection<Types[number]>>>;
|
|
105
105
|
abstract registerModules(...modules: ServiceModuleType[]): void;
|
|
106
|
+
abstract overrideLifetime<T extends SourceType>(identifier: ServiceIdentifier<T>, lifetime: Lifetime): void;
|
|
106
107
|
abstract buildProvider(): IServiceProvider;
|
|
107
108
|
abstract clone(): IServiceCollection;
|
|
108
109
|
abstract clone(scoped: true): IServiceCollection;
|
|
109
110
|
}
|
|
111
|
+
declare abstract class ILifetimeBuilder {
|
|
112
|
+
abstract singleton(): ILifetimeBuilder;
|
|
113
|
+
abstract scoped(): ILifetimeBuilder;
|
|
114
|
+
abstract transient(): ILifetimeBuilder;
|
|
115
|
+
}
|
|
116
|
+
declare abstract class IServiceBuilder<T extends SourceType> {
|
|
117
|
+
abstract to: ServiceBuilderOptions<T>;
|
|
118
|
+
}
|
|
110
119
|
|
|
111
120
|
/**
|
|
112
121
|
* Creates a service collection with the (optionally) provided options
|
|
@@ -116,11 +125,14 @@ declare abstract class IServiceCollection {
|
|
|
116
125
|
declare const createServiceCollection: (options?: Partial<ServiceCollectionOptions>) => IServiceCollection;
|
|
117
126
|
|
|
118
127
|
/**
|
|
119
|
-
* declares a dependency, use on a class field
|
|
128
|
+
* declares a dependency, use on a class field.
|
|
129
|
+
* Can also depend on {@link IServiceProvider}, {@link IResolutionScope}, or {@link IScopedProvider}.
|
|
120
130
|
* @param identifier the identifier to depend on, i.e. the interface
|
|
121
131
|
*/
|
|
122
132
|
declare const dependsOn: <T extends SourceType>(identifier: ServiceIdentifier<T>) => (value: undefined, ctx: ClassFieldDecoratorContext) => (this: object, initialValue: any) => any;
|
|
123
133
|
|
|
134
|
+
declare const DefaultServiceCollectionOptions: ServiceCollectionOptions;
|
|
135
|
+
|
|
124
136
|
declare abstract class ServiceError extends Error {
|
|
125
137
|
}
|
|
126
138
|
declare class UnregisteredServiceError<T extends object> extends ServiceError {
|
|
@@ -140,40 +152,9 @@ declare class SelfDependencyError extends ServiceError {
|
|
|
140
152
|
name: string;
|
|
141
153
|
constructor();
|
|
142
154
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
readonly options: ServiceCollectionOptions;
|
|
147
|
-
private readonly isScoped;
|
|
148
|
-
private readonly services;
|
|
149
|
-
constructor(logger: ILogger, options: ServiceCollectionOptions, isScoped: boolean, services?: Map<ServiceIdentifier<any>, ServiceDescriptor<any>[]>);
|
|
150
|
-
registerModules(...modules: ServiceModuleType[]): void;
|
|
151
|
-
get<T extends SourceType>(key: ServiceIdentifier<T>): ServiceDescriptor<T>[];
|
|
152
|
-
register<T extends SourceType>(identifier: ServiceIdentifier<T>): ServiceBuilder<T>;
|
|
153
|
-
private addService;
|
|
154
|
-
clone(): IServiceCollection;
|
|
155
|
-
clone(scoped: true): IServiceCollection;
|
|
156
|
-
buildProvider(): IServiceProvider;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
type Id<T extends SourceType> = ServiceIdentifier<T> | ServiceImplementation<T>;
|
|
160
|
-
type ResolveMap<T extends SourceType> = Map<ServiceIdentifier<T>, Map<Id<T>, T>>;
|
|
161
|
-
declare class ServiceProvider implements IServiceProvider, IServiceScope {
|
|
162
|
-
private readonly logger;
|
|
163
|
-
private readonly services;
|
|
164
|
-
private readonly singletons;
|
|
165
|
-
private scoped;
|
|
166
|
-
private created;
|
|
167
|
-
constructor(logger: ILogger, services: IServiceCollection, singletons?: ResolveMap<object>);
|
|
168
|
-
get Services(): IServiceCollection;
|
|
169
|
-
[Symbol.dispose](): void;
|
|
170
|
-
private resolveFrom;
|
|
171
|
-
private resolveInternal;
|
|
172
|
-
resolveAll<T extends SourceType>(identifier: ServiceIdentifier<T>, currentResolve?: ResolveMap<T>): T[];
|
|
173
|
-
resolve<T extends SourceType>(identifier: ServiceIdentifier<T>, currentResolve?: ResolveMap<T>): T;
|
|
174
|
-
private createInstance;
|
|
175
|
-
createScope(): IServiceProvider & IDisposable;
|
|
176
|
-
private setDependencies;
|
|
155
|
+
declare class ScopedSingletonRegistrationError extends ServiceError {
|
|
156
|
+
name: string;
|
|
157
|
+
constructor();
|
|
177
158
|
}
|
|
178
159
|
|
|
179
|
-
export { type AbstractNewable, DefaultServiceCollectionOptions, IDisposable, ILogger, IServiceCollection, IServiceModule, IServiceProvider,
|
|
160
|
+
export { type AbstractNewable, DefaultServiceCollectionOptions, IDisposable, ILifetimeBuilder, ILogger, IResolutionScope, IScopedProvider, IServiceBuilder, IServiceCollection, IServiceModule, IServiceProvider, type InstanceFactory, Lifetime, LogLevel, type MetadataType, MultipleRegistrationError, type Newable, ResolveMultipleMode, ScopedSingletonRegistrationError, SelfDependencyError, type ServiceCollectionOptions, ServiceCreationError, type ServiceDescriptor, ServiceError, type ServiceIdentifier, type ServiceImplementation, type ServiceModuleType, type SourceType, UnregisteredServiceError, createServiceCollection, dependsOn };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";require("@abraham/reflection");var e=Object.defineProperty,t=(t,r)=>e(t,"name",{value:r,configurable:!0}),r=(e=>(e.Resolve="RESOLVE",e.Transient="TRANSIENT",e.Scoped="SCOPED",e.Singleton="SINGLETON",e))(r||{}),s=(e=>(e[e.Debug=0]="Debug",e[e.Info=1]="Info",e[e.Warn=2]="Warn",e[e.Error=3]="Error",e[e.None=4]="None",e))(s||{}),i=(e=>(e.Error="ERROR",e.LastRegistered="LAST_REGISTERED",e))(i||{}),o={registrationMode:"ERROR",logLevel:2},n=class extends Error{static{t(this,"ServiceError")}},c=class extends n{static{t(this,"UnregisteredServiceError")}name="UnregisteredServiceError";constructor(e){super(`Resolving service that has not been registered: ${e.name}`),Object.setPrototypeOf(this,new.target.prototype)}},l=class extends n{static{t(this,"MultipleRegistrationError")}name="MultipleRegistrationError";constructor(e){super(`Multiple services have been registered: ${e.name}`),Object.setPrototypeOf(this,new.target.prototype)}},a=class extends n{constructor(e,t){super(`Error creating service: ${e.name}`),this.innerError=t,Object.setPrototypeOf(this,new.target.prototype)}static{t(this,"ServiceCreationError")}name="ServiceCreationError"},p=class extends n{static{t(this,"SelfDependencyError")}name="SelfDependencyError";constructor(){super("Service depending on itself"),Object.setPrototypeOf(this,new.target.prototype)}},h=class extends n{static{t(this,"ScopedSingletonRegistrationError")}name="ScopedSingletonRegistrationError";constructor(){super("Cannot register a singleton in a scoped service collection"),Object.setPrototypeOf(this,new.target.prototype)}},g=class{constructor(e,t,r){this.identifiers=e,this.isScoped=t,this.addService=r}static{t(this,"ServiceBuilder")}descriptor;to(e,t){this.descriptor=this.createDescriptor(t,e);for(const e of this.identifiers)this.addService(e,this.descriptor);return this}createDescriptor(e,t){const r=e??(()=>new t);return{implementation:t,createInstance:r,lifetime:"RESOLVE"}}singleton(){if(this.isScoped)throw new h;return this.ensureDescriptor().lifetime="SINGLETON",this}scoped(){return this.ensureDescriptor().lifetime="SCOPED",this}transient(){return this.ensureDescriptor().lifetime="TRANSIENT",this}ensureDescriptor(){if(!this.descriptor)throw new Error("Must call to() before setting lifetime");return this.descriptor}},d=class{static{t(this,"IDisposable")}},u=class{static{t(this,"IServiceModule")}},v=class{static{t(this,"IResolutionScope")}},S=class extends v{static{t(this,"IScopedProvider")}},f=class extends v{static{t(this,"IServiceProvider")}},m=class{static{t(this,"IServiceCollection")}},E=class{static{t(this,"ILifetimeBuilder")}},I=class{static{t(this,"IServiceBuilder")}},w=class{constructor(e,t){this.singletons=e,this.scoped=t}static{t(this,"ResolutionContext")}transient=new Map;getFromLifetime(e,t){const r=this.getMapForLifetime(t);return r?.get(e)}setForLifetime(e,t,r){const s=this.getMapForLifetime(r);s?.set(e,t)}getMapForLifetime(e){return{SINGLETON:this.singletons,SCOPED:this.scoped,RESOLVE:this.transient}[e]}},x="design:dependencies",R=t(((e,t)=>Reflect.getMetadata(e,t)),"getMetadata"),L=t(((e,t,r)=>Reflect.defineMetadata(e,t,r)),"defineMetadata"),O=class e{constructor(e,t,r=new Map){this.logger=e,this.Services=t,this.singletons=r}static{t(this,"ServiceProvider")}scoped=new Map;created=[];[Symbol.dispose](){for(const e of this.created)e[Symbol.dispose]()}resolveInternal(e,t){let r=t.getFromLifetime(e.implementation,e.lifetime);return null==r&&(r=this.createInstance(e,t)),r}resolveAll(e,t){return this.Services.get(e).map((e=>this.resolveInternal(e,t??new w(this.singletons,this.scoped))))}resolve(e,t){if(e.prototype===v.prototype||e.prototype===S.prototype||e.prototype===f.prototype)return this;const r=this.getSingleDescriptor(e);return this.resolveInternal(r,t??new w(this.singletons,this.scoped))}getSingleDescriptor(e){const t=this.Services.get(e);if(0===t.length)throw new c(e);if(t.length>1&&"ERROR"===this.Services.options.registrationMode)throw new l(e);return t[t.length-1]}createInstance(e,t){const r=this.createInstanceInternal(e,t);return this.setDependencies(e.implementation,r,t),t.setForLifetime(e.implementation,r,e.lifetime),r}wrapContext(e){return{resolve:t((t=>this.resolve(t,e)),"resolve"),resolveAll:t((t=>this.resolveAll(t,e)),"resolveAll")}}createInstanceInternal(e,t){let r;try{r=e.createInstance(this.wrapContext(t))}catch(t){throw this.logger.error(t),new a(e.implementation,t)}return"SINGLETON"!==e.lifetime&&Symbol.dispose in r&&this.created.push(r),r}createScope(){return new e(this.logger,this.Services.clone(!0),this.singletons)}setDependencies(e,t,r){const s=R(x,e)??{};this.logger.debug("Dependencies",e.name,s);for(const[i,o]of Object.entries(s)){if(o===e)throw new p;{this.logger.debug("Resolving",o.name,"for",e.name);const s=this.resolve(o,r);t[i]=s}}return t}},b=class e{constructor(e,t,r,s=new Map){this.logger=e,this.options=t,this.isScoped=r,this.services=s}static{t(this,"ServiceCollection")}registerModules(...e){for(const t of e){(new t).registerServices(this)}}get(e){return this.services.get(e)??[]}overrideLifetime(e,t){for(const r of this.get(e))r.lifetime=t}register(...e){return new g(e,this.isScoped,((e,t)=>this.addService(e,t)))}addService(e,t){this.logger.info("Adding service",{identifier:e.name,descriptor:t});let r=this.services.get(e);null==r&&(r=[],this.services.set(e,r)),r.push(t)}clone(t){const r=new Map;for(const[e,t]of this.services){const s=t.map((e=>({...e})));r.set(e,s)}return new e(this.logger,this.options,!0===t,r)}buildProvider(){return new O(this.logger,this.clone())}},y=class{static{t(this,"ILogger")}debug(e,...t){}info(e,...t){}error(e,...t){}warn(e,...t){}},M=class extends y{constructor(e){super(),this.options=e}static{t(this,"ConsoleLogger")}debug(e,...t){this.options.logLevel<=0&&console.debug(e,...t)}info(e,...t){this.options.logLevel<=1&&console.info(e,...t)}warn(e,...t){this.options.logLevel<=2&&console.warn(e,...t)}error(e,...t){this.options.logLevel<=3&&console.error(e,...t)}},D=t((e=>({...o,...e})),"mergeOptions"),C=t((e=>{const t=D(e),r=t.logger??new M(t);return new b(r,t,!1)}),"createServiceCollection"),P=t(((e,t,r,s)=>{let i=R(e,t);void 0===i&&(i={},L(e,i,t)),i[r]=s}),"tagProperty"),N=t((e=>(t,r)=>function(t){const s=this.constructor;return P(x,s,r.name,e),t}),"dependsOn");exports.DefaultServiceCollectionOptions=o,exports.IDisposable=d,exports.ILifetimeBuilder=E,exports.ILogger=y,exports.IResolutionScope=v,exports.IScopedProvider=S,exports.IServiceBuilder=I,exports.IServiceCollection=m,exports.IServiceModule=u,exports.IServiceProvider=f,exports.Lifetime=r,exports.LogLevel=s,exports.MultipleRegistrationError=l,exports.ResolveMultipleMode=i,exports.ScopedSingletonRegistrationError=h,exports.SelfDependencyError=p,exports.ServiceCreationError=a,exports.ServiceError=n,exports.UnregisteredServiceError=c,exports.createServiceCollection=C,exports.dependsOn=N;//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/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/createServiceCollection.ts","../src/dependsOn.ts"],"names":["LogLevel"],"mappings":"AAAA,8PAAI,UAAU,EAAE,MAAM,CAAC,cAAc;AACrC,IAAI,OAAO,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,CAAC,CAAC;AACxF;AACA;ACIO,IAAM,sBAAA,EAAwB,qBAAA;ADFrC;AACA;AEJO,IAAe,aAAA,EAAf,MAAA,QAAoC,MAAM;AAAA,EAFjD,OAEiD;AAAA,IAAA,MAAA,CAAA,IAAA,EAAA,cAAA,CAAA;AAAA,EAAA;AAAC,CAAA;AAE3C,IAAM,yBAAA,YAAN,MAAA,QAAyD,aAAa;AAAA,EAJ7E,OAI6E;AAAA,IAAA,MAAA,CAAA,IAAA,EAAA,0BAAA,CAAA;AAAA,EAAA;AAAA,iBAC3E,KAAA,EAAO,2BAAA;AAAA,EACP,WAAA,CAAY,UAAA,EAAkC;AAC5C,IAAA,KAAA,CAAM,CAAA,gDAAA,EAAmD,UAAU,CAAA,CAAA;AACnB,IAAA;AAClD,EAAA;AACF;AAE8E;AAAA,EAAA;AAAA,IAAA;AAAA,EAAA;AACrE,kBAAA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ACb,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"]}
|
|
1
|
+
{"version":3,"sources":["../src/enums.ts","../src/defaults.ts","../src/errors.ts","../src/private/ServiceBuilder.ts","../src/interfaces.ts","../src/private/ResolutionContext.ts","../src/private/constants.ts","../src/private/metadata.ts","../src/private/ServiceProvider.ts","../src/private/ServiceCollection.ts","../src/logger.ts","../src/private/consoleLogger.ts","../src/createServiceCollection.ts","../src/dependsOn.ts"],"names":["Lifetime","LogLevel","ResolveMultipleMode"],"mappings":";;;;AAAY,IAAA,QAAA,qBAAAA,SAAL,KAAA;AACL,EAAAA,UAAA,SAAU,CAAA,GAAA,SAAA;AACV,EAAAA,UAAA,WAAY,CAAA,GAAA,WAAA;AACZ,EAAAA,UAAA,QAAS,CAAA,GAAA,QAAA;AACT,EAAAA,UAAA,WAAY,CAAA,GAAA,WAAA;AAJF,EAAAA,OAAAA,SAAAA;AAAA,CAAA,EAAA,QAAA,IAAA,EAAA;AAOA,IAAA,QAAA,qBAAAC,SAAL,KAAA;AACL,EAAAA,SAAAA,CAAAA,SAAAA,CAAA,WAAQ,CAAR,CAAA,GAAA,OAAA;AACA,EAAAA,SAAAA,CAAAA,SAAAA,CAAA,UAAO,CAAP,CAAA,GAAA,MAAA;AACA,EAAAA,SAAAA,CAAAA,SAAAA,CAAA,UAAO,CAAP,CAAA,GAAA,MAAA;AACA,EAAAA,SAAAA,CAAAA,SAAAA,CAAA,WAAQ,CAAR,CAAA,GAAA,OAAA;AACA,EAAAA,SAAAA,CAAAA,SAAAA,CAAA,UAAO,CAAP,CAAA,GAAA,MAAA;AALU,EAAAA,OAAAA,SAAAA;AAAA,CAAA,EAAA,QAAA,IAAA,EAAA;AAQA,IAAA,mBAAA,qBAAAC,oBAAL,KAAA;AACL,EAAAA,qBAAA,OAAQ,CAAA,GAAA,OAAA;AACR,EAAAA,qBAAA,gBAAiB,CAAA,G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B,UAAqC,KAAA;AACpJ,EAAI,IAAA,QAAA,GAAW,WAAe,CAAA,WAAA,EAAa,gBAAgB,CAAA;AAC3D,EAAA,IAAI,aAAa,KAAW,CAAA,EAAA;AAC1B,IAAA,QAAA,GAAW,EAAC;AACZ,IAAe,cAAA,CAAA,WAAA,EAAa,UAAU,gBAAgB,CAAA;AAAA;AAExD,EAAA,QAAA,CAAS,IAAI,CAAI,GAAA,UAAA;AACnB,CAPoB,EAAA,aAAA,CAAA;AAcP,IAAA,SAAA,2BAAmC,UAAqC,KAAA;AACnF,EAAO,OAAA,CAAC,OAAkB,GAAoC,KAAA;AAC5D,IAAA,OAAO,SAAwB,YAAmB,EAAA;AAChD,MAAA,MAAM,SAAS,IAAK,CAAA,WAAA;AACpB,MAAA,WAAA,CAAY,qBAAuB,EAAA,MAAA,EAAQ,GAAI,CAAA,IAAA,EAAM,UAAU,CAAA;AAC/D,MAAO,OAAA,YAAA;AAAA,KACT;AAAA,GACF;AACF,CARyB,EAAA,WAAA","file":"index.js","sourcesContent":["export enum Lifetime {\n Resolve = 'RESOLVE',\n Transient = 'TRANSIENT',\n Scoped = 'SCOPED',\n Singleton = 'SINGLETON',\n}\n\nexport enum LogLevel {\n Debug = 0,\n Info = 1,\n Warn = 2,\n Error = 3,\n None = 4,\n}\n\nexport enum ResolveMultipleMode {\n Error = 'ERROR',\n LastRegistered = 'LAST_REGISTERED',\n}\n","import { LogLevel, ResolveMultipleMode } from './enums';\nimport type { ServiceCollectionOptions } from './types';\n\nexport const DefaultServiceCollectionOptions: ServiceCollectionOptions = {\n registrationMode: ResolveMultipleMode.Error,\n logLevel: LogLevel.Warn,\n};\n","import type { ServiceIdentifier } from './types';\n\nexport abstract class ServiceError extends Error {}\n\nexport class UnregisteredServiceError<T extends object> extends ServiceError {\n name = 'UnregisteredServiceError';\n constructor(identifier: ServiceIdentifier<T>) {\n super(`Resolving service that has not been registered: ${identifier.name}`);\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class MultipleRegistrationError<T extends object> extends ServiceError {\n name = 'MultipleRegistrationError';\n constructor(identifier: ServiceIdentifier<T>) {\n super(`Multiple services have been registered: ${identifier.name}`);\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class ServiceCreationError<T extends object> extends ServiceError {\n name = 'ServiceCreationError';\n constructor(\n identifier: ServiceIdentifier<T>,\n public readonly innerError: any,\n ) {\n super(`Error creating service: ${identifier.name}`);\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class SelfDependencyError extends ServiceError {\n name = 'SelfDependencyError';\n constructor() {\n super('Service depending on itself');\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class ScopedSingletonRegistrationError extends ServiceError {\n name = 'ScopedSingletonRegistrationError';\n constructor() {\n super('Cannot register a singleton in a scoped service collection');\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n","import { Lifetime } from '../enums';\nimport { ScopedSingletonRegistrationError } from '../errors';\nimport type { ILifetimeBuilder, IServiceBuilder } from '../interfaces';\nimport type { InstanceFactory, ServiceDescriptor, ServiceIdentifier, ServiceImplementation, SourceType } from '../types';\n\nexport class ServiceBuilder<T extends SourceType> implements IServiceBuilder<T> {\n private descriptor: ServiceDescriptor<T> | undefined;\n\n constructor(\n private readonly identifiers: ServiceIdentifier<T>[],\n private readonly isScoped: boolean,\n private readonly addService: (identifier: ServiceIdentifier<T>, descriptor: ServiceDescriptor<T>) => void,\n ) {}\n\n public to(implementation: ServiceImplementation<T>, factory?: InstanceFactory<T>): ILifetimeBuilder {\n this.descriptor = this.createDescriptor(factory, implementation);\n\n for (const identifier of this.identifiers) {\n this.addService(identifier, this.descriptor);\n }\n return this;\n }\n\n private createDescriptor(factory: InstanceFactory<T> | undefined, implementation: ServiceImplementation<T>): ServiceDescriptor<T> {\n const createInstance = factory ?? (() => new implementation());\n\n return {\n implementation,\n createInstance,\n lifetime: Lifetime.Resolve,\n };\n }\n\n public singleton(): this {\n if (this.isScoped) {\n throw new ScopedSingletonRegistrationError();\n }\n this.ensureDescriptor().lifetime = Lifetime.Singleton;\n return this;\n }\n\n public scoped(): this {\n this.ensureDescriptor().lifetime = Lifetime.Scoped;\n return this;\n }\n\n public transient(): this {\n this.ensureDescriptor().lifetime = Lifetime.Transient;\n return this;\n }\n\n private ensureDescriptor(): ServiceDescriptor<T> {\n if (!this.descriptor) {\n throw new Error('Must call to() before setting lifetime');\n }\n return this.descriptor;\n }\n}\n","import type { Lifetime } from './enums';\nimport { ResolveMultipleMode } from './enums';\nimport type { EnsureObject, ServiceBuilderOptions, ServiceCollectionOptions, ServiceDescriptor, ServiceIdentifier, ServiceModuleType, SourceType, UnionToIntersection } from './types';\n\nexport abstract class IDisposable {\n public abstract [Symbol.dispose](): void;\n}\n\nexport abstract class IServiceModule {\n public abstract registerServices(services: IServiceCollection): void;\n}\n\nexport abstract class IResolutionScope {\n /**\n * Resolves a single implementation for the given identifier.\n * @template T The type of service to resolve\n * @param identifier The service identifier\n * @returns The resolved instance\n * @throws {MultipleRegistrationError} When multiple implementations exist (unless {@link ServiceCollectionOptions.registrationMode} is set to {@link ResolveMultipleMode.LastRegistered}).\n * @throws {UnregisteredServiceError} When no implementation exists\n */\n public abstract resolve<T extends SourceType>(identifier: ServiceIdentifier<T>): T;\n\n /**\n * Resolves all implementations for the given identifier.\n * @template T The type of service to resolve\n * @param identifier The service identifier\n * @returns Array of resolved instances\n */\n public abstract resolveAll<T extends SourceType>(identifier: ServiceIdentifier<T>): T[];\n}\n\nexport abstract class IScopedProvider extends IResolutionScope implements IDisposable {\n public abstract readonly Services: IServiceCollection;\n public abstract [Symbol.dispose](): void;\n}\n\nexport abstract class IServiceProvider extends IResolutionScope {\n public abstract readonly Services: IServiceCollection;\n public abstract createScope(): IScopedProvider;\n}\n\nexport abstract class IServiceCollection {\n public abstract readonly options: ServiceCollectionOptions;\n public abstract get<T extends SourceType>(identifier: ServiceIdentifier<T>): ServiceDescriptor<T>[];\n public abstract register<Types extends SourceType[]>(...identifiers: { [K in keyof Types]: ServiceIdentifier<Types[K]> }): IServiceBuilder<EnsureObject<UnionToIntersection<Types[number]>>>;\n public abstract registerModules(...modules: ServiceModuleType[]): void;\n public abstract overrideLifetime<T extends SourceType>(identifier: ServiceIdentifier<T>, lifetime: Lifetime): void;\n public abstract buildProvider(): IServiceProvider;\n public abstract clone(): IServiceCollection;\n public abstract clone(scoped: true): IServiceCollection;\n}\n\nexport abstract class ILifetimeBuilder {\n public abstract singleton(): ILifetimeBuilder;\n public abstract scoped(): ILifetimeBuilder;\n public abstract transient(): ILifetimeBuilder;\n}\n\nexport abstract class IServiceBuilder<T extends SourceType> {\n public abstract to: ServiceBuilderOptions<T>;\n}\n","import { Lifetime } from '../enums';\nimport type { ServiceImplementation, SourceType } from '../types';\n\nexport class ResolutionContext {\n constructor(\n private readonly singletons: Map<ServiceImplementation<any>, any>,\n private readonly scoped: Map<ServiceImplementation<any>, any>,\n ) {}\n\n private readonly transient = new Map<ServiceImplementation<any>, any>();\n\n public getFromLifetime<T extends SourceType>(implementation: ServiceImplementation<T>, lifetime: Lifetime): T {\n const map = this.getMapForLifetime(lifetime);\n return map?.get(implementation);\n }\n\n public setForLifetime<T extends SourceType>(implementation: ServiceImplementation<T>, instance: T, lifetime: Lifetime): void {\n const map = this.getMapForLifetime(lifetime);\n map?.set(implementation, instance);\n }\n\n private getMapForLifetime(lifetime: Lifetime) {\n const map: Partial<Record<Lifetime, Map<ServiceImplementation<any>, any>>> = {\n [Lifetime.Singleton]: this.singletons,\n [Lifetime.Scoped]: this.scoped,\n [Lifetime.Resolve]: this.transient,\n };\n return map[lifetime];\n }\n}\n","export const DesignDependenciesKey = 'design:dependencies';\n","import '@abraham/reflection';\nimport type { MetadataType, SourceType } from '../types';\n\nexport const getMetadata = <T extends SourceType>(key: string, obj: object): MetadataType<T> | undefined => Reflect.getMetadata(key, obj);\nexport const defineMetadata = <T extends SourceType>(key: string, metadata: MetadataType<T>, obj: object) => Reflect.defineMetadata(key, metadata, obj);\n","import { Lifetime } from '../enums';\nimport { ResolveMultipleMode } from '../enums';\nimport { MultipleRegistrationError, SelfDependencyError, ServiceCreationError, UnregisteredServiceError } from '../errors';\nimport { type IDisposable, IResolutionScope, IScopedProvider, type IServiceCollection } from '../interfaces';\nimport { IServiceProvider } from '../interfaces';\nimport type { ILogger } from '../logger';\nimport type { ServiceDescriptor, ServiceIdentifier, ServiceImplementation, SourceType } from '../types';\nimport { ResolutionContext } from './ResolutionContext';\nimport { DesignDependenciesKey } from './constants';\nimport { getMetadata } from './metadata';\n\nexport class ServiceProvider implements IServiceProvider, IScopedProvider {\n private scoped = new Map<ServiceImplementation<any>, any>();\n private created: IDisposable[] = [];\n\n constructor(\n private readonly logger: ILogger,\n public readonly Services: IServiceCollection,\n private readonly singletons = new Map<ServiceImplementation<any>, any>(),\n ) {}\n\n [Symbol.dispose]() {\n for (const x of this.created) {\n x[Symbol.dispose]();\n }\n }\n\n private resolveInternal<T extends SourceType>(descriptor: ServiceDescriptor<T>, context: ResolutionContext): T {\n let instance = context.getFromLifetime(descriptor.implementation, descriptor.lifetime);\n if (instance == null) {\n instance = this.createInstance(descriptor, context);\n }\n return instance;\n }\n\n public resolveAll<T extends SourceType>(identifier: ServiceIdentifier<T>, context?: ResolutionContext): T[] {\n const descriptors = this.Services.get(identifier);\n return descriptors.map((descriptor) => this.resolveInternal<T>(descriptor, context ?? new ResolutionContext(this.singletons, this.scoped)));\n }\n\n public resolve<T extends SourceType>(identifier: ServiceIdentifier<T>, context?: ResolutionContext): T {\n if (identifier.prototype === IResolutionScope.prototype || identifier.prototype === IScopedProvider.prototype || identifier.prototype === IServiceProvider.prototype) {\n return this as IResolutionScope & IScopedProvider & IServiceProvider as T;\n }\n\n const descriptor = this.getSingleDescriptor(identifier);\n return this.resolveInternal(descriptor, context ?? new ResolutionContext(this.singletons, this.scoped));\n }\n\n private getSingleDescriptor<T extends SourceType>(identifier: ServiceIdentifier<T>) {\n const descriptors = this.Services.get(identifier);\n if (descriptors.length === 0) {\n throw new UnregisteredServiceError(identifier);\n }\n\n if (descriptors.length > 1) {\n if (this.Services.options.registrationMode === ResolveMultipleMode.Error) {\n throw new MultipleRegistrationError(identifier);\n }\n }\n const descriptor = descriptors[descriptors.length - 1];\n return descriptor;\n }\n\n private createInstance<T extends SourceType>(descriptor: ServiceDescriptor<T>, context: ResolutionContext): T {\n const instance = this.createInstanceInternal(descriptor, context);\n this.setDependencies(descriptor.implementation, instance, context);\n context.setForLifetime(descriptor.implementation, instance, descriptor.lifetime);\n return instance;\n }\n\n private wrapContext(context: ResolutionContext): IResolutionScope {\n const resolve = (identifier: ServiceIdentifier<any>) => this.resolve(identifier, context);\n const resolveAll = (identifier: ServiceIdentifier<any>) => this.resolveAll(identifier, context);\n\n return {\n resolve,\n resolveAll,\n };\n }\n\n private createInstanceInternal<T extends SourceType>(descriptor: ServiceDescriptor<T>, context: ResolutionContext) {\n let instance: T | undefined;\n try {\n instance = descriptor.createInstance(this.wrapContext(context));\n } catch (err) {\n this.logger.error(err);\n throw new ServiceCreationError(descriptor.implementation, err);\n }\n if (descriptor.lifetime !== Lifetime.Singleton && Symbol.dispose in instance) {\n this.created.push(instance as IDisposable);\n }\n return instance;\n }\n\n public createScope(): IScopedProvider {\n return new ServiceProvider(this.logger, this.Services.clone(true), this.singletons);\n }\n\n private setDependencies<T extends SourceType>(implementation: ServiceImplementation<T>, instance: T, context: ResolutionContext): T {\n const dependencies = getMetadata<T>(DesignDependenciesKey, implementation) ?? {};\n this.logger.debug('Dependencies', implementation.name, dependencies);\n for (const [key, identifier] of Object.entries(dependencies)) {\n if (identifier !== implementation) {\n this.logger.debug('Resolving', identifier.name, 'for', implementation.name);\n const dep = this.resolve(identifier, context);\n (instance as Record<string, T>)[key] = dep;\n } else {\n throw new SelfDependencyError();\n }\n }\n return instance;\n }\n}\n","import type { Lifetime } from '../enums';\nimport type { IServiceBuilder, IServiceCollection, IServiceProvider } from '../interfaces';\nimport type { ILogger } from '../logger';\nimport type { EnsureObject, ServiceCollectionOptions, ServiceDescriptor, ServiceIdentifier, ServiceModuleType, SourceType, UnionToIntersection } from '../types';\nimport { ServiceBuilder } from './ServiceBuilder';\nimport { ServiceProvider } from './ServiceProvider';\n\nexport class ServiceCollection implements IServiceCollection {\n constructor(\n private readonly logger: ILogger,\n public readonly options: ServiceCollectionOptions,\n private readonly isScoped: boolean,\n private readonly services = new Map<ServiceIdentifier<any>, ServiceDescriptor<any>[]>(),\n ) {}\n\n public registerModules(...modules: ServiceModuleType[]): void {\n for (const x of modules) {\n const module = new x();\n module.registerServices(this);\n }\n }\n\n get<T extends SourceType>(key: ServiceIdentifier<T>): ServiceDescriptor<T>[] {\n return this.services.get(key) ?? [];\n }\n\n public overrideLifetime<T extends SourceType>(identifier: ServiceIdentifier<T>, lifetime: Lifetime): void {\n for (const descriptor of this.get(identifier)) {\n descriptor.lifetime = lifetime;\n }\n }\n\n register<Types extends SourceType[]>(...identifiers: { [K in keyof Types]: ServiceIdentifier<Types[K]> }): IServiceBuilder<EnsureObject<UnionToIntersection<Types[number]>>> {\n return new ServiceBuilder(identifiers, this.isScoped, (identifier, descriptor) => this.addService(identifier, descriptor));\n }\n\n private addService<T extends SourceType>(identifier: ServiceIdentifier<T>, descriptor: ServiceDescriptor<T>) {\n this.logger.info('Adding service', { identifier: identifier.name, descriptor });\n let existing = this.services.get(identifier);\n if (existing == null) {\n existing = [];\n this.services.set(identifier, existing);\n }\n existing.push(descriptor);\n }\n\n public clone(scoped?: unknown): IServiceCollection {\n const clonedMap = new Map<ServiceIdentifier<any>, ServiceDescriptor<any>[]>();\n for (const [key, descriptors] of this.services) {\n const clonedDescriptors = descriptors.map((descriptor) => ({ ...descriptor }));\n clonedMap.set(key, clonedDescriptors);\n }\n\n return new ServiceCollection(this.logger, this.options, scoped === true, clonedMap);\n }\n\n public buildProvider(): IServiceProvider {\n return new ServiceProvider(this.logger, this.clone());\n }\n}\n","export abstract class ILogger {\n public debug(_message?: any, ..._optionalParams: any[]) {}\n public info(_message?: any, ..._optionalParams: any[]) {}\n public error(_message?: any, ..._optionalParams: any[]) {}\n public warn(_message?: any, ..._optionalParams: any[]) {}\n}\n","import { LogLevel } from '../enums';\nimport { ILogger } from '../logger';\nimport type { ServiceCollectionOptions } from '../types';\n\nexport class ConsoleLogger extends ILogger {\n constructor(private readonly options: ServiceCollectionOptions) {\n super();\n }\n\n public override debug(message?: any, ...optionalParams: any[]): void {\n if (this.options.logLevel <= LogLevel.Debug) {\n console.debug(message, ...optionalParams);\n }\n }\n\n public override info(message?: any, ...optionalParams: any[]): void {\n if (this.options.logLevel <= LogLevel.Info) {\n console.info(message, ...optionalParams);\n }\n }\n\n public override warn(message?: any, ...optionalParams: any[]): void {\n if (this.options.logLevel <= LogLevel.Warn) {\n console.warn(message, ...optionalParams);\n }\n }\n\n public override error(message?: any, ...optionalParams: any[]): void {\n if (this.options.logLevel <= LogLevel.Error) {\n console.error(message, ...optionalParams);\n }\n }\n}\n","import { DefaultServiceCollectionOptions } from './defaults';\nimport type { IServiceCollection } from './interfaces';\nimport { ServiceCollection } from './private/ServiceCollection';\nimport { ConsoleLogger } from './private/consoleLogger';\nimport type { ServiceCollectionOptions } from './types';\n\nconst mergeOptions = (options: Partial<ServiceCollectionOptions> | undefined): ServiceCollectionOptions => ({\n ...DefaultServiceCollectionOptions,\n ...options,\n});\n\n/**\n * Creates a service collection with the (optionally) provided options\n * @param options - Optional configuration for the service collection.\n * @defaultValue Default options are taken from {@link DefaultServiceCollectionOptions}.\n */\nexport const createServiceCollection = (options?: Partial<ServiceCollectionOptions>): IServiceCollection => {\n const mergedOptions = mergeOptions(options);\n const logger = mergedOptions.logger ?? new ConsoleLogger(mergedOptions);\n return new ServiceCollection(logger, mergedOptions, false);\n};\n","import { IResolutionScope, IScopedProvider, IServiceProvider } from './interfaces';\nimport { DesignDependenciesKey } from './private/constants';\nimport { defineMetadata, getMetadata } from './private/metadata';\nimport type { ServiceIdentifier, SourceType } from './types';\n\nconst tagProperty = <T extends SourceType>(metadataKey: string, annotationTarget: object, name: string | symbol, identifier: ServiceIdentifier<T>) => {\n let existing = getMetadata<T>(metadataKey, annotationTarget);\n if (existing === undefined) {\n existing = {};\n defineMetadata(metadataKey, existing, annotationTarget);\n }\n existing[name] = identifier;\n};\n\n/**\n * declares a dependency, use on a class field.\n * Can also depend on {@link IServiceProvider}, {@link IResolutionScope}, or {@link IScopedProvider}.\n * @param identifier the identifier to depend on, i.e. the interface\n */\nexport const dependsOn = <T extends SourceType>(identifier: ServiceIdentifier<T>) => {\n return (value: undefined, ctx: ClassFieldDecoratorContext) => {\n return function (this: object, initialValue: any) {\n const target = this.constructor;\n tagProperty(DesignDependenciesKey, target, ctx.name, identifier);\n return initialValue;\n };\n };\n};\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=Object.defineProperty,t=(t,
|
|
1
|
+
import"@abraham/reflection";var e=Object.defineProperty,t=(t,s)=>e(t,"name",{value:s,configurable:!0}),s=(e=>(e.Resolve="RESOLVE",e.Transient="TRANSIENT",e.Scoped="SCOPED",e.Singleton="SINGLETON",e))(s||{}),r=(e=>(e[e.Debug=0]="Debug",e[e.Info=1]="Info",e[e.Warn=2]="Warn",e[e.Error=3]="Error",e[e.None=4]="None",e))(r||{}),i=(e=>(e.Error="ERROR",e.LastRegistered="LAST_REGISTERED",e))(i||{}),o={registrationMode:"ERROR",logLevel:2},n=class extends Error{static{t(this,"ServiceError")}},c=class extends n{static{t(this,"UnregisteredServiceError")}name="UnregisteredServiceError";constructor(e){super(`Resolving service that has not been registered: ${e.name}`),Object.setPrototypeOf(this,new.target.prototype)}},a=class extends n{static{t(this,"MultipleRegistrationError")}name="MultipleRegistrationError";constructor(e){super(`Multiple services have been registered: ${e.name}`),Object.setPrototypeOf(this,new.target.prototype)}},l=class extends n{constructor(e,t){super(`Error creating service: ${e.name}`),this.innerError=t,Object.setPrototypeOf(this,new.target.prototype)}static{t(this,"ServiceCreationError")}name="ServiceCreationError"},h=class extends n{static{t(this,"SelfDependencyError")}name="SelfDependencyError";constructor(){super("Service depending on itself"),Object.setPrototypeOf(this,new.target.prototype)}},p=class extends n{static{t(this,"ScopedSingletonRegistrationError")}name="ScopedSingletonRegistrationError";constructor(){super("Cannot register a singleton in a scoped service collection"),Object.setPrototypeOf(this,new.target.prototype)}},g=class{constructor(e,t,s){this.identifiers=e,this.isScoped=t,this.addService=s}static{t(this,"ServiceBuilder")}descriptor;to(e,t){this.descriptor=this.createDescriptor(t,e);for(const e of this.identifiers)this.addService(e,this.descriptor);return this}createDescriptor(e,t){const s=e??(()=>new t);return{implementation:t,createInstance:s,lifetime:"RESOLVE"}}singleton(){if(this.isScoped)throw new p;return this.ensureDescriptor().lifetime="SINGLETON",this}scoped(){return this.ensureDescriptor().lifetime="SCOPED",this}transient(){return this.ensureDescriptor().lifetime="TRANSIENT",this}ensureDescriptor(){if(!this.descriptor)throw new Error("Must call to() before setting lifetime");return this.descriptor}},d=class{static{t(this,"IDisposable")}},u=class{static{t(this,"IServiceModule")}},f=class{static{t(this,"IResolutionScope")}},v=class extends f{static{t(this,"IScopedProvider")}},S=class extends f{static{t(this,"IServiceProvider")}},m=class{static{t(this,"IServiceCollection")}},E=class{static{t(this,"ILifetimeBuilder")}},w=class{static{t(this,"IServiceBuilder")}},I=class{constructor(e,t){this.singletons=e,this.scoped=t}static{t(this,"ResolutionContext")}transient=new Map;getFromLifetime(e,t){const s=this.getMapForLifetime(t);return s?.get(e)}setForLifetime(e,t,s){const r=this.getMapForLifetime(s);r?.set(e,t)}getMapForLifetime(e){return{SINGLETON:this.singletons,SCOPED:this.scoped,RESOLVE:this.transient}[e]}},R="design:dependencies",O=t(((e,t)=>Reflect.getMetadata(e,t)),"getMetadata"),L=t(((e,t,s)=>Reflect.defineMetadata(e,t,s)),"defineMetadata"),b=class e{constructor(e,t,s=new Map){this.logger=e,this.Services=t,this.singletons=s}static{t(this,"ServiceProvider")}scoped=new Map;created=[];[Symbol.dispose](){for(const e of this.created)e[Symbol.dispose]()}resolveInternal(e,t){let s=t.getFromLifetime(e.implementation,e.lifetime);return null==s&&(s=this.createInstance(e,t)),s}resolveAll(e,t){return this.Services.get(e).map((e=>this.resolveInternal(e,t??new I(this.singletons,this.scoped))))}resolve(e,t){if(e.prototype===f.prototype||e.prototype===v.prototype||e.prototype===S.prototype)return this;const s=this.getSingleDescriptor(e);return this.resolveInternal(s,t??new I(this.singletons,this.scoped))}getSingleDescriptor(e){const t=this.Services.get(e);if(0===t.length)throw new c(e);if(t.length>1&&"ERROR"===this.Services.options.registrationMode)throw new a(e);return t[t.length-1]}createInstance(e,t){const s=this.createInstanceInternal(e,t);return this.setDependencies(e.implementation,s,t),t.setForLifetime(e.implementation,s,e.lifetime),s}wrapContext(e){return{resolve:t((t=>this.resolve(t,e)),"resolve"),resolveAll:t((t=>this.resolveAll(t,e)),"resolveAll")}}createInstanceInternal(e,t){let s;try{s=e.createInstance(this.wrapContext(t))}catch(t){throw this.logger.error(t),new l(e.implementation,t)}return"SINGLETON"!==e.lifetime&&Symbol.dispose in s&&this.created.push(s),s}createScope(){return new e(this.logger,this.Services.clone(!0),this.singletons)}setDependencies(e,t,s){const r=O(R,e)??{};this.logger.debug("Dependencies",e.name,r);for(const[i,o]of Object.entries(r)){if(o===e)throw new h;{this.logger.debug("Resolving",o.name,"for",e.name);const r=this.resolve(o,s);t[i]=r}}return t}},y=class e{constructor(e,t,s,r=new Map){this.logger=e,this.options=t,this.isScoped=s,this.services=r}static{t(this,"ServiceCollection")}registerModules(...e){for(const t of e){(new t).registerServices(this)}}get(e){return this.services.get(e)??[]}overrideLifetime(e,t){for(const s of this.get(e))s.lifetime=t}register(...e){return new g(e,this.isScoped,((e,t)=>this.addService(e,t)))}addService(e,t){this.logger.info("Adding service",{identifier:e.name,descriptor:t});let s=this.services.get(e);null==s&&(s=[],this.services.set(e,s)),s.push(t)}clone(t){const s=new Map;for(const[e,t]of this.services){const r=t.map((e=>({...e})));s.set(e,r)}return new e(this.logger,this.options,!0===t,s)}buildProvider(){return new b(this.logger,this.clone())}},D=class{static{t(this,"ILogger")}debug(e,...t){}info(e,...t){}error(e,...t){}warn(e,...t){}},M=class extends D{constructor(e){super(),this.options=e}static{t(this,"ConsoleLogger")}debug(e,...t){this.options.logLevel<=0&&console.debug(e,...t)}info(e,...t){this.options.logLevel<=1&&console.info(e,...t)}warn(e,...t){this.options.logLevel<=2&&console.warn(e,...t)}error(e,...t){this.options.logLevel<=3&&console.error(e,...t)}},N=t((e=>({...o,...e})),"mergeOptions"),P=t((e=>{const t=N(e),s=t.logger??new M(t);return new y(s,t,!1)}),"createServiceCollection"),x=t(((e,t,s,r)=>{let i=O(e,t);void 0===i&&(i={},L(e,i,t)),i[s]=r}),"tagProperty"),C=t((e=>(t,s)=>function(t){const r=this.constructor;return x(R,r,s.name,e),t}),"dependsOn");export{o as DefaultServiceCollectionOptions,d as IDisposable,E as ILifetimeBuilder,D as ILogger,f as IResolutionScope,v as IScopedProvider,w as IServiceBuilder,m as IServiceCollection,u as IServiceModule,S as IServiceProvider,s as Lifetime,r as LogLevel,a as MultipleRegistrationError,i as ResolveMultipleMode,p as ScopedSingletonRegistrationError,h as SelfDependencyError,l as ServiceCreationError,n as ServiceError,c as UnregisteredServiceError,P as createServiceCollection,C as dependsOn};//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,UAAU,EAAE;AACrE,WAAO,eAAe,MAAM,WAAW,SAAS;AAAA,EAClD;AACF;AAEO,IAAM,4BAAN,cAA0D,aAAa;AAAA,EAZ9E,OAY8E;AAAA;AAAA;AAAA,EAC5E,OAAO;AAAA,EACP,YAAY,YAAkC;AAC5C,UAAM,2CAA2C,UAAU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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"]}
|
|
1
|
+
{"version":3,"sources":["../src/enums.ts","../src/defaults.ts","../src/errors.ts","../src/private/ServiceBuilder.ts","../src/interfaces.ts","../src/private/ResolutionContext.ts","../src/private/constants.ts","../src/private/metadata.ts","../src/private/ServiceProvider.ts","../src/private/ServiceCollection.ts","../src/logger.ts","../src/private/consoleLogger.ts","../src/createServiceCollection.ts","../src/dependsOn.ts"],"names":["Lifetime","LogLevel","ResolveMultipleMode"],"mappings":";;;;AAAY,IAAA,QAAA,qBAAAA,SAAL,KAAA;AACL,EAAAA,UAAA,SAAU,CAAA,GAAA,SAAA;AACV,EAAAA,UAAA,WAAY,CAAA,GAAA,WAAA;AACZ,EAAAA,UAAA,QAAS,CAAA,GAAA,QAAA;AACT,EAAAA,UAAA,WAAY,CAAA,GAAA,WAAA;AAJF,EAAAA,OAAAA,SAAAA;AAAA,CAAA,EAAA,QAAA,IAAA,EAAA;AAOA,IAAA,QAAA,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n Transient = 'TRANSIENT',\n Scoped = 'SCOPED',\n Singleton = 'SINGLETON',\n}\n\nexport enum LogLevel {\n Debug = 0,\n Info = 1,\n Warn = 2,\n Error = 3,\n None = 4,\n}\n\nexport enum ResolveMultipleMode {\n Error = 'ERROR',\n LastRegistered = 'LAST_REGISTERED',\n}\n","import { LogLevel, ResolveMultipleMode } from './enums';\nimport type { ServiceCollectionOptions } from './types';\n\nexport const DefaultServiceCollectionOptions: ServiceCollectionOptions = {\n registrationMode: ResolveMultipleMode.Error,\n logLevel: LogLevel.Warn,\n};\n","import type { ServiceIdentifier } from './types';\n\nexport abstract class ServiceError extends Error {}\n\nexport class UnregisteredServiceError<T extends object> extends ServiceError {\n name = 'UnregisteredServiceError';\n constructor(identifier: ServiceIdentifier<T>) {\n super(`Resolving service that has not been registered: ${identifier.name}`);\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class MultipleRegistrationError<T extends object> extends ServiceError {\n name = 'MultipleRegistrationError';\n constructor(identifier: ServiceIdentifier<T>) {\n super(`Multiple services have been registered: ${identifier.name}`);\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class ServiceCreationError<T extends object> extends ServiceError {\n name = 'ServiceCreationError';\n constructor(\n identifier: ServiceIdentifier<T>,\n public readonly innerError: any,\n ) {\n super(`Error creating service: ${identifier.name}`);\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class SelfDependencyError extends ServiceError {\n name = 'SelfDependencyError';\n constructor() {\n super('Service depending on itself');\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class ScopedSingletonRegistrationError extends ServiceError {\n name = 'ScopedSingletonRegistrationError';\n constructor() {\n super('Cannot register a singleton in a scoped service collection');\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n","import { Lifetime } from '../enums';\nimport { ScopedSingletonRegistrationError } from '../errors';\nimport type { ILifetimeBuilder, IServiceBuilder } from '../interfaces';\nimport type { InstanceFactory, ServiceDescriptor, ServiceIdentifier, ServiceImplementation, SourceType } from '../types';\n\nexport class ServiceBuilder<T extends SourceType> implements IServiceBuilder<T> {\n private descriptor: ServiceDescriptor<T> | undefined;\n\n constructor(\n private readonly identifiers: ServiceIdentifier<T>[],\n private readonly isScoped: boolean,\n private readonly addService: (identifier: ServiceIdentifier<T>, descriptor: ServiceDescriptor<T>) => void,\n ) {}\n\n public to(implementation: ServiceImplementation<T>, factory?: InstanceFactory<T>): ILifetimeBuilder {\n this.descriptor = this.createDescriptor(factory, implementation);\n\n for (const identifier of this.identifiers) {\n this.addService(identifier, this.descriptor);\n }\n return this;\n }\n\n private createDescriptor(factory: InstanceFactory<T> | undefined, implementation: ServiceImplementation<T>): ServiceDescriptor<T> {\n const createInstance = factory ?? (() => new implementation());\n\n return {\n implementation,\n createInstance,\n lifetime: Lifetime.Resolve,\n };\n }\n\n public singleton(): this {\n if (this.isScoped) {\n throw new ScopedSingletonRegistrationError();\n }\n this.ensureDescriptor().lifetime = Lifetime.Singleton;\n return this;\n }\n\n public scoped(): this {\n this.ensureDescriptor().lifetime = Lifetime.Scoped;\n return this;\n }\n\n public transient(): this {\n this.ensureDescriptor().lifetime = Lifetime.Transient;\n return this;\n }\n\n private ensureDescriptor(): ServiceDescriptor<T> {\n if (!this.descriptor) {\n throw new Error('Must call to() before setting lifetime');\n }\n return this.descriptor;\n }\n}\n","import type { Lifetime } from './enums';\nimport { ResolveMultipleMode } from './enums';\nimport type { EnsureObject, ServiceBuilderOptions, ServiceCollectionOptions, ServiceDescriptor, ServiceIdentifier, ServiceModuleType, SourceType, UnionToIntersection } from './types';\n\nexport abstract class IDisposable {\n public abstract [Symbol.dispose](): void;\n}\n\nexport abstract class IServiceModule {\n public abstract registerServices(services: IServiceCollection): void;\n}\n\nexport abstract class IResolutionScope {\n /**\n * Resolves a single implementation for the given identifier.\n * @template T The type of service to resolve\n * @param identifier The service identifier\n * @returns The resolved instance\n * @throws {MultipleRegistrationError} When multiple implementations exist (unless {@link ServiceCollectionOptions.registrationMode} is set to {@link ResolveMultipleMode.LastRegistered}).\n * @throws {UnregisteredServiceError} When no implementation exists\n */\n public abstract resolve<T extends SourceType>(identifier: ServiceIdentifier<T>): T;\n\n /**\n * Resolves all implementations for the given identifier.\n * @template T The type of service to resolve\n * @param identifier The service identifier\n * @returns Array of resolved instances\n */\n public abstract resolveAll<T extends SourceType>(identifier: ServiceIdentifier<T>): T[];\n}\n\nexport abstract class IScopedProvider extends IResolutionScope implements IDisposable {\n public abstract readonly Services: IServiceCollection;\n public abstract [Symbol.dispose](): void;\n}\n\nexport abstract class IServiceProvider extends IResolutionScope {\n public abstract readonly Services: IServiceCollection;\n public abstract createScope(): IScopedProvider;\n}\n\nexport abstract class IServiceCollection {\n public abstract readonly options: ServiceCollectionOptions;\n public abstract get<T extends SourceType>(identifier: ServiceIdentifier<T>): ServiceDescriptor<T>[];\n public abstract register<Types extends SourceType[]>(...identifiers: { [K in keyof Types]: ServiceIdentifier<Types[K]> }): IServiceBuilder<EnsureObject<UnionToIntersection<Types[number]>>>;\n public abstract registerModules(...modules: ServiceModuleType[]): void;\n public abstract overrideLifetime<T extends SourceType>(identifier: ServiceIdentifier<T>, lifetime: Lifetime): void;\n public abstract buildProvider(): IServiceProvider;\n public abstract clone(): IServiceCollection;\n public abstract clone(scoped: true): IServiceCollection;\n}\n\nexport abstract class ILifetimeBuilder {\n public abstract singleton(): ILifetimeBuilder;\n public abstract scoped(): ILifetimeBuilder;\n public abstract transient(): ILifetimeBuilder;\n}\n\nexport abstract class IServiceBuilder<T extends SourceType> {\n public abstract to: ServiceBuilderOptions<T>;\n}\n","import { Lifetime } from '../enums';\nimport type { ServiceImplementation, SourceType } from '../types';\n\nexport class ResolutionContext {\n constructor(\n private readonly singletons: Map<ServiceImplementation<any>, any>,\n private readonly scoped: Map<ServiceImplementation<any>, any>,\n ) {}\n\n private readonly transient = new Map<ServiceImplementation<any>, any>();\n\n public getFromLifetime<T extends SourceType>(implementation: ServiceImplementation<T>, lifetime: Lifetime): T {\n const map = this.getMapForLifetime(lifetime);\n return map?.get(implementation);\n }\n\n public setForLifetime<T extends SourceType>(implementation: ServiceImplementation<T>, instance: T, lifetime: Lifetime): void {\n const map = this.getMapForLifetime(lifetime);\n map?.set(implementation, instance);\n }\n\n private getMapForLifetime(lifetime: Lifetime) {\n const map: Partial<Record<Lifetime, Map<ServiceImplementation<any>, any>>> = {\n [Lifetime.Singleton]: this.singletons,\n [Lifetime.Scoped]: this.scoped,\n [Lifetime.Resolve]: this.transient,\n };\n return map[lifetime];\n }\n}\n","export const DesignDependenciesKey = 'design:dependencies';\n","import '@abraham/reflection';\nimport type { MetadataType, SourceType } from '../types';\n\nexport const getMetadata = <T extends SourceType>(key: string, obj: object): MetadataType<T> | undefined => Reflect.getMetadata(key, obj);\nexport const defineMetadata = <T extends SourceType>(key: string, metadata: MetadataType<T>, obj: object) => Reflect.defineMetadata(key, metadata, obj);\n","import { Lifetime } from '../enums';\nimport { ResolveMultipleMode } from '../enums';\nimport { MultipleRegistrationError, SelfDependencyError, ServiceCreationError, UnregisteredServiceError } from '../errors';\nimport { type IDisposable, IResolutionScope, IScopedProvider, type IServiceCollection } from '../interfaces';\nimport { IServiceProvider } from '../interfaces';\nimport type { ILogger } from '../logger';\nimport type { ServiceDescriptor, ServiceIdentifier, ServiceImplementation, SourceType } from '../types';\nimport { ResolutionContext } from './ResolutionContext';\nimport { DesignDependenciesKey } from './constants';\nimport { getMetadata } from './metadata';\n\nexport class ServiceProvider implements IServiceProvider, IScopedProvider {\n private scoped = new Map<ServiceImplementation<any>, any>();\n private created: IDisposable[] = [];\n\n constructor(\n private readonly logger: ILogger,\n public readonly Services: IServiceCollection,\n private readonly singletons = new Map<ServiceImplementation<any>, any>(),\n ) {}\n\n [Symbol.dispose]() {\n for (const x of this.created) {\n x[Symbol.dispose]();\n }\n }\n\n private resolveInternal<T extends SourceType>(descriptor: ServiceDescriptor<T>, context: ResolutionContext): T {\n let instance = context.getFromLifetime(descriptor.implementation, descriptor.lifetime);\n if (instance == null) {\n instance = this.createInstance(descriptor, context);\n }\n return instance;\n }\n\n public resolveAll<T extends SourceType>(identifier: ServiceIdentifier<T>, context?: ResolutionContext): T[] {\n const descriptors = this.Services.get(identifier);\n return descriptors.map((descriptor) => this.resolveInternal<T>(descriptor, context ?? new ResolutionContext(this.singletons, this.scoped)));\n }\n\n public resolve<T extends SourceType>(identifier: ServiceIdentifier<T>, context?: ResolutionContext): T {\n if (identifier.prototype === IResolutionScope.prototype || identifier.prototype === IScopedProvider.prototype || identifier.prototype === IServiceProvider.prototype) {\n return this as IResolutionScope & IScopedProvider & IServiceProvider as T;\n }\n\n const descriptor = this.getSingleDescriptor(identifier);\n return this.resolveInternal(descriptor, context ?? new ResolutionContext(this.singletons, this.scoped));\n }\n\n private getSingleDescriptor<T extends SourceType>(identifier: ServiceIdentifier<T>) {\n const descriptors = this.Services.get(identifier);\n if (descriptors.length === 0) {\n throw new UnregisteredServiceError(identifier);\n }\n\n if (descriptors.length > 1) {\n if (this.Services.options.registrationMode === ResolveMultipleMode.Error) {\n throw new MultipleRegistrationError(identifier);\n }\n }\n const descriptor = descriptors[descriptors.length - 1];\n return descriptor;\n }\n\n private createInstance<T extends SourceType>(descriptor: ServiceDescriptor<T>, context: ResolutionContext): T {\n const instance = this.createInstanceInternal(descriptor, context);\n this.setDependencies(descriptor.implementation, instance, context);\n context.setForLifetime(descriptor.implementation, instance, descriptor.lifetime);\n return instance;\n }\n\n private wrapContext(context: ResolutionContext): IResolutionScope {\n const resolve = (identifier: ServiceIdentifier<any>) => this.resolve(identifier, context);\n const resolveAll = (identifier: ServiceIdentifier<any>) => this.resolveAll(identifier, context);\n\n return {\n resolve,\n resolveAll,\n };\n }\n\n private createInstanceInternal<T extends SourceType>(descriptor: ServiceDescriptor<T>, context: ResolutionContext) {\n let instance: T | undefined;\n try {\n instance = descriptor.createInstance(this.wrapContext(context));\n } catch (err) {\n this.logger.error(err);\n throw new ServiceCreationError(descriptor.implementation, err);\n }\n if (descriptor.lifetime !== Lifetime.Singleton && Symbol.dispose in instance) {\n this.created.push(instance as IDisposable);\n }\n return instance;\n }\n\n public createScope(): IScopedProvider {\n return new ServiceProvider(this.logger, this.Services.clone(true), this.singletons);\n }\n\n private setDependencies<T extends SourceType>(implementation: ServiceImplementation<T>, instance: T, context: ResolutionContext): T {\n const dependencies = getMetadata<T>(DesignDependenciesKey, implementation) ?? {};\n this.logger.debug('Dependencies', implementation.name, dependencies);\n for (const [key, identifier] of Object.entries(dependencies)) {\n if (identifier !== implementation) {\n this.logger.debug('Resolving', identifier.name, 'for', implementation.name);\n const dep = this.resolve(identifier, context);\n (instance as Record<string, T>)[key] = dep;\n } else {\n throw new SelfDependencyError();\n }\n }\n return instance;\n }\n}\n","import type { Lifetime } from '../enums';\nimport type { IServiceBuilder, IServiceCollection, IServiceProvider } from '../interfaces';\nimport type { ILogger } from '../logger';\nimport type { EnsureObject, ServiceCollectionOptions, ServiceDescriptor, ServiceIdentifier, ServiceModuleType, SourceType, UnionToIntersection } from '../types';\nimport { ServiceBuilder } from './ServiceBuilder';\nimport { ServiceProvider } from './ServiceProvider';\n\nexport class ServiceCollection implements IServiceCollection {\n constructor(\n private readonly logger: ILogger,\n public readonly options: ServiceCollectionOptions,\n private readonly isScoped: boolean,\n private readonly services = new Map<ServiceIdentifier<any>, ServiceDescriptor<any>[]>(),\n ) {}\n\n public registerModules(...modules: ServiceModuleType[]): void {\n for (const x of modules) {\n const module = new x();\n module.registerServices(this);\n }\n }\n\n get<T extends SourceType>(key: ServiceIdentifier<T>): ServiceDescriptor<T>[] {\n return this.services.get(key) ?? [];\n }\n\n public overrideLifetime<T extends SourceType>(identifier: ServiceIdentifier<T>, lifetime: Lifetime): void {\n for (const descriptor of this.get(identifier)) {\n descriptor.lifetime = lifetime;\n }\n }\n\n register<Types extends SourceType[]>(...identifiers: { [K in keyof Types]: ServiceIdentifier<Types[K]> }): IServiceBuilder<EnsureObject<UnionToIntersection<Types[number]>>> {\n return new ServiceBuilder(identifiers, this.isScoped, (identifier, descriptor) => this.addService(identifier, descriptor));\n }\n\n private addService<T extends SourceType>(identifier: ServiceIdentifier<T>, descriptor: ServiceDescriptor<T>) {\n this.logger.info('Adding service', { identifier: identifier.name, descriptor });\n let existing = this.services.get(identifier);\n if (existing == null) {\n existing = [];\n this.services.set(identifier, existing);\n }\n existing.push(descriptor);\n }\n\n public clone(scoped?: unknown): IServiceCollection {\n const clonedMap = new Map<ServiceIdentifier<any>, ServiceDescriptor<any>[]>();\n for (const [key, descriptors] of this.services) {\n const clonedDescriptors = descriptors.map((descriptor) => ({ ...descriptor }));\n clonedMap.set(key, clonedDescriptors);\n }\n\n return new ServiceCollection(this.logger, this.options, scoped === true, clonedMap);\n }\n\n public buildProvider(): IServiceProvider {\n return new ServiceProvider(this.logger, this.clone());\n }\n}\n","export abstract class ILogger {\n public debug(_message?: any, ..._optionalParams: any[]) {}\n public info(_message?: any, ..._optionalParams: any[]) {}\n public error(_message?: any, ..._optionalParams: any[]) {}\n public warn(_message?: any, ..._optionalParams: any[]) {}\n}\n","import { LogLevel } from '../enums';\nimport { ILogger } from '../logger';\nimport type { ServiceCollectionOptions } from '../types';\n\nexport class ConsoleLogger extends ILogger {\n constructor(private readonly options: ServiceCollectionOptions) {\n super();\n }\n\n public override debug(message?: any, ...optionalParams: any[]): void {\n if (this.options.logLevel <= LogLevel.Debug) {\n console.debug(message, ...optionalParams);\n }\n }\n\n public override info(message?: any, ...optionalParams: any[]): void {\n if (this.options.logLevel <= LogLevel.Info) {\n console.info(message, ...optionalParams);\n }\n }\n\n public override warn(message?: any, ...optionalParams: any[]): void {\n if (this.options.logLevel <= LogLevel.Warn) {\n console.warn(message, ...optionalParams);\n }\n }\n\n public override error(message?: any, ...optionalParams: any[]): void {\n if (this.options.logLevel <= LogLevel.Error) {\n console.error(message, ...optionalParams);\n }\n }\n}\n","import { DefaultServiceCollectionOptions } from './defaults';\nimport type { IServiceCollection } from './interfaces';\nimport { ServiceCollection } from './private/ServiceCollection';\nimport { ConsoleLogger } from './private/consoleLogger';\nimport type { ServiceCollectionOptions } from './types';\n\nconst mergeOptions = (options: Partial<ServiceCollectionOptions> | undefined): ServiceCollectionOptions => ({\n ...DefaultServiceCollectionOptions,\n ...options,\n});\n\n/**\n * Creates a service collection with the (optionally) provided options\n * @param options - Optional configuration for the service collection.\n * @defaultValue Default options are taken from {@link DefaultServiceCollectionOptions}.\n */\nexport const createServiceCollection = (options?: Partial<ServiceCollectionOptions>): IServiceCollection => {\n const mergedOptions = mergeOptions(options);\n const logger = mergedOptions.logger ?? new ConsoleLogger(mergedOptions);\n return new ServiceCollection(logger, mergedOptions, false);\n};\n","import { IResolutionScope, IScopedProvider, IServiceProvider } from './interfaces';\nimport { DesignDependenciesKey } from './private/constants';\nimport { defineMetadata, getMetadata } from './private/metadata';\nimport type { ServiceIdentifier, SourceType } from './types';\n\nconst tagProperty = <T extends SourceType>(metadataKey: string, annotationTarget: object, name: string | symbol, identifier: ServiceIdentifier<T>) => {\n let existing = getMetadata<T>(metadataKey, annotationTarget);\n if (existing === undefined) {\n existing = {};\n defineMetadata(metadataKey, existing, annotationTarget);\n }\n existing[name] = identifier;\n};\n\n/**\n * declares a dependency, use on a class field.\n * Can also depend on {@link IServiceProvider}, {@link IResolutionScope}, or {@link IScopedProvider}.\n * @param identifier the identifier to depend on, i.e. the interface\n */\nexport const dependsOn = <T extends SourceType>(identifier: ServiceIdentifier<T>) => {\n return (value: undefined, ctx: ClassFieldDecoratorContext) => {\n return function (this: object, initialValue: any) {\n const target = this.constructor;\n tagProperty(DesignDependenciesKey, target, ctx.name, identifier);\n return initialValue;\n };\n };\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shellicar/core-di",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "A basic dependency injection library",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -39,26 +39,32 @@
|
|
|
39
39
|
"homepage": "https://github.com/shellicar/core-di#readme",
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@biomejs/biome": "^1.9.4",
|
|
42
|
-
"@
|
|
43
|
-
"@types/node": "^22.
|
|
44
|
-
"
|
|
45
|
-
"npm-
|
|
42
|
+
"@tsconfig/node20": "^20.1.4",
|
|
43
|
+
"@types/node": "^22.10.5",
|
|
44
|
+
"lefthook": "^1.10.1",
|
|
45
|
+
"npm-check-updates": "^17.1.13",
|
|
46
|
+
"npm-run-all2": "^7.0.2",
|
|
46
47
|
"rimraf": "^6.0.1",
|
|
47
|
-
"terser": "^5.
|
|
48
|
+
"terser": "^5.37.0",
|
|
48
49
|
"tsup": "^8.3.5",
|
|
49
50
|
"tsx": "^4.19.2",
|
|
50
|
-
"typescript": "^5.
|
|
51
|
+
"typescript": "^5.7.2",
|
|
52
|
+
"vitest": "^2.1.8"
|
|
51
53
|
},
|
|
52
54
|
"dependencies": {
|
|
53
55
|
"@abraham/reflection": "^0.12.0"
|
|
54
56
|
},
|
|
55
57
|
"scripts": {
|
|
56
58
|
"build": "tsup-node",
|
|
57
|
-
"
|
|
58
|
-
"test": "
|
|
59
|
+
"dev": "tsup-node --watch",
|
|
60
|
+
"test": "vitest run",
|
|
59
61
|
"lint": "biome lint",
|
|
60
62
|
"format": "biome format",
|
|
61
63
|
"check": "biome check",
|
|
62
|
-
"
|
|
64
|
+
"type-check": "tsc -p tsconfig.check.json",
|
|
65
|
+
"ci": "biome ci",
|
|
66
|
+
"ci:fix": "biome check --fix --diagnostic-level=error",
|
|
67
|
+
"updates": "npm-check-updates",
|
|
68
|
+
"postinstall": "lefthook install"
|
|
63
69
|
}
|
|
64
70
|
}
|