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,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var logging_exports = {};
|
|
20
|
+
__export(logging_exports, {
|
|
21
|
+
buildResultLine: () => buildResultLine,
|
|
22
|
+
buildTreeLine: () => buildTreeLine,
|
|
23
|
+
formatResultValue: () => formatResultValue,
|
|
24
|
+
formatTimestamp: () => formatTimestamp,
|
|
25
|
+
logTree: () => logTree
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(logging_exports);
|
|
28
|
+
var import_base_event = require("./base_event.js");
|
|
29
|
+
var import_event_handler = require("./event_handler.js");
|
|
30
|
+
const logTree = (bus) => {
|
|
31
|
+
const parent_to_children = /* @__PURE__ */ new Map();
|
|
32
|
+
const addChild = (parent_id, child) => {
|
|
33
|
+
const existing = parent_to_children.get(parent_id) ?? [];
|
|
34
|
+
existing.push(child);
|
|
35
|
+
parent_to_children.set(parent_id, existing);
|
|
36
|
+
};
|
|
37
|
+
const root_events = [];
|
|
38
|
+
const seen = /* @__PURE__ */ new Set();
|
|
39
|
+
for (const event of bus.event_history.values()) {
|
|
40
|
+
const parent_id = event.event_parent_id;
|
|
41
|
+
if (!parent_id || parent_id === event.event_id || !bus.event_history.has(parent_id)) {
|
|
42
|
+
if (!seen.has(event.event_id)) {
|
|
43
|
+
root_events.push(event);
|
|
44
|
+
seen.add(event.event_id);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (root_events.length === 0) {
|
|
49
|
+
return "(No events in history)";
|
|
50
|
+
}
|
|
51
|
+
const nodes_by_id = /* @__PURE__ */ new Map();
|
|
52
|
+
for (const root of root_events) {
|
|
53
|
+
nodes_by_id.set(root.event_id, root);
|
|
54
|
+
for (const descendant of root.event_descendants) {
|
|
55
|
+
nodes_by_id.set(descendant.event_id, descendant);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
for (const node of nodes_by_id.values()) {
|
|
59
|
+
const parent_id = node.event_parent_id;
|
|
60
|
+
if (!parent_id || parent_id === node.event_id) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (!nodes_by_id.has(parent_id)) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
addChild(parent_id, node);
|
|
67
|
+
}
|
|
68
|
+
for (const children of parent_to_children.values()) {
|
|
69
|
+
children.sort((a, b) => a.event_created_at < b.event_created_at ? -1 : a.event_created_at > b.event_created_at ? 1 : 0);
|
|
70
|
+
}
|
|
71
|
+
const lines = [];
|
|
72
|
+
const bus_label = typeof bus.toString === "function" ? bus.toString() : bus.name;
|
|
73
|
+
lines.push(`\u{1F4CA} Event History Tree for ${bus_label}`);
|
|
74
|
+
lines.push("=".repeat(80));
|
|
75
|
+
root_events.sort((a, b) => a.event_created_at < b.event_created_at ? -1 : a.event_created_at > b.event_created_at ? 1 : 0);
|
|
76
|
+
const visited = /* @__PURE__ */ new Set();
|
|
77
|
+
root_events.forEach((event, index) => {
|
|
78
|
+
lines.push(buildTreeLine(event, "", index === root_events.length - 1, parent_to_children, visited));
|
|
79
|
+
});
|
|
80
|
+
lines.push("=".repeat(80));
|
|
81
|
+
return lines.join("\n");
|
|
82
|
+
};
|
|
83
|
+
const buildTreeLine = (event, indent, is_last, parent_to_children, visited) => {
|
|
84
|
+
const connector = is_last ? "\u2514\u2500\u2500 " : "\u251C\u2500\u2500 ";
|
|
85
|
+
const status_icon = event.event_status === "completed" ? "\u2705" : event.event_status === "started" ? "\u{1F3C3}" : "\u23F3";
|
|
86
|
+
const created_at = formatTimestamp(event.event_created_at);
|
|
87
|
+
let timing = `[${created_at}`;
|
|
88
|
+
if (event.event_completed_at) {
|
|
89
|
+
const created_ms = Date.parse(event.event_created_at);
|
|
90
|
+
const completed_ms = Date.parse(event.event_completed_at);
|
|
91
|
+
if (!Number.isNaN(created_ms) && !Number.isNaN(completed_ms)) {
|
|
92
|
+
const duration = (completed_ms - created_ms) / 1e3;
|
|
93
|
+
timing += ` (${duration.toFixed(3)}s)`;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
timing += "]";
|
|
97
|
+
const line = `${indent}${connector}${status_icon} ${event.event_type}#${event.event_id.slice(-4)} ${timing}`;
|
|
98
|
+
if (visited.has(event.event_id)) {
|
|
99
|
+
return line;
|
|
100
|
+
}
|
|
101
|
+
visited.add(event.event_id);
|
|
102
|
+
const extension = is_last ? " " : "\u2502 ";
|
|
103
|
+
const new_indent = indent + extension;
|
|
104
|
+
const result_items = [];
|
|
105
|
+
for (const result of event.event_results.values()) {
|
|
106
|
+
result_items.push({ type: "result", result });
|
|
107
|
+
}
|
|
108
|
+
const children = parent_to_children.get(event.event_id) ?? [];
|
|
109
|
+
const printed_child_ids = new Set(event.event_results.size > 0 ? event.event_results.keys() : []);
|
|
110
|
+
for (const child of children) {
|
|
111
|
+
if (!printed_child_ids.has(child.event_id) && !child.event_emitted_by_handler_id) {
|
|
112
|
+
result_items.push({ type: "child", child });
|
|
113
|
+
printed_child_ids.add(child.event_id);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (result_items.length === 0) {
|
|
117
|
+
return line;
|
|
118
|
+
}
|
|
119
|
+
const child_lines = [];
|
|
120
|
+
result_items.forEach((item, index) => {
|
|
121
|
+
const is_last_item = index === result_items.length - 1;
|
|
122
|
+
if (item.type === "result") {
|
|
123
|
+
child_lines.push(buildResultLine(item.result, new_indent, is_last_item, parent_to_children, visited));
|
|
124
|
+
} else {
|
|
125
|
+
child_lines.push(buildTreeLine(item.child, new_indent, is_last_item, parent_to_children, visited));
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
return [line, ...child_lines].join("\n");
|
|
129
|
+
};
|
|
130
|
+
const buildResultLine = (result, indent, is_last, parent_to_children, visited) => {
|
|
131
|
+
const connector = is_last ? "\u2514\u2500\u2500 " : "\u251C\u2500\u2500 ";
|
|
132
|
+
const status_icon = result.status === "completed" ? "\u2705" : result.status === "error" ? "\u274C" : result.status === "started" ? "\u{1F3C3}" : "\u23F3";
|
|
133
|
+
const handler_label = result.handler_name && result.handler_name !== "anonymous" ? result.handler_name : result.handler_file_path ? result.handler_file_path : "anonymous";
|
|
134
|
+
const handler_display = `${result.eventbus_label}.${handler_label}#${result.handler_id.slice(-4)}`;
|
|
135
|
+
let line = `${indent}${connector}${status_icon} ${handler_display}`;
|
|
136
|
+
if (result.started_at) {
|
|
137
|
+
line += ` [${formatTimestamp(result.started_at)}`;
|
|
138
|
+
if (result.completed_at) {
|
|
139
|
+
const started_ms = Date.parse(result.started_at);
|
|
140
|
+
const completed_ms = Date.parse(result.completed_at);
|
|
141
|
+
if (!Number.isNaN(started_ms) && !Number.isNaN(completed_ms)) {
|
|
142
|
+
const duration = (completed_ms - started_ms) / 1e3;
|
|
143
|
+
line += ` (${duration.toFixed(3)}s)`;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
line += "]";
|
|
147
|
+
}
|
|
148
|
+
if (result.status === "error" && result.error) {
|
|
149
|
+
if (result.error instanceof import_event_handler.EventHandlerTimeoutError) {
|
|
150
|
+
line += ` \u23F1\uFE0F Timeout: ${result.error.message}`;
|
|
151
|
+
} else if (result.error instanceof import_event_handler.EventHandlerCancelledError) {
|
|
152
|
+
line += ` \u{1F6AB} Cancelled: ${result.error.message}`;
|
|
153
|
+
} else {
|
|
154
|
+
const error_name = result.error instanceof Error ? result.error.name : "Error";
|
|
155
|
+
const error_message = result.error instanceof Error ? result.error.message : String(result.error);
|
|
156
|
+
line += ` \u2620\uFE0F ${error_name}: ${error_message}`;
|
|
157
|
+
}
|
|
158
|
+
} else if (result.status === "completed") {
|
|
159
|
+
line += ` \u2192 ${formatResultValue(result.result)}`;
|
|
160
|
+
}
|
|
161
|
+
const extension = is_last ? " " : "\u2502 ";
|
|
162
|
+
const new_indent = indent + extension;
|
|
163
|
+
const direct_children = result.event_children;
|
|
164
|
+
if (direct_children.length === 0) {
|
|
165
|
+
return line;
|
|
166
|
+
}
|
|
167
|
+
const child_lines = [];
|
|
168
|
+
const parent_children = parent_to_children.get(result.event_id) ?? [];
|
|
169
|
+
const emitted_children = parent_children.filter((child) => child.event_emitted_by_handler_id === result.handler_id);
|
|
170
|
+
const children_by_id = /* @__PURE__ */ new Map();
|
|
171
|
+
direct_children.forEach((child) => {
|
|
172
|
+
children_by_id.set(child.event_id, child);
|
|
173
|
+
});
|
|
174
|
+
emitted_children.forEach((child) => {
|
|
175
|
+
if (!children_by_id.has(child.event_id)) {
|
|
176
|
+
children_by_id.set(child.event_id, child);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
const children_to_print = Array.from(children_by_id.values()).filter((child) => !visited.has(child.event_id));
|
|
180
|
+
children_to_print.forEach((child, index) => {
|
|
181
|
+
child_lines.push(buildTreeLine(child, new_indent, index === children_to_print.length - 1, parent_to_children, visited));
|
|
182
|
+
});
|
|
183
|
+
return [line, ...child_lines].join("\n");
|
|
184
|
+
};
|
|
185
|
+
const formatTimestamp = (value) => {
|
|
186
|
+
if (!value) {
|
|
187
|
+
return "N/A";
|
|
188
|
+
}
|
|
189
|
+
const date = new Date(value);
|
|
190
|
+
if (Number.isNaN(date.getTime())) {
|
|
191
|
+
return "N/A";
|
|
192
|
+
}
|
|
193
|
+
return date.toISOString().slice(11, 23);
|
|
194
|
+
};
|
|
195
|
+
const formatResultValue = (value) => {
|
|
196
|
+
if (value === null || value === void 0) {
|
|
197
|
+
return "None";
|
|
198
|
+
}
|
|
199
|
+
if (value instanceof import_base_event.BaseEvent) {
|
|
200
|
+
return `Event(${value.event_type}#${value.event_id.slice(-4)})`;
|
|
201
|
+
}
|
|
202
|
+
if (typeof value === "string") {
|
|
203
|
+
return JSON.stringify(value);
|
|
204
|
+
}
|
|
205
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
206
|
+
return String(value);
|
|
207
|
+
}
|
|
208
|
+
if (Array.isArray(value)) {
|
|
209
|
+
return `list(${value.length} items)`;
|
|
210
|
+
}
|
|
211
|
+
if (typeof value === "object") {
|
|
212
|
+
return `dict(${Object.keys(value).length} items)`;
|
|
213
|
+
}
|
|
214
|
+
return `${typeof value}(...)`;
|
|
215
|
+
};
|
|
216
|
+
//# sourceMappingURL=logging.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/logging.ts"],
|
|
4
|
+
"sourcesContent": ["import { BaseEvent } from './base_event.js'\nimport { EventResult } from './event_result.js'\nimport { EventHandlerCancelledError, EventHandlerTimeoutError } from './event_handler.js'\n\ntype LogTreeBus = {\n name: string\n event_history: {\n values(): IterableIterator<BaseEvent>\n has(event_id: string): boolean\n }\n toString?: () => string\n}\n\nexport const logTree = (bus: LogTreeBus): string => {\n const parent_to_children = new Map<string, BaseEvent[]>()\n\n const addChild = (parent_id: string, child: BaseEvent): void => {\n const existing = parent_to_children.get(parent_id) ?? []\n existing.push(child)\n parent_to_children.set(parent_id, existing)\n }\n\n const root_events: BaseEvent[] = []\n const seen = new Set<string>()\n\n for (const event of bus.event_history.values()) {\n const parent_id = event.event_parent_id\n if (!parent_id || parent_id === event.event_id || !bus.event_history.has(parent_id)) {\n if (!seen.has(event.event_id)) {\n root_events.push(event)\n seen.add(event.event_id)\n }\n }\n }\n\n if (root_events.length === 0) {\n return '(No events in history)'\n }\n\n const nodes_by_id = new Map<string, BaseEvent>()\n for (const root of root_events) {\n nodes_by_id.set(root.event_id, root)\n for (const descendant of root.event_descendants) {\n nodes_by_id.set(descendant.event_id, descendant)\n }\n }\n\n for (const node of nodes_by_id.values()) {\n const parent_id = node.event_parent_id\n if (!parent_id || parent_id === node.event_id) {\n continue\n }\n if (!nodes_by_id.has(parent_id)) {\n continue\n }\n addChild(parent_id, node)\n }\n\n for (const children of parent_to_children.values()) {\n children.sort((a, b) => (a.event_created_at < b.event_created_at ? -1 : a.event_created_at > b.event_created_at ? 1 : 0))\n }\n\n const lines: string[] = []\n const bus_label = typeof bus.toString === 'function' ? bus.toString() : bus.name\n lines.push(`\uD83D\uDCCA Event History Tree for ${bus_label}`)\n lines.push('='.repeat(80))\n\n root_events.sort((a, b) => (a.event_created_at < b.event_created_at ? -1 : a.event_created_at > b.event_created_at ? 1 : 0))\n const visited = new Set<string>()\n root_events.forEach((event, index) => {\n lines.push(buildTreeLine(event, '', index === root_events.length - 1, parent_to_children, visited))\n })\n\n lines.push('='.repeat(80))\n\n return lines.join('\\n')\n}\n\nexport const buildTreeLine = (\n event: BaseEvent,\n indent: string,\n is_last: boolean,\n parent_to_children: Map<string, BaseEvent[]>,\n visited: Set<string>\n): string => {\n const connector = is_last ? '\u2514\u2500\u2500 ' : '\u251C\u2500\u2500 '\n const status_icon = event.event_status === 'completed' ? '\u2705' : event.event_status === 'started' ? '\uD83C\uDFC3' : '\u23F3'\n\n const created_at = formatTimestamp(event.event_created_at)\n let timing = `[${created_at}`\n if (event.event_completed_at) {\n const created_ms = Date.parse(event.event_created_at)\n const completed_ms = Date.parse(event.event_completed_at)\n if (!Number.isNaN(created_ms) && !Number.isNaN(completed_ms)) {\n const duration = (completed_ms - created_ms) / 1000\n timing += ` (${duration.toFixed(3)}s)`\n }\n }\n timing += ']'\n\n const line = `${indent}${connector}${status_icon} ${event.event_type}#${event.event_id.slice(-4)} ${timing}`\n\n if (visited.has(event.event_id)) {\n return line\n }\n visited.add(event.event_id)\n\n const extension = is_last ? ' ' : '\u2502 '\n const new_indent = indent + extension\n\n const result_items: Array<{ type: 'result'; result: EventResult } | { type: 'child'; child: BaseEvent }> = []\n for (const result of event.event_results.values()) {\n result_items.push({ type: 'result', result })\n }\n const children = parent_to_children.get(event.event_id) ?? []\n const printed_child_ids = new Set<string>(event.event_results.size > 0 ? event.event_results.keys() : [])\n for (const child of children) {\n if (!printed_child_ids.has(child.event_id) && !child.event_emitted_by_handler_id) {\n result_items.push({ type: 'child', child })\n printed_child_ids.add(child.event_id)\n }\n }\n\n if (result_items.length === 0) {\n return line\n }\n\n const child_lines: string[] = []\n result_items.forEach((item, index) => {\n const is_last_item = index === result_items.length - 1\n if (item.type === 'result') {\n child_lines.push(buildResultLine(item.result, new_indent, is_last_item, parent_to_children, visited))\n } else {\n child_lines.push(buildTreeLine(item.child, new_indent, is_last_item, parent_to_children, visited))\n }\n })\n\n return [line, ...child_lines].join('\\n')\n}\n\nexport const buildResultLine = (\n result: EventResult,\n indent: string,\n is_last: boolean,\n parent_to_children: Map<string, BaseEvent[]>,\n visited: Set<string>\n): string => {\n const connector = is_last ? '\u2514\u2500\u2500 ' : '\u251C\u2500\u2500 '\n const status_icon = result.status === 'completed' ? '\u2705' : result.status === 'error' ? '\u274C' : result.status === 'started' ? '\uD83C\uDFC3' : '\u23F3'\n\n const handler_label =\n result.handler_name && result.handler_name !== 'anonymous'\n ? result.handler_name\n : result.handler_file_path\n ? result.handler_file_path\n : 'anonymous'\n const handler_display = `${result.eventbus_label}.${handler_label}#${result.handler_id.slice(-4)}`\n let line = `${indent}${connector}${status_icon} ${handler_display}`\n\n if (result.started_at) {\n line += ` [${formatTimestamp(result.started_at)}`\n if (result.completed_at) {\n const started_ms = Date.parse(result.started_at)\n const completed_ms = Date.parse(result.completed_at)\n if (!Number.isNaN(started_ms) && !Number.isNaN(completed_ms)) {\n const duration = (completed_ms - started_ms) / 1000\n line += ` (${duration.toFixed(3)}s)`\n }\n }\n line += ']'\n }\n\n if (result.status === 'error' && result.error) {\n if (result.error instanceof EventHandlerTimeoutError) {\n line += ` \u23F1\uFE0F Timeout: ${result.error.message}`\n } else if (result.error instanceof EventHandlerCancelledError) {\n line += ` \uD83D\uDEAB Cancelled: ${result.error.message}`\n } else {\n const error_name = result.error instanceof Error ? result.error.name : 'Error'\n const error_message = result.error instanceof Error ? result.error.message : String(result.error)\n line += ` \u2620\uFE0F ${error_name}: ${error_message}`\n }\n } else if (result.status === 'completed') {\n line += ` \u2192 ${formatResultValue(result.result)}`\n }\n\n const extension = is_last ? ' ' : '\u2502 '\n const new_indent = indent + extension\n\n const direct_children = result.event_children\n if (direct_children.length === 0) {\n return line\n }\n\n const child_lines: string[] = []\n const parent_children = parent_to_children.get(result.event_id) ?? []\n const emitted_children = parent_children.filter((child) => child.event_emitted_by_handler_id === result.handler_id)\n const children_by_id = new Map<string, BaseEvent>()\n direct_children.forEach((child) => {\n children_by_id.set(child.event_id, child)\n })\n emitted_children.forEach((child) => {\n if (!children_by_id.has(child.event_id)) {\n children_by_id.set(child.event_id, child)\n }\n })\n const children_to_print = Array.from(children_by_id.values()).filter((child) => !visited.has(child.event_id))\n\n children_to_print.forEach((child, index) => {\n child_lines.push(buildTreeLine(child, new_indent, index === children_to_print.length - 1, parent_to_children, visited))\n })\n\n return [line, ...child_lines].join('\\n')\n}\n\nexport const formatTimestamp = (value?: string): string => {\n if (!value) {\n return 'N/A'\n }\n const date = new Date(value)\n if (Number.isNaN(date.getTime())) {\n return 'N/A'\n }\n return date.toISOString().slice(11, 23)\n}\n\nexport const formatResultValue = (value: unknown): string => {\n if (value === null || value === undefined) {\n return 'None'\n }\n if (value instanceof BaseEvent) {\n return `Event(${value.event_type}#${value.event_id.slice(-4)})`\n }\n if (typeof value === 'string') {\n return JSON.stringify(value)\n }\n if (typeof value === 'number' || typeof value === 'boolean') {\n return String(value)\n }\n if (Array.isArray(value)) {\n return `list(${value.length} items)`\n }\n if (typeof value === 'object') {\n return `dict(${Object.keys(value as Record<string, unknown>).length} items)`\n }\n return `${typeof value}(...)`\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAA0B;AAE1B,2BAAqE;AAW9D,MAAM,UAAU,CAAC,QAA4B;AAClD,QAAM,qBAAqB,oBAAI,IAAyB;AAExD,QAAM,WAAW,CAAC,WAAmB,UAA2B;AAC9D,UAAM,WAAW,mBAAmB,IAAI,SAAS,KAAK,CAAC;AACvD,aAAS,KAAK,KAAK;AACnB,uBAAmB,IAAI,WAAW,QAAQ;AAAA,EAC5C;AAEA,QAAM,cAA2B,CAAC;AAClC,QAAM,OAAO,oBAAI,IAAY;AAE7B,aAAW,SAAS,IAAI,cAAc,OAAO,GAAG;AAC9C,UAAM,YAAY,MAAM;AACxB,QAAI,CAAC,aAAa,cAAc,MAAM,YAAY,CAAC,IAAI,cAAc,IAAI,SAAS,GAAG;AACnF,UAAI,CAAC,KAAK,IAAI,MAAM,QAAQ,GAAG;AAC7B,oBAAY,KAAK,KAAK;AACtB,aAAK,IAAI,MAAM,QAAQ;AAAA,MACzB;AAAA,IACF;AAAA,EACF;AAEA,MAAI,YAAY,WAAW,GAAG;AAC5B,WAAO;AAAA,EACT;AAEA,QAAM,cAAc,oBAAI,IAAuB;AAC/C,aAAW,QAAQ,aAAa;AAC9B,gBAAY,IAAI,KAAK,UAAU,IA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BAAkB,CAAC,UAA2B;AACzD,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AACA,QAAM,OAAO,IAAI,KAAK,KAAK;AAC3B,MAAI,OAAO,MAAM,KAAK,QAAQ,CAAC,GAAG;AAChC,WAAO;AAAA,EACT;AACA,SAAO,KAAK,YAAY,EAAE,MAAM,IAAI,EAAE;AACxC;AAEO,MAAM,oBAAoB,CAAC,UAA2B;AAC3D,MAAI,UAAU,QAAQ,UAAU,QAAW;AACzC,WAAO;AAAA,EACT;AACA,MAAI,iBAAiB,6BAAW;AAC9B,WAAO,SAAS,MAAM,UAAU,IAAI,MAAM,SAAS,MAAM,EAAE,CAAC;AAAA,EAC9D;AACA,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,KAAK,UAAU,KAAK;AAAA,EAC7B;AACA,MAAI,OAAO,UAAU,YAAY,OAAO,UAAU,WAAW;AAC3D,WAAO,OAAO,KAAK;AAAA,EACrB;AACA,MAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,WAAO,QAAQ,MAAM,MAAM;AAAA,EAC7B;AACA,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,QAAQ,OAAO,KAAK,KAAgC,EAAE,MAAM;AAAA,EACrE;AACA,SAAO,GAAG,OAAO,KAAK;AACxB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { BaseEvent } from './base_event.js';
|
|
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;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var middlewares_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(middlewares_exports);
|
|
17
|
+
//# sourceMappingURL=middlewares.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/middlewares.ts"],
|
|
4
|
+
"sourcesContent": ["import type { BaseEvent } from './base_event.js'\nimport type { EventBus } from './event_bus.js'\nimport type { EventHandler } from './event_handler.js'\nimport type { EventResult } from './event_result.js'\nimport type { EventStatus } from './types.js'\n\nexport type { EventStatus } from './types.js'\n\nexport interface EventBusMiddleware {\n onEventChange?(eventbus: EventBus, event: BaseEvent, status: EventStatus): void | Promise<void>\n onEventResultChange?(eventbus: EventBus, event: BaseEvent, event_result: EventResult, status: EventStatus): void | Promise<void>\n onBusHandlersChange?(eventbus: EventBus, handler: EventHandler, registered: boolean): void | Promise<void>\n}\n\nexport type EventBusMiddlewareCtor = new () => EventBusMiddleware\nexport type EventBusMiddlewareInput = EventBusMiddleware | EventBusMiddlewareCtor\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var optional_deps_exports = {};
|
|
20
|
+
__export(optional_deps_exports, {
|
|
21
|
+
assertOptionalDependencyAvailable: () => assertOptionalDependencyAvailable,
|
|
22
|
+
importOptionalDependency: () => importOptionalDependency,
|
|
23
|
+
isNodeRuntime: () => isNodeRuntime
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(optional_deps_exports);
|
|
26
|
+
const isNodeRuntime = () => {
|
|
27
|
+
const maybe_process = globalThis.process;
|
|
28
|
+
return typeof maybe_process?.versions?.node === "string";
|
|
29
|
+
};
|
|
30
|
+
const missingDependencyError = (bridge_name, package_name) => new Error(`${bridge_name} requires optional dependency "${package_name}". Install it with: npm install ${package_name}`);
|
|
31
|
+
const assertOptionalDependencyAvailable = (bridge_name, package_name) => {
|
|
32
|
+
if (!isNodeRuntime()) return;
|
|
33
|
+
const maybe_process = globalThis.process;
|
|
34
|
+
const get_builtin_module = maybe_process?.getBuiltinModule;
|
|
35
|
+
let require_fn;
|
|
36
|
+
try {
|
|
37
|
+
require_fn = Function('return typeof require === "function" ? require : undefined')();
|
|
38
|
+
} catch {
|
|
39
|
+
require_fn = void 0;
|
|
40
|
+
}
|
|
41
|
+
if (!require_fn && typeof get_builtin_module === "function") {
|
|
42
|
+
const module_builtin = get_builtin_module("module");
|
|
43
|
+
const create_require = module_builtin?.createRequire;
|
|
44
|
+
if (typeof create_require === "function") {
|
|
45
|
+
const cwd = typeof maybe_process?.cwd === "function" ? maybe_process.cwd() : ".";
|
|
46
|
+
require_fn = create_require(`${cwd}/package.json`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (!require_fn) return;
|
|
50
|
+
try {
|
|
51
|
+
require_fn.resolve(package_name);
|
|
52
|
+
} catch {
|
|
53
|
+
throw missingDependencyError(bridge_name, package_name);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const importOptionalDependency = async (bridge_name, package_name) => {
|
|
57
|
+
const dynamic_import = Function("module_name", "return import(module_name)");
|
|
58
|
+
try {
|
|
59
|
+
return await dynamic_import(package_name);
|
|
60
|
+
} catch {
|
|
61
|
+
throw missingDependencyError(bridge_name, package_name);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=optional_deps.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/optional_deps.ts"],
|
|
4
|
+
"sourcesContent": ["export const isNodeRuntime = (): boolean => {\n const maybe_process = (globalThis as { process?: { versions?: { node?: string } } }).process\n return typeof maybe_process?.versions?.node === 'string'\n}\n\nconst missingDependencyError = (bridge_name: string, package_name: string): Error =>\n new Error(`${bridge_name} requires optional dependency \"${package_name}\". Install it with: npm install ${package_name}`)\n\nexport const assertOptionalDependencyAvailable = (bridge_name: string, package_name: string): void => {\n if (!isNodeRuntime()) return\n\n const maybe_process = (\n globalThis as {\n process?: { getBuiltinModule?: (name: string) => any; cwd?: () => string }\n }\n ).process\n const get_builtin_module = maybe_process?.getBuiltinModule\n\n let require_fn: { resolve: (specifier: string) => string } | undefined\n try {\n require_fn = Function('return typeof require === \"function\" ? require : undefined')() as\n | { resolve: (specifier: string) => string }\n | undefined\n } catch {\n require_fn = undefined\n }\n\n if (!require_fn && typeof get_builtin_module === 'function') {\n const module_builtin = get_builtin_module('module')\n const create_require = module_builtin?.createRequire\n if (typeof create_require === 'function') {\n const cwd = typeof maybe_process?.cwd === 'function' ? maybe_process.cwd() : '.'\n require_fn = create_require(`${cwd}/package.json`) as { resolve: (specifier: string) => string }\n }\n }\n\n if (!require_fn) return\n try {\n require_fn.resolve(package_name)\n } catch {\n throw missingDependencyError(bridge_name, package_name)\n }\n}\n\nexport const importOptionalDependency = async (bridge_name: string, package_name: string): Promise<any> => {\n const dynamic_import = Function('module_name', 'return import(module_name)') as (module_name: string) => Promise<unknown>\n try {\n return (await dynamic_import(package_name)) as any\n } catch {\n throw missingDependencyError(bridge_name, package_name)\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,MAAM,gBAAgB,MAAe;AAC1C,QAAM,gBAAiB,WAA8D;AACrF,SAAO,OAAO,eAAe,UAAU,SAAS;AAClD;AAEA,MAAM,yBAAyB,CAAC,aAAqB,iBACnD,IAAI,MAAM,GAAG,WAAW,kCAAkC,YAAY,mCAAmC,YAAY,EAAE;AAElH,MAAM,oCAAoC,CAAC,aAAqB,iBAA+B;AACpG,MAAI,CAAC,cAAc,EAAG;AAEtB,QAAM,gBACJ,WAGA;AACF,QAAM,qBAAqB,eAAe;AAE1C,MAAI;AACJ,MAAI;AACF,iBAAa,SAAS,4DAA4D,EAAE;AAAA,EAGtF,QAAQ;AACN,iBAAa;AAAA,EACf;AAEA,MAAI,CAAC,cAAc,OAAO,uBAAuB,YAAY;AAC3D,UAAM,iBAAiB,mBAAmB,QAAQ;AAClD,UAAM,iBAAiB,gBAAgB;AACvC,QAAI,OAAO,mBAAmB,YAAY;AACxC,YAAM,MAAM,OAAO,eAAe,QAAQ,aAAa,cAAc,IAAI,IAAI;AAC7E,mBAAa,eAAe,GAAG,GAAG,eAAe;AAAA,IACnD;AAAA,EACF;AAEA,MAAI,CAAC,WAAY;AACjB,MAAI;AACF,eAAW,QAAQ,YAAY;AAAA,EACjC,QAAQ;AACN,UAAM,uBAAuB,aAAa,YAAY;AAAA,EACxD;AACF;AAEO,MAAM,2BAA2B,OAAO,aAAqB,iBAAuC;AACzG,QAAM,iBAAiB,SAAS,eAAe,4BAA4B;AAC3E,MAAI;AACF,WAAQ,MAAM,eAAe,YAAY;AAAA,EAC3C,QAAQ;AACN,UAAM,uBAAuB,aAAa,YAAY;AAAA,EACxD;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export interface RetryOptions {
|
|
2
|
+
/** Total number of attempts including the initial call (1 = no retry, 3 = up to 2 retries). Default: 1 */
|
|
3
|
+
max_attempts?: number;
|
|
4
|
+
/** Seconds to wait between retries. Default: 0 */
|
|
5
|
+
retry_after?: number;
|
|
6
|
+
/** Multiplier applied to retry_after after each attempt for exponential backoff. Default: 1.0 (constant delay) */
|
|
7
|
+
retry_backoff_factor?: number;
|
|
8
|
+
/** Only retry when the thrown error matches one of these matchers. Accepts error class constructors,
|
|
9
|
+
* string error names (matched against error.name), or RegExp patterns (tested against String(error)).
|
|
10
|
+
* Default: undefined (retry on any error) */
|
|
11
|
+
retry_on_errors?: Array<(new (...args: any[]) => Error) | string | RegExp>;
|
|
12
|
+
/** Per-attempt timeout in seconds. Default: undefined (no per-attempt timeout) */
|
|
13
|
+
timeout?: number | null;
|
|
14
|
+
/** Maximum concurrent executions sharing this semaphore. Default: undefined (no concurrency limit) */
|
|
15
|
+
semaphore_limit?: number | null;
|
|
16
|
+
/** Semaphore identifier. Functions with the same name share the same concurrency slot pool. Default: function name.
|
|
17
|
+
* If a function is provided, it receives the same arguments as the wrapped function. */
|
|
18
|
+
semaphore_name?: string | ((...args: any[]) => string) | null;
|
|
19
|
+
/** If true, proceed without concurrency limit when semaphore acquisition times out. Default: true */
|
|
20
|
+
semaphore_lax?: boolean;
|
|
21
|
+
/** Semaphore scoping strategy. Default: 'global'
|
|
22
|
+
* - 'global': all calls share one semaphore (keyed by semaphore_name)
|
|
23
|
+
* - 'class': all instances of the same class share one semaphore (keyed by className.semaphore_name)
|
|
24
|
+
* - 'instance': each object instance gets its own semaphore (keyed by instanceId.semaphore_name)
|
|
25
|
+
* 'class' and 'instance' require `this` to be an object; they fall back to 'global' for standalone calls. */
|
|
26
|
+
semaphore_scope?: 'global' | 'class' | 'instance';
|
|
27
|
+
/** Maximum seconds to wait for semaphore acquisition. Default: undefined → timeout * max(1, limit - 1) */
|
|
28
|
+
semaphore_timeout?: number | null;
|
|
29
|
+
}
|
|
30
|
+
/** Thrown when a single attempt exceeds the per-attempt timeout. */
|
|
31
|
+
export declare class RetryTimeoutError extends Error {
|
|
32
|
+
timeout_seconds: number;
|
|
33
|
+
attempt: number;
|
|
34
|
+
constructor(message: string, params: {
|
|
35
|
+
timeout_seconds: number;
|
|
36
|
+
attempt: number;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/** Thrown (when semaphore_lax=false) if the semaphore cannot be acquired within the timeout. */
|
|
40
|
+
export declare class SemaphoreTimeoutError extends Error {
|
|
41
|
+
semaphore_name: string;
|
|
42
|
+
semaphore_limit: number;
|
|
43
|
+
timeout_seconds: number;
|
|
44
|
+
constructor(message: string, params: {
|
|
45
|
+
semaphore_name: string;
|
|
46
|
+
semaphore_limit: number;
|
|
47
|
+
timeout_seconds: number;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/** Reset the global semaphore registry. Useful in tests. */
|
|
51
|
+
export declare function clearSemaphoreRegistry(): void;
|
|
52
|
+
export declare function retry(options?: RetryOptions): <T extends (...args: any[]) => any>(target: T, _context?: ClassMethodDecoratorContext) => T;
|