@breeztech/breez-sdk-spark 0.8.0-dev1 → 0.8.2
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/breez-sdk-spark.tgz +0 -0
- package/bundler/breez_sdk_spark_wasm.d.ts +1 -2
- package/bundler/breez_sdk_spark_wasm_bg.js +8 -13
- package/bundler/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/bundler/breez_sdk_spark_wasm_bg.wasm.d.ts +2 -2
- package/bundler/storage/index.js +25 -166
- package/deno/breez_sdk_spark_wasm.d.ts +1 -2
- package/deno/breez_sdk_spark_wasm.js +8 -12
- package/deno/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/deno/breez_sdk_spark_wasm_bg.wasm.d.ts +2 -2
- package/nodejs/breez_sdk_spark_wasm.d.ts +1 -2
- package/nodejs/breez_sdk_spark_wasm.js +8 -13
- package/nodejs/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/nodejs/breez_sdk_spark_wasm_bg.wasm.d.ts +2 -2
- package/nodejs/storage/index.cjs +5 -53
- package/package.json +1 -1
- package/web/breez_sdk_spark_wasm.d.ts +3 -4
- package/web/breez_sdk_spark_wasm.js +8 -12
- package/web/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/web/breez_sdk_spark_wasm_bg.wasm.d.ts +2 -2
- package/web/storage/index.js +25 -166
package/breez-sdk-spark.tgz
CHANGED
|
Binary file
|
|
@@ -371,7 +371,7 @@ export interface RecordChange {
|
|
|
371
371
|
id: RecordId;
|
|
372
372
|
schemaVersion: string;
|
|
373
373
|
updatedFields: Map<string, string>;
|
|
374
|
-
|
|
374
|
+
localRevision: number;
|
|
375
375
|
}
|
|
376
376
|
|
|
377
377
|
export type TokenTransactionType = "transfer" | "mint" | "burn";
|
|
@@ -1019,7 +1019,6 @@ export interface Storage {
|
|
|
1019
1019
|
syncGetLastRevision: () => Promise<number>;
|
|
1020
1020
|
syncInsertIncomingRecords: (records: Record[]) => Promise<void>;
|
|
1021
1021
|
syncDeleteIncomingRecord: (record: Record) => Promise<void>;
|
|
1022
|
-
syncRebasePendingOutgoingRecords: (revision: number) => Promise<void>;
|
|
1023
1022
|
syncGetIncomingRecords: (limit: number) => Promise<IncomingChange[]>;
|
|
1024
1023
|
syncGetLatestOutgoingChange: () => Promise<OutgoingChange | null>;
|
|
1025
1024
|
syncUpdateRecordFromIncoming: (record: Record) => Promise<void>;
|
|
@@ -321,11 +321,11 @@ function __wbg_adapter_64(arg0, arg1) {
|
|
|
321
321
|
}
|
|
322
322
|
|
|
323
323
|
function __wbg_adapter_67(arg0, arg1, arg2) {
|
|
324
|
-
wasm.
|
|
324
|
+
wasm.closure1081_externref_shim(arg0, arg1, arg2);
|
|
325
325
|
}
|
|
326
326
|
|
|
327
|
-
function
|
|
328
|
-
wasm.
|
|
327
|
+
function __wbg_adapter_285(arg0, arg1, arg2, arg3) {
|
|
328
|
+
wasm.closure674_externref_shim(arg0, arg1, arg2, arg3);
|
|
329
329
|
}
|
|
330
330
|
|
|
331
331
|
const __wbindgen_enum_ReadableStreamType = ["bytes"];
|
|
@@ -1876,7 +1876,7 @@ export function __wbg_new_23a2665fac83c611(arg0, arg1) {
|
|
|
1876
1876
|
const a = state0.a;
|
|
1877
1877
|
state0.a = 0;
|
|
1878
1878
|
try {
|
|
1879
|
-
return
|
|
1879
|
+
return __wbg_adapter_285(a, state0.b, arg0, arg1);
|
|
1880
1880
|
} finally {
|
|
1881
1881
|
state0.a = a;
|
|
1882
1882
|
}
|
|
@@ -2288,11 +2288,6 @@ export function __wbg_syncInsertIncomingRecords_dde4039dbc9cb38f() { return hand
|
|
|
2288
2288
|
return ret;
|
|
2289
2289
|
}, arguments) };
|
|
2290
2290
|
|
|
2291
|
-
export function __wbg_syncRebasePendingOutgoingRecords_b3441ced5dee0c8e() { return handleError(function (arg0, arg1) {
|
|
2292
|
-
const ret = arg0.syncRebasePendingOutgoingRecords(BigInt.asUintN(64, arg1));
|
|
2293
|
-
return ret;
|
|
2294
|
-
}, arguments) };
|
|
2295
|
-
|
|
2296
2291
|
export function __wbg_syncUpdateRecordFromIncoming_a76ad82592bfdcb3() { return handleError(function (arg0, arg1) {
|
|
2297
2292
|
const ret = arg0.syncUpdateRecordFromIncoming(arg1);
|
|
2298
2293
|
return ret;
|
|
@@ -2406,13 +2401,13 @@ export function __wbindgen_cb_drop(arg0) {
|
|
|
2406
2401
|
return ret;
|
|
2407
2402
|
};
|
|
2408
2403
|
|
|
2409
|
-
export function
|
|
2410
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
2404
|
+
export function __wbindgen_closure_wrapper11757(arg0, arg1, arg2) {
|
|
2405
|
+
const ret = makeMutClosure(arg0, arg1, 851, __wbg_adapter_64);
|
|
2411
2406
|
return ret;
|
|
2412
2407
|
};
|
|
2413
2408
|
|
|
2414
|
-
export function
|
|
2415
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
2409
|
+
export function __wbindgen_closure_wrapper13706(arg0, arg1, arg2) {
|
|
2410
|
+
const ret = makeMutClosure(arg0, arg1, 1082, __wbg_adapter_67);
|
|
2416
2411
|
return ret;
|
|
2417
2412
|
};
|
|
2418
2413
|
|
|
Binary file
|
|
@@ -114,6 +114,6 @@ export const __externref_drop_slice: (a: number, b: number) => void;
|
|
|
114
114
|
export const __wbindgen_export_7: WebAssembly.Table;
|
|
115
115
|
export const __externref_table_dealloc: (a: number) => void;
|
|
116
116
|
export const _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hf2ef52c8a8b47594: (a: number, b: number) => void;
|
|
117
|
-
export const
|
|
118
|
-
export const
|
|
117
|
+
export const closure1081_externref_shim: (a: number, b: number, c: any) => void;
|
|
118
|
+
export const closure674_externref_shim: (a: number, b: number, c: any, d: any) => void;
|
|
119
119
|
export const __wbindgen_start: () => void;
|
package/bundler/storage/index.js
CHANGED
|
@@ -1280,30 +1280,24 @@ class IndexedDBStorage {
|
|
|
1280
1280
|
}
|
|
1281
1281
|
|
|
1282
1282
|
return new Promise((resolve, reject) => {
|
|
1283
|
-
const transaction = this.db.transaction(
|
|
1284
|
-
["sync_outgoing", "sync_revision"],
|
|
1285
|
-
"readwrite"
|
|
1286
|
-
);
|
|
1283
|
+
const transaction = this.db.transaction(["sync_outgoing"], "readwrite");
|
|
1287
1284
|
|
|
1288
|
-
//
|
|
1289
|
-
const revisionStore = transaction.objectStore("sync_revision");
|
|
1285
|
+
// This revision is a local queue id for pending rows, not a server revision.
|
|
1290
1286
|
const outgoingStore = transaction.objectStore("sync_outgoing");
|
|
1291
|
-
|
|
1292
|
-
const getRevisionRequest = revisionStore.get(1);
|
|
1293
1287
|
const getAllOutgoingRequest = outgoingStore.getAll();
|
|
1294
1288
|
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
const nextRevision =
|
|
1289
|
+
getAllOutgoingRequest.onsuccess = () => {
|
|
1290
|
+
const records = getAllOutgoingRequest.result;
|
|
1291
|
+
let maxOutgoingRevision = BigInt(0);
|
|
1292
|
+
for (const storeRecord of records) {
|
|
1293
|
+
const rev = BigInt(
|
|
1294
|
+
storeRecord.record.localRevision ?? storeRecord.record.revision
|
|
1295
|
+
);
|
|
1296
|
+
if (rev > maxOutgoingRevision) {
|
|
1297
|
+
maxOutgoingRevision = rev;
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
const nextRevision = maxOutgoingRevision + BigInt(1);
|
|
1307
1301
|
|
|
1308
1302
|
const storeRecord = {
|
|
1309
1303
|
type: record.id.type,
|
|
@@ -1311,7 +1305,7 @@ class IndexedDBStorage {
|
|
|
1311
1305
|
revision: Number(nextRevision),
|
|
1312
1306
|
record: {
|
|
1313
1307
|
...record,
|
|
1314
|
-
|
|
1308
|
+
localRevision: nextRevision,
|
|
1315
1309
|
},
|
|
1316
1310
|
};
|
|
1317
1311
|
|
|
@@ -1332,35 +1326,6 @@ class IndexedDBStorage {
|
|
|
1332
1326
|
};
|
|
1333
1327
|
};
|
|
1334
1328
|
|
|
1335
|
-
getRevisionRequest.onsuccess = () => {
|
|
1336
|
-
const revisionData = getRevisionRequest.result || {
|
|
1337
|
-
id: 1,
|
|
1338
|
-
revision: "0",
|
|
1339
|
-
};
|
|
1340
|
-
committedRevision = BigInt(revisionData.revision);
|
|
1341
|
-
onBothReady();
|
|
1342
|
-
};
|
|
1343
|
-
|
|
1344
|
-
getAllOutgoingRequest.onsuccess = () => {
|
|
1345
|
-
const records = getAllOutgoingRequest.result;
|
|
1346
|
-
maxOutgoingRevision = BigInt(0);
|
|
1347
|
-
for (const storeRecord of records) {
|
|
1348
|
-
const rev = BigInt(storeRecord.record.revision);
|
|
1349
|
-
if (rev > maxOutgoingRevision) {
|
|
1350
|
-
maxOutgoingRevision = rev;
|
|
1351
|
-
}
|
|
1352
|
-
}
|
|
1353
|
-
onBothReady();
|
|
1354
|
-
};
|
|
1355
|
-
|
|
1356
|
-
getRevisionRequest.onerror = (event) => {
|
|
1357
|
-
reject(
|
|
1358
|
-
new StorageError(
|
|
1359
|
-
`Failed to get revision: ${event.target.error.message}`
|
|
1360
|
-
)
|
|
1361
|
-
);
|
|
1362
|
-
};
|
|
1363
|
-
|
|
1364
1329
|
getAllOutgoingRequest.onerror = (event) => {
|
|
1365
1330
|
reject(
|
|
1366
1331
|
new StorageError(
|
|
@@ -1459,7 +1424,11 @@ class IndexedDBStorage {
|
|
|
1459
1424
|
const cursor = event.target.result;
|
|
1460
1425
|
if (cursor && count < limit) {
|
|
1461
1426
|
const storeRecord = cursor.value;
|
|
1462
|
-
const change =
|
|
1427
|
+
const change = {
|
|
1428
|
+
...storeRecord.record,
|
|
1429
|
+
localRevision:
|
|
1430
|
+
storeRecord.record.localRevision ?? storeRecord.record.revision,
|
|
1431
|
+
};
|
|
1463
1432
|
|
|
1464
1433
|
// Look up parent record if it exists
|
|
1465
1434
|
const stateRequest = stateStore.get([
|
|
@@ -1599,120 +1568,6 @@ class IndexedDBStorage {
|
|
|
1599
1568
|
});
|
|
1600
1569
|
}
|
|
1601
1570
|
|
|
1602
|
-
async syncRebasePendingOutgoingRecords(revision) {
|
|
1603
|
-
if (!this.db) {
|
|
1604
|
-
throw new StorageError("Database not initialized");
|
|
1605
|
-
}
|
|
1606
|
-
|
|
1607
|
-
return new Promise((resolve, reject) => {
|
|
1608
|
-
const transaction = this.db.transaction(
|
|
1609
|
-
["sync_outgoing", "sync_revision"],
|
|
1610
|
-
"readwrite"
|
|
1611
|
-
);
|
|
1612
|
-
const outgoingStore = transaction.objectStore("sync_outgoing");
|
|
1613
|
-
const revisionStore = transaction.objectStore("sync_revision");
|
|
1614
|
-
|
|
1615
|
-
// Get the last committed revision from sync_revision
|
|
1616
|
-
const getRevisionRequest = revisionStore.get(1);
|
|
1617
|
-
|
|
1618
|
-
getRevisionRequest.onsuccess = () => {
|
|
1619
|
-
const revisionData = getRevisionRequest.result || {
|
|
1620
|
-
id: 1,
|
|
1621
|
-
revision: "0",
|
|
1622
|
-
};
|
|
1623
|
-
const lastRevision = BigInt(revisionData.revision);
|
|
1624
|
-
|
|
1625
|
-
// Calculate the difference
|
|
1626
|
-
const diff = revision > lastRevision ? revision - lastRevision : BigInt(0);
|
|
1627
|
-
|
|
1628
|
-
// Helper to update sync_revision within the same transaction so retries are idempotent
|
|
1629
|
-
const updateSyncRevision = () => {
|
|
1630
|
-
if (revision > lastRevision) {
|
|
1631
|
-
revisionStore.put({ id: 1, revision: revision.toString() });
|
|
1632
|
-
}
|
|
1633
|
-
};
|
|
1634
|
-
|
|
1635
|
-
if (diff <= BigInt(0)) {
|
|
1636
|
-
updateSyncRevision();
|
|
1637
|
-
resolve();
|
|
1638
|
-
return;
|
|
1639
|
-
}
|
|
1640
|
-
|
|
1641
|
-
// Get all records from sync_outgoing and update their revisions
|
|
1642
|
-
const getAllRequest = outgoingStore.getAll();
|
|
1643
|
-
|
|
1644
|
-
getAllRequest.onsuccess = () => {
|
|
1645
|
-
const records = getAllRequest.result;
|
|
1646
|
-
|
|
1647
|
-
if (records.length === 0) {
|
|
1648
|
-
updateSyncRevision();
|
|
1649
|
-
resolve();
|
|
1650
|
-
return;
|
|
1651
|
-
}
|
|
1652
|
-
|
|
1653
|
-
let updatesCompleted = 0;
|
|
1654
|
-
|
|
1655
|
-
for (const storeRecord of records) {
|
|
1656
|
-
// Delete the old record
|
|
1657
|
-
const oldKey = [
|
|
1658
|
-
storeRecord.type,
|
|
1659
|
-
storeRecord.dataId,
|
|
1660
|
-
storeRecord.revision,
|
|
1661
|
-
];
|
|
1662
|
-
outgoingStore.delete(oldKey);
|
|
1663
|
-
|
|
1664
|
-
// Update revision in both the key and the nested record
|
|
1665
|
-
const newRevision = storeRecord.record.revision + diff;
|
|
1666
|
-
const updatedRecord = {
|
|
1667
|
-
type: storeRecord.type,
|
|
1668
|
-
dataId: storeRecord.dataId,
|
|
1669
|
-
revision: Number(newRevision),
|
|
1670
|
-
record: {
|
|
1671
|
-
...storeRecord.record,
|
|
1672
|
-
revision: newRevision,
|
|
1673
|
-
},
|
|
1674
|
-
};
|
|
1675
|
-
|
|
1676
|
-
// Add the updated record
|
|
1677
|
-
const putRequest = outgoingStore.put(updatedRecord);
|
|
1678
|
-
|
|
1679
|
-
putRequest.onsuccess = () => {
|
|
1680
|
-
updatesCompleted++;
|
|
1681
|
-
if (updatesCompleted === records.length) {
|
|
1682
|
-
updateSyncRevision();
|
|
1683
|
-
resolve();
|
|
1684
|
-
}
|
|
1685
|
-
};
|
|
1686
|
-
|
|
1687
|
-
putRequest.onerror = (event) => {
|
|
1688
|
-
reject(
|
|
1689
|
-
new StorageError(
|
|
1690
|
-
`Failed to rebase outgoing record: ${event.target.error.message}`
|
|
1691
|
-
)
|
|
1692
|
-
);
|
|
1693
|
-
};
|
|
1694
|
-
}
|
|
1695
|
-
};
|
|
1696
|
-
|
|
1697
|
-
getAllRequest.onerror = (event) => {
|
|
1698
|
-
reject(
|
|
1699
|
-
new StorageError(
|
|
1700
|
-
`Failed to get outgoing records for rebase: ${event.target.error.message}`
|
|
1701
|
-
)
|
|
1702
|
-
);
|
|
1703
|
-
};
|
|
1704
|
-
};
|
|
1705
|
-
|
|
1706
|
-
getRevisionRequest.onerror = (event) => {
|
|
1707
|
-
reject(
|
|
1708
|
-
new StorageError(
|
|
1709
|
-
`Failed to get last revision: ${event.target.error.message}`
|
|
1710
|
-
)
|
|
1711
|
-
);
|
|
1712
|
-
};
|
|
1713
|
-
});
|
|
1714
|
-
}
|
|
1715
|
-
|
|
1716
1571
|
async syncGetIncomingRecords(limit) {
|
|
1717
1572
|
if (!this.db) {
|
|
1718
1573
|
throw new StorageError("Database not initialized");
|
|
@@ -1802,7 +1657,11 @@ class IndexedDBStorage {
|
|
|
1802
1657
|
const cursor = event.target.result;
|
|
1803
1658
|
if (cursor) {
|
|
1804
1659
|
const storeRecord = cursor.value;
|
|
1805
|
-
const change =
|
|
1660
|
+
const change = {
|
|
1661
|
+
...storeRecord.record,
|
|
1662
|
+
localRevision:
|
|
1663
|
+
storeRecord.record.localRevision ?? storeRecord.record.revision,
|
|
1664
|
+
};
|
|
1806
1665
|
|
|
1807
1666
|
// Get the parent record
|
|
1808
1667
|
const stateRequest = stateStore.get([
|
|
@@ -371,7 +371,7 @@ export interface RecordChange {
|
|
|
371
371
|
id: RecordId;
|
|
372
372
|
schemaVersion: string;
|
|
373
373
|
updatedFields: Map<string, string>;
|
|
374
|
-
|
|
374
|
+
localRevision: number;
|
|
375
375
|
}
|
|
376
376
|
|
|
377
377
|
export type TokenTransactionType = "transfer" | "mint" | "burn";
|
|
@@ -1019,7 +1019,6 @@ export interface Storage {
|
|
|
1019
1019
|
syncGetLastRevision: () => Promise<number>;
|
|
1020
1020
|
syncInsertIncomingRecords: (records: Record[]) => Promise<void>;
|
|
1021
1021
|
syncDeleteIncomingRecord: (record: Record) => Promise<void>;
|
|
1022
|
-
syncRebasePendingOutgoingRecords: (revision: number) => Promise<void>;
|
|
1023
1022
|
syncGetIncomingRecords: (limit: number) => Promise<IncomingChange[]>;
|
|
1024
1023
|
syncGetLatestOutgoingChange: () => Promise<OutgoingChange | null>;
|
|
1025
1024
|
syncUpdateRecordFromIncoming: (record: Record) => Promise<void>;
|
|
@@ -304,11 +304,11 @@ function __wbg_adapter_64(arg0, arg1) {
|
|
|
304
304
|
}
|
|
305
305
|
|
|
306
306
|
function __wbg_adapter_67(arg0, arg1, arg2) {
|
|
307
|
-
wasm.
|
|
307
|
+
wasm.closure1081_externref_shim(arg0, arg1, arg2);
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
-
function
|
|
311
|
-
wasm.
|
|
310
|
+
function __wbg_adapter_285(arg0, arg1, arg2, arg3) {
|
|
311
|
+
wasm.closure674_externref_shim(arg0, arg1, arg2, arg3);
|
|
312
312
|
}
|
|
313
313
|
|
|
314
314
|
const __wbindgen_enum_ReadableStreamType = ["bytes"];
|
|
@@ -1768,7 +1768,7 @@ const imports = {
|
|
|
1768
1768
|
const a = state0.a;
|
|
1769
1769
|
state0.a = 0;
|
|
1770
1770
|
try {
|
|
1771
|
-
return
|
|
1771
|
+
return __wbg_adapter_285(a, state0.b, arg0, arg1);
|
|
1772
1772
|
} finally {
|
|
1773
1773
|
state0.a = a;
|
|
1774
1774
|
}
|
|
@@ -2106,10 +2106,6 @@ const imports = {
|
|
|
2106
2106
|
const ret = arg0.syncInsertIncomingRecords(v0);
|
|
2107
2107
|
return ret;
|
|
2108
2108
|
}, arguments) },
|
|
2109
|
-
__wbg_syncRebasePendingOutgoingRecords_b3441ced5dee0c8e: function() { return handleError(function (arg0, arg1) {
|
|
2110
|
-
const ret = arg0.syncRebasePendingOutgoingRecords(BigInt.asUintN(64, arg1));
|
|
2111
|
-
return ret;
|
|
2112
|
-
}, arguments) },
|
|
2113
2109
|
__wbg_syncUpdateRecordFromIncoming_a76ad82592bfdcb3: function() { return handleError(function (arg0, arg1) {
|
|
2114
2110
|
const ret = arg0.syncUpdateRecordFromIncoming(arg1);
|
|
2115
2111
|
return ret;
|
|
@@ -2204,12 +2200,12 @@ const imports = {
|
|
|
2204
2200
|
const ret = false;
|
|
2205
2201
|
return ret;
|
|
2206
2202
|
},
|
|
2207
|
-
|
|
2208
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
2203
|
+
__wbindgen_closure_wrapper11757: function(arg0, arg1, arg2) {
|
|
2204
|
+
const ret = makeMutClosure(arg0, arg1, 851, __wbg_adapter_64);
|
|
2209
2205
|
return ret;
|
|
2210
2206
|
},
|
|
2211
|
-
|
|
2212
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
2207
|
+
__wbindgen_closure_wrapper13706: function(arg0, arg1, arg2) {
|
|
2208
|
+
const ret = makeMutClosure(arg0, arg1, 1082, __wbg_adapter_67);
|
|
2213
2209
|
return ret;
|
|
2214
2210
|
},
|
|
2215
2211
|
__wbindgen_debug_string: function(arg0, arg1) {
|
|
Binary file
|
|
@@ -114,6 +114,6 @@ export const __externref_drop_slice: (a: number, b: number) => void;
|
|
|
114
114
|
export const __wbindgen_export_7: WebAssembly.Table;
|
|
115
115
|
export const __externref_table_dealloc: (a: number) => void;
|
|
116
116
|
export const _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hf2ef52c8a8b47594: (a: number, b: number) => void;
|
|
117
|
-
export const
|
|
118
|
-
export const
|
|
117
|
+
export const closure1081_externref_shim: (a: number, b: number, c: any) => void;
|
|
118
|
+
export const closure674_externref_shim: (a: number, b: number, c: any, d: any) => void;
|
|
119
119
|
export const __wbindgen_start: () => void;
|
|
@@ -371,7 +371,7 @@ export interface RecordChange {
|
|
|
371
371
|
id: RecordId;
|
|
372
372
|
schemaVersion: string;
|
|
373
373
|
updatedFields: Map<string, string>;
|
|
374
|
-
|
|
374
|
+
localRevision: number;
|
|
375
375
|
}
|
|
376
376
|
|
|
377
377
|
export type TokenTransactionType = "transfer" | "mint" | "burn";
|
|
@@ -1019,7 +1019,6 @@ export interface Storage {
|
|
|
1019
1019
|
syncGetLastRevision: () => Promise<number>;
|
|
1020
1020
|
syncInsertIncomingRecords: (records: Record[]) => Promise<void>;
|
|
1021
1021
|
syncDeleteIncomingRecord: (record: Record) => Promise<void>;
|
|
1022
|
-
syncRebasePendingOutgoingRecords: (revision: number) => Promise<void>;
|
|
1023
1022
|
syncGetIncomingRecords: (limit: number) => Promise<IncomingChange[]>;
|
|
1024
1023
|
syncGetLatestOutgoingChange: () => Promise<OutgoingChange | null>;
|
|
1025
1024
|
syncUpdateRecordFromIncoming: (record: Record) => Promise<void>;
|
|
@@ -317,11 +317,11 @@ function __wbg_adapter_64(arg0, arg1) {
|
|
|
317
317
|
}
|
|
318
318
|
|
|
319
319
|
function __wbg_adapter_67(arg0, arg1, arg2) {
|
|
320
|
-
wasm.
|
|
320
|
+
wasm.closure1081_externref_shim(arg0, arg1, arg2);
|
|
321
321
|
}
|
|
322
322
|
|
|
323
|
-
function
|
|
324
|
-
wasm.
|
|
323
|
+
function __wbg_adapter_285(arg0, arg1, arg2, arg3) {
|
|
324
|
+
wasm.closure674_externref_shim(arg0, arg1, arg2, arg3);
|
|
325
325
|
}
|
|
326
326
|
|
|
327
327
|
const __wbindgen_enum_ReadableStreamType = ["bytes"];
|
|
@@ -1879,7 +1879,7 @@ module.exports.__wbg_new_23a2665fac83c611 = function(arg0, arg1) {
|
|
|
1879
1879
|
const a = state0.a;
|
|
1880
1880
|
state0.a = 0;
|
|
1881
1881
|
try {
|
|
1882
|
-
return
|
|
1882
|
+
return __wbg_adapter_285(a, state0.b, arg0, arg1);
|
|
1883
1883
|
} finally {
|
|
1884
1884
|
state0.a = a;
|
|
1885
1885
|
}
|
|
@@ -2291,11 +2291,6 @@ module.exports.__wbg_syncInsertIncomingRecords_dde4039dbc9cb38f = function() { r
|
|
|
2291
2291
|
return ret;
|
|
2292
2292
|
}, arguments) };
|
|
2293
2293
|
|
|
2294
|
-
module.exports.__wbg_syncRebasePendingOutgoingRecords_b3441ced5dee0c8e = function() { return handleError(function (arg0, arg1) {
|
|
2295
|
-
const ret = arg0.syncRebasePendingOutgoingRecords(BigInt.asUintN(64, arg1));
|
|
2296
|
-
return ret;
|
|
2297
|
-
}, arguments) };
|
|
2298
|
-
|
|
2299
2294
|
module.exports.__wbg_syncUpdateRecordFromIncoming_a76ad82592bfdcb3 = function() { return handleError(function (arg0, arg1) {
|
|
2300
2295
|
const ret = arg0.syncUpdateRecordFromIncoming(arg1);
|
|
2301
2296
|
return ret;
|
|
@@ -2409,13 +2404,13 @@ module.exports.__wbindgen_cb_drop = function(arg0) {
|
|
|
2409
2404
|
return ret;
|
|
2410
2405
|
};
|
|
2411
2406
|
|
|
2412
|
-
module.exports.
|
|
2413
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
2407
|
+
module.exports.__wbindgen_closure_wrapper11757 = function(arg0, arg1, arg2) {
|
|
2408
|
+
const ret = makeMutClosure(arg0, arg1, 851, __wbg_adapter_64);
|
|
2414
2409
|
return ret;
|
|
2415
2410
|
};
|
|
2416
2411
|
|
|
2417
|
-
module.exports.
|
|
2418
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
2412
|
+
module.exports.__wbindgen_closure_wrapper13706 = function(arg0, arg1, arg2) {
|
|
2413
|
+
const ret = makeMutClosure(arg0, arg1, 1082, __wbg_adapter_67);
|
|
2419
2414
|
return ret;
|
|
2420
2415
|
};
|
|
2421
2416
|
|
|
Binary file
|
|
@@ -114,6 +114,6 @@ export const __externref_drop_slice: (a: number, b: number) => void;
|
|
|
114
114
|
export const __wbindgen_export_7: WebAssembly.Table;
|
|
115
115
|
export const __externref_table_dealloc: (a: number) => void;
|
|
116
116
|
export const _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hf2ef52c8a8b47594: (a: number, b: number) => void;
|
|
117
|
-
export const
|
|
118
|
-
export const
|
|
117
|
+
export const closure1081_externref_shim: (a: number, b: number, c: any) => void;
|
|
118
|
+
export const closure674_externref_shim: (a: number, b: number, c: any, d: any) => void;
|
|
119
119
|
export const __wbindgen_start: () => void;
|
package/nodejs/storage/index.cjs
CHANGED
|
@@ -798,14 +798,10 @@ class SqliteStorage {
|
|
|
798
798
|
syncAddOutgoingChange(record) {
|
|
799
799
|
try {
|
|
800
800
|
const transaction = this.db.transaction(() => {
|
|
801
|
-
//
|
|
801
|
+
// This revision is a local queue id for pending rows, not a server revision.
|
|
802
802
|
const revisionQuery = this.db.prepare(`
|
|
803
|
-
SELECT CAST(
|
|
804
|
-
|
|
805
|
-
(SELECT revision FROM sync_revision),
|
|
806
|
-
COALESCE((SELECT MAX(revision) FROM sync_outgoing), 0)
|
|
807
|
-
) + 1
|
|
808
|
-
AS TEXT) AS revision
|
|
803
|
+
SELECT CAST(COALESCE(MAX(revision), 0) + 1 AS TEXT) AS revision
|
|
804
|
+
FROM sync_outgoing
|
|
809
805
|
`);
|
|
810
806
|
const revision = BigInt(revisionQuery.get().revision);
|
|
811
807
|
|
|
@@ -931,7 +927,7 @@ class SqliteStorage {
|
|
|
931
927
|
},
|
|
932
928
|
schemaVersion: row.schema_version,
|
|
933
929
|
updatedFields: JSON.parse(row.updated_fields_json),
|
|
934
|
-
|
|
930
|
+
localRevision: BigInt(row.revision),
|
|
935
931
|
};
|
|
936
932
|
|
|
937
933
|
let parent = null;
|
|
@@ -1042,50 +1038,6 @@ class SqliteStorage {
|
|
|
1042
1038
|
}
|
|
1043
1039
|
}
|
|
1044
1040
|
|
|
1045
|
-
syncRebasePendingOutgoingRecords(revision) {
|
|
1046
|
-
try {
|
|
1047
|
-
const transaction = this.db.transaction(() => {
|
|
1048
|
-
// Get current committed revision from sync_revision table
|
|
1049
|
-
const getLastRevisionStmt = this.db.prepare(`
|
|
1050
|
-
SELECT CAST(revision AS TEXT) as last_revision FROM sync_revision
|
|
1051
|
-
`);
|
|
1052
|
-
const revisionRow = getLastRevisionStmt.get();
|
|
1053
|
-
const lastRevision = revisionRow
|
|
1054
|
-
? BigInt(revisionRow.last_revision)
|
|
1055
|
-
: BigInt(0);
|
|
1056
|
-
|
|
1057
|
-
// Calculate the difference to add to all revision numbers
|
|
1058
|
-
const diff =
|
|
1059
|
-
revision > lastRevision ? revision - lastRevision : BigInt(0);
|
|
1060
|
-
|
|
1061
|
-
if (diff > BigInt(0)) {
|
|
1062
|
-
// Update all pending outgoing records
|
|
1063
|
-
const updateRecordsStmt = this.db.prepare(`
|
|
1064
|
-
UPDATE sync_outgoing
|
|
1065
|
-
SET revision = revision + CAST(? AS INTEGER)
|
|
1066
|
-
`);
|
|
1067
|
-
updateRecordsStmt.run(diff.toString());
|
|
1068
|
-
}
|
|
1069
|
-
|
|
1070
|
-
// Update sync_revision within the same transaction so retries are idempotent
|
|
1071
|
-
const updateRevisionStmt = this.db.prepare(`
|
|
1072
|
-
UPDATE sync_revision SET revision = MAX(revision, CAST(? AS INTEGER))
|
|
1073
|
-
`);
|
|
1074
|
-
updateRevisionStmt.run(revision.toString());
|
|
1075
|
-
});
|
|
1076
|
-
|
|
1077
|
-
transaction();
|
|
1078
|
-
return Promise.resolve();
|
|
1079
|
-
} catch (error) {
|
|
1080
|
-
return Promise.reject(
|
|
1081
|
-
new StorageError(
|
|
1082
|
-
`Failed to rebase pending outgoing records: ${error.message}`,
|
|
1083
|
-
error
|
|
1084
|
-
)
|
|
1085
|
-
);
|
|
1086
|
-
}
|
|
1087
|
-
}
|
|
1088
|
-
|
|
1089
1041
|
syncGetIncomingRecords(limit) {
|
|
1090
1042
|
try {
|
|
1091
1043
|
const transaction = this.db.transaction(() => {
|
|
@@ -1191,7 +1143,7 @@ class SqliteStorage {
|
|
|
1191
1143
|
},
|
|
1192
1144
|
schemaVersion: row.schema_version,
|
|
1193
1145
|
updatedFields: JSON.parse(row.updated_fields_json),
|
|
1194
|
-
|
|
1146
|
+
localRevision: BigInt(row.revision),
|
|
1195
1147
|
};
|
|
1196
1148
|
|
|
1197
1149
|
let parent = null;
|
package/package.json
CHANGED
|
@@ -371,7 +371,7 @@ export interface RecordChange {
|
|
|
371
371
|
id: RecordId;
|
|
372
372
|
schemaVersion: string;
|
|
373
373
|
updatedFields: Map<string, string>;
|
|
374
|
-
|
|
374
|
+
localRevision: number;
|
|
375
375
|
}
|
|
376
376
|
|
|
377
377
|
export type TokenTransactionType = "transfer" | "mint" | "burn";
|
|
@@ -1019,7 +1019,6 @@ export interface Storage {
|
|
|
1019
1019
|
syncGetLastRevision: () => Promise<number>;
|
|
1020
1020
|
syncInsertIncomingRecords: (records: Record[]) => Promise<void>;
|
|
1021
1021
|
syncDeleteIncomingRecord: (record: Record) => Promise<void>;
|
|
1022
|
-
syncRebasePendingOutgoingRecords: (revision: number) => Promise<void>;
|
|
1023
1022
|
syncGetIncomingRecords: (limit: number) => Promise<IncomingChange[]>;
|
|
1024
1023
|
syncGetLatestOutgoingChange: () => Promise<OutgoingChange | null>;
|
|
1025
1024
|
syncUpdateRecordFromIncoming: (record: Record) => Promise<void>;
|
|
@@ -1260,8 +1259,8 @@ export interface InitOutput {
|
|
|
1260
1259
|
readonly __wbindgen_export_7: WebAssembly.Table;
|
|
1261
1260
|
readonly __externref_table_dealloc: (a: number) => void;
|
|
1262
1261
|
readonly _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hf2ef52c8a8b47594: (a: number, b: number) => void;
|
|
1263
|
-
readonly
|
|
1264
|
-
readonly
|
|
1262
|
+
readonly closure1081_externref_shim: (a: number, b: number, c: any) => void;
|
|
1263
|
+
readonly closure674_externref_shim: (a: number, b: number, c: any, d: any) => void;
|
|
1265
1264
|
readonly __wbindgen_start: () => void;
|
|
1266
1265
|
}
|
|
1267
1266
|
|
|
@@ -313,11 +313,11 @@ function __wbg_adapter_64(arg0, arg1) {
|
|
|
313
313
|
}
|
|
314
314
|
|
|
315
315
|
function __wbg_adapter_67(arg0, arg1, arg2) {
|
|
316
|
-
wasm.
|
|
316
|
+
wasm.closure1081_externref_shim(arg0, arg1, arg2);
|
|
317
317
|
}
|
|
318
318
|
|
|
319
|
-
function
|
|
320
|
-
wasm.
|
|
319
|
+
function __wbg_adapter_285(arg0, arg1, arg2, arg3) {
|
|
320
|
+
wasm.closure674_externref_shim(arg0, arg1, arg2, arg3);
|
|
321
321
|
}
|
|
322
322
|
|
|
323
323
|
const __wbindgen_enum_ReadableStreamType = ["bytes"];
|
|
@@ -1809,7 +1809,7 @@ function __wbg_get_imports() {
|
|
|
1809
1809
|
const a = state0.a;
|
|
1810
1810
|
state0.a = 0;
|
|
1811
1811
|
try {
|
|
1812
|
-
return
|
|
1812
|
+
return __wbg_adapter_285(a, state0.b, arg0, arg1);
|
|
1813
1813
|
} finally {
|
|
1814
1814
|
state0.a = a;
|
|
1815
1815
|
}
|
|
@@ -2147,10 +2147,6 @@ function __wbg_get_imports() {
|
|
|
2147
2147
|
const ret = arg0.syncInsertIncomingRecords(v0);
|
|
2148
2148
|
return ret;
|
|
2149
2149
|
}, arguments) };
|
|
2150
|
-
imports.wbg.__wbg_syncRebasePendingOutgoingRecords_b3441ced5dee0c8e = function() { return handleError(function (arg0, arg1) {
|
|
2151
|
-
const ret = arg0.syncRebasePendingOutgoingRecords(BigInt.asUintN(64, arg1));
|
|
2152
|
-
return ret;
|
|
2153
|
-
}, arguments) };
|
|
2154
2150
|
imports.wbg.__wbg_syncUpdateRecordFromIncoming_a76ad82592bfdcb3 = function() { return handleError(function (arg0, arg1) {
|
|
2155
2151
|
const ret = arg0.syncUpdateRecordFromIncoming(arg1);
|
|
2156
2152
|
return ret;
|
|
@@ -2245,12 +2241,12 @@ function __wbg_get_imports() {
|
|
|
2245
2241
|
const ret = false;
|
|
2246
2242
|
return ret;
|
|
2247
2243
|
};
|
|
2248
|
-
imports.wbg.
|
|
2249
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
2244
|
+
imports.wbg.__wbindgen_closure_wrapper11757 = function(arg0, arg1, arg2) {
|
|
2245
|
+
const ret = makeMutClosure(arg0, arg1, 851, __wbg_adapter_64);
|
|
2250
2246
|
return ret;
|
|
2251
2247
|
};
|
|
2252
|
-
imports.wbg.
|
|
2253
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
2248
|
+
imports.wbg.__wbindgen_closure_wrapper13706 = function(arg0, arg1, arg2) {
|
|
2249
|
+
const ret = makeMutClosure(arg0, arg1, 1082, __wbg_adapter_67);
|
|
2254
2250
|
return ret;
|
|
2255
2251
|
};
|
|
2256
2252
|
imports.wbg.__wbindgen_debug_string = function(arg0, arg1) {
|
|
Binary file
|
|
@@ -114,6 +114,6 @@ export const __externref_drop_slice: (a: number, b: number) => void;
|
|
|
114
114
|
export const __wbindgen_export_7: WebAssembly.Table;
|
|
115
115
|
export const __externref_table_dealloc: (a: number) => void;
|
|
116
116
|
export const _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hf2ef52c8a8b47594: (a: number, b: number) => void;
|
|
117
|
-
export const
|
|
118
|
-
export const
|
|
117
|
+
export const closure1081_externref_shim: (a: number, b: number, c: any) => void;
|
|
118
|
+
export const closure674_externref_shim: (a: number, b: number, c: any, d: any) => void;
|
|
119
119
|
export const __wbindgen_start: () => void;
|
package/web/storage/index.js
CHANGED
|
@@ -1280,30 +1280,24 @@ class IndexedDBStorage {
|
|
|
1280
1280
|
}
|
|
1281
1281
|
|
|
1282
1282
|
return new Promise((resolve, reject) => {
|
|
1283
|
-
const transaction = this.db.transaction(
|
|
1284
|
-
["sync_outgoing", "sync_revision"],
|
|
1285
|
-
"readwrite"
|
|
1286
|
-
);
|
|
1283
|
+
const transaction = this.db.transaction(["sync_outgoing"], "readwrite");
|
|
1287
1284
|
|
|
1288
|
-
//
|
|
1289
|
-
const revisionStore = transaction.objectStore("sync_revision");
|
|
1285
|
+
// This revision is a local queue id for pending rows, not a server revision.
|
|
1290
1286
|
const outgoingStore = transaction.objectStore("sync_outgoing");
|
|
1291
|
-
|
|
1292
|
-
const getRevisionRequest = revisionStore.get(1);
|
|
1293
1287
|
const getAllOutgoingRequest = outgoingStore.getAll();
|
|
1294
1288
|
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
const nextRevision =
|
|
1289
|
+
getAllOutgoingRequest.onsuccess = () => {
|
|
1290
|
+
const records = getAllOutgoingRequest.result;
|
|
1291
|
+
let maxOutgoingRevision = BigInt(0);
|
|
1292
|
+
for (const storeRecord of records) {
|
|
1293
|
+
const rev = BigInt(
|
|
1294
|
+
storeRecord.record.localRevision ?? storeRecord.record.revision
|
|
1295
|
+
);
|
|
1296
|
+
if (rev > maxOutgoingRevision) {
|
|
1297
|
+
maxOutgoingRevision = rev;
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
const nextRevision = maxOutgoingRevision + BigInt(1);
|
|
1307
1301
|
|
|
1308
1302
|
const storeRecord = {
|
|
1309
1303
|
type: record.id.type,
|
|
@@ -1311,7 +1305,7 @@ class IndexedDBStorage {
|
|
|
1311
1305
|
revision: Number(nextRevision),
|
|
1312
1306
|
record: {
|
|
1313
1307
|
...record,
|
|
1314
|
-
|
|
1308
|
+
localRevision: nextRevision,
|
|
1315
1309
|
},
|
|
1316
1310
|
};
|
|
1317
1311
|
|
|
@@ -1332,35 +1326,6 @@ class IndexedDBStorage {
|
|
|
1332
1326
|
};
|
|
1333
1327
|
};
|
|
1334
1328
|
|
|
1335
|
-
getRevisionRequest.onsuccess = () => {
|
|
1336
|
-
const revisionData = getRevisionRequest.result || {
|
|
1337
|
-
id: 1,
|
|
1338
|
-
revision: "0",
|
|
1339
|
-
};
|
|
1340
|
-
committedRevision = BigInt(revisionData.revision);
|
|
1341
|
-
onBothReady();
|
|
1342
|
-
};
|
|
1343
|
-
|
|
1344
|
-
getAllOutgoingRequest.onsuccess = () => {
|
|
1345
|
-
const records = getAllOutgoingRequest.result;
|
|
1346
|
-
maxOutgoingRevision = BigInt(0);
|
|
1347
|
-
for (const storeRecord of records) {
|
|
1348
|
-
const rev = BigInt(storeRecord.record.revision);
|
|
1349
|
-
if (rev > maxOutgoingRevision) {
|
|
1350
|
-
maxOutgoingRevision = rev;
|
|
1351
|
-
}
|
|
1352
|
-
}
|
|
1353
|
-
onBothReady();
|
|
1354
|
-
};
|
|
1355
|
-
|
|
1356
|
-
getRevisionRequest.onerror = (event) => {
|
|
1357
|
-
reject(
|
|
1358
|
-
new StorageError(
|
|
1359
|
-
`Failed to get revision: ${event.target.error.message}`
|
|
1360
|
-
)
|
|
1361
|
-
);
|
|
1362
|
-
};
|
|
1363
|
-
|
|
1364
1329
|
getAllOutgoingRequest.onerror = (event) => {
|
|
1365
1330
|
reject(
|
|
1366
1331
|
new StorageError(
|
|
@@ -1459,7 +1424,11 @@ class IndexedDBStorage {
|
|
|
1459
1424
|
const cursor = event.target.result;
|
|
1460
1425
|
if (cursor && count < limit) {
|
|
1461
1426
|
const storeRecord = cursor.value;
|
|
1462
|
-
const change =
|
|
1427
|
+
const change = {
|
|
1428
|
+
...storeRecord.record,
|
|
1429
|
+
localRevision:
|
|
1430
|
+
storeRecord.record.localRevision ?? storeRecord.record.revision,
|
|
1431
|
+
};
|
|
1463
1432
|
|
|
1464
1433
|
// Look up parent record if it exists
|
|
1465
1434
|
const stateRequest = stateStore.get([
|
|
@@ -1599,120 +1568,6 @@ class IndexedDBStorage {
|
|
|
1599
1568
|
});
|
|
1600
1569
|
}
|
|
1601
1570
|
|
|
1602
|
-
async syncRebasePendingOutgoingRecords(revision) {
|
|
1603
|
-
if (!this.db) {
|
|
1604
|
-
throw new StorageError("Database not initialized");
|
|
1605
|
-
}
|
|
1606
|
-
|
|
1607
|
-
return new Promise((resolve, reject) => {
|
|
1608
|
-
const transaction = this.db.transaction(
|
|
1609
|
-
["sync_outgoing", "sync_revision"],
|
|
1610
|
-
"readwrite"
|
|
1611
|
-
);
|
|
1612
|
-
const outgoingStore = transaction.objectStore("sync_outgoing");
|
|
1613
|
-
const revisionStore = transaction.objectStore("sync_revision");
|
|
1614
|
-
|
|
1615
|
-
// Get the last committed revision from sync_revision
|
|
1616
|
-
const getRevisionRequest = revisionStore.get(1);
|
|
1617
|
-
|
|
1618
|
-
getRevisionRequest.onsuccess = () => {
|
|
1619
|
-
const revisionData = getRevisionRequest.result || {
|
|
1620
|
-
id: 1,
|
|
1621
|
-
revision: "0",
|
|
1622
|
-
};
|
|
1623
|
-
const lastRevision = BigInt(revisionData.revision);
|
|
1624
|
-
|
|
1625
|
-
// Calculate the difference
|
|
1626
|
-
const diff = revision > lastRevision ? revision - lastRevision : BigInt(0);
|
|
1627
|
-
|
|
1628
|
-
// Helper to update sync_revision within the same transaction so retries are idempotent
|
|
1629
|
-
const updateSyncRevision = () => {
|
|
1630
|
-
if (revision > lastRevision) {
|
|
1631
|
-
revisionStore.put({ id: 1, revision: revision.toString() });
|
|
1632
|
-
}
|
|
1633
|
-
};
|
|
1634
|
-
|
|
1635
|
-
if (diff <= BigInt(0)) {
|
|
1636
|
-
updateSyncRevision();
|
|
1637
|
-
resolve();
|
|
1638
|
-
return;
|
|
1639
|
-
}
|
|
1640
|
-
|
|
1641
|
-
// Get all records from sync_outgoing and update their revisions
|
|
1642
|
-
const getAllRequest = outgoingStore.getAll();
|
|
1643
|
-
|
|
1644
|
-
getAllRequest.onsuccess = () => {
|
|
1645
|
-
const records = getAllRequest.result;
|
|
1646
|
-
|
|
1647
|
-
if (records.length === 0) {
|
|
1648
|
-
updateSyncRevision();
|
|
1649
|
-
resolve();
|
|
1650
|
-
return;
|
|
1651
|
-
}
|
|
1652
|
-
|
|
1653
|
-
let updatesCompleted = 0;
|
|
1654
|
-
|
|
1655
|
-
for (const storeRecord of records) {
|
|
1656
|
-
// Delete the old record
|
|
1657
|
-
const oldKey = [
|
|
1658
|
-
storeRecord.type,
|
|
1659
|
-
storeRecord.dataId,
|
|
1660
|
-
storeRecord.revision,
|
|
1661
|
-
];
|
|
1662
|
-
outgoingStore.delete(oldKey);
|
|
1663
|
-
|
|
1664
|
-
// Update revision in both the key and the nested record
|
|
1665
|
-
const newRevision = storeRecord.record.revision + diff;
|
|
1666
|
-
const updatedRecord = {
|
|
1667
|
-
type: storeRecord.type,
|
|
1668
|
-
dataId: storeRecord.dataId,
|
|
1669
|
-
revision: Number(newRevision),
|
|
1670
|
-
record: {
|
|
1671
|
-
...storeRecord.record,
|
|
1672
|
-
revision: newRevision,
|
|
1673
|
-
},
|
|
1674
|
-
};
|
|
1675
|
-
|
|
1676
|
-
// Add the updated record
|
|
1677
|
-
const putRequest = outgoingStore.put(updatedRecord);
|
|
1678
|
-
|
|
1679
|
-
putRequest.onsuccess = () => {
|
|
1680
|
-
updatesCompleted++;
|
|
1681
|
-
if (updatesCompleted === records.length) {
|
|
1682
|
-
updateSyncRevision();
|
|
1683
|
-
resolve();
|
|
1684
|
-
}
|
|
1685
|
-
};
|
|
1686
|
-
|
|
1687
|
-
putRequest.onerror = (event) => {
|
|
1688
|
-
reject(
|
|
1689
|
-
new StorageError(
|
|
1690
|
-
`Failed to rebase outgoing record: ${event.target.error.message}`
|
|
1691
|
-
)
|
|
1692
|
-
);
|
|
1693
|
-
};
|
|
1694
|
-
}
|
|
1695
|
-
};
|
|
1696
|
-
|
|
1697
|
-
getAllRequest.onerror = (event) => {
|
|
1698
|
-
reject(
|
|
1699
|
-
new StorageError(
|
|
1700
|
-
`Failed to get outgoing records for rebase: ${event.target.error.message}`
|
|
1701
|
-
)
|
|
1702
|
-
);
|
|
1703
|
-
};
|
|
1704
|
-
};
|
|
1705
|
-
|
|
1706
|
-
getRevisionRequest.onerror = (event) => {
|
|
1707
|
-
reject(
|
|
1708
|
-
new StorageError(
|
|
1709
|
-
`Failed to get last revision: ${event.target.error.message}`
|
|
1710
|
-
)
|
|
1711
|
-
);
|
|
1712
|
-
};
|
|
1713
|
-
});
|
|
1714
|
-
}
|
|
1715
|
-
|
|
1716
1571
|
async syncGetIncomingRecords(limit) {
|
|
1717
1572
|
if (!this.db) {
|
|
1718
1573
|
throw new StorageError("Database not initialized");
|
|
@@ -1802,7 +1657,11 @@ class IndexedDBStorage {
|
|
|
1802
1657
|
const cursor = event.target.result;
|
|
1803
1658
|
if (cursor) {
|
|
1804
1659
|
const storeRecord = cursor.value;
|
|
1805
|
-
const change =
|
|
1660
|
+
const change = {
|
|
1661
|
+
...storeRecord.record,
|
|
1662
|
+
localRevision:
|
|
1663
|
+
storeRecord.record.localRevision ?? storeRecord.record.revision,
|
|
1664
|
+
};
|
|
1806
1665
|
|
|
1807
1666
|
// Get the parent record
|
|
1808
1667
|
const stateRequest = stateStore.get([
|