abxbus 2.5.0 → 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.
- package/dist/cjs/BaseEvent.d.ts +2 -1
- 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/base_event.d.ts +2 -2
- package/dist/cjs/event_handler.d.ts +0 -1
- package/dist/cjs/retry.d.ts +8 -1
- package/dist/cjs/retry.js +283 -14
- package/dist/cjs/retry.js.map +2 -2
- package/dist/esm/BaseEvent.js.map +2 -2
- package/dist/esm/retry.js +283 -14
- package/dist/esm/retry.js.map +2 -2
- package/dist/types/BaseEvent.d.ts +2 -1
- 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/retry.d.ts +8 -1
- package/package.json +1 -1
- package/src/BaseEvent.ts +5 -1
- package/src/retry.ts +365 -22
- 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,167 @@
|
|
|
1
|
+
export declare const CORE_PROTOCOL_VERSION = 1;
|
|
2
|
+
export type ProtocolEnvelope<TMessage = Record<string, unknown>> = {
|
|
3
|
+
protocol_version: number;
|
|
4
|
+
session_id: string;
|
|
5
|
+
request_id?: string;
|
|
6
|
+
last_patch_seq?: number;
|
|
7
|
+
message: TMessage;
|
|
8
|
+
};
|
|
9
|
+
export type CoreMessage = Record<string, unknown> & {
|
|
10
|
+
type?: string;
|
|
11
|
+
};
|
|
12
|
+
type FastCompletedHandlerOptions = {
|
|
13
|
+
result_is_event_reference?: boolean;
|
|
14
|
+
process_route_after?: boolean;
|
|
15
|
+
process_available_after?: boolean;
|
|
16
|
+
compact_response?: boolean;
|
|
17
|
+
include_patches?: boolean;
|
|
18
|
+
};
|
|
19
|
+
type ForwardEventOptions = {
|
|
20
|
+
parent_invocation_id?: string | null;
|
|
21
|
+
block_parent_completion?: boolean;
|
|
22
|
+
pause_parent_route?: boolean;
|
|
23
|
+
event_timeout?: number | null;
|
|
24
|
+
event_slow_timeout?: number | null;
|
|
25
|
+
event_concurrency?: string | null;
|
|
26
|
+
event_handler_timeout?: number | null;
|
|
27
|
+
event_handler_slow_timeout?: number | null;
|
|
28
|
+
event_handler_concurrency?: string | null;
|
|
29
|
+
event_handler_completion?: string | null;
|
|
30
|
+
event_blocks_parent_completion?: boolean | null;
|
|
31
|
+
};
|
|
32
|
+
export declare class RustCoreClient {
|
|
33
|
+
private static shared_named_clients;
|
|
34
|
+
private static cleanup_registered;
|
|
35
|
+
static acquireNamed(bus_name: string): RustCoreClient;
|
|
36
|
+
static releaseNamed(client: RustCoreClient, options?: {
|
|
37
|
+
stopCore?: boolean;
|
|
38
|
+
}): void;
|
|
39
|
+
private static registerProcessCleanup;
|
|
40
|
+
static stopIdleNamedClients(): void;
|
|
41
|
+
readonly session_id: string;
|
|
42
|
+
readonly command: string;
|
|
43
|
+
readonly args: string[];
|
|
44
|
+
readonly socket_path: string;
|
|
45
|
+
private process;
|
|
46
|
+
private rpc;
|
|
47
|
+
private last_patch_seq;
|
|
48
|
+
private request_seq;
|
|
49
|
+
private release_transport_timer;
|
|
50
|
+
private readonly kill_process_on_close;
|
|
51
|
+
private readonly owns_socket_path;
|
|
52
|
+
private readonly bus_name;
|
|
53
|
+
private readonly session_id_bytes;
|
|
54
|
+
constructor(options?: {
|
|
55
|
+
command?: string;
|
|
56
|
+
args?: string[];
|
|
57
|
+
session_id?: string;
|
|
58
|
+
socket_path?: string;
|
|
59
|
+
bus_name?: string;
|
|
60
|
+
});
|
|
61
|
+
request(message: CoreMessage, options?: {
|
|
62
|
+
includePatches?: boolean;
|
|
63
|
+
advancePatchSeq?: boolean;
|
|
64
|
+
advancePatchSeqWhenNoPatches?: boolean;
|
|
65
|
+
}): ProtocolEnvelope<CoreMessage>[];
|
|
66
|
+
private requestOnce;
|
|
67
|
+
requestMessages(message: CoreMessage, options?: {
|
|
68
|
+
includePatches?: boolean;
|
|
69
|
+
advancePatchSeq?: boolean;
|
|
70
|
+
advancePatchSeqWhenNoPatches?: boolean;
|
|
71
|
+
}): CoreMessage[];
|
|
72
|
+
getPatchSeq(): number;
|
|
73
|
+
setPatchSeq(last_patch_seq: number): void;
|
|
74
|
+
filterUnseenPatchMessages(messages: CoreMessage[]): CoreMessage[];
|
|
75
|
+
ackPatchMessages(messages: CoreMessage | CoreMessage[]): void;
|
|
76
|
+
registerBus(bus: Record<string, unknown>): CoreMessage[];
|
|
77
|
+
unregisterBus(bus_id: string): CoreMessage[];
|
|
78
|
+
registerHandler(handler: Record<string, unknown>): CoreMessage[];
|
|
79
|
+
importBusSnapshot(snapshot: {
|
|
80
|
+
bus: Record<string, unknown>;
|
|
81
|
+
handlers: Record<string, unknown>[];
|
|
82
|
+
events: Record<string, unknown>[];
|
|
83
|
+
pending_event_ids: string[];
|
|
84
|
+
}): CoreMessage[];
|
|
85
|
+
unregisterHandler(handler_id: string): CoreMessage[];
|
|
86
|
+
disconnectHost(host_id?: string | null): CoreMessage[];
|
|
87
|
+
closeSession(): void;
|
|
88
|
+
stopCore(): CoreMessage[];
|
|
89
|
+
emitEvent(event: Record<string, unknown>, bus_id: string, defer_start?: boolean, compact_response?: boolean, options?: {
|
|
90
|
+
parent_invocation_id?: string | null;
|
|
91
|
+
block_parent_completion?: boolean;
|
|
92
|
+
pause_parent_route?: boolean;
|
|
93
|
+
}): CoreMessage[];
|
|
94
|
+
forwardEvent(event_id: string, bus_id: string, defer_start?: boolean, compact_response?: boolean, options?: ForwardEventOptions): CoreMessage[];
|
|
95
|
+
updateEventOptions(event_id: string, options: {
|
|
96
|
+
event_handler_completion?: string | null;
|
|
97
|
+
event_blocks_parent_completion?: boolean | null;
|
|
98
|
+
}): CoreMessage[];
|
|
99
|
+
processNextRoute(bus_id: string, limit?: number | null, compact_response?: boolean): CoreMessage[];
|
|
100
|
+
waitInvocations(bus_id?: string | null, limit?: number | null): CoreMessage[];
|
|
101
|
+
waitEventCompleted(event_id: string): CoreMessage[];
|
|
102
|
+
waitEventEmitted(bus_id: string, event_pattern?: string, seen_event_ids?: string[], after_event_id?: string | null, after_created_at?: string | null): CoreMessage[];
|
|
103
|
+
waitBusIdle(bus_id: string, timeout?: number | null): boolean;
|
|
104
|
+
processRoute(route_id: string, limit?: number | null, compact_response?: boolean): CoreMessage[];
|
|
105
|
+
awaitEvent(event_id: string, parent_invocation_id?: string | null): CoreMessage[];
|
|
106
|
+
queueJumpEvent(event_id: string, parent_invocation_id: string, block_parent_completion?: boolean, pause_parent_route?: boolean): CoreMessage[];
|
|
107
|
+
getEvent(event_id: string): Record<string, unknown> | null;
|
|
108
|
+
listEvents(event_pattern?: string, limit?: number | null, bus_id?: string | null): Record<string, unknown>[];
|
|
109
|
+
listEventIds(event_pattern?: string, limit?: number | null, bus_id?: string | null, statuses?: string[] | null): string[];
|
|
110
|
+
listPendingEventIds(bus_id: string): string[];
|
|
111
|
+
completeHandler(invocation: Record<string, unknown>, value: unknown, options?: FastCompletedHandlerOptions): CoreMessage[];
|
|
112
|
+
completeHandlerNoPatches(invocation: Record<string, unknown>, value: unknown, options?: FastCompletedHandlerOptions): CoreMessage[];
|
|
113
|
+
private requestFastCompletedHandler;
|
|
114
|
+
private requestFastRegisterHandler;
|
|
115
|
+
private requestFastUnregisterHandler;
|
|
116
|
+
private requestFastQueueJumpEvent;
|
|
117
|
+
private waitFastCoreAck;
|
|
118
|
+
private waitFastCoreMessages;
|
|
119
|
+
private readFastPatchSeq;
|
|
120
|
+
private requiredString;
|
|
121
|
+
private requiredUint64;
|
|
122
|
+
completeHandlerOutcomes(outcomes: Record<string, unknown>[], options?: {
|
|
123
|
+
compact_response?: boolean;
|
|
124
|
+
}): CoreMessage[];
|
|
125
|
+
completedHandlerOutcome(value: unknown, result_is_event_reference?: boolean): CoreMessage;
|
|
126
|
+
handlerOutcomeRecord(invocation: Record<string, unknown>, outcome: CoreMessage, options?: {
|
|
127
|
+
process_available_after?: boolean;
|
|
128
|
+
}): CoreMessage;
|
|
129
|
+
errorHandler(invocation: Record<string, unknown>, error: unknown, options?: {
|
|
130
|
+
process_route_after?: boolean;
|
|
131
|
+
process_available_after?: boolean;
|
|
132
|
+
compact_response?: boolean;
|
|
133
|
+
}): CoreMessage[];
|
|
134
|
+
erroredHandlerOutcome(error: unknown): CoreMessage;
|
|
135
|
+
close(): void;
|
|
136
|
+
closeTransportOnly(options?: {
|
|
137
|
+
closeSession?: boolean;
|
|
138
|
+
}): void;
|
|
139
|
+
disconnect(): void;
|
|
140
|
+
stop(): void;
|
|
141
|
+
private cleanupFailedSpawn;
|
|
142
|
+
private connect;
|
|
143
|
+
private tryConnect;
|
|
144
|
+
private connectNamedBus;
|
|
145
|
+
private requestNamedSession;
|
|
146
|
+
private requestNamedStop;
|
|
147
|
+
private waitForNamedDaemonStopped;
|
|
148
|
+
private ensureNamedDaemon;
|
|
149
|
+
private coreProcessEnv;
|
|
150
|
+
private ensureRpc;
|
|
151
|
+
private configureRpc;
|
|
152
|
+
private closeTransport;
|
|
153
|
+
private cleanupOwnedSocketPath;
|
|
154
|
+
releaseTransportSoon(): void;
|
|
155
|
+
private sendCloseSession;
|
|
156
|
+
}
|
|
157
|
+
export declare const defaultCoreCommand: (socket_path: string, options?: {
|
|
158
|
+
daemon?: boolean;
|
|
159
|
+
}) => {
|
|
160
|
+
command: string;
|
|
161
|
+
args: string[];
|
|
162
|
+
};
|
|
163
|
+
export declare const stableCoreSocketPath: (_bus_name: string) => string;
|
|
164
|
+
export declare const coreNamespace: () => string;
|
|
165
|
+
export declare const stableCoreSessionSocketPath: (bus_name: string) => string;
|
|
166
|
+
export declare const namedCoreLockPath: (socket_path: string) => string;
|
|
167
|
+
export {};
|
|
@@ -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;
|
package/dist/types/retry.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
type SemaphoreScope = 'multiprocess' | 'global' | 'class' | 'instance';
|
|
2
|
+
type AnyFunction = (this: any, ...args: any[]) => any;
|
|
3
|
+
type LegacyMethodDescriptor = TypedPropertyDescriptor<AnyFunction>;
|
|
4
|
+
type RetryDecorator = {
|
|
5
|
+
<T extends AnyFunction>(target: T): T;
|
|
6
|
+
<T extends AnyFunction>(target: T, context: ClassMethodDecoratorContext): T;
|
|
7
|
+
(target: object, property_key: string | symbol, descriptor: LegacyMethodDescriptor): LegacyMethodDescriptor;
|
|
8
|
+
};
|
|
2
9
|
export interface RetryOptions {
|
|
3
10
|
/** Total number of attempts including the initial call (1 = no retry, 3 = up to 2 retries). Default: 1 */
|
|
4
11
|
max_attempts?: number;
|
|
@@ -51,5 +58,5 @@ export declare class SemaphoreTimeoutError extends Error {
|
|
|
51
58
|
}
|
|
52
59
|
/** Reset the global semaphore registry. Useful in tests. */
|
|
53
60
|
export declare function clearSemaphoreRegistry(): void;
|
|
54
|
-
export declare function retry(options?: RetryOptions):
|
|
61
|
+
export declare function retry(options?: RetryOptions): RetryDecorator;
|
|
55
62
|
export {};
|
package/package.json
CHANGED
package/src/BaseEvent.ts
CHANGED
|
@@ -161,6 +161,7 @@ type ResultTypeFromEventResultTypeInput<TInput> = TInput extends z.ZodTypeAny
|
|
|
161
161
|
: unknown
|
|
162
162
|
|
|
163
163
|
type ResultSchemaFromShape<TShape> = TShape extends { event_result_type: infer S } ? ResultTypeFromEventResultTypeInput<S> : unknown
|
|
164
|
+
type ResultSchemaFromEventSchema<TSchema> = TSchema extends z.ZodObject<infer TShape> ? ResultSchemaFromShape<TShape> : unknown
|
|
164
165
|
export type EventResultInclude<TEvent extends BaseEvent> = (
|
|
165
166
|
result: EventResult<TEvent>['result'],
|
|
166
167
|
event_result: EventResult<TEvent>
|
|
@@ -465,7 +466,10 @@ export class BaseEvent {
|
|
|
465
466
|
|
|
466
467
|
// main entry point for users to define their own event types
|
|
467
468
|
// BaseEvent.extend("MyEvent", { some_custom_field: z.string(), event_result_type: z.string(), event_timeout: 25, ... }) -> MyEvent
|
|
468
|
-
static extend<TSchema extends z.ZodObject<z.ZodRawShape>>(
|
|
469
|
+
static extend<TSchema extends z.ZodObject<z.ZodRawShape>>(
|
|
470
|
+
event_type: string,
|
|
471
|
+
event_schema: TSchema
|
|
472
|
+
): SchemaEventFactory<TSchema, ResultSchemaFromEventSchema<TSchema>>
|
|
469
473
|
static extend<TShape extends z.ZodRawShape>(event_type: string, shape?: TShape): EventFactory<TShape, ResultSchemaFromShape<TShape>>
|
|
470
474
|
static extend<TShape extends Record<string, unknown>>(
|
|
471
475
|
event_type: string,
|