@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.
Files changed (54) hide show
  1. package/README.md +31 -9
  2. package/dist/capacitor.cjs +2 -2
  3. package/dist/capacitor.cjs.map +1 -1
  4. package/dist/capacitor.d.cts +1 -1
  5. package/dist/capacitor.d.ts +1 -1
  6. package/dist/capacitor.js +1 -1
  7. package/dist/{chunk-SQB6E7V2.js → chunk-XAHQXK76.js} +3 -3
  8. package/dist/{chunk-SQB6E7V2.js.map → chunk-XAHQXK76.js.map} +1 -1
  9. package/dist/{dexie-BFPA0JU2.d.ts → dexie-ImxmapkS.d.ts} +5 -5
  10. package/dist/{dexie-T9m1mP1h.d.cts → dexie-q17SmbBw.d.cts} +5 -5
  11. package/dist/dexie.d.cts +2 -2
  12. package/dist/dexie.d.ts +2 -2
  13. package/dist/expoSqlite.d.cts +1 -1
  14. package/dist/expoSqlite.d.ts +1 -1
  15. package/dist/index.cjs +54 -27
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.cts +9 -8
  18. package/dist/index.d.ts +9 -8
  19. package/dist/index.js +54 -27
  20. package/dist/index.js.map +1 -1
  21. package/dist/node.cjs +5 -5
  22. package/dist/node.cjs.map +1 -1
  23. package/dist/node.d.cts +9 -9
  24. package/dist/node.d.ts +9 -9
  25. package/dist/node.js +4 -4
  26. package/dist/node.js.map +1 -1
  27. package/dist/react/index.d.cts +3 -3
  28. package/dist/react/index.d.ts +3 -3
  29. package/dist/{types-DLFva7gq.d.ts → types-B7xq90Kc.d.cts} +2 -2
  30. package/dist/{types-9I2fmDbU.d.cts → types-CfvYBKI_.d.ts} +2 -2
  31. package/dist/{types-CSbIAfu2.d.cts → types-DeiRXWKl.d.cts} +4 -8
  32. package/dist/{types-CSbIAfu2.d.ts → types-DeiRXWKl.d.ts} +4 -8
  33. package/dist/wa-sqlite.cjs +9 -9
  34. package/dist/wa-sqlite.cjs.map +1 -1
  35. package/dist/wa-sqlite.d.cts +13 -13
  36. package/dist/wa-sqlite.d.ts +13 -13
  37. package/dist/wa-sqlite.js +8 -8
  38. package/dist/wa-sqlite.js.map +1 -1
  39. package/package.json +6 -4
  40. package/src/core/tableEnhancers.ts +15 -5
  41. package/src/index.native.ts +1 -1
  42. package/src/index.shared.ts +42 -14
  43. package/src/index.ts +1 -1
  44. package/src/node.ts +1 -1
  45. package/src/storage/sqlite/SQLiteAdapter.ts +10 -13
  46. package/src/storage/sqlite/{SqliteQueryContext.ts → SQLiteQueryContext.ts} +1 -1
  47. package/src/storage/sqlite/drivers/{BetterSqlite3Driver.ts → BetterSQLite3Driver.ts} +8 -8
  48. package/src/storage/sqlite/drivers/CapacitorSQLiteDriver.ts +2 -2
  49. package/src/storage/sqlite/drivers/{WaSqliteDriver.ts → WaSQLiteDriver.ts} +20 -20
  50. package/src/storage/sqlite/index.ts +1 -1
  51. package/src/storage/sqlite/types.ts +4 -9
  52. package/src/storage/types.ts +2 -2
  53. package/src/types.ts +1 -1
  54. package/src/wa-sqlite.ts +1 -1
@@ -6,7 +6,7 @@ import type { SQLiteDatabaseDriver, SQLiteQueryResult, SQLiteRunResult } from '.
6
6
  *
7
7
  * @see https://github.com/rhashimoto/wa-sqlite/tree/master/src/examples#vfs-comparison
8
8
  */
9
- export type WaSqliteVfsType =
9
+ export type WaSQLiteVfsType =
10
10
  /**
11
11
  * IDBBatchAtomicVFS - IndexedDB-backed storage
12
12
  * - Works on ALL contexts (Window, Worker, SharedWorker, service worker)
@@ -45,14 +45,14 @@ export type WaSqliteVfsType =
45
45
  | 'AccessHandlePoolVFS';
46
46
 
47
47
  /**
48
- * Options for configuring the WaSqliteDriver.
48
+ * Options for configuring the WaSQLiteDriver.
49
49
  */
