@evolu/common 8.15.1 → 8.17.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.
Files changed (41) hide show
  1. package/dist/src/Console.d.ts +24 -46
  2. package/dist/src/Console.d.ts.map +1 -1
  3. package/dist/src/Console.js +34 -29
  4. package/dist/src/Crypto.d.ts +21 -3
  5. package/dist/src/Crypto.d.ts.map +1 -1
  6. package/dist/src/Crypto.js +18 -2
  7. package/dist/src/Error.d.ts +10 -6
  8. package/dist/src/Error.d.ts.map +1 -1
  9. package/dist/src/Error.js +52 -20
  10. package/dist/src/Sqlite.d.ts.map +1 -1
  11. package/dist/src/Sqlite.js +16 -12
  12. package/dist/src/Task.d.ts +3 -1
  13. package/dist/src/Task.d.ts.map +1 -1
  14. package/dist/src/Task.js +15 -13
  15. package/dist/src/Worker.d.ts +3 -0
  16. package/dist/src/Worker.d.ts.map +1 -1
  17. package/dist/src/Worker.js +6 -1
  18. package/dist/src/local-first/Db.d.ts.map +1 -1
  19. package/dist/src/local-first/Db.js +7 -7
  20. package/dist/src/local-first/Owner.d.ts +20 -8
  21. package/dist/src/local-first/Owner.d.ts.map +1 -1
  22. package/dist/src/local-first/Owner.js +23 -10
  23. package/dist/src/local-first/Schema.d.ts +1 -1
  24. package/dist/src/local-first/Shared.d.ts +55 -39
  25. package/dist/src/local-first/Shared.d.ts.map +1 -1
  26. package/dist/src/local-first/Shared.js +264 -318
  27. package/package.json +1 -1
  28. package/src/Console.test.ts +75 -247
  29. package/src/Console.ts +68 -110
  30. package/src/Crypto.ts +23 -3
  31. package/src/Error.test.ts +85 -0
  32. package/src/Error.ts +48 -22
  33. package/src/Sqlite.ts +19 -11
  34. package/src/Task.test.ts +46 -0
  35. package/src/Task.ts +17 -13
  36. package/src/Worker.ts +6 -1
  37. package/src/local-first/Db.ts +12 -8
  38. package/src/local-first/Owner.test.ts +52 -1
  39. package/src/local-first/Owner.ts +26 -7
  40. package/src/local-first/Shared.test.ts +414 -39
  41. package/src/local-first/Shared.ts +386 -438
@@ -43,9 +43,7 @@ import { type Millis, type TimeDep } from "./Time.ts";
43
43
  * createConsole,
44
44
  * createConsoleArrayOutput,
45
45
  * Data,
46
- * type Console,
47
46
  * type ConsoleEntry,
48
- * type ConsoleLevel,
49
47
  * } from "@evolu/common";
50
48
  *
51
49
  * const entries: Array<ConsoleEntry> = [];
@@ -64,16 +62,11 @@ import { type Millis, type TimeDep } from "./Time.ts";
64
62
  * assertType(Data, args);
65
63
  * assertEqual(args, ["Creating instance", { config: { port: 4000 } }]);
66
64
  *
