tinybase 6.1.0-beta.1 → 6.1.0-beta.3

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 (108) hide show
  1. package/@types/common/index.d.ts +4 -4
  2. package/@types/common/with-schemas/index.d.ts +4 -4
  3. package/@types/mergeable-store/index.d.ts +45 -20
  4. package/@types/mergeable-store/with-schemas/index.d.ts +49 -21
  5. package/@types/persisters/index.d.ts +1 -1
  6. package/@types/persisters/with-schemas/index.d.ts +1 -1
  7. package/index.js +19 -11
  8. package/indexes/index.js +15 -3
  9. package/indexes/with-schemas/index.js +15 -3
  10. package/mergeable-store/index.js +4 -8
  11. package/mergeable-store/with-schemas/index.js +4 -8
  12. package/min/index.js +1 -1
  13. package/min/index.js.gz +0 -0
  14. package/min/indexes/index.js +1 -1
  15. package/min/indexes/index.js.gz +0 -0
  16. package/min/indexes/with-schemas/index.js +1 -1
  17. package/min/indexes/with-schemas/index.js.gz +0 -0
  18. package/min/mergeable-store/index.js +1 -1
  19. package/min/mergeable-store/index.js.gz +0 -0
  20. package/min/mergeable-store/with-schemas/index.js +1 -1
  21. package/min/mergeable-store/with-schemas/index.js.gz +0 -0
  22. package/min/with-schemas/index.js +1 -1
  23. package/min/with-schemas/index.js.gz +0 -0
  24. package/package.json +9 -9
  25. package/readme.md +2 -2
  26. package/with-schemas/index.js +19 -11
  27. package/@types/_internal/queries/index.d.cts +0 -0
  28. package/@types/_internal/queries/with-schemas/index.d.cts +0 -22
  29. package/@types/_internal/store/index.d.cts +0 -3
  30. package/@types/_internal/store/with-schemas/index.d.cts +0 -106
  31. package/@types/_internal/ui-react/index.d.cts +0 -0
  32. package/@types/_internal/ui-react/with-schemas/index.d.cts +0 -1130
  33. package/@types/checkpoints/index.d.cts +0 -1059
  34. package/@types/checkpoints/with-schemas/index.d.cts +0 -1151
  35. package/@types/common/index.d.cts +0 -158
  36. package/@types/common/with-schemas/index.d.cts +0 -158
  37. package/@types/index.d.cts +0 -17
  38. package/@types/indexes/index.d.cts +0 -1064
  39. package/@types/indexes/with-schemas/index.d.cts +0 -1210
  40. package/@types/mergeable-store/index.d.cts +0 -1139
  41. package/@types/mergeable-store/with-schemas/index.d.cts +0 -1628
  42. package/@types/metrics/index.d.cts +0 -917
  43. package/@types/metrics/with-schemas/index.d.cts +0 -1004
  44. package/@types/persisters/index.d.cts +0 -1877
  45. package/@types/persisters/persister-automerge/index.d.cts +0 -165
  46. package/@types/persisters/persister-automerge/with-schemas/index.d.cts +0 -180
  47. package/@types/persisters/persister-browser/index.d.cts +0 -185
  48. package/@types/persisters/persister-browser/with-schemas/index.d.cts +0 -208
  49. package/@types/persisters/persister-cr-sqlite-wasm/index.d.cts +0 -159
  50. package/@types/persisters/persister-cr-sqlite-wasm/with-schemas/index.d.cts +0 -178
  51. package/@types/persisters/persister-durable-object-storage/index.d.cts +0 -122
  52. package/@types/persisters/persister-durable-object-storage/with-schemas/index.d.cts +0 -136
  53. package/@types/persisters/persister-electric-sql/index.d.cts +0 -185
  54. package/@types/persisters/persister-electric-sql/with-schemas/index.d.cts +0 -204
  55. package/@types/persisters/persister-expo-sqlite/index.d.cts +0 -186
  56. package/@types/persisters/persister-expo-sqlite/with-schemas/index.d.cts +0 -205
  57. package/@types/persisters/persister-file/index.d.cts +0 -94
  58. package/@types/persisters/persister-file/with-schemas/index.d.cts +0 -107
  59. package/@types/persisters/persister-indexed-db/index.d.cts +0 -120
  60. package/@types/persisters/persister-indexed-db/with-schemas/index.d.cts +0 -135
  61. package/@types/persisters/persister-libsql/index.d.cts +0 -158
  62. package/@types/persisters/persister-libsql/with-schemas/index.d.cts +0 -177
  63. package/@types/persisters/persister-partykit-client/index.d.cts +0 -195
  64. package/@types/persisters/persister-partykit-client/with-schemas/index.d.cts +0 -210
  65. package/@types/persisters/persister-partykit-server/index.d.cts +0 -650
  66. package/@types/persisters/persister-partykit-server/with-schemas/index.d.cts +0 -695
  67. package/@types/persisters/persister-pglite/index.d.cts +0 -177
  68. package/@types/persisters/persister-pglite/with-schemas/index.d.cts +0 -196
  69. package/@types/persisters/persister-postgres/index.d.cts +0 -166
  70. package/@types/persisters/persister-postgres/with-schemas/index.d.cts +0 -185
  71. package/@types/persisters/persister-powersync/index.d.cts +0 -174
  72. package/@types/persisters/persister-powersync/with-schemas/index.d.cts +0 -193
  73. package/@types/persisters/persister-remote/index.d.cts +0 -117
  74. package/@types/persisters/persister-remote/with-schemas/index.d.cts +0 -133
  75. package/@types/persisters/persister-sqlite-wasm/index.d.cts +0 -175
  76. package/@types/persisters/persister-sqlite-wasm/with-schemas/index.d.cts +0 -195
  77. package/@types/persisters/persister-sqlite3/index.d.cts +0 -176
  78. package/@types/persisters/persister-sqlite3/with-schemas/index.d.cts +0 -195
  79. package/@types/persisters/persister-yjs/index.d.cts +0 -161
  80. package/@types/persisters/persister-yjs/with-schemas/index.d.cts +0 -176
  81. package/@types/persisters/with-schemas/index.d.cts +0 -2054
  82. package/@types/queries/index.d.cts +0 -3695
  83. package/@types/queries/with-schemas/index.d.cts +0 -4016
  84. package/@types/relationships/index.d.cts +0 -1320
  85. package/@types/relationships/with-schemas/index.d.cts +0 -1474
  86. package/@types/store/index.d.cts +0 -7598
  87. package/@types/store/with-schemas/index.d.cts +0 -9278
  88. package/@types/synchronizers/index.d.cts +0 -485
  89. package/@types/synchronizers/synchronizer-broadcast-channel/index.d.cts +0 -121
  90. package/@types/synchronizers/synchronizer-broadcast-channel/with-schemas/index.d.cts +0 -137
  91. package/@types/synchronizers/synchronizer-local/index.d.cts +0 -95
  92. package/@types/synchronizers/synchronizer-local/with-schemas/index.d.cts +0 -114
  93. package/@types/synchronizers/synchronizer-ws-client/index.d.cts +0 -160
  94. package/@types/synchronizers/synchronizer-ws-client/with-schemas/index.d.cts +0 -179
  95. package/@types/synchronizers/synchronizer-ws-server/index.d.cts +0 -736
  96. package/@types/synchronizers/synchronizer-ws-server/with-schemas/index.d.cts +0 -765
  97. package/@types/synchronizers/synchronizer-ws-server-durable-object/index.d.cts +0 -311
  98. package/@types/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.d.cts +0 -349
  99. package/@types/synchronizers/synchronizer-ws-server-simple/index.d.cts +0 -144
  100. package/@types/synchronizers/synchronizer-ws-server-simple/with-schemas/index.d.cts +0 -144
  101. package/@types/synchronizers/with-schemas/index.d.cts +0 -503
  102. package/@types/ui-react/index.d.cts +0 -16640
  103. package/@types/ui-react/with-schemas/index.d.cts +0 -17281
  104. package/@types/ui-react-dom/index.d.cts +0 -1862
  105. package/@types/ui-react-dom/with-schemas/index.d.cts +0 -1994
  106. package/@types/ui-react-inspector/index.d.cts +0 -79
  107. package/@types/ui-react-inspector/with-schemas/index.d.cts +0 -1985
  108. package/@types/with-schemas/index.d.cts +0 -17
