@narvega/container 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +178 -2
- package/dist/index.d.ts +134 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +318 -0
- package/dist/index.js.map +1 -0
- package/package.json +36 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Narvega
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,179 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @narvega/container
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@narvega/container` is Narvega's synchronous dependency-injection container.
|
|
4
|
+
It connects explicit service tokens to factories that create services.
|
|
5
|
+
|
|
6
|
+
The examples and rules in this document describe the current public contract.
|
|
7
|
+
|
|
8
|
+
The package declarations require TypeScript 5.4 or newer. This enables the
|
|
9
|
+
built-in `NoInfer<T>` type used to keep registration factories aligned with
|
|
10
|
+
their service tokens.
|
|
11
|
+
|
|
12
|
+
## Basic usage
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
import { Container, createInjectionToken } from '@narvega/container';
|
|
16
|
+
|
|
17
|
+
interface Logger {
|
|
18
|
+
info(message: string): void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
class ConsoleLogger implements Logger {
|
|
22
|
+
public info(message: string): void {
|
|
23
|
+
console.log(message);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const LOGGER_TOKEN = createInjectionToken<Logger>('Logger');
|
|
28
|
+
const container = new Container();
|
|
29
|
+
|
|
30
|
+
container.registerTransient(LOGGER_TOKEN, () => new ConsoleLogger());
|
|
31
|
+
|
|
32
|
+
const logger = container.resolve(LOGGER_TOKEN);
|
|
33
|
+
logger.info('Hello, Narvega');
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
An interface is a compile-time contract, so it needs an injection token that
|
|
37
|
+
exists at runtime. A class constructor can also be used as a token.
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
class UserService {
|
|
41
|
+
public constructor(public readonly logger: Logger) {}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
container.registerTransient(UserService, (resolver) => {
|
|
45
|
+
return new UserService(resolver.resolve(LOGGER_TOKEN));
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const users = container.resolve(UserService);
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Factories make dependencies explicit. The container does not inspect
|
|
52
|
+
constructors or infer dependencies from TypeScript types.
|
|
53
|
+
|
|
54
|
+
## Registration methods
|
|
55
|
+
|
|
56
|
+
| Method | Behavior |
|
|
57
|
+
| ------------------- | ----------------------------------------- |
|
|
58
|
+
| `registerTransient` | Runs the factory for every resolution. |
|
|
59
|
+
| `registerSingleton` | Runs the factory once per root container. |
|
|
60
|
+
| `registerScoped` | Runs the factory once per child scope. |
|
|
61
|
+
|
|
62
|
+
All registration methods reject duplicate tokens with
|
|
63
|
+
`DuplicateRegistrationError`.
|
|
64
|
+
|
|
65
|
+
## Scopes
|
|
66
|
+
|
|
67
|
+
Use a child scope for a request or another defined execution boundary:
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
class RequestContext {}
|
|
71
|
+
|
|
72
|
+
const REQUEST_CONTEXT_TOKEN = createInjectionToken<RequestContext>('RequestContext');
|
|
73
|
+
|
|
74
|
+
container.registerScoped(REQUEST_CONTEXT_TOKEN, () => new RequestContext());
|
|
75
|
+
|
|
76
|
+
const firstRequest = container.createScope();
|
|
77
|
+
const secondRequest = container.createScope();
|
|
78
|
+
|
|
79
|
+
const firstContext = firstRequest.resolve(REQUEST_CONTEXT_TOKEN);
|
|
80
|
+
const sameContext = firstRequest.resolve(REQUEST_CONTEXT_TOKEN);
|
|
81
|
+
const otherContext = secondRequest.resolve(REQUEST_CONTEXT_TOKEN);
|
|
82
|
+
|
|
83
|
+
firstContext === sameContext; // true
|
|
84
|
+
firstContext === otherContext; // false
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Scopes can resolve registrations from the root container, but they cannot add
|
|
88
|
+
registrations. A scoped service resolved directly from the root container
|
|
89
|
+
throws `ScopeRequiredError`.
|
|
90
|
+
|
|
91
|
+
Singletons are shared across all scopes created by the same root container.
|
|
92
|
+
Singleton factories use the root resolver, so they cannot resolve scoped
|
|
93
|
+
services.
|
|
94
|
+
|
|
95
|
+
## Resource cleanup
|
|
96
|
+
|
|
97
|
+
Services that own resources can implement `Disposable`:
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
class DatabaseConnection {
|
|
101
|
+
public dispose(): void {
|
|
102
|
+
// Close the connection.
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
The container tracks disposable singleton instances. A scope tracks
|
|
108
|
+
disposable scoped instances.
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
scope.dispose();
|
|
112
|
+
container.dispose();
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Disposal rules:
|
|
116
|
+
|
|
117
|
+
- Singleton resources are disposed by the root container.
|
|
118
|
+
- Scoped resources are disposed by their scope.
|
|
119
|
+
- Resources are disposed in reverse creation order.
|
|
120
|
+
- Repeated disposal calls are safe and do nothing.
|
|
121
|
+
- Transient resources are not tracked by the container.
|
|
122
|
+
- Resolution after disposal throws `ContainerDisposedError` or
|
|
123
|
+
`ScopeDisposedError`.
|
|
124
|
+
- Disposal during an active resolution throws
|
|
125
|
+
`DisposalDuringResolutionError` and leaves the owner available for a later
|
|
126
|
+
disposal attempt.
|
|
127
|
+
- Cached instances and disposable references are cleared even when cleanup
|
|
128
|
+
throws. The first cleanup error is rethrown after all resources have been
|
|
129
|
+
attempted.
|
|
130
|
+
|
|
131
|
+
Dispose child scopes before disposing their root container. Asynchronous
|
|
132
|
+
disposal is not supported. If a `dispose()` method returns a Promise or another
|
|
133
|
+
thenable, cleanup may already have started when `UnsupportedAsyncDisposalError`
|
|
134
|
+
is reported. The container consumes a later rejection to avoid an unhandled
|
|
135
|
+
promise rejection, but it cannot guarantee completion of asynchronous cleanup.
|
|
136
|
+
|
|
137
|
+
## Resolver contract
|
|
138
|
+
|
|
139
|
+
Factories receive this small interface:
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
import type { ServiceToken } from '@narvega/container';
|
|
143
|
+
|
|
144
|
+
interface Resolver {
|
|
145
|
+
resolve<T>(token: ServiceToken<T>): T;
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
This keeps factories focused on obtaining dependencies. Registration and scope
|
|
150
|
+
creation remain application composition responsibilities.
|
|
151
|
+
|
|
152
|
+
## Errors
|
|
153
|
+
|
|
154
|
+
- `ServiceNotFoundError` means no registration exists for the token.
|
|
155
|
+
- `DuplicateRegistrationError` means the token was registered more than once.
|
|
156
|
+
- `CircularDependencyError` includes the complete resolution path.
|
|
157
|
+
- `ScopeRequiredError` means a scoped service was resolved without a scope.
|
|
158
|
+
- `ContainerDisposedError` means the root container was used after disposal.
|
|
159
|
+
- `ScopeDisposedError` means a scope was used after disposal.
|
|
160
|
+
- `DisposalDuringResolutionError` means disposal was attempted while a service
|
|
161
|
+
resolution was active.
|
|
162
|
+
- `UnsupportedAsyncDisposalError` means a disposable returned a Promise or
|
|
163
|
+
another thenable from its synchronous `dispose()` method.
|
|
164
|
+
|
|
165
|
+
## Current non-goals
|
|
166
|
+
|
|
167
|
+
The current container intentionally does not provide:
|
|
168
|
+
|
|
169
|
+
- Asynchronous factories or asynchronous resolution
|
|
170
|
+
- A full asynchronous disposal API
|
|
171
|
+
- Decorator-based registration
|
|
172
|
+
- Runtime reflection
|
|
173
|
+
- Implicit constructor inspection
|
|
174
|
+
- Automatic class construction
|
|
175
|
+
- Registration methods on child scopes
|
|
176
|
+
|
|
177
|
+
Factories and disposal are synchronous and explicit. Async initialization and
|
|
178
|
+
async cleanup will be designed separately when application lifecycle
|
|
179
|
+
requirements are defined.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
declare const tokenType: unique symbol;
|
|
2
|
+
/**
|
|
3
|
+
* A unique runtime key associated with a dependency type.
|
|
4
|
+
*/
|
|
5
|
+
export type InjectionToken<T> = symbol & {
|
|
6
|
+
readonly [tokenType]: T;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Creates a token that can identify a dependency at runtime.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createInjectionToken<T>(description: string): InjectionToken<T>;
|
|
12
|
+
/**
|
|
13
|
+
* A class constructor that can be used as a service token.
|
|
14
|
+
*/
|
|
15
|
+
export type Constructor<T> = abstract new (...args: never[]) => T;
|
|
16
|
+
/**
|
|
17
|
+
* A token that identifies a registered service.
|
|
18
|
+
*/
|
|
19
|
+
export type ServiceToken<T> = InjectionToken<T> | Constructor<T>;
|
|
20
|
+
/**
|
|
21
|
+
* Resolves registered services.
|
|
22
|
+
*/
|
|
23
|
+
export interface Resolver {
|
|
24
|
+
resolve<T>(token: ServiceToken<T>): T;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A resolver with services scoped to one execution boundary.
|
|
28
|
+
*/
|
|
29
|
+
export interface Scope extends Resolver {
|
|
30
|
+
dispose(): void;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A service that can release resources owned by the container.
|
|
34
|
+
*/
|
|
35
|
+
export interface Disposable {
|
|
36
|
+
dispose(): void;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Creates a service from a resolver.
|
|
40
|
+
*/
|
|
41
|
+
export type Factory<T> = (resolver: Resolver) => T;
|
|
42
|
+
/**
|
|
43
|
+
* Thrown when a service has no registration.
|
|
44
|
+
*/
|
|
45
|
+
export declare class ServiceNotFoundError extends Error {
|
|
46
|
+
readonly token: ServiceToken<unknown>;
|
|
47
|
+
constructor(token: ServiceToken<unknown>);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Thrown when a token is registered more than once.
|
|
51
|
+
*/
|
|
52
|
+
export declare class DuplicateRegistrationError extends Error {
|
|
53
|
+
readonly token: ServiceToken<unknown>;
|
|
54
|
+
constructor(token: ServiceToken<unknown>);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Thrown when resolving a service reaches the same token twice.
|
|
58
|
+
*/
|
|
59
|
+
export declare class CircularDependencyError extends Error {
|
|
60
|
+
readonly path: readonly ServiceToken<unknown>[];
|
|
61
|
+
constructor(path: readonly ServiceToken<unknown>[]);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Thrown when a scoped service is resolved without a scope.
|
|
65
|
+
*/
|
|
66
|
+
export declare class ScopeRequiredError extends Error {
|
|
67
|
+
readonly token: ServiceToken<unknown>;
|
|
68
|
+
constructor(token: ServiceToken<unknown>);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Thrown when a container is used after disposal.
|
|
72
|
+
*/
|
|
73
|
+
export declare class ContainerDisposedError extends Error {
|
|
74
|
+
constructor();
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Thrown when a scope is used after disposal.
|
|
78
|
+
*/
|
|
79
|
+
export declare class ScopeDisposedError extends Error {
|
|
80
|
+
constructor();
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Thrown when disposal is requested while a service is being resolved.
|
|
84
|
+
*/
|
|
85
|
+
export declare class DisposalDuringResolutionError extends Error {
|
|
86
|
+
constructor(owner: 'container' | 'scope');
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Thrown when a disposable returns a Promise or another thenable.
|
|
90
|
+
*/
|
|
91
|
+
export declare class UnsupportedAsyncDisposalError extends Error {
|
|
92
|
+
constructor();
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Stores factories and creates services from registered tokens.
|
|
96
|
+
*/
|
|
97
|
+
export declare class Container implements Resolver {
|
|
98
|
+
private readonly registrations;
|
|
99
|
+
private readonly resolutionStack;
|
|
100
|
+
private readonly disposables;
|
|
101
|
+
private activeResolutionCount;
|
|
102
|
+
private disposed;
|
|
103
|
+
/**
|
|
104
|
+
* Registers a factory that creates a new value for every resolution.
|
|
105
|
+
*/
|
|
106
|
+
registerTransient<T>(token: ServiceToken<T>, factory: Factory<NoInfer<T>>): void;
|
|
107
|
+
/**
|
|
108
|
+
* Registers a factory whose value is reused for every resolution.
|
|
109
|
+
*/
|
|
110
|
+
registerSingleton<T>(token: ServiceToken<T>, factory: Factory<NoInfer<T>>): void;
|
|
111
|
+
/**
|
|
112
|
+
* Registers a factory whose value is reused inside one scope.
|
|
113
|
+
*/
|
|
114
|
+
registerScoped<T>(token: ServiceToken<T>, factory: Factory<NoInfer<T>>): void;
|
|
115
|
+
/**
|
|
116
|
+
* Creates a child scope that can resolve the root registrations.
|
|
117
|
+
*/
|
|
118
|
+
createScope(): Scope;
|
|
119
|
+
/**
|
|
120
|
+
* Creates a service using its registered factory.
|
|
121
|
+
*/
|
|
122
|
+
resolve<T>(token: ServiceToken<T>): T;
|
|
123
|
+
/**
|
|
124
|
+
* Disposes cached singleton resources in reverse creation order.
|
|
125
|
+
*/
|
|
126
|
+
dispose(): void;
|
|
127
|
+
private resolveInScope;
|
|
128
|
+
private resolveRegistration;
|
|
129
|
+
private register;
|
|
130
|
+
private trackDisposable;
|
|
131
|
+
private ensureNotDisposed;
|
|
132
|
+
}
|
|
133
|
+
export {};
|
|
134
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,SAAS,EAAE,OAAO,MAAM,CAAC;AAEvC;;GAEG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,MAAM,GAAG;IACvC,QAAQ,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;CACzB,CAAC;AAEF;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,GAAG,cAAc,CAAC,CAAC,CAAC,CAE9E;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,QAAQ,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;AAElE;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,cAAc,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;AAEjE;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB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;AA6DD;;GAEG;AACH,qBAAa,SAAU,YAAW,QAAQ;IACxC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA2D;IACzF,OAAO,CAAC,QAAQ,CAAC,eAAe,CAA+B;IAC/D,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoB;IAChD,OAAO,CAAC,qBAAqB,CAAK;IAClC,OAAO,CAAC,QAAQ,CAAS;IAEzB;;OAEG;IACI,iBAAiB,CAAC,CAAC,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI;IAIvF;;OAEG;IACI,iBAAiB,CAAC,CAAC,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI;IAIvF;;OAEG;IACI,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI;IAIpF;;OAEG;IACI,WAAW,IAAI,KAAK;IAK3B;;OAEG;IACI,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC;IAa5C;;OAEG;IACI,OAAO,IAAI,IAAI;IAwBtB,OAAO,CAAC,cAAc;IAiBtB,OAAO,CAAC,mBAAmB;IAuD3B,OAAO,CAAC,QAAQ;IAchB,OAAO,CAAC,eAAe;IAMvB,OAAO,CAAC,iBAAiB;CAK1B"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a token that can identify a dependency at runtime.
|
|
3
|
+
*/
|
|
4
|
+
export function createInjectionToken(description) {
|
|
5
|
+
return Symbol(description);
|
|
6
|
+
}
|
|
7
|
+
function isDisposable(value) {
|
|
8
|
+
const valueType = typeof value;
|
|
9
|
+
if (value === null || (valueType !== 'object' && valueType !== 'function')) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
return typeof value.dispose === 'function';
|
|
13
|
+
}
|
|
14
|
+
function isPromiseLike(value) {
|
|
15
|
+
if (value === null || (typeof value !== 'object' && typeof value !== 'function')) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return typeof value.then === 'function';
|
|
19
|
+
}
|
|
20
|
+
function disposeResources(resources) {
|
|
21
|
+
let firstError;
|
|
22
|
+
let hasError = false;
|
|
23
|
+
for (const resource of [...resources].reverse()) {
|
|
24
|
+
try {
|
|
25
|
+
const result = resource.dispose();
|
|
26
|
+
if (isPromiseLike(result)) {
|
|
27
|
+
void Promise.resolve(result).catch(() => undefined);
|
|
28
|
+
throw new UnsupportedAsyncDisposalError();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
if (!hasError) {
|
|
33
|
+
firstError = error;
|
|
34
|
+
hasError = true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (hasError) {
|
|
39
|
+
throw firstError;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function describeToken(token) {
|
|
43
|
+
if (typeof token === 'symbol') {
|
|
44
|
+
return token.description ?? 'anonymous token';
|
|
45
|
+
}
|
|
46
|
+
return token.name || 'anonymous class';
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Thrown when a service has no registration.
|
|
50
|
+
*/
|
|
51
|
+
export class ServiceNotFoundError extends Error {
|
|
52
|
+
token;
|
|
53
|
+
constructor(token) {
|
|
54
|
+
super(`No registration found for ${describeToken(token)}.`);
|
|
55
|
+
this.name = 'ServiceNotFoundError';
|
|
56
|
+
this.token = token;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Thrown when a token is registered more than once.
|
|
61
|
+
*/
|
|
62
|
+
export class DuplicateRegistrationError extends Error {
|
|
63
|
+
token;
|
|
64
|
+
constructor(token) {
|
|
65
|
+
super(`A registration already exists for ${describeToken(token)}.`);
|
|
66
|
+
this.name = 'DuplicateRegistrationError';
|
|
67
|
+
this.token = token;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Thrown when resolving a service reaches the same token twice.
|
|
72
|
+
*/
|
|
73
|
+
export class CircularDependencyError extends Error {
|
|
74
|
+
path;
|
|
75
|
+
constructor(path) {
|
|
76
|
+
super(`Circular dependency detected: ${path.map(describeToken).join(' -> ')}.`);
|
|
77
|
+
this.name = 'CircularDependencyError';
|
|
78
|
+
this.path = path;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Thrown when a scoped service is resolved without a scope.
|
|
83
|
+
*/
|
|
84
|
+
export class ScopeRequiredError extends Error {
|
|
85
|
+
token;
|
|
86
|
+
constructor(token) {
|
|
87
|
+
super(`Service ${describeToken(token)} requires a scope.`);
|
|
88
|
+
this.name = 'ScopeRequiredError';
|
|
89
|
+
this.token = token;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Thrown when a container is used after disposal.
|
|
94
|
+
*/
|
|
95
|
+
export class ContainerDisposedError extends Error {
|
|
96
|
+
constructor() {
|
|
97
|
+
super('The container has been disposed.');
|
|
98
|
+
this.name = 'ContainerDisposedError';
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Thrown when a scope is used after disposal.
|
|
103
|
+
*/
|
|
104
|
+
export class ScopeDisposedError extends Error {
|
|
105
|
+
constructor() {
|
|
106
|
+
super('The scope has been disposed.');
|
|
107
|
+
this.name = 'ScopeDisposedError';
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Thrown when disposal is requested while a service is being resolved.
|
|
112
|
+
*/
|
|
113
|
+
export class DisposalDuringResolutionError extends Error {
|
|
114
|
+
constructor(owner) {
|
|
115
|
+
super(`The ${owner} cannot be disposed while a resolution is active.`);
|
|
116
|
+
this.name = 'DisposalDuringResolutionError';
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Thrown when a disposable returns a Promise or another thenable.
|
|
121
|
+
*/
|
|
122
|
+
export class UnsupportedAsyncDisposalError extends Error {
|
|
123
|
+
constructor() {
|
|
124
|
+
super('Asynchronous disposal is not supported. Cleanup may have already started, and its completion cannot be guaranteed.');
|
|
125
|
+
this.name = 'UnsupportedAsyncDisposalError';
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
class ScopeImplementation {
|
|
129
|
+
resolveFromRoot;
|
|
130
|
+
instances = new Map();
|
|
131
|
+
resolutionStack = [];
|
|
132
|
+
disposables = [];
|
|
133
|
+
activeResolutionCount = 0;
|
|
134
|
+
disposed = false;
|
|
135
|
+
constructor(resolveFromRoot) {
|
|
136
|
+
this.resolveFromRoot = resolveFromRoot;
|
|
137
|
+
}
|
|
138
|
+
resolve(token) {
|
|
139
|
+
if (this.disposed) {
|
|
140
|
+
throw new ScopeDisposedError();
|
|
141
|
+
}
|
|
142
|
+
const resolveFromRoot = this.resolveFromRoot;
|
|
143
|
+
if (resolveFromRoot === undefined) {
|
|
144
|
+
throw new ScopeDisposedError();
|
|
145
|
+
}
|
|
146
|
+
this.activeResolutionCount += 1;
|
|
147
|
+
try {
|
|
148
|
+
return resolveFromRoot(token, this);
|
|
149
|
+
}
|
|
150
|
+
finally {
|
|
151
|
+
this.activeResolutionCount -= 1;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
dispose() {
|
|
155
|
+
if (this.disposed) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
if (this.activeResolutionCount > 0) {
|
|
159
|
+
throw new DisposalDuringResolutionError('scope');
|
|
160
|
+
}
|
|
161
|
+
this.disposed = true;
|
|
162
|
+
try {
|
|
163
|
+
disposeResources(this.disposables);
|
|
164
|
+
}
|
|
165
|
+
finally {
|
|
166
|
+
this.instances.clear();
|
|
167
|
+
this.disposables.length = 0;
|
|
168
|
+
this.resolutionStack.length = 0;
|
|
169
|
+
this.resolveFromRoot = undefined;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
trackDisposable(value) {
|
|
173
|
+
if (isDisposable(value) && !this.disposables.includes(value)) {
|
|
174
|
+
this.disposables.push(value);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Stores factories and creates services from registered tokens.
|
|
180
|
+
*/
|
|
181
|
+
export class Container {
|
|
182
|
+
registrations = new Map();
|
|
183
|
+
resolutionStack = [];
|
|
184
|
+
disposables = [];
|
|
185
|
+
activeResolutionCount = 0;
|
|
186
|
+
disposed = false;
|
|
187
|
+
/**
|
|
188
|
+
* Registers a factory that creates a new value for every resolution.
|
|
189
|
+
*/
|
|
190
|
+
registerTransient(token, factory) {
|
|
191
|
+
this.register(token, factory, 'transient');
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Registers a factory whose value is reused for every resolution.
|
|
195
|
+
*/
|
|
196
|
+
registerSingleton(token, factory) {
|
|
197
|
+
this.register(token, factory, 'singleton');
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Registers a factory whose value is reused inside one scope.
|
|
201
|
+
*/
|
|
202
|
+
registerScoped(token, factory) {
|
|
203
|
+
this.register(token, factory, 'scoped');
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Creates a child scope that can resolve the root registrations.
|
|
207
|
+
*/
|
|
208
|
+
createScope() {
|
|
209
|
+
this.ensureNotDisposed();
|
|
210
|
+
return new ScopeImplementation((token, scope) => this.resolveInScope(token, scope));
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Creates a service using its registered factory.
|
|
214
|
+
*/
|
|
215
|
+
resolve(token) {
|
|
216
|
+
this.ensureNotDisposed();
|
|
217
|
+
this.activeResolutionCount += 1;
|
|
218
|
+
try {
|
|
219
|
+
return this.resolveRegistration(token, this, this.resolutionStack, undefined, (value) => this.trackDisposable(value));
|
|
220
|
+
}
|
|
221
|
+
finally {
|
|
222
|
+
this.activeResolutionCount -= 1;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Disposes cached singleton resources in reverse creation order.
|
|
227
|
+
*/
|
|
228
|
+
dispose() {
|
|
229
|
+
if (this.disposed) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (this.activeResolutionCount > 0) {
|
|
233
|
+
throw new DisposalDuringResolutionError('container');
|
|
234
|
+
}
|
|
235
|
+
this.disposed = true;
|
|
236
|
+
try {
|
|
237
|
+
disposeResources(this.disposables);
|
|
238
|
+
}
|
|
239
|
+
finally {
|
|
240
|
+
for (const registration of this.registrations.values()) {
|
|
241
|
+
registration.instance = undefined;
|
|
242
|
+
}
|
|
243
|
+
this.registrations.clear();
|
|
244
|
+
this.disposables.length = 0;
|
|
245
|
+
this.resolutionStack.length = 0;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
resolveInScope(token, scope) {
|
|
249
|
+
this.ensureNotDisposed();
|
|
250
|
+
this.activeResolutionCount += 1;
|
|
251
|
+
try {
|
|
252
|
+
return this.resolveRegistration(token, scope, scope.resolutionStack, scope.instances, (value) => scope.trackDisposable(value));
|
|
253
|
+
}
|
|
254
|
+
finally {
|
|
255
|
+
this.activeResolutionCount -= 1;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
resolveRegistration(token, resolver, resolutionStack, scopedInstances, trackDisposable) {
|
|
259
|
+
if (resolutionStack.includes(token)) {
|
|
260
|
+
throw new CircularDependencyError([...resolutionStack, token]);
|
|
261
|
+
}
|
|
262
|
+
const registration = this.registrations.get(token);
|
|
263
|
+
if (registration === undefined) {
|
|
264
|
+
throw new ServiceNotFoundError(token);
|
|
265
|
+
}
|
|
266
|
+
if (registration.lifetime === 'scoped' && scopedInstances === undefined) {
|
|
267
|
+
throw new ScopeRequiredError(token);
|
|
268
|
+
}
|
|
269
|
+
if (registration.lifetime === 'singleton' && registration.instance !== undefined) {
|
|
270
|
+
return registration.instance.value;
|
|
271
|
+
}
|
|
272
|
+
if (registration.lifetime === 'scoped') {
|
|
273
|
+
const instance = scopedInstances?.get(token);
|
|
274
|
+
if (instance !== undefined) {
|
|
275
|
+
return instance.value;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
resolutionStack.push(token);
|
|
279
|
+
try {
|
|
280
|
+
const factoryResolver = registration.lifetime === 'singleton' ? this : resolver;
|
|
281
|
+
const value = registration.factory(factoryResolver);
|
|
282
|
+
if (registration.lifetime === 'singleton') {
|
|
283
|
+
registration.instance = { value };
|
|
284
|
+
this.trackDisposable(value);
|
|
285
|
+
}
|
|
286
|
+
if (registration.lifetime === 'scoped') {
|
|
287
|
+
scopedInstances?.set(token, { value });
|
|
288
|
+
trackDisposable?.(value);
|
|
289
|
+
}
|
|
290
|
+
return value;
|
|
291
|
+
}
|
|
292
|
+
finally {
|
|
293
|
+
resolutionStack.pop();
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
register(token, factory, lifetime) {
|
|
297
|
+
this.ensureNotDisposed();
|
|
298
|
+
if (this.registrations.has(token)) {
|
|
299
|
+
throw new DuplicateRegistrationError(token);
|
|
300
|
+
}
|
|
301
|
+
this.registrations.set(token, {
|
|
302
|
+
factory,
|
|
303
|
+
lifetime,
|
|
304
|
+
instance: undefined,
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
trackDisposable(value) {
|
|
308
|
+
if (isDisposable(value) && !this.disposables.includes(value)) {
|
|
309
|
+
this.disposables.push(value);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
ensureNotDisposed() {
|
|
313
|
+
if (this.disposed) {
|
|
314
|
+
throw new ContainerDisposedError();
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
//# source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,QAAQ,KAAK,QAAQ,EAAE,CAAC;gBACvC,eAAe,EAAE,GAAG,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;gBACvC,eAAe,EAAE,CAAC,KAAK,CAAC,CAAC;YAC3B,CAAC;YAED,OAAO,KAAK,CAAC;QACf,CAAC;gBAAS,CAAC;YACT,eAAe,CAAC,GAAG,EAAE,CAAC;QACxB,CAAC;IACH,CAAC;IAEO,QAAQ,CAAI,KAAsB,EAAE,OAAmB,EAAE,QAAkB;QACjF,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAEzB,IAAI,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YAClC,MAAM,IAAI,0BAA0B,CAAC,KAAK,CAAC,CAAC;QAC9C,CAAC;QAED,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,EAAE;YAC5B,OAAO;YACP,QAAQ;YACR,QAAQ,EAAE,SAAS;SACpB,CAAC,CAAC;IACL,CAAC;IAEO,eAAe,CAAC,KAAc;QACpC,IAAI,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YAC7D,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;IAEO,iBAAiB;QACvB,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,MAAM,IAAI,sBAAsB,EAAE,CAAC;QACrC,CAAC;IACH,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@narvega/container",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "The dependency-injection foundation for Narvega.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/narvega/framework.git",
|
|
9
|
+
"directory": "packages/container"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://narvega.com",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/narvega/framework/issues"
|
|
14
|
+
},
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=24.0.0",
|
|
17
|
+
"typescript": ">=5.4.0"
|
|
18
|
+
},
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"type": "module",
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"import": "./dist/index.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsc -p tsconfig.json",
|
|
35
|
+
"typecheck": "tsc --noEmit -p tsconfig.tests.json",
|
|
36
|
+
"test:package": "node --test test/package-exports.test.mjs"
|
|
37
|
+
}
|
|
38
|
+
}
|