@framers/sql-storage-adapter 0.6.12 → 0.6.14

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 (74) hide show
  1. package/README.md +20 -3
  2. package/dist/adapters/baseStorageAdapter.d.ts +3 -3
  3. package/dist/adapters/betterSqliteAdapter.d.ts +1 -1
  4. package/dist/adapters/capacitorSqliteAdapter.d.ts +43 -1
  5. package/dist/adapters/capacitorSqliteAdapter.d.ts.map +1 -1
  6. package/dist/adapters/capacitorSqliteAdapter.js +139 -21
  7. package/dist/adapters/capacitorSqliteAdapter.js.map +1 -1
  8. package/dist/adapters/electron/electronMainAdapter.d.ts +1 -1
  9. package/dist/adapters/electron/electronRendererAdapter.d.ts +2 -2
  10. package/dist/adapters/electron/index.d.ts +10 -10
  11. package/dist/adapters/electron/ipc/index.d.ts +3 -3
  12. package/dist/adapters/electron/ipc/protocol.d.ts +1 -1
  13. package/dist/adapters/electron/ipc/types.d.ts +1 -1
  14. package/dist/adapters/electron/migration/autoMigrator.d.ts +1 -1
  15. package/dist/adapters/electron/migration/index.d.ts +1 -1
  16. package/dist/adapters/electron/preload.d.ts +2 -2
  17. package/dist/adapters/electron/recovery/corruptionDetector.d.ts +1 -1
  18. package/dist/adapters/electron/recovery/index.d.ts +2 -2
  19. package/dist/adapters/electron/recovery/walCheckpoint.d.ts +1 -1
  20. package/dist/adapters/electron/window/index.d.ts +1 -1
  21. package/dist/adapters/electron/window/windowManager.d.ts +1 -1
  22. package/dist/adapters/indexedDbAdapter.d.ts +90 -11
  23. package/dist/adapters/indexedDbAdapter.d.ts.map +1 -1
  24. package/dist/adapters/indexedDbAdapter.js +265 -58
  25. package/dist/adapters/indexedDbAdapter.js.map +1 -1
  26. package/dist/adapters/postgresAdapter.d.ts +1 -1
  27. package/dist/adapters/sqlJsAdapter.d.ts +1 -1
  28. package/dist/adapters/supabase.d.ts +2 -2
  29. package/dist/core/contracts/context.d.ts +2 -2
  30. package/dist/core/contracts/events.d.ts +2 -2
  31. package/dist/core/contracts/extensions.d.ts +3 -3
  32. package/dist/core/contracts/hooks.d.ts +1 -1
  33. package/dist/core/contracts/index.d.ts +2 -2
  34. package/dist/core/contracts/limitations.d.ts +1 -1
  35. package/dist/core/database.d.ts +18 -10
  36. package/dist/core/database.d.ts.map +1 -1
  37. package/dist/core/database.js +17 -8
  38. package/dist/core/database.js.map +1 -1
  39. package/dist/core/resolver.d.ts +20 -10
  40. package/dist/core/resolver.d.ts.map +1 -1
  41. package/dist/core/resolver.js +43 -7
  42. package/dist/core/resolver.js.map +1 -1
  43. package/dist/features/backup/cloudBackup.d.ts +1 -1
  44. package/dist/features/migrations/dataExport.d.ts +1 -1
  45. package/dist/features/migrations/dataImport.d.ts +2 -2
  46. package/dist/features/migrations/migration.d.ts +2 -2
  47. package/dist/features/sync/conflicts/conflictResolver.d.ts +1 -1
  48. package/dist/features/sync/conflicts/index.d.ts +1 -1
  49. package/dist/features/sync/crossPlatformSync.d.ts +6 -6
  50. package/dist/features/sync/devices/deviceManager.d.ts +2 -2
  51. package/dist/features/sync/devices/index.d.ts +1 -1
  52. package/dist/features/sync/index.d.ts +9 -9
  53. package/dist/features/sync/protocol/index.d.ts +2 -2
  54. package/dist/features/sync/protocol/messages.d.ts +1 -1
  55. package/dist/features/sync/syncManager.d.ts +1 -1
  56. package/dist/features/sync/tables/index.d.ts +1 -1
  57. package/dist/features/sync/tables/syncLogManager.d.ts +4 -4
  58. package/dist/features/sync/transport/httpTransport.d.ts +2 -2
  59. package/dist/features/sync/transport/index.d.ts +3 -3
  60. package/dist/features/sync/transport/transport.d.ts +1 -1
  61. package/dist/features/sync/transport/websocketTransport.d.ts +2 -2
  62. package/dist/index.d.ts +25 -25
  63. package/dist/shared/connectionGate.d.ts +32 -9
  64. package/dist/shared/connectionGate.d.ts.map +1 -1
  65. package/dist/shared/connectionGate.js +31 -12
  66. package/dist/shared/connectionGate.js.map +1 -1
  67. package/dist/shared/parameterUtils.d.ts +1 -1
  68. package/dist/shared/postgresTarget.d.ts +10 -0
  69. package/dist/shared/postgresTarget.d.ts.map +1 -0
  70. package/dist/shared/postgresTarget.js +13 -0
  71. package/dist/shared/postgresTarget.js.map +1 -0
  72. package/dist/shared/serializedTransaction.d.ts +1 -1
  73. package/dist/types/index.d.ts +7 -7
  74. package/package.json +2 -1