@@ -33,10 +33,10 @@ export type Ids = Id[];
33
33
  export type Id = string;
34
34
 
35
35
  /**
36
- * The Id type is a simple alias for the union of a string or `null` value,
37
- * where the string should be considered to be the key of an objects (such as a
38
- * Row Id string used in a Table), and typically `null` indicates a wildcard -
39
- * such as when used in the Store addRowListener method.
36
+ * The IdOrNull type is a simple alias for the union of a string or `null`
37
+ * value, where the string should be considered to be the key of an objects
38
+ * (such as a Row Id string used in a Table), and typically `null` indicates a
39
+ * wildcard - such as when used in the Store addRowListener method.
40
40
  * @category Identity
41
41
  * @since v1.0.0
42
42
  */
@@ -33,10 +33,10 @@ export type Ids = Id[];
33
33
  export type Id = string;
34
34
 
35
35
  /**
36
- * The Id type is a simple alias for the union of a string or `null` value,
37
- * where the string should be considered to be the key of an objects (such as a
38
- * Row Id string used in a Table), and typically `null` indicates a wildcard -
39
- * such as when used in the Store addRowListener method.
36
+ * The IdOrNull type is a simple alias for the union of a string or `null`
37
+ * value, where the string should be considered to be the key of an objects
38
+ * (such as a Row Id string used in a Table), and typically `null` indicates a
39
+ * wildcard - such as when used in the Store addRowListener method.
40
40
  * @category Identity
41
41
  * @since v1.0.0
42
42
  */
@@ -27,6 +27,18 @@ import type {
27
27
  ValueOrUndefined,
28
28
  } from '../store/index.d.ts';
29
29
 
