@ebarahona/loopback-transport-core 1.0.0 → 1.2.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.
Files changed (105) hide show
  1. package/README.md +472 -35
  2. package/dist/client/client-proxy.d.ts +73 -42
  3. package/dist/client/client-proxy.js +71 -42
  4. package/dist/client/client-proxy.js.map +1 -1
  5. package/dist/client/index.d.ts +1 -1
  6. package/dist/client/index.js +3 -15
  7. package/dist/client/index.js.map +1 -1
  8. package/dist/context/execution-context.d.ts +58 -11
  9. package/dist/context/execution-context.js +62 -17
  10. package/dist/context/execution-context.js.map +1 -1
  11. package/dist/context/index.d.ts +2 -1
  12. package/dist/context/index.js +3 -15
  13. package/dist/context/index.js.map +1 -1
  14. package/dist/decorators/constants.d.ts +20 -10
  15. package/dist/decorators/constants.js +6 -2
  16. package/dist/decorators/constants.js.map +1 -1
  17. package/dist/decorators/event-handler.decorator.d.ts +10 -7
  18. package/dist/decorators/event-handler.decorator.js +18 -13
  19. package/dist/decorators/event-handler.decorator.js.map +1 -1
  20. package/dist/decorators/index.d.ts +5 -4
  21. package/dist/decorators/index.js +11 -18
  22. package/dist/decorators/index.js.map +1 -1
  23. package/dist/decorators/message-handler.decorator.d.ts +8 -5
  24. package/dist/decorators/message-handler.decorator.js +16 -11
  25. package/dist/decorators/message-handler.decorator.js.map +1 -1
  26. package/dist/decorators/payload.decorator.d.ts +16 -7
  27. package/dist/decorators/payload.decorator.js +16 -8
  28. package/dist/decorators/payload.decorator.js.map +1 -1
  29. package/dist/discovery/discovery.service.d.ts +143 -0
  30. package/dist/discovery/discovery.service.js +165 -0
  31. package/dist/discovery/discovery.service.js.map +1 -0
  32. package/dist/discovery/event-handler-discoverer.d.ts +19 -0
  33. package/dist/discovery/event-handler-discoverer.js +50 -0
  34. package/dist/discovery/event-handler-discoverer.js.map +1 -0
  35. package/dist/discovery/handler-discoverer.d.ts +48 -0
  36. package/dist/discovery/handler-discoverer.js +3 -0
  37. package/dist/discovery/handler-discoverer.js.map +1 -0
  38. package/dist/discovery/handler-kind.d.ts +23 -0
  39. package/dist/discovery/handler-kind.js +14 -0
  40. package/dist/discovery/handler-kind.js.map +1 -0
  41. package/dist/discovery/index.d.ts +7 -0
  42. package/dist/discovery/index.js +13 -0
  43. package/dist/discovery/index.js.map +1 -0
  44. package/dist/discovery/message-handler-discoverer.d.ts +19 -0
  45. package/dist/discovery/message-handler-discoverer.js +50 -0
  46. package/dist/discovery/message-handler-discoverer.js.map +1 -0
  47. package/dist/discovery/registered-handler.d.ts +35 -0
  48. package/dist/discovery/registered-handler.js +3 -0
  49. package/dist/discovery/registered-handler.js.map +1 -0
  50. package/dist/helpers/errors.d.ts +61 -0
  51. package/dist/helpers/errors.js +80 -0
  52. package/dist/helpers/errors.js.map +1 -0
  53. package/dist/helpers/index.d.ts +2 -0
  54. package/dist/helpers/index.js +14 -0
  55. package/dist/helpers/index.js.map +1 -0
  56. package/dist/helpers/register-server.d.ts +44 -0
  57. package/dist/helpers/register-server.js +72 -0
  58. package/dist/helpers/register-server.js.map +1 -0
  59. package/dist/index.d.ts +15 -7
  60. package/dist/index.js +33 -9
  61. package/dist/index.js.map +1 -1
  62. package/dist/interfaces/index.d.ts +4 -4
  63. package/dist/interfaces/index.js +0 -18
  64. package/dist/interfaces/index.js.map +1 -1
  65. package/dist/interfaces/message-handler.interface.d.ts +12 -6
  66. package/dist/interfaces/packet.interface.d.ts +20 -2
  67. package/dist/interfaces/transport-client.interface.d.ts +25 -13
  68. package/dist/interfaces/transport-server.interface.d.ts +36 -10
  69. package/dist/keys.d.ts +143 -46
  70. package/dist/keys.js +142 -68
  71. package/dist/keys.js.map +1 -1
  72. package/dist/registry/handler-registry.d.ts +94 -24
  73. package/dist/registry/handler-registry.js +279 -89
  74. package/dist/registry/handler-registry.js.map +1 -1
  75. package/dist/registry/index.d.ts +1 -1
  76. package/dist/registry/index.js +3 -15
  77. package/dist/registry/index.js.map +1 -1
  78. package/dist/serializers/cloudevents-serializer.d.ts +107 -0
  79. package/dist/serializers/cloudevents-serializer.js +130 -0
  80. package/dist/serializers/cloudevents-serializer.js.map +1 -0
  81. package/dist/serializers/index.d.ts +4 -1
  82. package/dist/serializers/index.js +7 -15
  83. package/dist/serializers/index.js.map +1 -1
  84. package/dist/serializers/serializer.interface.d.ts +49 -16
  85. package/dist/serializers/serializer.interface.js +41 -15
  86. package/dist/serializers/serializer.interface.js.map +1 -1
  87. package/dist/server/index.d.ts +2 -1
  88. package/dist/server/index.js +3 -15
  89. package/dist/server/index.js.map +1 -1
  90. package/dist/server/server-base.d.ts +125 -52
  91. package/dist/server/server-base.js +168 -57
  92. package/dist/server/server-base.js.map +1 -1
  93. package/dist/transport.component.d.ts +21 -8
  94. package/dist/transport.component.js +41 -18
  95. package/dist/transport.component.js.map +1 -1
  96. package/dist/transport.observer.d.ts +91 -0
  97. package/dist/transport.observer.js +297 -0
  98. package/dist/transport.observer.js.map +1 -0
  99. package/dist/utils/normalize-pattern.d.ts +11 -6
  100. package/dist/utils/normalize-pattern.js +18 -13
  101. package/dist/utils/normalize-pattern.js.map +1 -1
  102. package/package.json +58 -16
  103. package/dist/transport-booter.d.ts +0 -31
  104. package/dist/transport-booter.js +0 -117
  105. package/dist/transport-booter.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import { Observable, ReplaySubject } from 'rxjs';
