bubus 1.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ type AsyncLocalStorageLike = {
2
+ getStore(): unknown;
3
+ run<T>(store: unknown, callback: () => T): T;
4
+ enterWith?(store: unknown): void;
5
+ };
6
+ export declare let async_local_storage: AsyncLocalStorageLike | null;
7
+ export declare const captureAsyncContext: () => unknown | null;
8
+ export declare const runWithAsyncContext: <T>(context: unknown | null, fn: () => T) => T;
9
+ export declare const hasAsyncLocalStorage: () => boolean;
10
+ export {};
@@ -0,0 +1,152 @@
1
+ import { z } from 'zod';
2
+ import type { EventBus } from './event_bus.js';
3
+ import { EventResult } from './event_result.js';
4
+ import type { ConcurrencyMode, Deferred } from './lock_manager.js';
5
+ export declare const BaseEventSchema: z.ZodObject<{
6
+ event_id: z.ZodString;
7
+ event_created_at: z.ZodString;
8
+ event_created_ts: z.ZodOptional<z.ZodNumber>;
9
+ event_type: z.ZodString;
10
+ event_timeout: z.ZodNullable<z.ZodNumber>;
11
+ event_parent_id: z.ZodOptional<z.ZodString>;
12
+ event_path: z.ZodOptional<z.ZodArray<z.ZodString>>;
13
+ event_result_type: z.ZodOptional<z.ZodString>;
14
+ event_result_schema: z.ZodOptional<z.ZodUnknown>;
15
+ event_emitted_by_handler_id: z.ZodOptional<z.ZodString>;
16
+ event_pending_bus_count: z.ZodOptional<z.ZodNumber>;
17
+ event_status: z.ZodOptional<z.ZodEnum<{
18
+ pending: "pending";
19
+ started: "started";
20
+ completed: "completed";
21
+ }>>;
22
+ event_started_at: z.ZodOptional<z.ZodString>;
23
+ event_started_ts: z.ZodOptional<z.ZodNumber>;
24
+ event_completed_at: z.ZodOptional<z.ZodString>;
25
+ event_completed_ts: z.ZodOptional<z.ZodNumber>;
26
+ event_results: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
27
+ event_concurrency: z.ZodOptional<z.ZodEnum<{
28
+ "global-serial": "global-serial";
29
+ "bus-serial": "bus-serial";
30
+ parallel: "parallel";
31
+ auto: "auto";
32
+ }>>;
33
+ event_handler_concurrency: z.ZodOptional<z.ZodEnum<{
34
+ "global-serial": "global-serial";
35
+ "bus-serial": "bus-serial";
36
+ parallel: "parallel";
37
+ auto: "auto";
38
+ }>>;
39
+ }, z.core.$loose>;
40
+ export type BaseEventData = z.infer<typeof BaseEventSchema>;
41
+ type BaseEventFields = Pick<BaseEventData, 'event_id' | 'event_created_at' | 'event_created_ts' | 'event_type' | 'event_timeout' | 'event_parent_id' | 'event_path' | 'event_result_type' | 'event_result_schema' | 'event_emitted_by_handler_id' | 'event_pending_bus_count' | 'event_status' | 'event_started_at' | 'event_started_ts' | 'event_completed_at' | 'event_completed_ts' | 'event_results' | 'event_concurrency' | 'event_handler_concurrency'>;
42
+ export type BaseEventInit<TFields extends Record<string, unknown>> = TFields & Partial<BaseEventFields>;
43
+ type BaseEventSchemaShape = typeof BaseEventSchema.shape;
44
+ export type EventSchema<TShape extends z.ZodRawShape> = z.ZodObject<BaseEventSchemaShape & TShape>;
45
+ type EventPayload<TShape extends z.ZodRawShape> = z.infer<z.ZodObject<TShape>>;
46
+ type EventInput<TShape extends z.ZodRawShape> = z.input<EventSchema<TShape>>;
47
+ export type EventInit<TShape extends z.ZodRawShape> = Omit<EventInput<TShape>, keyof BaseEventFields> & Partial<BaseEventFields>;
48
+ type EventWithResult<TResult> = BaseEvent & {
49
+ __event_result_type__?: TResult;
50
+ };
51
+ type ResultTypeFromShape<TShape> = TShape extends {
52
+ event_result_schema: infer S;
53
+ } ? S extends z.ZodTypeAny ? z.infer<S> : unknown : unknown;
54
+ export type EventFactory<TShape extends z.ZodRawShape, TResult = unknown> = {
55
+ (data: EventInit<TShape>): EventWithResult<TResult> & EventPayload<TShape>;
56
+ new (data: EventInit<TShape>): EventWithResult<TResult> & EventPayload<TShape>;
57
+ schema: EventSchema<TShape>;
58
+ event_type?: string;
59
+ event_result_schema?: z.ZodTypeAny;
60
+ event_result_type?: string;
61
+ fromJSON?: (data: unknown) => EventWithResult<TResult> & EventPayload<TShape>;
62
+ };
63
+ type ZodShapeFrom<TShape extends Record<string, unknown>> = {
64
+ [K in keyof TShape as K extends 'event_result_schema' | 'event_result_type' | 'event_result_schema_json' ? never : TShape[K] extends z.ZodTypeAny ? K : never]: Extract<TShape[K], z.ZodTypeAny>;
65
+ };
66
+ export declare class BaseEvent {
67
+ event_id: string;
68
+ event_created_at: string;
69
+ event_created_ts: number;
70
+ event_type: string;
71
+ event_timeout: number | null;
72
+ event_parent_id?: string;
73
+ event_path: string[];
74
+ event_result_schema?: z.ZodTypeAny;
75
+ event_result_type?: string;
76
+ event_results: Map<string, EventResult<this>>;
77
+ event_emitted_by_handler_id?: string;
78
+ event_pending_bus_count: number;
79
+ event_status: 'pending' | 'started' | 'completed';
80
+ event_started_at?: string;
81
+ event_started_ts?: number;
82
+ event_completed_at?: string;
83
+ event_completed_ts?: number;
84
+ event_concurrency?: ConcurrencyMode;
85
+ event_handler_concurrency?: ConcurrencyMode;
86
+ static event_type?: string;
87
+ static schema: z.ZodObject<{
88
+ event_id: z.ZodString;
89
+ event_created_at: z.ZodString;
90
+ event_created_ts: z.ZodOptional<z.ZodNumber>;
91
+ event_type: z.ZodString;
92
+ event_timeout: z.ZodNullable<z.ZodNumber>;
93
+ event_parent_id: z.ZodOptional<z.ZodString>;
94
+ event_path: z.ZodOptional<z.ZodArray<z.ZodString>>;
95
+ event_result_type: z.ZodOptional<z.ZodString>;
96
+ event_result_schema: z.ZodOptional<z.ZodUnknown>;
97
+ event_emitted_by_handler_id: z.ZodOptional<z.ZodString>;
98
+ event_pending_bus_count: z.ZodOptional<z.ZodNumber>;
99
+ event_status: z.ZodOptional<z.ZodEnum<{
100
+ pending: "pending";
101
+ started: "started";
102
+ completed: "completed";
103
+ }>>;
104
+ event_started_at: z.ZodOptional<z.ZodString>;
105
+ event_started_ts: z.ZodOptional<z.ZodNumber>;
106
+ event_completed_at: z.ZodOptional<z.ZodString>;
107
+ event_completed_ts: z.ZodOptional<z.ZodNumber>;
108
+ event_results: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
109
+ event_concurrency: z.ZodOptional<z.ZodEnum<{
110
+ "global-serial": "global-serial";
111
+ "bus-serial": "bus-serial";
112
+ parallel: "parallel";
113
+ auto: "auto";
114
+ }>>;
115
+ event_handler_concurrency: z.ZodOptional<z.ZodEnum<{
116
+ "global-serial": "global-serial";
117
+ "bus-serial": "bus-serial";
118
+ parallel: "parallel";
119
+ auto: "auto";
120
+ }>>;
121
+ }, z.core.$loose>;
122
+ bus?: EventBus;
123
+ _event_original?: BaseEvent;
124
+ _event_dispatch_context?: unknown | null;
125
+ _event_done_signal: Deferred<this> | null;
126
+ constructor(data?: BaseEventInit<Record<string, unknown>>);
127
+ toString(): string;
128
+ static nextTimestamp(): {
129
+ date: Date;
130
+ isostring: string;
131
+ ts: number;
132
+ };
133
+ static extend<TShape extends z.ZodRawShape>(event_type: string, shape?: TShape): EventFactory<TShape, ResultTypeFromShape<TShape>>;
134
+ static extend<TShape extends Record<string, unknown>>(event_type: string, shape?: TShape): EventFactory<ZodShapeFrom<TShape>, ResultTypeFromShape<TShape>>;
135
+ static parse<T extends typeof BaseEvent>(this: T, data: unknown): InstanceType<T>;
136
+ static fromJSON<T extends typeof BaseEvent>(this: T, data: unknown): InstanceType<T>;
137
+ toJSON(): BaseEventData;
138
+ get event_parent(): BaseEvent | undefined;
139
+ get event_children(): BaseEvent[];
140
+ get event_descendants(): BaseEvent[];
141
+ done(): Promise<this>;
142
+ immediate(): Promise<this>;
143
+ waitForCompletion(): Promise<this>;
144
+ finished(): Promise<this>;
145
+ markStarted(): void;
146
+ markCompleted(force?: boolean): void;
147
+ get event_errors(): unknown[];
148
+ eventAreAllChildrenComplete(): boolean;
149
+ _notifyDoneListeners(): void;
150
+ _gc(): void;
151
+ }
152
+ export {};
@@ -0,0 +1,96 @@
1
+ import { BaseEvent } from './base_event.js';
2
+ import { EventResult } from './event_result.js';
3
+ import { type ConcurrencyMode, LockManager } from './lock_manager.js';
4
+ import { EventHandler } from './event_handler.js';
5
+ import type { EventClass, EventHandlerFunction, EventKey, FindOptions, UntypedEventHandlerFunction } from './types.js';
6
+ type FindWaiter = {
7
+ event_key: EventKey;
8
+ matches: (event: BaseEvent) => boolean;
9
+ resolve: (event: BaseEvent) => void;
10
+ timeout_id?: ReturnType<typeof setTimeout>;
11
+ };
12
+ type EventBusOptions = {
13
+ max_history_size?: number | null;
14
+ event_concurrency?: ConcurrencyMode;
15
+ event_handler_concurrency?: ConcurrencyMode;
16
+ event_timeout?: number | null;
17
+ event_handler_slow_timeout?: number | null;
18
+ event_slow_timeout?: number | null;
19
+ };
20
+ declare class GlobalEventBusInstanceRegistry {
21
+ private _refs;
22
+ private _lookup;
23
+ private _gc;
24
+ add(bus: EventBus): void;
25
+ delete(bus: EventBus): void;
26
+ has(bus: EventBus): boolean;
27
+ get size(): number;
28
+ [Symbol.iterator](): Iterator<EventBus>;
29
+ findEventById(event_id: string): BaseEvent | null;
30
+ }
31
+ export declare class EventBus {
32
+ static _all_instances: GlobalEventBusInstanceRegistry;
33
+ name: string;
34
+ max_history_size: number | null;
35
+ event_concurrency_default: ConcurrencyMode;
36
+ event_handler_concurrency_default: ConcurrencyMode;
37
+ event_timeout_default: number | null;
38
+ event_handler_slow_timeout: number | null;
39
+ event_slow_timeout: number | null;
40
+ handlers: Map<string, EventHandler>;
41
+ event_history: Map<string, BaseEvent>;
42
+ pending_event_queue: BaseEvent[];
43
+ in_flight_event_ids: Set<string>;
44
+ runloop_running: boolean;
45
+ locks: LockManager;
46
+ find_waiters: Set<FindWaiter>;
47
+ constructor(name?: string, options?: EventBusOptions);
48
+ toString(): string;
49
+ destroy(): void;
50
+ on<T extends BaseEvent>(event_key: EventClass<T>, handler: EventHandlerFunction<T>, options?: {
51
+ event_handler_concurrency?: ConcurrencyMode;
52
+ handler_timeout?: number | null;
53
+ }): EventHandler;
54
+ on<T extends BaseEvent>(event_key: string | '*', handler: UntypedEventHandlerFunction<T>, options?: {
55
+ event_handler_concurrency?: ConcurrencyMode;
56
+ handler_timeout?: number | null;
57
+ }): EventHandler;
58
+ off<T extends BaseEvent>(event_key: EventKey<T> | '*', handler?: EventHandlerFunction<T> | string | EventHandler): void;
59
+ dispatch<T extends BaseEvent>(event: T, _event_key?: EventKey<T>): T;
60
+ emit<T extends BaseEvent>(event: T, event_key?: EventKey<T>): T;
61
+ find<T extends BaseEvent>(event_key: EventKey<T>, options?: FindOptions): Promise<T | null>;
62
+ find<T extends BaseEvent>(event_key: EventKey<T>, where: (event: T) => boolean, options?: FindOptions): Promise<T | null>;
63
+ processEventImmediately<T extends BaseEvent>(event: T, handler_result?: EventResult): Promise<T>;
64
+ waitUntilIdle(): Promise<void>;
65
+ isIdle(): boolean;
66
+ isIdleAndQueueEmpty(): boolean;
67
+ eventIsChildOf(event: BaseEvent, ancestor: BaseEvent): boolean;
68
+ eventIsParentOf(parent_event: BaseEvent, child_event: BaseEvent): boolean;
69
+ logTree(): string;
70
+ findEventById(event_id: string): BaseEvent | null;
71
+ getParentEventResultAcrossAllBusses(event: BaseEvent): EventResult | null;
72
+ private runImmediatelyAcrossBuses;
73
+ private getBusesForImmediateRun;
74
+ private startRunloop;
75
+ private scheduleEventProcessing;
76
+ private runloop;
77
+ private processEvent;
78
+ runEventHandler(event: BaseEvent, handler: EventHandler, result: EventResult): Promise<void>;
79
+ private runHandlerWithTimeout;
80
+ private createSlowEventWarningTimer;
81
+ private createSlowHandlerWarningTimer;
82
+ private resolveEffectiveTimeout;
83
+ hasProcessedEvent(event: BaseEvent): boolean;
84
+ private notifyEventParentsOfCompletion;
85
+ getEventProxyScopedToThisBus<T extends BaseEvent>(event: T, handler_result?: EventResult): T;
86
+ cancelPendingDescendants(event: BaseEvent, reason: unknown): void;
87
+ private normalizeCancellationCause;
88
+ private cancelEvent;
89
+ private notifyFindListeners;
90
+ private createPendingHandlerResults;
91
+ getHandlersForEvent(event: BaseEvent): EventHandler[];
92
+ private eventMatchesKey;
93
+ private normalizeEventKey;
94
+ private trimHistory;
95
+ }
96
+ export {};
@@ -0,0 +1,85 @@
1
+ import type { ConcurrencyMode } from './lock_manager.js';
2
+ import type { EventHandlerFunction } from './types.js';
3
+ import { BaseEvent } from './base_event.js';
4
+ import { EventResult } from './event_result.js';
5
+ export declare class EventHandler {
6
+ id: string;
7
+ handler: EventHandlerFunction;
8
+ handler_name: string;
9
+ handler_file_path?: string;
10
+ handler_timeout: number | null;
11
+ event_handler_concurrency?: ConcurrencyMode;
12
+ handler_registered_at: string;
13
+ handler_registered_ts: number;
14
+ event_key: string | '*';
15
+ eventbus_name: string;
16
+ constructor(params: {
17
+ id?: string;
18
+ handler: EventHandlerFunction;
19
+ handler_name: string;
20
+ handler_file_path?: string;
21
+ handler_timeout: number | null;
22
+ event_handler_concurrency?: ConcurrencyMode;
23
+ handler_registered_at: string;
24
+ handler_registered_ts: number;
25
+ event_key: string | '*';
26
+ eventbus_name: string;
27
+ });
28
+ static computeHandlerId(params: {
29
+ eventbus_name: string;
30
+ handler_name: string;
31
+ handler_file_path?: string;
32
+ handler_registered_at: string;
33
+ event_key: string | '*';
34
+ }): string;
35
+ toString(): string;
36
+ private static detectHandlerFilePath;
37
+ }
38
+ export declare class TimeoutError extends Error {
39
+ constructor(message: string);
40
+ }
41
+ export declare class EventHandlerError extends Error {
42
+ event_result: EventResult;
43
+ timeout_seconds: number | null;
44
+ cause: Error;
45
+ constructor(message: string, params: {
46
+ event_result: EventResult;
47
+ timeout_seconds?: number | null;
48
+ cause: Error;
49
+ });
50
+ get event(): BaseEvent;
51
+ get event_type(): string;
52
+ get handler_name(): string;
53
+ get handler_id(): string;
54
+ get event_timeout(): number | null;
55
+ }
56
+ export declare class EventHandlerTimeoutError extends EventHandlerError {
57
+ constructor(message: string, params: {
58
+ event_result: EventResult;
59
+ timeout_seconds?: number | null;
60
+ cause?: Error;
61
+ });
62
+ }
63
+ export declare class EventHandlerCancelledError extends EventHandlerError {
64
+ constructor(message: string, params: {
65
+ event_result: EventResult;
66
+ timeout_seconds?: number | null;
67
+ cause: Error;
68
+ });
69
+ }
70
+ export declare class EventHandlerAbortedError extends EventHandlerError {
71
+ constructor(message: string, params: {
72
+ event_result: EventResult;
73
+ timeout_seconds?: number | null;
74
+ cause: Error;
75
+ });
76
+ }
77
+ export declare class EventHandlerResultSchemaError extends EventHandlerError {
78
+ raw_value: unknown;
79
+ constructor(message: string, params: {
80
+ event_result: EventResult;
81
+ timeout_seconds?: number | null;
82
+ cause: Error;
83
+ raw_value: unknown;
84
+ });
85
+ }
@@ -0,0 +1,64 @@
1
+ import { BaseEvent } from './base_event.js';
2
+ import type { EventHandler } from './event_handler.js';
3
+ import { HandlerLock, type ConcurrencyMode } from './lock_manager.js';
4
+ import type { Deferred } from './lock_manager.js';
5
+ import type { EventResultType } from './types.js';
6
+ export type EventResultStatus = 'pending' | 'started' | 'completed' | 'error';
7
+ export type EventResultData = {
8
+ id?: string;
9
+ status?: EventResultStatus;
10
+ event_id?: string;
11
+ handler?: {
12
+ id?: string;
13
+ handler_name?: string;
14
+ handler_file_path?: string;
15
+ handler_timeout?: number | null;
16
+ event_handler_concurrency?: ConcurrencyMode;
17
+ handler_registered_at?: string;
18
+ handler_registered_ts?: number;
19
+ event_key?: string | '*';
20
+ eventbus_name?: string;
21
+ };
22
+ started_at?: string;
23
+ started_ts?: number;
24
+ completed_at?: string;
25
+ completed_ts?: number;
26
+ result?: unknown;
27
+ error?: unknown;
28
+ event_children?: string[];
29
+ };
30
+ export declare class EventResult<TEvent extends BaseEvent = BaseEvent> {
31
+ id: string;
32
+ status: EventResultStatus;
33
+ event: TEvent;
34
+ handler: EventHandler;
35
+ started_at?: string;
36
+ started_ts?: number;
37
+ completed_at?: string;
38
+ completed_ts?: number;
39
+ result?: EventResultType<TEvent>;
40
+ error?: unknown;
41
+ event_children: BaseEvent[];
42
+ _abort: Deferred<never> | null;
43
+ _lock: HandlerLock | null;
44
+ constructor(params: {
45
+ event: TEvent;
46
+ handler: EventHandler;
47
+ });
48
+ toString(): string;
49
+ get event_id(): string;
50
+ get handler_id(): string;
51
+ get handler_name(): string;
52
+ get handler_file_path(): string | undefined;
53
+ get handler_timeout(): number | null;
54
+ get eventbus_name(): string;
55
+ get value(): EventResultType<TEvent> | undefined;
56
+ linkEmittedChildEvent(child_event: BaseEvent): void;
57
+ get raw_value(): EventResultType<TEvent> | undefined;
58
+ signalAbort(error: Error): void;
59
+ markStarted(): Promise<never>;
60
+ markCompleted(result: EventResultType<TEvent> | undefined): void;
61
+ markError(error: unknown): void;
62
+ toJSON(): EventResultData;
63
+ static fromJSON<TEvent extends BaseEvent>(event: TEvent, data: unknown): EventResult<TEvent> | null;
64
+ }
@@ -0,0 +1,6 @@
1
+ export { BaseEvent, BaseEventSchema } from './base_event.js';
2
+ export { EventResult } from './event_result.js';
3
+ export { EventBus } from './event_bus.js';
4
+ export { EventHandlerTimeoutError, EventHandlerCancelledError, EventHandlerAbortedError, EventHandlerResultSchemaError, } from './event_handler.js';
5
+ export type { ConcurrencyMode, EventBusInterfaceForLockManager } from './lock_manager.js';
6
+ export type { EventClass, EventHandlerFunction as EventHandler, EventKey, EventStatus, FindOptions, FindWindow } from './types.js';
@@ -0,0 +1,68 @@
1
+ import type { BaseEvent } from './base_event.js';
2
+ import type { EventHandler } from './event_handler.js';
3
+ import type { EventResult } from './event_result.js';
4
+ export type Deferred<T> = {
5
+ promise: Promise<T>;
6
+ resolve: (value: T | PromiseLike<T>) => void;
7
+ reject: (reason?: unknown) => void;
8
+ };
9
+ export declare const withResolvers: <T>() => Deferred<T>;
10
+ export declare const CONCURRENCY_MODES: readonly ["global-serial", "bus-serial", "parallel", "auto"];
11
+ export type ConcurrencyMode = (typeof CONCURRENCY_MODES)[number];
12
+ export declare const DEFAULT_CONCURRENCY_MODE = "bus-serial";
13
+ export declare const resolveConcurrencyMode: (mode: ConcurrencyMode | undefined, fallback: ConcurrencyMode) => ConcurrencyMode;
14
+ export declare class AsyncSemaphore {
15
+ size: number;
16
+ in_use: number;
17
+ waiters: Array<() => void>;
18
+ constructor(size: number);
19
+ acquire(): Promise<void>;
20
+ release(): void;
21
+ }
22
+ export declare const semaphoreForMode: (mode: ConcurrencyMode, global_semaphore: AsyncSemaphore, bus_semaphore: AsyncSemaphore) => AsyncSemaphore | null;
23
+ export declare const runWithSemaphore: <T>(semaphore: AsyncSemaphore | null, fn: () => Promise<T>) => Promise<T>;
24
+ export type HandlerExecutionState = 'held' | 'yielded' | 'closed';
25
+ export declare class HandlerLock {
26
+ private semaphore;
27
+ private state;
28
+ constructor(semaphore: AsyncSemaphore | 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_default: ConcurrencyMode;
37
+ event_handler_concurrency_default: ConcurrencyMode;
38
+ };
39
+ export declare class LockManager {
40
+ static global_event_semaphore: AsyncSemaphore;
41
+ static global_handler_semaphore: AsyncSemaphore;
42
+ private bus;
43
+ readonly bus_event_semaphore: AsyncSemaphore;
44
+ readonly bus_handler_semaphore: AsyncSemaphore;
45
+ private pause_depth;
46
+ private pause_waiters;
47
+ private queue_jump_pause_releases;
48
+ private active_handler_results;
49
+ private idle_waiters;
50
+ private idle_check_pending;
51
+ private idle_check_streak;
52
+ constructor(bus: EventBusInterfaceForLockManager);
53
+ requestPause(): () => void;
54
+ waitUntilRunloopResumed(): Promise<void>;
55
+ isPaused(): boolean;
56
+ enterActiveHandlerContext(result: EventResult): void;
57
+ exitActiveHandlerContext(result: EventResult): void;
58
+ getActiveHandlerResult(): EventResult | undefined;
59
+ isAnyHandlerActive(): boolean;
60
+ requestRunloopPauseForQueueJumpEvent(result: EventResult): void;
61
+ releaseRunloopPauseForQueueJumpEvent(result: EventResult): void;
62
+ waitForIdle(): Promise<void>;
63
+ notifyIdleListeners(): void;
64
+ getSemaphoreForEvent(event: BaseEvent): AsyncSemaphore | null;
65
+ getSemaphoreForHandler(event: BaseEvent, handler?: Pick<EventHandler, 'event_handler_concurrency'>): AsyncSemaphore | null;
66
+ private scheduleIdleCheck;
67
+ clear(): void;
68
+ }
@@ -0,0 +1,12 @@
1
+ import { BaseEvent } from './base_event.js';
2
+ import { EventResult } from './event_result.js';
3
+ type LogTreeBus = {
4
+ name: string;
5
+ event_history: Map<string, BaseEvent>;
6
+ };
7
+ export declare const logTree: (bus: LogTreeBus) => string;
8
+ export declare const buildTreeLine: (event: BaseEvent, indent: string, is_last: boolean, parent_to_children: Map<string, BaseEvent[]>, visited: Set<string>) => string;
9
+ export declare const buildResultLine: (result: EventResult, indent: string, is_last: boolean, parent_to_children: Map<string, BaseEvent[]>, visited: Set<string>) => string;
10
+ export declare const formatTimestamp: (value?: string) => string;
11
+ export declare const formatResultValue: (value: unknown) => string;
12
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,25 @@
1
+ import { z } from 'zod';
2
+ import type { BaseEvent } from './base_event.js';
3
+ export type EventStatus = 'pending' | 'started' | 'completed';
4
+ export type EventClass<T extends BaseEvent = BaseEvent> = {
5
+ event_type?: string;
6
+ } & (new (...args: any[]) => T);
7
+ export type EventKey<T extends BaseEvent = BaseEvent> = string | EventClass<T>;
8
+ export type EventWithResult<TResult> = BaseEvent & {
9
+ __event_result_type__?: TResult;
10
+ };
11
+ export type EventResultType<TEvent extends BaseEvent> = TEvent extends {
12
+ __event_result_type__?: infer TResult;
13
+ } ? TResult : unknown;
14
+ export type EventHandlerFunction<T extends BaseEvent = BaseEvent> = (event: T) => void | EventResultType<T> | Promise<void | EventResultType<T>>;
15
+ export type UntypedEventHandlerFunction<T extends BaseEvent = BaseEvent> = (event: T) => void | unknown | Promise<void | unknown>;
16
+ export type FindWindow = boolean | number;
17
+ export type FindOptions = {
18
+ past?: FindWindow;
19
+ future?: FindWindow;
20
+ child_of?: BaseEvent | null;
21
+ };
22
+ export declare const isZodSchema: (value: unknown) => value is z.ZodTypeAny;
23
+ export declare const extractZodShape: (raw: Record<string, unknown>) => z.ZodRawShape;
24
+ export declare const toJsonSchema: (schema: unknown) => unknown;
25
+ export declare const getStringTypeName: (schema?: z.ZodTypeAny) => string | undefined;
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "bubus",
3
+ "version": "1.7.3",
4
+ "description": "Event bus library for browsers and ESM Node.js",
5
+ "type": "module",
6
+ "main": "./dist/esm/index.js",
7
+ "module": "./dist/esm/index.js",
8
+ "types": "./dist/types/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/types/index.d.ts",
12
+ "import": "./dist/esm/index.js",
13
+ "default": "./dist/esm/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist/esm",
18
+ "dist/types"
19
+ ],
20
+ "keywords": [],
21
+ "author": "",
22
+ "license": "MIT",
23
+ "dependencies": {
24
+ "uuid": "^11.1.0",
25
+ "zod": "^4.3.6"
26
+ },
27
+ "devDependencies": {
28
+ "@typescript-eslint/eslint-plugin": "^8.46.0",
29
+ "@typescript-eslint/parser": "^8.46.0",
30
+ "esbuild": "^0.27.2",
31
+ "eslint": "^9.39.2",
32
+ "prettier": "^3.8.1",
33
+ "tsx": "^4.20.6",
34
+ "typescript": "^5.9.3"
35
+ },
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "git+https://github.com/pirate/bbus.git",
39
+ "directory": "bubus-ts"
40
+ },
41
+ "bugs": {
42
+ "url": "https://github.com/pirate/bbus/issues"
43
+ },
44
+ "homepage": "https://github.com/pirate/bbus/tree/main/bubus-ts",
45
+ "publishConfig": {
46
+ "access": "public",
47
+ "registry": "https://registry.npmjs.org/"
48
+ },
49
+ "scripts": {
50
+ "build": "pnpm run build:esm && pnpm run build:types",
51
+ "build:esm": "esbuild src/index.ts --bundle --format=esm --platform=neutral --target=es2022 --sourcemap --outdir=dist/esm",
52
+ "build:types": "tsc -p tsconfig.json --emitDeclarationOnly",
53
+ "typecheck": "tsc -p tsconfig.json --noEmit",
54
+ "lint": "eslint .",
55
+ "format": "prettier --write .",
56
+ "format:check": "prettier --check .",
57
+ "test": "NODE_OPTIONS='--expose-gc' node --expose-gc --test --import tsx tests/**/*.test.ts",
58
+ "release:dry-run": "pnpm publish --access public --dry-run --no-git-checks",
59
+ "release:check": "pnpm run typecheck && pnpm test && pnpm run build"
60
+ }
61
+ }