abxbus 2.4.32 → 2.5.1
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 +74 -51
- package/dist/cjs/BaseEvent.d.ts +46 -55
- package/dist/cjs/BaseEvent.js +350 -169
- package/dist/cjs/BaseEvent.js.map +3 -3
- package/dist/cjs/EventBus.d.ts +8 -1
- package/dist/cjs/EventBus.js +153 -85
- package/dist/cjs/EventBus.js.map +2 -2
- package/dist/cjs/EventHandler.d.ts +3 -3
- package/dist/cjs/EventHandler.js.map +1 -1
- package/dist/cjs/EventResult.js +16 -22
- package/dist/cjs/EventResult.js.map +2 -2
- package/dist/cjs/LockManager.d.ts +1 -0
- package/dist/cjs/LockManager.js +4 -1
- package/dist/cjs/LockManager.js.map +2 -2
- package/dist/cjs/events_suck.js +1 -1
- package/dist/cjs/events_suck.js.map +2 -2
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/timing.js +1 -1
- package/dist/cjs/timing.js.map +2 -2
- package/dist/esm/BaseEvent.js +351 -170
- package/dist/esm/BaseEvent.js.map +3 -3
- package/dist/esm/EventBus.js +153 -85
- package/dist/esm/EventBus.js.map +2 -2
- package/dist/esm/EventHandler.js.map +1 -1
- package/dist/esm/EventResult.js +16 -22
- package/dist/esm/EventResult.js.map +2 -2
- package/dist/esm/LockManager.js +4 -1
- package/dist/esm/LockManager.js.map +2 -2
- package/dist/esm/events_suck.js +1 -1
- package/dist/esm/events_suck.js.map +2 -2
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/timing.js +1 -1
- package/dist/esm/timing.js.map +2 -2
- package/dist/types/BaseEvent.d.ts +46 -55
- package/dist/types/EventBus.d.ts +8 -1
- package/dist/types/EventHandler.d.ts +3 -3
- package/dist/types/LockManager.d.ts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +4 -3
- package/src/BaseEvent.ts +456 -219
- package/src/EventBus.ts +186 -99
- package/src/EventHandler.ts +3 -3
- package/src/EventResult.ts +18 -22
- package/src/LockManager.ts +5 -1
- package/src/events_suck.ts +1 -1
- package/src/index.ts +1 -0
- package/src/timing.ts +1 -1
- package/dist/cjs/base_event.d.ts +0 -211
- package/dist/cjs/bridge_jsonl.d.ts +0 -26
- package/dist/cjs/bridge_nats.d.ts +0 -20
- package/dist/cjs/bridge_postgres.d.ts +0 -31
- package/dist/cjs/bridge_redis.d.ts +0 -34
- package/dist/cjs/bridge_sqlite.d.ts +0 -30
- package/dist/cjs/event_bus.d.ts +0 -125
- package/dist/cjs/event_handler.d.ts +0 -139
- package/dist/cjs/event_history.d.ts +0 -45
- package/dist/cjs/event_result.d.ts +0 -86
- package/dist/cjs/lock_manager.d.ts +0 -70
- package/dist/types/base_event.d.ts +0 -211
- package/dist/types/bridge_jsonl.d.ts +0 -26
- package/dist/types/bridge_nats.d.ts +0 -20
- package/dist/types/bridge_postgres.d.ts +0 -31
- package/dist/types/bridge_redis.d.ts +0 -34
- package/dist/types/bridge_sqlite.d.ts +0 -30
- package/dist/types/event_bus.d.ts +0 -125
- package/dist/types/event_handler.d.ts +0 -139
- package/dist/types/event_history.d.ts +0 -45
- package/dist/types/event_result.d.ts +0 -86
- package/dist/types/lock_manager.d.ts +0 -70
package/README.md
CHANGED
|
@@ -65,8 +65,8 @@ bus.on(CreateUserEvent, async (event) => {
|
|
|
65
65
|
})
|
|
66
66
|
|
|
67
67
|
const event = bus.emit(CreateUserEvent({ email: 'someuser@example.com' }))
|
|
68
|
-
await event.
|
|
69
|
-
console.log(event.
|
|
68
|
+
await event.wait()
|
|
69
|
+
console.log(await event.eventResult()) // { user_id: 'some-user-uuid' }
|
|
70
70
|
```
|
|
71
71
|
|
|
72
72
|
<br/>
|
|
@@ -108,6 +108,7 @@ Constructor:
|
|
|
108
108
|
new EventBus(name?: string, options?: {
|
|
109
109
|
id?: string
|
|
110
110
|
max_history_size?: number | null
|
|
111
|
+
max_history_drop?: boolean
|
|
111
112
|
event_concurrency?: 'global-serial' | 'bus-serial' | 'parallel' | null
|
|
112
113
|
event_timeout?: number | null
|
|
113
114
|
event_slow_timeout?: number | null
|
|
@@ -125,14 +126,16 @@ new EventBus(name?: string, options?: {
|
|
|
125
126
|
| `id` | `string` | `uuidv7()` | Override bus UUID (mostly for serialization/tests). |
|
|
126
127
|
| `max_history_size` | `number \| null` | `100` | Max events kept in `event_history`; `null` = unbounded; `0` = keep only in-flight events and drop completed events immediately. |
|
|
127
128
|
| `max_history_drop` | `boolean` | `false` | If `true`, when history is full drop oldest history entries (including uncompleted if needed). If `false`, reject new emits when history reaches `max_history_size`. |
|
|
128
|
-
| `event_concurrency` | `'global-serial' \| 'bus-serial' \| 'parallel' \| null` | `'bus-serial'` | Event-level scheduling policy.
|
|
129
|
-
| `event_handler_concurrency` | `'serial' \| 'parallel' \| null` | `'serial'` | Per-event handler scheduling policy.
|
|
130
|
-
| `event_handler_completion` | `'all' \| 'first'` | `'all'` | Event completion mode
|
|
131
|
-
| `event_timeout` | `number \| null` | `60` | Default per-handler timeout budget in seconds
|
|
132
|
-
| `event_handler_slow_timeout` | `number \| null` | `30` | Slow handler warning threshold
|
|
133
|
-
| `event_slow_timeout` | `number \| null` | `300` | Slow event warning threshold
|
|
129
|
+
| `event_concurrency` | `'global-serial' \| 'bus-serial' \| 'parallel' \| null` | `'bus-serial'` | Event-level scheduling policy, resolved at processing time when the event does not override it. |
|
|
130
|
+
| `event_handler_concurrency` | `'serial' \| 'parallel' \| null` | `'serial'` | Per-event handler scheduling policy, resolved at processing time when the event does not override it. |
|
|
131
|
+
| `event_handler_completion` | `'all' \| 'first'` | `'all'` | Event completion mode, resolved at processing time when the event does not override it. |
|
|
132
|
+
| `event_timeout` | `number \| null` | `60` | Default per-handler timeout budget in seconds, resolved at processing time when the event does not override it; `0` disables. |
|
|
133
|
+
| `event_handler_slow_timeout` | `number \| null` | `30` | Slow handler warning threshold in seconds, resolved at processing time when the event does not override it; `0` disables. |
|
|
134
|
+
| `event_slow_timeout` | `number \| null` | `300` | Slow event warning threshold in seconds, resolved at processing time when the event does not override it; `0` disables. |
|
|
134
135
|
| `event_handler_detect_file_paths` | `boolean` | `true` | Capture source file:line for handlers (slower, better logs). |
|
|
135
136
|
|
|
137
|
+
Unset event option fields stay unset on the event object. The bus that actually processes the event resolves its defaults at execution time, so forwarded events can inherit the target bus defaults.
|
|
138
|
+
|
|
136
139
|
#### Runtime state properties
|
|
137
140
|
|
|
138
141
|
- `id: string`
|
|
@@ -203,8 +206,8 @@ Normal lifecycle:
|
|
|
203
206
|
|
|
204
207
|
1. Create event instance (`const event = MyEvent({...})`).
|
|
205
208
|
2. Emit (`const queued = bus.emit(event)`).
|
|
206
|
-
3. Await with `await queued.
|
|
207
|
-
4. Inspect `queued.event_results`, `queued.
|
|
209
|
+
3. Await with `await queued.now()` (immediate/queue-jump semantics) or `await queued.wait()` (bus queue order).
|
|
210
|
+
4. Inspect `queued.event_results`, or call `await queued.eventResult()` / `await queued.eventResultsList()` if you need handler return values.
|
|
208
211
|
|
|
209
212
|
#### `find()`
|
|
210
213
|
|
|
@@ -272,7 +275,7 @@ Debouncing expensive events with `find()`:
|
|
|
272
275
|
|
|
273
276
|
```ts
|
|
274
277
|
const some_expensive_event = (await bus.find(ExpensiveEvent, { past: 15, future: 5 })) ?? bus.emit(ExpensiveEvent({}))
|
|
275
|
-
await some_expensive_event.
|
|
278
|
+
await some_expensive_event.now()
|
|
276
279
|
```
|
|
277
280
|
|
|
278
281
|
#### `filter()`
|
|
@@ -297,10 +300,10 @@ const recent = await bus.filter(ResponseEvent, { past: 10, future: false, limit:
|
|
|
297
300
|
Important semantics:
|
|
298
301
|
|
|
299
302
|
- Past lookup matches any emitted events, not just completed events.
|
|
300
|
-
- Past/future matches resolve as soon as event is emitted. If you need the completed event, await `event.
|
|
303
|
+
- Past/future matches resolve as soon as event is emitted. If you need the completed event, await `event.now()` or pass `{event_status: 'completed'}` to filter only for completed events.
|
|
301
304
|
- If both `past` and `future` are omitted, defaults are `past: true, future: false`.
|
|
302
305
|
- If both `past` and `future` are `false`, it returns `null` immediately.
|
|
303
|
-
- Detailed behavior matrix is covered in `abxbus-ts/tests/
|
|
306
|
+
- Detailed behavior matrix is covered in `abxbus-ts/tests/EventBus_find.test.ts`.
|
|
304
307
|
|
|
305
308
|
#### `waitUntilIdle(timeout?)`
|
|
306
309
|
|
|
@@ -317,13 +320,13 @@ await bus.waitUntilIdle(5) // wait up to 5 seconds, then continue even if work
|
|
|
317
320
|
|
|
318
321
|
#### Emit styles from handlers
|
|
319
322
|
|
|
320
|
-
Most handler code should use `await event.emit(ChildEvent({})).
|
|
323
|
+
Most handler code should use `await event.emit(ChildEvent({})).now()`. That creates a linked child and marks it as blocking parent completion.
|
|
321
324
|
|
|
322
325
|
| Style | `event_parent_id` | `event_blocks_parent_completion` | Blocks current handler? | Effect |
|
|
323
326
|
| --- | --- | --- | --- | --- |
|
|
324
|
-
| `await event.emit(ChildEvent({})).
|
|
327
|
+
| `await event.emit(ChildEvent({})).now()` | Parent event id | `true` | Yes | Linked child work; parent completion waits too. |
|
|
325
328
|
| `event.emit(ChildEvent({}))` without awaiting | Parent event id | `false` | No | Linked background child; visible in ancestry but parent completion does not wait. |
|
|
326
|
-
| `await bus.emit(TopLevelEvent({})).
|
|
329
|
+
| `await bus.emit(TopLevelEvent({})).now()` | `null` | `false` | Yes | Detached top-level event; the handler waits naturally because it is awaited. |
|
|
327
330
|
| `bus.emit(TopLevelEvent({}))` without awaiting | `null` | `false` | No | True detached background event with no retained parent relationship. |
|
|
328
331
|
|
|
329
332
|
#### Parent/child/event lookup helpers
|
|
@@ -357,11 +360,14 @@ logTree(): string
|
|
|
357
360
|
#### `destroy()`
|
|
358
361
|
|
|
359
362
|
```ts
|
|
360
|
-
destroy(): void
|
|
363
|
+
destroy(clear?: boolean): Promise<void>
|
|
364
|
+
destroy(options?: { clear?: boolean }): Promise<void>
|
|
361
365
|
```
|
|
362
366
|
|
|
363
|
-
- `
|
|
364
|
-
- `destroy()
|
|
367
|
+
- `clear` defaults to `true`.
|
|
368
|
+
- `await bus.destroy()` clears handlers/history/pending events/in-flight state/find waiters/locks and removes this bus from global tracking.
|
|
369
|
+
- `await bus.destroy({ clear: false })` stops runtime work and resolves waiters but keeps handlers/history for inspection. The bus is still destroyed and cannot be used again.
|
|
370
|
+
- Destroy/GC behavior is exercised in `abxbus-ts/tests/EventBus.test.ts` and `abxbus-ts/tests/EventBus_performance.test.ts`.
|
|
365
371
|
|
|
366
372
|
</details>
|
|
367
373
|
|
|
@@ -379,7 +385,7 @@ const MyEvent = BaseEvent.extend('MyEvent', {
|
|
|
379
385
|
// ...
|
|
380
386
|
// any other payload fields you want to include can go here
|
|
381
387
|
|
|
382
|
-
//
|
|
388
|
+
// known event_* fields are event metadata/options; unknown event_* fields are rejected
|
|
383
389
|
event_result_type: z.string().optional(),
|
|
384
390
|
event_timeout: 60,
|
|
385
391
|
// ...
|
|
@@ -387,7 +393,7 @@ const MyEvent = BaseEvent.extend('MyEvent', {
|
|
|
387
393
|
|
|
388
394
|
const pending_event = MyEvent({ some_key: 'abc', some_other_key: 234 })
|
|
389
395
|
const queued_event = bus.emit(pending_event)
|
|
390
|
-
const completed_event = await queued_event.
|
|
396
|
+
const completed_event = await queued_event.now()
|
|
391
397
|
```
|
|
392
398
|
|
|
393
399
|
API behavior and lifecycle examples:
|
|
@@ -395,12 +401,12 @@ API behavior and lifecycle examples:
|
|
|
395
401
|
- `abxbus-ts/examples/simple.ts`
|
|
396
402
|
- `abxbus-ts/examples/immediate_event_processing.ts`
|
|
397
403
|
- `abxbus-ts/examples/forwarding_between_busses.ts`
|
|
398
|
-
- `abxbus-ts/tests/
|
|
399
|
-
- `abxbus-ts/tests/
|
|
400
|
-
- `abxbus-ts/tests/
|
|
401
|
-
- `abxbus-ts/tests/
|
|
402
|
-
- `abxbus-ts/tests/
|
|
403
|
-
- `abxbus-ts/tests/
|
|
404
|
+
- `abxbus-ts/tests/EventBus.test.ts`
|
|
405
|
+
- `abxbus-ts/tests/EventBus_find.test.ts`
|
|
406
|
+
- `abxbus-ts/tests/EventHandler_first.test.ts`
|
|
407
|
+
- `abxbus-ts/tests/BaseEvent.test.ts`
|
|
408
|
+
- `abxbus-ts/tests/EventBus_timeout.test.ts`
|
|
409
|
+
- `abxbus-ts/tests/EventResult.test.ts`
|
|
404
410
|
|
|
405
411
|
#### Event configuration fields
|
|
406
412
|
|
|
@@ -410,11 +416,14 @@ Special configuration fields you can set on each event to control processing:
|
|
|
410
416
|
- `event_version?: string` (default: `'0.0.1'`; useful for your own schema/data migrations)
|
|
411
417
|
- `event_timeout?: number | null`
|
|
412
418
|
- `event_handler_timeout?: number | null`
|
|
419
|
+
- `event_slow_timeout?: number | null`
|
|
413
420
|
- `event_handler_slow_timeout?: number | null`
|
|
414
421
|
- `event_concurrency?: 'global-serial' | 'bus-serial' | 'parallel' | null`
|
|
415
422
|
- `event_handler_concurrency?: 'serial' | 'parallel' | null`
|
|
416
423
|
- `event_handler_completion?: 'all' | 'first'`
|
|
417
424
|
|
|
425
|
+
When these fields are `null`/unset, they are resolved from the current processing bus at execution time and are not eagerly written onto the event.
|
|
426
|
+
|
|
418
427
|
#### Runtime state fields
|
|
419
428
|
|
|
420
429
|
- `event_id`, `event_type`, `event_version`
|
|
@@ -437,48 +446,61 @@ Special configuration fields you can set on each event to control processing:
|
|
|
437
446
|
- `event_errors` -> `Error[]`
|
|
438
447
|
- `event_result` -> `EventResultType<this> | undefined`
|
|
439
448
|
|
|
440
|
-
#### `
|
|
449
|
+
#### `now()`
|
|
441
450
|
|
|
442
451
|
```ts
|
|
443
|
-
|
|
452
|
+
now(options?: { first_result?: boolean; timeout?: number | null }): Promise<this>
|
|
444
453
|
```
|
|
445
454
|
|
|
446
455
|
- If called from inside a running handler, it queue-jumps child processing immediately.
|
|
447
456
|
- If called outside handler context, it waits for normal completion (or processes immediately if already next).
|
|
448
|
-
-
|
|
449
|
-
-
|
|
457
|
+
- `{ first_result: true }` resolves when the first valid result is available; other handlers keep running.
|
|
458
|
+
- `{ timeout }` limits this wait call only. Use `event_timeout: 0` / `event_handler_timeout: 0` to disable execution timeouts.
|
|
450
459
|
- Rejects if event is not attached to a bus (`event has no bus attached`).
|
|
451
|
-
- Queue-jump behavior is demonstrated in `abxbus-ts/examples/immediate_event_processing.ts` and `abxbus-ts/tests/
|
|
460
|
+
- Queue-jump behavior is demonstrated in `abxbus-ts/examples/immediate_event_processing.ts` and `abxbus-ts/tests/BaseEvent.test.ts`.
|
|
452
461
|
|
|
453
|
-
#### `
|
|
462
|
+
#### `wait()`
|
|
454
463
|
|
|
455
464
|
```ts
|
|
456
|
-
|
|
465
|
+
wait(options?: { first_result?: boolean; timeout?: number | null }): Promise<this>
|
|
457
466
|
```
|
|
458
467
|
|
|
459
468
|
- Waits for completion in normal runloop order.
|
|
460
469
|
- Use inside handlers when you explicitly do not want queue-jump behavior.
|
|
470
|
+
- Supports the same `{ first_result, timeout }` wait-shaping options as `now()`.
|
|
471
|
+
|
|
472
|
+
#### First result
|
|
473
|
+
|
|
474
|
+
```ts
|
|
475
|
+
event.now({ first_result: true }).eventResult(): Promise<EventResultType<this> | undefined>
|
|
476
|
+
```
|
|
461
477
|
|
|
462
|
-
|
|
478
|
+
- Resolves as soon as the first valid result is available.
|
|
479
|
+
- Does not change `event_handler_completion`; all handlers keep running unless the event definition explicitly sets `event_handler_completion: 'first'`.
|
|
480
|
+
- Result filtering and error policy are controlled by `eventResult(...)`, not `now()` / `wait()`.
|
|
481
|
+
- Cancellation and winner-selection behavior is covered in `abxbus-ts/tests/EventHandler_first.test.ts`.
|
|
482
|
+
|
|
483
|
+
#### `eventResult(options?)`
|
|
463
484
|
|
|
464
485
|
```ts
|
|
465
|
-
|
|
486
|
+
eventResult(
|
|
487
|
+
options?: {
|
|
488
|
+
include?: (result: EventResultType<this> | undefined, event_result: EventResult<this>) => boolean
|
|
489
|
+
raise_if_any?: boolean
|
|
490
|
+
raise_if_none?: boolean
|
|
491
|
+
}
|
|
492
|
+
): Promise<EventResultType<this> | undefined>
|
|
466
493
|
```
|
|
467
494
|
|
|
468
|
-
-
|
|
469
|
-
-
|
|
470
|
-
-
|
|
471
|
-
- Re-raises the first non-cancellation handler exception encountered after processing completes.
|
|
472
|
-
- Returns `undefined` only when no handler produces a successful non-`undefined` value and no handler raises.
|
|
473
|
-
- Cancellation and winner-selection behavior is covered in `abxbus-ts/tests/event_handler_first.test.ts`.
|
|
495
|
+
- Returns the first matching handler result in handler registration order.
|
|
496
|
+
- If the event is still pending and has no settled results, it first waits through `now({ first_result: true })`.
|
|
497
|
+
- Uses the same filtering and error policy options as `eventResultsList(...)`.
|
|
474
498
|
|
|
475
|
-
#### `eventResultsList(
|
|
499
|
+
#### `eventResultsList(options?)`
|
|
476
500
|
|
|
477
501
|
```ts
|
|
478
502
|
eventResultsList(
|
|
479
|
-
include?: (result: EventResultType<this> | undefined, event_result: EventResult<this>) => boolean,
|
|
480
503
|
options?: {
|
|
481
|
-
timeout?: number | null
|
|
482
504
|
include?: (result: EventResultType<this> | undefined, event_result: EventResult<this>) => boolean
|
|
483
505
|
raise_if_any?: boolean
|
|
484
506
|
raise_if_none?: boolean
|
|
@@ -489,11 +511,12 @@ eventResultsList(
|
|
|
489
511
|
- Returns handler result values in `event_results` order.
|
|
490
512
|
- Default filter includes completed non-`null`/non-`undefined` non-error, non-forwarded (`BaseEvent`) values.
|
|
491
513
|
- `raise_if_any` defaults to `true` and throws when any handler result has an error.
|
|
492
|
-
- `raise_if_none` defaults to `
|
|
493
|
-
- `
|
|
514
|
+
- `raise_if_none` defaults to `false` and throws when no results match `include`.
|
|
515
|
+
- If every handler errors, only `{ raise_if_any: false, raise_if_none: false }` suppresses the error; every other option combination rejects.
|
|
516
|
+
- A single handler error rejects as that error; multiple handler errors reject as `AggregateError`.
|
|
494
517
|
- Examples:
|
|
495
518
|
- `await event.eventResultsList({ raise_if_any: false, raise_if_none: false })`
|
|
496
|
-
- `await event.eventResultsList((result) => typeof result === 'object',
|
|
519
|
+
- `await event.eventResultsList({ include: (result) => typeof result === 'object', raise_if_any: false })`
|
|
497
520
|
|
|
498
521
|
#### `eventResultUpdate(handler, options?)`
|
|
499
522
|
|
|
@@ -538,7 +561,7 @@ EventFactory.fromJSON?.(data: unknown): TypedEvent
|
|
|
538
561
|
- JSON format is cross-language compatible with Python implementation.
|
|
539
562
|
- `event_result_type` is serialized as JSON Schema when possible and rehydrated on `fromJSON`.
|
|
540
563
|
- In TypeScript-only usage, `event_result_type` can be any Zod schema shape or base type like `number | string | boolean | etc.`. For cross-language roundtrips, object-like schemas (including Python `TypedDict`/`dataclass`-style shapes) are reconstructed on Python as Pydantic models, JSON object keys are always strings, and some fine-grained string-shape constraints may be normalized between Zod and Pydantic.
|
|
541
|
-
- Round-trip coverage is in `abxbus-ts/tests/
|
|
564
|
+
- Round-trip coverage is in `abxbus-ts/tests/EventResult.test.ts` and `abxbus-ts/tests/EventBus.test.ts`.
|
|
542
565
|
|
|
543
566
|
</details>
|
|
544
567
|
|
|
@@ -595,8 +618,8 @@ Represents one registered handler entry on a bus. You usually get these from `bu
|
|
|
595
618
|
- `handler` function reference that executes for matching events
|
|
596
619
|
- `handler_name` function name (or `'anonymous'`)
|
|
597
620
|
- `handler_file_path` detected source path (`~/path/file.ts:line`) or `null`
|
|
598
|
-
- `handler_timeout` optional timeout override in seconds (`null`
|
|
599
|
-
- `handler_slow_timeout` optional slow-warning threshold in seconds (`null`
|
|
621
|
+
- `handler_timeout` optional timeout override in seconds (`null` / `undefined` inherits, `0` disables)
|
|
622
|
+
- `handler_slow_timeout` optional slow-warning threshold in seconds (`null` / `undefined` inherits, `0` disables)
|
|
600
623
|
- `handler_registered_at` ISO timestamp
|
|
601
624
|
- `event_pattern` subscribed key (`'SomeEvent'` or `'*'`)
|
|
602
625
|
- `eventbus_name` bus name where this handler was registered
|
package/dist/cjs/BaseEvent.d.ts
CHANGED
|
@@ -42,6 +42,7 @@ export declare const BaseEventSchema: z.ZodObject<{
|
|
|
42
42
|
first: "first";
|
|
43
43
|
}>>>;
|
|
44
44
|
}, z.core.$loose>;
|
|
45
|
+
type AnyEventSchema = z.ZodTypeAny;
|
|
45
46
|
export type BaseEventData = z.infer<typeof BaseEventSchema>;
|
|
46
47
|
export type BaseEventJSON = BaseEventData & Record<string, unknown>;
|
|
47
48
|
type BaseEventFieldName = 'event_id' | 'event_created_at' | 'event_type' | 'event_version' | 'event_timeout' | 'event_slow_timeout' | 'event_handler_timeout' | 'event_handler_slow_timeout' | 'event_blocks_parent_completion' | 'event_parent_id' | 'event_path' | 'event_result_type' | 'event_emitted_by_handler_id' | 'event_pending_bus_count' | 'event_status' | 'event_started_at' | 'event_completed_at' | 'event_results' | 'event_concurrency' | 'event_handler_concurrency' | 'event_handler_completion';
|
|
@@ -54,6 +55,9 @@ export type EventSchema<TShape extends z.ZodRawShape> = z.ZodObject<BaseEventSch
|
|
|
54
55
|
type EventPayload<TShape extends z.ZodRawShape> = TShape extends Record<string, never> ? {} : z.infer<z.ZodObject<TShape>>;
|
|
55
56
|
type EventInput<TShape extends z.ZodRawShape> = z.input<EventSchema<TShape>>;
|
|
56
57
|
export type EventInit<TShape extends z.ZodRawShape> = Omit<EventInput<TShape>, keyof BaseEventFields> & Partial<BaseEventFields>;
|
|
58
|
+
type EventPayloadFromSchema<TSchema extends AnyEventSchema> = z.output<TSchema> extends Record<string, unknown> ? z.output<TSchema> : {};
|
|
59
|
+
type EventInputFromSchema<TSchema extends AnyEventSchema> = z.input<TSchema> extends Record<string, unknown> ? z.input<TSchema> : never;
|
|
60
|
+
export type EventInitFromSchema<TSchema extends AnyEventSchema> = Omit<EventInputFromSchema<TSchema>, keyof BaseEventFields> & Partial<BaseEventFields>;
|
|
57
61
|
type EventWithResultSchema<TResult> = BaseEvent & {
|
|
58
62
|
__event_result_type__?: TResult;
|
|
59
63
|
};
|
|
@@ -61,15 +65,20 @@ type ResultTypeFromEventResultTypeInput<TInput> = TInput extends z.ZodTypeAny ?
|
|
|
61
65
|
type ResultSchemaFromShape<TShape> = TShape extends {
|
|
62
66
|
event_result_type: infer S;
|
|
63
67
|
} ? ResultTypeFromEventResultTypeInput<S> : unknown;
|
|
64
|
-
type
|
|
65
|
-
type
|
|
66
|
-
|
|
67
|
-
include?:
|
|
68
|
+
type ResultSchemaFromEventSchema<TSchema> = TSchema extends z.ZodObject<infer TShape> ? ResultSchemaFromShape<TShape> : unknown;
|
|
69
|
+
export type EventResultInclude<TEvent extends BaseEvent> = (result: EventResult<TEvent>['result'], event_result: EventResult<TEvent>) => boolean;
|
|
70
|
+
export type EventResultOptions<TEvent extends BaseEvent> = {
|
|
71
|
+
include?: EventResultInclude<TEvent>;
|
|
68
72
|
raise_if_any?: boolean;
|
|
69
73
|
raise_if_none?: boolean;
|
|
70
74
|
};
|
|
71
|
-
type
|
|
72
|
-
|
|
75
|
+
export type EventWaitOptions = {
|
|
76
|
+
timeout?: number | null;
|
|
77
|
+
first_result?: boolean;
|
|
78
|
+
};
|
|
79
|
+
export type EventWaitPromise<TEvent extends BaseEvent> = Promise<TEvent> & {
|
|
80
|
+
eventResult(options?: EventResultOptions<TEvent>): Promise<EventResultType<TEvent> | undefined>;
|
|
81
|
+
eventResultsList(options?: EventResultOptions<TEvent>): Promise<Array<EventResultType<TEvent> | undefined>>;
|
|
73
82
|
};
|
|
74
83
|
type EventResultUpdateOptions<TEvent extends BaseEvent> = {
|
|
75
84
|
eventbus?: EventBus;
|
|
@@ -80,13 +89,23 @@ type EventResultUpdateOptions<TEvent extends BaseEvent> = {
|
|
|
80
89
|
export type EventFactory<TShape extends z.ZodRawShape, TResult = unknown> = {
|
|
81
90
|
(data: EventInit<TShape>): EventWithResultSchema<TResult> & EventPayload<TShape>;
|
|
82
91
|
new (data: EventInit<TShape>): EventWithResultSchema<TResult> & EventPayload<TShape>;
|
|
83
|
-
|
|
92
|
+
event_schema: EventSchema<TShape>;
|
|
84
93
|
class?: new (data: EventInit<TShape>) => EventWithResultSchema<TResult> & EventPayload<TShape>;
|
|
85
94
|
event_type?: string;
|
|
86
95
|
event_version?: string;
|
|
87
96
|
event_result_type?: z.ZodTypeAny;
|
|
88
97
|
fromJSON?: (data: unknown) => EventWithResultSchema<TResult> & EventPayload<TShape>;
|
|
89
98
|
};
|
|
99
|
+
export type SchemaEventFactory<TSchema extends AnyEventSchema, TResult = unknown> = {
|
|
100
|
+
(data: EventInitFromSchema<TSchema>): EventWithResultSchema<TResult> & EventPayloadFromSchema<TSchema>;
|
|
101
|
+
new (data: EventInitFromSchema<TSchema>): EventWithResultSchema<TResult> & EventPayloadFromSchema<TSchema>;
|
|
102
|
+
event_schema: TSchema;
|
|
103
|
+
class?: new (data: EventInitFromSchema<TSchema>) => EventWithResultSchema<TResult> & EventPayloadFromSchema<TSchema>;
|
|
104
|
+
event_type?: string;
|
|
105
|
+
event_version?: string;
|
|
106
|
+
event_result_type?: z.ZodTypeAny;
|
|
107
|
+
fromJSON?: (data: unknown) => EventWithResultSchema<TResult> & EventPayloadFromSchema<TSchema>;
|
|
108
|
+
};
|
|
90
109
|
type ZodShapeFrom<TShape extends Record<string, unknown>> = {
|
|
91
110
|
[K in keyof TShape as K extends 'event_result_type' ? never : TShape[K] extends z.ZodTypeAny ? K : never]: Extract<TShape[K], z.ZodTypeAny>;
|
|
92
111
|
};
|
|
@@ -112,59 +131,27 @@ export declare class BaseEvent {
|
|
|
112
131
|
event_concurrency?: EventConcurrencyMode | null;
|
|
113
132
|
event_handler_concurrency?: EventHandlerConcurrencyMode | null;
|
|
114
133
|
event_handler_completion?: EventHandlerCompletionMode | null;
|
|
134
|
+
event_schema?: z.ZodTypeAny;
|
|
115
135
|
static event_type?: string;
|
|
116
136
|
static event_version: string;
|
|
117
|
-
static
|
|
118
|
-
|
|
119
|
-
event_created_at: z.ZodString;
|
|
120
|
-
event_type: z.ZodString;
|
|
121
|
-
event_version: z.ZodDefault<z.ZodString>;
|
|
122
|
-
event_timeout: z.ZodNullable<z.ZodNumber>;
|
|
123
|
-
event_slow_timeout: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
124
|
-
event_handler_timeout: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
125
|
-
event_handler_slow_timeout: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
126
|
-
event_blocks_parent_completion: z.ZodOptional<z.ZodBoolean>;
|
|
127
|
-
event_parent_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
128
|
-
event_path: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
129
|
-
event_result_type: z.ZodOptional<z.ZodUnknown>;
|
|
130
|
-
event_emitted_by_handler_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
131
|
-
event_pending_bus_count: z.ZodOptional<z.ZodNumber>;
|
|
132
|
-
event_status: z.ZodOptional<z.ZodEnum<{
|
|
133
|
-
pending: "pending";
|
|
134
|
-
started: "started";
|
|
135
|
-
completed: "completed";
|
|
136
|
-
}>>;
|
|
137
|
-
event_started_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
138
|
-
event_completed_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
139
|
-
event_results: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
140
|
-
event_concurrency: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
141
|
-
"global-serial": "global-serial";
|
|
142
|
-
"bus-serial": "bus-serial";
|
|
143
|
-
parallel: "parallel";
|
|
144
|
-
}>>>;
|
|
145
|
-
event_handler_concurrency: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
146
|
-
parallel: "parallel";
|
|
147
|
-
serial: "serial";
|
|
148
|
-
}>>>;
|
|
149
|
-
event_handler_completion: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
150
|
-
all: "all";
|
|
151
|
-
first: "first";
|
|
152
|
-
}>>>;
|
|
153
|
-
}, z.core.$loose>;
|
|
137
|
+
static event_result_type?: z.ZodTypeAny;
|
|
138
|
+
static event_schema: AnyEventSchema;
|
|
154
139
|
event_bus?: EventBus;
|
|
155
140
|
_event_original?: BaseEvent;
|
|
156
141
|
_event_dispatch_context?: unknown | null;
|
|
142
|
+
_event_fields_set?: Set<string>;
|
|
157
143
|
_event_completed_signal: Deferred<this> | null;
|
|
158
144
|
_lock_for_event_handler: AsyncLock | null;
|
|
159
145
|
constructor(data?: BaseEventInit<Record<string, unknown>>);
|
|
160
146
|
toString(): string;
|
|
147
|
+
static extend<TSchema extends z.ZodObject<z.ZodRawShape>>(event_type: string, event_schema: TSchema): SchemaEventFactory<TSchema, ResultSchemaFromEventSchema<TSchema>>;
|
|
161
148
|
static extend<TShape extends z.ZodRawShape>(event_type: string, shape?: TShape): EventFactory<TShape, ResultSchemaFromShape<TShape>>;
|
|
162
149
|
static extend<TShape extends Record<string, unknown>>(event_type: string, shape?: TShape): EventFactory<ZodShapeFrom<TShape>, ResultSchemaFromShape<TShape>>;
|
|
163
150
|
static fromJSON<T extends typeof BaseEvent>(this: T, data: unknown): InstanceType<T>;
|
|
164
151
|
static toJSONArray(events: Iterable<BaseEvent>): BaseEventJSON[];
|
|
165
152
|
static fromJSONArray(data: unknown): BaseEvent[];
|
|
166
153
|
toJSON(): BaseEventJSON;
|
|
167
|
-
_createSlowEventWarningTimer(): ReturnType<typeof setTimeout> | null;
|
|
154
|
+
_createSlowEventWarningTimer(event_slow_timeout?: number | null, bus_name?: string): ReturnType<typeof setTimeout> | null;
|
|
168
155
|
eventResultUpdate(handler: EventHandler | EventHandlerCallable<this>, options?: EventResultUpdateOptions<this>): EventResult<this>;
|
|
169
156
|
_createPendingHandlerResults(bus: EventBus): Array<{
|
|
170
157
|
handler: EventHandler;
|
|
@@ -172,6 +159,8 @@ export declare class BaseEvent {
|
|
|
172
159
|
}>;
|
|
173
160
|
private _collectPendingResults;
|
|
174
161
|
private _isFirstModeWinningResult;
|
|
162
|
+
private static _defaultResultInclude;
|
|
163
|
+
private static _includeEventResult;
|
|
175
164
|
private _markFirstModeWinnerIfNeeded;
|
|
176
165
|
private _runHandlerWithLock;
|
|
177
166
|
_runHandlers(pending_entries?: Array<{
|
|
@@ -190,11 +179,17 @@ export declare class BaseEvent {
|
|
|
190
179
|
_markRemainingFirstModeResultCancelled(winner: EventResult): void;
|
|
191
180
|
_markCancelled(cause: Error): void;
|
|
192
181
|
_notifyEventParentsOfCompletion(): void;
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
182
|
+
private _withEventResultMethods;
|
|
183
|
+
private _timeoutPromise;
|
|
184
|
+
private _orderedEventResults;
|
|
185
|
+
private _orderedEventResultsByRegistration;
|
|
186
|
+
private _collectResultValues;
|
|
187
|
+
private _hasIncludedResult;
|
|
188
|
+
private _waitForFirstResultOrCompletion;
|
|
189
|
+
now(options?: EventWaitOptions): EventWaitPromise<this>;
|
|
190
|
+
wait(options?: EventWaitOptions): EventWaitPromise<this>;
|
|
191
|
+
eventResult(options?: EventResultOptions<this>): Promise<EventResultType<this> | undefined>;
|
|
192
|
+
eventResultsList(options?: EventResultOptions<this>): Promise<Array<EventResultType<this> | undefined>>;
|
|
198
193
|
_markBlocksParentCompletionIfAwaitedFromEmittingHandler(): void;
|
|
199
194
|
_markPending(): this;
|
|
200
195
|
eventReset(): this;
|
|
@@ -202,11 +197,7 @@ export declare class BaseEvent {
|
|
|
202
197
|
_markCompleted(force?: boolean, notify_parents?: boolean): void;
|
|
203
198
|
private dropFromZeroHistoryBuses;
|
|
204
199
|
get event_errors(): unknown[];
|
|
205
|
-
|
|
206
|
-
_firstProcessingError(options?: {
|
|
207
|
-
ignore_first_mode_control_errors?: boolean;
|
|
208
|
-
}): unknown | undefined;
|
|
209
|
-
get event_result(): EventResultType<this> | undefined;
|
|
200
|
+
_firstProcessingError(): unknown | undefined;
|
|
210
201
|
_areAllChildrenComplete(visited?: Set<string>): boolean;
|
|
211
202
|
private _notifyDoneListeners;
|
|
212
203
|
_gc(): void;
|