67
- * const setLevelRecursive = (
68
- * console: Console,
69
- * level: ConsoleLevel,
70
- * ): void => {
71
- * console.setLevel(level);
72
- * for (const child of console.children) setLevelRecursive(child, level);
73
- * };
74
- * setLevelRecursive(root, "warn");
75
- * assertEqual(root.getLevel(), "warn");
76
- * assertEqual(relay.getLevel(), "warn");
65
+ * // Children without their own level follow their parent.
66
+ * const db = root.child("db");
67
+ * root.setLevel("warn");
68
+ * assertEqual(db.getLevel(), "warn");
69
+ * assertEqual(relay.getLevel(), "silent");
77
70
  * ```
78
71
  *
79
72
  * Console intentionally does not use {@link Task}. Logging must be as fast as
@@ -86,15 +79,12 @@ import { type Millis, type TimeDep } from "./Time.ts";
86
79
  * @see {@link createConsole}
87
80
  */
88
81
  export interface Console {
89
- /** Name of this console. Empty for root. */
90
- readonly name: string;
91
- /** Child consoles created via {@link Console.child}. */
92
- readonly children: ReadonlySet<Console>;
93
82
  /**
94
83
  * Returns the effective log level.
95
84
  *
96
85
  * If this console has its own level set via {@link Console.setLevel}, returns
97
- * that. Otherwise returns the inherited level from creation time.
86
+ * that. Otherwise returns its parent's current level, or
87
+ * {@link ConsoleConfig.level} for a root console.
98
88
  */
99
89
  readonly getLevel: () => ConsoleLevel;
100
90
  /**
@@ -109,11 +99,11 @@ export interface Console {
109
99
  /**
110
100
  * Creates a child console with the given name added to the path.
111
101
  *
112
- * Child inherits the parent's configured level (not any runtime override).
113
- * Use {@link Console.children} to access all children for batch operations.
102
+ * A child without its own level follows its parent's level, including later
103
+ * changes.
114
104
  */
115
105
  readonly child: (name: string) => Console;
116
- /** Outputs a stack trace. */
106
+ /** Most detailed execution flow, such as every SQL query. */
117
107
  readonly trace: (...args: ReadonlyArray<unknown>) => void;
118
108
  /** Development diagnostics. */
119
109
  readonly debug: (...args: ReadonlyArray<unknown>) => void;
@@ -125,24 +115,10 @@ export interface Console {
125
115
  readonly warn: (...args: ReadonlyArray<unknown>) => void;
126
116
  /** Failures requiring immediate attention. */
127
117
  readonly error: (...args: ReadonlyArray<unknown>) => void;
128
- /** Displays an object with expandable properties. Level: debug. */
129
- readonly dir: (item: unknown) => void;
130
- /** Displays tabular data. Level: debug. */
131
- readonly table: (data: unknown) => void;
132
- /** Starts a timer with the given label. Level: debug. */
133
- readonly time: (label: string) => void;
134
- /** Logs elapsed time for a timer. Level: debug. */
135
- readonly timeLog: (label: string, ...args: ReadonlyArray<unknown>) => void;
136
- /** Ends a timer and logs elapsed time. Level: debug. */
137
- readonly timeEnd: (label: string) => void;
138
- /** Increments and logs a counter. Level: debug. */
139
- readonly count: (label?: string) => void;
140
- /** Resets a counter. Level: debug. */
141
- readonly countReset: (label?: string) => void;
142
118
  /**
143
- * Writes a pre-built {@link ConsoleEntry} directly to the output, bypassing
144
- * level filtering. Used to replay entries from another context (e.g., a
145
- * SharedWorker) where filtering was already applied.
119
+ * Writes a pre-built {@link ConsoleEntry} to the output if this console's
120
+ * level allows its method. Used to replay entries from another context, such
121
+ * as a worker, that filtered them by its own level.
146
122
  */
147
123
  readonly write: (entry: ConsoleEntry) => void;
148
124
  }
@@ -160,8 +136,8 @@ export interface ConsoleDep {
160
136
  * Setting a level enables all logs at that level and above (ordered by
161
137
  * severity):
162
138
  *
163
- * - `"trace"` — Stack traces and detailed execution flow
164
- * - `"debug"` — Development diagnostics, timers, counters
139
+ * - `"trace"` — Most detailed execution flow, such as every SQL query
140
+ * - `"debug"` — Development diagnostics
165
141
  * - `"log"` — General-purpose messages
166
142
  * - `"info"` — Operational milestones (startup, shutdown)
167
143
  * - `"warn"` — Recoverable issues that may need attention
@@ -195,7 +171,7 @@ export interface ConsoleEntry {
195
171
  *
196
172
  * @group Core
197
173
  */
198
- export type ConsoleMethod = "trace" | "debug" | "log" | "info" | "warn" | "error" | "dir" | "table" | "time" | "timeLog" | "timeEnd" | "count" | "countReset";
174
+ export type ConsoleMethod = "trace" | "debug" | "log" | "info" | "warn" | "error";
199
175
  /**
200
176
  * Output destination for {@link Console}.
201
177
  *
@@ -225,8 +201,6 @@ export type ConsoleFormatter = (entry: ConsoleEntry) => ReadonlyArray<unknown>;
225
201
  * @group Core
226
202
  */
227
203
  export interface ConsoleConfig {
228
- /** Name of this console. Defaults to empty string. */
229
- readonly name?: string;
230
204
  /** Initial log level. Defaults to `"log"`. */
231
205
  readonly level?: ConsoleLevel;
232
206
  /**
@@ -261,7 +235,8 @@ export interface ConsoleFormatterConfig {
261
235
  */
262
236
  readonly timestampFormat?: ConsoleEntryTimestampFormat;
263
237
  /**
264
- * Start time for relative timestamps. Defaults to first entry timestamp.
238
+ * Start time for relative timestamps. Defaults to the time the first entry is
239
+ * formatted.
265
240
  *
266
241
  * Pass a {@link Millis} value to use a custom start time, useful when multiple
267
242
  * consoles should share the same relative timeline.
@@ -349,7 +324,7 @@ export interface TestConsoleDep {
349
324
  *
350
325
  * @group Core
351
326
  */
352
- export declare const createConsole: ({ name, level, output, path, formatter, }?: ConsoleConfig) => Console;
327
+ export declare const createConsole: ({ level, output, path, formatter, }?: ConsoleConfig) => Console;
353
328
  /**
354
329
  * Creates a {@link ConsoleOutput} that writes to `globalThis.console`.
355
330
  *
@@ -357,6 +332,9 @@ export declare const createConsole: ({ name, level, output, path, formatter, }?:
357
332
  * Use {@link createConsoleFormatter} with {@link ConsoleConfig.formatter} for
358
333
  * timestamps and path prefixes.
359
334
  *
335
+ * Trace entries are written with native `console.debug`, because native
336
+ * `console.trace` prints a stack trace with every call.
337
+ *
360
338
  * ### Example
361
339
  *
362
340
  * ```ts
