@powersync/capacitor 0.0.0-dev-20260202162549 → 0.0.0-dev-20260216124709

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/docs.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "api": {
3
+ "name": "PowerSyncPlugin",
4
+ "slug": "powersyncplugin",
5
+ "docs": "",
6
+ "tags": [],
7
+ "methods": [
8
+ {
9
+ "name": "registerCore",
10
+ "signature": "() => Promise<RegistrationResponse>",
11
+ "parameters": [],
12
+ "returns": "Promise<RegistrationResponse>",
13
+ "tags": [],
14
+ "docs": "Registers the PowerSync core extension with the SQLite library.",
15
+ "complexTypes": [
16
+ "RegistrationResponse"
17
+ ],
18
+ "slug": "registercore"
19
+ }
20
+ ],
21
+ "properties": []
22
+ },
23
+ "interfaces": [],
24
+ "enums": [],
25
+ "typeAliases": [
26
+ {
27
+ "name": "RegistrationResponse",
28
+ "slug": "registrationresponse",
29
+ "docs": "",
30
+ "types": [
31
+ {
32
+ "text": "{\n /**\n * Zero for successful registration, non-zero for failure.\n */\n responseCode: number;\n}",
33
+ "complexTypes": []
34
+ }
35
+ ]
36
+ }
37
+ ],
38
+ "pluginConfigs": []
39
+ }
@@ -0,0 +1,16 @@
1
+ import { DBAdapter, PowerSyncBackendConnector, RequiredAdditionalConnectionOptions, StreamingSyncImplementation, TriggerManagerConfig, PowerSyncDatabase as WebPowerSyncDatabase, WebPowerSyncDatabaseOptionsWithSettings } from '@powersync/web';
2
+ /**
3
+ * PowerSyncDatabase class for managing database connections and sync implementations.
4
+ * This extends the WebPowerSyncDatabase to provide platform-specific implementations
5
+ * for Capacitor environments (iOS and Android).
6
+ *
7
+ * @experimental
8
+ * @alpha
9
+ */
10
+ export declare class PowerSyncDatabase extends WebPowerSyncDatabase {
11
+ protected get isNativeCapacitorPlatform(): boolean;
12
+ protected openDBAdapter(options: WebPowerSyncDatabaseOptionsWithSettings): DBAdapter;
13
+ protected generateTriggerManagerConfig(): TriggerManagerConfig;
14
+ protected runExclusive<T>(cb: () => Promise<T>): Promise<T>;
15
+ protected generateSyncStreamImplementation(connector: PowerSyncBackendConnector, options: RequiredAdditionalConnectionOptions): StreamingSyncImplementation;
16
+ }
@@ -0,0 +1,79 @@
1
+ import { Capacitor } from '@capacitor/core';
2
+ import { MEMORY_TRIGGER_CLAIM_MANAGER, PowerSyncDatabase as WebPowerSyncDatabase, WebRemote } from '@powersync/web';
3
+ import { CapacitorSQLiteAdapter } from './adapter/CapacitorSQLiteAdapter.js';
4
+ import { CapacitorStreamingSyncImplementation } from './sync/CapacitorSyncImplementation.js';
5
+ /**
6
+ * PowerSyncDatabase class for managing database connections and sync implementations.
7
+ * This extends the WebPowerSyncDatabase to provide platform-specific implementations
8
+ * for Capacitor environments (iOS and Android).
9
+ *
10
+ * @experimental
11
+ * @alpha
12
+ */
13
+ export class PowerSyncDatabase extends WebPowerSyncDatabase {
14
+ get isNativeCapacitorPlatform() {
15
+ const platform = Capacitor.getPlatform();
16
+ return platform == 'ios' || platform == 'android';
17
+ }
18
+ openDBAdapter(options) {
19
+ var _a, _b, _c;
20
+ const platform = Capacitor.getPlatform();
21
+ if (platform == 'ios' || platform == 'android') {
22
+ if (options.database.dbLocation) {
23
+ (_a = options.logger) === null || _a === void 0 ? void 0 : _a.warn(`
24
+ dbLocation is ignored on iOS and Android platforms.
25
+ The database directory can be configured in the Capacitor project.
26
+ See https://github.com/capacitor-community/sqlite?tab=readme-ov-file#installation`);
27
+ }
28
+ (_b = options.logger) === null || _b === void 0 ? void 0 : _b.debug(`Using CapacitorSQLiteAdapter for platform: ${platform}`);
29
+ return new CapacitorSQLiteAdapter(Object.assign({}, options.database));
30
+ }
31
+ else {
32
+ (_c = options.logger) === null || _c === void 0 ? void 0 : _c.debug(`Using default web adapter for web platform`);
33
+ return super.openDBAdapter(options);
34
+ }
35
+ }
36
+ generateTriggerManagerConfig() {
37
+ const config = super.generateTriggerManagerConfig();
38
+ if (this.isNativeCapacitorPlatform) {
39
+ /**
40
+ * We usually only ever have a single tab for capacitor.
41
+ * Avoiding navigator locks allows insecure contexts (during development).
42
+ */
43
+ config.claimManager = MEMORY_TRIGGER_CLAIM_MANAGER;
44
+ }
45
+ return config;
46
+ }
47
+ runExclusive(cb) {
48
+ if (this.isNativeCapacitorPlatform) {
49
+ // Use mutex for mobile platforms.
50
+ // This is mainly for testing purposes since navigator.locks require secure contexts.
51
+ return this.runExclusiveMutex.runExclusive(cb);
52
+ }
53
+ else {
54
+ // Use navigator.locks for web platform
55
+ return super.runExclusive(cb);
56
+ }
57
+ }
58
+ generateSyncStreamImplementation(connector, options) {
59
+ var _a;
60
+ if (this.isNativeCapacitorPlatform) {
61
+ // We don't want to support multi-tab on mobile platforms.
62
+ // We technically can, but it's not a common use case and requires additional work/testing.
63
+ this.logger.debug(`Using Capacitor sync implementation`);
64
+ if ((_a = this.options.flags) === null || _a === void 0 ? void 0 : _a.enableMultiTabs) {
65
+ this.logger.warn(`enableMultiTabs is not supported on Capacitor mobile platforms. Ignoring the flag.`);
66
+ }
67
+ const remote = new WebRemote(connector, this.logger);
68
+ return new CapacitorStreamingSyncImplementation(Object.assign(Object.assign({}, this.options), { retryDelayMs: options.retryDelayMs, crudUploadThrottleMs: options.crudUploadThrottleMs, adapter: this.bucketStorageAdapter, remote, uploadCrud: async () => {
69
+ await this.waitForReady();
70
+ await connector.uploadData(this);
71
+ }, identifier: this.database.name, logger: this.logger, subscriptions: options.subscriptions }));
72
+ }
73
+ else {
74
+ this.logger.debug(`Using default web sync implementation for web platform`);
75
+ return super.generateSyncStreamImplementation(connector, options);
76
+ }
77
+ }
78
+ }
79
+ //# sourceMappingURL=PowerSyncDatabase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PowerSyncDatabase.js","sourceRoot":"","sources":["../../src/PowerSyncDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAEL,4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5E,OAAO,KAAK,CAAC,gCAAgC,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QACpE,CAAC;IACH,CAAC;CACF","sourcesContent":["import { Capacitor } from '@capacitor/core';\nimport {\n DBAdapter,\n MEMORY_TRIGGER_CLAIM_MANAGER,\n PowerSyncBackendConnector,\n RequiredAdditionalConnectionOptions,\n StreamingSyncImplementation,\n TriggerManagerConfig,\n PowerSyncDatabase as WebPowerSyncDatabase,\n WebPowerSyncDatabaseOptionsWithSettings,\n WebRemote\n} from '@powersync/web';\nimport { CapacitorSQLiteAdapter } from './adapter/CapacitorSQLiteAdapter.js';\nimport { CapacitorStreamingSyncImplementation } from './sync/CapacitorSyncImplementation.js';\n\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 protected get isNativeCapacitorPlatform(): boolean {\n const platform = Capacitor.getPlatform();\n return platform == 'ios' || platform == 'android';\n }\n\n protected openDBAdapter(options: WebPowerSyncDatabaseOptionsWithSettings): DBAdapter {\n const platform = Capacitor.getPlatform();\n if (platform == 'ios' || platform == 'android') {\n if (options.database.dbLocation) {\n options.logger?.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 options.logger?.debug(`Using CapacitorSQLiteAdapter for platform: ${platform}`);\n return new CapacitorSQLiteAdapter({\n ...options.database\n });\n } else {\n options.logger?.debug(`Using default web adapter for web platform`);\n return super.openDBAdapter(options);\n }\n }\n\n protected generateTriggerManagerConfig(): TriggerManagerConfig {\n const config = super.generateTriggerManagerConfig();\n if (this.isNativeCapacitorPlatform) {\n /**\n * We usually only ever have a single tab for capacitor.\n * Avoiding navigator locks allows insecure contexts (during development).\n */\n config.claimManager = MEMORY_TRIGGER_CLAIM_MANAGER;\n }\n return config;\n }\n\n protected runExclusive<T>(cb: () => Promise<T>): Promise<T> {\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 } else {\n // Use navigator.locks for web platform\n return super.runExclusive(cb);\n }\n }\n\n protected generateSyncStreamImplementation(\n connector: PowerSyncBackendConnector,\n options: RequiredAdditionalConnectionOptions\n ): StreamingSyncImplementation {\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 (this.options.flags?.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\n return new CapacitorStreamingSyncImplementation({\n ...(this.options as {}),\n retryDelayMs: options.retryDelayMs,\n crudUploadThrottleMs: options.crudUploadThrottleMs,\n adapter: this.bucketStorageAdapter,\n remote,\n uploadCrud: async () => {\n await this.waitForReady();\n await connector.uploadData(this);\n },\n identifier: this.database.name,\n logger: this.logger,\n 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"]}
@@ -0,0 +1,37 @@
1
+ import { SQLiteDBConnection } from '@capacitor-community/sqlite';
2
+ import { BaseObserver, DBAdapter, DBAdapterListener, DBLockOptions, LockContext, QueryResult, Transaction } from '@powersync/web';
3
+ import { Mutex } from 'async-mutex';
4
+ import { CapacitorSQLiteOpenFactoryOptions } from './CapacitorSQLiteOpenFactory.js';
5
+ /**
6
+ * An implementation of {@link DBAdapter} using the Capacitor Community SQLite [plugin](https://github.com/capacitor-community/sqlite).
7
+ *
8
+ * @experimental
9
+ * @alpha This is currently experimental and may change without a major version bump.
10
+ */
11
+ export declare class CapacitorSQLiteAdapter extends BaseObserver<DBAdapterListener> implements DBAdapter {
12
+ protected options: CapacitorSQLiteOpenFactoryOptions;
13
+ protected _writeConnection: SQLiteDBConnection | null;
14
+ protected _readConnection: SQLiteDBConnection | null;
15
+ protected initializedPromise: Promise<void>;
16
+ protected writeMutex: Mutex;
17
+ protected readMutex: Mutex;
18
+ constructor(options: CapacitorSQLiteOpenFactoryOptions);
19
+ protected get writeConnection(): SQLiteDBConnection;
20
+ protected get readConnection(): SQLiteDBConnection;
21
+ get name(): string;
22
+ private init;
23
+ close(): Promise<void>;
24
+ protected generateLockContext(db: SQLiteDBConnection): LockContext;
25
+ execute(query: string, params?: any[]): Promise<QueryResult>;
26
+ executeRaw(query: string, params?: any[]): Promise<any[][]>;
27
+ executeBatch(query: string, params?: any[][]): Promise<QueryResult>;
28
+ readLock<T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions): Promise<T>;
29
+ readTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions): Promise<T>;
30
+ writeLock<T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions): Promise<T>;
31
+ writeTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions): Promise<T>;
32
+ refreshSchema(): Promise<void>;
33
+ getAll<T>(sql: string, parameters?: any[]): Promise<T[]>;
34
+ getOptional<T>(sql: string, parameters?: any[]): Promise<T | null>;
35
+ get<T>(sql: string, parameters?: any[]): Promise<T>;
36
+ protected internalTransaction<T>(ctx: LockContext, fn: (tx: Transaction) => Promise<T>): Promise<T>;
37
+ }
@@ -0,0 +1,290 @@
1
+ import { CapacitorSQLite, SQLiteConnection } from '@capacitor-community/sqlite';
2
+ import { Capacitor } from '@capacitor/core';
3
+ import { BaseObserver, mutexRunExclusive } from '@powersync/web';
4
+ import { Mutex } from 'async-mutex';
5
+ import { PowerSyncCore } from '../plugin/PowerSyncCore.js';
6
+ import { messageForErrorCode } from '../plugin/PowerSyncPlugin.js';
7
+ import { DEFAULT_SQLITE_OPTIONS } from './CapacitorSQLiteOpenFactory.js';
8
+ /**
9
+ * Monitors the execution time of a query and logs it to the performance timeline.
10
+ */
11
+ async function monitorQuery(sql, executor) {
12
+ const start = performance.now();
13
+ try {
14
+ const r = await executor();
15
+ performance.measure(`[SQL] ${sql}`, { start });
16
+ return r;
17
+ }
18
+ catch (e) {
19
+ performance.measure(`[SQL] [ERROR: ${e.message}] ${sql}`, { start });
20
+ throw e;
21
+ }
22
+ }
23
+ /**
24
+ * An implementation of {@link DBAdapter} using the Capacitor Community SQLite [plugin](https://github.com/capacitor-community/sqlite).
25
+ *
26
+ * @experimental
27
+ * @alpha This is currently experimental and may change without a major version bump.
28
+ */
29
+ export class CapacitorSQLiteAdapter extends BaseObserver {
30
+ constructor(options) {
31
+ super();
32
+ this.options = options;
33
+ this._writeConnection = null;
34
+ this._readConnection = null;
35
+ this.writeMutex = new Mutex();
36
+ this.readMutex = new Mutex();
37
+ this.initializedPromise = this.init();
38
+ }
39
+ get writeConnection() {
40
+ if (!this._writeConnection) {
41
+ throw new Error('Init not completed yet');
42
+ }
43
+ return this._writeConnection;
44
+ }
45
+ get readConnection() {
46
+ if (!this._readConnection) {
47
+ throw new Error('Init not completed yet');
48
+ }
49
+ return this._readConnection;
50
+ }
51
+ get name() {
52
+ return this.options.dbFilename;
53
+ }
54
+ async init() {
55
+ const { responseCode: registrationResponseCode } = await PowerSyncCore.registerCore();
56
+ if (registrationResponseCode != 0) {
57
+ throw new Error(`Could not register PowerSync core extension: ${messageForErrorCode(registrationResponseCode)}`);
58
+ }
59
+ const sqlite = new SQLiteConnection(CapacitorSQLite);
60
+ // It seems like the isConnection and retrieveConnection methods
61
+ // only check a JS side map of connections.
62
+ // On hot reload this JS cache can be cleared, while the connection
63
+ // still exists natively. and `createConnection` will fail if it already exists.
64
+ await sqlite.closeConnection(this.options.dbFilename, false).catch(() => { });
65
+ await sqlite.closeConnection(this.options.dbFilename, true).catch(() => { });
66
+ // TODO support encryption eventually
67
+ this._writeConnection = await sqlite.createConnection(this.options.dbFilename, false, 'no-encryption', 1, false);
68
+ this._readConnection = await sqlite.createConnection(this.options.dbFilename, false, 'no-encryption', 1, true);
69
+ await this._writeConnection.open();
70
+ const { cacheSizeKb, journalSizeLimit, synchronous } = Object.assign(Object.assign({}, DEFAULT_SQLITE_OPTIONS), this.options.sqliteOptions);
71
+ await this.writeConnection.query('PRAGMA journal_mode = WAL');
72
+ await this.writeConnection.query(`PRAGMA journal_size_limit = ${journalSizeLimit}`);
73
+ await this.writeConnection.query(`PRAGMA temp_store = memory`);
74
+ await this.writeConnection.query(`PRAGMA synchronous = ${synchronous}`);
75
+ await this.writeConnection.query(`PRAGMA cache_size = -${cacheSizeKb}`);
76
+ await this._readConnection.open();
77
+ const platform = Capacitor.getPlatform();
78
+ if (platform == 'android') {
79
+ /**
80
+ * SQLCipher for Android enables dynamic loading of extensions.
81
+ * On iOS we use a static auto extension registration.
82
+ */
83
+ const extensionQuery = "SELECT load_extension('libpowersync.so', 'sqlite3_powersync_init')";
84
+ await this.writeConnection.query(extensionQuery);
85
+ await this.readConnection.query(extensionQuery);
86
+ }
87
+ await this.writeConnection.query("SELECT powersync_update_hooks('install')");
88
+ }
89
+ async close() {
90
+ await this.initializedPromise;
91
+ await this.writeConnection.close();
92
+ await this.readConnection.close();
93
+ }
94
+ generateLockContext(db) {
95
+ const _query = async (query, params = []) => {
96
+ var _a;
97
+ const result = await db.query(query, params);
98
+ const arrayResult = (_a = result.values) !== null && _a !== void 0 ? _a : [];
99
+ return {
100
+ rowsAffected: 0,
101
+ rows: {
102
+ _array: arrayResult,
103
+ length: arrayResult.length,
104
+ item: (idx) => arrayResult[idx]
105
+ }
106
+ };
107
+ };
108
+ const _execute = async (query, params = []) => {
109
+ var _a, _b, _c, _d, _e, _f, _g, _h;
110
+ const platform = Capacitor.getPlatform();
111
+ if (db.getConnectionReadOnly()) {
112
+ return _query(query, params);
113
+ }
114
+ if (platform == 'android') {
115
+ // Android: use query for SELECT and executeSet for mutations
116
+ // We cannot use `run` here for both cases.
117
+ if (query.toLowerCase().trim().startsWith('select')) {
118
+ return _query(query, params);
119
+ }
120
+ else {
121
+ const result = await db.executeSet([{ statement: query, values: params }], false);
122
+ return {
123
+ insertId: (_a = result.changes) === null || _a === void 0 ? void 0 : _a.lastId,
124
+ rowsAffected: (_c = (_b = result.changes) === null || _b === void 0 ? void 0 : _b.changes) !== null && _c !== void 0 ? _c : 0,
125
+ rows: {
126
+ _array: [],
127
+ length: 0,
128
+ item: () => null
129
+ }
130
+ };
131
+ }
132
+ }
133
+ // iOS (and other platforms): use run("all")
134
+ const result = await db.run(query, params, false, 'all');
135
+ const resultSet = (_e = (_d = result.changes) === null || _d === void 0 ? void 0 : _d.values) !== null && _e !== void 0 ? _e : [];
136
+ return {
137
+ insertId: (_f = result.changes) === null || _f === void 0 ? void 0 : _f.lastId,
138
+ rowsAffected: (_h = (_g = result.changes) === null || _g === void 0 ? void 0 : _g.changes) !== null && _h !== void 0 ? _h : 0,
139
+ rows: {
140
+ _array: resultSet,
141
+ length: resultSet.length,
142
+ item: (idx) => resultSet[idx]
143
+ }
144
+ };
145
+ };
146
+ const execute = this.options.debugMode
147
+ ? (sql, params) => monitorQuery(sql, () => _execute(sql, params))
148
+ : _execute;
149
+ const executeQuery = this.options.debugMode
150
+ ? (sql, params) => monitorQuery(sql, () => _query(sql, params))
151
+ : _query;
152
+ const getAll = async (query, params) => {
153
+ var _a, _b;
154
+ const result = await executeQuery(query, params);
155
+ return (_b = (_a = result.rows) === null || _a === void 0 ? void 0 : _a._array) !== null && _b !== void 0 ? _b : [];
156
+ };
157
+ const getOptional = async (query, params) => {
158
+ const results = await getAll(query, params);
159
+ return results.length > 0 ? results[0] : null;
160
+ };
161
+ const get = async (query, params) => {
162
+ const result = await getOptional(query, params);
163
+ if (!result) {
164
+ throw new Error(`No results for query: ${query}`);
165
+ }
166
+ return result;
167
+ };
168
+ const executeRaw = async (query, params) => {
169
+ var _a, _b;
170
+ // This is a workaround, we don't support multiple columns of the same name
171
+ const results = await execute(query, params);
172
+ return (_b = (_a = results.rows) === null || _a === void 0 ? void 0 : _a._array.map((row) => Object.values(row))) !== null && _b !== void 0 ? _b : [];
173
+ };
174
+ return {
175
+ getAll,
176
+ getOptional,
177
+ get,
178
+ executeRaw,
179
+ execute
180
+ };
181
+ }
182
+ execute(query, params) {
183
+ return this.writeLock((tx) => tx.execute(query, params));
184
+ }
185
+ executeRaw(query, params) {
186
+ return this.writeLock((tx) => tx.executeRaw(query, params));
187
+ }
188
+ async executeBatch(query, params = []) {
189
+ return this.writeLock(async (tx) => {
190
+ var _a, _b, _c;
191
+ let result = await this.writeConnection.executeSet(params.map((param) => ({
192
+ statement: query,
193
+ values: param
194
+ })));
195
+ return {
196
+ rowsAffected: (_b = (_a = result.changes) === null || _a === void 0 ? void 0 : _a.changes) !== null && _b !== void 0 ? _b : 0,
197
+ insertId: (_c = result.changes) === null || _c === void 0 ? void 0 : _c.lastId
198
+ };
199
+ });
200
+ }
201
+ readLock(fn, options) {
202
+ return mutexRunExclusive(this.readMutex, async () => {
203
+ await this.initializedPromise;
204
+ return await fn(this.generateLockContext(this.readConnection));
205
+ }, options);
206
+ }
207
+ readTransaction(fn, options) {
208
+ return this.readLock(async (ctx) => {
209
+ return this.internalTransaction(ctx, fn);
210
+ });
211
+ }
212
+ writeLock(fn, options) {
213
+ return mutexRunExclusive(this.writeMutex, async () => {
214
+ var _a;
215
+ await this.initializedPromise;
216
+ const result = await fn(this.generateLockContext(this.writeConnection));
217
+ // Fetch table updates
218
+ const updates = await this.writeConnection.query("SELECT powersync_update_hooks('get') AS table_name");
219
+ const jsonUpdates = (_a = updates.values) === null || _a === void 0 ? void 0 : _a[0];
220
+ if (!jsonUpdates || !jsonUpdates.table_name) {
221
+ throw new Error('Could not fetch table updates');
222
+ }
223
+ const notification = {
224
+ rawUpdates: [],
225
+ tables: JSON.parse(jsonUpdates.table_name),
226
+ groupedUpdates: {}
227
+ };
228
+ this.iterateListeners((l) => { var _a; return (_a = l.tablesUpdated) === null || _a === void 0 ? void 0 : _a.call(l, notification); });
229
+ return result;
230
+ }, options);
231
+ }
232
+ writeTransaction(fn, options) {
233
+ return this.writeLock(async (ctx) => {
234
+ return this.internalTransaction(ctx, fn);
235
+ });
236
+ }
237
+ refreshSchema() {
238
+ return this.writeLock(async (writeTx) => {
239
+ return this.readLock(async (readTx) => {
240
+ const updateQuery = `PRAGMA table_info('sqlite_master')`;
241
+ await writeTx.get(updateQuery);
242
+ await readTx.get(updateQuery);
243
+ });
244
+ });
245
+ }
246
+ getAll(sql, parameters) {
247
+ return this.readLock((tx) => tx.getAll(sql, parameters));
248
+ }
249
+ getOptional(sql, parameters) {
250
+ return this.readLock((tx) => tx.getOptional(sql, parameters));
251
+ }
252
+ get(sql, parameters) {
253
+ return this.readLock((tx) => tx.get(sql, parameters));
254
+ }
255
+ async internalTransaction(ctx, fn) {
256
+ let finalized = false;
257
+ const commit = async () => {
258
+ if (finalized) {
259
+ return { rowsAffected: 0 };
260
+ }
261
+ finalized = true;
262
+ return ctx.execute('COMMIT');
263
+ };
264
+ const rollback = async () => {
265
+ if (finalized) {
266
+ return { rowsAffected: 0 };
267
+ }
268
+ finalized = true;
269
+ return ctx.execute('ROLLBACK');
270
+ };
271
+ try {
272
+ await ctx.execute('BEGIN');
273
+ const result = await fn(Object.assign(Object.assign({}, ctx), { commit,
274
+ rollback }));
275
+ await commit();
276
+ return result;
277
+ }
278
+ catch (ex) {
279
+ try {
280
+ await rollback();
281
+ }
282
+ catch (ex2) {
283
+ // In rare cases, a rollback may fail.
284
+ // Safe to ignore.
285
+ }
286
+ throw ex;
287
+ }
288
+ }
289
+ }
290
+ //# sourceMappingURL=CapacitorSQLiteAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CapacitorSQLiteAdapter.js","sourceRoot":"","sources":["../../../src/adapter/CapacitorSQLiteAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAsB,MAAM,6BAA6B,CAA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,CAAC;YACD,SAAS,GAAG,IAAI,CAAC;YACjB,OAAO,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,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 mutexRunExclusive,\n QueryResult,\n Transaction\n} from '@powersync/web';\nimport { Mutex } from 'async-mutex';\nimport { PowerSyncCore } from '../plugin/PowerSyncCore.js';\nimport { messageForErrorCode } from '../plugin/PowerSyncPlugin.js';\nimport { CapacitorSQLiteOpenFactoryOptions, DEFAULT_SQLITE_OPTIONS } from './CapacitorSQLiteOpenFactory.js';\n/**\n * Monitors the execution time of a query and logs it to the performance timeline.\n */\nasync function monitorQuery(sql: string, executor: () => Promise<QueryResult>): Promise<QueryResult> {\n const start = performance.now();\n try {\n const r = await executor();\n performance.measure(`[SQL] ${sql}`, { start });\n return r;\n } catch (e: any) {\n performance.measure(`[SQL] [ERROR: ${e.message}] ${sql}`, { start });\n throw e;\n }\n}\n/**\n * An implementation of {@link DBAdapter} using the Capacitor Community SQLite [plugin](https://github.com/capacitor-community/sqlite).\n *\n * @experimental\n * @alpha This is currently experimental and may change without a major version bump.\n */\nexport class CapacitorSQLiteAdapter extends BaseObserver<DBAdapterListener> implements DBAdapter {\n protected _writeConnection: SQLiteDBConnection | null;\n protected _readConnection: SQLiteDBConnection | null;\n protected initializedPromise: Promise<void>;\n protected writeMutex: Mutex;\n protected readMutex: Mutex;\n\n constructor(protected options: CapacitorSQLiteOpenFactoryOptions) {\n super();\n this._writeConnection = null;\n this._readConnection = null;\n this.writeMutex = new Mutex();\n this.readMutex = new Mutex();\n this.initializedPromise = this.init();\n }\n\n protected get writeConnection(): SQLiteDBConnection {\n if (!this._writeConnection) {\n throw new Error('Init not completed yet');\n }\n return this._writeConnection;\n }\n\n protected get readConnection(): SQLiteDBConnection {\n if (!this._readConnection) {\n throw new Error('Init not completed yet');\n }\n return this._readConnection;\n }\n\n get name() {\n return this.options.dbFilename;\n }\n\n private async init() {\n const { responseCode: registrationResponseCode } = await PowerSyncCore.registerCore();\n if (registrationResponseCode != 0) {\n throw new Error(`Could not register PowerSync core extension: ${messageForErrorCode(registrationResponseCode)}`);\n }\n\n const sqlite = new SQLiteConnection(CapacitorSQLite);\n\n // It seems like the isConnection and retrieveConnection methods\n // only check a JS side map of connections.\n // On hot reload this JS cache can be cleared, while the connection\n // still exists natively. and `createConnection` will fail if it already exists.\n await sqlite.closeConnection(this.options.dbFilename, false).catch(() => {});\n await sqlite.closeConnection(this.options.dbFilename, true).catch(() => {});\n\n // TODO support encryption eventually\n this._writeConnection = await sqlite.createConnection(this.options.dbFilename, false, 'no-encryption', 1, false);\n this._readConnection = await sqlite.createConnection(this.options.dbFilename, false, 'no-encryption', 1, true);\n\n await this._writeConnection.open();\n\n const { cacheSizeKb, journalSizeLimit, synchronous } = { ...DEFAULT_SQLITE_OPTIONS, ...this.options.sqliteOptions };\n\n await this.writeConnection.query('PRAGMA journal_mode = WAL');\n await this.writeConnection.query(`PRAGMA journal_size_limit = ${journalSizeLimit}`);\n await this.writeConnection.query(`PRAGMA temp_store = memory`);\n await this.writeConnection.query(`PRAGMA synchronous = ${synchronous}`);\n await this.writeConnection.query(`PRAGMA cache_size = -${cacheSizeKb}`);\n\n await this._readConnection.open();\n\n const platform = Capacitor.getPlatform();\n if (platform == 'android') {\n /**\n * SQLCipher for Android enables dynamic loading of extensions.\n * On iOS we use a static auto extension registration.\n */\n const extensionQuery = \"SELECT load_extension('libpowersync.so', 'sqlite3_powersync_init')\";\n await this.writeConnection.query(extensionQuery);\n await this.readConnection.query(extensionQuery);\n }\n await this.writeConnection.query(\"SELECT powersync_update_hooks('install')\");\n }\n\n async close(): Promise<void> {\n await this.initializedPromise;\n await this.writeConnection.close();\n await this.readConnection.close();\n }\n\n protected generateLockContext(db: SQLiteDBConnection): LockContext {\n const _query = async (query: string, params: any[] = []) => {\n const result = await db.query(query, params);\n const arrayResult = result.values ?? [];\n return {\n rowsAffected: 0,\n rows: {\n _array: arrayResult,\n length: arrayResult.length,\n item: (idx: number) => arrayResult[idx]\n }\n };\n };\n\n const _execute = async (query: string, params: any[] = []): Promise<QueryResult> => {\n const platform = Capacitor.getPlatform();\n\n if (db.getConnectionReadOnly()) {\n return _query(query, params);\n }\n\n if (platform == 'android') {\n // Android: use query for SELECT and executeSet for mutations\n // We cannot use `run` here for both cases.\n if (query.toLowerCase().trim().startsWith('select')) {\n return _query(query, params);\n } else {\n const result = await db.executeSet([{ statement: query, values: params }], false);\n return {\n insertId: result.changes?.lastId,\n rowsAffected: result.changes?.changes ?? 0,\n rows: {\n _array: [],\n length: 0,\n item: () => null\n }\n };\n }\n }\n\n // iOS (and other platforms): use run(\"all\")\n const result = await db.run(query, params, false, 'all');\n const resultSet = result.changes?.values ?? [];\n return {\n insertId: result.changes?.lastId,\n rowsAffected: result.changes?.changes ?? 0,\n rows: {\n _array: resultSet,\n length: resultSet.length,\n item: (idx) => resultSet[idx]\n }\n };\n };\n\n const execute = this.options.debugMode\n ? (sql: string, params?: any[]) => monitorQuery(sql, () => _execute(sql, params))\n : _execute;\n\n const executeQuery = this.options.debugMode\n ? (sql: string, params?: any[]) => monitorQuery(sql, () => _query(sql, params))\n : _query;\n\n const getAll = async <T>(query: string, params?: any[]): Promise<T[]> => {\n const result = await executeQuery(query, params);\n return result.rows?._array ?? ([] as T[]);\n };\n\n const getOptional = async <T>(query: string, params?: any[]): Promise<T | null> => {\n const results = await getAll<T>(query, params);\n return results.length > 0 ? results[0] : null;\n };\n\n const get = async <T>(query: string, params?: any[]): Promise<T> => {\n const result = await getOptional<T>(query, params);\n if (!result) {\n throw new Error(`No results for query: ${query}`);\n }\n return result;\n };\n\n const executeRaw = async (query: string, params?: any[]): Promise<any[][]> => {\n // This is a workaround, we don't support multiple columns of the same name\n const results = await execute(query, params);\n return results.rows?._array.map((row) => Object.values(row)) ?? [];\n };\n\n return {\n getAll,\n getOptional,\n get,\n executeRaw,\n execute\n };\n }\n\n execute(query: string, params?: any[]): Promise<QueryResult> {\n return this.writeLock((tx) => tx.execute(query, params));\n }\n\n executeRaw(query: string, params?: any[]): Promise<any[][]> {\n return this.writeLock((tx) => tx.executeRaw(query, params));\n }\n\n async executeBatch(query: string, params: any[][] = []): Promise<QueryResult> {\n return this.writeLock(async (tx) => {\n let result = await this.writeConnection.executeSet(\n params.map((param) => ({\n statement: query,\n values: param\n }))\n );\n\n return {\n rowsAffected: result.changes?.changes ?? 0,\n insertId: result.changes?.lastId\n };\n });\n }\n\n readLock<T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions): Promise<T> {\n return mutexRunExclusive(\n this.readMutex,\n async () => {\n await this.initializedPromise;\n return await fn(this.generateLockContext(this.readConnection));\n },\n options\n );\n }\n\n readTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions): Promise<T> {\n return this.readLock(async (ctx) => {\n return this.internalTransaction(ctx, fn);\n });\n }\n\n writeLock<T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions): Promise<T> {\n return mutexRunExclusive(\n this.writeMutex,\n async () => {\n await this.initializedPromise;\n const result = await fn(this.generateLockContext(this.writeConnection));\n\n // Fetch table updates\n const updates = await this.writeConnection.query(\"SELECT powersync_update_hooks('get') AS table_name\");\n const jsonUpdates = updates.values?.[0];\n if (!jsonUpdates || !jsonUpdates.table_name) {\n throw new Error('Could not fetch table updates');\n }\n const notification: BatchedUpdateNotification = {\n rawUpdates: [],\n tables: JSON.parse(jsonUpdates.table_name),\n groupedUpdates: {}\n };\n this.iterateListeners((l) => l.tablesUpdated?.(notification));\n return result;\n },\n options\n );\n }\n\n writeTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions): Promise<T> {\n return this.writeLock(async (ctx) => {\n return this.internalTransaction(ctx, fn);\n });\n }\n\n refreshSchema(): Promise<void> {\n return this.writeLock(async (writeTx) => {\n return this.readLock(async (readTx) => {\n const updateQuery = `PRAGMA table_info('sqlite_master')`;\n await writeTx.get(updateQuery);\n await readTx.get(updateQuery);\n });\n });\n }\n\n getAll<T>(sql: string, parameters?: any[]): Promise<T[]> {\n return this.readLock((tx) => tx.getAll<T>(sql, parameters));\n }\n\n getOptional<T>(sql: string, parameters?: any[]): Promise<T | null> {\n return this.readLock((tx) => tx.getOptional<T>(sql, parameters));\n }\n\n get<T>(sql: string, parameters?: any[]): Promise<T> {\n return this.readLock((tx) => tx.get<T>(sql, parameters));\n }\n\n protected async internalTransaction<T>(ctx: LockContext, fn: (tx: Transaction) => Promise<T>): Promise<T> {\n let finalized = false;\n const commit = async (): Promise<QueryResult> => {\n if (finalized) {\n return { rowsAffected: 0 };\n }\n finalized = true;\n return ctx.execute('COMMIT');\n };\n const rollback = async (): Promise<QueryResult> => {\n if (finalized) {\n return { rowsAffected: 0 };\n }\n finalized = true;\n return ctx.execute('ROLLBACK');\n };\n try {\n await ctx.execute('BEGIN');\n const result = await fn({\n ...ctx,\n commit,\n rollback\n });\n await commit();\n return result;\n } catch (ex) {\n try {\n await rollback();\n } catch (ex2) {\n // In rare cases, a rollback may fail.\n // Safe to ignore.\n }\n throw ex;\n }\n }\n}\n"]}
@@ -0,0 +1,35 @@
1
+ import { DBAdapter, SQLOpenFactory, SQLOpenOptions } from '@powersync/web';
2
+ declare enum SqliteSynchronous {
3
+ normal = "NORMAL",
4
+ full = "FULL",
5
+ off = "OFF"
6
+ }
7
+ export interface CapacitorSQLiteOptions {
8
+ /**
9
+ * Journal/WAL size limit. Defaults to 6MB.
10
+ * The WAL may grow larger than this limit during writes, but SQLite will
11
+ * attempt to truncate the file afterwards.
12
+ */
13
+ journalSizeLimit?: number;
14
+ /**
15
+ * SQLite synchronous flag. Defaults to [SqliteSynchronous.normal], which
16
+ * is safe for WAL mode.
17
+ */
18
+ synchronous?: SqliteSynchronous;
19
+ /**
20
+ * Maximum SQLite cache size. Defaults to 50MB.
21
+ *
22
+ * For details, see: https://www.sqlite.org/pragma.html#pragma_cache_size
23
+ */
24
+ cacheSizeKb?: number;
25
+ }
26
+ export interface CapacitorSQLiteOpenFactoryOptions extends SQLOpenOptions {
27
+ sqliteOptions?: CapacitorSQLiteOptions;
28
+ }
29
+ export declare const DEFAULT_SQLITE_OPTIONS: Required<CapacitorSQLiteOptions>;
30
+ export declare class CapacitorSQLiteOpenFactory implements SQLOpenFactory {
31
+ protected options: CapacitorSQLiteOpenFactoryOptions;
32
+ constructor(options: CapacitorSQLiteOpenFactoryOptions);
33
+ openDB(): DBAdapter;
34
+ }
35
+ export {};
@@ -0,0 +1,21 @@
1
+ import { CapacitorSQLiteAdapter } from './CapacitorSQLiteAdapter.js';
2
+ var SqliteSynchronous;
3
+ (function (SqliteSynchronous) {
4
+ SqliteSynchronous["normal"] = "NORMAL";
5
+ SqliteSynchronous["full"] = "FULL";
6
+ SqliteSynchronous["off"] = "OFF";
7
+ })(SqliteSynchronous || (SqliteSynchronous = {}));
8
+ export const DEFAULT_SQLITE_OPTIONS = {
9
+ journalSizeLimit: 6 * 1024 * 1024,
10
+ synchronous: SqliteSynchronous.normal,
11
+ cacheSizeKb: 50 * 1024
12
+ };
13
+ export class CapacitorSQLiteOpenFactory {
14
+ constructor(options) {
15
+ this.options = options;
16
+ }
17
+ openDB() {
18
+ return new CapacitorSQLiteAdapter(this.options);
19
+ }
20
+ }
21
+ //# sourceMappingURL=CapacitorSQLiteOpenFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CapacitorSQLiteOpenFactory.js","sourceRoot":"","sources":["../../../src/adapter/CapacitorSQLiteOpenFactory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAErE,IAAK,iBAIJ;AAJD,WAAK,iBAAiB;IACpB,sCAAiB,CAAA;IACjB,kCAAa,CAAA;IACb,gCAAW,CAAA;AACb,CAAC,EAJI,iBAAiB,KAAjB,iBAAiB,QAIrB;AA4BD,MAAM,CAAC,MAAM,sBAAsB,GAAqC;IACtE,gBAAgB,EAAE,CAAC,GAAG,IAAI,GAAG,IAAI;IACjC,WAAW,EAAE,iBAAiB,CAAC,MAAM;IACrC,WAAW,EAAE,EAAE,GAAG,IAAI;CACvB,CAAC;AAEF,MAAM,OAAO,0BAA0B;IACrC,YAAsB,OAA0C;QAA1C,YAAO,GAAP,OAAO,CAAmC;IAAG,CAAC;IAEpE,MAAM;QACJ,OAAO,IAAI,sBAAsB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAClD,CAAC;CACF","sourcesContent":["import { DBAdapter, SQLOpenFactory, SQLOpenOptions } from '@powersync/web';\nimport { CapacitorSQLiteAdapter } from './CapacitorSQLiteAdapter.js';\n\nenum SqliteSynchronous {\n normal = 'NORMAL',\n full = 'FULL',\n off = 'OFF'\n}\n\nexport interface CapacitorSQLiteOptions {\n /**\n * Journal/WAL size limit. Defaults to 6MB.\n * The WAL may grow larger than this limit during writes, but SQLite will\n * attempt to truncate the file afterwards.\n */\n journalSizeLimit?: number;\n\n /**\n * SQLite synchronous flag. Defaults to [SqliteSynchronous.normal], which\n * is safe for WAL mode.\n */\n synchronous?: SqliteSynchronous;\n\n /**\n * Maximum SQLite cache size. Defaults to 50MB.\n *\n * For details, see: https://www.sqlite.org/pragma.html#pragma_cache_size\n */\n cacheSizeKb?: number;\n}\n\nexport interface CapacitorSQLiteOpenFactoryOptions extends SQLOpenOptions {\n sqliteOptions?: CapacitorSQLiteOptions;\n}\n\nexport const DEFAULT_SQLITE_OPTIONS: Required<CapacitorSQLiteOptions> = {\n journalSizeLimit: 6 * 1024 * 1024,\n synchronous: SqliteSynchronous.normal,\n cacheSizeKb: 50 * 1024\n};\n\nexport class CapacitorSQLiteOpenFactory implements SQLOpenFactory {\n constructor(protected options: CapacitorSQLiteOpenFactoryOptions) {}\n\n openDB(): DBAdapter {\n return new CapacitorSQLiteAdapter(this.options);\n }\n}\n"]}
@@ -0,0 +1,3 @@
1
+ export { CapacitorSQLiteAdapter } from './adapter/CapacitorSQLiteAdapter.js';
2
+ export { CapacitorSQLiteOpenFactory } from './adapter/CapacitorSQLiteOpenFactory.js';
3
+ export { PowerSyncDatabase } from './PowerSyncDatabase.js';
@@ -0,0 +1,4 @@
1
+ export { CapacitorSQLiteAdapter } from './adapter/CapacitorSQLiteAdapter.js';
2
+ export { CapacitorSQLiteOpenFactory } from './adapter/CapacitorSQLiteOpenFactory.js';
3
+ export { PowerSyncDatabase } from './PowerSyncDatabase.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAC7E,OAAO,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAC;AACrF,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["export { CapacitorSQLiteAdapter } from './adapter/CapacitorSQLiteAdapter.js';\nexport { CapacitorSQLiteOpenFactory } from './adapter/CapacitorSQLiteOpenFactory.js';\nexport { PowerSyncDatabase } from './PowerSyncDatabase.js';\n\n"]}
@@ -0,0 +1,2 @@
1
+ import { PowerSyncPlugin } from './PowerSyncPlugin.js';
2
+ export declare const PowerSyncCore: PowerSyncPlugin;
@@ -0,0 +1,5 @@
1
+ import { registerPlugin } from '@capacitor/core';
2
+ export const PowerSyncCore = registerPlugin('PowerSync', {
3
+ web: () => import('./web.js').then((m) => new m.PowerSyncWeb())
4
+ });
5
+ //# sourceMappingURL=PowerSyncCore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PowerSyncCore.js","sourceRoot":"","sources":["../../../src/plugin/PowerSyncCore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGjD,MAAM,CAAC,MAAM,aAAa,GAAG,cAAc,CAAkB,WAAW,EAAE;IACxE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,CAAC;CAChE,CAAC,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\nimport { PowerSyncPlugin } from './PowerSyncPlugin.js';\n\nexport const PowerSyncCore = registerPlugin<PowerSyncPlugin>('PowerSync', {\n web: () => import('./web.js').then((m) => new m.PowerSyncWeb())\n});\n"]}
@@ -0,0 +1,13 @@
1
+ export type RegistrationResponse = {
2
+ /**
3
+ * Zero for successful registration, non-zero for failure.
4
+ */
5
+ responseCode: number;
6
+ };
7
+ export declare const messageForErrorCode: (code: number) => string;
8
+ export interface PowerSyncPlugin {
9
+ /**
10
+ * Registers the PowerSync core extension with the SQLite library.
11
+ */
12
+ registerCore(): Promise<RegistrationResponse>;
13
+ }