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.
Files changed (70) hide show
  1. package/README.md +74 -51
  2. package/dist/cjs/BaseEvent.d.ts +46 -55
  3. package/dist/cjs/BaseEvent.js +350 -169
  4. package/dist/cjs/BaseEvent.js.map +3 -3
  5. package/dist/cjs/EventBus.d.ts +8 -1
  6. package/dist/cjs/EventBus.js +153 -85
  7. package/dist/cjs/EventBus.js.map +2 -2
  8. package/dist/cjs/EventHandler.d.ts +3 -3
  9. package/dist/cjs/EventHandler.js.map +1 -1
  10. package/dist/cjs/EventResult.js +16 -22
  11. package/dist/cjs/EventResult.js.map +2 -2
  12. package/dist/cjs/LockManager.d.ts +1 -0
  13. package/dist/cjs/LockManager.js +4 -1
  14. package/dist/cjs/LockManager.js.map +2 -2
  15. package/dist/cjs/events_suck.js +1 -1
  16. package/dist/cjs/events_suck.js.map +2 -2
  17. package/dist/cjs/index.d.ts +1 -0
  18. package/dist/cjs/index.js.map +2 -2
  19. package/dist/cjs/timing.js +1 -1
  20. package/dist/cjs/timing.js.map +2 -2
  21. package/dist/esm/BaseEvent.js +351 -170
  22. package/dist/esm/BaseEvent.js.map +3 -3
  23. package/dist/esm/EventBus.js +153 -85
  24. package/dist/esm/EventBus.js.map +2 -2
  25. package/dist/esm/EventHandler.js.map +1 -1
  26. package/dist/esm/EventResult.js +16 -22
  27. package/dist/esm/EventResult.js.map +2 -2
  28. package/dist/esm/LockManager.js +4 -1
  29. package/dist/esm/LockManager.js.map +2 -2
  30. package/dist/esm/events_suck.js +1 -1
  31. package/dist/esm/events_suck.js.map +2 -2
  32. package/dist/esm/index.js.map +2 -2
  33. package/dist/esm/timing.js +1 -1
  34. package/dist/esm/timing.js.map +2 -2
  35. package/dist/types/BaseEvent.d.ts +46 -55
  36. package/dist/types/EventBus.d.ts +8 -1
  37. package/dist/types/EventHandler.d.ts +3 -3
  38. package/dist/types/LockManager.d.ts +1 -0
  39. package/dist/types/index.d.ts +1 -0
  40. package/package.json +4 -3
  41. package/src/BaseEvent.ts +456 -219
  42. package/src/EventBus.ts +186 -99
  43. package/src/EventHandler.ts +3 -3
  44. package/src/EventResult.ts +18 -22
  45. package/src/LockManager.ts +5 -1
  46. package/src/events_suck.ts +1 -1
  47. package/src/index.ts +1 -0
  48. package/src/timing.ts +1 -1
  49. package/dist/cjs/base_event.d.ts +0 -211
  50. package/dist/cjs/bridge_jsonl.d.ts +0 -26
  51. package/dist/cjs/bridge_nats.d.ts +0 -20
  52. package/dist/cjs/bridge_postgres.d.ts +0 -31
  53. package/dist/cjs/bridge_redis.d.ts +0 -34
  54. package/dist/cjs/bridge_sqlite.d.ts +0 -30
  55. package/dist/cjs/event_bus.d.ts +0 -125
  56. package/dist/cjs/event_handler.d.ts +0 -139
  57. package/dist/cjs/event_history.d.ts +0 -45
  58. package/dist/cjs/event_result.d.ts +0 -86
  59. package/dist/cjs/lock_manager.d.ts +0 -70
  60. package/dist/types/base_event.d.ts +0 -211
  61. package/dist/types/bridge_jsonl.d.ts +0 -26
  62. package/dist/types/bridge_nats.d.ts +0 -20
  63. package/dist/types/bridge_postgres.d.ts +0 -31
  64. package/dist/types/bridge_redis.d.ts +0 -34
  65. package/dist/types/bridge_sqlite.d.ts +0 -30
  66. package/dist/types/event_bus.d.ts +0 -125
  67. package/dist/types/event_handler.d.ts +0 -139
  68. package/dist/types/event_history.d.ts +0 -45
  69. package/dist/types/event_result.d.ts +0 -86
  70. package/dist/types/lock_manager.d.ts +0 -70
