@evolu/common 6.0.1-preview.2 → 6.0.1-preview.20

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 (154) hide show
  1. package/dist/src/Assert.d.ts +6 -3
  2. package/dist/src/Assert.d.ts.map +1 -1
  3. package/dist/src/Assert.js +7 -4
  4. package/dist/src/Brand.d.ts +75 -0
  5. package/dist/src/Brand.d.ts.map +1 -0
  6. package/dist/src/Brand.js +1 -0
  7. package/dist/src/Buffer.d.ts +1 -1
  8. package/dist/src/Buffer.d.ts.map +1 -1
  9. package/dist/src/Buffer.js +1 -1
  10. package/dist/src/CallbackRegistry.d.ts +53 -0
  11. package/dist/src/CallbackRegistry.d.ts.map +1 -0
  12. package/dist/src/CallbackRegistry.js +25 -0
  13. package/dist/src/Console.d.ts +31 -6
  14. package/dist/src/Console.d.ts.map +1 -1
  15. package/dist/src/Console.js +72 -9
  16. package/dist/src/Crypto.d.ts +61 -34
  17. package/dist/src/Crypto.d.ts.map +1 -1
  18. package/dist/src/Crypto.js +29 -42
  19. package/dist/src/Evolu/Db.d.ts +137 -66
  20. package/dist/src/Evolu/Db.d.ts.map +1 -1
  21. package/dist/src/Evolu/Db.js +300 -705
  22. package/dist/src/Evolu/Diff.d.ts +3 -3
  23. package/dist/src/Evolu/Diff.d.ts.map +1 -1
  24. package/dist/src/Evolu/Diff.js +7 -5
  25. package/dist/src/Evolu/Evolu.d.ts +200 -115
  26. package/dist/src/Evolu/Evolu.d.ts.map +1 -1
  27. package/dist/src/Evolu/Evolu.js +287 -157
  28. package/dist/src/Evolu/Internal.d.ts +0 -2
  29. package/dist/src/Evolu/Internal.d.ts.map +1 -1
  30. package/dist/src/Evolu/Internal.js +0 -2
  31. package/dist/src/Evolu/LocalAuth.d.ts +144 -0
  32. package/dist/src/Evolu/LocalAuth.d.ts.map +1 -0
  33. package/dist/src/Evolu/LocalAuth.js +171 -0
  34. package/dist/src/Evolu/Owner.d.ts +152 -127
  35. package/dist/src/Evolu/Owner.d.ts.map +1 -1
  36. package/dist/src/Evolu/Owner.js +88 -107
  37. package/dist/src/Evolu/Platform.d.ts +9 -7
  38. package/dist/src/Evolu/Platform.d.ts.map +1 -1
  39. package/dist/src/Evolu/Protocol.d.ts +170 -186
  40. package/dist/src/Evolu/Protocol.d.ts.map +1 -1
  41. package/dist/src/Evolu/Protocol.js +487 -343
  42. package/dist/src/Evolu/Public.d.ts +6 -8
  43. package/dist/src/Evolu/Public.d.ts.map +1 -1
  44. package/dist/src/Evolu/Public.js +2 -3
  45. package/dist/src/Evolu/PublicKysely.js +3 -3
  46. package/dist/src/Evolu/Query.d.ts +2 -1
  47. package/dist/src/Evolu/Query.d.ts.map +1 -1
  48. package/dist/src/Evolu/Relay.d.ts +4 -3
  49. package/dist/src/Evolu/Relay.d.ts.map +1 -1
  50. package/dist/src/Evolu/Relay.js +50 -12
  51. package/dist/src/Evolu/Schema.d.ts +129 -73
  52. package/dist/src/Evolu/Schema.d.ts.map +1 -1
  53. package/dist/src/Evolu/Schema.js +169 -89
  54. package/dist/src/Evolu/Storage.d.ts +159 -14
  55. package/dist/src/Evolu/Storage.d.ts.map +1 -1
  56. package/dist/src/Evolu/Storage.js +42 -32
  57. package/dist/src/Evolu/Sync.d.ts +77 -13
  58. package/dist/src/Evolu/Sync.d.ts.map +1 -1
  59. package/dist/src/Evolu/Sync.js +453 -20
  60. package/dist/src/Evolu/Timestamp.d.ts +35 -27
  61. package/dist/src/Evolu/Timestamp.d.ts.map +1 -1
  62. package/dist/src/Evolu/Timestamp.js +27 -18
  63. package/dist/src/ManyToManyMap.d.ts +74 -10
  64. package/dist/src/ManyToManyMap.d.ts.map +1 -1
  65. package/dist/src/ManyToManyMap.js +41 -6
  66. package/dist/src/Number.d.ts +2 -1
  67. package/dist/src/Number.d.ts.map +1 -1
  68. package/dist/src/Random.d.ts +3 -2
  69. package/dist/src/Random.d.ts.map +1 -1
  70. package/dist/src/RefCountedResourceManager.d.ts +119 -0
  71. package/dist/src/RefCountedResourceManager.d.ts.map +1 -0
  72. package/dist/src/RefCountedResourceManager.js +197 -0
  73. package/dist/src/Result.d.ts +147 -51
  74. package/dist/src/Result.d.ts.map +1 -1
  75. package/dist/src/Result.js +7 -241
  76. package/dist/src/Sqlite.d.ts +21 -4
  77. package/dist/src/Sqlite.d.ts.map +1 -1
  78. package/dist/src/Sqlite.js +50 -8
  79. package/dist/src/Task.d.ts +511 -0
  80. package/dist/src/Task.d.ts.map +1 -0
  81. package/dist/src/Task.js +410 -0
  82. package/dist/src/Time.d.ts +59 -0
  83. package/dist/src/Time.d.ts.map +1 -1
  84. package/dist/src/Time.js +87 -4
  85. package/dist/src/Type.d.ts +462 -327
  86. package/dist/src/Type.d.ts.map +1 -1
  87. package/dist/src/Type.js +490 -436
  88. package/dist/src/Types.d.ts +0 -74
  89. package/dist/src/Types.d.ts.map +1 -1
  90. package/dist/src/WebSocket.d.ts +5 -2
  91. package/dist/src/WebSocket.d.ts.map +1 -1
  92. package/dist/src/WebSocket.js +12 -13
  93. package/dist/src/Worker.d.ts +39 -11
  94. package/dist/src/Worker.d.ts.map +1 -1
  95. package/dist/src/Worker.js +22 -4
  96. package/dist/src/index.d.ts +3 -3
  97. package/dist/src/index.d.ts.map +1 -1
  98. package/dist/src/index.js +3 -3
  99. package/package.json +14 -13
  100. package/src/Assert.ts +8 -7
  101. package/src/Brand.ts +75 -0
  102. package/src/Buffer.ts +1 -1
  103. package/src/CallbackRegistry.ts +84 -0
  104. package/src/Console.ts +91 -11
  105. package/src/Crypto.ts +94 -79
  106. package/src/Evolu/Db.ts +505 -1027
  107. package/src/Evolu/Diff.ts +7 -5
  108. package/src/Evolu/Evolu.ts +682 -329
  109. package/src/Evolu/Internal.ts +0 -2
  110. package/src/Evolu/LocalAuth.ts +422 -0
  111. package/src/Evolu/Owner.ts +221 -235
  112. package/src/Evolu/Platform.ts +9 -9
  113. package/src/Evolu/Protocol.ts +681 -614
  114. package/src/Evolu/Public.ts +7 -14
  115. package/src/Evolu/PublicKysely.ts +3 -3
  116. package/src/Evolu/Query.ts +2 -1
  117. package/src/Evolu/Relay.ts +62 -16
  118. package/src/Evolu/Schema.ts +391 -191
  119. package/src/Evolu/Storage.ts +275 -55
  120. package/src/Evolu/Sync.ts +758 -37
  121. package/src/Evolu/Timestamp.ts +38 -35
  122. package/src/ManyToManyMap.ts +127 -24
  123. package/src/Number.ts +2 -6
  124. package/src/Random.ts +3 -2
  125. package/src/RefCountedResourceManager.ts +368 -0
  126. package/src/Result.ts +152 -53
  127. package/src/Sqlite.ts +59 -23
  128. package/src/Task.ts +779 -0
  129. package/src/Time.ts +168 -4
  130. package/src/Type.ts +696 -660
  131. package/src/Types.ts +0 -76
  132. package/src/WebSocket.ts +23 -17
  133. package/src/Worker.ts +72 -23
  134. package/src/index.ts +3 -3
  135. package/dist/src/Callbacks.d.ts +0 -20
  136. package/dist/src/Callbacks.d.ts.map +0 -1
  137. package/dist/src/Callbacks.js +0 -18
  138. package/dist/src/Evolu/Config.d.ts +0 -69
  139. package/dist/src/Evolu/Config.d.ts.map +0 -1
  140. package/dist/src/Evolu/Config.js +0 -9
  141. package/dist/src/Evolu/Kysely.d.ts +0 -6
  142. package/dist/src/Evolu/Kysely.d.ts.map +0 -1
  143. package/dist/src/Evolu/Kysely.js +0 -21
  144. package/dist/src/NanoId.d.ts +0 -27
  145. package/dist/src/NanoId.d.ts.map +0 -1
  146. package/dist/src/NanoId.js +0 -6
  147. package/dist/src/Promise.d.ts +0 -180
  148. package/dist/src/Promise.d.ts.map +0 -1
  149. package/dist/src/Promise.js +0 -176
  150. package/src/Callbacks.ts +0 -43
  151. package/src/Evolu/Config.ts +0 -83
  152. package/src/Evolu/Kysely.ts +0 -38
  153. package/src/NanoId.ts +0 -39
  154. package/src/Promise.ts +0 -295
