@nexus-ioc/core 0.6.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +731 -1
- package/dist/cjs/browser.js +2 -2
- package/dist/cjs/browser.js.map +1 -1
- package/dist/cjs/core/child-module.js +32 -0
- package/dist/cjs/core/child-module.js.map +1 -0
- package/dist/cjs/core/graph/analyze-lazy-module.js +54 -0
- package/dist/cjs/core/graph/analyze-lazy-module.js.map +1 -0
- package/dist/cjs/core/graph/analyze-module.js +11 -0
- package/dist/cjs/core/graph/analyze-module.js.map +1 -1
- package/dist/cjs/core/graph/module-graph.js +685 -70
- package/dist/cjs/core/graph/module-graph.js.map +1 -1
- package/dist/cjs/core/injection/injection-context.js +29 -0
- package/dist/cjs/core/injection/injection-context.js.map +1 -0
- package/dist/cjs/core/lazy-module-loader.js +41 -0
- package/dist/cjs/core/lazy-module-loader.js.map +1 -0
- package/dist/cjs/core/module-ref.js +84 -0
- package/dist/cjs/core/module-ref.js.map +1 -0
- package/dist/cjs/core/modules/container.js +305 -17
- package/dist/cjs/core/modules/container.js.map +1 -1
- package/dist/cjs/core/modules/module-container-factory.js +2 -2
- package/dist/cjs/core/modules/module-container-factory.js.map +1 -1
- package/dist/cjs/core/modules/module-container.js +54 -16
- package/dist/cjs/core/modules/module-container.js.map +1 -1
- package/dist/cjs/core/modules/module-token-factory.js.map +1 -1
- package/dist/cjs/core/modules/modules-container.js +43 -3
- package/dist/cjs/core/modules/modules-container.js.map +1 -1
- package/dist/cjs/core/nexus-applications.browser.js +57 -15
- package/dist/cjs/core/nexus-applications.browser.js.map +1 -1
- package/dist/cjs/core/nexus-applications.js +440 -82
- package/dist/cjs/core/nexus-applications.js.map +1 -1
- package/dist/cjs/core/nexus-applications.server.js +57 -15
- package/dist/cjs/core/nexus-applications.server.js.map +1 -1
- package/dist/cjs/core/resolver/providers-container.js.map +1 -1
- package/dist/cjs/core/resolver/resolution-context.js +62 -0
- package/dist/cjs/core/resolver/resolution-context.js.map +1 -0
- package/dist/cjs/core/resolver/resolver.js +523 -99
- package/dist/cjs/core/resolver/resolver.js.map +1 -1
- package/dist/cjs/decorators/inject.js +6 -3
- package/dist/cjs/decorators/inject.js.map +1 -1
- package/dist/cjs/decorators/injectable.js +0 -7
- package/dist/cjs/decorators/injectable.js.map +1 -1
- package/dist/cjs/decorators/{nsModule.js → module.js} +9 -7
- package/dist/cjs/decorators/module.js.map +1 -0
- package/dist/cjs/errors/bootstrap-error.js +47 -0
- package/dist/cjs/errors/bootstrap-error.js.map +1 -0
- package/dist/cjs/errors/child-errors.js +21 -0
- package/dist/cjs/errors/child-errors.js.map +1 -0
- package/dist/cjs/errors/index.js +24 -0
- package/dist/cjs/errors/index.js.map +1 -0
- package/dist/cjs/errors/injection-errors.js +25 -0
- package/dist/cjs/errors/injection-errors.js.map +1 -0
- package/dist/cjs/errors/lazy-module-errors.js +26 -0
- package/dist/cjs/errors/lazy-module-errors.js.map +1 -0
- package/dist/cjs/errors/provider-errors.js +95 -0
- package/dist/cjs/errors/provider-errors.js.map +1 -0
- package/dist/cjs/index.js +30 -6
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/interfaces/index.js +1 -0
- package/dist/cjs/interfaces/index.js.map +1 -1
- package/dist/cjs/interfaces/modules/index.js +1 -0
- package/dist/cjs/interfaces/modules/index.js.map +1 -1
- package/dist/cjs/interfaces/modules/module-graph.interface.js +2 -0
- package/dist/cjs/interfaces/modules/module-graph.interface.js.map +1 -1
- package/dist/cjs/interfaces/modules/parent-link.interface.js +3 -0
- package/dist/cjs/interfaces/modules/parent-link.interface.js.map +1 -0
- package/dist/cjs/interfaces/on-module-destroy.interface.js +3 -0
- package/dist/cjs/interfaces/on-module-destroy.interface.js.map +1 -0
- package/dist/cjs/interfaces/scope.interface.js +2 -55
- package/dist/cjs/interfaces/scope.interface.js.map +1 -1
- package/dist/cjs/interfaces/validate-module-keys.js +2 -0
- package/dist/cjs/interfaces/validate-module-keys.js.map +1 -1
- package/dist/cjs/internal.js +9 -0
- package/dist/cjs/internal.js.map +1 -0
- package/dist/cjs/server.js +2 -2
- package/dist/cjs/server.js.map +1 -1
- package/dist/cjs/utils/forward-ref.js +14 -0
- package/dist/cjs/utils/forward-ref.js.map +1 -0
- package/dist/cjs/utils/helpers.js +14 -4
- package/dist/cjs/utils/helpers.js.map +1 -1
- package/dist/cjs/utils/lazy-module.js +33 -0
- package/dist/cjs/utils/lazy-module.js.map +1 -0
- package/dist/esm/browser.js +1 -1
- package/dist/esm/browser.js.map +1 -1
- package/dist/esm/core/child-module.js +29 -0
- package/dist/esm/core/child-module.js.map +1 -0
- package/dist/esm/core/graph/analyze-lazy-module.js +50 -0
- package/dist/esm/core/graph/analyze-lazy-module.js.map +1 -0
- package/dist/esm/core/graph/analyze-module.js +11 -0
- package/dist/esm/core/graph/analyze-module.js.map +1 -1
- package/dist/esm/core/graph/module-graph.js +686 -71
- package/dist/esm/core/graph/module-graph.js.map +1 -1
- package/dist/esm/core/injection/injection-context.js +25 -0
- package/dist/esm/core/injection/injection-context.js.map +1 -0
- package/dist/esm/core/lazy-module-loader.js +36 -0
- package/dist/esm/core/lazy-module-loader.js.map +1 -0
- package/dist/esm/core/module-ref.js +80 -0
- package/dist/esm/core/module-ref.js.map +1 -0
- package/dist/esm/core/modules/container.js +305 -17
- package/dist/esm/core/modules/container.js.map +1 -1
- package/dist/esm/core/modules/module-container-factory.js +2 -2
- package/dist/esm/core/modules/module-container-factory.js.map +1 -1
- package/dist/esm/core/modules/module-container.js +55 -17
- package/dist/esm/core/modules/module-container.js.map +1 -1
- package/dist/esm/core/modules/module-token-factory.js.map +1 -1
- package/dist/esm/core/modules/modules-container.js +43 -3
- package/dist/esm/core/modules/modules-container.js.map +1 -1
- package/dist/esm/core/nexus-applications.browser.js +55 -13
- package/dist/esm/core/nexus-applications.browser.js.map +1 -1
- package/dist/esm/core/nexus-applications.js +439 -81
- package/dist/esm/core/nexus-applications.js.map +1 -1
- package/dist/esm/core/nexus-applications.server.js +55 -13
- package/dist/esm/core/nexus-applications.server.js.map +1 -1
- package/dist/esm/core/resolver/providers-container.js.map +1 -1
- package/dist/esm/core/resolver/resolution-context.js +58 -0
- package/dist/esm/core/resolver/resolution-context.js.map +1 -0
- package/dist/esm/core/resolver/resolver.js +524 -100
- package/dist/esm/core/resolver/resolver.js.map +1 -1
- package/dist/esm/decorators/inject.js +6 -3
- package/dist/esm/decorators/inject.js.map +1 -1
- package/dist/esm/decorators/injectable.js +0 -7
- package/dist/esm/decorators/injectable.js.map +1 -1
- package/dist/esm/decorators/{nsModule.js → module.js} +8 -6
- package/dist/esm/decorators/module.js.map +1 -0
- package/dist/esm/errors/bootstrap-error.js +42 -0
- package/dist/esm/errors/bootstrap-error.js.map +1 -0
- package/dist/esm/errors/child-errors.js +17 -0
- package/dist/esm/errors/child-errors.js.map +1 -0
- package/dist/esm/errors/index.js +6 -0
- package/dist/esm/errors/index.js.map +1 -0
- package/dist/esm/errors/injection-errors.js +20 -0
- package/dist/esm/errors/injection-errors.js.map +1 -0
- package/dist/esm/errors/lazy-module-errors.js +21 -0
- package/dist/esm/errors/lazy-module-errors.js.map +1 -0
- package/dist/esm/errors/provider-errors.js +84 -0
- package/dist/esm/errors/provider-errors.js.map +1 -0
- package/dist/esm/index.js +9 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/interfaces/index.js +1 -0
- package/dist/esm/interfaces/index.js.map +1 -1
- package/dist/esm/interfaces/modules/index.js +1 -0
- package/dist/esm/interfaces/modules/index.js.map +1 -1
- package/dist/esm/interfaces/modules/module-graph.interface.js +2 -0
- package/dist/esm/interfaces/modules/module-graph.interface.js.map +1 -1
- package/dist/esm/interfaces/modules/parent-link.interface.js +2 -0
- package/dist/esm/interfaces/modules/parent-link.interface.js.map +1 -0
- package/dist/esm/interfaces/on-module-destroy.interface.js +2 -0
- package/dist/esm/interfaces/on-module-destroy.interface.js.map +1 -0
- package/dist/esm/interfaces/scope.interface.js +1 -55
- package/dist/esm/interfaces/scope.interface.js.map +1 -1
- package/dist/esm/interfaces/validate-module-keys.js +2 -0
- package/dist/esm/interfaces/validate-module-keys.js.map +1 -1
- package/dist/esm/internal.js +3 -0
- package/dist/esm/internal.js.map +1 -0
- package/dist/esm/server.js +1 -1
- package/dist/esm/server.js.map +1 -1
- package/dist/esm/utils/forward-ref.js +10 -0
- package/dist/esm/utils/forward-ref.js.map +1 -0
- package/dist/esm/utils/helpers.js +14 -4
- package/dist/esm/utils/helpers.js.map +1 -1
- package/dist/esm/utils/lazy-module.js +29 -0
- package/dist/esm/utils/lazy-module.js.map +1 -0
- package/dist/types/browser.d.ts +1 -1
- package/dist/types/core/child-module.d.ts +8 -0
- package/dist/types/core/graph/analyze-lazy-module.d.ts +28 -0
- package/dist/types/core/graph/analyze-module.d.ts +4 -2
- package/dist/types/core/graph/analyze-provider.d.ts +4 -4
- package/dist/types/core/graph/module-graph.d.ts +200 -7
- package/dist/types/core/graph/providers/analyze-class-provider.d.ts +1 -1
- package/dist/types/core/graph/providers/analyze-factory-provider.d.ts +2 -2
- package/dist/types/core/graph/providers/analyze-value-provider.d.ts +1 -1
- package/dist/types/core/injection/injection-context.d.ts +29 -0
- package/dist/types/core/lazy-module-loader.d.ts +17 -0
- package/dist/types/core/module-ref.d.ts +34 -0
- package/dist/types/core/modules/container.d.ts +134 -18
- package/dist/types/core/modules/module-container-factory.d.ts +3 -3
- package/dist/types/core/modules/module-container.d.ts +44 -5
- package/dist/types/core/modules/module-token-factory.d.ts +2 -2
- package/dist/types/core/modules/modules-container.d.ts +23 -4
- package/dist/types/core/nexus-applications.browser.d.ts +30 -8
- package/dist/types/core/nexus-applications.d.ts +219 -55
- package/dist/types/core/nexus-applications.server.d.ts +30 -8
- package/dist/types/core/resolver/providers-container.d.ts +2 -2
- package/dist/types/core/resolver/resolution-context.d.ts +22 -0
- package/dist/types/core/resolver/resolver.d.ts +122 -4
- package/dist/types/decorators/inject.d.ts +9 -5
- package/dist/types/decorators/injectable.d.ts +0 -7
- package/dist/types/decorators/{nsModule.d.ts → module.d.ts} +6 -5
- package/dist/types/errors/bootstrap-error.d.ts +6 -0
- package/dist/types/errors/child-errors.d.ts +10 -0
- package/dist/types/errors/index.d.ts +5 -0
- package/dist/types/errors/injection-errors.d.ts +11 -0
- package/dist/types/errors/lazy-module-errors.d.ts +12 -0
- package/dist/types/errors/provider-errors.d.ts +47 -0
- package/dist/types/index.d.ts +13 -4
- package/dist/types/interfaces/abstract.interface.d.ts +1 -3
- package/dist/types/interfaces/dynamic-module.interface.d.ts +7 -5
- package/dist/types/interfaces/index.d.ts +1 -0
- package/dist/types/interfaces/injection-token.interface.d.ts +1 -3
- package/dist/types/interfaces/module-metadata.interface.d.ts +12 -4
- package/dist/types/interfaces/module-types.interface.d.ts +21 -24
- package/dist/types/interfaces/modules/container.interface.d.ts +10 -4
- package/dist/types/interfaces/modules/index.d.ts +1 -0
- package/dist/types/interfaces/modules/module-container-factory.interface.d.ts +2 -2
- package/dist/types/interfaces/modules/module-graph.interface.d.ts +85 -12
- package/dist/types/interfaces/modules/module-token-factory.interface.d.ts +2 -2
- package/dist/types/interfaces/modules/modules-container.interface.d.ts +5 -4
- package/dist/types/interfaces/modules/parent-link.interface.d.ts +12 -0
- package/dist/types/interfaces/nexus-application.interface.d.ts +49 -6
- package/dist/types/interfaces/on-module-destroy.interface.d.ts +3 -0
- package/dist/types/interfaces/plugins/scanner-plugin.interface.d.ts +1 -1
- package/dist/types/interfaces/scope.interface.d.ts +1 -54
- package/dist/types/interfaces/validate-module-keys.d.ts +1 -0
- package/dist/types/internal.d.ts +3 -0
- package/dist/types/server.d.ts +1 -1
- package/dist/types/utils/forward-ref.d.ts +5 -0
- package/dist/types/utils/helpers.d.ts +8 -8
- package/dist/types/utils/lazy-module.d.ts +20 -0
- package/package.json +23 -7
- package/dist/cjs/decorators/nsModule.js.map +0 -1
- package/dist/esm/decorators/nsModule.js.map +0 -1
- package/dist/tsconfig.cjs.tsbuildinfo +0 -1
- package/dist/tsconfig.esm.tsbuildinfo +0 -1
package/dist/esm/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function forwardRef(fn) {
|
|
2
|
+
return { forwardRef: fn };
|
|
3
|
+
}
|
|
4
|
+
export function isForwardRef(token) {
|
|
5
|
+
return (typeof token === "object" &&
|
|
6
|
+
token !== null &&
|
|
7
|
+
"forwardRef" in token &&
|
|
8
|
+
typeof token.forwardRef === "function");
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=forward-ref.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"forward-ref.js","sourceRoot":"","sources":["../../../src/utils/forward-ref.ts"],"names":[],"mappings":"AAIA,MAAM,UAAU,UAAU,CAAc,EAAW;IAClD,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAc;IAC1C,OAAO,CACN,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,YAAY,IAAI,KAAK;QACrB,OAAQ,KAAoB,CAAC,UAAU,KAAK,UAAU,CACtD,CAAC;AACH,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
+
import { InvalidScopeError } from "../errors/provider-errors.js";
|
|
2
3
|
import { INJECTABLE_OPTIONS, INJECTABLE_WATERMARK, MODULE_GLOBAL_WATERMARK, Scope, } from "../interfaces/index.js";
|
|
3
4
|
export function isFunctionProvider(target) {
|
|
4
5
|
return typeof target === "function";
|
|
@@ -47,17 +48,26 @@ export function getModuleLabel(module) {
|
|
|
47
48
|
return module.name;
|
|
48
49
|
}
|
|
49
50
|
export function getProviderScope(target) {
|
|
51
|
+
const scope = declaredScope(target) ?? Scope.Singleton;
|
|
52
|
+
if (scope !== Scope.Singleton && scope !== Scope.Transient) {
|
|
53
|
+
throw new InvalidScopeError(getProviderToken(target), scope);
|
|
54
|
+
}
|
|
55
|
+
return scope;
|
|
56
|
+
}
|
|
57
|
+
/** The scope a provider declares, or undefined when it declares none. */
|
|
58
|
+
function declaredScope(target) {
|
|
50
59
|
if (isFactoryProvider(target)) {
|
|
51
|
-
return target.scope
|
|
60
|
+
return target.scope;
|
|
52
61
|
}
|
|
53
62
|
if (isClassProvider(target)) {
|
|
63
|
+
// A Singleton (0) on the class falls through to the provider object,
|
|
64
|
+
// so `{ useClass, scope: Scope.Transient }` overrides it.
|
|
54
65
|
return (Reflect.getMetadata(INJECTABLE_OPTIONS, target.useClass)?.scope ||
|
|
55
|
-
target.scope
|
|
56
|
-
Scope.Singleton);
|
|
66
|
+
target.scope);
|
|
57
67
|
}
|
|
58
68
|
if (isValueProvider(target)) {
|
|
59
69
|
return Scope.Singleton;
|
|
60
70
|
}
|
|
61
|
-
return
|
|
71
|
+
return Reflect.getMetadata(INJECTABLE_OPTIONS, target)?.scope;
|
|
62
72
|
}
|
|
63
73
|
//# sourceMappingURL=helpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/utils/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAIN,kBAAkB,EAClB,oBAAoB,
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/utils/helpers.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Declares a lazily loaded module import.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* export const FeatureLazy = lazy(() =>
|
|
7
|
+
* import("./feature/feature.module").then((m) => m.FeatureModule),
|
|
8
|
+
* );
|
|
9
|
+
*
|
|
10
|
+
* @Module({ imports: [CoreModule, FeatureLazy] })
|
|
11
|
+
* class AppModule {}
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export function lazy(loader, options = {}) {
|
|
15
|
+
const name = options.name ?? "LazyModule";
|
|
16
|
+
return Object.freeze({
|
|
17
|
+
id: Symbol(name),
|
|
18
|
+
name,
|
|
19
|
+
load: loader,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export function isLazyModule(value) {
|
|
23
|
+
return (typeof value === "object" &&
|
|
24
|
+
value !== null &&
|
|
25
|
+
typeof value.id === "symbol" &&
|
|
26
|
+
typeof value.load === "function" &&
|
|
27
|
+
typeof value.name === "string");
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=lazy-module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazy-module.js","sourceRoot":"","sources":["../../../src/utils/lazy-module.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,IAAI,CACnB,MAAwC,EACxC,UAA6B,EAAE;IAE/B,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,YAAY,CAAC;IAC1C,OAAO,MAAM,CAAC,MAAM,CAAC;QACpB,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC;QAChB,IAAI;QACJ,IAAI,EAAE,MAAM;KACZ,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAc;IAC1C,OAAO,CACN,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,OAAQ,KAAoB,CAAC,EAAE,KAAK,QAAQ;QAC5C,OAAQ,KAAoB,CAAC,IAAI,KAAK,UAAU;QAChD,OAAQ,KAAoB,CAAC,IAAI,KAAK,QAAQ,CAC9C,CAAC;AACH,CAAC"}
|
package/dist/types/browser.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { NexusApplicationBrowser } from "./core/nexus-applications.browser";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { type DynamicModule, type Provider, type Type } from "../interfaces";
|
|
3
|
+
/**
|
|
4
|
+
* Returns `module` with `providers` appended to its root providers, as a
|
|
5
|
+
* `DynamicModule`. A `Type` keeps its decorator imports and exports. Returns
|
|
6
|
+
* `module` itself when there is nothing to add.
|
|
7
|
+
*/
|
|
8
|
+
export declare function withExtraProviders(module: Type | DynamicModule, providers: Provider[] | undefined): Type | DynamicModule;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type LazyModule, NodeTypeEnum } from "../../interfaces";
|
|
2
|
+
/**
|
|
3
|
+
* Placeholder graph node for a `lazy()` import. It carries no providers.
|
|
4
|
+
* `isProviderExported` never looks through it, so eager providers cannot
|
|
5
|
+
* depend on anything the lazy module will provide.
|
|
6
|
+
*/
|
|
7
|
+
export declare class AnalyzeLazyModule {
|
|
8
|
+
private readonly _lazyModule;
|
|
9
|
+
private _loaded;
|
|
10
|
+
private _moduleToken;
|
|
11
|
+
constructor(_lazyModule: LazyModule);
|
|
12
|
+
get type(): NodeTypeEnum.LAZY;
|
|
13
|
+
get id(): symbol;
|
|
14
|
+
get label(): string;
|
|
15
|
+
get lazyModule(): LazyModule;
|
|
16
|
+
get loaded(): boolean;
|
|
17
|
+
/** Token of the real module node once loaded; null before. */
|
|
18
|
+
get moduleToken(): string | null;
|
|
19
|
+
markLoaded(moduleToken: string): void;
|
|
20
|
+
markUnloaded(): void;
|
|
21
|
+
get node(): {
|
|
22
|
+
type: NodeTypeEnum.LAZY;
|
|
23
|
+
id: symbol;
|
|
24
|
+
label: string;
|
|
25
|
+
loaded: boolean;
|
|
26
|
+
moduleToken: string | null;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EdgeTypeEnum, type ModuleContainerInterface, NodeTypeEnum } from "../../interfaces";
|
|
1
|
+
import { type Edge, EdgeTypeEnum, type ModuleContainerInterface, NodeTypeEnum } from "../../interfaces";
|
|
2
2
|
export declare class AnalyzeModule {
|
|
3
3
|
private readonly _module;
|
|
4
4
|
private readonly _isDynamic;
|
|
@@ -29,8 +29,10 @@ export declare class AnalyzeModule {
|
|
|
29
29
|
isCircular: boolean;
|
|
30
30
|
};
|
|
31
31
|
}[]>;
|
|
32
|
+
get lazyImports(): import("@nexus-ioc/shared").LazyModule<import("@nexus-ioc/shared").Module>[];
|
|
33
|
+
get lazyEdges(): Edge[];
|
|
32
34
|
get providers(): import("@nexus-ioc/shared").Provider[];
|
|
33
35
|
get isGlobal(): boolean;
|
|
34
36
|
get imports(): Promise<ModuleContainerInterface[]>;
|
|
35
|
-
get exports(): (import("@nexus-ioc/shared").
|
|
37
|
+
get exports(): (import("@nexus-ioc/shared").ProviderToken | import("@nexus-ioc/shared").Module)[];
|
|
36
38
|
}
|
|
@@ -7,18 +7,18 @@ export declare abstract class AnalyzeProvider {
|
|
|
7
7
|
private readonly _scope;
|
|
8
8
|
constructor(provider: Provider, module: ModuleContainerInterface);
|
|
9
9
|
get type(): NodeTypeEnum.PROVIDER;
|
|
10
|
-
get id(): import("
|
|
10
|
+
get id(): import("@nexus-ioc/shared").ProviderToken;
|
|
11
11
|
get label(): string;
|
|
12
12
|
get metatype(): Provider;
|
|
13
13
|
get moduleContainer(): ModuleContainerInterface;
|
|
14
|
-
get scope(): import("
|
|
14
|
+
get scope(): import("@nexus-ioc/shared").Scope;
|
|
15
15
|
get node(): {
|
|
16
16
|
type: NodeTypeEnum.PROVIDER;
|
|
17
|
-
id: import("
|
|
17
|
+
id: import("@nexus-ioc/shared").ProviderToken;
|
|
18
18
|
label: string;
|
|
19
19
|
metatype: Provider;
|
|
20
20
|
moduleContainer: ModuleContainerInterface;
|
|
21
|
-
scope: import("
|
|
21
|
+
scope: import("@nexus-ioc/shared").Scope;
|
|
22
22
|
};
|
|
23
23
|
get edge(): Edge;
|
|
24
24
|
}
|
|
@@ -1,30 +1,223 @@
|
|
|
1
|
-
import { type Edge, type GraphError, type
|
|
1
|
+
import { type Edge, type GraphError, type GraphSegment, type LazyModule, type ModuleContainerInterface, type ModuleGraphInterface, type ModuleGraphOptions, type Node, type ProviderToken, type SegmentUnloadResult, type Type } from "../../interfaces";
|
|
2
2
|
export declare class ModuleGraph implements ModuleGraphInterface {
|
|
3
3
|
private readonly _root;
|
|
4
|
+
private readonly _internalRoots;
|
|
5
|
+
private readonly options;
|
|
4
6
|
private _nodes;
|
|
5
7
|
private _edges;
|
|
6
8
|
private _globalModules;
|
|
9
|
+
/** Module token -> its own declared provider tokens. */
|
|
10
|
+
private readonly _moduleProviders;
|
|
11
|
+
/**
|
|
12
|
+
* Module token -> the other module tokens that need it alive: every
|
|
13
|
+
* module that imports it, plus every module owning a provider that
|
|
14
|
+
* depends (via a resolved `DEPENDENCY` edge, including one resolved
|
|
15
|
+
* through a `@Global()` module) on one of its providers.
|
|
16
|
+
*/
|
|
17
|
+
private readonly _moduleReferrers;
|
|
18
|
+
/**
|
|
19
|
+
* Late-bound edge index: target token -> source provider token -> whether
|
|
20
|
+
* the edge is bound. A `lateBound` edge is an `@Optional()` static edge
|
|
21
|
+
* whose target was not visible from the source's module when it was
|
|
22
|
+
* compiled (it may not have existed yet). The resolver injects its target
|
|
23
|
+
* only while the target exists and is visible. "Bound" means that held
|
|
24
|
+
* when a segment added the target (or a global module exposing it), so
|
|
25
|
+
* the source's module was recorded as a referrer of the target's module;
|
|
26
|
+
* only a bound edge counts in `moduleDependencies`, which keeps the
|
|
27
|
+
* referrer purge symmetric with the recording.
|
|
28
|
+
*/
|
|
29
|
+
private readonly _lateBound;
|
|
30
|
+
/**
|
|
31
|
+
* Child declaration index: the child's module class (or the `LazyModule.id`
|
|
32
|
+
* symbol of a lazy ref) -> the token of the one module declaring it.
|
|
33
|
+
*/
|
|
34
|
+
private readonly _childDeclarations;
|
|
7
35
|
private readonly _errors;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
36
|
+
/**
|
|
37
|
+
* While a segment compiles, its errors are collected here instead of in
|
|
38
|
+
* `_errors`, so they are never mixed with (or mistaken for) errors of the
|
|
39
|
+
* eager graph or of another segment.
|
|
40
|
+
*/
|
|
41
|
+
private _errorSink;
|
|
42
|
+
/** See `version`. */
|
|
43
|
+
private _version;
|
|
44
|
+
constructor(_root: ModuleContainerInterface, _internalRoots?: ModuleContainerInterface[], options?: ModuleGraphOptions);
|
|
45
|
+
get nodes(): Map<ProviderToken, Node>;
|
|
46
|
+
get edges(): Map<ProviderToken, Edge[]>;
|
|
11
47
|
get errors(): GraphError[];
|
|
48
|
+
get rootToken(): string;
|
|
49
|
+
get internalRootTokens(): string[];
|
|
50
|
+
/**
|
|
51
|
+
* Bumped whenever `compile`, `compileSegment` or `unloadSegment` may have
|
|
52
|
+
* changed which providers exist or which modules see them. A cache of
|
|
53
|
+
* `isProviderVisible` results is valid while this number is unchanged.
|
|
54
|
+
*/
|
|
55
|
+
get version(): number;
|
|
56
|
+
/** Records a graph error in the active sink, or in the shared list. */
|
|
57
|
+
private pushError;
|
|
58
|
+
/**
|
|
59
|
+
* Compiles the eager graph. Internal roots are added before the user root so
|
|
60
|
+
* `_globalModules` already contains the internal modules when user providers
|
|
61
|
+
* are checked by `isProviderExported`.
|
|
62
|
+
*/
|
|
12
63
|
compile(): Promise<void>;
|
|
13
|
-
|
|
14
|
-
|
|
64
|
+
/**
|
|
65
|
+
* Compiles the part of the graph reachable from `root` that is not already
|
|
66
|
+
* registered, attributing it to the `lazyModule` placeholder node.
|
|
67
|
+
*
|
|
68
|
+
* The pass is atomic: if it produces any error the segment is rolled back
|
|
69
|
+
* (every node, edge, global registration and LAZY placeholder it created is
|
|
70
|
+
* removed) and the placeholder stays unloaded. On success the placeholder is
|
|
71
|
+
* marked loaded. A placeholder that already existed before the segment
|
|
72
|
+
* started is never removed.
|
|
73
|
+
*
|
|
74
|
+
* The segment's errors are collected in a segment-local sink and never
|
|
75
|
+
* reach `this.errors`, so they cannot be attributed to the eager graph or
|
|
76
|
+
* to another segment. The caller (`Container.load`) runs one segment at a
|
|
77
|
+
* time, which is what makes the sink and the graph mutations safe under
|
|
78
|
+
* concurrent loads of different refs.
|
|
79
|
+
*/
|
|
80
|
+
compileSegment(root: ModuleContainerInterface, lazyModule: LazyModule): Promise<GraphSegment>;
|
|
81
|
+
/**
|
|
82
|
+
* Binds the late-bound edges (see `_lateBound`) whose target this
|
|
83
|
+
* segment made visible to the edge's source, recording the referrer the
|
|
84
|
+
* resolver's injection now implies. The same visibility check as the
|
|
85
|
+
* resolver's, so bookkeeping and injection always agree.
|
|
86
|
+
*
|
|
87
|
+
* Only two things can make a late-bound target visible to an existing
|
|
88
|
+
* source: the target's node being added (looked up per added provider)
|
|
89
|
+
* or a new `@Global()` module exposing it (compiled modules' imports
|
|
90
|
+
* never change). Only a segment adding a global module rechecks every
|
|
91
|
+
* indexed target; the index holds only late-bound edges, so it is small.
|
|
92
|
+
*
|
|
93
|
+
* Once bound, an edge keeps the target's module pinned for the consumer
|
|
94
|
+
* module's lifetime, even after the global module that exposed it
|
|
95
|
+
* unloads. This is deliberately safe: instances created meanwhile may
|
|
96
|
+
* still hold the target.
|
|
97
|
+
*/
|
|
98
|
+
private bindLateEdges;
|
|
99
|
+
/**
|
|
100
|
+
* Drops removed sources from the late-bound index and unbinds edges
|
|
101
|
+
* whose target was removed (a later load of the target binds them
|
|
102
|
+
* again). Runs after `purgeModuleIndexes`, which reads the bound state.
|
|
103
|
+
*/
|
|
104
|
+
private purgeLateBound;
|
|
105
|
+
/**
|
|
106
|
+
* Rolls back a segment that failed validation: removes every node, edge
|
|
107
|
+
* and global registration it created (module, provider and LAZY
|
|
108
|
+
* placeholder tokens are all passed in together). Also purges
|
|
109
|
+
* `_moduleProviders`/`_moduleReferrers` index entries for `tokens` via
|
|
110
|
+
* `purgeModuleIndexes` — without this, a referrer entry recorded by
|
|
111
|
+
* `addModuleImports` before the rollback (pointing at a module token
|
|
112
|
+
* that no longer exists) would survive and could later be mistaken by
|
|
113
|
+
* `rescueCandidates` for a live outside referrer of a module reused by a
|
|
114
|
+
* different, successful segment.
|
|
115
|
+
*/
|
|
116
|
+
private removeTokens;
|
|
117
|
+
/**
|
|
118
|
+
* Unloads a loaded lazy segment. Scoped to the segment's own subgraph,
|
|
119
|
+
* not the whole live graph: collects everything reachable from the
|
|
120
|
+
* segment's root (pruned at any module in `protectedRoots` — the eager
|
|
121
|
+
* root, internal roots, and every *other* currently loaded segment's
|
|
122
|
+
* root), then rescues back anything a survivor still needs. Returns the
|
|
123
|
+
* modules and providers that were actually destroyed; a no-op (empty
|
|
124
|
+
* result) if the ref is not currently loaded.
|
|
125
|
+
*/
|
|
126
|
+
unloadSegment(lazyModule: LazyModule, protectedRoots: Set<string>): SegmentUnloadResult;
|
|
127
|
+
/** A module's own `IMPORT` targets, plus the declaring modules of
|
|
128
|
+
* whatever its own providers depend on in another module. Shared by
|
|
129
|
+
* candidate collection, rescue propagation and teardown cleanup. */
|
|
130
|
+
private moduleDependencies;
|
|
131
|
+
private collectCandidates;
|
|
132
|
+
/**
|
|
133
|
+
* A candidate survives if something outside the candidate set still
|
|
134
|
+
* needs it (a "seed"), or if it is only reachable through a candidate
|
|
135
|
+
* that survives. A plain per-node check for the first case alone is not
|
|
136
|
+
* enough — see the "rescues a module only reachable through a surviving
|
|
137
|
+
* sibling candidate" test.
|
|
138
|
+
*/
|
|
139
|
+
private rescueCandidates;
|
|
140
|
+
private removeModuleTokens;
|
|
141
|
+
/**
|
|
142
|
+
* Purges `_moduleProviders`/`_moduleReferrers` index entries for
|
|
143
|
+
* `tokens`, and removes each of them from any surviving module's
|
|
144
|
+
* referrer set. Shared by `removeModuleTokens` (destroying a live
|
|
145
|
+
* segment) and `removeTokens` (rolling back a failed one).
|
|
146
|
+
*
|
|
147
|
+
* `tokens` may freely mix module tokens with provider or LAZY
|
|
148
|
+
* placeholder tokens: both indexes are keyed by module tokens only, so a
|
|
149
|
+
* lookup or delete with a non-module key is a harmless no-op.
|
|
150
|
+
*
|
|
151
|
+
* Must run before the tokens' own `_edges` entries (and, for a removed
|
|
152
|
+
* module, its `_moduleProviders` entry) are deleted — `moduleDependencies`
|
|
153
|
+
* reads both to determine what each token itself depended on.
|
|
154
|
+
*/
|
|
155
|
+
private purgeModuleIndexes;
|
|
156
|
+
addRuntimeDependency(source: ProviderToken, target: ProviderToken): void;
|
|
157
|
+
findChildDeclaration(child: Type | LazyModule): ModuleContainerInterface | undefined;
|
|
158
|
+
getNode(token: ProviderToken): Node | undefined;
|
|
159
|
+
getEdge(token: ProviderToken): Edge[];
|
|
15
160
|
getAllEdges(): Edge[][];
|
|
16
161
|
getAllNodes(): Node[];
|
|
17
162
|
private addModules;
|
|
18
163
|
private addModule;
|
|
164
|
+
/**
|
|
165
|
+
* Records the module's declared children. Children are never compiled into
|
|
166
|
+
* this graph; only the declaration is indexed. A child declared by a second
|
|
167
|
+
* module is a graph error and keeps its first declarer.
|
|
168
|
+
*/
|
|
169
|
+
private indexChildren;
|
|
170
|
+
private moduleLabel;
|
|
171
|
+
/**
|
|
172
|
+
* @returns the ids of the LAZY placeholder nodes this call created, so a
|
|
173
|
+
* rolled back segment can remove them again. Placeholders that already
|
|
174
|
+
* existed are not reported and must never be removed.
|
|
175
|
+
*/
|
|
19
176
|
private addModuleImports;
|
|
20
177
|
private addModuleProviders;
|
|
21
178
|
private addEdge;
|
|
22
179
|
private addNode;
|
|
180
|
+
private addModuleProvider;
|
|
181
|
+
private addModuleReferrer;
|
|
182
|
+
/**
|
|
183
|
+
* Bookkeeping for a static `DEPENDENCY` edge just added: a late-bound
|
|
184
|
+
* edge is indexed (its referrer is recorded by `bindLateEdges` once the
|
|
185
|
+
* target is visible), any other edge records its referrer now.
|
|
186
|
+
*/
|
|
187
|
+
private recordStaticDependency;
|
|
188
|
+
/**
|
|
189
|
+
* Records that `consumerToken` (a provider) keeps `dependencyToken`'s
|
|
190
|
+
* declaring module alive, when the two providers are declared in
|
|
191
|
+
* different modules. Called after every `DEPENDENCY` edge is added,
|
|
192
|
+
* regardless of how the dependency was resolved (own module, import, or
|
|
193
|
+
* `@Global()` fallback) — the edge already reflects that, so this needs
|
|
194
|
+
* no help from `isProviderExported`.
|
|
195
|
+
*
|
|
196
|
+
* @param countsAsReferrer - False for an edge that keeps nothing in this
|
|
197
|
+
* graph alive: an unreached dependency, or an external one (resolved
|
|
198
|
+
* through the parent link, so its target lives in another container).
|
|
199
|
+
*/
|
|
200
|
+
private recordCrossModuleReferrer;
|
|
23
201
|
private addDependencies;
|
|
24
202
|
private addClassDependency;
|
|
25
203
|
private addClassProviderDependency;
|
|
26
204
|
private addFactoryProviderDependency;
|
|
27
|
-
|
|
205
|
+
/**
|
|
206
|
+
* How a dependency of a provider declared in `moduleContainer` is
|
|
207
|
+
* satisfied: locally (own module, imports, globals), by the parent
|
|
208
|
+
* container chain, or not at all. Optional dependencies count as
|
|
209
|
+
* satisfied; a parent that can provide one is still preferred. An
|
|
210
|
+
* optional dependency satisfied only by being optional is `lateBound`:
|
|
211
|
+
* the resolver injects it only once it exists and is visible.
|
|
212
|
+
*/
|
|
213
|
+
private reachDependency;
|
|
214
|
+
isProviderExported(moduleContainer: ModuleContainerInterface, dependencyToken: ProviderToken): Promise<boolean>;
|
|
215
|
+
isProviderVisible(moduleContainer: ModuleContainerInterface, dependencyToken: ProviderToken): boolean;
|
|
216
|
+
/**
|
|
217
|
+
* Whether `dependencyToken` is among `exports`, following module-class
|
|
218
|
+
* re-exports through the modules' own exports.
|
|
219
|
+
*/
|
|
220
|
+
private exportsReach;
|
|
28
221
|
private detectCircularDependencies;
|
|
29
222
|
private detectCircularImports;
|
|
30
223
|
private getConstructorDependencies;
|
|
@@ -2,6 +2,6 @@ import type { ClassProvider } from "../../../interfaces";
|
|
|
2
2
|
import { AnalyzeProvider } from "../analyze-provider";
|
|
3
3
|
export declare class AnalyzeClassProvider extends AnalyzeProvider {
|
|
4
4
|
get metatype(): ClassProvider;
|
|
5
|
-
get provide(): import("
|
|
5
|
+
get provide(): import("@nexus-ioc/shared").ProviderToken;
|
|
6
6
|
get useClass(): import("../../..").Type<any>;
|
|
7
7
|
}
|
|
@@ -2,6 +2,6 @@ import type { FactoryProvider } from "../../../interfaces";
|
|
|
2
2
|
import { AnalyzeProvider } from "../analyze-provider";
|
|
3
3
|
export declare class AnalyzeFactoryProvider extends AnalyzeProvider {
|
|
4
4
|
get metatype(): FactoryProvider;
|
|
5
|
-
get provide(): import("
|
|
6
|
-
get inject(): import("../../..").
|
|
5
|
+
get provide(): import("@nexus-ioc/shared").ProviderToken;
|
|
6
|
+
get inject(): (import("../../..").ForwardRef<unknown> | import("@nexus-ioc/shared").ProviderToken)[] | undefined;
|
|
7
7
|
}
|
|
@@ -2,6 +2,6 @@ import type { ValueProvider } from "../../../interfaces";
|
|
|
2
2
|
import { AnalyzeProvider } from "../analyze-provider";
|
|
3
3
|
export declare class AnalyzeValueProvider extends AnalyzeProvider {
|
|
4
4
|
get metatype(): ValueProvider;
|
|
5
|
-
get provide(): import("
|
|
5
|
+
get provide(): import("@nexus-ioc/shared").ProviderToken;
|
|
6
6
|
get useValue(): any;
|
|
7
7
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ProviderToken } from "../../interfaces";
|
|
2
|
+
export interface InjectOptions {
|
|
3
|
+
/** Return undefined instead of throwing when the token is not available. */
|
|
4
|
+
optional?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface InjectionContext {
|
|
7
|
+
inject(token: ProviderToken, options: InjectOptions): unknown;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Runs `fn` with `ctx` as the current injection context (`null` = none)
|
|
11
|
+
* and restores the previous one afterwards, even if `fn` throws.
|
|
12
|
+
*
|
|
13
|
+
* @internal Not exported from the package entry point.
|
|
14
|
+
*/
|
|
15
|
+
export declare function withInjectionContext<R>(ctx: InjectionContext | null, fn: () => R): R;
|
|
16
|
+
/**
|
|
17
|
+
* Returns the provider for `token` from the container that is currently
|
|
18
|
+
* creating an instance. Callable only synchronously during creation: in
|
|
19
|
+
* field initializers, constructor bodies and factory functions.
|
|
20
|
+
*
|
|
21
|
+
* @throws {InjectionContextError} When called outside of an injection context
|
|
22
|
+
* @throws {ProviderNotFoundError} When the token is not visible to the requester and `optional` is not set
|
|
23
|
+
* @throws {CircularInjectionError} When the token is already being created in this resolution
|
|
24
|
+
*/
|
|
25
|
+
export declare function inject<T>(token: ProviderToken<T>): T;
|
|
26
|
+
export declare function inject<T>(token: ProviderToken<T>, options: {
|
|
27
|
+
optional: true;
|
|
28
|
+
}): T | undefined;
|
|
29
|
+
export declare function inject<T>(token: ProviderToken<T>, options: InjectOptions): T | undefined;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import type { DynamicModule, LazyModule, UnloadResult } from "../interfaces";
|
|
3
|
+
import type { ModuleRef } from "./module-ref";
|
|
4
|
+
/**
|
|
5
|
+
* Built-in provider that lets any service load a lazy module on demand.
|
|
6
|
+
* Registered automatically by `NexusApplication`; inject it with
|
|
7
|
+
* `@Inject(LazyModuleLoader)`.
|
|
8
|
+
*/
|
|
9
|
+
export declare class LazyModuleLoader {
|
|
10
|
+
private readonly loadFn;
|
|
11
|
+
private readonly unloadFn;
|
|
12
|
+
constructor(loadFn: (lazyModule: LazyModule) => Promise<ModuleRef>, unloadFn: (ref: ModuleRef) => Promise<UnloadResult>);
|
|
13
|
+
load(lazyModule: LazyModule): Promise<ModuleRef>;
|
|
14
|
+
unload(ref: ModuleRef): Promise<UnloadResult>;
|
|
15
|
+
}
|
|
16
|
+
/** Global module carrying the application's built-in providers. */
|
|
17
|
+
export declare function createInternalModule(loader: LazyModuleLoader): DynamicModule;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ContainerInterface, GraphSegment, ProviderToken, Type, UnloadResult } from "../interfaces";
|
|
2
|
+
export interface ModuleRefGetOptions {
|
|
3
|
+
/**
|
|
4
|
+
* `true` (default): only tokens the module can see — its own providers and
|
|
5
|
+
* providers exported to it by its imports or by global modules.
|
|
6
|
+
* `false`: any token in the container.
|
|
7
|
+
*/
|
|
8
|
+
strict?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Handle to a lazily loaded module. Providers physically live in the
|
|
12
|
+
* application's single container; `get()` and `resolve()` only scope what is
|
|
13
|
+
* visible. `get()` is synchronous and returns already-created singletons;
|
|
14
|
+
* `resolve()` is async and creates transient/scoped/uncreated providers on demand.
|
|
15
|
+
*/
|
|
16
|
+
export declare class ModuleRef {
|
|
17
|
+
private readonly container;
|
|
18
|
+
private readonly segment;
|
|
19
|
+
private _loaded;
|
|
20
|
+
constructor(container: ContainerInterface, segment: GraphSegment);
|
|
21
|
+
get name(): string;
|
|
22
|
+
get module(): Type;
|
|
23
|
+
/** `false` once `unload()` has run; a later `load()` of the same ref
|
|
24
|
+
* returns a new `ModuleRef` instead of reactivating this one. */
|
|
25
|
+
get loaded(): boolean;
|
|
26
|
+
get<T>(token: ProviderToken<T>, options?: ModuleRefGetOptions): T | undefined;
|
|
27
|
+
resolve<T>(token: ProviderToken<T>, options?: ModuleRefGetOptions): Promise<T | undefined>;
|
|
28
|
+
private canSee;
|
|
29
|
+
/**
|
|
30
|
+
* Unloads this segment: destroys every singleton and module nothing else
|
|
31
|
+
* still needs. A no-op if already unloaded.
|
|
32
|
+
*/
|
|
33
|
+
unload(): Promise<UnloadResult>;
|
|
34
|
+
}
|