package/README.md CHANGED
@@ -131,13 +131,13 @@ See [Platform Strategy Guide](./PLATFORM_STRATEGY.md) for detailed pros/cons and
131
131
 
132
132
  | Adapter | Package | Ideal for | Pros | Considerations |
133
133
  | --- | --- | --- | --- | --- |
134
- | **🆕 `electron`** | bundled | **Electron desktop apps** | IPC bridge, multi-window, WAL, auto-migrations, crash recovery | Requires Electron runtime |
134
+ | **🆕 `electron`** | bundled | **Electron desktop apps** | IPC bridge, multi-window, WAL, auto-migrations, crash recovery | Requires Electron runtime; create it from `@framers/sql-storage-adapter/electron` (the resolver does not build the `electron-main` and `electron-renderer` kinds) |
135
135
  | **🆕 `indexeddb`** | bundled (sql.js) | **Browsers, PWAs** | sql.js + IndexedDB persistence wrapper, browser-native storage, 50MB-1GB+ quota, offline-first | IndexedDB quotas vary, WASM overhead (sql.js), not a separate SQL engine |
136
136
  | `better-sqlite3` | `better-sqlite3` | Node/Electron, CLI, CI | Native performance, transactional semantics, WAL support | Needs native toolchain; version must match Node ABI; 13.x needs Node-API 10 (Node.js 22.14+, Electron 35+) |
137
137
  | `postgres` | `pg` | Hosted or on-prem PostgreSQL | Connection pooling, rich SQL features, cloud friendly | Requires `DATABASE_URL`/credentials |
138
138
  | `sqljs` | bundled | Browsers, serverless edge, native fallback | Pure WASM SQLite, no native deps, optional filesystem persistence | Write performance limited vs native, in-memory by default |
139
139
  | `capacitor` | `@capacitor-community/sqlite` | Mobile (iOS/Android, Capacitor) | Native SQLite on mobile, encryption | Requires Capacitor runtime |
140
- | `memory` | built-in | Unit tests, storybooks, constrained sandboxes | Zero dependencies, instant startup | Non-durable, single-process only |
140
+ | `memory` | bundled (sql.js) | Unit tests, storybooks, constrained sandboxes | Zero dependencies, instant startup | The resolver builds the sql.js adapter for it, as for `sqljs`: in memory in a browser, persisted to the resolver's file path on Node |
141
141
 
142
142
  ### Platform Priorities
143
143
 
@@ -243,9 +243,24 @@ await sync.connect();
243
243
  - environment variables (`STORAGE_ADAPTER`, `DATABASE_URL`),
244
244
  - runtime hints (Capacitor detection, browser globals, IndexedDB availability).
245
245
  - Adapters are attempted in priority order until one opens successfully; a `StorageResolutionError` includes the full failure chain.
246
+ - The resolver builds `postgres`, `better-sqlite3`, `capacitor`, `indexeddb` and `sqljs`, and builds sql.js for `memory`. Any other kind (`electron-main`, `electron-renderer`, `supabase`, or an unknown name, from `priority` or `STORAGE_ADAPTER`) fails as a candidate with an error that names it, and the next candidate is tried.
247
+ - On Node, `createDatabase({ url })`, `createDatabase({ postgres })` and `connectDatabase()` open PostgreSQL, with every Postgres option (pool size, SSL, timeouts, application name, or host, port, database, user and password without a connection string) passed on, and do not fall back to SQLite. In a browser and on Deno, `createDatabase()` opens sql.js whatever the options say. `DATABASE_URL` in the environment does not change what `createDatabase()` picks; `resolveStorageAdapter()` without a `priority` tries Postgres first when it is set.
246
248
  - Provide `priority: ['indexeddb', 'sqljs']` for browser bundles or tests where native modules shouldn't load.
247
249
  - Use `createCloudBackupManager` for S3-compatible backups with gzip compression and retention limits.
248
250
 
251
+ ### Transactions
252
+
253
+ `transaction(fn)` commits when `fn` resolves and rolls back when it throws. Run the callback's statements through the handle it receives:
254
+
255
+ ```typescript
256
+ await db.transaction(async (trx) => {
257
+ await trx.run('UPDATE accounts SET balance = balance - ? WHERE id = ?', [100, 'a']);
258
+ await trx.run('UPDATE accounts SET balance = balance + ? WHERE id = ?', [100, 'b']);
259
+ });
260
+ ```
261
+
262
+ The IndexedDB, Capacitor and better-sqlite3 adapters run every transaction on one connection, so they run transactions one at a time, and a statement from another caller waits until the open transaction ends: it neither joins the transaction (and vanishes in its rollback) nor reads what the transaction has not committed. A browser or a WebView has no async context to tell the callback's own statements apart, so on the IndexedDB and Capacitor adapters a statement the callback issues through the adapter itself, not through its handle, waits for the transaction too. The two then wait on each other, and the adapter logs a warning after 10 seconds. (On Node, better-sqlite3 tells them apart with `AsyncLocalStorage`.) Inside a callback, run every statement through the handle, and do not await work that itself needs the database.
263
+
249
264
  ### IndexedDB-Specific Config
