@zlink-systems/nestjs 0.26.0 → 0.27.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/dist/.tsbuildinfo +1 -1
- package/dist/dispatch-scope.d.ts +1 -2
- package/dist/dispatch-scope.js +0 -4
- package/dist/framework-loader.d.ts +17 -0
- package/dist/framework-loader.js +13 -1
- package/dist/handler-adapters.d.ts +0 -2
- package/dist/handler-adapters.js +2 -10
- package/dist/handler-metadata.d.ts +3 -2
- package/dist/handler-metadata.js +7 -1
- package/dist/http-client-module.js +2 -4
- package/dist/module.js +4 -6
- package/dist/options-builder.js +20 -30
- package/dist/providers.d.ts +1 -2
- package/dist/providers.js +20 -49
- package/dist/registration-composer.d.ts +0 -1
- package/dist/registration-composer.js +0 -14
- package/package.json +3 -3
package/dist/dispatch-scope.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ZLinkMessageContext } from '@zlink-systems/framework';
|
|
2
2
|
import type { ContextId, ModuleRef } from '@nestjs/core';
|
|
3
3
|
export declare function runInNestDispatchScope<T>(moduleRef: ModuleRef, context: ZLinkMessageContext, callback: () => Promise<T>): Promise<T>;
|
|
4
|
-
export declare function resolveInNestDispatchScope<T>(moduleRef: ModuleRef, type: Type<T>): Promise<T>;
|
|
5
4
|
export declare function currentNestDispatchContext(): ContextId | undefined;
|
package/dist/dispatch-scope.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.runInNestDispatchScope = runInNestDispatchScope;
|
|
4
|
-
exports.resolveInNestDispatchScope = resolveInNestDispatchScope;
|
|
5
4
|
exports.currentNestDispatchContext = currentNestDispatchContext;
|
|
6
5
|
const node_async_hooks_1 = require("node:async_hooks");
|
|
7
6
|
const core_1 = require("@nestjs/core");
|
|
@@ -11,9 +10,6 @@ async function runInNestDispatchScope(moduleRef, context, callback) {
|
|
|
11
10
|
moduleRef.registerRequestByContextId({ zlinkContext: context }, contextId);
|
|
12
11
|
return dispatchContext.run(contextId, callback);
|
|
13
12
|
}
|
|
14
|
-
async function resolveInNestDispatchScope(moduleRef, type) {
|
|
15
|
-
return await moduleRef.resolve(type, dispatchContext.getStore(), { strict: false });
|
|
16
|
-
}
|
|
17
13
|
function currentNestDispatchContext() {
|
|
18
14
|
return dispatchContext.getStore();
|
|
19
15
|
}
|
|
@@ -3,8 +3,17 @@ import type { ZLinkHttpExecutionScheduler } from '@zlink-systems/http-client';
|
|
|
3
3
|
import type { ZLinkCodecSerializerRegistration, ZLinkFrameworkRegistration, ZLinkFrameworkRegistrationOptions, ZLinkNestIntegrationRuntimeHost, ZLinkProviderResolver, ZLinkStreamCodecRegistration } from './framework-integration-contracts';
|
|
4
4
|
export type FrameworkRuntimeHost = ZLinkNestIntegrationRuntimeHost;
|
|
5
5
|
interface FrameworkIntegrationModule {
|
|
6
|
+
ZLinkSpotActorSend(packetName?: string): MethodDecorator;
|
|
7
|
+
ZLinkSpotActorRequest(packetName?: string): MethodDecorator;
|
|
8
|
+
disposeIntegrationHandler(instance: unknown): Promise<void>;
|
|
9
|
+
disposeIntegrationHandlers(instances: readonly unknown[]): Promise<void>;
|
|
10
|
+
readonly MAX_LISTENER_PORT: number;
|
|
11
|
+
readonly ZLINK_MAX_PUBLIC_WEIGHT: number;
|
|
12
|
+
readonly ZLINK_MAX_CAPACITY: number;
|
|
13
|
+
readonly ZLINK_MAX_STABLE_TYPE_BYTES: number;
|
|
6
14
|
readonly ZLinkConfigurationException: new (message: string) => Error;
|
|
7
15
|
createFrameworkRegistration(options: ZLinkFrameworkRegistrationOptions): ZLinkFrameworkRegistration;
|
|
16
|
+
normalizeFrameworkRegistration(options: ZLinkFrameworkRegistrationOptions): ZLinkFrameworkRegistration;
|
|
8
17
|
hasActorManager(registration: ZLinkFrameworkRegistration): boolean;
|
|
9
18
|
hasSpotNode(registration: ZLinkFrameworkRegistration): boolean;
|
|
10
19
|
hasSpotPublisherClient(registration: ZLinkFrameworkRegistration): boolean;
|
|
@@ -33,6 +42,11 @@ interface FrameworkIntegrationModule {
|
|
|
33
42
|
validateMessageFollowDuration(timeoutMs: number): number;
|
|
34
43
|
validateSessionReplacementCallbackTimeout(timeoutMs: number): number;
|
|
35
44
|
validateRoutingIdPrefix(prefix: string): string;
|
|
45
|
+
isValidPublicWeight(value: number): boolean;
|
|
46
|
+
requirePublicWeight(value: number, label: string): number;
|
|
47
|
+
isValidPositiveCapacity(value: number): boolean;
|
|
48
|
+
isValidListenerPort(value: number): boolean;
|
|
49
|
+
isValidCapacity(value: number): boolean;
|
|
36
50
|
registerEntrySpot(options: {
|
|
37
51
|
entrySpotType?: Type<ZLinkEntrySpot>;
|
|
38
52
|
}, entrySpotType: Type<ZLinkEntrySpot>): void;
|
|
@@ -42,6 +56,9 @@ interface FrameworkIntegrationModule {
|
|
|
42
56
|
registerActorFactory(options: {
|
|
43
57
|
actorFactories?: Record<string, Type>;
|
|
44
58
|
}, actorType: string, factoryType: Type): void;
|
|
59
|
+
registerRelocationStore(options: {
|
|
60
|
+
relocationStoreInstance?: import('@zlink-systems/framework').ZLinkRelocationStore;
|
|
61
|
+
}, store: import('@zlink-systems/framework').ZLinkRelocationStore): void;
|
|
45
62
|
registerIntegrationHandlerFilterScope(resolver: ZLinkProviderResolver, runner: (context: ZLinkHandlerFilterContext, callback: (scope: {
|
|
46
63
|
resolve<T>(type: Type<T>): Promise<T>;
|
|
47
64
|
}) => Promise<unknown>) => Promise<unknown>): void;
|
package/dist/framework-loader.js
CHANGED
|
@@ -9,7 +9,19 @@ const node_path_1 = __importDefault(require("node:path"));
|
|
|
9
9
|
function loadFramework() {
|
|
10
10
|
const requireFramework = (0, node_module_1.createRequire)(__filename);
|
|
11
11
|
const frameworkEntry = requireFramework.resolve('@zlink-systems/framework');
|
|
12
|
-
|
|
12
|
+
const internal = requireFramework(node_path_1.default.join(node_path_1.default.dirname(frameworkEntry), 'internal'));
|
|
13
|
+
return {
|
|
14
|
+
...requireFramework(node_path_1.default.join(node_path_1.default.dirname(frameworkEntry), 'nest-integration')),
|
|
15
|
+
MAX_LISTENER_PORT: internal.MAX_LISTENER_PORT,
|
|
16
|
+
ZLINK_MAX_PUBLIC_WEIGHT: internal.ZLINK_MAX_PUBLIC_WEIGHT,
|
|
17
|
+
ZLINK_MAX_CAPACITY: internal.ZLINK_MAX_CAPACITY,
|
|
18
|
+
ZLINK_MAX_STABLE_TYPE_BYTES: internal.ZLINK_MAX_STABLE_TYPE_BYTES,
|
|
19
|
+
isValidPublicWeight: internal.isValidPublicWeight,
|
|
20
|
+
isValidPositiveCapacity: internal.isValidPositiveCapacity,
|
|
21
|
+
isValidListenerPort: internal.isValidListenerPort,
|
|
22
|
+
isValidCapacity: internal.isValidCapacity,
|
|
23
|
+
requirePublicWeight: internal.requirePublicWeight
|
|
24
|
+
};
|
|
13
25
|
}
|
|
14
26
|
// The Nest package is a workspace adapter. It loads the framework's private
|
|
15
27
|
// composition bridge without turning that bridge into a package subpath.
|
|
@@ -9,5 +9,3 @@ export declare function createDiscoveredPublishHandlers(providerRefs: readonly D
|
|
|
9
9
|
export declare function createManualRequestHandlers(handlerTypes: readonly ZLinkNestManualHandlerOptions[] | undefined, moduleRef: ModuleRef): NonNullable<ZLinkChannelOptions['requestHandlers']>;
|
|
10
10
|
export declare function createManualPublishHandlers(handlerTypes: readonly ZLinkNestManualHandlerOptions[] | undefined, moduleRef: ModuleRef): NonNullable<ZLinkChannelOptions['publishHandlers']>;
|
|
11
11
|
export declare function createManualSendHandlers(handlerTypes: readonly ZLinkNestManualHandlerOptions[] | undefined, moduleRef: ModuleRef): NonNullable<ZLinkChannelOptions['sendHandlers']>;
|
|
12
|
-
export declare function createManualRouteSendHandlers(handlerTypes: readonly ZLinkNestManualHandlerOptions[] | undefined, moduleRef: ModuleRef): NonNullable<NonNullable<ZLinkChannelOptions['routeMesh']>['sendHandlers']>;
|
|
13
|
-
export declare function createManualRouteRequestHandlers(handlerTypes: readonly ZLinkNestManualHandlerOptions[] | undefined, moduleRef: ModuleRef): NonNullable<NonNullable<ZLinkChannelOptions['routeMesh']>['requestHandlers']>;
|
package/dist/handler-adapters.js
CHANGED
|
@@ -7,8 +7,6 @@ exports.createDiscoveredPublishHandlers = createDiscoveredPublishHandlers;
|
|
|
7
7
|
exports.createManualRequestHandlers = createManualRequestHandlers;
|
|
8
8
|
exports.createManualPublishHandlers = createManualPublishHandlers;
|
|
9
9
|
exports.createManualSendHandlers = createManualSendHandlers;
|
|
10
|
-
exports.createManualRouteSendHandlers = createManualRouteSendHandlers;
|
|
11
|
-
exports.createManualRouteRequestHandlers = createManualRouteRequestHandlers;
|
|
12
10
|
const core_1 = require("@nestjs/core");
|
|
13
11
|
const framework_loader_1 = require("./framework-loader");
|
|
14
12
|
const dispatch_scope_1 = require("./dispatch-scope");
|
|
@@ -53,12 +51,6 @@ function createManualPublishHandlers(handlerTypes, moduleRef) {
|
|
|
53
51
|
function createManualSendHandlers(handlerTypes, moduleRef) {
|
|
54
52
|
return createManualHandlerRegistrations(handlerTypes, moduleRef, () => undefined);
|
|
55
53
|
}
|
|
56
|
-
function createManualRouteSendHandlers(handlerTypes, moduleRef) {
|
|
57
|
-
return createManualHandlerRegistrations(handlerTypes, moduleRef, () => undefined);
|
|
58
|
-
}
|
|
59
|
-
function createManualRouteRequestHandlers(handlerTypes, moduleRef) {
|
|
60
|
-
return createManualHandlerRegistrations(handlerTypes, moduleRef, (result) => result);
|
|
61
|
-
}
|
|
62
54
|
function createManualHandlerRegistrations(handlerTypes, moduleRef, result) {
|
|
63
55
|
return (handlerTypes ?? []).map((registration) => ({
|
|
64
56
|
packetName: registration.packetName,
|
|
@@ -111,7 +103,7 @@ async function invokeDiscoveredHandler(moduleRef, ref, metadata, payload, contex
|
|
|
111
103
|
return await method.call(instance, decodePayload(metadata, payload, context), context);
|
|
112
104
|
}
|
|
113
105
|
finally {
|
|
114
|
-
await
|
|
106
|
+
await framework_loader_1.framework.disposeIntegrationHandler(instance);
|
|
115
107
|
}
|
|
116
108
|
}
|
|
117
109
|
async function invokeManualHandler(moduleRef, handlerType, payload, context) {
|
|
@@ -124,7 +116,7 @@ async function invokeManualHandler(moduleRef, handlerType, payload, context) {
|
|
|
124
116
|
return await method.call(instance, decodePayload(undefined, payload, context), context);
|
|
125
117
|
}
|
|
126
118
|
finally {
|
|
127
|
-
await
|
|
119
|
+
await framework_loader_1.framework.disposeIntegrationHandler(instance);
|
|
128
120
|
}
|
|
129
121
|
}
|
|
130
122
|
async function resolveHandlerInstance(moduleRef, handlerType, context) {
|
|
@@ -14,7 +14,6 @@ export type ZLinkNestSpotActorHandlerKind = 'spotActorSend' | 'spotActorRequest'
|
|
|
14
14
|
export interface ZLinkNestSpotActorHandlerMetadata {
|
|
15
15
|
readonly kind: ZLinkNestSpotActorHandlerKind;
|
|
16
16
|
readonly packetName: string;
|
|
17
|
-
readonly methodName: string;
|
|
18
17
|
readonly handlerType: Type;
|
|
19
18
|
readonly actor: ZLinkNestTypeResolver<ZLinkActor>;
|
|
20
19
|
readonly spot?: ZLinkNestTypeResolver<ZLinkSpot>;
|
|
@@ -40,7 +39,9 @@ export interface ZLinkNestSpotTimerHandlerMetadata {
|
|
|
40
39
|
}
|
|
41
40
|
export declare function appendNestHandlerMetadata(handlerToken: InjectionToken, metadata: ZLinkNestHandlerMetadata): void;
|
|
42
41
|
export declare function readNestHandlerMetadata(handlerToken: InjectionToken | undefined): readonly ZLinkNestHandlerMetadata[];
|
|
43
|
-
export declare function appendNestSpotActorHandlerMetadata(handlerToken: InjectionToken, metadata: ZLinkNestSpotActorHandlerMetadata
|
|
42
|
+
export declare function appendNestSpotActorHandlerMetadata(handlerToken: InjectionToken, metadata: ZLinkNestSpotActorHandlerMetadata & {
|
|
43
|
+
readonly methodName: string;
|
|
44
|
+
}): void;
|
|
44
45
|
export declare function readNestSpotActorHandlerMetadata(handlerToken: InjectionToken | undefined): readonly ZLinkNestSpotActorHandlerMetadata[];
|
|
45
46
|
export declare function appendNestSpotHandlerMetadata(handlerToken: InjectionToken, metadata: ZLinkNestSpotHandlerMetadata): void;
|
|
46
47
|
export declare function readNestSpotHandlerMetadata(handlerToken: InjectionToken | undefined): readonly ZLinkNestSpotHandlerMetadata[];
|
package/dist/handler-metadata.js
CHANGED
|
@@ -15,6 +15,7 @@ exports.nestSpotActorHandlerMetadataEntries = nestSpotActorHandlerMetadataEntrie
|
|
|
15
15
|
exports.nestSpotHandlerMetadataEntries = nestSpotHandlerMetadataEntries;
|
|
16
16
|
exports.nestSpotTimerHandlerMetadataEntries = nestSpotTimerHandlerMetadataEntries;
|
|
17
17
|
const tokens_1 = require("./tokens");
|
|
18
|
+
const framework_loader_1 = require("./framework-loader");
|
|
18
19
|
const handlerMetadata = new Map();
|
|
19
20
|
const spotActorHandlerMetadata = new Map();
|
|
20
21
|
const spotHandlerMetadata = new Map();
|
|
@@ -44,8 +45,13 @@ function readNestHandlerMetadata(handlerToken) {
|
|
|
44
45
|
return handlerMetadata.get(handlerToken) ?? reflected ?? [];
|
|
45
46
|
}
|
|
46
47
|
function appendNestSpotActorHandlerMetadata(handlerToken, metadata) {
|
|
48
|
+
const { methodName, ...registration } = metadata;
|
|
49
|
+
const decorator = metadata.kind === 'spotActorSend' || metadata.kind === 'entrySpotActorSend'
|
|
50
|
+
? framework_loader_1.framework.ZLinkSpotActorSend(metadata.packetName)
|
|
51
|
+
: framework_loader_1.framework.ZLinkSpotActorRequest(metadata.packetName);
|
|
52
|
+
decorator(metadata.handlerType.prototype, methodName, {});
|
|
47
53
|
const current = readNestSpotActorHandlerMetadata(handlerToken);
|
|
48
|
-
spotActorHandlerMetadata.set(handlerToken, [...current,
|
|
54
|
+
spotActorHandlerMetadata.set(handlerToken, [...current, registration]);
|
|
49
55
|
}
|
|
50
56
|
function readNestSpotActorHandlerMetadata(handlerToken) {
|
|
51
57
|
return handlerToken === undefined ? [] : (spotActorHandlerMetadata.get(handlerToken) ?? []);
|
|
@@ -14,6 +14,7 @@ const core_1 = require("@nestjs/core");
|
|
|
14
14
|
const http_client_1 = require("@zlink-systems/http-client");
|
|
15
15
|
const framework_loader_1 = require("./framework-loader");
|
|
16
16
|
const tokens_1 = require("./tokens");
|
|
17
|
+
const providers_1 = require("./providers");
|
|
17
18
|
const ZLINK_HTTP_CLIENT_REGISTRY = Symbol.for('@zlink-systems/nestjs:http-client-registry');
|
|
18
19
|
function zlinkHttpClientToken(name) {
|
|
19
20
|
const normalized = name.trim();
|
|
@@ -74,7 +75,7 @@ let ZLinkHttpClientModule = ZLinkHttpClientModule_1 = class ZLinkHttpClientModul
|
|
|
74
75
|
module: ZLinkHttpClientModule_1,
|
|
75
76
|
imports: options.imports,
|
|
76
77
|
providers: [registry, ...clients],
|
|
77
|
-
exports: clients.map((provider) => providerToken(provider))
|
|
78
|
+
exports: clients.map((provider) => (0, providers_1.providerToken)(provider))
|
|
78
79
|
};
|
|
79
80
|
}
|
|
80
81
|
};
|
|
@@ -93,6 +94,3 @@ function validateRegistrations(registrations) {
|
|
|
93
94
|
names.add(name);
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
|
-
function providerToken(provider) {
|
|
97
|
-
return typeof provider === 'function' ? provider : provider.provide;
|
|
98
|
-
}
|
package/dist/module.js
CHANGED
|
@@ -96,10 +96,7 @@ function addDecoratedProviderModuleExports(providers, filePath) {
|
|
|
96
96
|
let ZLinkModule = ZLinkModule_1 = class ZLinkModule {
|
|
97
97
|
static forRoot(options = (0, options_builder_1.createZLinkNestFrameworkOptionsBuilder)().build()) {
|
|
98
98
|
const resolvedOptions = (0, registration_composer_1.assertBuiltModuleOptions)(options);
|
|
99
|
-
|
|
100
|
-
return createDiscoveringZLinkDynamicModule(resolvedOptions);
|
|
101
|
-
}
|
|
102
|
-
return createZLinkDynamicModule(framework_loader_1.framework.createFrameworkRegistration((0, registration_composer_1.createRegistrationOptions)(resolvedOptions)));
|
|
99
|
+
return createDiscoveringZLinkDynamicModule(resolvedOptions);
|
|
103
100
|
}
|
|
104
101
|
static forRootFactory(options) {
|
|
105
102
|
const registrationProvider = {
|
|
@@ -157,6 +154,7 @@ function createZLinkDynamicModule(registration) {
|
|
|
157
154
|
};
|
|
158
155
|
}
|
|
159
156
|
function createDiscoveringZLinkDynamicModule(options) {
|
|
157
|
+
const conditionalProviders = (0, providers_1.conditionalClientProvidersForFactory)(framework_loader_1.framework.normalizeFrameworkRegistration((0, registration_composer_1.createRegistrationOptions)(options)));
|
|
160
158
|
const registrationProvider = {
|
|
161
159
|
provide: tokens_1.ZLINK_FRAMEWORK_REGISTRATION,
|
|
162
160
|
inject: [core_1.DiscoveryService, core_1.ModuleRef],
|
|
@@ -173,12 +171,12 @@ function createDiscoveringZLinkDynamicModule(options) {
|
|
|
173
171
|
useFactory: (registration, moduleRef, discovery) => (0, providers_1.createRuntimeHost)(registration, moduleRef, discovery)
|
|
174
172
|
},
|
|
175
173
|
...(0, providers_1.alwaysAvailableClientProviders)(),
|
|
176
|
-
...
|
|
174
|
+
...conditionalProviders
|
|
177
175
|
],
|
|
178
176
|
exports: [
|
|
179
177
|
tokens_1.ZLINK_FRAMEWORK_RUNTIME,
|
|
180
178
|
...(0, providers_1.alwaysAvailableClientTokens)(),
|
|
181
|
-
...(
|
|
179
|
+
...conditionalProviders.map(providers_1.providerToken)
|
|
182
180
|
]
|
|
183
181
|
};
|
|
184
182
|
}
|
package/dist/options-builder.js
CHANGED
|
@@ -95,13 +95,9 @@ class ZLinkNestOptionsBuilder {
|
|
|
95
95
|
return this;
|
|
96
96
|
}
|
|
97
97
|
addRelocationStore(store) {
|
|
98
|
-
this.state.additionalOptions
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
...(this.state.additionalOptions.locations ?? {}),
|
|
102
|
-
relocationStoreInstance: store
|
|
103
|
-
}
|
|
104
|
-
};
|
|
98
|
+
const locations = { ...(this.state.additionalOptions.locations ?? {}) };
|
|
99
|
+
framework_loader_1.framework.registerRelocationStore(locations, store);
|
|
100
|
+
this.state.additionalOptions = { ...this.state.additionalOptions, locations };
|
|
105
101
|
return this;
|
|
106
102
|
}
|
|
107
103
|
setApplicationVersion(version) {
|
|
@@ -360,8 +356,8 @@ class DefaultZLinkNestClientServerChannelServerBuilder extends ZLinkNestOptionsB
|
|
|
360
356
|
this.channel = channel;
|
|
361
357
|
}
|
|
362
358
|
listen(port = 0) {
|
|
363
|
-
if (!
|
|
364
|
-
throw new framework_loader_1.framework.ZLinkConfigurationException(`ClientServer channel '${this.name}' port must be between 0 and
|
|
359
|
+
if (!framework_loader_1.framework.isValidListenerPort(port)) {
|
|
360
|
+
throw new framework_loader_1.framework.ZLinkConfigurationException(`ClientServer channel '${this.name}' port must be between 0 and ${framework_loader_1.framework.MAX_LISTENER_PORT}.`);
|
|
365
361
|
}
|
|
366
362
|
this.updateServer({ port });
|
|
367
363
|
this.updateBind();
|
|
@@ -380,8 +376,8 @@ class DefaultZLinkNestClientServerChannelServerBuilder extends ZLinkNestOptionsB
|
|
|
380
376
|
return this;
|
|
381
377
|
}
|
|
382
378
|
setWeight(weight) {
|
|
383
|
-
if (!
|
|
384
|
-
throw new framework_loader_1.framework.ZLinkConfigurationException(`ClientServer channel '${this.name}' weight must be between 0 and
|
|
379
|
+
if (!framework_loader_1.framework.isValidPublicWeight(weight)) {
|
|
380
|
+
throw new framework_loader_1.framework.ZLinkConfigurationException(`ClientServer channel '${this.name}' weight must be between 0 and ${framework_loader_1.framework.ZLINK_MAX_PUBLIC_WEIGHT}.`);
|
|
385
381
|
}
|
|
386
382
|
this.updateServer({ weight });
|
|
387
383
|
return this;
|
|
@@ -426,17 +422,11 @@ function requireClientServerText(value, label) {
|
|
|
426
422
|
}
|
|
427
423
|
function requireListenerPort(port, label) {
|
|
428
424
|
const normalized = port ?? 0;
|
|
429
|
-
if (!
|
|
430
|
-
throw new framework_loader_1.framework.ZLinkConfigurationException(`${label} port must be between 0 and
|
|
425
|
+
if (!framework_loader_1.framework.isValidListenerPort(normalized)) {
|
|
426
|
+
throw new framework_loader_1.framework.ZLinkConfigurationException(`${label} port must be between 0 and ${framework_loader_1.framework.MAX_LISTENER_PORT}.`);
|
|
431
427
|
}
|
|
432
428
|
return normalized;
|
|
433
429
|
}
|
|
434
|
-
function requirePublicWeight(value, label) {
|
|
435
|
-
if (!Number.isInteger(value) || value < 0 || value > 10_000) {
|
|
436
|
-
throw new framework_loader_1.framework.ZLinkConfigurationException(`${label} must be an integer in 0..10000.`);
|
|
437
|
-
}
|
|
438
|
-
return value;
|
|
439
|
-
}
|
|
440
430
|
function rejectFixedRoutingId(routingId, memberName) {
|
|
441
431
|
if (routingId !== undefined) {
|
|
442
432
|
throw new framework_loader_1.framework.ZLinkConfigurationException(`Mesh member '${memberName}' cannot combine a fixed routing id with a generated prefix.`);
|
|
@@ -559,8 +549,8 @@ class DefaultZLinkNestMeshNodeBuilder extends ZLinkNestOptionsBuilder {
|
|
|
559
549
|
return this;
|
|
560
550
|
}
|
|
561
551
|
setPlacementWeight(weight) {
|
|
562
|
-
if (!
|
|
563
|
-
throw new framework_loader_1.framework.ZLinkConfigurationException(
|
|
552
|
+
if (!framework_loader_1.framework.isValidPublicWeight(weight)) {
|
|
553
|
+
throw new framework_loader_1.framework.ZLinkConfigurationException(`Placement weight must be an integer in 0..${framework_loader_1.framework.ZLINK_MAX_PUBLIC_WEIGHT}.`);
|
|
564
554
|
}
|
|
565
555
|
this.spotOptions.placementWeight = weight;
|
|
566
556
|
return this;
|
|
@@ -850,9 +840,9 @@ class DefaultZLinkNestMeshObjectServerBuilder extends ZLinkNestOptionsBuilder {
|
|
|
850
840
|
function validateObjectFactory(stableType, label) {
|
|
851
841
|
if (typeof stableType !== 'string' ||
|
|
852
842
|
Buffer.byteLength(stableType) < 1 ||
|
|
853
|
-
Buffer.byteLength(stableType) >
|
|
843
|
+
Buffer.byteLength(stableType) > framework_loader_1.framework.ZLINK_MAX_STABLE_TYPE_BYTES ||
|
|
854
844
|
stableType.includes('\0')) {
|
|
855
|
-
throw new framework_loader_1.framework.ZLinkConfigurationException(`${label} must contain 1
|
|
845
|
+
throw new framework_loader_1.framework.ZLinkConfigurationException(`${label} must contain 1..${framework_loader_1.framework.ZLINK_MAX_STABLE_TYPE_BYTES} UTF-8 bytes and no NUL.`);
|
|
856
846
|
}
|
|
857
847
|
return stableType;
|
|
858
848
|
}
|
|
@@ -879,19 +869,19 @@ function validateUserSpotFactoryConfiguration(options) {
|
|
|
879
869
|
}
|
|
880
870
|
}
|
|
881
871
|
function validateStableTypeLimit(value) {
|
|
882
|
-
if (value !== undefined &&
|
|
883
|
-
throw new framework_loader_1.framework.ZLinkConfigurationException(
|
|
872
|
+
if (value !== undefined && !framework_loader_1.framework.isValidCapacity(value)) {
|
|
873
|
+
throw new framework_loader_1.framework.ZLinkConfigurationException(`stableTypeLimit must be an integer from 0 through ${framework_loader_1.framework.ZLINK_MAX_CAPACITY}.`);
|
|
884
874
|
}
|
|
885
875
|
}
|
|
886
876
|
function requirePositiveCapacity(value, label) {
|
|
887
|
-
if (!
|
|
888
|
-
throw new framework_loader_1.framework.ZLinkConfigurationException(`${label} must be an integer in 1
|
|
877
|
+
if (!framework_loader_1.framework.isValidPositiveCapacity(value)) {
|
|
878
|
+
throw new framework_loader_1.framework.ZLinkConfigurationException(`${label} must be an integer in 1..${framework_loader_1.framework.ZLINK_MAX_CAPACITY}.`);
|
|
889
879
|
}
|
|
890
880
|
return value;
|
|
891
881
|
}
|
|
892
882
|
function requireCapacity(value, label) {
|
|
893
|
-
if (!
|
|
894
|
-
throw new framework_loader_1.framework.ZLinkConfigurationException(`${label} must be an integer in 0
|
|
883
|
+
if (!framework_loader_1.framework.isValidCapacity(value)) {
|
|
884
|
+
throw new framework_loader_1.framework.ZLinkConfigurationException(`${label} must be an integer in 0..${framework_loader_1.framework.ZLINK_MAX_CAPACITY}.`);
|
|
895
885
|
}
|
|
896
886
|
return value;
|
|
897
887
|
}
|
|
@@ -936,7 +926,7 @@ class DefaultZLinkNestMeshChannelServerBuilder extends ZLinkNestOptionsBuilder {
|
|
|
936
926
|
this.channel = channel;
|
|
937
927
|
}
|
|
938
928
|
setWeight(weight) {
|
|
939
|
-
this.channel.weight = requirePublicWeight(weight, 'Mesh channel weight');
|
|
929
|
+
this.channel.weight = framework_loader_1.framework.requirePublicWeight(weight, 'Mesh channel weight');
|
|
940
930
|
return this;
|
|
941
931
|
}
|
|
942
932
|
addSendHandler(packetName, handlerType) {
|
package/dist/providers.d.ts
CHANGED
|
@@ -7,10 +7,9 @@ type RuntimeHostWithNestLifecycle = FrameworkRuntimeHost & OnModuleInit & OnModu
|
|
|
7
7
|
export declare function alwaysAvailableClientProviders(registration?: ZLinkFrameworkRegistration): Provider[];
|
|
8
8
|
export declare function alwaysAvailableClientTokens(): InjectionToken[];
|
|
9
9
|
export declare function conditionalClientProviders(registration: ZLinkFrameworkRegistration): Provider[];
|
|
10
|
-
export declare function conditionalClientProvidersForFactory(): Provider[];
|
|
10
|
+
export declare function conditionalClientProvidersForFactory(registration?: ZLinkFrameworkRegistration): Provider[];
|
|
11
11
|
export declare function conditionalClientTokens(): InjectionToken[];
|
|
12
12
|
export declare function createRuntimeHost(registration: ZLinkFrameworkRegistration, moduleRef: ModuleRef, discovery: DiscoveryService): RuntimeHostWithNestLifecycle;
|
|
13
|
-
export declare function disposeNestOwnedHandler(instance: unknown): Promise<void>;
|
|
14
13
|
export declare function createNestHandlerInstance<T>(moduleRef: ModuleRef, contextId: import('@nestjs/core').ContextId, dependencies: Map<unknown, Promise<unknown>>, type: Type<T>): Promise<T>;
|
|
15
14
|
export declare function providerToken(provider: Provider): InjectionToken;
|
|
16
15
|
export {};
|
package/dist/providers.js
CHANGED
|
@@ -6,7 +6,6 @@ exports.conditionalClientProviders = conditionalClientProviders;
|
|
|
6
6
|
exports.conditionalClientProvidersForFactory = conditionalClientProvidersForFactory;
|
|
7
7
|
exports.conditionalClientTokens = conditionalClientTokens;
|
|
8
8
|
exports.createRuntimeHost = createRuntimeHost;
|
|
9
|
-
exports.disposeNestOwnedHandler = disposeNestOwnedHandler;
|
|
10
9
|
exports.createNestHandlerInstance = createNestHandlerInstance;
|
|
11
10
|
exports.providerToken = providerToken;
|
|
12
11
|
const constants_1 = require("@nestjs/common/constants");
|
|
@@ -165,11 +164,8 @@ const CONDITIONAL_CLIENT_PROVIDER_SPECS = [
|
|
|
165
164
|
}
|
|
166
165
|
}
|
|
167
166
|
];
|
|
168
|
-
function conditionalClientProvidersForFactory() {
|
|
169
|
-
return CONDITIONAL_CLIENT_PROVIDER_SPECS.map(
|
|
170
|
-
}
|
|
171
|
-
function createConditionalClientProviderForFactory(spec) {
|
|
172
|
-
return createConditionalClientProviderFromSpec(spec, { checkEnabled: true });
|
|
167
|
+
function conditionalClientProvidersForFactory(registration) {
|
|
168
|
+
return CONDITIONAL_CLIENT_PROVIDER_SPECS.filter((spec) => registration === undefined || spec.isEnabled(registration)).map((spec) => createConditionalClientProviderFromSpec(spec, { checkEnabled: registration === undefined }));
|
|
173
169
|
}
|
|
174
170
|
function createConditionalClientProvider(spec, registration) {
|
|
175
171
|
return createConditionalClientProviderFromSpec(spec, { registration, checkEnabled: false });
|
|
@@ -240,7 +236,7 @@ function createRuntimeHost(registration, moduleRef, discovery) {
|
|
|
240
236
|
function createProviderResolver(moduleRef, discovery) {
|
|
241
237
|
const resolver = {
|
|
242
238
|
get(type) {
|
|
243
|
-
const discovered =
|
|
239
|
+
const discovered = findDiscoveredProvider(discovery, type)?.instance;
|
|
244
240
|
if (discovered !== undefined) {
|
|
245
241
|
return discovered;
|
|
246
242
|
}
|
|
@@ -252,20 +248,9 @@ function createProviderResolver(moduleRef, discovery) {
|
|
|
252
248
|
}
|
|
253
249
|
},
|
|
254
250
|
async create(type) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
// singleton when the application also lists that class as a Nest
|
|
259
|
-
// provider, which would make later Spot contexts overwrite earlier
|
|
260
|
-
// activations. ModuleRef.create() preserves dependency injection
|
|
261
|
-
// while creating an independent object.
|
|
262
|
-
return await moduleRef.create(type);
|
|
263
|
-
}
|
|
264
|
-
catch {
|
|
265
|
-
// Fall back to direct construction through Nest for classes that are
|
|
266
|
-
// not registered as providers.
|
|
267
|
-
}
|
|
268
|
-
return await moduleRef.resolve(type, undefined, { strict: false });
|
|
251
|
+
const owner = findDiscoveredProvider(discovery, type)?.host;
|
|
252
|
+
const creationModuleRef = owner?.getProviderByKey(core_1.ModuleRef).instance ?? moduleRef;
|
|
253
|
+
return await creationModuleRef.create(type);
|
|
269
254
|
}
|
|
270
255
|
};
|
|
271
256
|
Object.defineProperty(resolver, Symbol.for('@zlink-systems/framework.handler-instance-scope-factory'), {
|
|
@@ -289,7 +274,7 @@ function createProviderResolver(moduleRef, discovery) {
|
|
|
289
274
|
if (instance === undefined) {
|
|
290
275
|
instance = createNestHandlerInstance(moduleRef, contextId, dependencies, type).then(async (created) => {
|
|
291
276
|
if (disposed) {
|
|
292
|
-
await
|
|
277
|
+
await framework_loader_1.framework.disposeIntegrationHandler(created);
|
|
293
278
|
throw new Error('Handler instance scope was disposed during activation.');
|
|
294
279
|
}
|
|
295
280
|
owned.push(created);
|
|
@@ -305,12 +290,14 @@ function createProviderResolver(moduleRef, discovery) {
|
|
|
305
290
|
disposed = true;
|
|
306
291
|
const pending = [...instances.values()];
|
|
307
292
|
await Promise.allSettled(pending);
|
|
308
|
-
|
|
309
|
-
await
|
|
293
|
+
try {
|
|
294
|
+
await framework_loader_1.framework.disposeIntegrationHandlers(owned);
|
|
295
|
+
}
|
|
296
|
+
finally {
|
|
297
|
+
owned.length = 0;
|
|
298
|
+
instances.clear();
|
|
299
|
+
dependencies.clear();
|
|
310
300
|
}
|
|
311
|
-
owned.length = 0;
|
|
312
|
-
instances.clear();
|
|
313
|
-
dependencies.clear();
|
|
314
301
|
}
|
|
315
302
|
};
|
|
316
303
|
}
|
|
@@ -331,27 +318,11 @@ function createProviderResolver(moduleRef, discovery) {
|
|
|
331
318
|
});
|
|
332
319
|
}
|
|
333
320
|
finally {
|
|
334
|
-
|
|
335
|
-
await disposeNestOwnedHandler(owned[index]);
|
|
336
|
-
}
|
|
321
|
+
await framework_loader_1.framework.disposeIntegrationHandlers(owned);
|
|
337
322
|
}
|
|
338
323
|
}));
|
|
339
324
|
return resolver;
|
|
340
325
|
}
|
|
341
|
-
async function disposeNestOwnedHandler(instance) {
|
|
342
|
-
if (instance === null || instance === undefined)
|
|
343
|
-
return;
|
|
344
|
-
const value = instance;
|
|
345
|
-
if (typeof value.dispose === 'function') {
|
|
346
|
-
await value.dispose();
|
|
347
|
-
}
|
|
348
|
-
else if (typeof value.close === 'function') {
|
|
349
|
-
await value.close();
|
|
350
|
-
}
|
|
351
|
-
else if (typeof value.onModuleDestroy === 'function') {
|
|
352
|
-
await value.onModuleDestroy();
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
326
|
async function createNestHandlerInstance(moduleRef, contextId, dependencies, type) {
|
|
356
327
|
const reflected = [
|
|
357
328
|
...(Reflect.getMetadata(constants_1.PARAMTYPES_METADATA, type) ??
|
|
@@ -398,12 +369,12 @@ async function resolveNestHandlerDependency(moduleRef, contextId, dependencies,
|
|
|
398
369
|
throw error;
|
|
399
370
|
}
|
|
400
371
|
}
|
|
401
|
-
function
|
|
372
|
+
function findDiscoveredProvider(discovery, type) {
|
|
402
373
|
for (const wrapper of discovery?.getProviders() ?? []) {
|
|
403
|
-
if (wrapper.
|
|
404
|
-
wrapper.
|
|
405
|
-
|
|
406
|
-
return wrapper
|
|
374
|
+
if (wrapper.token === type ||
|
|
375
|
+
wrapper.metatype === type ||
|
|
376
|
+
wrapper.instance?.constructor === type) {
|
|
377
|
+
return wrapper;
|
|
407
378
|
}
|
|
408
379
|
}
|
|
409
380
|
return undefined;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { DiscoveryService, ModuleRef } from '@nestjs/core';
|
|
2
2
|
import type { ZLinkFrameworkRegistrationOptions } from './framework-integration-contracts';
|
|
3
3
|
import { type ZLinkModuleOptions, type ZLinkNestModuleRegistrationOptions } from './contracts';
|
|
4
|
-
export declare function hasNestHandlerDiscovery(options: ZLinkNestModuleRegistrationOptions): boolean;
|
|
5
4
|
export declare function createDiscoveredOptions(options: ZLinkNestModuleRegistrationOptions, discovery: DiscoveryService, moduleRef: ModuleRef): ZLinkFrameworkRegistrationOptions;
|
|
6
5
|
export declare function createRegistrationOptions(options: ZLinkNestModuleRegistrationOptions): ZLinkFrameworkRegistrationOptions;
|
|
7
6
|
export declare function assertBuiltModuleOptions(options: ZLinkModuleOptions): ZLinkNestModuleRegistrationOptions;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hasNestHandlerDiscovery = hasNestHandlerDiscovery;
|
|
4
3
|
exports.createDiscoveredOptions = createDiscoveredOptions;
|
|
5
4
|
exports.createRegistrationOptions = createRegistrationOptions;
|
|
6
5
|
exports.assertBuiltModuleOptions = assertBuiltModuleOptions;
|
|
@@ -9,19 +8,6 @@ const provider_discovery_1 = require("./provider-discovery");
|
|
|
9
8
|
const handler_adapters_1 = require("./handler-adapters");
|
|
10
9
|
const framework_loader_1 = require("./framework-loader");
|
|
11
10
|
const spot_node_handler_registry_1 = require("./spot-node-handler-registry");
|
|
12
|
-
function hasNestHandlerDiscovery(options) {
|
|
13
|
-
return (hasConfiguredSpotNodes(options.spotNodes) ||
|
|
14
|
-
Object.values(options.clientServerChannels ?? {}).some((channel) => (channel.handlerGroups ?? []).length > 0 ||
|
|
15
|
-
(channel.requestHandlerTypes ?? []).length > 0 ||
|
|
16
|
-
(channel.sendHandlerTypes ?? []).length > 0) ||
|
|
17
|
-
Object.values(options.fanoutChannels ?? {}).some((channel) => (channel.handlerGroups ?? []).length > 0 || (channel.publishHandlerTypes ?? []).length > 0));
|
|
18
|
-
}
|
|
19
|
-
function hasConfiguredSpotNodes(value) {
|
|
20
|
-
if (value === undefined) {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
return Array.isArray(value) ? value.length > 0 : Object.keys(value).length > 0;
|
|
24
|
-
}
|
|
25
11
|
function createDiscoveredOptions(options, discovery, moduleRef) {
|
|
26
12
|
const registrationOptions = createRegistrationOptions(options);
|
|
27
13
|
const channels = { ...(registrationOptions.channels ?? {}) };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zlink-systems/nestjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@nestjs/common": "^10.4.22",
|
|
24
|
-
"@zlink-systems/framework": "0.
|
|
25
|
-
"@zlink-systems/http-client": "0.
|
|
24
|
+
"@zlink-systems/framework": "0.27.0",
|
|
25
|
+
"@zlink-systems/http-client": "0.27.0",
|
|
26
26
|
"reflect-metadata": "^0.2.2",
|
|
27
27
|
"rxjs": "^7.8.2"
|
|
28
28
|
},
|