@powersync/capacitor 0.1.2 → 0.2.0

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.
@@ -23,7 +23,7 @@ Pod::Spec.new do |s|
23
23
  s.ios.deployment_target = '14.0'
24
24
  s.dependency 'Capacitor'
25
25
  s.swift_version = '5.1'
26
- s.dependency "powersync-sqlite-core", "~> 0.4.6"
26
+ s.dependency "powersync-sqlite-core", "~> 0.4.10"
27
27
  s.xcconfig = {
28
28
  'OTHER_CFLAGS' => '$(inherited) -DSQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION=1',
29
29
  'HEADER_SEARCH_PATHS' => '$(inherited) "$(PODS_ROOT)/SQLCipher"'
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  # PowerSync SDK for Capacitor
6
6
 
7
- _[PowerSync](https://www.powersync.com) is a sync engine for building local-first apps with instantly-responsive UI/UX and simplified state transfer. Syncs between SQLite on the client-side and Postgres, MongoDB or MySQL on the server-side._
7
+ _[PowerSync](https://www.powersync.com) is a sync engine for building local-first apps with instantly-responsive UI/UX and simplified state transfer. Syncs between SQLite on the client-side and Postgres, MongoDB, MySQL or SQL Server on the server-side._
8
8
 
9
9
  This package (`@powersync/capacitor`) is the PowerSync SDK for Capacitor apps. It wraps the [PowerSync Web SDK](https://www.npmjs.com/package/@powersync/web) for Capacitor PWAs and uses [Capacitor Community SQLite](https://github.com/capacitor-community/sqlite) as the database driver for Android and iOS.
10
10
 
@@ -82,7 +82,7 @@ const db = new PowerSyncDatabase({
82
82
 
83
83
  - Encryption for native mobile platforms is not yet supported.
84
84
  - `PowerSyncDatabase.executeRaw` does not support results where multiple columns would have the same name in SQLite
85
- - `PowerSyncDatabase.execute` has limited support on Android. The SQLCipher Android driver exposes queries and executions as separate APIs, so there is no single method that handles both. While `PowerSyncDatabase.execute` accepts both, on Android we treat a statement as a query only when the SQL starts with `select` (case-insensitive).
85
+ - `PowerSyncDatabase.execute` has limited support on Android. The SQLCipher Android driver exposes queries and executions as separate APIs, so there is no single method that handles both. While `PowerSyncDatabase.execute` accepts both, on Android we treat a statement as a query only when the SQL starts with `select` (case-insensitive). Queries such as `INSERT into customers (id, name) VALUES (uuid(), 'name') RETURNING *` do not work on Android.
86
86
  - Multiple tab support is not available for native Android and iOS targets. If you're not opening a second webview in your native app using something like `@jackobo/capacitor-webview`, you are unaffected by this.
87
87
 
88
88
  ## Examples
@@ -3,7 +3,7 @@ ext {
3
3
  androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.0'
4
4
  androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.2.1'
5
5
  androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.6.1'
6
- powerSyncCoreVersion = project.hasProperty('powerSyncCoreVersion') ? rootProject.ext.powerSyncCoreVersion : '0.4.6'
6
+ powerSyncCoreVersion = project.hasProperty('powerSyncCoreVersion') ? rootProject.ext.powerSyncCoreVersion : '0.4.10'
7
7
  }
8
8
 
9
9
  buildscript {
@@ -91,29 +91,36 @@ export class CapacitorSQLiteAdapter extends BaseObserver {
91
91
  await this.readConnection.close();
92
92
  }
93
93
  generateLockContext(db) {
94
+ const _query = async (query, params = []) => {
95
+ var _a;
96
+ const result = await db.query(query, params);
97
+ const arrayResult = (_a = result.values) !== null && _a !== void 0 ? _a : [];
98
+ return {
99
+ rowsAffected: 0,
100
+ rows: {
101
+ _array: arrayResult,
102
+ length: arrayResult.length,
103
+ item: (idx) => arrayResult[idx]
104
+ }
105
+ };
106
+ };
94
107
  const _execute = async (query, params = []) => {
95
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
108
+ var _a, _b, _c, _d, _e, _f, _g, _h;
96
109
  const platform = Capacitor.getPlatform();
110
+ if (db.getConnectionReadOnly()) {
111
+ return _query(query, params);
112
+ }
97
113
  if (platform == 'android') {
98
114
  // Android: use query for SELECT and executeSet for mutations
99
115
  // We cannot use `run` here for both cases.
100
116
  if (query.toLowerCase().trim().startsWith('select')) {
101
- const result = await db.query(query, params);
102
- const arrayResult = (_a = result.values) !== null && _a !== void 0 ? _a : [];
103
- return {
104
- rowsAffected: 0,
105
- rows: {
106
- _array: arrayResult,
107
- length: arrayResult.length,
108
- item: (idx) => arrayResult[idx]
109
- }
110
- };
117
+ return _query(query, params);
111
118
  }
112
119
  else {
113
120
  const result = await db.executeSet([{ statement: query, values: params }], false);
114
121
  return {
115
- insertId: (_b = result.changes) === null || _b === void 0 ? void 0 : _b.lastId,
116
- rowsAffected: (_d = (_c = result.changes) === null || _c === void 0 ? void 0 : _c.changes) !== null && _d !== void 0 ? _d : 0,
122
+ insertId: (_a = result.changes) === null || _a === void 0 ? void 0 : _a.lastId,
123
+ rowsAffected: (_c = (_b = result.changes) === null || _b === void 0 ? void 0 : _b.changes) !== null && _c !== void 0 ? _c : 0,
117
124
  rows: {
118
125
  _array: [],
119
126
  length: 0,
@@ -124,10 +131,10 @@ export class CapacitorSQLiteAdapter extends BaseObserver {
124
131
  }
125
132
  // iOS (and other platforms): use run("all")
126
133
  const result = await db.run(query, params, false, 'all');
127
- const resultSet = (_f = (_e = result.changes) === null || _e === void 0 ? void 0 : _e.values) !== null && _f !== void 0 ? _f : [];
134
+ const resultSet = (_e = (_d = result.changes) === null || _d === void 0 ? void 0 : _d.values) !== null && _e !== void 0 ? _e : [];
128
135
  return {
129
- insertId: (_g = result.changes) === null || _g === void 0 ? void 0 : _g.lastId,
130
- rowsAffected: (_j = (_h = result.changes) === null || _h === void 0 ? void 0 : _h.changes) !== null && _j !== void 0 ? _j : 0,
136
+ insertId: (_f = result.changes) === null || _f === void 0 ? void 0 : _f.lastId,
137
+ rowsAffected: (_h = (_g = result.changes) === null || _g === void 0 ? void 0 : _g.changes) !== null && _h !== void 0 ? _h : 0,
131
138
  rows: {
132
139
  _array: resultSet,
133
140
  length: resultSet.length,
@@ -138,22 +145,9 @@ export class CapacitorSQLiteAdapter extends BaseObserver {
138
145
  const execute = this.options.debugMode
139
146
  ? (sql, params) => monitorQuery(sql, () => _execute(sql, params))
140
147
  : _execute;
141
- const _executeQuery = async (query, params) => {
142
- var _a;
143
- let result = await db.query(query, params);
144
- let arrayResult = (_a = result.values) !== null && _a !== void 0 ? _a : [];
145
- return {
146
- rowsAffected: 0,
147
- rows: {
148
- _array: arrayResult,
149
- length: arrayResult.length,
150
- item: (idx) => arrayResult[idx]
151
- }
152
- };
153
- };
154
148
  const executeQuery = this.options.debugMode
155
- ? (sql, params) => monitorQuery(sql, () => _executeQuery(sql, params))
156
- : _executeQuery;
149
+ ? (sql, params) => monitorQuery(sql, () => _query(sql, params))
150
+ : _query;
157
151
  const getAll = async (query, params) => {
158
152
  var _a, _b;
159
153
  const result = await executeQuery(query, params);
@@ -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,EAQb,MAAM,gBAAgB,CAAC;AACxB,OAAO,IAAI,MAAM,YAAY,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAqC,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACzG;;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,OAAO,CAAC,SAA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;YAC3B,MAAM,MAAM,GAAG,MAAM,EAAE,iCAClB,GAAG,KACN,MAAM;gBACN,QAAQ,IACR,CAAC;YACH,MAAM,MAAM,EAAE,CAAC;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 QueryResult,\n Transaction\n} from '@powersync/web';\nimport Lock from 'async-lock';\nimport { PowerSyncCore } from '../plugin/PowerSyncCore';\nimport { messageForErrorCode } from '../plugin/PowerSyncPlugin';\nimport { CapacitorSQLiteOpenFactoryOptions, DEFAULT_SQLITE_OPTIONS } from './CapacitorSQLiteOpenFactory';\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 lock: Lock;\n\n constructor(protected options: CapacitorSQLiteOpenFactoryOptions) {\n super();\n this._writeConnection = null;\n this._readConnection = null;\n this.lock = new Lock();\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 _execute = async (query: string, params: any[] = []): Promise<QueryResult> => {\n const platform = Capacitor.getPlatform();\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 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 } 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 = async (query: string, params?: any[]): Promise<QueryResult> => {\n let result = await db.query(query, params);\n\n let arrayResult = result.values ?? [];\n\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 executeQuery = this.options.debugMode\n ? (sql: string, params?: any[]) => monitorQuery(sql, () => _executeQuery(sql, params))\n : _executeQuery;\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 this.lock.acquire('read_lock', async () => {\n await this.initializedPromise;\n return await fn(this.generateLockContext(this.readConnection));\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 this.lock.acquire('write_lock', 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 }\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,C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AAC,CAAC;QAC/B,CAAC,CAAC;QACF,MAAM,QAAQ,GAAG,KAAK,IAA0B,EAAE;YAChD,IAAI,SAAS,EAAE,CAAC;gBACd,OAAO,EAAE,YAAY,EAAE,CAAC,EAAE,CAAC;YAC7B,CAAC;YACD,SAAS,GAAG,IAAI,CAAC;YACjB,OAAO,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QACjC,CAAC,CAAC;QACF,IAAI,CAAC;YACH,MAAM,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAC3B,MAAM,MAAM,GAAG,MAAM,EAAE,iCAClB,GAAG,KACN,MAAM;gBACN,QAAQ,IACR,CAAC;YACH,MAAM,MAAM,EAAE,CAAC;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 QueryResult,\n Transaction\n} from '@powersync/web';\nimport Lock from 'async-lock';\nimport { PowerSyncCore } from '../plugin/PowerSyncCore';\nimport { messageForErrorCode } from '../plugin/PowerSyncPlugin';\nimport { CapacitorSQLiteOpenFactoryOptions, DEFAULT_SQLITE_OPTIONS } from './CapacitorSQLiteOpenFactory';\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 lock: Lock;\n\n constructor(protected options: CapacitorSQLiteOpenFactoryOptions) {\n super();\n this._writeConnection = null;\n this._readConnection = null;\n this.lock = new Lock();\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 this.lock.acquire('read_lock', async () => {\n await this.initializedPromise;\n return await fn(this.generateLockContext(this.readConnection));\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 this.lock.acquire('write_lock', 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 }\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"]}
@@ -124,29 +124,36 @@ class CapacitorSQLiteAdapter extends web$1.BaseObserver {
124
124
  await this.readConnection.close();
125
125
  }
126
126
  generateLockContext(db) {
127
+ const _query = async (query, params = []) => {
128
+ var _a;
129
+ const result = await db.query(query, params);
130
+ const arrayResult = (_a = result.values) !== null && _a !== void 0 ? _a : [];
131
+ return {
132
+ rowsAffected: 0,
133
+ rows: {
134
+ _array: arrayResult,
135
+ length: arrayResult.length,
136
+ item: (idx) => arrayResult[idx]
137
+ }
138
+ };
139
+ };
127
140
  const _execute = async (query, params = []) => {
128
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
141
+ var _a, _b, _c, _d, _e, _f, _g, _h;
129
142
  const platform = core.Capacitor.getPlatform();
143
+ if (db.getConnectionReadOnly()) {
144
+ return _query(query, params);
145
+ }
130
146
  if (platform == 'android') {
131
147
  // Android: use query for SELECT and executeSet for mutations
132
148
  // We cannot use `run` here for both cases.
133
149
  if (query.toLowerCase().trim().startsWith('select')) {
134
- const result = await db.query(query, params);
135
- const arrayResult = (_a = result.values) !== null && _a !== void 0 ? _a : [];
136
- return {
137
- rowsAffected: 0,
138
- rows: {
139
- _array: arrayResult,
140
- length: arrayResult.length,
141
- item: (idx) => arrayResult[idx]
142
- }
143
- };
150
+ return _query(query, params);
144
151
  }
145
152
  else {
146
153
  const result = await db.executeSet([{ statement: query, values: params }], false);
147
154
  return {
148
- insertId: (_b = result.changes) === null || _b === void 0 ? void 0 : _b.lastId,
149
- rowsAffected: (_d = (_c = result.changes) === null || _c === void 0 ? void 0 : _c.changes) !== null && _d !== void 0 ? _d : 0,
155
+ insertId: (_a = result.changes) === null || _a === void 0 ? void 0 : _a.lastId,
156
+ rowsAffected: (_c = (_b = result.changes) === null || _b === void 0 ? void 0 : _b.changes) !== null && _c !== void 0 ? _c : 0,
150
157
  rows: {
151
158
  _array: [],
152
159
  length: 0,
@@ -157,10 +164,10 @@ class CapacitorSQLiteAdapter extends web$1.BaseObserver {
157
164
  }
158
165
  // iOS (and other platforms): use run("all")
159
166
  const result = await db.run(query, params, false, 'all');
160
- const resultSet = (_f = (_e = result.changes) === null || _e === void 0 ? void 0 : _e.values) !== null && _f !== void 0 ? _f : [];
167
+ const resultSet = (_e = (_d = result.changes) === null || _d === void 0 ? void 0 : _d.values) !== null && _e !== void 0 ? _e : [];
161
168
  return {
162
- insertId: (_g = result.changes) === null || _g === void 0 ? void 0 : _g.lastId,
163
- rowsAffected: (_j = (_h = result.changes) === null || _h === void 0 ? void 0 : _h.changes) !== null && _j !== void 0 ? _j : 0,
169
+ insertId: (_f = result.changes) === null || _f === void 0 ? void 0 : _f.lastId,
170
+ rowsAffected: (_h = (_g = result.changes) === null || _g === void 0 ? void 0 : _g.changes) !== null && _h !== void 0 ? _h : 0,
164
171
  rows: {
165
172
  _array: resultSet,
166
173
  length: resultSet.length,
@@ -171,22 +178,9 @@ class CapacitorSQLiteAdapter extends web$1.BaseObserver {
171
178
  const execute = this.options.debugMode
172
179
  ? (sql, params) => monitorQuery(sql, () => _execute(sql, params))
173
180
  : _execute;
174
- const _executeQuery = async (query, params) => {
175
- var _a;
176
- let result = await db.query(query, params);
177
- let arrayResult = (_a = result.values) !== null && _a !== void 0 ? _a : [];
178
- return {
179
- rowsAffected: 0,
180
- rows: {
181
- _array: arrayResult,
182
- length: arrayResult.length,
183
- item: (idx) => arrayResult[idx]
184
- }
185
- };
186
- };
187
181
  const executeQuery = this.options.debugMode
188
- ? (sql, params) => monitorQuery(sql, () => _executeQuery(sql, params))
189
- : _executeQuery;
182
+ ? (sql, params) => monitorQuery(sql, () => _query(sql, params))
183
+ : _query;
190
184
  const getAll = async (query, params) => {
191
185
  var _a, _b;
192
186
  const result = await executeQuery(query, params);
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs.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').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';\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 } from '@powersync/web';\nimport Lock from 'async-lock';\nimport { PowerSyncCore } from '../plugin/PowerSyncCore';\nimport { messageForErrorCode } from '../plugin/PowerSyncPlugin';\nimport { DEFAULT_SQLITE_OPTIONS } from './CapacitorSQLiteOpenFactory';\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.lock = new Lock();\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 _execute = async (query, params = []) => {\n var _a, _b, _c, _d, _e, _f, _g, _h, _j;\n const platform = Capacitor.getPlatform();\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 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 else {\n const result = await db.executeSet([{ statement: query, values: params }], false);\n return {\n insertId: (_b = result.changes) === null || _b === void 0 ? void 0 : _b.lastId,\n rowsAffected: (_d = (_c = result.changes) === null || _c === void 0 ? void 0 : _c.changes) !== null && _d !== void 0 ? _d : 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 = (_f = (_e = result.changes) === null || _e === void 0 ? void 0 : _e.values) !== null && _f !== void 0 ? _f : [];\n return {\n insertId: (_g = result.changes) === null || _g === void 0 ? void 0 : _g.lastId,\n rowsAffected: (_j = (_h = result.changes) === null || _h === void 0 ? void 0 : _h.changes) !== null && _j !== void 0 ? _j : 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 = async (query, params) => {\n var _a;\n let result = await db.query(query, params);\n let 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 executeQuery = this.options.debugMode\n ? (sql, params) => monitorQuery(sql, () => _executeQuery(sql, params))\n : _executeQuery;\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 this.lock.acquire('read_lock', async () => {\n await this.initializedPromise;\n return await fn(this.generateLockContext(this.readConnection));\n });\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 this.lock.acquire('write_lock', 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 });\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 } from '@powersync/web';\nimport Lock from 'async-lock';\nexport class CapacitorStreamingSyncImplementation extends AbstractStreamingSyncImplementation {\n async obtainLock(lockOptions) {\n const identifier = `streaming-sync-${lockOptions.type}-${this.options.identifier}`;\n return CapacitorStreamingSyncImplementation.GLOBAL_LOCK.acquire(identifier, 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}\nCapacitorStreamingSyncImplementation.GLOBAL_LOCK = new Lock();\n//# sourceMappingURL=CapacitorSyncImplementation.js.map","import { Capacitor } from '@capacitor/core';\nimport { PowerSyncDatabase as WebPowerSyncDatabase, WebRemote } from '@powersync/web';\nimport { CapacitorSQLiteAdapter } from './adapter/CapacitorSQLiteAdapter';\nimport { CapacitorStreamingSyncImplementation } from './sync/CapacitorSyncImplementation';\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 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","sqlite","SQLiteConnection","CapacitorSQLite","Capacitor","AbstractStreamingSyncImplementation","WebPowerSyncDatabase","WebRemote","WebPlugin"],"mappings":";;;;;;;AACO,MAAM,aAAa,GAAGA,mBAAc,CAAC,WAAW,EAAE;AACzD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,YAAY,EAAE;AAC/D,CAAC,CAAC;;ACHK,MAAM,mBAAmB,GAAG,CAAC,IAAI,KAAK;AAC7C,IAAI,QAAQ,IAAI;AAChB,QAAQ,KAAK,CAAC;AACd,YAAY,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AAM,CAAC,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,YAAY,EAAE,OAAO,CAAC,YAAY,EAAE,oBAAoB,EAAE,OAAO,CAAC,oBAAoB,EAAE,OAAO,EAAE,IAAI,CAAC,oBAAoB,EAAE,MAAM,EAAE,UAAU,EAAE,YAAY;AACzQ,oBAAoB,MAAM,IAAI,CAAC,YAAY,EAAE;AAC7C,oBAAoB,MAAM,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC;AACpD,gBAAgB,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;AAChH,QAAQ;AACR,aAAa;AACb,YAAY,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,sDAAsD,CAAC,CAAC;AACvF,YAAY,OAAO,KAAK,CAAC,gCAAgC,CAAC,SAAS,EAAE,OAAO,CAAC;AAC7E,QAAQ;AACR,IAAI;AACJ;;ACjEO,MAAM,YAAY,SAASC,cAAS,CAAC;AAC5C,IAAI,MAAM,YAAY,GAAG;AACzB,QAAQ,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC;AAClE,IAAI;AACJ;;;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.cjs.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').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';\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 } from '@powersync/web';\nimport Lock from 'async-lock';\nimport { PowerSyncCore } from '../plugin/PowerSyncCore';\nimport { messageForErrorCode } from '../plugin/PowerSyncPlugin';\nimport { DEFAULT_SQLITE_OPTIONS } from './CapacitorSQLiteOpenFactory';\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.lock = new Lock();\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 this.lock.acquire('read_lock', async () => {\n await this.initializedPromise;\n return await fn(this.generateLockContext(this.readConnection));\n });\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 this.lock.acquire('write_lock', 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 });\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 } from '@powersync/web';\nimport Lock from 'async-lock';\nexport class CapacitorStreamingSyncImplementation extends AbstractStreamingSyncImplementation {\n async obtainLock(lockOptions) {\n const identifier = `streaming-sync-${lockOptions.type}-${this.options.identifier}`;\n return CapacitorStreamingSyncImplementation.GLOBAL_LOCK.acquire(identifier, 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}\nCapacitorStreamingSyncImplementation.GLOBAL_LOCK = new Lock();\n//# sourceMappingURL=CapacitorSyncImplementation.js.map","import { Capacitor } from '@capacitor/core';\nimport { PowerSyncDatabase as WebPowerSyncDatabase, WebRemote } from '@powersync/web';\nimport { CapacitorSQLiteAdapter } from './adapter/CapacitorSQLiteAdapter';\nimport { CapacitorStreamingSyncImplementation } from './sync/CapacitorSyncImplementation';\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 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","sqlite","SQLiteConnection","CapacitorSQLite","Capacitor","AbstractStreamingSyncImplementation","WebPowerSyncDatabase","WebRemote","WebPlugin"],"mappings":";;;;;;;AACO,MAAM,aAAa,GAAGA,mBAAc,CAAC,WAAW,EAAE;AACzD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,YAAY,EAAE;AAC/D,CAAC,CAAC;;ACHK,MAAM,mBAAmB,GAAG,CAAC,IAAI,KAAK;AAC7C,IAAI,QAAQ,IAAI;AAChB,QAAQ,KAAK,CAAC;AACd,YAAY,OAAO,SAAS;AAC5B,QAAQ;AACR,YAAY,OAAO,CAAC,sDAAsD,EAAE,IAAI,CAAC,CAAC;AAClF;AACA,CAAC;;ACND,IAAI,iBAAiB;AACrB,CAAC,UAAU,iBAAiB,EAAE;AAC9B,IAAI,iBAAiB,CAAC,QAAQ,CAAC,GAAG,QAAQ;AAC1C,IAAI,iBAAiB,CAAC,MAAM,CAAC,GAAG,MAAM;AACtC,IAAI,iBAAiB,CAAC,KAAK,CAAC,GAAG,KAAK;AACpC,CAAC,EAAE,iBAAiB,KAAK,iBAAiB,GAAG,EAAE,CAAC,CAAC;AAC1C,MAAM,sBAAsB,GAAG;AACtC,IAAI,gBAAgB,EAAE,CAAC,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AAI,MAAM,YAAY,GAAG;AACzB,QAAQ,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC;AAClE,IAAI;AACJ;;;;;;;;;;;"}
package/dist/plugin.js CHANGED
@@ -120,29 +120,36 @@ var capacitorPowerSync = (function (exports, sqlite, core, web$1, Lock) {
120
120
  await this.readConnection.close();
121
121
  }
122
122
  generateLockContext(db) {
123
+ const _query = async (query, params = []) => {
124
+ var _a;
125
+ const result = await db.query(query, params);
126
+ const arrayResult = (_a = result.values) !== null && _a !== void 0 ? _a : [];
127
+ return {
128
+ rowsAffected: 0,
129
+ rows: {
130
+ _array: arrayResult,
131
+ length: arrayResult.length,
132
+ item: (idx) => arrayResult[idx]
133
+ }
134
+ };
135
+ };
123
136
  const _execute = async (query, params = []) => {
124
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
137
+ var _a, _b, _c, _d, _e, _f, _g, _h;
125
138
  const platform = core.Capacitor.getPlatform();
139
+ if (db.getConnectionReadOnly()) {
140
+ return _query(query, params);
141
+ }
126
142
  if (platform == 'android') {
127
143
  // Android: use query for SELECT and executeSet for mutations
128
144
  // We cannot use `run` here for both cases.
129
145
  if (query.toLowerCase().trim().startsWith('select')) {
130
- const result = await db.query(query, params);
131
- const arrayResult = (_a = result.values) !== null && _a !== void 0 ? _a : [];
132
- return {
133
- rowsAffected: 0,
134
- rows: {
135
- _array: arrayResult,
136
- length: arrayResult.length,
137
- item: (idx) => arrayResult[idx]
138
- }
139
- };
146
+ return _query(query, params);
140
147
  }
141
148
  else {
142
149
  const result = await db.executeSet([{ statement: query, values: params }], false);
143
150
  return {
144
- insertId: (_b = result.changes) === null || _b === void 0 ? void 0 : _b.lastId,
145
- rowsAffected: (_d = (_c = result.changes) === null || _c === void 0 ? void 0 : _c.changes) !== null && _d !== void 0 ? _d : 0,
151
+ insertId: (_a = result.changes) === null || _a === void 0 ? void 0 : _a.lastId,
152
+ rowsAffected: (_c = (_b = result.changes) === null || _b === void 0 ? void 0 : _b.changes) !== null && _c !== void 0 ? _c : 0,
146
153
  rows: {
147
154
  _array: [],
148
155
  length: 0,
@@ -153,10 +160,10 @@ var capacitorPowerSync = (function (exports, sqlite, core, web$1, Lock) {
153
160
  }
154
161
  // iOS (and other platforms): use run("all")
155
162
  const result = await db.run(query, params, false, 'all');
156
- const resultSet = (_f = (_e = result.changes) === null || _e === void 0 ? void 0 : _e.values) !== null && _f !== void 0 ? _f : [];
163
+ const resultSet = (_e = (_d = result.changes) === null || _d === void 0 ? void 0 : _d.values) !== null && _e !== void 0 ? _e : [];
157
164
  return {
158
- insertId: (_g = result.changes) === null || _g === void 0 ? void 0 : _g.lastId,
159
- rowsAffected: (_j = (_h = result.changes) === null || _h === void 0 ? void 0 : _h.changes) !== null && _j !== void 0 ? _j : 0,
165
+ insertId: (_f = result.changes) === null || _f === void 0 ? void 0 : _f.lastId,
166
+ rowsAffected: (_h = (_g = result.changes) === null || _g === void 0 ? void 0 : _g.changes) !== null && _h !== void 0 ? _h : 0,
160
167
  rows: {
161
168
  _array: resultSet,
162
169
  length: resultSet.length,
@@ -167,22 +174,9 @@ var capacitorPowerSync = (function (exports, sqlite, core, web$1, Lock) {
167
174
  const execute = this.options.debugMode
168
175
  ? (sql, params) => monitorQuery(sql, () => _execute(sql, params))
169
176
  : _execute;
170
- const _executeQuery = async (query, params) => {
171
- var _a;
172
- let result = await db.query(query, params);
173
- let arrayResult = (_a = result.values) !== null && _a !== void 0 ? _a : [];
174
- return {
175
- rowsAffected: 0,
176
- rows: {
177
- _array: arrayResult,
178
- length: arrayResult.length,
179
- item: (idx) => arrayResult[idx]
180
- }
181
- };
182
- };
183
177
  const executeQuery = this.options.debugMode
184
- ? (sql, params) => monitorQuery(sql, () => _executeQuery(sql, params))
185
- : _executeQuery;
178
+ ? (sql, params) => monitorQuery(sql, () => _query(sql, params))
179
+ : _query;
186
180
  const getAll = async (query, params) => {
187
181
  var _a, _b;
188
182
  const result = await executeQuery(query, params);
@@ -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').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';\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 } from '@powersync/web';\nimport Lock from 'async-lock';\nimport { PowerSyncCore } from '../plugin/PowerSyncCore';\nimport { messageForErrorCode } from '../plugin/PowerSyncPlugin';\nimport { DEFAULT_SQLITE_OPTIONS } from './CapacitorSQLiteOpenFactory';\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.lock = new Lock();\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 _execute = async (query, params = []) => {\n var _a, _b, _c, _d, _e, _f, _g, _h, _j;\n const platform = Capacitor.getPlatform();\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 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 else {\n const result = await db.executeSet([{ statement: query, values: params }], false);\n return {\n insertId: (_b = result.changes) === null || _b === void 0 ? void 0 : _b.lastId,\n rowsAffected: (_d = (_c = result.changes) === null || _c === void 0 ? void 0 : _c.changes) !== null && _d !== void 0 ? _d : 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 = (_f = (_e = result.changes) === null || _e === void 0 ? void 0 : _e.values) !== null && _f !== void 0 ? _f : [];\n return {\n insertId: (_g = result.changes) === null || _g === void 0 ? void 0 : _g.lastId,\n rowsAffected: (_j = (_h = result.changes) === null || _h === void 0 ? void 0 : _h.changes) !== null && _j !== void 0 ? _j : 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 = async (query, params) => {\n var _a;\n let result = await db.query(query, params);\n let 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 executeQuery = this.options.debugMode\n ? (sql, params) => monitorQuery(sql, () => _executeQuery(sql, params))\n : _executeQuery;\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 this.lock.acquire('read_lock', async () => {\n await this.initializedPromise;\n return await fn(this.generateLockContext(this.readConnection));\n });\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 this.lock.acquire('write_lock', 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 });\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 } from '@powersync/web';\nimport Lock from 'async-lock';\nexport class CapacitorStreamingSyncImplementation extends AbstractStreamingSyncImplementation {\n async obtainLock(lockOptions) {\n const identifier = `streaming-sync-${lockOptions.type}-${this.options.identifier}`;\n return CapacitorStreamingSyncImplementation.GLOBAL_LOCK.acquire(identifier, 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}\nCapacitorStreamingSyncImplementation.GLOBAL_LOCK = new Lock();\n//# sourceMappingURL=CapacitorSyncImplementation.js.map","import { Capacitor } from '@capacitor/core';\nimport { PowerSyncDatabase as WebPowerSyncDatabase, WebRemote } from '@powersync/web';\nimport { CapacitorSQLiteAdapter } from './adapter/CapacitorSQLiteAdapter';\nimport { CapacitorStreamingSyncImplementation } from './sync/CapacitorSyncImplementation';\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 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","sqlite","SQLiteConnection","CapacitorSQLite","Capacitor","AbstractStreamingSyncImplementation","WebPowerSyncDatabase","WebRemote","WebPlugin"],"mappings":";;;IACO,MAAM,aAAa,GAAGA,mBAAc,CAAC,WAAW,EAAE;IACzD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,YAAY,EAAE;IAC/D,CAAC,CAAC;;ICHK,MAAM,mBAAmB,GAAG,CAAC,IAAI,KAAK;IA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O,IAAI,oCAAoC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,YAAY,EAAE,OAAO,CAAC,YAAY,EAAE,oBAAoB,EAAE,OAAO,CAAC,oBAAoB,EAAE,OAAO,EAAE,IAAI,CAAC,oBAAoB,EAAE,MAAM,EAAE,UAAU,EAAE,YAAY;IACzQ,oBAAoB,MAAM,IAAI,CAAC,YAAY,EAAE;IAC7C,oBAAoB,MAAM,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC;IACpD,gBAAgB,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;IAChH,QAAQ;IACR,aAAa;IACb,YAAY,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,sDAAsD,CAAC,CAAC;IACvF,YAAY,OAAO,KAAK,CAAC,gCAAgC,CAAC,SAAS,EAAE,OAAO,CAAC;IAC7E,QAAQ;IACR,IAAI;IACJ;;ICjEO,MAAM,YAAY,SAASC,cAAS,CAAC;IAC5C,IAAI,MAAM,YAAY,GAAG;IACzB,QAAQ,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC;IAClE,IAAI;IACJ;;;;;;;;;;;;;;;;;"}
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').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';\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 } from '@powersync/web';\nimport Lock from 'async-lock';\nimport { PowerSyncCore } from '../plugin/PowerSyncCore';\nimport { messageForErrorCode } from '../plugin/PowerSyncPlugin';\nimport { DEFAULT_SQLITE_OPTIONS } from './CapacitorSQLiteOpenFactory';\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.lock = new Lock();\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 this.lock.acquire('read_lock', async () => {\n await this.initializedPromise;\n return await fn(this.generateLockContext(this.readConnection));\n });\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 this.lock.acquire('write_lock', 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 });\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 } from '@powersync/web';\nimport Lock from 'async-lock';\nexport class CapacitorStreamingSyncImplementation extends AbstractStreamingSyncImplementation {\n async obtainLock(lockOptions) {\n const identifier = `streaming-sync-${lockOptions.type}-${this.options.identifier}`;\n return CapacitorStreamingSyncImplementation.GLOBAL_LOCK.acquire(identifier, 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}\nCapacitorStreamingSyncImplementation.GLOBAL_LOCK = new Lock();\n//# sourceMappingURL=CapacitorSyncImplementation.js.map","import { Capacitor } from '@capacitor/core';\nimport { PowerSyncDatabase as WebPowerSyncDatabase, WebRemote } from '@powersync/web';\nimport { CapacitorSQLiteAdapter } from './adapter/CapacitorSQLiteAdapter';\nimport { CapacitorStreamingSyncImplementation } from './sync/CapacitorSyncImplementation';\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 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","sqlite","SQLiteConnection","CapacitorSQLite","Capacitor","AbstractStreamingSyncImplementation","WebPowerSyncDatabase","WebRemote","WebPlugin"],"mappings":";;;IACO,MAAM,aAAa,GAAGA,mBAAc,CAAC,WAAW,EAAE;IACzD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,YAAY,EAAE;IAC/D,CAAC,CAAC;;ICHK,MAAM,mBAAmB,GAAG,CAAC,IAAI,KAAK;IAC7C,IAAI,QAAQ,IAAI;IAChB,QAAQ,KAAK,CAAC;IACd,YAAY,OAAO,SAAS;IAC5B,QAAQ;IACR,YAAY,OAAO,CAAC,sDAAsD,EAAE,IAAI,CAAC,CAAC;IAClF;IACA,CAAC;;ICND,IAAI,iBAAiB;IACrB,CAAC,UAAU,iBAAiB,EAAE;IAC9B,IAAI,iBAAiB,CAAC,QAAQ,CAAC,GAAG,QAAQ;IAC1C,IAAI,iBAAiB,CAAC,MAAM,CAAC,GAAG,MAAM;IACtC,IAAI,iBAAiB,CAAC,KAAK,CAAC,GAAG,KAAK;IACpC,CAAC,EAAE,iBAAiB,KAAK,iBAAiB,GAAG,EAAE,CAAC,CAAC;IA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AAI;IACJ;;ICjEO,MAAM,YAAY,SAASC,cAAS,CAAC;IAC5C,IAAI,MAAM,YAAY,GAAG;IACzB,QAAQ,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC;IAClE,IAAI;IACJ;;;;;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powersync/capacitor",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "Adds PowerSync Capacitor support for iOS/Android",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/",
@@ -53,7 +53,7 @@
53
53
  },
54
54
  "peerDependencies": {
55
55
  "@capacitor-community/sqlite": "^7.0.2",
56
- "@powersync/web": "^1.28.1"
56
+ "@powersync/web": "^1.30.0"
57
57
  },
58
58
  "swiftlint": "@ionic/swiftlint-config",
59
59
  "capacitor": {
@@ -118,22 +118,31 @@ export class CapacitorSQLiteAdapter extends BaseObserver<DBAdapterListener> impl
118
118
  }
119
119
 
120
120
  protected generateLockContext(db: SQLiteDBConnection): LockContext {
121
+ const _query = async (query: string, params: any[] = []) => {
122
+ const result = await db.query(query, params);
123
+ const arrayResult = result.values ?? [];
124
+ return {
125
+ rowsAffected: 0,
126
+ rows: {
127
+ _array: arrayResult,
128
+ length: arrayResult.length,
129
+ item: (idx: number) => arrayResult[idx]
130
+ }
131
+ };
132
+ };
133
+
121
134
  const _execute = async (query: string, params: any[] = []): Promise<QueryResult> => {
122
135
  const platform = Capacitor.getPlatform();
136
+
137
+ if (db.getConnectionReadOnly()) {
138
+ return _query(query, params);
139
+ }
140
+
123
141
  if (platform == 'android') {
124
142
  // Android: use query for SELECT and executeSet for mutations
125
143
  // We cannot use `run` here for both cases.
126
144
  if (query.toLowerCase().trim().startsWith('select')) {
127
- const result = await db.query(query, params);
128
- const arrayResult = result.values ?? [];
129
- return {
130
- rowsAffected: 0,
131
- rows: {
132
- _array: arrayResult,
133
- length: arrayResult.length,
134
- item: (idx: number) => arrayResult[idx]
135
- }
136
- };
145
+ return _query(query, params);
137
146
  } else {
138
147
  const result = await db.executeSet([{ statement: query, values: params }], false);
139
148
  return {
@@ -166,24 +175,9 @@ export class CapacitorSQLiteAdapter extends BaseObserver<DBAdapterListener> impl
166
175
  ? (sql: string, params?: any[]) => monitorQuery(sql, () => _execute(sql, params))
167
176
  : _execute;
168
177
 
169
- const _executeQuery = async (query: string, params?: any[]): Promise<QueryResult> => {
170
- let result = await db.query(query, params);
171
-
172
- let arrayResult = result.values ?? [];
173
-
174
- return {
175
- rowsAffected: 0,
176
- rows: {
177
- _array: arrayResult,
178
- length: arrayResult.length,
179
- item: (idx: number) => arrayResult[idx]
180
- }
181
- };
182
- };
183
-
184
178
  const executeQuery = this.options.debugMode
185
- ? (sql: string, params?: any[]) => monitorQuery(sql, () => _executeQuery(sql, params))
186
- : _executeQuery;
179
+ ? (sql: string, params?: any[]) => monitorQuery(sql, () => _query(sql, params))
180
+ : _query;
187
181
 
188
182
  const getAll = async <T>(query: string, params?: any[]): Promise<T[]> => {
189
183
  const result = await executeQuery(query, params);