abxbus 2.5.6 → 2.5.9
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/dist/cjs/BaseEvent.d.ts +12 -32
- package/dist/cjs/BaseEvent.js +20 -17
- package/dist/cjs/BaseEvent.js.map +2 -2
- package/dist/cjs/CoreClient.d.ts +167 -0
- package/dist/cjs/CoreEventBus.d.ts +334 -0
- package/dist/cjs/LockManager.js +1 -1
- package/dist/cjs/LockManager.js.map +2 -2
- package/dist/cjs/base_event.d.ts +2 -2
- package/dist/cjs/event_handler.d.ts +0 -1
- package/dist/cjs/events_suck.d.ts +7 -14
- package/dist/cjs/events_suck.js +1 -1
- package/dist/cjs/events_suck.js.map +2 -2
- package/dist/cjs/retry.d.ts +2 -0
- package/dist/cjs/retry.js +110 -35
- package/dist/cjs/retry.js.map +3 -3
- package/dist/cjs/types.d.ts +3 -6
- package/dist/cjs/types.js +1 -1
- package/dist/cjs/types.js.map +2 -2
- package/dist/esm/BaseEvent.js +20 -17
- package/dist/esm/BaseEvent.js.map +2 -2
- package/dist/esm/LockManager.js +1 -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/retry.js +110 -35
- package/dist/esm/retry.js.map +3 -3
- package/dist/esm/types.js +1 -1
- package/dist/esm/types.js.map +2 -2
- package/dist/types/BaseEvent.d.ts +12 -32
- package/dist/types/CoreClient.d.ts +167 -0
- package/dist/types/CoreEventBus.d.ts +334 -0
- package/dist/types/base_event.d.ts +2 -2
- package/dist/types/event_handler.d.ts +0 -1
- package/dist/types/events_suck.d.ts +7 -14
- package/dist/types/retry.d.ts +2 -0
- package/dist/types/types.d.ts +3 -6
- package/package.json +1 -1
- package/src/BaseEvent.ts +93 -75
- package/src/LockManager.ts +1 -1
- package/src/events_suck.ts +17 -20
- package/src/retry.ts +132 -38
- package/src/types.ts +4 -5
- package/dist/cjs/bridge_ipc.d.ts +0 -45
- package/dist/cjs/middleware_otel_tracing.d.ts +0 -49
- package/dist/types/bridge_ipc.d.ts +0 -45
- package/dist/types/middleware_otel_tracing.d.ts +0 -49
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import { RustCoreClient, type CoreMessage } from './CoreClient.js';
|
|
2
|
+
import { BaseEvent } from './BaseEvent.js';
|
|
3
|
+
import type { BaseEventJSON } from './BaseEvent.js';
|
|
4
|
+
import { EventHandler } from './EventHandler.js';
|
|
5
|
+
import type { EventHandlerJSON } from './EventHandler.js';
|
|
6
|
+
import { EventResult } from './EventResult.js';
|
|
7
|
+
import { AsyncLock, HandlerLock, type EventConcurrencyMode, type EventHandlerCompletionMode, type EventHandlerConcurrencyMode } from './LockManager.js';
|
|
8
|
+
import type { EventBusMiddlewareInput } from './EventBusMiddleware.js';
|
|
9
|
+
import { type EventHandlerCallable, type EventPattern, type FilterOptions, type FindOptions } from './types.js';
|
|
10
|
+
export type CoreHandler<T extends BaseEvent = BaseEvent> = EventHandlerCallable<T>;
|
|
11
|
+
export type RustCoreEventBusOptions = {
|
|
12
|
+
id?: string;
|
|
13
|
+
core?: RustCoreClient;
|
|
14
|
+
event_concurrency?: EventConcurrencyMode;
|
|
15
|
+
event_handler_concurrency?: EventHandlerConcurrencyMode;
|
|
16
|
+
event_handler_completion?: EventHandlerCompletionMode;
|
|
17
|
+
event_handler_detect_file_paths?: boolean;
|
|
18
|
+
event_timeout?: number | null;
|
|
19
|
+
event_slow_timeout?: number | null;
|
|
20
|
+
event_handler_timeout?: number | null;
|
|
21
|
+
event_handler_slow_timeout?: number | null;
|
|
22
|
+
max_history_size?: number | null;
|
|
23
|
+
max_history_drop?: boolean;
|
|
24
|
+
middlewares?: EventBusMiddlewareInput[];
|
|
25
|
+
background_worker?: boolean;
|
|
26
|
+
};
|
|
27
|
+
export type RustCoreHandlerOptions = {
|
|
28
|
+
id?: string;
|
|
29
|
+
handler_name?: string;
|
|
30
|
+
handler_registered_at?: string;
|
|
31
|
+
handler_file_path?: string | null;
|
|
32
|
+
handler_timeout?: number | null;
|
|
33
|
+
handler_slow_timeout?: number | null;
|
|
34
|
+
handler_concurrency?: EventHandlerConcurrencyMode | null;
|
|
35
|
+
handler_completion?: EventHandlerCompletionMode | null;
|
|
36
|
+
[key: string]: unknown;
|
|
37
|
+
};
|
|
38
|
+
export type RustCoreFilterOptions = {
|
|
39
|
+
limit?: number | null;
|
|
40
|
+
[field: string]: unknown;
|
|
41
|
+
};
|
|
42
|
+
export type RustCoreEventBusJSON = {
|
|
43
|
+
id: string;
|
|
44
|
+
name: string;
|
|
45
|
+
max_history_size: number | null;
|
|
46
|
+
max_history_drop: boolean;
|
|
47
|
+
event_concurrency: EventConcurrencyMode;
|
|
48
|
+
event_timeout: number | null;
|
|
49
|
+
event_slow_timeout: number | null;
|
|
50
|
+
event_handler_concurrency: EventHandlerConcurrencyMode;
|
|
51
|
+
event_handler_completion: EventHandlerCompletionMode;
|
|
52
|
+
event_handler_timeout: number | null;
|
|
53
|
+
event_handler_slow_timeout: number | null;
|
|
54
|
+
event_handler_detect_file_paths: boolean;
|
|
55
|
+
handlers: Record<string, EventHandlerJSON>;
|
|
56
|
+
handlers_by_key: Record<string, string[]>;
|
|
57
|
+
event_history: Record<string, BaseEventJSON>;
|
|
58
|
+
pending_event_queue: string[];
|
|
59
|
+
};
|
|
60
|
+
export declare class CoreEventBusRegistry {
|
|
61
|
+
private _bus_refs;
|
|
62
|
+
private _bus_refs_by_id;
|
|
63
|
+
add(bus: RustCoreEventBus): void;
|
|
64
|
+
discard(bus: RustCoreEventBus): void;
|
|
65
|
+
has(bus: RustCoreEventBus): boolean;
|
|
66
|
+
get size(): number;
|
|
67
|
+
[Symbol.iterator](): IterableIterator<RustCoreEventBus>;
|
|
68
|
+
findBusById(bus_id: string): RustCoreEventBus | undefined;
|
|
69
|
+
findEventById(event_id: string): BaseEvent | null;
|
|
70
|
+
}
|
|
71
|
+
export declare const rustCoreEventBusRegistry: CoreEventBusRegistry;
|
|
72
|
+
export declare class CoreEventHistory implements Iterable<[string, BaseEvent]> {
|
|
73
|
+
max_history_size: number | null;
|
|
74
|
+
max_history_drop: boolean;
|
|
75
|
+
private readonly bus;
|
|
76
|
+
constructor(bus: RustCoreEventBus, options?: {
|
|
77
|
+
max_history_size?: number | null;
|
|
78
|
+
max_history_drop?: boolean;
|
|
79
|
+
});
|
|
80
|
+
get size(): number;
|
|
81
|
+
[Symbol.iterator](): Iterator<[string, BaseEvent]>;
|
|
82
|
+
entries(): IterableIterator<[string, BaseEvent]>;
|
|
83
|
+
keys(): IterableIterator<string>;
|
|
84
|
+
values(): IterableIterator<BaseEvent>;
|
|
85
|
+
clear(): void;
|
|
86
|
+
get(event_id: string): BaseEvent | undefined;
|
|
87
|
+
set(event_id: string, event: BaseEvent): this;
|
|
88
|
+
has(event_id: string): boolean;
|
|
89
|
+
delete(event_id: string): boolean;
|
|
90
|
+
addEvent(event: BaseEvent): void;
|
|
91
|
+
getEvent(event_id: string): BaseEvent | undefined;
|
|
92
|
+
removeEvent(event_id: string): boolean;
|
|
93
|
+
hasEvent(event_id: string): boolean;
|
|
94
|
+
find(event_pattern: '*', options?: FindOptions<BaseEvent>): Promise<BaseEvent | null>;
|
|
95
|
+
find(event_pattern: '*', where: (event: BaseEvent) => boolean, options?: FindOptions<BaseEvent>): Promise<BaseEvent | null>;
|
|
96
|
+
find<T extends BaseEvent>(event_pattern: EventPattern<T>, options?: FindOptions<T>): Promise<T | null>;
|
|
97
|
+
find<T extends BaseEvent>(event_pattern: EventPattern<T>, where: (event: T) => boolean, options?: FindOptions<T>): Promise<T | null>;
|
|
98
|
+
filter(event_pattern: '*', options?: FilterOptions<BaseEvent>): Promise<BaseEvent[]>;
|
|
99
|
+
filter(event_pattern: '*', where: (event: BaseEvent) => boolean, options?: FilterOptions<BaseEvent>): Promise<BaseEvent[]>;
|
|
100
|
+
filter<T extends BaseEvent>(event_pattern: EventPattern<T>, options?: FilterOptions<T>): Promise<T[]>;
|
|
101
|
+
filter<T extends BaseEvent>(event_pattern: EventPattern<T>, where: (event: T) => boolean, options?: FilterOptions<T>): Promise<T[]>;
|
|
102
|
+
}
|
|
103
|
+
export declare class CoreLockFacade {
|
|
104
|
+
private readonly bus;
|
|
105
|
+
private paused_count;
|
|
106
|
+
private pause_waiters;
|
|
107
|
+
private active_handler_results;
|
|
108
|
+
readonly bus_event_lock: AsyncLock;
|
|
109
|
+
constructor(bus: RustCoreEventBus);
|
|
110
|
+
_getActiveHandlerResultForCurrentAsyncContext(): EventResult | undefined;
|
|
111
|
+
_getActiveHandlerResults(): EventResult[];
|
|
112
|
+
_requestRunloopPause(): () => void;
|
|
113
|
+
_waitUntilRunloopResumed(): Promise<void>;
|
|
114
|
+
_isPaused(): boolean;
|
|
115
|
+
_notifyIdleListeners(): void;
|
|
116
|
+
_isAnyHandlerActive(): boolean;
|
|
117
|
+
getLockForEvent(event: BaseEvent): AsyncLock | null;
|
|
118
|
+
waitForIdle(timeout?: number | null): Promise<boolean>;
|
|
119
|
+
_runWithHandlerLock<T>(event: BaseEvent, default_concurrency: EventHandlerConcurrencyMode, fn: (handler_lock: HandlerLock | null) => Promise<T> | T): Promise<T>;
|
|
120
|
+
_runWithHandlerDispatchContext<T>(result: EventResult, fn: () => Promise<T> | T): Promise<T>;
|
|
121
|
+
_runWithEventLock<T>(event: BaseEvent, fn: () => Promise<T> | T, options?: {
|
|
122
|
+
bypass_event_locks?: boolean;
|
|
123
|
+
pre_acquired_lock?: AsyncLock | null;
|
|
124
|
+
}): Promise<T>;
|
|
125
|
+
clear(): void;
|
|
126
|
+
}
|
|
127
|
+
export declare class RustCoreEventBus {
|
|
128
|
+
readonly core: RustCoreClient;
|
|
129
|
+
readonly name: string;
|
|
130
|
+
readonly id: string;
|
|
131
|
+
readonly bus_id: string;
|
|
132
|
+
readonly label: string;
|
|
133
|
+
readonly event_concurrency: EventConcurrencyMode;
|
|
134
|
+
readonly event_handler_concurrency: EventHandlerConcurrencyMode;
|
|
135
|
+
readonly event_handler_completion: EventHandlerCompletionMode;
|
|
136
|
+
readonly event_handler_detect_file_paths: boolean;
|
|
137
|
+
readonly event_timeout: number | null;
|
|
138
|
+
readonly event_slow_timeout: number | null;
|
|
139
|
+
readonly event_handler_timeout: number | null;
|
|
140
|
+
readonly event_handler_slow_timeout: number | null;
|
|
141
|
+
readonly handlers: Map<string, EventHandler>;
|
|
142
|
+
readonly handlers_by_key: Map<string, string[]>;
|
|
143
|
+
readonly event_history: CoreEventHistory;
|
|
144
|
+
readonly locks: CoreLockFacade;
|
|
145
|
+
all_instances: CoreEventBusRegistry;
|
|
146
|
+
_lock_for_event_global_serial: AsyncLock;
|
|
147
|
+
in_flight_event_ids: Set<string>;
|
|
148
|
+
runloop_running: boolean;
|
|
149
|
+
private registered;
|
|
150
|
+
private events;
|
|
151
|
+
private processing;
|
|
152
|
+
private processing_tasks;
|
|
153
|
+
private middlewares;
|
|
154
|
+
private invocation_by_result_id;
|
|
155
|
+
private abort_by_invocation_id;
|
|
156
|
+
private event_types_by_pattern;
|
|
157
|
+
private event_timeout_causes;
|
|
158
|
+
private event_completion_waiters;
|
|
159
|
+
private event_emission_waiters;
|
|
160
|
+
private invocation_worker;
|
|
161
|
+
private background_worker_enabled;
|
|
162
|
+
private foreground_drain_task;
|
|
163
|
+
private foreground_drain_requested;
|
|
164
|
+
private serial_route_pause_releases;
|
|
165
|
+
private completed_event_refs;
|
|
166
|
+
private closed;
|
|
167
|
+
private readonly owns_shared_core;
|
|
168
|
+
private registered_max_history_size;
|
|
169
|
+
private registered_max_history_drop;
|
|
170
|
+
constructor(name?: string, options?: RustCoreEventBusOptions);
|
|
171
|
+
get pending_event_queue(): BaseEvent[];
|
|
172
|
+
get find_waiters(): Set<(event: BaseEvent) => void>;
|
|
173
|
+
set pending_event_queue(events: BaseEvent[]);
|
|
174
|
+
toString(): string;
|
|
175
|
+
defaultsRecord(): Record<string, unknown>;
|
|
176
|
+
private busRecord;
|
|
177
|
+
start(): void;
|
|
178
|
+
private syncBusHistoryPolicy;
|
|
179
|
+
on<T extends BaseEvent>(event_type: EventPattern<T>, handler: CoreHandler<T>, options?: RustCoreHandlerOptions): EventHandler;
|
|
180
|
+
on(event_type: '*', handler: CoreHandler, options?: RustCoreHandlerOptions): EventHandler;
|
|
181
|
+
off<T extends BaseEvent>(event_type: EventPattern<T> | '*', handler?: CoreHandler<T> | string | EventHandler): void;
|
|
182
|
+
emit<T extends BaseEvent>(event: T): T;
|
|
183
|
+
emit(event: Record<string, unknown>): Promise<CoreMessage>;
|
|
184
|
+
private scheduleForegroundDrain;
|
|
185
|
+
_onRunloopResumed(): void;
|
|
186
|
+
private drainForegroundCore;
|
|
187
|
+
private processAvailableCoreMessages;
|
|
188
|
+
private coreEventRecordForEmit;
|
|
189
|
+
private coreForwardControlOptions;
|
|
190
|
+
dispatch<T extends BaseEvent>(event: T): T;
|
|
191
|
+
onEventChange(_event: BaseEvent, _status: 'pending' | 'started' | 'completed'): Promise<void>;
|
|
192
|
+
onEventResultChange(_event: BaseEvent, _result: EventResult, _status: 'pending' | 'started' | 'completed'): Promise<void>;
|
|
193
|
+
hasMiddlewareHooks(): boolean;
|
|
194
|
+
hasEventChangeHooks(): boolean;
|
|
195
|
+
hasEventResultHooks(): boolean;
|
|
196
|
+
_notifyEventChange(event: BaseEvent, status: 'pending' | 'started' | 'completed'): void;
|
|
197
|
+
_notifyEventResultChange(event: BaseEvent, result: EventResult, status: 'pending' | 'started' | 'completed'): void;
|
|
198
|
+
findEventById(event_id: string): BaseEvent | null;
|
|
199
|
+
findLocalEventById(event_id: string): BaseEvent | undefined;
|
|
200
|
+
rememberEvent(event_id: string, event: BaseEvent): void;
|
|
201
|
+
rememberLiveEvent(event_id: string, event: BaseEvent): void;
|
|
202
|
+
forgetEvent(event_id: string): void;
|
|
203
|
+
localEvents(): IterableIterator<BaseEvent>;
|
|
204
|
+
importEventsToCore(events: BaseEvent[], pending_events?: BaseEvent[]): void;
|
|
205
|
+
historyRecords(event_pattern?: string, limit?: number | null): Record<string, unknown>[];
|
|
206
|
+
historyEventIds(event_pattern?: string, limit?: number | null, statuses?: string[] | null): string[];
|
|
207
|
+
coreRecordBelongsToThisBus(record: Record<string, unknown>): boolean;
|
|
208
|
+
activeHandlerResult(): EventResult | null;
|
|
209
|
+
_getEventProxyScopedToThisBus<T extends BaseEvent>(event: T, _handler_result?: EventResult): T;
|
|
210
|
+
_hasProcessedEvent(event: BaseEvent): boolean;
|
|
211
|
+
_getHandlersForEvent(event: BaseEvent): EventHandler[];
|
|
212
|
+
private ensurePendingLocalResults;
|
|
213
|
+
_processEventImmediately<T extends BaseEvent>(event: T, _handler_result?: EventResult): Promise<T>;
|
|
214
|
+
private findActiveInvocationForQueueJump;
|
|
215
|
+
private waitForLocalCompletionPush;
|
|
216
|
+
private waitForLocalCompletionOrProcessingDrain;
|
|
217
|
+
_waitForEventCompletedInQueueOrder<T extends BaseEvent>(event: T): Promise<T>;
|
|
218
|
+
private eventIsOwnedByActiveHandler;
|
|
219
|
+
private findParentInvocationForEvent;
|
|
220
|
+
private findBusForInvocation;
|
|
221
|
+
processUntilEventCompleted(event_id: string, initial_messages?: CoreMessage[] | null): Promise<BaseEvent>;
|
|
222
|
+
private waitForCoreCompletedEvent;
|
|
223
|
+
runUntilEventCompleted(event_id: string): Promise<BaseEvent>;
|
|
224
|
+
_syncEventRuntimeOptions(event: BaseEvent): void;
|
|
225
|
+
waitUntilIdle(timeout?: number | null): Promise<boolean>;
|
|
226
|
+
isIdle(): boolean;
|
|
227
|
+
isIdleAndQueueEmpty(): boolean;
|
|
228
|
+
removeEventFromPendingQueue(_event: BaseEvent): number;
|
|
229
|
+
isEventInFlightOrQueued(event_id: string): boolean;
|
|
230
|
+
removeEventFromHistory(event_id: string): boolean;
|
|
231
|
+
destroy(options?: number | {
|
|
232
|
+
timeout?: number | null;
|
|
233
|
+
clear?: boolean;
|
|
234
|
+
}): Promise<void>;
|
|
235
|
+
eventIsChildOf(child_event: BaseEvent, parent_event: BaseEvent): boolean;
|
|
236
|
+
eventIsParentOf(parent_event: BaseEvent, child_event: BaseEvent): boolean;
|
|
237
|
+
logTree(): string;
|
|
238
|
+
private applyAndRunMessagesUntilEventCompleted;
|
|
239
|
+
private runInvocationMessagesInCoreRouteOrder;
|
|
240
|
+
private completedSnapshotOrEvent;
|
|
241
|
+
private releaseCompletedLocalEvent;
|
|
242
|
+
private trackLocalEventUntilCoreEvictsIt;
|
|
243
|
+
collectEvictedCompletedEventRefs(visible_event_ids?: Set<string> | null): void;
|
|
244
|
+
private pendingQueueEventsFromCore;
|
|
245
|
+
private refreshPendingQueueFromCore;
|
|
246
|
+
private refreshKnownEventsFromCore;
|
|
247
|
+
private applyCoreSnapshotToEvent;
|
|
248
|
+
find<T extends BaseEvent>(event_type: EventPattern<T> | '*', where_or_options?: ((event: T) => boolean) | FindOptions<T>, maybe_options?: FindOptions<T>): Promise<T | null>;
|
|
249
|
+
filter<T extends BaseEvent>(event_type: EventPattern<T> | '*', where_or_options?: ((event: T) => boolean) | FilterOptions<T>, maybe_options?: FilterOptions<T>): Promise<T[]>;
|
|
250
|
+
disconnect(): void;
|
|
251
|
+
close(): void;
|
|
252
|
+
stop(): void;
|
|
253
|
+
scheduleMicrotask(fn: () => void): void;
|
|
254
|
+
toJSON(): RustCoreEventBusJSON;
|
|
255
|
+
eventFromCoreRecord<T extends BaseEvent>(event_type: EventPattern<T> | '*', record: Record<string, unknown>): BaseEvent;
|
|
256
|
+
private isStaleInvocationOutcomeError;
|
|
257
|
+
private eventSnapshotMessageForInvocation;
|
|
258
|
+
private completeHandlerOrSnapshot;
|
|
259
|
+
private completeHandlerNoPatchesOrSnapshot;
|
|
260
|
+
private canUsePatchlessCompletedOutcome;
|
|
261
|
+
private errorHandlerOrSnapshot;
|
|
262
|
+
private activeCoreOutcomeBatch;
|
|
263
|
+
private runWithCoreOutcomeBatch;
|
|
264
|
+
private runWithoutCoreOutcomeBatch;
|
|
265
|
+
private localOutcomePatchMessages;
|
|
266
|
+
private commitInvocationOutcomeMessages;
|
|
267
|
+
private invocationCanUseBatchedOutcome;
|
|
268
|
+
private invocationUsesFirstCompletion;
|
|
269
|
+
private eventForInvocation;
|
|
270
|
+
private runInvocationOutcome;
|
|
271
|
+
private runInvocation;
|
|
272
|
+
private startForegroundCoreSignalTimer;
|
|
273
|
+
private applyExpiredEventTimeout;
|
|
274
|
+
private startForegroundEventTimeoutTimer;
|
|
275
|
+
private startedAtForInvocation;
|
|
276
|
+
private eventTimeoutForInvocation;
|
|
277
|
+
private startForegroundEventSlowWarningTimer;
|
|
278
|
+
private eventSlowTimeoutForInvocation;
|
|
279
|
+
private abortResultForEventTimeout;
|
|
280
|
+
private invocationAbortError;
|
|
281
|
+
private eventTimeoutIpcGraceSeconds;
|
|
282
|
+
private processAvailableAfterHandlerOutcome;
|
|
283
|
+
private releaseSerialRoutePausesForInvocation;
|
|
284
|
+
private applyResultSnapshot;
|
|
285
|
+
private retargetErrorResult;
|
|
286
|
+
private orderedResultRecords;
|
|
287
|
+
private childIdsFromResultRecord;
|
|
288
|
+
private attachResultChildren;
|
|
289
|
+
private normalizeResultError;
|
|
290
|
+
private restoreCoreError;
|
|
291
|
+
private restoreGenericError;
|
|
292
|
+
private publicCoreErrorMessage;
|
|
293
|
+
private causeForCancellation;
|
|
294
|
+
private parentTimeoutEventIdFromMessage;
|
|
295
|
+
private eventTimeoutCause;
|
|
296
|
+
private timeoutSecondsForCoreError;
|
|
297
|
+
private eventTimeoutSecondsForResult;
|
|
298
|
+
private resolveTimeoutOverride;
|
|
299
|
+
private positiveTimeoutFromUnknown;
|
|
300
|
+
private numberFromUnknown;
|
|
301
|
+
private timestampMs;
|
|
302
|
+
private timestampBefore;
|
|
303
|
+
private warnSlowEvent;
|
|
304
|
+
private warnSlowResult;
|
|
305
|
+
runWithActiveHandlerResult<T>(result: EventResult, fn: () => T): T;
|
|
306
|
+
private startWorker;
|
|
307
|
+
private stopWorker;
|
|
308
|
+
private handleWorkerMessages;
|
|
309
|
+
private runAndApplyInvocationMessages;
|
|
310
|
+
private runInvocationMessages;
|
|
311
|
+
private resolveEventCompletionWaiters;
|
|
312
|
+
private notifyEventEmissionWaiters;
|
|
313
|
+
private waitForLocalEventEmission;
|
|
314
|
+
private waitForEventCompleted;
|
|
315
|
+
private localBusesForCoreSession;
|
|
316
|
+
private busForInvocation;
|
|
317
|
+
private applyCoreMessageToLocalBuses;
|
|
318
|
+
private targetBusesForCoreMessage;
|
|
319
|
+
private applyCoreMessage;
|
|
320
|
+
private applyCoreMessageFromSharedCursor;
|
|
321
|
+
private patchBelongsToThisBus;
|
|
322
|
+
private localResultIdExists;
|
|
323
|
+
private applyCoreMessageUnchecked;
|
|
324
|
+
private applyResultRecord;
|
|
325
|
+
private cancelFirstModeLosersForCompletedEvent;
|
|
326
|
+
private _runMiddlewareHook;
|
|
327
|
+
private _onBusHandlersChange;
|
|
328
|
+
private waitForFutureMatch;
|
|
329
|
+
private findCoreRecordCreatedAfter;
|
|
330
|
+
private waitForEventEmittedCancellable;
|
|
331
|
+
}
|
|
332
|
+
export declare const stableCoreBusId: (bus_name: string) => string;
|
|
333
|
+
export declare const uniqueCoreBusId: () => string;
|
|
334
|
+
export declare const defaultCoreBusId: (bus_name: string, registry: CoreEventBusRegistry) => string;
|
|
@@ -27,7 +27,7 @@ export declare const BaseEventSchema: z.ZodObject<{
|
|
|
27
27
|
}>>;
|
|
28
28
|
event_started_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
29
29
|
event_completed_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
30
|
-
event_results: z.ZodOptional<z.
|
|
30
|
+
event_results: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
31
31
|
event_concurrency: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
32
32
|
"global-serial": "global-serial";
|
|
33
33
|
"bus-serial": "bus-serial";
|
|
@@ -133,7 +133,7 @@ export declare class BaseEvent {
|
|
|
133
133
|
}>>;
|
|
134
134
|
event_started_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
135
135
|
event_completed_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
136
|
-
event_results: z.ZodOptional<z.
|
|
136
|
+
event_results: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
137
137
|
event_concurrency: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
138
138
|
"global-serial": "global-serial";
|
|
139
139
|
"bus-serial": "bus-serial";
|
|
@@ -61,7 +61,6 @@ export declare class EventHandler {
|
|
|
61
61
|
eventbus_id: string;
|
|
62
62
|
});
|
|
63
63
|
get _handler_async(): EventHandlerCallable;
|
|
64
|
-
static handlerNameFromCallable(handler: EventHandlerCallable): string;
|
|
65
64
|
static computeHandlerId(params: {
|
|
66
65
|
eventbus_id: string;
|
|
67
66
|
handler_name: string;
|
|
@@ -1,26 +1,19 @@
|
|
|
1
1
|
import { EventBus } from './EventBus.js';
|
|
2
2
|
import { BaseEvent } from './BaseEvent.js';
|
|
3
3
|
import type { EventClass, EventResultType } from './types.js';
|
|
4
|
-
type EventMap = Record<string, EventClass<BaseEvent>>;
|
|
5
|
-
type
|
|
6
|
-
type FunctionMap = Record<string, AnyFn>;
|
|
4
|
+
type EventMap = Record<string, EventClass<BaseEvent, never>>;
|
|
5
|
+
type FunctionMap = Record<string, (...args: never[]) => unknown>;
|
|
7
6
|
type ExtraDict = Record<string, unknown>;
|
|
8
|
-
type EventFieldsFromFn<TFunc extends
|
|
9
|
-
type
|
|
10
|
-
|
|
11
|
-
__event_result_type__?: Awaited<ReturnType<TFunc>>;
|
|
12
|
-
};
|
|
13
|
-
new (data: EventFieldsFromFn<TFunc> & ExtraDict): BaseEvent & EventFieldsFromFn<TFunc> & {
|
|
14
|
-
__event_result_type__?: Awaited<ReturnType<TFunc>>;
|
|
15
|
-
};
|
|
16
|
-
event_type?: string;
|
|
7
|
+
type EventFieldsFromFn<TFunc extends FunctionMap[string]> = Parameters<TFunc> extends [infer TArg, ...unknown[]] ? (TArg extends Record<string, unknown> ? TArg : ExtraDict) : ExtraDict;
|
|
8
|
+
type EventFromFn<TFunc extends FunctionMap[string]> = BaseEvent & EventFieldsFromFn<TFunc> & {
|
|
9
|
+
__event_result_type__?: Awaited<ReturnType<TFunc>>;
|
|
17
10
|
};
|
|
18
11
|
export type GeneratedEvents<TEvents extends FunctionMap> = {
|
|
19
12
|
by_name: {
|
|
20
|
-
[K in keyof TEvents]:
|
|
13
|
+
[K in keyof TEvents]: EventClass<EventFromFn<TEvents[K]>, EventFieldsFromFn<TEvents[K]> & ExtraDict>;
|
|
21
14
|
};
|
|
22
15
|
} & {
|
|
23
|
-
[K in keyof TEvents]:
|
|
16
|
+
[K in keyof TEvents]: EventClass<EventFromFn<TEvents[K]>, EventFieldsFromFn<TEvents[K]> & ExtraDict>;
|
|
24
17
|
};
|
|
25
18
|
type EventInit<TEventClass extends EventClass<BaseEvent>> = [ConstructorParameters<TEventClass>[0]] extends [undefined] ? {} : NonNullable<ConstructorParameters<TEventClass>[0]>;
|
|
26
19
|
type EventMethodArgs<TEventClass extends EventClass<BaseEvent>> = {} extends EventInit<TEventClass> ? [init?: EventInit<TEventClass>, extra?: Record<string, unknown>] : [init: EventInit<TEventClass>, extra?: Record<string, unknown>];
|
package/dist/types/retry.d.ts
CHANGED
|
@@ -19,6 +19,8 @@ export interface RetryOptions {
|
|
|
19
19
|
retry_on_errors?: Array<(new (...args: any[]) => Error) | string | RegExp>;
|
|
20
20
|
/** Per-attempt timeout in seconds. Default: undefined (no per-attempt timeout) */
|
|
21
21
|
timeout?: number | null;
|
|
22
|
+
/** Emit a warning when a decorated call exceeds this many seconds. Default: undefined (disabled) */
|
|
23
|
+
slow_timeout?: number | null;
|
|
22
24
|
/** Maximum concurrent executions sharing this semaphore. Default: undefined (no concurrency limit) */
|
|
23
25
|
semaphore_limit?: number | null;
|
|
24
26
|
/** Semaphore identifier. Functions with the same name share the same concurrency slot pool. Default: function name.
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import type { BaseEvent } from './BaseEvent.js';
|
|
2
|
+
import type { BaseEvent, EventClass as BaseEventClass } from './BaseEvent.js';
|
|
3
3
|
import { type JsonSchema } from './jsonschema.js';
|
|
4
4
|
export type EventStatus = 'pending' | 'started' | 'completed';
|
|
5
|
-
export type EventClass
|
|
6
|
-
|
|
7
|
-
} & (new (...args: any[]) => T);
|
|
8
|
-
export type EventPattern<T extends BaseEvent = BaseEvent> = string | EventClass<T>;
|
|
5
|
+
export type { EventClass } from './BaseEvent.js';
|
|
6
|
+
export type EventPattern<T extends BaseEvent = BaseEvent> = string | BaseEventClass<T>;
|
|
9
7
|
export type EventWithResultSchema<TResult> = BaseEvent & {
|
|
10
8
|
__event_result_type__?: TResult;
|
|
11
9
|
};
|
|
@@ -35,4 +33,3 @@ export declare const isZodSchema: (value: unknown) => value is z.ZodTypeAny;
|
|
|
35
33
|
export declare const eventResultTypeFromConstructor: (value: unknown) => z.ZodTypeAny | undefined;
|
|
36
34
|
export declare const extractZodShape: (raw: Record<string, unknown>) => z.ZodRawShape;
|
|
37
35
|
export declare function normalizeEventResultType(value: unknown): z.ZodTypeAny | undefined;
|
|
38
|
-
export {};
|
package/package.json
CHANGED
package/src/BaseEvent.ts
CHANGED
|
@@ -151,8 +151,7 @@ type EventPayloadShape<TShape extends z.ZodRawShape> = {
|
|
|
151
151
|
}
|
|
152
152
|
type EventPayload<TShape extends z.ZodRawShape> =
|
|
153
153
|
EventPayloadShape<TShape> extends Record<string, never> ? {} : z.infer<z.ZodObject<EventPayloadShape<TShape>>>
|
|
154
|
-
type
|
|
155
|
-
| 'class'
|
|
154
|
+
type EventClassMetadataFieldName =
|
|
156
155
|
| 'fromJSON'
|
|
157
156
|
| 'prototype'
|
|
158
157
|
| 'event_schema'
|
|
@@ -165,7 +164,7 @@ type EventModelFields<TShape extends z.ZodRawShape> = {
|
|
|
165
164
|
readonly [K in keyof TShape]: TShape[K]
|
|
166
165
|
}
|
|
167
166
|
type StaticEventDefaultValues<TShape extends z.ZodRawShape> = {
|
|
168
|
-
readonly [K in keyof TShape as K extends
|
|
167
|
+
readonly [K in keyof TShape as K extends EventClassMetadataFieldName
|
|
169
168
|
? never
|
|
170
169
|
: TShape[K] extends StaticDefaultSchema
|
|
171
170
|
? K
|
|
@@ -243,7 +242,7 @@ type ShortcutZodModelFields<TShape> = {
|
|
|
243
242
|
[K in keyof ShortcutModelFields<TShape>]: ShortcutModelFields<TShape>[K] extends z.ZodTypeAny ? ShortcutModelFields<TShape>[K] : never
|
|
244
243
|
}
|
|
245
244
|
type ShortcutStaticDefaultValues<TShape, TModelFields extends z.ZodRawShape> = StaticEventDefaultValues<TModelFields> & {
|
|
246
|
-
readonly [K in keyof TShape as K extends
|
|
245
|
+
readonly [K in keyof TShape as K extends EventClassMetadataFieldName ? never : TShape[K] extends z.ZodTypeAny ? never : K]: TShape[K]
|
|
247
246
|
}
|
|
248
247
|
export type EventResultInclude<TEvent extends BaseEvent> = (
|
|
249
248
|
result: EventResult<TEvent>['result'],
|
|
@@ -271,45 +270,22 @@ type EventResultUpdateOptions<TEvent extends BaseEvent> = {
|
|
|
271
270
|
|
|
272
271
|
const ROOT_EVENTBUS_ID = '00000000-0000-0000-0000-000000000000'
|
|
273
272
|
|
|
274
|
-
export type
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
export type EventFactory<
|
|
283
|
-
TShape extends z.ZodRawShape,
|
|
284
|
-
TResult = unknown,
|
|
285
|
-
TStaticFields = StaticEventDefaultValues<TShape>,
|
|
273
|
+
export type EventClass<
|
|
274
|
+
TEvent extends BaseEvent = BaseEvent,
|
|
275
|
+
TInit = never,
|
|
276
|
+
TSchema extends z.ZodTypeAny = AnyEventSchema,
|
|
277
|
+
TModelFields extends z.ZodRawShape = z.ZodRawShape,
|
|
278
|
+
TResultSchema extends z.ZodTypeAny | undefined = z.ZodTypeAny | undefined,
|
|
279
|
+
TStaticFields = {},
|
|
286
280
|
> = TStaticFields & {
|
|
287
|
-
(...args: OptionalFactoryArgs<
|
|
288
|
-
new (...args: OptionalFactoryArgs<
|
|
289
|
-
event_schema: EventSchema<TShape>
|
|
290
|
-
model_fields: EventModelFields<TShape>
|
|
291
|
-
class: EventFactoryClass<TShape, TResult>
|
|
292
|
-
event_type: string
|
|
293
|
-
event_version: string
|
|
294
|
-
event_result_type: ResultTypeSchemaFromShape<TShape>
|
|
295
|
-
fromJSON: (data: unknown) => EventWithResultSchema<TResult> & EventPayload<TShape>
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
export type SchemaEventFactoryClass<TSchema extends AnyEventSchema, TResult = unknown> = (new (
|
|
299
|
-
...args: OptionalFactoryArgs<EventInitFromSchema<TSchema>>
|
|
300
|
-
) => EventWithResultSchema<TResult> & EventPayloadFromSchema<TSchema>) &
|
|
301
|
-
StaticEventDefaultValuesFromSchema<TSchema> & { event_schema: TSchema; model_fields: EventModelFieldsFromSchema<TSchema> }
|
|
302
|
-
|
|
303
|
-
export type SchemaEventFactory<TSchema extends AnyEventSchema, TResult = unknown> = StaticEventDefaultValuesFromSchema<TSchema> & {
|
|
304
|
-
(...args: OptionalFactoryArgs<EventInitFromSchema<TSchema>>): EventWithResultSchema<TResult> & EventPayloadFromSchema<TSchema>
|
|
305
|
-
new (...args: OptionalFactoryArgs<EventInitFromSchema<TSchema>>): EventWithResultSchema<TResult> & EventPayloadFromSchema<TSchema>
|
|
281
|
+
(...args: OptionalFactoryArgs<TInit>): TEvent
|
|
282
|
+
new (...args: OptionalFactoryArgs<TInit>): TEvent
|
|
306
283
|
event_schema: TSchema
|
|
307
|
-
model_fields:
|
|
308
|
-
class: SchemaEventFactoryClass<TSchema, TResult>
|
|
284
|
+
model_fields: TModelFields
|
|
309
285
|
event_type: string
|
|
310
286
|
event_version: string
|
|
311
|
-
event_result_type:
|
|
312
|
-
fromJSON: (data: unknown) =>
|
|
287
|
+
event_result_type: TResultSchema
|
|
288
|
+
fromJSON: (data: unknown) => TEvent
|
|
313
289
|
}
|
|
314
290
|
|
|
315
291
|
type ZodShapeFrom<TShape extends Record<string, unknown>> = {
|
|
@@ -680,20 +656,56 @@ export class BaseEvent {
|
|
|
680
656
|
static extend<TSchema extends z.ZodObject<z.ZodRawShape>>(
|
|
681
657
|
event_type: string,
|
|
682
658
|
event_schema: TSchema
|
|
683
|
-
):
|
|
659
|
+
): EventClass<
|
|
660
|
+
EventWithResultSchema<ResultSchemaFromEventSchema<TSchema>> & EventPayloadFromSchema<TSchema>,
|
|
661
|
+
EventInitFromSchema<TSchema>,
|
|
662
|
+
TSchema,
|
|
663
|
+
EventModelFieldsFromSchema<TSchema>,
|
|
664
|
+
ResultTypeSchemaFromEventSchema<TSchema>,
|
|
665
|
+
StaticEventDefaultValuesFromSchema<TSchema>
|
|
666
|
+
>
|
|
684
667
|
static extend<const TShape extends Record<string, unknown>>(
|
|
685
668
|
event_type: string,
|
|
686
669
|
shape?: TShape
|
|
687
|
-
):
|
|
688
|
-
ShortcutZodModelFields<TShape
|
|
689
|
-
|
|
670
|
+
): EventClass<
|
|
671
|
+
EventWithResultSchema<ResultSchemaFromShape<ShortcutZodModelFields<TShape>>> & EventPayload<ShortcutZodModelFields<TShape>>,
|
|
672
|
+
EventInit<ShortcutZodModelFields<TShape>>,
|
|
673
|
+
EventSchema<ShortcutZodModelFields<TShape>>,
|
|
674
|
+
EventModelFields<ShortcutZodModelFields<TShape>>,
|
|
675
|
+
ResultTypeSchemaFromShape<ShortcutZodModelFields<TShape>>,
|
|
690
676
|
ShortcutStaticDefaultValues<TShape, ShortcutZodModelFields<TShape>>
|
|
691
677
|
>
|
|
692
|
-
static extend<TShape extends z.ZodRawShape>(
|
|
678
|
+
static extend<TShape extends z.ZodRawShape>(
|
|
679
|
+
event_type: string,
|
|
680
|
+
shape?: TShape
|
|
681
|
+
): EventClass<
|
|
682
|
+
EventWithResultSchema<ResultSchemaFromShape<TShape>> & EventPayload<TShape>,
|
|
683
|
+
EventInit<TShape>,
|
|
684
|
+
EventSchema<TShape>,
|
|
685
|
+
EventModelFields<TShape>,
|
|
686
|
+
ResultTypeSchemaFromShape<TShape>,
|
|
687
|
+
StaticEventDefaultValues<TShape>
|
|
688
|
+
>
|
|
693
689
|
static extend<const TShape extends Record<string, unknown>>(
|
|
694
690
|
event_type: string,
|
|
695
691
|
shape?: TShape
|
|
696
|
-
):
|
|
692
|
+
):
|
|
693
|
+
| EventClass<
|
|
694
|
+
EventWithResultSchema<ResultSchemaFromShape<ZodShapeFrom<TShape>>> & EventPayload<ZodShapeFrom<TShape>>,
|
|
695
|
+
EventInit<ZodShapeFrom<TShape>>,
|
|
696
|
+
EventSchema<ZodShapeFrom<TShape>>,
|
|
697
|
+
EventModelFields<ZodShapeFrom<TShape>>,
|
|
698
|
+
ResultTypeSchemaFromShape<ZodShapeFrom<TShape>>,
|
|
699
|
+
StaticEventDefaultValues<ZodShapeFrom<TShape>>
|
|
700
|
+
>
|
|
701
|
+
| EventClass<
|
|
702
|
+
EventWithResultSchema<ResultSchemaFromEventSchema<AnyEventSchema>> & EventPayloadFromSchema<AnyEventSchema>,
|
|
703
|
+
EventInitFromSchema<AnyEventSchema>,
|
|
704
|
+
AnyEventSchema,
|
|
705
|
+
EventModelFieldsFromSchema<AnyEventSchema>,
|
|
706
|
+
ResultTypeSchemaFromEventSchema<AnyEventSchema>,
|
|
707
|
+
StaticEventDefaultValuesFromSchema<AnyEventSchema>
|
|
708
|
+
> {
|
|
697
709
|
const built = buildFullEventSchema(event_type, shape ?? {})
|
|
698
710
|
const full_schema = built.event_schema
|
|
699
711
|
const event_parse_schema = built.event_parse_schema
|
|
@@ -701,41 +713,47 @@ export class BaseEvent {
|
|
|
701
713
|
const event_result_type = built.event_result_type
|
|
702
714
|
const event_version = built.event_version
|
|
703
715
|
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
static
|
|
707
|
-
static
|
|
708
|
-
static
|
|
709
|
-
static
|
|
710
|
-
static
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
super(data as BaseEventInit<Record<string, unknown>>)
|
|
716
|
+
const EventClass = class extends BaseEvent {
|
|
717
|
+
static override event_schema = full_schema as EventSchema<ZodShapeFrom<TShape>>
|
|
718
|
+
static override model_fields = full_schema.shape as EventModelFields<ZodShapeFrom<TShape>>
|
|
719
|
+
static override _event_parse_schema = event_parse_schema
|
|
720
|
+
static override event_type = event_type
|
|
721
|
+
static override event_version = event_version ?? BaseEvent.event_version
|
|
722
|
+
static override event_result_type = event_result_type
|
|
723
|
+
|
|
724
|
+
constructor(data?: EventInit<ZodShapeFrom<TShape>>) {
|
|
725
|
+
super(data)
|
|
715
726
|
}
|
|
716
727
|
}
|
|
717
728
|
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
function EventFactory(data?: EventInit<ZodShapeFrom<TShape>>): FactoryResult {
|
|
721
|
-
return new ExtendedEvent(data) as FactoryResult
|
|
722
|
-
}
|
|
729
|
+
Object.defineProperty(EventClass, 'name', { value: event_type, configurable: true })
|
|
730
|
+
defineStaticEventFields(EventClass, static_field_defaults)
|
|
723
731
|
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
EventFactory.prototype = ExtendedEvent.prototype
|
|
734
|
-
defineStaticEventFields(ExtendedEvent, static_field_defaults)
|
|
735
|
-
defineStaticEventFields(EventFactory, static_field_defaults)
|
|
736
|
-
EVENT_TYPE_REGISTRY.set(event_type, ExtendedEvent)
|
|
732
|
+
let CallableEventClass: typeof EventClass
|
|
733
|
+
CallableEventClass = new Proxy(EventClass, {
|
|
734
|
+
apply(target, _this_arg, args) {
|
|
735
|
+
return Reflect.construct(target, args, target)
|
|
736
|
+
},
|
|
737
|
+
construct(target, args, new_target) {
|
|
738
|
+
return Reflect.construct(target, args, new_target === CallableEventClass ? target : new_target)
|
|
739
|
+
},
|
|
740
|
+
})
|
|
737
741
|
|
|
738
|
-
|
|
742
|
+
Object.defineProperty(EventClass.prototype, 'constructor', {
|
|
743
|
+
value: CallableEventClass,
|
|
744
|
+
writable: true,
|
|
745
|
+
configurable: true,
|
|
746
|
+
})
|
|
747
|
+
EVENT_TYPE_REGISTRY.set(event_type, CallableEventClass as unknown as typeof BaseEvent)
|
|
748
|
+
|
|
749
|
+
return CallableEventClass as unknown as EventClass<
|
|
750
|
+
EventWithResultSchema<ResultSchemaFromShape<ZodShapeFrom<TShape>>> & EventPayload<ZodShapeFrom<TShape>>,
|
|
751
|
+
EventInit<ZodShapeFrom<TShape>>,
|
|
752
|
+
EventSchema<ZodShapeFrom<TShape>>,
|
|
753
|
+
EventModelFields<ZodShapeFrom<TShape>>,
|
|
754
|
+
ResultTypeSchemaFromShape<ZodShapeFrom<TShape>>,
|
|
755
|
+
StaticEventDefaultValues<ZodShapeFrom<TShape>>
|
|
756
|
+
>
|
|
739
757
|
}
|
|
740
758
|
|
|
741
759
|
static fromJSON<T extends typeof BaseEvent>(this: T, data: unknown): InstanceType<T> {
|