abxbus 2.5.1 → 2.5.3

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.
@@ -0,0 +1,211 @@
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 {};
@@ -0,0 +1,26 @@
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
+ }
@@ -0,0 +1,20 @@
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
+ }
@@ -0,0 +1,31 @@
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
+ }
@@ -0,0 +1,34 @@
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
+ }
@@ -0,0 +1,30 @@
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
+ }
@@ -0,0 +1,125 @@
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
+ }
@@ -0,0 +1,139 @@
1
+ import { z } from 'zod';
2
+ import { type EventHandlerCallable, type EventPattern } from './types.js';
3
+ import { BaseEvent } from './base_event.js';
4
+ import type { EventResult } from './event_result.js';
5
+ export type EphemeralFindEventHandler = {
6
+ event_pattern: string | '*';
7
+ matches: (event: BaseEvent) => boolean;
8
+ resolve: (event: BaseEvent) => void;
9
+ timeout_id?: ReturnType<typeof setTimeout>;
10
+ };
11
+ export declare const FindWaiterJSONSchema: z.ZodObject<{
12
+ event_pattern: z.ZodUnion<readonly [z.ZodString, z.ZodLiteral<"*">]>;
13
+ has_timeout: z.ZodBoolean;
14
+ }, z.core.$strict>;
15
+ export type FindWaiterJSON = z.infer<typeof FindWaiterJSONSchema>;
16
+ export declare class FindWaiter {
17
+ static toJSON(waiter: EphemeralFindEventHandler): FindWaiterJSON;
18
+ static fromJSON(data: unknown, overrides?: {
19
+ matches?: (event: BaseEvent) => boolean;
20
+ resolve?: (event: BaseEvent) => void;
21
+ }): EphemeralFindEventHandler;
22
+ static toJSONArray(waiters: Iterable<EphemeralFindEventHandler>): FindWaiterJSON[];
23
+ static fromJSONArray(data: unknown, overrides?: {
24
+ matches?: (event: BaseEvent) => boolean;
25
+ resolve?: (event: BaseEvent) => void;
26
+ }): EphemeralFindEventHandler[];
27
+ }
28
+ export declare const EventHandlerJSONSchema: z.ZodObject<{
29
+ id: z.ZodString;
30
+ eventbus_name: z.ZodString;
31
+ eventbus_id: z.ZodString;
32
+ event_pattern: z.ZodUnion<readonly [z.ZodString, z.ZodLiteral<"*">]>;
33
+ handler_name: z.ZodString;
34
+ handler_file_path: z.ZodOptional<z.ZodNullable<z.ZodString>>;
35
+ handler_timeout: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
36
+ handler_slow_timeout: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
37
+ handler_registered_at: z.ZodString;
38
+ }, z.core.$strict>;
39
+ export type EventHandlerJSON = z.infer<typeof EventHandlerJSONSchema>;
40
+ export declare class EventHandler {
41
+ id: string;
42
+ handler: EventHandlerCallable;
43
+ handler_name: string;
44
+ handler_file_path: string | null;
45
+ handler_timeout?: number | null;
46
+ handler_slow_timeout?: number | null;
47
+ handler_registered_at: string;
48
+ event_pattern: string | '*';
49
+ eventbus_name: string;
50
+ eventbus_id: string;
51
+ constructor(params: {
52
+ id?: string;
53
+ handler: EventHandlerCallable;
54
+ handler_name: string;
55
+ handler_file_path?: string | null;
56
+ handler_timeout?: number | null;
57
+ handler_slow_timeout?: number | null;
58
+ handler_registered_at: string;
59
+ event_pattern: string | '*';
60
+ eventbus_name: string;
61
+ eventbus_id: string;
62
+ });
63
+ get _handler_async(): EventHandlerCallable;
64
+ static computeHandlerId(params: {
65
+ eventbus_id: string;
66
+ handler_name: string;
67
+ handler_file_path?: string | null;
68
+ handler_registered_at: string;
69
+ event_pattern: string | '*';
70
+ }): string;
71
+ static fromCallable<TEvent extends BaseEvent = BaseEvent>(params: {
72
+ handler: EventHandlerCallable<TEvent>;
73
+ event_pattern: EventPattern | '*';
74
+ eventbus_name: string;
75
+ eventbus_id: string;
76
+ detect_handler_file_path?: boolean;
77
+ id?: string;
78
+ handler_file_path?: string | null;
79
+ handler_timeout?: number | null;
80
+ handler_slow_timeout?: number | null;
81
+ handler_registered_at?: string;
82
+ }): EventHandler;
83
+ toString(): string;
84
+ _detectHandlerFilePath(): void;
85
+ toJSON(): EventHandlerJSON;
86
+ static fromJSON(data: unknown, handler?: EventHandlerCallable): EventHandler;
87
+ static toJSONArray(handlers: Iterable<EventHandler>): EventHandlerJSON[];
88
+ static fromJSONArray(data: unknown, handler?: EventHandlerCallable): EventHandler[];
89
+ get eventbus_label(): string;
90
+ }
91
+ export declare class TimeoutError extends Error {
92
+ constructor(message: string);
93
+ }
94
+ export declare class EventHandlerError extends Error {
95
+ event_result: EventResult;
96
+ timeout_seconds: number | null;
97
+ cause: Error;
98
+ constructor(message: string, params: {
99
+ event_result: EventResult;
100
+ timeout_seconds?: number | null;
101
+ cause: Error;
102
+ });
103
+ get event(): BaseEvent;
104
+ get event_type(): string;
105
+ get handler_name(): string;
106
+ get handler_id(): string;
107
+ get event_timeout(): number | null;
108
+ }
109
+ export declare class EventHandlerTimeoutError extends EventHandlerError {
110
+ constructor(message: string, params: {
111
+ event_result: EventResult;
112
+ timeout_seconds?: number | null;
113
+ cause?: Error;
114
+ });
115
+ }
116
+ export declare class EventHandlerCancelledError extends EventHandlerError {
117
+ constructor(message: string, params: {
118
+ event_result: EventResult;
119
+ timeout_seconds?: number | null;
120
+ cause: Error;
121
+ });
122
+ }
123
+ export declare class EventHandlerAbortedError extends EventHandlerError {
124
+ constructor(message: string, params: {
125
+ event_result: EventResult;
126
+ timeout_seconds?: number | null;
127
+ cause: Error;
128
+ });
129
+ }
130
+ export declare class EventHandlerResultSchemaError extends EventHandlerError {
131
+ raw_value: unknown;
132
+ constructor(message: string, params: {
133
+ event_result: EventResult;
134
+ timeout_seconds?: number | null;
135
+ cause: Error;
136
+ raw_value: unknown;
137
+ });
138
+ get expected_schema(): any;
139
+ }
@@ -0,0 +1,45 @@
1
+ import { BaseEvent } from './base_event.js';
2
+ import type { EventPattern, FindWindow } from './types.js';
3
+ export type EventHistoryFindOptions = {
4
+ past?: FindWindow;
5
+ future?: FindWindow;
6
+ child_of?: BaseEvent | null;
7
+ event_is_child_of?: (event: BaseEvent, ancestor: BaseEvent) => boolean;
8
+ wait_for_future_match?: (event_pattern: string | '*', matches: (event: BaseEvent) => boolean, future: FindWindow) => Promise<BaseEvent | null>;
9
+ } & Record<string, unknown>;
10
+ export type EventHistoryTrimOptions<TEvent extends BaseEvent = BaseEvent> = {
11
+ is_event_complete?: (event: TEvent) => boolean;
12
+ on_remove?: (event: TEvent) => void;
13
+ owner_label?: string;
14
+ max_history_size?: number | null;
15
+ max_history_drop?: boolean;
16
+ };
17
+ export declare class EventHistory<TEvent extends BaseEvent = BaseEvent> implements Iterable<[string, TEvent]> {
18
+ max_history_size: number | null;
19
+ max_history_drop: boolean;
20
+ private _events;
21
+ private _warned_about_dropping_uncompleted_events;
22
+ constructor(options?: {
23
+ max_history_size?: number | null;
24
+ max_history_drop?: boolean;
25
+ });
26
+ get size(): number;
27
+ [Symbol.iterator](): Iterator<[string, TEvent]>;
28
+ entries(): IterableIterator<[string, TEvent]>;
29
+ keys(): IterableIterator<string>;
30
+ values(): IterableIterator<TEvent>;
31
+ clear(): void;
32
+ get(event_id: string): TEvent | undefined;
33
+ set(event_id: string, event: TEvent): this;
34
+ has(event_id: string): boolean;
35
+ delete(event_id: string): boolean;
36
+ addEvent(event: TEvent): void;
37
+ getEvent(event_id: string): TEvent | undefined;
38
+ removeEvent(event_id: string): boolean;
39
+ hasEvent(event_id: string): boolean;
40
+ static normalizeEventPattern(event_pattern: EventPattern | '*'): string | '*';
41
+ find(event_pattern: '*', where?: (event: TEvent) => boolean, options?: EventHistoryFindOptions): Promise<TEvent | null>;
42
+ find<TMatch extends TEvent>(event_pattern: EventPattern<TMatch>, where?: (event: TMatch) => boolean, options?: EventHistoryFindOptions): Promise<TMatch | null>;
43
+ trimEventHistory(options?: EventHistoryTrimOptions<TEvent>): number;
44
+ private eventIsChildOf;
45
+ }