@anfenn/dync 1.0.28 → 1.0.31
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 +31 -9
- package/dist/capacitor.cjs +2 -2
- package/dist/capacitor.cjs.map +1 -1
- package/dist/capacitor.d.cts +1 -1
- package/dist/capacitor.d.ts +1 -1
- package/dist/capacitor.js +1 -1
- package/dist/{chunk-SQB6E7V2.js → chunk-XAHQXK76.js} +3 -3
- package/dist/{chunk-SQB6E7V2.js.map → chunk-XAHQXK76.js.map} +1 -1
- package/dist/{dexie-BFPA0JU2.d.ts → dexie-ImxmapkS.d.ts} +5 -5
- package/dist/{dexie-T9m1mP1h.d.cts → dexie-q17SmbBw.d.cts} +5 -5
- package/dist/dexie.d.cts +2 -2
- package/dist/dexie.d.ts +2 -2
- package/dist/expoSqlite.d.cts +1 -1
- package/dist/expoSqlite.d.ts +1 -1
- package/dist/index.cjs +54 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -8
- package/dist/index.d.ts +9 -8
- package/dist/index.js +54 -27
- package/dist/index.js.map +1 -1
- package/dist/node.cjs +5 -5
- package/dist/node.cjs.map +1 -1
- package/dist/node.d.cts +9 -9
- package/dist/node.d.ts +9 -9
- package/dist/node.js +4 -4
- package/dist/node.js.map +1 -1
- package/dist/react/index.d.cts +3 -3
- package/dist/react/index.d.ts +3 -3
- package/dist/{types-DLFva7gq.d.ts → types-B7xq90Kc.d.cts} +2 -2
- package/dist/{types-9I2fmDbU.d.cts → types-CfvYBKI_.d.ts} +2 -2
- package/dist/{types-CSbIAfu2.d.cts → types-DeiRXWKl.d.cts} +4 -8
- package/dist/{types-CSbIAfu2.d.ts → types-DeiRXWKl.d.ts} +4 -8
- package/dist/wa-sqlite.cjs +9 -9
- package/dist/wa-sqlite.cjs.map +1 -1
- package/dist/wa-sqlite.d.cts +13 -13
- package/dist/wa-sqlite.d.ts +13 -13
- package/dist/wa-sqlite.js +8 -8
- package/dist/wa-sqlite.js.map +1 -1
- package/package.json +6 -4
- package/src/core/tableEnhancers.ts +15 -5
- package/src/index.native.ts +1 -1
- package/src/index.shared.ts +42 -14
- package/src/index.ts +1 -1
- package/src/node.ts +1 -1
- package/src/storage/sqlite/SQLiteAdapter.ts +10 -13
- package/src/storage/sqlite/{SqliteQueryContext.ts → SQLiteQueryContext.ts} +1 -1
- package/src/storage/sqlite/drivers/{BetterSqlite3Driver.ts → BetterSQLite3Driver.ts} +8 -8
- package/src/storage/sqlite/drivers/CapacitorSQLiteDriver.ts +2 -2
- package/src/storage/sqlite/drivers/{WaSqliteDriver.ts → WaSQLiteDriver.ts} +20 -20
- package/src/storage/sqlite/index.ts +1 -1
- package/src/storage/sqlite/types.ts +4 -9
- package/src/storage/types.ts +2 -2
- package/src/types.ts +1 -1
- package/src/wa-sqlite.ts +1 -1
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, c as ApiFunctions, f as BatchFirstLoadResult, d as BatchPushPayload, e as BatchPushResult, B as BatchSync, C as ConflictResolutionStrategy, 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
|
|
4
|
-
export { b as MemoryAdapter, c as SQLiteAdapter, d as StorageAdapter } from './dexie-
|
|
5
|
-
import { c as SQLiteVersionConfigurator } 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-B7xq90Kc.cjs';
|
|
2
|
+
export { A as AfterRemoteAddCallback, c as ApiFunctions, f as BatchFirstLoadResult, d as BatchPushPayload, e as BatchPushResult, B as BatchSync, C as ConflictResolutionStrategy, 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-B7xq90Kc.cjs';
|
|
3
|
+
import { T as TableSchemaDefinition, D as DexieQueryContext, S as SQLiteQueryContext, M as MemoryQueryContext, a as StorageTable } from './dexie-q17SmbBw.cjs';
|
|
4
|
+
export { b as MemoryAdapter, c as SQLiteAdapter, d as StorageAdapter } from './dexie-q17SmbBw.cjs';
|
|
5
|
+
import { c as SQLiteVersionConfigurator } from './types-DeiRXWKl.cjs';
|
|
6
|
+
export { S as SQLiteDatabaseDriver, b as SQLiteQueryResult, a as SQLiteRunResult } from './types-DeiRXWKl.cjs';
|
|
7
7
|
import 'dexie';
|
|
8
8
|
|
|
9
9
|
declare class DyncBase<_TStoreMap extends Record<string, any> = Record<string, any>> {
|
|
@@ -56,12 +56,13 @@ declare class DyncBase<_TStoreMap extends Record<string, any> = Record<string, a
|
|
|
56
56
|
open(): Promise<void>;
|
|
57
57
|
close(): Promise<void>;
|
|
58
58
|
delete(): Promise<void>;
|
|
59
|
-
query<R>(callback: (ctx: DexieQueryContext |
|
|
59
|
+
query<R>(callback: (ctx: DexieQueryContext | SQLiteQueryContext | MemoryQueryContext) => Promise<R>): Promise<R>;
|
|
60
60
|
table<K extends keyof _TStoreMap>(name: K): StorageTable<_TStoreMap[K]>;
|
|
61
61
|
table<T = any>(name: string): StorageTable<T>;
|
|
62
62
|
private withTransaction;
|
|
63
63
|
private setupEnhancedTables;
|
|
64
64
|
private injectSyncColumns;
|
|
65
|
+
private injectLocalIdColumn;
|
|
65
66
|
private enhanceSyncTable;
|
|
66
67
|
private syncOnce;
|
|
67
68
|
private pullAll;
|
|
@@ -93,4 +94,4 @@ type Dync<TStoreMap extends Record<string, any> = Record<string, any>> = DyncIns
|
|
|
93
94
|
|
|
94
95
|
declare function createLocalId(): string;
|
|
95
96
|
|
|
96
|
-
export { Dync, DyncOptions, MemoryQueryContext,
|
|
97
|
+
export { Dync, DyncOptions, MemoryQueryContext, SQLiteQueryContext, TableMap, createLocalId };
|
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, c as ApiFunctions, f as BatchFirstLoadResult, d as BatchPushPayload, e as BatchPushResult, B as BatchSync, C as ConflictResolutionStrategy, 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
|
|
4
|
-
export { b as MemoryAdapter, c as SQLiteAdapter, d as StorageAdapter } from './dexie-
|
|
5
|
-
import { c as SQLiteVersionConfigurator } 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-CfvYBKI_.js';
|
|
2
|
+
export { A as AfterRemoteAddCallback, c as ApiFunctions, f as BatchFirstLoadResult, d as BatchPushPayload, e as BatchPushResult, B as BatchSync, C as ConflictResolutionStrategy, 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-CfvYBKI_.js';
|
|
3
|
+
import { T as TableSchemaDefinition, D as DexieQueryContext, S as SQLiteQueryContext, M as MemoryQueryContext, a as StorageTable } from './dexie-ImxmapkS.js';
|
|
4
|
+
export { b as MemoryAdapter, c as SQLiteAdapter, d as StorageAdapter } from './dexie-ImxmapkS.js';
|
|
5
|
+
import { c as SQLiteVersionConfigurator } from './types-DeiRXWKl.js';
|
|
6
|
+
export { S as SQLiteDatabaseDriver, b as SQLiteQueryResult, a as SQLiteRunResult } from './types-DeiRXWKl.js';
|
|
7
7
|
import 'dexie';
|
|
8
8
|
|
|
9
9
|
declare class DyncBase<_TStoreMap extends Record<string, any> = Record<string, any>> {
|
|
@@ -56,12 +56,13 @@ declare class DyncBase<_TStoreMap extends Record<string, any> = Record<string, a
|
|
|
56
56
|
open(): Promise<void>;
|
|
57
57
|
close(): Promise<void>;
|
|
58
58
|
delete(): Promise<void>;
|
|
59
|
-
query<R>(callback: (ctx: DexieQueryContext |
|
|
59
|
+
query<R>(callback: (ctx: DexieQueryContext | SQLiteQueryContext | MemoryQueryContext) => Promise<R>): Promise<R>;
|
|
60
60
|
table<K extends keyof _TStoreMap>(name: K): StorageTable<_TStoreMap[K]>;
|
|
61
61
|
table<T = any>(name: string): StorageTable<T>;
|
|
62
62
|
private withTransaction;
|
|
63
63
|
private setupEnhancedTables;
|
|
64
64
|
private injectSyncColumns;
|
|
65
|
+
private injectLocalIdColumn;
|
|
65
66
|
private enhanceSyncTable;
|
|
66
67
|
private syncOnce;
|
|
67
68
|
private pullAll;
|
|
@@ -93,4 +94,4 @@ type Dync<TStoreMap extends Record<string, any> = Record<string, any>> = DyncIns
|
|
|
93
94
|
|
|
94
95
|
declare function createLocalId(): string;
|
|
95
96
|
|
|
96
|
-
export { Dync, DyncOptions, MemoryQueryContext,
|
|
97
|
+
export { Dync, DyncOptions, MemoryQueryContext, SQLiteQueryContext, TableMap, createLocalId };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./chunk-
|
|
1
|
+
import "./chunk-XAHQXK76.js";
|
|
2
2
|
|
|
3
3
|
// src/logger.ts
|
|
4
4
|
function newLogger(base, min) {
|
|
@@ -341,12 +341,14 @@ function wrapWithMutationEmitter(table, tableName, emitMutation) {
|
|
|
341
341
|
const rawBulkDelete = table.raw.bulkDelete;
|
|
342
342
|
const rawClear = table.raw.clear;
|
|
343
343
|
table.add = async (item) => {
|
|
344
|
-
const
|
|
344
|
+
const itemWithLocalId = { ...item, _localId: item._localId || createLocalId() };
|
|
345
|
+
const result = await rawAdd(itemWithLocalId);
|
|
345
346
|
emitMutation({ type: "add", tableName, keys: [result] });
|
|
346
347
|
return result;
|
|
347
348
|
};
|
|
348
349
|
table.put = async (item) => {
|
|
349
|
-
const
|
|
350
|
+
const itemWithLocalId = { ...item, _localId: item._localId || createLocalId() };
|
|
351
|
+
const result = await rawPut(itemWithLocalId);
|
|
350
352
|
emitMutation({ type: "update", tableName, keys: [result] });
|
|
351
353
|
return result;
|
|
352
354
|
};
|
|
@@ -362,14 +364,22 @@ function wrapWithMutationEmitter(table, tableName, emitMutation) {
|
|
|
362
364
|
emitMutation({ type: "delete", tableName, keys: [key] });
|
|
363
365
|
};
|
|
364
366
|
table.bulkAdd = async (items) => {
|
|
365
|
-
const
|
|
367
|
+
const itemsWithLocalIds = items.map((item) => ({
|
|
368
|
+
...item,
|
|
369
|
+
_localId: item._localId || createLocalId()
|
|
370
|
+
}));
|
|
371
|
+
const result = await rawBulkAdd(itemsWithLocalIds);
|
|
366
372
|
if (items.length > 0) {
|
|
367
373
|
emitMutation({ type: "add", tableName });
|
|
368
374
|
}
|
|
369
375
|
return result;
|
|
370
376
|
};
|
|
371
377
|
table.bulkPut = async (items) => {
|
|
372
|
-
const
|
|
378
|
+
const itemsWithLocalIds = items.map((item) => ({
|
|
379
|
+
...item,
|
|
380
|
+
_localId: item._localId || createLocalId()
|
|
381
|
+
}));
|
|
382
|
+
const result = await rawBulkPut(itemsWithLocalIds);
|
|
373
383
|
if (items.length > 0) {
|
|
374
384
|
emitMutation({ type: "update", tableName });
|
|
375
385
|
}
|
|
@@ -1310,13 +1320,15 @@ var DyncBase = class {
|
|
|
1310
1320
|
*/
|
|
1311
1321
|
constructor(config) {
|
|
1312
1322
|
const { databaseName, storageAdapter, sync: syncConfig, options } = config;
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1323
|
+
if (syncConfig) {
|
|
1324
|
+
const isBatchMode = typeof syncConfig.push === "function" && typeof syncConfig.pull === "function";
|
|
1325
|
+
if (isBatchMode) {
|
|
1326
|
+
this.batchSync = syncConfig;
|
|
1327
|
+
this.syncedTables = new Set(this.batchSync.syncTables);
|
|
1328
|
+
} else {
|
|
1329
|
+
this.syncApis = syncConfig;
|
|
1330
|
+
this.syncedTables = new Set(Object.keys(this.syncApis));
|
|
1331
|
+
}
|
|
1320
1332
|
}
|
|
1321
1333
|
this.adapter = storageAdapter;
|
|
1322
1334
|
this.name = databaseName;
|
|
@@ -1361,6 +1373,8 @@ var DyncBase = class {
|
|
|
1361
1373
|
if (typeof tableSchema === "string") {
|
|
1362
1374
|
if (isSyncTable) {
|
|
1363
1375
|
fullSchema[tableName] = `${LOCAL_PK}, &${SERVER_PK}, ${tableSchema}, ${UPDATED_AT}`;
|
|
1376
|
+
} else {
|
|
1377
|
+
fullSchema[tableName] = `${LOCAL_PK}, ${tableSchema}`;
|
|
1364
1378
|
}
|
|
1365
1379
|
self.logger.debug(
|
|
1366
1380
|
`[dync] Defining ${isSyncTable ? "" : "non-"}sync table '${tableName}' with primary key & indexes '${fullSchema[tableName]}'`
|
|
@@ -1368,6 +1382,8 @@ var DyncBase = class {
|
|
|
1368
1382
|
} else {
|
|
1369
1383
|
if (isSyncTable) {
|
|
1370
1384
|
fullSchema[tableName] = self.injectSyncColumns(tableSchema);
|
|
1385
|
+
} else {
|
|
1386
|
+
fullSchema[tableName] = self.injectLocalIdColumn(tableSchema);
|
|
1371
1387
|
}
|
|
1372
1388
|
const schemaColumns = Object.keys(fullSchema[tableName].columns ?? {}).join(", ");
|
|
1373
1389
|
const schemaIndexes = (fullSchema[tableName].indexes ?? []).map((idx) => idx.columns.join("+")).join(", ");
|
|
@@ -1399,11 +1415,11 @@ var DyncBase = class {
|
|
|
1399
1415
|
const sqliteOptions = schemaOptions.sqlite ??= {};
|
|
1400
1416
|
const migrations = sqliteOptions.migrations ??= {};
|
|
1401
1417
|
const configurator = {
|
|
1402
|
-
|
|
1403
|
-
migrations.
|
|
1418
|
+
up(handler) {
|
|
1419
|
+
migrations.up = handler;
|
|
1404
1420
|
},
|
|
1405
|
-
|
|
1406
|
-
migrations.
|
|
1421
|
+
down(handler) {
|
|
1422
|
+
migrations.down = handler;
|
|
1407
1423
|
}
|
|
1408
1424
|
};
|
|
1409
1425
|
configure(configurator);
|
|
@@ -1514,6 +1530,20 @@ var DyncBase = class {
|
|
|
1514
1530
|
indexes: injectedIndexes
|
|
1515
1531
|
};
|
|
1516
1532
|
}
|
|
1533
|
+
injectLocalIdColumn(schema) {
|
|
1534
|
+
const columns = schema.columns ?? {};
|
|
1535
|
+
if (columns[LOCAL_PK]) {
|
|
1536
|
+
throw new Error(`Column '${LOCAL_PK}' is auto-injected and cannot be defined manually.`);
|
|
1537
|
+
}
|
|
1538
|
+
const injectedColumns = {
|
|
1539
|
+
...columns,
|
|
1540
|
+
[LOCAL_PK]: { type: "TEXT" }
|
|
1541
|
+
};
|
|
1542
|
+
return {
|
|
1543
|
+
...schema,
|
|
1544
|
+
columns: injectedColumns
|
|
1545
|
+
};
|
|
1546
|
+
}
|
|
1517
1547
|
enhanceSyncTable(table, tableName) {
|
|
1518
1548
|
enhanceSyncTable({
|
|
1519
1549
|
table,
|
|
@@ -2472,8 +2502,8 @@ var normalizeComparableValue = (value) => {
|
|
|
2472
2502
|
return value;
|
|
2473
2503
|
};
|
|
2474
2504
|
|
|
2475
|
-
// src/storage/sqlite/
|
|
2476
|
-
var
|
|
2505
|
+
// src/storage/sqlite/SQLiteQueryContext.ts
|
|
2506
|
+
var SQLiteQueryContext = class {
|
|
2477
2507
|
constructor(driver, adapter) {
|
|
2478
2508
|
this.driver = driver;
|
|
2479
2509
|
this.adapter = adapter;
|
|
@@ -2659,7 +2689,7 @@ var SQLiteAdapter2 = class {
|
|
|
2659
2689
|
async query(arg1, arg2) {
|
|
2660
2690
|
if (typeof arg1 === "function") {
|
|
2661
2691
|
const driver2 = await this.getDriver();
|
|
2662
|
-
return arg1(new
|
|
2692
|
+
return arg1(new SQLiteQueryContext(driver2, this));
|
|
2663
2693
|
}
|
|
2664
2694
|
const statement = arg1;
|
|
2665
2695
|
const values = arg2;
|
|
@@ -2778,25 +2808,22 @@ var SQLiteAdapter2 = class {
|
|
|
2778
2808
|
}
|
|
2779
2809
|
if (currentVersion < targetVersion) {
|
|
2780
2810
|
for (let version = currentVersion + 1; version <= targetVersion; version += 1) {
|
|
2781
|
-
await this.runMigrationStep(version, "
|
|
2811
|
+
await this.runMigrationStep(version, "up");
|
|
2782
2812
|
await this.setStoredSchemaVersion(version);
|
|
2783
2813
|
}
|
|
2784
2814
|
return;
|
|
2785
2815
|
}
|
|
2786
2816
|
for (let version = currentVersion; version > targetVersion; version -= 1) {
|
|
2787
|
-
await this.runMigrationStep(version, "
|
|
2817
|
+
await this.runMigrationStep(version, "down");
|
|
2788
2818
|
await this.setStoredSchemaVersion(version - 1);
|
|
2789
2819
|
}
|
|
2790
2820
|
}
|
|
2791
|
-
async runMigrationStep(version, direction
|
|
2821
|
+
async runMigrationStep(version, direction) {
|
|
2792
2822
|
const handler = this.getMigrationHandler(version, direction);
|
|
2793
2823
|
if (!handler) {
|
|
2794
2824
|
return;
|
|
2795
2825
|
}
|
|
2796
2826
|
const context = {
|
|
2797
|
-
direction,
|
|
2798
|
-
fromVersion,
|
|
2799
|
-
toVersion,
|
|
2800
2827
|
execute: (statement) => this.internalExecute(statement),
|
|
2801
2828
|
run: (statement, values) => this.internalRun(statement, values),
|
|
2802
2829
|
query: (statement, values) => this.internalQuery(statement, values)
|
|
@@ -2809,7 +2836,7 @@ var SQLiteAdapter2 = class {
|
|
|
2809
2836
|
if (!migrations) {
|
|
2810
2837
|
return void 0;
|
|
2811
2838
|
}
|
|
2812
|
-
return direction === "
|
|
2839
|
+
return direction === "up" ? migrations.up : migrations.down;
|
|
2813
2840
|
}
|
|
2814
2841
|
async applySchema() {
|
|
2815
2842
|
if (this.schemaApplied) {
|
|
@@ -3866,7 +3893,7 @@ export {
|
|
|
3866
3893
|
MemoryAdapter,
|
|
3867
3894
|
MemoryQueryContext,
|
|
3868
3895
|
SQLiteAdapter2 as SQLiteAdapter,
|
|
3869
|
-
|
|
3896
|
+
SQLiteQueryContext,
|
|
3870
3897
|
SyncAction,
|
|
3871
3898
|
createLocalId
|
|
3872
3899
|
};
|