2
- import { TransportClient, TransportStatus, WritePacket, ReadPacket, PacketId } from '../interfaces';
2
+ import type { PacketId, ReadPacket, TransportClient, TransportStatus, WritePacket } from '../interfaces';
3
3
  /**
4
4
  * Abstract base class for transport clients.
5
5
  *
@@ -8,35 +8,37 @@ import { TransportClient, TransportStatus, WritePacket, ReadPacket, PacketId } f
8
8
  * - `send()`/`emit()` lazily connect on first use.
9
9
  * - Concurrent send/emit calls share one connect().
10
10
  * - `close()` transitions to 'closing', waits for any pending connect
11
- * (bounded by `closeConnectTimeoutMs`, default 5s), calls doClose(),
11
+ * (bounded by `closeConnectTimeoutMs`, default 5s), calls `doClose()`,
12
12
  * then transitions to 'idle'.
13
13
  * - If the pending connect does not settle within the timeout, close
14
- * proceeds anyway. The adapter's doClose() must safely tear down
14
+ * proceeds anyway. The adapter's `doClose()` must safely tear down
15
15
  * partially opened native resources in this case.
16
16
  * - `send()`/`emit()` during 'closing' fail fast.
17
17
  * - After close, the next send/emit reconnects.
18
18
  * - A stale connect that resolves after close always rejects for its
19
19
  * original caller, even if a newer connection is already healthy.
20
- * - State is always reset in finally -- failed doClose() does not
20
+ * - State is always reset in finally — a failed `doClose()` does not
21
21
  * leave the client stuck.
22
22
  *
23
23
  * ## Stale async detection
24
24
  *
25
- * A monotonic `epoch` counter increments on each close(). The
26
- * connect callback only transitions to 'connected' if the epoch
27
- * has not changed, preventing a late-resolving connect from
28
- * overriding a close that happened while it was pending.
25
+ * A monotonic `epoch` counter increments on each `close()`. The connect
26
+ * callback only transitions to `connected` if the epoch has not changed,
27
+ * preventing a late-resolving connect from overriding a close that
28
+ * happened while it was pending.
29
29
  *
30
- * The connectionPromise is only cleared by its own .finally()
30
+ * The `connectionPromise` is only cleared by its own `.finally()`
31
31
  * callback if it is still the current promise, preventing a stale
32
32
  * promise from clobbering a newer one.
33
+ *
34
+ * @public
33
35
  */