50
- export interface WaSqliteDriverOptions {
50
+ export interface WaSQLiteDriverOptions {
51
51
  /**
52
52
  * Virtual File System to use for storage.
53
53
  * @default 'IDBBatchAtomicVFS'
54
54
  */
55
- vfs?: WaSqliteVfsType;
55
+ vfs?: WaSQLiteVfsType;
56
56
 
57
57
  /**
58
58
  * Directory path for the database in OPFS VFS modes.
@@ -96,22 +96,22 @@ export interface WaSqliteDriverOptions {
96
96
  }
97
97
 
98
98
  // Internal VFS interface for lifecycle management
99
- interface WaSqliteVFS {
99
+ interface WaSQLiteVFS {
100
100
  close(): Promise<void>;
101
101
  name: string;
102
102
  }
103
103
 
104
104
  // VFS class type with static create method
105
105
  interface VFSClass {
106
- create(name: string, module: any, options?: any): Promise<WaSqliteVFS>;
106
+ create(name: string, module: any, options?: any): Promise<WaSQLiteVFS>;
107
107
  }
108
108
 
109
109
  // Cached module factory and instance
110
110
  let cachedModuleFactory: (() => Promise<any>) | null = null;
111
111
  let cachedModule: any = null;
112
- let cachedSqlite3: any = null;
112
+ let cachedSQLite3: any = null;
113
113
  // Track VFS instances by name to avoid re-registering
114
- const registeredVFS = new Map<string, WaSqliteVFS>();
114
+ const registeredVFS = new Map<string, WaSQLiteVFS>();
115
115
 
116
116
  /**
117
117
  * SQLite driver for web browsers using wa-sqlite with IndexedDB or OPFS persistence.
@@ -138,30 +138,30 @@ const registeredVFS = new Map<string, WaSqliteVFS>();
138
138
  *
139
139
  * @example
140
140
  * ```ts
141
- * import { WaSqliteDriver } from '@anfenn/dync/wa-sqlite';
141
+ * import { WaSQLiteDriver } from '@anfenn/dync/wa-sqlite';
142
142
  * import { SQLiteAdapter } from '@anfenn/dync';
143
143
  *
144
144
  * // Default: IDBBatchAtomicVFS (works in main thread, multi-tab safe)
145
- * const driver = new WaSqliteDriver('myapp.db');
145
+ * const driver = new WaSQLiteDriver('myapp.db');
146
146
  *
147
147
  * // For OPFS (faster, requires Worker, filesystem transparent)
148
- * const opfsDriver = new WaSqliteDriver('myapp.db', { vfs: 'OPFSCoopSyncVFS' });
148
+ * const opfsDriver = new WaSQLiteDriver('myapp.db', { vfs: 'OPFSCoopSyncVFS' });
149
149
  *
150
150
  * const adapter = new SQLiteAdapter('myapp', driver);
151
151
  * ```
152
152
  */
153
- export class WaSqliteDriver implements SQLiteDatabaseDriver {
154
- readonly type = 'WaSqliteDriver';
153
+ export class WaSQLiteDriver implements SQLiteDatabaseDriver {
154
+ readonly type = 'WaSQLiteDriver';
155
155
  private db: number | null = null;
156
156
  private sqlite3: any = null;
157
- private readonly options: Required<WaSqliteDriverOptions>;
157
+ private readonly options: Required<WaSQLiteDriverOptions>;
158
158
  private opened = false;
159
159
  private openPromise: Promise<void> | null = null;
160
160
  // Mutex to prevent concurrent database operations (critical for wa-sqlite)
161
161
  private executionLock: Promise<void> = Promise.resolve();
162
162
  readonly name: string;
163
163
 
164
- constructor(databaseName: string, options: WaSqliteDriverOptions = {}) {
164
+ constructor(databaseName: string, options: WaSQLiteDriverOptions = {}) {
165
165
  this.name = databaseName;
166
166
  this.options = {
167
167
  vfs: 'IDBBatchAtomicVFS',
@@ -215,11 +215,11 @@ export class WaSqliteDriver implements SQLiteDatabaseDriver {
215
215
  const module = await this.loadWasmModule();
216
216
 
217
217
  // Create SQLite API from module (cached - must only create once per module)
218
- if (!cachedSqlite3) {
218
+ if (!cachedSQLite3) {
219
219
  const { Factory } = await import('@journeyapps/wa-sqlite');
220
- cachedSqlite3 = Factory(module);
220
+ cachedSQLite3 = Factory(module);
221
221
  }
222
- this.sqlite3 = cachedSqlite3;
222
+ this.sqlite3 = cachedSQLite3;
223
223
 
224
224
  // For IDB-based VFS, the VFS name is also used as the IndexedDB database name
225
225
  // Use a unique name based on database name to avoid conflicts
@@ -259,7 +259,7 @@ export class WaSqliteDriver implements SQLiteDatabaseDriver {
259
259
  return cachedModule;
260
260
  }
261
261
 
262
- private async createVFS(module: any, vfsName: string): Promise<WaSqliteVFS> {
262
+ private async createVFS(module: any, vfsName: string): Promise<WaSQLiteVFS> {
263
263
  const vfsType = this.options.vfs;
264
264
  let VFSClass: VFSClass;
265
265
  let vfsOptions: any = undefined;
@@ -470,7 +470,7 @@ export class WaSqliteDriver implements SQLiteDatabaseDriver {
470
470
  /**
471
471
  * Get the VFS type being used by this driver.
472
472
  */
473
- getVfsType(): WaSqliteVfsType {
473
+ getVfsType(): WaSQLiteVfsType {
474
474
  return this.options.vfs;
475
475
  }
476
476
 
@@ -3,7 +3,7 @@ export * from './helpers';
3
3
  export * from './SQLiteCollection';
4
4
  export * from './SQLiteWhereClause';
5
5
  export * from './SQLiteTable';
6
- export * from './SqliteQueryContext';
6
+ export * from './SQLiteQueryContext';
7
7
  export * from './SQLiteAdapter';
8
8
 
9
9
  // Drivers
@@ -128,12 +128,7 @@ export interface SQLiteDatabaseDriver {
128
128
  query(statement: string, values?: any[]): Promise<SQLiteQueryResult>;
129
129
  }
130
130
 
131
- export type SQLiteMigrationDirection = 'upgrade' | 'downgrade';
132
-
133
131
  export interface SQLiteMigrationContext {
134
- direction: SQLiteMigrationDirection;
135
- fromVersion: number;
136
- toVersion: number;
137
132
  execute: (statement: string) => Promise<void>;
138
133
  run: (statement: string, values?: any[]) => Promise<SQLiteRunResult>;
139
134
  query: (statement: string, values?: any[]) => Promise<SQLiteQueryResult>;
@@ -142,13 +137,13 @@ export interface SQLiteMigrationContext {
142
137
  export type SQLiteMigrationHandler = (context: SQLiteMigrationContext) => Promise<void> | void;
143
138
 
144
139
  export interface SQLiteVersionMigration {
145
- upgrade?: SQLiteMigrationHandler;
146
- downgrade?: SQLiteMigrationHandler;
140
+ up?: SQLiteMigrationHandler;
141
+ down?: SQLiteMigrationHandler;
147
142
  }
148
143
 
149
144
  export interface SQLiteVersionConfigurator {
150
- upgrade(handler: SQLiteMigrationHandler): void;
151
- downgrade(handler: SQLiteMigrationHandler): void;
145
+ up(handler: SQLiteMigrationHandler): void;
146
+ down(handler: SQLiteMigrationHandler): void;
152
147
  }
153
148
 
154
149
  export interface SQLiteSchemaDefinitionOptions {
@@ -2,7 +2,7 @@ import type { DexieQueryContext } from './dexie/DexieQueryContext';
2
2
  import type { MemoryQueryContext } from './memory/MemoryQueryContext';
3
3
  import type { TableSchemaDefinition } from './sqlite/schema';
4
4
  import type { StorageSchemaDefinitionOptions } from './sqlite/types';
5
- import type { SqliteQueryContext } from './sqlite/SqliteQueryContext';
5
+ import type { SQLiteQueryContext } from './sqlite/SQLiteQueryContext';
6
6
 
7
7
  export type TransactionMode = 'r' | 'rw';
8
8
 
@@ -15,7 +15,7 @@ export interface StorageAdapter {
15
15
  defineSchema(version: number, schema: Record<string, TableSchemaDefinition>, options?: StorageSchemaDefinitionOptions): void;
16
16
  table<T = any>(name: string): StorageTable<T>;
17
17
  transaction<T>(mode: TransactionMode, tableNames: string[], callback: (context: StorageTransactionContext) => Promise<T>): Promise<T>;
18
- query<R>(callback: (ctx: DexieQueryContext | SqliteQueryContext | MemoryQueryContext) => Promise<R>): Promise<R>;
18
+ query<R>(callback: (ctx: DexieQueryContext | SQLiteQueryContext | MemoryQueryContext) => Promise<R>): Promise<R>;
19
19
  }
20
20
 
21
21
  export interface StorageTransactionContext {
package/src/types.ts CHANGED
@@ -125,7 +125,7 @@ export interface SyncOptions {
125
125
  export interface DyncOptions<TStoreMap extends Record<string, any> = Record<string, any>> {
126
126
  databaseName: string;
127
127
  storageAdapter: StorageAdapter;
128
- sync: Partial<Record<keyof TStoreMap, ApiFunctions>> | BatchSync;
128
+ sync?: Partial<Record<keyof TStoreMap, ApiFunctions>> | BatchSync;
129
129
  options?: SyncOptions;
130
130
  }
131
131
 
package/src/wa-sqlite.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  // wa-sqlite Browser SQLite Driver
2
2
  // Import this entry point for browser/web builds with SQLite support
3
- export { WaSqliteDriver, type WaSqliteDriverOptions, type WaSqliteVfsType } from './storage/sqlite/drivers/WaSqliteDriver';
3
+ export { WaSQLiteDriver, type WaSQLiteDriverOptions, type WaSQLiteVfsType } from './storage/sqlite/drivers/WaSQLiteDriver';
4
4
  export type { SQLiteDatabaseDriver, SQLiteQueryResult, SQLiteRunResult } from './storage/sqlite/types';