@@ -503,8 +481,8 @@ export declare const createMultiOutput: (outputs: ReadonlyArray<ConsoleOutput>)
503
481
  /**
504
482
  * Creates a {@link TestConsole} that captures all output for testing.
505
483
  *
506
- * Unlike {@link createConsole}, this doesn't require dependencies and captures
507
- * entries in memory.
484
+ * Captures entries in memory and defaults to the `"trace"` level, so tests see
485
+ * every entry.
508
486
  *
509
487
  * ### Example
510
488
  *
@@ -1 +1 @@
1
- {"version":3,"file":"Console.d.ts","sourceRoot":"","sources":["../../src/Console.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD,OAAO,EAIL,KAAK,MAAM,EACX,KAAK,OAAO,EACb,MAAM,WAAW,CAAC;AAEnB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+EG;AACH,MAAM,WAAW,OAAO;IACtB,4CAA4C;IAC5C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,wDAAwD;IACxD,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IAExC;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,YAAY,CAAC;IAEtC;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,KAAK,IAAI,CAAC;IAExD,0EAA0E;IAC1E,QAAQ,CAAC,WAAW,EAAE,MAAM,OAAO,CAAC;IAEpC;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;IAE1C,6BAA6B;IAC7B,QAAQ,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC;IAE1D,+BAA+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CAAC;CACtB,KAAQ,WAkBR,CAAC"}
@@ -3,7 +3,6 @@
3
3
  *
4
4
  * @module
5
5
  */
6
- import { objectFrom } from "./Object.js";
7
6
  import { createStore } from "./Store.js";
8
7
  import { createTime, formatMillisAsClockTime, formatMillisAsDuration, } from "./Time.js";
