@dxos/debug 0.10.0 → 0.11.0
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/lib/index.mjs +398 -0
- package/dist/lib/index.mjs.map +1 -0
- package/dist/types/src/index.d.ts +0 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/stack-trace.d.ts +17 -1
- package/dist/types/src/stack-trace.d.ts.map +1 -1
- package/dist/types/src/stack-trace.test.d.ts +2 -0
- package/dist/types/src/stack-trace.test.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -7
- package/src/index.ts +0 -1
- package/src/stack-trace.test.ts +36 -0
- package/src/stack-trace.ts +30 -6
- package/dist/lib/browser/index.mjs +0 -322
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/node-esm/index.mjs +0 -324
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/types/src/error-handler.d.ts +0 -10
- package/dist/types/src/error-handler.d.ts.map +0 -1
- package/src/error-handler.ts +0 -36
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
import { inspect } from "@dxos/node-std/util";
|
|
2
|
+
//#region src/assert.ts
|
|
3
|
+
/**
|
|
4
|
+
* A simple syntax sugar to write `value as T` as a statement.
|
|
5
|
+
*
|
|
6
|
+
* NOTE: This does not provide any type safety.
|
|
7
|
+
* It's just for convenience so that autocomplete works for value.
|
|
8
|
+
* It's recommended to check the type URL manually beforehand or use `assertAnyType` instead.
|
|
9
|
+
* @param value
|
|
10
|
+
*/
|
|
11
|
+
var checkType = (value) => value;
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/error-stream.ts
|
|
14
|
+
/**
|
|
15
|
+
* Represents a stream of errors that entities can expose.
|
|
16
|
+
*/
|
|
17
|
+
var ErrorStream = class {
|
|
18
|
+
_handler;
|
|
19
|
+
_unhandledErrors = 0;
|
|
20
|
+
assertNoUnhandledErrors() {
|
|
21
|
+
if (this._unhandledErrors > 0) throw new Error(`Assertion failed: expected no unhandled errors to be thrown, but ${this._unhandledErrors} were thrown.`);
|
|
22
|
+
}
|
|
23
|
+
raise(error) {
|
|
24
|
+
if (this._handler) this._handler(error);
|
|
25
|
+
else this._unhandledError(error);
|
|
26
|
+
}
|
|
27
|
+
handle(handler) {
|
|
28
|
+
this._handler = handler;
|
|
29
|
+
}
|
|
30
|
+
pipeTo(receiver) {
|
|
31
|
+
this.handle((error) => receiver.raise(error));
|
|
32
|
+
}
|
|
33
|
+
_unhandledError(error) {
|
|
34
|
+
this._unhandledErrors++;
|
|
35
|
+
setTimeout(() => {
|
|
36
|
+
throw error;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/fail.ts
|
|
42
|
+
/**
|
|
43
|
+
* Should be used in expressions where values are cheked not to be null or undefined.
|
|
44
|
+
*
|
|
45
|
+
* Example:
|
|
46
|
+
*
|
|
47
|
+
* ```
|
|
48
|
+
* const value: string | undefined;
|
|
49
|
+
*
|
|
50
|
+
* callMethod(value ?? failUndefined());
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
var failUndefined = () => {
|
|
54
|
+
throw new Error("Required value was null or undefined.");
|
|
55
|
+
};
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/inspect.ts
|
|
58
|
+
/**
|
|
59
|
+
* Utility to automatically log debug info.
|
|
60
|
+
*
|
|
61
|
+
* ```
|
|
62
|
+
* // Called via `console.log`.
|
|
63
|
+
* [inspect.custom] () {
|
|
64
|
+
* return inspectObject(this);
|
|
65
|
+
* }
|
|
66
|
+
*
|
|
67
|
+
* // Called via `JSON.stringify`.
|
|
68
|
+
* toJSON () {
|
|
69
|
+
* return { ... };
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
var inspectObject = (obj) => {
|
|
74
|
+
const name = Object.getPrototypeOf(obj).constructor.name;
|
|
75
|
+
return obj.toJSON ? `${name}(${inspect(obj.toJSON())})` : String(obj);
|
|
76
|
+
};
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/log-method.ts
|
|
79
|
+
function logMethod(target, propertyName, descriptor) {
|
|
80
|
+
const method = descriptor.value;
|
|
81
|
+
descriptor.value = function(...args) {
|
|
82
|
+
console.log(`Called ${target.constructor.name}.${propertyName} ${args}`);
|
|
83
|
+
try {
|
|
84
|
+
const result = method.apply(this, args);
|
|
85
|
+
if (typeof result.catch === "function") result.catch((err) => {
|
|
86
|
+
console.log(`Rejected ${target.constructor.name}.${propertyName}`, err);
|
|
87
|
+
});
|
|
88
|
+
return result;
|
|
89
|
+
} catch (err) {
|
|
90
|
+
console.log(`Thrown ${target.constructor.name}.${propertyName}`, err);
|
|
91
|
+
throw err;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/raise.ts
|
|
97
|
+
/**
|
|
98
|
+
* Immediatelly throws an error passed as an argument.
|
|
99
|
+
*
|
|
100
|
+
* Usefull for throwing errors from inside expressions.
|
|
101
|
+
* For example:
|
|
102
|
+
* ```
|
|
103
|
+
* const item = model.getById(someId) ?? raise(new Error('Not found'));
|
|
104
|
+
* ```
|
|
105
|
+
* @param error
|
|
106
|
+
*/
|
|
107
|
+
var raise = (error) => {
|
|
108
|
+
throw error;
|
|
109
|
+
};
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/snoop.ts
|
|
112
|
+
var SnoopLevel = /* @__PURE__ */ function(SnoopLevel) {
|
|
113
|
+
SnoopLevel[SnoopLevel["DEFAULT"] = 0] = "DEFAULT";
|
|
114
|
+
SnoopLevel[SnoopLevel["VERBOSE"] = 1] = "VERBOSE";
|
|
115
|
+
SnoopLevel[SnoopLevel["BOLD"] = 2] = "BOLD";
|
|
116
|
+
return SnoopLevel;
|
|
117
|
+
}({});
|
|
118
|
+
/**
|
|
119
|
+
* Utils for debug logging of functions.
|
|
120
|
+
*/
|
|
121
|
+
var Snoop = class Snoop {
|
|
122
|
+
_context;
|
|
123
|
+
static stackFunction(err) {
|
|
124
|
+
const match = err.stack.split("\n")[2].match(/.+\((.+)\).*/);
|
|
125
|
+
if (match) {
|
|
126
|
+
const [file, line] = match[1].split(":");
|
|
127
|
+
return `[${file.substring(file.lastIndexOf("/") + 1)}:${line}]`;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
constructor(_context) {
|
|
131
|
+
this._context = _context;
|
|
132
|
+
}
|
|
133
|
+
get verbose() {
|
|
134
|
+
return 1;
|
|
135
|
+
}
|
|
136
|
+
get bold() {
|
|
137
|
+
return 2;
|
|
138
|
+
}
|
|
139
|
+
format(prefix, name, args, level) {
|
|
140
|
+
const pre = prefix.repeat(level === 2 ? 8 : 2);
|
|
141
|
+
const line = `${pre} ${this._context ? `${this._context}.${name}` : name}${args}`;
|
|
142
|
+
return level === 2 ? [
|
|
143
|
+
pre,
|
|
144
|
+
line,
|
|
145
|
+
pre
|
|
146
|
+
].join("\n") : line;
|
|
147
|
+
}
|
|
148
|
+
in(label, level, ...args) {
|
|
149
|
+
return this.format("<", label, level === 0 ? "" : `(${String(...args)})`, level);
|
|
150
|
+
}
|
|
151
|
+
out(label, level, result) {
|
|
152
|
+
return this.format(">", label, level === 0 ? "" : ` = ${String(result)}`, level);
|
|
153
|
+
}
|
|
154
|
+
sync(f, label, level = 1) {
|
|
155
|
+
label = label ?? Snoop.stackFunction(/* @__PURE__ */ new Error());
|
|
156
|
+
return (...args) => {
|
|
157
|
+
console.log(this.in(label ?? "", level, ...args));
|
|
158
|
+
const r = f(...args);
|
|
159
|
+
console.log(this.out(label ?? "", level, r));
|
|
160
|
+
return r;
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
async(f, label, level = 1) {
|
|
164
|
+
label = label ?? Snoop.stackFunction(/* @__PURE__ */ new Error());
|
|
165
|
+
return async (...args) => {
|
|
166
|
+
console.log(this.in(label ?? "", level, ...args));
|
|
167
|
+
const r = await f(...args);
|
|
168
|
+
console.log(this.out(label ?? "", level, r));
|
|
169
|
+
return r;
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
var snoop = new Snoop();
|
|
174
|
+
//#endregion
|
|
175
|
+
//#region src/stack-trace.ts
|
|
176
|
+
/**
|
|
177
|
+
* Will capture the stack trace at the point where the class is created.
|
|
178
|
+
* Stack traces are formatted lazily only when `getStack` is called.
|
|
179
|
+
* Formatting is significantly more expensive than capture so only call getStack when you need them.
|
|
180
|
+
*
|
|
181
|
+
* IMPORTANT: a trace that has never been formatted keeps its entire capture site reachable. V8 holds
|
|
182
|
+
* the captured frames structurally until `Error.prototype.stack` is read, and every frame holds a
|
|
183
|
+
* strong reference to that frame's receiver — so retaining an unformatted `StackTrace` retains the
|
|
184
|
+
* `this` of each function that was on the stack at capture time. Records that outlive their capture
|
|
185
|
+
* site (diagnostics, registries, caches) must therefore store the formatted string rather than the
|
|
186
|
+
* `StackTrace` itself. Keeping one in a never-pruned module-level container leaked an entire ECHO
|
|
187
|
+
* client graph per query on Cloudflare Workers, where nothing ever reads the diagnostics (DX-1140).
|
|
188
|
+
*/
|
|
189
|
+
var StackTrace = class {
|
|
190
|
+
_error;
|
|
191
|
+
_frames;
|
|
192
|
+
constructor() {
|
|
193
|
+
this._error = /* @__PURE__ */ new Error();
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Formats on first use, then releases the captured frames — and with them the capture site.
|
|
197
|
+
*
|
|
198
|
+
* The `Error` is dropped before formatting, not after: releasing the capture site is the whole
|
|
199
|
+
* point, so it must not be contingent on `stack` being present or `split` succeeding.
|
|
200
|
+
*/
|
|
201
|
+
_format() {
|
|
202
|
+
if (!this._frames) {
|
|
203
|
+
const error = this._error;
|
|
204
|
+
this._error = void 0;
|
|
205
|
+
this._frames = error?.stack?.split("\n") ?? [];
|
|
206
|
+
}
|
|
207
|
+
return this._frames;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Get stack formatted as string.
|
|
211
|
+
* @param skipFrames Number of frames to skip. By default, the first frame would be the invocation of the StackTrace constructor.
|
|
212
|
+
* @returns
|
|
213
|
+
*/
|
|
214
|
+
getStack(skipFrames = 0) {
|
|
215
|
+
return this.getStackArray(skipFrames).join("\n");
|
|
216
|
+
}
|
|
217
|
+
getStackArray(skipFrames = 0) {
|
|
218
|
+
return this._format().slice(skipFrames + 2);
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
//#endregion
|
|
222
|
+
//#region src/strings.ts
|
|
223
|
+
var truncate = (str = "", length = 8, pad = false) => {
|
|
224
|
+
if (str.length >= length - 1) return str.substring(0, length - 1) + "…";
|
|
225
|
+
else return pad ? str.padEnd(length, typeof pad === "boolean" ? " " : pad[0]) : str;
|
|
226
|
+
};
|
|
227
|
+
var truncateKey = (key, length = 8) => {
|
|
228
|
+
const str = String(key);
|
|
229
|
+
if (str.length <= length) return str;
|
|
230
|
+
return str.slice(0, length);
|
|
231
|
+
};
|
|
232
|
+
//#endregion
|
|
233
|
+
//#region src/throw.ts
|
|
234
|
+
/**
|
|
235
|
+
* Wrapper for async tests.
|
|
236
|
+
* @param {Function} test - Async test
|
|
237
|
+
* @param errType
|
|
238
|
+
* @return {Promise<void>}
|
|
239
|
+
*
|
|
240
|
+
* @deprecated Use vitests `expect(() => ...).toThrowError();` instead.
|
|
241
|
+
*/
|
|
242
|
+
var expectToThrow = async (test, errType = Error) => {
|
|
243
|
+
let thrown;
|
|
244
|
+
try {
|
|
245
|
+
await test();
|
|
246
|
+
} catch (err) {
|
|
247
|
+
thrown = err;
|
|
248
|
+
}
|
|
249
|
+
if (thrown === void 0 || !(thrown instanceof errType)) throw new Error(`Expected function to throw instance of ${errType.prototype.name}`);
|
|
250
|
+
};
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region src/timeout-warning.ts
|
|
253
|
+
/**
|
|
254
|
+
* Prints a warning to console if the action takes longer then specified timeout. No errors are thrown.
|
|
255
|
+
*
|
|
256
|
+
* @param timeout Timeout in milliseconds after which warning is printed.
|
|
257
|
+
* @param context Context description that would be included in the printed message.
|
|
258
|
+
* @param body Action which is timed.
|
|
259
|
+
*/
|
|
260
|
+
var warnAfterTimeout = async (timeout, context, body) => {
|
|
261
|
+
const stack = new StackTrace();
|
|
262
|
+
const timeoutId = setTimeout(() => {
|
|
263
|
+
console.warn(`Action \`${context}\` is taking more then ${timeout.toLocaleString()}ms to complete. This might be a bug.\n${stack.getStack()}`);
|
|
264
|
+
}, timeout);
|
|
265
|
+
try {
|
|
266
|
+
return await body();
|
|
267
|
+
} finally {
|
|
268
|
+
clearTimeout(timeoutId);
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
/**
|
|
272
|
+
* A decorator that prints a warning to console if method execution time exceeds specified timeout.
|
|
273
|
+
*
|
|
274
|
+
* ```typescript
|
|
275
|
+
* class Foo {
|
|
276
|
+
* @timed(5_000)
|
|
277
|
+
* async doStuff() {
|
|
278
|
+
* // long task
|
|
279
|
+
* }
|
|
280
|
+
* }
|
|
281
|
+
* ```
|
|
282
|
+
*
|
|
283
|
+
* This is useful for debugging code that might deadlock.
|
|
284
|
+
*
|
|
285
|
+
* @param timeout Timeout in milliseconds after which the warning is printed.
|
|
286
|
+
*/
|
|
287
|
+
function timed(timeout) {
|
|
288
|
+
return (target, propertyName, descriptor) => {
|
|
289
|
+
const method = descriptor.value;
|
|
290
|
+
descriptor.value = function(...args) {
|
|
291
|
+
return warnAfterTimeout(timeout, `${target.constructor.name}.${propertyName}`, () => method.apply(this, args));
|
|
292
|
+
};
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
//#endregion
|
|
296
|
+
//#region src/todo.ts
|
|
297
|
+
/**
|
|
298
|
+
* Throws an error. Can be used in an expression instead of a value
|
|
299
|
+
*/
|
|
300
|
+
var todo = (message) => {
|
|
301
|
+
throw new Error(message ?? "Not implemented.");
|
|
302
|
+
};
|
|
303
|
+
//#endregion
|
|
304
|
+
//#region src/devtools-formatter.ts
|
|
305
|
+
/**
|
|
306
|
+
* Lets types provide custom formatters for the Chrome Devtools.
|
|
307
|
+
*
|
|
308
|
+
* https://www.mattzeunert.com/2016/02/19/custom-chrome-devtools-object-formatters.html
|
|
309
|
+
* NOTE: Must be enabled in chrome devtools preferences.
|
|
310
|
+
*
|
|
311
|
+
* @example
|
|
312
|
+
* ```typescript
|
|
313
|
+
* class MyType {
|
|
314
|
+
* get [devtoolsFormatter] (): DevtoolsFormatter {
|
|
315
|
+
* ...
|
|
316
|
+
* }
|
|
317
|
+
* ```
|
|
318
|
+
*/
|
|
319
|
+
var devtoolsFormatter = Symbol.for("devtoolsFormatter");
|
|
320
|
+
var register = () => {
|
|
321
|
+
if (typeof window !== "undefined") (window.devtoolsFormatters ??= []).push({
|
|
322
|
+
header: (value, config) => {
|
|
323
|
+
const formatter = value[devtoolsFormatter];
|
|
324
|
+
if (formatter === void 0) return null;
|
|
325
|
+
if (typeof formatter !== "object" || formatter === null || typeof formatter.header !== "function") throw new Error(`Invalid devtools formatter for ${value.constructor.name}`);
|
|
326
|
+
return formatter.header(config);
|
|
327
|
+
},
|
|
328
|
+
hasBody: (value, config) => {
|
|
329
|
+
const formatter = value[devtoolsFormatter];
|
|
330
|
+
if (!formatter || !formatter.hasBody) return false;
|
|
331
|
+
return formatter.hasBody(config);
|
|
332
|
+
},
|
|
333
|
+
body: (value, config) => {
|
|
334
|
+
const formatter = value[devtoolsFormatter];
|
|
335
|
+
if (!formatter || !formatter.body) return null;
|
|
336
|
+
return formatter.body(config);
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
};
|
|
340
|
+
register();
|
|
341
|
+
//#endregion
|
|
342
|
+
//#region src/equality.ts
|
|
343
|
+
var equalsSymbol = Symbol.for("dxos.common.equals");
|
|
344
|
+
var isEquatable = (value) => {
|
|
345
|
+
return typeof value === "object" && value !== null && typeof value[equalsSymbol] === "function";
|
|
346
|
+
};
|
|
347
|
+
var isEqual = (value, other) => {
|
|
348
|
+
return value[equalsSymbol](other);
|
|
349
|
+
};
|
|
350
|
+
/**
|
|
351
|
+
* Feed this as a third argument to `_.isEqualWith` to compare objects with `Equatable` interface.
|
|
352
|
+
*/
|
|
353
|
+
var loadashEqualityFn = (value, other) => {
|
|
354
|
+
if (!isEquatable(value)) return;
|
|
355
|
+
return isEqual(value, other);
|
|
356
|
+
};
|
|
357
|
+
//#endregion
|
|
358
|
+
//#region src/exposed-modules.ts
|
|
359
|
+
/**
|
|
360
|
+
* Allows to register a module to be used later during debugging.
|
|
361
|
+
*
|
|
362
|
+
* ```ts
|
|
363
|
+
* import * as keys from '@dxos/keys';
|
|
364
|
+
* exposeModule('@dxos/keys', keys);
|
|
365
|
+
*
|
|
366
|
+
* ...
|
|
367
|
+
*
|
|
368
|
+
* const { PublicKey } = importModule('@dxos/keys');
|
|
369
|
+
* ```
|
|
370
|
+
*
|
|
371
|
+
* Overwrites the module if it already exists.
|
|
372
|
+
*/
|
|
373
|
+
var exposeModule = (name, module) => {
|
|
374
|
+
EXPOSED_MODULES[name] = module;
|
|
375
|
+
};
|
|
376
|
+
/**
|
|
377
|
+
* Imports a previously exposed module by its name.
|
|
378
|
+
* Throws an error if the module is not found.
|
|
379
|
+
*
|
|
380
|
+
* @param {string} name - The name of the module to import.
|
|
381
|
+
* @returns {any} The imported module.
|
|
382
|
+
* @throws {Error} If the module is not exposed.
|
|
383
|
+
*/
|
|
384
|
+
var importModule = (name) => {
|
|
385
|
+
if (EXPOSED_MODULES[name]) return EXPOSED_MODULES[name];
|
|
386
|
+
else throw new Error(`Module ${name} is not exposed.`);
|
|
387
|
+
};
|
|
388
|
+
var EXPOSED_MODULES = {};
|
|
389
|
+
//#endregion
|
|
390
|
+
//#region src/inspect-custom.ts
|
|
391
|
+
/**
|
|
392
|
+
* Using this allows code to be written in a portable fashion, so that the custom inspect function is used in an Node.js environment and ignored in the browser.
|
|
393
|
+
*/
|
|
394
|
+
var inspectCustom = Symbol.for("nodejs.util.inspect.custom");
|
|
395
|
+
//#endregion
|
|
396
|
+
export { ErrorStream, Snoop, SnoopLevel, StackTrace, checkType, devtoolsFormatter, equalsSymbol, expectToThrow, exposeModule, failUndefined, importModule, inspectCustom, inspectObject, isEqual, isEquatable, loadashEqualityFn, logMethod, raise, snoop, timed, todo, truncate, truncateKey, warnAfterTimeout };
|
|
397
|
+
|
|
398
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/assert.ts","../../src/error-stream.ts","../../src/fail.ts","../../src/inspect.ts","../../src/log-method.ts","../../src/raise.ts","../../src/snoop.ts","../../src/stack-trace.ts","../../src/strings.ts","../../src/throw.ts","../../src/timeout-warning.ts","../../src/todo.ts","../../src/devtools-formatter.ts","../../src/equality.ts","../../src/exposed-modules.ts","../../src/inspect-custom.ts"],"sourcesContent":["//\n// Copyright 2020 DXOS.org\n//\n\n/**\n * A simple syntax sugar to write `value as T` as a statement.\n *\n * NOTE: This does not provide any type safety.\n * It's just for convenience so that autocomplete works for value.\n * It's recommended to check the type URL manually beforehand or use `assertAnyType` instead.\n * @param value\n */\nexport const checkType = <T>(value: T): T => value;\n","//\n// Copyright 2021 DXOS.org\n//\n\nexport type ErrorHandlerCallback = (error: Error) => void;\n\n/**\n * Represents a stream of errors that entities can expose.\n */\nexport class ErrorStream {\n private _handler: ErrorHandlerCallback | undefined;\n\n private _unhandledErrors = 0;\n\n assertNoUnhandledErrors(): void {\n if (this._unhandledErrors > 0) {\n throw new Error(\n `Assertion failed: expected no unhandled errors to be thrown, but ${this._unhandledErrors} were thrown.`,\n );\n }\n }\n\n raise(error: Error): void {\n if (this._handler) {\n this._handler(error);\n } else {\n this._unhandledError(error);\n }\n }\n\n handle(handler: ErrorHandlerCallback): void {\n this._handler = handler;\n }\n\n pipeTo(receiver: ErrorStream): void {\n this.handle((error) => receiver.raise(error));\n }\n\n private _unhandledError(error: Error): void {\n this._unhandledErrors++;\n\n setTimeout(() => {\n throw error;\n });\n }\n}\n","//\n// Copyright 2021 DXOS.org\n//\n\n/**\n * Should be used in expressions where values are cheked not to be null or undefined.\n *\n * Example:\n *\n * ```\n * const value: string | undefined;\n *\n * callMethod(value ?? failUndefined());\n * ```\n */\n// TODO(burdon): Rename failIfUndefined().\nexport const failUndefined = () => {\n throw new Error('Required value was null or undefined.');\n};\n","//\n// Copyright 2022 DXOS.org\n//\n\nimport { inspect } from 'node:util';\n\n/**\n * Utility to automatically log debug info.\n *\n * ```\n * // Called via `console.log`.\n * [inspect.custom] () {\n * return inspectObject(this);\n * }\n *\n * // Called via `JSON.stringify`.\n * toJSON () {\n * return { ... };\n * }\n * ```\n */\nexport const inspectObject = (obj: any) => {\n const name = Object.getPrototypeOf(obj).constructor.name;\n return obj.toJSON ? `${name}(${inspect(obj.toJSON())})` : String(obj);\n};\n","//\n// Copyright 2021 DXOS.org\n//\n\n/* eslint-disable no-console */\n\nexport function logMethod(\n target: any,\n propertyName: string,\n descriptor: TypedPropertyDescriptor<(...args: any) => any>,\n): void {\n const method = descriptor.value!;\n descriptor.value = function (this: any, ...args: any) {\n console.log(`Called ${target.constructor.name}.${propertyName} ${args}`);\n try {\n const result = method.apply(this, args);\n if (typeof result.catch === 'function') {\n result.catch((err: any) => {\n console.log(`Rejected ${target.constructor.name}.${propertyName}`, err);\n });\n }\n return result;\n } catch (err: any) {\n console.log(`Thrown ${target.constructor.name}.${propertyName}`, err);\n throw err;\n }\n };\n}\n","//\n// Copyright 2020 DXOS.org\n//\n\n/**\n * Immediatelly throws an error passed as an argument.\n *\n * Usefull for throwing errors from inside expressions.\n * For example:\n * ```\n * const item = model.getById(someId) ?? raise(new Error('Not found'));\n * ```\n * @param error\n */\nexport const raise = (error: Error): never => {\n throw error;\n};\n","//\n// Copyright 2022 DXOS.org\n//\n\n/* eslint-disable no-console */\n\nexport enum SnoopLevel {\n DEFAULT = 0,\n VERBOSE = 1,\n BOLD = 2,\n}\n\n/**\n * Utils for debug logging of functions.\n */\n// TODO(burdon): Integrate with log/spyglass.\nexport class Snoop {\n static stackFunction(err: Error): string | undefined {\n const stack = err.stack!.split('\\n');\n const match = stack[2].match(/.+\\((.+)\\).*/);\n if (match) {\n const [file, line] = match[1].split(':');\n return `[${file.substring(file.lastIndexOf('/') + 1)}:${line}]`;\n }\n }\n\n constructor(private readonly _context?: string) {}\n\n get verbose() {\n return SnoopLevel.VERBOSE;\n }\n\n get bold() {\n return SnoopLevel.BOLD;\n }\n\n format(prefix: string, name: string, args: string, level: SnoopLevel): string {\n const pre = prefix.repeat(level === SnoopLevel.BOLD ? 8 : 2);\n const label = this._context ? `${this._context}.${name}` : name;\n const line = `${pre} ${label}${args}`;\n return level === SnoopLevel.BOLD ? [pre, line, pre].join('\\n') : line;\n }\n\n in(label: string, level: SnoopLevel, ...args: any[]): string {\n return this.format('<', label, level === SnoopLevel.DEFAULT ? '' : `(${String(...args)})`, level);\n }\n\n out(label: string, level: SnoopLevel, result: any): string {\n return this.format('>', label, level === SnoopLevel.DEFAULT ? '' : ` = ${String(result)}`, level);\n }\n\n sync(f: any, label?: string, level: SnoopLevel = SnoopLevel.VERBOSE) {\n label = label ?? Snoop.stackFunction(new Error());\n return (...args: any[]) => {\n console.log(this.in(label ?? '', level, ...args));\n const r = f(...args);\n console.log(this.out(label ?? '', level, r));\n return r;\n };\n }\n\n async(f: any, label?: string, level: SnoopLevel = SnoopLevel.VERBOSE) {\n label = label ?? Snoop.stackFunction(new Error());\n return async (...args: any[]) => {\n console.log(this.in(label ?? '', level, ...args));\n const r = await f(...args);\n console.log(this.out(label ?? '', level, r));\n return r;\n };\n }\n}\n\nexport const snoop = new Snoop();\n","//\n// Copyright 2021 DXOS.org\n//\n\n/**\n * Will capture the stack trace at the point where the class is created.\n * Stack traces are formatted lazily only when `getStack` is called.\n * Formatting is significantly more expensive than capture so only call getStack when you need them.\n *\n * IMPORTANT: a trace that has never been formatted keeps its entire capture site reachable. V8 holds\n * the captured frames structurally until `Error.prototype.stack` is read, and every frame holds a\n * strong reference to that frame's receiver — so retaining an unformatted `StackTrace` retains the\n * `this` of each function that was on the stack at capture time. Records that outlive their capture\n * site (diagnostics, registries, caches) must therefore store the formatted string rather than the\n * `StackTrace` itself. Keeping one in a never-pruned module-level container leaked an entire ECHO\n * client graph per query on Cloudflare Workers, where nothing ever reads the diagnostics (DX-1140).\n */\nexport class StackTrace {\n private _error: Error | undefined;\n private _frames: string[] | undefined;\n\n // NOTE: Captured in the constructor body, not a field initializer — an initializer adds its own\n // frame, which would shift the `skipFrames` offsets every caller passes.\n constructor() {\n this._error = new Error();\n }\n\n /**\n * Formats on first use, then releases the captured frames — and with them the capture site.\n *\n * The `Error` is dropped before formatting, not after: releasing the capture site is the whole\n * point, so it must not be contingent on `stack` being present or `split` succeeding.\n */\n private _format(): string[] {\n if (!this._frames) {\n const error = this._error;\n this._error = undefined;\n this._frames = error?.stack?.split('\\n') ?? [];\n }\n return this._frames;\n }\n\n /**\n * Get stack formatted as string.\n * @param skipFrames Number of frames to skip. By default, the first frame would be the invocation of the StackTrace constructor.\n * @returns\n */\n getStack(skipFrames = 0): string {\n return this.getStackArray(skipFrames).join('\\n');\n }\n\n getStackArray(skipFrames = 0): string[] {\n return this._format().slice(skipFrames + 2);\n }\n}\n","//\n// Copyright 2020 DXOS.org\n//\n\nexport const truncate = (str = '', length = 8, pad: boolean | string = false) => {\n if (str.length >= length - 1) {\n return str.substring(0, length - 1) + '…';\n } else {\n return pad ? str.padEnd(length, typeof pad === 'boolean' ? ' ' : pad[0]) : str;\n }\n};\n\nexport const truncateKey = (key: any, length = 8) => {\n const str = String(key);\n if (str.length <= length) {\n return str;\n }\n\n return str.slice(0, length);\n\n // return start\n // ? `${str.slice(0, length)}...`\n // : `${str.substring(0, length / 2)}...${str.substring(str.length - length / 2)}`;\n};\n","//\n// Copyright 2020 DXOS.org\n//\n\n/**\n * Wrapper for async tests.\n * @param {Function} test - Async test\n * @param errType\n * @return {Promise<void>}\n *\n * @deprecated Use vitests `expect(() => ...).toThrowError();` instead.\n */\nexport const expectToThrow = async (test: () => void, errType = Error) => {\n let thrown;\n try {\n await test();\n } catch (err) {\n thrown = err;\n }\n\n if (thrown === undefined || !(thrown instanceof errType)) {\n throw new Error(`Expected function to throw instance of ${errType.prototype.name}`);\n }\n};\n","//\n// Copyright 2020 DXOS.org\n//\n\nimport { StackTrace } from './stack-trace';\n\n/**\n * Prints a warning to console if the action takes longer then specified timeout. No errors are thrown.\n *\n * @param timeout Timeout in milliseconds after which warning is printed.\n * @param context Context description that would be included in the printed message.\n * @param body Action which is timed.\n */\nexport const warnAfterTimeout = async <T>(timeout: number, context: string, body: () => Promise<T>): Promise<T> => {\n const stack = new StackTrace();\n const timeoutId = setTimeout(() => {\n // eslint-disable-next-line no-console\n console.warn(\n `Action \\`${context}\\` is taking more then ${timeout.toLocaleString()}ms to complete. This might be a bug.\\n${stack.getStack()}`,\n );\n }, timeout);\n try {\n return await body();\n } finally {\n clearTimeout(timeoutId);\n }\n};\n\n/**\n * A decorator that prints a warning to console if method execution time exceeds specified timeout.\n *\n * ```typescript\n * class Foo {\n * @timed(5_000)\n * async doStuff() {\n * // long task\n * }\n * }\n * ```\n *\n * This is useful for debugging code that might deadlock.\n *\n * @param timeout Timeout in milliseconds after which the warning is printed.\n */\nexport function timed(timeout: number) {\n return (target: any, propertyName: string, descriptor: TypedPropertyDescriptor<(...args: any) => any>) => {\n const method = descriptor.value!;\n descriptor.value = function (this: any, ...args: any) {\n return warnAfterTimeout(timeout, `${target.constructor.name}.${propertyName}`, () => method.apply(this, args));\n };\n };\n}\n","//\n// Copyright 2020 DXOS.org\n//\n\n/**\n * Throws an error. Can be used in an expression instead of a value\n */\nexport const todo = (message?: string): never => {\n throw new Error(message ?? 'Not implemented.');\n};\n","//\n// Copyright 2023 DXOS.org\n//\n\n/**\n * Lets types provide custom formatters for the Chrome Devtools.\n *\n * https://www.mattzeunert.com/2016/02/19/custom-chrome-devtools-object-formatters.html\n * NOTE: Must be enabled in chrome devtools preferences.\n *\n * @example\n * ```typescript\n * class MyType {\n * get [devtoolsFormatter] (): DevtoolsFormatter {\n * ...\n * }\n * ```\n */\n\nexport const devtoolsFormatter = Symbol.for('devtoolsFormatter');\n\nexport type JsonML = [string, Record<string, any>?, ...(JsonML | string)[]];\n\nexport interface DevtoolsFormatter {\n /**\n * NOTE: Make sure to do an instance check and return null if the object is not of the correct type.\n */\n header: (config?: any) => JsonML | null;\n hasBody?: (config?: any) => boolean;\n body?: (config?: any) => JsonML | null;\n}\n\n/**\n * Types that implement this interface can provide custom formatters for the Chrome Devtools.\n *\n * https://firefox-source-docs.mozilla.org/devtools-user/custom_formatters/index.html\n */\nexport interface CustomDevtoolsFormattable {\n get [devtoolsFormatter](): DevtoolsFormatter;\n}\n\nconst register = () => {\n if (typeof window !== 'undefined') {\n ((window as any).devtoolsFormatters ??= []).push({\n header: (value: any, config: any) => {\n const formatter = value[devtoolsFormatter];\n if (formatter === undefined) {\n return null;\n }\n if (typeof formatter !== 'object' || formatter === null || typeof formatter.header !== 'function') {\n throw new Error(`Invalid devtools formatter for ${value.constructor.name}`);\n }\n\n return formatter.header(config);\n },\n hasBody: (value: any, config: any) => {\n const formatter = value[devtoolsFormatter];\n if (!formatter || !formatter.hasBody) {\n return false;\n }\n\n return formatter.hasBody(config);\n },\n body: (value: any, config: any) => {\n const formatter = value[devtoolsFormatter];\n if (!formatter || !formatter.body) {\n return null;\n }\n\n return formatter.body(config);\n },\n });\n }\n};\n\nregister();\n","//\n// Copyright 2023 DXOS.org\n//\n\nexport const equalsSymbol = Symbol.for('dxos.common.equals');\n\nexport interface Equatable {\n [equalsSymbol]: (other: any) => boolean;\n}\n\n// TODO(dmaretskyi): export to @dxos/traits.\n// TODO(dmaretskyi): Hash trait for maps?\n\nexport const isEquatable = (value: any): value is Equatable => {\n return typeof value === 'object' && value !== null && typeof value[equalsSymbol] === 'function';\n};\n\nexport const isEqual = (value: Equatable, other: any) => {\n return value[equalsSymbol](other);\n};\n\n/**\n * Feed this as a third argument to `_.isEqualWith` to compare objects with `Equatable` interface.\n */\nexport const loadashEqualityFn = (value: any, other: any): boolean | undefined => {\n if (!isEquatable(value)) {\n return undefined;\n }\n return isEqual(value, other);\n};\n","//\n// Copyright 2024 DXOS.org\n//\n\n/**\n * Allows to register a module to be used later during debugging.\n *\n * ```ts\n * import * as keys from '@dxos/keys';\n * exposeModule('@dxos/keys', keys);\n *\n * ...\n *\n * const { PublicKey } = importModule('@dxos/keys');\n * ```\n *\n * Overwrites the module if it already exists.\n */\nexport const exposeModule = (name: string, module: any) => {\n EXPOSED_MODULES[name] = module;\n};\n\n/**\n * Imports a previously exposed module by its name.\n * Throws an error if the module is not found.\n *\n * @param {string} name - The name of the module to import.\n * @returns {any} The imported module.\n * @throws {Error} If the module is not exposed.\n */\nexport const importModule = (name: string) => {\n if (EXPOSED_MODULES[name]) {\n return EXPOSED_MODULES[name];\n } else {\n throw new Error(`Module ${name} is not exposed.`);\n }\n};\n\nconst EXPOSED_MODULES: Record<string, any> = {};\n","//\n// Copyright 2024 DXOS.org\n//\n\nimport type { InspectOptionsStylized, inspect as inspectFn } from 'node:util';\n\n/**\n * Using this allows code to be written in a portable fashion, so that the custom inspect function is used in an Node.js environment and ignored in the browser.\n */\nexport const inspectCustom = Symbol.for('nodejs.util.inspect.custom');\n\nexport type CustomInspectFunction<T = any> = (\n this: T,\n depth: number,\n options: InspectOptionsStylized,\n inspect: typeof inspectFn,\n) => any; // TODO: , inspect: inspect\n\nexport interface CustomInspectable {\n [inspectCustom]: CustomInspectFunction;\n}\n"],"mappings":";;;;;;;;;;AAYA,IAAa,aAAgB,UAAgB;;;;;;ACH7C,IAAa,cAAb,MAAyB;CACvB;CAEA,mBAA2B;CAE3B,0BAAgC;EAC9B,IAAI,KAAK,mBAAmB,GAC1B,MAAM,IAAI,MACR,oEAAoE,KAAK,iBAAiB,cAC5F;CAEJ;CA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M;GAG5E,OAAO,UAAU,OAAO,MAAM;EAChC;EACA,UAAU,OAAY,WAAgB;GACpC,MAAM,YAAY,MAAM;GACxB,IAAI,CAAC,aAAa,CAAC,UAAU,SAC3B,OAAO;GAGT,OAAO,UAAU,QAAQ,MAAM;EACjC;EACA,OAAO,OAAY,WAAgB;GACjC,MAAM,YAAY,MAAM;GACxB,IAAI,CAAC,aAAa,CAAC,UAAU,MAC3B,OAAO;GAGT,OAAO,UAAU,KAAK,MAAM;EAC9B;CACF,CAAC;AAEL;AAEA,SAAS;;;ACvET,IAAa,eAAe,OAAO,IAAI,oBAAoB;AAS3D,IAAa,eAAe,UAAmC;CAC7D,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,OAAO,MAAM,kBAAkB;AACvF;AAEA,IAAa,WAAW,OAAkB,UAAe;CACvD,OAAO,MAAM,aAAa,CAAC,KAAK;AAClC;;;;AAKA,IAAa,qBAAqB,OAAY,UAAoC;CAChF,IAAI,CAAC,YAAY,KAAK,GACpB;CAEF,OAAO,QAAQ,OAAO,KAAK;AAC7B;;;;;;;;;;;;;;;;;ACXA,IAAa,gBAAgB,MAAc,WAAgB;CACzD,gBAAgB,QAAQ;AAC1B;;;;;;;;;AAUA,IAAa,gBAAgB,SAAiB;CAC5C,IAAI,gBAAgB,OAClB,OAAO,gBAAgB;MAEvB,MAAM,IAAI,MAAM,UAAU,KAAK,iBAAiB;AAEpD;AAEA,IAAM,kBAAuC,CAAC;;;;;;AC7B9C,IAAa,gBAAgB,OAAO,IAAI,4BAA4B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,UAAU,CAAC;AACzB,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,mBAAmB,CAAC;AAClC,cAAc,QAAQ,CAAC;AACvB,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC"}
|
|
@@ -2,10 +2,26 @@
|
|
|
2
2
|
* Will capture the stack trace at the point where the class is created.
|
|
3
3
|
* Stack traces are formatted lazily only when `getStack` is called.
|
|
4
4
|
* Formatting is significantly more expensive than capture so only call getStack when you need them.
|
|
5
|
+
*
|
|
6
|
+
* IMPORTANT: a trace that has never been formatted keeps its entire capture site reachable. V8 holds
|
|
7
|
+
* the captured frames structurally until `Error.prototype.stack` is read, and every frame holds a
|
|
8
|
+
* strong reference to that frame's receiver — so retaining an unformatted `StackTrace` retains the
|
|
9
|
+
* `this` of each function that was on the stack at capture time. Records that outlive their capture
|
|
10
|
+
* site (diagnostics, registries, caches) must therefore store the formatted string rather than the
|
|
11
|
+
* `StackTrace` itself. Keeping one in a never-pruned module-level container leaked an entire ECHO
|
|
12
|
+
* client graph per query on Cloudflare Workers, where nothing ever reads the diagnostics (DX-1140).
|
|
5
13
|
*/
|
|
6
14
|
export declare class StackTrace {
|
|
7
|
-
private
|
|
15
|
+
private _error;
|
|
16
|
+
private _frames;
|
|
8
17
|
constructor();
|
|
18
|
+
/**
|
|
19
|
+
* Formats on first use, then releases the captured frames — and with them the capture site.
|
|
20
|
+
*
|
|
21
|
+
* The `Error` is dropped before formatting, not after: releasing the capture site is the whole
|
|
22
|
+
* point, so it must not be contingent on `stack` being present or `split` succeeding.
|
|
23
|
+
*/
|
|
24
|
+
private _format;
|
|
9
25
|
/**
|
|
10
26
|
* Get stack formatted as string.
|
|
11
27
|
* @param skipFrames Number of frames to skip. By default, the first frame would be the invocation of the StackTrace constructor.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stack-trace.d.ts","sourceRoot":"","sources":["../../../src/stack-trace.ts"],"names":[],"mappings":"AAIA
|
|
1
|
+
{"version":3,"file":"stack-trace.d.ts","sourceRoot":"","sources":["../../../src/stack-trace.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;GAYG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,OAAO,CAAuB;IAItC,cAEC;IAED;;;;;OAKG;IACH,OAAO,CAAC,OAAO;IASf;;;;OAIG;IACH,QAAQ,CAAC,UAAU,SAAI,GAAG,MAAM,CAE/B;IAED,aAAa,CAAC,UAAU,SAAI,GAAG,MAAM,EAAE,CAEtC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stack-trace.test.d.ts","sourceRoot":"","sources":["../../../src/stack-trace.test.ts"],"names":[],"mappings":""}
|