@powersync/capacitor 0.5.0 → 0.5.1
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/esm/adapter/CapacitorSQLiteAdapter.d.ts +24 -14
- package/dist/esm/adapter/CapacitorSQLiteAdapter.js +21 -79
- package/dist/esm/adapter/CapacitorSQLiteAdapter.js.map +1 -1
- package/dist/plugin.cjs +20 -78
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.d.cts +23 -14
- package/dist/plugin.js +20 -78
- package/dist/plugin.js.map +1 -1
- package/package.json +2 -2
- package/src/adapter/CapacitorSQLiteAdapter.ts +24 -88
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
import { SQLiteDBConnection } from '@capacitor-community/sqlite';
|
|
2
|
-
import { BaseObserver,
|
|
2
|
+
import { BaseObserver, ConnectionPool, DBAdapterListener, DBLockOptions, LockContext, QueryResult, Transaction } from '@powersync/web';
|
|
3
3
|
import { Mutex } from 'async-mutex';
|
|
4
4
|
import { CapacitorSQLiteOpenFactoryOptions } from './CapacitorSQLiteOpenFactory.js';
|
|
5
|
-
|
|
6
|
-
* An implementation of {@link DBAdapter} using the Capacitor Community SQLite [plugin](https://github.com/capacitor-community/sqlite).
|
|
7
|
-
*
|
|
8
|
-
* @experimental
|
|
9
|
-
* @alpha This is currently experimental and may change without a major version bump.
|
|
10
|
-
*/
|
|
11
|
-
export declare class CapacitorSQLiteAdapter extends BaseObserver<DBAdapterListener> implements DBAdapter {
|
|
5
|
+
declare class CapacitorConnectionPool extends BaseObserver<DBAdapterListener> implements ConnectionPool {
|
|
12
6
|
protected options: CapacitorSQLiteOpenFactoryOptions;
|
|
13
7
|
protected _writeConnection: SQLiteDBConnection | null;
|
|
14
8
|
protected _readConnection: SQLiteDBConnection | null;
|
|
@@ -22,16 +16,32 @@ export declare class CapacitorSQLiteAdapter extends BaseObserver<DBAdapterListen
|
|
|
22
16
|
private init;
|
|
23
17
|
close(): Promise<void>;
|
|
24
18
|
protected generateLockContext(db: SQLiteDBConnection): LockContext;
|
|
25
|
-
execute(query: string, params?: any[]): Promise<QueryResult>;
|
|
26
|
-
executeRaw(query: string, params?: any[]): Promise<any[][]>;
|
|
27
|
-
executeBatch(query: string, params?: any[][]): Promise<QueryResult>;
|
|
28
19
|
readLock<T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions): Promise<T>;
|
|
29
|
-
readTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions): Promise<T>;
|
|
30
20
|
writeLock<T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions): Promise<T>;
|
|
31
|
-
writeTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions): Promise<T>;
|
|
32
21
|
refreshSchema(): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
declare const CapacitorSQLiteAdapter_base: (new (...args: any[]) => {
|
|
24
|
+
readTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions): Promise<T>;
|
|
25
|
+
writeTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions): Promise<T>;
|
|
33
26
|
getAll<T>(sql: string, parameters?: any[]): Promise<T[]>;
|
|
34
27
|
getOptional<T>(sql: string, parameters?: any[]): Promise<T | null>;
|
|
35
28
|
get<T>(sql: string, parameters?: any[]): Promise<T>;
|
|
36
|
-
|
|
29
|
+
execute(query: string, params?: any[]): Promise<QueryResult>;
|
|
30
|
+
executeRaw(query: string, params?: any[]): Promise<any[][]>;
|
|
31
|
+
executeBatch(query: string, params?: any[][]): Promise<QueryResult>;
|
|
32
|
+
name: string;
|
|
33
|
+
close: () => void | Promise<void>;
|
|
34
|
+
readLock: <T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions) => Promise<T>;
|
|
35
|
+
writeLock: <T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions) => Promise<T>;
|
|
36
|
+
refreshSchema: () => Promise<void>;
|
|
37
|
+
registerListener(listener: Partial<DBAdapterListener>): () => void;
|
|
38
|
+
}) & typeof CapacitorConnectionPool;
|
|
39
|
+
/**
|
|
40
|
+
* An implementation of {@link DBAdapter} using the Capacitor Community SQLite [plugin](https://github.com/capacitor-community/sqlite).
|
|
41
|
+
*
|
|
42
|
+
* @experimental
|
|
43
|
+
* @alpha This is currently experimental and may change without a major version bump.
|
|
44
|
+
*/
|
|
45
|
+
export declare class CapacitorSQLiteAdapter extends CapacitorSQLiteAdapter_base {
|
|
37
46
|
}
|
|
47
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CapacitorSQLite, SQLiteConnection } from '@capacitor-community/sqlite';
|
|
2
2
|
import { Capacitor } from '@capacitor/core';
|
|
3
|
-
import { BaseObserver, mutexRunExclusive } from '@powersync/web';
|
|
3
|
+
import { BaseObserver, DBAdapterDefaultMixin, mutexRunExclusive } from '@powersync/web';
|
|
4
4
|
import { Mutex } from 'async-mutex';
|
|
5
5
|
import { PowerSyncCore } from '../plugin/PowerSyncCore.js';
|
|
6
6
|
import { messageForErrorCode } from '../plugin/PowerSyncPlugin.js';
|
|
@@ -20,13 +20,7 @@ async function monitorQuery(sql, executor) {
|
|
|
20
20
|
throw e;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
* An implementation of {@link DBAdapter} using the Capacitor Community SQLite [plugin](https://github.com/capacitor-community/sqlite).
|
|
25
|
-
*
|
|
26
|
-
* @experimental
|
|
27
|
-
* @alpha This is currently experimental and may change without a major version bump.
|
|
28
|
-
*/
|
|
29
|
-
export class CapacitorSQLiteAdapter extends BaseObserver {
|
|
23
|
+
class CapacitorConnectionPool extends BaseObserver {
|
|
30
24
|
constructor(options) {
|
|
31
25
|
super();
|
|
32
26
|
this.options = options;
|
|
@@ -171,24 +165,9 @@ export class CapacitorSQLiteAdapter extends BaseObserver {
|
|
|
171
165
|
const results = await execute(query, params);
|
|
172
166
|
return (_b = (_a = results.rows) === null || _a === void 0 ? void 0 : _a._array.map((row) => Object.values(row))) !== null && _b !== void 0 ? _b : [];
|
|
173
167
|
};
|
|
174
|
-
|
|
175
|
-
getAll,
|
|
176
|
-
getOptional,
|
|
177
|
-
get,
|
|
178
|
-
executeRaw,
|
|
179
|
-
execute
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
execute(query, params) {
|
|
183
|
-
return this.writeLock((tx) => tx.execute(query, params));
|
|
184
|
-
}
|
|
185
|
-
executeRaw(query, params) {
|
|
186
|
-
return this.writeLock((tx) => tx.executeRaw(query, params));
|
|
187
|
-
}
|
|
188
|
-
async executeBatch(query, params = []) {
|
|
189
|
-
return this.writeLock(async (tx) => {
|
|
168
|
+
const executeBatch = async (query, params = []) => {
|
|
190
169
|
var _a, _b, _c;
|
|
191
|
-
let result = await
|
|
170
|
+
let result = await db.executeSet(params.map((param) => ({
|
|
192
171
|
statement: query,
|
|
193
172
|
values: param
|
|
194
173
|
})));
|
|
@@ -196,7 +175,15 @@ export class CapacitorSQLiteAdapter extends BaseObserver {
|
|
|
196
175
|
rowsAffected: (_b = (_a = result.changes) === null || _a === void 0 ? void 0 : _a.changes) !== null && _b !== void 0 ? _b : 0,
|
|
197
176
|
insertId: (_c = result.changes) === null || _c === void 0 ? void 0 : _c.lastId
|
|
198
177
|
};
|
|
199
|
-
}
|
|
178
|
+
};
|
|
179
|
+
return {
|
|
180
|
+
getAll,
|
|
181
|
+
getOptional,
|
|
182
|
+
get,
|
|
183
|
+
executeRaw,
|
|
184
|
+
execute,
|
|
185
|
+
executeBatch
|
|
186
|
+
};
|
|
200
187
|
}
|
|
201
188
|
readLock(fn, options) {
|
|
202
189
|
return mutexRunExclusive(this.readMutex, async () => {
|
|
@@ -204,11 +191,6 @@ export class CapacitorSQLiteAdapter extends BaseObserver {
|
|
|
204
191
|
return await fn(this.generateLockContext(this.readConnection));
|
|
205
192
|
}, options);
|
|
206
193
|
}
|
|
207
|
-
readTransaction(fn, options) {
|
|
208
|
-
return this.readLock(async (ctx) => {
|
|
209
|
-
return this.internalTransaction(ctx, fn);
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
194
|
writeLock(fn, options) {
|
|
213
195
|
return mutexRunExclusive(this.writeMutex, async () => {
|
|
214
196
|
var _a;
|
|
@@ -229,11 +211,6 @@ export class CapacitorSQLiteAdapter extends BaseObserver {
|
|
|
229
211
|
return result;
|
|
230
212
|
}, options);
|
|
231
213
|
}
|
|
232
|
-
writeTransaction(fn, options) {
|
|
233
|
-
return this.writeLock(async (ctx) => {
|
|
234
|
-
return this.internalTransaction(ctx, fn);
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
214
|
refreshSchema() {
|
|
238
215
|
return this.writeLock(async (writeTx) => {
|
|
239
216
|
return this.readLock(async (readTx) => {
|
|
@@ -243,48 +220,13 @@ export class CapacitorSQLiteAdapter extends BaseObserver {
|
|
|
243
220
|
});
|
|
244
221
|
});
|
|
245
222
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
255
|
-
async internalTransaction(ctx, fn) {
|
|
256
|
-
let finalized = false;
|
|
257
|
-
const commit = async () => {
|
|
258
|
-
if (finalized) {
|
|
259
|
-
return { rowsAffected: 0 };
|
|
260
|
-
}
|
|
261
|
-
finalized = true;
|
|
262
|
-
return ctx.execute('COMMIT');
|
|
263
|
-
};
|
|
264
|
-
const rollback = async () => {
|
|
265
|
-
if (finalized) {
|
|
266
|
-
return { rowsAffected: 0 };
|
|
267
|
-
}
|
|
268
|
-
finalized = true;
|
|
269
|
-
return ctx.execute('ROLLBACK');
|
|
270
|
-
};
|
|
271
|
-
try {
|
|
272
|
-
await ctx.execute('BEGIN');
|
|
273
|
-
const result = await fn(Object.assign(Object.assign({}, ctx), { commit,
|
|
274
|
-
rollback }));
|
|
275
|
-
await commit();
|
|
276
|
-
return result;
|
|
277
|
-
}
|
|
278
|
-
catch (ex) {
|
|
279
|
-
try {
|
|
280
|
-
await rollback();
|
|
281
|
-
}
|
|
282
|
-
catch (ex2) {
|
|
283
|
-
// In rare cases, a rollback may fail.
|
|
284
|
-
// Safe to ignore.
|
|
285
|
-
}
|
|
286
|
-
throw ex;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* An implementation of {@link DBAdapter} using the Capacitor Community SQLite [plugin](https://github.com/capacitor-community/sqlite).
|
|
226
|
+
*
|
|
227
|
+
* @experimental
|
|
228
|
+
* @alpha This is currently experimental and may change without a major version bump.
|
|
229
|
+
*/
|
|
230
|
+
export class CapacitorSQLiteAdapter extends DBAdapterDefaultMixin(CapacitorConnectionPool) {
|
|
289
231
|
}
|
|
290
232
|
//# sourceMappingURL=CapacitorSQLiteAdapter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CapacitorSQLiteAdapter.js","sourceRoot":"","sources":["../../../src/adapter/CapacitorSQLiteAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAsB,MAAM,6BAA6B,CAAC;AACpG,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EACL,YAAY,EAMZ,iBAAiB,EAGlB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAqC,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAC5G;;GAEG;AACH,KAAK,UAAU,YAAY,CAAC,GAAW,EAAE,QAAoC;IAC3E,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IAChC,IAAI,CAAC;QACH,MAAM,CAAC,GAAG,MAAM,QAAQ,EAAE,CAAC;QAC3B,WAAW,CAAC,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YACf,OAAO,MAAM,CAAC;QAChB,CAAC;QAAC,OAAO,EAAE,EAAE,CAAC;YACZ,IAAI,CAAC;gBACH,MAAM,QAAQ,EAAE,CAAC;YACnB,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,sCAAsC;gBACtC,kBAAkB;YACpB,CAAC;YACD,MAAM,EAAE,CAAC;QACX,CAAC;IACH,CAAC;CACF","sourcesContent":["import { CapacitorSQLite, SQLiteConnection, SQLiteDBConnection } from '@capacitor-community/sqlite';\nimport { Capacitor } from '@capacitor/core';\n\nimport {\n BaseObserver,\n BatchedUpdateNotification,\n DBAdapter,\n DBAdapterListener,\n DBLockOptions,\n LockContext,\n mutexRunExclusive,\n QueryResult,\n Transaction\n} from '@powersync/web';\nimport { Mutex } from 'async-mutex';\nimport { PowerSyncCore } from '../plugin/PowerSyncCore.js';\nimport { messageForErrorCode } from '../plugin/PowerSyncPlugin.js';\nimport { CapacitorSQLiteOpenFactoryOptions, DEFAULT_SQLITE_OPTIONS } from './CapacitorSQLiteOpenFactory.js';\n/**\n * Monitors the execution time of a query and logs it to the performance timeline.\n */\nasync function monitorQuery(sql: string, executor: () => Promise<QueryResult>): Promise<QueryResult> {\n const start = performance.now();\n try {\n const r = await executor();\n performance.measure(`[SQL] ${sql}`, { start });\n return r;\n } catch (e: any) {\n performance.measure(`[SQL] [ERROR: ${e.message}] ${sql}`, { start });\n throw e;\n }\n}\n/**\n * An implementation of {@link DBAdapter} using the Capacitor Community SQLite [plugin](https://github.com/capacitor-community/sqlite).\n *\n * @experimental\n * @alpha This is currently experimental and may change without a major version bump.\n */\nexport class CapacitorSQLiteAdapter extends BaseObserver<DBAdapterListener> implements DBAdapter {\n protected _writeConnection: SQLiteDBConnection | null;\n protected _readConnection: SQLiteDBConnection | null;\n protected initializedPromise: Promise<void>;\n protected writeMutex: Mutex;\n protected readMutex: Mutex;\n\n constructor(protected options: CapacitorSQLiteOpenFactoryOptions) {\n super();\n this._writeConnection = null;\n this._readConnection = null;\n this.writeMutex = new Mutex();\n this.readMutex = new Mutex();\n this.initializedPromise = this.init();\n }\n\n protected get writeConnection(): SQLiteDBConnection {\n if (!this._writeConnection) {\n throw new Error('Init not completed yet');\n }\n return this._writeConnection;\n }\n\n protected get readConnection(): SQLiteDBConnection {\n if (!this._readConnection) {\n throw new Error('Init not completed yet');\n }\n return this._readConnection;\n }\n\n get name() {\n return this.options.dbFilename;\n }\n\n private async init() {\n const { responseCode: registrationResponseCode } = await PowerSyncCore.registerCore();\n if (registrationResponseCode != 0) {\n throw new Error(`Could not register PowerSync core extension: ${messageForErrorCode(registrationResponseCode)}`);\n }\n\n const sqlite = new SQLiteConnection(CapacitorSQLite);\n\n // It seems like the isConnection and retrieveConnection methods\n // only check a JS side map of connections.\n // On hot reload this JS cache can be cleared, while the connection\n // still exists natively. and `createConnection` will fail if it already exists.\n await sqlite.closeConnection(this.options.dbFilename, false).catch(() => {});\n await sqlite.closeConnection(this.options.dbFilename, true).catch(() => {});\n\n // TODO support encryption eventually\n this._writeConnection = await sqlite.createConnection(this.options.dbFilename, false, 'no-encryption', 1, false);\n this._readConnection = await sqlite.createConnection(this.options.dbFilename, false, 'no-encryption', 1, true);\n\n await this._writeConnection.open();\n\n const { cacheSizeKb, journalSizeLimit, synchronous } = { ...DEFAULT_SQLITE_OPTIONS, ...this.options.sqliteOptions };\n\n await this.writeConnection.query('PRAGMA journal_mode = WAL');\n await this.writeConnection.query(`PRAGMA journal_size_limit = ${journalSizeLimit}`);\n await this.writeConnection.query(`PRAGMA temp_store = memory`);\n await this.writeConnection.query(`PRAGMA synchronous = ${synchronous}`);\n await this.writeConnection.query(`PRAGMA cache_size = -${cacheSizeKb}`);\n\n await this._readConnection.open();\n\n const platform = Capacitor.getPlatform();\n if (platform == 'android') {\n /**\n * SQLCipher for Android enables dynamic loading of extensions.\n * On iOS we use a static auto extension registration.\n */\n const extensionQuery = \"SELECT load_extension('libpowersync.so', 'sqlite3_powersync_init')\";\n await this.writeConnection.query(extensionQuery);\n await this.readConnection.query(extensionQuery);\n }\n await this.writeConnection.query(\"SELECT powersync_update_hooks('install')\");\n }\n\n async close(): Promise<void> {\n await this.initializedPromise;\n await this.writeConnection.close();\n await this.readConnection.close();\n }\n\n protected generateLockContext(db: SQLiteDBConnection): LockContext {\n const _query = async (query: string, params: any[] = []) => {\n const result = await db.query(query, params);\n const arrayResult = result.values ?? [];\n return {\n rowsAffected: 0,\n rows: {\n _array: arrayResult,\n length: arrayResult.length,\n item: (idx: number) => arrayResult[idx]\n }\n };\n };\n\n const _execute = async (query: string, params: any[] = []): Promise<QueryResult> => {\n const platform = Capacitor.getPlatform();\n\n if (db.getConnectionReadOnly()) {\n return _query(query, params);\n }\n\n if (platform == 'android') {\n // Android: use query for SELECT and executeSet for mutations\n // We cannot use `run` here for both cases.\n if (query.toLowerCase().trim().startsWith('select')) {\n return _query(query, params);\n } else {\n const result = await db.executeSet([{ statement: query, values: params }], false);\n return {\n insertId: result.changes?.lastId,\n rowsAffected: result.changes?.changes ?? 0,\n rows: {\n _array: [],\n length: 0,\n item: () => null\n }\n };\n }\n }\n\n // iOS (and other platforms): use run(\"all\")\n const result = await db.run(query, params, false, 'all');\n const resultSet = result.changes?.values ?? [];\n return {\n insertId: result.changes?.lastId,\n rowsAffected: result.changes?.changes ?? 0,\n rows: {\n _array: resultSet,\n length: resultSet.length,\n item: (idx) => resultSet[idx]\n }\n };\n };\n\n const execute = this.options.debugMode\n ? (sql: string, params?: any[]) => monitorQuery(sql, () => _execute(sql, params))\n : _execute;\n\n const executeQuery = this.options.debugMode\n ? (sql: string, params?: any[]) => monitorQuery(sql, () => _query(sql, params))\n : _query;\n\n const getAll = async <T>(query: string, params?: any[]): Promise<T[]> => {\n const result = await executeQuery(query, params);\n return result.rows?._array ?? ([] as T[]);\n };\n\n const getOptional = async <T>(query: string, params?: any[]): Promise<T | null> => {\n const results = await getAll<T>(query, params);\n return results.length > 0 ? results[0] : null;\n };\n\n const get = async <T>(query: string, params?: any[]): Promise<T> => {\n const result = await getOptional<T>(query, params);\n if (!result) {\n throw new Error(`No results for query: ${query}`);\n }\n return result;\n };\n\n const executeRaw = async (query: string, params?: any[]): Promise<any[][]> => {\n // This is a workaround, we don't support multiple columns of the same name\n const results = await execute(query, params);\n return results.rows?._array.map((row) => Object.values(row)) ?? [];\n };\n\n return {\n getAll,\n getOptional,\n get,\n executeRaw,\n execute\n };\n }\n\n execute(query: string, params?: any[]): Promise<QueryResult> {\n return this.writeLock((tx) => tx.execute(query, params));\n }\n\n executeRaw(query: string, params?: any[]): Promise<any[][]> {\n return this.writeLock((tx) => tx.executeRaw(query, params));\n }\n\n async executeBatch(query: string, params: any[][] = []): Promise<QueryResult> {\n return this.writeLock(async (tx) => {\n let result = await this.writeConnection.executeSet(\n params.map((param) => ({\n statement: query,\n values: param\n }))\n );\n\n return {\n rowsAffected: result.changes?.changes ?? 0,\n insertId: result.changes?.lastId\n };\n });\n }\n\n readLock<T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions): Promise<T> {\n return mutexRunExclusive(\n this.readMutex,\n async () => {\n await this.initializedPromise;\n return await fn(this.generateLockContext(this.readConnection));\n },\n options\n );\n }\n\n readTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions): Promise<T> {\n return this.readLock(async (ctx) => {\n return this.internalTransaction(ctx, fn);\n });\n }\n\n writeLock<T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions): Promise<T> {\n return mutexRunExclusive(\n this.writeMutex,\n async () => {\n await this.initializedPromise;\n const result = await fn(this.generateLockContext(this.writeConnection));\n\n // Fetch table updates\n const updates = await this.writeConnection.query(\"SELECT powersync_update_hooks('get') AS table_name\");\n const jsonUpdates = updates.values?.[0];\n if (!jsonUpdates || !jsonUpdates.table_name) {\n throw new Error('Could not fetch table updates');\n }\n const notification: BatchedUpdateNotification = {\n rawUpdates: [],\n tables: JSON.parse(jsonUpdates.table_name),\n groupedUpdates: {}\n };\n this.iterateListeners((l) => l.tablesUpdated?.(notification));\n return result;\n },\n options\n );\n }\n\n writeTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions): Promise<T> {\n return this.writeLock(async (ctx) => {\n return this.internalTransaction(ctx, fn);\n });\n }\n\n refreshSchema(): Promise<void> {\n return this.writeLock(async (writeTx) => {\n return this.readLock(async (readTx) => {\n const updateQuery = `PRAGMA table_info('sqlite_master')`;\n await writeTx.get(updateQuery);\n await readTx.get(updateQuery);\n });\n });\n }\n\n getAll<T>(sql: string, parameters?: any[]): Promise<T[]> {\n return this.readLock((tx) => tx.getAll<T>(sql, parameters));\n }\n\n getOptional<T>(sql: string, parameters?: any[]): Promise<T | null> {\n return this.readLock((tx) => tx.getOptional<T>(sql, parameters));\n }\n\n get<T>(sql: string, parameters?: any[]): Promise<T> {\n return this.readLock((tx) => tx.get<T>(sql, parameters));\n }\n\n protected async internalTransaction<T>(ctx: LockContext, fn: (tx: Transaction) => Promise<T>): Promise<T> {\n let finalized = false;\n const commit = async (): Promise<QueryResult> => {\n if (finalized) {\n return { rowsAffected: 0 };\n }\n finalized = true;\n return ctx.execute('COMMIT');\n };\n const rollback = async (): Promise<QueryResult> => {\n if (finalized) {\n return { rowsAffected: 0 };\n }\n finalized = true;\n return ctx.execute('ROLLBACK');\n };\n try {\n await ctx.execute('BEGIN');\n const result = await fn({\n ...ctx,\n commit,\n rollback\n });\n await commit();\n return result;\n } catch (ex) {\n try {\n await rollback();\n } catch (ex2) {\n // In rare cases, a rollback may fail.\n // Safe to ignore.\n }\n throw ex;\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"CapacitorSQLiteAdapter.js","sourceRoot":"","sources":["../../../src/adapter/CapacitorSQLiteAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAsB,MAAM,6BAA6B,CAAC;AACpG,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EACL,YAAY,EAIZ,qBAAqB,EAIrB,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AC5C,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;YACnD,CAAC;YACD,MAAM,YAAY,GAA8B;gBAC9C,UAAU,EAAE,EAAE;gBACd,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,UAAU,CAAC;gBAC1C,cAAc,EAAE,EAAE;aACnB,CAAC;YACF,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,EAAE,WAAC,OAAA,MAAA,CAAC,CAAC,aAAa,kDAAG,YAAY,CAAC,CAAA,EAAA,CAAC,CAAC;YAC9D,OAAO,MAAM,CAAC;QAChB,CAAC,EACD,OAAO,CACR,CAAC;IACJ,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;YACtC,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;gBACpC,MAAM,WAAW,GAAG,oCAAoC,CAAC;gBACzD,MAAM,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;gBAC/B,MAAM,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;YAChC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,OAAO,sBAAuB,SAAQ,qBAAqB,CAAC,uBAAuB,CAAC;CAAG","sourcesContent":["import { CapacitorSQLite, SQLiteConnection, SQLiteDBConnection } from '@capacitor-community/sqlite';\nimport { Capacitor } from '@capacitor/core';\n\nimport {\n BaseObserver,\n BatchedUpdateNotification,\n ConnectionPool,\n DBAdapter,\n DBAdapterDefaultMixin,\n DBAdapterListener,\n DBLockOptions,\n LockContext,\n mutexRunExclusive,\n QueryResult,\n Transaction\n} from '@powersync/web';\nimport { Mutex } from 'async-mutex';\nimport { PowerSyncCore } from '../plugin/PowerSyncCore.js';\nimport { messageForErrorCode } from '../plugin/PowerSyncPlugin.js';\nimport { CapacitorSQLiteOpenFactoryOptions, DEFAULT_SQLITE_OPTIONS } from './CapacitorSQLiteOpenFactory.js';\n/**\n * Monitors the execution time of a query and logs it to the performance timeline.\n */\nasync function monitorQuery(sql: string, executor: () => Promise<QueryResult>): Promise<QueryResult> {\n const start = performance.now();\n try {\n const r = await executor();\n performance.measure(`[SQL] ${sql}`, { start });\n return r;\n } catch (e: any) {\n performance.measure(`[SQL] [ERROR: ${e.message}] ${sql}`, { start });\n throw e;\n }\n}\n\nclass CapacitorConnectionPool extends BaseObserver<DBAdapterListener> implements ConnectionPool {\n protected _writeConnection: SQLiteDBConnection | null;\n protected _readConnection: SQLiteDBConnection | null;\n protected initializedPromise: Promise<void>;\n protected writeMutex: Mutex;\n protected readMutex: Mutex;\n\n constructor(protected options: CapacitorSQLiteOpenFactoryOptions) {\n super();\n this._writeConnection = null;\n this._readConnection = null;\n this.writeMutex = new Mutex();\n this.readMutex = new Mutex();\n this.initializedPromise = this.init();\n }\n\n protected get writeConnection(): SQLiteDBConnection {\n if (!this._writeConnection) {\n throw new Error('Init not completed yet');\n }\n return this._writeConnection;\n }\n\n protected get readConnection(): SQLiteDBConnection {\n if (!this._readConnection) {\n throw new Error('Init not completed yet');\n }\n return this._readConnection;\n }\n\n get name() {\n return this.options.dbFilename;\n }\n\n private async init() {\n const { responseCode: registrationResponseCode } = await PowerSyncCore.registerCore();\n if (registrationResponseCode != 0) {\n throw new Error(`Could not register PowerSync core extension: ${messageForErrorCode(registrationResponseCode)}`);\n }\n\n const sqlite = new SQLiteConnection(CapacitorSQLite);\n\n // It seems like the isConnection and retrieveConnection methods\n // only check a JS side map of connections.\n // On hot reload this JS cache can be cleared, while the connection\n // still exists natively. and `createConnection` will fail if it already exists.\n await sqlite.closeConnection(this.options.dbFilename, false).catch(() => {});\n await sqlite.closeConnection(this.options.dbFilename, true).catch(() => {});\n\n // TODO support encryption eventually\n this._writeConnection = await sqlite.createConnection(this.options.dbFilename, false, 'no-encryption', 1, false);\n this._readConnection = await sqlite.createConnection(this.options.dbFilename, false, 'no-encryption', 1, true);\n\n await this._writeConnection.open();\n\n const { cacheSizeKb, journalSizeLimit, synchronous } = { ...DEFAULT_SQLITE_OPTIONS, ...this.options.sqliteOptions };\n\n await this.writeConnection.query('PRAGMA journal_mode = WAL');\n await this.writeConnection.query(`PRAGMA journal_size_limit = ${journalSizeLimit}`);\n await this.writeConnection.query(`PRAGMA temp_store = memory`);\n await this.writeConnection.query(`PRAGMA synchronous = ${synchronous}`);\n await this.writeConnection.query(`PRAGMA cache_size = -${cacheSizeKb}`);\n\n await this._readConnection.open();\n\n const platform = Capacitor.getPlatform();\n if (platform == 'android') {\n /**\n * SQLCipher for Android enables dynamic loading of extensions.\n * On iOS we use a static auto extension registration.\n */\n const extensionQuery = \"SELECT load_extension('libpowersync.so', 'sqlite3_powersync_init')\";\n await this.writeConnection.query(extensionQuery);\n await this.readConnection.query(extensionQuery);\n }\n await this.writeConnection.query(\"SELECT powersync_update_hooks('install')\");\n }\n\n async close(): Promise<void> {\n await this.initializedPromise;\n await this.writeConnection.close();\n await this.readConnection.close();\n }\n\n protected generateLockContext(db: SQLiteDBConnection): LockContext {\n const _query = async (query: string, params: any[] = []) => {\n const result = await db.query(query, params);\n const arrayResult = result.values ?? [];\n return {\n rowsAffected: 0,\n rows: {\n _array: arrayResult,\n length: arrayResult.length,\n item: (idx: number) => arrayResult[idx]\n }\n };\n };\n\n const _execute = async (query: string, params: any[] = []): Promise<QueryResult> => {\n const platform = Capacitor.getPlatform();\n\n if (db.getConnectionReadOnly()) {\n return _query(query, params);\n }\n\n if (platform == 'android') {\n // Android: use query for SELECT and executeSet for mutations\n // We cannot use `run` here for both cases.\n if (query.toLowerCase().trim().startsWith('select')) {\n return _query(query, params);\n } else {\n const result = await db.executeSet([{ statement: query, values: params }], false);\n return {\n insertId: result.changes?.lastId,\n rowsAffected: result.changes?.changes ?? 0,\n rows: {\n _array: [],\n length: 0,\n item: () => null\n }\n };\n }\n }\n\n // iOS (and other platforms): use run(\"all\")\n const result = await db.run(query, params, false, 'all');\n const resultSet = result.changes?.values ?? [];\n return {\n insertId: result.changes?.lastId,\n rowsAffected: result.changes?.changes ?? 0,\n rows: {\n _array: resultSet,\n length: resultSet.length,\n item: (idx) => resultSet[idx]\n }\n };\n };\n\n const execute = this.options.debugMode\n ? (sql: string, params?: any[]) => monitorQuery(sql, () => _execute(sql, params))\n : _execute;\n\n const executeQuery = this.options.debugMode\n ? (sql: string, params?: any[]) => monitorQuery(sql, () => _query(sql, params))\n : _query;\n\n const getAll = async <T>(query: string, params?: any[]): Promise<T[]> => {\n const result = await executeQuery(query, params);\n return result.rows?._array ?? ([] as T[]);\n };\n\n const getOptional = async <T>(query: string, params?: any[]): Promise<T | null> => {\n const results = await getAll<T>(query, params);\n return results.length > 0 ? results[0] : null;\n };\n\n const get = async <T>(query: string, params?: any[]): Promise<T> => {\n const result = await getOptional<T>(query, params);\n if (!result) {\n throw new Error(`No results for query: ${query}`);\n }\n return result;\n };\n\n const executeRaw = async (query: string, params?: any[]): Promise<any[][]> => {\n // This is a workaround, we don't support multiple columns of the same name\n const results = await execute(query, params);\n return results.rows?._array.map((row) => Object.values(row)) ?? [];\n };\n\n const executeBatch = async (query: string, params: any[][] = []): Promise<QueryResult> => {\n let result = await db.executeSet(\n params.map((param) => ({\n statement: query,\n values: param\n }))\n );\n\n return {\n rowsAffected: result.changes?.changes ?? 0,\n insertId: result.changes?.lastId\n };\n };\n\n return {\n getAll,\n getOptional,\n get,\n executeRaw,\n execute,\n executeBatch\n };\n }\n\n readLock<T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions): Promise<T> {\n return mutexRunExclusive(\n this.readMutex,\n async () => {\n await this.initializedPromise;\n return await fn(this.generateLockContext(this.readConnection));\n },\n options\n );\n }\n\n writeLock<T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions): Promise<T> {\n return mutexRunExclusive(\n this.writeMutex,\n async () => {\n await this.initializedPromise;\n const result = await fn(this.generateLockContext(this.writeConnection));\n\n // Fetch table updates\n const updates = await this.writeConnection.query(\"SELECT powersync_update_hooks('get') AS table_name\");\n const jsonUpdates = updates.values?.[0];\n if (!jsonUpdates || !jsonUpdates.table_name) {\n throw new Error('Could not fetch table updates');\n }\n const notification: BatchedUpdateNotification = {\n rawUpdates: [],\n tables: JSON.parse(jsonUpdates.table_name),\n groupedUpdates: {}\n };\n this.iterateListeners((l) => l.tablesUpdated?.(notification));\n return result;\n },\n options\n );\n }\n\n refreshSchema(): Promise<void> {\n return this.writeLock(async (writeTx) => {\n return this.readLock(async (readTx) => {\n const updateQuery = `PRAGMA table_info('sqlite_master')`;\n await writeTx.get(updateQuery);\n await readTx.get(updateQuery);\n });\n });\n }\n}\n\n/**\n * An implementation of {@link DBAdapter} using the Capacitor Community SQLite [plugin](https://github.com/capacitor-community/sqlite).\n *\n * @experimental\n * @alpha This is currently experimental and may change without a major version bump.\n */\nexport class CapacitorSQLiteAdapter extends DBAdapterDefaultMixin(CapacitorConnectionPool) {}\n"]}
|
package/dist/plugin.cjs
CHANGED
|
@@ -53,13 +53,7 @@ async function monitorQuery(sql, executor) {
|
|
|
53
53
|
throw e;
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
|
|
57
|
-
* An implementation of {@link DBAdapter} using the Capacitor Community SQLite [plugin](https://github.com/capacitor-community/sqlite).
|
|
58
|
-
*
|
|
59
|
-
* @experimental
|
|
60
|
-
* @alpha This is currently experimental and may change without a major version bump.
|
|
61
|
-
*/
|
|
62
|
-
class CapacitorSQLiteAdapter extends web$1.BaseObserver {
|
|
56
|
+
class CapacitorConnectionPool extends web$1.BaseObserver {
|
|
63
57
|
constructor(options) {
|
|
64
58
|
super();
|
|
65
59
|
this.options = options;
|
|
@@ -204,24 +198,9 @@ class CapacitorSQLiteAdapter extends web$1.BaseObserver {
|
|
|
204
198
|
const results = await execute(query, params);
|
|
205
199
|
return (_b = (_a = results.rows) === null || _a === void 0 ? void 0 : _a._array.map((row) => Object.values(row))) !== null && _b !== void 0 ? _b : [];
|
|
206
200
|
};
|
|
207
|
-
|
|
208
|
-
getAll,
|
|
209
|
-
getOptional,
|
|
210
|
-
get,
|
|
211
|
-
executeRaw,
|
|
212
|
-
execute
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
execute(query, params) {
|
|
216
|
-
return this.writeLock((tx) => tx.execute(query, params));
|
|
217
|
-
}
|
|
218
|
-
executeRaw(query, params) {
|
|
219
|
-
return this.writeLock((tx) => tx.executeRaw(query, params));
|
|
220
|
-
}
|
|
221
|
-
async executeBatch(query, params = []) {
|
|
222
|
-
return this.writeLock(async (tx) => {
|
|
201
|
+
const executeBatch = async (query, params = []) => {
|
|
223
202
|
var _a, _b, _c;
|
|
224
|
-
let result = await
|
|
203
|
+
let result = await db.executeSet(params.map((param) => ({
|
|
225
204
|
statement: query,
|
|
226
205
|
values: param
|
|
227
206
|
})));
|
|
@@ -229,7 +208,15 @@ class CapacitorSQLiteAdapter extends web$1.BaseObserver {
|
|
|
229
208
|
rowsAffected: (_b = (_a = result.changes) === null || _a === void 0 ? void 0 : _a.changes) !== null && _b !== void 0 ? _b : 0,
|
|
230
209
|
insertId: (_c = result.changes) === null || _c === void 0 ? void 0 : _c.lastId
|
|
231
210
|
};
|
|
232
|
-
}
|
|
211
|
+
};
|
|
212
|
+
return {
|
|
213
|
+
getAll,
|
|
214
|
+
getOptional,
|
|
215
|
+
get,
|
|
216
|
+
executeRaw,
|
|
217
|
+
execute,
|
|
218
|
+
executeBatch
|
|
219
|
+
};
|
|
233
220
|
}
|
|
234
221
|
readLock(fn, options) {
|
|
235
222
|
return web$1.mutexRunExclusive(this.readMutex, async () => {
|
|
@@ -237,11 +224,6 @@ class CapacitorSQLiteAdapter extends web$1.BaseObserver {
|
|
|
237
224
|
return await fn(this.generateLockContext(this.readConnection));
|
|
238
225
|
}, options);
|
|
239
226
|
}
|
|
240
|
-
readTransaction(fn, options) {
|
|
241
|
-
return this.readLock(async (ctx) => {
|
|
242
|
-
return this.internalTransaction(ctx, fn);
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
227
|
writeLock(fn, options) {
|
|
246
228
|
return web$1.mutexRunExclusive(this.writeMutex, async () => {
|
|
247
229
|
var _a;
|
|
@@ -262,11 +244,6 @@ class CapacitorSQLiteAdapter extends web$1.BaseObserver {
|
|
|
262
244
|
return result;
|
|
263
245
|
}, options);
|
|
264
246
|
}
|
|
265
|
-
writeTransaction(fn, options) {
|
|
266
|
-
return this.writeLock(async (ctx) => {
|
|
267
|
-
return this.internalTransaction(ctx, fn);
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
247
|
refreshSchema() {
|
|
271
248
|
return this.writeLock(async (writeTx) => {
|
|
272
249
|
return this.readLock(async (readTx) => {
|
|
@@ -276,49 +253,14 @@ class CapacitorSQLiteAdapter extends web$1.BaseObserver {
|
|
|
276
253
|
});
|
|
277
254
|
});
|
|
278
255
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}
|
|
288
|
-
async internalTransaction(ctx, fn) {
|
|
289
|
-
let finalized = false;
|
|
290
|
-
const commit = async () => {
|
|
291
|
-
if (finalized) {
|
|
292
|
-
return { rowsAffected: 0 };
|
|
293
|
-
}
|
|
294
|
-
finalized = true;
|
|
295
|
-
return ctx.execute('COMMIT');
|
|
296
|
-
};
|
|
297
|
-
const rollback = async () => {
|
|
298
|
-
if (finalized) {
|
|
299
|
-
return { rowsAffected: 0 };
|
|
300
|
-
}
|
|
301
|
-
finalized = true;
|
|
302
|
-
return ctx.execute('ROLLBACK');
|
|
303
|
-
};
|
|
304
|
-
try {
|
|
305
|
-
await ctx.execute('BEGIN');
|
|
306
|
-
const result = await fn(Object.assign(Object.assign({}, ctx), { commit,
|
|
307
|
-
rollback }));
|
|
308
|
-
await commit();
|
|
309
|
-
return result;
|
|
310
|
-
}
|
|
311
|
-
catch (ex) {
|
|
312
|
-
try {
|
|
313
|
-
await rollback();
|
|
314
|
-
}
|
|
315
|
-
catch (ex2) {
|
|
316
|
-
// In rare cases, a rollback may fail.
|
|
317
|
-
// Safe to ignore.
|
|
318
|
-
}
|
|
319
|
-
throw ex;
|
|
320
|
-
}
|
|
321
|
-
}
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* An implementation of {@link DBAdapter} using the Capacitor Community SQLite [plugin](https://github.com/capacitor-community/sqlite).
|
|
259
|
+
*
|
|
260
|
+
* @experimental
|
|
261
|
+
* @alpha This is currently experimental and may change without a major version bump.
|
|
262
|
+
*/
|
|
263
|
+
class CapacitorSQLiteAdapter extends web$1.DBAdapterDefaultMixin(CapacitorConnectionPool) {
|
|
322
264
|
}
|
|
323
265
|
|
|
324
266
|
const GLOBAL_MUTEX_STORE = new Map();
|
package/dist/plugin.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs","sources":["esm/plugin/PowerSyncCore.js","esm/plugin/PowerSyncPlugin.js","esm/adapter/CapacitorSQLiteOpenFactory.js","esm/adapter/CapacitorSQLiteAdapter.js","esm/sync/CapacitorSyncImplementation.js","esm/PowerSyncDatabase.js","esm/plugin/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nexport const PowerSyncCore = registerPlugin('PowerSync', {\n web: () => import('./web.js').then((m) => new m.PowerSyncWeb())\n});\n//# sourceMappingURL=PowerSyncCore.js.map","export const messageForErrorCode = (code) => {\n switch (code) {\n case 0:\n return 'Success';\n default:\n return `Extension registration failed with SQLite error code: ${code}`;\n }\n};\n//# sourceMappingURL=PowerSyncPlugin.js.map","import { CapacitorSQLiteAdapter } from './CapacitorSQLiteAdapter.js';\nvar SqliteSynchronous;\n(function (SqliteSynchronous) {\n SqliteSynchronous[\"normal\"] = \"NORMAL\";\n SqliteSynchronous[\"full\"] = \"FULL\";\n SqliteSynchronous[\"off\"] = \"OFF\";\n})(SqliteSynchronous || (SqliteSynchronous = {}));\nexport const DEFAULT_SQLITE_OPTIONS = {\n journalSizeLimit: 6 * 1024 * 1024,\n synchronous: SqliteSynchronous.normal,\n cacheSizeKb: 50 * 1024\n};\nexport class CapacitorSQLiteOpenFactory {\n constructor(options) {\n this.options = options;\n }\n openDB() {\n return new CapacitorSQLiteAdapter(this.options);\n }\n}\n//# sourceMappingURL=CapacitorSQLiteOpenFactory.js.map","import { CapacitorSQLite, SQLiteConnection } from '@capacitor-community/sqlite';\nimport { Capacitor } from '@capacitor/core';\nimport { BaseObserver, mutexRunExclusive } from '@powersync/web';\nimport { Mutex } from 'async-mutex';\nimport { PowerSyncCore } from '../plugin/PowerSyncCore.js';\nimport { messageForErrorCode } from '../plugin/PowerSyncPlugin.js';\nimport { DEFAULT_SQLITE_OPTIONS } from './CapacitorSQLiteOpenFactory.js';\n/**\n * Monitors the execution time of a query and logs it to the performance timeline.\n */\nasync function monitorQuery(sql, executor) {\n const start = performance.now();\n try {\n const r = await executor();\n performance.measure(`[SQL] ${sql}`, { start });\n return r;\n }\n catch (e) {\n performance.measure(`[SQL] [ERROR: ${e.message}] ${sql}`, { start });\n throw e;\n }\n}\n/**\n * An implementation of {@link DBAdapter} using the Capacitor Community SQLite [plugin](https://github.com/capacitor-community/sqlite).\n *\n * @experimental\n * @alpha This is currently experimental and may change without a major version bump.\n */\nexport class CapacitorSQLiteAdapter extends BaseObserver {\n constructor(options) {\n super();\n this.options = options;\n this._writeConnection = null;\n this._readConnection = null;\n this.writeMutex = new Mutex();\n this.readMutex = new Mutex();\n this.initializedPromise = this.init();\n }\n get writeConnection() {\n if (!this._writeConnection) {\n throw new Error('Init not completed yet');\n }\n return this._writeConnection;\n }\n get readConnection() {\n if (!this._readConnection) {\n throw new Error('Init not completed yet');\n }\n return this._readConnection;\n }\n get name() {\n return this.options.dbFilename;\n }\n async init() {\n const { responseCode: registrationResponseCode } = await PowerSyncCore.registerCore();\n if (registrationResponseCode != 0) {\n throw new Error(`Could not register PowerSync core extension: ${messageForErrorCode(registrationResponseCode)}`);\n }\n const sqlite = new SQLiteConnection(CapacitorSQLite);\n // It seems like the isConnection and retrieveConnection methods\n // only check a JS side map of connections.\n // On hot reload this JS cache can be cleared, while the connection\n // still exists natively. and `createConnection` will fail if it already exists.\n await sqlite.closeConnection(this.options.dbFilename, false).catch(() => { });\n await sqlite.closeConnection(this.options.dbFilename, true).catch(() => { });\n // TODO support encryption eventually\n this._writeConnection = await sqlite.createConnection(this.options.dbFilename, false, 'no-encryption', 1, false);\n this._readConnection = await sqlite.createConnection(this.options.dbFilename, false, 'no-encryption', 1, true);\n await this._writeConnection.open();\n const { cacheSizeKb, journalSizeLimit, synchronous } = Object.assign(Object.assign({}, DEFAULT_SQLITE_OPTIONS), this.options.sqliteOptions);\n await this.writeConnection.query('PRAGMA journal_mode = WAL');\n await this.writeConnection.query(`PRAGMA journal_size_limit = ${journalSizeLimit}`);\n await this.writeConnection.query(`PRAGMA temp_store = memory`);\n await this.writeConnection.query(`PRAGMA synchronous = ${synchronous}`);\n await this.writeConnection.query(`PRAGMA cache_size = -${cacheSizeKb}`);\n await this._readConnection.open();\n const platform = Capacitor.getPlatform();\n if (platform == 'android') {\n /**\n * SQLCipher for Android enables dynamic loading of extensions.\n * On iOS we use a static auto extension registration.\n */\n const extensionQuery = \"SELECT load_extension('libpowersync.so', 'sqlite3_powersync_init')\";\n await this.writeConnection.query(extensionQuery);\n await this.readConnection.query(extensionQuery);\n }\n await this.writeConnection.query(\"SELECT powersync_update_hooks('install')\");\n }\n async close() {\n await this.initializedPromise;\n await this.writeConnection.close();\n await this.readConnection.close();\n }\n generateLockContext(db) {\n const _query = async (query, params = []) => {\n var _a;\n const result = await db.query(query, params);\n const arrayResult = (_a = result.values) !== null && _a !== void 0 ? _a : [];\n return {\n rowsAffected: 0,\n rows: {\n _array: arrayResult,\n length: arrayResult.length,\n item: (idx) => arrayResult[idx]\n }\n };\n };\n const _execute = async (query, params = []) => {\n var _a, _b, _c, _d, _e, _f, _g, _h;\n const platform = Capacitor.getPlatform();\n if (db.getConnectionReadOnly()) {\n return _query(query, params);\n }\n if (platform == 'android') {\n // Android: use query for SELECT and executeSet for mutations\n // We cannot use `run` here for both cases.\n if (query.toLowerCase().trim().startsWith('select')) {\n return _query(query, params);\n }\n else {\n const result = await db.executeSet([{ statement: query, values: params }], false);\n return {\n insertId: (_a = result.changes) === null || _a === void 0 ? void 0 : _a.lastId,\n rowsAffected: (_c = (_b = result.changes) === null || _b === void 0 ? void 0 : _b.changes) !== null && _c !== void 0 ? _c : 0,\n rows: {\n _array: [],\n length: 0,\n item: () => null\n }\n };\n }\n }\n // iOS (and other platforms): use run(\"all\")\n const result = await db.run(query, params, false, 'all');\n const resultSet = (_e = (_d = result.changes) === null || _d === void 0 ? void 0 : _d.values) !== null && _e !== void 0 ? _e : [];\n return {\n insertId: (_f = result.changes) === null || _f === void 0 ? void 0 : _f.lastId,\n rowsAffected: (_h = (_g = result.changes) === null || _g === void 0 ? void 0 : _g.changes) !== null && _h !== void 0 ? _h : 0,\n rows: {\n _array: resultSet,\n length: resultSet.length,\n item: (idx) => resultSet[idx]\n }\n };\n };\n const execute = this.options.debugMode\n ? (sql, params) => monitorQuery(sql, () => _execute(sql, params))\n : _execute;\n const executeQuery = this.options.debugMode\n ? (sql, params) => monitorQuery(sql, () => _query(sql, params))\n : _query;\n const getAll = async (query, params) => {\n var _a, _b;\n const result = await executeQuery(query, params);\n return (_b = (_a = result.rows) === null || _a === void 0 ? void 0 : _a._array) !== null && _b !== void 0 ? _b : [];\n };\n const getOptional = async (query, params) => {\n const results = await getAll(query, params);\n return results.length > 0 ? results[0] : null;\n };\n const get = async (query, params) => {\n const result = await getOptional(query, params);\n if (!result) {\n throw new Error(`No results for query: ${query}`);\n }\n return result;\n };\n const executeRaw = async (query, params) => {\n var _a, _b;\n // This is a workaround, we don't support multiple columns of the same name\n const results = await execute(query, params);\n return (_b = (_a = results.rows) === null || _a === void 0 ? void 0 : _a._array.map((row) => Object.values(row))) !== null && _b !== void 0 ? _b : [];\n };\n return {\n getAll,\n getOptional,\n get,\n executeRaw,\n execute\n };\n }\n execute(query, params) {\n return this.writeLock((tx) => tx.execute(query, params));\n }\n executeRaw(query, params) {\n return this.writeLock((tx) => tx.executeRaw(query, params));\n }\n async executeBatch(query, params = []) {\n return this.writeLock(async (tx) => {\n var _a, _b, _c;\n let result = await this.writeConnection.executeSet(params.map((param) => ({\n statement: query,\n values: param\n })));\n return {\n rowsAffected: (_b = (_a = result.changes) === null || _a === void 0 ? void 0 : _a.changes) !== null && _b !== void 0 ? _b : 0,\n insertId: (_c = result.changes) === null || _c === void 0 ? void 0 : _c.lastId\n };\n });\n }\n readLock(fn, options) {\n return mutexRunExclusive(this.readMutex, async () => {\n await this.initializedPromise;\n return await fn(this.generateLockContext(this.readConnection));\n }, options);\n }\n readTransaction(fn, options) {\n return this.readLock(async (ctx) => {\n return this.internalTransaction(ctx, fn);\n });\n }\n writeLock(fn, options) {\n return mutexRunExclusive(this.writeMutex, async () => {\n var _a;\n await this.initializedPromise;\n const result = await fn(this.generateLockContext(this.writeConnection));\n // Fetch table updates\n const updates = await this.writeConnection.query(\"SELECT powersync_update_hooks('get') AS table_name\");\n const jsonUpdates = (_a = updates.values) === null || _a === void 0 ? void 0 : _a[0];\n if (!jsonUpdates || !jsonUpdates.table_name) {\n throw new Error('Could not fetch table updates');\n }\n const notification = {\n rawUpdates: [],\n tables: JSON.parse(jsonUpdates.table_name),\n groupedUpdates: {}\n };\n this.iterateListeners((l) => { var _a; return (_a = l.tablesUpdated) === null || _a === void 0 ? void 0 : _a.call(l, notification); });\n return result;\n }, options);\n }\n writeTransaction(fn, options) {\n return this.writeLock(async (ctx) => {\n return this.internalTransaction(ctx, fn);\n });\n }\n refreshSchema() {\n return this.writeLock(async (writeTx) => {\n return this.readLock(async (readTx) => {\n const updateQuery = `PRAGMA table_info('sqlite_master')`;\n await writeTx.get(updateQuery);\n await readTx.get(updateQuery);\n });\n });\n }\n getAll(sql, parameters) {\n return this.readLock((tx) => tx.getAll(sql, parameters));\n }\n getOptional(sql, parameters) {\n return this.readLock((tx) => tx.getOptional(sql, parameters));\n }\n get(sql, parameters) {\n return this.readLock((tx) => tx.get(sql, parameters));\n }\n async internalTransaction(ctx, fn) {\n let finalized = false;\n const commit = async () => {\n if (finalized) {\n return { rowsAffected: 0 };\n }\n finalized = true;\n return ctx.execute('COMMIT');\n };\n const rollback = async () => {\n if (finalized) {\n return { rowsAffected: 0 };\n }\n finalized = true;\n return ctx.execute('ROLLBACK');\n };\n try {\n await ctx.execute('BEGIN');\n const result = await fn(Object.assign(Object.assign({}, ctx), { commit,\n rollback }));\n await commit();\n return result;\n }\n catch (ex) {\n try {\n await rollback();\n }\n catch (ex2) {\n // In rare cases, a rollback may fail.\n // Safe to ignore.\n }\n throw ex;\n }\n }\n}\n//# sourceMappingURL=CapacitorSQLiteAdapter.js.map","import { AbstractStreamingSyncImplementation, LockType, mutexRunExclusive } from '@powersync/web';\nimport { Mutex } from 'async-mutex';\nconst GLOBAL_MUTEX_STORE = new Map();\n/**\n * Used to identify multiple instances of CapacitorStreamingSyncImplementation\n */\nlet _CAPACITOR_STREAMING_SYNC_SEQUENCE = 0;\nexport class CapacitorStreamingSyncImplementation extends AbstractStreamingSyncImplementation {\n constructor() {\n super(...arguments);\n // A unique ID for tacking this specific instance of CapacitorStreamingSyncImplementation\n this.instanceId = _CAPACITOR_STREAMING_SYNC_SEQUENCE++;\n }\n async dispose() {\n await super.dispose();\n // Clear up any global mutexes which aren't used anymore\n for (const mutexEntry of GLOBAL_MUTEX_STORE.entries()) {\n const [identifier, mutex] = mutexEntry;\n if (!mutex.tracking.has(this.instanceId)) {\n continue;\n }\n mutex.tracking.delete(this.instanceId);\n if (mutex.tracking.size == 0) {\n GLOBAL_MUTEX_STORE.delete(identifier);\n }\n }\n }\n async obtainLock(lockOptions) {\n // If we don't have an identifier for some reason (should not happen), we use a shared Mutex\n const { identifier: baseIdentifier = 'DEFAULT' } = this.options;\n if (!GLOBAL_MUTEX_STORE.has(baseIdentifier)) {\n GLOBAL_MUTEX_STORE.set(baseIdentifier, {\n tracking: new Set([this.instanceId]),\n locks: {\n [LockType.CRUD]: new Mutex(),\n [LockType.SYNC]: new Mutex()\n }\n });\n }\n const mutexRecord = GLOBAL_MUTEX_STORE.get(baseIdentifier);\n mutexRecord.tracking.add(this.instanceId);\n const mutex = mutexRecord.locks[lockOptions.type];\n return mutexRunExclusive(mutex, async () => {\n var _a;\n if ((_a = lockOptions.signal) === null || _a === void 0 ? void 0 : _a.aborted) {\n throw new Error('Aborted');\n }\n return await lockOptions.callback();\n });\n }\n}\n//# sourceMappingURL=CapacitorSyncImplementation.js.map","import { Capacitor } from '@capacitor/core';\nimport { MEMORY_TRIGGER_CLAIM_MANAGER, PowerSyncDatabase as WebPowerSyncDatabase, WebRemote } from '@powersync/web';\nimport { CapacitorSQLiteAdapter } from './adapter/CapacitorSQLiteAdapter.js';\nimport { CapacitorStreamingSyncImplementation } from './sync/CapacitorSyncImplementation.js';\n/**\n * PowerSyncDatabase class for managing database connections and sync implementations.\n * This extends the WebPowerSyncDatabase to provide platform-specific implementations\n * for Capacitor environments (iOS and Android).\n *\n * @experimental\n * @alpha\n */\nexport class PowerSyncDatabase extends WebPowerSyncDatabase {\n get isNativeCapacitorPlatform() {\n const platform = Capacitor.getPlatform();\n return platform == 'ios' || platform == 'android';\n }\n openDBAdapter(options) {\n var _a, _b, _c;\n const platform = Capacitor.getPlatform();\n if (platform == 'ios' || platform == 'android') {\n if (options.database.dbLocation) {\n (_a = options.logger) === null || _a === void 0 ? void 0 : _a.warn(`\n dbLocation is ignored on iOS and Android platforms. \n The database directory can be configured in the Capacitor project.\n See https://github.com/capacitor-community/sqlite?tab=readme-ov-file#installation`);\n }\n (_b = options.logger) === null || _b === void 0 ? void 0 : _b.debug(`Using CapacitorSQLiteAdapter for platform: ${platform}`);\n return new CapacitorSQLiteAdapter(Object.assign({}, options.database));\n }\n else {\n (_c = options.logger) === null || _c === void 0 ? void 0 : _c.debug(`Using default web adapter for web platform`);\n return super.openDBAdapter(options);\n }\n }\n generateTriggerManagerConfig() {\n const config = super.generateTriggerManagerConfig();\n if (this.isNativeCapacitorPlatform) {\n /**\n * We usually only ever have a single tab for capacitor.\n * Avoiding navigator locks allows insecure contexts (during development).\n */\n config.claimManager = MEMORY_TRIGGER_CLAIM_MANAGER;\n }\n return config;\n }\n runExclusive(cb) {\n if (this.isNativeCapacitorPlatform) {\n // Use mutex for mobile platforms.\n // This is mainly for testing purposes since navigator.locks require secure contexts.\n return this.runExclusiveMutex.runExclusive(cb);\n }\n else {\n // Use navigator.locks for web platform\n return super.runExclusive(cb);\n }\n }\n generateSyncStreamImplementation(connector, options) {\n var _a;\n if (this.isNativeCapacitorPlatform) {\n // We don't want to support multi-tab on mobile platforms.\n // We technically can, but it's not a common use case and requires additional work/testing.\n this.logger.debug(`Using Capacitor sync implementation`);\n if ((_a = this.options.flags) === null || _a === void 0 ? void 0 : _a.enableMultiTabs) {\n this.logger.warn(`enableMultiTabs is not supported on Capacitor mobile platforms. Ignoring the flag.`);\n }\n const remote = new WebRemote(connector, this.logger);\n return new CapacitorStreamingSyncImplementation(Object.assign(Object.assign({}, this.options), { retryDelayMs: options.retryDelayMs, crudUploadThrottleMs: options.crudUploadThrottleMs, adapter: this.bucketStorageAdapter, remote, uploadCrud: async () => {\n await this.waitForReady();\n await connector.uploadData(this);\n }, identifier: this.database.name, logger: this.logger, subscriptions: options.subscriptions }));\n }\n else {\n this.logger.debug(`Using default web sync implementation for web platform`);\n return super.generateSyncStreamImplementation(connector, options);\n }\n }\n}\n//# sourceMappingURL=PowerSyncDatabase.js.map","import { WebPlugin } from '@capacitor/core';\nexport class PowerSyncWeb extends WebPlugin {\n async registerCore() {\n throw new Error('This code path is not supported on web.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","BaseObserver","Mutex","sqlite","SQLiteConnection","CapacitorSQLite","Capacitor","mutexRunExclusive","AbstractStreamingSyncImplementation","LockType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AAyC,CAAC;AAClE,IAAI;AACJ;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"plugin.cjs","sources":["esm/plugin/PowerSyncCore.js","esm/plugin/PowerSyncPlugin.js","esm/adapter/CapacitorSQLiteOpenFactory.js","esm/adapter/CapacitorSQLiteAdapter.js","esm/sync/CapacitorSyncImplementation.js","esm/PowerSyncDatabase.js","esm/plugin/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nexport const PowerSyncCore = registerPlugin('PowerSync', {\n web: () => import('./web.js').then((m) => new m.PowerSyncWeb())\n});\n//# sourceMappingURL=PowerSyncCore.js.map","export const messageForErrorCode = (code) => {\n switch (code) {\n case 0:\n return 'Success';\n default:\n return `Extension registration failed with SQLite error code: ${code}`;\n }\n};\n//# sourceMappingURL=PowerSyncPlugin.js.map","import { CapacitorSQLiteAdapter } from './CapacitorSQLiteAdapter.js';\nvar SqliteSynchronous;\n(function (SqliteSynchronous) {\n SqliteSynchronous[\"normal\"] = \"NORMAL\";\n SqliteSynchronous[\"full\"] = \"FULL\";\n SqliteSynchronous[\"off\"] = \"OFF\";\n})(SqliteSynchronous || (SqliteSynchronous = {}));\nexport const DEFAULT_SQLITE_OPTIONS = {\n journalSizeLimit: 6 * 1024 * 1024,\n synchronous: SqliteSynchronous.normal,\n cacheSizeKb: 50 * 1024\n};\nexport class CapacitorSQLiteOpenFactory {\n constructor(options) {\n this.options = options;\n }\n openDB() {\n return new CapacitorSQLiteAdapter(this.options);\n }\n}\n//# sourceMappingURL=CapacitorSQLiteOpenFactory.js.map","import { CapacitorSQLite, SQLiteConnection } from '@capacitor-community/sqlite';\nimport { Capacitor } from '@capacitor/core';\nimport { BaseObserver, DBAdapterDefaultMixin, mutexRunExclusive } from '@powersync/web';\nimport { Mutex } from 'async-mutex';\nimport { PowerSyncCore } from '../plugin/PowerSyncCore.js';\nimport { messageForErrorCode } from '../plugin/PowerSyncPlugin.js';\nimport { DEFAULT_SQLITE_OPTIONS } from './CapacitorSQLiteOpenFactory.js';\n/**\n * Monitors the execution time of a query and logs it to the performance timeline.\n */\nasync function monitorQuery(sql, executor) {\n const start = performance.now();\n try {\n const r = await executor();\n performance.measure(`[SQL] ${sql}`, { start });\n return r;\n }\n catch (e) {\n performance.measure(`[SQL] [ERROR: ${e.message}] ${sql}`, { start });\n throw e;\n }\n}\nclass CapacitorConnectionPool extends BaseObserver {\n constructor(options) {\n super();\n this.options = options;\n this._writeConnection = null;\n this._readConnection = null;\n this.writeMutex = new Mutex();\n this.readMutex = new Mutex();\n this.initializedPromise = this.init();\n }\n get writeConnection() {\n if (!this._writeConnection) {\n throw new Error('Init not completed yet');\n }\n return this._writeConnection;\n }\n get readConnection() {\n if (!this._readConnection) {\n throw new Error('Init not completed yet');\n }\n return this._readConnection;\n }\n get name() {\n return this.options.dbFilename;\n }\n async init() {\n const { responseCode: registrationResponseCode } = await PowerSyncCore.registerCore();\n if (registrationResponseCode != 0) {\n throw new Error(`Could not register PowerSync core extension: ${messageForErrorCode(registrationResponseCode)}`);\n }\n const sqlite = new SQLiteConnection(CapacitorSQLite);\n // It seems like the isConnection and retrieveConnection methods\n // only check a JS side map of connections.\n // On hot reload this JS cache can be cleared, while the connection\n // still exists natively. and `createConnection` will fail if it already exists.\n await sqlite.closeConnection(this.options.dbFilename, false).catch(() => { });\n await sqlite.closeConnection(this.options.dbFilename, true).catch(() => { });\n // TODO support encryption eventually\n this._writeConnection = await sqlite.createConnection(this.options.dbFilename, false, 'no-encryption', 1, false);\n this._readConnection = await sqlite.createConnection(this.options.dbFilename, false, 'no-encryption', 1, true);\n await this._writeConnection.open();\n const { cacheSizeKb, journalSizeLimit, synchronous } = Object.assign(Object.assign({}, DEFAULT_SQLITE_OPTIONS), this.options.sqliteOptions);\n await this.writeConnection.query('PRAGMA journal_mode = WAL');\n await this.writeConnection.query(`PRAGMA journal_size_limit = ${journalSizeLimit}`);\n await this.writeConnection.query(`PRAGMA temp_store = memory`);\n await this.writeConnection.query(`PRAGMA synchronous = ${synchronous}`);\n await this.writeConnection.query(`PRAGMA cache_size = -${cacheSizeKb}`);\n await this._readConnection.open();\n const platform = Capacitor.getPlatform();\n if (platform == 'android') {\n /**\n * SQLCipher for Android enables dynamic loading of extensions.\n * On iOS we use a static auto extension registration.\n */\n const extensionQuery = \"SELECT load_extension('libpowersync.so', 'sqlite3_powersync_init')\";\n await this.writeConnection.query(extensionQuery);\n await this.readConnection.query(extensionQuery);\n }\n await this.writeConnection.query(\"SELECT powersync_update_hooks('install')\");\n }\n async close() {\n await this.initializedPromise;\n await this.writeConnection.close();\n await this.readConnection.close();\n }\n generateLockContext(db) {\n const _query = async (query, params = []) => {\n var _a;\n const result = await db.query(query, params);\n const arrayResult = (_a = result.values) !== null && _a !== void 0 ? _a : [];\n return {\n rowsAffected: 0,\n rows: {\n _array: arrayResult,\n length: arrayResult.length,\n item: (idx) => arrayResult[idx]\n }\n };\n };\n const _execute = async (query, params = []) => {\n var _a, _b, _c, _d, _e, _f, _g, _h;\n const platform = Capacitor.getPlatform();\n if (db.getConnectionReadOnly()) {\n return _query(query, params);\n }\n if (platform == 'android') {\n // Android: use query for SELECT and executeSet for mutations\n // We cannot use `run` here for both cases.\n if (query.toLowerCase().trim().startsWith('select')) {\n return _query(query, params);\n }\n else {\n const result = await db.executeSet([{ statement: query, values: params }], false);\n return {\n insertId: (_a = result.changes) === null || _a === void 0 ? void 0 : _a.lastId,\n rowsAffected: (_c = (_b = result.changes) === null || _b === void 0 ? void 0 : _b.changes) !== null && _c !== void 0 ? _c : 0,\n rows: {\n _array: [],\n length: 0,\n item: () => null\n }\n };\n }\n }\n // iOS (and other platforms): use run(\"all\")\n const result = await db.run(query, params, false, 'all');\n const resultSet = (_e = (_d = result.changes) === null || _d === void 0 ? void 0 : _d.values) !== null && _e !== void 0 ? _e : [];\n return {\n insertId: (_f = result.changes) === null || _f === void 0 ? void 0 : _f.lastId,\n rowsAffected: (_h = (_g = result.changes) === null || _g === void 0 ? void 0 : _g.changes) !== null && _h !== void 0 ? _h : 0,\n rows: {\n _array: resultSet,\n length: resultSet.length,\n item: (idx) => resultSet[idx]\n }\n };\n };\n const execute = this.options.debugMode\n ? (sql, params) => monitorQuery(sql, () => _execute(sql, params))\n : _execute;\n const executeQuery = this.options.debugMode\n ? (sql, params) => monitorQuery(sql, () => _query(sql, params))\n : _query;\n const getAll = async (query, params) => {\n var _a, _b;\n const result = await executeQuery(query, params);\n return (_b = (_a = result.rows) === null || _a === void 0 ? void 0 : _a._array) !== null && _b !== void 0 ? _b : [];\n };\n const getOptional = async (query, params) => {\n const results = await getAll(query, params);\n return results.length > 0 ? results[0] : null;\n };\n const get = async (query, params) => {\n const result = await getOptional(query, params);\n if (!result) {\n throw new Error(`No results for query: ${query}`);\n }\n return result;\n };\n const executeRaw = async (query, params) => {\n var _a, _b;\n // This is a workaround, we don't support multiple columns of the same name\n const results = await execute(query, params);\n return (_b = (_a = results.rows) === null || _a === void 0 ? void 0 : _a._array.map((row) => Object.values(row))) !== null && _b !== void 0 ? _b : [];\n };\n const executeBatch = async (query, params = []) => {\n var _a, _b, _c;\n let result = await db.executeSet(params.map((param) => ({\n statement: query,\n values: param\n })));\n return {\n rowsAffected: (_b = (_a = result.changes) === null || _a === void 0 ? void 0 : _a.changes) !== null && _b !== void 0 ? _b : 0,\n insertId: (_c = result.changes) === null || _c === void 0 ? void 0 : _c.lastId\n };\n };\n return {\n getAll,\n getOptional,\n get,\n executeRaw,\n execute,\n executeBatch\n };\n }\n readLock(fn, options) {\n return mutexRunExclusive(this.readMutex, async () => {\n await this.initializedPromise;\n return await fn(this.generateLockContext(this.readConnection));\n }, options);\n }\n writeLock(fn, options) {\n return mutexRunExclusive(this.writeMutex, async () => {\n var _a;\n await this.initializedPromise;\n const result = await fn(this.generateLockContext(this.writeConnection));\n // Fetch table updates\n const updates = await this.writeConnection.query(\"SELECT powersync_update_hooks('get') AS table_name\");\n const jsonUpdates = (_a = updates.values) === null || _a === void 0 ? void 0 : _a[0];\n if (!jsonUpdates || !jsonUpdates.table_name) {\n throw new Error('Could not fetch table updates');\n }\n const notification = {\n rawUpdates: [],\n tables: JSON.parse(jsonUpdates.table_name),\n groupedUpdates: {}\n };\n this.iterateListeners((l) => { var _a; return (_a = l.tablesUpdated) === null || _a === void 0 ? void 0 : _a.call(l, notification); });\n return result;\n }, options);\n }\n refreshSchema() {\n return this.writeLock(async (writeTx) => {\n return this.readLock(async (readTx) => {\n const updateQuery = `PRAGMA table_info('sqlite_master')`;\n await writeTx.get(updateQuery);\n await readTx.get(updateQuery);\n });\n });\n }\n}\n/**\n * An implementation of {@link DBAdapter} using the Capacitor Community SQLite [plugin](https://github.com/capacitor-community/sqlite).\n *\n * @experimental\n * @alpha This is currently experimental and may change without a major version bump.\n */\nexport class CapacitorSQLiteAdapter extends DBAdapterDefaultMixin(CapacitorConnectionPool) {\n}\n//# sourceMappingURL=CapacitorSQLiteAdapter.js.map","import { AbstractStreamingSyncImplementation, LockType, mutexRunExclusive } from '@powersync/web';\nimport { Mutex } from 'async-mutex';\nconst GLOBAL_MUTEX_STORE = new Map();\n/**\n * Used to identify multiple instances of CapacitorStreamingSyncImplementation\n */\nlet _CAPACITOR_STREAMING_SYNC_SEQUENCE = 0;\nexport class CapacitorStreamingSyncImplementation extends AbstractStreamingSyncImplementation {\n constructor() {\n super(...arguments);\n // A unique ID for tacking this specific instance of CapacitorStreamingSyncImplementation\n this.instanceId = _CAPACITOR_STREAMING_SYNC_SEQUENCE++;\n }\n async dispose() {\n await super.dispose();\n // Clear up any global mutexes which aren't used anymore\n for (const mutexEntry of GLOBAL_MUTEX_STORE.entries()) {\n const [identifier, mutex] = mutexEntry;\n if (!mutex.tracking.has(this.instanceId)) {\n continue;\n }\n mutex.tracking.delete(this.instanceId);\n if (mutex.tracking.size == 0) {\n GLOBAL_MUTEX_STORE.delete(identifier);\n }\n }\n }\n async obtainLock(lockOptions) {\n // If we don't have an identifier for some reason (should not happen), we use a shared Mutex\n const { identifier: baseIdentifier = 'DEFAULT' } = this.options;\n if (!GLOBAL_MUTEX_STORE.has(baseIdentifier)) {\n GLOBAL_MUTEX_STORE.set(baseIdentifier, {\n tracking: new Set([this.instanceId]),\n locks: {\n [LockType.CRUD]: new Mutex(),\n [LockType.SYNC]: new Mutex()\n }\n });\n }\n const mutexRecord = GLOBAL_MUTEX_STORE.get(baseIdentifier);\n mutexRecord.tracking.add(this.instanceId);\n const mutex = mutexRecord.locks[lockOptions.type];\n return mutexRunExclusive(mutex, async () => {\n var _a;\n if ((_a = lockOptions.signal) === null || _a === void 0 ? void 0 : _a.aborted) {\n throw new Error('Aborted');\n }\n return await lockOptions.callback();\n });\n }\n}\n//# sourceMappingURL=CapacitorSyncImplementation.js.map","import { Capacitor } from '@capacitor/core';\nimport { MEMORY_TRIGGER_CLAIM_MANAGER, PowerSyncDatabase as WebPowerSyncDatabase, WebRemote } from '@powersync/web';\nimport { CapacitorSQLiteAdapter } from './adapter/CapacitorSQLiteAdapter.js';\nimport { CapacitorStreamingSyncImplementation } from './sync/CapacitorSyncImplementation.js';\n/**\n * PowerSyncDatabase class for managing database connections and sync implementations.\n * This extends the WebPowerSyncDatabase to provide platform-specific implementations\n * for Capacitor environments (iOS and Android).\n *\n * @experimental\n * @alpha\n */\nexport class PowerSyncDatabase extends WebPowerSyncDatabase {\n get isNativeCapacitorPlatform() {\n const platform = Capacitor.getPlatform();\n return platform == 'ios' || platform == 'android';\n }\n openDBAdapter(options) {\n var _a, _b, _c;\n const platform = Capacitor.getPlatform();\n if (platform == 'ios' || platform == 'android') {\n if (options.database.dbLocation) {\n (_a = options.logger) === null || _a === void 0 ? void 0 : _a.warn(`\n dbLocation is ignored on iOS and Android platforms. \n The database directory can be configured in the Capacitor project.\n See https://github.com/capacitor-community/sqlite?tab=readme-ov-file#installation`);\n }\n (_b = options.logger) === null || _b === void 0 ? void 0 : _b.debug(`Using CapacitorSQLiteAdapter for platform: ${platform}`);\n return new CapacitorSQLiteAdapter(Object.assign({}, options.database));\n }\n else {\n (_c = options.logger) === null || _c === void 0 ? void 0 : _c.debug(`Using default web adapter for web platform`);\n return super.openDBAdapter(options);\n }\n }\n generateTriggerManagerConfig() {\n const config = super.generateTriggerManagerConfig();\n if (this.isNativeCapacitorPlatform) {\n /**\n * We usually only ever have a single tab for capacitor.\n * Avoiding navigator locks allows insecure contexts (during development).\n */\n config.claimManager = MEMORY_TRIGGER_CLAIM_MANAGER;\n }\n return config;\n }\n runExclusive(cb) {\n if (this.isNativeCapacitorPlatform) {\n // Use mutex for mobile platforms.\n // This is mainly for testing purposes since navigator.locks require secure contexts.\n return this.runExclusiveMutex.runExclusive(cb);\n }\n else {\n // Use navigator.locks for web platform\n return super.runExclusive(cb);\n }\n }\n generateSyncStreamImplementation(connector, options) {\n var _a;\n if (this.isNativeCapacitorPlatform) {\n // We don't want to support multi-tab on mobile platforms.\n // We technically can, but it's not a common use case and requires additional work/testing.\n this.logger.debug(`Using Capacitor sync implementation`);\n if ((_a = this.options.flags) === null || _a === void 0 ? void 0 : _a.enableMultiTabs) {\n this.logger.warn(`enableMultiTabs is not supported on Capacitor mobile platforms. Ignoring the flag.`);\n }\n const remote = new WebRemote(connector, this.logger);\n return new CapacitorStreamingSyncImplementation(Object.assign(Object.assign({}, this.options), { retryDelayMs: options.retryDelayMs, crudUploadThrottleMs: options.crudUploadThrottleMs, adapter: this.bucketStorageAdapter, remote, uploadCrud: async () => {\n await this.waitForReady();\n await connector.uploadData(this);\n }, identifier: this.database.name, logger: this.logger, subscriptions: options.subscriptions }));\n }\n else {\n this.logger.debug(`Using default web sync implementation for web platform`);\n return super.generateSyncStreamImplementation(connector, options);\n }\n }\n}\n//# sourceMappingURL=PowerSyncDatabase.js.map","import { WebPlugin } from '@capacitor/core';\nexport class PowerSyncWeb extends WebPlugin {\n async registerCore() {\n throw new Error('This code path is not supported on web.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","BaseObserver","Mutex","sqlite","SQLiteConnection","CapacitorSQLite","Capacitor","mutexRunExclusive","DBAdap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Y,SAASC,cAAS,CAAC;AAC5C,IAAI,MAAM,YAAY,GAAG;AACzB,QAAQ,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC;AAClE,IAAI;AACJ;;;;;;;;;;;"}
|
package/dist/plugin.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SQLiteDBConnection } from '@capacitor-community/sqlite';
|
|
2
|
-
import { SQLOpenOptions, SQLOpenFactory, DBAdapter,
|
|
2
|
+
import { SQLOpenOptions, SQLOpenFactory, DBAdapter, Transaction, DBLockOptions, QueryResult, LockContext, DBAdapterListener, BaseObserver, ConnectionPool, PowerSyncDatabase as PowerSyncDatabase$1, WebPowerSyncDatabaseOptionsWithSettings, TriggerManagerConfig, PowerSyncBackendConnector, RequiredAdditionalConnectionOptions, StreamingSyncImplementation } from '@powersync/web';
|
|
3
3
|
import { Mutex } from 'async-mutex';
|
|
4
4
|
|
|
5
5
|
declare enum SqliteSynchronous {
|
|
@@ -35,13 +35,7 @@ declare class CapacitorSQLiteOpenFactory implements SQLOpenFactory {
|
|
|
35
35
|
openDB(): DBAdapter;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
* An implementation of {@link DBAdapter} using the Capacitor Community SQLite [plugin](https://github.com/capacitor-community/sqlite).
|
|
40
|
-
*
|
|
41
|
-
* @experimental
|
|
42
|
-
* @alpha This is currently experimental and may change without a major version bump.
|
|
43
|
-
*/
|
|
44
|
-
declare class CapacitorSQLiteAdapter extends BaseObserver<DBAdapterListener> implements DBAdapter {
|
|
38
|
+
declare class CapacitorConnectionPool extends BaseObserver<DBAdapterListener> implements ConnectionPool {
|
|
45
39
|
protected options: CapacitorSQLiteOpenFactoryOptions;
|
|
46
40
|
protected _writeConnection: SQLiteDBConnection | null;
|
|
47
41
|
protected _readConnection: SQLiteDBConnection | null;
|
|
@@ -55,18 +49,33 @@ declare class CapacitorSQLiteAdapter extends BaseObserver<DBAdapterListener> imp
|
|
|
55
49
|
private init;
|
|
56
50
|
close(): Promise<void>;
|
|
57
51
|
protected generateLockContext(db: SQLiteDBConnection): LockContext;
|
|
58
|
-
execute(query: string, params?: any[]): Promise<QueryResult>;
|
|
59
|
-
executeRaw(query: string, params?: any[]): Promise<any[][]>;
|
|
60
|
-
executeBatch(query: string, params?: any[][]): Promise<QueryResult>;
|
|
61
52
|
readLock<T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions): Promise<T>;
|
|
62
|
-
readTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions): Promise<T>;
|
|
63
53
|
writeLock<T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions): Promise<T>;
|
|
64
|
-
writeTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions): Promise<T>;
|
|
65
54
|
refreshSchema(): Promise<void>;
|
|
55
|
+
}
|
|
56
|
+
declare const CapacitorSQLiteAdapter_base: (new (...args: any[]) => {
|
|
57
|
+
readTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions): Promise<T>;
|
|
58
|
+
writeTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions): Promise<T>;
|
|
66
59
|
getAll<T>(sql: string, parameters?: any[]): Promise<T[]>;
|
|
67
60
|
getOptional<T>(sql: string, parameters?: any[]): Promise<T | null>;
|
|
68
61
|
get<T>(sql: string, parameters?: any[]): Promise<T>;
|
|
69
|
-
|
|
62
|
+
execute(query: string, params?: any[]): Promise<QueryResult>;
|
|
63
|
+
executeRaw(query: string, params?: any[]): Promise<any[][]>;
|
|
64
|
+
executeBatch(query: string, params?: any[][]): Promise<QueryResult>;
|
|
65
|
+
name: string;
|
|
66
|
+
close: () => void | Promise<void>;
|
|
67
|
+
readLock: <T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions) => Promise<T>;
|
|
68
|
+
writeLock: <T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions) => Promise<T>;
|
|
69
|
+
refreshSchema: () => Promise<void>;
|
|
70
|
+
registerListener(listener: Partial<DBAdapterListener>): () => void;
|
|
71
|
+
}) & typeof CapacitorConnectionPool;
|
|
72
|
+
/**
|
|
73
|
+
* An implementation of {@link DBAdapter} using the Capacitor Community SQLite [plugin](https://github.com/capacitor-community/sqlite).
|
|
74
|
+
*
|
|
75
|
+
* @experimental
|
|
76
|
+
* @alpha This is currently experimental and may change without a major version bump.
|
|
77
|
+
*/
|
|
78
|
+
declare class CapacitorSQLiteAdapter extends CapacitorSQLiteAdapter_base {
|
|
70
79
|
}
|
|
71
80
|
|
|
72
81
|
/**
|
package/dist/plugin.js
CHANGED
|
@@ -49,13 +49,7 @@ var capacitorPowerSync = (function (exports, sqlite, core, web$1, asyncMutex) {
|
|
|
49
49
|
throw e;
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
* An implementation of {@link DBAdapter} using the Capacitor Community SQLite [plugin](https://github.com/capacitor-community/sqlite).
|
|
54
|
-
*
|
|
55
|
-
* @experimental
|
|
56
|
-
* @alpha This is currently experimental and may change without a major version bump.
|
|
57
|
-
*/
|
|
58
|
-
class CapacitorSQLiteAdapter extends web$1.BaseObserver {
|
|
52
|
+
class CapacitorConnectionPool extends web$1.BaseObserver {
|
|
59
53
|
constructor(options) {
|
|
60
54
|
super();
|
|
61
55
|
this.options = options;
|
|
@@ -200,24 +194,9 @@ var capacitorPowerSync = (function (exports, sqlite, core, web$1, asyncMutex) {
|
|
|
200
194
|
const results = await execute(query, params);
|
|
201
195
|
return (_b = (_a = results.rows) === null || _a === void 0 ? void 0 : _a._array.map((row) => Object.values(row))) !== null && _b !== void 0 ? _b : [];
|
|
202
196
|
};
|
|
203
|
-
|
|
204
|
-
getAll,
|
|
205
|
-
getOptional,
|
|
206
|
-
get,
|
|
207
|
-
executeRaw,
|
|
208
|
-
execute
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
execute(query, params) {
|
|
212
|
-
return this.writeLock((tx) => tx.execute(query, params));
|
|
213
|
-
}
|
|
214
|
-
executeRaw(query, params) {
|
|
215
|
-
return this.writeLock((tx) => tx.executeRaw(query, params));
|
|
216
|
-
}
|
|
217
|
-
async executeBatch(query, params = []) {
|
|
218
|
-
return this.writeLock(async (tx) => {
|
|
197
|
+
const executeBatch = async (query, params = []) => {
|
|
219
198
|
var _a, _b, _c;
|
|
220
|
-
let result = await
|
|
199
|
+
let result = await db.executeSet(params.map((param) => ({
|
|
221
200
|
statement: query,
|
|
222
201
|
values: param
|
|
223
202
|
})));
|
|
@@ -225,7 +204,15 @@ var capacitorPowerSync = (function (exports, sqlite, core, web$1, asyncMutex) {
|
|
|
225
204
|
rowsAffected: (_b = (_a = result.changes) === null || _a === void 0 ? void 0 : _a.changes) !== null && _b !== void 0 ? _b : 0,
|
|
226
205
|
insertId: (_c = result.changes) === null || _c === void 0 ? void 0 : _c.lastId
|
|
227
206
|
};
|
|
228
|
-
}
|
|
207
|
+
};
|
|
208
|
+
return {
|
|
209
|
+
getAll,
|
|
210
|
+
getOptional,
|
|
211
|
+
get,
|
|
212
|
+
executeRaw,
|
|
213
|
+
execute,
|
|
214
|
+
executeBatch
|
|
215
|
+
};
|
|
229
216
|
}
|
|
230
217
|
readLock(fn, options) {
|
|
231
218
|
return web$1.mutexRunExclusive(this.readMutex, async () => {
|
|
@@ -233,11 +220,6 @@ var capacitorPowerSync = (function (exports, sqlite, core, web$1, asyncMutex) {
|
|
|
233
220
|
return await fn(this.generateLockContext(this.readConnection));
|
|
234
221
|
}, options);
|
|
235
222
|
}
|
|
236
|
-
readTransaction(fn, options) {
|
|
237
|
-
return this.readLock(async (ctx) => {
|
|
238
|
-
return this.internalTransaction(ctx, fn);
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
223
|
writeLock(fn, options) {
|
|
242
224
|
return web$1.mutexRunExclusive(this.writeMutex, async () => {
|
|
243
225
|
var _a;
|
|
@@ -258,11 +240,6 @@ var capacitorPowerSync = (function (exports, sqlite, core, web$1, asyncMutex) {
|
|
|
258
240
|
return result;
|
|
259
241
|
}, options);
|
|
260
242
|
}
|
|
261
|
-
writeTransaction(fn, options) {
|
|
262
|
-
return this.writeLock(async (ctx) => {
|
|
263
|
-
return this.internalTransaction(ctx, fn);
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
243
|
refreshSchema() {
|
|
267
244
|
return this.writeLock(async (writeTx) => {
|
|
268
245
|
return this.readLock(async (readTx) => {
|
|
@@ -272,49 +249,14 @@ var capacitorPowerSync = (function (exports, sqlite, core, web$1, asyncMutex) {
|
|
|
272
249
|
});
|
|
273
250
|
});
|
|
274
251
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
}
|
|
284
|
-
async internalTransaction(ctx, fn) {
|
|
285
|
-
let finalized = false;
|
|
286
|
-
const commit = async () => {
|
|
287
|
-
if (finalized) {
|
|
288
|
-
return { rowsAffected: 0 };
|
|
289
|
-
}
|
|
290
|
-
finalized = true;
|
|
291
|
-
return ctx.execute('COMMIT');
|
|
292
|
-
};
|
|
293
|
-
const rollback = async () => {
|
|
294
|
-
if (finalized) {
|
|
295
|
-
return { rowsAffected: 0 };
|
|
296
|
-
}
|
|
297
|
-
finalized = true;
|
|
298
|
-
return ctx.execute('ROLLBACK');
|
|
299
|
-
};
|
|
300
|
-
try {
|
|
301
|
-
await ctx.execute('BEGIN');
|
|
302
|
-
const result = await fn(Object.assign(Object.assign({}, ctx), { commit,
|
|
303
|
-
rollback }));
|
|
304
|
-
await commit();
|
|
305
|
-
return result;
|
|
306
|
-
}
|
|
307
|
-
catch (ex) {
|
|
308
|
-
try {
|
|
309
|
-
await rollback();
|
|
310
|
-
}
|
|
311
|
-
catch (ex2) {
|
|
312
|
-
// In rare cases, a rollback may fail.
|
|
313
|
-
// Safe to ignore.
|
|
314
|
-
}
|
|
315
|
-
throw ex;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* An implementation of {@link DBAdapter} using the Capacitor Community SQLite [plugin](https://github.com/capacitor-community/sqlite).
|
|
255
|
+
*
|
|
256
|
+
* @experimental
|
|
257
|
+
* @alpha This is currently experimental and may change without a major version bump.
|
|
258
|
+
*/
|
|
259
|
+
class CapacitorSQLiteAdapter extends web$1.DBAdapterDefaultMixin(CapacitorConnectionPool) {
|
|
318
260
|
}
|
|
319
261
|
|
|
320
262
|
const GLOBAL_MUTEX_STORE = new Map();
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["esm/plugin/PowerSyncCore.js","esm/plugin/PowerSyncPlugin.js","esm/adapter/CapacitorSQLiteOpenFactory.js","esm/adapter/CapacitorSQLiteAdapter.js","esm/sync/CapacitorSyncImplementation.js","esm/PowerSyncDatabase.js","esm/plugin/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nexport const PowerSyncCore = registerPlugin('PowerSync', {\n web: () => import('./web.js').then((m) => new m.PowerSyncWeb())\n});\n//# sourceMappingURL=PowerSyncCore.js.map","export const messageForErrorCode = (code) => {\n switch (code) {\n case 0:\n return 'Success';\n default:\n return `Extension registration failed with SQLite error code: ${code}`;\n }\n};\n//# sourceMappingURL=PowerSyncPlugin.js.map","import { CapacitorSQLiteAdapter } from './CapacitorSQLiteAdapter.js';\nvar SqliteSynchronous;\n(function (SqliteSynchronous) {\n SqliteSynchronous[\"normal\"] = \"NORMAL\";\n SqliteSynchronous[\"full\"] = \"FULL\";\n SqliteSynchronous[\"off\"] = \"OFF\";\n})(SqliteSynchronous || (SqliteSynchronous = {}));\nexport const DEFAULT_SQLITE_OPTIONS = {\n journalSizeLimit: 6 * 1024 * 1024,\n synchronous: SqliteSynchronous.normal,\n cacheSizeKb: 50 * 1024\n};\nexport class CapacitorSQLiteOpenFactory {\n constructor(options) {\n this.options = options;\n }\n openDB() {\n return new CapacitorSQLiteAdapter(this.options);\n }\n}\n//# sourceMappingURL=CapacitorSQLiteOpenFactory.js.map","import { CapacitorSQLite, SQLiteConnection } from '@capacitor-community/sqlite';\nimport { Capacitor } from '@capacitor/core';\nimport { BaseObserver, mutexRunExclusive } from '@powersync/web';\nimport { Mutex } from 'async-mutex';\nimport { PowerSyncCore } from '../plugin/PowerSyncCore.js';\nimport { messageForErrorCode } from '../plugin/PowerSyncPlugin.js';\nimport { DEFAULT_SQLITE_OPTIONS } from './CapacitorSQLiteOpenFactory.js';\n/**\n * Monitors the execution time of a query and logs it to the performance timeline.\n */\nasync function monitorQuery(sql, executor) {\n const start = performance.now();\n try {\n const r = await executor();\n performance.measure(`[SQL] ${sql}`, { start });\n return r;\n }\n catch (e) {\n performance.measure(`[SQL] [ERROR: ${e.message}] ${sql}`, { start });\n throw e;\n }\n}\n/**\n * An implementation of {@link DBAdapter} using the Capacitor Community SQLite [plugin](https://github.com/capacitor-community/sqlite).\n *\n * @experimental\n * @alpha This is currently experimental and may change without a major version bump.\n */\nexport class CapacitorSQLiteAdapter extends BaseObserver {\n constructor(options) {\n super();\n this.options = options;\n this._writeConnection = null;\n this._readConnection = null;\n this.writeMutex = new Mutex();\n this.readMutex = new Mutex();\n this.initializedPromise = this.init();\n }\n get writeConnection() {\n if (!this._writeConnection) {\n throw new Error('Init not completed yet');\n }\n return this._writeConnection;\n }\n get readConnection() {\n if (!this._readConnection) {\n throw new Error('Init not completed yet');\n }\n return this._readConnection;\n }\n get name() {\n return this.options.dbFilename;\n }\n async init() {\n const { responseCode: registrationResponseCode } = await PowerSyncCore.registerCore();\n if (registrationResponseCode != 0) {\n throw new Error(`Could not register PowerSync core extension: ${messageForErrorCode(registrationResponseCode)}`);\n }\n const sqlite = new SQLiteConnection(CapacitorSQLite);\n // It seems like the isConnection and retrieveConnection methods\n // only check a JS side map of connections.\n // On hot reload this JS cache can be cleared, while the connection\n // still exists natively. and `createConnection` will fail if it already exists.\n await sqlite.closeConnection(this.options.dbFilename, false).catch(() => { });\n await sqlite.closeConnection(this.options.dbFilename, true).catch(() => { });\n // TODO support encryption eventually\n this._writeConnection = await sqlite.createConnection(this.options.dbFilename, false, 'no-encryption', 1, false);\n this._readConnection = await sqlite.createConnection(this.options.dbFilename, false, 'no-encryption', 1, true);\n await this._writeConnection.open();\n const { cacheSizeKb, journalSizeLimit, synchronous } = Object.assign(Object.assign({}, DEFAULT_SQLITE_OPTIONS), this.options.sqliteOptions);\n await this.writeConnection.query('PRAGMA journal_mode = WAL');\n await this.writeConnection.query(`PRAGMA journal_size_limit = ${journalSizeLimit}`);\n await this.writeConnection.query(`PRAGMA temp_store = memory`);\n await this.writeConnection.query(`PRAGMA synchronous = ${synchronous}`);\n await this.writeConnection.query(`PRAGMA cache_size = -${cacheSizeKb}`);\n await this._readConnection.open();\n const platform = Capacitor.getPlatform();\n if (platform == 'android') {\n /**\n * SQLCipher for Android enables dynamic loading of extensions.\n * On iOS we use a static auto extension registration.\n */\n const extensionQuery = \"SELECT load_extension('libpowersync.so', 'sqlite3_powersync_init')\";\n await this.writeConnection.query(extensionQuery);\n await this.readConnection.query(extensionQuery);\n }\n await this.writeConnection.query(\"SELECT powersync_update_hooks('install')\");\n }\n async close() {\n await this.initializedPromise;\n await this.writeConnection.close();\n await this.readConnection.close();\n }\n generateLockContext(db) {\n const _query = async (query, params = []) => {\n var _a;\n const result = await db.query(query, params);\n const arrayResult = (_a = result.values) !== null && _a !== void 0 ? _a : [];\n return {\n rowsAffected: 0,\n rows: {\n _array: arrayResult,\n length: arrayResult.length,\n item: (idx) => arrayResult[idx]\n }\n };\n };\n const _execute = async (query, params = []) => {\n var _a, _b, _c, _d, _e, _f, _g, _h;\n const platform = Capacitor.getPlatform();\n if (db.getConnectionReadOnly()) {\n return _query(query, params);\n }\n if (platform == 'android') {\n // Android: use query for SELECT and executeSet for mutations\n // We cannot use `run` here for both cases.\n if (query.toLowerCase().trim().startsWith('select')) {\n return _query(query, params);\n }\n else {\n const result = await db.executeSet([{ statement: query, values: params }], false);\n return {\n insertId: (_a = result.changes) === null || _a === void 0 ? void 0 : _a.lastId,\n rowsAffected: (_c = (_b = result.changes) === null || _b === void 0 ? void 0 : _b.changes) !== null && _c !== void 0 ? _c : 0,\n rows: {\n _array: [],\n length: 0,\n item: () => null\n }\n };\n }\n }\n // iOS (and other platforms): use run(\"all\")\n const result = await db.run(query, params, false, 'all');\n const resultSet = (_e = (_d = result.changes) === null || _d === void 0 ? void 0 : _d.values) !== null && _e !== void 0 ? _e : [];\n return {\n insertId: (_f = result.changes) === null || _f === void 0 ? void 0 : _f.lastId,\n rowsAffected: (_h = (_g = result.changes) === null || _g === void 0 ? void 0 : _g.changes) !== null && _h !== void 0 ? _h : 0,\n rows: {\n _array: resultSet,\n length: resultSet.length,\n item: (idx) => resultSet[idx]\n }\n };\n };\n const execute = this.options.debugMode\n ? (sql, params) => monitorQuery(sql, () => _execute(sql, params))\n : _execute;\n const executeQuery = this.options.debugMode\n ? (sql, params) => monitorQuery(sql, () => _query(sql, params))\n : _query;\n const getAll = async (query, params) => {\n var _a, _b;\n const result = await executeQuery(query, params);\n return (_b = (_a = result.rows) === null || _a === void 0 ? void 0 : _a._array) !== null && _b !== void 0 ? _b : [];\n };\n const getOptional = async (query, params) => {\n const results = await getAll(query, params);\n return results.length > 0 ? results[0] : null;\n };\n const get = async (query, params) => {\n const result = await getOptional(query, params);\n if (!result) {\n throw new Error(`No results for query: ${query}`);\n }\n return result;\n };\n const executeRaw = async (query, params) => {\n var _a, _b;\n // This is a workaround, we don't support multiple columns of the same name\n const results = await execute(query, params);\n return (_b = (_a = results.rows) === null || _a === void 0 ? void 0 : _a._array.map((row) => Object.values(row))) !== null && _b !== void 0 ? _b : [];\n };\n return {\n getAll,\n getOptional,\n get,\n executeRaw,\n execute\n };\n }\n execute(query, params) {\n return this.writeLock((tx) => tx.execute(query, params));\n }\n executeRaw(query, params) {\n return this.writeLock((tx) => tx.executeRaw(query, params));\n }\n async executeBatch(query, params = []) {\n return this.writeLock(async (tx) => {\n var _a, _b, _c;\n let result = await this.writeConnection.executeSet(params.map((param) => ({\n statement: query,\n values: param\n })));\n return {\n rowsAffected: (_b = (_a = result.changes) === null || _a === void 0 ? void 0 : _a.changes) !== null && _b !== void 0 ? _b : 0,\n insertId: (_c = result.changes) === null || _c === void 0 ? void 0 : _c.lastId\n };\n });\n }\n readLock(fn, options) {\n return mutexRunExclusive(this.readMutex, async () => {\n await this.initializedPromise;\n return await fn(this.generateLockContext(this.readConnection));\n }, options);\n }\n readTransaction(fn, options) {\n return this.readLock(async (ctx) => {\n return this.internalTransaction(ctx, fn);\n });\n }\n writeLock(fn, options) {\n return mutexRunExclusive(this.writeMutex, async () => {\n var _a;\n await this.initializedPromise;\n const result = await fn(this.generateLockContext(this.writeConnection));\n // Fetch table updates\n const updates = await this.writeConnection.query(\"SELECT powersync_update_hooks('get') AS table_name\");\n const jsonUpdates = (_a = updates.values) === null || _a === void 0 ? void 0 : _a[0];\n if (!jsonUpdates || !jsonUpdates.table_name) {\n throw new Error('Could not fetch table updates');\n }\n const notification = {\n rawUpdates: [],\n tables: JSON.parse(jsonUpdates.table_name),\n groupedUpdates: {}\n };\n this.iterateListeners((l) => { var _a; return (_a = l.tablesUpdated) === null || _a === void 0 ? void 0 : _a.call(l, notification); });\n return result;\n }, options);\n }\n writeTransaction(fn, options) {\n return this.writeLock(async (ctx) => {\n return this.internalTransaction(ctx, fn);\n });\n }\n refreshSchema() {\n return this.writeLock(async (writeTx) => {\n return this.readLock(async (readTx) => {\n const updateQuery = `PRAGMA table_info('sqlite_master')`;\n await writeTx.get(updateQuery);\n await readTx.get(updateQuery);\n });\n });\n }\n getAll(sql, parameters) {\n return this.readLock((tx) => tx.getAll(sql, parameters));\n }\n getOptional(sql, parameters) {\n return this.readLock((tx) => tx.getOptional(sql, parameters));\n }\n get(sql, parameters) {\n return this.readLock((tx) => tx.get(sql, parameters));\n }\n async internalTransaction(ctx, fn) {\n let finalized = false;\n const commit = async () => {\n if (finalized) {\n return { rowsAffected: 0 };\n }\n finalized = true;\n return ctx.execute('COMMIT');\n };\n const rollback = async () => {\n if (finalized) {\n return { rowsAffected: 0 };\n }\n finalized = true;\n return ctx.execute('ROLLBACK');\n };\n try {\n await ctx.execute('BEGIN');\n const result = await fn(Object.assign(Object.assign({}, ctx), { commit,\n rollback }));\n await commit();\n return result;\n }\n catch (ex) {\n try {\n await rollback();\n }\n catch (ex2) {\n // In rare cases, a rollback may fail.\n // Safe to ignore.\n }\n throw ex;\n }\n }\n}\n//# sourceMappingURL=CapacitorSQLiteAdapter.js.map","import { AbstractStreamingSyncImplementation, LockType, mutexRunExclusive } from '@powersync/web';\nimport { Mutex } from 'async-mutex';\nconst GLOBAL_MUTEX_STORE = new Map();\n/**\n * Used to identify multiple instances of CapacitorStreamingSyncImplementation\n */\nlet _CAPACITOR_STREAMING_SYNC_SEQUENCE = 0;\nexport class CapacitorStreamingSyncImplementation extends AbstractStreamingSyncImplementation {\n constructor() {\n super(...arguments);\n // A unique ID for tacking this specific instance of CapacitorStreamingSyncImplementation\n this.instanceId = _CAPACITOR_STREAMING_SYNC_SEQUENCE++;\n }\n async dispose() {\n await super.dispose();\n // Clear up any global mutexes which aren't used anymore\n for (const mutexEntry of GLOBAL_MUTEX_STORE.entries()) {\n const [identifier, mutex] = mutexEntry;\n if (!mutex.tracking.has(this.instanceId)) {\n continue;\n }\n mutex.tracking.delete(this.instanceId);\n if (mutex.tracking.size == 0) {\n GLOBAL_MUTEX_STORE.delete(identifier);\n }\n }\n }\n async obtainLock(lockOptions) {\n // If we don't have an identifier for some reason (should not happen), we use a shared Mutex\n const { identifier: baseIdentifier = 'DEFAULT' } = this.options;\n if (!GLOBAL_MUTEX_STORE.has(baseIdentifier)) {\n GLOBAL_MUTEX_STORE.set(baseIdentifier, {\n tracking: new Set([this.instanceId]),\n locks: {\n [LockType.CRUD]: new Mutex(),\n [LockType.SYNC]: new Mutex()\n }\n });\n }\n const mutexRecord = GLOBAL_MUTEX_STORE.get(baseIdentifier);\n mutexRecord.tracking.add(this.instanceId);\n const mutex = mutexRecord.locks[lockOptions.type];\n return mutexRunExclusive(mutex, async () => {\n var _a;\n if ((_a = lockOptions.signal) === null || _a === void 0 ? void 0 : _a.aborted) {\n throw new Error('Aborted');\n }\n return await lockOptions.callback();\n });\n }\n}\n//# sourceMappingURL=CapacitorSyncImplementation.js.map","import { Capacitor } from '@capacitor/core';\nimport { MEMORY_TRIGGER_CLAIM_MANAGER, PowerSyncDatabase as WebPowerSyncDatabase, WebRemote } from '@powersync/web';\nimport { CapacitorSQLiteAdapter } from './adapter/CapacitorSQLiteAdapter.js';\nimport { CapacitorStreamingSyncImplementation } from './sync/CapacitorSyncImplementation.js';\n/**\n * PowerSyncDatabase class for managing database connections and sync implementations.\n * This extends the WebPowerSyncDatabase to provide platform-specific implementations\n * for Capacitor environments (iOS and Android).\n *\n * @experimental\n * @alpha\n */\nexport class PowerSyncDatabase extends WebPowerSyncDatabase {\n get isNativeCapacitorPlatform() {\n const platform = Capacitor.getPlatform();\n return platform == 'ios' || platform == 'android';\n }\n openDBAdapter(options) {\n var _a, _b, _c;\n const platform = Capacitor.getPlatform();\n if (platform == 'ios' || platform == 'android') {\n if (options.database.dbLocation) {\n (_a = options.logger) === null || _a === void 0 ? void 0 : _a.warn(`\n dbLocation is ignored on iOS and Android platforms. \n The database directory can be configured in the Capacitor project.\n See https://github.com/capacitor-community/sqlite?tab=readme-ov-file#installation`);\n }\n (_b = options.logger) === null || _b === void 0 ? void 0 : _b.debug(`Using CapacitorSQLiteAdapter for platform: ${platform}`);\n return new CapacitorSQLiteAdapter(Object.assign({}, options.database));\n }\n else {\n (_c = options.logger) === null || _c === void 0 ? void 0 : _c.debug(`Using default web adapter for web platform`);\n return super.openDBAdapter(options);\n }\n }\n generateTriggerManagerConfig() {\n const config = super.generateTriggerManagerConfig();\n if (this.isNativeCapacitorPlatform) {\n /**\n * We usually only ever have a single tab for capacitor.\n * Avoiding navigator locks allows insecure contexts (during development).\n */\n config.claimManager = MEMORY_TRIGGER_CLAIM_MANAGER;\n }\n return config;\n }\n runExclusive(cb) {\n if (this.isNativeCapacitorPlatform) {\n // Use mutex for mobile platforms.\n // This is mainly for testing purposes since navigator.locks require secure contexts.\n return this.runExclusiveMutex.runExclusive(cb);\n }\n else {\n // Use navigator.locks for web platform\n return super.runExclusive(cb);\n }\n }\n generateSyncStreamImplementation(connector, options) {\n var _a;\n if (this.isNativeCapacitorPlatform) {\n // We don't want to support multi-tab on mobile platforms.\n // We technically can, but it's not a common use case and requires additional work/testing.\n this.logger.debug(`Using Capacitor sync implementation`);\n if ((_a = this.options.flags) === null || _a === void 0 ? void 0 : _a.enableMultiTabs) {\n this.logger.warn(`enableMultiTabs is not supported on Capacitor mobile platforms. Ignoring the flag.`);\n }\n const remote = new WebRemote(connector, this.logger);\n return new CapacitorStreamingSyncImplementation(Object.assign(Object.assign({}, this.options), { retryDelayMs: options.retryDelayMs, crudUploadThrottleMs: options.crudUploadThrottleMs, adapter: this.bucketStorageAdapter, remote, uploadCrud: async () => {\n await this.waitForReady();\n await connector.uploadData(this);\n }, identifier: this.database.name, logger: this.logger, subscriptions: options.subscriptions }));\n }\n else {\n this.logger.debug(`Using default web sync implementation for web platform`);\n return super.generateSyncStreamImplementation(connector, options);\n }\n }\n}\n//# sourceMappingURL=PowerSyncDatabase.js.map","import { WebPlugin } from '@capacitor/core';\nexport class PowerSyncWeb extends WebPlugin {\n async registerCore() {\n throw new Error('This code path is not supported on web.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","BaseObserver","Mutex","sqlite","SQLiteConnection","CapacitorSQLite","Capacitor","mutexRunExclusive","AbstractStreamingSyncImplementation","LockType","WebPowerSyncDatabase","MEMORY_TRIGGER_CLAIM_MANAGER","WebRemote","WebPlugin"],"mappings":";;;IACO,MAAM,aAAa,GAAGA,mBAAc,CAAC,WAAW,EAAE;IACzD,IAAI,GAAG,EAAE,MAAM,mDAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK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/CapacitorSyncImplementation.js","esm/PowerSyncDatabase.js","esm/plugin/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nexport const PowerSyncCore = registerPlugin('PowerSync', {\n web: () => import('./web.js').then((m) => new m.PowerSyncWeb())\n});\n//# sourceMappingURL=PowerSyncCore.js.map","export const messageForErrorCode = (code) => {\n switch (code) {\n case 0:\n return 'Success';\n default:\n return `Extension registration failed with SQLite error code: ${code}`;\n }\n};\n//# sourceMappingURL=PowerSyncPlugin.js.map","import { CapacitorSQLiteAdapter } from './CapacitorSQLiteAdapter.js';\nvar SqliteSynchronous;\n(function (SqliteSynchronous) {\n SqliteSynchronous[\"normal\"] = \"NORMAL\";\n SqliteSynchronous[\"full\"] = \"FULL\";\n SqliteSynchronous[\"off\"] = \"OFF\";\n})(SqliteSynchronous || (SqliteSynchronous = {}));\nexport const DEFAULT_SQLITE_OPTIONS = {\n journalSizeLimit: 6 * 1024 * 1024,\n synchronous: SqliteSynchronous.normal,\n cacheSizeKb: 50 * 1024\n};\nexport class CapacitorSQLiteOpenFactory {\n constructor(options) {\n this.options = options;\n }\n openDB() {\n return new CapacitorSQLiteAdapter(this.options);\n }\n}\n//# sourceMappingURL=CapacitorSQLiteOpenFactory.js.map","import { CapacitorSQLite, SQLiteConnection } from '@capacitor-community/sqlite';\nimport { Capacitor } from '@capacitor/core';\nimport { BaseObserver, DBAdapterDefaultMixin, mutexRunExclusive } from '@powersync/web';\nimport { Mutex } from 'async-mutex';\nimport { PowerSyncCore } from '../plugin/PowerSyncCore.js';\nimport { messageForErrorCode } from '../plugin/PowerSyncPlugin.js';\nimport { DEFAULT_SQLITE_OPTIONS } from './CapacitorSQLiteOpenFactory.js';\n/**\n * Monitors the execution time of a query and logs it to the performance timeline.\n */\nasync function monitorQuery(sql, executor) {\n const start = performance.now();\n try {\n const r = await executor();\n performance.measure(`[SQL] ${sql}`, { start });\n return r;\n }\n catch (e) {\n performance.measure(`[SQL] [ERROR: ${e.message}] ${sql}`, { start });\n throw e;\n }\n}\nclass CapacitorConnectionPool extends BaseObserver {\n constructor(options) {\n super();\n this.options = options;\n this._writeConnection = null;\n this._readConnection = null;\n this.writeMutex = new Mutex();\n this.readMutex = new Mutex();\n this.initializedPromise = this.init();\n }\n get writeConnection() {\n if (!this._writeConnection) {\n throw new Error('Init not completed yet');\n }\n return this._writeConnection;\n }\n get readConnection() {\n if (!this._readConnection) {\n throw new Error('Init not completed yet');\n }\n return this._readConnection;\n }\n get name() {\n return this.options.dbFilename;\n }\n async init() {\n const { responseCode: registrationResponseCode } = await PowerSyncCore.registerCore();\n if (registrationResponseCode != 0) {\n throw new Error(`Could not register PowerSync core extension: ${messageForErrorCode(registrationResponseCode)}`);\n }\n const sqlite = new SQLiteConnection(CapacitorSQLite);\n // It seems like the isConnection and retrieveConnection methods\n // only check a JS side map of connections.\n // On hot reload this JS cache can be cleared, while the connection\n // still exists natively. and `createConnection` will fail if it already exists.\n await sqlite.closeConnection(this.options.dbFilename, false).catch(() => { });\n await sqlite.closeConnection(this.options.dbFilename, true).catch(() => { });\n // TODO support encryption eventually\n this._writeConnection = await sqlite.createConnection(this.options.dbFilename, false, 'no-encryption', 1, false);\n this._readConnection = await sqlite.createConnection(this.options.dbFilename, false, 'no-encryption', 1, true);\n await this._writeConnection.open();\n const { cacheSizeKb, journalSizeLimit, synchronous } = Object.assign(Object.assign({}, DEFAULT_SQLITE_OPTIONS), this.options.sqliteOptions);\n await this.writeConnection.query('PRAGMA journal_mode = WAL');\n await this.writeConnection.query(`PRAGMA journal_size_limit = ${journalSizeLimit}`);\n await this.writeConnection.query(`PRAGMA temp_store = memory`);\n await this.writeConnection.query(`PRAGMA synchronous = ${synchronous}`);\n await this.writeConnection.query(`PRAGMA cache_size = -${cacheSizeKb}`);\n await this._readConnection.open();\n const platform = Capacitor.getPlatform();\n if (platform == 'android') {\n /**\n * SQLCipher for Android enables dynamic loading of extensions.\n * On iOS we use a static auto extension registration.\n */\n const extensionQuery = \"SELECT load_extension('libpowersync.so', 'sqlite3_powersync_init')\";\n await this.writeConnection.query(extensionQuery);\n await this.readConnection.query(extensionQuery);\n }\n await this.writeConnection.query(\"SELECT powersync_update_hooks('install')\");\n }\n async close() {\n await this.initializedPromise;\n await this.writeConnection.close();\n await this.readConnection.close();\n }\n generateLockContext(db) {\n const _query = async (query, params = []) => {\n var _a;\n const result = await db.query(query, params);\n const arrayResult = (_a = result.values) !== null && _a !== void 0 ? _a : [];\n return {\n rowsAffected: 0,\n rows: {\n _array: arrayResult,\n length: arrayResult.length,\n item: (idx) => arrayResult[idx]\n }\n };\n };\n const _execute = async (query, params = []) => {\n var _a, _b, _c, _d, _e, _f, _g, _h;\n const platform = Capacitor.getPlatform();\n if (db.getConnectionReadOnly()) {\n return _query(query, params);\n }\n if (platform == 'android') {\n // Android: use query for SELECT and executeSet for mutations\n // We cannot use `run` here for both cases.\n if (query.toLowerCase().trim().startsWith('select')) {\n return _query(query, params);\n }\n else {\n const result = await db.executeSet([{ statement: query, values: params }], false);\n return {\n insertId: (_a = result.changes) === null || _a === void 0 ? void 0 : _a.lastId,\n rowsAffected: (_c = (_b = result.changes) === null || _b === void 0 ? void 0 : _b.changes) !== null && _c !== void 0 ? _c : 0,\n rows: {\n _array: [],\n length: 0,\n item: () => null\n }\n };\n }\n }\n // iOS (and other platforms): use run(\"all\")\n const result = await db.run(query, params, false, 'all');\n const resultSet = (_e = (_d = result.changes) === null || _d === void 0 ? void 0 : _d.values) !== null && _e !== void 0 ? _e : [];\n return {\n insertId: (_f = result.changes) === null || _f === void 0 ? void 0 : _f.lastId,\n rowsAffected: (_h = (_g = result.changes) === null || _g === void 0 ? void 0 : _g.changes) !== null && _h !== void 0 ? _h : 0,\n rows: {\n _array: resultSet,\n length: resultSet.length,\n item: (idx) => resultSet[idx]\n }\n };\n };\n const execute = this.options.debugMode\n ? (sql, params) => monitorQuery(sql, () => _execute(sql, params))\n : _execute;\n const executeQuery = this.options.debugMode\n ? (sql, params) => monitorQuery(sql, () => _query(sql, params))\n : _query;\n const getAll = async (query, params) => {\n var _a, _b;\n const result = await executeQuery(query, params);\n return (_b = (_a = result.rows) === null || _a === void 0 ? void 0 : _a._array) !== null && _b !== void 0 ? _b : [];\n };\n const getOptional = async (query, params) => {\n const results = await getAll(query, params);\n return results.length > 0 ? results[0] : null;\n };\n const get = async (query, params) => {\n const result = await getOptional(query, params);\n if (!result) {\n throw new Error(`No results for query: ${query}`);\n }\n return result;\n };\n const executeRaw = async (query, params) => {\n var _a, _b;\n // This is a workaround, we don't support multiple columns of the same name\n const results = await execute(query, params);\n return (_b = (_a = results.rows) === null || _a === void 0 ? void 0 : _a._array.map((row) => Object.values(row))) !== null && _b !== void 0 ? _b : [];\n };\n const executeBatch = async (query, params = []) => {\n var _a, _b, _c;\n let result = await db.executeSet(params.map((param) => ({\n statement: query,\n values: param\n })));\n return {\n rowsAffected: (_b = (_a = result.changes) === null || _a === void 0 ? void 0 : _a.changes) !== null && _b !== void 0 ? _b : 0,\n insertId: (_c = result.changes) === null || _c === void 0 ? void 0 : _c.lastId\n };\n };\n return {\n getAll,\n getOptional,\n get,\n executeRaw,\n execute,\n executeBatch\n };\n }\n readLock(fn, options) {\n return mutexRunExclusive(this.readMutex, async () => {\n await this.initializedPromise;\n return await fn(this.generateLockContext(this.readConnection));\n }, options);\n }\n writeLock(fn, options) {\n return mutexRunExclusive(this.writeMutex, async () => {\n var _a;\n await this.initializedPromise;\n const result = await fn(this.generateLockContext(this.writeConnection));\n // Fetch table updates\n const updates = await this.writeConnection.query(\"SELECT powersync_update_hooks('get') AS table_name\");\n const jsonUpdates = (_a = updates.values) === null || _a === void 0 ? void 0 : _a[0];\n if (!jsonUpdates || !jsonUpdates.table_name) {\n throw new Error('Could not fetch table updates');\n }\n const notification = {\n rawUpdates: [],\n tables: JSON.parse(jsonUpdates.table_name),\n groupedUpdates: {}\n };\n this.iterateListeners((l) => { var _a; return (_a = l.tablesUpdated) === null || _a === void 0 ? void 0 : _a.call(l, notification); });\n return result;\n }, options);\n }\n refreshSchema() {\n return this.writeLock(async (writeTx) => {\n return this.readLock(async (readTx) => {\n const updateQuery = `PRAGMA table_info('sqlite_master')`;\n await writeTx.get(updateQuery);\n await readTx.get(updateQuery);\n });\n });\n }\n}\n/**\n * An implementation of {@link DBAdapter} using the Capacitor Community SQLite [plugin](https://github.com/capacitor-community/sqlite).\n *\n * @experimental\n * @alpha This is currently experimental and may change without a major version bump.\n */\nexport class CapacitorSQLiteAdapter extends DBAdapterDefaultMixin(CapacitorConnectionPool) {\n}\n//# sourceMappingURL=CapacitorSQLiteAdapter.js.map","import { AbstractStreamingSyncImplementation, LockType, mutexRunExclusive } from '@powersync/web';\nimport { Mutex } from 'async-mutex';\nconst GLOBAL_MUTEX_STORE = new Map();\n/**\n * Used to identify multiple instances of CapacitorStreamingSyncImplementation\n */\nlet _CAPACITOR_STREAMING_SYNC_SEQUENCE = 0;\nexport class CapacitorStreamingSyncImplementation extends AbstractStreamingSyncImplementation {\n constructor() {\n super(...arguments);\n // A unique ID for tacking this specific instance of CapacitorStreamingSyncImplementation\n this.instanceId = _CAPACITOR_STREAMING_SYNC_SEQUENCE++;\n }\n async dispose() {\n await super.dispose();\n // Clear up any global mutexes which aren't used anymore\n for (const mutexEntry of GLOBAL_MUTEX_STORE.entries()) {\n const [identifier, mutex] = mutexEntry;\n if (!mutex.tracking.has(this.instanceId)) {\n continue;\n }\n mutex.tracking.delete(this.instanceId);\n if (mutex.tracking.size == 0) {\n GLOBAL_MUTEX_STORE.delete(identifier);\n }\n }\n }\n async obtainLock(lockOptions) {\n // If we don't have an identifier for some reason (should not happen), we use a shared Mutex\n const { identifier: baseIdentifier = 'DEFAULT' } = this.options;\n if (!GLOBAL_MUTEX_STORE.has(baseIdentifier)) {\n GLOBAL_MUTEX_STORE.set(baseIdentifier, {\n tracking: new Set([this.instanceId]),\n locks: {\n [LockType.CRUD]: new Mutex(),\n [LockType.SYNC]: new Mutex()\n }\n });\n }\n const mutexRecord = GLOBAL_MUTEX_STORE.get(baseIdentifier);\n mutexRecord.tracking.add(this.instanceId);\n const mutex = mutexRecord.locks[lockOptions.type];\n return mutexRunExclusive(mutex, async () => {\n var _a;\n if ((_a = lockOptions.signal) === null || _a === void 0 ? void 0 : _a.aborted) {\n throw new Error('Aborted');\n }\n return await lockOptions.callback();\n });\n }\n}\n//# sourceMappingURL=CapacitorSyncImplementation.js.map","import { Capacitor } from '@capacitor/core';\nimport { MEMORY_TRIGGER_CLAIM_MANAGER, PowerSyncDatabase as WebPowerSyncDatabase, WebRemote } from '@powersync/web';\nimport { CapacitorSQLiteAdapter } from './adapter/CapacitorSQLiteAdapter.js';\nimport { CapacitorStreamingSyncImplementation } from './sync/CapacitorSyncImplementation.js';\n/**\n * PowerSyncDatabase class for managing database connections and sync implementations.\n * This extends the WebPowerSyncDatabase to provide platform-specific implementations\n * for Capacitor environments (iOS and Android).\n *\n * @experimental\n * @alpha\n */\nexport class PowerSyncDatabase extends WebPowerSyncDatabase {\n get isNativeCapacitorPlatform() {\n const platform = Capacitor.getPlatform();\n return platform == 'ios' || platform == 'android';\n }\n openDBAdapter(options) {\n var _a, _b, _c;\n const platform = Capacitor.getPlatform();\n if (platform == 'ios' || platform == 'android') {\n if (options.database.dbLocation) {\n (_a = options.logger) === null || _a === void 0 ? void 0 : _a.warn(`\n dbLocation is ignored on iOS and Android platforms. \n The database directory can be configured in the Capacitor project.\n See https://github.com/capacitor-community/sqlite?tab=readme-ov-file#installation`);\n }\n (_b = options.logger) === null || _b === void 0 ? void 0 : _b.debug(`Using CapacitorSQLiteAdapter for platform: ${platform}`);\n return new CapacitorSQLiteAdapter(Object.assign({}, options.database));\n }\n else {\n (_c = options.logger) === null || _c === void 0 ? void 0 : _c.debug(`Using default web adapter for web platform`);\n return super.openDBAdapter(options);\n }\n }\n generateTriggerManagerConfig() {\n const config = super.generateTriggerManagerConfig();\n if (this.isNativeCapacitorPlatform) {\n /**\n * We usually only ever have a single tab for capacitor.\n * Avoiding navigator locks allows insecure contexts (during development).\n */\n config.claimManager = MEMORY_TRIGGER_CLAIM_MANAGER;\n }\n return config;\n }\n runExclusive(cb) {\n if (this.isNativeCapacitorPlatform) {\n // Use mutex for mobile platforms.\n // This is mainly for testing purposes since navigator.locks require secure contexts.\n return this.runExclusiveMutex.runExclusive(cb);\n }\n else {\n // Use navigator.locks for web platform\n return super.runExclusive(cb);\n }\n }\n generateSyncStreamImplementation(connector, options) {\n var _a;\n if (this.isNativeCapacitorPlatform) {\n // We don't want to support multi-tab on mobile platforms.\n // We technically can, but it's not a common use case and requires additional work/testing.\n this.logger.debug(`Using Capacitor sync implementation`);\n if ((_a = this.options.flags) === null || _a === void 0 ? void 0 : _a.enableMultiTabs) {\n this.logger.warn(`enableMultiTabs is not supported on Capacitor mobile platforms. Ignoring the flag.`);\n }\n const remote = new WebRemote(connector, this.logger);\n return new CapacitorStreamingSyncImplementation(Object.assign(Object.assign({}, this.options), { retryDelayMs: options.retryDelayMs, crudUploadThrottleMs: options.crudUploadThrottleMs, adapter: this.bucketStorageAdapter, remote, uploadCrud: async () => {\n await this.waitForReady();\n await connector.uploadData(this);\n }, identifier: this.database.name, logger: this.logger, subscriptions: options.subscriptions }));\n }\n else {\n this.logger.debug(`Using default web sync implementation for web platform`);\n return super.generateSyncStreamImplementation(connector, options);\n }\n }\n}\n//# sourceMappingURL=PowerSyncDatabase.js.map","import { WebPlugin } from '@capacitor/core';\nexport class PowerSyncWeb extends WebPlugin {\n async registerCore() {\n throw new Error('This code path is not supported on web.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","BaseObserver","Mutex","sqlite","SQLiteConnection","CapacitorSQLite","Capacitor","mutexRunExclusive","DBAdapterDefaultMixin","AbstractStreamingSyncImplementation","LockType","WebPowerSyncDatabase","MEMORY_TRIGGER_CLAIM_MANAGER","WebRemote","WebPlugin"],"mappings":";;;IACO,MAAM,aAAa,GAAGA,mBAAc,CAAC,WAAW,EAAE;IACzD,IAAI,GAAG,EAAE,MAAM,mDAAkB,C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
|
2
2
|
"name": "@powersync/capacitor",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Adds PowerSync Capacitor support for iOS/Android",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
69
|
"@capacitor-community/sqlite": "^7.0.2",
|
|
70
|
-
"@powersync/web": "^1.
|
|
70
|
+
"@powersync/web": "^1.36.0"
|
|
71
71
|
},
|
|
72
72
|
"swiftlint": "@ionic/swiftlint-config",
|
|
73
73
|
"capacitor": {
|
|
@@ -4,7 +4,9 @@ import { Capacitor } from '@capacitor/core';
|
|
|
4
4
|
import {
|
|
5
5
|
BaseObserver,
|
|
6
6
|
BatchedUpdateNotification,
|
|
7
|
+
ConnectionPool,
|
|
7
8
|
DBAdapter,
|
|
9
|
+
DBAdapterDefaultMixin,
|
|
8
10
|
DBAdapterListener,
|
|
9
11
|
DBLockOptions,
|
|
10
12
|
LockContext,
|
|
@@ -30,13 +32,8 @@ async function monitorQuery(sql: string, executor: () => Promise<QueryResult>):
|
|
|
30
32
|
throw e;
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
*
|
|
36
|
-
* @experimental
|
|
37
|
-
* @alpha This is currently experimental and may change without a major version bump.
|
|
38
|
-
*/
|
|
39
|
-
export class CapacitorSQLiteAdapter extends BaseObserver<DBAdapterListener> implements DBAdapter {
|
|
35
|
+
|
|
36
|
+
class CapacitorConnectionPool extends BaseObserver<DBAdapterListener> implements ConnectionPool {
|
|
40
37
|
protected _writeConnection: SQLiteDBConnection | null;
|
|
41
38
|
protected _readConnection: SQLiteDBConnection | null;
|
|
42
39
|
protected initializedPromise: Promise<void>;
|
|
@@ -206,26 +203,8 @@ export class CapacitorSQLiteAdapter extends BaseObserver<DBAdapterListener> impl
|
|
|
206
203
|
return results.rows?._array.map((row) => Object.values(row)) ?? [];
|
|
207
204
|
};
|
|
208
205
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
getOptional,
|
|
212
|
-
get,
|
|
213
|
-
executeRaw,
|
|
214
|
-
execute
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
execute(query: string, params?: any[]): Promise<QueryResult> {
|
|
219
|
-
return this.writeLock((tx) => tx.execute(query, params));
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
executeRaw(query: string, params?: any[]): Promise<any[][]> {
|
|
223
|
-
return this.writeLock((tx) => tx.executeRaw(query, params));
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
async executeBatch(query: string, params: any[][] = []): Promise<QueryResult> {
|
|
227
|
-
return this.writeLock(async (tx) => {
|
|
228
|
-
let result = await this.writeConnection.executeSet(
|
|
206
|
+
const executeBatch = async (query: string, params: any[][] = []): Promise<QueryResult> => {
|
|
207
|
+
let result = await db.executeSet(
|
|
229
208
|
params.map((param) => ({
|
|
230
209
|
statement: query,
|
|
231
210
|
values: param
|
|
@@ -236,7 +215,16 @@ export class CapacitorSQLiteAdapter extends BaseObserver<DBAdapterListener> impl
|
|
|
236
215
|
rowsAffected: result.changes?.changes ?? 0,
|
|
237
216
|
insertId: result.changes?.lastId
|
|
238
217
|
};
|
|
239
|
-
}
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
return {
|
|
221
|
+
getAll,
|
|
222
|
+
getOptional,
|
|
223
|
+
get,
|
|
224
|
+
executeRaw,
|
|
225
|
+
execute,
|
|
226
|
+
executeBatch
|
|
227
|
+
};
|
|
240
228
|
}
|
|
241
229
|
|
|
242
230
|
readLock<T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions): Promise<T> {
|
|
@@ -250,12 +238,6 @@ export class CapacitorSQLiteAdapter extends BaseObserver<DBAdapterListener> impl
|
|
|
250
238
|
);
|
|
251
239
|
}
|
|
252
240
|
|
|
253
|
-
readTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions): Promise<T> {
|
|
254
|
-
return this.readLock(async (ctx) => {
|
|
255
|
-
return this.internalTransaction(ctx, fn);
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
|
|
259
241
|
writeLock<T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions): Promise<T> {
|
|
260
242
|
return mutexRunExclusive(
|
|
261
243
|
this.writeMutex,
|
|
@@ -281,12 +263,6 @@ export class CapacitorSQLiteAdapter extends BaseObserver<DBAdapterListener> impl
|
|
|
281
263
|
);
|
|
282
264
|
}
|
|
283
265
|
|
|
284
|
-
writeTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions): Promise<T> {
|
|
285
|
-
return this.writeLock(async (ctx) => {
|
|
286
|
-
return this.internalTransaction(ctx, fn);
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
|
|
290
266
|
refreshSchema(): Promise<void> {
|
|
291
267
|
return this.writeLock(async (writeTx) => {
|
|
292
268
|
return this.readLock(async (readTx) => {
|
|
@@ -296,52 +272,12 @@ export class CapacitorSQLiteAdapter extends BaseObserver<DBAdapterListener> impl
|
|
|
296
272
|
});
|
|
297
273
|
});
|
|
298
274
|
}
|
|
299
|
-
|
|
300
|
-
getAll<T>(sql: string, parameters?: any[]): Promise<T[]> {
|
|
301
|
-
return this.readLock((tx) => tx.getAll<T>(sql, parameters));
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
getOptional<T>(sql: string, parameters?: any[]): Promise<T | null> {
|
|
305
|
-
return this.readLock((tx) => tx.getOptional<T>(sql, parameters));
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
get<T>(sql: string, parameters?: any[]): Promise<T> {
|
|
309
|
-
return this.readLock((tx) => tx.get<T>(sql, parameters));
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
protected async internalTransaction<T>(ctx: LockContext, fn: (tx: Transaction) => Promise<T>): Promise<T> {
|
|
313
|
-
let finalized = false;
|
|
314
|
-
const commit = async (): Promise<QueryResult> => {
|
|
315
|
-
if (finalized) {
|
|
316
|
-
return { rowsAffected: 0 };
|
|
317
|
-
}
|
|
318
|
-
finalized = true;
|
|
319
|
-
return ctx.execute('COMMIT');
|
|
320
|
-
};
|
|
321
|
-
const rollback = async (): Promise<QueryResult> => {
|
|
322
|
-
if (finalized) {
|
|
323
|
-
return { rowsAffected: 0 };
|
|
324
|
-
}
|
|
325
|
-
finalized = true;
|
|
326
|
-
return ctx.execute('ROLLBACK');
|
|
327
|
-
};
|
|
328
|
-
try {
|
|
329
|
-
await ctx.execute('BEGIN');
|
|
330
|
-
const result = await fn({
|
|
331
|
-
...ctx,
|
|
332
|
-
commit,
|
|
333
|
-
rollback
|
|
334
|
-
});
|
|
335
|
-
await commit();
|
|
336
|
-
return result;
|
|
337
|
-
} catch (ex) {
|
|
338
|
-
try {
|
|
339
|
-
await rollback();
|
|
340
|
-
} catch (ex2) {
|
|
341
|
-
// In rare cases, a rollback may fail.
|
|
342
|
-
// Safe to ignore.
|
|
343
|
-
}
|
|
344
|
-
throw ex;
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
275
|
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* An implementation of {@link DBAdapter} using the Capacitor Community SQLite [plugin](https://github.com/capacitor-community/sqlite).
|
|
279
|
+
*
|
|
280
|
+
* @experimental
|
|
281
|
+
* @alpha This is currently experimental and may change without a major version bump.
|
|
282
|
+
*/
|
|
283
|
+
export class CapacitorSQLiteAdapter extends DBAdapterDefaultMixin(CapacitorConnectionPool) {}
|