9
8
  const levelOrder = {
@@ -20,39 +19,41 @@ const levelOrder = {
20
19
  *
21
20
  * @group Core
22
21
  */
23
- export const createConsole = ({ name = "", level = "log", output = createNativeConsoleOutput(), path = [], formatter, } = {}) => {
24
- const childrenSet = new Set();
22
+ export const createConsole = ({ level = "log", output = createNativeConsoleOutput(), path = [], formatter, } = {}) => createConsoleWithInheritedLevel({
23
+ getInheritedLevel: () => level,
24
+ output,
25
+ path,
26
+ formatter,
27
+ });
28
+ const createConsoleWithInheritedLevel = ({ getInheritedLevel, output, path, formatter, }) => {
25
29
  let ownLevel = null;
26
- const getLevel = () => ownLevel ?? level;
27
- const createMethod = (method, methodLevel, formatter) => (...args) => {
28
- if (levelOrder[methodLevel] >= levelOrder[getLevel()])
30
+ const getLevel = () => ownLevel ?? getInheritedLevel();
31
+ const isEnabled = (method) => levelOrder[method] >= levelOrder[getLevel()];
32
+ const createMethod = (method) => (...args) => {
33
+ if (isEnabled(method))
29
34
  output.write({ method, path, args }, formatter);
30
35
  };
31
- const levelMethod = (method) => createMethod(method, method, formatter);
32
- const debugMethod = (method) => createMethod(method, "debug");
33
36
  return {
34
- name,
35
- children: childrenSet,
36
37
  getLevel,
37
38
  setLevel: (level) => {
38
39
  ownLevel = level;
39
40
  },
40
41
  hasOwnLevel: () => ownLevel !== null,
41
- child: (name) => {
42
- const childConsole = createConsole({
43
- name,
44
- level,
45
- output,
46
- path: [...path, name],
47
- ...(formatter && { formatter }),
48
- });
49
- childrenSet.add(childConsole);
50
- return childConsole;
51
- },
52
- ...objectFrom(["trace", "debug", "log", "info", "warn", "error"], levelMethod),
53
- ...objectFrom(["dir", "table", "time", "timeLog", "timeEnd", "count", "countReset"], debugMethod),
42
+ child: (name) => createConsoleWithInheritedLevel({
43
+ getInheritedLevel: getLevel,
44
+ output,
45
+ path: [...path, name],
46
+ formatter,
47
+ }),
48
+ trace: createMethod("trace"),
49
+ debug: createMethod("debug"),
50
+ log: createMethod("log"),
51
+ info: createMethod("info"),
52
+ warn: createMethod("warn"),
53
+ error: createMethod("error"),
54
54
  write: (entry) => {
55
- output.write(entry, formatter);
55
+ if (isEnabled(entry.method))
56
+ output.write(entry, formatter);
56
57
  },
57
58
  };
58
59
  };
@@ -63,6 +64,9 @@ export const createConsole = ({ name = "", level = "log", output = createNativeC
63
64
  * Use {@link createConsoleFormatter} with {@link ConsoleConfig.formatter} for
64
65
  * timestamps and path prefixes.
65
66
  *
67
+ * Trace entries are written with native `console.debug`, because native
68
+ * `console.trace` prints a stack trace with every call.
69
+ *
66
70
  * ### Example
67
71
  *
68
72
  * ```ts
@@ -83,8 +87,7 @@ export const createNativeConsoleOutput = () => ({
83
87
  write: (entry, formatter) => {
84
88
  const args = formatter ? formatter(entry) : entry.args;
85
89
  // oxlint-disable-next-line evolu/no-unnecessary-global-this -- Write to the global object console even if a realm lexical binding shadows it.
86
- const nativeConsole = globalThis.console;
87
- nativeConsole[entry.method](...args);
90
+ globalThis.console[entry.method === "trace" ? "debug" : entry.method](...args);
88
91
  },
89
92
  });
90
93
  /**
@@ -150,7 +153,9 @@ export const createConsoleFormatter = ({ time = createTime() } = {}) => (config
150
153
  timestamp = "";
151
154
  break;
152
155
  case "relative":
153
- timestamp = `+${formatMillisAsDuration((now - startTime))}`;
156
+ // A clock set back, or a startTime ahead of now, must not print a
157
+ // negative duration.
158
+ timestamp = `+${formatMillisAsDuration(Math.max(0, now - startTime))}`;
154
159
  break;
155
160
  case "absolute":
156
161
  timestamp = formatMillisAsClockTime(now);
@@ -256,8 +261,8 @@ export const createMultiOutput = (outputs) => ({
256
261
  /**
257
262
  * Creates a {@link TestConsole} that captures all output for testing.
258
263
  *
259
- * Unlike {@link createConsole}, this doesn't require dependencies and captures
260
- * entries in memory.
264
+ * Captures entries in memory and defaults to the `"trace"` level, so tests see
265
+ * every entry.
261
266
  *
262
267
  * ### Example
263
268
  *
@@ -84,6 +84,13 @@ type Entropy = typeof Entropy.Output;
84
84
  */
85
85
  export declare const Entropy16: import("./Type.ts").BrandType<import("./Type.ts").BrandType<import("./Type.ts").Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, import("./Type.ts").ObjectTagError<"Uint8Array">, null, import("./Type.ts").ObjectTagError<"Uint8Array">, never, Uint8Array<ArrayBufferLike>, true>, "Entropy", never>, "Length16", import("./Type.ts").LengthError<16>>;
86
86
  export type Entropy16 = typeof Entropy16.Output;
87
+ /**
88
+ * Cryptographic entropy of exactly 20 bytes.
89
+ *
90
+ * @group Random bytes
91
+ */
92
+ export declare const Entropy20: import("./Type.ts").BrandType<import("./Type.ts").BrandType<import("./Type.ts").Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, import("./Type.ts").ObjectTagError<"Uint8Array">, null, import("./Type.ts").ObjectTagError<"Uint8Array">, never, Uint8Array<ArrayBufferLike>, true>, "Entropy", never>, "Length20", import("./Type.ts").LengthError<20>>;
93
+ export type Entropy20 = typeof Entropy20.Output;
87
94
  /**
88
95
  * Cryptographic entropy of exactly 24 bytes.
89
96
  *
@@ -91,6 +98,13 @@ export type Entropy16 = typeof Entropy16.Output;
91
98
  */
92
99
  export declare const Entropy24: import("./Type.ts").BrandType<import("./Type.ts").BrandType<import("./Type.ts").Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, import("./Type.ts").ObjectTagError<"Uint8Array">, null, import("./Type.ts").ObjectTagError<"Uint8Array">, never, Uint8Array<ArrayBufferLike>, true>, "Entropy", never>, "Length24", import("./Type.ts").LengthError<24>>;
93
100
  export type Entropy24 = typeof Entropy24.Output;
101
+ /**
102
+ * Cryptographic entropy of exactly 28 bytes.
103
+ *
104
+ * @group Random bytes
105
+ */
106
+ export declare const Entropy28: import("./Type.ts").BrandType<import("./Type.ts").BrandType<import("./Type.ts").Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, import("./Type.ts").ObjectTagError<"Uint8Array">, null, import("./Type.ts").ObjectTagError<"Uint8Array">, never, Uint8Array<ArrayBufferLike>, true>, "Entropy", never>, "Length28", import("./Type.ts").LengthError<28>>;
107
+ export type Entropy28 = typeof Entropy28.Output;
94
108
  /**
95
109
  * Cryptographic entropy of exactly 32 bytes.
96
110
  *
@@ -119,13 +133,17 @@ export declare const createRandomBytes: () => RandomBytes;
119
133
  */
120
134
  export declare const testCreateRandomBytes: (deps: RandomLibDep) => RandomBytes;
121
135
  /**
122
- * SLIP21.
136
+ * Derives a 32-byte key from a seed and a path using
137
+ * [SLIP-21](https://github.com/satoshilabs/slips/blob/master/slip-0021.md).
123
138
  *
124
- * https://github.com/satoshilabs/slips/blob/master/slip-0021.md
139
+ * Derived keys are no stronger than the seed. A 16-byte seed gives 128 bits of
140
+ * security, or about 64 against a quantum computer, whatever the output length.
141
+ * Use a 32-byte random seed for keys that must stay safe against a quantum
142
+ * computer.
125
143
  *
126
144
  * @group Key derivation
127
145
  */
128
- export declare const createSlip21: (seed: Entropy16 | Entropy32 | Entropy64, path: ReadonlyArray<string | number>) => Entropy32;
146
+ export declare const createSlip21: (seed: Entropy16 | Entropy20 | Entropy24 | Entropy28 | Entropy32 | Entropy64, path: ReadonlyArray<string | number>) => Entropy32;
129
147
  /**
130
148
  * Derives a single node in the SLIP-21 hierarchical key derivation.
131
149
  *
@@ -1 +1 @@
1
- {"version":3,"file":"Crypto.d.ts","sourceRoot":"","sources":["../../src/Crypto.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAGL,cAAc,EAE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,iCAAkC,SAAQ,KAAK,CAAC,mCAAmC,CAAC;IACnG,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,eAAO,MAAM,4BAA4B,eAC3B,2BAA2B,SAChC,SAAS,iBACD,aAAa,KAC3B,MAAM,CAAC,UAAU,EAAE,iCAAiC,CAOpD,CAAC;AAEJ;;;;;;;;;GASG;AACH,eAAO,MAAM,uBAAuB,WAC1B,cAAc,KACrB,cAOF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,WAAY,cAAc,KAAG,UAI3D,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,KAAK,OAAO,CAAC;AAExE;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC;CAC3C"}
@@ -20,12 +20,24 @@ const Entropy = /*#__PURE__*/ brand("Entropy", Uint8Array);
20
20
  * @group Random bytes
21
21
  */
22
22
  export const Entropy16 = /*#__PURE__*/ length(16)(Entropy);
23
+ /**
24
+ * Cryptographic entropy of exactly 20 bytes.
25
+ *
26
+ * @group Random bytes
27
+ */
28
+ export const Entropy20 = /*#__PURE__*/ length(20)(Entropy);
23
29
  /**
24
30
  * Cryptographic entropy of exactly 24 bytes.
25
31
  *
26
32
  * @group Random bytes
27
33
  */
28
34
  export const Entropy24 = /*#__PURE__*/ length(24)(Entropy);
35
+ /**
36
+ * Cryptographic entropy of exactly 28 bytes.
37
+ *
38
+ * @group Random bytes
39
+ */
40
+ export const Entropy28 = /*#__PURE__*/ length(28)(Entropy);
29
41
  /**
30
42
  * Cryptographic entropy of exactly 32 bytes.
31
43
  *
@@ -56,9 +68,13 @@ export const testCreateRandomBytes = (deps) => ({
56
68
  create: (bytesLength) => globalThis.Uint8Array.from({ length: bytesLength }, () => deps.randomLib.int(0, 255)),
57
69
  });
58
70
  /**
59
- * SLIP21.
71
+ * Derives a 32-byte key from a seed and a path using
72
+ * [SLIP-21](https://github.com/satoshilabs/slips/blob/master/slip-0021.md).
60
73
  *
61
- * https://github.com/satoshilabs/slips/blob/master/slip-0021.md
74
+ * Derived keys are no stronger than the seed. A 16-byte seed gives 128 bits of
75
+ * security, or about 64 against a quantum computer, whatever the output length.
76
+ * Use a 32-byte random seed for keys that must stay safe against a quantum
77
+ * computer.
62
78
  *
63
79
  * @group Key derivation
64
80
  */
@@ -27,12 +27,16 @@ export interface UnknownError extends InferType<typeof UnknownError> {
27
27
  * Creates an {@link UnknownError} from an unknown error.
28
28
  *
29
29
  * An `Error` becomes a plain object of its own properties, such as `message`
30
- * and `stack`. A `cause` that is an `Error` is converted the same way, a
31
- * function is dropped, and any other property is kept as it is. An `Error`'s
32
- * properties are not enumerable, so JSON and comparisons by content miss them,
33
- * and a structured clone creates a new `Error`. Any other value is
34
- * structured-cloned, or described by `String` when it cannot be, or as
35
- * `"[Unserializable Object]"` when even that throws.
30
+ * and `stack`, plus its `name`, `message`, and `stack` when they are inherited,
31
+ * as in a `DOMException`. A property that is an `Error`, such as `cause`, is
32
+ * converted the same way, an array, such as the `errors` of an
33
+ * `AggregateError`, is converted element by element, a function is dropped, and
34
+ * any other property is kept when it can be structured-cloned, or described as
35
+ * a string when it cannot. Reference cycles through errors and arrays stay
36
+ * cycles in the result. An `Error`'s properties are not enumerable, so JSON and
37
+ * comparisons by content miss them, and a structured clone creates a new
38
+ * `Error`. Any other value is structured-cloned, or described by `String` when
39
+ * it cannot be, or as `"[Unserializable Object]"` when even that throws.
36
40
  */
37
41
  export declare const createUnknownError: (error: unknown) => UnknownError;
38
42
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"Error.d.ts","sourceRoot":"","sources":["../../src/Error.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,KAAK,SAAS,EAAS,KAAK,SAAS,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE3E;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,YAAY,EAAE,SAAS,CAClC,cAAc,EACd;IAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,OAAO,CAAA;CAAE,CAGlC,CAAC;AACH,MAAM,WAAW,YAAa,SAAQ,SAAS,CAAC,OAAO,YAAY,CAAC;CAAG;AAEvE;;;;;;;;;;GAUG;AACH,eAAO,MAAM,kBAAkB,UAAW,OAAO,KAAG,YAkDnD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,eAAO,MAAM,aAAa,aAAc,OAAO,KAAG,KAuBjD,CAAC"}
1
+ {"version":3,"file":"Error.d.ts","sourceRoot":"","sources":["../../src/Error.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,KAAK,SAAS,EAAS,KAAK,SAAS,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE3E;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,YAAY,EAAE,SAAS,CAClC,cAAc,EACd;IAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,OAAO,CAAA;CAAE,CAGlC,CAAC;AACH,MAAM,WAAW,YAAa,SAAQ,SAAS,CAAC,OAAO,YAAY,CAAC;CAAG;AAEvE;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,kBAAkB,UAAW,OAAO,KAAG,YAwEnD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,eAAO,MAAM,aAAa,aAAc,OAAO,KAAG,KAuBjD,CAAC"}
package/dist/src/Error.js CHANGED
@@ -27,30 +27,62 @@ export const UnknownError = /*#__PURE__*/ typed("UnknownError", {
27
27
  * Creates an {@link UnknownError} from an unknown error.
28
28
  *
29
29
  * An `Error` becomes a plain object of its own properties, such as `message`
30
- * and `stack`. A `cause` that is an `Error` is converted the same way, a
31
- * function is dropped, and any other property is kept as it is. An `Error`'s
32
- * properties are not enumerable, so JSON and comparisons by content miss them,
33
- * and a structured clone creates a new `Error`. Any other value is
34
- * structured-cloned, or described by `String` when it cannot be, or as
35
- * `"[Unserializable Object]"` when even that throws.
30
+ * and `stack`, plus its `name`, `message`, and `stack` when they are inherited,
31
+ * as in a `DOMException`. A property that is an `Error`, such as `cause`, is
32
+ * converted the same way, an array, such as the `errors` of an
33
+ * `AggregateError`, is converted element by element, a function is dropped, and
34
+ * any other property is kept when it can be structured-cloned, or described as
35
+ * a string when it cannot. Reference cycles through errors and arrays stay
36
+ * cycles in the result. An `Error`'s properties are not enumerable, so JSON and
37
+ * comparisons by content miss them, and a structured clone creates a new
38
+ * `Error`. Any other value is structured-cloned, or described by `String` when
39
+ * it cannot be, or as `"[Unserializable Object]"` when even that throws.
36
40
  */
37
41
  export const createUnknownError = (error) => {
42
+ // An UnknownError is posted between workers, so its values must clone.
43
+ // Each error and array is converted once and registered before its values,
44
+ // so a reference cycle becomes a cycle in the result instead of endless
45
+ // recursion, and structured cloning preserves it.
46
+ const converted = new Map();
47
+ const convertValue = (value) => {
48
+ if (value instanceof Error)
49
+ return convertError(value);
50
+ if (Array.isArray(value)) {
51
+ const known = converted.get(value);
52
+ if (known !== undefined)
53
+ return known;
54
+ const result = [];
55
+ converted.set(value, result);
56
+ for (const element of value)
57
+ result.push(convertValue(element));
58
+ return result;
59
+ }
60
+ try {
61
+ structuredClone(value);
62
+ return value;
63
+ }
64
+ catch {
65
+ return safelyStringifyUnknownValue(value);
66
+ }
67
+ };
38
68
  const convertError = (err) => {
39
- const result = Object.getOwnPropertyNames(err).reduce((acc, key) => {
69
+ const known = converted.get(err);
70
+ if (known !== undefined)
71
+ return known;
72
+ const result = {};
73
+ converted.set(err, result);
74
+ for (const key of Object.getOwnPropertyNames(err)) {
75
+ const value = err[key];
76
+ if (typeof value !== "function")
77
+ result[key] = convertValue(value);
78
+ }
79
+ // A DOMException keeps `name` and `message` on its prototype, and Firefox
80
+ // defines `stack` as a getter on Error.prototype, so getOwnPropertyNames
81
+ // misses them. Explicitly include them.
82
+ for (const key of ["name", "message", "stack"]) {
40
83
  const value = err[key];
41
- if (key === "cause" && value instanceof Error) {
42
- // Recursively process the `cause` property
43
- acc[key] = convertError(value);
44
- }
45
- else if (typeof value !== "function") {
46
- acc[key] = value;
47
- }
48
- return acc;
49
- }, {});
50
- // Firefox defines `stack` as a getter on Error.prototype, not as an own
51
- // property, so getOwnPropertyNames misses it. Explicitly include it.
52
- if (err.stack !== undefined && !("stack" in result)) {
53
- result.stack = err.stack;
84
+ if (value !== undefined && !(key in result))
85
+ result[key] = value;
54
86
  }
55
87
  return result;
56
88
  };
@@ -1 +1 @@
1
- {"version":3,"file":"Sqlite.d.ts","sourceRoot":"","sources":["../../src/Sqlite.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAIlC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,KAAK,IAAI,EAAiB,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AACtE,OAAO,EAEL,KAAK,SAAS,EAEd,KAAK,SAAS,EACd,KAAK,IAAI,EAGT,KAAK,UAAU,EAEf,KAAK,UAAU,EAEf,KAAK,OAAO,EACZ,MAAM,EAEN,KAAK,KAAK,EAGX,MAAM,WAAW,CAAC;AAEnB;;;;;;;;GAQG;AACH,MAAM,WAAW,MAAO,SAAQ,eAAe;IAC7C,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,EAC7C,KAAK,EAAE,WAAW,KACf,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAEzB;;;;;;;;;OASG;IAC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AED;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,SAAU,SAAS,KAAG,cAiBnD,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,aAAa,kHAA4B,CAAC;AACvD,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAC,MAAM,CAAC;AAExD;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,IAAI,CAAC;AAE5B;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,IAAI,CAAC;AAE7B;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,sBAAsB,UAAW,OAAO,KAAG,aACtB,CAAC;AAEnC;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,sBAAsB,UAAW,aAAa,KAAG,OACxC,CAAC"}
@@ -61,6 +61,7 @@ import { disposable } from "./Function.js";
61
61
  import { createMutableRecord, objectToEntries } from "./Object.js";
62
62
  import { ok } from "./Result.js";
63
63
  import { testCreateRun } from "./Task.js";
64
+ import { performanceDurationBetween } from "./Time.js";
64
65
  import { array, FiniteNumber, Null, object, record, set, String, testName, Uint8Array, union, } from "./Type.js";
65
66
  /**
66
67
  * A value that can be stored in {@link Sqlite}.
@@ -130,22 +131,25 @@ export const sqliteQueryStringToSqliteQuery = (query) => {
130
131
  export const createSqlite = (name, options) => async (run) => {
131
132
  const env_1 = { stack: [], error: void 0, hasError: false };
132
133
  try {
133
- const { createSqliteDriver } = run.deps;
134
+ const { createSqliteDriver, time } = run.deps;
134
135
  const console = run.deps.console.child("sql");
135
136
  const disposer = __addDisposableResource(env_1, new AsyncDisposableStack(), true);
136
137
  const driver = disposer.use(await run.ok(createSqliteDriver(name, options)));
137
138
  console.debug("SQLite driver created");
138
139
  return ok(disposable({
139
140
  exec: (query) => {
140
- console.debug({ query });
141
- const label = query.options?.logQueryExecutionTime === true
142
- ? `SqliteQueryExecutionTime ${query.sql}`
141
+ console.trace({ query });
142
+ const start = query.options?.logQueryExecutionTime === true
143
+ ? time.performance.now()
143
144
  : null;
144
- if (label !== null)
145
- console.time(label);
146
145
  const result = driver.exec(query);
147
- if (label !== null)
148
- console.timeEnd(label);
146
+ if (start !== null) {
147
+ const duration = performanceDurationBetween(start, time.performance.now());
148
+ console.log("[logQueryExecutionTime]", {
149
+ query,
150
+ duration: `${duration.toFixed(3)}ms`,
151
+ });
152
+ }
149
153
  if (query.options?.logExplainQueryPlan) {
150
154
  const result = driver.exec({
151
155
  ...query,
@@ -154,13 +158,13 @@ export const createSqlite = (name, options) => async (run) => {
154
158
  console.log("[logExplainQueryPlan]", query);
155
159
  console.log(drawSqliteQueryPlan(result.rows));
156
160
  }
157
- console.debug({ result });
161
+ console.trace({ result });
158
162
  return result;
159
163
  },
160
164
  transaction: ((callback) => {
161
165
  const env_2 = { stack: [], error: void 0, hasError: false };
162
166
  try {
163
- console.debug("begin");
167
+ console.trace("begin");
164
168
  driver.exec(sql `begin;`);
165
169
  // After errors such as SQLITE_FULL or SQLITE_IOERR, SQLite may roll
166
170
  // back the transaction itself, and this rollback then fails with
@@ -174,13 +178,13 @@ export const createSqlite = (name, options) => async (run) => {
174
178
  rollback.defer(() => {
175
179
  if (!shouldRollback)
176
180
  return;
177
- console.debug("rollback");
181
+ console.trace("rollback");
178
182
  driver.exec(sql `rollback;`);
179
183
  });
180
184
  const result = callback();
181
185
  if (result != null && !result.ok)
182
186
  return result;
183
- console.debug("commit");
187
+ console.trace("commit");
184
188
  driver.exec(sql `commit;`);
185
189
  shouldRollback = false;
186
190
  return result;
@@ -1904,9 +1904,11 @@ export type RunDefaultDeps = ConsoleDep & LeakDetectorDep & NativeFetchDep & Ran
1904
1904
  /**
1905
1905
  * Creates {@link RunDefaultDeps}.
1906
1906
  *
1907
+ * The leak detector reports to the provided console, or to a default one.
1908
+ *
1907
1909
  * @group Run
1908
1910
  */
1909
- export declare const createRunDefaultDeps: () => RunDefaultDeps;
1911
+ export declare const createRunDefaultDeps: ({ console, }?: Partial<ConsoleDep>) => RunDefaultDeps;
1910
1912
  /**
1911
1913
  * Factory type for creating root {@link DisposableRun} instances.
1912
1914
  *