abxbus 2.4.26 → 2.4.28
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 +211 -0
- package/dist/cjs/{base_event.js → BaseEvent.js} +38 -30
- package/dist/cjs/BaseEvent.js.map +7 -0
- package/dist/cjs/EventBridge.d.ts +34 -0
- package/dist/cjs/EventBridge.js +295 -0
- package/dist/cjs/EventBridge.js.map +7 -0
- package/dist/cjs/EventBus.d.ts +125 -0
- package/dist/cjs/{event_bus.js → EventBus.js} +21 -21
- package/dist/cjs/EventBus.js.map +7 -0
- package/dist/cjs/EventBusMiddleware.d.ts +13 -0
- package/dist/cjs/EventBusMiddleware.js +17 -0
- package/dist/cjs/EventBusMiddleware.js.map +7 -0
- package/dist/cjs/EventHandler.d.ts +140 -0
- package/dist/cjs/{event_handler.js → EventHandler.js} +4 -4
- package/dist/cjs/EventHandler.js.map +7 -0
- package/dist/cjs/EventHistory.d.ts +45 -0
- package/dist/cjs/{event_history.js → EventHistory.js} +4 -4
- package/dist/cjs/EventHistory.js.map +7 -0
- package/dist/cjs/EventResult.d.ts +86 -0
- package/dist/cjs/{event_result.js → EventResult.js} +18 -16
- package/dist/cjs/EventResult.js.map +7 -0
- package/dist/cjs/HTTPEventBridge.d.ts +10 -0
- package/dist/cjs/HTTPEventBridge.js +37 -0
- package/dist/cjs/HTTPEventBridge.js.map +7 -0
- package/dist/cjs/JSONLEventBridge.d.ts +26 -0
- package/dist/cjs/{bridge_jsonl.js → JSONLEventBridge.js} +8 -8
- package/dist/cjs/JSONLEventBridge.js.map +7 -0
- package/dist/cjs/LockManager.d.ts +70 -0
- package/dist/cjs/{lock_manager.js → LockManager.js} +4 -4
- package/dist/cjs/LockManager.js.map +7 -0
- package/dist/cjs/NATSEventBridge.d.ts +20 -0
- package/dist/cjs/{bridge_nats.js → NATSEventBridge.js} +8 -8
- package/dist/cjs/NATSEventBridge.js.map +7 -0
- package/dist/cjs/{middleware_otel_tracing.d.ts → OtelTracingMiddleware.d.ts} +4 -4
- package/dist/cjs/{middleware_otel_tracing.js → OtelTracingMiddleware.js} +4 -4
- package/dist/cjs/OtelTracingMiddleware.js.map +7 -0
- package/dist/cjs/PostgresEventBridge.d.ts +31 -0
- package/dist/cjs/{bridge_postgres.js → PostgresEventBridge.js} +8 -8
- package/dist/cjs/PostgresEventBridge.js.map +7 -0
- package/dist/cjs/RedisEventBridge.d.ts +34 -0
- package/dist/cjs/{bridge_redis.js → RedisEventBridge.js} +8 -8
- package/dist/cjs/RedisEventBridge.js.map +7 -0
- package/dist/cjs/SQLiteEventBridge.d.ts +30 -0
- package/dist/cjs/{bridge_sqlite.js → SQLiteEventBridge.js} +8 -8
- package/dist/cjs/SQLiteEventBridge.js.map +7 -0
- package/dist/cjs/SocketEventBridge.d.ts +4 -0
- package/dist/cjs/SocketEventBridge.js +35 -0
- package/dist/cjs/SocketEventBridge.js.map +7 -0
- package/dist/cjs/base_event.d.ts +2 -2
- package/dist/cjs/bridges.d.ts +9 -49
- package/dist/cjs/bridges.js +16 -303
- package/dist/cjs/bridges.js.map +2 -2
- package/dist/cjs/event_handler.d.ts +0 -1
- package/dist/cjs/events_suck.d.ts +2 -2
- package/dist/cjs/events_suck.js +4 -4
- package/dist/cjs/events_suck.js.map +2 -2
- package/dist/cjs/index.d.ts +15 -14
- package/dist/cjs/index.js +24 -24
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/logging.d.ts +2 -2
- package/dist/cjs/logging.js +7 -7
- package/dist/cjs/logging.js.map +2 -2
- package/dist/cjs/middlewares.d.ts +1 -13
- package/dist/cjs/middlewares.js.map +1 -1
- package/dist/cjs/types.d.ts +1 -1
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/{base_event.js → BaseEvent.js} +20 -12
- package/dist/esm/BaseEvent.js.map +7 -0
- package/dist/esm/EventBridge.js +275 -0
- package/dist/esm/EventBridge.js.map +7 -0
- package/dist/esm/{event_bus.js → EventBus.js} +5 -5
- package/dist/esm/EventBus.js.map +7 -0
- package/dist/esm/EventBusMiddleware.js +1 -0
- package/dist/esm/EventBusMiddleware.js.map +7 -0
- package/dist/esm/{event_handler.js → EventHandler.js} +1 -1
- package/dist/esm/EventHandler.js.map +7 -0
- package/dist/esm/{event_history.js → EventHistory.js} +1 -1
- package/dist/esm/EventHistory.js.map +7 -0
- package/dist/esm/{event_result.js → EventResult.js} +7 -5
- package/dist/esm/EventResult.js.map +7 -0
- package/dist/esm/HTTPEventBridge.js +17 -0
- package/dist/esm/HTTPEventBridge.js.map +7 -0
- package/dist/esm/{bridge_jsonl.js → JSONLEventBridge.js} +3 -3
- package/dist/esm/JSONLEventBridge.js.map +7 -0
- package/dist/esm/{lock_manager.js → LockManager.js} +1 -1
- package/dist/esm/LockManager.js.map +7 -0
- package/dist/esm/{bridge_nats.js → NATSEventBridge.js} +3 -3
- package/dist/esm/NATSEventBridge.js.map +7 -0
- package/dist/esm/{middleware_otel_tracing.js → OtelTracingMiddleware.js} +1 -1
- package/dist/esm/OtelTracingMiddleware.js.map +7 -0
- package/dist/esm/{bridge_postgres.js → PostgresEventBridge.js} +3 -3
- package/dist/esm/PostgresEventBridge.js.map +7 -0
- package/dist/esm/{bridge_redis.js → RedisEventBridge.js} +3 -3
- package/dist/esm/RedisEventBridge.js.map +7 -0
- package/dist/esm/{bridge_sqlite.js → SQLiteEventBridge.js} +3 -3
- package/dist/esm/SQLiteEventBridge.js.map +7 -0
- package/dist/esm/SocketEventBridge.js +15 -0
- package/dist/esm/SocketEventBridge.js.map +7 -0
- package/dist/esm/bridges.js +9 -296
- package/dist/esm/bridges.js.map +2 -2
- package/dist/esm/events_suck.js +2 -2
- package/dist/esm/events_suck.js.map +1 -1
- package/dist/esm/index.js +11 -19
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/logging.js +2 -2
- package/dist/esm/logging.js.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/types/BaseEvent.d.ts +211 -0
- package/dist/types/EventBridge.d.ts +34 -0
- package/dist/types/EventBus.d.ts +125 -0
- package/dist/types/EventBusMiddleware.d.ts +13 -0
- package/dist/types/EventHandler.d.ts +140 -0
- package/dist/types/EventHistory.d.ts +45 -0
- package/dist/types/EventResult.d.ts +86 -0
- package/dist/types/HTTPEventBridge.d.ts +10 -0
- package/dist/types/JSONLEventBridge.d.ts +26 -0
- package/dist/types/LockManager.d.ts +70 -0
- package/dist/types/NATSEventBridge.d.ts +20 -0
- package/dist/types/{middleware_otel_tracing.d.ts → OtelTracingMiddleware.d.ts} +4 -4
- package/dist/types/PostgresEventBridge.d.ts +31 -0
- package/dist/types/RedisEventBridge.d.ts +34 -0
- package/dist/types/SQLiteEventBridge.d.ts +30 -0
- package/dist/types/SocketEventBridge.d.ts +4 -0
- package/dist/types/base_event.d.ts +2 -2
- package/dist/types/bridges.d.ts +9 -49
- package/dist/types/event_handler.d.ts +0 -1
- package/dist/types/events_suck.d.ts +2 -2
- package/dist/types/index.d.ts +15 -14
- package/dist/types/logging.d.ts +2 -2
- package/dist/types/middlewares.d.ts +1 -13
- package/dist/types/types.d.ts +1 -1
- package/package.json +52 -10
- package/src/{base_event.ts → BaseEvent.ts} +21 -13
- package/src/EventBridge.ts +332 -0
- package/src/{event_bus.ts → EventBus.ts} +6 -6
- package/src/EventBusMiddleware.ts +16 -0
- package/src/{event_handler.ts → EventHandler.ts} +2 -2
- package/src/{event_history.ts → EventHistory.ts} +1 -1
- package/src/{event_result.ts → EventResult.ts} +8 -6
- package/src/HTTPEventBridge.ts +27 -0
- package/src/{bridge_jsonl.ts → JSONLEventBridge.ts} +2 -2
- package/src/{lock_manager.ts → LockManager.ts} +2 -2
- package/src/{bridge_nats.ts → NATSEventBridge.ts} +2 -2
- package/src/{middleware_otel_tracing.ts → OtelTracingMiddleware.ts} +4 -4
- package/src/{bridge_postgres.ts → PostgresEventBridge.ts} +2 -2
- package/src/{bridge_redis.ts → RedisEventBridge.ts} +2 -2
- package/src/{bridge_sqlite.ts → SQLiteEventBridge.ts} +2 -2
- package/src/SocketEventBridge.ts +13 -0
- package/src/bridges.ts +9 -376
- package/src/events_suck.ts +2 -2
- package/src/index.ts +15 -22
- package/src/logging.ts +3 -3
- package/src/middlewares.ts +1 -16
- package/src/types.ts +1 -1
- package/dist/cjs/base_event.js.map +0 -7
- package/dist/cjs/bridge_jsonl.js.map +0 -7
- package/dist/cjs/bridge_nats.js.map +0 -7
- package/dist/cjs/bridge_postgres.js.map +0 -7
- package/dist/cjs/bridge_redis.js.map +0 -7
- package/dist/cjs/bridge_sqlite.js.map +0 -7
- package/dist/cjs/event_bus.js.map +0 -7
- package/dist/cjs/event_handler.js.map +0 -7
- package/dist/cjs/event_history.js.map +0 -7
- package/dist/cjs/event_result.js.map +0 -7
- package/dist/cjs/lock_manager.js.map +0 -7
- package/dist/cjs/middleware_otel_tracing.js.map +0 -7
- package/dist/esm/base_event.js.map +0 -7
- package/dist/esm/bridge_jsonl.js.map +0 -7
- package/dist/esm/bridge_nats.js.map +0 -7
- package/dist/esm/bridge_postgres.js.map +0 -7
- package/dist/esm/bridge_redis.js.map +0 -7
- package/dist/esm/bridge_sqlite.js.map +0 -7
- package/dist/esm/event_bus.js.map +0 -7
- package/dist/esm/event_handler.js.map +0 -7
- package/dist/esm/event_history.js.map +0 -7
- package/dist/esm/event_result.js.map +0 -7
- package/dist/esm/lock_manager.js.map +0 -7
- package/dist/esm/middleware_otel_tracing.js.map +0 -7
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { BaseEvent } from './BaseEvent.js';
|
|
2
|
+
import type { EventClass, EventHandlerCallable, UntypedEventHandlerFunction } from './types.js';
|
|
3
|
+
export declare class JSONLEventBridge {
|
|
4
|
+
readonly path: string;
|
|
5
|
+
readonly poll_interval: number;
|
|
6
|
+
readonly name: string;
|
|
7
|
+
private readonly inbound_bus;
|
|
8
|
+
private running;
|
|
9
|
+
private byte_offset;
|
|
10
|
+
private pending_line;
|
|
11
|
+
private listener_task;
|
|
12
|
+
constructor(path: string, poll_interval?: number, name?: string);
|
|
13
|
+
on<T extends BaseEvent>(event_pattern: EventClass<T>, handler: EventHandlerCallable<T>): void;
|
|
14
|
+
on<T extends BaseEvent>(event_pattern: string | '*', handler: UntypedEventHandlerFunction<T>): void;
|
|
15
|
+
emit<T extends BaseEvent>(event: T): Promise<void>;
|
|
16
|
+
dispatch<T extends BaseEvent>(event: T): Promise<void>;
|
|
17
|
+
start(): Promise<void>;
|
|
18
|
+
close(): Promise<void>;
|
|
19
|
+
private ensureStarted;
|
|
20
|
+
private listenLoop;
|
|
21
|
+
private pollNewLines;
|
|
22
|
+
private dispatchInboundPayload;
|
|
23
|
+
private readAppended;
|
|
24
|
+
private dirname;
|
|
25
|
+
private loadFs;
|
|
26
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { BaseEvent } from './BaseEvent.js';
|
|
2
|
+
import type { EventResult } from './EventResult.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
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BaseEvent } from './BaseEvent.js';
|
|
2
|
+
import type { EventClass, EventHandlerCallable, UntypedEventHandlerFunction } from './types.js';
|
|
3
|
+
export declare class NATSEventBridge {
|
|
4
|
+
readonly server: string;
|
|
5
|
+
readonly subject: string;
|
|
6
|
+
readonly name: string;
|
|
7
|
+
private readonly inbound_bus;
|
|
8
|
+
private running;
|
|
9
|
+
private nc;
|
|
10
|
+
private sub_task;
|
|
11
|
+
constructor(server: string, subject: string, name?: string);
|
|
12
|
+
on<T extends BaseEvent>(event_pattern: EventClass<T>, handler: EventHandlerCallable<T>): void;
|
|
13
|
+
on<T extends BaseEvent>(event_pattern: string | '*', handler: UntypedEventHandlerFunction<T>): void;
|
|
14
|
+
emit<T extends BaseEvent>(event: T): Promise<void>;
|
|
15
|
+
dispatch<T extends BaseEvent>(event: T): Promise<void>;
|
|
16
|
+
start(): Promise<void>;
|
|
17
|
+
close(): Promise<void>;
|
|
18
|
+
private ensureStarted;
|
|
19
|
+
private dispatchInboundPayload;
|
|
20
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { trace, type Span, type SpanAttributes, type SpanContext, type TimeInput, type Tracer } from '@opentelemetry/api';
|
|
2
|
-
import type { BaseEvent } from './
|
|
3
|
-
import type { EventBus } from './
|
|
4
|
-
import type { EventResult } from './
|
|
5
|
-
import type { EventBusMiddleware } from './
|
|
2
|
+
import type { BaseEvent } from './BaseEvent.js';
|
|
3
|
+
import type { EventBus } from './EventBus.js';
|
|
4
|
+
import type { EventResult } from './EventResult.js';
|
|
5
|
+
import type { EventBusMiddleware } from './EventBusMiddleware.js';
|
|
6
6
|
import type { EventStatus } from './types.js';
|
|
7
7
|
type OpenTelemetryTraceApi = Pick<typeof trace, 'getTracer' | 'setSpan'> & Partial<Pick<typeof trace, 'setSpanContext'>>;
|
|
8
8
|
export type OtelTracingSpanFactoryInput = {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PostgreSQL LISTEN/NOTIFY + flat-table bridge for forwarding events.
|
|
3
|
+
*/
|
|
4
|
+
import { BaseEvent } from './BaseEvent.js';
|
|
5
|
+
import type { EventClass, EventHandlerCallable, UntypedEventHandlerFunction } from './types.js';
|
|
6
|
+
export declare class PostgresEventBridge {
|
|
7
|
+
readonly table_url: string;
|
|
8
|
+
readonly dsn: string;
|
|
9
|
+
readonly table: string;
|
|
10
|
+
readonly channel: string;
|
|
11
|
+
readonly name: string;
|
|
12
|
+
private readonly inbound_bus;
|
|
13
|
+
private running;
|
|
14
|
+
private client;
|
|
15
|
+
private table_columns;
|
|
16
|
+
private notification_handler;
|
|
17
|
+
constructor(table_url: string, channel?: string, name?: string);
|
|
18
|
+
on<T extends BaseEvent>(event_pattern: EventClass<T>, handler: EventHandlerCallable<T>): void;
|
|
19
|
+
on<T extends BaseEvent>(event_pattern: string | '*', handler: UntypedEventHandlerFunction<T>): void;
|
|
20
|
+
emit<T extends BaseEvent>(event: T): Promise<void>;
|
|
21
|
+
dispatch<T extends BaseEvent>(event: T): Promise<void>;
|
|
22
|
+
start(): Promise<void>;
|
|
23
|
+
close(): Promise<void>;
|
|
24
|
+
private ensureStarted;
|
|
25
|
+
private dispatchByEventId;
|
|
26
|
+
private dispatchInboundPayload;
|
|
27
|
+
private ensureTableExists;
|
|
28
|
+
private ensureBaseIndexes;
|
|
29
|
+
private refreshColumnCache;
|
|
30
|
+
private ensureColumns;
|
|
31
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Redis pub/sub bridge for forwarding events between runtimes.
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* // channel from URL path
|
|
6
|
+
* const bridge = new RedisEventBridge('redis://user:pass@localhost:6379/1/my_channel')
|
|
7
|
+
*
|
|
8
|
+
* // explicit channel override
|
|
9
|
+
* const bridge2 = new RedisEventBridge('redis://user:pass@localhost:6379/1', 'my_channel')
|
|
10
|
+
*
|
|
11
|
+
* URL format:
|
|
12
|
+
* redis://user:pass@host:6379/<db>/<optional_channel>
|
|
13
|
+
*/
|
|
14
|
+
import { BaseEvent } from './BaseEvent.js';
|
|
15
|
+
import type { EventClass, EventHandlerCallable, UntypedEventHandlerFunction } from './types.js';
|
|
16
|
+
export declare class RedisEventBridge {
|
|
17
|
+
readonly url: string;
|
|
18
|
+
readonly channel: string;
|
|
19
|
+
readonly name: string;
|
|
20
|
+
private readonly inbound_bus;
|
|
21
|
+
private running;
|
|
22
|
+
private start_promise;
|
|
23
|
+
private redis_pub;
|
|
24
|
+
private redis_sub;
|
|
25
|
+
constructor(redis_url: string, channel?: string, name?: string);
|
|
26
|
+
on<T extends BaseEvent>(event_pattern: EventClass<T>, handler: EventHandlerCallable<T>): void;
|
|
27
|
+
on<T extends BaseEvent>(event_pattern: string | '*', handler: UntypedEventHandlerFunction<T>): void;
|
|
28
|
+
emit<T extends BaseEvent>(event: T): Promise<void>;
|
|
29
|
+
dispatch<T extends BaseEvent>(event: T): Promise<void>;
|
|
30
|
+
start(): Promise<void>;
|
|
31
|
+
close(): Promise<void>;
|
|
32
|
+
private ensureStarted;
|
|
33
|
+
private dispatchInboundPayload;
|
|
34
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BaseEvent } from './BaseEvent.js';
|
|
2
|
+
import type { EventClass, EventHandlerCallable, UntypedEventHandlerFunction } from './types.js';
|
|
3
|
+
export declare class SQLiteEventBridge {
|
|
4
|
+
readonly path: string;
|
|
5
|
+
readonly table: string;
|
|
6
|
+
readonly poll_interval: number;
|
|
7
|
+
readonly name: string;
|
|
8
|
+
private readonly inbound_bus;
|
|
9
|
+
private running;
|
|
10
|
+
private last_seen_event_created_at;
|
|
11
|
+
private last_seen_event_id;
|
|
12
|
+
private listener_task;
|
|
13
|
+
private start_task;
|
|
14
|
+
private db;
|
|
15
|
+
private table_columns;
|
|
16
|
+
constructor(path: string, table?: string, poll_interval?: number, name?: string);
|
|
17
|
+
on<T extends BaseEvent>(event_pattern: EventClass<T>, handler: EventHandlerCallable<T>): void;
|
|
18
|
+
on<T extends BaseEvent>(event_pattern: string | '*', handler: UntypedEventHandlerFunction<T>): void;
|
|
19
|
+
emit<T extends BaseEvent>(event: T): Promise<void>;
|
|
20
|
+
dispatch<T extends BaseEvent>(event: T): Promise<void>;
|
|
21
|
+
start(): Promise<void>;
|
|
22
|
+
close(): Promise<void>;
|
|
23
|
+
private ensureStarted;
|
|
24
|
+
private listenLoop;
|
|
25
|
+
private dispatchInboundPayload;
|
|
26
|
+
private refreshColumnCache;
|
|
27
|
+
private ensureColumns;
|
|
28
|
+
private ensureBaseIndexes;
|
|
29
|
+
private setCursorToLatestRow;
|
|
30
|
+
}
|
|
@@ -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";
|
package/dist/types/bridges.d.ts
CHANGED
|
@@ -1,49 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
path?: string;
|
|
11
|
-
};
|
|
12
|
-
export type HTTPEventBridgeOptions = {
|
|
13
|
-
send_to?: string | null;
|
|
14
|
-
listen_on?: string | null;
|
|
15
|
-
name?: string;
|
|
16
|
-
};
|
|
17
|
-
declare class _EventBridge {
|
|
18
|
-
readonly send_to: ParsedEndpoint | null;
|
|
19
|
-
readonly listen_on: ParsedEndpoint | null;
|
|
20
|
-
readonly name: string;
|
|
21
|
-
protected readonly inbound_bus: EventBus;
|
|
22
|
-
private start_promise;
|
|
23
|
-
private node_server;
|
|
24
|
-
constructor(send_to?: string | null, listen_on?: string | null, name?: string);
|
|
25
|
-
on<T extends BaseEvent>(event_pattern: EventClass<T>, handler: EventHandlerCallable<T>): void;
|
|
26
|
-
on<T extends BaseEvent>(event_pattern: string | '*', handler: UntypedEventHandlerFunction<T>): void;
|
|
27
|
-
emit<T extends BaseEvent>(event: T): Promise<void>;
|
|
28
|
-
dispatch<T extends BaseEvent>(event: T): Promise<void>;
|
|
29
|
-
start(): Promise<void>;
|
|
30
|
-
close(): Promise<void>;
|
|
31
|
-
private ensureListenerStarted;
|
|
32
|
-
private handleIncomingPayload;
|
|
33
|
-
private sendHttp;
|
|
34
|
-
private sendUnix;
|
|
35
|
-
private startHttpListener;
|
|
36
|
-
private startUnixListener;
|
|
37
|
-
}
|
|
38
|
-
export declare class HTTPEventBridge extends _EventBridge {
|
|
39
|
-
constructor(send_to?: string | null, listen_on?: string | null, name?: string);
|
|
40
|
-
constructor(options?: HTTPEventBridgeOptions);
|
|
41
|
-
}
|
|
42
|
-
export declare class SocketEventBridge extends _EventBridge {
|
|
43
|
-
constructor(path?: string | null, name?: string);
|
|
44
|
-
}
|
|
45
|
-
export { NATSEventBridge } from './bridge_nats.js';
|
|
46
|
-
export { RedisEventBridge } from './bridge_redis.js';
|
|
47
|
-
export { PostgresEventBridge } from './bridge_postgres.js';
|
|
48
|
-
export { JSONLEventBridge } from './bridge_jsonl.js';
|
|
49
|
-
export { SQLiteEventBridge } from './bridge_sqlite.js';
|
|
1
|
+
export { EventBridge } from './EventBridge.js';
|
|
2
|
+
export { HTTPEventBridge } from './HTTPEventBridge.js';
|
|
3
|
+
export type { HTTPEventBridgeOptions } from './HTTPEventBridge.js';
|
|
4
|
+
export { SocketEventBridge } from './SocketEventBridge.js';
|
|
5
|
+
export { JSONLEventBridge } from './JSONLEventBridge.js';
|
|
6
|
+
export { SQLiteEventBridge } from './SQLiteEventBridge.js';
|
|
7
|
+
export { NATSEventBridge } from './NATSEventBridge.js';
|
|
8
|
+
export { RedisEventBridge } from './RedisEventBridge.js';
|
|
9
|
+
export { PostgresEventBridge } from './PostgresEventBridge.js';
|
|
@@ -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,5 +1,5 @@
|
|
|
1
|
-
import { EventBus } from './
|
|
2
|
-
import { BaseEvent } from './
|
|
1
|
+
import { EventBus } from './EventBus.js';
|
|
2
|
+
import { BaseEvent } from './BaseEvent.js';
|
|
3
3
|
import type { EventClass, EventResultType } from './types.js';
|
|
4
4
|
type EventMap = Record<string, EventClass<BaseEvent>>;
|
|
5
5
|
type AnyFn = (...args: any[]) => any;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
export { BaseEvent, BaseEventSchema } from './
|
|
2
|
-
export { EventHistory } from './
|
|
3
|
-
export type { EventHistoryFindOptions, EventHistoryTrimOptions } from './
|
|
4
|
-
export { EventResult } from './
|
|
5
|
-
export { EventBus } from './
|
|
6
|
-
export type { EventBusJSON, EventBusOptions } from './
|
|
1
|
+
export { BaseEvent, BaseEventSchema } from './BaseEvent.js';
|
|
2
|
+
export { EventHistory } from './EventHistory.js';
|
|
3
|
+
export type { EventHistoryFindOptions, EventHistoryTrimOptions } from './EventHistory.js';
|
|
4
|
+
export { EventResult } from './EventResult.js';
|
|
5
|
+
export { EventBus } from './EventBus.js';
|
|
6
|
+
export type { EventBusJSON, EventBusOptions } from './EventBus.js';
|
|
7
|
+
export { EventBridge } from './EventBridge.js';
|
|
8
|
+
export { HTTPEventBridge } from './HTTPEventBridge.js';
|
|
9
|
+
export type { HTTPEventBridgeOptions } from './HTTPEventBridge.js';
|
|
10
|
+
export { SocketEventBridge } from './SocketEventBridge.js';
|
|
11
|
+
export { JSONLEventBridge } from './JSONLEventBridge.js';
|
|
12
|
+
export { SQLiteEventBridge } from './SQLiteEventBridge.js';
|
|
13
|
+
export type { EventBusMiddleware, EventBusMiddlewareCtor, EventBusMiddlewareInput } from './EventBusMiddleware.js';
|
|
7
14
|
export { monotonicDatetime } from './helpers.js';
|
|
8
|
-
export
|
|
9
|
-
export {
|
|
10
|
-
export type { OtelTracingMiddlewareOptions } from './middleware_otel_tracing.js';
|
|
11
|
-
export type { OtelTracingSpanFactory, OtelTracingSpanFactoryInput, OtelTracingSpanProvider } from './middleware_otel_tracing.js';
|
|
12
|
-
export { EventHandlerTimeoutError, EventHandlerCancelledError, EventHandlerAbortedError, EventHandlerResultSchemaError, } from './event_handler.js';
|
|
13
|
-
export type { EventConcurrencyMode, EventHandlerConcurrencyMode, EventHandlerCompletionMode, EventBusInterfaceForLockManager, } from './lock_manager.js';
|
|
15
|
+
export { EventHandlerTimeoutError, EventHandlerCancelledError, EventHandlerAbortedError, EventHandlerResultSchemaError, } from './EventHandler.js';
|
|
16
|
+
export type { EventConcurrencyMode, EventHandlerConcurrencyMode, EventHandlerCompletionMode, EventBusInterfaceForLockManager, } from './LockManager.js';
|
|
14
17
|
export type { EventClass, EventHandlerCallable as EventHandler, EventPattern, EventStatus, FindOptions, FindWindow } from './types.js';
|
|
15
18
|
export { retry, clearSemaphoreRegistry, RetryTimeoutError, SemaphoreTimeoutError } from './retry.js';
|
|
16
19
|
export type { RetryOptions } from './retry.js';
|
|
17
|
-
export { HTTPEventBridge, SocketEventBridge, NATSEventBridge, RedisEventBridge, PostgresEventBridge, JSONLEventBridge, SQLiteEventBridge, } from './bridges.js';
|
|
18
|
-
export type { HTTPEventBridgeOptions } from './bridges.js';
|
|
19
20
|
export { events_suck } from './events_suck.js';
|
|
20
21
|
export type { EventsSuckClient, EventsSuckClientClass, GeneratedEvents } from './events_suck.js';
|
package/dist/types/logging.d.ts
CHANGED
|
@@ -1,13 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import type { EventBus } from './event_bus.js';
|
|
3
|
-
import type { EventHandler } from './event_handler.js';
|
|
4
|
-
import type { EventResult } from './event_result.js';
|
|
5
|
-
import type { EventStatus } from './types.js';
|
|
6
|
-
export type { EventStatus } from './types.js';
|
|
7
|
-
export interface EventBusMiddleware {
|
|
8
|
-
onEventChange?(eventbus: EventBus, event: BaseEvent, status: EventStatus): void | Promise<void>;
|
|
9
|
-
onEventResultChange?(eventbus: EventBus, event: BaseEvent, event_result: EventResult, status: EventStatus): void | Promise<void>;
|
|
10
|
-
onBusHandlersChange?(eventbus: EventBus, handler: EventHandler, registered: boolean): void | Promise<void>;
|
|
11
|
-
}
|
|
12
|
-
export type EventBusMiddlewareCtor = new () => EventBusMiddleware;
|
|
13
|
-
export type EventBusMiddlewareInput = EventBusMiddleware | EventBusMiddlewareCtor;
|
|
1
|
+
export type { EventBusMiddleware, EventBusMiddlewareCtor, EventBusMiddlewareInput } from './EventBusMiddleware.js';
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import type { BaseEvent } from './
|
|
2
|
+
import type { BaseEvent } from './BaseEvent.js';
|
|
3
3
|
export type EventStatus = 'pending' | 'started' | 'completed';
|
|
4
4
|
export type EventClass<T extends BaseEvent = BaseEvent> = {
|
|
5
5
|
event_type?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "abxbus",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.28",
|
|
4
4
|
"description": "Event bus library for browsers and ESM Node.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -15,6 +15,18 @@
|
|
|
15
15
|
"require": "./dist/cjs/index.js",
|
|
16
16
|
"default": "./dist/esm/index.js"
|
|
17
17
|
},
|
|
18
|
+
"./source": {
|
|
19
|
+
"source": "./src/index.ts",
|
|
20
|
+
"types": "./src/index.ts",
|
|
21
|
+
"import": "./src/index.ts",
|
|
22
|
+
"default": "./src/index.ts"
|
|
23
|
+
},
|
|
24
|
+
"./source/*": {
|
|
25
|
+
"source": "./src/*.ts",
|
|
26
|
+
"types": "./src/*.ts",
|
|
27
|
+
"import": "./src/*.ts",
|
|
28
|
+
"default": "./src/*.ts"
|
|
29
|
+
},
|
|
18
30
|
"./*": {
|
|
19
31
|
"source": "./src/*.ts",
|
|
20
32
|
"types": "./dist/types/*.d.ts",
|
|
@@ -34,24 +46,59 @@
|
|
|
34
46
|
"author": "",
|
|
35
47
|
"license": "MIT",
|
|
36
48
|
"dependencies": {
|
|
37
|
-
"@opentelemetry/api": "^1.9.1",
|
|
38
|
-
"@opentelemetry/exporter-trace-otlp-http": "^0.215.0",
|
|
39
|
-
"@opentelemetry/resources": "^2.7.0",
|
|
40
|
-
"@opentelemetry/sdk-trace-base": "^2.7.0",
|
|
41
49
|
"uuid": "^13.0.0",
|
|
42
50
|
"zod": "^4.3.6"
|
|
43
51
|
},
|
|
44
52
|
"devDependencies": {
|
|
53
|
+
"@opentelemetry/api": "^1.9.1",
|
|
54
|
+
"@opentelemetry/exporter-trace-otlp-http": "^0.215.0",
|
|
55
|
+
"@opentelemetry/resources": "^2.7.0",
|
|
56
|
+
"@opentelemetry/sdk-trace-base": "^2.7.0",
|
|
45
57
|
"@types/node": "^25.2.3",
|
|
46
58
|
"@typescript-eslint/eslint-plugin": "^8.55.0",
|
|
47
59
|
"@typescript-eslint/parser": "^8.55.0",
|
|
48
60
|
"esbuild": "^0.27.3",
|
|
49
61
|
"eslint": "^9.39.2",
|
|
62
|
+
"ioredis": "^5.9.3",
|
|
63
|
+
"nats": "^2.29.3",
|
|
64
|
+
"pg": "^8.18.0",
|
|
50
65
|
"prettier": "^3.8.1",
|
|
51
66
|
"tsc-files": "^1.1.4",
|
|
52
67
|
"tsx": "^4.21.0",
|
|
53
68
|
"typescript": "^5.9.3"
|
|
54
69
|
},
|
|
70
|
+
"peerDependencies": {
|
|
71
|
+
"@opentelemetry/api": "^1.9.1",
|
|
72
|
+
"@opentelemetry/exporter-trace-otlp-http": "^0.215.0",
|
|
73
|
+
"@opentelemetry/resources": "^2.7.0",
|
|
74
|
+
"@opentelemetry/sdk-trace-base": "^2.7.0",
|
|
75
|
+
"ioredis": "^5.9.3",
|
|
76
|
+
"nats": "^2.29.3",
|
|
77
|
+
"pg": "^8.18.0"
|
|
78
|
+
},
|
|
79
|
+
"peerDependenciesMeta": {
|
|
80
|
+
"@opentelemetry/api": {
|
|
81
|
+
"optional": true
|
|
82
|
+
},
|
|
83
|
+
"@opentelemetry/exporter-trace-otlp-http": {
|
|
84
|
+
"optional": true
|
|
85
|
+
},
|
|
86
|
+
"@opentelemetry/resources": {
|
|
87
|
+
"optional": true
|
|
88
|
+
},
|
|
89
|
+
"@opentelemetry/sdk-trace-base": {
|
|
90
|
+
"optional": true
|
|
91
|
+
},
|
|
92
|
+
"ioredis": {
|
|
93
|
+
"optional": true
|
|
94
|
+
},
|
|
95
|
+
"nats": {
|
|
96
|
+
"optional": true
|
|
97
|
+
},
|
|
98
|
+
"pg": {
|
|
99
|
+
"optional": true
|
|
100
|
+
}
|
|
101
|
+
},
|
|
55
102
|
"repository": {
|
|
56
103
|
"type": "git",
|
|
57
104
|
"url": "git+https://github.com/ArchiveBox/abxbus.git",
|
|
@@ -65,11 +112,6 @@
|
|
|
65
112
|
"access": "public",
|
|
66
113
|
"registry": "https://registry.npmjs.org/"
|
|
67
114
|
},
|
|
68
|
-
"optionalDependencies": {
|
|
69
|
-
"ioredis": "^5.9.3",
|
|
70
|
-
"nats": "^2.29.3",
|
|
71
|
-
"pg": "^8.18.0"
|
|
72
|
-
},
|
|
73
115
|
"scripts": {
|
|
74
116
|
"build": "pnpm run build:esm && pnpm run build:cjs && pnpm run build:types && pnpm run build:cjs:types",
|
|
75
117
|
"build:esm": "node ./scripts/build_esm.mjs",
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { z } from 'zod'
|
|
2
2
|
import { v7 as uuidv7 } from 'uuid'
|
|
3
3
|
|
|
4
|
-
import { EventBus } from './
|
|
5
|
-
import { EventResult } from './
|
|
6
|
-
import { EventHandler, EventHandlerAbortedError, EventHandlerCancelledError, EventHandlerTimeoutError } from './
|
|
7
|
-
import type { EventConcurrencyMode, EventHandlerConcurrencyMode, EventHandlerCompletionMode, Deferred } from './
|
|
4
|
+
import { EventBus } from './EventBus.js'
|
|
5
|
+
import { EventResult } from './EventResult.js'
|
|
6
|
+
import { EventHandler, EventHandlerAbortedError, EventHandlerCancelledError, EventHandlerTimeoutError } from './EventHandler.js'
|
|
7
|
+
import type { EventConcurrencyMode, EventHandlerConcurrencyMode, EventHandlerCompletionMode, Deferred } from './LockManager.js'
|
|
8
8
|
import {
|
|
9
9
|
AsyncLock,
|
|
10
10
|
EVENT_CONCURRENCY_MODES,
|
|
11
11
|
EVENT_HANDLER_CONCURRENCY_MODES,
|
|
12
12
|
EVENT_HANDLER_COMPLETION_MODES,
|
|
13
13
|
withResolvers,
|
|
14
|
-
} from './
|
|
14
|
+
} from './LockManager.js'
|
|
15
15
|
import { _runWithTimeout } from './timing.js'
|
|
16
16
|
import { extractZodShape, normalizeEventResultType, toJsonSchema } from './types.js'
|
|
17
17
|
import type { EventHandlerCallable, EventResultType } from './types.js'
|
|
@@ -71,7 +71,7 @@ export const BaseEventSchema = z
|
|
|
71
71
|
event_status: z.enum(['pending', 'started', 'completed']).optional(),
|
|
72
72
|
event_started_at: z.string().datetime().nullable().optional(),
|
|
73
73
|
event_completed_at: z.string().datetime().nullable().optional(),
|
|
74
|
-
event_results: z.
|
|
74
|
+
event_results: z.record(z.string(), z.unknown()).optional(),
|
|
75
75
|
event_concurrency: z.enum(EVENT_CONCURRENCY_MODES).nullable().optional(),
|
|
76
76
|
event_handler_concurrency: z.enum(EVENT_HANDLER_CONCURRENCY_MODES).nullable().optional(),
|
|
77
77
|
event_handler_completion: z.enum(EVENT_HANDLER_COMPLETION_MODES).nullable().optional(),
|
|
@@ -379,7 +379,9 @@ export class BaseEvent {
|
|
|
379
379
|
if (value === undefined || typeof value === 'function') continue
|
|
380
380
|
record[key] = value
|
|
381
381
|
}
|
|
382
|
-
const event_results =
|
|
382
|
+
const event_results = Object.fromEntries(
|
|
383
|
+
Array.from(this.event_results.entries()).map(([handler_id, result]) => [handler_id, result.toJSON()])
|
|
384
|
+
)
|
|
383
385
|
|
|
384
386
|
return {
|
|
385
387
|
...record,
|
|
@@ -411,7 +413,7 @@ export class BaseEvent {
|
|
|
411
413
|
event_completed_at: this.event_completed_at ?? null,
|
|
412
414
|
|
|
413
415
|
// mutable result state
|
|
414
|
-
...(event_results.length > 0 ? { event_results } : {}),
|
|
416
|
+
...(Object.keys(event_results).length > 0 ? { event_results } : {}),
|
|
415
417
|
}
|
|
416
418
|
}
|
|
417
419
|
|
|
@@ -1189,13 +1191,19 @@ export class BaseEvent {
|
|
|
1189
1191
|
|
|
1190
1192
|
const hydrateEventResults = <TEvent extends BaseEvent>(event: TEvent, raw_event_results: unknown): Map<string, EventResult<TEvent>> => {
|
|
1191
1193
|
const event_results = new Map<string, EventResult<TEvent>>()
|
|
1192
|
-
if (
|
|
1194
|
+
if (raw_event_results == null) {
|
|
1193
1195
|
return event_results
|
|
1194
1196
|
}
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1197
|
+
if (typeof raw_event_results !== 'object' || Array.isArray(raw_event_results)) {
|
|
1198
|
+
throw new Error('BaseEvent.event_results must be an object keyed by handler id')
|
|
1199
|
+
}
|
|
1200
|
+
for (const [handler_id, item] of Object.entries(raw_event_results)) {
|
|
1201
|
+
if (item == null || typeof item !== 'object' || Array.isArray(item)) continue
|
|
1202
|
+
const result = EventResult.fromJSON(event, {
|
|
1203
|
+
handler_id,
|
|
1204
|
+
...(item as Record<string, unknown>),
|
|
1205
|
+
})
|
|
1206
|
+
event_results.set(handler_id, result)
|
|
1199
1207
|
}
|
|
1200
1208
|
return event_results
|
|
1201
1209
|
}
|