@anfenn/dync 1.1.1 → 1.2.1
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/README.md +8 -4
- package/dist/capacitor.d.cts +1 -1
- package/dist/capacitor.d.ts +1 -1
- package/dist/{dexie-D85rTx4g.d.ts → dexie-Cxn4kUoF.d.ts} +2 -7
- package/dist/{dexie-3VOQSn1s.d.cts → dexie-D8u9cGSy.d.cts} +2 -7
- package/dist/dexie.cjs +11 -0
- package/dist/dexie.cjs.map +1 -1
- package/dist/dexie.d.cts +2 -2
- package/dist/dexie.d.ts +2 -2
- package/dist/dexie.js +11 -0
- package/dist/dexie.js.map +1 -1
- package/dist/expoSqlite.d.cts +1 -1
- package/dist/expoSqlite.d.ts +1 -1
- package/dist/index.cjs +190 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +190 -24
- package/dist/index.js.map +1 -1
- package/dist/node.d.cts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/react/index.d.cts +3 -3
- package/dist/react/index.d.ts +3 -3
- package/dist/{types-BIJhsSOf.d.ts → types-Da3ZhO9Y.d.cts} +3 -3
- package/dist/{types-6-NyRQ0D.d.cts → types-DcEg2pvl.d.cts} +1 -1
- package/dist/{types-6-NyRQ0D.d.ts → types-DcEg2pvl.d.ts} +1 -1
- package/dist/{types-DhCTdAep.d.cts → types-DnHiaBZV.d.ts} +3 -3
- package/dist/wa-sqlite.d.cts +1 -1
- package/dist/wa-sqlite.d.ts +1 -1
- package/package.json +5 -3
- package/src/core/SyncAwareCollection.ts +124 -0
- package/src/core/SyncAwareWhereClause.ts +66 -0
- package/src/core/pushOperations.ts +14 -7
- package/src/core/tableEnhancers.ts +18 -0
- package/src/index.shared.ts +7 -7
- package/src/storage/dexie/DexieAdapter.ts +13 -2
- package/src/storage/sqlite/SQLiteAdapter.ts +2 -7
- package/src/storage/sqlite/SQLiteQueryContext.ts +1 -22
- package/src/storage/sqlite/types.ts +1 -1
- package/src/types.ts +9 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { D as DyncOptions, S as SyncStatus, a as SyncApi, T as TableMap } from './types-
|
|
2
|
-
export { A as AfterRemoteAddCallback, e as BatchFirstLoadResult, c as BatchPushPayload, d as BatchPushResult, B as BatchSync, f as ConflictResolutionStrategy, C as CrudSyncApi, F as FirstLoadProgress, g as FirstLoadProgressCallback, h as MissingRemoteRecordDuringUpdateCallback, M as MissingRemoteRecordStrategy, i as MutationEvent, b as SyncAction, j as SyncOptions, k as SyncState, l as SyncedRecord } from './types-
|
|
3
|
-
import { T as TableSchemaDefinition, D as DexieQueryContext, S as SQLiteQueryContext, M as MemoryQueryContext, a as StorageTable } from './dexie-
|
|
4
|
-
export { b as MemoryAdapter, c as SQLiteAdapter, d as StorageAdapter } from './dexie-
|
|
5
|
-
import { c as SQLiteVersionMigration } from './types-
|
|
6
|
-
export { S as SQLiteDatabaseDriver, b as SQLiteQueryResult, a as SQLiteRunResult } from './types-
|
|
1
|
+
import { D as DyncOptions, S as SyncStatus, a as SyncApi, T as TableMap } from './types-Da3ZhO9Y.cjs';
|
|
2
|
+
export { A as AfterRemoteAddCallback, e as BatchFirstLoadResult, c as BatchPushPayload, d as BatchPushResult, B as BatchSync, f as ConflictResolutionStrategy, C as CrudSyncApi, F as FirstLoadProgress, g as FirstLoadProgressCallback, h as MissingRemoteRecordDuringUpdateCallback, M as MissingRemoteRecordStrategy, i as MutationEvent, b as SyncAction, j as SyncOptions, k as SyncState, l as SyncedRecord } from './types-Da3ZhO9Y.cjs';
|
|
3
|
+
import { T as TableSchemaDefinition, D as DexieQueryContext, S as SQLiteQueryContext, M as MemoryQueryContext, a as StorageTable } from './dexie-D8u9cGSy.cjs';
|
|
4
|
+
export { b as MemoryAdapter, c as SQLiteAdapter, d as StorageAdapter } from './dexie-D8u9cGSy.cjs';
|
|
5
|
+
import { c as SQLiteVersionMigration } from './types-DcEg2pvl.cjs';
|
|
6
|
+
export { S as SQLiteDatabaseDriver, b as SQLiteQueryResult, a as SQLiteRunResult } from './types-DcEg2pvl.cjs';
|
|
7
7
|
import 'dexie';
|
|
8
8
|
|
|
9
9
|
declare class DyncBase<_TStoreMap extends Record<string, any> = Record<string, any>> {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { D as DyncOptions, S as SyncStatus, a as SyncApi, T as TableMap } from './types-
|
|
2
|
-
export { A as AfterRemoteAddCallback, e as BatchFirstLoadResult, c as BatchPushPayload, d as BatchPushResult, B as BatchSync, f as ConflictResolutionStrategy, C as CrudSyncApi, F as FirstLoadProgress, g as FirstLoadProgressCallback, h as MissingRemoteRecordDuringUpdateCallback, M as MissingRemoteRecordStrategy, i as MutationEvent, b as SyncAction, j as SyncOptions, k as SyncState, l as SyncedRecord } from './types-
|
|
3
|
-
import { T as TableSchemaDefinition, D as DexieQueryContext, S as SQLiteQueryContext, M as MemoryQueryContext, a as StorageTable } from './dexie-
|
|
4
|
-
export { b as MemoryAdapter, c as SQLiteAdapter, d as StorageAdapter } from './dexie-
|
|
5
|
-
import { c as SQLiteVersionMigration } from './types-
|
|
6
|
-
export { S as SQLiteDatabaseDriver, b as SQLiteQueryResult, a as SQLiteRunResult } from './types-
|
|
1
|
+
import { D as DyncOptions, S as SyncStatus, a as SyncApi, T as TableMap } from './types-DnHiaBZV.js';
|
|
2
|
+
export { A as AfterRemoteAddCallback, e as BatchFirstLoadResult, c as BatchPushPayload, d as BatchPushResult, B as BatchSync, f as ConflictResolutionStrategy, C as CrudSyncApi, F as FirstLoadProgress, g as FirstLoadProgressCallback, h as MissingRemoteRecordDuringUpdateCallback, M as MissingRemoteRecordStrategy, i as MutationEvent, b as SyncAction, j as SyncOptions, k as SyncState, l as SyncedRecord } from './types-DnHiaBZV.js';
|
|
3
|
+
import { T as TableSchemaDefinition, D as DexieQueryContext, S as SQLiteQueryContext, M as MemoryQueryContext, a as StorageTable } from './dexie-Cxn4kUoF.js';
|
|
4
|
+
export { b as MemoryAdapter, c as SQLiteAdapter, d as StorageAdapter } from './dexie-Cxn4kUoF.js';
|
|
5
|
+
import { c as SQLiteVersionMigration } from './types-DcEg2pvl.js';
|
|
6
|
+
export { S as SQLiteDatabaseDriver, b as SQLiteQueryResult, a as SQLiteRunResult } from './types-DcEg2pvl.js';
|
|
7
7
|
import 'dexie';
|
|
8
8
|
|
|
9
9
|
declare class DyncBase<_TStoreMap extends Record<string, any> = Record<string, any>> {
|
package/dist/index.js
CHANGED
|
@@ -330,6 +330,174 @@ function cloneRecord(record) {
|
|
|
330
330
|
return { ...record };
|
|
331
331
|
}
|
|
332
332
|
|
|
333
|
+
// src/core/SyncAwareWhereClause.ts
|
|
334
|
+
var SyncAwareWhereClause = class {
|
|
335
|
+
constructor(inner, tableRef) {
|
|
336
|
+
this.inner = inner;
|
|
337
|
+
this.tableRef = tableRef;
|
|
338
|
+
}
|
|
339
|
+
wrap(col) {
|
|
340
|
+
return new SyncAwareCollection(col, this.tableRef);
|
|
341
|
+
}
|
|
342
|
+
equals(value) {
|
|
343
|
+
return this.wrap(this.inner.equals(value));
|
|
344
|
+
}
|
|
345
|
+
above(value) {
|
|
346
|
+
return this.wrap(this.inner.above(value));
|
|
347
|
+
}
|
|
348
|
+
aboveOrEqual(value) {
|
|
349
|
+
return this.wrap(this.inner.aboveOrEqual(value));
|
|
350
|
+
}
|
|
351
|
+
below(value) {
|
|
352
|
+
return this.wrap(this.inner.below(value));
|
|
353
|
+
}
|
|
354
|
+
belowOrEqual(value) {
|
|
355
|
+
return this.wrap(this.inner.belowOrEqual(value));
|
|
356
|
+
}
|
|
357
|
+
between(lower, upper, includeLower, includeUpper) {
|
|
358
|
+
return this.wrap(this.inner.between(lower, upper, includeLower, includeUpper));
|
|
359
|
+
}
|
|
360
|
+
inAnyRange(ranges, options) {
|
|
361
|
+
return this.wrap(this.inner.inAnyRange(ranges, options));
|
|
362
|
+
}
|
|
363
|
+
startsWith(prefix) {
|
|
364
|
+
return this.wrap(this.inner.startsWith(prefix));
|
|
365
|
+
}
|
|
366
|
+
startsWithIgnoreCase(prefix) {
|
|
367
|
+
return this.wrap(this.inner.startsWithIgnoreCase(prefix));
|
|
368
|
+
}
|
|
369
|
+
startsWithAnyOf(...args) {
|
|
370
|
+
return this.wrap(this.inner.startsWithAnyOf(...args));
|
|
371
|
+
}
|
|
372
|
+
startsWithAnyOfIgnoreCase(...args) {
|
|
373
|
+
return this.wrap(this.inner.startsWithAnyOfIgnoreCase(...args));
|
|
374
|
+
}
|
|
375
|
+
equalsIgnoreCase(value) {
|
|
376
|
+
return this.wrap(this.inner.equalsIgnoreCase(value));
|
|
377
|
+
}
|
|
378
|
+
anyOf(...args) {
|
|
379
|
+
return this.wrap(this.inner.anyOf(...args));
|
|
380
|
+
}
|
|
381
|
+
anyOfIgnoreCase(...args) {
|
|
382
|
+
return this.wrap(this.inner.anyOfIgnoreCase(...args));
|
|
383
|
+
}
|
|
384
|
+
noneOf(...args) {
|
|
385
|
+
return this.wrap(this.inner.noneOf(...args));
|
|
386
|
+
}
|
|
387
|
+
notEqual(value) {
|
|
388
|
+
return this.wrap(this.inner.notEqual(value));
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
// src/core/SyncAwareCollection.ts
|
|
393
|
+
var SyncAwareCollection = class _SyncAwareCollection {
|
|
394
|
+
constructor(inner, tableRef) {
|
|
395
|
+
this.inner = inner;
|
|
396
|
+
this.tableRef = tableRef;
|
|
397
|
+
}
|
|
398
|
+
wrap(col) {
|
|
399
|
+
return new _SyncAwareCollection(col, this.tableRef);
|
|
400
|
+
}
|
|
401
|
+
// ---- read-only / pass-through ----
|
|
402
|
+
first() {
|
|
403
|
+
return this.inner.first();
|
|
404
|
+
}
|
|
405
|
+
last() {
|
|
406
|
+
return this.inner.last();
|
|
407
|
+
}
|
|
408
|
+
each(cb) {
|
|
409
|
+
return this.inner.each(cb);
|
|
410
|
+
}
|
|
411
|
+
eachKey(cb) {
|
|
412
|
+
return this.inner.eachKey(cb);
|
|
413
|
+
}
|
|
414
|
+
eachPrimaryKey(cb) {
|
|
415
|
+
return this.inner.eachPrimaryKey(cb);
|
|
416
|
+
}
|
|
417
|
+
eachUniqueKey(cb) {
|
|
418
|
+
return this.inner.eachUniqueKey(cb);
|
|
419
|
+
}
|
|
420
|
+
keys() {
|
|
421
|
+
return this.inner.keys();
|
|
422
|
+
}
|
|
423
|
+
primaryKeys() {
|
|
424
|
+
return this.inner.primaryKeys();
|
|
425
|
+
}
|
|
426
|
+
uniqueKeys() {
|
|
427
|
+
return this.inner.uniqueKeys();
|
|
428
|
+
}
|
|
429
|
+
count() {
|
|
430
|
+
return this.inner.count();
|
|
431
|
+
}
|
|
432
|
+
sortBy(key) {
|
|
433
|
+
return this.inner.sortBy(key);
|
|
434
|
+
}
|
|
435
|
+
toArray() {
|
|
436
|
+
return this.inner.toArray();
|
|
437
|
+
}
|
|
438
|
+
// ---- chaining — preserve sync-awareness ----
|
|
439
|
+
distinct() {
|
|
440
|
+
return this.wrap(this.inner.distinct());
|
|
441
|
+
}
|
|
442
|
+
clone(props) {
|
|
443
|
+
return this.wrap(this.inner.clone(props));
|
|
444
|
+
}
|
|
445
|
+
reverse() {
|
|
446
|
+
return this.wrap(this.inner.reverse());
|
|
447
|
+
}
|
|
448
|
+
offset(n) {
|
|
449
|
+
return this.wrap(this.inner.offset(n));
|
|
450
|
+
}
|
|
451
|
+
limit(n) {
|
|
452
|
+
return this.wrap(this.inner.limit(n));
|
|
453
|
+
}
|
|
454
|
+
toCollection() {
|
|
455
|
+
return this.wrap(this.inner.toCollection());
|
|
456
|
+
}
|
|
457
|
+
jsFilter(predicate) {
|
|
458
|
+
return this.wrap(this.inner.jsFilter(predicate));
|
|
459
|
+
}
|
|
460
|
+
or(index) {
|
|
461
|
+
return new SyncAwareWhereClause(this.inner.or(index), this.tableRef);
|
|
462
|
+
}
|
|
463
|
+
// ---- sync-aware mutations ----
|
|
464
|
+
async delete() {
|
|
465
|
+
const records = await this.inner.toArray();
|
|
466
|
+
if (records.length === 0) return 0;
|
|
467
|
+
const keys = records.map((r) => r._localId);
|
|
468
|
+
await this.tableRef.bulkDelete(keys);
|
|
469
|
+
return records.length;
|
|
470
|
+
}
|
|
471
|
+
async modify(changes) {
|
|
472
|
+
const records = await this.inner.toArray();
|
|
473
|
+
if (records.length === 0) return 0;
|
|
474
|
+
if (typeof changes === "function") {
|
|
475
|
+
const keysAndChanges = [];
|
|
476
|
+
for (const record of records) {
|
|
477
|
+
const draft = { ...record };
|
|
478
|
+
await changes(draft);
|
|
479
|
+
const delta = {};
|
|
480
|
+
const allKeys = /* @__PURE__ */ new Set([...Object.keys(record), ...Object.keys(draft)]);
|
|
481
|
+
for (const key of allKeys) {
|
|
482
|
+
if (draft[key] !== record[key]) {
|
|
483
|
+
delta[key] = draft[key];
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
if (Object.keys(delta).length > 0) {
|
|
487
|
+
keysAndChanges.push({ key: record._localId, changes: delta });
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
if (keysAndChanges.length > 0) {
|
|
491
|
+
await this.tableRef.bulkUpdate(keysAndChanges);
|
|
492
|
+
}
|
|
493
|
+
} else {
|
|
494
|
+
const keysAndChanges = records.map((r) => ({ key: r._localId, changes }));
|
|
495
|
+
await this.tableRef.bulkUpdate(keysAndChanges);
|
|
496
|
+
}
|
|
497
|
+
return records.length;
|
|
498
|
+
}
|
|
499
|
+
};
|
|
500
|
+
|
|
333
501
|
// src/core/tableEnhancers.ts
|
|
334
502
|
function wrapWithMutationEmitter(table, tableName, emitMutation) {
|
|
335
503
|
const rawAdd = table.raw.add;
|
|
@@ -700,6 +868,18 @@ function enhanceSyncTable({ table, tableName, withTransaction, state, enhancedTa
|
|
|
700
868
|
table.bulkUpdate = wrappedBulkUpdate;
|
|
701
869
|
table.bulkDelete = wrappedBulkDelete;
|
|
702
870
|
table.clear = wrappedClear;
|
|
871
|
+
const originalWhere = table.where.bind(table);
|
|
872
|
+
const originalOrderBy = table.orderBy.bind(table);
|
|
873
|
+
const originalReverse = table.reverse.bind(table);
|
|
874
|
+
const originalOffset = table.offset.bind(table);
|
|
875
|
+
const originalLimit = table.limit.bind(table);
|
|
876
|
+
const originalJsFilter = table.jsFilter.bind(table);
|
|
877
|
+
table.where = (index) => new SyncAwareWhereClause(originalWhere(index), table);
|
|
878
|
+
table.orderBy = (index) => new SyncAwareCollection(originalOrderBy(index), table);
|
|
879
|
+
table.reverse = () => new SyncAwareCollection(originalReverse(), table);
|
|
880
|
+
table.offset = (n) => new SyncAwareCollection(originalOffset(n), table);
|
|
881
|
+
table.limit = (n) => new SyncAwareCollection(originalLimit(n), table);
|
|
882
|
+
table.jsFilter = (predicate) => new SyncAwareCollection(originalJsFilter(predicate), table);
|
|
703
883
|
enhancedTables.add(tableName);
|
|
704
884
|
}
|
|
705
885
|
|
|
@@ -1067,7 +1247,11 @@ async function processBatchPushResult(change, result, ctx) {
|
|
|
1067
1247
|
const { action, tableName, localId } = change;
|
|
1068
1248
|
if (!result.success) {
|
|
1069
1249
|
if (action === "update" /* Update */) {
|
|
1070
|
-
|
|
1250
|
+
if (!result.error) {
|
|
1251
|
+
await handleMissingRemoteRecord(change, ctx);
|
|
1252
|
+
} else {
|
|
1253
|
+
ctx.logger.warn(`[dync] push:batch:update-failed tableName=${tableName} localId=${localId} error=${result.error}`);
|
|
1254
|
+
}
|
|
1071
1255
|
} else {
|
|
1072
1256
|
ctx.logger.warn(`[dync] push:batch:failed tableName=${tableName} localId=${localId} error=${result.error}`);
|
|
1073
1257
|
}
|
|
@@ -1075,10 +1259,10 @@ async function processBatchPushResult(change, result, ctx) {
|
|
|
1075
1259
|
}
|
|
1076
1260
|
switch (action) {
|
|
1077
1261
|
case "remove" /* Remove */:
|
|
1078
|
-
handleRemoveSuccess(change, ctx);
|
|
1262
|
+
await handleRemoveSuccess(change, ctx);
|
|
1079
1263
|
break;
|
|
1080
1264
|
case "update" /* Update */:
|
|
1081
|
-
handleUpdateSuccess(change, ctx);
|
|
1265
|
+
await handleUpdateSuccess(change, ctx);
|
|
1082
1266
|
break;
|
|
1083
1267
|
case "create" /* Create */: {
|
|
1084
1268
|
const serverResult = { id: result.id };
|
|
@@ -2526,22 +2710,9 @@ var normalizeComparableValue = (value) => {
|
|
|
2526
2710
|
|
|
2527
2711
|
// src/storage/sqlite/SQLiteQueryContext.ts
|
|
2528
2712
|
var SQLiteQueryContext = class {
|
|
2529
|
-
constructor(
|
|
2530
|
-
this.driver = driver;
|
|
2713
|
+
constructor(adapter) {
|
|
2531
2714
|
this.adapter = adapter;
|
|
2532
2715
|
}
|
|
2533
|
-
table(name) {
|
|
2534
|
-
return this.adapter.table(name);
|
|
2535
|
-
}
|
|
2536
|
-
transaction(mode, tableNames, callback) {
|
|
2537
|
-
return this.adapter.transaction(mode, tableNames, callback);
|
|
2538
|
-
}
|
|
2539
|
-
async execute(statement) {
|
|
2540
|
-
return this.driver.execute(statement);
|
|
2541
|
-
}
|
|
2542
|
-
async run(statement, values) {
|
|
2543
|
-
return this.driver.run(statement, values);
|
|
2544
|
-
}
|
|
2545
2716
|
async queryRows(statement, values) {
|
|
2546
2717
|
return this.adapter.queryRows(statement, values);
|
|
2547
2718
|
}
|
|
@@ -2710,8 +2881,7 @@ var SQLiteAdapter2 = class {
|
|
|
2710
2881
|
}
|
|
2711
2882
|
async query(arg1, arg2) {
|
|
2712
2883
|
if (typeof arg1 === "function") {
|
|
2713
|
-
|
|
2714
|
-
return arg1(new SQLiteQueryContext(driver2, this));
|
|
2884
|
+
return arg1(new SQLiteQueryContext(this));
|
|
2715
2885
|
}
|
|
2716
2886
|
const statement = arg1;
|
|
2717
2887
|
const values = arg2;
|
|
@@ -2791,12 +2961,8 @@ var SQLiteAdapter2 = class {
|
|
|
2791
2961
|
if (!debug) {
|
|
2792
2962
|
return;
|
|
2793
2963
|
}
|
|
2794
|
-
const hasParams = parameters && parameters.length;
|
|
2795
|
-
if (typeof debug === "function") {
|
|
2796
|
-
debug(statement, hasParams ? parameters : void 0);
|
|
2797
|
-
return;
|
|
2798
|
-
}
|
|
2799
2964
|
if (debug === true) {
|
|
2965
|
+
const hasParams = parameters && parameters.length;
|
|
2800
2966
|
if (hasParams) {
|
|
2801
2967
|
console.debug("[dync][sqlite]", statement, parameters);
|
|
2802
2968
|
} else {
|