30
+ /**
31
+ * The GetNow type is used to represent a function that returns the current time
32
+ * in milliseconds.
33
+ *
34
+ * This is used internally within the mergeable-store module, but is used for
35
+ * the createMergeableStore function's second optional argument to allow
36
+ * applications to override the clock used to generate timestamps.
37
+ * @category Stamps
38
+ * @since v6.1.0
39
+ */
40
+ export type GetNow = () => number;
41
+
30
42
  /**
31
43
  * The Hash type is used within the mergeable-store module to quickly compare
32
44
  * the content of two objects.
@@ -328,7 +340,7 @@ export interface MergeableStore extends Store {
328
340
  * ```js
329
341
  * import {createMergeableStore} from 'tinybase';
330
342
  *
331
- * const store = createMergeableStore('store1'); // !resetHlc
343
+ * const store = createMergeableStore('store1'); // !reset
332
344
  *
333
345
  * store.setCell('pets', 'fido', 'color', 'brown');
334
346
  *
@@ -380,7 +392,7 @@ export interface MergeableStore extends Store {
380
392
  * ```js
381
393
  * import {createMergeableStore} from 'tinybase';
382
394
  *
383
- * const store = createMergeableStore('store1'); // !resetHlc
395
+ * const store = createMergeableStore('store1'); // !reset
384
396
  *
385
397
  * store.setCell('pets', 'fido', 'color', 'brown');
386
398
  * console.log(store.getMergeableContentHashes());
@@ -414,7 +426,7 @@ export interface MergeableStore extends Store {
414
426
  * ```js
415
427
  * import {createMergeableStore} from 'tinybase';
416
428
  *
417
- * const store = createMergeableStore('store1'); // !resetHlc
429
+ * const store = createMergeableStore('store1'); // !reset
418
430
  *
419
431
  * store.setCell('pets', 'fido', 'color', 'brown');
420
432
  * console.log(store.getMergeableTableHashes());
@@ -447,7 +459,7 @@ export interface MergeableStore extends Store {
447
459
  * ```js
448
460
  * import {createMergeableStore} from 'tinybase';
449
461
  *
450
- * const store1 = createMergeableStore('store1'); // !resetHlc
462
+ * const store1 = createMergeableStore('store1'); // !reset
451
463
  * store1.setTables({pets: {fido: {color: 'brown'}}});
452
464
  *
453
465
  * const store2 = createMergeableStore('store2');
@@ -500,7 +512,7 @@ export interface MergeableStore extends Store {
500
512
  * ```js
501
513
  * import {createMergeableStore} from 'tinybase';
502
514
  *
503
- * const store1 = createMergeableStore('store1'); // !resetHlc
515
+ * const store1 = createMergeableStore('store1'); // !reset
504
516
  * store1.setTables({pets: {fido: {color: 'brown'}, felix: {color: 'tan'}}});
505
517
  *
506
518
  * const store2 = createMergeableStore('store2');
@@ -536,7 +548,7 @@ export interface MergeableStore extends Store {
536
548
  * ```js
537
549
  * import {createMergeableStore} from 'tinybase';
538
550
  *
539
- * const store1 = createMergeableStore('store1'); // !resetHlc
551
+ * const store1 = createMergeableStore('store1'); // !reset
540
552
  * store1.setTables({pets: {fido: {color: 'brown'}}});
541
553
  *
542
554
  * const store2 = createMergeableStore('store2');
@@ -594,7 +606,7 @@ export interface MergeableStore extends Store {
594
606
  * ```js
595
607
  * import {createMergeableStore} from 'tinybase';
596
608
  *
597
- * const store1 = createMergeableStore('store1'); // !resetHlc
609
+ * const store1 = createMergeableStore('store1'); // !reset
598
610
  * store1.setTables({pets: {fido: {color: 'brown', species: 'dog'}}});
599
611
  *
600
612
  * const store2 = createMergeableStore('store2');
@@ -634,7 +646,7 @@ export interface MergeableStore extends Store {
634
646
  * ```js
635
647
  * import {createMergeableStore} from 'tinybase';
636
648
  *
637
- * const store1 = createMergeableStore('store1'); // !resetHlc
649
+ * const store1 = createMergeableStore('store1'); // !reset
638
650
  * store1.setTables({pets: {fido: {color: 'brown'}}});
639
651
  *
640
652
  * const store2 = createMergeableStore('store2');
@@ -710,7 +722,7 @@ export interface MergeableStore extends Store {
710
722
  * ```js
711
723
  * import {createMergeableStore} from 'tinybase';
712
724
  *
713
- * const store = createMergeableStore('store1'); // !resetHlc
725
+ * const store = createMergeableStore('store1'); // !reset
714
726
  *
715
727
  * store.setValue('employees', 3);
716
728
  * console.log(store.getMergeableValueHashes());
@@ -743,7 +755,7 @@ export interface MergeableStore extends Store {
743
755
  * ```js
744
756
  * import {createMergeableStore} from 'tinybase';
745
757
  *
746
- * const store1 = createMergeableStore('store1'); // !resetHlc
758
+ * const store1 = createMergeableStore('store1'); // !reset
747
759
  * store1.setValues({employees: 3});
748
760
  *
749
761
  * const store2 = createMergeableStore('store2');
@@ -788,7 +800,7 @@ export interface MergeableStore extends Store {
788
800
  * ```js
789
801
  * import {createMergeableStore} from 'tinybase';
790
802
  *
791
- * const store1 = createMergeableStore('store1'); // !resetHlc
803
+ * const store1 = createMergeableStore('store1'); // !reset
792
804
  * store1.setValues({employees: 3});
793
805
  * console.log(store1.getMergeableContent());
794
806
  * // ->
@@ -836,7 +848,7 @@ export interface MergeableStore extends Store {
836
848
  * ```js
837
849
  * import {createMergeableStore} from 'tinybase';
838
850
  *
839
- * const store1 = createMergeableStore('store1'); // !resetHlc
851
+ * const store1 = createMergeableStore('store1'); // !reset
840
852
  * store1.setValues({employees: 3});
841
853
  *
842
854
  * const store2 = createMergeableStore('store2');
@@ -870,7 +882,7 @@ export interface MergeableStore extends Store {
870
882
  * ```js
871
883
  * import {createMergeableStore} from 'tinybase';
872
884
  *
873
- * const store = createMergeableStore('store1'); // !resetHlc
885
+ * const store = createMergeableStore('store1'); // !reset
874
886
  * store.setTables({pets: {fido: {species: 'dog', color: 'brown'}}});
875
887
  * store.setValues({open: true});
876
888
  *
@@ -1034,12 +1046,22 @@ export interface MergeableStore extends Store {
1034
1046
  * The createMergeableStore function creates a MergeableStore, and is the main
1035
1047
  * entry point into the mergeable-store module.
1036
1048
  *
1037
- * There is one optional parameter which is a uniqueId for the MergeableStore.
1038
- * This is used to distinguish conflicting changes made in the same millisecond
1039
- * by two different MergeableStore objects as its hash is added to the end of
1040
- * the HLC timestamps. Generally this can be omitted unless you have a need for
1041
- * deterministic HLCs, such as in a testing scenario. Otherwise, TinyBase will
1042
- * assign a unique Id to the Store at the time of creation.
1049
+ * There are two optional parameters which are only for testing and advanced
1050
+ * usage.
1051
+ *
1052
+ * The first is a uniqueId for the MergeableStore, used to distinguish
1053
+ * conflicting changes made in the same millisecond by two different
1054
+ * MergeableStore objects as its hash is added to the end of the HLC timestamps.
1055
+ * Generally this can be omitted unless you have a need for deterministic HLCs,
1056
+ * such as in a testing scenario. Otherwise, TinyBase will assign a unique Id to
1057
+ * the Store at the time of creation.
1058
+ *
1059
+ * Since v6.1.0, the second is a function that can be used to replace the way
1060
+ * the timestamp is generated for HLCs (by default JavaScript's `Date.now()`
1061
+ * method).
1062
+ * @param uniqueId An optional unique Id for the MergeableStore.
1063
+ * @param getNow An optional function that generates millisecond timestamps,
1064
+ * since v6.1.0.
1043
1065
  * @returns A reference to the new MergeableStore.
1044
1066
  * @example
1045
1067
  * This example creates a MergeableStore.
@@ -1136,4 +1158,7 @@ export interface MergeableStore extends Store {
1136
1158
  * @category Creation
1137
1159
  * @since v5.0.0
1138
1160
  */
