@codefast/di 0.5.0-canary.5 → 0.5.0-canary.7

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.
Files changed (214) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/README.md +73 -496
  3. package/dist/binding.d.ts +211 -0
  4. package/dist/binding.d.ts.map +1 -0
  5. package/dist/binding.js +46 -0
  6. package/dist/binding.js.map +1 -0
  7. package/dist/{constructor-type.d.mts → constructor-type.d.ts} +3 -5
  8. package/dist/constructor-type.d.ts.map +1 -0
  9. package/dist/constructor-type.js +2 -0
  10. package/dist/constructor-type.js.map +1 -0
  11. package/dist/container/binding-builders.d.ts +35 -0
  12. package/dist/container/binding-builders.d.ts.map +1 -0
  13. package/dist/container/binding-builders.js +247 -0
  14. package/dist/container/binding-builders.js.map +1 -0
  15. package/dist/container/container.d.ts +58 -0
  16. package/dist/container/container.d.ts.map +1 -0
  17. package/dist/container/container.js +641 -0
  18. package/dist/container/container.js.map +1 -0
  19. package/dist/decorators/inject.d.ts +57 -0
  20. package/dist/decorators/inject.d.ts.map +1 -0
  21. package/dist/decorators/inject.js +145 -0
  22. package/dist/decorators/inject.js.map +1 -0
  23. package/dist/decorators/injectable.d.ts +29 -0
  24. package/dist/decorators/injectable.d.ts.map +1 -0
  25. package/dist/decorators/injectable.js +53 -0
  26. package/dist/decorators/injectable.js.map +1 -0
  27. package/dist/decorators/lifecycle-decorators.d.ts +9 -0
  28. package/dist/decorators/lifecycle-decorators.d.ts.map +1 -0
  29. package/dist/decorators/lifecycle-decorators.js +40 -0
  30. package/dist/decorators/lifecycle-decorators.js.map +1 -0
  31. package/dist/errors.d.ts +150 -0
  32. package/dist/errors.d.ts.map +1 -0
  33. package/dist/errors.js +197 -0
  34. package/dist/errors.js.map +1 -0
  35. package/dist/index.d.ts +30 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +25 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/introspection/dependency-graph.d.ts +40 -0
  40. package/dist/introspection/dependency-graph.d.ts.map +1 -0
  41. package/dist/introspection/dependency-graph.js +66 -0
  42. package/dist/introspection/dependency-graph.js.map +1 -0
  43. package/dist/introspection/graph-adapters/cytoscape.d.ts +33 -0
  44. package/dist/introspection/graph-adapters/cytoscape.d.ts.map +1 -0
  45. package/dist/introspection/graph-adapters/cytoscape.js +30 -0
  46. package/dist/introspection/graph-adapters/cytoscape.js.map +1 -0
  47. package/dist/introspection/graph-adapters/dot.d.ts +6 -0
  48. package/dist/introspection/graph-adapters/dot.d.ts.map +1 -0
  49. package/dist/introspection/graph-adapters/dot.js +18 -0
  50. package/dist/introspection/graph-adapters/dot.js.map +1 -0
  51. package/dist/introspection/graph-adapters/reactflow.d.ts +38 -0
  52. package/dist/introspection/graph-adapters/reactflow.d.ts.map +1 -0
  53. package/dist/introspection/graph-adapters/reactflow.js +33 -0
  54. package/dist/introspection/graph-adapters/reactflow.js.map +1 -0
  55. package/dist/introspection/inspector.d.ts +39 -0
  56. package/dist/introspection/inspector.d.ts.map +1 -0
  57. package/dist/introspection/inspector.js +82 -0
  58. package/dist/introspection/inspector.js.map +1 -0
  59. package/dist/metadata/{metadata-keys.d.mts → metadata-keys.d.ts} +5 -7
  60. package/dist/metadata/metadata-keys.d.ts.map +1 -0
  61. package/dist/metadata/metadata-keys.js +25 -0
  62. package/dist/metadata/metadata-keys.js.map +1 -0
  63. package/dist/metadata/metadata-reader-token.d.ts +7 -0
  64. package/dist/metadata/metadata-reader-token.d.ts.map +1 -0
  65. package/dist/metadata/metadata-reader-token.js +6 -0
  66. package/dist/metadata/metadata-reader-token.js.map +1 -0
  67. package/dist/metadata/metadata-types.d.ts +48 -0
  68. package/dist/metadata/metadata-types.d.ts.map +1 -0
  69. package/dist/metadata/metadata-types.js +2 -0
  70. package/dist/metadata/metadata-types.js.map +1 -0
  71. package/dist/metadata/symbol-metadata-reader.d.ts +20 -0
  72. package/dist/metadata/symbol-metadata-reader.d.ts.map +1 -0
  73. package/dist/metadata/symbol-metadata-reader.js +34 -0
  74. package/dist/metadata/symbol-metadata-reader.js.map +1 -0
  75. package/dist/module.d.ts +67 -0
  76. package/dist/module.d.ts.map +1 -0
  77. package/dist/module.js +54 -0
  78. package/dist/module.js.map +1 -0
  79. package/dist/registry.d.ts +33 -0
  80. package/dist/registry.d.ts.map +1 -0
  81. package/dist/registry.js +249 -0
  82. package/dist/registry.js.map +1 -0
  83. package/dist/resolution/binding-scope.d.ts +10 -0
  84. package/dist/resolution/binding-scope.d.ts.map +1 -0
  85. package/dist/resolution/binding-scope.js +24 -0
  86. package/dist/resolution/binding-scope.js.map +1 -0
  87. package/dist/resolution/binding-select.d.ts +16 -0
  88. package/dist/resolution/binding-select.d.ts.map +1 -0
  89. package/dist/resolution/binding-select.js +143 -0
  90. package/dist/resolution/binding-select.js.map +1 -0
  91. package/dist/resolution/constraints.d.ts +51 -0
  92. package/dist/resolution/constraints.d.ts.map +1 -0
  93. package/dist/resolution/constraints.js +88 -0
  94. package/dist/resolution/constraints.js.map +1 -0
  95. package/dist/resolution/environment.d.ts +47 -0
  96. package/dist/resolution/environment.d.ts.map +1 -0
  97. package/dist/resolution/environment.js +100 -0
  98. package/dist/resolution/environment.js.map +1 -0
  99. package/dist/resolution/instantiation-plan.d.ts +67 -0
  100. package/dist/resolution/instantiation-plan.d.ts.map +1 -0
  101. package/dist/resolution/instantiation-plan.js +163 -0
  102. package/dist/resolution/instantiation-plan.js.map +1 -0
  103. package/dist/resolution/lifecycle.d.ts +21 -0
  104. package/dist/resolution/lifecycle.d.ts.map +1 -0
  105. package/dist/resolution/lifecycle.js +178 -0
  106. package/dist/resolution/lifecycle.js.map +1 -0
  107. package/dist/resolution/resolution-path.d.ts +31 -0
  108. package/dist/resolution/resolution-path.d.ts.map +1 -0
  109. package/dist/resolution/resolution-path.js +53 -0
  110. package/dist/resolution/resolution-path.js.map +1 -0
  111. package/dist/resolution/resolve-options.d.ts +19 -0
  112. package/dist/resolution/resolve-options.d.ts.map +1 -0
  113. package/dist/resolution/resolve-options.js +32 -0
  114. package/dist/resolution/resolve-options.js.map +1 -0
  115. package/dist/resolution/resolver.d.ts +35 -0
  116. package/dist/resolution/resolver.d.ts.map +1 -0
  117. package/dist/resolution/resolver.js +1320 -0
  118. package/dist/resolution/resolver.js.map +1 -0
  119. package/dist/resolution/scope.d.ts +32 -0
  120. package/dist/resolution/scope.d.ts.map +1 -0
  121. package/dist/resolution/scope.js +76 -0
  122. package/dist/resolution/scope.js.map +1 -0
  123. package/dist/token.d.ts +23 -0
  124. package/dist/token.d.ts.map +1 -0
  125. package/dist/token.js +22 -0
  126. package/dist/token.js.map +1 -0
  127. package/dist/types.d.ts +90 -0
  128. package/dist/types.d.ts.map +1 -0
  129. package/dist/types.js +2 -0
  130. package/dist/types.js.map +1 -0
  131. package/package.json +143 -120
  132. package/src/binding.ts +38 -22
  133. package/src/container/binding-builders.ts +397 -0
  134. package/src/container/container.ts +838 -0
  135. package/src/decorators/inject.ts +16 -3
  136. package/src/decorators/injectable.ts +3 -3
  137. package/src/index.ts +14 -7
  138. package/src/{dependency-graph.ts → introspection/dependency-graph.ts} +1 -1
  139. package/src/{graph-adapters → introspection/graph-adapters}/cytoscape.ts +1 -1
  140. package/src/{graph-adapters → introspection/graph-adapters}/dot.ts +1 -1
  141. package/src/{graph-adapters → introspection/graph-adapters}/reactflow.ts +13 -2
  142. package/src/{inspector.ts → introspection/inspector.ts} +26 -21
  143. package/src/metadata/symbol-metadata-reader.ts +4 -4
  144. package/src/module.ts +14 -6
  145. package/src/registry.ts +115 -61
  146. package/src/{binding-select.ts → resolution/binding-select.ts} +16 -3
  147. package/src/{environment.ts → resolution/environment.ts} +35 -35
  148. package/src/resolution/instantiation-plan.ts +240 -0
  149. package/src/{lifecycle.ts → resolution/lifecycle.ts} +20 -13
  150. package/src/resolution/resolution-path.ts +77 -0
  151. package/src/resolution/resolver.ts +1755 -0
  152. package/src/{scope.ts → resolution/scope.ts} +35 -18
  153. package/src/token.ts +0 -3
  154. package/dist/binding-scope.d.mts +0 -13
  155. package/dist/binding-scope.mjs +0 -21
  156. package/dist/binding-select.d.mts +0 -19
  157. package/dist/binding-select.mjs +0 -72
  158. package/dist/binding.d.mts +0 -191
  159. package/dist/binding.mjs +0 -36
  160. package/dist/constraints.d.mts +0 -55
  161. package/dist/constraints.mjs +0 -87
  162. package/dist/constructor-type.mjs +0 -1
  163. package/dist/container.d.mts +0 -62
  164. package/dist/container.mjs +0 -741
  165. package/dist/decorators/inject.d.mts +0 -49
  166. package/dist/decorators/inject.mjs +0 -136
  167. package/dist/decorators/injectable.d.mts +0 -32
  168. package/dist/decorators/injectable.mjs +0 -57
  169. package/dist/decorators/lifecycle-decorators.d.mts +0 -11
  170. package/dist/decorators/lifecycle-decorators.mjs +0 -38
  171. package/dist/dependency-graph.d.mts +0 -43
  172. package/dist/dependency-graph.mjs +0 -63
  173. package/dist/environment.d.mts +0 -55
  174. package/dist/environment.mjs +0 -98
  175. package/dist/errors.d.mts +0 -153
  176. package/dist/errors.mjs +0 -197
  177. package/dist/graph-adapters/cytoscape.d.mts +0 -36
  178. package/dist/graph-adapters/cytoscape.mjs +0 -26
  179. package/dist/graph-adapters/dot.d.mts +0 -9
  180. package/dist/graph-adapters/dot.mjs +0 -20
  181. package/dist/graph-adapters/reactflow.d.mts +0 -41
  182. package/dist/graph-adapters/reactflow.mjs +0 -29
  183. package/dist/index.d.mts +0 -18
  184. package/dist/index.mjs +0 -12
  185. package/dist/inspector.d.mts +0 -48
  186. package/dist/inspector.mjs +0 -71
  187. package/dist/lifecycle.d.mts +0 -25
  188. package/dist/lifecycle.mjs +0 -118
  189. package/dist/metadata/metadata-keys.mjs +0 -27
  190. package/dist/metadata/metadata-reader-token.d.mts +0 -10
  191. package/dist/metadata/metadata-reader-token.mjs +0 -8
  192. package/dist/metadata/metadata-types.d.mts +0 -51
  193. package/dist/metadata/metadata-types.mjs +0 -1
  194. package/dist/metadata/symbol-metadata-reader.d.mts +0 -23
  195. package/dist/metadata/symbol-metadata-reader.mjs +0 -29
  196. package/dist/module.d.mts +0 -62
  197. package/dist/module.mjs +0 -42
  198. package/dist/registry.d.mts +0 -45
  199. package/dist/registry.mjs +0 -163
  200. package/dist/resolve-options.d.mts +0 -22
  201. package/dist/resolve-options.mjs +0 -28
  202. package/dist/resolver.d.mts +0 -94
  203. package/dist/resolver.mjs +0 -767
  204. package/dist/scope.d.mts +0 -28
  205. package/dist/scope.mjs +0 -58
  206. package/dist/token.d.mts +0 -25
  207. package/dist/token.mjs +0 -22
  208. package/dist/types.d.mts +0 -92
  209. package/dist/types.mjs +0 -1
  210. package/src/container.ts +0 -1141
  211. package/src/resolver.ts +0 -1626
  212. /package/src/{binding-scope.ts → resolution/binding-scope.ts} +0 -0
  213. /package/src/{constraints.ts → resolution/constraints.ts} +0 -0
  214. /package/src/{resolve-options.ts → resolution/resolve-options.ts} +0 -0