250
265
 
251
266
  ```typescript
@@ -269,6 +284,8 @@ await adapter.open();
269
284
  - ✅ Export/import (Uint8Array SQLite file format)
270
285
  - ✅ Auto-save with batching (reduce IDB overhead)
271
286
 
287
+ **When it saves:** every `saveIntervalMs`, the adapter writes the database image to IndexedDB if anything changed. It skips the tick while a transaction is open, its own or one begun with `BEGIN`, because sql.js's export closes and reopens the connection, which would end the transaction; the next tick saves it once it has committed. A save counts as done when IndexedDB commits it, not when the put request succeeds. A save that fails or aborts is reported once, and the next tick tries again. A write made while a save is in flight is saved by the next one. A transaction's commit marks its writes for saving, including writes made through `all()` or `get()` (`INSERT ... RETURNING`). `close()` rolls back a transaction still open and saves the committed state. `importDatabase()` saves the imported image before it resolves. `exportDatabase()` throws while a transaction is open.
288
+
272
289
  **Why IndexedDB Adapter vs sql.js Adapter?**
273
290
 
274
291
  | Feature | IndexedDB Adapter | sql.js Adapter |
@@ -503,7 +520,7 @@ On Postgres, `features.exporter` requires a Node runtime plus an adapter that wa
503
520
  ## CI, Releases, and Badges
504
521
 
505
522
  - GitHub Actions workflows:
506
- - `ci.yml` runs lint, tests, and coverage on every branch.
523
+ - `ci.yml` runs on pushes and pull requests to `master`: lint, type check, tests with coverage and the build, then it packs the package, installs the tarball into a new ES module project and type-checks a consumer with `--module nodenext --moduleResolution nodenext`. The job starts a PostgreSQL 16 service, and the specs that need a server read its URL from `POSTGRES_TEST_URL`.
507
524
  - `release.yml` publishes new versions to npm, tags the commit (`vX.Y.Z`), and creates/updates the GitHub Release when `CHANGELOG.md` and `package.json` bump the version.
508
525
  - Check badge health whenever builds fail:
509
526
  - CI badge should be green for `master`.
@@ -43,9 +43,9 @@
43
43
  * });
44
44
  * ```
45
45
  */
46
- import type { StorageAdapter, StorageCapability, StorageOpenOptions, StorageParameters, StorageRunResult, BatchOperation, BatchResult, PreparedStatement } from '../core/contracts';
47
- import type { PerformanceConfig, PerformanceSettings, CacheStats } from '../core/contracts/performance';
48
- import type { StorageHooks } from '../core/contracts/hooks';
46
+ import type { StorageAdapter, StorageCapability, StorageOpenOptions, StorageParameters, StorageRunResult, BatchOperation, BatchResult, PreparedStatement } from '../core/contracts/index.js';
47
+ import type { PerformanceConfig, PerformanceSettings, CacheStats } from '../core/contracts/performance.js';
48
+ import type { StorageHooks } from '../core/contracts/hooks.js';
49
49
  /**
50
50
  * Options for BaseStorageAdapter configuration.
51
51
  *
@@ -1,4 +1,4 @@
1
- import type { StorageAdapter, StorageOpenOptions, StorageParameters, StorageRunResult, StorageCapability, BatchOperation, BatchResult } from '../core/contracts';
1
+ import type { StorageAdapter, StorageOpenOptions, StorageParameters, StorageRunResult, StorageCapability, BatchOperation, BatchResult } from '../core/contracts/index.js';
2
2
  /**
3
3
  * Native SQLite adapter using better-sqlite3.
4
4
  *
@@ -1,4 +1,4 @@
1
- import type { StorageAdapter, StorageCapability, StorageOpenOptions, StorageParameters, StorageRunResult } from '../core/contracts';
1
+ import type { StorageAdapter, StorageCapability, StorageOpenOptions, StorageParameters, StorageRunResult } from '../core/contracts/index.js';
2
2
  export interface CapacitorAdapterOptions {
3
3
  /**
4
4
  * Database name. Defaults to `app`.
@@ -11,6 +11,12 @@ export interface CapacitorAdapterOptions {
11
11
  }
12
12
  /**
13
13
  * Adapter using @capacitor-community/sqlite for native mobile targets.
14
+ *
15
+ * Transactions use the plugin's beginTransaction, commitTransaction and
16
+ * rollbackTransaction (plugin 5.0.7 and later). The plugin runs every other
17
+ * execute and run call in a transaction of its own, which cannot nest in an
18
+ * open one, so the statements of a transaction's callback go to the plugin
19
+ * with `transaction` false.
14
20
  */