1139
- export function createMergeableStore(uniqueId?: Id): MergeableStore;
1161
+ export function createMergeableStore(
1162
+ uniqueId?: Id,
1163
+ getNow?: GetNow,
1164
+ ): MergeableStore;
@@ -40,6 +40,18 @@ import type {
40
40
  ValuesSchema,
41
41
  } from '../../store/with-schemas/index.d.ts';
42
42
 
43
+ /**
44
+ * The GetNow type is used to represent a function that returns the current time
45
+ * in milliseconds.
46
+ *
47
+ * This is used internally within the mergeable-store module, but is used for
48
+ * the createMergeableStore function's second optional argument to allow
49
+ * applications to override the clock used to generate timestamps.
50
+ * @category Stamps
51
+ * @since v6.1.0
52
+ */
53
+ export type GetNow = () => number;
54
+
43
55
  /**
44
56
  * The Hash type is used within the mergeable-store module to quickly compare
45
57
  * the content of two objects.
@@ -491,7 +503,7 @@ export interface MergeableStore<Schemas extends OptionalSchemas>
491
503
  * ```js
492
504
  * import {createMergeableStore} from 'tinybase';
493
505
  *
494
- * const store = createMergeableStore('store1'); // !resetHlc
506
+ * const store = createMergeableStore('store1'); // !reset
495
507
  *
496
508
  * store.setCell('pets', 'fido', 'color', 'brown');
497
509
  *
@@ -543,7 +555,7 @@ export interface MergeableStore<Schemas extends OptionalSchemas>
543
555
  * ```js
544
556
  * import {createMergeableStore} from 'tinybase';
545
557
  *
546
- * const store = createMergeableStore('store1'); // !resetHlc
558
+ * const store = createMergeableStore('store1'); // !reset
547
559
  *
548
560
  * store.setCell('pets', 'fido', 'color', 'brown');
549
561
  * console.log(store.getMergeableContentHashes());
@@ -583,7 +595,7 @@ export interface MergeableStore<Schemas extends OptionalSchemas>
583
595
  * ```js
584
596
  * import {createMergeableStore} from 'tinybase';
585
597
  *
586
- * const store = createMergeableStore('store1'); // !resetHlc
598
+ * const store = createMergeableStore('store1'); // !reset
587
599
  *
588
600
  * store.setCell('pets', 'fido', 'color', 'brown');
589
601
  * console.log(store.getMergeableTableHashes());
@@ -624,7 +636,7 @@ export interface MergeableStore<Schemas extends OptionalSchemas>
624
636
  * ```js
625
637
  * import {createMergeableStore} from 'tinybase';
626
638
  *
627
- * const store1 = createMergeableStore('store1'); // !resetHlc
639
+ * const store1 = createMergeableStore('store1'); // !reset
628
640
  * store1.setTables({pets: {fido: {color: 'brown'}}});
629
641
  *
630
642
  * const store2 = createMergeableStore('store2');
@@ -686,7 +698,7 @@ export interface MergeableStore<Schemas extends OptionalSchemas>
686
698
  * ```js
687
699
  * import {createMergeableStore} from 'tinybase';
688
700
  *
689
- * const store1 = createMergeableStore('store1'); // !resetHlc
701
+ * const store1 = createMergeableStore('store1'); // !reset
690
702
  * store1.setTables({pets: {fido: {color: 'brown'}, felix: {color: 'tan'}}});
691
703
  *
692
704
  * const store2 = createMergeableStore('store2');
@@ -732,7 +744,7 @@ export interface MergeableStore<Schemas extends OptionalSchemas>
732
744
  * ```js
733
745
  * import {createMergeableStore} from 'tinybase';
734
746
  *
735
- * const store1 = createMergeableStore('store1'); // !resetHlc
747
+ * const store1 = createMergeableStore('store1'); // !reset
736
748
  * store1.setTables({pets: {fido: {color: 'brown'}}});
737
749
  *
738
750
  * const store2 = createMergeableStore('store2');
@@ -799,7 +811,7 @@ export interface MergeableStore<Schemas extends OptionalSchemas>
799
811
  * ```js
800
812
  * import {createMergeableStore} from 'tinybase';
801
813
  *
802
- * const store1 = createMergeableStore('store1'); // !resetHlc
814
+ * const store1 = createMergeableStore('store1'); // !reset
803
815
  * store1.setTables({pets: {fido: {color: 'brown', species: 'dog'}}});
804
816
  *
805
817
  * const store2 = createMergeableStore('store2');
@@ -847,7 +859,7 @@ export interface MergeableStore<Schemas extends OptionalSchemas>
847
859
  * ```js
848
860
  * import {createMergeableStore} from 'tinybase';
849
861
  *
850
- * const store1 = createMergeableStore('store1'); // !resetHlc
862
+ * const store1 = createMergeableStore('store1'); // !reset
851
863
  * store1.setTables({pets: {fido: {color: 'brown'}}});
852
864
  *
853
865
  * const store2 = createMergeableStore('store2');
@@ -931,7 +943,7 @@ export interface MergeableStore<Schemas extends OptionalSchemas>
931
943
  * ```js
932
944
  * import {createMergeableStore} from 'tinybase';
933
945
  *
934
- * const store = createMergeableStore('store1'); // !resetHlc
946
+ * const store = createMergeableStore('store1'); // !reset
935
947
  *
936
948
  * store.setValue('employees', 3);
937
949
  * console.log(store.getMergeableValueHashes());
@@ -970,7 +982,7 @@ export interface MergeableStore<Schemas extends OptionalSchemas>
970
982
  * ```js
971
983
  * import {createMergeableStore} from 'tinybase';
972
984
  *
973
- * const store1 = createMergeableStore('store1'); // !resetHlc
985
+ * const store1 = createMergeableStore('store1'); // !reset
974
986
  * store1.setValues({employees: 3});
975
987
  *
976
988
  * const store2 = createMergeableStore('store2');
@@ -1023,7 +1035,7 @@ export interface MergeableStore<Schemas extends OptionalSchemas>
1023
1035
  * ```js
1024
1036
  * import {createMergeableStore} from 'tinybase';
1025
1037
  *
1026
- * const store1 = createMergeableStore('store1'); // !resetHlc
1038
+ * const store1 = createMergeableStore('store1'); // !reset
1027
1039
  * store1.setValues({employees: 3});
1028
1040
  * console.log(store1.getMergeableContent());
1029
1041
  * // ->
@@ -1079,7 +1091,7 @@ export interface MergeableStore<Schemas extends OptionalSchemas>
1079
1091
  * ```js
1080
1092
  * import {createMergeableStore} from 'tinybase';
1081
1093
  *
1082
- * const store1 = createMergeableStore('store1'); // !resetHlc
1094
+ * const store1 = createMergeableStore('store1'); // !reset
1083
1095
  * store1.setValues({employees: 3});
1084
1096
  *
1085
1097
  * const store2 = createMergeableStore('store2');
@@ -1121,7 +1133,7 @@ export interface MergeableStore<Schemas extends OptionalSchemas>
1121
1133
  * ```js
1122
1134
  * import {createMergeableStore} from 'tinybase';
1123
1135
  *
1124
- * const store = createMergeableStore('store1'); // !resetHlc
1136
+ * const store = createMergeableStore('store1'); // !reset
1125
1137
  * store.setTables({pets: {fido: {species: 'dog', color: 'brown'}}});
1126
1138
  * store.setValues({open: true});
1127
1139
  *
@@ -1520,15 +1532,28 @@ export interface MergeableStore<Schemas extends OptionalSchemas>
1520
1532
  * This has schema-based typing. The following is a simplified representation:
1521
1533
  *
1522
1534
  * ```ts override
1523
- * createMergeableStore(uniqueId?: Id): MergeableStore;
1535
+ * createMergeableStore(
1536
+ * uniqueId?: Id,
1537
+ * getNow?: GetNow,
1538
+ * ): MergeableStore;
1524
1539
  * ```
1525
1540
  *
1526
- * There is one optional parameter which is a uniqueId for the MergeableStore.
1527
- * This is used to distinguish conflicting changes made in the same millisecond
1528
- * by two different MergeableStore objects as its hash is added to the end of
1529
- * the HLC timestamps. Generally this can be omitted unless you have a need for
1530
- * deterministic HLCs, such as in a testing scenario. Otherwise, TinyBase will
1531
- * assign a unique Id to the Store at the time of creation.
1541
+ * There are two optional parameters which are only for testing and advanced
1542
+ * usage.
1543
+ *
1544
+ * The first is a uniqueId for the MergeableStore, used to distinguish
1545
+ * conflicting changes made in the same millisecond by two different
1546
+ * MergeableStore objects as its hash is added to the end of the HLC timestamps.
1547
+ * Generally this can be omitted unless you have a need for deterministic HLCs,
1548
+ * such as in a testing scenario. Otherwise, TinyBase will assign a unique Id to
1549
+ * the Store at the time of creation.
1550
+ *
1551
+ * Since v6.1.0, the second is a function that can be used to replace the way
1552
+ * the timestamp is generated for HLCs (by default JavaScript's `Date.now()`
1553
+ * method).
1554
+ * @param uniqueId An optional unique Id for the MergeableStore.
1555
+ * @param getNow An optional function that generates millisecond timestamps,
1556
+ * since v6.1.0.
1532
1557
  * @returns A reference to the new MergeableStore.
1533
1558
  * @example
1534
1559
  * This example creates a MergeableStore.
@@ -1625,4 +1650,7 @@ export interface MergeableStore<Schemas extends OptionalSchemas>
1625
1650
  * @category Creation
1626
1651
  * @since v5.0.0
1627
1652
  */
