@tiberjs/di 0.1.0 → 0.1.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 +37 -10
- package/dist/ambient.d.ts +19 -2
- package/dist/ambient.d.ts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +42 -10
- package/dist/index.js.map +1 -1
- package/package.json +14 -7
package/README.md
CHANGED
|
@@ -68,7 +68,7 @@ test.provide(Db, () => new Db()); // without this, Db stays the root's
|
|
|
68
68
|
|
|
69
69
|
**Register before you resolve.** Replacing a provider whose instance this container already handed out raises `ProviderConflictError`, because the cached instance would keep winning. Override in a child instead.
|
|
70
70
|
|
|
71
|
-
**`inject()` needs an ambient container.** It works while an object is being constructed or disposed, inside `withContainer()`,
|
|
71
|
+
**`inject()` needs an ambient container.** It works while an object is being constructed or disposed, inside `withContainer()`, inside a Runner execution bound to `ContainerKey`, and inside an execution whose attachment is a `ScopeHost`. A method called later with none of those raises. Capture what you need during construction, or use `container.resolve()` directly.
|
|
72
72
|
|
|
73
73
|
## API
|
|
74
74
|
|
|
@@ -94,16 +94,43 @@ test.provide(Db, () => new Db()); // without this, Db stays the root's
|
|
|
94
94
|
|
|
95
95
|
### Ambient access
|
|
96
96
|
|
|
97
|
-
Each reads the ambient container, so classes stay free of container plumbing.
|
|
97
|
+
Each reads the ambient container, so classes stay free of container plumbing. The container is found in this order: the one currently constructing, an explicit `ContainerKey` binding, then the execution's scope host.
|
|
98
98
|
|
|
99
|
-
| |
|
|
100
|
-
| ----------------------------------- |
|
|
101
|
-
| `inject(token)` | Resolve.
|
|
102
|
-
| `scoped(token, factory, dispose?)` | Acquire an inline resource.
|
|
103
|
-
| `onDispose(cleanup)` | Register cleanup.
|
|
104
|
-
| `currentContainer()` | The ambient container; raises when there is none.
|
|
105
|
-
| `withContainer(container, handler)` | Run `handler` with `container` ambient.
|
|
106
|
-
| `ContainerKey` | Runner context key, for binding a container to an execution yourself.
|
|
99
|
+
| | |
|
|
100
|
+
| ----------------------------------- | ----------------------------------------------------------------------------------------- |
|
|
101
|
+
| `inject(token)` | Resolve. On a host, resolves through the scope if one exists, otherwise the root. |
|
|
102
|
+
| `scoped(token, factory, dispose?)` | Acquire an inline resource in the ambient container, creating the host's scope if needed. |
|
|
103
|
+
| `onDispose(cleanup)` | Register cleanup in the ambient container, creating the host's scope if needed. |
|
|
104
|
+
| `currentContainer()` | The ambient container; creates the host's scope; raises when there is none. |
|
|
105
|
+
| `withContainer(container, handler)` | Run `handler` with `container` ambient. Overrides a host. |
|
|
106
|
+
| `ContainerKey` | Runner context key, for binding a container to an execution yourself. |
|
|
107
|
+
|
|
108
|
+
### Scope host
|
|
109
|
+
|
|
110
|
+
Two ways to give an execution its own scope:
|
|
111
|
+
|
|
112
|
+
- **You create it.** `execute({ values: [provide(ContainerKey, root.child())] }, …)` binds a child for that execution; you dispose it afterwards. Simple, and it pays for the child whether or not the execution uses it.
|
|
113
|
+
- **The execution hosts it.** Its Runner attachment declares `[scopeRoot]`; the scope — `root.child()` — is created on the attachment by the first `currentContainer()`, `scoped()`, or `onDispose()`. An execution that only calls `inject()` never creates one. This is for frameworks that run many short executions, most of which never touch a scope.
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
import { Container, executionScope, scopeRoot, type ScopeHost } from "@tiberjs/di";
|
|
117
|
+
import { execute } from "@tiberjs/runner";
|
|
118
|
+
|
|
119
|
+
class RequestContext implements ScopeHost {
|
|
120
|
+
readonly [scopeRoot]: Container;
|
|
121
|
+
[executionScope]: Container | undefined = undefined;
|
|
122
|
+
constructor(root: Container) {
|
|
123
|
+
this[scopeRoot] = root;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const context = new RequestContext(root);
|
|
128
|
+
await execute({ attachment: context }, async () => {
|
|
129
|
+
// ... a handler that may call scoped() / onDispose() ...
|
|
130
|
+
});
|
|
131
|
+
// The host's owner releases the scope, if one was created.
|
|
132
|
+
await context[executionScope]?.[Symbol.asyncDispose]();
|
|
133
|
+
```
|
|
107
134
|
|
|
108
135
|
## Cleanup
|
|
109
136
|
|
package/dist/ambient.d.ts
CHANGED
|
@@ -3,9 +3,26 @@ import type { Container } from "./container.js";
|
|
|
3
3
|
import type { Factory, InjectionToken } from "./tokens.js";
|
|
4
4
|
/** The execution-context binding that carries a container across executions. */
|
|
5
5
|
export declare const ContainerKey: ContextKey<Container>;
|
|
6
|
-
/**
|
|
6
|
+
/** The root a host's execution scope is created from. */
|
|
7
|
+
export declare const scopeRoot: unique symbol;
|
|
8
|
+
/** The execution scope itself, created on the host the first time it is needed. */
|
|
9
|
+
export declare const executionScope: unique symbol;
|
|
10
|
+
/**
|
|
11
|
+
* A runner attachment that hosts one execution's scope.
|
|
12
|
+
*
|
|
13
|
+
* The host declares `[scopeRoot]`; the scope is `root.child()`, created on
|
|
14
|
+
* the host by the first `currentContainer()`, `scoped()`, or `onDispose()`
|
|
15
|
+
* and disposed by whoever owns the host. An execution that only resolves
|
|
16
|
+
* through `inject()` never creates one. An explicit `ContainerKey` binding
|
|
17
|
+
* takes precedence over the host.
|
|
18
|
+
*/
|
|
19
|
+
export interface ScopeHost {
|
|
20
|
+
readonly [scopeRoot]: Container;
|
|
21
|
+
[executionScope]?: Container;
|
|
22
|
+
}
|
|
23
|
+
/** The ambient container, created on a host if it does not exist yet. */
|
|
7
24
|
export declare function currentContainer(): Container;
|
|
8
|
-
/** Resolve a dependency
|
|
25
|
+
/** Resolve a dependency in the ambient container without creating a host's scope. */
|
|
9
26
|
export declare function inject<T>(token: InjectionToken<T>): T;
|
|
10
27
|
/** Acquire a resource once per container and release it when that container closes. */
|
|
11
28
|
export declare function scoped<T>(token: InjectionToken<T>, factory: Factory<T>, dispose?: (value: T) => unknown | Promise<unknown>): T;
|
package/dist/ambient.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ambient.d.ts","sourceRoot":"","sources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;;GAMG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,CAQ1E"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** Hierarchical dependency resolution and resource ownership. */
|
|
2
|
-
export { ContainerKey, currentContainer, inject, onDispose, scoped, withContainer, } from "./ambient.js";
|
|
2
|
+
export { ContainerKey, currentContainer, executionScope, inject, onDispose, scoped, scopeRoot, withContainer, } from "./ambient.js";
|
|
3
|
+
export type { ScopeHost } from "./ambient.js";
|
|
3
4
|
export type { ContainerObject } from "./resources/cleanup.js";
|
|
4
5
|
export { Container } from "./container.js";
|
|
5
6
|
export { ContainerClosedError, DisposalConflictError, ProviderConflictError, ResolutionError, } from "./errors.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,iEAAiE;AAEjE,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,MAAM,EACN,SAAS,EACT,MAAM,EACN,aAAa,GACd,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,eAAe,GAChB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,iEAAiE;AAEjE,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,MAAM,EACN,SAAS,EACT,MAAM,EACN,SAAS,EACT,aAAa,GACd,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,YAAY,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,eAAe,GAChB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -32,8 +32,10 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
32
32
|
kb: () => (/* reexport */ ProviderConflictError),
|
|
33
33
|
fe: () => (/* reexport */ ResolutionError),
|
|
34
34
|
zt: () => (/* reexport */ currentContainer),
|
|
35
|
+
pZ: () => (/* reexport */ executionScope),
|
|
35
36
|
WQ: () => (/* reexport */ inject),
|
|
36
37
|
zp: () => (/* reexport */ onDispose),
|
|
38
|
+
Vz: () => (/* reexport */ scopeRoot),
|
|
37
39
|
P1: () => (/* reexport */ scoped),
|
|
38
40
|
Sh: () => (/* reexport */ tokens_token),
|
|
39
41
|
Ub: () => (/* reexport */ withContainer)
|
|
@@ -54,21 +56,49 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
54
56
|
|
|
55
57
|
|
|
56
58
|
/** The execution-context binding that carries a container across executions. */ const ContainerKey = contextKey("di.container");
|
|
57
|
-
/**
|
|
59
|
+
/** The root a host's execution scope is created from. */ const scopeRoot = Symbol("di.scope-root");
|
|
60
|
+
/** The execution scope itself, created on the host the first time it is needed. */ const executionScope = Symbol("di.execution-scope");
|
|
61
|
+
/** A host is recognized by the declared slot, not by whether a scope exists yet. */ function hostOf(state) {
|
|
62
|
+
const attachment = state.context.attachment;
|
|
63
|
+
return typeof attachment === "object" && attachment !== null && scopeRoot in attachment ? attachment : undefined;
|
|
64
|
+
}
|
|
65
|
+
function noContainer() {
|
|
66
|
+
throw new Error("No active container. This API requires construction, disposal, withContainer(), an execution bound to ContainerKey, or a ScopeHost attachment.");
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The container ambient to this call, in precedence order: the one currently
|
|
70
|
+
* constructing, an explicit `ContainerKey` binding, then the scope host.
|
|
71
|
+
*
|
|
72
|
+
* On a host, `create` decides what a missing scope means: a caller that may
|
|
73
|
+
* register into the container needs the scope to exist; a caller that only
|
|
74
|
+
* resolves does not, because a scope resolves through its root anyway.
|
|
75
|
+
*/ function ambientContainer(create) {
|
|
58
76
|
const constructing = activeContainer.getStore();
|
|
59
77
|
if (constructing) {
|
|
60
78
|
return constructing;
|
|
61
79
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (!bound) {
|
|
66
|
-
throw new Error("No active container. This API requires construction, disposal, withContainer(), or an execution bound to ContainerKey.");
|
|
80
|
+
const state = peekState();
|
|
81
|
+
if (!state) {
|
|
82
|
+
noContainer();
|
|
67
83
|
}
|
|
68
|
-
|
|
84
|
+
const bound = state.context.values.get(ContainerKey.id);
|
|
85
|
+
if (bound) {
|
|
86
|
+
return bound;
|
|
87
|
+
}
|
|
88
|
+
const host = hostOf(state);
|
|
89
|
+
if (!host) {
|
|
90
|
+
noContainer();
|
|
91
|
+
}
|
|
92
|
+
if (create) {
|
|
93
|
+
return host[executionScope] ??= host[scopeRoot].child();
|
|
94
|
+
}
|
|
95
|
+
return host[executionScope] ?? host[scopeRoot];
|
|
96
|
+
}
|
|
97
|
+
/** The ambient container, created on a host if it does not exist yet. */ function currentContainer() {
|
|
98
|
+
return ambientContainer(true);
|
|
69
99
|
}
|
|
70
|
-
/** Resolve a dependency
|
|
71
|
-
return
|
|
100
|
+
/** Resolve a dependency in the ambient container without creating a host's scope. */ function inject(token) {
|
|
101
|
+
return ambientContainer(false).resolve(token);
|
|
72
102
|
}
|
|
73
103
|
/** Acquire a resource once per container and release it when that container closes. */ function scoped(token, factory, dispose) {
|
|
74
104
|
return currentContainer().use(token, factory, dispose);
|
|
@@ -624,11 +654,13 @@ var __webpack_exports__DisposalConflictError = __webpack_exports__.uP;
|
|
|
624
654
|
var __webpack_exports__ProviderConflictError = __webpack_exports__.kb;
|
|
625
655
|
var __webpack_exports__ResolutionError = __webpack_exports__.fe;
|
|
626
656
|
var __webpack_exports__currentContainer = __webpack_exports__.zt;
|
|
657
|
+
var __webpack_exports__executionScope = __webpack_exports__.pZ;
|
|
627
658
|
var __webpack_exports__inject = __webpack_exports__.WQ;
|
|
628
659
|
var __webpack_exports__onDispose = __webpack_exports__.zp;
|
|
660
|
+
var __webpack_exports__scopeRoot = __webpack_exports__.Vz;
|
|
629
661
|
var __webpack_exports__scoped = __webpack_exports__.P1;
|
|
630
662
|
var __webpack_exports__token = __webpack_exports__.Sh;
|
|
631
663
|
var __webpack_exports__withContainer = __webpack_exports__.Ub;
|
|
632
|
-
export { __webpack_exports__Container as Container, __webpack_exports__ContainerClosedError as ContainerClosedError, __webpack_exports__ContainerKey as ContainerKey, __webpack_exports__DisposalConflictError as DisposalConflictError, __webpack_exports__ProviderConflictError as ProviderConflictError, __webpack_exports__ResolutionError as ResolutionError, __webpack_exports__currentContainer as currentContainer, __webpack_exports__inject as inject, __webpack_exports__onDispose as onDispose, __webpack_exports__scoped as scoped, __webpack_exports__token as token, __webpack_exports__withContainer as withContainer };
|
|
664
|
+
export { __webpack_exports__Container as Container, __webpack_exports__ContainerClosedError as ContainerClosedError, __webpack_exports__ContainerKey as ContainerKey, __webpack_exports__DisposalConflictError as DisposalConflictError, __webpack_exports__ProviderConflictError as ProviderConflictError, __webpack_exports__ResolutionError as ResolutionError, __webpack_exports__currentContainer as currentContainer, __webpack_exports__executionScope as executionScope, __webpack_exports__inject as inject, __webpack_exports__onDispose as onDispose, __webpack_exports__scopeRoot as scopeRoot, __webpack_exports__scoped as scoped, __webpack_exports__token as token, __webpack_exports__withContainer as withContainer };
|
|
633
665
|
|
|
634
666
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["webpack://@tiberjs/di/webpack/runtime/define_property_getters","webpack://@tiberjs/di/webpack/runtime/has_own_property","webpack://@tiberjs/di/./src/resources/active-container.ts","webpack://@tiberjs/di/./src/ambient.ts","webpack://@tiberjs/di/./src/tokens.ts","webpack://@tiberjs/di/./src/errors.ts","webpack://@tiberjs/di/./src/resolution/graph.ts","webpack://@tiberjs/di/./src/resolution/path.ts","webpack://@tiberjs/di/./src/resolution/providers.ts","webpack://@tiberjs/di/./src/resources/cleanup.ts","webpack://@tiberjs/di/./src/resources/queue.ts","webpack://@tiberjs/di/./src/resources/owner.ts","webpack://@tiberjs/di/./src/resources/ownership.ts","webpack://@tiberjs/di/./src/container.ts","webpack://@tiberjs/di/./src/index.ts"],"sourcesContent":["__webpack_require__.d = (exports, getters, values) => {\n\tvar define = (defs, kind) => {\n\t\tfor(var key in defs) {\n\t\t\tif(__webpack_require__.o(defs, key) && !__webpack_require__.o(exports, key)) {\n\t\t\t\tObject.defineProperty(exports, key, { enumerable: true, [kind]: defs[key] });\n\t\t\t}\n\t\t}\n\t};\n\tdefine(getters, \"get\");\n\tdefine(values, \"value\");\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","import { AsyncLocalStorage } from \"node:async_hooks\";\nimport type { Container } from \"../container.js\";\n\n/**\n * The container bound as ambient while one of its resources is constructed or\n * torn down. Nested construction overrides it for the inner call only.\n */\nexport const activeContainer = new AsyncLocalStorage<Container>();\n","import { contextKey, peekState, provide, withContext, type ContextKey } from \"@tiberjs/runner\";\nimport type { Container } from \"./container.js\";\nimport { activeContainer } from \"./resources/active-container.js\";\nimport type { Factory, InjectionToken } from \"./tokens.js\";\n\n/** The execution-context binding that carries a container across executions. */\nexport const ContainerKey: ContextKey<Container> = contextKey<Container>(\"di.container\");\n\n/** Construction container first, otherwise the current execution's binding. */\nexport function currentContainer(): Container {\n const constructing = activeContainer.getStore();\n if (constructing) {\n return constructing;\n }\n\n // One state read and one frame walk: inject() runs on request paths, and a\n // bound container is never undefined, so absence needs no separate probe.\n const bound = peekState()?.context.values.get(ContainerKey.id) as Container | undefined;\n if (!bound) {\n throw new Error(\n \"No active container. This API requires construction, disposal, withContainer(), or an execution bound to ContainerKey.\",\n );\n }\n\n return bound;\n}\n\n/** Resolve a dependency during construction or inside a bound execution. */\nexport function inject<T>(token: InjectionToken<T>): T {\n return currentContainer().resolve(token);\n}\n\n/** Acquire a resource once per container and release it when that container closes. */\nexport function scoped<T>(\n token: InjectionToken<T>,\n factory: Factory<T>,\n dispose?: (value: T) => unknown | Promise<unknown>,\n): T {\n return currentContainer().use(token, factory, dispose);\n}\n\n/** Register LIFO cleanup in the ambient container. */\nexport function onDispose(cleanup: () => unknown | Promise<unknown>): void {\n currentContainer().defer(cleanup);\n}\n\n/**\n * Bind `container` as the ambient container for `handler`.\n *\n * The binding is always installed locally, so nested calls override an outer\n * construction container. With an active execution it is additionally published\n * on the context so derived executions observe the same container.\n */\nexport function withContainer<T>(container: Container, handler: () => T): T {\n if (peekState()) {\n return withContext([provide(ContainerKey, container)], () =>\n activeContainer.run(container, handler),\n );\n }\n\n return activeContainer.run(container, handler);\n}\n","import type { Container } from \"./container.js\";\n\n/** A zero-argument constructor usable as its own injection token. */\nexport type Constructor<T = object> = new (...args: never[]) => T;\n\n/** An opaque token for values/interfaces that have no runtime class. */\nexport interface Token<T> {\n readonly key: symbol;\n /** Phantom carrier; never present at runtime. */\n readonly _type?: T;\n}\n\nexport type InjectionToken<T> = Constructor<T> | Token<T>;\nexport type Factory<T> = (container: Container) => T;\n\nexport function token<T>(description: string): Token<T> {\n return { key: Symbol(description) };\n}\n\nexport function describeToken(token: InjectionToken<unknown>): string {\n if (typeof token === \"function\") {\n return token.name || \"anonymous class\";\n }\n\n return token.key.description ?? \"token\";\n}\n","import { describeToken, type InjectionToken } from \"./tokens.js\";\n\n/** A container resolution failure; provider exceptions propagate unchanged. */\nexport class ResolutionError extends Error {\n constructor(\n readonly reason: \"missing-provider\" | \"circular-dependency\",\n readonly token: InjectionToken<unknown>,\n options?: ErrorOptions,\n ) {\n super(\n reason === \"missing-provider\"\n ? `No provider registered for token \"${describeToken(token)}\". Use provide(token, factory) for values/interfaces.`\n : `Circular dependency while resolving \"${describeToken(token)}\".`,\n options,\n );\n this.name = \"ResolutionError\";\n }\n}\n\n/** Resource admission failed because this container's teardown has begun. */\nexport class ContainerClosedError extends Error {\n constructor(\n readonly state: \"closing\" | \"disposed\",\n options?: ErrorOptions,\n ) {\n super(state === \"closing\" ? \"Container is closing.\" : \"Container has been disposed.\", options);\n this.name = \"ContainerClosedError\";\n }\n}\n\n/** A provider cannot replace an instance this container has already handed out. */\nexport class ProviderConflictError extends Error {\n constructor(readonly token: InjectionToken<unknown>) {\n super(\n `\"${describeToken(token)}\" is already resolved in this container. Register providers before resolving, or override the token in a child container.`,\n );\n this.name = \"ProviderConflictError\";\n }\n}\n\n/** An object must have exactly one disposal owner and one automatic close protocol. */\nexport class DisposalConflictError extends Error {\n constructor(readonly reason: \"multiple-hooks\" | \"already-owned\") {\n super(\n reason === \"multiple-hooks\"\n ? \"ContainerObject.onClose cannot coexist with Symbol.asyncDispose or Symbol.dispose.\"\n : \"An explicit disposer cannot take ownership of an already-owned resource.\",\n );\n this.name = \"DisposalConflictError\";\n }\n}\n","import { describeToken, type InjectionToken } from \"../tokens.js\";\nimport type { ResolutionFrame } from \"./path.js\";\n\n/** The root container's resolution attempts: `from` resolves `to`. */\nexport interface ResolutionGraph {\n readonly nodes: ReadonlyArray<{ readonly id: number; readonly name: string }>;\n readonly edges: ReadonlyArray<{ readonly from: number; readonly to: number }>;\n}\n\n/**\n * Root-local resolution diagnostics. Node identity is per container, and both\n * edge directions are indexed so removing a disposed container costs its own\n * nodes rather than a full scan.\n */\nexport class ResolutionTracker {\n #nextId = 0;\n readonly #idsByOwner = new WeakMap<object, Map<InjectionToken<unknown>, number>>();\n readonly #nodes = new Map<number, string>();\n readonly #outgoing = new Map<number, Set<number>>();\n readonly #incoming = new Map<number, Set<number>>();\n\n /** Records a resolution as a dependency of the construction that requested it. */\n record(owner: object, token: InjectionToken<unknown>, parent?: ResolutionFrame): void {\n let ids = this.#idsByOwner.get(owner);\n if (!ids) {\n this.#idsByOwner.set(owner, (ids = new Map()));\n }\n\n let id = ids.get(token);\n if (id === undefined) {\n id = this.#nextId++;\n ids.set(token, id);\n this.#nodes.set(id, describeToken(token));\n }\n\n // A node never depends on itself, and a removed owner's frame links nothing.\n if (parent && (parent.owner !== owner || parent.token !== token)) {\n const from = this.#idsByOwner.get(parent.owner)?.get(parent.token);\n if (from !== undefined) {\n this.#link(from, id);\n }\n }\n }\n\n snapshot(): ResolutionGraph {\n const edges: Array<{ from: number; to: number }> = [];\n for (const [from, targets] of this.#outgoing) {\n for (const to of targets) {\n edges.push({ from, to });\n }\n }\n\n return { nodes: Array.from(this.#nodes, ([id, name]) => ({ id, name })), edges };\n }\n\n /** Drops a disposed owner's nodes and every edge that touched them. */\n remove(owner: object): void {\n const ids = this.#idsByOwner.get(owner);\n if (!ids) {\n return;\n }\n\n for (const id of ids.values()) {\n this.#nodes.delete(id);\n this.#unlink(id);\n }\n\n this.#idsByOwner.delete(owner);\n }\n\n #link(from: number, to: number): void {\n let targets = this.#outgoing.get(from);\n if (!targets) {\n this.#outgoing.set(from, (targets = new Set()));\n }\n targets.add(to);\n\n let sources = this.#incoming.get(to);\n if (!sources) {\n this.#incoming.set(to, (sources = new Set()));\n }\n sources.add(from);\n }\n\n #unlink(id: number): void {\n const targets = this.#outgoing.get(id);\n if (targets) {\n for (const to of targets) {\n this.#detach(this.#incoming, to, id);\n }\n this.#outgoing.delete(id);\n }\n\n const sources = this.#incoming.get(id);\n if (sources) {\n for (const from of sources) {\n this.#detach(this.#outgoing, from, id);\n }\n this.#incoming.delete(id);\n }\n }\n\n #detach(index: Map<number, Set<number>>, node: number, peer: number): void {\n const peers = index.get(node);\n if (peers?.delete(peer) && peers.size === 0) {\n index.delete(node);\n }\n }\n}\n","import { ResolutionError } from \"../errors.js\";\nimport type { InjectionToken } from \"../tokens.js\";\n\n/** One construction in flight: `owner` is building `token` right now. */\nexport interface ResolutionFrame {\n readonly owner: object;\n readonly token: InjectionToken<unknown>;\n}\n\n/**\n * The chain of constructions in flight under one container tree, newest last.\n *\n * A frame is a container and a token together, so the same token may be in\n * flight in two containers while a child decorates an ancestor's\n * implementation; only a container re-entering its own token is a cycle.\n */\nexport class ResolutionPath {\n readonly #frames: ResolutionFrame[] = [];\n\n /** The construction that whatever resolves next belongs to. */\n get current(): ResolutionFrame | undefined {\n return this.#frames[this.#frames.length - 1];\n }\n\n /** Rejects a container that re-enters a token it is already constructing. */\n enter(owner: object, token: InjectionToken<unknown>): void {\n for (const frame of this.#frames) {\n if (frame.owner === owner && frame.token === token) {\n throw new ResolutionError(\"circular-dependency\", token);\n }\n }\n\n this.#frames.push({ owner, token });\n }\n\n /** A failed attempt leaves no trace, so the token stays resolvable. */\n exit(): void {\n this.#frames.pop();\n }\n}\n","import { ProviderConflictError } from \"../errors.js\";\nimport type { Factory, InjectionToken } from \"../tokens.js\";\n\n/** One container's providers and the instances it has constructed. */\nexport class ProviderRegistry {\n #factories: Map<InjectionToken<unknown>, Factory<unknown>> | undefined;\n #instances: Map<InjectionToken<unknown>, unknown> | undefined;\n\n /** Whether this container has ever cached an instance of its own. */\n get hasInstances(): boolean {\n return this.#instances !== undefined;\n }\n\n /** An explicit provider or a cached instance, never a constructibility probe. */\n has(token: InjectionToken<unknown>): boolean {\n return (this.#instances?.has(token) ?? false) || (this.#factories?.has(token) ?? false);\n }\n\n /** Distinguishes a cached `undefined` from a missing instance. */\n hasInstance(token: InjectionToken<unknown>): boolean {\n return this.#instances?.has(token) ?? false;\n }\n\n instance<T>(token: InjectionToken<T>): T {\n return this.#instances?.get(token) as T;\n }\n\n hasFactory(token: InjectionToken<unknown>): boolean {\n return this.#factories?.has(token) ?? false;\n }\n\n factory<T>(token: InjectionToken<T>): Factory<T> | undefined {\n return this.#factories?.get(token) as Factory<T> | undefined;\n }\n\n /**\n * Replacing a factory whose instance this container already handed out is\n * rejected: the cached instance would silently win. Override in a child.\n */\n provide<T>(token: InjectionToken<T>, factory: Factory<T>): void {\n if (this.#instances?.has(token)) {\n throw new ProviderConflictError(token);\n }\n (this.#factories ??= new Map()).set(token, factory as Factory<unknown>);\n }\n\n cache(token: InjectionToken<unknown>, value: unknown): void {\n (this.#instances ??= new Map()).set(token, value);\n }\n\n /** Disposal makes the container unusable, so its storage is released. */\n clear(): void {\n this.#factories = undefined;\n this.#instances = undefined;\n }\n}\n","import { DisposalConflictError } from \"../errors.js\";\n\n/** Releases one resource; a returned promise is awaited during disposal. */\nexport type Cleanup = () => unknown | Promise<unknown>;\n\n/** Structural resource hook. Do not combine onClose with a symbol disposer. */\nexport interface ContainerObject {\n onClose?(): unknown | Promise<unknown>;\n}\n\n/**\n * How a constructed value is released, plus the conflict that must reject it.\n *\n * A conflicting shape still yields `cleanup`: the caller registers it to roll\n * back an object it will never hand out, then throws `conflict`.\n */\nexport interface CleanupPlan {\n readonly cleanup: Cleanup | undefined;\n readonly conflict: DisposalConflictError | undefined;\n}\n\n/**\n * Precedence is explicit disposer, then `Symbol.asyncDispose`/`Symbol.dispose`,\n * then `ContainerObject.onClose`. `onClose` beside a symbol disposer is\n * ambiguous and refused, unless an explicit disposer overrides both shapes.\n */\nexport function planCleanup<T>(\n value: T,\n explicitDispose?: (value: T) => unknown | Promise<unknown>,\n): CleanupPlan {\n const asyncDispose = (value as Partial<AsyncDisposable>)[Symbol.asyncDispose];\n const dispose = (value as Partial<Disposable>)[Symbol.dispose];\n const onClose = (value as ContainerObject).onClose;\n const symbolDispose = typeof asyncDispose === \"function\" ? asyncDispose : dispose;\n\n const cleanup = explicitDispose\n ? () => explicitDispose(value)\n : typeof symbolDispose === \"function\"\n ? () => symbolDispose.call(value)\n : typeof onClose === \"function\"\n ? () => onClose.call(value)\n : undefined;\n const conflict =\n !explicitDispose && typeof onClose === \"function\" && typeof symbolDispose === \"function\"\n ? new DisposalConflictError(\"multiple-hooks\")\n : undefined;\n\n return { cleanup, conflict };\n}\n","import { combinedError } from \"@tiberjs/runner\";\nimport { ContainerClosedError } from \"../errors.js\";\nimport type { Cleanup } from \"./cleanup.js\";\n\n/** Runs one cleanup callback with the owner's ambient binding installed. */\nexport type CleanupInvoker = (cleanup: Cleanup) => unknown;\n\n/**\n * LIFO cleanup storage for one owner, drained once. Knows nothing about\n * containers: every callback runs through the invoker its owner supplied.\n */\nexport class DisposalQueue {\n #cleanups: Cleanup[] | undefined;\n #drained = false;\n\n constructor(private readonly invoke: CleanupInvoker) {}\n\n /** Cleanup registered while draining is drained too; after that nothing would run it. */\n defer(cleanup: Cleanup): void {\n if (this.#drained) {\n throw new ContainerClosedError(\"disposed\");\n }\n (this.#cleanups ??= []).push(cleanup);\n }\n\n /** Drains in reverse registration order, retaining independent failures. */\n async close(): Promise<void> {\n // Yield past a synchronous factory that initiated disposal before returning its resource.\n await Promise.resolve();\n\n const errors: unknown[] = [];\n while (this.#cleanups?.length) {\n try {\n await this.invoke(this.#cleanups.pop()!);\n } catch (error) {\n errors.push(error);\n }\n }\n\n this.#drained = true;\n this.#cleanups = undefined;\n\n // Independent failures keep their identity, in drain order.\n if (errors.length) {\n throw combinedError(errors, \"Errors during disposal.\");\n }\n }\n}\n","import type { Container } from \"../container.js\";\nimport { DisposalConflictError } from \"../errors.js\";\nimport { activeContainer } from \"./active-container.js\";\nimport { type Cleanup, planCleanup } from \"./cleanup.js\";\nimport type { OwnershipRegistry } from \"./ownership.js\";\nimport { DisposalQueue } from \"./queue.js\";\n\n/**\n * The resources one container owns: it binds the ambient container around\n * construction and teardown, claims each constructed value at most once, and\n * releases what it claimed in LIFO order.\n */\nexport class ResourceOwner {\n readonly #queue: DisposalQueue;\n\n constructor(\n private readonly container: Container,\n private readonly ownership: OwnershipRegistry,\n ) {\n this.#queue = new DisposalQueue((cleanup) => activeContainer.run(container, cleanup));\n }\n\n /** Only the queue knows whether it already drained, so admission is its call. */\n defer(cleanup: Cleanup): void {\n this.#queue.defer(cleanup);\n }\n\n /** Construct with ambient resolution bound, then take disposal ownership. */\n construct<T>(\n factory: (container: Container) => T,\n dispose?: (value: T) => unknown | Promise<unknown>,\n ): T {\n const value = activeContainer.run(this.container, factory, this.container);\n this.#adopt(value, dispose);\n\n return value;\n }\n\n /** Once drained, this owner is responsible for nothing it claimed. */\n close(): Promise<void> {\n return this.#queue.close().finally(() => this.ownership.release(this));\n }\n\n #adopt<T>(value: T, explicitDispose?: (value: T) => unknown | Promise<unknown>): void {\n if (value === null || (typeof value !== \"object\" && typeof value !== \"function\")) {\n if (explicitDispose) {\n this.defer(() => explicitDispose(value));\n }\n return;\n }\n\n const target = value as object;\n if (this.ownership.hasLiveOwner(target)) {\n // An alias of a live resource borrows it; a second disposer would double-release.\n if (explicitDispose) {\n throw new DisposalConflictError(\"already-owned\");\n }\n return;\n }\n\n const plan = planCleanup(value, explicitDispose);\n if (plan.cleanup) {\n this.defer(plan.cleanup);\n this.ownership.claim(target, this);\n }\n // Registered cleanup above survives refusal, because the value is never returned.\n if (plan.conflict) {\n this.ownership.reject(target, plan.conflict);\n throw plan.conflict;\n }\n }\n}\n","/** A permanently refused value, boxed so it is never mistaken for an owner. */\nclass Rejection {\n constructor(readonly error: unknown) {}\n}\n\n// Keyed by root so surviving children share ownership without initializing a\n// closed ancestor's resources.\nconst registriesByRoot = new WeakMap<object, OwnershipRegistry>();\n\n/** At most one disposal owner per object, shared across one container tree. */\nexport class OwnershipRegistry {\n readonly #entries = new WeakMap<object, object>();\n readonly #drained = new WeakSet<object>();\n\n /** Every container descending from `root` claims into the same registry. */\n static forRoot(root: object): OwnershipRegistry {\n let registry = registriesByRoot.get(root);\n if (!registry) {\n registriesByRoot.set(root, (registry = new OwnershipRegistry()));\n }\n\n return registry;\n }\n\n /**\n * Whether someone is still responsible for releasing `value`; an owner that\n * already drained leaves it adoptable again. Rethrows a refused shape's\n * cached rejection so every later alias of that object fails identically.\n */\n hasLiveOwner(value: object): boolean {\n const entry = this.#entries.get(value);\n if (entry instanceof Rejection) {\n throw entry.error;\n }\n\n return entry !== undefined && !this.#drained.has(entry);\n }\n\n claim(value: object, owner: object): void {\n this.#entries.set(value, owner);\n }\n\n /** `owner` finished its cleanup: every value it claimed is unowned again. */\n release(owner: object): void {\n this.#drained.add(owner);\n }\n\n /** Refusal is permanent: `value` can never gain a disposal owner afterwards. */\n reject(value: object, error: unknown): void {\n this.#entries.set(value, new Rejection(error));\n }\n}\n","import { ContainerClosedError, ResolutionError } from \"./errors.js\";\nimport { ResolutionTracker, type ResolutionGraph } from \"./resolution/graph.js\";\nimport { ResolutionPath } from \"./resolution/path.js\";\nimport { ProviderRegistry } from \"./resolution/providers.js\";\nimport { ResourceOwner } from \"./resources/owner.js\";\nimport { OwnershipRegistry } from \"./resources/ownership.js\";\nimport type { Factory, InjectionToken } from \"./tokens.js\";\n\ntype ContainerPhase = \"open\" | \"closing\" | \"disposed\";\n\n/**\n * A hierarchical dependency container and resource owner. A child resolves its\n * ancestors' providers but owns and disposes only what it constructed itself.\n */\nexport class Container {\n readonly #parent: Container | undefined;\n readonly #root: Container;\n readonly #providers = new ProviderRegistry();\n readonly #path: ResolutionPath;\n /** Diagnostics live on the root; a child records into its root's tracker. */\n #graph: ResolutionTracker | undefined;\n #resources: ResourceOwner | undefined;\n #disposal: Promise<void> | undefined;\n #phase: ContainerPhase = \"open\";\n\n constructor(parent?: Container) {\n this.#parent = parent;\n this.#root = parent ? parent.#root : this;\n this.#path = parent ? parent.#path : new ResolutionPath();\n }\n\n get #owner(): ResourceOwner {\n if (!this.#resources) {\n // A drained container must not build an owner whose queue nothing drains.\n this.#admitRetainedAccess();\n this.#resources = new ResourceOwner(this, OwnershipRegistry.forRoot(this.#root));\n }\n return this.#resources;\n }\n\n /** Undefined once the root is gone, so a surviving child cannot repopulate it. */\n get #tracker(): ResolutionTracker | undefined {\n if (this.#root.#phase === \"disposed\") {\n return undefined;\n }\n\n return (this.#root.#graph ??= new ResolutionTracker());\n }\n\n /** A child container resolves application singletons through its parent. */\n child(): Container {\n this.#admitNewAcquisition();\n return new Container(this);\n }\n\n /** Includes failed attempts and active children, but never disposed containers. */\n resolutionGraph(): ResolutionGraph {\n return this.#root.#graph?.snapshot() ?? { nodes: [], edges: [] };\n }\n\n /** Register a provider before the token is resolved here. */\n provide<T>(token: InjectionToken<T>, factory: Factory<T>): void {\n this.#admitNewAcquisition();\n this.#providers.provide(token, factory);\n }\n\n has(token: InjectionToken<unknown>): boolean {\n return this.#providers.has(token) || (this.#parent?.has(token) ?? false);\n }\n\n /** Resolve local cache/provider, then ancestors; default classes live at root. */\n resolve<T>(token: InjectionToken<T>): T {\n if (this.#providers.hasInstance(token)) {\n this.#admitRetainedAccess();\n this.#tracker?.record(this, token, this.#path.current);\n\n return this.#providers.instance(token);\n }\n\n // Ancestors own their own admission; a closing child may still read singletons.\n if (!this.#providers.hasFactory(token) && this.#parent) {\n this.#admitRetainedAccess();\n return this.#parent.resolve(token);\n }\n\n this.#admitNewAcquisition();\n\n return this.#acquire(token, () => {\n const factory = this.#providers.factory(token);\n if (factory) {\n return factory(this);\n }\n if (typeof token === \"function\") {\n return new token();\n }\n\n throw new ResolutionError(\"missing-provider\", token);\n });\n }\n\n /**\n * Acquire inline resources once per container, with explicit or automatic\n * disposal. Like a provider factory, `factory` receives this container.\n */\n use<T>(\n token: InjectionToken<T>,\n factory: Factory<T>,\n dispose?: (value: T) => unknown | Promise<unknown>,\n ): T {\n if (this.#providers.hasInstance(token)) {\n this.#admitRetainedAccess();\n this.#tracker?.record(this, token, this.#path.current);\n\n return this.#providers.instance(token);\n }\n\n this.#admitNewAcquisition();\n\n return this.#acquire(token, factory, dispose);\n }\n\n /**\n * Register LIFO cleanup. Blind to the phase on purpose: a resource released\n * mid-drain may still register its own cleanup, and only the queue knows\n * whether anything is left to run it.\n */\n defer(cleanup: () => unknown | Promise<unknown>): void {\n this.#owner.defer(cleanup);\n }\n\n /**\n * Close a container that never constructed or deferred anything, avoiding an\n * `await`. Returns `false` and changes nothing otherwise.\n */\n disposeSync(): boolean {\n if (this.#resources || this.#providers.hasInstances) {\n return false;\n }\n if (this.#phase !== \"disposed\") {\n this.#clearResolution();\n }\n return true;\n }\n\n /** Close acquisition synchronously, then clear resolution storage after teardown. */\n [Symbol.asyncDispose](): Promise<void> {\n if (this.#phase === \"open\") {\n this.#phase = \"closing\";\n this.#disposal = this.#owner.close().finally(() => {\n this.#clearResolution();\n });\n }\n\n return (this.#disposal ??= Promise.resolve());\n }\n\n /** Reading what this container already holds stays legal until it is disposed. */\n #admitRetainedAccess(): void {\n if (this.#phase === \"disposed\") {\n throw new ContainerClosedError(\"disposed\");\n }\n }\n\n /** Providers, children, and construction stop the moment teardown begins. */\n #admitNewAcquisition(): void {\n const phase = this.#phase;\n if (phase !== \"open\") {\n throw new ContainerClosedError(phase);\n }\n }\n\n #clearResolution(): void {\n this.#phase = \"disposed\";\n this.#providers.clear();\n\n if (this === this.#root) {\n this.#graph = undefined;\n } else {\n this.#root.#graph?.remove(this);\n }\n }\n\n #acquire<T>(\n token: InjectionToken<T>,\n factory: Factory<T>,\n dispose?: (value: T) => unknown | Promise<unknown>,\n ): T {\n // A cycle is still an attempt worth reporting, so record before guarding.\n this.#tracker?.record(this, token, this.#path.current);\n this.#path.enter(this, token);\n\n try {\n const value = this.#owner.construct(factory, dispose);\n this.#providers.cache(token, value);\n\n return value;\n } finally {\n this.#path.exit();\n }\n }\n}\n","/** Hierarchical dependency resolution and resource ownership. */\n\nexport {\n ContainerKey,\n currentContainer,\n inject,\n onDispose,\n scoped,\n withContainer,\n} from \"./ambient.js\";\nexport type { ContainerObject } from \"./resources/cleanup.js\";\nexport { Container } from \"./container.js\";\nexport {\n ContainerClosedError,\n DisposalConflictError,\n ProviderConflictError,\n ResolutionError,\n} from \"./errors.js\";\nexport type { ResolutionGraph } from \"./resolution/graph.js\";\nexport { token } from \"./tokens.js\";\nexport type { Constructor, Factory, InjectionToken, Token } from \"./tokens.js\";\n"],"names":["AsyncLocalStorage","activeContainer","contextKey","peekState","provide","withContext","ContainerKey","currentContainer","constructing","bound","Error","inject","token","scoped","factory","dispose","onDispose","cleanup","withContainer","container","handler","description","Symbol","describeToken","ResolutionError","reason","options","ContainerClosedError","state","ProviderConflictError","DisposalConflictError","ResolutionTracker","WeakMap","Map","owner","parent","ids","id","undefined","from","edges","targets","to","Array","name","Set","sources","index","node","peer","peers","ResolutionPath","frame","ProviderRegistry","value","planCleanup","explicitDispose","asyncDispose","onClose","symbolDispose","conflict","combinedError","DisposalQueue","invoke","Promise","errors","error","ResourceOwner","ownership","target","plan","Rejection","registriesByRoot","OwnershipRegistry","WeakSet","root","registry","entry","Container","phase"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA,0CAA0C,qCAAqC;AAC/E;AACA;AACA;AACA;AACA;AACA,E;;;;ACVA,wF;;;;;;;;;;;;;;;;;;;;;;;;;ACAqD;AAGrD;;;CAGC,GACM,MAAMC,kBAAkB,IAAID,iBAAiBA,GAAc;;;ACP6B;AAE7B;AAGlE,8EAA8E,GACvE,MAAMM,eAAsCJ,UAAUA,CAAY,gBAAgB;AAEzF,6EAA6E,GACtE,SAASK;IACd,MAAMC,eAAeP,wBAAwB;IAC7C,IAAIO,cAAc;QAChB,OAAOA;IACT;IAEA,2EAA2E;IAC3E,0EAA0E;IAC1E,MAAMC,QAAQN,SAASA,IAAI,QAAQ,OAAO,IAAIG,aAAa,EAAE;IAC7D,IAAI,CAACG,OAAO;QACV,MAAM,IAAIC,M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AE7B,OAAOA;QACT,SAAU;YACR,IAAI,CAAC,KAAK,CAAC,IAAI;QACjB;IACF;AACF;;;ACxMA,+DAA+D,GASzC;AAEqB;AAMtB;AAEe"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["webpack://@tiberjs/di/webpack/runtime/define_property_getters","webpack://@tiberjs/di/webpack/runtime/has_own_property","webpack://@tiberjs/di/./src/resources/active-container.ts","webpack://@tiberjs/di/./src/ambient.ts","webpack://@tiberjs/di/./src/tokens.ts","webpack://@tiberjs/di/./src/errors.ts","webpack://@tiberjs/di/./src/resolution/graph.ts","webpack://@tiberjs/di/./src/resolution/path.ts","webpack://@tiberjs/di/./src/resolution/providers.ts","webpack://@tiberjs/di/./src/resources/cleanup.ts","webpack://@tiberjs/di/./src/resources/queue.ts","webpack://@tiberjs/di/./src/resources/owner.ts","webpack://@tiberjs/di/./src/resources/ownership.ts","webpack://@tiberjs/di/./src/container.ts","webpack://@tiberjs/di/./src/index.ts"],"sourcesContent":["__webpack_require__.d = (exports, getters, values) => {\n\tvar define = (defs, kind) => {\n\t\tfor(var key in defs) {\n\t\t\tif(__webpack_require__.o(defs, key) && !__webpack_require__.o(exports, key)) {\n\t\t\t\tObject.defineProperty(exports, key, { enumerable: true, [kind]: defs[key] });\n\t\t\t}\n\t\t}\n\t};\n\tdefine(getters, \"get\");\n\tdefine(values, \"value\");\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","import { AsyncLocalStorage } from \"node:async_hooks\";\nimport type { Container } from \"../container.js\";\n\n/**\n * The container bound as ambient while one of its resources is constructed or\n * torn down. Nested construction overrides it for the inner call only.\n */\nexport const activeContainer = new AsyncLocalStorage<Container>();\n","import { contextKey, peekState, provide, withContext, type ContextKey } from \"@tiberjs/runner\";\nimport type { RuntimeState } from \"@tiberjs/runner\";\nimport type { Container } from \"./container.js\";\nimport { activeContainer } from \"./resources/active-container.js\";\nimport type { Factory, InjectionToken } from \"./tokens.js\";\n\n/** The execution-context binding that carries a container across executions. */\nexport const ContainerKey: ContextKey<Container> = contextKey<Container>(\"di.container\");\n\n/** The root a host's execution scope is created from. */\nexport const scopeRoot: unique symbol = Symbol(\"di.scope-root\");\n/** The execution scope itself, created on the host the first time it is needed. */\nexport const executionScope: unique symbol = Symbol(\"di.execution-scope\");\n\n/**\n * A runner attachment that hosts one execution's scope.\n *\n * The host declares `[scopeRoot]`; the scope is `root.child()`, created on\n * the host by the first `currentContainer()`, `scoped()`, or `onDispose()`\n * and disposed by whoever owns the host. An execution that only resolves\n * through `inject()` never creates one. An explicit `ContainerKey` binding\n * takes precedence over the host.\n */\nexport interface ScopeHost {\n readonly [scopeRoot]: Container;\n [executionScope]?: Container;\n}\n\n/** A host is recognized by the declared slot, not by whether a scope exists yet. */\nfunction hostOf(state: RuntimeState): ScopeHost | undefined {\n const attachment = state.context.attachment;\n return typeof attachment === \"object\" && attachment !== null && scopeRoot in attachment\n ? (attachment as ScopeHost)\n : undefined;\n}\n\nfunction noContainer(): never {\n throw new Error(\n \"No active container. This API requires construction, disposal, withContainer(), an execution bound to ContainerKey, or a ScopeHost attachment.\",\n );\n}\n\n/**\n * The container ambient to this call, in precedence order: the one currently\n * constructing, an explicit `ContainerKey` binding, then the scope host.\n *\n * On a host, `create` decides what a missing scope means: a caller that may\n * register into the container needs the scope to exist; a caller that only\n * resolves does not, because a scope resolves through its root anyway.\n */\nfunction ambientContainer(create: boolean): Container {\n const constructing = activeContainer.getStore();\n if (constructing) {\n return constructing;\n }\n const state = peekState();\n if (!state) {\n noContainer();\n }\n const bound = state.context.values.get(ContainerKey.id) as Container | undefined;\n if (bound) {\n return bound;\n }\n const host = hostOf(state);\n if (!host) {\n noContainer();\n }\n if (create) {\n return (host[executionScope] ??= host[scopeRoot].child());\n }\n return host[executionScope] ?? host[scopeRoot];\n}\n\n/** The ambient container, created on a host if it does not exist yet. */\nexport function currentContainer(): Container {\n return ambientContainer(true);\n}\n\n/** Resolve a dependency in the ambient container without creating a host's scope. */\nexport function inject<T>(token: InjectionToken<T>): T {\n return ambientContainer(false).resolve(token);\n}\n\n/** Acquire a resource once per container and release it when that container closes. */\nexport function scoped<T>(\n token: InjectionToken<T>,\n factory: Factory<T>,\n dispose?: (value: T) => unknown | Promise<unknown>,\n): T {\n return currentContainer().use(token, factory, dispose);\n}\n\n/** Register LIFO cleanup in the ambient container. */\nexport function onDispose(cleanup: () => unknown | Promise<unknown>): void {\n currentContainer().defer(cleanup);\n}\n\n/**\n * Bind `container` as the ambient container for `handler`.\n *\n * The binding is always installed locally, so nested calls override an outer\n * construction container. With an active execution it is additionally published\n * on the context so derived executions observe the same container.\n */\nexport function withContainer<T>(container: Container, handler: () => T): T {\n if (peekState()) {\n return withContext([provide(ContainerKey, container)], () =>\n activeContainer.run(container, handler),\n );\n }\n\n return activeContainer.run(container, handler);\n}\n","import type { Container } from \"./container.js\";\n\n/** A zero-argument constructor usable as its own injection token. */\nexport type Constructor<T = object> = new (...args: never[]) => T;\n\n/** An opaque token for values/interfaces that have no runtime class. */\nexport interface Token<T> {\n readonly key: symbol;\n /** Phantom carrier; never present at runtime. */\n readonly _type?: T;\n}\n\nexport type InjectionToken<T> = Constructor<T> | Token<T>;\nexport type Factory<T> = (container: Container) => T;\n\nexport function token<T>(description: string): Token<T> {\n return { key: Symbol(description) };\n}\n\nexport function describeToken(token: InjectionToken<unknown>): string {\n if (typeof token === \"function\") {\n return token.name || \"anonymous class\";\n }\n\n return token.key.description ?? \"token\";\n}\n","import { describeToken, type InjectionToken } from \"./tokens.js\";\n\n/** A container resolution failure; provider exceptions propagate unchanged. */\nexport class ResolutionError extends Error {\n constructor(\n readonly reason: \"missing-provider\" | \"circular-dependency\",\n readonly token: InjectionToken<unknown>,\n options?: ErrorOptions,\n ) {\n super(\n reason === \"missing-provider\"\n ? `No provider registered for token \"${describeToken(token)}\". Use provide(token, factory) for values/interfaces.`\n : `Circular dependency while resolving \"${describeToken(token)}\".`,\n options,\n );\n this.name = \"ResolutionError\";\n }\n}\n\n/** Resource admission failed because this container's teardown has begun. */\nexport class ContainerClosedError extends Error {\n constructor(\n readonly state: \"closing\" | \"disposed\",\n options?: ErrorOptions,\n ) {\n super(state === \"closing\" ? \"Container is closing.\" : \"Container has been disposed.\", options);\n this.name = \"ContainerClosedError\";\n }\n}\n\n/** A provider cannot replace an instance this container has already handed out. */\nexport class ProviderConflictError extends Error {\n constructor(readonly token: InjectionToken<unknown>) {\n super(\n `\"${describeToken(token)}\" is already resolved in this container. Register providers before resolving, or override the token in a child container.`,\n );\n this.name = \"ProviderConflictError\";\n }\n}\n\n/** An object must have exactly one disposal owner and one automatic close protocol. */\nexport class DisposalConflictError extends Error {\n constructor(readonly reason: \"multiple-hooks\" | \"already-owned\") {\n super(\n reason === \"multiple-hooks\"\n ? \"ContainerObject.onClose cannot coexist with Symbol.asyncDispose or Symbol.dispose.\"\n : \"An explicit disposer cannot take ownership of an already-owned resource.\",\n );\n this.name = \"DisposalConflictError\";\n }\n}\n","import { describeToken, type InjectionToken } from \"../tokens.js\";\nimport type { ResolutionFrame } from \"./path.js\";\n\n/** The root container's resolution attempts: `from` resolves `to`. */\nexport interface ResolutionGraph {\n readonly nodes: ReadonlyArray<{ readonly id: number; readonly name: string }>;\n readonly edges: ReadonlyArray<{ readonly from: number; readonly to: number }>;\n}\n\n/**\n * Root-local resolution diagnostics. Node identity is per container, and both\n * edge directions are indexed so removing a disposed container costs its own\n * nodes rather than a full scan.\n */\nexport class ResolutionTracker {\n #nextId = 0;\n readonly #idsByOwner = new WeakMap<object, Map<InjectionToken<unknown>, number>>();\n readonly #nodes = new Map<number, string>();\n readonly #outgoing = new Map<number, Set<number>>();\n readonly #incoming = new Map<number, Set<number>>();\n\n /** Records a resolution as a dependency of the construction that requested it. */\n record(owner: object, token: InjectionToken<unknown>, parent?: ResolutionFrame): void {\n let ids = this.#idsByOwner.get(owner);\n if (!ids) {\n this.#idsByOwner.set(owner, (ids = new Map()));\n }\n\n let id = ids.get(token);\n if (id === undefined) {\n id = this.#nextId++;\n ids.set(token, id);\n this.#nodes.set(id, describeToken(token));\n }\n\n // A node never depends on itself, and a removed owner's frame links nothing.\n if (parent && (parent.owner !== owner || parent.token !== token)) {\n const from = this.#idsByOwner.get(parent.owner)?.get(parent.token);\n if (from !== undefined) {\n this.#link(from, id);\n }\n }\n }\n\n snapshot(): ResolutionGraph {\n const edges: Array<{ from: number; to: number }> = [];\n for (const [from, targets] of this.#outgoing) {\n for (const to of targets) {\n edges.push({ from, to });\n }\n }\n\n return { nodes: Array.from(this.#nodes, ([id, name]) => ({ id, name })), edges };\n }\n\n /** Drops a disposed owner's nodes and every edge that touched them. */\n remove(owner: object): void {\n const ids = this.#idsByOwner.get(owner);\n if (!ids) {\n return;\n }\n\n for (const id of ids.values()) {\n this.#nodes.delete(id);\n this.#unlink(id);\n }\n\n this.#idsByOwner.delete(owner);\n }\n\n #link(from: number, to: number): void {\n let targets = this.#outgoing.get(from);\n if (!targets) {\n this.#outgoing.set(from, (targets = new Set()));\n }\n targets.add(to);\n\n let sources = this.#incoming.get(to);\n if (!sources) {\n this.#incoming.set(to, (sources = new Set()));\n }\n sources.add(from);\n }\n\n #unlink(id: number): void {\n const targets = this.#outgoing.get(id);\n if (targets) {\n for (const to of targets) {\n this.#detach(this.#incoming, to, id);\n }\n this.#outgoing.delete(id);\n }\n\n const sources = this.#incoming.get(id);\n if (sources) {\n for (const from of sources) {\n this.#detach(this.#outgoing, from, id);\n }\n this.#incoming.delete(id);\n }\n }\n\n #detach(index: Map<number, Set<number>>, node: number, peer: number): void {\n const peers = index.get(node);\n if (peers?.delete(peer) && peers.size === 0) {\n index.delete(node);\n }\n }\n}\n","import { ResolutionError } from \"../errors.js\";\nimport type { InjectionToken } from \"../tokens.js\";\n\n/** One construction in flight: `owner` is building `token` right now. */\nexport interface ResolutionFrame {\n readonly owner: object;\n readonly token: InjectionToken<unknown>;\n}\n\n/**\n * The chain of constructions in flight under one container tree, newest last.\n *\n * A frame is a container and a token together, so the same token may be in\n * flight in two containers while a child decorates an ancestor's\n * implementation; only a container re-entering its own token is a cycle.\n */\nexport class ResolutionPath {\n readonly #frames: ResolutionFrame[] = [];\n\n /** The construction that whatever resolves next belongs to. */\n get current(): ResolutionFrame | undefined {\n return this.#frames[this.#frames.length - 1];\n }\n\n /** Rejects a container that re-enters a token it is already constructing. */\n enter(owner: object, token: InjectionToken<unknown>): void {\n for (const frame of this.#frames) {\n if (frame.owner === owner && frame.token === token) {\n throw new ResolutionError(\"circular-dependency\", token);\n }\n }\n\n this.#frames.push({ owner, token });\n }\n\n /** A failed attempt leaves no trace, so the token stays resolvable. */\n exit(): void {\n this.#frames.pop();\n }\n}\n","import { ProviderConflictError } from \"../errors.js\";\nimport type { Factory, InjectionToken } from \"../tokens.js\";\n\n/** One container's providers and the instances it has constructed. */\nexport class ProviderRegistry {\n #factories: Map<InjectionToken<unknown>, Factory<unknown>> | undefined;\n #instances: Map<InjectionToken<unknown>, unknown> | undefined;\n\n /** Whether this container has ever cached an instance of its own. */\n get hasInstances(): boolean {\n return this.#instances !== undefined;\n }\n\n /** An explicit provider or a cached instance, never a constructibility probe. */\n has(token: InjectionToken<unknown>): boolean {\n return (this.#instances?.has(token) ?? false) || (this.#factories?.has(token) ?? false);\n }\n\n /** Distinguishes a cached `undefined` from a missing instance. */\n hasInstance(token: InjectionToken<unknown>): boolean {\n return this.#instances?.has(token) ?? false;\n }\n\n instance<T>(token: InjectionToken<T>): T {\n return this.#instances?.get(token) as T;\n }\n\n hasFactory(token: InjectionToken<unknown>): boolean {\n return this.#factories?.has(token) ?? false;\n }\n\n factory<T>(token: InjectionToken<T>): Factory<T> | undefined {\n return this.#factories?.get(token) as Factory<T> | undefined;\n }\n\n /**\n * Replacing a factory whose instance this container already handed out is\n * rejected: the cached instance would silently win. Override in a child.\n */\n provide<T>(token: InjectionToken<T>, factory: Factory<T>): void {\n if (this.#instances?.has(token)) {\n throw new ProviderConflictError(token);\n }\n (this.#factories ??= new Map()).set(token, factory as Factory<unknown>);\n }\n\n cache(token: InjectionToken<unknown>, value: unknown): void {\n (this.#instances ??= new Map()).set(token, value);\n }\n\n /** Disposal makes the container unusable, so its storage is released. */\n clear(): void {\n this.#factories = undefined;\n this.#instances = undefined;\n }\n}\n","import { DisposalConflictError } from \"../errors.js\";\n\n/** Releases one resource; a returned promise is awaited during disposal. */\nexport type Cleanup = () => unknown | Promise<unknown>;\n\n/** Structural resource hook. Do not combine onClose with a symbol disposer. */\nexport interface ContainerObject {\n onClose?(): unknown | Promise<unknown>;\n}\n\n/**\n * How a constructed value is released, plus the conflict that must reject it.\n *\n * A conflicting shape still yields `cleanup`: the caller registers it to roll\n * back an object it will never hand out, then throws `conflict`.\n */\nexport interface CleanupPlan {\n readonly cleanup: Cleanup | undefined;\n readonly conflict: DisposalConflictError | undefined;\n}\n\n/**\n * Precedence is explicit disposer, then `Symbol.asyncDispose`/`Symbol.dispose`,\n * then `ContainerObject.onClose`. `onClose` beside a symbol disposer is\n * ambiguous and refused, unless an explicit disposer overrides both shapes.\n */\nexport function planCleanup<T>(\n value: T,\n explicitDispose?: (value: T) => unknown | Promise<unknown>,\n): CleanupPlan {\n const asyncDispose = (value as Partial<AsyncDisposable>)[Symbol.asyncDispose];\n const dispose = (value as Partial<Disposable>)[Symbol.dispose];\n const onClose = (value as ContainerObject).onClose;\n const symbolDispose = typeof asyncDispose === \"function\" ? asyncDispose : dispose;\n\n const cleanup = explicitDispose\n ? () => explicitDispose(value)\n : typeof symbolDispose === \"function\"\n ? () => symbolDispose.call(value)\n : typeof onClose === \"function\"\n ? () => onClose.call(value)\n : undefined;\n const conflict =\n !explicitDispose && typeof onClose === \"function\" && typeof symbolDispose === \"function\"\n ? new DisposalConflictError(\"multiple-hooks\")\n : undefined;\n\n return { cleanup, conflict };\n}\n","import { combinedError } from \"@tiberjs/runner\";\nimport { ContainerClosedError } from \"../errors.js\";\nimport type { Cleanup } from \"./cleanup.js\";\n\n/** Runs one cleanup callback with the owner's ambient binding installed. */\nexport type CleanupInvoker = (cleanup: Cleanup) => unknown;\n\n/**\n * LIFO cleanup storage for one owner, drained once. Knows nothing about\n * containers: every callback runs through the invoker its owner supplied.\n */\nexport class DisposalQueue {\n #cleanups: Cleanup[] | undefined;\n #drained = false;\n\n constructor(private readonly invoke: CleanupInvoker) {}\n\n /** Cleanup registered while draining is drained too; after that nothing would run it. */\n defer(cleanup: Cleanup): void {\n if (this.#drained) {\n throw new ContainerClosedError(\"disposed\");\n }\n (this.#cleanups ??= []).push(cleanup);\n }\n\n /** Drains in reverse registration order, retaining independent failures. */\n async close(): Promise<void> {\n // Yield past a synchronous factory that initiated disposal before returning its resource.\n await Promise.resolve();\n\n const errors: unknown[] = [];\n while (this.#cleanups?.length) {\n try {\n await this.invoke(this.#cleanups.pop()!);\n } catch (error) {\n errors.push(error);\n }\n }\n\n this.#drained = true;\n this.#cleanups = undefined;\n\n // Independent failures keep their identity, in drain order.\n if (errors.length) {\n throw combinedError(errors, \"Errors during disposal.\");\n }\n }\n}\n","import type { Container } from \"../container.js\";\nimport { DisposalConflictError } from \"../errors.js\";\nimport { activeContainer } from \"./active-container.js\";\nimport { type Cleanup, planCleanup } from \"./cleanup.js\";\nimport type { OwnershipRegistry } from \"./ownership.js\";\nimport { DisposalQueue } from \"./queue.js\";\n\n/**\n * The resources one container owns: it binds the ambient container around\n * construction and teardown, claims each constructed value at most once, and\n * releases what it claimed in LIFO order.\n */\nexport class ResourceOwner {\n readonly #queue: DisposalQueue;\n\n constructor(\n private readonly container: Container,\n private readonly ownership: OwnershipRegistry,\n ) {\n this.#queue = new DisposalQueue((cleanup) => activeContainer.run(container, cleanup));\n }\n\n /** Only the queue knows whether it already drained, so admission is its call. */\n defer(cleanup: Cleanup): void {\n this.#queue.defer(cleanup);\n }\n\n /** Construct with ambient resolution bound, then take disposal ownership. */\n construct<T>(\n factory: (container: Container) => T,\n dispose?: (value: T) => unknown | Promise<unknown>,\n ): T {\n const value = activeContainer.run(this.container, factory, this.container);\n this.#adopt(value, dispose);\n\n return value;\n }\n\n /** Once drained, this owner is responsible for nothing it claimed. */\n close(): Promise<void> {\n return this.#queue.close().finally(() => this.ownership.release(this));\n }\n\n #adopt<T>(value: T, explicitDispose?: (value: T) => unknown | Promise<unknown>): void {\n if (value === null || (typeof value !== \"object\" && typeof value !== \"function\")) {\n if (explicitDispose) {\n this.defer(() => explicitDispose(value));\n }\n return;\n }\n\n const target = value as object;\n if (this.ownership.hasLiveOwner(target)) {\n // An alias of a live resource borrows it; a second disposer would double-release.\n if (explicitDispose) {\n throw new DisposalConflictError(\"already-owned\");\n }\n return;\n }\n\n const plan = planCleanup(value, explicitDispose);\n if (plan.cleanup) {\n this.defer(plan.cleanup);\n this.ownership.claim(target, this);\n }\n // Registered cleanup above survives refusal, because the value is never returned.\n if (plan.conflict) {\n this.ownership.reject(target, plan.conflict);\n throw plan.conflict;\n }\n }\n}\n","/** A permanently refused value, boxed so it is never mistaken for an owner. */\nclass Rejection {\n constructor(readonly error: unknown) {}\n}\n\n// Keyed by root so surviving children share ownership without initializing a\n// closed ancestor's resources.\nconst registriesByRoot = new WeakMap<object, OwnershipRegistry>();\n\n/** At most one disposal owner per object, shared across one container tree. */\nexport class OwnershipRegistry {\n readonly #entries = new WeakMap<object, object>();\n readonly #drained = new WeakSet<object>();\n\n /** Every container descending from `root` claims into the same registry. */\n static forRoot(root: object): OwnershipRegistry {\n let registry = registriesByRoot.get(root);\n if (!registry) {\n registriesByRoot.set(root, (registry = new OwnershipRegistry()));\n }\n\n return registry;\n }\n\n /**\n * Whether someone is still responsible for releasing `value`; an owner that\n * already drained leaves it adoptable again. Rethrows a refused shape's\n * cached rejection so every later alias of that object fails identically.\n */\n hasLiveOwner(value: object): boolean {\n const entry = this.#entries.get(value);\n if (entry instanceof Rejection) {\n throw entry.error;\n }\n\n return entry !== undefined && !this.#drained.has(entry);\n }\n\n claim(value: object, owner: object): void {\n this.#entries.set(value, owner);\n }\n\n /** `owner` finished its cleanup: every value it claimed is unowned again. */\n release(owner: object): void {\n this.#drained.add(owner);\n }\n\n /** Refusal is permanent: `value` can never gain a disposal owner afterwards. */\n reject(value: object, error: unknown): void {\n this.#entries.set(value, new Rejection(error));\n }\n}\n","import { ContainerClosedError, ResolutionError } from \"./errors.js\";\nimport { ResolutionTracker, type ResolutionGraph } from \"./resolution/graph.js\";\nimport { ResolutionPath } from \"./resolution/path.js\";\nimport { ProviderRegistry } from \"./resolution/providers.js\";\nimport { ResourceOwner } from \"./resources/owner.js\";\nimport { OwnershipRegistry } from \"./resources/ownership.js\";\nimport type { Factory, InjectionToken } from \"./tokens.js\";\n\ntype ContainerPhase = \"open\" | \"closing\" | \"disposed\";\n\n/**\n * A hierarchical dependency container and resource owner. A child resolves its\n * ancestors' providers but owns and disposes only what it constructed itself.\n */\nexport class Container {\n readonly #parent: Container | undefined;\n readonly #root: Container;\n readonly #providers = new ProviderRegistry();\n readonly #path: ResolutionPath;\n /** Diagnostics live on the root; a child records into its root's tracker. */\n #graph: ResolutionTracker | undefined;\n #resources: ResourceOwner | undefined;\n #disposal: Promise<void> | undefined;\n #phase: ContainerPhase = \"open\";\n\n constructor(parent?: Container) {\n this.#parent = parent;\n this.#root = parent ? parent.#root : this;\n this.#path = parent ? parent.#path : new ResolutionPath();\n }\n\n get #owner(): ResourceOwner {\n if (!this.#resources) {\n // A drained container must not build an owner whose queue nothing drains.\n this.#admitRetainedAccess();\n this.#resources = new ResourceOwner(this, OwnershipRegistry.forRoot(this.#root));\n }\n return this.#resources;\n }\n\n /** Undefined once the root is gone, so a surviving child cannot repopulate it. */\n get #tracker(): ResolutionTracker | undefined {\n if (this.#root.#phase === \"disposed\") {\n return undefined;\n }\n\n return (this.#root.#graph ??= new ResolutionTracker());\n }\n\n /** A child container resolves application singletons through its parent. */\n child(): Container {\n this.#admitNewAcquisition();\n return new Container(this);\n }\n\n /** Includes failed attempts and active children, but never disposed containers. */\n resolutionGraph(): ResolutionGraph {\n return this.#root.#graph?.snapshot() ?? { nodes: [], edges: [] };\n }\n\n /** Register a provider before the token is resolved here. */\n provide<T>(token: InjectionToken<T>, factory: Factory<T>): void {\n this.#admitNewAcquisition();\n this.#providers.provide(token, factory);\n }\n\n has(token: InjectionToken<unknown>): boolean {\n return this.#providers.has(token) || (this.#parent?.has(token) ?? false);\n }\n\n /** Resolve local cache/provider, then ancestors; default classes live at root. */\n resolve<T>(token: InjectionToken<T>): T {\n if (this.#providers.hasInstance(token)) {\n this.#admitRetainedAccess();\n this.#tracker?.record(this, token, this.#path.current);\n\n return this.#providers.instance(token);\n }\n\n // Ancestors own their own admission; a closing child may still read singletons.\n if (!this.#providers.hasFactory(token) && this.#parent) {\n this.#admitRetainedAccess();\n return this.#parent.resolve(token);\n }\n\n this.#admitNewAcquisition();\n\n return this.#acquire(token, () => {\n const factory = this.#providers.factory(token);\n if (factory) {\n return factory(this);\n }\n if (typeof token === \"function\") {\n return new token();\n }\n\n throw new ResolutionError(\"missing-provider\", token);\n });\n }\n\n /**\n * Acquire inline resources once per container, with explicit or automatic\n * disposal. Like a provider factory, `factory` receives this container.\n */\n use<T>(\n token: InjectionToken<T>,\n factory: Factory<T>,\n dispose?: (value: T) => unknown | Promise<unknown>,\n ): T {\n if (this.#providers.hasInstance(token)) {\n this.#admitRetainedAccess();\n this.#tracker?.record(this, token, this.#path.current);\n\n return this.#providers.instance(token);\n }\n\n this.#admitNewAcquisition();\n\n return this.#acquire(token, factory, dispose);\n }\n\n /**\n * Register LIFO cleanup. Blind to the phase on purpose: a resource released\n * mid-drain may still register its own cleanup, and only the queue knows\n * whether anything is left to run it.\n */\n defer(cleanup: () => unknown | Promise<unknown>): void {\n this.#owner.defer(cleanup);\n }\n\n /**\n * Close a container that never constructed or deferred anything, avoiding an\n * `await`. Returns `false` and changes nothing otherwise.\n */\n disposeSync(): boolean {\n if (this.#resources || this.#providers.hasInstances) {\n return false;\n }\n if (this.#phase !== \"disposed\") {\n this.#clearResolution();\n }\n return true;\n }\n\n /** Close acquisition synchronously, then clear resolution storage after teardown. */\n [Symbol.asyncDispose](): Promise<void> {\n if (this.#phase === \"open\") {\n this.#phase = \"closing\";\n this.#disposal = this.#owner.close().finally(() => {\n this.#clearResolution();\n });\n }\n\n return (this.#disposal ??= Promise.resolve());\n }\n\n /** Reading what this container already holds stays legal until it is disposed. */\n #admitRetainedAccess(): void {\n if (this.#phase === \"disposed\") {\n throw new ContainerClosedError(\"disposed\");\n }\n }\n\n /** Providers, children, and construction stop the moment teardown begins. */\n #admitNewAcquisition(): void {\n const phase = this.#phase;\n if (phase !== \"open\") {\n throw new ContainerClosedError(phase);\n }\n }\n\n #clearResolution(): void {\n this.#phase = \"disposed\";\n this.#providers.clear();\n\n if (this === this.#root) {\n this.#graph = undefined;\n } else {\n this.#root.#graph?.remove(this);\n }\n }\n\n #acquire<T>(\n token: InjectionToken<T>,\n factory: Factory<T>,\n dispose?: (value: T) => unknown | Promise<unknown>,\n ): T {\n // A cycle is still an attempt worth reporting, so record before guarding.\n this.#tracker?.record(this, token, this.#path.current);\n this.#path.enter(this, token);\n\n try {\n const value = this.#owner.construct(factory, dispose);\n this.#providers.cache(token, value);\n\n return value;\n } finally {\n this.#path.exit();\n }\n }\n}\n","/** Hierarchical dependency resolution and resource ownership. */\n\nexport {\n ContainerKey,\n currentContainer,\n executionScope,\n inject,\n onDispose,\n scoped,\n scopeRoot,\n withContainer,\n} from \"./ambient.js\";\nexport type { ScopeHost } from \"./ambient.js\";\nexport type { ContainerObject } from \"./resources/cleanup.js\";\nexport { Container } from \"./container.js\";\nexport {\n ContainerClosedError,\n DisposalConflictError,\n ProviderConflictError,\n ResolutionError,\n} from \"./errors.js\";\nexport type { ResolutionGraph } from \"./resolution/graph.js\";\nexport { token } from \"./tokens.js\";\nexport type { Constructor, Factory, InjectionToken, Token } from \"./tokens.js\";\n"],"names":["AsyncLocalStorage","activeContainer","contextKey","peekState","provide","withContext","ContainerKey","scopeRoot","Symbol","executionScope","hostOf","state","attachment","undefined","noContainer","Error","ambientContainer","create","constructing","bound","host","currentContainer","inject","token","scoped","factory","dispose","onDispose","cleanup","withContainer","container","handler","description","describeToken","ResolutionError","reason","options","ContainerClosedError","ProviderConflictError","DisposalConflictError","ResolutionTracker","WeakMap","Map","owner","parent","ids","id","from","edges","targets","to","Array","name","Set","sources","index","node","peer","peers","ResolutionPath","frame","ProviderRegistry","value","planCleanup","explicitDispose","asyncDispose","onClose","symbolDispose","conflict","combinedError","DisposalQueue","invoke","Promise","errors","error","ResourceOwner","ownership","target","plan","Rejection","registriesByRoot","OwnershipRegistry","WeakSet","root","registry","entry","Container","phase"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA,0CAA0C,qCAAqC;AAC/E;AACA;AACA;AACA;AACA;AACA,E;;;;ACVA,wF;;;;;;;;;;;;;;;;;;;;;;;;;;;ACAqD;AAGrD;;;CAGC,GACM,MAAMC,kBAAkB,IAAID,iBAAiBA,GAAc;;;ACP6B;AAG7B;AAGlE,8EAA8E,GACvE,MAAMM,eAAsCJ,UAAUA,CAAY,gBAAgB;AAEzF,uDAAuD,GAChD,MAAMK,YAA2BC,OAAO,iBAAiB;AAChE,iFAAiF,GAC1E,MAAMC,iBAAgCD,OAAO,sBAAsB;AAgB1E,kFAAkF,GAClF,SAASE,OAAOC,KAAmB;IACjC,MAAMC,aAAaD,MAAM,OAAO,CAAC,UAAU;IAC3C,OAAO,OAAOC,eAAe,YAAYA,eAAe,QAAQL,aAAaK,aACxEA,aACDC;AACN;AAEA,SAASC;IACP,MAAM,IAAIC,MACR;AAEJ;AAEA;;;;;;;CAOC,GACD,SAASC,iBAAiBC,MAAe;IACvC,MAAMC,eAAejB,wBAAwB;IAC7C,IAAIiB,cAAc;QAChB,OAAOA;IACT;IACA,MAAMP,QAAQR,SAASA;IACvB,IAAI,CAACQ,OAAO;QACVG;IACF;IACA,MAAMK,QAAQR,MAAM,OAAO,CAAC,MAAM,CAAC,GAAG,CAACL,aAAa,EAAE;IACtD,IAAIa,OAAO;QACT,OAAOA;IACT;IACA,MAAMC,OAAOV,OAAOC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,EAAE,OAAO,IAAI,EAAEH,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO;QACrD,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAEA;QAEvB,IAAI;YACF,MAAMuC,QAAQ,IAAI,CAAC,MAAM,CAAC,SAAS,CAACrC,SAASC;YAC7C,IAAI,CAAC,UAAU,CAAC,KAAK,CAACH,OAAOuC;YAE7B,OAAOA;QACT,SAAU;YACR,IAAI,CAAC,KAAK,CAAC,IAAI;QACjB;IACF;AACF;;;ACxMA,+DAA+D,GAWzC;AAGqB;AAMtB;AAEe"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiberjs/di",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Hierarchical dependency container and resource ownership for tiberjs.",
|
|
5
5
|
"author": "miinhho",
|
|
6
6
|
"type": "module",
|
|
@@ -8,16 +8,28 @@
|
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
+
"tiberjs-source": "./src/index.ts",
|
|
11
12
|
"types": "./dist/index.d.ts",
|
|
12
13
|
"import": "./dist/index.js"
|
|
13
14
|
}
|
|
14
15
|
},
|
|
15
16
|
"publishConfig": {
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
16
23
|
"access": "public"
|
|
17
24
|
},
|
|
18
25
|
"files": [
|
|
19
26
|
"dist"
|
|
20
27
|
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "rspack build --config ../../rspack.config.mjs && tsc -p tsconfig.build.json",
|
|
30
|
+
"typecheck": "tsc --noEmit",
|
|
31
|
+
"test": "pnpm -w exec vitest run --project @tiberjs/di"
|
|
32
|
+
},
|
|
21
33
|
"dependencies": {
|
|
22
34
|
"@tiberjs/runner": "^0.3.0"
|
|
23
35
|
},
|
|
@@ -28,10 +40,5 @@
|
|
|
28
40
|
},
|
|
29
41
|
"engines": {
|
|
30
42
|
"node": ">=24"
|
|
31
|
-
},
|
|
32
|
-
"scripts": {
|
|
33
|
-
"build": "rspack build --config ../../rspack.config.mjs && tsc -p tsconfig.build.json",
|
|
34
|
-
"typecheck": "tsc --noEmit",
|
|
35
|
-
"test": "pnpm -w exec vitest run --project @tiberjs/di"
|
|
36
43
|
}
|
|
37
|
-
}
|
|
44
|
+
}
|