@evolu/common 8.10.0 → 8.12.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 (152) hide show
  1. package/dist/src/Bytes.d.ts +39 -2
  2. package/dist/src/Bytes.d.ts.map +1 -1
  3. package/dist/src/Bytes.js +50 -2
  4. package/dist/src/Config.d.ts +22 -22
  5. package/dist/src/Config.d.ts.map +1 -1
  6. package/dist/src/Console.d.ts +62 -7
  7. package/dist/src/Console.d.ts.map +1 -1
  8. package/dist/src/Console.js +20 -4
  9. package/dist/src/Crypto.d.ts +76 -4
  10. package/dist/src/Crypto.d.ts.map +1 -1
  11. package/dist/src/Crypto.js +55 -4
  12. package/dist/src/Error.d.ts +45 -0
  13. package/dist/src/Error.d.ts.map +1 -1
  14. package/dist/src/Error.js +69 -0
  15. package/dist/src/Fs.d.ts +92 -18
  16. package/dist/src/Fs.d.ts.map +1 -1
  17. package/dist/src/Fs.js +2 -0
  18. package/dist/src/Identicon.d.ts +2 -2
  19. package/dist/src/Identicon.js +2 -2
  20. package/dist/src/LeakDetector.d.ts +22 -3
  21. package/dist/src/LeakDetector.d.ts.map +1 -1
  22. package/dist/src/LeakDetector.js +12 -2
  23. package/dist/src/LockManager.d.ts +8 -0
  24. package/dist/src/LockManager.d.ts.map +1 -1
  25. package/dist/src/LockManager.js +6 -0
  26. package/dist/src/Object.d.ts.map +1 -1
  27. package/dist/src/Object.js +5 -0
  28. package/dist/src/Platform.d.ts +47 -7
  29. package/dist/src/Platform.d.ts.map +1 -1
  30. package/dist/src/Platform.js +24 -5
  31. package/dist/src/Random.d.ts +25 -2
  32. package/dist/src/Random.d.ts.map +1 -1
  33. package/dist/src/Random.js +14 -2
  34. package/dist/src/Resource.d.ts +156 -1
  35. package/dist/src/Resource.d.ts.map +1 -1
  36. package/dist/src/Resource.js +201 -72
  37. package/dist/src/Schedule.d.ts +11 -10
  38. package/dist/src/Schedule.d.ts.map +1 -1
  39. package/dist/src/Schedule.js +1 -1
  40. package/dist/src/Sqlite.d.ts +132 -16
  41. package/dist/src/Sqlite.d.ts.map +1 -1
  42. package/dist/src/Sqlite.js +63 -9
  43. package/dist/src/Task.d.ts +15 -4
  44. package/dist/src/Task.d.ts.map +1 -1
  45. package/dist/src/Task.js +41 -15
  46. package/dist/src/Test.d.ts +9 -0
  47. package/dist/src/Test.d.ts.map +1 -1
  48. package/dist/src/Test.js +4 -0
  49. package/dist/src/Time.d.ts +106 -9
  50. package/dist/src/Time.d.ts.map +1 -1
  51. package/dist/src/Time.js +55 -4
  52. package/dist/src/Type.d.ts +1455 -1310
  53. package/dist/src/Type.d.ts.map +1 -1
  54. package/dist/src/Type.js +1274 -517
  55. package/dist/src/WebSocket.d.ts +164 -13
  56. package/dist/src/WebSocket.d.ts.map +1 -1
  57. package/dist/src/WebSocket.js +133 -24
  58. package/dist/src/Worker.d.ts +90 -8
  59. package/dist/src/Worker.d.ts.map +1 -1
  60. package/dist/src/Worker.js +28 -2
  61. package/dist/src/index.d.ts +6 -7
  62. package/dist/src/index.d.ts.map +1 -1
  63. package/dist/src/index.js +2 -3
  64. package/dist/src/local-first/Db.d.ts +52 -3
  65. package/dist/src/local-first/Db.d.ts.map +1 -1
  66. package/dist/src/local-first/Db.js +412 -137
  67. package/dist/src/local-first/Evolu.d.ts +412 -213
  68. package/dist/src/local-first/Evolu.d.ts.map +1 -1
  69. package/dist/src/local-first/Evolu.js +181 -18
  70. package/dist/src/local-first/Owner.d.ts +13 -30
  71. package/dist/src/local-first/Owner.d.ts.map +1 -1
  72. package/dist/src/local-first/Owner.js +13 -30
  73. package/dist/src/local-first/Protocol.d.ts +106 -19
  74. package/dist/src/local-first/Protocol.d.ts.map +1 -1
  75. package/dist/src/local-first/Protocol.js +162 -60
  76. package/dist/src/local-first/Query.d.ts +8 -15
  77. package/dist/src/local-first/Query.d.ts.map +1 -1
  78. package/dist/src/local-first/Relay.d.ts.map +1 -1
  79. package/dist/src/local-first/Relay.js +4 -2
  80. package/dist/src/local-first/Schema.d.ts +346 -23
  81. package/dist/src/local-first/Schema.d.ts.map +1 -1
  82. package/dist/src/local-first/Schema.js +214 -17
  83. package/dist/src/local-first/Shared.d.ts +537 -22
  84. package/dist/src/local-first/Shared.d.ts.map +1 -1
  85. package/dist/src/local-first/Shared.js +1437 -234
  86. package/dist/src/local-first/Storage.d.ts +195 -17
  87. package/dist/src/local-first/Storage.d.ts.map +1 -1
  88. package/dist/src/local-first/Storage.js +85 -22
  89. package/dist/src/local-first/Timestamp.d.ts +392 -41
  90. package/dist/src/local-first/Timestamp.d.ts.map +1 -1
  91. package/dist/src/local-first/Timestamp.js +403 -81
  92. package/dist/src/local-first/index.d.ts +0 -1
  93. package/dist/src/local-first/index.d.ts.map +1 -1
  94. package/dist/src/local-first/index.js +0 -1
  95. package/package.json +1 -1
  96. package/src/Assert.test.ts +2 -5
  97. package/src/Bytes.test.ts +27 -0
  98. package/src/Bytes.ts +58 -2
  99. package/src/Config.test.ts +2 -6
  100. package/src/Config.ts +133 -133
  101. package/src/Console.ts +62 -7
  102. package/src/Crypto.ts +76 -4
  103. package/src/Eq.test.ts +2 -3
  104. package/src/Error.test.ts +76 -3
  105. package/src/Error.ts +71 -0
  106. package/src/Fs.ts +92 -18
  107. package/src/Identicon.ts +2 -2
  108. package/src/LeakDetector.ts +22 -3
  109. package/src/LockManager.ts +8 -0
  110. package/src/Object.test.ts +27 -12
  111. package/src/Object.ts +5 -0
  112. package/src/Platform.ts +50 -8
  113. package/src/Random.ts +25 -2
  114. package/src/Resource.test.ts +837 -0
  115. package/src/Resource.ts +235 -15
  116. package/src/Schedule.test.ts +50 -12
  117. package/src/Schedule.ts +24 -14
  118. package/src/Sqlite.ts +137 -17
  119. package/src/Task.test.ts +189 -8
  120. package/src/Task.ts +56 -17
  121. package/src/Test.ts +9 -0
  122. package/src/Time.ts +106 -9
  123. package/src/Type.test.ts +946 -1028
  124. package/src/Type.ts +4195 -3136
  125. package/src/Types.test.ts +4 -14
  126. package/src/WebSocket.ts +313 -40
  127. package/src/Worker.ts +90 -8
  128. package/src/index.ts +20 -6
  129. package/src/local-first/Db.ts +644 -339
  130. package/src/local-first/Evolu.test.ts +994 -22
  131. package/src/local-first/Evolu.ts +625 -232
  132. package/src/local-first/Owner.ts +13 -30
  133. package/src/local-first/Protocol.test.ts +634 -10
  134. package/src/local-first/Protocol.ts +255 -109
  135. package/src/local-first/Query.ts +8 -15
  136. package/src/local-first/Relay.ts +4 -2
  137. package/src/local-first/Schema.test.ts +143 -0
  138. package/src/local-first/Schema.ts +376 -26
  139. package/src/local-first/Shared.test.ts +7731 -559
  140. package/src/local-first/Shared.ts +2036 -267
  141. package/src/local-first/Storage.ts +224 -36
  142. package/src/local-first/Timestamp.test.ts +344 -70
  143. package/src/local-first/Timestamp.ts +434 -118
  144. package/src/local-first/index.ts +0 -1
  145. package/dist/src/local-first/Error.d.ts +0 -12
  146. package/dist/src/local-first/Error.d.ts.map +0 -1
  147. package/dist/src/local-first/Error.js +0 -6
  148. package/dist/src/local-first/LocalAuth.d.ts +0 -150
  149. package/dist/src/local-first/LocalAuth.d.ts.map +0 -1
  150. package/dist/src/local-first/LocalAuth.js +0 -179
  151. package/src/local-first/Error.ts +0 -17
  152. package/src/local-first/LocalAuth.ts +0 -457
