tinybase 6.2.0-beta.3 → 6.2.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.
- package/@types/common/index.d.ts +295 -0
- package/@types/common/with-schemas/index.d.ts +375 -0
- package/@types/mergeable-store/index.d.ts +5 -34
- package/@types/mergeable-store/with-schemas/index.d.ts +5 -34
- package/@types/omni/with-schemas/index.d.ts +3 -3
- package/common/index.js +62 -3
- package/common/with-schemas/index.js +62 -3
- package/index.js +133 -86
- package/mergeable-store/index.js +102 -94
- package/mergeable-store/with-schemas/index.js +102 -94
- package/min/common/index.js +1 -1
- package/min/common/index.js.gz +0 -0
- package/min/common/with-schemas/index.js +1 -1
- package/min/common/with-schemas/index.js.gz +0 -0
- package/min/index.js +1 -1
- package/min/index.js.gz +0 -0
- package/min/mergeable-store/index.js +1 -1
- package/min/mergeable-store/index.js.gz +0 -0
- package/min/mergeable-store/with-schemas/index.js +1 -1
- package/min/mergeable-store/with-schemas/index.js.gz +0 -0
- package/min/omni/index.js +1 -1
- package/min/omni/index.js.gz +0 -0
- package/min/omni/with-schemas/index.js +1 -1
- package/min/omni/with-schemas/index.js.gz +0 -0
- package/min/persisters/index.js +1 -1
- package/min/persisters/index.js.gz +0 -0
- package/min/persisters/persister-pglite/index.js +1 -1
- package/min/persisters/persister-pglite/index.js.gz +0 -0
- package/min/persisters/persister-pglite/with-schemas/index.js +1 -1
- package/min/persisters/persister-pglite/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-postgres/index.js +1 -1
- package/min/persisters/persister-postgres/index.js.gz +0 -0
- package/min/persisters/persister-postgres/with-schemas/index.js +1 -1
- package/min/persisters/persister-postgres/with-schemas/index.js.gz +0 -0
- package/min/persisters/with-schemas/index.js +1 -1
- package/min/persisters/with-schemas/index.js.gz +0 -0
- package/min/store/index.js +1 -1
- package/min/store/index.js.gz +0 -0
- package/min/store/with-schemas/index.js +1 -1
- package/min/store/with-schemas/index.js.gz +0 -0
- package/min/ui-react-inspector/index.js +1 -1
- package/min/ui-react-inspector/index.js.gz +0 -0
- package/min/ui-react-inspector/with-schemas/index.js +1 -1
- package/min/ui-react-inspector/with-schemas/index.js.gz +0 -0
- package/min/with-schemas/index.js +1 -1
- package/min/with-schemas/index.js.gz +0 -0
- package/omni/index.js +148 -101
- package/omni/with-schemas/index.js +148 -101
- package/package.json +3 -3
- package/persisters/index.js +9 -9
- package/persisters/persister-durable-object-storage/index.js +12 -12
- package/persisters/persister-durable-object-storage/with-schemas/index.js +12 -12
- package/persisters/persister-pglite/index.js +11 -11
- package/persisters/persister-pglite/with-schemas/index.js +11 -11
- package/persisters/persister-postgres/index.js +11 -11
- package/persisters/persister-postgres/with-schemas/index.js +11 -11
- package/persisters/with-schemas/index.js +9 -9
- package/readme.md +2 -2
- package/releases.md +9 -10
- package/store/index.js +4 -4
- package/store/with-schemas/index.js +4 -4
- package/synchronizers/index.js +7 -7
- package/synchronizers/synchronizer-broadcast-channel/index.js +7 -7
- package/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js +7 -7
- package/synchronizers/synchronizer-local/index.js +7 -7
- package/synchronizers/synchronizer-local/with-schemas/index.js +7 -7
- package/synchronizers/synchronizer-ws-client/index.js +7 -7
- package/synchronizers/synchronizer-ws-client/with-schemas/index.js +7 -7
- package/synchronizers/synchronizer-ws-server/index.js +7 -7
- package/synchronizers/synchronizer-ws-server/with-schemas/index.js +7 -7
- package/synchronizers/synchronizer-ws-server-durable-object/index.js +7 -7
- package/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +7 -7
- package/synchronizers/with-schemas/index.js +7 -7
- package/ui-react-inspector/index.js +1 -1
- package/ui-react-inspector/with-schemas/index.js +1 -1
- package/with-schemas/index.js +133 -86
|
@@ -176,8 +176,8 @@ const collDel = (coll, keyOrValue) => coll?.delete(keyOrValue);
|
|
|
176
176
|
|
|
177
177
|
const object = Object;
|
|
178
178
|
const getPrototypeOf = (obj) => object.getPrototypeOf(obj);
|
|
179
|
-
const objEntries = object.entries;
|
|
180
179
|
const objFrozen = object.isFrozen;
|
|
180
|
+
const objEntries = object.entries;
|
|
181
181
|
const isObject = (obj) =>
|
|
182
182
|
!isUndefined(obj) &&
|
|
183
183
|
ifNotUndefined(
|
|
@@ -859,16 +859,60 @@ const getUniqueId$1 = (length = 16) =>
|
|
|
859
859
|
'',
|
|
860
860
|
);
|
|
861
861
|
|
|
862
|
+
const jsonString = JSON.stringify;
|
|
863
|
+
const jsonParse = JSON.parse;
|
|
864
|
+
const jsonStringWithMap = (obj) =>
|
|
865
|
+
jsonString(obj, (_key, value) =>
|
|
866
|
+
isInstanceOf(value, Map) ? object.fromEntries([...value]) : value,
|
|
867
|
+
);
|
|
868
|
+
const jsonStringWithUndefined = (obj) =>
|
|
869
|
+
jsonString(obj, (_key, value) => (value === void 0 ? UNDEFINED : value));
|
|
870
|
+
const jsonParseWithUndefined = (str) =>
|
|
871
|
+
jsonParse(str, (_key, value) => (value === UNDEFINED ? void 0 : value));
|
|
872
|
+
|
|
862
873
|
const textEncoder = /* @__PURE__ */ new GLOBAL.TextEncoder();
|
|
863
|
-
const getHash = (
|
|
874
|
+
const getHash = (string) => {
|
|
864
875
|
let hash = 2166136261;
|
|
865
|
-
arrayForEach(textEncoder.encode(
|
|
876
|
+
arrayForEach(textEncoder.encode(string), (char) => {
|
|
866
877
|
hash ^= char;
|
|
867
878
|
hash +=
|
|
868
879
|
(hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24);
|
|
869
880
|
});
|
|
870
881
|
return hash >>> 0;
|
|
871
882
|
};
|
|
883
|
+
const addOrRemoveHash = (hash1, hash2) => (hash1 ^ hash2) >>> 0;
|
|
884
|
+
const getValuesHash = (valueHashes) =>
|
|
885
|
+
arrayReduce(
|
|
886
|
+
objEntries(valueHashes),
|
|
887
|
+
(valuesHash, [valueId, valueHash]) =>
|
|
888
|
+
addOrRemoveHash(
|
|
889
|
+
valuesHash,
|
|
890
|
+
getValueInValuesHash(valueId, valueHash) ^
|
|
891
|
+
getValueInValuesHash(valueId, 0),
|
|
892
|
+
// legacy v5; remove in v7
|
|
893
|
+
),
|
|
894
|
+
0,
|
|
895
|
+
// legacy v5; valuesHlc in v7?
|
|
896
|
+
);
|
|
897
|
+
const getValueInValuesHash = (valueId, valueHash) =>
|
|
898
|
+
getHash(valueId + ':' + valueHash);
|
|
899
|
+
const getValueHash = (value, valueHlc) =>
|
|
900
|
+
getHash(jsonStringWithMap(value ?? null) + ':' + valueHlc);
|
|
901
|
+
const getCellHash = getValueHash;
|
|
902
|
+
const getCellInRowHash = getValueInValuesHash;
|
|
903
|
+
const getRowHash = getValuesHash;
|
|
904
|
+
const getRowInTableHash = getValueInValuesHash;
|
|
905
|
+
const getTableHash = (rowHashes) =>
|
|
906
|
+
// alias to getValuesHash in v7
|
|
907
|
+
arrayReduce(
|
|
908
|
+
objEntries(rowHashes),
|
|
909
|
+
(valuesHash, [rowId, rowHash]) =>
|
|
910
|
+
addOrRemoveHash(valuesHash, getValueInValuesHash(rowId, rowHash)),
|
|
911
|
+
0,
|
|
912
|
+
// legacy v5; rowHlc in v7?
|
|
913
|
+
);
|
|
914
|
+
const getTableInTablesHash = getValueInValuesHash;
|
|
915
|
+
const getTablesHash = getTableHash;
|
|
872
916
|
|
|
873
917
|
const SHIFT36 = 2 ** 36;
|
|
874
918
|
const SHIFT30 = 2 ** 30;
|
|
@@ -1164,42 +1208,30 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
1164
1208
|
return objFreeze(indexes);
|
|
1165
1209
|
});
|
|
1166
1210
|
|
|
1167
|
-
const
|
|
1168
|
-
const
|
|
1169
|
-
const
|
|
1170
|
-
|
|
1171
|
-
isInstanceOf(value, Map) ? object.fromEntries([...value]) : value,
|
|
1172
|
-
);
|
|
1173
|
-
const jsonStringWithUndefined = (obj) =>
|
|
1174
|
-
jsonString(obj, (_key, value) => (value === void 0 ? UNDEFINED : value));
|
|
1175
|
-
const jsonParseWithUndefined = (str) =>
|
|
1176
|
-
jsonParse(str, (_key, value) => (value === UNDEFINED ? void 0 : value));
|
|
1177
|
-
|
|
1178
|
-
const stampClone = ([value, time]) => stampNew(value, time);
|
|
1179
|
-
const stampCloneWithHash = ([value, time, hash]) => [value, time, hash];
|
|
1180
|
-
const stampNew = (value, time) => (time ? [value, time] : [value]);
|
|
1181
|
-
const stampNewWithHash = (value, time, hash) => [value, time, hash];
|
|
1211
|
+
const stampClone = ([value, hlc]) => stampNew(value, hlc);
|
|
1212
|
+
const stampCloneWithHash = ([value, hlc, hash]) => [value, hlc, hash];
|
|
1213
|
+
const stampNew = (value, hlc) => (hlc ? [value, hlc] : [value]);
|
|
1214
|
+
const stampNewWithHash = (value, hlc, hash) => [value, hlc, hash];
|
|
1182
1215
|
const getStampHash = (stamp) => stamp[2];
|
|
1183
|
-
const
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
const getLatestTime = (time1, time2) =>
|
|
1216
|
+
const replaceHlcHash = (oldHlc, newHlc) =>
|
|
1217
|
+
newHlc > oldHlc ? (oldHlc ? getHash(oldHlc) : 0) ^ getHash(newHlc) : 0;
|
|
1218
|
+
const getLatestHlc = (hlc1, hlc2) =>
|
|
1187
1219
|
/* istanbul ignore next */
|
|
1188
|
-
((
|
|
1189
|
-
const stampUpdate = (stamp,
|
|
1190
|
-
if (
|
|
1191
|
-
stamp[1] =
|
|
1220
|
+
((hlc1 ?? '') > (hlc2 ?? '') ? hlc1 : hlc2) ?? '';
|
|
1221
|
+
const stampUpdate = (stamp, hlc, hash) => {
|
|
1222
|
+
if (hlc > stamp[1]) {
|
|
1223
|
+
stamp[1] = hlc;
|
|
1192
1224
|
}
|
|
1193
1225
|
stamp[2] = hash >>> 0;
|
|
1194
1226
|
};
|
|
1195
|
-
const stampNewObj = (
|
|
1196
|
-
const stampNewMap = (
|
|
1227
|
+
const stampNewObj = (hlc = EMPTY_STRING) => stampNew(objNew(), hlc);
|
|
1228
|
+
const stampNewMap = (hlc = EMPTY_STRING) => [mapNew(), hlc, 0];
|
|
1197
1229
|
const stampMapToObjWithHash = (
|
|
1198
|
-
[map,
|
|
1230
|
+
[map, hlc, hash],
|
|
1199
1231
|
mapper = stampCloneWithHash,
|
|
1200
|
-
) => [mapToObj(map, mapper),
|
|
1201
|
-
const stampMapToObjWithoutHash = ([map,
|
|
1202
|
-
stampNew(mapToObj(map, mapper),
|
|
1232
|
+
) => [mapToObj(map, mapper), hlc, hash];
|
|
1233
|
+
const stampMapToObjWithoutHash = ([map, hlc], mapper = stampClone) =>
|
|
1234
|
+
stampNew(mapToObj(map, mapper), hlc);
|
|
1203
1235
|
const stampValidate = (stamp, validateThing) =>
|
|
1204
1236
|
isArray(stamp) &&
|
|
1205
1237
|
size(stamp) == 3 &&
|
|
@@ -2644,25 +2676,25 @@ const createMergeableStore = (uniqueId, getNow) => {
|
|
|
2644
2676
|
const tablesChanges = {};
|
|
2645
2677
|
const valuesChanges = {};
|
|
2646
2678
|
const [
|
|
2647
|
-
[tablesObj,
|
|
2679
|
+
[tablesObj, incomingTablesHlc = EMPTY_STRING, incomingTablesHash = 0],
|
|
2648
2680
|
values,
|
|
2649
2681
|
] = contentOrChanges;
|
|
2650
2682
|
const [tablesStampMap, valuesStampMap] = contentStampMap;
|
|
2651
|
-
const [tableStampMaps,
|
|
2683
|
+
const [tableStampMaps, oldTablesHlc, oldTablesHash] = tablesStampMap;
|
|
2652
2684
|
let tablesHash = isContent ? incomingTablesHash : oldTablesHash;
|
|
2653
|
-
let
|
|
2685
|
+
let tablesHlc = incomingTablesHlc;
|
|
2654
2686
|
objForEach(
|
|
2655
2687
|
tablesObj,
|
|
2656
2688
|
(
|
|
2657
|
-
[rowsObj,
|
|
2689
|
+
[rowsObj, incomingTableHlc = EMPTY_STRING, incomingTableHash = 0],
|
|
2658
2690
|
tableId,
|
|
2659
2691
|
) => {
|
|
2660
2692
|
const tableStampMap = mapEnsure(tableStampMaps, tableId, stampNewMap);
|
|
2661
|
-
const [rowStampMaps,
|
|
2693
|
+
const [rowStampMaps, oldTableHlc, oldTableHash] = tableStampMap;
|
|
2662
2694
|
let tableHash = isContent ? incomingTableHash : oldTableHash;
|
|
2663
|
-
let
|
|
2695
|
+
let tableHlc = incomingTableHlc;
|
|
2664
2696
|
objForEach(rowsObj, (row, rowId) => {
|
|
2665
|
-
const [
|
|
2697
|
+
const [rowHlc, oldRowHash, rowHash] = mergeCellsOrValues(
|
|
2666
2698
|
row,
|
|
2667
2699
|
mapEnsure(rowStampMaps, rowId, stampNewMap),
|
|
2668
2700
|
objEnsure(objEnsure(tablesChanges, tableId, objNew), rowId, objNew),
|
|
@@ -2670,32 +2702,36 @@ const createMergeableStore = (uniqueId, getNow) => {
|
|
|
2670
2702
|
);
|
|
2671
2703
|
tableHash ^= isContent
|
|
2672
2704
|
? 0
|
|
2673
|
-
: (
|
|
2674
|
-
|
|
2675
|
-
|
|
2705
|
+
: addOrRemoveHash(
|
|
2706
|
+
oldRowHash ? getValueInValuesHash(rowId, oldRowHash) : 0,
|
|
2707
|
+
getValueInValuesHash(rowId, rowHash),
|
|
2708
|
+
);
|
|
2709
|
+
tableHlc = getLatestHlc(tableHlc, rowHlc);
|
|
2676
2710
|
});
|
|
2677
2711
|
tableHash ^= isContent
|
|
2678
2712
|
? 0
|
|
2679
|
-
:
|
|
2680
|
-
stampUpdate(tableStampMap,
|
|
2713
|
+
: replaceHlcHash(oldTableHlc, incomingTableHlc);
|
|
2714
|
+
stampUpdate(tableStampMap, incomingTableHlc, tableHash);
|
|
2681
2715
|
tablesHash ^= isContent
|
|
2682
2716
|
? 0
|
|
2683
|
-
: (
|
|
2684
|
-
|
|
2685
|
-
|
|
2717
|
+
: addOrRemoveHash(
|
|
2718
|
+
oldTableHash ? getValueInValuesHash(tableId, oldTableHash) : 0,
|
|
2719
|
+
getValueInValuesHash(tableId, tableStampMap[2]),
|
|
2720
|
+
);
|
|
2721
|
+
tablesHlc = getLatestHlc(tablesHlc, tableHlc);
|
|
2686
2722
|
},
|
|
2687
2723
|
);
|
|
2688
2724
|
tablesHash ^= isContent
|
|
2689
2725
|
? 0
|
|
2690
|
-
:
|
|
2691
|
-
stampUpdate(tablesStampMap,
|
|
2692
|
-
const [
|
|
2726
|
+
: replaceHlcHash(oldTablesHlc, incomingTablesHlc);
|
|
2727
|
+
stampUpdate(tablesStampMap, incomingTablesHlc, tablesHash);
|
|
2728
|
+
const [valuesHlc] = mergeCellsOrValues(
|
|
2693
2729
|
values,
|
|
2694
2730
|
valuesStampMap,
|
|
2695
2731
|
valuesChanges,
|
|
2696
2732
|
isContent,
|
|
2697
2733
|
);
|
|
2698
|
-
seenHlc(
|
|
2734
|
+
seenHlc(getLatestHlc(tablesHlc, valuesHlc));
|
|
2699
2735
|
return [tablesChanges, valuesChanges, 1];
|
|
2700
2736
|
};
|
|
2701
2737
|
const mergeCellsOrValues = (
|
|
@@ -2706,44 +2742,44 @@ const createMergeableStore = (uniqueId, getNow) => {
|
|
|
2706
2742
|
) => {
|
|
2707
2743
|
const [
|
|
2708
2744
|
thingsObj,
|
|
2709
|
-
|
|
2745
|
+
incomingThingsHlc = EMPTY_STRING,
|
|
2710
2746
|
incomingThingsHash = 0,
|
|
2711
2747
|
] = things;
|
|
2712
|
-
const [thingStampMaps,
|
|
2713
|
-
let
|
|
2748
|
+
const [thingStampMaps, oldThingsHlc, oldThingsHash] = thingsStampMap;
|
|
2749
|
+
let thingsHlc = incomingThingsHlc;
|
|
2714
2750
|
let thingsHash = isContent ? incomingThingsHash : oldThingsHash;
|
|
2715
2751
|
objForEach(
|
|
2716
2752
|
thingsObj,
|
|
2717
|
-
([thing,
|
|
2753
|
+
([thing, thingHlc = EMPTY_STRING, incomingThingHash = 0], thingId) => {
|
|
2718
2754
|
const thingStampMap = mapEnsure(thingStampMaps, thingId, () => [
|
|
2719
2755
|
void 0,
|
|
2720
2756
|
EMPTY_STRING,
|
|
2721
2757
|
0,
|
|
2722
2758
|
]);
|
|
2723
|
-
const [,
|
|
2724
|
-
if (!
|
|
2759
|
+
const [, oldThingHlc, oldThingHash] = thingStampMap;
|
|
2760
|
+
if (!oldThingHlc || thingHlc > oldThingHlc) {
|
|
2725
2761
|
stampUpdate(
|
|
2726
2762
|
thingStampMap,
|
|
2727
|
-
|
|
2728
|
-
isContent
|
|
2729
|
-
? incomingThingHash
|
|
2730
|
-
: getHash(jsonStringWithMap(thing ?? null) + ':' + thingTime),
|
|
2763
|
+
thingHlc,
|
|
2764
|
+
isContent ? incomingThingHash : getValueHash(thing, thingHlc),
|
|
2731
2765
|
);
|
|
2732
2766
|
thingStampMap[0] = thing;
|
|
2733
2767
|
thingsChanges[thingId] = thing;
|
|
2734
2768
|
thingsHash ^= isContent
|
|
2735
2769
|
? 0
|
|
2736
|
-
:
|
|
2737
|
-
|
|
2738
|
-
|
|
2770
|
+
: addOrRemoveHash(
|
|
2771
|
+
getValueInValuesHash(thingId, oldThingHash),
|
|
2772
|
+
getValueInValuesHash(thingId, thingStampMap[2]),
|
|
2773
|
+
);
|
|
2774
|
+
thingsHlc = getLatestHlc(thingsHlc, thingHlc);
|
|
2739
2775
|
}
|
|
2740
2776
|
},
|
|
2741
2777
|
);
|
|
2742
2778
|
thingsHash ^= isContent
|
|
2743
2779
|
? 0
|
|
2744
|
-
:
|
|
2745
|
-
stampUpdate(thingsStampMap,
|
|
2746
|
-
return [
|
|
2780
|
+
: replaceHlcHash(oldThingsHlc, incomingThingsHlc);
|
|
2781
|
+
stampUpdate(thingsStampMap, incomingThingsHlc, thingsHash);
|
|
2782
|
+
return [thingsHlc, oldThingsHash, thingsStampMap[2]];
|
|
2747
2783
|
};
|
|
2748
2784
|
const preStartTransaction = noop;
|
|
2749
2785
|
const preFinishTransaction = noop;
|
|
@@ -2815,13 +2851,13 @@ const createMergeableStore = (uniqueId, getNow) => {
|
|
|
2815
2851
|
const differingTableHashes = {};
|
|
2816
2852
|
mapForEach(
|
|
2817
2853
|
contentStampMap[0][0],
|
|
2818
|
-
(tableId, [tableStampMap,
|
|
2854
|
+
(tableId, [tableStampMap, tableHlc, hash]) =>
|
|
2819
2855
|
objHas(otherTableHashes, tableId)
|
|
2820
2856
|
? hash != otherTableHashes[tableId]
|
|
2821
2857
|
? (differingTableHashes[tableId] = hash)
|
|
2822
2858
|
: 0
|
|
2823
2859
|
: (newTables[0][tableId] = stampMapToObjWithoutHash(
|
|
2824
|
-
[tableStampMap,
|
|
2860
|
+
[tableStampMap, tableHlc],
|
|
2825
2861
|
(rowStampMap) => stampMapToObjWithoutHash(rowStampMap),
|
|
2826
2862
|
)),
|
|
2827
2863
|
);
|
|
@@ -2850,13 +2886,13 @@ const createMergeableStore = (uniqueId, getNow) => {
|
|
|
2850
2886
|
objForEach(otherTableRowHashes, (otherRowHashes, tableId) =>
|
|
2851
2887
|
mapForEach(
|
|
2852
2888
|
mapGet(contentStampMap[0][0], tableId)?.[0],
|
|
2853
|
-
(rowId, [rowStampMap,
|
|
2889
|
+
(rowId, [rowStampMap, rowHlc, hash]) =>
|
|
2854
2890
|
objHas(otherRowHashes, rowId)
|
|
2855
2891
|
? hash !== otherRowHashes[rowId]
|
|
2856
2892
|
? (objEnsure(differingRowHashes, tableId, objNew)[rowId] = hash)
|
|
2857
2893
|
: 0
|
|
2858
2894
|
: (objEnsure(newRows[0], tableId, stampNewObj)[0][rowId] =
|
|
2859
|
-
stampMapToObjWithoutHash([rowStampMap,
|
|
2895
|
+
stampMapToObjWithoutHash([rowStampMap, rowHlc])),
|
|
2860
2896
|
),
|
|
2861
2897
|
);
|
|
2862
2898
|
return [newRows, differingRowHashes];
|
|
@@ -2887,43 +2923,43 @@ const createMergeableStore = (uniqueId, getNow) => {
|
|
|
2887
2923
|
return cellHashes;
|
|
2888
2924
|
};
|
|
2889
2925
|
const getMergeableCellDiff = (otherTableRowCellHashes) => {
|
|
2890
|
-
const [[tableStampMaps,
|
|
2926
|
+
const [[tableStampMaps, tablesHlc]] = contentStampMap;
|
|
2891
2927
|
const tablesObj = {};
|
|
2892
2928
|
objForEach(otherTableRowCellHashes, (otherRowCellHashes, tableId) =>
|
|
2893
2929
|
objForEach(otherRowCellHashes, (otherCellHashes, rowId) =>
|
|
2894
2930
|
ifNotUndefined(
|
|
2895
2931
|
mapGet(tableStampMaps, tableId),
|
|
2896
|
-
([rowStampMaps,
|
|
2932
|
+
([rowStampMaps, tableHlc]) =>
|
|
2897
2933
|
ifNotUndefined(
|
|
2898
2934
|
mapGet(rowStampMaps, rowId),
|
|
2899
|
-
([cellStampMaps,
|
|
2900
|
-
mapForEach(cellStampMaps, (cellId, [cell,
|
|
2935
|
+
([cellStampMaps, rowHlc]) =>
|
|
2936
|
+
mapForEach(cellStampMaps, (cellId, [cell, cellHlc, hash]) =>
|
|
2901
2937
|
hash !== otherCellHashes[cellId]
|
|
2902
2938
|
? (objEnsure(
|
|
2903
2939
|
objEnsure(tablesObj, tableId, () =>
|
|
2904
|
-
stampNewObj(
|
|
2940
|
+
stampNewObj(tableHlc),
|
|
2905
2941
|
)[0],
|
|
2906
2942
|
rowId,
|
|
2907
|
-
() => stampNewObj(
|
|
2908
|
-
)[0][cellId] = [cell,
|
|
2943
|
+
() => stampNewObj(rowHlc),
|
|
2944
|
+
)[0][cellId] = [cell, cellHlc])
|
|
2909
2945
|
: 0,
|
|
2910
2946
|
),
|
|
2911
2947
|
),
|
|
2912
2948
|
),
|
|
2913
2949
|
),
|
|
2914
2950
|
);
|
|
2915
|
-
return stampNew(tablesObj,
|
|
2951
|
+
return stampNew(tablesObj, tablesHlc);
|
|
2916
2952
|
};
|
|
2917
2953
|
const getMergeableValueHashes = () =>
|
|
2918
2954
|
mapToObj(contentStampMap[1][0], getStampHash);
|
|
2919
2955
|
const getMergeableValueDiff = (otherValueHashes) => {
|
|
2920
|
-
const [, [valueStampMaps,
|
|
2956
|
+
const [, [valueStampMaps, valuesHlc]] = contentStampMap;
|
|
2921
2957
|
const values = mapToObj(
|
|
2922
2958
|
valueStampMaps,
|
|
2923
2959
|
stampClone,
|
|
2924
2960
|
([, , hash], valueId) => hash == otherValueHashes?.[valueId],
|
|
2925
2961
|
);
|
|
2926
|
-
return stampNew(values,
|
|
2962
|
+
return stampNew(values, valuesHlc);
|
|
2927
2963
|
};
|
|
2928
2964
|
const setMergeableContent = (mergeableContent) =>
|
|
2929
2965
|
disableListeningToRawStoreChanges(() =>
|
|
@@ -2945,20 +2981,20 @@ const createMergeableStore = (uniqueId, getNow) => {
|
|
|
2945
2981
|
};
|
|
2946
2982
|
const getTransactionMergeableChanges = (withHashes = false) => {
|
|
2947
2983
|
const [
|
|
2948
|
-
[tableStampMaps,
|
|
2949
|
-
[valueStampMaps,
|
|
2984
|
+
[tableStampMaps, tablesHlc, tablesHash],
|
|
2985
|
+
[valueStampMaps, valuesHlc, valuesHash],
|
|
2950
2986
|
] = contentStampMap;
|
|
2951
2987
|
const newStamp = withHashes ? stampNewWithHash : stampNew;
|
|
2952
2988
|
const tablesObj = {};
|
|
2953
2989
|
collForEach(touchedCells, (touchedTable, tableId) =>
|
|
2954
2990
|
ifNotUndefined(
|
|
2955
2991
|
mapGet(tableStampMaps, tableId),
|
|
2956
|
-
([rowStampMaps,
|
|
2992
|
+
([rowStampMaps, tableHlc, tableHash]) => {
|
|
2957
2993
|
const tableObj = {};
|
|
2958
2994
|
collForEach(touchedTable, (touchedRow, rowId) =>
|
|
2959
2995
|
ifNotUndefined(
|
|
2960
2996
|
mapGet(rowStampMaps, rowId),
|
|
2961
|
-
([cellStampMaps,
|
|
2997
|
+
([cellStampMaps, rowHlc, rowHash]) => {
|
|
2962
2998
|
const rowObj = {};
|
|
2963
2999
|
collForEach(touchedRow, (cellId) => {
|
|
2964
3000
|
ifNotUndefined(
|
|
@@ -2967,11 +3003,11 @@ const createMergeableStore = (uniqueId, getNow) => {
|
|
|
2967
3003
|
(rowObj[cellId] = newStamp(cell, time, hash)),
|
|
2968
3004
|
);
|
|
2969
3005
|
});
|
|
2970
|
-
tableObj[rowId] = newStamp(rowObj,
|
|
3006
|
+
tableObj[rowId] = newStamp(rowObj, rowHlc, rowHash);
|
|
2971
3007
|
},
|
|
2972
3008
|
),
|
|
2973
3009
|
);
|
|
2974
|
-
tablesObj[tableId] = newStamp(tableObj,
|
|
3010
|
+
tablesObj[tableId] = newStamp(tableObj, tableHlc, tableHash);
|
|
2975
3011
|
},
|
|
2976
3012
|
),
|
|
2977
3013
|
);
|
|
@@ -2984,8 +3020,8 @@ const createMergeableStore = (uniqueId, getNow) => {
|
|
|
2984
3020
|
),
|
|
2985
3021
|
);
|
|
2986
3022
|
return [
|
|
2987
|
-
newStamp(tablesObj,
|
|
2988
|
-
newStamp(valuesObj,
|
|
3023
|
+
newStamp(tablesObj, tablesHlc, tablesHash),
|
|
3024
|
+
newStamp(valuesObj, valuesHlc, valuesHash),
|
|
2989
3025
|
1,
|
|
2990
3026
|
];
|
|
2991
3027
|
};
|
|
@@ -4608,18 +4644,18 @@ const createDurableObjectStoragePersister = (
|
|
|
4608
4644
|
const setPersisted = async (
|
|
4609
4645
|
getContent,
|
|
4610
4646
|
[
|
|
4611
|
-
[tablesObj,
|
|
4612
|
-
[valuesObj,
|
|
4647
|
+
[tablesObj, tablesHlc, tablesHash],
|
|
4648
|
+
[valuesObj, valuesHlc, valuesHash],
|
|
4613
4649
|
] = getContent(),
|
|
4614
4650
|
) => {
|
|
4615
4651
|
const keysToSet = mapNew();
|
|
4616
|
-
mapSet(keysToSet, constructKey(T), [0,
|
|
4617
|
-
objForEach(tablesObj, ([tableObj,
|
|
4618
|
-
mapSet(keysToSet, constructKey(T, tableId), [0,
|
|
4619
|
-
objForEach(tableObj, ([rowObj,
|
|
4652
|
+
mapSet(keysToSet, constructKey(T), [0, tablesHlc, tablesHash]);
|
|
4653
|
+
objForEach(tablesObj, ([tableObj, tableHlc, tableHash], tableId) => {
|
|
4654
|
+
mapSet(keysToSet, constructKey(T, tableId), [0, tableHlc, tableHash]);
|
|
4655
|
+
objForEach(tableObj, ([rowObj, rowHlc, rowHash], rowId) => {
|
|
4620
4656
|
mapSet(keysToSet, constructKey(T, tableId, rowId), [
|
|
4621
4657
|
0,
|
|
4622
|
-
|
|
4658
|
+
rowHlc,
|
|
4623
4659
|
rowHash,
|
|
4624
4660
|
]);
|
|
4625
4661
|
objForEach(rowObj, (cellStamp, cellId) =>
|
|
@@ -4627,7 +4663,7 @@ const createDurableObjectStoragePersister = (
|
|
|
4627
4663
|
);
|
|
4628
4664
|
});
|
|
4629
4665
|
});
|
|
4630
|
-
mapSet(keysToSet, constructKey(V), [0,
|
|
4666
|
+
mapSet(keysToSet, constructKey(V), [0, valuesHlc, valuesHash]);
|
|
4631
4667
|
objForEach(valuesObj, (valueStamp, valueId) =>
|
|
4632
4668
|
mapSet(keysToSet, constructKey(V, valueId), valueStamp),
|
|
4633
4669
|
);
|
|
@@ -6335,11 +6371,11 @@ const createCustomSynchronizer = (
|
|
|
6335
6371
|
([cell2, cellTime2], cellId) =>
|
|
6336
6372
|
(rowStamp[0][cellId] = stampNew(cell2, cellTime2)),
|
|
6337
6373
|
);
|
|
6338
|
-
rowStamp[1] =
|
|
6374
|
+
rowStamp[1] = getLatestHlc(rowStamp[1], rowTime2);
|
|
6339
6375
|
});
|
|
6340
|
-
tableStamp[1] =
|
|
6376
|
+
tableStamp[1] = getLatestHlc(tableStamp[1], tableTime2);
|
|
6341
6377
|
});
|
|
6342
|
-
tablesStamp[1] =
|
|
6378
|
+
tablesStamp[1] = getLatestHlc(tablesStamp[1], tablesTime2);
|
|
6343
6379
|
};
|
|
6344
6380
|
const getChangesFromOtherStore = (
|
|
6345
6381
|
otherClientId = null,
|
|
@@ -10364,6 +10400,7 @@ const Inspector = ({position = 'right', open = false}) => {
|
|
|
10364
10400
|
};
|
|
10365
10401
|
|
|
10366
10402
|
export {
|
|
10403
|
+
addOrRemoveHash,
|
|
10367
10404
|
BackwardCheckpointsView,
|
|
10368
10405
|
broadcastChanges,
|
|
10369
10406
|
CellView,
|
|
@@ -10408,9 +10445,19 @@ export {
|
|
|
10408
10445
|
EditableCellView,
|
|
10409
10446
|
EditableValueView,
|
|
10410
10447
|
ForwardCheckpointsView,
|
|
10448
|
+
getCellHash,
|
|
10449
|
+
getCellInRowHash,
|
|
10450
|
+
getHash,
|
|
10411
10451
|
getHlcFunctions,
|
|
10412
|
-
|
|
10452
|
+
getRowHash,
|
|
10453
|
+
getRowInTableHash,
|
|
10454
|
+
getTableHash,
|
|
10455
|
+
getTableInTablesHash,
|
|
10456
|
+
getTablesHash,
|
|
10413
10457
|
getUniqueId$1 as getUniqueId,
|
|
10458
|
+
getValueHash,
|
|
10459
|
+
getValueInValuesHash,
|
|
10460
|
+
getValuesHash,
|
|
10414
10461
|
getWsServerDurableObjectFetch,
|
|
10415
10462
|
hasStoreInStorage,
|
|
10416
10463
|
IndexView$1 as IndexView,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tinybase",
|
|
3
|
-
"version": "6.2.0
|
|
3
|
+
"version": "6.2.0",
|
|
4
4
|
"author": "jamesgpearce",
|
|
5
5
|
"repository": "github:tinyplex/tinybase",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"sideEffects": false,
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"@automerge/automerge-repo": "^1.2.1",
|
|
25
|
-
"@cloudflare/workers-types": "^4.
|
|
25
|
+
"@cloudflare/workers-types": "^4.20250531.0",
|
|
26
26
|
"@electric-sql/pglite": "^0.2.17",
|
|
27
|
-
"@libsql/client": "^0.15.
|
|
27
|
+
"@libsql/client": "^0.15.8",
|
|
28
28
|
"@powersync/common": "^1.31.0",
|
|
29
29
|
"@sqlite.org/sqlite-wasm": "^3.49.2-build1",
|
|
30
30
|
"@vlcn.io/crsqlite-wasm": "^0.16.0",
|
package/persisters/index.js
CHANGED
|
@@ -468,10 +468,17 @@ const createCustomPersister = (
|
|
|
468
468
|
return objFreeze(persister);
|
|
469
469
|
};
|
|
470
470
|
|
|
471
|
+
const jsonString = JSON.stringify;
|
|
472
|
+
const jsonParse = JSON.parse;
|
|
473
|
+
const jsonStringWithUndefined = (obj) =>
|
|
474
|
+
jsonString(obj, (_key, value) => (value === void 0 ? UNDEFINED : value));
|
|
475
|
+
const jsonParseWithUndefined = (str) =>
|
|
476
|
+
jsonParse(str, (_key, value) => (value === UNDEFINED ? void 0 : value));
|
|
477
|
+
|
|
471
478
|
const textEncoder = /* @__PURE__ */ new GLOBAL.TextEncoder();
|
|
472
|
-
const getHash = (
|
|
479
|
+
const getHash = (string) => {
|
|
473
480
|
let hash = 2166136261;
|
|
474
|
-
arrayForEach(textEncoder.encode(
|
|
481
|
+
arrayForEach(textEncoder.encode(string), (char) => {
|
|
475
482
|
hash ^= char;
|
|
476
483
|
hash +=
|
|
477
484
|
(hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24);
|
|
@@ -479,13 +486,6 @@ const getHash = (value) => {
|
|
|
479
486
|
return hash >>> 0;
|
|
480
487
|
};
|
|
481
488
|
|
|
482
|
-
const jsonString = JSON.stringify;
|
|
483
|
-
const jsonParse = JSON.parse;
|
|
484
|
-
const jsonStringWithUndefined = (obj) =>
|
|
485
|
-
jsonString(obj, (_key, value) => (value === void 0 ? UNDEFINED : value));
|
|
486
|
-
const jsonParseWithUndefined = (str) =>
|
|
487
|
-
jsonParse(str, (_key, value) => (value === UNDEFINED ? void 0 : value));
|
|
488
|
-
|
|
489
489
|
const SINGLE_ROW_ID = '_';
|
|
490
490
|
const DEFAULT_ROW_ID_COLUMN_NAME = '_id';
|
|
491
491
|
const SELECT = 'SELECT';
|
|
@@ -113,10 +113,10 @@ const visitTree = (node, path, ensureLeaf, pruneLeaf, p = 0) =>
|
|
|
113
113
|
},
|
|
114
114
|
);
|
|
115
115
|
|
|
116
|
-
const stampNewWithHash = (value,
|
|
117
|
-
const stampUpdate = (stamp,
|
|
118
|
-
if (
|
|
119
|
-
stamp[1] =
|
|
116
|
+
const stampNewWithHash = (value, hlc, hash) => [value, hlc, hash];
|
|
117
|
+
const stampUpdate = (stamp, hlc, hash) => {
|
|
118
|
+
if (hlc > stamp[1]) {
|
|
119
|
+
stamp[1] = hlc;
|
|
120
120
|
}
|
|
121
121
|
stamp[2] = hash >>> 0;
|
|
122
122
|
};
|
|
@@ -523,18 +523,18 @@ const createDurableObjectStoragePersister = (
|
|
|
523
523
|
const setPersisted = async (
|
|
524
524
|
getContent,
|
|
525
525
|
[
|
|
526
|
-
[tablesObj,
|
|
527
|
-
[valuesObj,
|
|
526
|
+
[tablesObj, tablesHlc, tablesHash],
|
|
527
|
+
[valuesObj, valuesHlc, valuesHash],
|
|
528
528
|
] = getContent(),
|
|
529
529
|
) => {
|
|
530
530
|
const keysToSet = mapNew();
|
|
531
|
-
mapSet(keysToSet, constructKey(T), [0,
|
|
532
|
-
objForEach(tablesObj, ([tableObj,
|
|
533
|
-
mapSet(keysToSet, constructKey(T, tableId), [0,
|
|
534
|
-
objForEach(tableObj, ([rowObj,
|
|
531
|
+
mapSet(keysToSet, constructKey(T), [0, tablesHlc, tablesHash]);
|
|
532
|
+
objForEach(tablesObj, ([tableObj, tableHlc, tableHash], tableId) => {
|
|
533
|
+
mapSet(keysToSet, constructKey(T, tableId), [0, tableHlc, tableHash]);
|
|
534
|
+
objForEach(tableObj, ([rowObj, rowHlc, rowHash], rowId) => {
|
|
535
535
|
mapSet(keysToSet, constructKey(T, tableId, rowId), [
|
|
536
536
|
0,
|
|
537
|
-
|
|
537
|
+
rowHlc,
|
|
538
538
|
rowHash,
|
|
539
539
|
]);
|
|
540
540
|
objForEach(rowObj, (cellStamp, cellId) =>
|
|
@@ -542,7 +542,7 @@ const createDurableObjectStoragePersister = (
|
|
|
542
542
|
);
|
|
543
543
|
});
|
|
544
544
|
});
|
|
545
|
-
mapSet(keysToSet, constructKey(V), [0,
|
|
545
|
+
mapSet(keysToSet, constructKey(V), [0, valuesHlc, valuesHash]);
|
|
546
546
|
objForEach(valuesObj, (valueStamp, valueId) =>
|
|
547
547
|
mapSet(keysToSet, constructKey(V, valueId), valueStamp),
|
|
548
548
|
);
|
|
@@ -113,10 +113,10 @@ const visitTree = (node, path, ensureLeaf, pruneLeaf, p = 0) =>
|
|
|
113
113
|
},
|
|
114
114
|
);
|
|
115
115
|
|
|
116
|
-
const stampNewWithHash = (value,
|
|
117
|
-
const stampUpdate = (stamp,
|
|
118
|
-
if (
|
|
119
|
-
stamp[1] =
|
|
116
|
+
const stampNewWithHash = (value, hlc, hash) => [value, hlc, hash];
|
|
117
|
+
const stampUpdate = (stamp, hlc, hash) => {
|
|
118
|
+
if (hlc > stamp[1]) {
|
|
119
|
+
stamp[1] = hlc;
|
|
120
120
|
}
|
|
121
121
|
stamp[2] = hash >>> 0;
|
|
122
122
|
};
|
|
@@ -523,18 +523,18 @@ const createDurableObjectStoragePersister = (
|
|
|
523
523
|
const setPersisted = async (
|
|
524
524
|
getContent,
|
|
525
525
|
[
|
|
526
|
-
[tablesObj,
|
|
527
|
-
[valuesObj,
|
|
526
|
+
[tablesObj, tablesHlc, tablesHash],
|
|
527
|
+
[valuesObj, valuesHlc, valuesHash],
|
|
528
528
|
] = getContent(),
|
|
529
529
|
) => {
|
|
530
530
|
const keysToSet = mapNew();
|
|
531
|
-
mapSet(keysToSet, constructKey(T), [0,
|
|
532
|
-
objForEach(tablesObj, ([tableObj,
|
|
533
|
-
mapSet(keysToSet, constructKey(T, tableId), [0,
|
|
534
|
-
objForEach(tableObj, ([rowObj,
|
|
531
|
+
mapSet(keysToSet, constructKey(T), [0, tablesHlc, tablesHash]);
|
|
532
|
+
objForEach(tablesObj, ([tableObj, tableHlc, tableHash], tableId) => {
|
|
533
|
+
mapSet(keysToSet, constructKey(T, tableId), [0, tableHlc, tableHash]);
|
|
534
|
+
objForEach(tableObj, ([rowObj, rowHlc, rowHash], rowId) => {
|
|
535
535
|
mapSet(keysToSet, constructKey(T, tableId, rowId), [
|
|
536
536
|
0,
|
|
537
|
-
|
|
537
|
+
rowHlc,
|
|
538
538
|
rowHash,
|
|
539
539
|
]);
|
|
540
540
|
objForEach(rowObj, (cellStamp, cellId) =>
|
|
@@ -542,7 +542,7 @@ const createDurableObjectStoragePersister = (
|
|
|
542
542
|
);
|
|
543
543
|
});
|
|
544
544
|
});
|
|
545
|
-
mapSet(keysToSet, constructKey(V), [0,
|
|
545
|
+
mapSet(keysToSet, constructKey(V), [0, valuesHlc, valuesHash]);
|
|
546
546
|
objForEach(valuesObj, (valueStamp, valueId) =>
|
|
547
547
|
mapSet(keysToSet, constructKey(V, valueId), valueStamp),
|
|
548
548
|
);
|