@@ -16,9 +16,12 @@
16
16
  * assert(true, "true is not true"); // no-op
17
17
  * assert(false, "true is not true"); // throws Error
18
18
  *
19
- * const size = fooSize - buffer.getLength();
20
- * // Ensure required type
21
- * assert(PositiveInt.is(size), "size is not positive int");
19
+ * const length = buffer.getLength();
20
+ * // We know length is logically non-negative, but TypeScript doesn't
21
+ * assert(
22
+ * NonNegativeInt.is(length),
23
+ * "buffer length should be non-negative",
24
+ * );
22
25
  * ```
23
26
  */
24
27
  export declare const assert: (condition: unknown, message: string) => asserts condition;
@@ -1 +1 @@
1
- {"version":3,"file":"Assert.d.ts","sourceRoot":"","sources":["../../src/Assert.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,MAAM,EAAE,CACnB,SAAS,EAAE,OAAO,EAClB,OAAO,EAAE,MAAM,KACZ,OAAO,CAAC,SAIZ,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,mBAAmB,EAAE,CAAC,CAAC,EAClC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,EACb,OAAO,CAAC,EAAE,MAAM,KACb,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAKlC,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,2BAA2B,EAAE,CAAC,CAAC,EAC1C,GAAG,EAAE,aAAa,CAAC,CAAC,CAAC,EACrB,OAAO,CAAC,EAAE,MAAM,KACb,OAAO,CAAC,GAAG,IAAI,SAAS,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAK3C,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,CAO3E"}
1
+ {"version":3,"file":"Assert.d.ts","sourceRoot":"","sources":["../../src/Assert.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,MAAM,EAAE,CACnB,SAAS,EAAE,OAAO,EAClB,OAAO,EAAE,MAAM,KACZ,OAAO,CAAC,SAIZ,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,mBAAmB,EAAE,CAAC,CAAC,EAClC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,EACb,OAAO,CAAC,EAAE,MAAM,KACb,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAKlC,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,2BAA2B,EAAE,CAAC,CAAC,EAC1C,GAAG,EAAE,aAAa,CAAC,CAAC,CAAC,EACrB,OAAO,CAAC,EAAE,MAAM,KACb,OAAO,CAAC,GAAG,IAAI,SAAS,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAK3C,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,CAK3E"}
@@ -16,9 +16,12 @@
16
16
  * assert(true, "true is not true"); // no-op
17
17
  * assert(false, "true is not true"); // throws Error
18
18
  *
19
- * const size = fooSize - buffer.getLength();
20
- * // Ensure required type
21
- * assert(PositiveInt.is(size), "size is not positive int");
19
+ * const length = buffer.getLength();
20
+ * // We know length is logically non-negative, but TypeScript doesn't
21
+ * assert(
22
+ * NonNegativeInt.is(length),
23
+ * "buffer length should be non-negative",
24
+ * );
22
25
  * ```
