local-lite 1.0.1 → 1.0.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.
- package/dist/actions/manager.js +6 -2
- package/dist/actions/store.js +33 -19
- package/dist/adapters/local/expo-sqlite.js +4 -2
- package/dist/adapters/local/libsql.js +3 -1
- package/dist/adapters/local/op-sqlite.js +2 -1
- package/dist/adapters/network/index.js +10 -5
- package/dist/adapters/remote/convex.js +37 -10
- package/dist/adapters/remote/firestore.js +11 -4
- package/dist/adapters/remote/self-hosted.js +9 -5
- package/dist/adapters/remote/supabase.js +95 -29
- package/dist/auth/apple.js +8 -4
- package/dist/auth/github.js +15 -7
- package/dist/auth/google.js +7 -4
- package/dist/auth/identity.js +5 -1
- package/dist/auth/local.js +74 -21
- package/dist/auth/microsoft.js +22 -8
- package/dist/auth/session.js +45 -34
- package/dist/auth/unified.js +3 -2
- package/dist/backups/cloud-storage.js +10 -7
- package/dist/backups/encryption.js +4 -2
- package/dist/backups/onedrive.js +3 -3
- package/dist/backups/operations.js +4 -2
- package/dist/config/index.d.ts +1 -1
- package/dist/config/resolve-local.js +18 -6
- package/dist/config/resolve-remote.js +2 -1
- package/dist/core/client.d.ts +2 -2
- package/dist/core/client.js +64 -26
- package/dist/core/index.d.ts +1 -1
- package/dist/core/maintenance.js +5 -4
- package/dist/core/meta-store.js +3 -3
- package/dist/core/outbox-store.js +32 -25
- package/dist/core/query-builder.js +23 -10
- package/dist/core/query.js +19 -7
- package/dist/core/schema-manager.js +6 -2
- package/dist/core/sync-worker.js +38 -12
- package/dist/core/table-manager.js +8 -2
- package/dist/core/types.d.ts +1 -1
- package/dist/devtools/BenchmarkModal.d.ts +1 -1
- package/dist/devtools/BenchmarkModal.js +234 -54
- package/dist/devtools/SyncInspector.js +260 -37
- package/dist/email/index.js +46 -18
- package/dist/keys/generator.js +4 -1
- package/dist/keys/manager.js +22 -4
- package/dist/keys/signed-token.js +12 -4
- package/dist/keys/store.js +23 -16
- package/dist/kv/manager.js +5 -2
- package/dist/kv/store.js +13 -13
- package/dist/react/auth.js +12 -12
- package/dist/react/backups.js +1 -1
- package/dist/react/index.js +14 -9
- package/dist/react/runner.js +1 -1
- package/dist/react/status.js +6 -2
- package/dist/reactive/event-emitter.js +2 -2
- package/dist/scheduler/cron.js +3 -1
- package/dist/scheduler/store.js +37 -31
- package/dist/schema/generator.js +37 -34
- package/dist/search/manager.js +3 -1
- package/dist/search/store.js +17 -16
- package/dist/server/email.js +3 -2
- package/dist/server/index.js +4 -4
- package/dist/server/sync.js +11 -4
- package/dist/storage/driver.js +2 -1
- package/dist/storage/expo.js +5 -2
- package/dist/storage/manager.js +3 -1
- package/dist/storage/store.js +26 -25
- package/dist/utils/dynamic.js +4 -2
- package/dist/utils/logger.js +13 -6
- package/dist/utils/portability.js +21 -9
- package/package.json +1 -1
package/dist/core/maintenance.js
CHANGED
|
@@ -34,9 +34,10 @@ class DatabaseMaintenance {
|
|
|
34
34
|
if (options.retentionDays !== undefined && options.retentionDays >= 0) {
|
|
35
35
|
const daysMs = options.retentionDays * 24 * 60 * 60 * 1000;
|
|
36
36
|
const calculatedCutoff = Date.now() - daysMs;
|
|
37
|
-
cutoffTimestamp =
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
cutoffTimestamp =
|
|
38
|
+
cutoffTimestamp !== undefined
|
|
39
|
+
? Math.min(cutoffTimestamp, calculatedCutoff)
|
|
40
|
+
: calculatedCutoff;
|
|
40
41
|
}
|
|
41
42
|
const conditions = [];
|
|
42
43
|
const params = [];
|
|
@@ -89,7 +90,7 @@ class DatabaseMaintenance {
|
|
|
89
90
|
tableNames = this.getKnownTables();
|
|
90
91
|
}
|
|
91
92
|
if (!includeInternal) {
|
|
92
|
-
tableNames = tableNames.filter(name => !(0, sql_js_1.isInternalTable)(name));
|
|
93
|
+
tableNames = tableNames.filter((name) => !(0, sql_js_1.isInternalTable)(name));
|
|
93
94
|
}
|
|
94
95
|
for (const tableName of tableNames) {
|
|
95
96
|
try {
|
package/dist/core/meta-store.js
CHANGED
|
@@ -7,9 +7,9 @@ class MetaStore {
|
|
|
7
7
|
* This table is strictly local to the device and is never synced to the remote server.
|
|
8
8
|
*/
|
|
9
9
|
static async ensureSchema(db) {
|
|
10
|
-
await db.execute(`CREATE TABLE IF NOT EXISTS sync_meta (
|
|
11
|
-
key TEXT PRIMARY KEY,
|
|
12
|
-
value TEXT NOT NULL
|
|
10
|
+
await db.execute(`CREATE TABLE IF NOT EXISTS sync_meta (
|
|
11
|
+
key TEXT PRIMARY KEY,
|
|
12
|
+
value TEXT NOT NULL
|
|
13
13
|
);`);
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
@@ -10,7 +10,11 @@ function mapOutboxRow(r) {
|
|
|
10
10
|
tableName: r.table_name,
|
|
11
11
|
rowId: r.row_id,
|
|
12
12
|
operation: r.operation,
|
|
13
|
-
payload: r.payload
|
|
13
|
+
payload: r.payload
|
|
14
|
+
? typeof r.payload === 'string'
|
|
15
|
+
? JSON.parse(r.payload)
|
|
16
|
+
: r.payload
|
|
17
|
+
: null,
|
|
14
18
|
timestamp: Number(r.timestamp),
|
|
15
19
|
status: r.status,
|
|
16
20
|
retryCount: Number(r.retry_count || 0),
|
|
@@ -22,16 +26,16 @@ class OutboxStore {
|
|
|
22
26
|
* Initializes the sync_outbox schema if it does not already exist.
|
|
23
27
|
*/
|
|
24
28
|
static async ensureSchema(db) {
|
|
25
|
-
await db.execute(`CREATE TABLE IF NOT EXISTS sync_outbox (
|
|
26
|
-
id TEXT PRIMARY KEY,
|
|
27
|
-
table_name TEXT NOT NULL,
|
|
28
|
-
row_id TEXT NOT NULL,
|
|
29
|
-
operation TEXT NOT NULL,
|
|
30
|
-
payload TEXT,
|
|
31
|
-
timestamp INTEGER NOT NULL,
|
|
32
|
-
status TEXT NOT NULL DEFAULT 'PENDING',
|
|
33
|
-
retry_count INTEGER NOT NULL DEFAULT 0,
|
|
34
|
-
last_error TEXT
|
|
29
|
+
await db.execute(`CREATE TABLE IF NOT EXISTS sync_outbox (
|
|
30
|
+
id TEXT PRIMARY KEY,
|
|
31
|
+
table_name TEXT NOT NULL,
|
|
32
|
+
row_id TEXT NOT NULL,
|
|
33
|
+
operation TEXT NOT NULL,
|
|
34
|
+
payload TEXT,
|
|
35
|
+
timestamp INTEGER NOT NULL,
|
|
36
|
+
status TEXT NOT NULL DEFAULT 'PENDING',
|
|
37
|
+
retry_count INTEGER NOT NULL DEFAULT 0,
|
|
38
|
+
last_error TEXT
|
|
35
39
|
);`);
|
|
36
40
|
// Indexes for the hot paths: pending scans (push), per-row conflict lookups (pull),
|
|
37
41
|
// and status counts (telemetry). Executed separately: many drivers prepare one statement.
|
|
@@ -43,7 +47,7 @@ class OutboxStore {
|
|
|
43
47
|
* Inserts a new outbox entry within an existing database transaction.
|
|
44
48
|
*/
|
|
45
49
|
static async insertRecord(tx, op) {
|
|
46
|
-
await tx.execute(`INSERT INTO sync_outbox (id, table_name, row_id, operation, payload, timestamp, status, retry_count)
|
|
50
|
+
await tx.execute(`INSERT INTO sync_outbox (id, table_name, row_id, operation, payload, timestamp, status, retry_count)
|
|
47
51
|
VALUES (?, ?, ?, ?, ?, ?, 'PENDING', 0)`, [
|
|
48
52
|
op.id,
|
|
49
53
|
op.tableName,
|
|
@@ -85,11 +89,11 @@ class OutboxStore {
|
|
|
85
89
|
static async getPending(db, maxRetries = 5, limit = 50) {
|
|
86
90
|
const isInfinite = !Number.isFinite(maxRetries) || maxRetries === -1;
|
|
87
91
|
const query = isInfinite
|
|
88
|
-
? `SELECT * FROM sync_outbox
|
|
89
|
-
WHERE status = 'PENDING' OR status = 'FAILED'
|
|
92
|
+
? `SELECT * FROM sync_outbox
|
|
93
|
+
WHERE status = 'PENDING' OR status = 'FAILED'
|
|
90
94
|
ORDER BY timestamp ASC LIMIT ?`
|
|
91
|
-
: `SELECT * FROM sync_outbox
|
|
92
|
-
WHERE status = 'PENDING' OR (status = 'FAILED' AND retry_count < ?)
|
|
95
|
+
: `SELECT * FROM sync_outbox
|
|
96
|
+
WHERE status = 'PENDING' OR (status = 'FAILED' AND retry_count < ?)
|
|
93
97
|
ORDER BY timestamp ASC LIMIT ?`;
|
|
94
98
|
const params = isInfinite ? [limit] : [maxRetries, limit];
|
|
95
99
|
const rows = await db.execute(query, params);
|
|
@@ -101,8 +105,8 @@ class OutboxStore {
|
|
|
101
105
|
* Finds the latest pending outbox record for a given table and row.
|
|
102
106
|
*/
|
|
103
107
|
static async findPendingByRow(tx, tableName, rowId) {
|
|
104
|
-
const rows = await tx.execute(`SELECT * FROM sync_outbox
|
|
105
|
-
WHERE table_name = ? AND row_id = ? AND status != 'FAILED'
|
|
108
|
+
const rows = await tx.execute(`SELECT * FROM sync_outbox
|
|
109
|
+
WHERE table_name = ? AND row_id = ? AND status != 'FAILED'
|
|
106
110
|
ORDER BY timestamp DESC LIMIT 1`, [tableName, rowId]);
|
|
107
111
|
if (!rows || rows.length === 0)
|
|
108
112
|
return undefined;
|
|
@@ -207,7 +211,10 @@ class OutboxStore {
|
|
|
207
211
|
await tx.execute(`UPDATE sync_outbox SET payload = ?, timestamp = ? WHERE id = ?`, [JSON.stringify(payload), timestamp, id]);
|
|
208
212
|
}
|
|
209
213
|
else {
|
|
210
|
-
await tx.execute(`UPDATE sync_outbox SET payload = ? WHERE id = ?`, [
|
|
214
|
+
await tx.execute(`UPDATE sync_outbox SET payload = ? WHERE id = ?`, [
|
|
215
|
+
JSON.stringify(payload),
|
|
216
|
+
id,
|
|
217
|
+
]);
|
|
211
218
|
}
|
|
212
219
|
}
|
|
213
220
|
/**
|
|
@@ -224,10 +231,10 @@ class OutboxStore {
|
|
|
224
231
|
if (ids.length === 0)
|
|
225
232
|
return;
|
|
226
233
|
const placeholders = ids.map(() => '?').join(',');
|
|
227
|
-
await db.execute(`UPDATE sync_outbox
|
|
228
|
-
SET status = 'FAILED',
|
|
229
|
-
retry_count = retry_count + 1,
|
|
230
|
-
last_error = ?
|
|
234
|
+
await db.execute(`UPDATE sync_outbox
|
|
235
|
+
SET status = 'FAILED',
|
|
236
|
+
retry_count = retry_count + 1,
|
|
237
|
+
last_error = ?
|
|
231
238
|
WHERE id IN (${placeholders})`, [errorMessage, ...ids]);
|
|
232
239
|
}
|
|
233
240
|
/**
|
|
@@ -266,8 +273,8 @@ class OutboxStore {
|
|
|
266
273
|
try {
|
|
267
274
|
if (ids && ids.length > 0) {
|
|
268
275
|
const placeholders = ids.map(() => '?').join(',');
|
|
269
|
-
await db.execute(`UPDATE sync_outbox
|
|
270
|
-
SET status = 'PENDING', retry_count = 0, last_error = NULL
|
|
276
|
+
await db.execute(`UPDATE sync_outbox
|
|
277
|
+
SET status = 'PENDING', retry_count = 0, last_error = NULL
|
|
271
278
|
WHERE status = 'FAILED' AND id IN (${placeholders})`, ids);
|
|
272
279
|
return ids.length;
|
|
273
280
|
}
|
|
@@ -228,13 +228,21 @@ class QueryBuilder {
|
|
|
228
228
|
if (typeof columnOrFilter === 'string') {
|
|
229
229
|
if (value !== undefined) {
|
|
230
230
|
const rawOp = String(operatorOrValue).toLowerCase().trim();
|
|
231
|
-
const opKey = rawOp === '>='
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
231
|
+
const opKey = rawOp === '>='
|
|
232
|
+
? '$gte'
|
|
233
|
+
: rawOp === '<='
|
|
234
|
+
? '$lte'
|
|
235
|
+
: rawOp === '>'
|
|
236
|
+
? '$gt'
|
|
237
|
+
: rawOp === '<'
|
|
238
|
+
? '$lt'
|
|
239
|
+
: rawOp === '!=' || rawOp === '<>'
|
|
240
|
+
? '$ne'
|
|
241
|
+
: rawOp === '=' || rawOp === '=='
|
|
242
|
+
? '$eq'
|
|
243
|
+
: rawOp === 'like'
|
|
244
|
+
? '$contains'
|
|
245
|
+
: '$eq';
|
|
238
246
|
const existing = typeof this.whereConditions[columnOrFilter] === 'object' &&
|
|
239
247
|
this.whereConditions[columnOrFilter] !== null
|
|
240
248
|
? this.whereConditions[columnOrFilter]
|
|
@@ -331,7 +339,8 @@ class QueryBuilder {
|
|
|
331
339
|
const schemaManager = 'schemaManager' in this.client
|
|
332
340
|
? this.client.schemaManager
|
|
333
341
|
: this.client.parent?.schemaManager;
|
|
334
|
-
if (!this.includeDeleted &&
|
|
342
|
+
if (!this.includeDeleted &&
|
|
343
|
+
schemaManager?.hasColumn(this.tableName, 'deleted')) {
|
|
335
344
|
const delCol = this.tableName.includes('.')
|
|
336
345
|
? `${formatColumnIdentifier(this.tableName)}."deleted"`
|
|
337
346
|
: `"${this.tableName.replace(/"/g, '""')}"."deleted"`;
|
|
@@ -370,7 +379,9 @@ class QueryBuilder {
|
|
|
370
379
|
const schemaManager = 'schemaManager' in this.client
|
|
371
380
|
? this.client.schemaManager
|
|
372
381
|
: this.client.parent?.schemaManager;
|
|
373
|
-
const db = 'db' in this.client
|
|
382
|
+
const db = 'db' in this.client
|
|
383
|
+
? this.client.db
|
|
384
|
+
: this.client.tx;
|
|
374
385
|
if (schemaManager && db) {
|
|
375
386
|
await schemaManager.ensureTableIntrospected(db, this.tableName);
|
|
376
387
|
for (const j of this.joins) {
|
|
@@ -451,7 +462,9 @@ class QueryBuilder {
|
|
|
451
462
|
try {
|
|
452
463
|
const rows = await this.execute();
|
|
453
464
|
const avgVal = rows[0]?._avg;
|
|
454
|
-
return avgVal === null || avgVal === undefined
|
|
465
|
+
return avgVal === null || avgVal === undefined
|
|
466
|
+
? null
|
|
467
|
+
: Number(avgVal) || 0;
|
|
455
468
|
}
|
|
456
469
|
finally {
|
|
457
470
|
this.selectCols = originalSelect;
|
package/dist/core/query.js
CHANGED
|
@@ -48,13 +48,18 @@ function matchesField(fieldValue, filter) {
|
|
|
48
48
|
if (ops.$lte !== undefined && !(fieldValue <= ops.$lte)) {
|
|
49
49
|
return false;
|
|
50
50
|
}
|
|
51
|
-
if (ops.$contains !== undefined ||
|
|
51
|
+
if (ops.$contains !== undefined ||
|
|
52
|
+
ops.$startsWith !== undefined ||
|
|
53
|
+
ops.$endsWith !== undefined) {
|
|
52
54
|
const str = fieldValue == null ? '' : String(fieldValue).toLowerCase();
|
|
53
|
-
if (ops.$contains !== undefined &&
|
|
55
|
+
if (ops.$contains !== undefined &&
|
|
56
|
+
!str.includes(String(ops.$contains).toLowerCase()))
|
|
54
57
|
return false;
|
|
55
|
-
if (ops.$startsWith !== undefined &&
|
|
58
|
+
if (ops.$startsWith !== undefined &&
|
|
59
|
+
!str.startsWith(String(ops.$startsWith).toLowerCase()))
|
|
56
60
|
return false;
|
|
57
|
-
if (ops.$endsWith !== undefined &&
|
|
61
|
+
if (ops.$endsWith !== undefined &&
|
|
62
|
+
!str.endsWith(String(ops.$endsWith).toLowerCase()))
|
|
58
63
|
return false;
|
|
59
64
|
}
|
|
60
65
|
if (ops.$null !== undefined) {
|
|
@@ -126,7 +131,11 @@ function applyQueryOptions(rows, options) {
|
|
|
126
131
|
(options?.limit !== undefined && options.limit > 0);
|
|
127
132
|
const needsSelect = Array.isArray(options?.select) && options.select.length > 0;
|
|
128
133
|
// Fast-path: nothing to do
|
|
129
|
-
if (!needsDeleteFilter &&
|
|
134
|
+
if (!needsDeleteFilter &&
|
|
135
|
+
!needsWhere &&
|
|
136
|
+
!needsSort &&
|
|
137
|
+
!needsSlice &&
|
|
138
|
+
!needsSelect) {
|
|
130
139
|
return rows;
|
|
131
140
|
}
|
|
132
141
|
let result = rows;
|
|
@@ -158,14 +167,17 @@ function applyQueryOptions(rows, options) {
|
|
|
158
167
|
if (typeof valA === 'number' && typeof valB === 'number') {
|
|
159
168
|
return isAsc ? valA - valB : valB - valA;
|
|
160
169
|
}
|
|
161
|
-
return isAsc ? (valA > valB ? 1 : -1) :
|
|
170
|
+
return isAsc ? (valA > valB ? 1 : -1) : valA < valB ? 1 : -1;
|
|
162
171
|
});
|
|
163
172
|
}
|
|
164
173
|
// 3. Offset and Limit
|
|
165
174
|
if (needsSlice) {
|
|
166
175
|
const offset = options?.offset && options.offset > 0 ? options.offset : 0;
|
|
167
176
|
const limit = options?.limit && options.limit > 0 ? options.limit : undefined;
|
|
168
|
-
result =
|
|
177
|
+
result =
|
|
178
|
+
limit !== undefined
|
|
179
|
+
? result.slice(offset, offset + limit)
|
|
180
|
+
: result.slice(offset);
|
|
169
181
|
}
|
|
170
182
|
// 4. Column projection
|
|
171
183
|
if (needsSelect) {
|
|
@@ -98,7 +98,10 @@ class SchemaManager {
|
|
|
98
98
|
const hasDeleted = this.knownColumns.has(`${tableName}:deleted`);
|
|
99
99
|
for (const key of columns) {
|
|
100
100
|
const lower = key.toLowerCase();
|
|
101
|
-
if (lower.endsWith('_id') ||
|
|
101
|
+
if (lower.endsWith('_id') ||
|
|
102
|
+
lower === 'deleted' ||
|
|
103
|
+
lower === 'created_at' ||
|
|
104
|
+
lower === 'updated_at') {
|
|
102
105
|
const indexKey = `${tableName}:${lower}`;
|
|
103
106
|
if (!this.knownIndexes.has(indexKey)) {
|
|
104
107
|
this.knownIndexes.add(indexKey);
|
|
@@ -146,7 +149,8 @@ class SchemaManager {
|
|
|
146
149
|
const safeTable = (0, sql_js_1.escapeIdentifier)(tableName);
|
|
147
150
|
let cacheMiss = false;
|
|
148
151
|
for (const key of keys) {
|
|
149
|
-
if (key !== primaryKey &&
|
|
152
|
+
if (key !== primaryKey &&
|
|
153
|
+
!this.knownColumns.has(`${tableName}:${key.toLowerCase()}`)) {
|
|
150
154
|
cacheMiss = true;
|
|
151
155
|
break;
|
|
152
156
|
}
|
package/dist/core/sync-worker.js
CHANGED
|
@@ -17,12 +17,16 @@ function stableScopeValue(value) {
|
|
|
17
17
|
if (Array.isArray(value))
|
|
18
18
|
return value.map(stableScopeValue);
|
|
19
19
|
if (value && typeof value === 'object') {
|
|
20
|
-
return Object.fromEntries(Object.keys(value)
|
|
20
|
+
return Object.fromEntries(Object.keys(value)
|
|
21
|
+
.sort()
|
|
22
|
+
.map((key) => [key, stableScopeValue(value[key])]));
|
|
21
23
|
}
|
|
22
24
|
return value;
|
|
23
25
|
}
|
|
24
26
|
function getScopeCursorKey(scope) {
|
|
25
|
-
return scope === undefined
|
|
27
|
+
return scope === undefined
|
|
28
|
+
? 'last_synced_at'
|
|
29
|
+
: `last_synced_at:scope:${JSON.stringify(stableScopeValue(scope))}`;
|
|
26
30
|
}
|
|
27
31
|
class SyncWorker {
|
|
28
32
|
db;
|
|
@@ -260,7 +264,8 @@ class SyncWorker {
|
|
|
260
264
|
// Not React Native
|
|
261
265
|
}
|
|
262
266
|
// Web Page Visibility API
|
|
263
|
-
if (typeof document !== 'undefined' &&
|
|
267
|
+
if (typeof document !== 'undefined' &&
|
|
268
|
+
typeof document.hidden === 'boolean') {
|
|
264
269
|
return document.hidden;
|
|
265
270
|
}
|
|
266
271
|
return false;
|
|
@@ -293,7 +298,8 @@ class SyncWorker {
|
|
|
293
298
|
// Not React Native
|
|
294
299
|
}
|
|
295
300
|
// 2. Web Page Visibility API
|
|
296
|
-
if (typeof document !== 'undefined' &&
|
|
301
|
+
if (typeof document !== 'undefined' &&
|
|
302
|
+
typeof document.addEventListener === 'function') {
|
|
297
303
|
const onVisibilityChange = () => {
|
|
298
304
|
if (document.hidden) {
|
|
299
305
|
this.pause();
|
|
@@ -436,14 +442,21 @@ class SyncWorker {
|
|
|
436
442
|
else if (pushRes && typeof pushRes === 'object') {
|
|
437
443
|
isSuccess = Boolean(pushRes.success);
|
|
438
444
|
successfulIds = pushRes.successfulIds ?? (isSuccess ? recordIds : []);
|
|
439
|
-
failedIds =
|
|
445
|
+
failedIds =
|
|
446
|
+
pushRes.failedIds ??
|
|
447
|
+
(isSuccess
|
|
448
|
+
? []
|
|
449
|
+
: recordIds.filter((id) => !successfulIds.includes(id)));
|
|
440
450
|
errorsMap = pushRes.errors ?? {};
|
|
441
451
|
}
|
|
442
452
|
if (successfulIds.length > 0) {
|
|
443
453
|
// Delete records that were pushed successfully
|
|
444
454
|
await outbox_store_js_1.OutboxStore.deleteCompleted(this.db, successfulIds);
|
|
445
455
|
this.totalPushedOperations += successfulIds.length;
|
|
446
|
-
this.events.emit('sync_outbox', {
|
|
456
|
+
this.events.emit('sync_outbox', {
|
|
457
|
+
operation: 'DELETE',
|
|
458
|
+
rowId: 'batch',
|
|
459
|
+
});
|
|
447
460
|
}
|
|
448
461
|
if (failedIds.length === 0) {
|
|
449
462
|
this.lastPushError = null;
|
|
@@ -556,7 +569,9 @@ class SyncWorker {
|
|
|
556
569
|
if (!(await this.isOnline()))
|
|
557
570
|
return;
|
|
558
571
|
this.totalPullCycles++;
|
|
559
|
-
const scope = typeof this.syncScope === 'function'
|
|
572
|
+
const scope = typeof this.syncScope === 'function'
|
|
573
|
+
? await this.syncScope()
|
|
574
|
+
: this.syncScope;
|
|
560
575
|
const cursorKey = getScopeCursorKey(scope);
|
|
561
576
|
await this.loadCursor(cursorKey);
|
|
562
577
|
const sinceTimestamp = this.lastPulledTimestamp;
|
|
@@ -628,7 +643,9 @@ class SyncWorker {
|
|
|
628
643
|
}
|
|
629
644
|
async processDeltasLocally(deltas, cursorKey = this.lastSyncedAtKey) {
|
|
630
645
|
if (!deltas.changes || deltas.changes.length === 0) {
|
|
631
|
-
if (deltas.timestamp &&
|
|
646
|
+
if (deltas.timestamp &&
|
|
647
|
+
(cursorKey !== this.lastSyncedAtKey ||
|
|
648
|
+
deltas.timestamp > this.lastPulledTimestamp)) {
|
|
632
649
|
await meta_store_js_1.MetaStore.setLastSyncedAt(this.db, deltas.timestamp, cursorKey);
|
|
633
650
|
if (cursorKey === this.lastSyncedAtKey)
|
|
634
651
|
this.lastPulledTimestamp = deltas.timestamp;
|
|
@@ -652,7 +669,10 @@ class SyncWorker {
|
|
|
652
669
|
// 2. Conflict resolution if there is a pending local change
|
|
653
670
|
if (localPendingRecord) {
|
|
654
671
|
// Only load the current local row when a resolver actually needs it.
|
|
655
|
-
const localRow = await table_manager_js_1.TableManager.fetchRow(tx, change.tableName, change.rowId, this.primaryKey, {
|
|
672
|
+
const localRow = await table_manager_js_1.TableManager.fetchRow(tx, change.tableName, change.rowId, this.primaryKey, {
|
|
673
|
+
autoSchema: this.autoSchema,
|
|
674
|
+
schemaManager: this.schemaManager,
|
|
675
|
+
});
|
|
656
676
|
const resolution = await Promise.resolve(this.conflictResolver({
|
|
657
677
|
tableName: change.tableName,
|
|
658
678
|
rowId: change.rowId,
|
|
@@ -677,7 +697,8 @@ class SyncWorker {
|
|
|
677
697
|
await outbox_store_js_1.OutboxStore.deleteRecord(tx, localPendingRecord.id);
|
|
678
698
|
pendingOutboxMap.delete(outboxKey);
|
|
679
699
|
}
|
|
680
|
-
else if (typeof resolution === 'object' &&
|
|
700
|
+
else if (typeof resolution === 'object' &&
|
|
701
|
+
resolution.mergePayload) {
|
|
681
702
|
// Merge scenario
|
|
682
703
|
change.payload = resolution.mergePayload;
|
|
683
704
|
await outbox_store_js_1.OutboxStore.updatePayload(tx, localPendingRecord.id, resolution.mergePayload);
|
|
@@ -698,7 +719,10 @@ class SyncWorker {
|
|
|
698
719
|
});
|
|
699
720
|
}
|
|
700
721
|
// Advance durable checkpoint only when a valid pull timestamp was provided
|
|
701
|
-
if (isLastChunk &&
|
|
722
|
+
if (isLastChunk &&
|
|
723
|
+
deltas.timestamp &&
|
|
724
|
+
(cursorKey !== this.lastSyncedAtKey ||
|
|
725
|
+
deltas.timestamp > this.lastPulledTimestamp)) {
|
|
702
726
|
await meta_store_js_1.MetaStore.setLastSyncedAt(tx, deltas.timestamp, cursorKey);
|
|
703
727
|
if (cursorKey === this.lastSyncedAtKey)
|
|
704
728
|
this.lastPulledTimestamp = deltas.timestamp;
|
|
@@ -718,7 +742,9 @@ class SyncWorker {
|
|
|
718
742
|
}
|
|
719
743
|
}
|
|
720
744
|
async getLastPulledTimestamp() {
|
|
721
|
-
const scope = typeof this.syncScope === 'function'
|
|
745
|
+
const scope = typeof this.syncScope === 'function'
|
|
746
|
+
? await this.syncScope()
|
|
747
|
+
: this.syncScope;
|
|
722
748
|
await this.loadCursor(getScopeCursorKey(scope));
|
|
723
749
|
return this.lastPulledTimestamp;
|
|
724
750
|
}
|
|
@@ -15,13 +15,19 @@ function formatPayload(payload) {
|
|
|
15
15
|
}
|
|
16
16
|
async function withTouchedColumn(tx, sm, tableName, operation, payload, options) {
|
|
17
17
|
const col = options.touchColumn;
|
|
18
|
-
if (operation === 'INSERT' &&
|
|
18
|
+
if (operation === 'INSERT' &&
|
|
19
|
+
payload &&
|
|
20
|
+
payload[col] !== undefined &&
|
|
21
|
+
payload[col] !== null) {
|
|
19
22
|
return payload;
|
|
20
23
|
}
|
|
21
24
|
if (!options.autoSchema && !(await sm.tableHasColumn(tx, tableName, col))) {
|
|
22
25
|
return payload;
|
|
23
26
|
}
|
|
24
|
-
return {
|
|
27
|
+
return {
|
|
28
|
+
...(payload || {}),
|
|
29
|
+
[col]: options.touchValue ?? new Date().toISOString(),
|
|
30
|
+
};
|
|
25
31
|
}
|
|
26
32
|
class TableManager {
|
|
27
33
|
/**
|
package/dist/core/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type SyncOp = 'INSERT' | 'UPDATE' | 'DELETE';
|
|
2
|
-
export type OutboxStatus = 'PENDING' | 'PROCESSING' | 'FAILED';
|
|
2
|
+
export type OutboxStatus = 'PENDING' | 'PROCESSING' | 'COMPLETED' | 'FAILED';
|
|
3
3
|
export interface SchemaMigration {
|
|
4
4
|
version: number;
|
|
5
5
|
up: string | string[];
|
|
@@ -29,4 +29,4 @@ export declare function runSQLiteBenchmark(clientOrDb: any, onProgress?: (step:
|
|
|
29
29
|
* Pure package-driven, full-height Performance Benchmark Modal.
|
|
30
30
|
* Opens full-height with zero screen flickering or dynamic jumping.
|
|
31
31
|
*/
|
|
32
|
-
export declare function BenchmarkModal({ client, visible, onDismiss, theme }: BenchmarkModalProps): React.JSX.Element | null;
|
|
32
|
+
export declare function BenchmarkModal({ client, visible, onDismiss, theme, }: BenchmarkModalProps): React.JSX.Element | null;
|