@evolu/common 7.4.0 → 8.0.0-next.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 (251) hide show
  1. package/README.md +4 -61
  2. package/dist/src/Array.d.ts +343 -102
  3. package/dist/src/Array.d.ts.map +1 -1
  4. package/dist/src/Array.js +181 -85
  5. package/dist/src/Assert.d.ts +57 -11
  6. package/dist/src/Assert.d.ts.map +1 -1
  7. package/dist/src/Assert.js +47 -11
  8. package/dist/src/BigInt.d.ts +6 -1
  9. package/dist/src/BigInt.d.ts.map +1 -1
  10. package/dist/src/BigInt.js +5 -0
  11. package/dist/src/Brand.d.ts +40 -12
  12. package/dist/src/Brand.d.ts.map +1 -1
  13. package/dist/src/Brand.js +5 -0
  14. package/dist/src/Buffer.d.ts +6 -1
  15. package/dist/src/Buffer.d.ts.map +1 -1
  16. package/dist/src/Buffer.js +7 -2
  17. package/dist/src/Cache.d.ts +10 -2
  18. package/dist/src/Cache.d.ts.map +1 -1
  19. package/dist/src/Cache.js +6 -0
  20. package/dist/src/Callbacks.d.ts +10 -7
  21. package/dist/src/Callbacks.d.ts.map +1 -1
  22. package/dist/src/Callbacks.js +23 -13
  23. package/dist/src/Console.d.ts +361 -69
  24. package/dist/src/Console.d.ts.map +1 -1
  25. package/dist/src/Console.js +217 -117
  26. package/dist/src/Crypto.d.ts +70 -21
  27. package/dist/src/Crypto.d.ts.map +1 -1
  28. package/dist/src/Crypto.js +72 -27
  29. package/dist/src/Eq.d.ts +22 -2
  30. package/dist/src/Eq.d.ts.map +1 -1
  31. package/dist/src/Eq.js +21 -1
  32. package/dist/src/Error.d.ts +23 -12
  33. package/dist/src/Error.d.ts.map +1 -1
  34. package/dist/src/Error.js +27 -11
  35. package/dist/src/Function.d.ts +128 -56
  36. package/dist/src/Function.d.ts.map +1 -1
  37. package/dist/src/Function.js +118 -14
  38. package/dist/src/Identicon.d.ts +5 -0
  39. package/dist/src/Identicon.d.ts.map +1 -1
  40. package/dist/src/Identicon.js +6 -1
  41. package/dist/src/Lookup.d.ts +160 -0
  42. package/dist/src/Lookup.d.ts.map +1 -0
  43. package/dist/src/Lookup.js +192 -0
  44. package/dist/src/Microtask.d.ts +21 -0
  45. package/dist/src/Microtask.d.ts.map +1 -0
  46. package/dist/src/Microtask.js +37 -0
  47. package/dist/src/Number.d.ts +18 -4
  48. package/dist/src/Number.d.ts.map +1 -1
  49. package/dist/src/Number.js +23 -1
  50. package/dist/src/Object.d.ts +110 -5
  51. package/dist/src/Object.d.ts.map +1 -1
  52. package/dist/src/Object.js +108 -5
  53. package/dist/src/Option.d.ts +58 -0
  54. package/dist/src/Option.d.ts.map +1 -0
  55. package/dist/src/Option.js +43 -0
  56. package/dist/src/Order.d.ts +5 -0
  57. package/dist/src/Order.d.ts.map +1 -1
  58. package/dist/src/Order.js +8 -3
  59. package/dist/src/Platform.d.ts +36 -2
  60. package/dist/src/Platform.d.ts.map +1 -1
  61. package/dist/src/Platform.js +10 -6
  62. package/dist/src/Polyfills.d.ts +27 -0
  63. package/dist/src/Polyfills.d.ts.map +1 -0
  64. package/dist/src/Polyfills.js +299 -0
  65. package/dist/src/Random.d.ts +18 -7
  66. package/dist/src/Random.d.ts.map +1 -1
  67. package/dist/src/Random.js +9 -7
  68. package/dist/src/Redacted.d.ts +7 -4
  69. package/dist/src/Redacted.d.ts.map +1 -1
  70. package/dist/src/Redacted.js +5 -0
  71. package/dist/src/Ref.d.ts +31 -16
  72. package/dist/src/Ref.d.ts.map +1 -1
  73. package/dist/src/Ref.js +35 -7
  74. package/dist/src/RefCount.d.ts +62 -0
  75. package/dist/src/RefCount.d.ts.map +1 -0
  76. package/dist/src/RefCount.js +83 -0
  77. package/dist/src/Relation.d.ts +84 -29
  78. package/dist/src/Relation.d.ts.map +1 -1
  79. package/dist/src/Relation.js +83 -105
  80. package/dist/src/Resource.d.ts +263 -0
  81. package/dist/src/Resource.d.ts.map +1 -0
  82. package/dist/src/Resource.js +389 -0
  83. package/dist/src/Result.d.ts +390 -374
  84. package/dist/src/Result.d.ts.map +1 -1
  85. package/dist/src/Result.js +142 -70
  86. package/dist/src/Schedule.d.ts +953 -0
  87. package/dist/src/Schedule.d.ts.map +1 -0
  88. package/dist/src/Schedule.js +1199 -0
  89. package/dist/src/Set.d.ts +181 -0
  90. package/dist/src/Set.d.ts.map +1 -0
  91. package/dist/src/Set.js +137 -0
  92. package/dist/src/Skiplist.d.ts +6 -1
  93. package/dist/src/Skiplist.d.ts.map +1 -1
  94. package/dist/src/Skiplist.js +5 -0
  95. package/dist/src/Sqlite.d.ts +160 -60
  96. package/dist/src/Sqlite.d.ts.map +1 -1
  97. package/dist/src/Sqlite.js +290 -190
  98. package/dist/src/Store.d.ts +36 -28
  99. package/dist/src/Store.d.ts.map +1 -1
  100. package/dist/src/Store.js +55 -15
  101. package/dist/src/String.d.ts +5 -0
  102. package/dist/src/String.d.ts.map +1 -1
  103. package/dist/src/String.js +5 -0
  104. package/dist/src/Task.d.ts +2263 -423
  105. package/dist/src/Task.d.ts.map +1 -1
  106. package/dist/src/Task.js +1488 -348
  107. package/dist/src/Test.d.ts +122 -0
  108. package/dist/src/Test.d.ts.map +1 -0
  109. package/dist/src/Test.js +66 -0
  110. package/dist/src/Time.d.ts +201 -48
  111. package/dist/src/Time.d.ts.map +1 -1
  112. package/dist/src/Time.js +190 -86
  113. package/dist/src/Tracer.d.ts +48 -0
  114. package/dist/src/Tracer.d.ts.map +1 -0
  115. package/dist/src/Tracer.js +6 -0
  116. package/dist/src/Type.d.ts +582 -209
  117. package/dist/src/Type.d.ts.map +1 -1
  118. package/dist/src/Type.js +362 -240
  119. package/dist/src/Types.d.ts +160 -6
  120. package/dist/src/Types.d.ts.map +1 -1
  121. package/dist/src/Types.js +22 -2
  122. package/dist/src/WebSocket.d.ts +113 -58
  123. package/dist/src/WebSocket.d.ts.map +1 -1
  124. package/dist/src/WebSocket.js +210 -118
  125. package/dist/src/Worker.d.ts +245 -60
  126. package/dist/src/Worker.d.ts.map +1 -1
  127. package/dist/src/Worker.js +220 -64
  128. package/dist/src/index.d.ts +25 -3
  129. package/dist/src/index.d.ts.map +1 -1
  130. package/dist/src/index.js +19 -3
  131. package/dist/src/local-first/Db.d.ts +24 -213
  132. package/dist/src/local-first/Db.d.ts.map +1 -1
  133. package/dist/src/local-first/Db.js +622 -293
  134. package/dist/src/local-first/Error.d.ts +12 -0
  135. package/dist/src/local-first/Error.d.ts.map +1 -0
  136. package/dist/src/local-first/Error.js +6 -0
  137. package/dist/src/local-first/Evolu.d.ts +330 -285
  138. package/dist/src/local-first/Evolu.d.ts.map +1 -1
  139. package/dist/src/local-first/Evolu.js +472 -402
  140. package/dist/src/local-first/LocalAuth.d.ts +10 -10
  141. package/dist/src/local-first/LocalAuth.d.ts.map +1 -1
  142. package/dist/src/local-first/LocalAuth.js +6 -1
  143. package/dist/src/local-first/Owner.d.ts +70 -27
  144. package/dist/src/local-first/Owner.d.ts.map +1 -1
  145. package/dist/src/local-first/Owner.js +27 -14
  146. package/dist/src/local-first/Protocol.d.ts +58 -50
  147. package/dist/src/local-first/Protocol.d.ts.map +1 -1
  148. package/dist/src/local-first/Protocol.js +253 -155
  149. package/dist/src/local-first/Query.d.ts +133 -43
  150. package/dist/src/local-first/Query.d.ts.map +1 -1
  151. package/dist/src/local-first/Query.js +139 -90
  152. package/dist/src/local-first/Relay.d.ts +18 -38
  153. package/dist/src/local-first/Relay.d.ts.map +1 -1
  154. package/dist/src/local-first/Relay.js +59 -171
  155. package/dist/src/local-first/Schema.d.ts +139 -144
  156. package/dist/src/local-first/Schema.d.ts.map +1 -1
  157. package/dist/src/local-first/Schema.js +78 -163
  158. package/dist/src/local-first/Shared.d.ts +125 -0
  159. package/dist/src/local-first/Shared.d.ts.map +1 -0
  160. package/dist/src/local-first/Shared.js +569 -0
  161. package/dist/src/local-first/Storage.d.ts +50 -53
  162. package/dist/src/local-first/Storage.d.ts.map +1 -1
  163. package/dist/src/local-first/Storage.js +121 -173
  164. package/dist/src/local-first/Timestamp.d.ts +28 -35
  165. package/dist/src/local-first/Timestamp.d.ts.map +1 -1
  166. package/dist/src/local-first/Timestamp.js +24 -25
  167. package/dist/src/local-first/index.d.ts +2 -15
  168. package/dist/src/local-first/index.d.ts.map +1 -1
  169. package/dist/src/local-first/index.js +2 -15
  170. package/package.json +36 -26
  171. package/src/Array.ts +467 -106
  172. package/src/Assert.ts +87 -12
  173. package/src/BigInt.ts +7 -1
  174. package/src/Brand.ts +41 -12
  175. package/src/Buffer.ts +10 -4
  176. package/src/Cache.ts +11 -2
  177. package/src/Callbacks.ts +33 -23
  178. package/src/Console.ts +567 -178
  179. package/src/Crypto.ts +111 -62
  180. package/src/Eq.ts +30 -3
  181. package/src/Error.ts +50 -34
  182. package/src/Function.ts +140 -68
  183. package/src/Identicon.ts +7 -1
  184. package/src/Lookup.ts +415 -0
  185. package/src/Microtask.ts +58 -0
  186. package/src/Number.ts +40 -7
  187. package/src/Object.ts +155 -16
  188. package/src/Option.ts +74 -0
  189. package/src/Order.ts +11 -3
  190. package/src/Platform.ts +43 -7
  191. package/src/Polyfills.ts +465 -0
  192. package/src/Random.ts +25 -11
  193. package/src/Redacted.ts +8 -4
  194. package/src/Ref.ts +72 -21
  195. package/src/RefCount.ts +170 -0
  196. package/src/Relation.ts +188 -136
  197. package/src/Resource.ts +864 -0
  198. package/src/Result.ts +548 -381
  199. package/src/Schedule.ts +1471 -0
  200. package/src/Set.ts +247 -0
  201. package/src/Skiplist.ts +7 -1
  202. package/src/Sqlite.ts +409 -304
  203. package/src/Store.ts +94 -48
  204. package/src/String.ts +6 -0
  205. package/src/Task.ts +3685 -740
  206. package/src/Test.ts +162 -0
  207. package/src/Time.ts +348 -145
  208. package/src/Tracer.ts +54 -0
  209. package/src/Type.ts +1064 -630
  210. package/src/Types.ts +202 -7
  211. package/src/WebSocket.ts +311 -178
  212. package/src/Worker.ts +527 -147
  213. package/src/index.ts +74 -3
  214. package/src/local-first/Db.ts +871 -597
  215. package/src/local-first/Error.ts +17 -0
  216. package/src/local-first/Evolu.ts +884 -823
  217. package/src/local-first/LocalAuth.ts +10 -10
  218. package/src/local-first/Owner.ts +94 -42
  219. package/src/local-first/Protocol.ts +440 -303
  220. package/src/local-first/Query.ts +243 -194
  221. package/src/local-first/Relay.ts +91 -252
  222. package/src/local-first/Schema.ts +284 -394
  223. package/src/local-first/Shared.ts +932 -0
  224. package/src/local-first/Storage.ts +209 -282
  225. package/src/local-first/Timestamp.ts +38 -45
  226. package/src/local-first/index.ts +2 -16
  227. package/LICENSE +0 -21
  228. package/dist/src/Instances.d.ts +0 -34
  229. package/dist/src/Instances.d.ts.map +0 -1
  230. package/dist/src/Instances.js +0 -44
  231. package/dist/src/Resources.d.ts +0 -118
  232. package/dist/src/Resources.d.ts.map +0 -1
  233. package/dist/src/Resources.js +0 -197
  234. package/dist/src/local-first/Platform.d.ts +0 -25
  235. package/dist/src/local-first/Platform.d.ts.map +0 -1
  236. package/dist/src/local-first/Platform.js +0 -1
  237. package/dist/src/local-first/Public.d.ts +0 -22
  238. package/dist/src/local-first/Public.d.ts.map +0 -1
  239. package/dist/src/local-first/Public.js +0 -15
  240. package/dist/src/local-first/PublicKysely.d.ts +0 -148
  241. package/dist/src/local-first/PublicKysely.d.ts.map +0 -1
  242. package/dist/src/local-first/PublicKysely.js +0 -184
  243. package/dist/src/local-first/Sync.d.ts +0 -112
  244. package/dist/src/local-first/Sync.d.ts.map +0 -1
  245. package/dist/src/local-first/Sync.js +0 -529
  246. package/src/Instances.ts +0 -90
  247. package/src/Resources.ts +0 -367
  248. package/src/local-first/Platform.ts +0 -27
  249. package/src/local-first/Public.ts +0 -42
  250. package/src/local-first/PublicKysely.ts +0 -239
  251. package/src/local-first/Sync.ts +0 -960