34
36
  export declare abstract class ClientProxy implements TransportClient {
35
37
  protected readonly statusSubject: ReplaySubject<TransportStatus>;
36
38
  private state;
37
- private connectionPromise?;
38
- private connectionEpoch?;
39
- private closePromise?;
39
+ private connectionPromise;
40
+ private connectionEpoch;
41
+ private closePromise;
40
42
  private epoch;
41
43
  private readonly closeConnectTimeoutMs;
42
44
  readonly status$: Observable<TransportStatus>;
@@ -44,16 +46,19 @@ export declare abstract class ClientProxy implements TransportClient {
44
46
  closeConnectTimeoutMs?: number;
45
47
  });
46
48
  /**
47
- * Establish connection to the broker.
48
- * Implementations should be idempotent (safe to call multiple times).
49
+ * Establish connection to the broker. Implementations should be
50
+ * idempotent (safe to call multiple times).
51
+ *
52
+ * @public
49
53
  */
50
54
  abstract connect(): Promise<void>;
51
55
  /**
52
56
  * Close the native connection. Implemented by transport adapters.
53
- * Called by the base close() template method after waiting for any
54
- * pending connect (bounded by closeConnectTimeoutMs). If the timeout
55
- * fires before connect settles, doClose() is still called -- adapters
56
- * must handle partially opened native resources in that case.
57
+ * Called by the base `close()` template method after waiting for any
58
+ * pending connect (bounded by `closeConnectTimeoutMs`). If the
59
+ * timeout fires before connect settles, `doClose()` is still called —
60
+ * adapters must handle partially opened native resources in that
61
+ * case.
57
62
  */
58
63
  protected abstract doClose(): Promise<void>;
59
64
  /**
@@ -62,25 +67,33 @@ export declare abstract class ClientProxy implements TransportClient {
62
67
  * - If idle with no pending connect, returns immediately (no-op).
63
68
  * - If already closing, returns the existing close promise (dedupe).
64
69
  * - Otherwise:
65
- * 1. Increments epoch to invalidate any in-flight connect().
66
- * 2. Transitions to 'closing' so new send/emit fails fast.
67
- * 3. Waits for pending connect (bounded by closeConnectTimeoutMs).
68
- * 4. Calls doClose() for adapter-specific teardown.
69
- * 5. Resets to 'idle' in finally (even if doClose throws).
70
+ * 1. Increments epoch to invalidate any in-flight `connect()`.
71
+ * 2. Transitions to `closing` so new send/emit fails fast.
72
+ * 3. Waits for pending connect (bounded by `closeConnectTimeoutMs`).
73
+ * 4. Calls `doClose()` for adapter-specific teardown.
74
+ * 5. Resets to `idle` in finally (even if `doClose` throws).
70
75
  *
71
- * After close, the client is reusable: the next send/emit
72
- * will trigger a fresh connect().
76
+ * After close, the client is reusable: the next send/emit will
77
+ * trigger a fresh `connect()`.
78
+ *
79
+ * @public
80
+ * @throws TransportError When the adapter's `doClose()` rejects.
81
+ * State is still reset to `idle` so the client remains reusable.
73
82
  */
74
83
  close(): Promise<void>;
75
84
  private doCloseInternal;
76
85
  /**
77
- * Wait for a pending connect to settle, bounded by timeout.
78
- * If connect does not settle in time, proceed anyway -- the epoch
86
+ * Wait for a pending connect to settle, bounded by timeout. If
87
+ * connect does not settle in time, proceed anyway — the epoch
79
88
  * invalidation ensures the stale connect result is ignored.
80
89
  */
81
90
  private waitForPendingConnect;
82
91
  /**
83
92
  * Access the underlying native client.
93
+ *
94
+ * @public
95
+ * @typeParam T - Caller-asserted shape of the native client.
96
+ * @returns The native client cast to `T`.
84
97
  */
85
98
  abstract unwrap<T>(): T;
86
99
  /**
@@ -97,22 +110,40 @@ export declare abstract class ClientProxy implements TransportClient {
97
110
  *
98
111
  * Returns a cold Observable: the message is sent only when subscribed.
99
112
  * The connection is established lazily on first subscription.
113
+ *
114
+ * @public
115
+ * @typeParam TResult - Expected response shape.
116
+ * @typeParam TInput - Caller-provided payload shape.
117
+ * @param pattern - Pattern to match on the server side.
118
+ * @param data - The message payload.
119
+ * @returns A cold Observable that emits the response value(s).
100
120
  */
101
121
  send<TResult = unknown, TInput = unknown>(pattern: string | Record<string, unknown>, data: TInput): Observable<TResult>;
