abxbus 2.5.0 → 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/BaseEvent.d.ts +2 -1
- package/dist/cjs/BaseEvent.js.map +2 -2
- package/dist/esm/BaseEvent.js.map +2 -2
- package/dist/types/BaseEvent.d.ts +2 -1
- package/package.json +1 -1
- package/src/BaseEvent.ts +5 -1
- package/dist/cjs/base_event.d.ts +0 -211
- package/dist/cjs/bridge_ipc.d.ts +0 -45
- package/dist/cjs/bridge_jsonl.d.ts +0 -26
- package/dist/cjs/bridge_nats.d.ts +0 -20
- package/dist/cjs/bridge_postgres.d.ts +0 -31
- package/dist/cjs/bridge_redis.d.ts +0 -34
- package/dist/cjs/bridge_sqlite.d.ts +0 -30
- package/dist/cjs/event_bus.d.ts +0 -125
- package/dist/cjs/event_handler.d.ts +0 -140
- package/dist/cjs/event_history.d.ts +0 -45
- package/dist/cjs/event_result.d.ts +0 -86
- package/dist/cjs/lock_manager.d.ts +0 -70
- package/dist/cjs/middleware_otel_tracing.d.ts +0 -49
- package/dist/types/base_event.d.ts +0 -211
- package/dist/types/bridge_ipc.d.ts +0 -45
- package/dist/types/bridge_jsonl.d.ts +0 -26
- package/dist/types/bridge_nats.d.ts +0 -20
- package/dist/types/bridge_postgres.d.ts +0 -31
- package/dist/types/bridge_redis.d.ts +0 -34
- package/dist/types/bridge_sqlite.d.ts +0 -30
- package/dist/types/event_bus.d.ts +0 -125
- package/dist/types/event_handler.d.ts +0 -140
- package/dist/types/event_history.d.ts +0 -45
- package/dist/types/event_result.d.ts +0 -86
- package/dist/types/lock_manager.d.ts +0 -70
- package/dist/types/middleware_otel_tracing.d.ts +0 -49
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { BaseEvent, type BaseEventJSON } from './base_event.js';
|
|
2
|
-
import { EventHistory } from './event_history.js';
|
|
3
|
-
import { EventResult } from './event_result.js';
|
|
4
|
-
import { AsyncLock, type EventConcurrencyMode, type EventHandlerConcurrencyMode, type EventHandlerCompletionMode, LockManager } from './lock_manager.js';
|
|
5
|
-
import { EventHandler, type EphemeralFindEventHandler, type EventHandlerJSON } from './event_handler.js';
|
|
6
|
-
import type { EventBusMiddleware, EventBusMiddlewareInput } from './middlewares.js';
|
|
7
|
-
import type { EventClass, EventHandlerCallable, EventPattern, FindOptions, UntypedEventHandlerFunction } from './types.js';
|
|
8
|
-
export type EventBusOptions = {
|
|
9
|
-
id?: string;
|
|
10
|
-
max_history_size?: number | null;
|
|
11
|
-
max_history_drop?: boolean;
|
|
12
|
-
event_concurrency?: EventConcurrencyMode | null;
|
|
13
|
-
event_timeout?: number | null;
|
|
14
|
-
event_slow_timeout?: number | null;
|
|
15
|
-
event_handler_concurrency?: EventHandlerConcurrencyMode | null;
|
|
16
|
-
event_handler_completion?: EventHandlerCompletionMode;
|
|
17
|
-
event_handler_slow_timeout?: number | null;
|
|
18
|
-
event_handler_detect_file_paths?: boolean;
|
|
19
|
-
middlewares?: EventBusMiddlewareInput[];
|
|
20
|
-
};
|
|
21
|
-
export type EventBusJSON = {
|
|
22
|
-
id: string;
|
|
23
|
-
name: string;
|
|
24
|
-
max_history_size: number | null;
|
|
25
|
-
max_history_drop: boolean;
|
|
26
|
-
event_concurrency: EventConcurrencyMode;
|
|
27
|
-
event_timeout: number | null;
|
|
28
|
-
event_slow_timeout: number | null;
|
|
29
|
-
event_handler_concurrency: EventHandlerConcurrencyMode;
|
|
30
|
-
event_handler_completion: EventHandlerCompletionMode;
|
|
31
|
-
event_handler_slow_timeout: number | null;
|
|
32
|
-
event_handler_detect_file_paths: boolean;
|
|
33
|
-
handlers: Record<string, EventHandlerJSON>;
|
|
34
|
-
handlers_by_key: Record<string, string[]>;
|
|
35
|
-
event_history: Record<string, BaseEventJSON>;
|
|
36
|
-
pending_event_queue: string[];
|
|
37
|
-
};
|
|
38
|
-
export declare class GlobalEventBusRegistry {
|
|
39
|
-
private _bus_refs;
|
|
40
|
-
add(bus: EventBus): void;
|
|
41
|
-
discard(bus: EventBus): void;
|
|
42
|
-
has(bus: EventBus): boolean;
|
|
43
|
-
get size(): number;
|
|
44
|
-
[Symbol.iterator](): IterableIterator<EventBus>;
|
|
45
|
-
findBusById(bus_id: string): EventBus | undefined;
|
|
46
|
-
findEventById(event_id: string): BaseEvent | null;
|
|
47
|
-
}
|
|
48
|
-
export declare class EventBus {
|
|
49
|
-
private static _registry_by_constructor;
|
|
50
|
-
private static _global_event_lock_by_constructor;
|
|
51
|
-
private static getRegistryForConstructor;
|
|
52
|
-
private static getGlobalEventLockForConstructor;
|
|
53
|
-
static get all_instances(): GlobalEventBusRegistry;
|
|
54
|
-
get all_instances(): GlobalEventBusRegistry;
|
|
55
|
-
get _lock_for_event_global_serial(): AsyncLock;
|
|
56
|
-
id: string;
|
|
57
|
-
name: string;
|
|
58
|
-
event_timeout: number | null;
|
|
59
|
-
event_concurrency: EventConcurrencyMode;
|
|
60
|
-
event_handler_concurrency: EventHandlerConcurrencyMode;
|
|
61
|
-
event_handler_completion: EventHandlerCompletionMode;
|
|
62
|
-
event_handler_detect_file_paths: boolean;
|
|
63
|
-
event_handler_slow_timeout: number | null;
|
|
64
|
-
event_slow_timeout: number | null;
|
|
65
|
-
handlers: Map<string, EventHandler>;
|
|
66
|
-
handlers_by_key: Map<string, string[]>;
|
|
67
|
-
event_history: EventHistory<BaseEvent>;
|
|
68
|
-
pending_event_queue: BaseEvent[];
|
|
69
|
-
in_flight_event_ids: Set<string>;
|
|
70
|
-
runloop_running: boolean;
|
|
71
|
-
locks: LockManager;
|
|
72
|
-
find_waiters: Set<EphemeralFindEventHandler>;
|
|
73
|
-
middlewares: EventBusMiddleware[];
|
|
74
|
-
private static normalizeMiddlewares;
|
|
75
|
-
constructor(name?: string, options?: EventBusOptions);
|
|
76
|
-
toString(): string;
|
|
77
|
-
scheduleMicrotask(fn: () => void): void;
|
|
78
|
-
private _runMiddlewareHook;
|
|
79
|
-
onEventChange(event: BaseEvent, status: 'pending' | 'started' | 'completed'): Promise<void>;
|
|
80
|
-
onEventResultChange(event: BaseEvent, result: EventResult, status: 'pending' | 'started' | 'completed'): Promise<void>;
|
|
81
|
-
private _onEventChange;
|
|
82
|
-
private _onEventResultChange;
|
|
83
|
-
private _onBusHandlersChange;
|
|
84
|
-
private _finalizeEventTimeout;
|
|
85
|
-
private _createEventTimeoutError;
|
|
86
|
-
private _runHandlersWithTimeout;
|
|
87
|
-
private _markEventCompletedIfNeeded;
|
|
88
|
-
toJSON(): EventBusJSON;
|
|
89
|
-
private static _stubHandlerFn;
|
|
90
|
-
private static _upsertHandlerIndex;
|
|
91
|
-
private static _linkEventResultHandlers;
|
|
92
|
-
static fromJSON(data: unknown): EventBus;
|
|
93
|
-
get label(): string;
|
|
94
|
-
removeEventFromPendingQueue(event: BaseEvent): number;
|
|
95
|
-
isEventInFlightOrQueued(event_id: string): boolean;
|
|
96
|
-
removeEventFromHistory(event_id: string): boolean;
|
|
97
|
-
destroy(): void;
|
|
98
|
-
on<T extends BaseEvent>(event_pattern: EventClass<T>, handler: EventHandlerCallable<T>, options?: Partial<EventHandler>): EventHandler;
|
|
99
|
-
on<T extends BaseEvent>(event_pattern: string | '*', handler: UntypedEventHandlerFunction<T>, options?: Partial<EventHandler>): EventHandler;
|
|
100
|
-
off<T extends BaseEvent>(event_pattern: EventPattern<T> | '*', handler?: EventHandlerCallable<T> | string | EventHandler): void;
|
|
101
|
-
emit<T extends BaseEvent>(event: T): T;
|
|
102
|
-
dispatch<T extends BaseEvent>(event: T): T;
|
|
103
|
-
find(event_pattern: '*', options?: FindOptions<BaseEvent>): Promise<BaseEvent | null>;
|
|
104
|
-
find(event_pattern: '*', where: (event: BaseEvent) => boolean, options?: FindOptions<BaseEvent>): Promise<BaseEvent | null>;
|
|
105
|
-
find<T extends BaseEvent>(event_pattern: EventPattern<T>, options?: FindOptions<T>): Promise<T | null>;
|
|
106
|
-
find<T extends BaseEvent>(event_pattern: EventPattern<T>, where: (event: T) => boolean, options?: FindOptions<T>): Promise<T | null>;
|
|
107
|
-
private _waitForFutureMatch;
|
|
108
|
-
waitUntilIdle(timeout?: number | null): Promise<boolean>;
|
|
109
|
-
isIdle(): boolean;
|
|
110
|
-
isIdleAndQueueEmpty(): boolean;
|
|
111
|
-
eventIsChildOf(child_event: BaseEvent, parent_event: BaseEvent): boolean;
|
|
112
|
-
eventIsParentOf(parent_event: BaseEvent, child_event: BaseEvent): boolean;
|
|
113
|
-
logTree(): string;
|
|
114
|
-
findEventById(event_id: string): BaseEvent | null;
|
|
115
|
-
private _startRunloop;
|
|
116
|
-
private _processEvent;
|
|
117
|
-
_processEventImmediately<T extends BaseEvent>(event: T, handler_result?: EventResult): Promise<T>;
|
|
118
|
-
private _processEventImmediatelyAcrossBuses;
|
|
119
|
-
private _runloop;
|
|
120
|
-
_hasProcessedEvent(event: BaseEvent): boolean;
|
|
121
|
-
_getEventProxyScopedToThisBus<T extends BaseEvent>(event: T, handler_result?: EventResult): T;
|
|
122
|
-
private _resolveFindWaiters;
|
|
123
|
-
_getHandlersForEvent(event: BaseEvent): EventHandler[];
|
|
124
|
-
private _removeIndexedHandler;
|
|
125
|
-
}
|
|
@@ -1,140 +0,0 @@
|
|
|
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 handlerNameFromCallable(handler: EventHandlerCallable): string;
|
|
65
|
-
static computeHandlerId(params: {
|
|
66
|
-
eventbus_id: string;
|
|
67
|
-
handler_name: string;
|
|
68
|
-
handler_file_path?: string | null;
|
|
69
|
-
handler_registered_at: string;
|
|
70
|
-
event_pattern: string | '*';
|
|
71
|
-
}): string;
|
|
72
|
-
static fromCallable<TEvent extends BaseEvent = BaseEvent>(params: {
|
|
73
|
-
handler: EventHandlerCallable<TEvent>;
|
|
74
|
-
event_pattern: EventPattern | '*';
|
|
75
|
-
eventbus_name: string;
|
|
76
|
-
eventbus_id: string;
|
|
77
|
-
detect_handler_file_path?: boolean;
|
|
78
|
-
id?: string;
|
|
79
|
-
handler_file_path?: string | null;
|
|
80
|
-
handler_timeout?: number | null;
|
|
81
|
-
handler_slow_timeout?: number | null;
|
|
82
|
-
handler_registered_at?: string;
|
|
83
|
-
}): EventHandler;
|
|
84
|
-
toString(): string;
|
|
85
|
-
_detectHandlerFilePath(): void;
|
|
86
|
-
toJSON(): EventHandlerJSON;
|
|
87
|
-
static fromJSON(data: unknown, handler?: EventHandlerCallable): EventHandler;
|
|
88
|
-
static toJSONArray(handlers: Iterable<EventHandler>): EventHandlerJSON[];
|
|
89
|
-
static fromJSONArray(data: unknown, handler?: EventHandlerCallable): EventHandler[];
|
|
90
|
-
get eventbus_label(): string;
|
|
91
|
-
}
|
|
92
|
-
export declare class TimeoutError extends Error {
|
|
93
|
-
constructor(message: string);
|
|
94
|
-
}
|
|
95
|
-
export declare class EventHandlerError extends Error {
|
|
96
|
-
event_result: EventResult;
|
|
97
|
-
timeout_seconds: number | null;
|
|
98
|
-
cause: Error;
|
|
99
|
-
constructor(message: string, params: {
|
|
100
|
-
event_result: EventResult;
|
|
101
|
-
timeout_seconds?: number | null;
|
|
102
|
-
cause: Error;
|
|
103
|
-
});
|
|
104
|
-
get event(): BaseEvent;
|
|
105
|
-
get event_type(): string;
|
|
106
|
-
get handler_name(): string;
|
|
107
|
-
get handler_id(): string;
|
|
108
|
-
get event_timeout(): number | null;
|
|
109
|
-
}
|
|
110
|
-
export declare class EventHandlerTimeoutError extends EventHandlerError {
|
|
111
|
-
constructor(message: string, params: {
|
|
112
|
-
event_result: EventResult;
|
|
113
|
-
timeout_seconds?: number | null;
|
|
114
|
-
cause?: Error;
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
export declare class EventHandlerCancelledError extends EventHandlerError {
|
|
118
|
-
constructor(message: string, params: {
|
|
119
|
-
event_result: EventResult;
|
|
120
|
-
timeout_seconds?: number | null;
|
|
121
|
-
cause: Error;
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
export declare class EventHandlerAbortedError extends EventHandlerError {
|
|
125
|
-
constructor(message: string, params: {
|
|
126
|
-
event_result: EventResult;
|
|
127
|
-
timeout_seconds?: number | null;
|
|
128
|
-
cause: Error;
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
export declare class EventHandlerResultSchemaError extends EventHandlerError {
|
|
132
|
-
raw_value: unknown;
|
|
133
|
-
constructor(message: string, params: {
|
|
134
|
-
event_result: EventResult;
|
|
135
|
-
timeout_seconds?: number | null;
|
|
136
|
-
cause: Error;
|
|
137
|
-
raw_value: unknown;
|
|
138
|
-
});
|
|
139
|
-
get expected_schema(): any;
|
|
140
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { BaseEvent } from './base_event.js';
|
|
3
|
-
import type { EventBus } from './event_bus.js';
|
|
4
|
-
import { EventHandler } from './event_handler.js';
|
|
5
|
-
import { type HandlerLock } from './lock_manager.js';
|
|
6
|
-
import type { Deferred } from './lock_manager.js';
|
|
7
|
-
import type { EventResultType } from './types.js';
|
|
8
|
-
export type EventResultStatus = 'pending' | 'started' | 'completed' | 'error';
|
|
9
|
-
export declare const EventResultJSONSchema: z.ZodObject<{
|
|
10
|
-
id: z.ZodString;
|
|
11
|
-
status: z.ZodEnum<{
|
|
12
|
-
pending: "pending";
|
|
13
|
-
started: "started";
|
|
14
|
-
completed: "completed";
|
|
15
|
-
error: "error";
|
|
16
|
-
}>;
|
|
17
|
-
event_id: z.ZodString;
|
|
18
|
-
handler_id: z.ZodString;
|
|
19
|
-
handler_name: z.ZodString;
|
|
20
|
-
handler_file_path: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
21
|
-
handler_timeout: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
22
|
-
handler_slow_timeout: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
23
|
-
handler_registered_at: z.ZodOptional<z.ZodString>;
|
|
24
|
-
handler_event_pattern: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodLiteral<"*">]>>;
|
|
25
|
-
eventbus_name: z.ZodString;
|
|
26
|
-
eventbus_id: z.ZodString;
|
|
27
|
-
started_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
28
|
-
completed_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
29
|
-
result: z.ZodOptional<z.ZodUnknown>;
|
|
30
|
-
error: z.ZodOptional<z.ZodUnknown>;
|
|
31
|
-
event_children: z.ZodArray<z.ZodString>;
|
|
32
|
-
}, z.core.$strict>;
|
|
33
|
-
export type EventResultJSON = z.infer<typeof EventResultJSONSchema>;
|
|
34
|
-
export declare class EventResult<TEvent extends BaseEvent = BaseEvent> {
|
|
35
|
-
id: string;
|
|
36
|
-
status: EventResultStatus;
|
|
37
|
-
event: TEvent;
|
|
38
|
-
handler: EventHandler;
|
|
39
|
-
started_at: string | null;
|
|
40
|
-
completed_at: string | null;
|
|
41
|
-
result?: EventResultType<TEvent>;
|
|
42
|
-
error?: unknown;
|
|
43
|
-
event_children: BaseEvent[];
|
|
44
|
-
_abort: Deferred<never> | null;
|
|
45
|
-
_lock: HandlerLock | null;
|
|
46
|
-
_queue_jump_pause_releases: Map<EventBus, () => void> | null;
|
|
47
|
-
constructor(params: {
|
|
48
|
-
event: TEvent;
|
|
49
|
-
handler: EventHandler;
|
|
50
|
-
});
|
|
51
|
-
toString(): string;
|
|
52
|
-
get event_id(): string;
|
|
53
|
-
get bus(): EventBus;
|
|
54
|
-
get handler_id(): string;
|
|
55
|
-
get handler_name(): string;
|
|
56
|
-
get handler_file_path(): string | null;
|
|
57
|
-
get eventbus_name(): string;
|
|
58
|
-
get eventbus_id(): string;
|
|
59
|
-
get eventbus_label(): string;
|
|
60
|
-
private getHookBus;
|
|
61
|
-
private _notifyStatusHook;
|
|
62
|
-
get value(): EventResultType<TEvent> | undefined;
|
|
63
|
-
get result_type(): TEvent['event_result_type'];
|
|
64
|
-
_linkEmittedChildEvent(child_event: BaseEvent): void;
|
|
65
|
-
get raw_value(): EventResultType<TEvent> | undefined;
|
|
66
|
-
get handler_timeout(): number | null;
|
|
67
|
-
get handler_slow_timeout(): number | null;
|
|
68
|
-
_createSlowHandlerWarningTimer(effective_timeout: number | null): ReturnType<typeof setTimeout> | null;
|
|
69
|
-
_ensureQueueJumpPause(bus: EventBus): void;
|
|
70
|
-
_releaseQueueJumpPauses(): void;
|
|
71
|
-
update(params: {
|
|
72
|
-
status?: EventResultStatus;
|
|
73
|
-
result?: EventResultType<TEvent> | BaseEvent | undefined;
|
|
74
|
-
error?: unknown;
|
|
75
|
-
}): this;
|
|
76
|
-
private _createHandlerTimeoutError;
|
|
77
|
-
private _handleHandlerError;
|
|
78
|
-
private _onHandlerExit;
|
|
79
|
-
runHandler(handler_lock: HandlerLock | null): Promise<void>;
|
|
80
|
-
_signalAbort(error: Error): void;
|
|
81
|
-
_markStarted(notify_hook?: boolean): Promise<never>;
|
|
82
|
-
_markCompleted(result: EventResultType<TEvent> | BaseEvent | undefined, notify_hook?: boolean): void;
|
|
83
|
-
_markError(error: unknown, notify_hook?: boolean): void;
|
|
84
|
-
toJSON(): EventResultJSON;
|
|
85
|
-
static fromJSON<TEvent extends BaseEvent>(event: TEvent, data: unknown): EventResult<TEvent>;
|
|
86
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import type { BaseEvent } from './base_event.js';
|
|
2
|
-
import type { EventResult } from './event_result.js';
|
|
3
|
-
export type Deferred<T> = {
|
|
4
|
-
promise: Promise<T>;
|
|
5
|
-
resolve: (value: T | PromiseLike<T>) => void;
|
|
6
|
-
reject: (reason?: unknown) => void;
|
|
7
|
-
};
|
|
8
|
-
export declare const withResolvers: <T>() => Deferred<T>;
|
|
9
|
-
export declare const EVENT_CONCURRENCY_MODES: readonly ["global-serial", "bus-serial", "parallel"];
|
|
10
|
-
export type EventConcurrencyMode = (typeof EVENT_CONCURRENCY_MODES)[number];
|
|
11
|
-
export declare const EVENT_HANDLER_CONCURRENCY_MODES: readonly ["serial", "parallel"];
|
|
12
|
-
export type EventHandlerConcurrencyMode = (typeof EVENT_HANDLER_CONCURRENCY_MODES)[number];
|
|
13
|
-
export declare const EVENT_HANDLER_COMPLETION_MODES: readonly ["all", "first"];
|
|
14
|
-
export type EventHandlerCompletionMode = (typeof EVENT_HANDLER_COMPLETION_MODES)[number];
|
|
15
|
-
export declare class AsyncLock {
|
|
16
|
-
size: number;
|
|
17
|
-
in_use: number;
|
|
18
|
-
waiters: Array<() => void>;
|
|
19
|
-
constructor(size: number);
|
|
20
|
-
acquire(): Promise<void>;
|
|
21
|
-
release(): void;
|
|
22
|
-
}
|
|
23
|
-
export declare const runWithLock: <T>(lock: AsyncLock | null, fn: () => Promise<T>) => Promise<T>;
|
|
24
|
-
export type HandlerExecutionState = 'held' | 'yielded' | 'closed';
|
|
25
|
-
export declare class HandlerLock {
|
|
26
|
-
private lock;
|
|
27
|
-
private state;
|
|
28
|
-
constructor(lock: AsyncLock | null);
|
|
29
|
-
yieldHandlerLockForChildRun(): boolean;
|
|
30
|
-
reclaimHandlerLockIfRunning(): Promise<boolean>;
|
|
31
|
-
exitHandlerRun(): void;
|
|
32
|
-
runQueueJump<T>(fn: () => Promise<T>): Promise<T>;
|
|
33
|
-
}
|
|
34
|
-
export type EventBusInterfaceForLockManager = {
|
|
35
|
-
isIdleAndQueueEmpty: () => boolean;
|
|
36
|
-
event_concurrency: EventConcurrencyMode;
|
|
37
|
-
_lock_for_event_global_serial: AsyncLock;
|
|
38
|
-
};
|
|
39
|
-
export type LockManagerOptions = {
|
|
40
|
-
auto_schedule_idle_checks?: boolean;
|
|
41
|
-
};
|
|
42
|
-
export declare class LockManager {
|
|
43
|
-
private bus;
|
|
44
|
-
private auto_schedule_idle_checks;
|
|
45
|
-
readonly bus_event_lock: AsyncLock;
|
|
46
|
-
private pause_depth;
|
|
47
|
-
private pause_waiters;
|
|
48
|
-
private active_handler_results;
|
|
49
|
-
private idle_waiters;
|
|
50
|
-
private idle_check_pending;
|
|
51
|
-
private idle_check_streak;
|
|
52
|
-
constructor(bus: EventBusInterfaceForLockManager, options?: LockManagerOptions);
|
|
53
|
-
_requestRunloopPause(): () => void;
|
|
54
|
-
_waitUntilRunloopResumed(): Promise<void>;
|
|
55
|
-
_isPaused(): boolean;
|
|
56
|
-
_runWithHandlerDispatchContext<T>(result: EventResult, fn: () => Promise<T>): Promise<T>;
|
|
57
|
-
_getActiveHandlerResultForCurrentAsyncContext(): EventResult | undefined;
|
|
58
|
-
_getActiveHandlerResults(): EventResult[];
|
|
59
|
-
_isAnyHandlerActive(): boolean;
|
|
60
|
-
waitForIdle(timeout_seconds?: number | null): Promise<boolean>;
|
|
61
|
-
_notifyIdleListeners(): void;
|
|
62
|
-
getLockForEvent(event: BaseEvent): AsyncLock | null;
|
|
63
|
-
_runWithEventLock<T>(event: BaseEvent, fn: () => Promise<T>, options?: {
|
|
64
|
-
bypass_event_locks?: boolean;
|
|
65
|
-
pre_acquired_lock?: AsyncLock | null;
|
|
66
|
-
}): Promise<T>;
|
|
67
|
-
_runWithHandlerLock<T>(event: BaseEvent, default_handler_concurrency: EventHandlerConcurrencyMode | undefined, fn: (lock: HandlerLock | null) => Promise<T>): Promise<T>;
|
|
68
|
-
private scheduleIdleCheck;
|
|
69
|
-
clear(): void;
|
|
70
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { trace, type Span, type SpanAttributes, type SpanContext, type TimeInput, type Tracer } from '@opentelemetry/api';
|
|
2
|
-
import type { BaseEvent } from './base_event.js';
|
|
3
|
-
import type { EventBus } from './event_bus.js';
|
|
4
|
-
import type { EventResult } from './event_result.js';
|
|
5
|
-
import type { EventBusMiddleware } from './middlewares.js';
|
|
6
|
-
import type { EventStatus } from './types.js';
|
|
7
|
-
type OpenTelemetryTraceApi = Pick<typeof trace, 'getTracer' | 'setSpan'> & Partial<Pick<typeof trace, 'setSpanContext'>>;
|
|
8
|
-
export type OtelTracingSpanFactoryInput = {
|
|
9
|
-
name: string;
|
|
10
|
-
span_context: SpanContext;
|
|
11
|
-
parent_span_context?: SpanContext;
|
|
12
|
-
attributes: SpanAttributes;
|
|
13
|
-
start_time?: TimeInput;
|
|
14
|
-
};
|
|
15
|
-
export type OtelTracingSpanFactory = (input: OtelTracingSpanFactoryInput) => Span;
|
|
16
|
-
export type OtelTracingSpanProvider = object;
|
|
17
|
-
export type OtelTracingMiddlewareOptions = {
|
|
18
|
-
tracer?: Tracer;
|
|
19
|
-
trace_api?: OpenTelemetryTraceApi;
|
|
20
|
-
span_provider?: OtelTracingSpanProvider;
|
|
21
|
-
span_factory?: OtelTracingSpanFactory;
|
|
22
|
-
otlp_endpoint?: string;
|
|
23
|
-
service_name?: string;
|
|
24
|
-
instrumentation_name?: string;
|
|
25
|
-
root_span_attributes?: SpanAttributes | ((eventbus: EventBus, event: BaseEvent) => SpanAttributes);
|
|
26
|
-
};
|
|
27
|
-
export declare class OtelTracingMiddleware implements EventBusMiddleware {
|
|
28
|
-
private readonly tracer;
|
|
29
|
-
private readonly trace_api;
|
|
30
|
-
private readonly span_factory?;
|
|
31
|
-
private readonly span_provider?;
|
|
32
|
-
private readonly root_span_attributes;
|
|
33
|
-
private readonly event_spans;
|
|
34
|
-
private readonly event_contexts;
|
|
35
|
-
private readonly handler_spans;
|
|
36
|
-
private readonly handler_contexts;
|
|
37
|
-
constructor(options?: OtelTracingMiddlewareOptions);
|
|
38
|
-
onEventChange(eventbus: EventBus, event: BaseEvent, status: EventStatus): void;
|
|
39
|
-
onEventResultChange(eventbus: EventBus, event: BaseEvent, event_result: EventResult, status: EventStatus): void;
|
|
40
|
-
private startEventSpan;
|
|
41
|
-
private completeEventSpan;
|
|
42
|
-
private startHandlerSpan;
|
|
43
|
-
private completeHandlerSpan;
|
|
44
|
-
private parentContextForEvent;
|
|
45
|
-
private completeEventSpanWithFactory;
|
|
46
|
-
private exportEventTreeWithFactory;
|
|
47
|
-
private exportHandlerSpanWithFactory;
|
|
48
|
-
}
|
|
49
|
-
export {};
|