package/dist/src/Brand.js CHANGED
@@ -1 +1,6 @@
1
+ /**
2
+ * A utility interface for creating branded types.
3
+ *
4
+ * @module
5
+ */
1
6
  export {};
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Binary data handling and byte array utilities.
3
+ *
4
+ * @module
5
+ */
1
6
  import { NonNegativeInt } from "./Type.js";
2
7
  export { bytesToHex, bytesToUtf8, concatBytes, hexToBytes, utf8ToBytes, } from "@noble/ciphers/utils.js";
3
8
  /**
@@ -13,7 +18,7 @@ export declare class BufferError extends Error {
13
18
  * its capacity) to minimize memory reallocations and uses `subarray` for
14
19
  * efficient, copy-free data access in methods like `unwrap` and `shift`.
15
20
  *
16
- * ### Recommended Usage
21
+ * ## Recommended Usage
17
22
  *
18
23
  * Create as few Buffers as possible—typically one main Buffer for the final
19
24
  * output. Temporary Buffers are allowed when necessary (e.g., for
@@ -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,WAAW,GACZ,MAAM,yBAAyB,CAAC;AAEjC;;;GAGG;AACH,qBAAa,WAAY,SAAQ,KAAK;gBACxB,OAAO,EAAE,MAAM;CAM5B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,WAAW,MAAM;IACrB,kDAAkD;IAClD,WAAW,EAAE,MAAM,cAAc,CAAC;IAElC,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;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
1
+ /**
2
+ * Binary data handling and byte array utilities.
3
+ *
4
+ * @module
5
+ */
6
+ import { NonNegativeInt, zeroNonNegativeInt } from "./Type.js";
2
7
  export { bytesToHex, bytesToUtf8, concatBytes, hexToBytes, utf8ToBytes, } from "@noble/ciphers/utils.js";