102
122
  /**
103
123
  * Emit an event with no response expected (fire-and-forget pattern).
104
124
  *
105
- * Returns a Promise that resolves when the event is dispatched.
106
- * The connection is established lazily if not already connected.
125
+ * Returns a Promise that resolves when the event is dispatched. The
126
+ * connection is established lazily if not already connected.
127
+ *
128
+ * @public
129
+ * @typeParam TInput - Caller-provided payload shape.
130
+ * @param pattern - Event pattern.
131
+ * @param data - The event payload.
132
+ * @returns Resolves when the broker has accepted the event.
133
+ * @throws TransportError When the client is closing or a concurrent
134
+ * close invalidated the pending connect.
107
135
  */
108
136
  emit<TInput = unknown>(pattern: string | Record<string, unknown>, data: TInput): Promise<void>;
109
137
  /**
110
- * Assign a unique correlation ID to a packet.
111
- * Uses crypto.randomUUID() for distributed-system-safe IDs.
138
+ * Assign a unique correlation ID to a packet. Uses
139
+ * `crypto.randomUUID()` for distributed-system-safe IDs.
112
140
  */
113
141
  protected assignPacketId(packet: ReadPacket): ReadPacket & PacketId;
114
142
  /**
115
- * Create an Observer callback that maps WritePacket to Observable emissions.
143
+ * Create an Observer callback that maps `WritePacket` values to
144
+ * Observable emissions.
145
+ *
146
+ * @typeParam T - Expected response type.
116
147
  */
