@horizon-republic/nestjs-jetstream 2.2.0 → 2.3.2
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 +129 -80
- package/dist/index.cjs +2068 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +995 -0
- package/dist/index.d.ts +995 -13
- package/dist/index.js +2068 -39
- package/dist/index.js.map +1 -1
- package/package.json +29 -19
- package/dist/client/index.d.ts +0 -3
- package/dist/client/index.d.ts.map +0 -1
- package/dist/client/index.js +0 -9
- package/dist/client/index.js.map +0 -1
- package/dist/client/jetstream.client.d.ts +0 -76
- package/dist/client/jetstream.client.d.ts.map +0 -1
- package/dist/client/jetstream.client.js +0 -325
- package/dist/client/jetstream.client.js.map +0 -1
- package/dist/client/jetstream.record.d.ts +0 -55
- package/dist/client/jetstream.record.d.ts.map +0 -1
- package/dist/client/jetstream.record.js +0 -84
- package/dist/client/jetstream.record.js.map +0 -1
- package/dist/codec/index.d.ts +0 -2
- package/dist/codec/index.d.ts.map +0 -1
- package/dist/codec/index.js +0 -6
- package/dist/codec/index.js.map +0 -1
- package/dist/codec/json.codec.d.ts +0 -20
- package/dist/codec/json.codec.d.ts.map +0 -1
- package/dist/codec/json.codec.js +0 -30
- package/dist/codec/json.codec.js.map +0 -1
- package/dist/connection/connection.provider.d.ts +0 -50
- package/dist/connection/connection.provider.d.ts.map +0 -1
- package/dist/connection/connection.provider.js +0 -141
- package/dist/connection/connection.provider.js.map +0 -1
- package/dist/connection/index.d.ts +0 -2
- package/dist/connection/index.d.ts.map +0 -1
- package/dist/connection/index.js +0 -6
- package/dist/connection/index.js.map +0 -1
- package/dist/context/index.d.ts +0 -2
- package/dist/context/index.d.ts.map +0 -1
- package/dist/context/index.js +0 -6
- package/dist/context/index.js.map +0 -1
- package/dist/context/rpc.context.d.ts +0 -35
- package/dist/context/rpc.context.d.ts.map +0 -1
- package/dist/context/rpc.context.js +0 -44
- package/dist/context/rpc.context.js.map +0 -1
- package/dist/health/index.d.ts +0 -3
- package/dist/health/index.d.ts.map +0 -1
- package/dist/health/index.js +0 -6
- package/dist/health/index.js.map +0 -1
- package/dist/health/jetstream.health-indicator.d.ts +0 -47
- package/dist/health/jetstream.health-indicator.d.ts.map +0 -1
- package/dist/health/jetstream.health-indicator.js +0 -85
- package/dist/health/jetstream.health-indicator.js.map +0 -1
- package/dist/hooks/event-bus.d.ts +0 -31
- package/dist/hooks/event-bus.d.ts.map +0 -1
- package/dist/hooks/event-bus.js +0 -79
- package/dist/hooks/event-bus.js.map +0 -1
- package/dist/hooks/index.d.ts +0 -2
- package/dist/hooks/index.d.ts.map +0 -1
- package/dist/hooks/index.js +0 -6
- package/dist/hooks/index.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/interfaces/client.interface.d.ts +0 -14
- package/dist/interfaces/client.interface.d.ts.map +0 -1
- package/dist/interfaces/client.interface.js +0 -3
- package/dist/interfaces/client.interface.js.map +0 -1
- package/dist/interfaces/codec.interface.d.ts +0 -28
- package/dist/interfaces/codec.interface.d.ts.map +0 -1
- package/dist/interfaces/codec.interface.js +0 -3
- package/dist/interfaces/codec.interface.js.map +0 -1
- package/dist/interfaces/hooks.interface.d.ts +0 -71
- package/dist/interfaces/hooks.interface.d.ts.map +0 -1
- package/dist/interfaces/hooks.interface.js +0 -16
- package/dist/interfaces/hooks.interface.js.map +0 -1
- package/dist/interfaces/index.d.ts +0 -8
- package/dist/interfaces/index.d.ts.map +0 -1
- package/dist/interfaces/index.js +0 -6
- package/dist/interfaces/index.js.map +0 -1
- package/dist/interfaces/options.interface.d.ts +0 -142
- package/dist/interfaces/options.interface.d.ts.map +0 -1
- package/dist/interfaces/options.interface.js +0 -3
- package/dist/interfaces/options.interface.js.map +0 -1
- package/dist/interfaces/routing.interface.d.ts +0 -15
- package/dist/interfaces/routing.interface.d.ts.map +0 -1
- package/dist/interfaces/routing.interface.js +0 -3
- package/dist/interfaces/routing.interface.js.map +0 -1
- package/dist/interfaces/stream.interface.d.ts +0 -5
- package/dist/interfaces/stream.interface.d.ts.map +0 -1
- package/dist/interfaces/stream.interface.js +0 -3
- package/dist/interfaces/stream.interface.js.map +0 -1
- package/dist/jetstream.constants.d.ts +0 -58
- package/dist/jetstream.constants.d.ts.map +0 -1
- package/dist/jetstream.constants.js +0 -168
- package/dist/jetstream.constants.js.map +0 -1
- package/dist/jetstream.module.d.ts +0 -89
- package/dist/jetstream.module.d.ts.map +0 -1
- package/dist/jetstream.module.js +0 -410
- package/dist/jetstream.module.js.map +0 -1
- package/dist/server/core-rpc.server.d.ts +0 -31
- package/dist/server/core-rpc.server.d.ts.map +0 -1
- package/dist/server/core-rpc.server.js +0 -95
- package/dist/server/core-rpc.server.js.map +0 -1
- package/dist/server/index.d.ts +0 -5
- package/dist/server/index.d.ts.map +0 -1
- package/dist/server/index.js +0 -16
- package/dist/server/index.js.map +0 -1
- package/dist/server/infrastructure/consumer.provider.d.ts +0 -36
- package/dist/server/infrastructure/consumer.provider.d.ts.map +0 -1
- package/dist/server/infrastructure/consumer.provider.js +0 -123
- package/dist/server/infrastructure/consumer.provider.js.map +0 -1
- package/dist/server/infrastructure/index.d.ts +0 -4
- package/dist/server/infrastructure/index.d.ts.map +0 -1
- package/dist/server/infrastructure/index.js +0 -10
- package/dist/server/infrastructure/index.js.map +0 -1
- package/dist/server/infrastructure/message.provider.d.ts +0 -46
- package/dist/server/infrastructure/message.provider.d.ts.map +0 -1
- package/dist/server/infrastructure/message.provider.js +0 -100
- package/dist/server/infrastructure/message.provider.js.map +0 -1
- package/dist/server/infrastructure/stream.provider.d.ts +0 -38
- package/dist/server/infrastructure/stream.provider.d.ts.map +0 -1
- package/dist/server/infrastructure/stream.provider.js +0 -109
- package/dist/server/infrastructure/stream.provider.js.map +0 -1
- package/dist/server/routing/event.router.d.ts +0 -56
- package/dist/server/routing/event.router.d.ts.map +0 -1
- package/dist/server/routing/event.router.js +0 -132
- package/dist/server/routing/event.router.js.map +0 -1
- package/dist/server/routing/index.d.ts +0 -5
- package/dist/server/routing/index.d.ts.map +0 -1
- package/dist/server/routing/index.js +0 -10
- package/dist/server/routing/index.js.map +0 -1
- package/dist/server/routing/pattern-registry.d.ts +0 -39
- package/dist/server/routing/pattern-registry.d.ts.map +0 -1
- package/dist/server/routing/pattern-registry.js +0 -116
- package/dist/server/routing/pattern-registry.js.map +0 -1
- package/dist/server/routing/rpc.router.d.ts +0 -37
- package/dist/server/routing/rpc.router.d.ts.map +0 -1
- package/dist/server/routing/rpc.router.js +0 -121
- package/dist/server/routing/rpc.router.js.map +0 -1
- package/dist/server/strategy.d.ts +0 -55
- package/dist/server/strategy.d.ts.map +0 -1
- package/dist/server/strategy.js +0 -113
- package/dist/server/strategy.js.map +0 -1
- package/dist/shutdown/index.d.ts +0 -2
- package/dist/shutdown/index.d.ts.map +0 -1
- package/dist/shutdown/index.js +0 -6
- package/dist/shutdown/index.js.map +0 -1
- package/dist/shutdown/shutdown.manager.d.ts +0 -27
- package/dist/shutdown/shutdown.manager.d.ts.map +0 -1
- package/dist/shutdown/shutdown.manager.js +0 -45
- package/dist/shutdown/shutdown.manager.js.map +0 -1
- package/dist/utils/index.d.ts +0 -3
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js +0 -8
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/serialize-error.d.ts +0 -10
- package/dist/utils/serialize-error.d.ts.map +0 -1
- package/dist/utils/serialize-error.js +0 -21
- package/dist/utils/serialize-error.js.map +0 -1
- package/dist/utils/unwrap-result.d.ts +0 -15
- package/dist/utils/unwrap-result.d.ts.map +0 -1
- package/dist/utils/unwrap-result.js +0 -49
- package/dist/utils/unwrap-result.js.map +0 -1
package/dist/server/strategy.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JetstreamStrategy = void 0;
|
|
4
|
-
const microservices_1 = require("@nestjs/microservices");
|
|
5
|
-
/**
|
|
6
|
-
* NestJS custom transport strategy for NATS JetStream.
|
|
7
|
-
*
|
|
8
|
-
* Coordinates all server-side providers:
|
|
9
|
-
* 1. Registers handlers from NestJS into PatternRegistry
|
|
10
|
-
* 2. Creates required streams and consumers
|
|
11
|
-
* 3. Starts message consumption and routing
|
|
12
|
-
* 4. Handles Core or JetStream RPC based on configuration
|
|
13
|
-
*
|
|
14
|
-
* All dependencies are injected via the NestJS DI container.
|
|
15
|
-
*/
|
|
16
|
-
class JetstreamStrategy extends microservices_1.Server {
|
|
17
|
-
constructor(options, connection, patternRegistry, streamProvider, consumerProvider, messageProvider, eventRouter, rpcRouter, coreRpcServer) {
|
|
18
|
-
super();
|
|
19
|
-
this.options = options;
|
|
20
|
-
this.connection = connection;
|
|
21
|
-
this.patternRegistry = patternRegistry;
|
|
22
|
-
this.streamProvider = streamProvider;
|
|
23
|
-
this.consumerProvider = consumerProvider;
|
|
24
|
-
this.messageProvider = messageProvider;
|
|
25
|
-
this.eventRouter = eventRouter;
|
|
26
|
-
this.rpcRouter = rpcRouter;
|
|
27
|
-
this.coreRpcServer = coreRpcServer;
|
|
28
|
-
this.transportId = Symbol('jetstream-transport');
|
|
29
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
30
|
-
this.listeners = new Map();
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Start the transport: register handlers, create infrastructure, begin consumption.
|
|
34
|
-
*
|
|
35
|
-
* Called by NestJS when `connectMicroservice()` is used, or internally by the module.
|
|
36
|
-
*/
|
|
37
|
-
async listen(callback) {
|
|
38
|
-
// 1. Register all NestJS handlers
|
|
39
|
-
this.patternRegistry.registerHandlers(this.getHandlers());
|
|
40
|
-
// 2. Determine which stream kinds are needed
|
|
41
|
-
const streamKinds = this.resolveStreamKinds();
|
|
42
|
-
if (streamKinds.length > 0) {
|
|
43
|
-
// 3. Ensure streams exist
|
|
44
|
-
await this.streamProvider.ensureStreams(streamKinds);
|
|
45
|
-
// 4. Ensure consumers exist
|
|
46
|
-
const consumers = await this.consumerProvider.ensureConsumers(streamKinds);
|
|
47
|
-
// 5. Start message consumption
|
|
48
|
-
this.messageProvider.start(consumers);
|
|
49
|
-
// 6. Start event router if needed
|
|
50
|
-
if (this.patternRegistry.hasEventHandlers() || this.patternRegistry.hasBroadcastHandlers()) {
|
|
51
|
-
this.eventRouter.start();
|
|
52
|
-
}
|
|
53
|
-
// 7. Start RPC router if JetStream mode
|
|
54
|
-
if (this.isJetStreamRpcMode() && this.patternRegistry.hasRpcHandlers()) {
|
|
55
|
-
this.rpcRouter.start();
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
// 8. Start Core RPC server if core mode
|
|
59
|
-
if (this.isCoreRpcMode() && this.patternRegistry.hasRpcHandlers()) {
|
|
60
|
-
await this.coreRpcServer.start();
|
|
61
|
-
}
|
|
62
|
-
callback();
|
|
63
|
-
}
|
|
64
|
-
/** Gracefully stop the transport. */
|
|
65
|
-
close() {
|
|
66
|
-
this.eventRouter.destroy();
|
|
67
|
-
this.rpcRouter.destroy();
|
|
68
|
-
this.coreRpcServer.stop();
|
|
69
|
-
this.messageProvider.destroy();
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Register event listener (required by Server base class).
|
|
73
|
-
*
|
|
74
|
-
* Stores callbacks for potential use. Primary lifecycle events
|
|
75
|
-
* are routed through EventBus.
|
|
76
|
-
*/
|
|
77
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
78
|
-
on(event, callback) {
|
|
79
|
-
const existing = this.listeners.get(event) ?? [];
|
|
80
|
-
existing.push(callback);
|
|
81
|
-
this.listeners.set(event, existing);
|
|
82
|
-
}
|
|
83
|
-
/** Unwrap the underlying NATS connection. */
|
|
84
|
-
unwrap() {
|
|
85
|
-
return this.connection.unwrap;
|
|
86
|
-
}
|
|
87
|
-
/** Access the pattern registry (for module-level introspection). */
|
|
88
|
-
getPatternRegistry() {
|
|
89
|
-
return this.patternRegistry;
|
|
90
|
-
}
|
|
91
|
-
/** Determine which JetStream stream kinds are needed. */
|
|
92
|
-
resolveStreamKinds() {
|
|
93
|
-
const kinds = [];
|
|
94
|
-
if (this.patternRegistry.hasEventHandlers()) {
|
|
95
|
-
kinds.push('ev');
|
|
96
|
-
}
|
|
97
|
-
if (this.isJetStreamRpcMode() && this.patternRegistry.hasRpcHandlers()) {
|
|
98
|
-
kinds.push('cmd');
|
|
99
|
-
}
|
|
100
|
-
if (this.patternRegistry.hasBroadcastHandlers()) {
|
|
101
|
-
kinds.push('broadcast');
|
|
102
|
-
}
|
|
103
|
-
return kinds;
|
|
104
|
-
}
|
|
105
|
-
isCoreRpcMode() {
|
|
106
|
-
return !this.options.rpc || this.options.rpc.mode === 'core';
|
|
107
|
-
}
|
|
108
|
-
isJetStreamRpcMode() {
|
|
109
|
-
return this.options.rpc?.mode === 'jetstream';
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
exports.JetstreamStrategy = JetstreamStrategy;
|
|
113
|
-
//# sourceMappingURL=strategy.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"strategy.js","sourceRoot":"","sources":["../../src/server/strategy.ts"],"names":[],"mappings":";;;AAAA,yDAAwE;AASxE;;;;;;;;;;GAUG;AACH,MAAa,iBAAkB,SAAQ,sBAAM;IAK3C,YACmB,OAA+B,EAC/B,UAA8B,EAC9B,eAAgC,EAChC,cAA8B,EAC9B,gBAAkC,EAClC,eAAgC,EAChC,WAAwB,EACxB,SAAoB,EACpB,aAA4B;QAE7C,KAAK,EAAE,CAAC;QAVS,YAAO,GAAP,OAAO,CAAwB;QAC/B,eAAU,GAAV,UAAU,CAAoB;QAC9B,oBAAe,GAAf,eAAe,CAAiB;QAChC,mBAAc,GAAd,cAAc,CAAgB;QAC9B,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,oBAAe,GAAf,eAAe,CAAiB;QAChC,gBAAW,GAAX,WAAW,CAAa;QACxB,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IACf,CAAC;IAEO,aAAa;QACnB,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,KAAK,MAAM,CAAC;IAC/D,CAAC;IAEO,kBAAkB;QACxB,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,KAAK,WAAW,CAAC;IAChD,CAAC;CACF;AAtHD,8CAsHC"}
|
package/dist/shutdown/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shutdown/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/shutdown/index.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ShutdownManager = void 0;
|
|
4
|
-
var shutdown_manager_1 = require("./shutdown.manager");
|
|
5
|
-
Object.defineProperty(exports, "ShutdownManager", { enumerable: true, get: function () { return shutdown_manager_1.ShutdownManager; } });
|
|
6
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/shutdown/index.ts"],"names":[],"mappings":";;;AAAA,uDAAqD;AAA5C,mHAAA,eAAe,OAAA"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { ConnectionProvider } from '../connection';
|
|
2
|
-
import { EventBus } from '../hooks';
|
|
3
|
-
import { JetstreamStrategy } from '../server/strategy';
|
|
4
|
-
/**
|
|
5
|
-
* Orchestrates graceful transport shutdown.
|
|
6
|
-
*
|
|
7
|
-
* Shutdown sequence:
|
|
8
|
-
* 1. Emit onShutdownStart hook
|
|
9
|
-
* 2. Stop accepting new messages (close subscriptions, stop consumers)
|
|
10
|
-
* 3. Wait for in-flight handlers to complete (up to timeout)
|
|
11
|
-
* 4. Drain and close NATS connection
|
|
12
|
-
* 5. Emit onShutdownComplete hook
|
|
13
|
-
*/
|
|
14
|
-
export declare class ShutdownManager {
|
|
15
|
-
private readonly connection;
|
|
16
|
-
private readonly eventBus;
|
|
17
|
-
private readonly timeout;
|
|
18
|
-
private readonly logger;
|
|
19
|
-
constructor(connection: ConnectionProvider, eventBus: EventBus, timeout: number);
|
|
20
|
-
/**
|
|
21
|
-
* Execute the full shutdown sequence.
|
|
22
|
-
*
|
|
23
|
-
* @param strategy Optional strategy to close (stops consumers and subscriptions).
|
|
24
|
-
*/
|
|
25
|
-
shutdown(strategy?: JetstreamStrategy): Promise<void>;
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=shutdown.manager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shutdown.manager.d.ts","sourceRoot":"","sources":["../../src/shutdown/shutdown.manager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD;;;;;;;;;GASG;AACH,qBAAa,eAAe;IAIxB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAL1B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoC;gBAGxC,UAAU,EAAE,kBAAkB,EAC9B,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,MAAM;IAGlC;;;;OAIG;IACU,QAAQ,CAAC,QAAQ,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;CAkBnE"}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ShutdownManager = void 0;
|
|
4
|
-
const common_1 = require("@nestjs/common");
|
|
5
|
-
const interfaces_1 = require("../interfaces");
|
|
6
|
-
/**
|
|
7
|
-
* Orchestrates graceful transport shutdown.
|
|
8
|
-
*
|
|
9
|
-
* Shutdown sequence:
|
|
10
|
-
* 1. Emit onShutdownStart hook
|
|
11
|
-
* 2. Stop accepting new messages (close subscriptions, stop consumers)
|
|
12
|
-
* 3. Wait for in-flight handlers to complete (up to timeout)
|
|
13
|
-
* 4. Drain and close NATS connection
|
|
14
|
-
* 5. Emit onShutdownComplete hook
|
|
15
|
-
*/
|
|
16
|
-
class ShutdownManager {
|
|
17
|
-
constructor(connection, eventBus, timeout) {
|
|
18
|
-
this.connection = connection;
|
|
19
|
-
this.eventBus = eventBus;
|
|
20
|
-
this.timeout = timeout;
|
|
21
|
-
this.logger = new common_1.Logger('Jetstream:Shutdown');
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Execute the full shutdown sequence.
|
|
25
|
-
*
|
|
26
|
-
* @param strategy Optional strategy to close (stops consumers and subscriptions).
|
|
27
|
-
*/
|
|
28
|
-
async shutdown(strategy) {
|
|
29
|
-
this.eventBus.emit(interfaces_1.TransportEvent.ShutdownStart);
|
|
30
|
-
this.logger.log(`Graceful shutdown started (timeout: ${this.timeout}ms)`);
|
|
31
|
-
// 1. Stop accepting new messages (close subscriptions, stop consumers)
|
|
32
|
-
strategy?.close();
|
|
33
|
-
// 2. Drain and close NATS connection.
|
|
34
|
-
// NATS drain() waits for in-flight messages and pending subscriptions,
|
|
35
|
-
// then closes the connection. We add a timeout as a safety net.
|
|
36
|
-
await Promise.race([
|
|
37
|
-
this.connection.shutdown(),
|
|
38
|
-
new Promise((resolve) => setTimeout(resolve, this.timeout)),
|
|
39
|
-
]);
|
|
40
|
-
this.eventBus.emit(interfaces_1.TransportEvent.ShutdownComplete);
|
|
41
|
-
this.logger.log('Graceful shutdown complete');
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
exports.ShutdownManager = ShutdownManager;
|
|
45
|
-
//# sourceMappingURL=shutdown.manager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shutdown.manager.js","sourceRoot":"","sources":["../../src/shutdown/shutdown.manager.ts"],"names":[],"mappings":";;;AAAA,2CAAwC;AAIxC,8CAA+C;AAG/C;;;;;;;;;GASG;AACH,MAAa,eAAe;IAG1B,YACmB,UAA8B,EAC9B,QAAkB,EAClB,OAAe;QAFf,eAAU,GAAV,UAAU,CAAoB;QAC9B,aAAQ,GAAR,QAAQ,CAAU;QAClB,YAAO,GAAP,OAAO,CAAQ;QALjB,WAAM,GAAG,IAAI,eAAM,CAAC,oBAAoB,CAAC,CAAC;IAMxD,CAAC;IAEJ;;;;OAIG;IACI,KAAK,CAAC,QAAQ,CAAC,QAA4B;QAChD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,2BAAc,CAAC,aAAa,CAAC,CAAC;QACjD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,uCAAuC,IAAI,CAAC,OAAO,KAAK,CAAC,CAAC;QAE1E,uEAAuE;QACvE,QAAQ,EAAE,KAAK,EAAE,CAAC;QAElB,sCAAsC;QACtC,0EAA0E;QAC1E,mEAAmE;QACnE,MAAM,OAAO,CAAC,IAAI,CAAC;YACjB,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE;YAC1B,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;SAClE,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,2BAAc,CAAC,gBAAgB,CAAC,CAAC;QACpD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;IAChD,CAAC;CACF;AAhCD,0CAgCC"}
|
package/dist/utils/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/utils/index.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.unwrapResult = exports.serializeError = void 0;
|
|
4
|
-
var serialize_error_1 = require("./serialize-error");
|
|
5
|
-
Object.defineProperty(exports, "serializeError", { enumerable: true, get: function () { return serialize_error_1.serializeError; } });
|
|
6
|
-
var unwrap_result_1 = require("./unwrap-result");
|
|
7
|
-
Object.defineProperty(exports, "unwrapResult", { enumerable: true, get: function () { return unwrap_result_1.unwrapResult; } });
|
|
8
|
-
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;AAAA,qDAAmD;AAA1C,iHAAA,cAAc,OAAA;AAEvB,iDAA+C;AAAtC,6GAAA,YAAY,OAAA"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Serialize an error for transport over NATS.
|
|
3
|
-
*
|
|
4
|
-
* Handles three cases:
|
|
5
|
-
* 1. RpcException — unwraps via getError() to preserve the full payload
|
|
6
|
-
* 2. Generic Error — extracts { message } to avoid "[object Object]"
|
|
7
|
-
* 3. Plain object — passed through as-is (already unwrapped by NestJS filters)
|
|
8
|
-
*/
|
|
9
|
-
export declare const serializeError: (err: unknown) => unknown;
|
|
10
|
-
//# sourceMappingURL=serialize-error.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serialize-error.d.ts","sourceRoot":"","sources":["../../src/utils/serialize-error.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,GAAI,KAAK,OAAO,KAAG,OAK7C,CAAC"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.serializeError = void 0;
|
|
4
|
-
const microservices_1 = require("@nestjs/microservices");
|
|
5
|
-
/**
|
|
6
|
-
* Serialize an error for transport over NATS.
|
|
7
|
-
*
|
|
8
|
-
* Handles three cases:
|
|
9
|
-
* 1. RpcException — unwraps via getError() to preserve the full payload
|
|
10
|
-
* 2. Generic Error — extracts { message } to avoid "[object Object]"
|
|
11
|
-
* 3. Plain object — passed through as-is (already unwrapped by NestJS filters)
|
|
12
|
-
*/
|
|
13
|
-
const serializeError = (err) => {
|
|
14
|
-
if (err instanceof microservices_1.RpcException)
|
|
15
|
-
return err.getError();
|
|
16
|
-
if (err instanceof Error)
|
|
17
|
-
return { message: err.message };
|
|
18
|
-
return err;
|
|
19
|
-
};
|
|
20
|
-
exports.serializeError = serializeError;
|
|
21
|
-
//# sourceMappingURL=serialize-error.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serialize-error.js","sourceRoot":"","sources":["../../src/utils/serialize-error.ts"],"names":[],"mappings":";;;AAAA,yDAAqD;AAErD;;;;;;;GAOG;AACI,MAAM,cAAc,GAAG,CAAC,GAAY,EAAW,EAAE;IACtD,IAAI,GAAG,YAAY,4BAAY;QAAE,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;IACvD,IAAI,GAAG,YAAY,KAAK;QAAE,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC;IAE1D,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AALW,QAAA,cAAc,kBAKzB"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unwrap a handler result that may be a Promise, Observable, or nested combination.
|
|
3
|
-
*
|
|
4
|
-
* NestJS-wrapped handlers may return Promise<Observable> (e.g. when exception
|
|
5
|
-
* filters convert errors to throwError() Observables). This function handles:
|
|
6
|
-
*
|
|
7
|
-
* - Observable → subscribe immediately (no await — preserves sync emissions)
|
|
8
|
-
* - Promise<Observable> → await Promise, then subscribe
|
|
9
|
-
* - Promise<value> → await
|
|
10
|
-
* - Plain value → return as-is
|
|
11
|
-
*
|
|
12
|
-
* Used by both CoreRpcServer and RpcRouter to normalize handler output.
|
|
13
|
-
*/
|
|
14
|
-
export declare const unwrapResult: (result: unknown) => Promise<unknown>;
|
|
15
|
-
//# sourceMappingURL=unwrap-result.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"unwrap-result.d.ts","sourceRoot":"","sources":["../../src/utils/unwrap-result.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,GAAU,QAAQ,OAAO,KAAG,OAAO,CAAC,OAAO,CAenE,CAAC"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.unwrapResult = void 0;
|
|
4
|
-
const rxjs_1 = require("rxjs");
|
|
5
|
-
/**
|
|
6
|
-
* Unwrap a handler result that may be a Promise, Observable, or nested combination.
|
|
7
|
-
*
|
|
8
|
-
* NestJS-wrapped handlers may return Promise<Observable> (e.g. when exception
|
|
9
|
-
* filters convert errors to throwError() Observables). This function handles:
|
|
10
|
-
*
|
|
11
|
-
* - Observable → subscribe immediately (no await — preserves sync emissions)
|
|
12
|
-
* - Promise<Observable> → await Promise, then subscribe
|
|
13
|
-
* - Promise<value> → await
|
|
14
|
-
* - Plain value → return as-is
|
|
15
|
-
*
|
|
16
|
-
* Used by both CoreRpcServer and RpcRouter to normalize handler output.
|
|
17
|
-
*/
|
|
18
|
-
const unwrapResult = async (result) => {
|
|
19
|
-
// Direct Observable — subscribe immediately (no microtask yield)
|
|
20
|
-
if ((0, rxjs_1.isObservable)(result)) {
|
|
21
|
-
return subscribeToFirst(result);
|
|
22
|
-
}
|
|
23
|
-
// Await Promise, then check if it resolved to an Observable
|
|
24
|
-
// (NestJS-wrapped handlers return Promise<Observable> when exception filters fire)
|
|
25
|
-
const resolved = await result;
|
|
26
|
-
if ((0, rxjs_1.isObservable)(resolved)) {
|
|
27
|
-
return subscribeToFirst(resolved);
|
|
28
|
-
}
|
|
29
|
-
return resolved;
|
|
30
|
-
};
|
|
31
|
-
exports.unwrapResult = unwrapResult;
|
|
32
|
-
/** Subscribe to an Observable and resolve with its first emitted value. */
|
|
33
|
-
const subscribeToFirst = (obs) => new Promise((resolve, reject) => {
|
|
34
|
-
let done = false;
|
|
35
|
-
obs.subscribe({
|
|
36
|
-
next: (val) => {
|
|
37
|
-
if (!done) {
|
|
38
|
-
done = true;
|
|
39
|
-
resolve(val);
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
error: reject,
|
|
43
|
-
complete: () => {
|
|
44
|
-
if (!done)
|
|
45
|
-
resolve(undefined);
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
//# sourceMappingURL=unwrap-result.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"unwrap-result.js","sourceRoot":"","sources":["../../src/utils/unwrap-result.ts"],"names":[],"mappings":";;;AAAA,+BAAgD;AAEhD;;;;;;;;;;;;GAYG;AACI,MAAM,YAAY,GAAG,KAAK,EAAE,MAAe,EAAoB,EAAE;IACtE,iEAAiE;IACjE,IAAI,IAAA,mBAAY,EAAC,MAAM,CAAC,EAAE,CAAC;QACzB,OAAO,gBAAgB,CAAC,MAA6B,CAAC,CAAC;IACzD,CAAC;IAED,4DAA4D;IAC5D,mFAAmF;IACnF,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC;IAE9B,IAAI,IAAA,mBAAY,EAAC,QAAQ,CAAC,EAAE,CAAC;QAC3B,OAAO,gBAAgB,CAAC,QAA+B,CAAC,CAAC;IAC3D,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AAfW,QAAA,YAAY,gBAevB;AAEF,2EAA2E;AAC3E,MAAM,gBAAgB,GAAG,CAAC,GAAwB,EAAoB,EAAE,CACtE,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;IAC9B,IAAI,IAAI,GAAG,KAAK,CAAC;IAEjB,GAAG,CAAC,SAAS,CAAC;QACZ,IAAI,EAAE,CAAC,GAAY,EAAE,EAAE;YACrB,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,IAAI,GAAG,IAAI,CAAC;gBACZ,OAAO,CAAC,GAAG,CAAC,CAAC;YACf,CAAC;QACH,CAAC;QACD,KAAK,EAAE,MAAM;QACb,QAAQ,EAAE,GAAG,EAAE;YACb,IAAI,CAAC,IAAI;gBAAE,OAAO,CAAC,SAAS,CAAC,CAAC;QAChC,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|