@spooky-sync/core 0.0.1-canary.20 → 0.0.1-canary.22
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/dist/index.js +6 -8
- package/package.json +1 -1
- package/src/modules/sync/engine.ts +10 -7
- package/src/modules/sync/sync.ts +0 -1
- package/src/modules/sync/utils.ts +0 -1
package/dist/index.js
CHANGED
|
@@ -1514,7 +1514,6 @@ var ArraySyncer = class {
|
|
|
1514
1514
|
this.localArray.sort((a, b) => a[0].localeCompare(b[0]));
|
|
1515
1515
|
this.needsSort = false;
|
|
1516
1516
|
}
|
|
1517
|
-
console.log("xxxx555", this.localArray, this.remoteArray);
|
|
1518
1517
|
return diffRecordVersionArray(this.localArray, this.remoteArray);
|
|
1519
1518
|
}
|
|
1520
1519
|
};
|
|
@@ -1609,18 +1608,18 @@ var SyncEngine = class {
|
|
|
1609
1608
|
if (removed.length > 0) await this.handleRemovedRecords(removed);
|
|
1610
1609
|
const idsToFetch = [...added, ...updated].map((x) => x.id);
|
|
1611
1610
|
if (idsToFetch.length === 0) return;
|
|
1612
|
-
const [remoteResults] = await this.remote.query("SELECT
|
|
1613
|
-
console.log("remoteResults>", remoteResults);
|
|
1611
|
+
const [remoteResults] = await this.remote.query("SELECT *, (SELECT version FROM ONLY _spooky_version WHERE record_id = $parent.id)['version'] as spooky_rv FROM $idsToFetch", { idsToFetch });
|
|
1614
1612
|
const cacheBatch = [];
|
|
1615
|
-
for (const
|
|
1616
|
-
if (!
|
|
1613
|
+
for (const result of remoteResults) {
|
|
1614
|
+
if (!result?.id) {
|
|
1617
1615
|
this.logger.warn({
|
|
1618
|
-
|
|
1616
|
+
result,
|
|
1619
1617
|
idsToFetch,
|
|
1620
1618
|
Category: "spooky-client::SyncEngine::syncRecords"
|
|
1621
|
-
}, "Remote record has no id. Skipping record");
|
|
1619
|
+
}, "Remote record has no id (possibly deleted). Skipping record");
|
|
1622
1620
|
continue;
|
|
1623
1621
|
}
|
|
1622
|
+
const { spooky_rv, ...record } = result;
|
|
1624
1623
|
const fullId = encodeRecordId(record.id);
|
|
1625
1624
|
const table = record.id.table.toString();
|
|
1626
1625
|
const isAdded = added.some((item) => encodeRecordId(item.id) === fullId);
|
|
@@ -1854,7 +1853,6 @@ var SpookySync = class {
|
|
|
1854
1853
|
event,
|
|
1855
1854
|
Category: "spooky-client::SpookySync::processUpEvent"
|
|
1856
1855
|
}, "Processing up event");
|
|
1857
|
-
console.log("xx1", event);
|
|
1858
1856
|
switch (event.type) {
|
|
1859
1857
|
case "create":
|
|
1860
1858
|
const dataKeys = Object.keys(event.data).map((key) => ({
|
package/package.json
CHANGED
|
@@ -57,26 +57,29 @@ export class SyncEngine {
|
|
|
57
57
|
return;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
const [remoteResults] = await this.remote.query<
|
|
61
|
-
|
|
60
|
+
const [remoteResults] = await this.remote.query<
|
|
61
|
+
[(RecordWithId & { spooky_rv: number })[]]
|
|
62
|
+
>(
|
|
63
|
+
"SELECT *, (SELECT version FROM ONLY _spooky_version WHERE record_id = $parent.id)['version'] as spooky_rv FROM $idsToFetch",
|
|
62
64
|
{ idsToFetch }
|
|
63
65
|
);
|
|
64
|
-
|
|
66
|
+
|
|
65
67
|
// Prepare batch for cache (which handles both DB and DBSP)
|
|
66
68
|
const cacheBatch: CacheRecord[] = [];
|
|
67
69
|
|
|
68
|
-
for (const
|
|
69
|
-
if (!
|
|
70
|
+
for (const result of remoteResults) {
|
|
71
|
+
if (!result?.id) {
|
|
70
72
|
this.logger.warn(
|
|
71
73
|
{
|
|
72
|
-
|
|
74
|
+
result,
|
|
73
75
|
idsToFetch,
|
|
74
76
|
Category: 'spooky-client::SyncEngine::syncRecords',
|
|
75
77
|
},
|
|
76
|
-
'Remote record has no id. Skipping record'
|
|
78
|
+
'Remote record has no id (possibly deleted). Skipping record'
|
|
77
79
|
);
|
|
78
80
|
continue;
|
|
79
81
|
}
|
|
82
|
+
const { spooky_rv, ...record } = result;
|
|
80
83
|
const fullId = encodeRecordId(record.id);
|
|
81
84
|
const table = record.id.table.toString();
|
|
82
85
|
const isAdded = added.some((item) => encodeRecordId(item.id) === fullId);
|
package/src/modules/sync/sync.ts
CHANGED
|
@@ -169,7 +169,6 @@ export class SpookySync<S extends SchemaStructure> {
|
|
|
169
169
|
{ event, Category: 'spooky-client::SpookySync::processUpEvent' },
|
|
170
170
|
'Processing up event'
|
|
171
171
|
);
|
|
172
|
-
console.log('xx1', event);
|
|
173
172
|
switch (event.type) {
|
|
174
173
|
case 'create':
|
|
175
174
|
const dataKeys = Object.keys(event.data).map((key) => ({ key, variable: `data_${key}` }));
|
|
@@ -49,7 +49,6 @@ export class ArraySyncer {
|
|
|
49
49
|
this.localArray.sort((a, b) => a[0].localeCompare(b[0]));
|
|
50
50
|
this.needsSort = false;
|
|
51
51
|
}
|
|
52
|
-
console.log('xxxx555', this.localArray, this.remoteArray);
|
|
53
52
|
const diff = diffRecordVersionArray(this.localArray, this.remoteArray);
|
|
54
53
|
return diff;
|
|
55
54
|
}
|