@anfenn/dync 1.0.3 → 1.0.4

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 (35) hide show
  1. package/README.md +31 -13
  2. package/dist/{chunk-66PSQW4D.js → chunk-PCA4XM2N.js} +17 -17
  3. package/dist/chunk-PCA4XM2N.js.map +1 -0
  4. package/dist/{dexie-Bv-fV10P.d.cts → dexie-1_xyU5MV.d.cts} +41 -38
  5. package/dist/{dexie-DJFApKsM.d.ts → dexie-ChZ0o0Sz.d.ts} +41 -38
  6. package/dist/dexie.cjs +40 -40
  7. package/dist/dexie.cjs.map +1 -1
  8. package/dist/dexie.d.cts +1 -1
  9. package/dist/dexie.d.ts +1 -1
  10. package/dist/dexie.js +40 -40
  11. package/dist/dexie.js.map +1 -1
  12. package/dist/index.cjs +16 -16
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.cts +2 -2
  15. package/dist/index.d.ts +2 -2
  16. package/dist/index.js +1 -1
  17. package/dist/{index.shared-CkYsQYyn.d.ts → index.shared-Byhq6TyU.d.ts} +1 -1
  18. package/dist/{index.shared-BGwvMH8f.d.cts → index.shared-DsDBNWlz.d.cts} +1 -1
  19. package/dist/react/index.cjs +2 -2
  20. package/dist/react/index.cjs.map +1 -1
  21. package/dist/react/index.d.cts +2 -2
  22. package/dist/react/index.d.ts +2 -2
  23. package/dist/react/index.js +1 -1
  24. package/package.json +1 -1
  25. package/src/core/tableEnhancers.ts +17 -17
  26. package/src/storage/dexie/DexieAdapter.ts +2 -2
  27. package/src/storage/dexie/{DexieStorageCollection.ts → DexieCollection.ts} +12 -12
  28. package/src/storage/dexie/DexieTable.ts +123 -0
  29. package/src/storage/dexie/{DexieStorageWhereClause.ts → DexieWhereClause.ts} +21 -21
  30. package/src/storage/dexie/index.ts +3 -3
  31. package/src/storage/memory/MemoryTable.ts +40 -40
  32. package/src/storage/sqlite/SQLiteTable.ts +34 -36
  33. package/src/storage/types.ts +22 -19
  34. package/dist/chunk-66PSQW4D.js.map +0 -1
  35. package/src/storage/dexie/DexieStorageTable.ts +0 -123
@@ -1,5 +1,5 @@
1
- import { a as ApiFunctions, h as SyncOptions, B as BatchSync, D as Dync, i as SyncState } from '../index.shared-BGwvMH8f.cjs';
2
- import { c as StorageAdapter } from '../dexie-Bv-fV10P.cjs';
1
+ import { a as ApiFunctions, h as SyncOptions, B as BatchSync, D as Dync, i as SyncState } from '../index.shared-DsDBNWlz.cjs';
2
+ import { c as StorageAdapter } from '../dexie-1_xyU5MV.cjs';
3
3
  import '../types-CSbIAfu2.cjs';
4
4
  import 'dexie';
5
5
 
@@ -1,5 +1,5 @@
1
- import { a as ApiFunctions, h as SyncOptions, B as BatchSync, D as Dync, i as SyncState } from '../index.shared-CkYsQYyn.js';
2
- import { c as StorageAdapter } from '../dexie-DJFApKsM.js';
1
+ import { a as ApiFunctions, h as SyncOptions, B as BatchSync, D as Dync, i as SyncState } from '../index.shared-Byhq6TyU.js';
2
+ import { c as StorageAdapter } from '../dexie-ChZ0o0Sz.js';
3
3
  import '../types-CSbIAfu2.js';
4
4
  import 'dexie';
5
5
 
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Dync
3
- } from "../chunk-66PSQW4D.js";
3
+ } from "../chunk-PCA4XM2N.js";
4
4
  import "../chunk-SQB6E7V2.js";
5
5
 
6
6
  // src/react/useDync.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anfenn/dync",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "private": false,
5
5
  "description": "Write once, run IndexedDB & SQLite with sync anywhere - React, React Native, Expo, Capacitor, Electron & Node.js",
6
6
  "keywords": [],
@@ -1,6 +1,6 @@
1
1
  import { createLocalId } from '../helpers';
2
2
  import { SyncAction, type MutationEvent, type SyncedRecord } from '../types';
3
- import type { StorageTable } from '../storage/types';
3
+ import type { AddItem, StorageTable } from '../storage/types';
4
4
  import { DYNC_STATE_TABLE, type StateHelpers } from './StateManager';
