@evolu/common 8.10.0 → 8.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/dist/src/Config.d.ts +22 -22
  2. package/dist/src/Config.d.ts.map +1 -1
  3. package/dist/src/Console.d.ts +62 -7
  4. package/dist/src/Console.d.ts.map +1 -1
  5. package/dist/src/Console.js +20 -4
  6. package/dist/src/Crypto.d.ts +76 -4
  7. package/dist/src/Crypto.d.ts.map +1 -1
  8. package/dist/src/Crypto.js +55 -4
  9. package/dist/src/Error.d.ts +45 -0
  10. package/dist/src/Error.d.ts.map +1 -1
  11. package/dist/src/Error.js +69 -0
  12. package/dist/src/Fs.d.ts +92 -18
  13. package/dist/src/Fs.d.ts.map +1 -1
  14. package/dist/src/Fs.js +2 -0
  15. package/dist/src/Identicon.d.ts +2 -2
  16. package/dist/src/Identicon.js +2 -2
  17. package/dist/src/LeakDetector.d.ts +22 -3
  18. package/dist/src/LeakDetector.d.ts.map +1 -1
  19. package/dist/src/LeakDetector.js +12 -2
  20. package/dist/src/LockManager.d.ts +8 -0
  21. package/dist/src/LockManager.d.ts.map +1 -1
  22. package/dist/src/LockManager.js +6 -0
  23. package/dist/src/Object.d.ts.map +1 -1
  24. package/dist/src/Object.js +5 -0
  25. package/dist/src/Platform.d.ts +47 -7
  26. package/dist/src/Platform.d.ts.map +1 -1
  27. package/dist/src/Platform.js +24 -5
  28. package/dist/src/Random.d.ts +25 -2
  29. package/dist/src/Random.d.ts.map +1 -1
  30. package/dist/src/Random.js +14 -2
  31. package/dist/src/Resource.d.ts +156 -1
  32. package/dist/src/Resource.d.ts.map +1 -1
  33. package/dist/src/Resource.js +201 -72
  34. package/dist/src/Schedule.d.ts +11 -10
  35. package/dist/src/Schedule.d.ts.map +1 -1
  36. package/dist/src/Schedule.js +1 -1
  37. package/dist/src/Sqlite.d.ts +132 -16
  38. package/dist/src/Sqlite.d.ts.map +1 -1
  39. package/dist/src/Sqlite.js +63 -9
  40. package/dist/src/Task.d.ts +15 -4
  41. package/dist/src/Task.d.ts.map +1 -1
  42. package/dist/src/Task.js +41 -15
  43. package/dist/src/Test.d.ts +9 -0
  44. package/dist/src/Test.d.ts.map +1 -1
  45. package/dist/src/Test.js +4 -0
  46. package/dist/src/Time.d.ts +106 -9
  47. package/dist/src/Time.d.ts.map +1 -1
  48. package/dist/src/Time.js +55 -4
  49. package/dist/src/Type.d.ts +1455 -1310
  50. package/dist/src/Type.d.ts.map +1 -1
  51. package/dist/src/Type.js +1274 -517
  52. package/dist/src/WebSocket.d.ts +164 -13
  53. package/dist/src/WebSocket.d.ts.map +1 -1
  54. package/dist/src/WebSocket.js +133 -24
  55. package/dist/src/Worker.d.ts +90 -8
  56. package/dist/src/Worker.d.ts.map +1 -1
  57. package/dist/src/Worker.js +28 -2
  58. package/dist/src/index.d.ts +6 -7
  59. package/dist/src/index.d.ts.map +1 -1
  60. package/dist/src/index.js +2 -3
  61. package/dist/src/local-first/Db.d.ts +52 -3
  62. package/dist/src/local-first/Db.d.ts.map +1 -1
  63. package/dist/src/local-first/Db.js +412 -137
  64. package/dist/src/local-first/Evolu.d.ts +336 -211
  65. package/dist/src/local-first/Evolu.d.ts.map +1 -1
  66. package/dist/src/local-first/Evolu.js +102 -15
  67. package/dist/src/local-first/Owner.d.ts +13 -30
  68. package/dist/src/local-first/Owner.d.ts.map +1 -1
  69. package/dist/src/local-first/Owner.js +13 -30
  70. package/dist/src/local-first/Protocol.d.ts +94 -16
  71. package/dist/src/local-first/Protocol.d.ts.map +1 -1
  72. package/dist/src/local-first/Protocol.js +118 -38
  73. package/dist/src/local-first/Query.d.ts +8 -15
  74. package/dist/src/local-first/Query.d.ts.map +1 -1
  75. package/dist/src/local-first/Schema.d.ts +335 -21
  76. package/dist/src/local-first/Schema.d.ts.map +1 -1
  77. package/dist/src/local-first/Schema.js +214 -17
  78. package/dist/src/local-first/Shared.d.ts +537 -22
  79. package/dist/src/local-first/Shared.d.ts.map +1 -1
  80. package/dist/src/local-first/Shared.js +1437 -234
  81. package/dist/src/local-first/Storage.d.ts +192 -14
  82. package/dist/src/local-first/Storage.d.ts.map +1 -1
  83. package/dist/src/local-first/Storage.js +81 -20
  84. package/dist/src/local-first/Timestamp.d.ts +392 -41
  85. package/dist/src/local-first/Timestamp.d.ts.map +1 -1
  86. package/dist/src/local-first/Timestamp.js +403 -81
  87. package/dist/src/local-first/index.d.ts +0 -1
  88. package/dist/src/local-first/index.d.ts.map +1 -1
  89. package/dist/src/local-first/index.js +0 -1
  90. package/package.json +1 -1
  91. package/src/Assert.test.ts +2 -5
  92. package/src/Config.test.ts +2 -6
  93. package/src/Config.ts +133 -133
  94. package/src/Console.ts +62 -7
  95. package/src/Crypto.ts +76 -4
  96. package/src/Eq.test.ts +2 -3
  97. package/src/Error.test.ts +76 -3
  98. package/src/Error.ts +71 -0
  99. package/src/Fs.ts +92 -18
  100. package/src/Identicon.ts +2 -2
  101. package/src/LeakDetector.ts +22 -3
  102. package/src/LockManager.ts +8 -0
  103. package/src/Object.test.ts +27 -12
  104. package/src/Object.ts +5 -0
  105. package/src/Platform.ts +50 -8
  106. package/src/Random.ts +25 -2
  107. package/src/Resource.test.ts +837 -0
  108. package/src/Resource.ts +235 -15
  109. package/src/Schedule.test.ts +50 -12
  110. package/src/Schedule.ts +24 -14
  111. package/src/Sqlite.ts +137 -17
  112. package/src/Task.test.ts +189 -8
  113. package/src/Task.ts +56 -17
  114. package/src/Test.ts +9 -0
  115. package/src/Time.ts +106 -9
  116. package/src/Type.test.ts +946 -1028
  117. package/src/Type.ts +4195 -3136
  118. package/src/Types.test.ts +4 -14
  119. package/src/WebSocket.ts +313 -40
  120. package/src/Worker.ts +90 -8
  121. package/src/index.ts +15 -6
  122. package/src/local-first/Db.ts +644 -339
  123. package/src/local-first/Evolu.test.ts +686 -21
  124. package/src/local-first/Evolu.ts +450 -228
  125. package/src/local-first/Owner.ts +13 -30
  126. package/src/local-first/Protocol.test.ts +617 -10
  127. package/src/local-first/Protocol.ts +196 -72
  128. package/src/local-first/Query.ts +8 -15
  129. package/src/local-first/Schema.test.ts +143 -0
  130. package/src/local-first/Schema.ts +363 -24
  131. package/src/local-first/Shared.test.ts +7731 -559
  132. package/src/local-first/Shared.ts +2036 -267
  133. package/src/local-first/Storage.ts +218 -32
  134. package/src/local-first/Timestamp.test.ts +344 -70
  135. package/src/local-first/Timestamp.ts +434 -118
  136. package/src/local-first/index.ts +0 -1
  137. package/dist/src/local-first/Error.d.ts +0 -12
  138. package/dist/src/local-first/Error.d.ts.map +0 -1
  139. package/dist/src/local-first/Error.js +0 -6
  140. package/dist/src/local-first/LocalAuth.d.ts +0 -150
  141. package/dist/src/local-first/LocalAuth.d.ts.map +0 -1
  142. package/dist/src/local-first/LocalAuth.js +0 -179
  143. package/src/local-first/Error.ts +0 -17
  144. package/src/local-first/LocalAuth.ts +0 -457
