@zlink-systems/nestjs 0.27.0 → 0.29.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/contracts.d.ts +2 -0
- package/dist/framework-integration-contracts.d.ts +3 -0
- package/dist/handler-adapters.js +22 -16
- package/dist/options-builder.js +9 -0
- package/dist/providers.d.ts +1 -0
- package/dist/providers.js +60 -11
- package/package.json +3 -3
package/dist/contracts.d.ts
CHANGED
|
@@ -179,6 +179,8 @@ export interface ZLinkNestClientServerChannelServerBuilder extends ZLinkNestFram
|
|
|
179
179
|
addHandlerGroup(groupName: string): this;
|
|
180
180
|
}
|
|
181
181
|
export interface ZLinkNestStreamNodeBuilder extends ZLinkNestFrameworkOptionsBuilder {
|
|
182
|
+
setHeartbeat(intervalMs: number, timeoutMs: number): this;
|
|
183
|
+
setIdleTimeout(timeoutMs: number): this;
|
|
182
184
|
bind(endpoint: string | undefined): this;
|
|
183
185
|
bind(port?: number): this;
|
|
184
186
|
setBindHost(bindHost: string): this;
|
|
@@ -163,6 +163,9 @@ export interface ZLinkRouteChannelOptions extends ZLinkRouteMeshChannelOptions {
|
|
|
163
163
|
readonly routerChannelId: string;
|
|
164
164
|
}
|
|
165
165
|
export interface ZLinkStreamNodeOptions {
|
|
166
|
+
readonly heartbeatIntervalMs?: number;
|
|
167
|
+
readonly heartbeatTimeoutMs?: number;
|
|
168
|
+
readonly idleTimeoutMs?: number;
|
|
166
169
|
readonly bind?: string;
|
|
167
170
|
readonly bindHost?: string;
|
|
168
171
|
readonly advertiseHost?: string;
|
package/dist/handler-adapters.js
CHANGED
|
@@ -12,7 +12,7 @@ const framework_loader_1 = require("./framework-loader");
|
|
|
12
12
|
const dispatch_scope_1 = require("./dispatch-scope");
|
|
13
13
|
const providers_1 = require("./providers");
|
|
14
14
|
function createDiscoveredRequestHandlers(providerRefs, handlerGroups, moduleRef) {
|
|
15
|
-
return createDiscoveredHandlerRegistrations(providerRefs, handlerGroups, 'request', (ref, metadata) => ({
|
|
15
|
+
return createDiscoveredHandlerRegistrations(providerRefs, handlerGroups, 'request', moduleRef, (ref, metadata) => ({
|
|
16
16
|
async handle(payload, context) {
|
|
17
17
|
const result = await invokeDiscoveredHandler(moduleRef, ref, metadata, payload, context);
|
|
18
18
|
return metadata.encodeResult === undefined
|
|
@@ -22,21 +22,21 @@ function createDiscoveredRequestHandlers(providerRefs, handlerGroups, moduleRef)
|
|
|
22
22
|
}));
|
|
23
23
|
}
|
|
24
24
|
function createDiscoveredSendHandlers(providerRefs, handlerGroups, moduleRef) {
|
|
25
|
-
return createDiscoveredHandlerRegistrations(providerRefs, handlerGroups, 'send', (ref, metadata) => ({
|
|
25
|
+
return createDiscoveredHandlerRegistrations(providerRefs, handlerGroups, 'send', moduleRef, (ref, metadata) => ({
|
|
26
26
|
async handle(payload, context) {
|
|
27
27
|
await invokeDiscoveredHandler(moduleRef, ref, metadata, payload, context);
|
|
28
28
|
}
|
|
29
29
|
}));
|
|
30
30
|
}
|
|
31
31
|
function createDiscoveredChannelSendHandlers(providerRefs, handlerGroups, moduleRef) {
|
|
32
|
-
return createDiscoveredHandlerRegistrations(providerRefs, handlerGroups, 'send', (ref, metadata) => ({
|
|
32
|
+
return createDiscoveredHandlerRegistrations(providerRefs, handlerGroups, 'send', moduleRef, (ref, metadata) => ({
|
|
33
33
|
async handle(payload, context) {
|
|
34
34
|
await invokeDiscoveredHandler(moduleRef, ref, metadata, payload, context);
|
|
35
35
|
}
|
|
36
36
|
}));
|
|
37
37
|
}
|
|
38
38
|
function createDiscoveredPublishHandlers(providerRefs, handlerGroups, moduleRef) {
|
|
39
|
-
return createDiscoveredHandlerRegistrations(providerRefs, handlerGroups, 'publish', (ref, metadata) => ({
|
|
39
|
+
return createDiscoveredHandlerRegistrations(providerRefs, handlerGroups, 'publish', moduleRef, (ref, metadata) => ({
|
|
40
40
|
async handle(payload, context) {
|
|
41
41
|
await invokeDiscoveredHandler(moduleRef, ref, metadata, payload, context);
|
|
42
42
|
}
|
|
@@ -52,21 +52,27 @@ function createManualSendHandlers(handlerTypes, moduleRef) {
|
|
|
52
52
|
return createManualHandlerRegistrations(handlerTypes, moduleRef, () => undefined);
|
|
53
53
|
}
|
|
54
54
|
function createManualHandlerRegistrations(handlerTypes, moduleRef, result) {
|
|
55
|
-
return (handlerTypes ?? []).map((registration) =>
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
return (handlerTypes ?? []).map((registration) => {
|
|
56
|
+
(0, providers_1.validateNestConstructorDependencies)(moduleRef, registration.handlerType);
|
|
57
|
+
return {
|
|
58
|
+
packetName: registration.packetName,
|
|
59
|
+
handler: {
|
|
60
|
+
async handle(payload, context) {
|
|
61
|
+
return result(await invokeManualHandler(moduleRef, registration.handlerType, payload, context));
|
|
62
|
+
}
|
|
60
63
|
}
|
|
61
|
-
}
|
|
62
|
-
})
|
|
64
|
+
};
|
|
65
|
+
});
|
|
63
66
|
}
|
|
64
|
-
function createDiscoveredHandlerRegistrations(providerRefs, handlerGroups, kind, createHandler) {
|
|
67
|
+
function createDiscoveredHandlerRegistrations(providerRefs, handlerGroups, kind, moduleRef, createHandler) {
|
|
65
68
|
const descriptors = createDiscoveredHandlerDescriptors(providerRefs, handlerGroups, kind);
|
|
66
|
-
return descriptors.map(({ ref, metadata }) =>
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
return descriptors.map(({ ref, metadata }) => {
|
|
70
|
+
(0, providers_1.validateNestConstructorDependencies)(moduleRef, ref.handlerKey);
|
|
71
|
+
return {
|
|
72
|
+
packetName: metadata.packetName,
|
|
73
|
+
handler: createHandler(ref, metadata)
|
|
74
|
+
};
|
|
75
|
+
});
|
|
70
76
|
}
|
|
71
77
|
function createDiscoveredHandlerDescriptors(providerRefs, handlerGroups, kind) {
|
|
72
78
|
if ((handlerGroups ?? []).length === 0) {
|
package/dist/options-builder.js
CHANGED
|
@@ -443,6 +443,15 @@ class DefaultZLinkNestStreamNodeBuilder extends ZLinkNestOptionsBuilder {
|
|
|
443
443
|
super(state);
|
|
444
444
|
this.streamOptions = streamOptions;
|
|
445
445
|
}
|
|
446
|
+
setHeartbeat(intervalMs, timeoutMs) {
|
|
447
|
+
this.streamOptions.heartbeatIntervalMs = intervalMs;
|
|
448
|
+
this.streamOptions.heartbeatTimeoutMs = timeoutMs;
|
|
449
|
+
return this;
|
|
450
|
+
}
|
|
451
|
+
setIdleTimeout(timeoutMs) {
|
|
452
|
+
this.streamOptions.idleTimeoutMs = timeoutMs;
|
|
453
|
+
return this;
|
|
454
|
+
}
|
|
446
455
|
bind(endpointOrPort) {
|
|
447
456
|
if (typeof endpointOrPort === 'string') {
|
|
448
457
|
this.streamOptions.bind = endpointOrPort;
|
package/dist/providers.d.ts
CHANGED
|
@@ -11,5 +11,6 @@ export declare function conditionalClientProvidersForFactory(registration?: ZLin
|
|
|
11
11
|
export declare function conditionalClientTokens(): InjectionToken[];
|
|
12
12
|
export declare function createRuntimeHost(registration: ZLinkFrameworkRegistration, moduleRef: ModuleRef, discovery: DiscoveryService): RuntimeHostWithNestLifecycle;
|
|
13
13
|
export declare function createNestHandlerInstance<T>(moduleRef: ModuleRef, contextId: import('@nestjs/core').ContextId, dependencies: Map<unknown, Promise<unknown>>, type: Type<T>): Promise<T>;
|
|
14
|
+
export declare function validateNestConstructorDependencies(moduleRef: ModuleRef, type: Type): void;
|
|
14
15
|
export declare function providerToken(provider: Provider): InjectionToken;
|
|
15
16
|
export {};
|
package/dist/providers.js
CHANGED
|
@@ -7,9 +7,11 @@ exports.conditionalClientProvidersForFactory = conditionalClientProvidersForFact
|
|
|
7
7
|
exports.conditionalClientTokens = conditionalClientTokens;
|
|
8
8
|
exports.createRuntimeHost = createRuntimeHost;
|
|
9
9
|
exports.createNestHandlerInstance = createNestHandlerInstance;
|
|
10
|
+
exports.validateNestConstructorDependencies = validateNestConstructorDependencies;
|
|
10
11
|
exports.providerToken = providerToken;
|
|
11
12
|
const constants_1 = require("@nestjs/common/constants");
|
|
12
13
|
const core_1 = require("@nestjs/core");
|
|
14
|
+
const unknown_element_exception_1 = require("@nestjs/core/errors/exceptions/unknown-element.exception");
|
|
13
15
|
const tokens_1 = require("./tokens");
|
|
14
16
|
const internal_tokens_1 = require("./internal-tokens");
|
|
15
17
|
const framework_loader_1 = require("./framework-loader");
|
|
@@ -223,6 +225,34 @@ function hasLocationStores(registration) {
|
|
|
223
225
|
return (registration.locations.useInMemoryStores || registration.locations.storeInstance !== undefined);
|
|
224
226
|
}
|
|
225
227
|
function createRuntimeHost(registration, moduleRef, discovery) {
|
|
228
|
+
const types = new Set([...registration.spotFactories, ...registration.filterTypes]);
|
|
229
|
+
for (const node of registration.spotNodes.values()) {
|
|
230
|
+
if (node.entrySpotType !== undefined)
|
|
231
|
+
types.add(node.entrySpotType);
|
|
232
|
+
for (const type of node.spotFactories ?? [])
|
|
233
|
+
types.add(type);
|
|
234
|
+
for (const type of Object.values(node.instanceSpotFactories ?? {}))
|
|
235
|
+
types.add(type);
|
|
236
|
+
for (const value of Object.values(node.spotFactoryRegistrations ?? {}))
|
|
237
|
+
types.add(value.implementation);
|
|
238
|
+
for (const value of Object.values(node.instanceSpotFactoryRegistrations ?? {}))
|
|
239
|
+
types.add(value.implementation);
|
|
240
|
+
for (const handler of [
|
|
241
|
+
...(node.entrySpotTimerHandlers ?? []),
|
|
242
|
+
...(node.entrySpotPacketHandlers ?? []),
|
|
243
|
+
...(node.entrySpotSubscriptionHandlers ?? []),
|
|
244
|
+
...(node.entrySpotActorSendHandlers ?? []),
|
|
245
|
+
...(node.entrySpotActorRequestHandlers ?? []),
|
|
246
|
+
...(node.spotTimerHandlers ?? []),
|
|
247
|
+
...(node.spotPacketHandlers ?? []),
|
|
248
|
+
...(node.spotSubscriptionHandlers ?? []),
|
|
249
|
+
...(node.spotActorSendHandlers ?? []),
|
|
250
|
+
...(node.spotActorRequestHandlers ?? [])
|
|
251
|
+
])
|
|
252
|
+
types.add(handler.handlerType);
|
|
253
|
+
}
|
|
254
|
+
for (const type of types)
|
|
255
|
+
validateNestConstructorDependencies(moduleRef, type);
|
|
226
256
|
const runtime = framework_loader_1.framework.createIntegrationRuntimeHost(registration, createProviderResolver(moduleRef, discovery));
|
|
227
257
|
runtime.onModuleInit = async () => {
|
|
228
258
|
await runtime.start();
|
|
@@ -324,15 +354,7 @@ function createProviderResolver(moduleRef, discovery) {
|
|
|
324
354
|
return resolver;
|
|
325
355
|
}
|
|
326
356
|
async function createNestHandlerInstance(moduleRef, contextId, dependencies, type) {
|
|
327
|
-
const reflected =
|
|
328
|
-
...(Reflect.getMetadata(constants_1.PARAMTYPES_METADATA, type) ??
|
|
329
|
-
[])
|
|
330
|
-
];
|
|
331
|
-
const declared = Reflect.getMetadata(constants_1.SELF_DECLARED_DEPS_METADATA, type);
|
|
332
|
-
for (const dependency of declared ?? []) {
|
|
333
|
-
reflected[dependency.index] = dependency.param;
|
|
334
|
-
}
|
|
335
|
-
const optional = new Set(Reflect.getMetadata(constants_1.OPTIONAL_DEPS_METADATA, type) ?? []);
|
|
357
|
+
const { reflected, optional } = nestConstructorDependencies(type);
|
|
336
358
|
const parameters = await Promise.all(reflected.map((token, index) => resolveNestHandlerDependency(moduleRef, contextId, dependencies, token, optional.has(index))));
|
|
337
359
|
const instance = new type(...parameters);
|
|
338
360
|
const properties = Reflect.getMetadata(constants_1.PROPERTY_DEPS_METADATA, type);
|
|
@@ -345,13 +367,40 @@ async function createNestHandlerInstance(moduleRef, contextId, dependencies, typ
|
|
|
345
367
|
}
|
|
346
368
|
return instance;
|
|
347
369
|
}
|
|
348
|
-
|
|
370
|
+
function nestConstructorDependencies(type) {
|
|
371
|
+
const reflected = [
|
|
372
|
+
...(Reflect.getMetadata(constants_1.PARAMTYPES_METADATA, type) ??
|
|
373
|
+
[])
|
|
374
|
+
];
|
|
375
|
+
const declared = Reflect.getMetadata(constants_1.SELF_DECLARED_DEPS_METADATA, type);
|
|
376
|
+
for (const dependency of declared ?? []) {
|
|
377
|
+
reflected[dependency.index] = dependency.param;
|
|
378
|
+
}
|
|
379
|
+
const optional = new Set(Reflect.getMetadata(constants_1.OPTIONAL_DEPS_METADATA, type) ?? []);
|
|
380
|
+
return { reflected, optional };
|
|
381
|
+
}
|
|
382
|
+
function validateNestConstructorDependencies(moduleRef, type) {
|
|
383
|
+
const { reflected, optional } = nestConstructorDependencies(type);
|
|
384
|
+
for (const [index, token] of reflected.entries()) {
|
|
385
|
+
try {
|
|
386
|
+
moduleRef.introspect(nestDependencyToken(token));
|
|
387
|
+
}
|
|
388
|
+
catch (error) {
|
|
389
|
+
if (!(error instanceof unknown_element_exception_1.UnknownElementException) || !optional.has(index))
|
|
390
|
+
throw error;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
function nestDependencyToken(token) {
|
|
349
395
|
const forwardReference = typeof token === 'object' && token !== null && 'forwardRef' in token
|
|
350
396
|
? token
|
|
351
397
|
: undefined;
|
|
352
|
-
|
|
398
|
+
return typeof forwardReference?.forwardRef === 'function'
|
|
353
399
|
? forwardReference.forwardRef()
|
|
354
400
|
: token;
|
|
401
|
+
}
|
|
402
|
+
async function resolveNestHandlerDependency(moduleRef, contextId, dependencies, token, optional) {
|
|
403
|
+
const resolvedToken = nestDependencyToken(token);
|
|
355
404
|
let dependency = dependencies.get(resolvedToken);
|
|
356
405
|
if (dependency === undefined) {
|
|
357
406
|
dependency = moduleRef.resolve(resolvedToken, contextId, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zlink-systems/nestjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.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.29.0",
|
|
25
|
+
"@zlink-systems/http-client": "0.29.0",
|
|
26
26
|
"reflect-metadata": "^0.2.2",
|
|
27
27
|
"rxjs": "^7.8.2"
|
|
28
28
|
},
|