1628
- export function createMergeableStore(uniqueId?: Id): MergeableStore<NoSchemas>;
1653
+ export function createMergeableStore(
1654
+ uniqueId?: Id,
1655
+ getNow?: GetNow,
1656
+ ): MergeableStore<NoSchemas>;
@@ -1710,7 +1710,7 @@ export type DatabaseChangeListener = (tableName: string) => void;
1710
1710
  * // -> '[{"pets":{"fido":{"species":"dog"}}},{}]'
1711
1711
  * storePersister.destroy();
1712
1712
  *
1713
- * const mergeableStore = createMergeableStore('mergeableStore1'); // !resetHlc
1713
+ * const mergeableStore = createMergeableStore('mergeableStore1'); // !reset
1714
1714
  * mergeableStore.setTables({pets: {fido: {species: 'dog'}}});
1715
1715
  * const mergeableStorePersister = createJsonPersister(mergeableStore);
1716
1716
  * await mergeableStorePersister.save();
@@ -1839,7 +1839,7 @@ export type DatabaseChangeListener = (tableName: string) => void;
1839
1839
  * // -> '[{"pets":{"fido":{"species":"dog"}}},{}]'
1840
1840
  * storePersister.destroy();
1841
1841
  *
1842
- * const mergeableStore = createMergeableStore('mergeableStore1'); // !resetHlc
1842
+ * const mergeableStore = createMergeableStore('mergeableStore1'); // !reset
1843
1843
  * mergeableStore.setTables({pets: {fido: {species: 'dog'}}});