117
148
  protected createObserver<T>(observer: {
118
149
  next: (value: T) => void;
@@ -120,27 +151,27 @@ export declare abstract class ClientProxy implements TransportClient {
120
151
  complete: () => void;
121
152
  }): (packet: WritePacket) => void;
122
153
  /**
123
- * Verify the client is in connected state.
124
- * Throws if a concurrent close() prevented the transition.
154
+ * Verify the client is in connected state. Throws if a concurrent
155
+ * close prevented the transition.
125
156
  */
126
157
  private assertConnected;
127
158
  /**
128
159
  * Ensure the client is connected. Concurrent calls share the same
129
160
  * connection promise to prevent duplicate connections.
130
161
  *
131
- * - 'closing': reject immediately.
132
- * - 'connected': return immediately.
133
- * - 'connecting': await the shared promise.
134
- * - 'idle': start connect, capture epoch, only transition to
135
- * 'connected' if epoch hasn't changed.
162
+ * - `closing`: reject immediately.
163
+ * - `connected`: return immediately.
164
+ * - `connecting`: await the shared promise.
165
+ * - `idle`: start connect, capture epoch, only transition to
166
+ * `connected` if epoch hasn't changed.
136
167
  *
137
168
  * After await, the caller validates that the epoch it waited on
138
169
  * still matches. A stale connect that was invalidated by close()
139
- * always rejects for its original caller, even if a newer
140
- * connection is already healthy.
170
+ * always rejects for its original caller, even if a newer connection
171
+ * is already healthy.
141
172
  *
142
173
  * The connectionPromise/connectionEpoch are only cleared in
143
- * .finally() if the finishing promise is still the current one,
174
+ * `.finally()` if the finishing promise is still the current one,
144
175
  * preventing a stale promise from clobbering a newer one.
145
176
  */
146
177
  private ensureConnected;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ClientProxy = void 0;
4
4
  const crypto_1 = require("crypto");
5
5
  const rxjs_1 = require("rxjs");
6
+ const errors_1 = require("../helpers/errors");
6
7
  const utils_1 = require("../utils");
7
8
  /**
8
9
  * Abstract base class for transport clients.
@@ -12,35 +13,41 @@ const utils_1 = require("../utils");
12
13
  * - `send()`/`emit()` lazily connect on first use.
13
14
  * - Concurrent send/emit calls share one connect().
14
15
  * - `close()` transitions to 'closing', waits for any pending connect
15
- * (bounded by `closeConnectTimeoutMs`, default 5s), calls doClose(),
16
+ * (bounded by `closeConnectTimeoutMs`, default 5s), calls `doClose()`,
16
17
  * then transitions to 'idle'.
17
18
  * - If the pending connect does not settle within the timeout, close
18
- * proceeds anyway. The adapter's doClose() must safely tear down
19
+ * proceeds anyway. The adapter's `doClose()` must safely tear down
19
20
  * partially opened native resources in this case.
20
21
  * - `send()`/`emit()` during 'closing' fail fast.
21
22
  * - After close, the next send/emit reconnects.
22
23
  * - A stale connect that resolves after close always rejects for its
23
24
  * original caller, even if a newer connection is already healthy.
24
- * - State is always reset in finally -- failed doClose() does not
25
+ * - State is always reset in finally — a failed `doClose()` does not
25
26
  * leave the client stuck.
26
27
  *
27
28
  * ## Stale async detection
28
29
  *
29
- * A monotonic `epoch` counter increments on each close(). The
30
- * connect callback only transitions to 'connected' if the epoch
31
- * has not changed, preventing a late-resolving connect from
32
- * overriding a close that happened while it was pending.
30
+ * A monotonic `epoch` counter increments on each `close()`. The connect
31
+ * callback only transitions to `connected` if the epoch has not changed,
32
+ * preventing a late-resolving connect from overriding a close that
33
+ * happened while it was pending.
33
34
  *
34
- * The connectionPromise is only cleared by its own .finally()
35
+ * The `connectionPromise` is only cleared by its own `.finally()`
35
36
  * callback if it is still the current promise, preventing a stale
36
37
  * promise from clobbering a newer one.
38
+ *
39
+ * @public
37
40
  */
38
41
  class ClientProxy {
42
+ statusSubject = new rxjs_1.ReplaySubject(1);
43
+ state = 'idle';
44
+ connectionPromise;
45
+ connectionEpoch;
46
+ closePromise;
47
+ epoch = 0;
48
+ closeConnectTimeoutMs;
49
+ status$ = this.statusSubject.asObservable();
39
50
  constructor(options) {
40
- this.statusSubject = new rxjs_1.ReplaySubject(1);
41
- this.state = 'idle';
42
- this.epoch = 0;
43
- this.status$ = this.statusSubject.asObservable();
44
51
  this.closeConnectTimeoutMs = options?.closeConnectTimeoutMs ?? 5000;
45
52
  }
46
53
  /**
@@ -49,14 +56,18 @@ class ClientProxy {
49
56
  * - If idle with no pending connect, returns immediately (no-op).
50
57
  * - If already closing, returns the existing close promise (dedupe).
51
58
  * - Otherwise:
52
- * 1. Increments epoch to invalidate any in-flight connect().
53
- * 2. Transitions to 'closing' so new send/emit fails fast.
54
- * 3. Waits for pending connect (bounded by closeConnectTimeoutMs).
55
- * 4. Calls doClose() for adapter-specific teardown.
56
- * 5. Resets to 'idle' in finally (even if doClose throws).
59
+ * 1. Increments epoch to invalidate any in-flight `connect()`.
60
+ * 2. Transitions to `closing` so new send/emit fails fast.
61
+ * 3. Waits for pending connect (bounded by `closeConnectTimeoutMs`).
62
+ * 4. Calls `doClose()` for adapter-specific teardown.
63
+ * 5. Resets to `idle` in finally (even if `doClose` throws).
64
+ *
65
+ * After close, the client is reusable: the next send/emit will
66
+ * trigger a fresh `connect()`.
57
67
  *
58
- * After close, the client is reusable: the next send/emit
59
- * will trigger a fresh connect().
68
+ * @public
69
+ * @throws TransportError When the adapter's `doClose()` rejects.
70
+ * State is still reset to `idle` so the client remains reusable.
60
71
  */
61
72
  async close() {
62
73
  if (this.state === 'idle' && !this.connectionPromise)
@@ -71,7 +82,7 @@ class ClientProxy {
71
82
  async doCloseInternal() {
72
83
  this.epoch++;
73
84
  this.state = 'closing';
74
- // Wait for pending connect with timeout so close never hangs
85
+ // Wait for pending connect with timeout so close never hangs.
75
86
  await this.waitForPendingConnect();
76
87
  try {
77
88
  await this.doClose();
@@ -84,8 +95,8 @@ class ClientProxy {
84
95
  }
85
96
  }
86
97
  /**
87
- * Wait for a pending connect to settle, bounded by timeout.
88
- * If connect does not settle in time, proceed anyway -- the epoch
98
+ * Wait for a pending connect to settle, bounded by timeout. If
99
+ * connect does not settle in time, proceed anyway — the epoch
89
100
  * invalidation ensures the stale connect result is ignored.
90
101
  */
91
102
  async waitForPendingConnect() {
@@ -102,6 +113,13 @@ class ClientProxy {
102
113
  *
103
114
  * Returns a cold Observable: the message is sent only when subscribed.
104
115
  * The connection is established lazily on first subscription.
116
+ *
117
+ * @public
118
+ * @typeParam TResult - Expected response shape.
119
+ * @typeParam TInput - Caller-provided payload shape.
120
+ * @param pattern - Pattern to match on the server side.
121
+ * @param data - The message payload.
122
+ * @returns A cold Observable that emits the response value(s).
105
123
  */
106
124
  send(pattern, data) {
107
125
  const normalizedPattern = (0, utils_1.normalizePattern)(pattern);
@@ -117,8 +135,16 @@ class ClientProxy {
117
135
  /**
118
136
  * Emit an event with no response expected (fire-and-forget pattern).
119
137
  *
120
- * Returns a Promise that resolves when the event is dispatched.
121
- * The connection is established lazily if not already connected.
138
+ * Returns a Promise that resolves when the event is dispatched. The
139
+ * connection is established lazily if not already connected.
140
+ *
141
+ * @public
142
+ * @typeParam TInput - Caller-provided payload shape.
143
+ * @param pattern - Event pattern.
144
+ * @param data - The event payload.
145
+ * @returns Resolves when the broker has accepted the event.
146
+ * @throws TransportError When the client is closing or a concurrent
147
+ * close invalidated the pending connect.
122
148
  */
123
149
  async emit(pattern, data) {
124
150
  const normalizedPattern = (0, utils_1.normalizePattern)(pattern);
@@ -126,14 +152,17 @@ class ClientProxy {
126
152
  await this.dispatchEvent({ pattern: normalizedPattern, data });
127
153
  }
128
154
  /**
129
- * Assign a unique correlation ID to a packet.
130
- * Uses crypto.randomUUID() for distributed-system-safe IDs.
155
+ * Assign a unique correlation ID to a packet. Uses
156
+ * `crypto.randomUUID()` for distributed-system-safe IDs.
131
157
  */
132
158
  assignPacketId(packet) {
133
159
  return { ...packet, id: (0, crypto_1.randomUUID)() };
134
160
  }
135
161
  /**
136
- * Create an Observer callback that maps WritePacket to Observable emissions.
162
+ * Create an Observer callback that maps `WritePacket` values to
163
+ * Observable emissions.
164
+ *
165
+ * @typeParam T - Expected response type.
137
166
  */
138
167
  createObserver(observer) {
139
168
  return (packet) => {
@@ -149,40 +178,40 @@ class ClientProxy {
149
178
  };
150
179
  }
151
180
  /**
152
- * Verify the client is in connected state.
153
- * Throws if a concurrent close() prevented the transition.
181
+ * Verify the client is in connected state. Throws if a concurrent
182
+ * close prevented the transition.
154
183
  */
155
184
  assertConnected() {
156
185
  if (this.state !== 'connected') {
157
- throw new Error('Client was closed during connection');
186
+ throw new errors_1.TransportError('Client was closed during connection');
158
187
  }
159
188
  }
160
189
  /**
161
190
  * Ensure the client is connected. Concurrent calls share the same
162
191
  * connection promise to prevent duplicate connections.
163
192
  *
164
- * - 'closing': reject immediately.
165
- * - 'connected': return immediately.
166
- * - 'connecting': await the shared promise.
167
- * - 'idle': start connect, capture epoch, only transition to
168
- * 'connected' if epoch hasn't changed.
193
+ * - `closing`: reject immediately.
194
+ * - `connected`: return immediately.
195
+ * - `connecting`: await the shared promise.
196
+ * - `idle`: start connect, capture epoch, only transition to
197
+ * `connected` if epoch hasn't changed.
169
198
  *
170
199
  * After await, the caller validates that the epoch it waited on
171
200
  * still matches. A stale connect that was invalidated by close()
172
- * always rejects for its original caller, even if a newer
173
- * connection is already healthy.
201
+ * always rejects for its original caller, even if a newer connection
202
+ * is already healthy.
174
203
  *
175
204
  * The connectionPromise/connectionEpoch are only cleared in
176
- * .finally() if the finishing promise is still the current one,
205
+ * `.finally()` if the finishing promise is still the current one,
177
206
  * preventing a stale promise from clobbering a newer one.
178
207
  */
179
208
  async ensureConnected() {
180
209
  if (this.state === 'closing') {
181
- throw new Error('Client is closing');
210
+ throw new errors_1.TransportError('Client is closing');
182
211
  }
183
212
  if (this.state === 'connected')
184
213
  return;
185
- // Capture the epoch this caller will wait on
214
+ // Capture the epoch this caller will wait on.
186
215
  const awaitedEpoch = this.connectionEpoch ?? this.epoch;
187
216
  if (!this.connectionPromise) {
188
217
  const ep = this.epoch;
@@ -195,7 +224,7 @@ class ClientProxy {
195
224
  this.statusSubject.next('connected');
196
225
  }
197
226
  else {
198
- throw new Error('Client was closed during connection');
227
+ throw new errors_1.TransportError('Client was closed during connection');
199
228
  }
200
229
  })
201
230
  .catch(err => {
@@ -216,7 +245,7 @@ class ClientProxy {
216
245
  // Validate that this caller's epoch is still current.
217
246
  // A stale caller whose connect was invalidated must not proceed.
218
247
  if (this.epoch !== awaitedEpoch) {
219
- throw new Error('Client was closed during connection');
248
+ throw new errors_1.TransportError('Client was closed during connection');
220
249
  }
221
250
  this.assertConnected();
222
251
  }
@@ -1 +1 @@
1
- {"version":3,"file":"client-proxy.js","sourceRoot":"","sources":["../../src/client/client-proxy.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAClC,+BAAgE;AAEhE,oCAA0C;AAY1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAsB,WAAW;IAW/B,YAAY,OAA0C;QAVnC,kBAAa,GAAG,IAAI,oBAAa,CAAkB,CAAC,CAAC,CAAC;QACjE,UAAK,GAAgB,MAAM,CAAC;QAI5B,UAAK,GAAG,CAAC,CAAC;QAGT,YAAO,GAAG,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE,CAAC;QAGnD,IAAI,CAAC,qBAAqB,GAAG,OAAO,EAAE,qBAAqB,IAAI,IAAI,CAAC;IACtE,CAAC;IAiBD;;;;;;;;;;;;;;OAcG;IACH,KAAK,CAAC,KAAK;QACT,IAAI,IAAI,CAAC,KAAK,KAAK,MAAM,IAAI,CAAC,IAAI,CAAC,iBAAiB;YAAE,OAAO;QAC7D,IAAI,IAAI,CAAC,YAAY;YAAE,OAAO,IAAI,CAAC,YAAY,CAAC;QAEhD,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE;YACtD,IAAI,CAAC,YAAY,GAAG,SAAS,CAAC;QAChC,CAAC,CAAC,CAAC;QACH,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAEO,KAAK,CAAC,eAAe;QAC3B,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;QACvB,6DAA6D;QAC7D,MAAM,IAAI,CAAC,qBAAqB,EAAE,CAAC;QACnC,IAAI;YACF,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;SACtB;gBAAS;YACR,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export * from './client-proxy';
1
+ export { ClientProxy } from './client-proxy';
@@ -1,18 +1,6 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
2
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./client-proxy"), exports);
3
+ exports.ClientProxy = void 0;
4
+ var client_proxy_1 = require("./client-proxy");
5
+ Object.defineProperty(exports, "ClientProxy", { enumerable: true, get: function () { return client_proxy_1.ClientProxy; } });
18
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":";;;AAAA,+CAA2C;AAAnC,2GAAA,WAAW,OAAA"}
@@ -1,17 +1,26 @@
1
1
  /**
2
2
  * The type of transport handling the current request.
3
+ *
4
+ * @public
3
5
  */
4
6
  export type ContextType = 'http' | 'rpc' | 'event';
5
7
  /**
6
8
  * Handler function type. Avoids bare `Function`.
9
+ *
10
+ * @public
7
11
  */
8
12
  export type HandlerFunction = (...args: unknown[]) => unknown;
9
13
  /**
10
14
  * Controller class type. Avoids bare `Function`.
15
+ *
16
+ * @public
17
+ * @typeParam T - The constructed instance type.
11
18
  */
12
19
  export type ControllerClass<T = unknown> = abstract new (...args: never[]) => T;
13
20
  /**
14
21
  * HTTP-specific context. Wraps Express request/response.
22
+ *
23
+ * @public
15
24
  */
16
25
  export interface HttpContext {
17
26
  getRequest<T = unknown>(): T;
@@ -19,6 +28,8 @@ export interface HttpContext {
19
28
  }
20
29
  /**
21
30
  * RPC-specific context (gRPC, request/response patterns).
31
+ *
32
+ * @public
22
33
  */
23
34
  export interface RpcContext {
24
35
  getData<T = unknown>(): T;
@@ -27,6 +38,8 @@ export interface RpcContext {
27
38
  }
28
39
  /**
29
40
  * Event-specific context (Kafka, RabbitMQ, MQTT, NATS events).
41
+ *
42
+ * @public
30
43
  */
31
44
  export interface EventContext {
32
45
  getData<T = unknown>(): T;
@@ -34,14 +47,17 @@ export interface EventContext {
34
47
  getContext<T = unknown>(): T;
35
48
  }
36
49
  /**
37
- * Unified execution context that works across HTTP, RPC, and event transports.
50
+ * Unified execution context that works across HTTP, RPC, and event
51
+ * transports.
38
52
  *
39
- * Immutable after construction. Created via static factory methods
40
- * that guarantee the transport-specific context is present.
41
- * No half-built contexts, no post-construction mutation.
53
+ * Immutable after construction. Created via static factory methods that
54
+ * guarantee the transport-specific context is present. No half-built
55
+ * contexts, no post-construction mutation.
42
56
  *
43
- * NestJS-compatible mental model: getType() + switchToHttp/Rpc/Event.
57
+ * NestJS-compatible mental model: `getType()` + `switchToHttp/Rpc/Event`.
44
58
  * Cleaner construction: factory methods enforce correct state.
59
+ *
60
+ * @public
45
61
  */
46
62
  export declare class ExecutionContext {
47
63
  private readonly type;
@@ -54,49 +70,80 @@ export declare class ExecutionContext {
54
70
  private constructor();
55
71
  /**
56
72
  * Create an HTTP execution context.
73
+ *
74
+ * @public
57
75
  */
58
76
  static forHttp(args: unknown[], handler: HandlerFunction, controllerClass: ControllerClass, httpCtx: HttpContext): ExecutionContext;
59
77
  /**
60
78
  * Create an RPC execution context (gRPC, request/response patterns).
79
+ *
80
+ * @public
61
81
  */
62
82
  static forRpc(args: unknown[], handler: HandlerFunction, controllerClass: ControllerClass, rpcCtx: RpcContext): ExecutionContext;
63
83
  /**
64
84
  * Create an event execution context (Kafka, RabbitMQ, MQTT, NATS).
85
+ *
86
+ * @public
65
87
  */
66
88
  static forEvent(args: unknown[], handler: HandlerFunction, controllerClass: ControllerClass, eventCtx: EventContext): ExecutionContext;
67
89
  /**
68
90
  * Returns the transport type handling this request.
91
+ *
92
+ * @public
69
93
  */
70
94
  getType(): ContextType;
71
95
  /**
72
96
  * Returns the controller class the handler belongs to.
97
+ *
98
+ * @experimental The generic parameter is asserted, not inferred.
99
+ * Callers must verify the resulting class shape themselves.
100
+ * @typeParam T - Caller-asserted instance type.
73
101
  */
74
102
  getClass<T = unknown>(): ControllerClass<T>;
75
103
  /**
76
104
  * Returns the handler function that will be invoked.
105
+ *
106
+ * @public
77
107
  */
78
108
  getHandler(): HandlerFunction;
79
109
  /**
80
110
  * Returns a copy of the arguments array.
111
+ *
112
+ * @experimental Callers assert the tuple shape; no runtime check is
113
+ * performed.
114
+ * @typeParam T - Caller-asserted tuple type.
81
115
  */
82
116
  getArgs<T extends readonly unknown[] = readonly unknown[]>(): T;
83
117
  /**
84
118
  * Returns a specific argument by index.
119
+ *
120
+ * @experimental Callers assert the value type; no runtime check is
121
+ * performed.
122
+ * @typeParam T - Caller-asserted argument type.
85
123
  */
86
124
  getArgByIndex<T = unknown>(index: number): T;
87
125
  /**
88
- * Switch to HTTP context.
89
- * Throws if the current type is not 'http' or context is missing.
126
+ * Switch to HTTP context. Throws if the current type is not `http`
127
+ * or the context is missing.
128
+ *
129
+ * @public
130
+ * @throws TransportError When the current transport type is not HTTP.
90
131
  */
91
132
  switchToHttp(): HttpContext;
92
133
  /**
93
- * Switch to RPC context.
94
- * Throws if the current type is not 'rpc' or context is missing.
134
+ * Switch to RPC context. Throws if the current type is not `rpc` or
135
+ * the context is missing.
136
+ *
137
+ * @public
138
+ * @throws TransportError When the current transport type is not RPC.
95
139
  */
96
140
  switchToRpc(): RpcContext;
97
141
  /**
98
- * Switch to event context.
99
- * Throws if the current type is not 'event' or context is missing.
142
+ * Switch to event context. Throws if the current type is not `event`
143
+ * or the context is missing.
144
+ *
145
+ * @public
146
+ * @throws TransportError When the current transport type is not event.
100
147
  */
101
148
  switchToEvent(): EventContext;
102
149
  }