3
8
  /**
4
9
  * Custom error for {@link Buffer}-related failures like premature end of data.
@@ -56,7 +61,7 @@ export const createBuffer = (arrayLike) => {
56
61
  length = newLength;
57
62
  },
58
63
  reset: () => {
59
- length = NonNegativeInt.orThrow(0);
64
+ length = zeroNonNegativeInt;
60
65
  },
61
66
  unwrap: () => value.subarray(0, length),
62
67
  };
@@ -1,11 +1,19 @@
1
+ /**
2
+ * Cache implementations including LRU eviction.
3
+ *
4
+ * @module
5
+ */
1
6
  import { PositiveInt } from "./Type.js";
2
7
  /**
3
8
  * Generic cache interface providing basic key-value storage operations.
4
9
  *
5
10
  * Keys are compared by reference (standard Map semantics).
6
11
  *
7
- * Note: Cache does not extend Map because eviction policies (like in LRU)
8
- * violate the Liskov Substitution Principle.
12
+ * Note: Cache has a Map-like API but does not extend Map because it behaves
13
+ * differently. Eviction policies (like LRU) can remove entries implicitly, and
14
+ * code that accepts a Map can assume values remain until deleted explicitly. An
15
+ * evicting cache is not a safe substitute for Map (Liskov Substitution
16
+ * Principle).
9
17
  */