15
21
  export declare class CapacitorSqliteAdapter implements StorageAdapter {
16
22
  private readonly options;
@@ -19,14 +25,50 @@ export declare class CapacitorSqliteAdapter implements StorageAdapter {
19
25
  private plugin;
20
26
  private connection;
21
27
  private dbName;
28
+ /** The connection is shared, so transaction() runs one callback at a time. */
29
+ private readonly runSerializedTransaction;
30
+ /**
31
+ * Holds statements from outside an open transaction until it ends. A WebView
32
+ * has no async context to tell the callback's own statements apart, so the
33
+ * callback's handle is the only way into an open transaction.
34
+ */
35
+ private readonly gate;
36
+ /** Statements sent to the plugin from outside a transaction and not yet answered. */
37
+ private readonly inFlight;
38
+ private longWaitReported;
39
+ private readonly longWait;
22
40
  constructor(options?: CapacitorAdapterOptions);
23
41
  open(options?: StorageOpenOptions): Promise<void>;
24
42
  run(statement: string, parameters?: StorageParameters): Promise<StorageRunResult>;
25
43
  get<T>(statement: string, parameters?: StorageParameters): Promise<T | null>;
26
44
  all<T>(statement: string, parameters?: StorageParameters): Promise<T[]>;
27
45
  exec(script: string): Promise<void>;
46
+ /**
47
+ * Executes a callback within a database transaction.
48
+ *
49
+ * Callbacks run one at a time, since every transaction shares the one
50
+ * connection. The callback's statements go through the handle it receives;
51
+ * a statement issued through the adapter itself while the callback runs
52
+ * waits until the transaction ends, so a callback must not await one.
53
+ */
28
54
  transaction<T>(fn: (trx: StorageAdapter) => Promise<T>): Promise<T>;
29
55
  close(): Promise<void>;
56
+ /**
57
+ * The statements of one transaction's handle: they carry the transaction's
58
+ * token, so the gate admits them while the transaction is open, and run
59
+ * inside the plugin's open transaction.
60
+ */
61
+ private handleStatements;
62
+ /**
63
+ * @param ownTransaction - true for a statement from outside a transaction:
64
+ * the plugin runs it in a transaction of its own, as it always has.
65
+ */
66
+ private runNow;
67
+ private allNow;
68
+ private execNow;
69
+ /** Keeps a statement sent from outside a transaction in `inFlight` until it answers. */
70
+ private track;
71
+ private reportLongWait;
30
72
  private ensureConnection;
31
73
  }
32
74
  export declare const createCapacitorSqliteAdapter: (options?: CapacitorAdapterOptions) => StorageAdapter;
@@ -1 +1 @@
1
- {"version":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C;IAIjF,GAAG,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAK5E,GAAG,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IAIvE,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIhD;;;;;;;OAOG;IACU,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,cAAc,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IA8BnE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAOnC;;;;OAIG;IACH,OAAO,CAAC,gBAAgB;IAmBxB;;;OAGG;YACW,MAAM;YAUN,MAAM;YAON,OAAO;IAKrB,wFAAwF;IACxF,OAAO,CAAC,KAAK;IASb,OAAO,CAAC,cAAc;IAUtB,OAAO,CAAC,gBAAgB;CAMzB;AAED,eAAO,MAAM,4BAA4B,aAAc,uBAAuB,KAAG,cAC5C,CAAC"}
@@ -1,4 +1,8 @@
1
1
  import { normaliseParameters } from '../shared/parameterUtils.js';
2
+ import { createSerializedTransactionRunner, createSharedConnectionTransactionAdapter, } from '../shared/serializedTransaction.js';
3
+ import { createConnectionGate, whenAdmitted } from '../shared/connectionGate.js';
4
+ /** How long a statement waits for an open transaction before the adapter warns. */
5
+ const LONG_WAIT_MS = 10000;
2
6
  const isCapacitorPlugin = (value) => {
3
7
  if (!value || typeof value !== 'object') {
4
8
  return false;
@@ -28,8 +32,30 @@ const loadCapacitorSqlite = async () => {
28
32
  return null;
29
33
  }
30
34
  };
35
+ /**
36
+ * The plugin answers run() with `{ changes: { changes, lastId } }`
37
+ * (`capSQLiteChanges`); a flat `{ changes, lastId }` is read as well.
38
+ */
39
+ const toRunResult = (answer) => {
40
+ const outer = (answer ?? {});
41
+ const inner = typeof outer.changes === 'object' && outer.changes !== null
42
+ ? outer.changes
43
+ : outer;
44
+ const changes = typeof inner.changes === 'number' ? inner.changes : 0;
45
+ const lastId = inner.lastId;
46
+ return {
47
+ changes,
48
+ lastInsertRowid: typeof lastId === 'number' || typeof lastId === 'string' ? lastId : null,
49
+ };
50
+ };
31
51
  /**
32
52
  * Adapter using @capacitor-community/sqlite for native mobile targets.
53
+ *
54
+ * Transactions use the plugin's beginTransaction, commitTransaction and
55
+ * rollbackTransaction (plugin 5.0.7 and later). The plugin runs every other
56
+ * execute and run call in a transaction of its own, which cannot nest in an
57
+ * open one, so the statements of a transaction's callback go to the plugin
58
+ * with `transaction` false.
33
59
  */
34
60
  export class CapacitorSqliteAdapter {
35
61
  constructor(options = {}) {
@@ -43,6 +69,21 @@ export class CapacitorSqliteAdapter {
43
69
  ]);
44
70
  this.plugin = null;
45
71
  this.connection = null;
72
+ /** The connection is shared, so transaction() runs one callback at a time. */
73
+ this.runSerializedTransaction = createSerializedTransactionRunner();
74
+ /**
75
+ * Holds statements from outside an open transaction until it ends. A WebView
76
+ * has no async context to tell the callback's own statements apart, so the
77
+ * callback's handle is the only way into an open transaction.
78
+ */
79
+ this.gate = createConnectionGate(null, { withoutContext: 'wait' });
80
+ /** Statements sent to the plugin from outside a transaction and not yet answered. */
81
+ this.inFlight = new Set();
82
+ this.longWaitReported = false;
83
+ this.longWait = {
84
+ afterMs: LONG_WAIT_MS,
85
+ onLongWait: () => this.reportLongWait(),
86
+ };
46
87
  this.dbName = options.database ?? 'app';
47
88
  }
48
89
  async open(options) {
@@ -69,37 +110,56 @@ export class CapacitorSqliteAdapter {
69
110
  }
70
111
  }
71
112
  async run(statement, parameters) {
72
- const conn = this.ensureConnection();
73
- const { positional } = normaliseParameters(parameters);
74
- const result = await conn.run(statement, positional ?? []);
75
- return { changes: result.changes ?? 0, lastInsertRowid: result.lastId ?? null };
113
+ return whenAdmitted(this.gate, () => this.track(this.runNow(statement, parameters, true)), undefined, this.longWait);
76
114
  }
77
115
  async get(statement, parameters) {
78
116
  const rows = await this.all(statement, parameters);
79
117
  return rows.length > 0 ? rows[0] : null;
80
118
  }
81
119
  async all(statement, parameters) {
82
- const conn = this.ensureConnection();
83
- const { positional } = normaliseParameters(parameters);
84
- const result = await conn.query(statement, positional ?? []);
85
- return (result.values ?? []);
120
+ return whenAdmitted(this.gate, () => this.track(this.allNow(statement, parameters)), undefined, this.longWait);
86
121
  }
87
122
  async exec(script) {
88
- const conn = this.ensureConnection();
89
- await conn.execute(script);
123
+ return whenAdmitted(this.gate, () => this.track(this.execNow(script, true)), undefined, this.longWait);
90
124
  }
125
+ /**
126
+ * Executes a callback within a database transaction.
127
+ *
128
+ * Callbacks run one at a time, since every transaction shares the one
129
+ * connection. The callback's statements go through the handle it receives;
130
+ * a statement issued through the adapter itself while the callback runs
131
+ * waits until the transaction ends, so a callback must not await one.
132
+ */
91
133
  async transaction(fn) {
92
- const conn = this.ensureConnection();
93
- await conn.execute('BEGIN TRANSACTION;');
94
- try {
95
- const result = await fn(this);
96
- await conn.execute('COMMIT;');
97
- return result;
98
- }
99
- catch (error) {
100
- await conn.execute('ROLLBACK;');
101
- throw error;
102
- }
134
+ this.ensureConnection();
135
+ const queued = setTimeout(() => this.reportLongWait(), LONG_WAIT_MS);
136
+ return this.runSerializedTransaction(() => {
137
+ clearTimeout(queued);
138
+ return this.gate.hold(async (token) => {
139
+ // The gate now holds new statements back; let the ones already sent
140
+ // answer before the transaction begins.
141
+ await Promise.allSettled([...this.inFlight]);
142
+ const conn = this.ensureConnection();
143
+ // Outside the try: when beginTransaction fails, no transaction of this
144
+ // call is open to roll back.
145
+ await conn.beginTransaction();
146
+ const transactionAdapter = createSharedConnectionTransactionAdapter(this.handleStatements(token));
147
+ try {
148
+ const result = await fn(transactionAdapter);
149
+ await conn.commitTransaction();
150
+ return result;
151
+ }
152
+ catch (error) {
153
+ try {
154
+ await conn.rollbackTransaction();
155
+ }
156
+ catch {
157
+ // The transaction already ended.
158
+ }
159
+ throw error;
160
+ }
161
+ });
162
+ });
103
163
  }
104
164
  async close() {
105
165
  if (this.connection) {
@@ -107,6 +167,64 @@ export class CapacitorSqliteAdapter {
107
167
  this.connection = null;
108
168
  }
109
169
  }
170
+ /**
171
+ * The statements of one transaction's handle: they carry the transaction's
172
+ * token, so the gate admits them while the transaction is open, and run
173
+ * inside the plugin's open transaction.
174
+ */
175
+ handleStatements(token) {
176
+ return {
177
+ kind: this.kind,
178
+ capabilities: this.capabilities,
179
+ open: async () => { },
180
+ close: async () => { },
181
+ run: (statement, parameters) => whenAdmitted(this.gate, () => this.runNow(statement, parameters, false), token),
182
+ get: async (statement, parameters) => {
183
+ const rows = await whenAdmitted(this.gate, () => this.allNow(statement, parameters), token);
184
+ return rows.length > 0 ? rows[0] : null;
185
+ },
186
+ all: (statement, parameters) => whenAdmitted(this.gate, () => this.allNow(statement, parameters), token),
187
+ exec: (script) => whenAdmitted(this.gate, () => this.execNow(script, false), token),
188
+ // The handle answers a nested transaction() itself and never calls this.
189
+ transaction: (fn) => fn(this),
190
+ };
191
+ }
192
+ /**
193
+ * @param ownTransaction - true for a statement from outside a transaction:
194
+ * the plugin runs it in a transaction of its own, as it always has.
195
+ */
196
+ async runNow(statement, parameters, ownTransaction) {
197
+ const conn = this.ensureConnection();
198
+ const { positional } = normaliseParameters(parameters);
199
+ return toRunResult(await conn.run(statement, positional ?? [], ownTransaction));
200
+ }
201
+ async allNow(statement, parameters) {
202
+ const conn = this.ensureConnection();
203
+ const { positional } = normaliseParameters(parameters);
204
+ const result = await conn.query(statement, positional ?? []);
205
+ return (result.values ?? []);
206
+ }
207
+ async execNow(script, ownTransaction) {
208
+ const conn = this.ensureConnection();
209
+ await conn.execute(script, ownTransaction);
210
+ }
211
+ /** Keeps a statement sent from outside a transaction in `inFlight` until it answers. */
212
+ track(sent) {
213
+ this.inFlight.add(sent);
214
+ const forget = () => {
215
+ this.inFlight.delete(sent);
216
+ };
217
+ sent.then(forget, forget);
218
+ return sent;
219
+ }
220
+ reportLongWait() {
221
+ if (this.longWaitReported)
222
+ return;
223
+ this.longWaitReported = true;
224
+ console.warn(`[StorageAdapter] A Capacitor SQLite statement has waited ${LONG_WAIT_MS / 1000} s for an open transaction to end. ` +
225
+ "Inside a transaction() callback, run statements through the callback's handle: one run through the adapter " +
226
+ 'itself waits for the transaction, and the transaction waits for it.');
227
+ }
110
228
  ensureConnection() {
111
229
  if (!this.connection) {
112
230
  throw new Error('Storage adapter not opened. Call open() before executing statements.');
@@ -1 +1 @@
1
- {"version":3,"file":"capacitorSqliteAdapter.js","sourceRoot":"","sources":["../../src/adapters/capacitorSqliteAdapter.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAe/D,MAAM,iBAAiB,GAAG,CAAC,KAAc,EAAkC,EAAE;IAC3E,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACxC,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,SAAS,GAAG,KAAuC,CAAC;IAC1D,OAAO,OAAO,SAAS,CAAC,gBAAgB,KAAK,UAAU,CAAC;AAC1D,CAAC,CAAC;AAEF,MAAM,mBAAmB,GAAG,KAAK,IAA2C,EAAE;IAC5E,IAAI,CAAC;QACH,MAAM,GAAG,GAAY,MAAM,MAAM,CAAC,6BAA6B,CAAC,CAAC;QAEjE,IAAI,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC;YAC3B,OAAO,GAAG,CAAC;QACb,CAAC;QAED,IAAI,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;YACnC,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,GAAG,GAGnD,CAAC;YAEF,IAAI,iBAAiB,CAAC,aAAa,CAAC,EAAE,CAAC;gBACrC,OAAO,aAAa,CAAC;YACvB,CAAC;YACD,IAAI,iBAAiB,CAAC,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C;IAEO,cAAc;QACpB,IAAI,IAAI,CAAC,gBAAgB;YAAE,OAAO;QAClC,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;QAC7B,OAAO,CAAC,IAAI,CACV,4DAA4D,YAAY,GAAG,IAAI,qCAAqC;YAClH,6GAA6G;YAC7G,qEAAqE,CACxE,CAAC;IACJ,CAAC;IAEO,gBAAgB;QACtB,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,sEAAsE,CAAC,CAAC;QAC1F,CAAC;QACD,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;CACF;AAED,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,OAAiC,EAAkB,EAAE,CAChG,IAAI,sBAAsB,CAAC,OAAO,CAAC,CAAC"}
@@ -31,7 +31,7 @@
31
31
  * await db.open();
32
32
  * ```
33
33
  */
34
- import type { StorageAdapter, StorageCapability, StorageOpenOptions, StorageParameters, StorageRunResult, BatchOperation, BatchResult, PreparedStatement } from '../../core/contracts';
34
+ import type { StorageAdapter, StorageCapability, StorageOpenOptions, StorageParameters, StorageRunResult, BatchOperation, BatchResult, PreparedStatement } from '../../core/contracts/index.js';
35
35
  /**
36
36
  * WAL (Write-Ahead Logging) configuration.
37
37
  */
@@ -27,8 +27,8 @@
27
27
  * const users = await db.all('SELECT * FROM users');
28
28
  * ```
29
29
  */
30
- import type { StorageAdapter, StorageCapability, StorageOpenOptions, StorageParameters, StorageRunResult, BatchOperation, BatchResult, PreparedStatement } from '../../core/contracts';
31
- import type { DbChangeEvent, SyncStatus } from './ipc/types';
30
+ import type { StorageAdapter, StorageCapability, StorageOpenOptions, StorageParameters, StorageRunResult, BatchOperation, BatchResult, PreparedStatement } from '../../core/contracts/index.js';
31
+ import type { DbChangeEvent, SyncStatus } from './ipc/types.js';
32
32
  /**
33
33
  * Options for ElectronRendererAdapter.
34
34
  */
@@ -61,14 +61,14 @@
61
61
  *
62
62
  * @packageDocumentation
63
63
  */
64
- export { ElectronMainAdapter, createElectronMainAdapter, type ElectronMainAdapterOptions, type WalConfig, type RecoveryConfig, type MigrationConfig, type BackupConfig, type CloudBackupProvider, type MultiWindowConfig, } from './electronMainAdapter';
65
- export { ElectronRendererAdapter, createElectronRendererAdapter, isElectronRenderer, isPreloadApiAvailable, type ElectronRendererAdapterOptions, } from './electronRendererAdapter';
66
- export { sqlStorageApi, type SqlStorageApi, } from './preload';
67
- export { IPC_CHANNELS, DB_CHANNELS, TRANSACTION_CHANNELS, SYNC_CHANNELS, BACKUP_CHANNELS, RECOVERY_CHANNELS, MIGRATION_CHANNELS, BROADCAST_CHANNELS, type IpcChannel, } from './ipc/channels';
68
- export type { IpcRequest, IpcResponse, IpcError, SqlOperationPayload, ExecPayload, BatchPayload, OpenPayload, TransactionContext, TransactionOperationPayload, SyncStatus, BackupInfo, DbChangeEvent, ConnectionStateEvent, IntegrityCheckResult, WalCheckpointResult, MigrationStatus, } from './ipc/types';
69
- export { IpcProtocolManager, protocolManager, initializeIpcProtocol, disposeIpcProtocol, } from './ipc/protocol';
70
- export { WalCheckpointManager, createWalCheckpointManager, type WalCheckpointConfig, type CheckpointStrategy, type CheckpointResult, type WalStatus, CorruptionDetector, createCorruptionDetector, type CorruptionDetectorConfig, type IntegrityCheckLevel, type IntegrityCheckResult as RecoveryIntegrityCheckResult, type CorruptionIssue, type RepairStrategy, type RepairResult, } from './recovery';
71
- export { AutoMigrator, createAutoMigrator, type AutoMigratorConfig, type MigrationFile, type AppliedMigration, type MigrationResult, } from './migration';
72
- export { WindowManager, createWindowManager, type WindowManagerConfig, type WindowManagerCallbacks, type RegisteredWindow, } from './window';
73
- export type { StorageAdapter, StorageCapability, StorageOpenOptions, StorageParameters, StorageRunResult, BatchOperation, BatchResult, } from '../../core/contracts';
64
+ export { ElectronMainAdapter, createElectronMainAdapter, type ElectronMainAdapterOptions, type WalConfig, type RecoveryConfig, type MigrationConfig, type BackupConfig, type CloudBackupProvider, type MultiWindowConfig, } from './electronMainAdapter.js';
65
+ export { ElectronRendererAdapter, createElectronRendererAdapter, isElectronRenderer, isPreloadApiAvailable, type ElectronRendererAdapterOptions, } from './electronRendererAdapter.js';
66
+ export { sqlStorageApi, type SqlStorageApi, } from './preload.js';
67
+ export { IPC_CHANNELS, DB_CHANNELS, TRANSACTION_CHANNELS, SYNC_CHANNELS, BACKUP_CHANNELS, RECOVERY_CHANNELS, MIGRATION_CHANNELS, BROADCAST_CHANNELS, type IpcChannel, } from './ipc/channels.js';
68
+ export type { IpcRequest, IpcResponse, IpcError, SqlOperationPayload, ExecPayload, BatchPayload, OpenPayload, TransactionContext, TransactionOperationPayload, SyncStatus, BackupInfo, DbChangeEvent, ConnectionStateEvent, IntegrityCheckResult, WalCheckpointResult, MigrationStatus, } from './ipc/types.js';
69
+ export { IpcProtocolManager, protocolManager, initializeIpcProtocol, disposeIpcProtocol, } from './ipc/protocol.js';
70
+ export { WalCheckpointManager, createWalCheckpointManager, type WalCheckpointConfig, type CheckpointStrategy, type CheckpointResult, type WalStatus, CorruptionDetector, createCorruptionDetector, type CorruptionDetectorConfig, type IntegrityCheckLevel, type IntegrityCheckResult as RecoveryIntegrityCheckResult, type CorruptionIssue, type RepairStrategy, type RepairResult, } from './recovery/index.js';
71
+ export { AutoMigrator, createAutoMigrator, type AutoMigratorConfig, type MigrationFile, type AppliedMigration, type MigrationResult, } from './migration/index.js';
72
+ export { WindowManager, createWindowManager, type WindowManagerConfig, type WindowManagerCallbacks, type RegisteredWindow, } from './window/index.js';
73
+ export type { StorageAdapter, StorageCapability, StorageOpenOptions, StorageParameters, StorageRunResult, BatchOperation, BatchResult, } from '../../core/contracts/index.js';
74
74
  //# sourceMappingURL=index.d.ts.map
@@ -5,7 +5,7 @@
5
5
  *
6
6
  * @packageDocumentation
7
7
  */
8
- export * from './channels';
9
- export * from './types';
10
- export { IpcProtocolManager, protocolManager, initializeIpcProtocol, disposeIpcProtocol, } from './protocol';
8
+ export * from './channels.js';
9
+ export * from './types.js';
10
+ export { IpcProtocolManager, protocolManager, initializeIpcProtocol, disposeIpcProtocol, } from './protocol.js';
11
11
  //# sourceMappingURL=index.d.ts.map
@@ -5,7 +5,7 @@
5
5
  * operations from renderer processes. Ensures type-safe communication
6
6
  * and proper error handling.
7
7
  */
8
- import type { StorageAdapter } from '../../../core/contracts';
8
+ import type { StorageAdapter } from '../../../core/contracts/index.js';
9
9
  /**
10
10
  * IPC Protocol Manager.
11
11
  *
@@ -4,7 +4,7 @@
4
4
  * Provides type-safe request/response patterns for IPC communication
5
5
  * between main and renderer processes.
6
6
  */
7
- import type { StorageParameters, StorageRunResult, StorageOpenOptions, StorageCapability, BatchOperation, BatchResult } from '../../../core/contracts';
7
+ import type { StorageParameters, StorageRunResult, StorageOpenOptions, StorageCapability, BatchOperation, BatchResult } from '../../../core/contracts/index.js';
8
8
  /**
9
9
  * Base request structure with correlation ID for request tracking.
10
10
  */
@@ -22,7 +22,7 @@
22
22
  * await migrator.runPending();
23
23
  * ```
24
24
  */
25
- import type { StorageAdapter } from '../../../core/contracts';
25
+ import type { StorageAdapter } from '../../../core/contracts/index.js';
26
26
  /**
27
27
  * Migration file definition.
28
28
  */
@@ -5,5 +5,5 @@
5
5
  *
6
6
  * @packageDocumentation
7
7
  */
8
- export { AutoMigrator, createAutoMigrator, type AutoMigratorConfig, type MigrationFile, type AppliedMigration, type MigrationResult, } from './autoMigrator';
8
+ export { AutoMigrator, createAutoMigrator, type AutoMigratorConfig, type MigrationFile, type AppliedMigration, type MigrationResult, } from './autoMigrator.js';
9
9
  //# sourceMappingURL=index.d.ts.map
@@ -21,8 +21,8 @@
21
21
  * });
22
22
  * ```
23
23
  */
24
- import type { TransactionContext, SyncStatus, DbChangeEvent } from './ipc/types';
25
- import type { StorageRunResult, StorageOpenOptions, StorageParameters, BatchOperation, BatchResult, StorageCapability } from '../../core/contracts';
24
+ import type { TransactionContext, SyncStatus, DbChangeEvent } from './ipc/types.js';
25
+ import type { StorageRunResult, StorageOpenOptions, StorageParameters, BatchOperation, BatchResult, StorageCapability } from '../../core/contracts/index.js';
26
26
  /**
27
27
  * SQL Storage API exposed to renderer processes.
28
28
  */
@@ -30,7 +30,7 @@
30
30
  * }
31
31
  * ```
32
32
  */
33
- import type { StorageAdapter } from '../../../core/contracts';
33
+ import type { StorageAdapter } from '../../../core/contracts/index.js';
34
34
  /**
35
35
  * Integrity check level.
36
36
  */
@@ -6,6 +6,6 @@
6
6
  *
7
7
  * @packageDocumentation
8
8
  */
9
- export { WalCheckpointManager, createWalCheckpointManager, type WalCheckpointConfig, type CheckpointStrategy, type CheckpointResult, type WalStatus, } from './walCheckpoint';
10
- export { CorruptionDetector, createCorruptionDetector, type CorruptionDetectorConfig, type IntegrityCheckLevel, type IntegrityCheckResult, type CorruptionIssue, type RepairStrategy, type RepairResult, } from './corruptionDetector';
9
+ export { WalCheckpointManager, createWalCheckpointManager, type WalCheckpointConfig, type CheckpointStrategy, type CheckpointResult, type WalStatus, } from './walCheckpoint.js';
10
+ export { CorruptionDetector, createCorruptionDetector, type CorruptionDetectorConfig, type IntegrityCheckLevel, type IntegrityCheckResult, type CorruptionIssue, type RepairStrategy, type RepairResult, } from './corruptionDetector.js';
11
11
  //# sourceMappingURL=index.d.ts.map
@@ -27,7 +27,7 @@
27
27
  * await manager.start();
28
28
  * ```
29
29
  */
30
- import type { StorageAdapter } from '../../../core/contracts';
30
+ import type { StorageAdapter } from '../../../core/contracts/index.js';
31
31
  /**
32
32
  * WAL checkpoint strategy.
33
33
  */
@@ -5,5 +5,5 @@
5
5
  *
6
6
  * @packageDocumentation
7
7
  */
8
- export { WindowManager, createWindowManager, type WindowManagerConfig, type WindowManagerCallbacks, type RegisteredWindow, } from './windowManager';
8
+ export { WindowManager, createWindowManager, type WindowManagerConfig, type WindowManagerCallbacks, type RegisteredWindow, } from './windowManager.js';
9
9
  //# sourceMappingURL=index.d.ts.map
@@ -32,7 +32,7 @@
32
32
  * ```
33
33
  */
34
34
  import { BrowserWindow } from 'electron';
35
- import type { DbChangeEvent } from '../ipc/types';
35
+ import type { DbChangeEvent } from '../ipc/types.js';
36
36
  /**
37
37
  * Window registration info.
38
38
  */