@pawells/rxjs-events 1.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/LICENSE +21 -0
- package/README.md +210 -0
- package/build/async-generator-esn.d.ts +27 -0
- package/build/async-generator-esn.d.ts.map +1 -0
- package/build/async-generator-esn.js +2 -0
- package/build/async-generator-esn.js.map +1 -0
- package/build/async-observable.d.ts +72 -0
- package/build/async-observable.d.ts.map +1 -0
- package/build/async-observable.js +201 -0
- package/build/async-observable.js.map +1 -0
- package/build/event-data.d.ts +17 -0
- package/build/event-data.d.ts.map +1 -0
- package/build/event-data.js +2 -0
- package/build/event-data.js.map +1 -0
- package/build/event-filter.d.ts +44 -0
- package/build/event-filter.d.ts.map +1 -0
- package/build/event-filter.js +66 -0
- package/build/event-filter.js.map +1 -0
- package/build/event-function.d.ts +23 -0
- package/build/event-function.d.ts.map +1 -0
- package/build/event-function.js +2 -0
- package/build/event-function.js.map +1 -0
- package/build/extract-event-payload.d.ts +7 -0
- package/build/extract-event-payload.d.ts.map +1 -0
- package/build/extract-event-payload.js +2 -0
- package/build/extract-event-payload.js.map +1 -0
- package/build/filter-criteria.d.ts +8 -0
- package/build/filter-criteria.d.ts.map +1 -0
- package/build/filter-criteria.js +2 -0
- package/build/filter-criteria.js.map +1 -0
- package/build/handler.d.ts +225 -0
- package/build/handler.d.ts.map +1 -0
- package/build/handler.js +341 -0
- package/build/handler.js.map +1 -0
- package/build/index.d.ts +9 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +7 -0
- package/build/index.js.map +1 -0
- package/build/types.d.ts +20 -0
- package/build/types.d.ts.map +1 -0
- package/build/types.js +2 -0
- package/build/types.js.map +1 -0
- package/package.json +80 -0
package/build/handler.js
ADDED
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import { Subject } from 'rxjs';
|
|
2
|
+
/**
|
|
3
|
+
* Event handler class that provides reactive event management with RxJS integration.
|
|
4
|
+
* Supports subscription management, event triggering, and async iteration patterns.
|
|
5
|
+
*
|
|
6
|
+
* @template TObject - The type of data objects that can be triggered as events
|
|
7
|
+
* @template TEvent - The event data type extending TEventData that will be received by subscribers
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* interface MessageData {
|
|
12
|
+
* id: number;
|
|
13
|
+
* text: string;
|
|
14
|
+
* }
|
|
15
|
+
*
|
|
16
|
+
* interface MessageEvent extends TEventData {
|
|
17
|
+
* MessageReceived: MessageData;
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* // Create handler
|
|
21
|
+
* const handler = new EventHandler<MessageData, MessageEvent>('MessageReceived');
|
|
22
|
+
*
|
|
23
|
+
* // Subscribe to events
|
|
24
|
+
* const subscription = handler.Subscribe(async (event) => {
|
|
25
|
+
* console.log('Message:', event.MessageReceived.text);
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* // Trigger events
|
|
29
|
+
* handler.Trigger({ id: 1, text: 'Hello World' });
|
|
30
|
+
*
|
|
31
|
+
* // Unsubscribe
|
|
32
|
+
* handler.Unsubscribe(subscription);
|
|
33
|
+
*
|
|
34
|
+
* // Async iteration
|
|
35
|
+
* for await (const event of handler.GetAsyncIterableIterator()) {
|
|
36
|
+
* console.log('Async event:', event.MessageReceived.text);
|
|
37
|
+
* break; // Important: break to avoid infinite loop
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export class EventHandler {
|
|
42
|
+
/**
|
|
43
|
+
* The name of the event type this handler manages.
|
|
44
|
+
* Used as the key when wrapping triggered data into event objects.
|
|
45
|
+
*/
|
|
46
|
+
Name;
|
|
47
|
+
/**
|
|
48
|
+
* Creates a new EventHandler instance.
|
|
49
|
+
*
|
|
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
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const handler = new EventHandler('UserRegistered');
|
|
56
|
+
* console.log(handler.Name); // 'UserRegistered'
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
constructor(name) {
|
|
60
|
+
this.Name = name;
|
|
61
|
+
if (this.Name.length === 0)
|
|
62
|
+
throw new Error('Event Name is Empty');
|
|
63
|
+
}
|
|
64
|
+
/** Internal map storing active subscriptions by their unique IDs */
|
|
65
|
+
_subscriptions = new Map();
|
|
66
|
+
/**
|
|
67
|
+
* Set of available subscription IDs for efficient reuse.
|
|
68
|
+
* IDs are reused in insertion order (i.e. the order they were freed via Unsubscribe).
|
|
69
|
+
* This is deterministic but not necessarily ascending; callers must not depend on a
|
|
70
|
+
* specific reuse order.
|
|
71
|
+
*/
|
|
72
|
+
_AvailableIds = new Set();
|
|
73
|
+
/** Next sequential ID to assign when no IDs are available for reuse */
|
|
74
|
+
_NextId = 0;
|
|
75
|
+
/** Internal RxJS Subject for event broadcasting */
|
|
76
|
+
_Subject = new Subject();
|
|
77
|
+
/**
|
|
78
|
+
* Returns an async iterable iterator for receiving events.
|
|
79
|
+
* Allows using for-await-of loops to process events as they arrive.
|
|
80
|
+
*
|
|
81
|
+
* @returns AsyncIterableIterator that yields events as they are triggered
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* const handler = new EventHandler<MessageData, MessageEvent>('Message');
|
|
86
|
+
*
|
|
87
|
+
* // Process events in a background task
|
|
88
|
+
* const processEvents = async () => {
|
|
89
|
+
* for await (const event of handler.GetAsyncIterableIterator()) {
|
|
90
|
+
* console.log('Received:', event.Message.text);
|
|
91
|
+
* // Important: include break condition to avoid infinite loop
|
|
92
|
+
* if (shouldStop) break;
|
|
93
|
+
* }
|
|
94
|
+
* };
|
|
95
|
+
*
|
|
96
|
+
* processEvents();
|
|
97
|
+
* handler.Trigger({ text: 'Hello' }); // Will be processed by the loop
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
async *GetAsyncIterableIterator() {
|
|
101
|
+
const queue = [];
|
|
102
|
+
let resolve;
|
|
103
|
+
let reject;
|
|
104
|
+
let promise;
|
|
105
|
+
let error;
|
|
106
|
+
let hasError = false;
|
|
107
|
+
const subscription = this._Subject.subscribe({
|
|
108
|
+
next: (value) => {
|
|
109
|
+
queue.push(value);
|
|
110
|
+
if (resolve) {
|
|
111
|
+
resolve();
|
|
112
|
+
resolve = undefined;
|
|
113
|
+
reject = undefined;
|
|
114
|
+
promise = undefined;
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
error: (err) => {
|
|
118
|
+
hasError = true;
|
|
119
|
+
error = err;
|
|
120
|
+
if (reject) {
|
|
121
|
+
reject(err);
|
|
122
|
+
resolve = undefined;
|
|
123
|
+
reject = undefined;
|
|
124
|
+
promise = undefined;
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
complete: () => {
|
|
128
|
+
if (resolve) {
|
|
129
|
+
resolve();
|
|
130
|
+
resolve = undefined;
|
|
131
|
+
reject = undefined;
|
|
132
|
+
promise = undefined;
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
try {
|
|
137
|
+
while (!subscription.closed) {
|
|
138
|
+
if (hasError) {
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
141
|
+
if (queue.length === 0) {
|
|
142
|
+
promise = new Promise((res, rej) => {
|
|
143
|
+
resolve = res;
|
|
144
|
+
reject = rej;
|
|
145
|
+
});
|
|
146
|
+
await promise;
|
|
147
|
+
}
|
|
148
|
+
if (hasError) {
|
|
149
|
+
throw error;
|
|
150
|
+
}
|
|
151
|
+
if (queue.length > 0) {
|
|
152
|
+
const value = queue.shift();
|
|
153
|
+
if (value !== undefined) {
|
|
154
|
+
yield value;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
finally {
|
|
163
|
+
subscription.unsubscribe();
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Returns an async iterator for receiving events.
|
|
168
|
+
* Provides lower-level access to the event stream compared to GetAsyncIterableIterator.
|
|
169
|
+
*
|
|
170
|
+
* @returns AsyncIterator that can be manually advanced with next() calls
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* const handler = new EventHandler<MessageData, MessageEvent>('Message');
|
|
175
|
+
* const iterator = handler.GetAsyncIterator();
|
|
176
|
+
*
|
|
177
|
+
* // Manually advance the iterator
|
|
178
|
+
* const result1 = await iterator.next();
|
|
179
|
+
* console.log('First event:', result1.value?.Message.text);
|
|
180
|
+
*
|
|
181
|
+
* const result2 = await iterator.next();
|
|
182
|
+
* console.log('Second event:', result2.value?.Message.text);
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
GetAsyncIterator() {
|
|
186
|
+
return this.GetAsyncIterableIterator();
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Makes EventHandler directly usable in for-await-of loops.
|
|
190
|
+
* Delegates to GetAsyncIterableIterator().
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```typescript
|
|
194
|
+
* for await (const event of handler) {
|
|
195
|
+
* console.log(event);
|
|
196
|
+
* if (shouldStop) break;
|
|
197
|
+
* }
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
[Symbol.asyncIterator]() {
|
|
201
|
+
return this.GetAsyncIterableIterator();
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Triggers an event with the provided data.
|
|
205
|
+
* Wraps the data in an event object using the handler's name as the key.
|
|
206
|
+
*
|
|
207
|
+
* @param data - The data to wrap and broadcast as an event
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```typescript
|
|
211
|
+
* interface UserData {
|
|
212
|
+
* id: string;
|
|
213
|
+
* name: string;
|
|
214
|
+
* }
|
|
215
|
+
*
|
|
216
|
+
* const handler = new EventHandler<UserData, any>('UserCreated');
|
|
217
|
+
* handler.Trigger({ id: '123', name: 'John' });
|
|
218
|
+
* // Subscribers will receive: { UserCreated: { id: '123', name: 'John' } }
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
Trigger(data) {
|
|
222
|
+
const event = { [this.Name]: data };
|
|
223
|
+
this._Subject.next(event);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Subscribes to events with the provided handler function.
|
|
227
|
+
* Uses optimized O(1) ID allocation for efficient subscription management.
|
|
228
|
+
*
|
|
229
|
+
* @param onEvent - Function to call when events are triggered
|
|
230
|
+
* @returns number representing the unique subscription ID
|
|
231
|
+
*
|
|
232
|
+
* @remarks
|
|
233
|
+
* **Error handling:** if the internal RxJS Subject ever errors (which only happens if
|
|
234
|
+
* external code accesses `_Subject` directly), the error is logged via `console.error`
|
|
235
|
+
* and the subscription silently stops receiving events. If you need in-band error
|
|
236
|
+
* delivery use `GetAsyncIterableIterator()` instead, which propagates Subject errors as
|
|
237
|
+
* iterator rejections.
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```typescript
|
|
241
|
+
* interface MessageEvent extends TEventData {
|
|
242
|
+
* MessageReceived: { text: string };
|
|
243
|
+
* }
|
|
244
|
+
*
|
|
245
|
+
* const handler = new EventHandler<any, MessageEvent>('MessageReceived');
|
|
246
|
+
*
|
|
247
|
+
* // Synchronous subscription
|
|
248
|
+
* const subId = handler.Subscribe((event) => {
|
|
249
|
+
* console.log('Message:', event.MessageReceived.text);
|
|
250
|
+
* });
|
|
251
|
+
*
|
|
252
|
+
* // Asynchronous subscription
|
|
253
|
+
* const asyncSubId = handler.Subscribe(async (event) => {
|
|
254
|
+
* await processMessage(event.MessageReceived);
|
|
255
|
+
* });
|
|
256
|
+
*
|
|
257
|
+
* // Later unsubscribe
|
|
258
|
+
* handler.Unsubscribe(subId);
|
|
259
|
+
* handler.Unsubscribe(asyncSubId);
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
Subscribe(onEvent) {
|
|
263
|
+
const sub = this._Subject.subscribe({
|
|
264
|
+
next: onEvent,
|
|
265
|
+
error: (err) => {
|
|
266
|
+
// Prevent an unhandled RxJS error from crashing the process.
|
|
267
|
+
// Note: after a Subject errors, no further events will be delivered to this subscriber.
|
|
268
|
+
// Use GetAsyncIterableIterator() to receive errors in-band.
|
|
269
|
+
console.error('EventHandler subscription error:', err);
|
|
270
|
+
},
|
|
271
|
+
});
|
|
272
|
+
// Optimized ID allocation: O(1) performance
|
|
273
|
+
let id;
|
|
274
|
+
if (this._AvailableIds.size > 0) {
|
|
275
|
+
// Reuse an available ID - O(1) operation
|
|
276
|
+
const iterator = this._AvailableIds.values();
|
|
277
|
+
id = iterator.next().value;
|
|
278
|
+
this._AvailableIds.delete(id);
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
// Use next sequential ID - O(1) operation
|
|
282
|
+
id = this._NextId;
|
|
283
|
+
this._NextId += 1;
|
|
284
|
+
}
|
|
285
|
+
this._subscriptions.set(id, sub);
|
|
286
|
+
return id;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Unsubscribes from events using the subscription ID.
|
|
290
|
+
* Safely handles non-existent subscription IDs without throwing errors.
|
|
291
|
+
* Freed IDs are made available for reuse to optimize memory usage.
|
|
292
|
+
*
|
|
293
|
+
* @param subscription - The unique subscription ID returned from Subscribe()
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* ```typescript
|
|
297
|
+
* const handler = new EventHandler('TestEvent');
|
|
298
|
+
*
|
|
299
|
+
* const subId = handler.Subscribe((event) => {
|
|
300
|
+
* console.log('Event received');
|
|
301
|
+
* });
|
|
302
|
+
*
|
|
303
|
+
* // Later, unsubscribe
|
|
304
|
+
* handler.Unsubscribe(subId);
|
|
305
|
+
*
|
|
306
|
+
* // Safe to call with non-existent IDs
|
|
307
|
+
* handler.Unsubscribe(999); // No error thrown
|
|
308
|
+
* ```
|
|
309
|
+
*/
|
|
310
|
+
Unsubscribe(subscription) {
|
|
311
|
+
const sub = this._subscriptions.get(subscription);
|
|
312
|
+
if (!sub)
|
|
313
|
+
return;
|
|
314
|
+
this._subscriptions.delete(subscription);
|
|
315
|
+
sub.unsubscribe();
|
|
316
|
+
// Add the freed ID back to available set for reuse - O(1) operation
|
|
317
|
+
this._AvailableIds.add(subscription);
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Destroys the event handler and cleans up all resources.
|
|
321
|
+
* Completes the internal subject and unsubscribes all active subscriptions.
|
|
322
|
+
*
|
|
323
|
+
* @example
|
|
324
|
+
* ```typescript
|
|
325
|
+
* const handler = new EventHandler('TestEvent');
|
|
326
|
+
* handler.Subscribe((event) => { });
|
|
327
|
+
* handler.Destroy(); // Cleanup
|
|
328
|
+
* ```
|
|
329
|
+
*/
|
|
330
|
+
Destroy() {
|
|
331
|
+
this._Subject.complete();
|
|
332
|
+
// Unsubscribe all active subscriptions
|
|
333
|
+
for (const subscription of this._subscriptions.values()) {
|
|
334
|
+
subscription.unsubscribe();
|
|
335
|
+
}
|
|
336
|
+
// Clear all subscriptions and available IDs
|
|
337
|
+
this._subscriptions.clear();
|
|
338
|
+
this._AvailableIds.clear();
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
//# sourceMappingURL=handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAgB,MAAM,MAAM,CAAC;AAI7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,MAAM,OAAO,YAAY;IACxB;;;OAGG;IACa,IAAI,CAAS;IAE7B;;;;;;;;;;;OAWG;IACH,YAAY,IAAY;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI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,OAAO;QAEjB,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QACzC,GAAG,CAAC,WAAW,EAAE,CAAC;QAElB,oEAAoE;QACpE,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IACtC,CAAC;IAED;;;;;;;;;;OAUG;IACI,OAAO;QACb,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;QAEzB,uCAAuC;QACvC,KAAK,MAAM,YAAY,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,EAAE,CAAC;YACzD,YAAY,CAAC,WAAW,EAAE,CAAC;QAC5B,CAAC;QAED,4CAA4C;QAC5C,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;QAC5B,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;IAC5B,CAAC;CACD"}
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type * from './event-data.js';
|
|
2
|
+
export type * from './event-function.js';
|
|
3
|
+
export type { TEventHandler } from './types.js';
|
|
4
|
+
export * from './filter-criteria.js';
|
|
5
|
+
export * from './extract-event-payload.js';
|
|
6
|
+
export * from './event-filter.js';
|
|
7
|
+
export * from './handler.js';
|
|
8
|
+
export * from './async-observable.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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;AAChD,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mBAAmB,CAAC;AAElC,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC"}
|
package/build/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './filter-criteria.js';
|
|
2
|
+
export * from './extract-event-payload.js';
|
|
3
|
+
export * from './event-filter.js';
|
|
4
|
+
// IAsyncGeneratorESN is an implementation detail of AsyncObservable; not re-exported here.
|
|
5
|
+
export * from './handler.js';
|
|
6
|
+
export * from './async-observable.js';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mBAAmB,CAAC;AAClC,2FAA2F;AAC3F,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC"}
|
package/build/types.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event handler callback function type
|
|
3
|
+
* @template TPayload - The type of event payload
|
|
4
|
+
* @param payload - The event data
|
|
5
|
+
* @returns void or Promise<void>
|
|
6
|
+
*/
|
|
7
|
+
export type TEventHandler<TPayload = unknown> = (payload: TPayload) => void | Promise<void>;
|
|
8
|
+
/**
|
|
9
|
+
* Event subscription options
|
|
10
|
+
* @remarks `once` and `priority` are reserved for a future release and are not yet implemented
|
|
11
|
+
* by `EventHandler`. Passing these options currently has no effect.
|
|
12
|
+
* @internal Not part of the public API until implemented; not re-exported from the package entry point.
|
|
13
|
+
*/
|
|
14
|
+
export interface ISubscriptionOptions {
|
|
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
|
+
}
|
|
20
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,aAAa,CAAC,QAAQ,GAAG,OAAO,IAAI,CAAC,OAAO,EAAE,QAAQ,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE5F;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACpC,kEAAkE;IAClE,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB"}
|
package/build/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pawells/rxjs-events",
|
|
3
|
+
"displayName": "RxJS Events",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"description": "RxJS-based event handling library with reactive observables and async event streams.",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./build/index.js",
|
|
8
|
+
"types": "./build/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./build/index.d.ts",
|
|
12
|
+
"import": "./build/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc --project tsconfig.build.json",
|
|
17
|
+
"start": "node build/index.js",
|
|
18
|
+
"dev": "tsc --project tsconfig.build.json && node build/index.js",
|
|
19
|
+
"watch": "tsc --watch --project tsconfig.build.json",
|
|
20
|
+
"typecheck": "tsc --project tsconfig.test.json --noEmit",
|
|
21
|
+
"lint": "eslint src/",
|
|
22
|
+
"lint:fix": "eslint src/ --fix",
|
|
23
|
+
"test": "vitest run",
|
|
24
|
+
"test:ui": "vitest --ui",
|
|
25
|
+
"test:coverage": "vitest --coverage",
|
|
26
|
+
"prepublishOnly": "npm run build",
|
|
27
|
+
"prepare": "husky"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"rxjs": "^7.8.2"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@eslint/js": "^10.0.1",
|
|
34
|
+
"@stylistic/eslint-plugin": "^5.9.0",
|
|
35
|
+
"@types/node": "^25.3.0",
|
|
36
|
+
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
37
|
+
"@typescript-eslint/parser": "^8.0.0",
|
|
38
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
39
|
+
"@vitest/ui": "^4.0.18",
|
|
40
|
+
"eslint": "^10.0.1",
|
|
41
|
+
"eslint-import-resolver-typescript": "^4.4.4",
|
|
42
|
+
"eslint-plugin-import": "^2.31.0",
|
|
43
|
+
"eslint-plugin-unused-imports": "^4.0.0",
|
|
44
|
+
"globals": "^17.3.0",
|
|
45
|
+
"husky": "^9.1.7",
|
|
46
|
+
"typescript": "^5.3.3",
|
|
47
|
+
"vitest": "^4.0.18"
|
|
48
|
+
},
|
|
49
|
+
"keywords": [
|
|
50
|
+
"typescript",
|
|
51
|
+
"rxjs",
|
|
52
|
+
"events",
|
|
53
|
+
"observables",
|
|
54
|
+
"async",
|
|
55
|
+
"reactive",
|
|
56
|
+
"esm"
|
|
57
|
+
],
|
|
58
|
+
"author": "Phillip Aaron Wells",
|
|
59
|
+
"license": "MIT",
|
|
60
|
+
"repository": {
|
|
61
|
+
"type": "git",
|
|
62
|
+
"url": "git+https://github.com/PhillipAWells/rxjs-events.git"
|
|
63
|
+
},
|
|
64
|
+
"bugs": {
|
|
65
|
+
"url": "https://github.com/PhillipAWells/rxjs-events/issues"
|
|
66
|
+
},
|
|
67
|
+
"homepage": "https://github.com/PhillipAWells/rxjs-events#readme",
|
|
68
|
+
"engines": {
|
|
69
|
+
"node": ">=24.0.0"
|
|
70
|
+
},
|
|
71
|
+
"packageManager": "yarn@4.12.0",
|
|
72
|
+
"files": [
|
|
73
|
+
"build/",
|
|
74
|
+
"README.md",
|
|
75
|
+
"LICENSE"
|
|
76
|
+
],
|
|
77
|
+
"publishConfig": {
|
|
78
|
+
"access": "public"
|
|
79
|
+
}
|
|
80
|
+
}
|