@anfenn/dync 1.0.26 → 1.0.28

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.d.cts CHANGED
@@ -1,12 +1,12 @@
1
- import { A as ApiFunctions, S as SyncOptions, B as BatchSync, a as SyncStatus, b as SyncApi, T as TableMap } from './types-BgGGLrE9.cjs';
2
- export { d as AfterRemoteAddCallback, g as BatchFirstLoadResult, e as BatchPushPayload, f as BatchPushResult, C as ConflictResolutionStrategy, F as FirstLoadProgress, h as FirstLoadProgressCallback, i as MissingRemoteRecordDuringUpdateCallback, M as MissingRemoteRecordStrategy, j as MutationEvent, c as SyncAction, k as SyncState, l as SyncedRecord } from './types-BgGGLrE9.cjs';
3
- import { S as StorageAdapter, T as TableSchemaDefinition, D as DexieQueryContext, a as SqliteQueryContext, M as MemoryQueryContext, b as StorageTable } from './dexie-DtgGGM68.cjs';
4
- export { c as MemoryAdapter, d as SQLiteAdapter } from './dexie-DtgGGM68.cjs';
1
+ import { D as DyncOptions, S as SyncStatus, a as SyncApi, T as TableMap } from './types-9I2fmDbU.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-9I2fmDbU.cjs';
3
+ import { T as TableSchemaDefinition, D as DexieQueryContext, S as SqliteQueryContext, M as MemoryQueryContext, a as StorageTable } from './dexie-T9m1mP1h.cjs';
4
+ export { b as MemoryAdapter, c as SQLiteAdapter, d as StorageAdapter } from './dexie-T9m1mP1h.cjs';
5
5
  import { c as SQLiteVersionConfigurator } from './types-CSbIAfu2.cjs';
6
6
  export { S as SQLiteDatabaseDriver, b as SQLiteQueryResult, a as SQLiteRunResult } from './types-CSbIAfu2.cjs';
7
7
  import 'dexie';
8
8
 