23
26
  */
24
27
  export const assert = (condition, message) => {
@@ -73,5 +76,5 @@ export const assertNonEmptyReadonlyArray = (arr, message = "Expected a non-empty
73
76
  * ```
74
77
  */
75
78
  export function assertNoErrorInCatch(context, error) {
76
- throw Object.assign(new Error(`Error in ${context}: an unexpected error reached a catch block and requires a fix`), { cause: error });
79
+ throw new Error(`Error in ${context}: an unexpected error reached a catch block and requires a fix`, { cause: error });
77
80
  }
@@ -0,0 +1,75 @@
1
+ /**
2
+ * A utility interface for creating branded types.
3
+ *
4
+ * Branded types enhance type safety by differentiating otherwise identical base
5
+ * types, such as `number` or `string`, to enforce stricter type checks.
6
+ *
7
+ * Supports multiple brands, allowing types to act like flags.
8
+ *
9
+ * ### Example 1: Single Brand
10
+ *
11
+ * ```ts
12
+ * // A branded type definition
13
+ * type UserId = number & Brand<"UserId">;
14
+ *
15
+ * // A function that creates `UserId` values.
16
+ * // Casting with `as UserId` is unsafe, so `createUserId` must be unit-tested.
17
+ * const createUserId = (): UserId => {
18
+ * return 123 as UserId; // Unsafe casting
19
+ * };
20
+ *
21
+ * const userId = createUserId();
22
+ *
23
+ * // A function that accepts only `UserId`.
24
+ * const getUser = (id: UserId) => {
25
+ * // Implementation
26
+ * };
27
+ *
28
+ * getUser(userId); // ✅ Valid
29
+ * getUser(123); // ❌ TypeScript error
30
+ * getUser("123"); // ❌ TypeScript error
31
+ * ```
32
+ *
33
+ * ### Example 2: Multiple Brands
34
+ *
35
+ * ```ts
36
+ * // Define branded types
37
+ * type Min1 = string & Brand<"Min1">;
38
+ * type Max100 = string & Brand<"Max100">;
39
+ * type Min1Max100 = string & Brand<"Min1" | "Max100">;
40
+ *
41
+ * // Functions requiring specific brands
42
+ * const requiresMin1 = (value: Min1): void => {};
43
+ * const requiresMax100 = (value: Max100): void => {};
44
+ *
45
+ * // Values with single brands
46
+ * const min1Value: Min1 = "hello" as Min1;
47
+ * const max100Value: Max100 = "world" as Max100;
48
+ *
49
+ * // Value with multiple brands
50
+ * const min1Max100Value: Min1Max100 = "typescript" as Min1Max100;
51
+ *
52
+ * // Valid cases
53
+ * requiresMin1(min1Value); // ✅ Valid
54
+ * requiresMax100(max100Value); // ✅ Valid
55
+ * requiresMin1(min1Max100Value); // ✅ Valid: Min1Max100 satisfies Min1
56
+ * requiresMax100(min1Max100Value); // ✅ Valid: Min1Max100 satisfies Max100
57
+ * ```
58
+ */
59
+ export interface Brand<B extends string> {
60
+ readonly [__brand]: Readonly<Record<B, true>>;
61
+ }
62
+ declare const __brand: unique symbol;
63
+ /**
64
+ * Determines whether a type `T` is a branded type.
65
+ *
66
+ * Works with any base type intersected with a `Brand`.
67
+ *
68
+ * ### Examples
69
+ *
70
+ * - `IsBranded<string>` -> false
71
+ * - `IsBranded<string & Brand<"X">>` -> true
72
+ */
73
+ export type IsBranded<T> = T extends Brand<string> ? true : false;
74
+ export {};
75
+ //# sourceMappingURL=Brand.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Brand.d.ts","sourceRoot":"","sources":["../../src/Brand.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AACH,MAAM,WAAW,KAAK,CAAC,CAAC,SAAS,MAAM;IACrC,QAAQ,CAAC,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;CAC/C;AAED,OAAO,CAAC,MAAM,OAAO,EAAE,OAAO,MAAM,CAAC;AAErC;;;;;;;;;GASG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,SAAS,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,5 @@
1
1
  import { NonNegativeInt } from "./Type.js";
2
- export { bytesToHex, bytesToUtf8, concatBytes, hexToBytes, utf8ToBytes, } from "@noble/ciphers/utils";
2
+ export { bytesToHex, bytesToUtf8, concatBytes, hexToBytes, utf8ToBytes, } from "@noble/ciphers/utils.js";
3
3
  /**
4
4
  * Custom error for {@link Buffer}-related failures like premature end of data.
5
5
  * Provides better stack traces for debugging binary protocol issues.
@@ -1 +1 @@
1
- {"version":3,"file":"Buffer.d.ts","sourceRoot":"","sources":["../../src/Buffer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EACL,UAAU,EACV,WAAW,EACX,WAAW,EACX,UAAU,EACV,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AElC,gEAAgE;IAChE,SAAS,EAAE,MAAM,cAAc,CAAC;IAEhC;;;OAGG;IACH,MAAM,EAAE,CAAC,GAAG,EAAE,UAAU,GAAG,SAAS,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;IAEtD;;;OAGG;IACH,KAAK,EAAE,MAAM,cAAc,CAAC;IAE5B;;;OAGG;IACH,MAAM,EAAE,CAAC,CAAC,EAAE,cAAc,KAAK,UAAU,CAAC;IAE1C;;;OAGG;IACH,QAAQ,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,IAAI,CAAC;IAE3C;;;;;;OAMG;IACH,KAAK,EAAE,MAAM,IAAI,CAAC;IAElB;;;;OAIG;IACH,MAAM,EAAE,MAAM,UAAU,CAAC;CAC1B;AAED,eAAO,MAAM,YAAY,GACvB,YAAY,UAAU,GAAG,SAAS,CAAC,MAAM,CAAC,KACzC,MA4DF,CAAC"}
@@ -1,4 +1,4 @@
1
- export { bytesToHex, bytesToUtf8, concatBytes, hexToBytes, utf8ToBytes, } from "@noble/ciphers/utils";
1
+ export { bytesToHex, bytesToUtf8, concatBytes, hexToBytes, utf8ToBytes, } from "@noble/ciphers/utils.js";
2
2
  /**
3
3
  * Custom error for {@link Buffer}-related failures like premature end of data.
4
4
  * Provides better stack traces for debugging binary protocol issues.
@@ -0,0 +1,53 @@
1
+ import { Brand } from "./Brand.js";
2
+ import { RandomBytesDep } from "./Crypto.js";
3
+ import { Id } from "./Type.js";
4
+ /**
5
+ * A registry for one-time callback functions.
6
+ *
7
+ * Stores callbacks with unique IDs and executes them once with an optional
8
+ * argument. Executed callbacks are automatically removed from the registry.
9
+ *
10
+ * This is useful for correlating asynchronous operations across boundaries
11
+ * where callback functions cannot be passed directly (e.g., web workers).
12
+ *
13
+ * The `execute` method intentionally does not use try-catch or {@link Result}
14
+ * because it's the callback's responsibility to handle its own errors. The
15
+ * registry is just a correlation mechanism and should not interfere with error
16
+ * handling or debugging by masking the original error location.
17
+ *
18
+ * ### Example
19
+ *
20
+ * ```ts
21
+ * // No-argument callbacks
22
+ * const registry = createCallbackRegistry(deps);
23
+ * const id = registry.register(() => console.log("called"));
24
+ * registry.execute(id);
25
+ *
26
+ * // With argument callbacks
27
+ * const stringRegistry = createCallbackRegistry<string>(deps);
28
+ * const id = stringRegistry.register((value) => {
29
+ * console.log(value);
30
+ * });
31
+ * stringRegistry.execute(id, "hello");
32
+ *
33
+ * // Promise.withResolvers pattern
34
+ * const promiseRegistry = createCallbackRegistry<string>(deps);
35
+ * const { promise, resolve } = Promise.withResolvers<string>();
36
+ * const id = promiseRegistry.register(resolve);
37
+ * promiseRegistry.execute(id, "resolved value");
38
+ * await promise; // "resolved value"
39
+ * ```
40
+ *
41
+ * @template T - The type of argument passed to callbacks (defaults to undefined
42
+ * for no-argument callbacks)
43
+ */
44
+ export interface CallbackRegistry<T = undefined> {
45
+ /** Registers a callback function and returns a unique ID. */
46
+ readonly register: (callback: (arg: T) => void) => CallbackId;
47
+ /** Executes and removes a callback associated with the given ID. */
48
+ readonly execute: T extends undefined ? (id: CallbackId) => undefined : (id: CallbackId, arg: T) => undefined;
49
+ }
50
+ export type CallbackId = Id & Brand<"Callback">;
51
+ /** Creates a new {@link CallbackRegistry} for one-time callback functions. */
52
+ export declare const createCallbackRegistry: <T = undefined>(deps: RandomBytesDep) => CallbackRegistry<T>;
53
+ //# sourceMappingURL=CallbackRegistry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CallbackRegistry.d.ts","sourceRoot":"","sources":["../../src/CallbackRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,EAAY,EAAE,EAAE,MAAM,WAAW,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC,GAAG,SAAS;IAC7C,6DAA6D;IAC7D,QAAQ,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,IAAI,KAAK,UAAU,CAAC;IAE9D,oEAAoE;IACpE,QAAQ,CAAC,OAAO,EAAE,CAAC,SAAS,SAAS,GACjC,CAAC,EAAE,EAAE,UAAU,KAAK,SAAS,GAC7B,CAAC,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,KAAK,SAAS,CAAC;CAC3C;AAED,MAAM,MAAM,UAAU,GAAG,EAAE,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC;AAEhD,8EAA8E;AAC9E,eAAO,MAAM,sBAAsB,GAAI,CAAC,GAAG,SAAS,EAClD,MAAM,cAAc,KACnB,gBAAgB,CAAC,CAAC,CAuBpB,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { createId } from "./Type.js";
2
+ /** Creates a new {@link CallbackRegistry} for one-time callback functions. */
3
+ export const createCallbackRegistry = (deps) => {
4
+ const callbackMap = new Map();
5
+ return {
6
+ register: (callback) => {
7
+ const id = createId(deps);
8
+ callbackMap.set(id, callback);
9
+ return id;
10
+ },
11
+ execute: (id, ...args) => {
12
+ const callback = callbackMap.get(id);
13
+ if (callback) {
14
+ callbackMap.delete(id);
15
+ if (args.length === 0) {
16
+ // Called without argument (undefined case)
17
+ callback();
18
+ }
19
+ else {
20
+ callback(args[0]);
21
+ }
22
+ }
23
+ },
24
+ };
25
+ };
@@ -13,14 +13,28 @@
13
13
  * ### Example
14
14
  *
15
15
  * ```ts
16
- * deps.console.log("[db]", "send data message", protocolMessage);
16
+ * deps.console.log("[evolu]", "createEvoluInstance", { name });
17
17
  * ```
18
18
  *
19
19
  * **Tip**: In browser dev tools, you can filter logs by tag (e.g., `[db]`) to
20
- * quickly find relevant messages.
20
+ * quickly find relevant messages. In Node.js, use `grep` to filter output:
21
21
  *
22
- * **Warning**: If you encounter platform-specific issues or missing methods,
23
- * please contribute a PR with details about the environment and behavior.
22
+ * ```bash
23
+ * node app.js | grep "\[relay\]" # Show only relay logs
24
+ * node app.js | grep -E "\[db\]|\[sql\]" # Show db and sql logs
25
+ * node app.js | grep -v "\[debug\]" # Hide debug logs
26
+ * ```
27
+ *
28
+ * Or add to package.json scripts:
29
+ *
30
+ * ```json
31
+ * {
32
+ * "scripts": {
33
+ * "dev:relay": "node app.js | grep \"\\[relay\\]\"",
34
+ * "dev:db": "node app.js | grep -E \"\\[db\\]|\\[sql\\]\""
35
+ * }
36
+ * }
37
+ * ```
24
38
  *
25
39
  * @module
26
40
  */
@@ -43,6 +57,8 @@ export interface Console {
43
57
  debug: (...args: Array<any>) => void;
44
58
  /** Starts a timer with an optional label */
45
59
  time: (label?: string) => void;
60
+ /** Logs the elapsed time for a timer without ending it */
61
+ timeLog: (label?: string, ...data: Array<any>) => void;
46
62
  /** Ends a timer and logs the elapsed time */
47
63
  timeEnd: (label?: string) => void;
48
64
  /** Displays an object's properties in a detailed format */
@@ -55,8 +71,6 @@ export interface Console {
55
71
  countReset: (label?: string) => void;
56
72
  /** Writes a message if the value is falsy, otherwise does nothing */
57
73
  assert: (value: any, message?: string, ...optionalParams: Array<any>) => void;
58
- /** Logs the elapsed time for a timer without ending it */
59
- timeLog: (label?: string, ...data: Array<any>) => void;
60
74
  /** Prints a stack trace with an optional message */
61
75
  trace: (message?: any, ...optionalParams: Array<any>) => void;
62
76
  }
@@ -75,4 +89,15 @@ export interface ConsoleConfig {
75
89
  }
76
90
  /** Creates a console instance using the global console. */
77
91
  export declare const createConsole: (config?: ConsoleConfig) => Console;
92
+ export interface ConsoleWithTimeConfig extends ConsoleConfig {
93
+ /**
94
+ * Type of timestamp to prepend to log messages.
95
+ *
96
+ * - 'absolute': Shows actual time (e.g., "14:32:15.234")
97
+ * - 'relative': Shows time since console creation (e.g., "+1.234s")
98
+ */
99
+ readonly timestampType: "absolute" | "relative";
100
+ }
101
+ /** Creates a console instance with timestamp prefixes. */
102
+ export declare const createConsoleWithTime: (config?: ConsoleWithTimeConf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AED,6DAA6D;AAC7D,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAED,MAAM,WAAW,aAAa;IAC5B;;;;;OAKG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC;CAClC;AAED,2DAA2D;AAC3D,eAAO,MAAM,aAAa,GAAI,SAAQ,aAAkB,KAAG,OAgE1D,CAAC;AAEF,MAAM,WAAW,qBAAsB,SAAQ,aAAa;IAC1D;;;;;OAKG;IACH,QAAQ,CAAC,aAAa,EAAE,UAAU,GAAG,UAAU,CAAC;CACjD;AAED,0DAA0D;AAC1D,eAAO,MAAM,qBAAqB,GAChC,SAAQ,qBAAqD,KAC5D,OAmDF,CAAC"}
@@ -13,14 +13,28 @@
13
13
  * ### Example
14
14
  *
15
15
  * ```ts
16
- * deps.console.log("[db]", "send data message", protocolMessage);
16
+ * deps.console.log("[evolu]", "createEvoluInstance", { name });
17
17
  * ```
18
18
  *
19
19
  * **Tip**: In browser dev tools, you can filter logs by tag (e.g., `[db]`) to
20
- * quickly find relevant messages.
20
+ * quickly find relevant messages. In Node.js, use `grep` to filter output:
21
21
  *
22
- * **Warning**: If you encounter platform-specific issues or missing methods,
23
- * please contribute a PR with details about the environment and behavior.
22
+ * ```bash
23
+ * node app.js | grep "\[relay\]" # Show only relay logs
24
+ * node app.js | grep -E "\[db\]|\[sql\]" # Show db and sql logs
25
+ * node app.js | grep -v "\[debug\]" # Hide debug logs
26
+ * ```
27
+ *
28
+ * Or add to package.json scripts:
29
+ *
30
+ * ```json
31
+ * {
32
+ * "scripts": {
33
+ * "dev:relay": "node app.js | grep \"\\[relay\\]\"",
34
+ * "dev:db": "node app.js | grep -E \"\\[db\\]|\\[sql\\]\""
35
+ * }
36
+ * }
37
+ * ```
24
38
  *
25
39
  * @module
26
40
  */
@@ -58,6 +72,11 @@ export const createConsole = (config = {}) => {
58
72
  if (instance.enabled)
59
73
  console.time(label);
60
74
  },
75
+ timeLog: (label, ...data) => {
76
+ // eslint-disable-next-line no-console, @typescript-eslint/no-unsafe-argument
77
+ if (instance.enabled)
78
+ console.timeLog(label, ...data);
79
+ },
61
80
  timeEnd: (label) => {
62
81
  // eslint-disable-next-line no-console
63
82
  if (instance.enabled)
@@ -88,11 +107,6 @@ export const createConsole = (config = {}) => {
88
107
  if (instance.enabled)
89
108
  console.assert(value, message, ...optionalParams);
90
109
  },
91
- timeLog: (label, ...data) => {
92
- // eslint-disable-next-line no-console, @typescript-eslint/no-unsafe-argument
93
- if (instance.enabled)
94
- console.timeLog(label, ...data);
95
- },
96
110
  trace: (message, ...optionalParams) => {
97
111
  // eslint-disable-next-line no-console, @typescript-eslint/no-unsafe-argument
98
112
  if (instance.enabled)
@@ -101,3 +115,52 @@ export const createConsole = (config = {}) => {
101
115
  };
102
116
  return instance;
103
117
  };
118
+ /** Creates a console instance with timestamp prefixes. */
119
+ export const createConsoleWithTime = (config = { timestampType: "relative" }) => {
120
+ const console = createConsole(config);
121
+ const startTime = performance.now();
122
+ const getTimestamp = () => {
123
+ if (config.timestampType === "relative") {
124
+ const elapsed = (performance.now() - startTime) / 1000;
125
+ // Format for better readability at different time scales
126
+ if (elapsed < 60) {
127
+ // Under 1 minute: show seconds with millisecond precision
128
+ return `+${elapsed.toFixed(3)}s`;
129
+ }
130
+ else if (elapsed < 3600) {
131
+ // 1 minute to 1 hour: show minutes and seconds with millisecond precision
132
+ const minutes = Math.floor(elapsed / 60);
133
+ const seconds = (elapsed % 60).toFixed(3);
134
+ return `+${minutes}m${seconds}s`;
135
+ }
136
+ else {
137
+ // Over 1 hour: show hours, minutes, and seconds with millisecond precision
138
+ const hours = Math.floor(elapsed / 3600);
139
+ const minutes = Math.floor((elapsed % 3600) / 60);
140
+ const seconds = ((elapsed % 3600) % 60).toFixed(3);
141
+ return `+${hours}h${minutes}m${seconds}s`;
142
+ }
143
+ }
144
+ else {
145
+ // Absolute time - format as HH:MM:SS.mmm
146
+ const now = new Date();
147
+ const hours = now.getHours().toString().padStart(2, "0");
148
+ const minutes = now.getMinutes().toString().padStart(2, "0");
149
+ const seconds = now.getSeconds().toString().padStart(2, "0");
150
+ const milliseconds = now.getMilliseconds().toString().padStart(3, "0");
151
+ return `${hours}:${minutes}:${seconds}.${milliseconds}`;
152
+ }
153
+ };
154
+ const withTimestamp = (fn) => (...args) => {
155
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
156
+ fn(`[${getTimestamp()}]`, ...args);
157
+ };
158
+ // Override methods that should have timestamps
159
+ console.log = withTimestamp(console.log);
160
+ console.info = withTimestamp(console.info);
161
+ console.warn = withTimestamp(console.warn);
162
+ console.error = withTimestamp(console.error);
163
+ console.debug = withTimestamp(console.debug);
164
+ console.trace = withTimestamp(console.trace);
165
+ return console;
166
+ };
@@ -1,49 +1,64 @@
1
- /**
2
- * 🔒
3
- *
4
- * @module
5
- */
6
1
  import { Result } from "./Result.js";
7
- import { Id, Mnemonic, NonNegativeInt } from "./Type.js";
8
- import { Brand } from "./Types.js";
9
- /** `Uint8Array` created by {@link createRandomBytes}. */
10
- export type RandomBytes = Uint8Array & Brand<"RandomBytes">;
11
- export type CreateRandomBytes = (bytesLength?: number) => RandomBytes;
12
- export interface CreateRandomBytesDep {
13
- readonly createRandomBytes: CreateRandomBytes;
2
+ import { NonNegativeInt } from "./Type.js";
3
+ export interface RandomBytes {
4
+ /**
5
+ * Creates cryptographically secure random bytes with type-safe length
6
+ * branding.
7
+ *
8
+ * Uses the operating system's cryptographically secure random number
9
+ * generator (crypto.getRandomValues) to generate high-quality entropy
10
+ * suitable for cryptographic operations.
11
+ *
12
+ * ### Type Safety
13
+ *
14
+ * Returns specific branded types for common sizes:
15
+ *
16
+ * - `Random16` for 16-byte values (128 bits)
17
+ * - `Random32` for 32-byte values (256 bits)
18
+ * - `Random64` for 64-byte values (512 bits)
19
+ * - `Random` for any other size
20
+ *
21
+ * ### Example
22
+ *
23
+ * ```ts
24
+ * const nonce = randomBytes.create(16); // Type: Random16
25
+ * const key = randomBytes.create(32); // Type: Random32
26
+ * const seed = randomBytes.create(64); // Type: Random64
27
+ * const custom = randomBytes.create(48); // Type: Random
28
+ * ```
29
+ */
30
+ create(bytesLength: 16): Entropy16;
31
+ create(bytesLength: 32): Entropy32;
32
+ create(bytesLength: 64): Entropy64;
33
+ create(bytesLength: number): Entropy;
14
34
  }
15
- /** Cryptographically secure PRNG. Uses internal OS-level crypto.getRandomValues. */
16
- export declare const createRandomBytes: CreateRandomBytes;
17
- export type CreateMnemonic = () => Mnemonic;
18
- export interface CreateMnemonicDep {
19
- readonly createMnemonic: CreateMnemonic;
35
+ export interface RandomBytesDep {
36
+ readonly randomBytes: RandomBytes;
20
37
  }
21
- export declare const createEnglishMnemonic: CreateMnemonic;
22
- export type MnemonicSeed = Uint8Array & Brand<"MnemonicSeed">;
23
- export declare const mnemonicToMnemonicSeed: (mnemonic: Mnemonic) => MnemonicSeed;
38
+ declare const Entropy: import("./Type.js").BrandType<import("./Type.js").Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, import("./Type.js").Uint8ArrayError, Uint8Array<ArrayBufferLike>, import("./Type.js").Uint8ArrayError>, "Entropy", import("./Type.js").BrandWithoutRefineError<"Entropy", import("./Type.js").Uint8ArrayError>, never>;
39
+ type Entropy = typeof Entropy.Type;
40
+ export declare const Entropy16: import("./Type.js").BrandType<import("./Type.js").Type<"Brand", Uint8Array<ArrayBufferLike> & import("./Brand.js").Brand<"Entropy">, Uint8Array<ArrayBufferLike>, import("./Type.js").BrandWithoutRefineError<"Entropy", import("./Type.js").Uint8ArrayError>, Uint8Array<ArrayBufferLike>, never>, "Length16", import("./Type.js").LengthError<16>, import("./Type.js").BrandWithoutRefineError<"Entropy", import("./Type.js").Uint8ArrayError>>;
41
+ export type Entropy16 = typeof Entropy16.Type;
42
+ export declare const Entropy32: import("./Type.js").BrandType<import("./Type.js").Type<"Brand", Uint8Array<ArrayBufferLike> & import("./Brand.js").Brand<"Entropy">, Uint8Array<ArrayBufferLike>, import("./Type.js").BrandWithoutRefineError<"Entropy", import("./Type.js").Uint8ArrayError>, Uint8Array<ArrayBufferLike>, never>, "Length32", import("./Type.js").LengthError<32>, import("./Type.js").BrandWithoutRefineError<"Entropy", import("./Type.js").Uint8ArrayError>>;
43
+ export type Entropy32 = typeof Entropy32.Type;
44
+ export declare const Entropy64: import("./Type.js").BrandType<import("./Type.js").Type<"Brand", Uint8Array<ArrayBufferLike> & import("./Brand.js").Brand<"Entropy">, Uint8Array<ArrayBufferLike>, import("./Type.js").BrandWithoutRefineError<"Entropy", import("./Type.js").Uint8ArrayError>, Uint8Array<ArrayBufferLike>, never>, "Length64", import("./Type.js").LengthError<64>, import("./Type.js").BrandWithoutRefineError<"Entropy", import("./Type.js").Uint8ArrayError>>;
45
+ export type Entropy64 = typeof Entropy64.Type;
46
+ export declare const createRandomBytes: () => RandomBytes;
24
47
  /**
25
48
  * SLIP21.
26
49
  *
27
50
  * https://github.com/satoshilabs/slips/blob/master/slip-0021.md
28
51
  */
29
- export declare const createSlip21: (seed: MnemonicSeed, path: ReadonlyArray<string>) => Uint8Array;
52
+ export declare const createSlip21: (seed: Entropy16 | Entropy32 | Entropy64, path: ReadonlyArray<string | number>) => Entropy32;
30
53
  /**
31
- * Creates a 21-character Base64URL ID (also known as nanoid) from a SLIP-21
32
- * derived key.
33
- *
34
- * Reduces the 256-bit SLIP-21 output to 126 bits (21 chars × 6 bits) for a
35
- * compact, human-readable, and shareable identifier suitable for UI display or
36
- * URL use. While this lowers entropy, 126 bits remains cryptographically secure
37
- * for uniqueness and unpredictability in most applications (comparable to
38
- * UUIDv4's 122 bits).
54
+ * Derives a single node in the SLIP-21 hierarchical key derivation.
39
55
  *
40
- * See https://github.com/satoshilabs/slips/blob/master/slip-0021.md
56
+ * @see {@link createSlip21}
41
57
  */
42
- export declare const createSlip21Id: (seed: MnemonicSeed, path: ReadonlyArray<string>) => Id;
58
+ export declare const deriveSlip21Node: (label: string, parentNode: Entropy64) => Entropy64;
43
59
  /** The encryption key for {@link SymmetricCrypto}. */
44
- export declare const EncryptionKey: import("./Type.js").BrandType<import("./Type.js").BrandType<import("./Type.js").Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, import("./Type.js").Uint8ArrayError, Uint8Array<ArrayBufferLike>, import("./Type.js").Uint8ArrayError>, "Length32", import("./Type.js").LengthError<32>, import("./Type.js").Uint8ArrayError>, "EncryptionKey", import("./Type.js").BrandWithoutRefineError<"EncryptionKey", import("./Type.js").Uint8ArrayError | import("./Type.js").LengthError<32>>, never>;
60
+ export declare const EncryptionKey: import("./Type.js").BrandType<import("./Type.js").BrandType<import("./Type.js").Type<"Brand", Uint8Array<ArrayBufferLike> & import("./Brand.js").Brand<"Entropy">, Uint8Array<ArrayBufferLike>, import("./Type.js").BrandWithoutRefineError<"Entropy", import("./Type.js").Uint8ArrayError>, Uint8Array<ArrayBufferLike>, never>, "Length32", import("./Type.js").LengthError<32>, import("./Type.js").BrandWithoutRefineError<"Entropy", import("./Type.js").Uint8ArrayError>>, "EncryptionKey", import("./Type.js").BrandWithoutRefineError<"EncryptionKey", import("./Type.js").BrandWithoutRefineError<"Entropy", import("./Type.js").Uint8ArrayError> | import("./Type.js").LengthError<32>>, never>;
45
61
  export type EncryptionKey = typeof EncryptionKey.Type;
46
- export declare const createEncryptionKey: (seed: MnemonicSeed) => EncryptionKey;
47
62
  /** Symmetric cryptography. */
48
63
  export interface SymmetricCrypto {
49
64
  readonly nonceLength: NonNegativeInt;
@@ -65,7 +80,7 @@ export interface SymmetricCryptoDecryptError {
65
80
  *
66
81
  * https://github.com/paulmillr/noble-ciphers?tab=readme-ov-file#which-cipher-should-i-pick
67
82
  */
68
- export declare const createSymmetricCrypto: (deps: CreateRandomBytesDep) => SymmetricCrypto;
83
+ export declare const createSymmetricCrypto: (deps: RandomBytesDep) => SymmetricCrypto;
69
84
  /**
70
85
  * Returns the PADMÉ padded length for a given input length.
71
86
  *
@@ -79,4 +94,16 @@ export declare const padmePaddedLength: (length: NonNegativeInt) => NonNegativeI
79
94
  * {@link padmePaddedLength}.
80
95
  */
81
96
  export declare const padmePaddingLength: (length: NonNegativeInt) => NonNegativeInt;
97
+ /**
98
+ * Performs a timing-safe comparison of two Uint8Arrays. Returns true if they
99
+ * are equal, false otherwise. Takes constant time regardless of where the
100
+ * arrays differ.
101
+ *
102
+ * @see https://nodejs.org/api/crypto.html#cryptotimingsafeequala-b
103
+ */
104
+ export type TimingSafeEqual = (a: Uint8Array, b: Uint8Array) => boolean;
105
+ export interface TimingSafeEqualDep {
106
+ readonly timingSafeEqual: TimingSafeEqual;
107
+ }
108
+ export {};
82
109
  //# sourceMappingURL=Crypto.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Crypto.d.ts","sourceRoot":"","sources":["../../src/Crypto.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AASH,OAAO,EAAc,MAAM,EAAW,MAAM,aAAa,CAAC;AAC1D,OAAO,EAEL,EAAE,EAEF,QAAQ,EACR,cAAc,EAEf,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,yDAAyD;AACzD,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,KAAK,CAAC,aAAa,CAAC,CAAC;AAE5D,MAAM,MAAM,iBAAiB,GAAG,CAAC,WAAW,CAAC,EAAE,MAAM,KAAK,WAAW,CAAC;AAEtE,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;CAC/C;AAED,oFAAoF;AACpF,eAAO,MAAM,iBAAiB,EAAE,iBACS,CAAC;AAE1C,MAAM,MAAM,cAAc,GAAG,MAAM,QAAQ,CAAC;AAE5C,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAC;CACzC;AAED,eAAO,MAAM,qBAAqB,EAAE,cACe,CAAC;AAEpD,MAAM,MAAM,YAAY,GAA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