@pawells/rxjs-events 1.0.3 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -17
- package/build/async-generator-esn.d.ts +17 -6
- package/build/async-generator-esn.d.ts.map +1 -1
- package/build/async-observable.d.ts +85 -6
- package/build/async-observable.d.ts.map +1 -1
- package/build/async-observable.js +51 -3
- package/build/async-observable.js.map +1 -1
- package/build/event-filter.d.ts.map +1 -1
- package/build/event-filter.js +2 -17
- package/build/event-filter.js.map +1 -1
- package/build/event-operators.d.ts.map +1 -1
- package/build/event-operators.js +8 -32
- package/build/event-operators.js.map +1 -1
- package/build/event-pipeline.d.ts +5 -0
- package/build/event-pipeline.d.ts.map +1 -1
- package/build/event-pipeline.js +11 -2
- package/build/event-pipeline.js.map +1 -1
- package/build/extract-event-payload.d.ts +24 -2
- package/build/extract-event-payload.d.ts.map +1 -1
- package/build/filter-criteria.d.ts +24 -2
- package/build/filter-criteria.d.ts.map +1 -1
- package/build/handler.d.ts +21 -16
- package/build/handler.d.ts.map +1 -1
- package/build/handler.js +19 -15
- package/build/handler.js.map +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.d.ts.map +1 -1
- package/build/nestjs-pubsub.d.ts +41 -13
- package/build/nestjs-pubsub.d.ts.map +1 -1
- package/build/nestjs-pubsub.js +31 -12
- package/build/nestjs-pubsub.js.map +1 -1
- package/build/types.d.ts +41 -15
- package/build/types.d.ts.map +1 -1
- package/package.json +9 -8
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@pawells/rxjs-events)
|
|
4
4
|
[](https://github.com/PhillipAWells/rxjs-events/releases)
|
|
5
5
|
[](https://github.com/PhillipAWells/rxjs-events/actions/workflows/ci.yml)
|
|
6
|
-
[](https://nodejs.org)
|
|
7
7
|
[](./LICENSE)
|
|
8
8
|
[](https://github.com/sponsors/PhillipAWells)
|
|
9
9
|
|
|
@@ -86,8 +86,8 @@ async function processOnce() {
|
|
|
86
86
|
import { AsyncObservable, BackpressureStrategy } from '@pawells/rxjs-events';
|
|
87
87
|
|
|
88
88
|
const obs = new AsyncObservable<string>({
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
maxBufferSize: 100,
|
|
90
|
+
overflowStrategy: BackpressureStrategy.DropOldest,
|
|
91
91
|
});
|
|
92
92
|
|
|
93
93
|
for await (const item of obs) {
|
|
@@ -117,14 +117,16 @@ Main event handler class wrapping an RxJS `Subject`.
|
|
|
117
117
|
|
|
118
118
|
| Method | Signature | Description |
|
|
119
119
|
|--------|-----------|-------------|
|
|
120
|
-
| `constructor` | `(name:
|
|
121
|
-
| `Name` | `string` (
|
|
122
|
-
| `Subscribe` | `(
|
|
123
|
-
| `Unsubscribe` | `(
|
|
124
|
-
| `Trigger` | `(data: TObject
|
|
120
|
+
| `constructor` | `(name: string)` | Creates a handler with the given event name (cannot be empty or whitespace-only) |
|
|
121
|
+
| `Name` | `string` (readonly) | Returns the event name |
|
|
122
|
+
| `Subscribe` | `(onEvent: TEventFunction<TEvent>) => number` | Subscribes and returns a numeric ID |
|
|
123
|
+
| `Unsubscribe` | `(subscription: number) => void` | Removes subscription by ID |
|
|
124
|
+
| `Trigger` | `(data: TObject) => void` | Emits the event with the given payload |
|
|
125
125
|
| `Destroy` | `() => void` | Completes the Subject and cleans up all subscriptions |
|
|
126
|
-
| `GetAsyncIterableIterator` | `() => AsyncIterableIterator<
|
|
127
|
-
| `GetAsyncIterator` | `() =>
|
|
126
|
+
| `GetAsyncIterableIterator` | `() => AsyncIterableIterator<TEvent>` | Returns an async iterable iterator |
|
|
127
|
+
| `GetAsyncIterator` | `() => AsyncIterator<TEvent>` | Returns an async iterator |
|
|
128
|
+
| `GetSubscriptionCount` | `() => number` | Returns the count of active subscriptions |
|
|
129
|
+
| `GetActiveSubscriptionIds` | `() => number[]` | Returns array of active subscription IDs |
|
|
128
130
|
|
|
129
131
|
Subscription IDs are recycled internally — allocation is O(1).
|
|
130
132
|
|
|
@@ -132,10 +134,10 @@ Subscription IDs are recycled internally — allocation is O(1).
|
|
|
132
134
|
|
|
133
135
|
An `Observable` subclass with a push buffer and configurable backpressure. Implements `Symbol.asyncIterator`.
|
|
134
136
|
|
|
135
|
-
| Option | Type | Description |
|
|
136
|
-
|
|
137
|
-
| `
|
|
138
|
-
| `
|
|
137
|
+
| Option | Type | Default | Description |
|
|
138
|
+
|--------|------|---------|-------------|
|
|
139
|
+
| `maxBufferSize` | `number` | 1000 | Maximum number of buffered items |
|
|
140
|
+
| `overflowStrategy` | `BackpressureStrategy` | `DropOldest` | How to handle buffer overflow: `DropOldest`, `DropNewest`, or `Error` |
|
|
139
141
|
|
|
140
142
|
Throws `BufferOverflowError` when strategy is `Error` and the buffer is full.
|
|
141
143
|
|
|
@@ -154,7 +156,6 @@ Filters a single-key event object against an `IFilterCriteria` map using strict
|
|
|
154
156
|
| `TAsyncObserver` | Async observer callback type |
|
|
155
157
|
| `TUnsubscribe` | Unsubscribe function type |
|
|
156
158
|
| `IFilterCriteria` | Index-signature interface `{ [key: string]: unknown }` |
|
|
157
|
-
| `ISubscriptionOptions` | Options passed to `Subscribe` |
|
|
158
159
|
| `IBackpressureConfig` | Configuration object for `AsyncObservable` |
|
|
159
160
|
| `IAsyncGeneratorESN<T, TReturn, TNext>` | `AsyncGenerator` extended with `Symbol.asyncDispose` |
|
|
160
161
|
| `TExtractEventPayload<TEvent>` | Utility type — extracts payload type from a `TEventData` object |
|
|
@@ -197,12 +198,12 @@ yarn start # Run built output
|
|
|
197
198
|
To run a single test file:
|
|
198
199
|
|
|
199
200
|
```bash
|
|
200
|
-
yarn vitest run src/
|
|
201
|
+
yarn vitest run src/tests/file.spec.ts
|
|
201
202
|
```
|
|
202
203
|
|
|
203
204
|
## Requirements
|
|
204
205
|
|
|
205
|
-
- Node.js >=
|
|
206
|
+
- Node.js >= 22.0.0
|
|
206
207
|
- ESM-only (`"type": "module"`) — use ESM imports throughout
|
|
207
208
|
|
|
208
209
|
## License
|
|
@@ -11,14 +11,25 @@
|
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* ```typescript
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
14
|
+
* import { EventHandler } from '@pawells/rxjs-events';
|
|
15
|
+
* import type { IAsyncGeneratorESN } from '@pawells/rxjs-events';
|
|
16
|
+
*
|
|
17
|
+
* interface MessageEvent extends Record<string, unknown> {
|
|
18
|
+
* MessageReceived: { text: string };
|
|
17
19
|
* }
|
|
18
20
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
21
|
+
* const handler = new EventHandler<MessageEvent, 'MessageReceived'>('MessageReceived');
|
|
22
|
+
*
|
|
23
|
+
* async function processOnce(): Promise<void> {
|
|
24
|
+
* // GetAsyncIterator() returns IAsyncGeneratorESN, which implements Symbol.asyncDispose.
|
|
25
|
+
* // TypeScript target ES2022 + lib ESNext enables the `await using` syntax directly.
|
|
26
|
+
* await using iter: IAsyncGeneratorESN<{ text: string }, void, void> = handler.GetAsyncIterator();
|
|
27
|
+
* const { value, done } = await iter.next();
|
|
28
|
+
* if (!done) {
|
|
29
|
+
* console.log('Message:', value.text);
|
|
30
|
+
* }
|
|
31
|
+
* // iter[Symbol.asyncDispose]() is called automatically at block exit
|
|
32
|
+
* }
|
|
22
33
|
* ```
|
|
23
34
|
*/
|
|
24
35
|
export interface IAsyncGeneratorESN<T = unknown, TReturn = unknown, TNext = unknown> extends AsyncGenerator<T, TReturn, TNext> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async-generator-esn.d.ts","sourceRoot":"","sources":["../src/async-generator-esn.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"async-generator-esn.d.ts","sourceRoot":"","sources":["../src/async-generator-esn.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,WAAW,kBAAkB,CAAC,CAAC,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO,EAAE,KAAK,GAAG,OAAO,CAAE,SAAQ,cAAc,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC;IAC7H,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,CAAA;CAC1C"}
|
|
@@ -1,28 +1,107 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
2
|
/**
|
|
3
|
-
* Error thrown when
|
|
3
|
+
* Error thrown when an {@link AsyncObservable} buffer overflows and the
|
|
4
|
+
* configured strategy is {@link BackpressureStrategy.Error}.
|
|
5
|
+
*
|
|
6
|
+
* The error message includes the configured `maxBufferSize` so callers can
|
|
7
|
+
* distinguish overflow from other runtime errors.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* This error is only thrown when `overflowStrategy` is set to
|
|
11
|
+
* `BackpressureStrategy.Error`. The `DropOldest` and `DropNewest` strategies
|
|
12
|
+
* silently discard excess items instead of throwing.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { AsyncObservable, BackpressureStrategy, BufferOverflowError } from '@pawells/rxjs-events';
|
|
17
|
+
*
|
|
18
|
+
* const obs = new AsyncObservable<number>({
|
|
19
|
+
* maxBufferSize: 2,
|
|
20
|
+
* overflowStrategy: BackpressureStrategy.Error,
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* try {
|
|
24
|
+
* obs.Push(1);
|
|
25
|
+
* obs.Push(2);
|
|
26
|
+
* obs.Push(3); // throws BufferOverflowError
|
|
27
|
+
* } catch (err) {
|
|
28
|
+
* if (err instanceof BufferOverflowError) {
|
|
29
|
+
* console.error('Buffer full:', err.message);
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
4
33
|
*/
|
|
5
34
|
export declare class BufferOverflowError extends Error {
|
|
6
35
|
constructor(maxSize: number);
|
|
7
36
|
}
|
|
8
37
|
/**
|
|
9
|
-
*
|
|
38
|
+
* Strategy applied by {@link AsyncObservable} when its push buffer reaches
|
|
39
|
+
* {@link IBackpressureConfig.maxBufferSize}.
|
|
40
|
+
*
|
|
41
|
+
* Choose a strategy based on how your consumer handles lag. `DropOldest` (the
|
|
42
|
+
* default) keeps the most recent data; `DropNewest` preserves historical order
|
|
43
|
+
* at the cost of discarding late arrivals; `Error` makes overflow a hard fault
|
|
44
|
+
* so callers must handle it explicitly.
|
|
45
|
+
*
|
|
46
|
+
* @see {@link IBackpressureConfig} for configuration details.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* import { AsyncObservable, BackpressureStrategy } from '@pawells/rxjs-events';
|
|
51
|
+
*
|
|
52
|
+
* // Keep the most recent 50 items; discard the oldest when full
|
|
53
|
+
* const obs = new AsyncObservable<string>({
|
|
54
|
+
* maxBufferSize: 50,
|
|
55
|
+
* overflowStrategy: BackpressureStrategy.DropOldest,
|
|
56
|
+
* });
|
|
57
|
+
* ```
|
|
10
58
|
*/
|
|
11
59
|
export declare enum BackpressureStrategy {
|
|
12
60
|
/** Drop oldest events when buffer is full */
|
|
13
61
|
DropOldest = "DropOldest",
|
|
14
62
|
/** Drop newest events when buffer is full */
|
|
15
63
|
DropNewest = "DropNewest",
|
|
16
|
-
/** Throw
|
|
64
|
+
/** Throw {@link BufferOverflowError} when buffer is full */
|
|
17
65
|
Error = "Error"
|
|
18
66
|
}
|
|
19
67
|
/**
|
|
20
|
-
* Configuration for AsyncObservable backpressure
|
|
68
|
+
* Configuration object for {@link AsyncObservable} backpressure behaviour.
|
|
69
|
+
*
|
|
70
|
+
* All properties are optional. Omit the entire config object to accept all
|
|
71
|
+
* defaults (`maxBufferSize: 1000`, `overflowStrategy: BackpressureStrategy.DropOldest`).
|
|
72
|
+
*
|
|
73
|
+
* @remarks
|
|
74
|
+
* Setting `maxBufferSize` to a non-positive integer throws a `RangeError` at
|
|
75
|
+
* construction time.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* import { AsyncObservable, BackpressureStrategy } from '@pawells/rxjs-events';
|
|
80
|
+
* import type { IBackpressureConfig } from '@pawells/rxjs-events';
|
|
81
|
+
*
|
|
82
|
+
* // DropOldest — discard the oldest buffered item to make room (default)
|
|
83
|
+
* const dropOldest = new AsyncObservable<number>({
|
|
84
|
+
* maxBufferSize: 100,
|
|
85
|
+
* overflowStrategy: BackpressureStrategy.DropOldest,
|
|
86
|
+
* });
|
|
87
|
+
*
|
|
88
|
+
* // DropNewest — discard the incoming item when the buffer is full
|
|
89
|
+
* const dropNewest = new AsyncObservable<number>({
|
|
90
|
+
* maxBufferSize: 100,
|
|
91
|
+
* overflowStrategy: BackpressureStrategy.DropNewest,
|
|
92
|
+
* });
|
|
93
|
+
*
|
|
94
|
+
* // Error — throw BufferOverflowError on overflow
|
|
95
|
+
* const strict = new AsyncObservable<number>({
|
|
96
|
+
* maxBufferSize: 100,
|
|
97
|
+
* overflowStrategy: BackpressureStrategy.Error,
|
|
98
|
+
* });
|
|
99
|
+
* ```
|
|
21
100
|
*/
|
|
22
101
|
export interface IBackpressureConfig {
|
|
23
|
-
/** Maximum buffer
|
|
102
|
+
/** Maximum number of items held in the push buffer before overflow handling kicks in. Defaults to 1000. */
|
|
24
103
|
maxBufferSize?: number;
|
|
25
|
-
/** Strategy when buffer
|
|
104
|
+
/** Strategy applied when the buffer is full. Defaults to {@link BackpressureStrategy.DropOldest}. */
|
|
26
105
|
overflowStrategy?: BackpressureStrategy;
|
|
27
106
|
}
|
|
28
107
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async-observable.d.ts","sourceRoot":"","sources":["../src/async-observable.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAyB,MAAM,MAAM,CAAC;AAGzD
|
|
1
|
+
{"version":3,"file":"async-observable.d.ts","sourceRoot":"","sources":["../src/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link AsyncObservable} buffer overflows and the
|
|
4
|
+
* configured strategy is {@link BackpressureStrategy.Error}.
|
|
5
|
+
*
|
|
6
|
+
* The error message includes the configured `maxBufferSize` so callers can
|
|
7
|
+
* distinguish overflow from other runtime errors.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* This error is only thrown when `overflowStrategy` is set to
|
|
11
|
+
* `BackpressureStrategy.Error`. The `DropOldest` and `DropNewest` strategies
|
|
12
|
+
* silently discard excess items instead of throwing.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { AsyncObservable, BackpressureStrategy, BufferOverflowError } from '@pawells/rxjs-events';
|
|
17
|
+
*
|
|
18
|
+
* const obs = new AsyncObservable<number>({
|
|
19
|
+
* maxBufferSize: 2,
|
|
20
|
+
* overflowStrategy: BackpressureStrategy.Error,
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* try {
|
|
24
|
+
* obs.Push(1);
|
|
25
|
+
* obs.Push(2);
|
|
26
|
+
* obs.Push(3); // throws BufferOverflowError
|
|
27
|
+
* } catch (err) {
|
|
28
|
+
* if (err instanceof BufferOverflowError) {
|
|
29
|
+
* console.error('Buffer full:', err.message);
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
4
33
|
*/
|
|
5
34
|
export class BufferOverflowError extends Error {
|
|
6
35
|
constructor(maxSize) {
|
|
@@ -9,7 +38,26 @@ export class BufferOverflowError extends Error {
|
|
|
9
38
|
}
|
|
10
39
|
}
|
|
11
40
|
/**
|
|
12
|
-
*
|
|
41
|
+
* Strategy applied by {@link AsyncObservable} when its push buffer reaches
|
|
42
|
+
* {@link IBackpressureConfig.maxBufferSize}.
|
|
43
|
+
*
|
|
44
|
+
* Choose a strategy based on how your consumer handles lag. `DropOldest` (the
|
|
45
|
+
* default) keeps the most recent data; `DropNewest` preserves historical order
|
|
46
|
+
* at the cost of discarding late arrivals; `Error` makes overflow a hard fault
|
|
47
|
+
* so callers must handle it explicitly.
|
|
48
|
+
*
|
|
49
|
+
* @see {@link IBackpressureConfig} for configuration details.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* import { AsyncObservable, BackpressureStrategy } from '@pawells/rxjs-events';
|
|
54
|
+
*
|
|
55
|
+
* // Keep the most recent 50 items; discard the oldest when full
|
|
56
|
+
* const obs = new AsyncObservable<string>({
|
|
57
|
+
* maxBufferSize: 50,
|
|
58
|
+
* overflowStrategy: BackpressureStrategy.DropOldest,
|
|
59
|
+
* });
|
|
60
|
+
* ```
|
|
13
61
|
*/
|
|
14
62
|
export var BackpressureStrategy;
|
|
15
63
|
(function (BackpressureStrategy) {
|
|
@@ -17,7 +65,7 @@ export var BackpressureStrategy;
|
|
|
17
65
|
BackpressureStrategy["DropOldest"] = "DropOldest";
|
|
18
66
|
/** Drop newest events when buffer is full */
|
|
19
67
|
BackpressureStrategy["DropNewest"] = "DropNewest";
|
|
20
|
-
/** Throw
|
|
68
|
+
/** Throw {@link BufferOverflowError} when buffer is full */
|
|
21
69
|
BackpressureStrategy["Error"] = "Error";
|
|
22
70
|
})(BackpressureStrategy || (BackpressureStrategy = {}));
|
|
23
71
|
/** Default maximum buffer size for AsyncObservable instances */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async-observable.js","sourceRoot":"","sources":["../src/async-observable.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAgB,MAAM,MAAM,CAAC;AAGzD
|
|
1
|
+
{"version":3,"file":"async-observable.js","sourceRoot":"","sources":["../src/async-observable.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAgB,MAAM,MAAM,CAAC;AAGzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC7C,YAAY,OAAe;QAC1B,KAAK,CAAC,2CAA2C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I,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;YAC1D,CAAC;YAED,KAAK,EAAE,CAAC,GAAG,EAA8B,EAAE;gBAC1C,YAAY,EAAE,WAAW,EAAE,CAAC;gBAC5B,sEAAsE;gBACtE,WAAW,CAAC,GAAG,CAAC,CAAC;gBACjB,OAAO,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAC5B,CAAC;YACD,CAAC,MAAM,CAAC,aAAa,CAAC;gBACrB,OAAO,IAAI,CAAC;YACb,CAAC;SACD,CAAC;QACF,OAAO,SAAS,CAAC;IAClB,CAAC;CACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-filter.d.ts","sourceRoot":"","sources":["../src/event-filter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAGvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AACH,wBAAgB,WAAW,CAAC,MAAM,SAAS,UAAU,GAAG,UAAU,EACjE,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,eAAe,GAAG,IAAI,GAAG,SAAS,GACtC,OAAO,
|
|
1
|
+
{"version":3,"file":"event-filter.d.ts","sourceRoot":"","sources":["../src/event-filter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAGvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AACH,wBAAgB,WAAW,CAAC,MAAM,SAAS,UAAU,GAAG,UAAU,EACjE,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,eAAe,GAAG,IAAI,GAAG,SAAS,GACtC,OAAO,CAmBT;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,SAAS,UAAU,GAAG,UAAU,EAC1E,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,eAAe,GAAG,IAAI,GAAG,SAAS,GACtC,CAAC,MAAM,GAAG,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC,CAGhC"}
|
package/build/event-filter.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ObjectFilter } from '@pawells/typescript-common';
|
|
2
2
|
/**
|
|
3
3
|
* Filters events based on payload property matching criteria.
|
|
4
4
|
* Performs strict equality comparison between event payload properties and filter arguments.
|
|
@@ -77,22 +77,7 @@ export function EventFilter(event, args) {
|
|
|
77
77
|
const payload = event[eventKey];
|
|
78
78
|
if (!payload)
|
|
79
79
|
throw new Error('No Payload');
|
|
80
|
-
|
|
81
|
-
// Support nested paths using dot notation
|
|
82
|
-
const payloadValue = ObjectGetPropertyByPath(payload, key);
|
|
83
|
-
// Support predicate functions as filter values
|
|
84
|
-
if (typeof filterValue === 'function') {
|
|
85
|
-
const predicate = filterValue;
|
|
86
|
-
if (!predicate(payloadValue))
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
// Standard equality check
|
|
91
|
-
if (payloadValue !== filterValue)
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return true;
|
|
80
|
+
return ObjectFilter(payload, args);
|
|
96
81
|
}
|
|
97
82
|
/**
|
|
98
83
|
* Partitions an event into matching and non-matching tuples based on filter criteria.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-filter.js","sourceRoot":"","sources":["../src/event-filter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"event-filter.js","sourceRoot":"","sources":["../src/event-filter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,4B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AAqB,CAAC,MAAM,CAAC,CAAC,CA2EhE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,SAAS,UAAU,GAAG,UAAU,EAAE,IAAI,GAAG,MAAM,EACzF,OAAO,EAAE,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,EAClC,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,EAC9B,SAAS,EAAE,MAAM,GACf,qBAAqB,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,CAmC5C"}
|
package/build/event-operators.js
CHANGED
|
@@ -73,7 +73,8 @@ export function PartitionEvents(handler, predicate) {
|
|
|
73
73
|
const nonMatchingQueue = [];
|
|
74
74
|
let matchingResolve;
|
|
75
75
|
let nonMatchingResolve;
|
|
76
|
-
|
|
76
|
+
// Track reference count for proper cleanup
|
|
77
|
+
let activeIterators = 2;
|
|
77
78
|
// Subscribe to the handler and distribute events to appropriate queues
|
|
78
79
|
const subscriptionId = handler.Subscribe((event) => {
|
|
79
80
|
if (predicate(event)) {
|
|
@@ -98,7 +99,7 @@ export function PartitionEvents(handler, predicate) {
|
|
|
98
99
|
if (closed) {
|
|
99
100
|
return { done: true, value: undefined };
|
|
100
101
|
}
|
|
101
|
-
while (queue.length === 0
|
|
102
|
+
while (queue.length === 0) {
|
|
102
103
|
await new Promise((resolve) => {
|
|
103
104
|
if (queue === matchingQueue) {
|
|
104
105
|
matchingResolve = resolve;
|
|
@@ -120,7 +121,11 @@ export function PartitionEvents(handler, predicate) {
|
|
|
120
121
|
async return() {
|
|
121
122
|
await Promise.resolve();
|
|
122
123
|
closed = true;
|
|
123
|
-
|
|
124
|
+
activeIterators--;
|
|
125
|
+
// Only unsubscribe when all iterators have closed
|
|
126
|
+
if (activeIterators === 0) {
|
|
127
|
+
handler.Unsubscribe(subscriptionId);
|
|
128
|
+
}
|
|
124
129
|
return { done: true, value: undefined };
|
|
125
130
|
},
|
|
126
131
|
};
|
|
@@ -128,35 +133,6 @@ export function PartitionEvents(handler, predicate) {
|
|
|
128
133
|
// Create iterators that share the same queues and handler
|
|
129
134
|
const matchingIterator = createIterator(matchingQueue);
|
|
130
135
|
const nonMatchingIterator = createIterator(nonMatchingQueue);
|
|
131
|
-
// Add destroy handlers to both iterators to clean up when iteration is done
|
|
132
|
-
Promise.allSettled([
|
|
133
|
-
(async () => {
|
|
134
|
-
try {
|
|
135
|
-
for await (const _ of matchingIterator) {
|
|
136
|
-
// Consumer will iterate; we just need to wait for completion
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
finally {
|
|
140
|
-
handlerComplete = true;
|
|
141
|
-
if (nonMatchingResolve)
|
|
142
|
-
nonMatchingResolve();
|
|
143
|
-
}
|
|
144
|
-
})(),
|
|
145
|
-
(async () => {
|
|
146
|
-
try {
|
|
147
|
-
for await (const _ of nonMatchingIterator) {
|
|
148
|
-
// Consumer will iterate; we just need to wait for completion
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
finally {
|
|
152
|
-
handlerComplete = true;
|
|
153
|
-
if (matchingResolve)
|
|
154
|
-
matchingResolve();
|
|
155
|
-
}
|
|
156
|
-
})(),
|
|
157
|
-
]).catch(() => {
|
|
158
|
-
// Silently handle any errors to avoid unhandled rejection warnings
|
|
159
|
-
});
|
|
160
136
|
return [matchingIterator, nonMatchingIterator];
|
|
161
137
|
}
|
|
162
138
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-operators.js","sourceRoot":"","sources":["../src/event-operators.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,WAAW,CAC1B,OAAkC,EAClC,IAAY;IAEZ,IAAI,IAAI,IAAI,CAAC,EAAE,CAAC;QACf,MAAM,IAAI,UAAU,CAAC,mCAAmC,CAAC,CAAC;IAC3D,CAAC;IAED,OAAO,CAAC,KAAK,SAAS,CAAC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;AACH,MAAM,UAAU,oBAAoB,CACnC,OAAkC,EAClC,KAA8B,EAC9B,SAAiB;IAEjB,IAAI,SAAS,IAAI,CAAC,EAAE,CAAC;QACpB,MAAM,IAAI,UAAU,CAAC,mCAAmC,CAAC,CAAC;IAC3D,CAAC;IAED,OAAO,CAAC,KAAK,SAAS,CAAC;QACtB,MAAM,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;QACzC,IAAI,UAAU,GAAG,CAAC,CAAC;QAEnB,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;YACnC,MAAM,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;YAEzB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;gBACtB,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YACrB,CAAC;YAED,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAC9B,IAAI,KAAK,EAAE,CAAC;gBACX,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBAClB,UAAU,EAAE,CAAC;gBAEb,mDAAmD;gBACnD,IAAI,KAAK,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC;oBAC/B,MAAM,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;oBACtB,MAAM,CAAC,KAAK,EAAE,CAAC;oBACf,UAAU,GAAG,CAAC,CAAC;gBAChB,CAAC;YACF,CAAC;QACF,CAAC;QAED,6BAA6B;QAC7B,IAAI,UAAU,GAAG,CAAC,EAAE,CAAC;YACpB,MAAM,MAAM,CAAC;QACd,CAAC;IACF,CAAC,CAAC,EAAE,CAAC;AACN,CAAC"}
|
|
@@ -65,6 +65,11 @@ export declare function ThrottleEvents<TObject extends object = object, TEvent e
|
|
|
65
65
|
* @param fns - Transform functions to apply in sequence
|
|
66
66
|
* @returns AsyncIterableIterator of transformed results
|
|
67
67
|
*
|
|
68
|
+
* @remarks
|
|
69
|
+
* Due to the underlying Pipe utility from @pawells/typescript-common accepting `(arg: any) => any`,
|
|
70
|
+
* the transform functions must use implicit typing or explicit any casts. The first function
|
|
71
|
+
* receives the event, and subsequent functions receive the output of the previous function.
|
|
72
|
+
*
|
|
68
73
|
* @example
|
|
69
74
|
* ```typescript
|
|
70
75
|
* interface MessageEvent extends TEventData {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-pipeline.d.ts","sourceRoot":"","sources":["../src/event-pipeline.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,cAAc,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM,EAAE,MAAM,SAAS,UAAU,GAAG,UAAU,EACrG,OAAO,EAAE,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,EACtC,EAAE,EAAE,MAAM,GACR,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"event-pipeline.d.ts","sourceRoot":"","sources":["../src/event-pipeline.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,cAAc,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM,EAAE,MAAM,SAAS,UAAU,GAAG,UAAU,EACrG,OAAO,EAAE,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,EACtC,EAAE,EAAE,MAAM,GACR,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,CAS/B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,cAAc,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM,EAAE,MAAM,SAAS,UAAU,GAAG,UAAU,EACrG,OAAO,EAAE,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,EACtC,EAAE,EAAE,MAAM,GACR,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,CAS/B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,UAAU,CAAC,MAAM,SAAS,UAAU,GAAG,UAAU,EAAE,OAAO,GAAG,GAAG,EAC/E,OAAO,EAAE,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,EAClC,GAAG,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,GAAG,CAAC,GAC5B,qBAAqB,CAAC,OAAO,CAAC,CAahC"}
|
package/build/event-pipeline.js
CHANGED
|
@@ -29,7 +29,9 @@ import { EventHandler } from './handler.js';
|
|
|
29
29
|
export function DebounceEvents(handler, ms) {
|
|
30
30
|
const debouncedHandler = new EventHandler(handler.Name);
|
|
31
31
|
const debouncedTrigger = Debounce((event) => {
|
|
32
|
-
|
|
32
|
+
// Extract payload from the event object before triggering to avoid double-wrapping
|
|
33
|
+
const payload = event[handler.Name];
|
|
34
|
+
debouncedHandler.Trigger(payload);
|
|
33
35
|
}, ms);
|
|
34
36
|
handler.Subscribe((event) => debouncedTrigger(event));
|
|
35
37
|
return debouncedHandler;
|
|
@@ -63,7 +65,9 @@ export function DebounceEvents(handler, ms) {
|
|
|
63
65
|
export function ThrottleEvents(handler, ms) {
|
|
64
66
|
const throttledHandler = new EventHandler(handler.Name);
|
|
65
67
|
const throttledTrigger = Throttle((event) => {
|
|
66
|
-
|
|
68
|
+
// Extract payload from the event object before triggering to avoid double-wrapping
|
|
69
|
+
const payload = event[handler.Name];
|
|
70
|
+
throttledHandler.Trigger(payload);
|
|
67
71
|
}, ms);
|
|
68
72
|
handler.Subscribe((event) => throttledTrigger(event));
|
|
69
73
|
return throttledHandler;
|
|
@@ -79,6 +83,11 @@ export function ThrottleEvents(handler, ms) {
|
|
|
79
83
|
* @param fns - Transform functions to apply in sequence
|
|
80
84
|
* @returns AsyncIterableIterator of transformed results
|
|
81
85
|
*
|
|
86
|
+
* @remarks
|
|
87
|
+
* Due to the underlying Pipe utility from @pawells/typescript-common accepting `(arg: any) => any`,
|
|
88
|
+
* the transform functions must use implicit typing or explicit any casts. The first function
|
|
89
|
+
* receives the event, and subsequent functions receive the output of the previous function.
|
|
90
|
+
*
|
|
82
91
|
* @example
|
|
83
92
|
* ```typescript
|
|
84
93
|
* interface MessageEvent extends TEventData {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-pipeline.js","sourceRoot":"","sources":["../src/event-pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG5C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,cAAc,CAC7B,OAAsC,EACtC,EAAU;IAEV,MAAM,gBAAgB,GAAG,IAAI,YAAY,CAAkB,OAAO,CAAC,IAAI,CAAC,CAAC;IACzE,MAAM,gBAAgB,GAAG,QAAQ,CAAC,CAAC,KAAa,EAAE,EAAE;QACnD,gBAAgB,CAAC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"event-pipeline.js","sourceRoot":"","sources":["../src/event-pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG5C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,cAAc,CAC7B,OAAsC,EACtC,EAAU;IAEV,MAAM,gBAAgB,GAAG,IAAI,YAAY,CAAkB,OAAO,CAAC,IAAI,CAAC,CAAC;IACzE,MA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AAQ,GAAG,IAAI,CAAC,GAAI,GAAuB,CAAC,CAAC;QACnD,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;YACnC,MAAM,QAAQ,CAAC,KAAK,CAAY,CAAC;QAClC,CAAC;IACF,CAAC,CAAC,EAAE,CAAC;AACN,CAAC"}
|
|
@@ -1,7 +1,29 @@
|
|
|
1
1
|
import { TEventData } from './event-data.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* Utility type that extracts the payload type from a {@link TEventData} object.
|
|
4
|
+
*
|
|
5
|
+
* Because every event shape has exactly one top-level key (the event name) whose
|
|
6
|
+
* value is the payload, indexing by `keyof TEvent` resolves directly to the payload
|
|
7
|
+
* type. Use this type to obtain the payload type without manually referencing the
|
|
8
|
+
* event-name key.
|
|
9
|
+
*
|
|
10
|
+
* @template TEvent - A {@link TEventData} object with exactly one top-level key.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import type { TEventData, TExtractEventPayload } from '@pawells/rxjs-events';
|
|
15
|
+
*
|
|
16
|
+
* interface UserCreatedEvent extends TEventData {
|
|
17
|
+
* UserCreated: { userId: string; username: string };
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* // Resolves to: { userId: string; username: string }
|
|
21
|
+
* type UserCreatedPayload = TExtractEventPayload<UserCreatedEvent>;
|
|
22
|
+
*
|
|
23
|
+
* const handler = (payload: UserCreatedPayload): void => {
|
|
24
|
+
* console.log('New user:', payload.userId);
|
|
25
|
+
* };
|
|
26
|
+
* ```
|
|
5
27
|
*/
|
|
6
28
|
export type TExtractEventPayload<TEvent extends TEventData> = TEvent[keyof TEvent];
|
|
7
29
|
//# sourceMappingURL=extract-event-payload.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract-event-payload.d.ts","sourceRoot":"","sources":["../src/extract-event-payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C
|
|
1
|
+
{"version":3,"file":"extract-event-payload.d.ts","sourceRoot":"","sources":["../src/extract-event-payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,MAAM,oBAAoB,CAAC,MAAM,SAAS,UAAU,IAAI,MAAM,CAAC,MAAM,MAAM,CAAC,CAAC"}
|
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Filter criteria
|
|
3
|
-
*
|
|
2
|
+
* Filter criteria for matching against event payloads.
|
|
3
|
+
*
|
|
4
|
+
* An `IFilterCriteria` object is a plain key-value map where each entry
|
|
5
|
+
* specifies a property name and the expected value. {@link EventFilter} uses
|
|
6
|
+
* strict equality (`===`) to test each criterion against the corresponding
|
|
7
|
+
* property on the event payload. An event passes the filter only when every
|
|
8
|
+
* criterion matches.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import type { IFilterCriteria } from '@pawells/rxjs-events';
|
|
13
|
+
* import { EventFilter } from '@pawells/rxjs-events';
|
|
14
|
+
*
|
|
15
|
+
* const criteria: IFilterCriteria = {
|
|
16
|
+
* userId: '42',
|
|
17
|
+
* role: 'admin',
|
|
18
|
+
* };
|
|
19
|
+
*
|
|
20
|
+
* const event = { UserCreated: { userId: '42', role: 'admin', username: 'alice' } };
|
|
21
|
+
*
|
|
22
|
+
* if (EventFilter(event, criteria)) {
|
|
23
|
+
* // All criteria matched — safe to process the event
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
4
26
|
*/
|
|
5
27
|
export interface IFilterCriteria {
|
|
6
28
|
[key: string]: unknown;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter-criteria.d.ts","sourceRoot":"","sources":["../src/filter-criteria.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"filter-criteria.d.ts","sourceRoot":"","sources":["../src/filter-criteria.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,WAAW,eAAe;IAC/B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACvB"}
|
package/build/handler.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Subscription } from 'rxjs';
|
|
2
2
|
import { TEventData } from './event-data.js';
|
|
3
3
|
import { TEventFunction } from './event-function.js';
|
|
4
|
+
import type { SubscriptionHandle } from './types.js';
|
|
4
5
|
/**
|
|
5
6
|
* Event handler class that provides reactive event management with RxJS integration.
|
|
6
7
|
* Supports subscription management, event triggering, and async iteration patterns.
|
|
@@ -8,6 +9,10 @@ import { TEventFunction } from './event-function.js';
|
|
|
8
9
|
* @template TObject - The type of data objects that can be triggered as events
|
|
9
10
|
* @template TEvent - The event data type extending TEventData that will be received by subscribers
|
|
10
11
|
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* **Error Handling:** Subscribe-based handlers log errors to console.error and stop receiving events.
|
|
14
|
+
* For in-band error propagation, use GetAsyncIterableIterator() instead, which throws on errors.
|
|
15
|
+
*
|
|
11
16
|
* @example
|
|
12
17
|
* ```typescript
|
|
13
18
|
* interface MessageData {
|
|
@@ -33,7 +38,7 @@ import { TEventFunction } from './event-function.js';
|
|
|
33
38
|
* // Unsubscribe
|
|
34
39
|
* handler.Unsubscribe(subscription);
|
|
35
40
|
*
|
|
36
|
-
* // Async iteration
|
|
41
|
+
* // Async iteration (propagates errors)
|
|
37
42
|
* for await (const event of handler.GetAsyncIterableIterator()) {
|
|
38
43
|
* console.log('Async event:', event.MessageReceived.text);
|
|
39
44
|
* break; // Important: break to avoid infinite loop
|
|
@@ -49,8 +54,8 @@ export declare class EventHandler<TObject extends object = object, TEvent extend
|
|
|
49
54
|
/**
|
|
50
55
|
* Creates a new EventHandler instance.
|
|
51
56
|
*
|
|
52
|
-
* @param name - The name of the event type to handle. Cannot be empty.
|
|
53
|
-
* @throws {Error} 'Event Name is Empty' - When the provided name is an empty string
|
|
57
|
+
* @param name - The name of the event type to handle. Cannot be empty or whitespace-only.
|
|
58
|
+
* @throws {Error} 'Event Name is Empty' - When the provided name is an empty string or contains only whitespace
|
|
54
59
|
*
|
|
55
60
|
* @example
|
|
56
61
|
* ```typescript
|
|
@@ -153,7 +158,7 @@ export declare class EventHandler<TObject extends object = object, TEvent extend
|
|
|
153
158
|
* Uses optimized O(1) ID allocation for efficient subscription management.
|
|
154
159
|
*
|
|
155
160
|
* @param onEvent - Function to call when events are triggered
|
|
156
|
-
* @returns
|
|
161
|
+
* @returns SubscriptionHandle representing the unique subscription identifier
|
|
157
162
|
*
|
|
158
163
|
* @remarks
|
|
159
164
|
* **Error handling:** if the internal RxJS Subject ever errors (which only happens if
|
|
@@ -185,13 +190,13 @@ export declare class EventHandler<TObject extends object = object, TEvent extend
|
|
|
185
190
|
* handler.Unsubscribe(asyncSubId);
|
|
186
191
|
* ```
|
|
187
192
|
*/
|
|
188
|
-
Subscribe(onEvent: TEventFunction<TEvent>):
|
|
193
|
+
Subscribe(onEvent: TEventFunction<TEvent>): SubscriptionHandle;
|
|
189
194
|
/**
|
|
190
|
-
* Unsubscribes from events using the subscription
|
|
191
|
-
* Safely handles non-existent subscription
|
|
195
|
+
* Unsubscribes from events using the subscription handle.
|
|
196
|
+
* Safely handles non-existent subscription handles without throwing errors.
|
|
192
197
|
* Freed IDs are made available for reuse to optimize memory usage.
|
|
193
198
|
*
|
|
194
|
-
* @param subscription - The unique subscription
|
|
199
|
+
* @param subscription - The unique subscription handle returned from Subscribe()
|
|
195
200
|
*
|
|
196
201
|
* @example
|
|
197
202
|
* ```typescript
|
|
@@ -204,11 +209,11 @@ export declare class EventHandler<TObject extends object = object, TEvent extend
|
|
|
204
209
|
* // Later, unsubscribe
|
|
205
210
|
* handler.Unsubscribe(subId);
|
|
206
211
|
*
|
|
207
|
-
* // Safe to call with non-existent
|
|
208
|
-
* handler.Unsubscribe(999); // No error thrown
|
|
212
|
+
* // Safe to call with non-existent handles
|
|
213
|
+
* handler.Unsubscribe(999 as SubscriptionHandle); // No error thrown
|
|
209
214
|
* ```
|
|
210
215
|
*/
|
|
211
|
-
Unsubscribe(subscription:
|
|
216
|
+
Unsubscribe(subscription: SubscriptionHandle): void;
|
|
212
217
|
/**
|
|
213
218
|
* Destroys the event handler and cleans up all resources.
|
|
214
219
|
* Completes the internal subject and unsubscribes all active subscriptions.
|
|
@@ -236,10 +241,10 @@ export declare class EventHandler<TObject extends object = object, TEvent extend
|
|
|
236
241
|
*/
|
|
237
242
|
GetSubscriptionCount(): number;
|
|
238
243
|
/**
|
|
239
|
-
* Gets all subscription
|
|
240
|
-
* The returned array is a snapshot of active
|
|
244
|
+
* Gets all subscription handles that are currently active.
|
|
245
|
+
* The returned array is a snapshot of active handles at the time of the call.
|
|
241
246
|
*
|
|
242
|
-
* @returns Array of active subscription
|
|
247
|
+
* @returns Array of active subscription handles
|
|
243
248
|
*
|
|
244
249
|
* @example
|
|
245
250
|
* ```typescript
|
|
@@ -247,9 +252,9 @@ export declare class EventHandler<TObject extends object = object, TEvent extend
|
|
|
247
252
|
* const id1 = handler.Subscribe((event) => { });
|
|
248
253
|
* const id2 = handler.Subscribe((event) => { });
|
|
249
254
|
* const ids = handler.GetActiveSubscriptionIds();
|
|
250
|
-
* console.log(ids); // [0, 1] or similar
|
|
255
|
+
* console.log(ids); // [0 as SubscriptionHandle, 1 as SubscriptionHandle] or similar
|
|
251
256
|
* ```
|
|
252
257
|
*/
|
|
253
|
-
GetActiveSubscriptionIds():
|
|
258
|
+
GetActiveSubscriptionIds(): SubscriptionHandle[];
|
|
254
259
|
}
|
|
255
260
|
//# sourceMappingURL=handler.d.ts.map
|
package/build/handler.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["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IAI9D;;;;;;;;;;;;;;;;;OAiBG;IACI,OAAO,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI;IAKnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoCG;IACI,SAAS,CAAC,OAAO,EAAE,cAAc,CAAC,MAAM,CAAC,GAAG,kBAAkB;IA6BrE;;;;;;;;;;;;;;;;;;;;;OAqBG;IACI,WAAW,CAAC,YAAY,EAAE,kBAAkB,GAAG,IAAI;IAW1D;;;;;;;;;;OAUG;IACI,OAAO,IAAI,IAAI;IAatB;;;;;;;;;;;;OAYG;IACI,oBAAoB,IAAI,MAAM;IAIrC;;;;;;;;;;;;;;OAcG;IACI,wBAAwB,IAAI,kBAAkB,EAAE;CAGvD"}
|
package/build/handler.js
CHANGED
|
@@ -6,6 +6,10 @@ import { Subject } from 'rxjs';
|
|
|
6
6
|
* @template TObject - The type of data objects that can be triggered as events
|
|
7
7
|
* @template TEvent - The event data type extending TEventData that will be received by subscribers
|
|
8
8
|
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* **Error Handling:** Subscribe-based handlers log errors to console.error and stop receiving events.
|
|
11
|
+
* For in-band error propagation, use GetAsyncIterableIterator() instead, which throws on errors.
|
|
12
|
+
*
|
|
9
13
|
* @example
|
|
10
14
|
* ```typescript
|
|
11
15
|
* interface MessageData {
|
|
@@ -31,7 +35,7 @@ import { Subject } from 'rxjs';
|
|
|
31
35
|
* // Unsubscribe
|
|
32
36
|
* handler.Unsubscribe(subscription);
|
|
33
37
|
*
|
|
34
|
-
* // Async iteration
|
|
38
|
+
* // Async iteration (propagates errors)
|
|
35
39
|
* for await (const event of handler.GetAsyncIterableIterator()) {
|
|
36
40
|
* console.log('Async event:', event.MessageReceived.text);
|
|
37
41
|
* break; // Important: break to avoid infinite loop
|
|
@@ -47,8 +51,8 @@ export class EventHandler {
|
|
|
47
51
|
/**
|
|
48
52
|
* Creates a new EventHandler instance.
|
|
49
53
|
*
|
|
50
|
-
* @param name - The name of the event type to handle. Cannot be empty.
|
|
51
|
-
* @throws {Error} 'Event Name is Empty' - When the provided name is an empty string
|
|
54
|
+
* @param name - The name of the event type to handle. Cannot be empty or whitespace-only.
|
|
55
|
+
* @throws {Error} 'Event Name is Empty' - When the provided name is an empty string or contains only whitespace
|
|
52
56
|
*
|
|
53
57
|
* @example
|
|
54
58
|
* ```typescript
|
|
@@ -58,7 +62,7 @@ export class EventHandler {
|
|
|
58
62
|
*/
|
|
59
63
|
constructor(name) {
|
|
60
64
|
this.Name = name;
|
|
61
|
-
if (this.Name.length === 0)
|
|
65
|
+
if (this.Name.length === 0 || !this.Name.trim())
|
|
62
66
|
throw new Error('Event Name is Empty');
|
|
63
67
|
}
|
|
64
68
|
/** Internal map storing active subscriptions by their unique IDs */
|
|
@@ -227,7 +231,7 @@ export class EventHandler {
|
|
|
227
231
|
* Uses optimized O(1) ID allocation for efficient subscription management.
|
|
228
232
|
*
|
|
229
233
|
* @param onEvent - Function to call when events are triggered
|
|
230
|
-
* @returns
|
|
234
|
+
* @returns SubscriptionHandle representing the unique subscription identifier
|
|
231
235
|
*
|
|
232
236
|
* @remarks
|
|
233
237
|
* **Error handling:** if the internal RxJS Subject ever errors (which only happens if
|
|
@@ -286,11 +290,11 @@ export class EventHandler {
|
|
|
286
290
|
return id;
|
|
287
291
|
}
|
|
288
292
|
/**
|
|
289
|
-
* Unsubscribes from events using the subscription
|
|
290
|
-
* Safely handles non-existent subscription
|
|
293
|
+
* Unsubscribes from events using the subscription handle.
|
|
294
|
+
* Safely handles non-existent subscription handles without throwing errors.
|
|
291
295
|
* Freed IDs are made available for reuse to optimize memory usage.
|
|
292
296
|
*
|
|
293
|
-
* @param subscription - The unique subscription
|
|
297
|
+
* @param subscription - The unique subscription handle returned from Subscribe()
|
|
294
298
|
*
|
|
295
299
|
* @example
|
|
296
300
|
* ```typescript
|
|
@@ -303,8 +307,8 @@ export class EventHandler {
|
|
|
303
307
|
* // Later, unsubscribe
|
|
304
308
|
* handler.Unsubscribe(subId);
|
|
305
309
|
*
|
|
306
|
-
* // Safe to call with non-existent
|
|
307
|
-
* handler.Unsubscribe(999); // No error thrown
|
|
310
|
+
* // Safe to call with non-existent handles
|
|
311
|
+
* handler.Unsubscribe(999 as SubscriptionHandle); // No error thrown
|
|
308
312
|
* ```
|
|
309
313
|
*/
|
|
310
314
|
Unsubscribe(subscription) {
|
|
@@ -354,10 +358,10 @@ export class EventHandler {
|
|
|
354
358
|
return this._subscriptions.size;
|
|
355
359
|
}
|
|
356
360
|
/**
|
|
357
|
-
* Gets all subscription
|
|
358
|
-
* The returned array is a snapshot of active
|
|
361
|
+
* Gets all subscription handles that are currently active.
|
|
362
|
+
* The returned array is a snapshot of active handles at the time of the call.
|
|
359
363
|
*
|
|
360
|
-
* @returns Array of active subscription
|
|
364
|
+
* @returns Array of active subscription handles
|
|
361
365
|
*
|
|
362
366
|
* @example
|
|
363
367
|
* ```typescript
|
|
@@ -365,11 +369,11 @@ export class EventHandler {
|
|
|
365
369
|
* const id1 = handler.Subscribe((event) => { });
|
|
366
370
|
* const id2 = handler.Subscribe((event) => { });
|
|
367
371
|
* const ids = handler.GetActiveSubscriptionIds();
|
|
368
|
-
* console.log(ids); // [0, 1] or similar
|
|
372
|
+
* console.log(ids); // [0 as SubscriptionHandle, 1 as SubscriptionHandle] or similar
|
|
369
373
|
* ```
|
|
370
374
|
*/
|
|
371
375
|
GetActiveSubscriptionIds() {
|
|
372
|
-
return Array.from(this._subscriptions.keys());
|
|
376
|
+
return Array.from(this._subscriptions.keys()).map((id) => id);
|
|
373
377
|
}
|
|
374
378
|
}
|
|
375
379
|
//# sourceMappingURL=handler.js.map
|
package/build/handler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAgB,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../src/hand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
1
|
export type * from './event-data.js';
|
|
2
2
|
export type * from './event-function.js';
|
|
3
|
-
export type { TEventHandler } from './types.js';
|
|
3
|
+
export type { TEventHandler, SubscriptionHandle } from './types.js';
|
|
4
4
|
export * from './filter-criteria.js';
|
|
5
5
|
export * from './extract-event-payload.js';
|
|
6
6
|
export * from './event-filter.js';
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,iBAAiB,CAAC;AACrC,mBAAmB,qBAAqB,CAAC;AACzC,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,iBAAiB,CAAC;AACrC,mBAAmB,qBAAqB,CAAC;AACzC,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACpE,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mBAAmB,CAAC;AAElC,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC"}
|
package/build/nestjs-pubsub.d.ts
CHANGED
|
@@ -1,10 +1,38 @@
|
|
|
1
|
+
import type { SubscriptionHandle } from './types.js';
|
|
1
2
|
/**
|
|
2
3
|
* PubSub engine interface compatible with NestJS GraphQL subscriptions.
|
|
3
|
-
*
|
|
4
|
+
*
|
|
5
|
+
* Implementors of this interface can be registered as the `pubSub` provider in a
|
|
6
|
+
* NestJS GraphQL module and used directly with `@Subscription()` decorators.
|
|
7
|
+
* {@link EventHandlerPubSub} is the concrete implementation provided by this library.
|
|
4
8
|
*
|
|
5
9
|
* @remarks
|
|
6
|
-
* This interface
|
|
7
|
-
*
|
|
10
|
+
* This interface mirrors the `PubSubEngine` contract from `graphql-subscriptions`
|
|
11
|
+
* without introducing a dependency on that package. If you already use
|
|
12
|
+
* `graphql-subscriptions`, `EventHandlerPubSub` is a drop-in replacement.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { EventHandlerPubSub } from '@pawells/rxjs-events';
|
|
17
|
+
* import type { IPubSubEngine } from '@pawells/rxjs-events';
|
|
18
|
+
*
|
|
19
|
+
* // Use the concrete implementation
|
|
20
|
+
* const pubSub: IPubSubEngine = new EventHandlerPubSub();
|
|
21
|
+
*
|
|
22
|
+
* // Publish a message
|
|
23
|
+
* await pubSub.publish('USER_CREATED', { userId: '42', username: 'alice' });
|
|
24
|
+
*
|
|
25
|
+
* // Subscribe to a channel
|
|
26
|
+
* const handle = await pubSub.subscribe('USER_CREATED', (payload) => {
|
|
27
|
+
* console.log('Received:', payload);
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* // Iterate over published values (used by GraphQL resolvers)
|
|
31
|
+
* const iterator = pubSub.asyncIterator<{ userId: string }>('USER_CREATED');
|
|
32
|
+
*
|
|
33
|
+
* // Clean up
|
|
34
|
+
* pubSub.unsubscribe(handle);
|
|
35
|
+
* ```
|
|
8
36
|
*/
|
|
9
37
|
export interface IPubSubEngine {
|
|
10
38
|
/**
|
|
@@ -18,14 +46,14 @@ export interface IPubSubEngine {
|
|
|
18
46
|
* @param triggerName - The name of the trigger to subscribe to
|
|
19
47
|
* @param onMessage - Callback function when a message is received
|
|
20
48
|
* @param options - Optional subscription options
|
|
21
|
-
* @returns A subscription
|
|
49
|
+
* @returns A subscription handle that can be used to unsubscribe
|
|
22
50
|
*/
|
|
23
|
-
subscribe(triggerName: string, onMessage: (payload: any) => void, options?: Record<string, unknown>): Promise<
|
|
51
|
+
subscribe(triggerName: string, onMessage: (payload: any) => void, options?: Record<string, unknown>): Promise<SubscriptionHandle>;
|
|
24
52
|
/**
|
|
25
|
-
* Unsubscribes from a trigger channel using the subscription
|
|
26
|
-
* @param subId - The subscription
|
|
53
|
+
* Unsubscribes from a trigger channel using the subscription handle.
|
|
54
|
+
* @param subId - The subscription handle returned from subscribe()
|
|
27
55
|
*/
|
|
28
|
-
unsubscribe(subId:
|
|
56
|
+
unsubscribe(subId: SubscriptionHandle): void;
|
|
29
57
|
/**
|
|
30
58
|
* Creates an async iterator for one or more trigger channels.
|
|
31
59
|
* Used by GraphQL subscriptions to iterate over published values.
|
|
@@ -105,15 +133,15 @@ export declare class EventHandlerPubSub implements IPubSubEngine {
|
|
|
105
133
|
* @param triggerName - The trigger channel name
|
|
106
134
|
* @param onMessage - Callback function that receives the published payload
|
|
107
135
|
* @param _options - Optional subscription options (not used in current implementation)
|
|
108
|
-
* @returns Unique subscription
|
|
136
|
+
* @returns Unique subscription handle for later unsubscription
|
|
109
137
|
*/
|
|
110
|
-
subscribe(triggerName: string, onMessage: (payload: any) => void, _options?: Record<string, unknown>): Promise<
|
|
138
|
+
subscribe(triggerName: string, onMessage: (payload: any) => void, _options?: Record<string, unknown>): Promise<SubscriptionHandle>;
|
|
111
139
|
/**
|
|
112
140
|
* Unsubscribes from a trigger channel.
|
|
113
141
|
*
|
|
114
|
-
* @param subId - The subscription
|
|
142
|
+
* @param subId - The subscription handle returned from subscribe()
|
|
115
143
|
*/
|
|
116
|
-
unsubscribe(subId:
|
|
144
|
+
unsubscribe(subId: SubscriptionHandle): void;
|
|
117
145
|
/**
|
|
118
146
|
* Creates an async iterator for one or more trigger channels.
|
|
119
147
|
* Useful for GraphQL subscription resolvers.
|
|
@@ -138,7 +166,7 @@ export declare class EventHandlerPubSub implements IPubSubEngine {
|
|
|
138
166
|
*
|
|
139
167
|
* @template T - The type of values yielded
|
|
140
168
|
* @param triggers - Array of trigger names
|
|
141
|
-
* @returns Merged async iterator
|
|
169
|
+
* @returns Merged async iterator that yields events from all triggers concurrently
|
|
142
170
|
*/
|
|
143
171
|
private _mergeAsyncIterators;
|
|
144
172
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nestjs-pubsub.d.ts","sourceRoot":"","sources":["../src/nestjs-pubsub.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"nestjs-pubsub.d.ts","sourceRoot":"","sources":["../src/nestjs-pubsub.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAGrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,WAAW,aAAa;IAC7B;;;;OAIG;IACH,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1D;;;;;;OAMG;IACH,SAAS,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,IAAI,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAElI;;;OAGG;IACH,WAAW,CAAC,KAAK,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAE7C;;;;;OAKG;IACH,aAAa,CAAC,CAAC,GAAG,GAAG,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,qBAAqB,CAAC,CAAC,CAAC,CAAC;CAC9E;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,qBAAa,kBAAmB,YAAW,aAAa;IACvD;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAkD;IAE5E;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA4D;IAE3F;;OAEG;IACH,OAAO,CAAC,mBAAmB,CAAK;IAEhC;;;;;OAKG;IACH,OAAO,CAAC,mBAAmB;IAS3B;;;;;OAKG;IACU,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAMtE;;;;;;;OAOG;IACU,SAAS,CACrB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,IAAI,EACjC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,OAAO,CAAC,kBAAkB,CAAC;IAY9B;;;;OAIG;IACI,WAAW,CAAC,KAAK,EAAE,kBAAkB,GAAG,IAAI;IASnD;;;;;;;;;;;;;;;;OAgBG;IACI,aAAa,CAAC,CAAC,GAAG,GAAG,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,qBAAqB,CAAC,CAAC,CAAC;IAoBpF;;;;;;;OAOG;IACH,OAAO,CAAC,oBAAoB;CA6C5B;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAC3B,eAAe,EAAE,MAAM,qBAAqB,CAAC,CAAC,CAAC,EAC/C,QAAQ,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,GAClD,qBAAqB,CAAC,CAAC,CAAC,CAa1B"}
|
package/build/nestjs-pubsub.js
CHANGED
|
@@ -81,7 +81,7 @@ export class EventHandlerPubSub {
|
|
|
81
81
|
* @param triggerName - The trigger channel name
|
|
82
82
|
* @param onMessage - Callback function that receives the published payload
|
|
83
83
|
* @param _options - Optional subscription options (not used in current implementation)
|
|
84
|
-
* @returns Unique subscription
|
|
84
|
+
* @returns Unique subscription handle for later unsubscription
|
|
85
85
|
*/
|
|
86
86
|
async subscribe(triggerName, onMessage, _options) {
|
|
87
87
|
const handler = this._getOrCreateHandler(triggerName);
|
|
@@ -95,7 +95,7 @@ export class EventHandlerPubSub {
|
|
|
95
95
|
/**
|
|
96
96
|
* Unsubscribes from a trigger channel.
|
|
97
97
|
*
|
|
98
|
-
* @param subId - The subscription
|
|
98
|
+
* @param subId - The subscription handle returned from subscribe()
|
|
99
99
|
*/
|
|
100
100
|
unsubscribe(subId) {
|
|
101
101
|
const subscription = this._subscriptions.get(subId);
|
|
@@ -144,25 +144,44 @@ export class EventHandlerPubSub {
|
|
|
144
144
|
*
|
|
145
145
|
* @template T - The type of values yielded
|
|
146
146
|
* @param triggers - Array of trigger names
|
|
147
|
-
* @returns Merged async iterator
|
|
147
|
+
* @returns Merged async iterator that yields events from all triggers concurrently
|
|
148
148
|
*/
|
|
149
149
|
_mergeAsyncIterators(triggers) {
|
|
150
150
|
const handlers = triggers.map((trigger) => this._getOrCreateHandler(trigger));
|
|
151
|
-
const self = this;
|
|
152
151
|
return (async function* () {
|
|
153
152
|
const iterators = handlers.map((h) => h.GetAsyncIterableIterator());
|
|
154
|
-
|
|
155
|
-
// Use Promise.race to get the first event from any handler
|
|
156
|
-
// This is a simplified implementation; production systems may want more sophisticated merging
|
|
153
|
+
let activeIterators = iterators.length;
|
|
157
154
|
try {
|
|
158
|
-
|
|
159
|
-
|
|
155
|
+
// Create promises for each iterator's next() call
|
|
156
|
+
const createNextPromises = () => {
|
|
157
|
+
return iterators.map((iter) => iter.next()
|
|
158
|
+
.then((result) => {
|
|
159
|
+
if (result.done) {
|
|
160
|
+
activeIterators--;
|
|
161
|
+
}
|
|
162
|
+
return result;
|
|
163
|
+
})
|
|
164
|
+
.catch((err) => {
|
|
165
|
+
activeIterators--;
|
|
166
|
+
throw err;
|
|
167
|
+
}));
|
|
168
|
+
};
|
|
169
|
+
let promises = createNextPromises();
|
|
170
|
+
while (activeIterators > 0) {
|
|
171
|
+
const result = await Promise.race(promises);
|
|
172
|
+
if (!result.done) {
|
|
173
|
+
yield result.value;
|
|
174
|
+
promises = createNextPromises();
|
|
175
|
+
}
|
|
160
176
|
}
|
|
161
177
|
}
|
|
162
178
|
finally {
|
|
163
|
-
// Clean up
|
|
164
|
-
|
|
165
|
-
|
|
179
|
+
// Clean up all iterators
|
|
180
|
+
for (const iterator of iterators) {
|
|
181
|
+
if (typeof iterator.return === 'function') {
|
|
182
|
+
await iterator.return?.();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
166
185
|
}
|
|
167
186
|
})();
|
|
168
187
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nestjs-pubsub.js","sourceRoot":"","sources":["../src/nestjs-pubsub.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"nestjs-pubsub.js","sourceRoot":"","sources":["../src/nestjs-pubsub.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAqE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,OAAO,kBAAkB;IAC9B;;;OAGG;IACc,SAAS,GAAwC,IAAI,GAAG,EAAE,CAAC;IAE5E;;;OAGG;IACc,cAAc,GAAkD,IAAI,GAAG,EAAE,CAAC;IAE3F;;OAEG;IACK,mBAAmB,GAAG,CAAC,CAAC;IAEhC;;;;;OAKG;IACK,mBAAmB,CAAC,WAAmB;QAC9C,IAAI,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QAC9C,IAAI,CAAC,OAAO,EAAE,CAAC;YACd,OAAO,GAAG,IAAI,YAAY,CAAC,WAAW,CAAC,CAAC;YACxC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QAC1C,CAAC;QACD,OAAO,OAAO,CAAC;IAChB,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,OAAO,CAAC,WAAmB,EAAE,OAAY;QACrD,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;QACxB,MAAM,OAAO,GAAG,IAAI,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC;QACtD,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1B,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,SAAS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C,IAAI,EAAE,CAAC;wBAClB,MAAM,MAAM,CAAC,KAAU,CAAC;wBACxB,QAAQ,GAAG,kBAAkB,EAAE,CAAC;oBACjC,CAAC;gBACF,CAAC;YACF,CAAC;oBAAS,CAAC;gBACV,yBAAyB;gBACzB,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;oBAClC,IAAI,OAAO,QAAQ,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;wBAC3C,MAAM,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC;oBAC3B,CAAC;gBACF,CAAC;YACF,CAAC;QACF,CAAC,CAAC,EAAE,CAAC;IACN,CAAC;CACD;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,UAAU,CACzB,eAA+C,EAC/C,QAAoD;IAEpD,OAAO,CAAC,KAAK,SAAS,CAAC;QACtB,MAAM,aAAa,GAAG,eAAe,EAAE,CAAC;QAExC,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,aAAa,EAAE,CAAC;YACzC,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;YAC/B,MAAM,MAAM,GAAG,MAAM,YAAY,OAAO,CAAC,CAAC,CAAC,MAAM,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;YAEjE,IAAI,MAAM,EAAE,CAAC;gBACZ,MAAM,KAAK,CAAC;YACb,CAAC;QACF,CAAC;IACF,CAAC,CAAC,EAAE,CAAC;AACN,CAAC"}
|
package/build/types.d.ts
CHANGED
|
@@ -1,20 +1,46 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* @
|
|
2
|
+
* Opaque branded type representing a subscription handle.
|
|
3
|
+
*
|
|
4
|
+
* A SubscriptionHandle is a unique identifier returned by {@link subscribe} methods
|
|
5
|
+
* and used with {@link unsubscribe} methods to remove event subscriptions. The numeric
|
|
6
|
+
* value is intentionally inaccessible to consumers—this is an opaque type, so you cannot
|
|
7
|
+
* extract or rely on the underlying ID.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const handle: SubscriptionHandle = eventHandler.subscribe((payload) => {
|
|
12
|
+
* console.log('Event received:', payload);
|
|
13
|
+
* });
|
|
14
|
+
*
|
|
15
|
+
* // Later, unsubscribe using the handle
|
|
16
|
+
* eventHandler.unsubscribe(handle);
|
|
17
|
+
* ```
|
|
6
18
|
*/
|
|
7
|
-
export type
|
|
19
|
+
export type SubscriptionHandle = number & {
|
|
20
|
+
readonly __brand: 'SubscriptionHandle';
|
|
21
|
+
};
|
|
8
22
|
/**
|
|
9
|
-
* Event
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
23
|
+
* Event handler callback function type.
|
|
24
|
+
*
|
|
25
|
+
* Use this type to annotate variables or parameters that hold an event-handling
|
|
26
|
+
* callback. The callback receives the typed payload and may return either `void`
|
|
27
|
+
* or a `Promise<void>` for async handlers.
|
|
28
|
+
*
|
|
29
|
+
* @template TPayload - The type of the event payload passed to the callback.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* import type { TEventHandler } from '@pawells/rxjs-events';
|
|
34
|
+
*
|
|
35
|
+
* const handleUserCreated: TEventHandler<{ userId: string; username: string }> = (payload) => {
|
|
36
|
+
* console.log('User created:', payload.userId);
|
|
37
|
+
* };
|
|
38
|
+
*
|
|
39
|
+
* // Async handler
|
|
40
|
+
* const handleAsync: TEventHandler<{ id: string }> = async (payload) => {
|
|
41
|
+
* await saveToDatabase(payload.id);
|
|
42
|
+
* };
|
|
43
|
+
* ```
|
|
13
44
|
*/
|
|
14
|
-
export
|
|
15
|
-
/** Whether to call the handler only once (not yet implemented) */
|
|
16
|
-
once?: boolean;
|
|
17
|
-
/** Priority for handler execution, higher = earlier (not yet implemented) */
|
|
18
|
-
priority?: number;
|
|
19
|
-
}
|
|
45
|
+
export type TEventHandler<TPayload = unknown> = (payload: TPayload) => void | Promise<void>;
|
|
20
46
|
//# sourceMappingURL=types.d.ts.map
|
package/build/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,oBAAoB,CAAA;CAAE,CAAC;AAErF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,MAAM,aAAa,CAAC,QAAQ,GAAG,OAAO,IAAI,CAAC,OAAO,EAAE,QAAQ,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pawells/rxjs-events",
|
|
3
3
|
"displayName": "RxJS Events",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0",
|
|
5
5
|
"description": "RxJS-based event handling library with reactive observables and async event streams.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./build/index.js",
|
|
@@ -23,28 +23,29 @@
|
|
|
23
23
|
"test": "vitest run",
|
|
24
24
|
"test:ui": "vitest --ui",
|
|
25
25
|
"test:coverage": "vitest --coverage",
|
|
26
|
+
"pipeline": "yarn typecheck && yarn lint && yarn test && yarn build",
|
|
26
27
|
"prepublishOnly": "npm run build",
|
|
27
28
|
"prepare": "husky"
|
|
28
29
|
},
|
|
29
30
|
"dependencies": {
|
|
30
|
-
"@pawells/typescript-common": "^
|
|
31
|
+
"@pawells/typescript-common": "^2.0.0",
|
|
31
32
|
"rxjs": "^7.8.2"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
35
|
"@eslint/js": "^10.0.1",
|
|
35
|
-
"@stylistic/eslint-plugin": "^5.
|
|
36
|
-
"@types/node": "^25.3.
|
|
36
|
+
"@stylistic/eslint-plugin": "^5.10.0",
|
|
37
|
+
"@types/node": "^25.3.3",
|
|
37
38
|
"@typescript-eslint/eslint-plugin": "^8.56.1",
|
|
38
39
|
"@typescript-eslint/parser": "^8.56.1",
|
|
39
40
|
"@vitest/coverage-v8": "^4.0.18",
|
|
40
41
|
"@vitest/ui": "^4.0.18",
|
|
41
|
-
"eslint": "^10.0.
|
|
42
|
+
"eslint": "^10.0.3",
|
|
42
43
|
"eslint-import-resolver-typescript": "^4.4.4",
|
|
43
44
|
"eslint-plugin-import": "^2.31.0",
|
|
44
45
|
"eslint-plugin-unused-imports": "^4.0.0",
|
|
45
|
-
"globals": "^17.
|
|
46
|
+
"globals": "^17.4.0",
|
|
46
47
|
"husky": "^9.1.7",
|
|
47
|
-
"typescript": "^
|
|
48
|
+
"typescript": "^6.0.2",
|
|
48
49
|
"vitest": "^4.0.18"
|
|
49
50
|
},
|
|
50
51
|
"keywords": [
|
|
@@ -67,7 +68,7 @@
|
|
|
67
68
|
},
|
|
68
69
|
"homepage": "https://github.com/PhillipAWells/rxjs-events#readme",
|
|
69
70
|
"engines": {
|
|
70
|
-
"node": ">=
|
|
71
|
+
"node": ">=22.0.0"
|
|
71
72
|
},
|
|
72
73
|
"packageManager": "yarn@4.12.0",
|
|
73
74
|
"files": [
|