1844
1844
  * const mergeableStorePersister = createJsonPersister(mergeableStore);
1845
1845
  * await mergeableStorePersister.save();
package/index.js CHANGED
@@ -825,7 +825,14 @@ const createIndexes = getCreateFunction((store) => {
825
825
  setDefinitionAndListen(
826
826
  indexId,
827
827
  tableId,
828
- (change, changedSliceIds, changedSortKeys, sliceIds, sortKeys, force) => {
828
+ (
829
+ change,
830
+ changedSliceIds,
831
+ changedSortKeys,
832
+ sliceIdOrIdsByRowId,
833
+ sortKeys,
834
+ force,
835
+ ) => {
829
836
  let sliceIdsChanged = 0;
830
837
  const changedSlices = setNew();
831
838
  const unsortedSlices = setNew();
@@ -869,8 +876,13 @@ const createIndexes = getCreateFunction((store) => {
869
876
  mapForEach(index, (sliceId) => setAdd(unsortedSlices, sliceId));
870
877
  } else {
871
878
  mapForEach(changedSortKeys, (rowId) =>
872
- ifNotUndefined(mapGet(sliceIds, rowId), (sliceId) =>
873
- setAdd(unsortedSlices, sliceId),
879
+ ifNotUndefined(
880
+ mapGet(sliceIdOrIdsByRowId, rowId),
881
+ (sliceIdOrIds) =>
882
+ arrayForEach(
883
+ isArray(sliceIdOrIds) ? sliceIdOrIds : [sliceIdOrIds],
884
+ (sliceId) => setAdd(unsortedSlices, sliceId),
885
+ ),
874
886
  ),
875
887
  );
876
888
  }
@@ -1019,7 +1031,7 @@ const decodeTimeAndCounter = (hlc16) => [
1019
1031
  decode(hlc16, 9) * SHIFT6 +
1020
1032
  decode(hlc16, 10),
1021
1033
  ];
1022
- const getHlcFunctions = (uniqueId) => {
1034
+ const getHlcFunctions = (uniqueId, getNow = Date.now) => {
1023
1035
  let logicalTime = 0;
1024
1036
  let lastCounter = -1;
1025
1037
  const clientPart = ifNotUndefined(
@@ -1044,11 +1056,7 @@ const getHlcFunctions = (uniqueId) => {
1044
1056
  const previousLogicalTime = logicalTime;
1045
1057
  const [remoteLogicalTime, remoteCounter] =
1046
1058
  isUndefined(hlc) || hlc == '' ? [0, 0] : decodeTimeAndCounter(hlc);
1047
- logicalTime = mathMax(
1048
- previousLogicalTime,
1049
- remoteLogicalTime,
1050
- GLOBAL.HLC_TIME ?? Date.now(),
1051
- );
1059
+ logicalTime = mathMax(previousLogicalTime, remoteLogicalTime, getNow());
1052
1060
  lastCounter =
1053
1061
  logicalTime == previousLogicalTime
1054
1062
  ? logicalTime == remoteLogicalTime
@@ -2501,13 +2509,13 @@ const validateMergeableContent = (mergeableContent) =>
2501
2509
  1,
2502
2510
  ),
2503
2511
  );
2504
- const createMergeableStore = (uniqueId) => {
2512
+ const createMergeableStore = (uniqueId, getNow) => {
2505
2513
  let listeningToRawStoreChanges = 1;
2506
2514
  let contentStampMap = newContentStampMap();
2507
2515
  let defaultingContent = 0;
2508
2516
  const touchedCells = mapNew();
2509
2517
  const touchedValues = setNew();
2510
- const [getHlc, seenHlc] = getHlcFunctions(uniqueId);
2518
+ const [getHlc, seenHlc] = getHlcFunctions(uniqueId, getNow);
2511
2519
  const store = createStore();
2512
2520
  const disableListeningToRawStoreChanges = (actions) => {
2513
2521
  const wasListening = listeningToRawStoreChanges;
package/indexes/index.js CHANGED
@@ -394,7 +394,14 @@ const createIndexes = getCreateFunction((store) => {
394
394
  setDefinitionAndListen(
395
395
  indexId,
396
396
  tableId,
397
- (change, changedSliceIds, changedSortKeys, sliceIds, sortKeys, force) => {
397
+ (
398
+ change,
399
+ changedSliceIds,
400
+ changedSortKeys,
401
+ sliceIdOrIdsByRowId,
402
+ sortKeys,
403
+ force,
404
+ ) => {
398
405
  let sliceIdsChanged = 0;
399
406
  const changedSlices = setNew();
400
407
  const unsortedSlices = setNew();
@@ -438,8 +445,13 @@ const createIndexes = getCreateFunction((store) => {
438
445
  mapForEach(index, (sliceId) => setAdd(unsortedSlices, sliceId));
439
446
  } else {
440
447
  mapForEach(changedSortKeys, (rowId) =>
441
- ifNotUndefined(mapGet(sliceIds, rowId), (sliceId) =>
442
- setAdd(unsortedSlices, sliceId),
448
+ ifNotUndefined(
449
+ mapGet(sliceIdOrIdsByRowId, rowId),
450
+ (sliceIdOrIds) =>
451
+ arrayForEach(
452
+ isArray(sliceIdOrIds) ? sliceIdOrIds : [sliceIdOrIds],
453
+ (sliceId) => setAdd(unsortedSlices, sliceId),
454
+ ),
443
455
  ),
444
456
  );
445
457
  }
@@ -394,7 +394,14 @@ const createIndexes = getCreateFunction((store) => {
394
394
  setDefinitionAndListen(
395
395
  indexId,
396
396
  tableId,
397
- (change, changedSliceIds, changedSortKeys, sliceIds, sortKeys, force) => {
397
+ (
398
+ change,
399
+ changedSliceIds,
400
+ changedSortKeys,
401
+ sliceIdOrIdsByRowId,
402
+ sortKeys,
403
+ force,
404
+ ) => {
398
405
  let sliceIdsChanged = 0;
399
406
  const changedSlices = setNew();
400
407
  const unsortedSlices = setNew();
@@ -438,8 +445,13 @@ const createIndexes = getCreateFunction((store) => {
438
445
  mapForEach(index, (sliceId) => setAdd(unsortedSlices, sliceId));
439
446
  } else {
440
447
  mapForEach(changedSortKeys, (rowId) =>
441
- ifNotUndefined(mapGet(sliceIds, rowId), (sliceId) =>
442
- setAdd(unsortedSlices, sliceId),
448
+ ifNotUndefined(
449
+ mapGet(sliceIdOrIdsByRowId, rowId),
450
+ (sliceIdOrIds) =>
451
+ arrayForEach(
452
+ isArray(sliceIdOrIds) ? sliceIdOrIds : [sliceIdOrIds],
453
+ (sliceId) => setAdd(unsortedSlices, sliceId),
454
+ ),
443
455
  ),
444
456
  );
445
457
  }
@@ -285,7 +285,7 @@ const decodeTimeAndCounter = (hlc16) => [
285
285
  decode(hlc16, 9) * SHIFT6 +
286
286
  decode(hlc16, 10),
287
287
  ];
288
- const getHlcFunctions = (uniqueId) => {
288
+ const getHlcFunctions = (uniqueId, getNow = Date.now) => {
289
289
  let logicalTime = 0;
290
290
  let lastCounter = -1;
291
291
  const clientPart = ifNotUndefined(
@@ -310,11 +310,7 @@ const getHlcFunctions = (uniqueId) => {
310
310
  const previousLogicalTime = logicalTime;
311
311
  const [remoteLogicalTime, remoteCounter] =
312
312
  isUndefined(hlc) || hlc == '' ? [0, 0] : decodeTimeAndCounter(hlc);
313
- logicalTime = mathMax(
314
- previousLogicalTime,
315
- remoteLogicalTime,
316
- GLOBAL.HLC_TIME ?? Date.now(),
317
- );
313
+ logicalTime = mathMax(previousLogicalTime, remoteLogicalTime, getNow());
318
314
  lastCounter =
319
315
  logicalTime == previousLogicalTime
320
316
  ? logicalTime == remoteLogicalTime
@@ -1861,13 +1857,13 @@ const validateMergeableContent = (mergeableContent) =>
1861
1857
  1,
1862
1858
  ),
1863
1859
  );
1864
- const createMergeableStore = (uniqueId) => {
1860
+ const createMergeableStore = (uniqueId, getNow) => {
1865
1861
  let listeningToRawStoreChanges = 1;
1866
1862
  let contentStampMap = newContentStampMap();
1867
1863
  let defaultingContent = 0;
1868
1864
  const touchedCells = mapNew();
1869
1865
  const touchedValues = setNew();
1870
- const [getHlc, seenHlc] = getHlcFunctions(uniqueId);
1866
+ const [getHlc, seenHlc] = getHlcFunctions(uniqueId, getNow);
1871
1867
  const store = createStore();
1872
1868
  const disableListeningToRawStoreChanges = (actions) => {
1873
1869
  const wasListening = listeningToRawStoreChanges;
@@ -285,7 +285,7 @@ const decodeTimeAndCounter = (hlc16) => [
285
285
  decode(hlc16, 9) * SHIFT6 +
286
286
  decode(hlc16, 10),
287
287
  ];
288
- const getHlcFunctions = (uniqueId) => {
288
+ const getHlcFunctions = (uniqueId, getNow = Date.now) => {
289
289
  let logicalTime = 0;
290
290
  let lastCounter = -1;
291
291
  const clientPart = ifNotUndefined(
@@ -310,11 +310,7 @@ const getHlcFunctions = (uniqueId) => {
310
310
  const previousLogicalTime = logicalTime;
311
311
  const [remoteLogicalTime, remoteCounter] =
312
312
  isUndefined(hlc) || hlc == '' ? [0, 0] : decodeTimeAndCounter(hlc);
313
- logicalTime = mathMax(
314
- previousLogicalTime,
315
- remoteLogicalTime,
316
- GLOBAL.HLC_TIME ?? Date.now(),
317
- );
313
+ logicalTime = mathMax(previousLogicalTime, remoteLogicalTime, getNow());
318
314
  lastCounter =
319
315
  logicalTime == previousLogicalTime
320
316
  ? logicalTime == remoteLogicalTime
@@ -1861,13 +1857,13 @@ const validateMergeableContent = (mergeableContent) =>
1861
1857
  1,
1862
1858
  ),
1863
1859
  );
1864
- const createMergeableStore = (uniqueId) => {
1860
+ const createMergeableStore = (uniqueId, getNow) => {
1865
1861
  let listeningToRawStoreChanges = 1;
1866
1862
  let contentStampMap = newContentStampMap();
1867
1863
  let defaultingContent = 0;
1868
1864
  const touchedCells = mapNew();
1869
1865
  const touchedValues = setNew();
1870
- const [getHlc, seenHlc] = getHlcFunctions(uniqueId);
1866
+ const [getHlc, seenHlc] = getHlcFunctions(uniqueId, getNow);
1871
1867
  const store = createStore();
1872
1868
  const disableListeningToRawStoreChanges = (actions) => {
1873
1869
  const wasListening = listeningToRawStoreChanges;