10
18
  export interface Cache<K, V> {
11
19
  /** Checks if a key exists in the cache. */
@@ -1 +1 @@
1
- {"version":3,"file":"Cache.d.ts","sourceRoot":"","sources":["../../src/Cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC;;;;;;;GAOG;AACH,MAAM,WAAW,KAAK,CAAC,CAAC,EAAE,CAAC;IACzB,2CAA2C;IAC3C,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,CAAC;IAEzB,kEAAkE;IAClE,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC;IAE/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,9 @@
1
+ /**
2
+ * Cache implementations including LRU eviction.
3
+ *
4
+ * @module
5
+ */
6
+ import { PositiveInt } from "./Type.js";
1
7
  /**
2
8
  * Creates an LRU (least recently used) cache with a maximum capacity.
3
9
  *
@@ -1,6 +1,11 @@
1
- import { Brand } from "./Brand.js";
2
- import { RandomBytesDep } from "./Crypto.js";
1
+ /**
2
+ * Request-response correlation for callbacks across boundaries.
3
+ *
4
+ * @module
5
+ */
6
+ import type { RandomBytesDep } from "./Crypto.js";
3
7
  import { Id } from "./Type.js";
8
+ import type { Callback } from "./Types.js";
4
9
  /**
5
10
  * Request-response correlation for callbacks across boundaries.
6
11
  *
@@ -40,14 +45,12 @@ import { Id } from "./Type.js";
40
45
  * @template T - The type of argument passed to callbacks (defaults to undefined
41
46
  * for no-argument callbacks)
42
47
  */
43
- export interface Callbacks<T = undefined> {
48
+ export interface Callbacks<T = undefined> extends Disposable {
44
49
  /** Registers a callback function and returns a unique ID. */
45
- readonly register: (callback: (arg: T) => void) => CallbackId;
50
+ readonly register: (callback: Callback<T>) => Id;
46
51
  /** Executes and removes a callback associated with the given ID. */
47
- readonly execute: T extends undefined ? (id: CallbackId) => undefined : (id: CallbackId, arg: T) => undefined;
52
+ readonly execute: T extends undefined ? (id: Id) => undefined : (id: Id, arg: T) => undefined;
48
53
  }
49
- /** Unique identifier for a callback in {@link Callbacks}. */
50
- export type CallbackId = Id & Brand<"Callback">;
51
54
  /** Creates a {@link Callbacks} registry for managing callbacks. */
52
55
  export declare const createCallbacks: <T = undefined>(deps: RandomBytesDep) => Callbacks<T>;
53
56
  //# sourceMappingURL=Callbacks.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Callbacks.d.ts","sourceRoot":"","sources":["../../src/Callbacks.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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ACrB,CAAC,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,KAAK,SAAS,CAAC;CACnC;AAED,mEAAmE;AACnE,eAAO,MAAM,eAAe,GAAI,CAAC,GAAG,SAAS,EAC3C,MAAM,cAAc,KACnB,SAAS,CAAC,CAAC,CA6Bb,CAAC"}
@@ -1,25 +1,35 @@
1
- import { createId } from "./Type.js";
1
+ /**
2
+ * Request-response correlation for callbacks across boundaries.
3
+ *
4
+ * @module
5
+ */
6
+ import { createId, Id } from "./Type.js";
2
7
  /** Creates a {@link Callbacks} registry for managing callbacks. */
3
8
  export const createCallbacks = (deps) => {
4
9
  const callbackMap = new Map();
10
+ const execute = ((id, ...args) => {
11
+ const callback = callbackMap.get(id);
12
+ if (!callback)
13
+ return undefined;
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
+ return undefined;
23
+ });
5
24
  return {
6
25
  register: (callback) => {
7
26
  const id = createId(deps);
8
27
  callbackMap.set(id, callback);
9
28
  return id;
10
29
  },
11
- execute: (id, ...args) => {
12
- const callback = callbackMap.get(id);
13
- if (!callback)
14
- return;
15
- callbackMap.delete(id);
16
- if (args.length === 0) {
17
- // Called without argument (undefined case)
18
- callback();
19
- }
20
- else {
21
- callback(args[0]);
22
- }
30
+ execute,
31
+ [Symbol.dispose]: () => {
32
+ callbackMap.clear();
23
33
  },
24
34
  };
25
35
  };
@@ -1,95 +1,387 @@
1
1
  /**
2
- * Console abstraction for Chrome 123+, Firefox 125+, Safari 18.1+, Node.js
3
- * 22.x+, and React Native 0.75+. Includes methods guaranteed to be available in
4
- * these environments and expected to remain compatible in future versions.
5
- * Output formatting may vary (e.g., interactive UI in browsers vs. text in
6
- * Node.js/React Native), but functionality is consistent across platforms.
2
+ * Platform-agnostic console with structured logging.
7
3
  *
8
- * **Convention**: Use a tag (e.g., `[db]`) as the first argument for log
9
- * filtering.
4
+ * @module
5
+ */
6
+ import type { ReadonlyStore } from "./Store.js";
7
+ import { type Millis, type TimeDep } from "./Time.js";
8
+ /**
9
+ * Platform-agnostic console with structured logging.
10
+ *
11
+ * Captures structured log entries and routes them to configurable outputs.
12
+ * Provides methods guaranteed to be available across browsers, Node.js, and
13
+ * React Native.
14
+ *
15
+ * Key features:
16
+ *
17
+ * - Structured entries — logs are captured as {@link ConsoleEntry} objects with
18
+ * method, path, and args
19
+ * - Pluggable outputs — route logs to console, files, arrays, or custom
20
+ * destinations via {@link ConsoleOutput}
21
+ * - Child consoles — use {@link Console.child} to create derived consoles
22
+ * - Level filtering — see {@link ConsoleLevel} for severity ordering
23
+ * - Entry formatting — use {@link createConsoleFormatter} for timestamps and path
24
+ * prefixes
25
+ *
26
+ * Built-in outputs:
27
+ *
28
+ * - {@link createNativeConsoleOutput} — writes to `globalThis.console` (default)
29
+ * - {@link createConsoleArrayOutput} — captures entries to an array (testing)
30
+ * - {@link createConsoleStoreOutput} — stores latest entry in a
31
+ * {@link ReadonlyStore} for subscribing
32
+ * - {@link createMultiOutput} — fans out to multiple outputs
10
33
  *
11
34
  * ### Example
12
35
  *
13
36
  * ```ts
14
- * deps.console.log("[evolu]", "createEvoluInstance", { name });
15
- * ```
37
+ * // Basic usage - defaults to "log"
38
+ * const console = createConsole();
16
39
  *
17
- * **Tip**: In browser dev tools, you can filter logs by tag (e.g., `[db]`) to
18
- * quickly find relevant messages. In Node.js, use `grep` to filter output:
40
+ * // With formatting (timestamps and path prefixes)
41
+ * const console = createConsole({
42
+ * level: "info",
43
+ * formatter: createConsoleFormatter()({ timestampFormat: "relative" }),
44
+ * });
19
45
  *
20
- * ```bash
21
- * node app.js | grep "\[relay\]" # Show only relay logs
22
- * node app.js | grep -E "\[db\]|\[sql\]" # Show db and sql logs
23
- * node app.js | grep -v "\[debug\]" # Hide debug logs
24
- * ```
46
+ * // Children inherit level at creation, then are independent
47
+ * const console = run.deps.console.child("relay");
48
+ * console.setLevel("silent");
25
49
  *
26
- * Or add to package.json scripts:
50
+ * // Tip: Wrap logged values in objects for labeled output in DevTools
51
+ * console.info("Creating instance", { config }); // Good — expandable "config:" label
52
+ * console.info("Creating instance", config); // Avoid — anonymous object, no label
27
53
  *
28
- * ```json
29
- * {
30
- * "scripts": {
31
- * "dev:relay": "node app.js | grep \"\\[relay\\]\"",
32
- * "dev:db": "node app.js | grep -E \"\\[db\\]|\\[sql\\]\""
33
- * }
34
- * }
54
+ * // Batch update via children
55
+ * const setLevelRecursive = (c: Console, level: ConsoleLevel): void => {
56
+ * c.setLevel(level);
57
+ * for (const child of c.children) setLevelRecursive(child, level);
58
+ * };
35
59
  * ```
60
+ *
61
+ * Console intentionally does not use {@link Task}. Logging must be as fast as
62
+ * possible and always work, even during error handling or shutdown.
63
+ *
64
+ * For testing, use {@link testCreateConsole} which creates a {@link TestConsole}
65
+ * with array output and snapshot helpers.
66
+ *
67
+ * @see {@link createConsole}
36
68
  */
37
69
  export interface Console {
38
- /** Controls whether console methods produce output (default: true) */
39
- enabled?: boolean;
40
- /** Outputs a message to the console */
41
- log: (...args: Array<any>) => void;
42
- /** Outputs an informational message (often same as log) */
43
- info: (...args: Array<any>) => void;
44
- /** Outputs a warning message */
45
- warn: (...args: Array<any>) => void;
46
- /** Outputs an error message */
47
- error: (...args: Array<any>) => void;
48
- /** Outputs a debug message */
49
- debug: (...args: Array<any>) => void;
50
- /** Starts a timer with an optional label */
51
- time: (label?: string) => void;
52
- /** Logs the elapsed time for a timer without ending it */
53
- timeLog: (label?: string, ...data: Array<any>) => void;
54
- /** Ends a timer and logs the elapsed time */
55
- timeEnd: (label?: string) => void;
56
- /** Displays an object's properties in a detailed format */
57
- dir: (object: any, options?: any) => void;
58
- /** Displays tabular data as a table */
59
- table: (tabularData: any, properties?: Array<string>) => void;
60
- /** Logs the number of times this has been called with the given label */
61
- count: (label?: string) => void;
62
- /** Resets the counter for the given label */
63
- countReset: (label?: string) => void;
64
- /** Writes a message if the value is falsy, otherwise does nothing */
65
- assert: (value: any, message?: string, ...optionalParams: Array<any>) => void;
66
- /** Prints a stack trace with an optional message */
67
- trace: (message?: any, ...optionalParams: Array<any>) => void;
70
+ /** Name of this console. Empty for root. */
71
+ readonly name: string;
72
+ /** Child consoles created via {@link Console.child}. */
73
+ readonly children: ReadonlySet<Console>;
74
+ /**
75
+ * Returns the effective log level.
76
+ *
77
+ * If this console has its own level set via {@link Console.setLevel}, returns
78
+ * that. Otherwise returns the inherited level from creation time.
79
+ */
80
+ readonly getLevel: () => ConsoleLevel;
81
+ /**
82
+ * Sets the log level for this console.
83
+ *
84
+ * Pass a level to override the inherited level, or `null` to revert to the
85
+ * inherited level.
86
+ */
87
+ readonly setLevel: (level: ConsoleLevel | null) => void;
88
+ /** Returns true if this console has its own level set (not inherited). */
89
+ readonly hasOwnLevel: () => boolean;
90
+ /**
91
+ * Creates a child console with the given name added to the path.
92
+ *
93
+ * Child inherits the parent's configured level (not any runtime override).
94
+ * Use {@link Console.children} to access all children for batch operations.
95
+ */
96
+ readonly child: (name: string) => Console;
97
+ /** Outputs a stack trace. */
98
+ readonly trace: (...args: ReadonlyArray<unknown>) => void;
99
+ /** Development diagnostics. */
100
+ readonly debug: (...args: ReadonlyArray<unknown>) => void;
101
+ /** General-purpose messages. */
102
+ readonly log: (...args: ReadonlyArray<unknown>) => void;
103
+ /** Operational milestones (startup, shutdown). */
104
+ readonly info: (...args: ReadonlyArray<unknown>) => void;
105
+ /** Recoverable issues that may need attention. */
106
+ readonly warn: (...args: ReadonlyArray<unknown>) => void;
107
+ /** Failures requiring immediate attention. */
108
+ readonly error: (...args: ReadonlyArray<unknown>) => void;
109
+ /** Displays an object with expandable properties. Level: debug. */
110
+ readonly dir: (item: unknown) => void;
111
+ /** Displays tabular data. Level: debug. */
112
+ readonly table: (data: unknown) => void;
113
+ /** Starts a timer with the given label. Level: debug. */
114
+ readonly time: (label: string) => void;
115
+ /** Logs elapsed time for a timer. Level: debug. */
116
+ readonly timeLog: (label: string, ...args: ReadonlyArray<unknown>) => void;
117
+ /** Ends a timer and logs elapsed time. Level: debug. */
118
+ readonly timeEnd: (label: string) => void;
119
+ /** Increments and logs a counter. Level: debug. */
120
+ readonly count: (label?: string) => void;
121
+ /** Resets a counter. Level: debug. */
122
+ readonly countReset: (label?: string) => void;
123
+ /**
124
+ * Writes a pre-built {@link ConsoleEntry} directly to the output, bypassing
125
+ * level filtering. Used to replay entries from another context (e.g., a
126
+ * SharedWorker) where filtering was already applied.
127
+ */
128
+ readonly write: (entry: ConsoleEntry) => void;
68
129
  }
69
- /** Dependency interface for injecting a Console instance. */
70
130
  export interface ConsoleDep {
71
131
  readonly console: Console;
72
132
  }
133
+ /**
134
+ * Log level controlling which messages are output.
135
+ *
136
+ * Setting a level enables all logs at that level and above (ordered by
137
+ * severity):
138
+ *
139
+ * - `"trace"` — Stack traces and detailed execution flow
140
+ * - `"debug"` — Development diagnostics, timers, counters
141
+ * - `"log"` — General-purpose messages
142
+ * - `"info"` — Operational milestones (startup, shutdown)
143
+ * - `"warn"` — Recoverable issues that may need attention
144
+ * - `"error"` — Failures requiring immediate attention
145
+ * - `"silent"` — Disables all logging
146
+ */
147
+ export type ConsoleLevel = "trace" | "debug" | "log" | "info" | "warn" | "error" | "silent";
148
+ /**
149
+ * Structured log entry captured by {@link Console}.
150
+ *
151
+ * Contains all information needed for outputs to route the log: method for
152
+ * routing, path for context, and the original arguments.
153
+ */
154
+ export interface ConsoleEntry {
155
+ /** The console method that was called. */
156
+ readonly method: ConsoleMethod;
157
+ /** Hierarchical path from {@link Console.child} calls (e.g., ["relay", "db"]). */
158
+ readonly path: ReadonlyArray<string>;
159
+ /** Original arguments passed to the console method. */
160
+ readonly args: ReadonlyArray<unknown>;
161
+ }
162
+ /**
163
+ * Console method being called.
164
+ *
165
+ * Used in {@link ConsoleEntry} to identify which console method was invoked.
166
+ * Outputs can route or format differently based on the method.
167
+ */
168
+ export type ConsoleMethod = "trace" | "debug" | "log" | "info" | "warn" | "error" | "dir" | "table" | "time" | "timeLog" | "timeEnd" | "count" | "countReset";
169
+ /**
170
+ * Output destination for {@link Console}.
171
+ *
172
+ * Implement this interface to create custom log destinations (file, network,
173
+ * array for testing, etc.).
174
+ *
175
+ * Use {@link createNativeConsoleOutput} for native console output.
176
+ */
177
+ export interface ConsoleOutput {
178
+ /** Write a log entry to this output. */
179
+ readonly write: (entry: ConsoleEntry, formatter?: ConsoleFormatter) => void;
180
+ }
181
+ /**
182
+ * Transforms a {@link ConsoleEntry} before output.
183
+ *
184
+ * Used by {@link ConsoleConfig.formatter} and {@link ConsoleOutput.write}. Create
185
+ * one with {@link createConsoleFormatter}.
186
+ */
187
+ export type ConsoleFormatter = (entry: ConsoleEntry) => ReadonlyArray<unknown>;
188
+ /** Configuration for {@link createConsole}. */
73
189
  export interface ConsoleConfig {
190
+ /** Name of this console. Defaults to empty string. */
191
+ readonly name?: string;
192
+ /** Initial log level. Defaults to `"log"`. */
193
+ readonly level?: ConsoleLevel;
74
194
  /**
75
- * Enable or disable console logging (default: false). When true, logs are
76
- * output to the {@link Console}; when false, logging is disabled for all
77
- * methods except `error`, which always outputs to ensure critical issues are
78
- * not missed.
195
+ * Output destination for log entries. Defaults to
196
+ * {@link createNativeConsoleOutput}.
79
197
  */
80
- readonly enableLogging?: boolean;
198
+ readonly output?: ConsoleOutput;
199
+ /** Path prefix for this console. Defaults to `[]`. */
200
+ readonly path?: ReadonlyArray<string>;
201
+ /**
202
+ * Transforms entry args before writing (e.g., adds timestamps, path
203
+ * prefixes).
204
+ *
205
+ * Receives the entry and returns modified args. Use
206
+ * {@link createConsoleFormatter} for common formatting options.
207
+ */
208
+ readonly formatter?: ConsoleFormatter;
81
209
  }
82
- /** Creates a {@link Console} for logging with configurable output. */
83
- export declare const createConsole: (config?: ConsoleConfig) => Console;
84
- export interface ConsoleWithTimeConfig extends ConsoleConfig {
210
+ /** Configuration for {@link createConsoleFormatter}. */
211
+ export interface ConsoleFormatterConfig {
85
212
  /**
86
- * Type of timestamp to prepend to log messages.
213
+ * Timestamp format to prepend to log messages.
87
214
  *
88
- * - 'absolute': Shows actual time (e.g., "14:32:15.234")
89
- * - 'relative': Shows time since console creation (e.g., "+1.234s")
215
+ * - `"relative"` elapsed since start: `+0.000s`, `+1.500s`, `+1m30.000s`
216
+ * - `"absolute"` local clock time: `14:32:15.234`
217
+ * - `"iso"` — ISO 8601 UTC: `2026-01-28T14:30:00.123Z`
218
+ * - `"none"` — no timestamp (default)
90
219
  */
91
- readonly timestampType: "absolute" | "relative";
220
+ readonly timestampFormat?: ConsoleEntryTimestampFormat;
221
+ /**
222
+ * Start time for relative timestamps. Defaults to first entry timestamp.
223
+ *
224
+ * Pass a {@link Millis} value to use a custom start time, useful when multiple
225
+ * consoles should share the same relative timeline.
226
+ */
227
+ readonly startTime?: Millis;
228
+ }
229
+ /** Timestamp format for {@link ConsoleFormatterConfig}. */
230
+ export type ConsoleEntryTimestampFormat = "relative" | "absolute" | "iso" | "none";
231
+ /**
232
+ * A {@link ConsoleOutput} that stores the latest entry in a
233
+ * {@link ReadonlyStore}.
234
+ *
235
+ * Subscribe to {@link ConsoleStoreOutput.entry} to observe all log entries.
236
+ *
237
+ * ### Example
238
+ *
239
+ * ```ts
240
+ * const storeOutput = createConsoleStoreOutput();
241
+ * const console = createConsole({ output: storeOutput });
242
+ *
243
+ * storeOutput.entry.subscribe(() => {
244
+ * const entry = storeOutput.entry.get();
245
+ * if (entry) forwardToClient(entry);
246
+ * });
247
+ * ```
248
+ */
249
+ export interface ConsoleStoreOutput extends ConsoleOutput {
250
+ /** Latest entry written to this output. */
251
+ readonly entry: ReadonlyStore<ConsoleEntry | null>;
252
+ }
253
+ /**
254
+ * Dependency providing the latest {@link ConsoleEntry} from a
255
+ * {@link ConsoleStoreOutput}.
256
+ */
257
+ export interface ConsoleStoreOutputEntryDep {
258
+ readonly consoleStoreOutputEntry: ReadonlyStore<ConsoleEntry | null>;
259
+ }
260
+ /**
261
+ * A test console that captures all output for assertions.
262
+ *
263
+ * Use as a drop-in replacement for {@link Console} in tests.
264
+ */
265
+ export interface TestConsole extends Console {
266
+ /** Gets all captured entries and clears the internal buffer. */
267
+ readonly getEntriesSnapshot: () => ReadonlyArray<ConsoleEntry>;
268
+ /** Clears all captured entries. */
269
+ readonly clearEntries: () => void;
92
270
  }
93
- /** Creates a console instance with timestamp prefixes. */
94
- export declare const createConsoleWithTime: (config?: ConsoleWithTimeConfig) => Console;
271
+ export interface TestConsoleDep {
272
+ readonly console: TestConsole;
273
+ }
274
+ /** Creates a {@link Console}. */
275
+ export declare const createConsole: ({ name, level, output, path, formatter, }?: ConsoleConfig) => Console;
276
+ /**
277
+ * Creates a {@link ConsoleOutput} that writes to `globalThis.console`.
278
+ *
279
+ * Pure transport - just calls the native console method with the entry args.
280
+ * Use {@link createConsoleFormatter} with {@link ConsoleConfig.formatter} for
281
+ * timestamps and path prefixes.
282
+ *
283
+ * ### Example
284
+ *
285
+ * ```ts
286
+ * const output = createNativeConsoleOutput();
287
+ * ```
288
+ */
289
+ export declare const createNativeConsoleOutput: () => ConsoleOutput;
290
+ /**
291
+ * Creates a {@link ConsoleFormatter} for {@link ConsoleConfig.formatter}.
292
+ *
293
+ * Prepends timestamps and path prefixes to entry args.
294
+ *
295
+ * ### Example
296
+ *
297
+ * ```ts
298
+ * const root = createConsole({
299
+ * formatter: createConsoleFormatter()({
300
+ * timestampFormat: "relative",
301
+ * }),
302
+ * });
303
+ *
304
+ * // Relative — elapsed since start
305
+ * const relay = root.child("relay");
306
+ * relay.log("connected"); // +0.000s [relay] connected
307
+ * relay.log("synced"); // +1.500s [relay] synced
308
+ *
309
+ * // Nested children
310
+ * const db = relay.child("db");
311
+ * db.log("opened"); // +1.500s [relay] [db] opened
312
+ *
313
+ * // Absolute — local clock time (HH:MM:SS.mmm)
314
+ * // relay.log("connected"); // 15:30:15.123 [relay] connected
315
+ * ```
316
+ */
317
+ export declare const createConsoleFormatter: ({ time }?: Partial<TimeDep>) => (config?: ConsoleFormatterConfig) => ConsoleFormatter;
318
+ /** Creates a {@link ConsoleStoreOutput}. */
319
+ export declare const createConsoleStoreOutput: () => ConsoleStoreOutput;
320
+ /**
321
+ * Creates a {@link ConsoleOutput} that captures entries to an array.
322
+ *
323
+ * Useful for testing. Pass your own array to inspect captured entries.
324
+ *
325
+ * ### Example
326
+ *
327
+ * ```ts
328
+ * const entries: Array<ConsoleEntry> = [];
329
+ * const output = createConsoleArrayOutput(entries);
330
+ *
331
+ * // After logging...
332
+ * expect(entries).toMatchInlineSnapshot();
333
+ * ```
334
+ */
335
+ export declare const createConsoleArrayOutput: (entries: Array<ConsoleEntry>) => ConsoleOutput;
336
+ /**
337
+ * Creates a {@link ConsoleOutput} that fans out to multiple outputs.
338
+ *
339
+ * Each entry is written to all outputs in order. Useful for combining a native
340
+ * console output with a store output for forwarding.
341
+ *
342
+ * ### Example
343
+ *
344
+ * ```ts
345
+ * const storeOutput = createConsoleStoreOutput();
346
+ * const console = createConsole({
347
+ * output: createMultiOutput([createNativeConsoleOutput(), storeOutput]),
348
+ * });
349
+ * ```
350
+ */
351
+ export declare const createMultiOutput: (outputs: ReadonlyArray<ConsoleOutput>) => ConsoleOutput;
352
+ /**
353
+ * Creates a {@link TestConsole} that captures all output for testing.
354
+ *
355
+ * Unlike {@link createConsole}, this doesn't require dependencies and uses a
356
+ * simple incrementing counter for timestamps (starting at 0).
357
+ *
358
+ * ### Example
359
+ *
360
+ * ```ts
361
+ * test("logging", () => {
362
+ * const console = testCreateConsole();
363
+ * console.info("Hello");
364
+ *
365
+ * expect(console.getEntriesSnapshot()).toMatchInlineSnapshot(`
366
+ * [
367
+ * {
368
+ * "method": "info",
369
+ * "path": [],
370
+ * "args": ["Hello"]
371
+ * }
372
+ * ]
373
+ * `);
374
+ * });
375
+ *
376
+ * test("level filtering", () => {
377
+ * const console = testCreateConsole({ level: "warn" });
378
+ * console.debug("ignored");
379
+ * console.warn("logged");
380
+ * expect(console.getEntriesSnapshot()).toHaveLength(1);
381
+ * });
382
+ * ```
383
+ */
384
+ export declare const testCreateConsole: ({ level, }?: {
385
+ level?: ConsoleLevel;
386
+ }) => TestConsole;
95
387
  //# sourceMappingURL=Console.d.ts.map