5
5
  import type { WithTransaction } from './types';
6
6
  export type EmitMutation = (event: MutationEvent) => void;
@@ -20,8 +20,8 @@ export function wrapWithMutationEmitter<T>(table: StorageTable<T>, tableName: st
20
20
  const rawBulkDelete = table.raw.bulkDelete;
21
21
  const rawClear = table.raw.clear;
22
22
 
23
- table.add = async (item: T) => {
24
- const result = await rawAdd(item);
23
+ table.add = async (item: AddItem<T>) => {
24
+ const result = await rawAdd(item as T);
25
25
  emitMutation({ type: 'add', tableName, keys: [result] });
26
26
  return result;
27
27
  };
@@ -32,7 +32,7 @@ export function wrapWithMutationEmitter<T>(table: StorageTable<T>, tableName: st
32
32
  return result;
33
33
  };
34
34
 
35
- table.update = async (key: unknown, changes: Partial<T>) => {
35
+ table.update = async (key: string, changes: Partial<T>) => {
36
36
  const result = await rawUpdate(key, changes);
37
37
  if (result > 0) {
38
38
  emitMutation({ type: 'update', tableName, keys: [key] });
@@ -40,13 +40,13 @@ export function wrapWithMutationEmitter<T>(table: StorageTable<T>, tableName: st
40
40
  return result;
41
41
  };
42
42
 
43
- table.delete = async (key: unknown) => {
43
+ table.delete = async (key: string) => {
44
44
  await rawDelete(key);
45
45
  emitMutation({ type: 'delete', tableName, keys: [key] });
46
46
  };
47
47
 
48
- table.bulkAdd = async (items: T[]) => {
49
- const result = await rawBulkAdd(items);
48
+ table.bulkAdd = async (items: AddItem<T>[]) => {
49
+ const result = await rawBulkAdd(items as T[]);
50
50
  if (items.length > 0) {
51
51
  emitMutation({ type: 'add', tableName });
52
52
  }
@@ -61,7 +61,7 @@ export function wrapWithMutationEmitter<T>(table: StorageTable<T>, tableName: st
61
61
  return result;
62
62
  };
63
63
 
64
- table.bulkUpdate = async (keysAndChanges: Array<{ key: unknown; changes: Partial<T> }>) => {
64
+ table.bulkUpdate = async (keysAndChanges: Array<{ key: string; changes: Partial<T> }>) => {
65
65
  const result = await rawBulkUpdate(keysAndChanges);
66
66
  if (result > 0) {
67
67
  emitMutation({ type: 'update', tableName, keys: keysAndChanges.map((kc) => kc.key) });
@@ -69,7 +69,7 @@ export function wrapWithMutationEmitter<T>(table: StorageTable<T>, tableName: st
69
69
  return result;
70
70
  };
71
71
 
72
- table.bulkDelete = async (keys: unknown[]) => {
72
+ table.bulkDelete = async (keys: string[]) => {
73
73
  await rawBulkDelete(keys);
74
74
  if (keys.length > 0) {
75
75
  emitMutation({ type: 'delete', tableName });
@@ -134,7 +134,7 @@ export function enhanceSyncTable<T>({ table, tableName, withTransaction, state,
134
134
  updated_at: new Date().toISOString(),
135
135
  };
136
136
 
137
- let result: any;
137
+ let result!: string;
138
138
  await withTransaction('rw', [tableName, DYNC_STATE_TABLE], async () => {
139
139
  result = await rawAdd(syncedItem);
140
140
 
@@ -162,7 +162,7 @@ export function enhanceSyncTable<T>({ table, tableName, withTransaction, state,
162
162
  updated_at: new Date().toISOString(),
163
163
  };
164
164
 
165
- let result: any;
165
+ let result!: string;
166
166
  let isUpdate = false;
167
167
  let existingRecord: any;
168
168
 
@@ -248,8 +248,8 @@ export function enhanceSyncTable<T>({ table, tableName, withTransaction, state,
248
248
  }
249
249
  };
250
250
 
251
- const wrappedBulkAdd = async (items: any[]) => {
252
- if (items.length === 0) return;
251
+ const wrappedBulkAdd = async (items: any[]): Promise<string[]> => {
252
+ if (items.length === 0) return [];
253
253
 
254
254
  const now = new Date().toISOString();
255
255
  const syncedItems = items.map((item) => {
@@ -261,7 +261,7 @@ export function enhanceSyncTable<T>({ table, tableName, withTransaction, state,
261
261
  };
262
262
  });
263
263
 
264
- let result: any;
264
+ let result!: string[];
265
265
  await withTransaction('rw', [tableName, DYNC_STATE_TABLE], async () => {
266
266
  result = await rawBulkAdd(syncedItems);
267
267
 
@@ -281,8 +281,8 @@ export function enhanceSyncTable<T>({ table, tableName, withTransaction, state,
281
281
  return result;
282
282
  };
283
283
 
284
- const wrappedBulkPut = async (items: any[]) => {
285
- if (items.length === 0) return;
284
+ const wrappedBulkPut = async (items: any[]): Promise<string[]> => {
285
+ if (items.length === 0) return [];
286
286
 
287
287
  const now = new Date().toISOString();
288
288
  const syncedItems = items.map((item) => {
@@ -295,7 +295,7 @@ export function enhanceSyncTable<T>({ table, tableName, withTransaction, state,
295
295
  });
296
296
  const localIds = syncedItems.map((i) => i._localId);
297
297
 
298
- let result: any;
298
+ let result!: string[];
299
299
  await withTransaction('rw', [tableName, DYNC_STATE_TABLE], async (tables) => {
300
300
  const txTable = tables[tableName]!;
301
301
 
@@ -3,7 +3,7 @@ import type { StorageAdapter, StorageTable, StorageTransactionContext, Transacti
3
3
  import type { StorageSchemaDefinitionOptions } from '../sqlite/types';
4
4
  import type { TableSchemaDefinition } from '../sqlite/schema';
5
5
  import { DexieQueryContext } from './DexieQueryContext';
6
- import { DexieStorageTable } from './DexieStorageTable';
6
+ import { DexieTable } from './DexieTable';
7
7
 
8
8
  export class DexieAdapter implements StorageAdapter {
9
9
  readonly type = 'DexieAdapter';
@@ -55,7 +55,7 @@ export class DexieAdapter implements StorageAdapter {
55
55
  table<T = any>(name: string): StorageTable<T> {
56
56
  if (!this.tableCache.has(name)) {
57
57
  const table = this.db.table<T>(name);
58
- this.tableCache.set(name, new DexieStorageTable(table));
58
+ this.tableCache.set(name, new DexieTable(table));
59
59
  }
60
60
  return this.tableCache.get(name)! as StorageTable<T>;
61
61
  }
@@ -1,12 +1,12 @@
1
- import type { Collection as DexieCollection } from 'dexie';
1
+ import type { Collection } from 'dexie';
2
2
  import type { StorageCollection, StorageWhereClause } from '../types';
3
3
  import { normalizeIndexName } from './helpers';
4
- import { DexieStorageWhereClause } from './DexieStorageWhereClause';
4
+ import { DexieWhereClause } from './DexieWhereClause';
5
5
 
6
- export class DexieStorageCollection<T = any> implements StorageCollection<T> {
7
- private readonly collection: DexieCollection<T, any, T>;
6
+ export class DexieCollection<T = any> implements StorageCollection<T> {
7
+ private readonly collection: Collection<T, any, T>;
8
8
 
9
- constructor(collection: DexieCollection<T, any, T>) {
9
+ constructor(collection: Collection<T, any, T>) {
10
10
  this.collection = collection;
11
11
  }
12
12
 
@@ -79,31 +79,31 @@ export class DexieStorageCollection<T = any> implements StorageCollection<T> {
79
79
  }
80
80
 
81
81
  distinct(): StorageCollection<T> {
82
- return new DexieStorageCollection(this.collection.distinct());
82
+ return new DexieCollection(this.collection.distinct());
83
83
  }
84
84
 
85
85
  jsFilter(predicate: (item: T) => boolean): StorageCollection<T> {
86
- return new DexieStorageCollection(this.collection.filter(predicate));
86
+ return new DexieCollection(this.collection.filter(predicate));
87
87
  }
88
88
 
89
89
  or(index: string): StorageWhereClause<T> {
90
- return new DexieStorageWhereClause(this.collection.or(normalizeIndexName(index)));
90
+ return new DexieWhereClause(this.collection.or(normalizeIndexName(index)));
91
91
  }
92
92
 
93
93
  clone(props?: Record<string, unknown>): StorageCollection<T> {
94
- return new DexieStorageCollection(this.collection.clone(props));
94
+ return new DexieCollection(this.collection.clone(props));
95
95
  }
96
96
 
97
97
  reverse(): StorageCollection<T> {
98
- return new DexieStorageCollection(this.collection.reverse());
98
+ return new DexieCollection(this.collection.reverse());
99
99
  }
100
100
 
101
101
  offset(offset: number): StorageCollection<T> {
102
- return new DexieStorageCollection(this.collection.offset(offset));
102
+ return new DexieCollection(this.collection.offset(offset));
103
103
  }
104
104
 
105
105
  limit(count: number): StorageCollection<T> {
106
- return new DexieStorageCollection(this.collection.limit(count));
106
+ return new DexieCollection(this.collection.limit(count));
107
107
  }
108
108
 
109
109
  toCollection(): StorageCollection<T> {
@@ -0,0 +1,123 @@
1
+ import type { Table } from 'dexie';
2
+ import type { AddItem, StorageCollection, StorageTable, StorageWhereClause } from '../types';
3
+ import { normalizeIndexName } from './helpers';
4
+ import { DexieCollection } from './DexieCollection';
5
+ import { DexieWhereClause } from './DexieWhereClause';
6
+
7
+ export class DexieTable<T = any> implements StorageTable<T> {
8
+ readonly name: string;
9
+ readonly schema: unknown;
10
+ readonly primaryKey: unknown;
11
+ readonly hook: unknown;
12
+ readonly raw = Object.freeze({
13
+ add: (item: T): Promise<string> => this.table.add(item) as Promise<string>,
14
+ put: (item: T): Promise<string> => this.table.put(item) as Promise<string>,
15
+ update: (key: string, changes: Partial<T>) => this.table.update(key as any, changes as any),
16
+ delete: (key: string) => this.table.delete(key as any),
17
+ get: (key: string) => this.table.get(key as any),
18
+ bulkAdd: (items: T[]): Promise<string[]> => this.table.bulkAdd(items, { allKeys: true }) as Promise<string[]>,
19
+ bulkPut: (items: T[]): Promise<string[]> => this.table.bulkPut(items, { allKeys: true }) as Promise<string[]>,
20
+ bulkUpdate: (keysAndChanges: Array<{ key: string; changes: Partial<T> }>) => this.table.bulkUpdate(keysAndChanges as any),
21
+ bulkDelete: (keys: string[]) => this.table.bulkDelete(keys as any),
22
+ clear: () => this.table.clear(),
23
+ });
24
+
25
+ private readonly table: Table<T, any, T>;
26
+
27
+ constructor(table: Table<T, any, T>) {
28
+ this.table = table;
29
+ this.name = table.name;
30
+ this.schema = table.schema;
31
+ this.primaryKey = table.schema?.primKey;
32
+ this.hook = table.hook;
33
+ }
34
+
35
+ add(item: AddItem<T>): Promise<string> {
36
+ return this.table.add(item as T);
37
+ }
38
+
39
+ put(item: T): Promise<string> {
40
+ return this.table.put(item);
41
+ }
42
+
43
+ update(key: string, changes: Partial<T>): Promise<number> {
44
+ return this.table.update(key as any, changes as any);
45
+ }
46
+
47
+ delete(key: string): Promise<void> {
48
+ return this.table.delete(key as any).then(() => undefined);
49
+ }
50
+
51
+ clear(): Promise<void> {
52
+ return this.table.clear();
53
+ }
54
+
55
+ get(key: string): Promise<T | undefined> {
56
+ return this.table.get(key as any);
57
+ }
58
+
59
+ toArray(): Promise<T[]> {
60
+ return this.table.toArray();
61
+ }
62
+
63
+ count(): Promise<number> {
64
+ return this.table.count();
65
+ }
66
+
67
+ bulkAdd(items: AddItem<T>[]): Promise<string[]> {
68
+ return this.table.bulkAdd(items as T[], { allKeys: true }) as Promise<string[]>;
69
+ }
70
+
71
+ bulkPut(items: T[]): Promise<string[]> {
72
+ return this.table.bulkPut(items, { allKeys: true }) as Promise<string[]>;
73
+ }
74
+
75
+ bulkGet(keys: string[]): Promise<Array<T | undefined>> {
76
+ return this.table.bulkGet(keys as any);
77
+ }
78
+
79
+ bulkUpdate(keysAndChanges: Array<{ key: string; changes: Partial<T> }>): Promise<number> {
80
+ return this.table.bulkUpdate(keysAndChanges as any);
81
+ }
82
+
83
+ bulkDelete(keys: string[]): Promise<void> {
84
+ return this.table.bulkDelete(keys as any);
85
+ }
86
+
87
+ where(index: string | string[]): StorageWhereClause<T> {
88
+ return new DexieWhereClause(this.table.where(normalizeIndexName(index)));
89
+ }
90
+
91
+ orderBy(index: string | string[]): StorageCollection<T> {
92
+ return new DexieCollection(this.table.orderBy(normalizeIndexName(index)));
93
+ }
94
+
95
+ reverse(): StorageCollection<T> {
96
+ return new DexieCollection(this.table.reverse());
97
+ }
98
+
99
+ offset(offset: number): StorageCollection<T> {
100
+ return new DexieCollection(this.table.offset(offset));
101
+ }
102
+
103
+ limit(count: number): StorageCollection<T> {
104
+ return new DexieCollection(this.table.limit(count));
105
+ }
106
+
107
+ mapToClass(ctor: new (...args: any[]) => any): StorageTable<T> {
108
+ this.table.mapToClass(ctor as any);
109
+ return this;
110
+ }
111
+
112
+ async each(callback: (item: T) => void | Promise<void>): Promise<void> {
113
+ const tasks: Array<void | Promise<void>> = [];
114
+ await this.table.each((item) => {
115
+ tasks.push(callback(item));
116
+ });
117
+ await Promise.all(tasks.map((task) => (task ? Promise.resolve(task) : Promise.resolve())));
118
+ }
119
+
120
+ jsFilter(predicate: (item: T) => boolean): StorageCollection<T> {
121
+ return new DexieCollection(this.table.filter(predicate));
122
+ }
123
+ }
@@ -1,36 +1,36 @@
1
- import type { WhereClause as DexieWhereClause } from 'dexie';
1
+ import type { WhereClause } from 'dexie';
2
2
  import type { StorageCollection, StorageWhereClause } from '../types';
3
- import { DexieStorageCollection } from './DexieStorageCollection';
3
+ import { DexieCollection } from './DexieCollection';
4
4
 
5
- export class DexieStorageWhereClause<T = any> implements StorageWhereClause<T> {
6
- private readonly clause: DexieWhereClause<T, any, T>;
5
+ export class DexieWhereClause<T = any> implements StorageWhereClause<T> {
6
+ private readonly clause: WhereClause<T, any, T>;
7
7
 
8
- constructor(clause: DexieWhereClause<T, any, T>) {
8
+ constructor(clause: WhereClause<T, any, T>) {
9
9
  this.clause = clause;
10
10
  }
11
11
 
12
12
  equals(value: any): StorageCollection<T> {
13
- return new DexieStorageCollection(this.clause.equals(value));
13
+ return new DexieCollection(this.clause.equals(value));
14
14
  }
15
15
 
16
16
  above(value: any): StorageCollection<T> {
17
- return new DexieStorageCollection(this.clause.above(value));
17
+ return new DexieCollection(this.clause.above(value));
18
18
  }
19
19
 
20
20
  aboveOrEqual(value: any): StorageCollection<T> {
21
- return new DexieStorageCollection(this.clause.aboveOrEqual(value));
21
+ return new DexieCollection(this.clause.aboveOrEqual(value));
22
22
  }
23
23
 
24
24
  below(value: any): StorageCollection<T> {
25
- return new DexieStorageCollection(this.clause.below(value));
25
+ return new DexieCollection(this.clause.below(value));
26
26
  }
27
27
 
28
28
  belowOrEqual(value: any): StorageCollection<T> {
29
- return new DexieStorageCollection(this.clause.belowOrEqual(value));
29
+ return new DexieCollection(this.clause.belowOrEqual(value));
30
30
  }
31
31
 
32
32
  between(lower: any, upper: any, includeLower?: boolean, includeUpper?: boolean): StorageCollection<T> {
33
- return new DexieStorageCollection(this.clause.between(lower, upper, includeLower, includeUpper));
33
+ return new DexieCollection(this.clause.between(lower, upper, includeLower, includeUpper));
34
34
  }
35
35
 
36
36
  inAnyRange(ranges: Array<[any, any]>, options?: { includeLower?: boolean; includeUpper?: boolean }): StorageCollection<T> {
@@ -40,58 +40,58 @@ export class DexieStorageWhereClause<T = any> implements StorageWhereClause<T> {
40
40
  includeUppers: options.includeUpper,
41
41
  }
42
42
  : undefined;
43
- return new DexieStorageCollection(this.clause.inAnyRange(ranges as any, normalizedOptions));
43
+ return new DexieCollection(this.clause.inAnyRange(ranges as any, normalizedOptions));
44
44
  }
45
45
 
46
46
  startsWith(prefix: string): StorageCollection<T> {
47
- return new DexieStorageCollection(this.clause.startsWith(prefix));
47
+ return new DexieCollection(this.clause.startsWith(prefix));
48
48
  }
49
49
 
50
50
  startsWithIgnoreCase(prefix: string): StorageCollection<T> {
51
- return new DexieStorageCollection(this.clause.startsWithIgnoreCase(prefix));
51
+ return new DexieCollection(this.clause.startsWithIgnoreCase(prefix));
52
52
  }
53
53
 
54
54
  startsWithAnyOf(...prefixes: string[]): StorageCollection<T>;
55
55
  startsWithAnyOf(prefixes: string[]): StorageCollection<T>;
56
56
  startsWithAnyOf(...args: any[]): StorageCollection<T> {
57
57
  const values = this.flattenArgs<string>(args);
58
- return new DexieStorageCollection(this.clause.startsWithAnyOf(...values));
58
+ return new DexieCollection(this.clause.startsWithAnyOf(...values));
59
59
  }
60
60
 
61
61
  startsWithAnyOfIgnoreCase(...prefixes: string[]): StorageCollection<T>;
62
62
  startsWithAnyOfIgnoreCase(prefixes: string[]): StorageCollection<T>;
63
63
  startsWithAnyOfIgnoreCase(...args: any[]): StorageCollection<T> {
64
64
  const values = this.flattenArgs<string>(args);
65
- return new DexieStorageCollection(this.clause.startsWithAnyOfIgnoreCase(...values));
65
+ return new DexieCollection(this.clause.startsWithAnyOfIgnoreCase(...values));
66
66
  }
67
67
 
68
68
  equalsIgnoreCase(value: string): StorageCollection<T> {
69
- return new DexieStorageCollection(this.clause.equalsIgnoreCase(value));
69
+ return new DexieCollection(this.clause.equalsIgnoreCase(value));
70
70
  }
71
71
 
72
72
  anyOf(...values: any[]): StorageCollection<T>;
73
73
  anyOf(values: any[]): StorageCollection<T>;
74
74
  anyOf(...args: any[]): StorageCollection<T> {
75
75
  const values = this.flattenArgs<any>(args);
76
- return new DexieStorageCollection(this.clause.anyOf(...values));
76
+ return new DexieCollection(this.clause.anyOf(...values));
77
77
  }
78
78
 
79
79
  anyOfIgnoreCase(...values: string[]): StorageCollection<T>;
80
80
  anyOfIgnoreCase(values: string[]): StorageCollection<T>;
81
81
  anyOfIgnoreCase(...args: any[]): StorageCollection<T> {
82
82
  const values = this.flattenArgs<string>(args);
83
- return new DexieStorageCollection(this.clause.anyOfIgnoreCase(...values));
83
+ return new DexieCollection(this.clause.anyOfIgnoreCase(...values));
84
84
  }
85
85
 
86
86
  noneOf(...values: any[]): StorageCollection<T>;
87
87
  noneOf(values: any[]): StorageCollection<T>;
88
88
  noneOf(...args: any[]): StorageCollection<T> {
89
89
  const values = this.flattenArgs<any>(args);
90
- return new DexieStorageCollection(this.clause.noneOf(values as any));
90
+ return new DexieCollection(this.clause.noneOf(values as any));
91
91
  }
92
92
 
93
93
  notEqual(value: any): StorageCollection<T> {
94
- return new DexieStorageCollection(this.clause.notEqual(value));
94
+ return new DexieCollection(this.clause.notEqual(value));
95
95
  }
96
96
 
97
97
  private flattenArgs<TValue>(args: any[]): TValue[] {
@@ -1,7 +1,7 @@
1
1
  // Export all classes
2
2
  export { DexieAdapter } from './DexieAdapter';
3
3
  export { DexieQueryContext } from './DexieQueryContext';
4
- export { DexieStorageCollection } from './DexieStorageCollection';
5
- export { DexieStorageWhereClause } from './DexieStorageWhereClause';
6
- export { DexieStorageTable } from './DexieStorageTable';
4
+ export { DexieCollection } from './DexieCollection';
5
+ export { DexieWhereClause } from './DexieWhereClause';
6
+ export { DexieTable } from './DexieTable';
7
7
  export { normalizeIndexName } from './helpers';
@@ -1,4 +1,4 @@
1
- import type { StorageCollection, StorageTable, StorageWhereClause } from '../types';
1
+ import type { AddItem, StorageCollection, StorageTable, StorageWhereClause } from '../types';
2
2
  import { LOCAL_PK } from '../../types';
3
3
  import { createLocalId } from '../../helpers';
4
4
  import type { MemoryCollectionState, MemoryRecord } from './types';
@@ -12,15 +12,15 @@ export class MemoryTable<T extends MemoryRecord = MemoryRecord> implements Stora
12
12
  readonly primaryKey: unknown = LOCAL_PK;
13
13
  readonly hook: unknown = Object.freeze({});
14
14
  readonly raw: {
15
- add: (item: T) => Promise<unknown>;
16
- put: (item: T) => Promise<unknown>;
17
- update: (key: unknown, changes: Partial<T>) => Promise<number>;
18
- delete: (key: unknown) => Promise<void>;
19
- get: (key: unknown) => Promise<T | undefined>;
20
- bulkAdd: (items: T[]) => Promise<unknown>;
21
- bulkPut: (items: T[]) => Promise<unknown>;
22
- bulkUpdate: (keysAndChanges: Array<{ key: unknown; changes: Partial<T> }>) => Promise<number>;
23
- bulkDelete: (keys: Array<unknown>) => Promise<void>;
15
+ add: (item: T) => Promise<string>;
16
+ put: (item: T) => Promise<string>;
17
+ update: (key: string, changes: Partial<T>) => Promise<number>;
18
+ delete: (key: string) => Promise<void>;
19
+ get: (key: string) => Promise<T | undefined>;
20
+ bulkAdd: (items: T[]) => Promise<string[]>;
21
+ bulkPut: (items: T[]) => Promise<string[]>;
22
+ bulkUpdate: (keysAndChanges: Array<{ key: string; changes: Partial<T> }>) => Promise<number>;
23
+ bulkDelete: (keys: string[]) => Promise<void>;
24
24
  clear: () => Promise<void>;
25
25
  };
26
26
  private readonly records = new Map<string, T>();
@@ -30,32 +30,32 @@ export class MemoryTable<T extends MemoryRecord = MemoryRecord> implements Stora
30
30
  this.raw = {
31
31
  add: async (item: T) => this.baseAdd(item),
32
32
  put: async (item: T) => this.basePut(item),
33
- update: async (key: unknown, changes: Partial<T>) => this.baseUpdate(key, changes),
34
- delete: async (key: unknown) => {
33
+ update: async (key: string, changes: Partial<T>) => this.baseUpdate(key, changes),
34
+ delete: async (key: string) => {
35
35
  this.baseDelete(key);
36
36
  },
37
- get: async (key: unknown) => this.baseGet(key),
37
+ get: async (key: string) => this.baseGet(key),
38
38
  bulkAdd: async (items: T[]) => this.baseBulkAdd(items),
39
39
  bulkPut: async (items: T[]) => this.baseBulkPut(items),
40
- bulkUpdate: async (keysAndChanges: Array<{ key: unknown; changes: Partial<T> }>) => this.baseBulkUpdate(keysAndChanges),
41
- bulkDelete: async (keys: Array<unknown>) => this.baseBulkDelete(keys),
40
+ bulkUpdate: async (keysAndChanges: Array<{ key: string; changes: Partial<T> }>) => this.baseBulkUpdate(keysAndChanges),
41
+ bulkDelete: async (keys: string[]) => this.baseBulkDelete(keys),
42
42
  clear: async () => this.baseClear(),
43
43
  };
44
44
  }
45
45
 
46
- async add(item: T): Promise<unknown> {
47
- return this.baseAdd(item);
46
+ async add(item: AddItem<T>): Promise<string> {
47
+ return this.baseAdd(item as T);
48
48
  }
49
49
 
50
- async put(item: T): Promise<unknown> {
50
+ async put(item: T): Promise<string> {
51
51
  return this.basePut(item);
52
52
  }
53
53
 
54
- async update(key: unknown, changes: Partial<T>): Promise<number> {
54
+ async update(key: string, changes: Partial<T>): Promise<number> {
55
55
  return this.baseUpdate(key, changes);
56
56
  }
57
57
 
58
- async delete(key: unknown): Promise<void> {
58
+ async delete(key: string): Promise<void> {
59
59
  this.baseDelete(key);
60
60
  }
61
61
 
@@ -67,7 +67,7 @@ export class MemoryTable<T extends MemoryRecord = MemoryRecord> implements Stora
67
67
  this.records.clear();
68
68
  }
69
69
 
70
- async get(key: unknown): Promise<T | undefined> {
70
+ async get(key: string): Promise<T | undefined> {
71
71
  const stored = this.baseGet(key);
72
72
  return stored ? this.cloneRecord(stored) : undefined;
73
73
  }
@@ -80,41 +80,41 @@ export class MemoryTable<T extends MemoryRecord = MemoryRecord> implements Stora
80
80
  return this.records.size;
81
81
  }
82
82
 
83
- async bulkAdd(items: T[]): Promise<unknown> {
84
- return this.baseBulkAdd(items);
83
+ async bulkAdd(items: AddItem<T>[]): Promise<string[]> {
84
+ return this.baseBulkAdd(items as T[]);
85
85
  }
86
86
 
87
- private baseBulkAdd(items: T[]): unknown {
88
- let lastKey: unknown = undefined;
87
+ private baseBulkAdd(items: T[]): string[] {
88
+ const keys: string[] = [];
89
89
  for (let index = 0; index < items.length; index += 1) {
90
90
  const item = items[index]!;
91
- lastKey = this.baseAdd(item);
91
+ keys.push(this.baseAdd(item));
92
92
  }
93
- return lastKey;
93
+ return keys;
94
94
  }
95
95
 
96
- async bulkPut(items: T[]): Promise<unknown> {
96
+ async bulkPut(items: T[]): Promise<string[]> {
97
97
  return this.baseBulkPut(items);
98
98
  }
99
99
 
100
- private baseBulkPut(items: T[]): unknown {
101
- let lastKey: unknown = undefined;
100
+ private baseBulkPut(items: T[]): string[] {
101
+ const keys: string[] = [];
102
102
  for (let index = 0; index < items.length; index += 1) {
103
103
  const item = items[index]!;
104
- lastKey = this.basePut(item);
104
+ keys.push(this.basePut(item));
105
105
  }
106
- return lastKey;
106
+ return keys;
107
107
  }
108
108
 
109
- async bulkGet(keys: Array<unknown>): Promise<Array<T | undefined>> {
109
+ async bulkGet(keys: string[]): Promise<Array<T | undefined>> {
110
110
  return Promise.all(keys.map((key) => this.get(key)));
111
111
  }
112
112
 
113
- async bulkUpdate(keysAndChanges: Array<{ key: unknown; changes: Partial<T> }>): Promise<number> {
113
+ async bulkUpdate(keysAndChanges: Array<{ key: string; changes: Partial<T> }>): Promise<number> {
114
114
  return this.baseBulkUpdate(keysAndChanges);
115
115
  }
116
116
 
117
- private baseBulkUpdate(keysAndChanges: Array<{ key: unknown; changes: Partial<T> }>): number {
117
+ private baseBulkUpdate(keysAndChanges: Array<{ key: string; changes: Partial<T> }>): number {
118
118
  let updatedCount = 0;
119
119
  for (const { key, changes } of keysAndChanges) {
120
120
  const result = this.baseUpdate(key, changes);
@@ -123,11 +123,11 @@ export class MemoryTable<T extends MemoryRecord = MemoryRecord> implements Stora
123
123
  return updatedCount;
124
124
  }
125
125
 
126
- async bulkDelete(keys: Array<unknown>): Promise<void> {
126
+ async bulkDelete(keys: string[]): Promise<void> {
127
127
  this.baseBulkDelete(keys);
128
128
  }
129
129
 
130
- private baseBulkDelete(keys: Array<unknown>): void {
130
+ private baseBulkDelete(keys: string[]): void {
131
131
  for (const key of keys) {
132
132
  this.baseDelete(key);
133
133
  }
@@ -277,7 +277,7 @@ export class MemoryTable<T extends MemoryRecord = MemoryRecord> implements Stora
277
277
  return primaryKey;
278
278
  }
279
279
 
280
- private baseUpdate(key: unknown, changes: Partial<T>): number {
280
+ private baseUpdate(key: string, changes: Partial<T>): number {
281
281
  const primaryKey = this.resolveKey(key);
282
282
  if (!primaryKey) {
283
283
  return 0;
@@ -291,14 +291,14 @@ export class MemoryTable<T extends MemoryRecord = MemoryRecord> implements Stora
291
291
  return 1;
292
292
  }
293
293
 
294
- private baseDelete(key: unknown): void {
294
+ private baseDelete(key: string): void {
295
295
  const primaryKey = this.resolveKey(key);
296
296
  if (primaryKey) {
297
297
  this.records.delete(primaryKey);
298
298
  }
299
299
  }
300
300
 
301
- private baseGet(key: unknown): T | undefined {
301
+ private baseGet(key: string): T | undefined {
302
302
  const primaryKey = this.resolveKey(key);
303
303
  if (!primaryKey) {
304
304
  return undefined;