@anfenn/dync 1.1.3 → 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.
Files changed (39) hide show
  1. package/README.md +4 -3
  2. package/dist/capacitor.d.cts +1 -1
  3. package/dist/capacitor.d.ts +1 -1
  4. package/dist/{dexie-B3Ihrrxi.d.ts → dexie-Cxn4kUoF.d.ts} +1 -1
  5. package/dist/{dexie-BRWUYM02.d.cts → dexie-D8u9cGSy.d.cts} +1 -1
  6. package/dist/dexie.cjs +11 -0
  7. package/dist/dexie.cjs.map +1 -1
  8. package/dist/dexie.d.cts +2 -2
  9. package/dist/dexie.d.ts +2 -2
  10. package/dist/dexie.js +11 -0
  11. package/dist/dexie.js.map +1 -1
  12. package/dist/expoSqlite.d.cts +1 -1
  13. package/dist/expoSqlite.d.ts +1 -1
  14. package/dist/index.cjs +188 -8
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +6 -6
  17. package/dist/index.d.ts +6 -6
  18. package/dist/index.js +188 -8
  19. package/dist/index.js.map +1 -1
  20. package/dist/node.d.cts +1 -1
  21. package/dist/node.d.ts +1 -1
  22. package/dist/react/index.d.cts +3 -3
  23. package/dist/react/index.d.ts +3 -3
  24. package/dist/{types-DhlgTu1o.d.ts → types-Da3ZhO9Y.d.cts} +3 -3
  25. package/dist/{types-6-NyRQ0D.d.cts → types-DcEg2pvl.d.cts} +1 -1
  26. package/dist/{types-6-NyRQ0D.d.ts → types-DcEg2pvl.d.ts} +1 -1
  27. package/dist/{types-Di82FTAL.d.cts → types-DnHiaBZV.d.ts} +3 -3
  28. package/dist/wa-sqlite.d.cts +1 -1
  29. package/dist/wa-sqlite.d.ts +1 -1
  30. package/package.json +2 -2
  31. package/src/core/SyncAwareCollection.ts +124 -0
  32. package/src/core/SyncAwareWhereClause.ts +66 -0
  33. package/src/core/pushOperations.ts +14 -7
  34. package/src/core/tableEnhancers.ts +18 -0
  35. package/src/index.shared.ts +7 -7
  36. package/src/storage/dexie/DexieAdapter.ts +13 -2
  37. package/src/storage/sqlite/SQLiteAdapter.ts +1 -5
  38. package/src/storage/sqlite/types.ts +1 -1
  39. 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-Di82FTAL.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-Di82FTAL.cjs';
3
- import { T as TableSchemaDefinition, D as DexieQueryContext, S as SQLiteQueryContext, M as MemoryQueryContext, a as StorageTable } from './dexie-BRWUYM02.cjs';
4
- export { b as MemoryAdapter, c as SQLiteAdapter, d as StorageAdapter } from './dexie-BRWUYM02.cjs';
5
- import { c as SQLiteVersionMigration } from './types-6-NyRQ0D.cjs';
6
- export { S as SQLiteDatabaseDriver, b as SQLiteQueryResult, a as SQLiteRunResult } from './types-6-NyRQ0D.cjs';
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-DhlgTu1o.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-DhlgTu1o.js';
3
- import { T as TableSchemaDefinition, D as DexieQueryContext, S as SQLiteQueryContext, M as MemoryQueryContext, a as StorageTable } from './dexie-B3Ihrrxi.js';
4
- export { b as MemoryAdapter, c as SQLiteAdapter, d as StorageAdapter } from './dexie-B3Ihrrxi.js';
5
- import { c as SQLiteVersionMigration } from './types-6-NyRQ0D.js';
6
- export { S as SQLiteDatabaseDriver, b as SQLiteQueryResult, a as SQLiteRunResult } from './types-6-NyRQ0D.js';
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
- await handleMissingRemoteRecord(change, ctx);
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 };
@@ -2777,12 +2961,8 @@ var SQLiteAdapter2 = class {
2777
2961
  if (!debug) {
2778
2962
  return;
2779
2963
  }
2780
- const hasParams = parameters && parameters.length;
2781
- if (typeof debug === "function") {
2782
- debug(statement, hasParams ? parameters : void 0);
2783
- return;
2784
- }
2785
2964
  if (debug === true) {
2965
+ const hasParams = parameters && parameters.length;
2786
2966
  if (hasParams) {
2787
2967
  console.debug("[dync][sqlite]", statement, parameters);
2788
2968
  } else {