@@ -1,49 +0,0 @@
1
- import { Constructor } from "../constructor-type.mjs";
2
- import { Token } from "../token.mjs";
3
- import { BindingTag } from "../types.mjs";
4
-
5
- //#region src/decorators/inject.d.ts
6
- /**
7
- * @since 0.3.16-canary.0
8
- */
9
- interface InjectOptions {
10
- name?: string;
11
- tags?: ReadonlyArray<BindingTag>;
12
- }
13
- /**
14
- * @since 0.3.16-canary.0
15
- */
16
- interface InjectionDescriptor<Value = unknown> {
17
- readonly token: Token<Value> | Constructor<Value>;
18
- readonly optional: boolean;
19
- readonly multi: boolean;
20
- readonly name?: string;
21
- readonly tags?: ReadonlyArray<BindingTag>;
22
- }
23
- /**
24
- * @since 0.3.16-canary.0
25
- */
26
- type InjectableDependency<Value = unknown> = Token<Value> | Constructor<Value> | InjectionDescriptor<Value>;
27
- /**
28
- * @since 0.3.16-canary.0
29
- */
30
- declare function isInjectionDescriptor(value: unknown): value is InjectionDescriptor;
31
- /**
32
- * @since 0.3.16-canary.0
33
- */
34
- declare function normalizeToDescriptor(dependency: InjectableDependency): InjectionDescriptor;
35
- type ClassAccessorDecorator<This, Value> = (target: ClassAccessorDecoratorTarget<This, Value>, context: ClassAccessorDecoratorContext<This, Value>) => ClassAccessorDecoratorResult<This, Value> | void;
36
- /**
37
- * @since 0.3.16-canary.0
38
- */
39
- declare function inject<const Value>(token: Token<Value> | Constructor<Value>, options?: InjectOptions): InjectionDescriptor<Value> & ClassAccessorDecorator<unknown, Value>;
40
- /**
41
- * @since 0.3.16-canary.0
42
- */
43
- declare function optional<const Value>(token: Token<Value> | Constructor<Value>, options?: InjectOptions): InjectionDescriptor<Value | undefined>;
44
- /**
45
- * @since 0.3.16-canary.0
46
- */
47
- declare function injectAll<const Value>(token: Token<Value> | Constructor<Value>, options?: InjectOptions): InjectionDescriptor<Array<Value>>;
48
- //#endregion
49
- export { InjectOptions, InjectableDependency, InjectionDescriptor, inject, injectAll, isInjectionDescriptor, normalizeToDescriptor, optional };
@@ -1,136 +0,0 @@
1
- import { InternalError, MissingContainerContextError } from "../errors.mjs";
2
- import { getActiveContainer } from "../environment.mjs";
3
- import { INJECT_ACCESSOR_KEY } from "../metadata/metadata-keys.mjs";
4
- import { injectionSlotToResolveOptions } from "../resolve-options.mjs";
5
- //#region src/decorators/inject.ts
6
- /**
7
- * @since 0.3.16-canary.0
8
- */
9
- function isInjectionDescriptor(value) {
10
- if (value === null || value === void 0) return false;
11
- const type = typeof value;
12
- if (type !== "object" && type !== "function") return false;
13
- return "token" in value && "optional" in value && "multi" in value && typeof value.optional === "boolean" && typeof value.multi === "boolean";
14
- }
15
- /**
16
- * @since 0.3.16-canary.0
17
- */
18
- function normalizeToDescriptor(dependency) {
19
- if (isInjectionDescriptor(dependency)) return materializeInjectionDescriptor(dependency);
20
- return {
21
- token: dependency,
22
- optional: false,
23
- multi: false
24
- };
25
- }
26
- /**
27
- * Dual-role `inject()` values are functions: [[Function]].name must not be treated as a DI slot name.
28
- * Only enumerable own `name` / `tags` from `Object.defineProperties` are real injection options.
29
- */
30
- function materializeInjectionDescriptor(dependency) {
31
- if (typeof dependency !== "function") return dependency;
32
- const dualRole = dependency;
33
- const base = {
34
- token: dualRole.token,
35
- optional: dualRole.optional,
36
- multi: dualRole.multi
37
- };
38
- const nameDesc = Object.getOwnPropertyDescriptor(dualRole, "name");
39
- const tagsDesc = Object.getOwnPropertyDescriptor(dualRole, "tags");
40
- const explicitName = nameDesc?.enumerable === true && typeof nameDesc.value === "string" ? nameDesc.value : void 0;
41
- const explicitTags = tagsDesc?.enumerable === true ? tagsDesc.value : void 0;
42
- if (explicitName !== void 0 && explicitTags !== void 0) return {
43
- ...base,
44
- name: explicitName,
45
- tags: explicitTags
46
- };
47
- if (explicitName !== void 0) return {
48
- ...base,
49
- name: explicitName
50
- };
51
- if (explicitTags !== void 0) return {
52
- ...base,
53
- tags: explicitTags
54
- };
55
- return base;
56
- }
57
- function withOptions(base, options) {
58
- if (options?.name !== void 0 && options.tags !== void 0) return {
59
- ...base,
60
- name: options.name,
61
- tags: options.tags
62
- };
63
- if (options?.name !== void 0) return {
64
- ...base,
65
- name: options.name
66
- };
67
- if (options?.tags !== void 0) return {
68
- ...base,
69
- tags: options.tags
70
- };
71
- return base;
72
- }
73
- function buildInjectionDescriptor(token, options) {
74
- return withOptions({
75
- token,
76
- optional: false,
77
- multi: false
78
- }, options);
79
- }
80
- /**
81
- * @since 0.3.16-canary.0
82
- */
83
- function inject(token, options) {
84
- const descriptor = buildInjectionDescriptor(token, options);
85
- const decoratorFn = (_target, context) => {
86
- if (context.static) throw new InternalError("@inject() on static accessors is not supported; only instance accessors participate in runWithContainer-based property injection.");
87
- const meta = context.metadata;
88
- if (!Array.isArray(meta[INJECT_ACCESSOR_KEY])) meta[INJECT_ACCESSOR_KEY] = [];
89
- meta[INJECT_ACCESSOR_KEY].push({
90
- key: context.name,
91
- descriptor
92
- });
93
- context.addInitializer(function() {
94
- const container = getActiveContainer();
95
- if (container === void 0) throw new MissingContainerContextError(String(context.name));
96
- const resolveOptions = options === void 0 ? void 0 : injectionSlotToResolveOptions({
97
- ...options.name !== void 0 ? { name: options.name } : {},
98
- ...options.tags !== void 0 ? { tags: options.tags } : {}
99
- });
100
- const value = descriptor.optional ? container.resolveOptional(token, resolveOptions) : container.resolve(token, resolveOptions);
101
- context.access.set(this, value);
102
- });
103
- return {};
104
- };
105
- const props = {};
106
- for (const key of Object.keys(descriptor)) props[key] = {
107
- value: descriptor[key],
108
- writable: true,
109
- enumerable: true,
110
- configurable: true
111
- };
112
- Object.defineProperties(decoratorFn, props);
113
- return decoratorFn;
114
- }
115
- /**
116
- * @since 0.3.16-canary.0
117
- */
118
- function optional(token, options) {
119
- return withOptions({
120
- token,
121
- optional: true,
122
- multi: false
123
- }, options);
124
- }
125
- /**
126
- * @since 0.3.16-canary.0
127
- */
128
- function injectAll(token, options) {
129
- return withOptions({
130
- token,
131
- optional: false,
132
- multi: true
133
- }, options);
134
- }
135
- //#endregion
136
- export { inject, injectAll, isInjectionDescriptor, normalizeToDescriptor, optional };
@@ -1,32 +0,0 @@
1
- import { Constructor } from "../constructor-type.mjs";
2
- import { BindingScope } from "../types.mjs";
3
- import { InjectableDependency } from "./inject.mjs";
4
-
5
- //#region src/decorators/injectable.d.ts
6
- /**
7
- * @since 0.3.16-canary.0
8
- */
9
- interface AutoRegisterRegistry {
10
- register(target: Constructor, scope: BindingScope): void;
11
- entries(): ReadonlyArray<{
12
- target: Constructor;
13
- scope: BindingScope;
14
- }>;
15
- }
16
- /**
17
- * @since 0.3.16-canary.0
18
- */
19
- declare function createAutoRegisterRegistry(): AutoRegisterRegistry;
20
- /**
21
- * @since 0.3.16-canary.0
22
- */
23
- interface InjectableOptions {
24
- autoRegister?: AutoRegisterRegistry;
25
- scope?: BindingScope;
26
- }
27
- /**
28
- * @since 0.3.16-canary.0
29
- */
30
- declare function injectable(deps?: ReadonlyArray<InjectableDependency>, options?: InjectableOptions): (target: unknown, context: ClassDecoratorContext) => void;
31
- //#endregion
32
- export { AutoRegisterRegistry, type InjectableDependency, InjectableOptions, createAutoRegisterRegistry, injectable };
@@ -1,57 +0,0 @@
1
- import { INJECTABLE_KEY } from "../metadata/metadata-keys.mjs";
2
- import { normalizeToDescriptor } from "./inject.mjs";
3
- //#region src/decorators/injectable.ts
4
- /**
5
- * @since 0.3.16-canary.0
6
- */
7
- function createAutoRegisterRegistry() {
8
- const _registeredEntries = [];
9
- return {
10
- register(target, scope) {
11
- _registeredEntries.push({
12
- target,
13
- scope
14
- });
15
- },
16
- entries() {
17
- return _registeredEntries;
18
- }
19
- };
20
- }
21
- /**
22
- * @since 0.3.16-canary.0
23
- */
24
- function injectable(deps, options) {
25
- return function(target, context) {
26
- const parameterMetadataList = (deps ?? []).map((dependency, index) => {
27
- const descriptor = normalizeToDescriptor(dependency);
28
- const baseParameterMetadata = {
29
- index,
30
- token: descriptor.token,
31
- optional: descriptor.optional,
32
- multi: descriptor.multi
33
- };
34
- if (descriptor.name !== void 0 && descriptor.tags !== void 0) return {
35
- ...baseParameterMetadata,
36
- name: descriptor.name,
37
- tags: descriptor.tags
38
- };
39
- if (descriptor.name !== void 0) return {
40
- ...baseParameterMetadata,
41
- name: descriptor.name
42
- };
43
- if (descriptor.tags !== void 0) return {
44
- ...baseParameterMetadata,
45
- tags: descriptor.tags
46
- };
47
- return baseParameterMetadata;
48
- });
49
- context.metadata[INJECTABLE_KEY] = { params: parameterMetadataList };
50
- if (options?.autoRegister !== void 0) {
51
- const scope = options.scope ?? "transient";
52
- options.autoRegister.register(target, scope);
53
- }
54
- };
55
- }
56
- //#endregion
57
- export { createAutoRegisterRegistry, injectable };
@@ -1,11 +0,0 @@
1
- //#region src/decorators/lifecycle-decorators.d.ts
2
- /**
3
- * @since 0.3.16-canary.0
4
- */
5
- declare function postConstruct(): (target: unknown, context: ClassMethodDecoratorContext) => void;
6
- /**
7
- * @since 0.3.16-canary.0
8
- */
9
- declare function preDestroy(): (target: unknown, context: ClassMethodDecoratorContext) => void;
10
- //#endregion
11
- export { postConstruct, preDestroy };
@@ -1,38 +0,0 @@
1
- import { InternalError } from "../errors.mjs";
2
- import { LIFECYCLE_KEY } from "../metadata/metadata-keys.mjs";
3
- //#region src/decorators/lifecycle-decorators.ts
4
- function appendUniqueMethod(metadata, phase, methodName) {
5
- if (!metadata[phase].includes(methodName)) metadata[phase].push(methodName);
6
- }
7
- /**
8
- * @since 0.3.16-canary.0
9
- */
10
- function postConstruct() {
11
- return function(target, context) {
12
- if (context.static) throw new InternalError("@postConstruct() applies to instance methods only; static methods are not invoked during instance lifecycle.");
13
- const methodName = String(context.name);
14
- const meta = context.metadata;
15
- if (!meta[LIFECYCLE_KEY]) meta[LIFECYCLE_KEY] = {
16
- postConstruct: [],
17
- preDestroy: []
18
- };
19
- appendUniqueMethod(meta[LIFECYCLE_KEY], "postConstruct", methodName);
20
- };
21
- }
22
- /**
23
- * @since 0.3.16-canary.0
24
- */
25
- function preDestroy() {
26
- return function(target, context) {
27
- if (context.static) throw new InternalError("@preDestroy() applies to instance methods only; static methods are not invoked during instance teardown.");
28
- const methodName = String(context.name);
29
- const meta = context.metadata;
30
- if (!meta[LIFECYCLE_KEY]) meta[LIFECYCLE_KEY] = {
31
- postConstruct: [],
32
- preDestroy: []
33
- };
34
- appendUniqueMethod(meta[LIFECYCLE_KEY], "preDestroy", methodName);
35
- };
36
- }
37
- //#endregion
38
- export { postConstruct, preDestroy };
@@ -1,43 +0,0 @@
1
- import { BindingScope } from "./types.mjs";
2
- import { MetadataReader } from "./metadata/metadata-types.mjs";
3
- import { BindingRegistry } from "./registry.mjs";
4
-
5
- //#region src/dependency-graph.d.ts
6
- /**
7
- * @since 0.3.16-canary.0
8
- */
9
- interface GraphNode {
10
- readonly id: string;
11
- readonly tokenName: string;
12
- readonly kind: string;
13
- readonly scope: BindingScope;
14
- readonly fromParent: boolean;
15
- }
16
- /**
17
- * @since 0.3.16-canary.0
18
- */
19
- interface GraphEdge {
20
- readonly from: string;
21
- readonly to: string;
22
- readonly label?: string;
23
- }
24
- /**
25
- * @since 0.3.16-canary.0
26
- */
27
- interface ContainerGraphJson {
28
- readonly nodes: ReadonlyArray<GraphNode>;
29
- readonly edges: ReadonlyArray<GraphEdge>;
30
- readonly includesParent: boolean;
31
- }
32
- /**
33
- * @since 0.3.16-canary.0
34
- */
35
- interface GraphOptions {
36
- readonly includeParent?: boolean;
37
- }
38
- /**
39
- * @since 0.3.16-canary.0
40
- */
41
- declare function buildDependencyGraph(registry: BindingRegistry, metadataReader: MetadataReader, options: GraphOptions | undefined, parentRegistry?: BindingRegistry): ContainerGraphJson;
42
- //#endregion
43
- export { ContainerGraphJson, GraphEdge, GraphNode, GraphOptions, buildDependencyGraph };
@@ -1,63 +0,0 @@
1
- import { effectiveBindingScope } from "./binding-scope.mjs";
2
- import { tokenName } from "./token.mjs";
3
- //#region src/dependency-graph.ts
4
- /**
5
- * @since 0.3.16-canary.0
6
- */
7
- function buildDependencyGraph(registry, metadataReader, options, parentRegistry) {
8
- const nodes = [];
9
- const edges = [];
10
- const includesParent = options?.includeParent === true;
11
- const addBindings = (sourceRegistry, fromParent) => {
12
- for (const binding of sourceRegistry.allBindings()) {
13
- const scope = effectiveBindingScope(binding);
14
- nodes.push({
15
- id: binding.id,
16
- tokenName: tokenName(binding.token),
17
- kind: binding.kind,
18
- scope,
19
- fromParent
20
- });
21
- if (binding.kind === "class") {
22
- const meta = metadataReader.getConstructorMetadata(binding.target);
23
- if (meta !== void 0) for (let index = 0; index < meta.params.length; index += 1) {
24
- const param = meta.params[index];
25
- const dependencyBinding = sourceRegistry.getAll(param.token)[0];
26
- if (dependencyBinding !== void 0) edges.push({
27
- from: binding.id,
28
- to: dependencyBinding.id,
29
- label: `[${index}]`
30
- });
31
- }
32
- } else if (binding.kind === "resolved" || binding.kind === "resolved-async") for (let index = 0; index < binding.deps.length; index += 1) {
33
- const dependency = binding.deps[index];
34
- const dependencyBindings = sourceRegistry.getAll(dependency.token);
35
- if (dependencyBindings.length > 0 && dependencyBindings[0] !== void 0) {
36
- const label = dependency.name !== void 0 ? `name:${dependency.name}` : dependency.tags !== void 0 && dependency.tags.length > 0 ? `tag:${dependency.tags[0]?.[0]}=${String(dependency.tags[0]?.[1])}` : `[${index}]`;
37
- edges.push({
38
- from: binding.id,
39
- to: dependencyBindings[0].id,
40
- label
41
- });
42
- }
43
- }
44
- else if (binding.kind === "alias") {
45
- const targetBindings = sourceRegistry.getAll(binding.target);
46
- if (targetBindings.length > 0 && targetBindings[0] !== void 0) edges.push({
47
- from: binding.id,
48
- to: targetBindings[0].id,
49
- label: "alias"
50
- });
51
- }
52
- }
53
- };
54
- addBindings(registry, false);
55
- if (includesParent && parentRegistry !== void 0) addBindings(parentRegistry, true);
56
- return {
57
- nodes,
58
- edges,
59
- includesParent
60
- };
61
- }
62
- //#endregion
63
- export { buildDependencyGraph };
@@ -1,55 +0,0 @@
1
- import { Constructor } from "./constructor-type.mjs";
2
- import { Token } from "./token.mjs";
3
- import { BindingIdentifier, BindingKind, BindingScope, ConstraintContext, ResolutionContext, ResolutionFrame, ResolveOptions } from "./types.mjs";
4
- import { Container } from "./container.mjs";
5
-
6
- //#region src/environment.d.ts
7
- /**
8
- * @since 0.3.16-canary.0
9
- */
10
- declare function runWithContainer<Result>(container: Container, fn: () => Result): Result;
11
- /**
12
- * @since 0.3.16-canary.0
13
- */
14
- declare function getActiveContainer(): Container | undefined;
15
- /**
16
- * @since 0.3.16-canary.0
17
- */
18
- interface ResolverCallbacks {
19
- resolveFromContext<const Value>(token: Token<Value> | Constructor<Value>, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Value;
20
- resolve<const Value>(token: Token<Value> | Constructor<Value>, options: ResolveOptions | undefined, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Value;
21
- resolveAsyncFromContext<const Value>(token: Token<Value> | Constructor<Value>, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Promise<Value>;
22
- resolveAsync<const Value>(token: Token<Value> | Constructor<Value>, options: ResolveOptions | undefined, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Promise<Value>;
23
- resolveOptional<const Value>(token: Token<Value> | Constructor<Value>, options: ResolveOptions | undefined, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Value | undefined;
24
- resolveOptionalAsync<const Value>(token: Token<Value> | Constructor<Value>, options: ResolveOptions | undefined, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Promise<Value | undefined>;
25
- resolveAll<const Value>(token: Token<Value> | Constructor<Value>, options: ResolveOptions | undefined, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Array<Value>;
26
- resolveAllAsync<const Value>(token: Token<Value> | Constructor<Value>, options: ResolveOptions | undefined, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Promise<Array<Value>>;
27
- }
28
- /**
29
- * @since 0.3.16-canary.0
30
- */
31
- declare class DefaultResolutionContext implements ResolutionContext {
32
- private _resolver;
33
- private _resolutionPath;
34
- private _resolutionStack;
35
- private _currentOptions;
36
- constructor(resolver: ResolverCallbacks, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>, currentOptions: ResolveOptions | undefined);
37
- private _graph;
38
- get graph(): ConstraintContext;
39
- reset(resolver: ResolverCallbacks, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>, currentOptions: ResolveOptions | undefined): void;
40
- resolve<const Value>(token: Token<Value> | Constructor<Value>, options?: ResolveOptions): Value;
41
- resolveAsync<const Value>(token: Token<Value> | Constructor<Value>, options?: ResolveOptions): Promise<Value>;
42
- resolveOptional<const Value>(token: Token<Value> | Constructor<Value>, options?: ResolveOptions): Value | undefined;
43
- resolveOptionalAsync<const Value>(token: Token<Value> | Constructor<Value>, options?: ResolveOptions): Promise<Value | undefined>;
44
- resolveAll<const Value>(token: Token<Value> | Constructor<Value>, options?: ResolveOptions): Array<Value>;
45
- resolveAllAsync<const Value>(token: Token<Value> | Constructor<Value>, options?: ResolveOptions): Promise<Array<Value>>;
46
- }
47
- /**
48
- * @since 0.3.16-canary.0
49
- */
50
- declare function buildResolutionFrame(tokenName: string, scope: BindingScope, bindingId: BindingIdentifier, kind: BindingKind, slot: {
51
- name: string | undefined;
52
- tags: ReadonlyArray<readonly [string, unknown]>;
53
- }): ResolutionFrame;
54
- //#endregion
55
- export { DefaultResolutionContext, ResolverCallbacks, buildResolutionFrame, getActiveContainer, runWithContainer };
@@ -1,98 +0,0 @@
1
- //#region src/environment.ts
2
- let _activeContainer;
3
- /**
4
- * @since 0.3.16-canary.0
5
- */
6
- function runWithContainer(container, fn) {
7
- const prev = _activeContainer;
8
- _activeContainer = container;
9
- try {
10
- return fn();
11
- } finally {
12
- _activeContainer = prev;
13
- }
14
- }
15
- /**
16
- * @since 0.3.16-canary.0
17
- */
18
- function getActiveContainer() {
19
- return _activeContainer;
20
- }
21
- /**
22
- * @since 0.3.16-canary.0
23
- */
24
- var DefaultResolutionContext = class {
25
- _resolver;
26
- _resolutionPath;
27
- _resolutionStack;
28
- _currentOptions;
29
- constructor(resolver, resolutionPath, resolutionStack, currentOptions) {
30
- this._resolver = resolver;
31
- this._resolutionPath = resolutionPath;
32
- this._resolutionStack = resolutionStack;
33
- this._currentOptions = currentOptions;
34
- }
35
- _graph;
36
- get graph() {
37
- if (this._graph === void 0) this._graph = new DefaultConstraintContext(this._resolutionPath, this._resolutionStack, this._currentOptions);
38
- return this._graph;
39
- }
40
- reset(resolver, resolutionPath, resolutionStack, currentOptions) {
41
- this._resolver = resolver;
42
- this._resolutionPath = resolutionPath;
43
- this._resolutionStack = resolutionStack;
44
- this._currentOptions = currentOptions;
45
- this._graph = void 0;
46
- }
47
- resolve(token, options) {
48
- if (options === void 0) return this._resolver.resolveFromContext(token, this._resolutionPath, this._resolutionStack);
49
- return this._resolver.resolve(token, options, this._resolutionPath, this._resolutionStack);
50
- }
51
- resolveAsync(token, options) {
52
- if (options === void 0) return this._resolver.resolveAsyncFromContext(token, this._resolutionPath, this._resolutionStack);
53
- return this._resolver.resolveAsync(token, options, this._resolutionPath, this._resolutionStack);
54
- }
55
- resolveOptional(token, options) {
56
- return this._resolver.resolveOptional(token, options, this._resolutionPath, this._resolutionStack);
57
- }
58
- resolveOptionalAsync(token, options) {
59
- return this._resolver.resolveOptionalAsync(token, options, this._resolutionPath, this._resolutionStack);
60
- }
61
- resolveAll(token, options) {
62
- return this._resolver.resolveAll(token, options, this._resolutionPath, this._resolutionStack);
63
- }
64
- resolveAllAsync(token, options) {
65
- return this._resolver.resolveAllAsync(token, options, this._resolutionPath, this._resolutionStack);
66
- }
67
- };
68
- var DefaultConstraintContext = class {
69
- resolutionPath;
70
- resolutionStack;
71
- parent;
72
- currentResolveOptions;
73
- constructor(resolutionPath, resolutionStack, currentResolveOptions) {
74
- this.resolutionPath = resolutionPath;
75
- this.resolutionStack = resolutionStack;
76
- this.parent = resolutionStack.at(-1);
77
- this.currentResolveOptions = currentResolveOptions;
78
- }
79
- _ancestors;
80
- get ancestors() {
81
- if (this._ancestors === void 0) this._ancestors = this.resolutionStack.length > 1 ? this.resolutionStack.slice(0, -1) : [];
82
- return this._ancestors;
83
- }
84
- };
85
- /**
86
- * @since 0.3.16-canary.0
87
- */
88
- function buildResolutionFrame(tokenName, scope, bindingId, kind, slot) {
89
- return {
90
- tokenName,
91
- scope,
92
- bindingId,
93
- kind,
94
- slot
95
- };
96
- }
97
- //#endregion
98
- export { DefaultResolutionContext, buildResolutionFrame, getActiveContainer, runWithContainer };