abxbus 2.4.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/README.md +647 -0
- package/dist/cjs/async_context.d.ts +12 -0
- package/dist/cjs/async_context.js +70 -0
- package/dist/cjs/async_context.js.map +7 -0
- package/dist/cjs/base_event.d.ts +207 -0
- package/dist/cjs/base_event.js +871 -0
- package/dist/cjs/base_event.js.map +7 -0
- package/dist/cjs/bridge_jsonl.d.ts +26 -0
- package/dist/cjs/bridge_jsonl.js +170 -0
- package/dist/cjs/bridge_jsonl.js.map +7 -0
- package/dist/cjs/bridge_nats.d.ts +20 -0
- package/dist/cjs/bridge_nats.js +108 -0
- package/dist/cjs/bridge_nats.js.map +7 -0
- package/dist/cjs/bridge_postgres.d.ts +31 -0
- package/dist/cjs/bridge_postgres.js +251 -0
- package/dist/cjs/bridge_postgres.js.map +7 -0
- package/dist/cjs/bridge_redis.d.ts +34 -0
- package/dist/cjs/bridge_redis.js +175 -0
- package/dist/cjs/bridge_redis.js.map +7 -0
- package/dist/cjs/bridge_sqlite.d.ts +30 -0
- package/dist/cjs/bridge_sqlite.js +255 -0
- package/dist/cjs/bridge_sqlite.js.map +7 -0
- package/dist/cjs/bridges.d.ts +49 -0
- package/dist/cjs/bridges.js +326 -0
- package/dist/cjs/bridges.js.map +7 -0
- package/dist/cjs/event_bus.d.ts +127 -0
- package/dist/cjs/event_bus.js +1058 -0
- package/dist/cjs/event_bus.js.map +7 -0
- package/dist/cjs/event_handler.d.ts +139 -0
- package/dist/cjs/event_handler.js +299 -0
- package/dist/cjs/event_handler.js.map +7 -0
- package/dist/cjs/event_history.d.ts +45 -0
- package/dist/cjs/event_history.js +192 -0
- package/dist/cjs/event_history.js.map +7 -0
- package/dist/cjs/event_result.d.ts +86 -0
- package/dist/cjs/event_result.js +446 -0
- package/dist/cjs/event_result.js.map +7 -0
- package/dist/cjs/events_suck.d.ts +40 -0
- package/dist/cjs/events_suck.js +59 -0
- package/dist/cjs/events_suck.js.map +7 -0
- package/dist/cjs/helpers.d.ts +1 -0
- package/dist/cjs/helpers.js +84 -0
- package/dist/cjs/helpers.js.map +7 -0
- package/dist/cjs/index.d.ts +17 -0
- package/dist/cjs/index.js +54 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/lock_manager.d.ts +70 -0
- package/dist/cjs/lock_manager.js +343 -0
- package/dist/cjs/lock_manager.js.map +7 -0
- package/dist/cjs/logging.d.ts +16 -0
- package/dist/cjs/logging.js +216 -0
- package/dist/cjs/logging.js.map +7 -0
- package/dist/cjs/middlewares.d.ts +13 -0
- package/dist/cjs/middlewares.js +17 -0
- package/dist/cjs/middlewares.js.map +7 -0
- package/dist/cjs/optional_deps.d.ts +3 -0
- package/dist/cjs/optional_deps.js +64 -0
- package/dist/cjs/optional_deps.js.map +7 -0
- package/dist/cjs/package.json +5 -0
- package/dist/cjs/retry.d.ts +52 -0
- package/dist/cjs/retry.js +257 -0
- package/dist/cjs/retry.js.map +7 -0
- package/dist/cjs/timing.d.ts +3 -0
- package/dist/cjs/timing.js +76 -0
- package/dist/cjs/timing.js.map +7 -0
- package/dist/cjs/type_inference.test.d.ts +1 -0
- package/dist/cjs/types.d.ts +36 -0
- package/dist/cjs/types.js +104 -0
- package/dist/cjs/types.js.map +7 -0
- package/dist/esm/async_context.js +50 -0
- package/dist/esm/async_context.js.map +7 -0
- package/dist/esm/base_event.js +857 -0
- package/dist/esm/base_event.js.map +7 -0
- package/dist/esm/bridge_jsonl.js +150 -0
- package/dist/esm/bridge_jsonl.js.map +7 -0
- package/dist/esm/bridge_nats.js +88 -0
- package/dist/esm/bridge_nats.js.map +7 -0
- package/dist/esm/bridge_postgres.js +231 -0
- package/dist/esm/bridge_postgres.js.map +7 -0
- package/dist/esm/bridge_redis.js +155 -0
- package/dist/esm/bridge_redis.js.map +7 -0
- package/dist/esm/bridge_sqlite.js +235 -0
- package/dist/esm/bridge_sqlite.js.map +7 -0
- package/dist/esm/bridges.js +306 -0
- package/dist/esm/bridges.js.map +7 -0
- package/dist/esm/event_bus.js +1046 -0
- package/dist/esm/event_bus.js.map +7 -0
- package/dist/esm/event_handler.js +279 -0
- package/dist/esm/event_handler.js.map +7 -0
- package/dist/esm/event_history.js +172 -0
- package/dist/esm/event_history.js.map +7 -0
- package/dist/esm/event_result.js +426 -0
- package/dist/esm/event_result.js.map +7 -0
- package/dist/esm/events_suck.js +39 -0
- package/dist/esm/events_suck.js.map +7 -0
- package/dist/esm/helpers.js +64 -0
- package/dist/esm/helpers.js.map +7 -0
- package/dist/esm/index.js +47 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/lock_manager.js +323 -0
- package/dist/esm/lock_manager.js.map +7 -0
- package/dist/esm/logging.js +196 -0
- package/dist/esm/logging.js.map +7 -0
- package/dist/esm/middlewares.js +1 -0
- package/dist/esm/middlewares.js.map +7 -0
- package/dist/esm/optional_deps.js +44 -0
- package/dist/esm/optional_deps.js.map +7 -0
- package/dist/esm/retry.js +237 -0
- package/dist/esm/retry.js.map +7 -0
- package/dist/esm/timing.js +56 -0
- package/dist/esm/timing.js.map +7 -0
- package/dist/esm/types.js +84 -0
- package/dist/esm/types.js.map +7 -0
- package/dist/types/async_context.d.ts +12 -0
- package/dist/types/base_event.d.ts +207 -0
- package/dist/types/bridge_jsonl.d.ts +26 -0
- package/dist/types/bridge_nats.d.ts +20 -0
- package/dist/types/bridge_postgres.d.ts +31 -0
- package/dist/types/bridge_redis.d.ts +34 -0
- package/dist/types/bridge_sqlite.d.ts +30 -0
- package/dist/types/bridges.d.ts +49 -0
- package/dist/types/event_bus.d.ts +127 -0
- package/dist/types/event_handler.d.ts +139 -0
- package/dist/types/event_history.d.ts +45 -0
- package/dist/types/event_result.d.ts +86 -0
- package/dist/types/events_suck.d.ts +40 -0
- package/dist/types/helpers.d.ts +1 -0
- package/dist/types/index.d.ts +17 -0
- package/dist/types/lock_manager.d.ts +70 -0
- package/dist/types/logging.d.ts +16 -0
- package/dist/types/middlewares.d.ts +13 -0
- package/dist/types/optional_deps.d.ts +3 -0
- package/dist/types/retry.d.ts +52 -0
- package/dist/types/timing.d.ts +3 -0
- package/dist/types/type_inference.test.d.ts +1 -0
- package/dist/types/types.d.ts +36 -0
- package/package.json +87 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const normalizeEventPattern = (event_pattern) => {
|
|
3
|
+
if (event_pattern === "*") {
|
|
4
|
+
return "*";
|
|
5
|
+
}
|
|
6
|
+
if (typeof event_pattern === "string") {
|
|
7
|
+
return event_pattern;
|
|
8
|
+
}
|
|
9
|
+
const event_type = event_pattern.event_type;
|
|
10
|
+
if (typeof event_type === "string" && event_type.length > 0 && event_type !== "BaseEvent") {
|
|
11
|
+
return event_type;
|
|
12
|
+
}
|
|
13
|
+
const class_name = event_pattern.name;
|
|
14
|
+
if (typeof class_name === "string" && class_name.length > 0 && class_name !== "BaseEvent") {
|
|
15
|
+
return class_name;
|
|
16
|
+
}
|
|
17
|
+
let preview;
|
|
18
|
+
try {
|
|
19
|
+
const encoded = JSON.stringify(event_pattern);
|
|
20
|
+
preview = typeof encoded === "string" ? encoded.slice(0, 30) : String(event_pattern).slice(0, 30);
|
|
21
|
+
} catch {
|
|
22
|
+
preview = String(event_pattern).slice(0, 30);
|
|
23
|
+
}
|
|
24
|
+
throw new Error('bus.on(match_pattern, ...) must be a string event type, "*", or a BaseEvent class, got: ' + preview);
|
|
25
|
+
};
|
|
26
|
+
const isZodSchema = (value) => !!value && typeof value.safeParse === "function";
|
|
27
|
+
const eventResultTypeFromConstructor = (value) => {
|
|
28
|
+
if (value === String) {
|
|
29
|
+
return z.string();
|
|
30
|
+
}
|
|
31
|
+
if (value === Number) {
|
|
32
|
+
return z.number();
|
|
33
|
+
}
|
|
34
|
+
if (value === Boolean) {
|
|
35
|
+
return z.boolean();
|
|
36
|
+
}
|
|
37
|
+
if (value === Array) {
|
|
38
|
+
return z.array(z.unknown());
|
|
39
|
+
}
|
|
40
|
+
if (value === Object) {
|
|
41
|
+
return z.record(z.string(), z.unknown());
|
|
42
|
+
}
|
|
43
|
+
return void 0;
|
|
44
|
+
};
|
|
45
|
+
const extractZodShape = (raw) => {
|
|
46
|
+
const shape = {};
|
|
47
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
48
|
+
if (key === "event_result_type") continue;
|
|
49
|
+
if (isZodSchema(value)) shape[key] = value;
|
|
50
|
+
}
|
|
51
|
+
return shape;
|
|
52
|
+
};
|
|
53
|
+
const toJsonSchema = (schema) => {
|
|
54
|
+
if (!schema || !isZodSchema(schema)) return schema;
|
|
55
|
+
const zod_any = z;
|
|
56
|
+
return zod_any.toJSONSchema(schema);
|
|
57
|
+
};
|
|
58
|
+
const fromJsonSchema = (schema) => {
|
|
59
|
+
const zod_any = z;
|
|
60
|
+
return zod_any.fromJSONSchema(schema);
|
|
61
|
+
};
|
|
62
|
+
const normalizeEventResultType = (value) => {
|
|
63
|
+
if (value === void 0 || value === null) {
|
|
64
|
+
return void 0;
|
|
65
|
+
}
|
|
66
|
+
if (isZodSchema(value)) {
|
|
67
|
+
return value;
|
|
68
|
+
}
|
|
69
|
+
const constructor_schema = eventResultTypeFromConstructor(value);
|
|
70
|
+
if (constructor_schema) {
|
|
71
|
+
return constructor_schema;
|
|
72
|
+
}
|
|
73
|
+
return fromJsonSchema(value);
|
|
74
|
+
};
|
|
75
|
+
export {
|
|
76
|
+
eventResultTypeFromConstructor,
|
|
77
|
+
extractZodShape,
|
|
78
|
+
fromJsonSchema,
|
|
79
|
+
isZodSchema,
|
|
80
|
+
normalizeEventPattern,
|
|
81
|
+
normalizeEventResultType,
|
|
82
|
+
toJsonSchema
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/types.ts"],
|
|
4
|
+
"sourcesContent": ["import { z } from 'zod'\nimport type { BaseEvent } from './base_event.js'\n\nexport type EventStatus = 'pending' | 'started' | 'completed'\n\nexport type EventClass<T extends BaseEvent = BaseEvent> = { event_type?: string } & (new (...args: any[]) => T)\n\nexport type EventPattern<T extends BaseEvent = BaseEvent> = string | EventClass<T>\n\nexport type EventWithResultSchema<TResult> = BaseEvent & { __event_result_type__?: TResult }\n\nexport type EventResultType<TEvent extends BaseEvent> = TEvent extends { __event_result_type__?: infer TResult } ? TResult : unknown\n\nexport type EventResultTypeConstructor = StringConstructor | NumberConstructor | BooleanConstructor | ArrayConstructor | ObjectConstructor\n\nexport type EventResultTypeInput = z.ZodTypeAny | EventResultTypeConstructor | unknown\n\nexport type EventHandlerReturn<T extends BaseEvent = BaseEvent> = EventResultType<T> | BaseEvent | null | void\n\nexport type EventHandlerCallable<T extends BaseEvent = BaseEvent> = (event: T) => EventHandlerReturn<T> | Promise<EventHandlerReturn<T>>\n\n// For string and wildcard subscriptions we cannot reliably infer which event\n// type will arrive, so return type checking intentionally degrades to unknown.\nexport type UntypedEventHandlerFunction<T extends BaseEvent = BaseEvent> = (\n event: T\n) => EventHandlerReturn<T> | unknown | Promise<EventHandlerReturn<T> | unknown>\n\nexport type FindWindow = boolean | number\n\ntype FindReservedOptionKeys = 'past' | 'future' | 'child_of'\n\ntype EventFilterFields<T extends BaseEvent> = {\n [K in keyof T as string extends K\n ? never\n : number extends K\n ? never\n : symbol extends K\n ? never\n : K extends FindReservedOptionKeys\n ? never\n : T[K] extends (...args: any[]) => any\n ? never\n : K]?: T[K]\n}\n\nexport type FindOptions<T extends BaseEvent = BaseEvent> = {\n past?: FindWindow\n future?: FindWindow\n child_of?: BaseEvent | null\n} & EventFilterFields<T> &\n Record<string, unknown>\n\nexport const normalizeEventPattern = (event_pattern: EventPattern | '*'): string | '*' => {\n if (event_pattern === '*') {\n return '*'\n }\n if (typeof event_pattern === 'string') {\n return event_pattern\n }\n const event_type = (event_pattern as { event_type?: unknown }).event_type\n if (typeof event_type === 'string' && event_type.length > 0 && event_type !== 'BaseEvent') {\n return event_type\n }\n const class_name = (event_pattern as { name?: unknown }).name\n if (typeof class_name === 'string' && class_name.length > 0 && class_name !== 'BaseEvent') {\n return class_name\n }\n let preview: string\n try {\n const encoded = JSON.stringify(event_pattern)\n preview = typeof encoded === 'string' ? encoded.slice(0, 30) : String(event_pattern).slice(0, 30)\n } catch {\n preview = String(event_pattern).slice(0, 30)\n }\n throw new Error('bus.on(match_pattern, ...) must be a string event type, \"*\", or a BaseEvent class, got: ' + preview)\n}\n\nexport const isZodSchema = (value: unknown): value is z.ZodTypeAny => !!value && typeof (value as z.ZodTypeAny).safeParse === 'function'\n\nexport const eventResultTypeFromConstructor = (value: unknown): z.ZodTypeAny | undefined => {\n if (value === String) {\n return z.string()\n }\n if (value === Number) {\n return z.number()\n }\n if (value === Boolean) {\n return z.boolean()\n }\n if (value === Array) {\n return z.array(z.unknown())\n }\n if (value === Object) {\n return z.record(z.string(), z.unknown())\n }\n return undefined\n}\n\nexport const extractZodShape = (raw: Record<string, unknown>): z.ZodRawShape => {\n const shape: Record<string, z.ZodTypeAny> = {}\n for (const [key, value] of Object.entries(raw)) {\n if (key === 'event_result_type') continue\n if (isZodSchema(value)) shape[key] = value\n }\n return shape as z.ZodRawShape\n}\n\nexport const toJsonSchema = (schema: unknown): unknown => {\n if (!schema || !isZodSchema(schema)) return schema\n const zod_any = z as unknown as { toJSONSchema: (input: z.ZodTypeAny) => unknown }\n // Cross-language roundtrips preserve core structural types; constraint keywords may not roundtrip exactly.\n return zod_any.toJSONSchema(schema)\n}\n\nexport const fromJsonSchema = (schema: unknown): z.ZodTypeAny => {\n const zod_any = z as unknown as { fromJSONSchema: (input: unknown) => z.ZodTypeAny }\n return zod_any.fromJSONSchema(schema)\n}\n\nexport const normalizeEventResultType = (value: EventResultTypeInput): z.ZodTypeAny | undefined => {\n if (value === undefined || value === null) {\n return undefined\n }\n if (isZodSchema(value)) {\n return value\n }\n const constructor_schema = eventResultTypeFromConstructor(value)\n if (constructor_schema) {\n return constructor_schema\n }\n return fromJsonSchema(value)\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,SAAS;AAoDX,MAAM,wBAAwB,CAAC,kBAAoD;AACxF,MAAI,kBAAkB,KAAK;AACzB,WAAO;AAAA,EACT;AACA,MAAI,OAAO,kBAAkB,UAAU;AACrC,WAAO;AAAA,EACT;AACA,QAAM,aAAc,cAA2C;AAC/D,MAAI,OAAO,eAAe,YAAY,WAAW,SAAS,KAAK,eAAe,aAAa;AACzF,WAAO;AAAA,EACT;AACA,QAAM,aAAc,cAAqC;AACzD,MAAI,OAAO,eAAe,YAAY,WAAW,SAAS,KAAK,eAAe,aAAa;AACzF,WAAO;AAAA,EACT;AACA,MAAI;AACJ,MAAI;AACF,UAAM,UAAU,KAAK,UAAU,aAAa;AAC5C,cAAU,OAAO,YAAY,WAAW,QAAQ,MAAM,GAAG,EAAE,IAAI,OAAO,aAAa,EAAE,MAAM,GAAG,EAAE;AAAA,EAClG,QAAQ;AACN,cAAU,OAAO,aAAa,EAAE,MAAM,GAAG,EAAE;AAAA,EAC7C;AACA,QAAM,IAAI,MAAM,6FAA6F,OAAO;AACtH;AAEO,MAAM,cAAc,CAAC,UAA0C,CAAC,CAAC,SAAS,OAAQ,MAAuB,cAAc;AAEvH,MAAM,iCAAiC,CAAC,UAA6C;AAC1F,MAAI,UAAU,QAAQ;AACpB,WAAO,EAAE,OAAO;AAAA,EAClB;AACA,MAAI,UAAU,QAAQ;AACpB,WAAO,EAAE,OAAO;AAAA,EAClB;AACA,MAAI,UAAU,SAAS;AACrB,WAAO,EAAE,QAAQ;AAAA,EACnB;AACA,MAAI,UAAU,OAAO;AACnB,WAAO,EAAE,MAAM,EAAE,QAAQ,CAAC;AAAA,EAC5B;AACA,MAAI,UAAU,QAAQ;AACpB,WAAO,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC;AAAA,EACzC;AACA,SAAO;AACT;AAEO,MAAM,kBAAkB,CAAC,QAAgD;AAC9E,QAAM,QAAsC,CAAC;AAC7C,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,QAAQ,oBAAqB;AACjC,QAAI,YAAY,KAAK,EAAG,OAAM,GAAG,IAAI;AAAA,EACvC;AACA,SAAO;AACT;AAEO,MAAM,eAAe,CAAC,WAA6B;AACxD,MAAI,CAAC,UAAU,CAAC,YAAY,MAAM,EAAG,QAAO;AAC5C,QAAM,UAAU;AAEhB,SAAO,QAAQ,aAAa,MAAM;AACpC;AAEO,MAAM,iBAAiB,CAAC,WAAkC;AAC/D,QAAM,UAAU;AAChB,SAAO,QAAQ,eAAe,MAAM;AACtC;AAEO,MAAM,2BAA2B,CAAC,UAA0D;AACjG,MAAI,UAAU,UAAa,UAAU,MAAM;AACzC,WAAO;AAAA,EACT;AACA,MAAI,YAAY,KAAK,GAAG;AACtB,WAAO;AAAA,EACT;AACA,QAAM,qBAAqB,+BAA+B,KAAK;AAC/D,MAAI,oBAAoB;AACtB,WAAO;AAAA,EACT;AACA,SAAO,eAAe,KAAK;AAC7B;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type AsyncLocalStorageLike = {
|
|
2
|
+
getStore(): unknown;
|
|
3
|
+
run<T>(store: unknown, callback: () => T): T;
|
|
4
|
+
enterWith?(store: unknown): void;
|
|
5
|
+
};
|
|
6
|
+
export type { AsyncLocalStorageLike };
|
|
7
|
+
/** Create a new AsyncLocalStorage instance, or null if unavailable (e.g. in browsers). */
|
|
8
|
+
export declare const createAsyncLocalStorage: () => AsyncLocalStorageLike | null;
|
|
9
|
+
export declare let async_local_storage: AsyncLocalStorageLike | null;
|
|
10
|
+
export declare const captureAsyncContext: () => unknown | null;
|
|
11
|
+
export declare const _runWithAsyncContext: <T>(context: unknown | null, fn: () => T) => T;
|
|
12
|
+
export declare const hasAsyncLocalStorage: () => boolean;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { EventBus } from './event_bus.js';
|
|
3
|
+
import { EventResult } from './event_result.js';
|
|
4
|
+
import { EventHandler } from './event_handler.js';
|
|
5
|
+
import type { EventConcurrencyMode, EventHandlerConcurrencyMode, EventHandlerCompletionMode, Deferred } from './lock_manager.js';
|
|
6
|
+
import { AsyncLock } from './lock_manager.js';
|
|
7
|
+
import type { EventHandlerCallable, EventResultType } from './types.js';
|
|
8
|
+
export declare const BaseEventSchema: z.ZodObject<{
|
|
9
|
+
event_id: z.ZodString;
|
|
10
|
+
event_created_at: z.ZodString;
|
|
11
|
+
event_type: z.ZodString;
|
|
12
|
+
event_version: z.ZodDefault<z.ZodString>;
|
|
13
|
+
event_timeout: z.ZodNullable<z.ZodNumber>;
|
|
14
|
+
event_slow_timeout: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
15
|
+
event_handler_timeout: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
16
|
+
event_handler_slow_timeout: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
17
|
+
event_parent_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
18
|
+
event_path: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
19
|
+
event_result_type: z.ZodOptional<z.ZodUnknown>;
|
|
20
|
+
event_emitted_by_handler_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
21
|
+
event_pending_bus_count: z.ZodOptional<z.ZodNumber>;
|
|
22
|
+
event_status: z.ZodOptional<z.ZodEnum<{
|
|
23
|
+
pending: "pending";
|
|
24
|
+
started: "started";
|
|
25
|
+
completed: "completed";
|
|
26
|
+
}>>;
|
|
27
|
+
event_started_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
28
|
+
event_completed_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
29
|
+
event_results: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
|
|
30
|
+
event_concurrency: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
31
|
+
"global-serial": "global-serial";
|
|
32
|
+
"bus-serial": "bus-serial";
|
|
33
|
+
parallel: "parallel";
|
|
34
|
+
}>>>;
|
|
35
|
+
event_handler_concurrency: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
36
|
+
parallel: "parallel";
|
|
37
|
+
serial: "serial";
|
|
38
|
+
}>>>;
|
|
39
|
+
event_handler_completion: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
40
|
+
all: "all";
|
|
41
|
+
first: "first";
|
|
42
|
+
}>>>;
|
|
43
|
+
}, z.core.$loose>;
|
|
44
|
+
export type BaseEventData = z.infer<typeof BaseEventSchema>;
|
|
45
|
+
export type BaseEventJSON = BaseEventData & Record<string, unknown>;
|
|
46
|
+
type BaseEventFields = Pick<BaseEventData, 'event_id' | 'event_created_at' | 'event_type' | 'event_version' | 'event_timeout' | 'event_slow_timeout' | 'event_handler_timeout' | 'event_handler_slow_timeout' | 'event_parent_id' | 'event_path' | 'event_result_type' | 'event_emitted_by_handler_id' | 'event_pending_bus_count' | 'event_status' | 'event_started_at' | 'event_completed_at' | 'event_results' | 'event_concurrency' | 'event_handler_concurrency' | 'event_handler_completion'>;
|
|
47
|
+
export type BaseEventInit<TFields extends Record<string, unknown>> = TFields & Partial<BaseEventFields>;
|
|
48
|
+
type BaseEventSchemaShape = typeof BaseEventSchema.shape;
|
|
49
|
+
export type EventSchema<TShape extends z.ZodRawShape> = z.ZodObject<BaseEventSchemaShape & TShape>;
|
|
50
|
+
type EventPayload<TShape extends z.ZodRawShape> = TShape extends Record<string, never> ? {} : z.infer<z.ZodObject<TShape>>;
|
|
51
|
+
type EventInput<TShape extends z.ZodRawShape> = z.input<EventSchema<TShape>>;
|
|
52
|
+
export type EventInit<TShape extends z.ZodRawShape> = Omit<EventInput<TShape>, keyof BaseEventFields> & Partial<BaseEventFields>;
|
|
53
|
+
type EventWithResultSchema<TResult> = BaseEvent & {
|
|
54
|
+
__event_result_type__?: TResult;
|
|
55
|
+
};
|
|
56
|
+
type ResultTypeFromEventResultTypeInput<TInput> = TInput extends z.ZodTypeAny ? z.infer<TInput> : TInput extends StringConstructor ? string : TInput extends NumberConstructor ? number : TInput extends BooleanConstructor ? boolean : TInput extends ArrayConstructor ? unknown[] : TInput extends ObjectConstructor ? Record<string, unknown> : unknown;
|
|
57
|
+
type ResultSchemaFromShape<TShape> = TShape extends {
|
|
58
|
+
event_result_type: infer S;
|
|
59
|
+
} ? ResultTypeFromEventResultTypeInput<S> : unknown;
|
|
60
|
+
type EventResultsListInclude<TEvent extends BaseEvent> = (result: EventResultType<TEvent> | undefined, event_result: EventResult<TEvent>) => boolean;
|
|
61
|
+
type EventResultsListOptions<TEvent extends BaseEvent> = {
|
|
62
|
+
timeout?: number | null;
|
|
63
|
+
include?: EventResultsListInclude<TEvent>;
|
|
64
|
+
raise_if_any?: boolean;
|
|
65
|
+
raise_if_none?: boolean;
|
|
66
|
+
};
|
|
67
|
+
type EventDoneOptions = {
|
|
68
|
+
raise_if_any?: boolean;
|
|
69
|
+
};
|
|
70
|
+
type EventResultUpdateOptions<TEvent extends BaseEvent> = {
|
|
71
|
+
eventbus?: EventBus;
|
|
72
|
+
status?: 'pending' | 'started' | 'completed' | 'error';
|
|
73
|
+
result?: EventResultType<TEvent> | BaseEvent | undefined;
|
|
74
|
+
error?: unknown;
|
|
75
|
+
};
|
|
76
|
+
export type EventFactory<TShape extends z.ZodRawShape, TResult = unknown> = {
|
|
77
|
+
(data: EventInit<TShape>): EventWithResultSchema<TResult> & EventPayload<TShape>;
|
|
78
|
+
new (data: EventInit<TShape>): EventWithResultSchema<TResult> & EventPayload<TShape>;
|
|
79
|
+
schema: EventSchema<TShape>;
|
|
80
|
+
class?: new (data: EventInit<TShape>) => EventWithResultSchema<TResult> & EventPayload<TShape>;
|
|
81
|
+
event_type?: string;
|
|
82
|
+
event_version?: string;
|
|
83
|
+
event_result_type?: z.ZodTypeAny;
|
|
84
|
+
fromJSON?: (data: unknown) => EventWithResultSchema<TResult> & EventPayload<TShape>;
|
|
85
|
+
};
|
|
86
|
+
type ZodShapeFrom<TShape extends Record<string, unknown>> = {
|
|
87
|
+
[K in keyof TShape as K extends 'event_result_type' ? never : TShape[K] extends z.ZodTypeAny ? K : never]: Extract<TShape[K], z.ZodTypeAny>;
|
|
88
|
+
};
|
|
89
|
+
export declare class BaseEvent {
|
|
90
|
+
event_id: string;
|
|
91
|
+
event_created_at: string;
|
|
92
|
+
event_type: string;
|
|
93
|
+
event_version: string;
|
|
94
|
+
event_timeout: number | null;
|
|
95
|
+
event_slow_timeout?: number | null;
|
|
96
|
+
event_handler_timeout?: number | null;
|
|
97
|
+
event_handler_slow_timeout?: number | null;
|
|
98
|
+
event_parent_id: string | null;
|
|
99
|
+
event_path: string[];
|
|
100
|
+
event_result_type?: z.ZodTypeAny;
|
|
101
|
+
event_results: Map<string, EventResult<this>>;
|
|
102
|
+
event_emitted_by_handler_id: string | null;
|
|
103
|
+
event_pending_bus_count: number;
|
|
104
|
+
event_status: 'pending' | 'started' | 'completed';
|
|
105
|
+
event_started_at: string | null;
|
|
106
|
+
event_completed_at: string | null;
|
|
107
|
+
event_concurrency?: EventConcurrencyMode | null;
|
|
108
|
+
event_handler_concurrency?: EventHandlerConcurrencyMode | null;
|
|
109
|
+
event_handler_completion?: EventHandlerCompletionMode | null;
|
|
110
|
+
static event_type?: string;
|
|
111
|
+
static event_version: string;
|
|
112
|
+
static schema: z.ZodObject<{
|
|
113
|
+
event_id: z.ZodString;
|
|
114
|
+
event_created_at: z.ZodString;
|
|
115
|
+
event_type: z.ZodString;
|
|
116
|
+
event_version: z.ZodDefault<z.ZodString>;
|
|
117
|
+
event_timeout: z.ZodNullable<z.ZodNumber>;
|
|
118
|
+
event_slow_timeout: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
119
|
+
event_handler_timeout: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
120
|
+
event_handler_slow_timeout: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
121
|
+
event_parent_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
122
|
+
event_path: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
123
|
+
event_result_type: z.ZodOptional<z.ZodUnknown>;
|
|
124
|
+
event_emitted_by_handler_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
125
|
+
event_pending_bus_count: z.ZodOptional<z.ZodNumber>;
|
|
126
|
+
event_status: z.ZodOptional<z.ZodEnum<{
|
|
127
|
+
pending: "pending";
|
|
128
|
+
started: "started";
|
|
129
|
+
completed: "completed";
|
|
130
|
+
}>>;
|
|
131
|
+
event_started_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
132
|
+
event_completed_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
133
|
+
event_results: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
|
|
134
|
+
event_concurrency: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
135
|
+
"global-serial": "global-serial";
|
|
136
|
+
"bus-serial": "bus-serial";
|
|
137
|
+
parallel: "parallel";
|
|
138
|
+
}>>>;
|
|
139
|
+
event_handler_concurrency: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
140
|
+
parallel: "parallel";
|
|
141
|
+
serial: "serial";
|
|
142
|
+
}>>>;
|
|
143
|
+
event_handler_completion: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
144
|
+
all: "all";
|
|
145
|
+
first: "first";
|
|
146
|
+
}>>>;
|
|
147
|
+
}, z.core.$loose>;
|
|
148
|
+
bus?: EventBus;
|
|
149
|
+
_event_original?: BaseEvent;
|
|
150
|
+
_event_dispatch_context?: unknown | null;
|
|
151
|
+
_event_completed_signal: Deferred<this> | null;
|
|
152
|
+
_lock_for_event_handler: AsyncLock | null;
|
|
153
|
+
get event_bus(): EventBus;
|
|
154
|
+
constructor(data?: BaseEventInit<Record<string, unknown>>);
|
|
155
|
+
toString(): string;
|
|
156
|
+
static extend<TShape extends z.ZodRawShape>(event_type: string, shape?: TShape): EventFactory<TShape, ResultSchemaFromShape<TShape>>;
|
|
157
|
+
static extend<TShape extends Record<string, unknown>>(event_type: string, shape?: TShape): EventFactory<ZodShapeFrom<TShape>, ResultSchemaFromShape<TShape>>;
|
|
158
|
+
static fromJSON<T extends typeof BaseEvent>(this: T, data: unknown): InstanceType<T>;
|
|
159
|
+
static toJSONArray(events: Iterable<BaseEvent>): BaseEventJSON[];
|
|
160
|
+
static fromJSONArray(data: unknown): BaseEvent[];
|
|
161
|
+
toJSON(): BaseEventJSON;
|
|
162
|
+
_createSlowEventWarningTimer(): ReturnType<typeof setTimeout> | null;
|
|
163
|
+
eventResultUpdate(handler: EventHandler | EventHandlerCallable<this>, options?: EventResultUpdateOptions<this>): EventResult<this>;
|
|
164
|
+
_createPendingHandlerResults(bus: EventBus): Array<{
|
|
165
|
+
handler: EventHandler;
|
|
166
|
+
result: EventResult;
|
|
167
|
+
}>;
|
|
168
|
+
private _collectPendingResults;
|
|
169
|
+
private _isFirstModeWinningResult;
|
|
170
|
+
private _markFirstModeWinnerIfNeeded;
|
|
171
|
+
private _runHandlerWithLock;
|
|
172
|
+
_runHandlers(pending_entries?: Array<{
|
|
173
|
+
handler: EventHandler;
|
|
174
|
+
result: EventResult;
|
|
175
|
+
}>): Promise<void>;
|
|
176
|
+
_getHandlerLock(default_concurrency?: EventHandlerConcurrencyMode): AsyncLock | null;
|
|
177
|
+
_setHandlerLock(lock: AsyncLock | null): void;
|
|
178
|
+
_getDispatchContext(): unknown | null | undefined;
|
|
179
|
+
_setDispatchContext(dispatch_context: unknown | null | undefined): void;
|
|
180
|
+
get event_parent(): BaseEvent | undefined;
|
|
181
|
+
get event_children(): BaseEvent[];
|
|
182
|
+
get event_descendants(): BaseEvent[];
|
|
183
|
+
_cancelPendingChildProcessing(reason: unknown): void;
|
|
184
|
+
_markRemainingFirstModeResultCancelled(winner: EventResult): void;
|
|
185
|
+
_markCancelled(cause: Error): void;
|
|
186
|
+
_notifyEventParentsOfCompletion(): void;
|
|
187
|
+
done(options?: EventDoneOptions): Promise<this>;
|
|
188
|
+
first(): Promise<EventResultType<this> | undefined>;
|
|
189
|
+
eventResultsList(include: EventResultsListInclude<this>, options?: EventResultsListOptions<this>): Promise<Array<EventResultType<this> | undefined>>;
|
|
190
|
+
eventResultsList(options?: EventResultsListOptions<this>): Promise<Array<EventResultType<this> | undefined>>;
|
|
191
|
+
eventCompleted(): Promise<this>;
|
|
192
|
+
_markPending(): this;
|
|
193
|
+
eventReset(): this;
|
|
194
|
+
_markStarted(started_at?: string | null, notify_hook?: boolean): void;
|
|
195
|
+
_markCompleted(force?: boolean, notify_parents?: boolean): void;
|
|
196
|
+
private dropFromZeroHistoryBuses;
|
|
197
|
+
get event_errors(): unknown[];
|
|
198
|
+
private _isFirstModeControlError;
|
|
199
|
+
_firstProcessingError(options?: {
|
|
200
|
+
ignore_first_mode_control_errors?: boolean;
|
|
201
|
+
}): unknown | undefined;
|
|
202
|
+
get event_result(): EventResultType<this> | undefined;
|
|
203
|
+
_areAllChildrenComplete(): boolean;
|
|
204
|
+
private _notifyDoneListeners;
|
|
205
|
+
_gc(): void;
|
|
206
|
+
}
|
|
207
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { BaseEvent } from './base_event.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,20 @@
|
|
|
1
|
+
import { BaseEvent } from './base_event.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
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PostgreSQL LISTEN/NOTIFY + flat-table bridge for forwarding events.
|
|
3
|
+
*/
|
|
4
|
+
import { BaseEvent } from './base_event.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 './base_event.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 './base_event.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
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { BaseEvent } from './base_event.js';
|
|
2
|
+
import { EventBus } from './event_bus.js';
|
|
3
|
+
import type { EventClass, EventHandlerCallable, UntypedEventHandlerFunction } from './types.js';
|
|
4
|
+
type EndpointScheme = 'unix' | 'http' | 'https';
|
|
5
|
+
type ParsedEndpoint = {
|
|
6
|
+
raw: string;
|
|
7
|
+
scheme: EndpointScheme;
|
|
8
|
+
host?: string;
|
|
9
|
+
port?: number;
|
|
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';
|
|
@@ -0,0 +1,127 @@
|
|
|
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
|
+
_getParentEventResultAcrossAllBuses(event: BaseEvent): EventResult | null;
|
|
116
|
+
private _startRunloop;
|
|
117
|
+
private _processEvent;
|
|
118
|
+
_processEventImmediately<T extends BaseEvent>(event: T, handler_result?: EventResult): Promise<T>;
|
|
119
|
+
private _processEventImmediatelyAcrossBuses;
|
|
120
|
+
private _runloop;
|
|
121
|
+
_hasProcessedEvent(event: BaseEvent): boolean;
|
|
122
|
+
private _resolveImplicitParentHandlerResult;
|
|
123
|
+
_getEventProxyScopedToThisBus<T extends BaseEvent>(event: T, handler_result?: EventResult): T;
|
|
124
|
+
private _resolveFindWaiters;
|
|
125
|
+
_getHandlersForEvent(event: BaseEvent): EventHandler[];
|
|
126
|
+
private _removeIndexedHandler;
|
|
127
|
+
}
|