package/dist/src/Time.js CHANGED
@@ -27,6 +27,8 @@ import { brand, createTypeWithError, Digit, Digit1To23, Digit1To51, Digit1To59,
27
27
  *
28
28
  * Throws if the system clock returns an out-of-range value. This is intentional
29
29
  * — there's no reasonable fallback for a misconfigured clock.
30
+ *
31
+ * @group Core
30
32
  */
31
33
  export const createTime = () => {
32
34
  const timeoutOwner = Symbol("Time");
@@ -106,6 +108,8 @@ const clearTimeoutId = (owner, id) => {
106
108
  * wall-clock or performance `now()` call. `"microtask"` increments after the
107
109
  * current turn, while `"sync"` increments immediately after each read. Omit it
108
110
  * to keep time fixed until `advance()` is called.
111
+ *
112
+ * @group Testing
109
113
  */
110
114
  export const testCreateTime = (options) => {
111
115
  const startAt = options?.startAt ?? minMillis;
@@ -200,18 +204,34 @@ const maxMillisWithInfinity = 281474976710655;
200
204
  *
201
205
  * If a system clock exceeds this range, operations will throw. This is
202
206
  * intentional — there's no reasonable fallback for a misconfigured clock.
207
+ *
208
+ * @group Millis
203
209
  */
204
210
  export const Millis = /*#__PURE__*/ brand("Millis",
205
211
  /*#__PURE__*/ lessThan(maxMillisWithInfinity)(NonNegativeInt));
206
- /** Positive {@link Millis} value. */
212
+ /**
213
+ * Positive {@link Millis} value.
214
+ *
215
+ * @group Millis
216
+ */
207
217
  export const PositiveMillis = /*#__PURE__*/ positive(Millis);
208
- /** Minimum {@link Millis} value. */
218
+ /**
219
+ * Minimum {@link Millis} value.
220
+ *
221
+ * @group Millis
222
+ */
209
223
  export const minMillis = 0;
210
- /** Maximum {@link Millis} value. */
224
+ /**
225
+ * Maximum {@link Millis} value.
226
+ *
227
+ * @group Millis
228
+ */
211
229
  export const maxMillis = (maxMillisWithInfinity - 1);
212
230
  /**
213
231
  * Converts a number to {@link Millis}, rounding to the nearest millisecond and
214
232
  * saturating overflow at {@link maxMillis}.
233
+ *
234
+ * @group Millis
215
235
  */
216
236
  export const saturateMillis = (value) => Millis.orNull(Math.max(0, Math.round(value))) ?? maxMillis;
217
237
  /**
@@ -219,12 +239,16 @@ export const saturateMillis = (value) => Millis.orNull(Math.max(0, Math.round(va
219
239
  *
220
240
  * This is a safe cast because {@link Millis} guarantees a valid timestamp range
221
241
  * that always produces a valid ISO string.
242
+ *
243
+ * @group Millis
222
244
  */
223
245
  export const millisToDateIso = (value) => new Date(value).toISOString();
224
246
  /**
225
247
  * Returns the elapsed fractional milliseconds between two performance times.
226
248
  *
227
249
  * Throws if `end` precedes `start`.
250
+ *
251
+ * @group Performance
228
252
  */
229
253
  export const performanceDurationBetween = (start, end) => {
230
254
  assert(end >= start, "Performance end time must not precede start time");
@@ -232,7 +256,11 @@ export const performanceDurationBetween = (start, end) => {
232
256
  };
233
257
  // Keep these annotations concrete. Generic unit wrappers add thousands of
234
258
  // compiler instantiations to pnpm bench:type.
235
- /** Milliseconds duration: `"1ms"` to `"999ms"`. See {@link DurationLiteral}. */
259
+ /**
260
+ * Milliseconds duration: `"1ms"` to `"999ms"`. See {@link DurationLiteral}.
261
+ *
262
+ * @group Durations
263
+ */
236
264
  export const DurationLiteralMilliseconds = /*#__PURE__*/ union(
237
265
  /*#__PURE__*/ templateLiteral(Digit1To9, "ms"),
238
266
  /*#__PURE__*/ templateLiteral(Digit1To9, Digit, "ms"),
@@ -240,6 +268,8 @@ export const DurationLiteralMilliseconds = /*#__PURE__*/ union(
240
268
  /**
241
269
  * Seconds duration: `"1s"` to `"59s"` or `"1.1s"` to `"59.9s"`. See
242
270
  * {@link DurationLiteral}.
271
+ *
272
+ * @group Durations
243
273
  */
244
274
  export const DurationLiteralSeconds = /*#__PURE__*/ union(
245
275
  /*#__PURE__*/ templateLiteral(Digit1To59, "s"),
@@ -247,6 +277,8 @@ export const DurationLiteralSeconds = /*#__PURE__*/ union(
247
277
  /**
248
278
  * Minutes duration: `"1m"` to `"59m"` or `"1.1m"` to `"59.9m"`. See
249
279
  * {@link DurationLiteral}.
280
+ *
281
+ * @group Durations
250
282
  */
251
283
  export const DurationLiteralMinutes = /*#__PURE__*/ union(
252
284
  /*#__PURE__*/ templateLiteral(Digit1To59, "m"),
@@ -254,6 +286,8 @@ export const DurationLiteralMinutes = /*#__PURE__*/ union(
254
286
  /**
255
287
  * Hours duration: `"1h"` to `"23h"` or `"1.1h"` to `"23.9h"`. See
256
288
  * {@link DurationLiteral}.
289
+ *
290
+ * @group Durations
257
291
  */
258
292
  export const DurationLiteralHours = /*#__PURE__*/ union(
259
293
  /*#__PURE__*/ templateLiteral(Digit1To23, "h"),
@@ -261,6 +295,8 @@ export const DurationLiteralHours = /*#__PURE__*/ union(
261
295
  /**
262
296
  * Days duration: `"1d"` to `"6d"` or `"1.1d"` to `"6.9d"`. See
263
297
  * {@link DurationLiteral}.
298
+ *
299
+ * @group Durations
264
300
  */
265
301
  export const DurationLiteralDays = /*#__PURE__*/ union(
266
302
  /*#__PURE__*/ templateLiteral(Digit1To6, "d"),
@@ -268,6 +304,8 @@ export const DurationLiteralDays = /*#__PURE__*/ union(
268
304
  /**
269
305
  * Weeks duration: `"1w"` to `"51w"` or `"1.1w"` to `"51.9w"`. See
270
306
  * {@link DurationLiteral}.
307
+ *
308
+ * @group Durations
271
309
  */
272
310
  export const DurationLiteralWeeks = /*#__PURE__*/ union(
273
311
  /*#__PURE__*/ templateLiteral(Digit1To51, "w"),
@@ -275,6 +313,8 @@ export const DurationLiteralWeeks = /*#__PURE__*/ union(
275
313
  /**
276
314
  * Years duration: `"1y"` to `"99y"` or `"1.1y"` to `"99.9y"`. See
277
315
  * {@link DurationLiteral}.
316
+ *
317
+ * @group Durations
278
318
  */
279
319
  export const DurationLiteralYears = /*#__PURE__*/ union(
280
320
  /*#__PURE__*/ templateLiteral(Digit1To99, "y"),
@@ -328,6 +368,8 @@ const durationLiteralSyntax = /*#__PURE__*/ union(DurationLiteralMilliseconds, D
328
368
  * assertOk(DurationLiteral.fromUnknown(literal), "1.5s");
329
369
  * assertFalse(DurationLiteral.is("1000ms"));
330
370
  * ```
371
+ *
372
+ * @group Durations
331
373
  */
332
374
  export const DurationLiteral = /*#__PURE__*/ createTypeWithError("DurationLiteral", durationLiteralSyntax, (cause, value) => ({
333
375
  type: "DurationLiteral",
@@ -357,12 +399,16 @@ const durationUnits = {
357
399
  * Frame budget at 60fps (16ms).
358
400
  *
359
401
  * Work exceeding this blocks a frame, causing visible jank in animations.
402
+ *
403
+ * @group Millis
360
404
  */
361
405
  export const ms60fps = 16;
362
406
  /**
363
407
  * Frame budget at 120fps (8ms).
364
408
  *
365
409
  * For high refresh rate displays. Work exceeding this blocks a frame.
410
+ *
411
+ * @group Millis
366
412
  */
367
413
  export const ms120fps = 8;
368
414
  /**
@@ -371,6 +417,7 @@ export const ms120fps = 8;
371
417
  * Tasks exceeding this are "long tasks" per web standards. Use with
372
418
  * {@link yieldNow} to yield periodically and keep UI responsive.
373
419
  *
420
+ * @group Millis
374
421
  * @see https://web.dev/articles/optimize-long-tasks
375
422
  */
376
423
  export const msLongTask = 50;
@@ -402,6 +449,8 @@ export const msLongTask = 50;
402
449
  * "1d1h1m1.000s",
403
450
  * );
404
451
  * ```
452
+ *
453
+ * @group Millis
405
454
  */
406
455
  export const formatMillisAsDuration = (millis) => {
407
456
  const seconds = ((millis % durationUnits.m) / durationUnits.s).toFixed(3);
@@ -441,6 +490,8 @@ export const formatMillisAsDuration = (millis) => {
441
490
  * "14:32:15.234",
442
491
  * );
443
492
  * ```
493
+ *
494
+ * @group Millis
444
495
  */
445
496
  export const formatMillisAsClockTime = (millis) => {
446
497
  const date = new Date(millis);