@@ -1,86 +0,0 @@
1
- import { z } from 'zod';
2
- import { BaseEvent } from './base_event.js';
3
- import type { EventBus } from './event_bus.js';
4
- import { EventHandler } from './event_handler.js';
5
- import { type HandlerLock } from './lock_manager.js';
6
- import type { Deferred } from './lock_manager.js';
7
- import type { EventResultType } from './types.js';
8
- export type EventResultStatus = 'pending' | 'started' | 'completed' | 'error';
9
- export declare const EventResultJSONSchema: z.ZodObject<{
10
- id: z.ZodString;
11
- status: z.ZodEnum<{
12
- pending: "pending";
13
- started: "started";
14
- completed: "completed";
15
- error: "error";
16
- }>;
17
- event_id: z.ZodString;
18
- handler_id: z.ZodString;
19
- handler_name: z.ZodString;
20
- handler_file_path: z.ZodOptional<z.ZodNullable<z.ZodString>>;
21
- handler_timeout: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
22
- handler_slow_timeout: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
23
- handler_registered_at: z.ZodOptional<z.ZodString>;
24
- handler_event_pattern: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodLiteral<"*">]>>;
25
- eventbus_name: z.ZodString;
26
- eventbus_id: z.ZodString;
27
- started_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
28
- completed_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
29
- result: z.ZodOptional<z.ZodUnknown>;
30
- error: z.ZodOptional<z.ZodUnknown>;
31
- event_children: z.ZodArray<z.ZodString>;
32
- }, z.core.$strict>;
33
- export type EventResultJSON = z.infer<typeof EventResultJSONSchema>;
34
- export declare class EventResult<TEvent extends BaseEvent = BaseEvent> {
35
- id: string;
36
- status: EventResultStatus;
37
- event: TEvent;
38
- handler: EventHandler;
39
- started_at: string | null;
40
- completed_at: string | null;
41
- result?: EventResultType<TEvent>;
42
- error?: unknown;
43
- event_children: BaseEvent[];
44
- _abort: Deferred<never> | null;
45
- _lock: HandlerLock | null;
46
- _queue_jump_pause_releases: Map<EventBus, () => void> | null;
47
- constructor(params: {
48
- event: TEvent;
49
- handler: EventHandler;
50
- });
51
- toString(): string;
52
- get event_id(): string;
53
- get bus(): EventBus;
54
- get handler_id(): string;
55
- get handler_name(): string;
56
- get handler_file_path(): string | null;
57
- get eventbus_name(): string;
58
- get eventbus_id(): string;
59
- get eventbus_label(): string;
60
- private getHookBus;
61
- private _notifyStatusHook;
62
- get value(): EventResultType<TEvent> | undefined;
63
- get result_type(): TEvent['event_result_type'];
64
- _linkEmittedChildEvent(child_event: BaseEvent): void;
65
- get raw_value(): EventResultType<TEvent> | undefined;
66
- get handler_timeout(): number | null;
67
- get handler_slow_timeout(): number | null;
68
- _createSlowHandlerWarningTimer(effective_timeout: number | null): ReturnType<typeof setTimeout> | null;
69
- _ensureQueueJumpPause(bus: EventBus): void;
70
- _releaseQueueJumpPauses(): void;
71
- update(params: {
72
- status?: EventResultStatus;
73
- result?: EventResultType<TEvent> | BaseEvent | undefined;
74
- error?: unknown;
75
- }): this;
76
- private _createHandlerTimeoutError;
77
- private _handleHandlerError;
78
- private _onHandlerExit;
79
- runHandler(handler_lock: HandlerLock | null): Promise<void>;
80
- _signalAbort(error: Error): void;
81
- _markStarted(notify_hook?: boolean): Promise<never>;
82
- _markCompleted(result: EventResultType<TEvent> | BaseEvent | undefined, notify_hook?: boolean): void;
83
- _markError(error: unknown, notify_hook?: boolean): void;
84
- toJSON(): EventResultJSON;
85
- static fromJSON<TEvent extends BaseEvent>(event: TEvent, data: unknown): EventResult<TEvent>;
86
- }
@@ -1,70 +0,0 @@
1
- import type { BaseEvent } from './base_event.js';
2
- import type { EventResult } from './event_result.js';
3
- export type Deferred<T> = {
4
- promise: Promise<T>;
5
- resolve: (value: T | PromiseLike<T>) => void;
6
- reject: (reason?: unknown) => void;
7
- };
8
- export declare const withResolvers: <T>() => Deferred<T>;
9
- export declare const EVENT_CONCURRENCY_MODES: readonly ["global-serial", "bus-serial", "parallel"];
10
- export type EventConcurrencyMode = (typeof EVENT_CONCURRENCY_MODES)[number];
11
- export declare const EVENT_HANDLER_CONCURRENCY_MODES: readonly ["serial", "parallel"];
12
- export type EventHandlerConcurrencyMode = (typeof EVENT_HANDLER_CONCURRENCY_MODES)[number];
13
- export declare const EVENT_HANDLER_COMPLETION_MODES: readonly ["all", "first"];
14
- export type EventHandlerCompletionMode = (typeof EVENT_HANDLER_COMPLETION_MODES)[number];
15
- export declare class AsyncLock {
16
- size: number;
17
- in_use: number;
18
- waiters: Array<() => void>;
19
- constructor(size: number);
20
- acquire(): Promise<void>;
21
- release(): void;
22
- }
23
- export declare const runWithLock: <T>(lock: AsyncLock | null, fn: () => Promise<T>) => Promise<T>;
24
- export type HandlerExecutionState = 'held' | 'yielded' | 'closed';
25
- export declare class HandlerLock {
26
- private lock;
27
- private state;
28
- constructor(lock: AsyncLock | null);
29
- yieldHandlerLockForChildRun(): boolean;
30
- reclaimHandlerLockIfRunning(): Promise<boolean>;
31
- exitHandlerRun(): void;
32
- runQueueJump<T>(fn: () => Promise<T>): Promise<T>;
33
- }
34
- export type EventBusInterfaceForLockManager = {
35
- isIdleAndQueueEmpty: () => boolean;
36
- event_concurrency: EventConcurrencyMode;
37
- _lock_for_event_global_serial: AsyncLock;
38
- };
39
- export type LockManagerOptions = {
40
- auto_schedule_idle_checks?: boolean;
41
- };
42
- export declare class LockManager {
43
- private bus;
44
- private auto_schedule_idle_checks;
45
- readonly bus_event_lock: AsyncLock;
46
- private pause_depth;
47
- private pause_waiters;
48
- private active_handler_results;
49
- private idle_waiters;
50
- private idle_check_pending;
51
- private idle_check_streak;
52
- constructor(bus: EventBusInterfaceForLockManager, options?: LockManagerOptions);
53
- _requestRunloopPause(): () => void;
54
- _waitUntilRunloopResumed(): Promise<void>;
55
- _isPaused(): boolean;
56
- _runWithHandlerDispatchContext<T>(result: EventResult, fn: () => Promise<T>): Promise<T>;
57
- _getActiveHandlerResultForCurrentAsyncContext(): EventResult | undefined;
58
- _getActiveHandlerResults(): EventResult[];
59
- _isAnyHandlerActive(): boolean;
60
- waitForIdle(timeout_seconds?: number | null): Promise<boolean>;
61
- _notifyIdleListeners(): void;
62
- getLockForEvent(event: BaseEvent): AsyncLock | null;
63
- _runWithEventLock<T>(event: BaseEvent, fn: () => Promise<T>, options?: {
64
- bypass_event_locks?: boolean;
65
- pre_acquired_lock?: AsyncLock | null;
66
- }): Promise<T>;
67
- _runWithHandlerLock<T>(event: BaseEvent, default_handler_concurrency: EventHandlerConcurrencyMode | undefined, fn: (lock: HandlerLock | null) => Promise<T>): Promise<T>;
68
- private scheduleIdleCheck;
69
- clear(): void;
70
- }
@@ -1,211 +0,0 @@
1
- import { z } from 'zod';
2
- import { EventBus } from './event_bus.js';
3
- import { EventResult } from './event_result.js';
4
- import { EventHandler } from './event_handler.js';
5
- import type { EventConcurrencyMode, EventHandlerConcurrencyMode, EventHandlerCompletionMode, Deferred } from './lock_manager.js';
6
- import { AsyncLock } from './lock_manager.js';
7
- import type { EventHandlerCallable, EventResultType } from './types.js';
8
- export declare const BaseEventSchema: z.ZodObject<{
9
- event_id: z.ZodString;
10
- event_created_at: z.ZodString;
11
- event_type: z.ZodString;
12
- event_version: z.ZodDefault<z.ZodString>;
13
- event_timeout: z.ZodNullable<z.ZodNumber>;
14
- event_slow_timeout: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
15
- event_handler_timeout: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
16
- event_handler_slow_timeout: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
17
- event_blocks_parent_completion: z.ZodOptional<z.ZodBoolean>;
18
- event_parent_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
19
- event_path: z.ZodOptional<z.ZodArray<z.ZodString>>;
20
- event_result_type: z.ZodOptional<z.ZodUnknown>;
21
- event_emitted_by_handler_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
22
- event_pending_bus_count: z.ZodOptional<z.ZodNumber>;
23
- event_status: z.ZodOptional<z.ZodEnum<{
24
- pending: "pending";
25
- started: "started";
26
- completed: "completed";
27
- }>>;
28
- event_started_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
29
- event_completed_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
30
- event_results: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
31
- event_concurrency: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
32
- "global-serial": "global-serial";
33
- "bus-serial": "bus-serial";
34
- parallel: "parallel";
35
- }>>>;
36
- event_handler_concurrency: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
37
- parallel: "parallel";
38
- serial: "serial";
39
- }>>>;
40
- event_handler_completion: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
41
- all: "all";
42
- first: "first";
43
- }>>>;
44
- }, z.core.$loose>;
45
- export type BaseEventData = z.infer<typeof BaseEventSchema>;
46
- export type BaseEventJSON = BaseEventData & Record<string, unknown>;
47
- type BaseEventFields = Pick<BaseEventData, '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'>;
48
- export type BaseEventInit<TFields extends Record<string, unknown>> = TFields & Partial<BaseEventFields>;
49
- type BaseEventSchemaShape = typeof BaseEventSchema.shape;
50
- export type EventSchema<TShape extends z.ZodRawShape> = z.ZodObject<BaseEventSchemaShape & TShape>;
51
- type EventPayload<TShape extends z.ZodRawShape> = TShape extends Record<string, never> ? {} : z.infer<z.ZodObject<TShape>>;
52
- type EventInput<TShape extends z.ZodRawShape> = z.input<EventSchema<TShape>>;
53
- export type EventInit<TShape extends z.ZodRawShape> = Omit<EventInput<TShape>, keyof BaseEventFields> & Partial<BaseEventFields>;
54
- type EventWithResultSchema<TResult> = BaseEvent & {
55
- __event_result_type__?: TResult;
56
- };
57
- type ResultTypeFromEventResultTypeInput<TInput> = TInput extends z.ZodTypeAny ? z.infer<TInput> : TInput extends StringConstructor ? string : TInput extends NumberConstructor ? number : TInput extends BooleanConstructor ? boolean : TInput extends ArrayConstructor ? unknown[] : TInput extends ObjectConstructor ? Record<string, unknown> : unknown;
58
- type ResultSchemaFromShape<TShape> = TShape extends {
59
- event_result_type: infer S;
60
- } ? ResultTypeFromEventResultTypeInput<S> : unknown;
61
- type EventResultsListInclude<TEvent extends BaseEvent> = (result: EventResultType<TEvent> | undefined, event_result: EventResult<TEvent>) => boolean;
62
- type EventResultsListOptions<TEvent extends BaseEvent> = {
63
- timeout?: number | null;
64
- include?: EventResultsListInclude<TEvent>;
65
- raise_if_any?: boolean;
66
- raise_if_none?: boolean;
67
- };
68
- type EventDoneOptions = {
69
- raise_if_any?: boolean;
70
- };
71
- type EventResultUpdateOptions<TEvent extends BaseEvent> = {
72
- eventbus?: EventBus;
73
- status?: 'pending' | 'started' | 'completed' | 'error';
74
- result?: EventResultType<TEvent> | BaseEvent | undefined;
75
- error?: unknown;
76
- };
77
- export type EventFactory<TShape extends z.ZodRawShape, TResult = unknown> = {
78
- (data: EventInit<TShape>): EventWithResultSchema<TResult> & EventPayload<TShape>;
79
- new (data: EventInit<TShape>): EventWithResultSchema<TResult> & EventPayload<TShape>;
80
- schema: EventSchema<TShape>;
81
- class?: new (data: EventInit<TShape>) => EventWithResultSchema<TResult> & EventPayload<TShape>;
82
- event_type?: string;
83
- event_version?: string;
84
- event_result_type?: z.ZodTypeAny;
85
- fromJSON?: (data: unknown) => EventWithResultSchema<TResult> & EventPayload<TShape>;
86
- };
87
- type ZodShapeFrom<TShape extends Record<string, unknown>> = {
88
- [K in keyof TShape as K extends 'event_result_type' ? never : TShape[K] extends z.ZodTypeAny ? K : never]: Extract<TShape[K], z.ZodTypeAny>;
89
- };
90
- export declare class BaseEvent {
91
- event_id: string;
92
- event_created_at: string;
93
- event_type: string;
94
- event_version: string;
95
- event_timeout: number | null;
96
- event_slow_timeout?: number | null;
97
- event_handler_timeout?: number | null;
98
- event_handler_slow_timeout?: number | null;
99
- event_blocks_parent_completion: boolean;
100
- event_parent_id: string | null;
101
- event_path: string[];
102
- event_result_type?: z.ZodTypeAny;
103
- event_results: Map<string, EventResult<this>>;
104
- event_emitted_by_handler_id: string | null;
105
- event_pending_bus_count: number;
106
- event_status: 'pending' | 'started' | 'completed';
107
- event_started_at: string | null;
108
- event_completed_at: string | null;
109
- event_concurrency?: EventConcurrencyMode | null;
110
- event_handler_concurrency?: EventHandlerConcurrencyMode | null;
111
- event_handler_completion?: EventHandlerCompletionMode | null;
112
- static event_type?: string;
113
- static event_version: string;
114
- static schema: z.ZodObject<{
115
- event_id: z.ZodString;
116
- event_created_at: z.ZodString;
117
- event_type: z.ZodString;
118
- event_version: z.ZodDefault<z.ZodString>;
119
- event_timeout: z.ZodNullable<z.ZodNumber>;
120
- event_slow_timeout: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
121
- event_handler_timeout: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
122
- event_handler_slow_timeout: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
123
- event_blocks_parent_completion: z.ZodOptional<z.ZodBoolean>;
124
- event_parent_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
125
- event_path: z.ZodOptional<z.ZodArray<z.ZodString>>;
126
- event_result_type: z.ZodOptional<z.ZodUnknown>;
127
- event_emitted_by_handler_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
128
- event_pending_bus_count: z.ZodOptional<z.ZodNumber>;
129
- event_status: z.ZodOptional<z.ZodEnum<{
130
- pending: "pending";
131
- started: "started";
132
- completed: "completed";
133
- }>>;
134
- event_started_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
135
- event_completed_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
136
- event_results: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
137
- event_concurrency: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
138
- "global-serial": "global-serial";
139
- "bus-serial": "bus-serial";
140
- parallel: "parallel";
141
- }>>>;
142
- event_handler_concurrency: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
143
- parallel: "parallel";
144
- serial: "serial";
145
- }>>>;
146
- event_handler_completion: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
147
- all: "all";
148
- first: "first";
149
- }>>>;
150
- }, z.core.$loose>;
151
- event_bus?: EventBus;
152
- _event_original?: BaseEvent;
153
- _event_dispatch_context?: unknown | null;
154
- _event_completed_signal: Deferred<this> | null;
155
- _lock_for_event_handler: AsyncLock | null;
156
- constructor(data?: BaseEventInit<Record<string, unknown>>);
157
- toString(): string;
158
- static extend<TShape extends z.ZodRawShape>(event_type: string, shape?: TShape): EventFactory<TShape, ResultSchemaFromShape<TShape>>;
159
- static extend<TShape extends Record<string, unknown>>(event_type: string, shape?: TShape): EventFactory<ZodShapeFrom<TShape>, ResultSchemaFromShape<TShape>>;
160
- static fromJSON<T extends typeof BaseEvent>(this: T, data: unknown): InstanceType<T>;
161
- static toJSONArray(events: Iterable<BaseEvent>): BaseEventJSON[];
162
- static fromJSONArray(data: unknown): BaseEvent[];
163
- toJSON(): BaseEventJSON;
164
- _createSlowEventWarningTimer(): ReturnType<typeof setTimeout> | null;
165
- eventResultUpdate(handler: EventHandler | EventHandlerCallable<this>, options?: EventResultUpdateOptions<this>): EventResult<this>;
166
- _createPendingHandlerResults(bus: EventBus): Array<{
167
- handler: EventHandler;
168
- result: EventResult;
169
- }>;
170
- private _collectPendingResults;
171
- private _isFirstModeWinningResult;
172
- private _markFirstModeWinnerIfNeeded;
173
- private _runHandlerWithLock;
174
- _runHandlers(pending_entries?: Array<{
175
- handler: EventHandler;
176
- result: EventResult;
177
- }>): Promise<void>;
178
- _getHandlerLock(default_concurrency?: EventHandlerConcurrencyMode): AsyncLock | null;
179
- _setHandlerLock(lock: AsyncLock | null): void;
180
- _getDispatchContext(): unknown | null | undefined;
181
- _setDispatchContext(dispatch_context: unknown | null | undefined): void;
182
- get event_parent(): BaseEvent | undefined;
183
- get event_children(): BaseEvent[];
184
- get event_descendants(): BaseEvent[];
185
- emit<T extends BaseEvent>(event: T): T;
186
- _cancelPendingChildProcessing(reason: unknown): void;
187
- _markRemainingFirstModeResultCancelled(winner: EventResult): void;
188
- _markCancelled(cause: Error): void;
189
- _notifyEventParentsOfCompletion(): void;
190
- done(options?: EventDoneOptions): Promise<this>;
191
- first(): Promise<EventResultType<this> | undefined>;
192
- eventResultsList(include: EventResultsListInclude<this>, options?: EventResultsListOptions<this>): Promise<Array<EventResultType<this> | undefined>>;
193
- eventResultsList(options?: EventResultsListOptions<this>): Promise<Array<EventResultType<this> | undefined>>;
194
- eventCompleted(): Promise<this>;
195
- _markBlocksParentCompletionIfAwaitedFromEmittingHandler(): void;
196
- _markPending(): this;
197
- eventReset(): this;
198
- _markStarted(started_at?: string | null, notify_hook?: boolean): void;
199
- _markCompleted(force?: boolean, notify_parents?: boolean): void;
200
- private dropFromZeroHistoryBuses;
201
- get event_errors(): unknown[];
202
- private _isFirstModeControlError;
203
- _firstProcessingError(options?: {
204
- ignore_first_mode_control_errors?: boolean;
205
- }): unknown | undefined;
206
- get event_result(): EventResultType<this> | undefined;
207
- _areAllChildrenComplete(visited?: Set<string>): boolean;
208
- private _notifyDoneListeners;
209
- _gc(): void;
210
- }
211
- export {};
@@ -1,26 +0,0 @@
1
- import { BaseEvent } from './base_event.js';
2
- import type { EventClass, EventHandlerCallable, UntypedEventHandlerFunction } from './types.js';
3
- export declare class JSONLEventBridge {
4
- readonly path: string;
5
- readonly poll_interval: number;
6
- readonly name: string;
7
- private readonly inbound_bus;
8
- private running;
9
- private byte_offset;
10
- private pending_line;
11
- private listener_task;
12
- constructor(path: string, poll_interval?: number, name?: string);
13
- on<T extends BaseEvent>(event_pattern: EventClass<T>, handler: EventHandlerCallable<T>): void;
14
- on<T extends BaseEvent>(event_pattern: string | '*', handler: UntypedEventHandlerFunction<T>): void;
15
- emit<T extends BaseEvent>(event: T): Promise<void>;
16
- dispatch<T extends BaseEvent>(event: T): Promise<void>;
17
- start(): Promise<void>;
18
- close(): Promise<void>;
19
- private ensureStarted;
20
- private listenLoop;
21
- private pollNewLines;
22
- private dispatchInboundPayload;
23
- private readAppended;
24
- private dirname;
25
- private loadFs;
26
- }
@@ -1,20 +0,0 @@
1
- import { BaseEvent } from './base_event.js';
2
- import type { EventClass, EventHandlerCallable, UntypedEventHandlerFunction } from './types.js';
3
- export declare class NATSEventBridge {
4
- readonly server: string;
5
- readonly subject: string;
6
- readonly name: string;
7
- private readonly inbound_bus;
8
- private running;
9
- private nc;
10
- private sub_task;
11
- constructor(server: string, subject: string, name?: string);
12
- on<T extends BaseEvent>(event_pattern: EventClass<T>, handler: EventHandlerCallable<T>): void;
13
- on<T extends BaseEvent>(event_pattern: string | '*', handler: UntypedEventHandlerFunction<T>): void;
14
- emit<T extends BaseEvent>(event: T): Promise<void>;
15
- dispatch<T extends BaseEvent>(event: T): Promise<void>;
16
- start(): Promise<void>;
17
- close(): Promise<void>;
18
- private ensureStarted;
19
- private dispatchInboundPayload;
20
- }
@@ -1,31 +0,0 @@
1
- /**
2
- * PostgreSQL LISTEN/NOTIFY + flat-table bridge for forwarding events.
3
- */
4
- import { BaseEvent } from './base_event.js';
5
- import type { EventClass, EventHandlerCallable, UntypedEventHandlerFunction } from './types.js';
6
- export declare class PostgresEventBridge {
7
- readonly table_url: string;
8
- readonly dsn: string;
9
- readonly table: string;
10
- readonly channel: string;
11
- readonly name: string;
12
- private readonly inbound_bus;
13
- private running;
14
- private client;
15
- private table_columns;
16
- private notification_handler;
17
- constructor(table_url: string, channel?: string, name?: string);
18
- on<T extends BaseEvent>(event_pattern: EventClass<T>, handler: EventHandlerCallable<T>): void;
19
- on<T extends BaseEvent>(event_pattern: string | '*', handler: UntypedEventHandlerFunction<T>): void;
20
- emit<T extends BaseEvent>(event: T): Promise<void>;
21
- dispatch<T extends BaseEvent>(event: T): Promise<void>;
22
- start(): Promise<void>;
23
- close(): Promise<void>;
24
- private ensureStarted;
25
- private dispatchByEventId;
26
- private dispatchInboundPayload;
27
- private ensureTableExists;
28
- private ensureBaseIndexes;
29
- private refreshColumnCache;
30
- private ensureColumns;
31
- }
@@ -1,34 +0,0 @@
1
- /**
2
- * Redis pub/sub bridge for forwarding events between runtimes.
3
- *
4
- * Usage:
5
- * // channel from URL path
6
- * const bridge = new RedisEventBridge('redis://user:pass@localhost:6379/1/my_channel')
7
- *
8
- * // explicit channel override
9
- * const bridge2 = new RedisEventBridge('redis://user:pass@localhost:6379/1', 'my_channel')
10
- *
11
- * URL format:
12
- * redis://user:pass@host:6379/<db>/<optional_channel>
13
- */
14
- import { BaseEvent } from './base_event.js';
15
- import type { EventClass, EventHandlerCallable, UntypedEventHandlerFunction } from './types.js';
16
- export declare class RedisEventBridge {
17
- readonly url: string;
18
- readonly channel: string;
19
- readonly name: string;
20
- private readonly inbound_bus;
21
- private running;
22
- private start_promise;
23
- private redis_pub;
24
- private redis_sub;
25
- constructor(redis_url: string, channel?: string, name?: string);
26
- on<T extends BaseEvent>(event_pattern: EventClass<T>, handler: EventHandlerCallable<T>): void;
27
- on<T extends BaseEvent>(event_pattern: string | '*', handler: UntypedEventHandlerFunction<T>): void;
28
- emit<T extends BaseEvent>(event: T): Promise<void>;
29
- dispatch<T extends BaseEvent>(event: T): Promise<void>;
30
- start(): Promise<void>;
31
- close(): Promise<void>;
32
- private ensureStarted;
33
- private dispatchInboundPayload;
34
- }
@@ -1,30 +0,0 @@
1
- import { BaseEvent } from './base_event.js';
2
- import type { EventClass, EventHandlerCallable, UntypedEventHandlerFunction } from './types.js';
3
- export declare class SQLiteEventBridge {
4
- readonly path: string;
5
- readonly table: string;
6
- readonly poll_interval: number;
7
- readonly name: string;
8
- private readonly inbound_bus;
9
- private running;
10
- private last_seen_event_created_at;
11
- private last_seen_event_id;
12
- private listener_task;
13
- private start_task;
14
- private db;
15
- private table_columns;
16
- constructor(path: string, table?: string, poll_interval?: number, name?: string);
17
- on<T extends BaseEvent>(event_pattern: EventClass<T>, handler: EventHandlerCallable<T>): void;
18
- on<T extends BaseEvent>(event_pattern: string | '*', handler: UntypedEventHandlerFunction<T>): void;
19
- emit<T extends BaseEvent>(event: T): Promise<void>;
20
- dispatch<T extends BaseEvent>(event: T): Promise<void>;
21
- start(): Promise<void>;
22
- close(): Promise<void>;
23
- private ensureStarted;
24
- private listenLoop;
25
- private dispatchInboundPayload;
26
- private refreshColumnCache;
27
- private ensureColumns;
28
- private ensureBaseIndexes;
29
- private setCursorToLatestRow;
30
- }
@@ -1,125 +0,0 @@
1
- import { BaseEvent, type BaseEventJSON } from './base_event.js';
2
- import { EventHistory } from './event_history.js';
3
- import { EventResult } from './event_result.js';
4
- import { AsyncLock, type EventConcurrencyMode, type EventHandlerConcurrencyMode, type EventHandlerCompletionMode, LockManager } from './lock_manager.js';
5
- import { EventHandler, type EphemeralFindEventHandler, type EventHandlerJSON } from './event_handler.js';
6
- import type { EventBusMiddleware, EventBusMiddlewareInput } from './middlewares.js';
7
- import type { EventClass, EventHandlerCallable, EventPattern, FindOptions, UntypedEventHandlerFunction } from './types.js';
8
- export type EventBusOptions = {
9
- id?: string;
10
- max_history_size?: number | null;
11
- max_history_drop?: boolean;
12
- event_concurrency?: EventConcurrencyMode | null;
13
- event_timeout?: number | null;
14
- event_slow_timeout?: number | null;
15
- event_handler_concurrency?: EventHandlerConcurrencyMode | null;
16
- event_handler_completion?: EventHandlerCompletionMode;
17
- event_handler_slow_timeout?: number | null;
18
- event_handler_detect_file_paths?: boolean;
19
- middlewares?: EventBusMiddlewareInput[];
20
- };
21
- export type EventBusJSON = {
22
- id: string;
23
- name: string;
24
- max_history_size: number | null;
25
- max_history_drop: boolean;
26
- event_concurrency: EventConcurrencyMode;
27
- event_timeout: number | null;
28
- event_slow_timeout: number | null;
29
- event_handler_concurrency: EventHandlerConcurrencyMode;
30
- event_handler_completion: EventHandlerCompletionMode;
31
- event_handler_slow_timeout: number | null;
32
- event_handler_detect_file_paths: boolean;
33
- handlers: Record<string, EventHandlerJSON>;
34
- handlers_by_key: Record<string, string[]>;
35
- event_history: Record<string, BaseEventJSON>;
36
- pending_event_queue: string[];
37
- };
38
- export declare class GlobalEventBusRegistry {
39
- private _bus_refs;
40
- add(bus: EventBus): void;
41
- discard(bus: EventBus): void;
42
- has(bus: EventBus): boolean;
43
- get size(): number;
44
- [Symbol.iterator](): IterableIterator<EventBus>;
45
- findBusById(bus_id: string): EventBus | undefined;
46
- findEventById(event_id: string): BaseEvent | null;
47
- }
48
- export declare class EventBus {
49
- private static _registry_by_constructor;
50
- private static _global_event_lock_by_constructor;
51
- private static getRegistryForConstructor;
52
- private static getGlobalEventLockForConstructor;
53
- static get all_instances(): GlobalEventBusRegistry;
54
- get all_instances(): GlobalEventBusRegistry;
55
- get _lock_for_event_global_serial(): AsyncLock;
56
- id: string;
57
- name: string;
58
- event_timeout: number | null;
59
- event_concurrency: EventConcurrencyMode;
60
- event_handler_concurrency: EventHandlerConcurrencyMode;
61
- event_handler_completion: EventHandlerCompletionMode;
62
- event_handler_detect_file_paths: boolean;
63
- event_handler_slow_timeout: number | null;
64
- event_slow_timeout: number | null;
65
- handlers: Map<string, EventHandler>;
66
- handlers_by_key: Map<string, string[]>;
67
- event_history: EventHistory<BaseEvent>;
68
- pending_event_queue: BaseEvent[];
69
- in_flight_event_ids: Set<string>;
70
- runloop_running: boolean;
71
- locks: LockManager;
72
- find_waiters: Set<EphemeralFindEventHandler>;
73
- middlewares: EventBusMiddleware[];
74
- private static normalizeMiddlewares;
75
- constructor(name?: string, options?: EventBusOptions);
76
- toString(): string;
77
- scheduleMicrotask(fn: () => void): void;
78
- private _runMiddlewareHook;
79
- onEventChange(event: BaseEvent, status: 'pending' | 'started' | 'completed'): Promise<void>;
80
- onEventResultChange(event: BaseEvent, result: EventResult, status: 'pending' | 'started' | 'completed'): Promise<void>;
81
- private _onEventChange;
82
- private _onEventResultChange;
83
- private _onBusHandlersChange;
84
- private _finalizeEventTimeout;
85
- private _createEventTimeoutError;
86
- private _runHandlersWithTimeout;
87
- private _markEventCompletedIfNeeded;
88
- toJSON(): EventBusJSON;
89
- private static _stubHandlerFn;
90
- private static _upsertHandlerIndex;
91
- private static _linkEventResultHandlers;
92
- static fromJSON(data: unknown): EventBus;
93
- get label(): string;
94
- removeEventFromPendingQueue(event: BaseEvent): number;
95
- isEventInFlightOrQueued(event_id: string): boolean;
96
- removeEventFromHistory(event_id: string): boolean;
97
- destroy(): void;
98
- on<T extends BaseEvent>(event_pattern: EventClass<T>, handler: EventHandlerCallable<T>, options?: Partial<EventHandler>): EventHandler;
99
- on<T extends BaseEvent>(event_pattern: string | '*', handler: UntypedEventHandlerFunction<T>, options?: Partial<EventHandler>): EventHandler;
100
- off<T extends BaseEvent>(event_pattern: EventPattern<T> | '*', handler?: EventHandlerCallable<T> | string | EventHandler): void;
101
- emit<T extends BaseEvent>(event: T): T;
102
- dispatch<T extends BaseEvent>(event: T): T;
103
- find(event_pattern: '*', options?: FindOptions<BaseEvent>): Promise<BaseEvent | null>;
104
- find(event_pattern: '*', where: (event: BaseEvent) => boolean, options?: FindOptions<BaseEvent>): Promise<BaseEvent | null>;
105
- find<T extends BaseEvent>(event_pattern: EventPattern<T>, options?: FindOptions<T>): Promise<T | null>;
106
- find<T extends BaseEvent>(event_pattern: EventPattern<T>, where: (event: T) => boolean, options?: FindOptions<T>): Promise<T | null>;
107
- private _waitForFutureMatch;
108
- waitUntilIdle(timeout?: number | null): Promise<boolean>;
109
- isIdle(): boolean;
110
- isIdleAndQueueEmpty(): boolean;
111
- eventIsChildOf(child_event: BaseEvent, parent_event: BaseEvent): boolean;
112
- eventIsParentOf(parent_event: BaseEvent, child_event: BaseEvent): boolean;
113
- logTree(): string;
114
- findEventById(event_id: string): BaseEvent | null;
115
- private _startRunloop;
116
- private _processEvent;
117
- _processEventImmediately<T extends BaseEvent>(event: T, handler_result?: EventResult): Promise<T>;
118
- private _processEventImmediatelyAcrossBuses;
119
- private _runloop;
120
- _hasProcessedEvent(event: BaseEvent): boolean;
121
- _getEventProxyScopedToThisBus<T extends BaseEvent>(event: T, handler_result?: EventResult): T;
122
- private _resolveFindWaiters;
123
- _getHandlersForEvent(event: BaseEvent): EventHandler[];
124
- private _removeIndexedHandler;
125
- }