9
- declare class DyncBase<_TStoreMap = Record<string, any>> {
9
+ declare class DyncBase<_TStoreMap extends Record<string, any> = Record<string, any>> {
10
10
  private readonly adapter;
11
11
  private readonly tableCache;
12
12
  private readonly mutationWrappedTables;
@@ -30,20 +30,25 @@ declare class DyncBase<_TStoreMap = Record<string, any>> {
30
30
  /**
31
31
  * Create a new Dync instance.
32
32
  *
33
- * Mode 1 - Per-table endpoints:
34
- * @param databaseName - Name of the database
35
- * @param syncApis - Map of table names to API functions
36
- * @param storageAdapter - Storage adapter implementation (required)
37
- * @param options - Sync options
33
+ * @example Per-table sync mode
34
+ * ```ts
35
+ * const db = new Dync<Store>({
36
+ * databaseName: 'my-app',
37
+ * storageAdapter: new SQLiteAdapter(driver),
38
+ * sync: { todos: todoSyncApi },
39
+ * });
40
+ * ```
38
41
  *
39
- * Mode 2 - Batch endpoints:
40
- * @param databaseName - Name of the database
41
- * @param batchSync - Batch sync config (syncTables, push, pull, firstLoad)
42
- * @param storageAdapter - Storage adapter implementation (required)
43
- * @param options - Sync options
42
+ * @example Batch sync mode
43
+ * ```ts
44
+ * const db = new Dync<Store>({
45
+ * databaseName: 'my-app',
46
+ * storageAdapter: new SQLiteAdapter(driver),
47
+ * sync: { syncTables: ['todos'], push, pull },
48
+ * });
49
+ * ```
44
50
  */
45
- constructor(databaseName: string, syncApis: Record<string, ApiFunctions>, storageAdapter: StorageAdapter, options?: SyncOptions);
46
- constructor(databaseName: string, batchSync: BatchSync, storageAdapter: StorageAdapter, options?: SyncOptions);
51
+ constructor(config: DyncOptions<_TStoreMap>);
47
52
  version(versionNumber: number): {
48
53
  stores(schema: Record<string, TableSchemaDefinition>): /*elided*/ any;
49
54
  sqlite(configure: (builder: SQLiteVersionConfigurator) => void): /*elided*/ any;
@@ -76,17 +81,16 @@ declare class DyncBase<_TStoreMap = Record<string, any>> {
76
81
  private emitMutation;
77
82
  sync: SyncApi;
78
83
  }
79
- type DyncInstance<TStoreMap extends Record<string, unknown> = Record<string, unknown>> = DyncBase<TStoreMap> & TableMap<TStoreMap> & {
84
+ type DyncInstance<TStoreMap extends Record<string, any> = Record<string, any>> = DyncBase<TStoreMap> & TableMap<TStoreMap> & {
80
85
  table<K extends keyof TStoreMap & string>(name: K): StorageTable<TStoreMap[K]>;
81
86
  table(name: string): StorageTable<any>;
82
87
  };
83
88
  declare const Dync: {
84
- new <TStoreMap extends Record<string, unknown> = Record<string, unknown>>(databaseName: string, syncApis: Record<string, ApiFunctions>, storageAdapter: StorageAdapter, options?: SyncOptions): DyncInstance<TStoreMap>;
85
- new <TStoreMap extends Record<string, unknown> = Record<string, unknown>>(databaseName: string, batchSync: BatchSync, storageAdapter: StorageAdapter, options?: SyncOptions): DyncInstance<TStoreMap>;
86
- prototype: DyncInstance<Record<string, unknown>>;
87
- } & typeof DyncBase;
88
- type Dync<TStoreMap extends Record<string, unknown> = Record<string, unknown>> = DyncInstance<TStoreMap>;
89
+ <TStoreMap extends Record<string, any> = Record<string, any>>(config: DyncOptions<TStoreMap>): DyncInstance<TStoreMap>;
90
+ new <TStoreMap extends Record<string, any> = Record<string, any>>(config: DyncOptions<TStoreMap>): DyncInstance<TStoreMap>;
91
+ };
92
+ type Dync<TStoreMap extends Record<string, any> = Record<string, any>> = DyncInstance<TStoreMap>;
89
93
 
90
94
  declare function createLocalId(): string;
91
95
 
92
- export { ApiFunctions, BatchSync, Dync, MemoryQueryContext, SqliteQueryContext, StorageAdapter, SyncOptions, TableMap, createLocalId };
96
+ export { Dync, DyncOptions, MemoryQueryContext, SqliteQueryContext, TableMap, createLocalId };
package/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- import { A as ApiFunctions, S as SyncOptions, B as BatchSync, a as SyncStatus, b as SyncApi, T as TableMap } from './types-B1Vn8_DF.js';
2
- export { d as AfterRemoteAddCallback, g as BatchFirstLoadResult, e as BatchPushPayload, f as BatchPushResult, C as ConflictResolutionStrategy, F as FirstLoadProgress, h as FirstLoadProgressCallback, i as MissingRemoteRecordDuringUpdateCallback, M as MissingRemoteRecordStrategy, j as MutationEvent, c as SyncAction, k as SyncState, l as SyncedRecord } from './types-B1Vn8_DF.js';
3
- import { S as StorageAdapter, T as TableSchemaDefinition, D as DexieQueryContext, a as SqliteQueryContext, M as MemoryQueryContext, b as StorageTable } from './dexie-B1FuZqDB.js';
4
- export { c as MemoryAdapter, d as SQLiteAdapter } from './dexie-B1FuZqDB.js';
1
+ import { D as DyncOptions, S as SyncStatus, a as SyncApi, T as TableMap } from './types-DLFva7gq.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-DLFva7gq.js';
3
+ import { T as TableSchemaDefinition, D as DexieQueryContext, S as SqliteQueryContext, M as MemoryQueryContext, a as StorageTable } from './dexie-BFPA0JU2.js';
4
+ export { b as MemoryAdapter, c as SQLiteAdapter, d as StorageAdapter } from './dexie-BFPA0JU2.js';
5
5
  import { c as SQLiteVersionConfigurator } from './types-CSbIAfu2.js';
6
6
  export { S as SQLiteDatabaseDriver, b as SQLiteQueryResult, a as SQLiteRunResult } from './types-CSbIAfu2.js';
7
7
  import 'dexie';
8
8
 
9
- declare class DyncBase<_TStoreMap = Record<string, any>> {
9
+ declare class DyncBase<_TStoreMap extends Record<string, any> = Record<string, any>> {
10
10
  private readonly adapter;
11
11
  private readonly tableCache;
12
12
  private readonly mutationWrappedTables;
@@ -30,20 +30,25 @@ declare class DyncBase<_TStoreMap = Record<string, any>> {
30
30
  /**
31
31
  * Create a new Dync instance.
32
32
  *
33
- * Mode 1 - Per-table endpoints:
34
- * @param databaseName - Name of the database
35
- * @param syncApis - Map of table names to API functions
36
- * @param storageAdapter - Storage adapter implementation (required)
37
- * @param options - Sync options
33
+ * @example Per-table sync mode
34
+ * ```ts
35
+ * const db = new Dync<Store>({
36
+ * databaseName: 'my-app',
37
+ * storageAdapter: new SQLiteAdapter(driver),
38
+ * sync: { todos: todoSyncApi },
39
+ * });
40
+ * ```
38
41
  *
39
- * Mode 2 - Batch endpoints:
40
- * @param databaseName - Name of the database
41
- * @param batchSync - Batch sync config (syncTables, push, pull, firstLoad)
42
- * @param storageAdapter - Storage adapter implementation (required)
43
- * @param options - Sync options
42
+ * @example Batch sync mode
43
+ * ```ts
44
+ * const db = new Dync<Store>({
45
+ * databaseName: 'my-app',
46
+ * storageAdapter: new SQLiteAdapter(driver),
47
+ * sync: { syncTables: ['todos'], push, pull },
48
+ * });
49
+ * ```
44
50
  */
45
- constructor(databaseName: string, syncApis: Record<string, ApiFunctions>, storageAdapter: StorageAdapter, options?: SyncOptions);
46
- constructor(databaseName: string, batchSync: BatchSync, storageAdapter: StorageAdapter, options?: SyncOptions);
51
+ constructor(config: DyncOptions<_TStoreMap>);
47
52
  version(versionNumber: number): {
48
53
  stores(schema: Record<string, TableSchemaDefinition>): /*elided*/ any;
49
54
  sqlite(configure: (builder: SQLiteVersionConfigurator) => void): /*elided*/ any;
@@ -76,17 +81,16 @@ declare class DyncBase<_TStoreMap = Record<string, any>> {
76
81
  private emitMutation;
77
82
  sync: SyncApi;
78
83
  }
79
- type DyncInstance<TStoreMap extends Record<string, unknown> = Record<string, unknown>> = DyncBase<TStoreMap> & TableMap<TStoreMap> & {
84
+ type DyncInstance<TStoreMap extends Record<string, any> = Record<string, any>> = DyncBase<TStoreMap> & TableMap<TStoreMap> & {
80
85
  table<K extends keyof TStoreMap & string>(name: K): StorageTable<TStoreMap[K]>;
81
86
  table(name: string): StorageTable<any>;
82
87
  };
83
88
  declare const Dync: {
84
- new <TStoreMap extends Record<string, unknown> = Record<string, unknown>>(databaseName: string, syncApis: Record<string, ApiFunctions>, storageAdapter: StorageAdapter, options?: SyncOptions): DyncInstance<TStoreMap>;
85
- new <TStoreMap extends Record<string, unknown> = Record<string, unknown>>(databaseName: string, batchSync: BatchSync, storageAdapter: StorageAdapter, options?: SyncOptions): DyncInstance<TStoreMap>;
86
- prototype: DyncInstance<Record<string, unknown>>;
87
- } & typeof DyncBase;
88
- type Dync<TStoreMap extends Record<string, unknown> = Record<string, unknown>> = DyncInstance<TStoreMap>;
89
+ <TStoreMap extends Record<string, any> = Record<string, any>>(config: DyncOptions<TStoreMap>): DyncInstance<TStoreMap>;
90
+ new <TStoreMap extends Record<string, any> = Record<string, any>>(config: DyncOptions<TStoreMap>): DyncInstance<TStoreMap>;
91
+ };
92
+ type Dync<TStoreMap extends Record<string, any> = Record<string, any>> = DyncInstance<TStoreMap>;
89
93
 
90
94
  declare function createLocalId(): string;
91
95
 
92
- export { ApiFunctions, BatchSync, Dync, MemoryQueryContext, SqliteQueryContext, StorageAdapter, SyncOptions, TableMap, createLocalId };
96
+ export { Dync, DyncOptions, MemoryQueryContext, SqliteQueryContext, TableMap, createLocalId };
package/dist/index.js CHANGED
@@ -1287,13 +1287,35 @@ var DyncBase = class {
1287
1287
  mutationsDuringSync = false;
1288
1288
  state;
1289
1289
  name;
1290
- constructor(databaseName, syncApisOrBatchSync, storageAdapter, options) {
1291
- const isBatchMode = typeof syncApisOrBatchSync.push === "function";
1290
+ /**
1291
+ * Create a new Dync instance.
1292
+ *
1293
+ * @example Per-table sync mode
1294
+ * ```ts
1295
+ * const db = new Dync<Store>({
1296
+ * databaseName: 'my-app',
1297
+ * storageAdapter: new SQLiteAdapter(driver),
1298
+ * sync: { todos: todoSyncApi },
1299
+ * });
1300
+ * ```
1301
+ *
1302
+ * @example Batch sync mode
1303
+ * ```ts
1304
+ * const db = new Dync<Store>({
1305
+ * databaseName: 'my-app',
1306
+ * storageAdapter: new SQLiteAdapter(driver),
1307
+ * sync: { syncTables: ['todos'], push, pull },
1308
+ * });
1309
+ * ```
1310
+ */
1311
+ constructor(config) {
1312
+ const { databaseName, storageAdapter, sync: syncConfig, options } = config;
1313
+ const isBatchMode = typeof syncConfig.push === "function" && typeof syncConfig.pull === "function";
1292
1314
  if (isBatchMode) {
1293
- this.batchSync = syncApisOrBatchSync;
1315
+ this.batchSync = syncConfig;
1294
1316
  this.syncedTables = new Set(this.batchSync.syncTables);
1295
1317
  } else {
1296
- this.syncApis = syncApisOrBatchSync;
1318
+ this.syncApis = syncConfig;
1297
1319
  this.syncedTables = new Set(Object.keys(this.syncApis));
1298
1320
  }
1299
1321
  this.adapter = storageAdapter;
@@ -1357,6 +1379,17 @@ var DyncBase = class {
1357
1379
  storesDefined = true;
1358
1380
  self.adapter.defineSchema(versionNumber, fullSchema, schemaOptions);
1359
1381
  self.setupEnhancedTables(Object.keys(schema));
1382
+ for (const tableName of Object.keys(schema)) {
1383
+ if (!(tableName in self)) {
1384
+ Object.defineProperty(self, tableName, {
1385
+ get() {
1386
+ return self.table(tableName);
1387
+ },
1388
+ enumerable: true,
1389
+ configurable: false
1390
+ });
1391
+ }
1392
+ }
1360
1393
  return builder;
1361
1394
  },
1362
1395
  sqlite(configure) {
@@ -1695,8 +1728,7 @@ var DyncBase = class {
1695
1728
  onMutation: this.onMutation.bind(this)
1696
1729
  };
1697
1730
  };
1698
- var DyncConstructor = DyncBase;
1699
- var Dync = DyncConstructor;
1731
+ var Dync = DyncBase;
1700
1732
 
1701
1733
  // src/storage/memory/MemoryQueryContext.ts
1702
1734
  var MemoryQueryContext = class {