package/src/Worker.ts CHANGED
@@ -12,6 +12,7 @@ import { disposable } from "./Function.ts";
12
12
  /**
13
13
  * Typed, disposable Worker.
14
14
  *
15
+ * @group Core
15
16
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Worker
16
17
  */
17
18
  export interface Worker<Input, Output = never> extends MessagePort<
@@ -25,6 +26,7 @@ export interface Worker<Input, Output = never> extends MessagePort<
25
26
  * A shared worker is shared across multiple clients (tabs, windows, iframes)
26
27
  * and provides a port for bidirectional communication with each client.
27
28
  *
29
+ * @group Core
28
30
  * @see https://developer.mozilla.org/en-US/docs/Web/API/SharedWorker
29
31
  */
30
32
  export interface SharedWorker<Input, Output = never> extends Disposable {
@@ -41,6 +43,7 @@ export interface SharedWorker<Input, Output = never> extends Disposable {
41
43
  * end periodically sends "alive" messages and stale ports are pruned after a
42
44
  * timeout.
43
45
  *
46
+ * @group Core
44
47
  * @see https://developer.mozilla.org/en-US/docs/Web/API/MessagePort
45
48
  */
46
49
  export interface MessagePort<Input, Output = never> extends Disposable {
@@ -92,6 +95,8 @@ export interface MessagePort<Input, Output = never> extends Disposable {
92
95
  * Intentionally scoped to types Evolu uses. The web platform defines additional
93
96
  * transferable types (`ImageBitmap`, `OffscreenCanvas`, `ReadableStream`, etc.)
94
97
  * that can be added here if needed.
98
+ *
99
+ * @group Core
95
100
  */
96
101
  export type Transferable = NativeMessagePort<any, any> | ArrayBuffer;
97
102
 
@@ -101,6 +106,8 @@ export type Transferable = NativeMessagePort<any, any> | ArrayBuffer;
101
106
  * Exists because `postMessage` transfer requires the native object itself, not
102
107
  * a wrapper. Ensures type-safe wiring between {@link MessagePort.native} and
103
108
  * {@link CreateMessagePort} without exposing platform details.
109
+ *
110
+ * @group Core
104
111
  */
105
112
  export type NativeMessagePort<
106
113
  Input = unknown,
@@ -113,16 +120,29 @@ export type NativeMessagePort<
113
120
  declare const nativeMessagePortInput: unique symbol;
114
121
  declare const nativeMessagePortOutput: unique symbol;
115
122
 
116
- /** Factory function to create a {@link MessagePort} from a native port. */
123
+ /**
124
+ * Factory function to create a {@link MessagePort} from a native port.
125
+ *
126
+ * @group Construction
127
+ */
117
128
  export type CreateMessagePort = <Input, Output = never>(
118
129
  nativePort: NativeMessagePort<Input, Output>,
119
130
  ) => MessagePort<Input, Output>;
120
131
 
132
+ /**
133
+ * Dependency wrapper for {@link CreateMessagePort}.
134
+ *
135
+ * @group Construction
136
+ */
121
137
  export interface CreateMessagePortDep {
122
138
  readonly createMessagePort: CreateMessagePort;
123
139
  }
124
140
 
125
- /** Common dependencies for worker entry points. */
141
+ /**
142
+ * Common dependencies for worker entry points.
143
+ *
144
+ * @group Core
145
+ */
126
146
  export type WorkerDeps = ConsoleDep &
127
147
  ConsoleStoreOutputEntryDep &
128
148
  CreateMessagePortDep;
@@ -221,6 +241,7 @@ export type WorkerDeps = ConsoleDep &
221
241
  * ]);
222
242
  * ```
223
243
  *
244
+ * @group Core
224
245
  * @see https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel
225
246
  */
226
247
  export interface MessageChannel<Input, Output = never> extends Disposable {
@@ -231,12 +252,21 @@ export interface MessageChannel<Input, Output = never> extends Disposable {
231
252
  readonly port2: MessagePort<Output, Input>;
232
253
  }
233
254
 
234
- /** Factory function to create a {@link MessageChannel}. */
255
+ /**
256
+ * Factory function to create a {@link MessageChannel}.
257
+ *
258
+ * @group Construction
259
+ */
235
260
  export type CreateMessageChannel = <Input, Output = never>() => MessageChannel<
236
261
  Input,
237
262
  Output
238
263
  >;
239
264
 
265
+ /**
266
+ * Dependency wrapper for {@link CreateMessageChannel}.
267
+ *
268
+ * @group Construction
269
+ */
240
270
  export interface CreateMessageChannelDep {
241
271
  readonly createMessageChannel: CreateMessageChannel;
242
272
  }
@@ -247,6 +277,7 @@ export interface CreateMessageChannelDep {
247
277
  * Broadcast channels deliver messages to other channels opened with the same
248
278
  * name. The sending channel does not receive its own messages.
249
279
  *
280
+ * @group Core
250
281
  * @see https://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel
251
282
  */
252
283
  export interface BroadcastChannel<Input, Output = Input> extends Disposable {
@@ -257,11 +288,20 @@ export interface BroadcastChannel<Input, Output = Input> extends Disposable {
257
288
  onMessage: ((message: Output) => void) | null;
258
289
  }
259
290
 
260
- /** Factory function to create a {@link BroadcastChannel}. */
291
+ /**
292
+ * Factory function to create a {@link BroadcastChannel}.
293
+ *
294
+ * @group Construction
295
+ */
261
296
  export type CreateBroadcastChannel = <Input, Output = Input>(
262
297
  name: string,
263
298
  ) => BroadcastChannel<Input, Output>;
264
299
 
300
+ /**
301
+ * Dependency wrapper for {@link CreateBroadcastChannel}.
302
+ *
303
+ * @group Construction
304
+ */
265
305
  export interface CreateBroadcastChannelDep {
266
306
  readonly createBroadcastChannel: CreateBroadcastChannel;
267
307
  }
@@ -271,6 +311,8 @@ export interface CreateBroadcastChannelDep {
271
311
  *
272
312
  * This is the worker-side counterpart to {@link Worker} — a typed
273
313
  * {@link MessagePort} that wraps `self` inside the worker.
314
+ *
315
+ * @group Core
274
316
  */
275
317
  export interface WorkerSelf<Input, Output = never> extends MessagePort<
276
318
  Output,
@@ -282,6 +324,8 @@ export interface WorkerSelf<Input, Output = never> extends MessagePort<
282
324
  *
283
325
  * This is the worker-side counterpart to {@link SharedWorker}. It wraps `self`
284
326
  * inside the shared worker, providing typed `onConnect` callbacks.
327
+ *
328
+ * @group Core
285
329
  */
286
330
  export interface SharedWorkerSelf<Input, Output = never> extends Disposable {
287
331
  onConnect: ((port: MessagePort<Output, Input>) => void) | null;
@@ -292,6 +336,8 @@ export interface SharedWorkerSelf<Input, Output = never> extends Disposable {
292
336
  *
293
337
  * This is a memory-only fallback for platforms without native worker support.
294
338
  * Message delivery is asynchronous in-process.
339
+ *
340
+ * @group Construction
295
341
  */
296
342
  export const createWorker = <Input, Output = never>(
297
343
  initWorker: (self: WorkerSelf<Input, Output>) => void,
@@ -309,6 +355,8 @@ export const createWorker = <Input, Output = never>(
309
355
  * in-process.
310
356
  *
311
357
  * Intended usage is one shared worker instance per process/app runtime.
358
+ *
359
+ * @group Construction
312
360
  */
313
361
  export const createSharedWorker = <Input, Output = never>(
314
362
  initWorker: (self: SharedWorkerSelf<Input, Output>) => void,
@@ -329,6 +377,8 @@ export const createSharedWorker = <Input, Output = never>(
329
377
  *
330
378
  * This is a memory-only fallback for platforms without native MessageChannel
331
379
  * support. Message delivery is asynchronous in-process.
380
+ *
381
+ * @group Construction
332
382
  */
333
383
  export const createMessageChannel: CreateMessageChannel = <
334
384
  Input,
@@ -386,6 +436,8 @@ export const createMessageChannel: CreateMessageChannel = <
386
436
  *
387
437
  * This is a memory-only fallback for platforms without native MessagePort
388
438
  * support. Message delivery through returned ports is asynchronous in-process.
439
+ *
440
+ * @group Construction
389
441
  */
390
442
  export const createMessagePort: CreateMessagePort = <Input, Output = never>(
391
443
  nativePort: NativeMessagePort<Input, Output>,
@@ -400,6 +452,8 @@ export const createMessagePort: CreateMessagePort = <Input, Output = never>(
400
452
  *
401
453
  * This is a memory-only fallback for platforms without native BroadcastChannel
402
454
  * support. Message delivery is asynchronous in-process.
455
+ *
456
+ * @group Construction
403
457
  */
404
458
  export const createBroadcastChannel: CreateBroadcastChannel = <
405
459
  Input,
@@ -468,6 +522,8 @@ const broadcastChannelDispatchesByName = new Map<
468
522
  * Test {@link Worker} with access to its paired worker-side `self`.
469
523
  *
470
524
  * Use `self` to simulate messages and behavior from inside the worker.
525
+ *
526
+ * @group Testing
471
527
  */
472
528
  export interface TestWorker<Input, Output = never> extends Worker<
473
529
  Input,
@@ -482,6 +538,8 @@ export interface TestWorker<Input, Output = never> extends Worker<
482
538
  *
483
539
  * Call `connect()` to simulate a client connection and trigger
484
540
  * `self.onConnect`.
541
+ *
542
+ * @group Testing
485
543
  */
486
544
  export interface TestSharedWorker<Input, Output = never> extends SharedWorker<
487
545
  Input,
@@ -491,7 +549,11 @@ export interface TestSharedWorker<Input, Output = never> extends SharedWorker<
491
549
  readonly connect: () => void;
492
550
  }
493
551
 
494
- /** {@link MessageChannel} with disposal tracking for testing. */
552
+ /**
553
+ * {@link MessageChannel} with disposal tracking for testing.
554
+ *
555
+ * @group Testing
556
+ */
495
557
  export interface TestMessageChannel<
496
558
  Input,
497
559
  Output = never,
@@ -499,7 +561,11 @@ export interface TestMessageChannel<
499
561
  readonly isDisposed: () => boolean;
500
562
  }
501
563
 
502
- /** {@link BroadcastChannel} with disposal tracking for testing. */
564
+ /**
565
+ * {@link BroadcastChannel} with disposal tracking for testing.
566
+ *
567
+ * @group Testing
568
+ */
503
569
  export interface TestBroadcastChannel<
504
570
  Input,
505
571
  Output = Input,
@@ -512,6 +578,8 @@ export interface TestBroadcastChannel<
512
578
  *
513
579
  * The returned worker includes its typed {@link TestWorker.self} counterpart, so
514
580
  * tests can exercise dedicated worker communication without a real thread.
581
+ *
582
+ * @group Testing
515
583
  */
516
584
  export const testCreateWorker = <Input, Output = never>(): TestWorker<
517
585
  Input,
@@ -531,6 +599,8 @@ export const testCreateWorker = <Input, Output = never>(): TestWorker<
531
599
  *
532
600
  * The returned worker includes `self` and `connect` so tests can exercise the
533
601
  * full worker ↔ client pipeline without a real worker thread.
602
+ *
603
+ * @group Testing
534
604
  */
535
605
  export const testCreateSharedWorker = <
536
606
  Input,
@@ -554,6 +624,8 @@ export const testCreateSharedWorker = <
554
624
  *
555
625
  * Both ports are registered in the native port registry so
556
626
  * {@link testCreateMessagePort} can look them up by their native token.
627
+ *
628
+ * @group Testing
557
629
  */
558
630
  export const testCreateMessageChannel = <
559
631
  Input,
@@ -572,12 +644,20 @@ export const testCreateMessageChannel = <
572
644
  };
573
645
  };
574
646
 
575
- /** Creates an in-memory {@link CreateMessagePort} for testing. */
647
+ /**
648
+ * Creates an in-memory {@link CreateMessagePort} for testing.
649
+ *
650
+ * @group Testing
651
+ */
576
652
  export const testCreateMessagePort: CreateMessagePort = <Input, Output = never>(
577
653
  nativePort: NativeMessagePort<Input, Output>,
578
654
  ): MessagePort<Input, Output> => createMessagePort(nativePort);
579
655
 
580
- /** Creates an in-memory {@link BroadcastChannel} for testing. */
656
+ /**
657
+ * Creates an in-memory {@link BroadcastChannel} for testing.
658
+ *
659
+ * @group Testing
660
+ */
581
661
  export const testCreateBroadcastChannel = <Input, Output = Input>(
582
662
  name: string,
583
663
  ): TestBroadcastChannel<Input, Output> => {
@@ -605,6 +685,8 @@ export const testCreateBroadcastChannel = <Input, Output = Input>(
605
685
  * This observes actual transport tasks instead of waiting for an arbitrary
606
686
  * duration. It also waits through message handlers that schedule more worker
607
687
  * tasks before the current microtask checkpoint completes.
688
+ *
689
+ * @group Testing
608
690
  */
609
691
  export const testWaitForWorkerMessage = (): Promise<void> =>
610
692
  new Promise((resolve) => {
package/src/index.ts CHANGED
@@ -51,16 +51,16 @@ export * from "./WebSocket.ts";
51
51
  export * from "./Worker.ts";
52
52
 
53
53
  // Local-first essentials.
54
- export type { EvoluError } from "./local-first/Error.ts";
55
- export { AppName, createEvolu } from "./local-first/Evolu.ts";
54
+ export type { UnsupportedDbVersionError } from "./local-first/Db.ts";
55
+ export { AppName, createEvolu, testAppName } from "./local-first/Evolu.ts";
56
56
  export type {
57
57
  AppNameError,
58
58
  Evolu,
59
59
  EvoluConfig,
60
60
  EvoluDeps,
61
+ EvoluError,
61
62
  UnuseOwner,
62
63
  } from "./local-first/Evolu.ts";
63
- export * from "./local-first/LocalAuth.ts";
64
64
  export * from "./local-first/Owner.ts";
65
65
  export type { SyncOwner } from "./local-first/Owner.ts";
66
66
  export {
@@ -75,7 +75,17 @@ export {
75
75
  type QueryRows,
76
76
  type Row,
77
77
  } from "./local-first/Query.ts";
78
- export { createQueryBuilder } from "./local-first/Schema.ts";
78
+ export {
79
+ createQueryBuilder,
80
+ QuarantineOrigin,
81
+ QuarantineReason,
82
+ testEvoluSchema,
83
+ testLocalOnlyEvoluSchema,
84
+ TestProjectId,
85
+ testProjectId,
86
+ TestTodoId,
87
+ testTodoId,
88
+ } from "./local-first/Schema.ts";
79
89
  export type {
80
90
  AnyStandardSchemaV1,
81
91
  EvoluSchema,
@@ -88,6 +98,7 @@ export type {
88
98
  OptionalColumnKeys,
89
99
  RequiredColumnKeys,
90
100
  TableSchema,
101
+ TestEvoluSchema,
91
102
  UpdateValues,
92
103
  UpsertValues,
93
104
  } from "./local-first/Schema.ts";
@@ -104,8 +115,6 @@ export {
104
115
  } from "./local-first/Timestamp.ts";
105
116
  export type {
106
117
  TimestampBytes,
107
- TimestampCounterOverflowError,
108
118
  TimestampDriftError,
109
119
  TimestampError,
110
- TimestampTimeOutOfRangeError,
111
120
  } from "./local-first/Timestamp.ts";