@powersync/web 0.0.0-dev-20241119081147 → 0.0.0-dev-20241203152232

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/dist/24cd027f23123a1360de.wasm +0 -0
  2. package/dist/_journeyapps_wa-sqlite-_journeyapps_wa-sqlite_src_examples_IDBBatchAtomicVFS_js-_powersync_co-780aa20.index.umd.js +335 -0
  3. package/dist/_journeyapps_wa-sqlite-_journeyapps_wa-sqlite_src_examples_IDBBatchAtomicVFS_js-_powersync_co-780aa20.index.umd.js.map +1 -0
  4. package/dist/_journeyapps_wa-sqlite-_journeyapps_wa-sqlite_src_examples_IDBBatchAtomicVFS_js-_powersync_co-780aa21.index.umd.js +335 -0
  5. package/dist/_journeyapps_wa-sqlite-_journeyapps_wa-sqlite_src_examples_IDBBatchAtomicVFS_js-_powersync_co-780aa21.index.umd.js.map +1 -0
  6. package/dist/f042552714d86563f127.wasm +0 -0
  7. package/dist/index.umd.js +3493 -623
  8. package/dist/index.umd.js.map +1 -1
  9. package/dist/worker/SharedSyncImplementation.umd.js +272 -2198
  10. package/dist/worker/SharedSyncImplementation.umd.js.map +1 -1
  11. package/dist/worker/WASQLiteDB.umd.js +900 -395
  12. package/dist/worker/WASQLiteDB.umd.js.map +1 -1
  13. package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_wa-sqlite-async_mjs.umd.js +2 -132
  14. package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_wa-sqlite-async_mjs.umd.js.map +1 -1
  15. package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs.umd.js +45 -0
  16. package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs.umd.js.map +1 -0
  17. package/dist/worker/node_modules_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js.umd.js +1470 -0
  18. package/dist/worker/node_modules_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js.umd.js.map +1 -0
  19. package/dist/worker/node_modules_journeyapps_wa-sqlite_src_examples_IDBBatchAtomicVFS_js.umd.js +1707 -1372
  20. package/dist/worker/node_modules_journeyapps_wa-sqlite_src_examples_IDBBatchAtomicVFS_js.umd.js.map +1 -1
  21. package/dist/worker/node_modules_journeyapps_wa-sqlite_src_examples_OPFSCoopSyncVFS_js.umd.js +1602 -0
  22. package/dist/worker/node_modules_journeyapps_wa-sqlite_src_examples_OPFSCoopSyncVFS_js.umd.js.map +1 -0
  23. package/lib/package.json +5 -5
  24. package/lib/src/db/PowerSyncDatabase.d.ts +1 -1
  25. package/lib/src/db/PowerSyncDatabase.js +5 -2
  26. package/lib/src/db/adapters/AbstractWebSQLOpenFactory.d.ts +2 -0
  27. package/lib/src/db/adapters/AbstractWebSQLOpenFactory.js +3 -0
  28. package/lib/src/db/adapters/AsyncDatabaseConnection.d.ts +26 -0
  29. package/lib/src/db/adapters/LockedAsyncDatabaseAdapter.d.ts +82 -0
  30. package/lib/src/db/adapters/LockedAsyncDatabaseAdapter.js +239 -0
  31. package/lib/src/db/adapters/WebDBAdapter.d.ts +17 -0
  32. package/lib/src/db/adapters/WebDBAdapter.js +1 -0
  33. package/lib/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.d.ts +38 -0
  34. package/lib/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.js +45 -0
  35. package/lib/src/db/adapters/wa-sqlite/WASQLiteConnection.d.ts +117 -0
  36. package/lib/src/db/adapters/wa-sqlite/WASQLiteConnection.js +289 -0
  37. package/lib/src/db/adapters/wa-sqlite/WASQLiteDBAdapter.d.ts +7 -43
  38. package/lib/src/db/adapters/wa-sqlite/WASQLiteDBAdapter.js +34 -209
  39. package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.d.ts +12 -0
  40. package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.js +57 -4
  41. package/lib/src/db/adapters/web-sql-flags.d.ts +16 -0
  42. package/lib/src/db/adapters/web-sql-flags.js +5 -0
  43. package/lib/src/db/sync/SharedWebStreamingSyncImplementation.d.ts +9 -2
  44. package/lib/src/db/sync/SharedWebStreamingSyncImplementation.js +16 -10
  45. package/lib/src/db/sync/WebStreamingSyncImplementation.d.ts +0 -5
  46. package/lib/src/index.d.ts +8 -7
  47. package/lib/src/index.js +8 -7
  48. package/lib/src/worker/db/WASQLiteDB.worker.js +38 -20
  49. package/lib/src/worker/db/open-worker-database.d.ts +5 -4
  50. package/lib/src/worker/db/open-worker-database.js +5 -3
  51. package/lib/src/worker/sync/AbstractSharedSyncClientProvider.d.ts +1 -0
  52. package/lib/src/worker/sync/SharedSyncImplementation.d.ts +20 -3
  53. package/lib/src/worker/sync/SharedSyncImplementation.js +40 -11
  54. package/lib/tsconfig.tsbuildinfo +1 -1
  55. package/package.json +6 -6
  56. package/dist/5fe5ed837a91c836c24f.wasm +0 -0
  57. package/lib/src/shared/open-db.d.ts +0 -5
  58. package/lib/src/shared/open-db.js +0 -192
  59. package/lib/src/shared/types.d.ts +0 -22
  60. /package/lib/src/{shared/types.js → db/adapters/AsyncDatabaseConnection.js} +0 -0
@@ -0,0 +1,45 @@
1
+ import * as Comlink from 'comlink';
2
+ /**
3
+ * Wraps a provided instance of {@link AsyncDatabaseConnection}, providing necessary proxy
4
+ * functions for worker listeners.
5
+ */
6
+ export class WorkerWrappedAsyncDatabaseConnection {
7
+ options;
8
+ constructor(options) {
9
+ this.options = options;
10
+ }
11
+ get baseConnection() {
12
+ return this.options.baseConnection;
13
+ }
14
+ init() {
15
+ return this.baseConnection.init();
16
+ }
17
+ /**
18
+ * Get a MessagePort which can be used to share the internals of this connection.
19
+ */
20
+ async shareConnection() {
21
+ const { identifier, remote } = this.options;
22
+ const newPort = await remote[Comlink.createEndpoint]();
23
+ return { port: newPort, identifier };
24
+ }
25
+ /**
26
+ * Registers a table change notification callback with the base database.
27
+ * This can be extended by custom implementations in order to handle proxy events.
28
+ */
29
+ async registerOnTableChange(callback) {
30
+ return this.baseConnection.registerOnTableChange(Comlink.proxy(callback));
31
+ }
32
+ async close() {
33
+ await this.baseConnection.close();
34
+ this.options.remote[Comlink.releaseProxy]();
35
+ }
36
+ execute(sql, params) {
37
+ return this.baseConnection.execute(sql, params);
38
+ }
39
+ executeBatch(sql, params) {
40
+ return this.baseConnection.executeBatch(sql, params);
41
+ }
42
+ getConfig() {
43
+ return this.baseConnection.getConfig();
44
+ }
45
+ }
@@ -0,0 +1,117 @@
1
+ import * as SQLite from '@journeyapps/wa-sqlite';
2
+ import { BaseObserver, BatchedUpdateNotification } from '@powersync/common';
3
+ import { Mutex } from 'async-mutex';
4
+ import { AsyncDatabaseConnection, OnTableChangeCallback, ProxiedQueryResult } from '../AsyncDatabaseConnection';
5
+ import { ResolvedWASQLiteOpenFactoryOptions } from './WASQLiteOpenFactory';
6
+ /**
7
+ * List of currently tested virtual filesystems
8
+ */
9
+ export declare enum WASQLiteVFS {
10
+ IDBBatchAtomicVFS = "IDBBatchAtomicVFS",
11
+ OPFSCoopSyncVFS = "OPFSCoopSyncVFS",
12
+ AccessHandlePoolVFS = "AccessHandlePoolVFS"
13
+ }
14
+ /**
15
+ * @internal
16
+ */
17
+ export type WASQLiteBroadCastTableUpdateEvent = {
18
+ changedTables: Set<string>;
19
+ connectionId: number;
20
+ };
21
+ /**
22
+ * @internal
23
+ */
24
+ export type WASQLiteConnectionListener = {
25
+ tablesUpdated: (event: BatchedUpdateNotification) => void;
26
+ };
27
+ /**
28
+ * @internal
29
+ */
30
+ export type SQLiteModule = Parameters<typeof SQLite.Factory>[0];
31
+ /**
32
+ * @internal
33
+ */
34
+ export type WASQLiteModuleFactoryOptions = {
35
+ dbFileName: string;
36
+ };
37
+ /**
38
+ * @internal
39
+ */
40
+ export type WASQLiteModuleFactory = (options: WASQLiteModuleFactoryOptions) => Promise<{
41
+ module: SQLiteModule;
42
+ vfs: SQLiteVFS;
43
+ }>;
44
+ /**
45
+ * @internal
46
+ */
47
+ export declare const AsyncWASQLiteModuleFactory: () => Promise<any>;
48
+ /**
49
+ * @internal
50
+ */
51
+ export declare const SyncWASQLiteModuleFactory: () => Promise<any>;
52
+ /**
53
+ * @internal
54
+ */
55
+ export declare const DEFAULT_MODULE_FACTORIES: {
56
+ IDBBatchAtomicVFS: (options: WASQLiteModuleFactoryOptions) => Promise<{
57
+ module: any;
58
+ vfs: any;
59
+ }>;
60
+ AccessHandlePoolVFS: (options: WASQLiteModuleFactoryOptions) => Promise<{
61
+ module: any;
62
+ vfs: any;
63
+ }>;
64
+ OPFSCoopSyncVFS: (options: WASQLiteModuleFactoryOptions) => Promise<{
65
+ module: any;
66
+ vfs: any;
67
+ }>;
68
+ };
69
+ /**
70
+ * @internal
71
+ * WA-SQLite connection which directly interfaces with WA-SQLite.
72
+ * This is usually instantiated inside a worker.
73
+ */
74
+ export declare class WASqliteConnection extends BaseObserver<WASQLiteConnectionListener> implements AsyncDatabaseConnection<ResolvedWASQLiteOpenFactoryOptions> {
75
+ protected options: ResolvedWASQLiteOpenFactoryOptions;
76
+ private _sqliteAPI;
77
+ private _dbP;
78
+ private _moduleFactory;
79
+ protected updatedTables: Set<string>;
80
+ protected updateTimer: ReturnType<typeof setTimeout> | null;
81
+ protected statementMutex: Mutex;
82
+ protected broadcastChannel: BroadcastChannel | null;
83
+ /**
84
+ * Unique id for this specific connection. This is used to prevent broadcast table change
85
+ * notification loops.
86
+ */
87
+ protected connectionId: number;
88
+ constructor(options: ResolvedWASQLiteOpenFactoryOptions);
89
+ protected get sqliteAPI(): SQLiteAPI;
90
+ protected get dbP(): number;
91
+ protected openDB(): Promise<number>;
92
+ protected openSQLiteAPI(): Promise<SQLiteAPI>;
93
+ protected registerBroadcastListeners(): void;
94
+ protected queueTableUpdate(tableNames: Set<string>): void;
95
+ init(): Promise<void>;
96
+ getConfig(): Promise<ResolvedWASQLiteOpenFactoryOptions>;
97
+ fireUpdates(): void;
98
+ /**
99
+ * This executes SQL statements in a batch.
100
+ */
101
+ executeBatch(sql: string, bindings?: any[][]): Promise<ProxiedQueryResult>;
102
+ /**
103
+ * This executes single SQL statements inside a requested lock.
104
+ */
105
+ execute(sql: string | TemplateStringsArray, bindings?: any[]): Promise<ProxiedQueryResult>;
106
+ close(): Promise<void>;
107
+ registerOnTableChange(callback: OnTableChangeCallback): Promise<() => void>;
108
+ /**
109
+ * This requests a lock for executing statements.
110
+ * Should only be used internally.
111
+ */
112
+ protected acquireExecuteLock: <T>(callback: () => Promise<T>) => Promise<T>;
113
+ /**
114
+ * This executes a single statement using SQLite3.
115
+ */
116
+ protected executeSingleStatement(sql: string | TemplateStringsArray, bindings?: any[]): Promise<ProxiedQueryResult>;
117
+ }
@@ -0,0 +1,289 @@
1
+ import * as SQLite from '@journeyapps/wa-sqlite';
2
+ import { BaseObserver } from '@powersync/common';
3
+ import { Mutex } from 'async-mutex';
4
+ /**
5
+ * List of currently tested virtual filesystems
6
+ */
7
+ export var WASQLiteVFS;
8
+ (function (WASQLiteVFS) {
9
+ WASQLiteVFS["IDBBatchAtomicVFS"] = "IDBBatchAtomicVFS";
10
+ WASQLiteVFS["OPFSCoopSyncVFS"] = "OPFSCoopSyncVFS";
11
+ WASQLiteVFS["AccessHandlePoolVFS"] = "AccessHandlePoolVFS";
12
+ })(WASQLiteVFS || (WASQLiteVFS = {}));
13
+ /**
14
+ * @internal
15
+ */
16
+ export const AsyncWASQLiteModuleFactory = async () => {
17
+ const { default: factory } = await import('@journeyapps/wa-sqlite/dist/wa-sqlite-async.mjs');
18
+ return factory();
19
+ };
20
+ /**
21
+ * @internal
22
+ */
23
+ export const SyncWASQLiteModuleFactory = async () => {
24
+ const { default: factory } = await import('@journeyapps/wa-sqlite/dist/wa-sqlite.mjs');
25
+ return factory();
26
+ };
27
+ /**
28
+ * @internal
29
+ */
30
+ export const DEFAULT_MODULE_FACTORIES = {
31
+ [WASQLiteVFS.IDBBatchAtomicVFS]: async (options) => {
32
+ const module = await AsyncWASQLiteModuleFactory();
33
+ const { IDBBatchAtomicVFS } = await import('@journeyapps/wa-sqlite/src/examples/IDBBatchAtomicVFS.js');
34
+ return {
35
+ module,
36
+ // @ts-expect-error The types for this static method are missing upstream
37
+ vfs: await IDBBatchAtomicVFS.create(options.dbFileName, module, { lockPolicy: 'exclusive' })
38
+ };
39
+ },
40
+ [WASQLiteVFS.AccessHandlePoolVFS]: async (options) => {
41
+ const module = await SyncWASQLiteModuleFactory();
42
+ // @ts-expect-error The types for this static method are missing upstream
43
+ const { AccessHandlePoolVFS } = await import('@journeyapps/wa-sqlite/src/examples/AccessHandlePoolVFS.js');
44
+ return {
45
+ module,
46
+ vfs: await AccessHandlePoolVFS.create(options.dbFileName, module)
47
+ };
48
+ },
49
+ [WASQLiteVFS.OPFSCoopSyncVFS]: async (options) => {
50
+ const module = await SyncWASQLiteModuleFactory();
51
+ // @ts-expect-error The types for this static method are missing upstream
52
+ const { OPFSCoopSyncVFS } = await import('@journeyapps/wa-sqlite/src/examples/OPFSCoopSyncVFS.js');
53
+ return {
54
+ module,
55
+ vfs: await OPFSCoopSyncVFS.create(options.dbFileName, module)
56
+ };
57
+ }
58
+ };
59
+ /**
60
+ * @internal
61
+ * WA-SQLite connection which directly interfaces with WA-SQLite.
62
+ * This is usually instantiated inside a worker.
63
+ */
64
+ export class WASqliteConnection extends BaseObserver {
65
+ options;
66
+ _sqliteAPI = null;
67
+ _dbP = null;
68
+ _moduleFactory;
69
+ updatedTables;
70
+ updateTimer;
71
+ statementMutex;
72
+ broadcastChannel;
73
+ /**
74
+ * Unique id for this specific connection. This is used to prevent broadcast table change
75
+ * notification loops.
76
+ */
77
+ connectionId;
78
+ constructor(options) {
79
+ super();
80
+ this.options = options;
81
+ this.updatedTables = new Set();
82
+ this.updateTimer = null;
83
+ this.broadcastChannel = null;
84
+ this.connectionId = new Date().valueOf() + Math.random();
85
+ this.statementMutex = new Mutex();
86
+ this._moduleFactory = DEFAULT_MODULE_FACTORIES[this.options.vfs];
87
+ }
88
+ get sqliteAPI() {
89
+ if (!this._sqliteAPI) {
90
+ throw new Error(`Initialization has not completed`);
91
+ }
92
+ return this._sqliteAPI;
93
+ }
94
+ get dbP() {
95
+ if (!this._dbP) {
96
+ throw new Error(`Initialization has not completed`);
97
+ }
98
+ return this._dbP;
99
+ }
100
+ async openDB() {
101
+ this._dbP = await this.sqliteAPI.open_v2(this.options.dbFilename);
102
+ return this._dbP;
103
+ }
104
+ async openSQLiteAPI() {
105
+ const { module, vfs } = await this._moduleFactory({ dbFileName: this.options.dbFilename });
106
+ const sqlite3 = SQLite.Factory(module);
107
+ sqlite3.vfs_register(vfs, true);
108
+ /**
109
+ * Register the PowerSync core SQLite extension
110
+ */
111
+ module.ccall('powersync_init_static', 'int', []);
112
+ return sqlite3;
113
+ }
114
+ registerBroadcastListeners() {
115
+ this.broadcastChannel = new BroadcastChannel(`${this.options.dbFilename}-table-updates`);
116
+ this.broadcastChannel.addEventListener('message', (event) => {
117
+ const data = event.data;
118
+ if (this.connectionId == data.connectionId) {
119
+ // Ignore messages from the same connection
120
+ return;
121
+ }
122
+ this.queueTableUpdate(data.changedTables);
123
+ });
124
+ }
125
+ queueTableUpdate(tableNames) {
126
+ tableNames.forEach((tableName) => this.updatedTables.add(tableName));
127
+ if (this.updateTimer == null) {
128
+ this.updateTimer = setTimeout(() => this.fireUpdates(), 0);
129
+ }
130
+ }
131
+ async init() {
132
+ this._sqliteAPI = await this.openSQLiteAPI();
133
+ await this.openDB();
134
+ this.registerBroadcastListeners();
135
+ await this.executeSingleStatement(`PRAGMA temp_store = ${this.options.temporaryStorage};`);
136
+ this.sqliteAPI.update_hook(this.dbP, (updateType, dbName, tableName) => {
137
+ if (!tableName) {
138
+ return;
139
+ }
140
+ const changedTables = new Set([tableName]);
141
+ this.queueTableUpdate(changedTables);
142
+ });
143
+ }
144
+ async getConfig() {
145
+ return this.options;
146
+ }
147
+ fireUpdates() {
148
+ this.updateTimer = null;
149
+ const event = { tables: [...this.updatedTables], groupedUpdates: {}, rawUpdates: [] };
150
+ // Share to other connections
151
+ this.broadcastChannel.postMessage({
152
+ changedTables: this.updatedTables,
153
+ connectionId: this.connectionId
154
+ });
155
+ this.updatedTables.clear();
156
+ this.iterateListeners((cb) => cb.tablesUpdated?.(event));
157
+ }
158
+ /**
159
+ * This executes SQL statements in a batch.
160
+ */
161
+ async executeBatch(sql, bindings) {
162
+ return this.acquireExecuteLock(async () => {
163
+ let affectedRows = 0;
164
+ try {
165
+ await this.executeSingleStatement('BEGIN TRANSACTION');
166
+ const wrappedBindings = bindings ? bindings : [];
167
+ for await (const stmt of this.sqliteAPI.statements(this.dbP, sql)) {
168
+ if (stmt === null) {
169
+ return {
170
+ rowsAffected: 0,
171
+ rows: { _array: [], length: 0 }
172
+ };
173
+ }
174
+ //Prepare statement once
175
+ for (const binding of wrappedBindings) {
176
+ // TODO not sure why this is needed currently, but booleans break
177
+ for (let i = 0; i < binding.length; i++) {
178
+ const b = binding[i];
179
+ if (typeof b == 'boolean') {
180
+ binding[i] = b ? 1 : 0;
181
+ }
182
+ }
183
+ if (bindings) {
184
+ this.sqliteAPI.bind_collection(stmt, binding);
185
+ }
186
+ const result = await this.sqliteAPI.step(stmt);
187
+ if (result === SQLite.SQLITE_DONE) {
188
+ //The value returned by sqlite3_changes() immediately after an INSERT, UPDATE or DELETE statement run on a view is always zero.
189
+ affectedRows += this.sqliteAPI.changes(this.dbP);
190
+ }
191
+ this.sqliteAPI.reset(stmt);
192
+ }
193
+ }
194
+ await this.executeSingleStatement('COMMIT');
195
+ }
196
+ catch (err) {
197
+ await this.executeSingleStatement('ROLLBACK');
198
+ return {
199
+ rowsAffected: 0,
200
+ rows: { _array: [], length: 0 }
201
+ };
202
+ }
203
+ const result = {
204
+ rowsAffected: affectedRows,
205
+ rows: { _array: [], length: 0 }
206
+ };
207
+ return result;
208
+ });
209
+ }
210
+ /**
211
+ * This executes single SQL statements inside a requested lock.
212
+ */
213
+ async execute(sql, bindings) {
214
+ // Running multiple statements on the same connection concurrently should not be allowed
215
+ return this.acquireExecuteLock(async () => {
216
+ return this.executeSingleStatement(sql, bindings);
217
+ });
218
+ }
219
+ async close() {
220
+ this.broadcastChannel?.close();
221
+ await this.sqliteAPI.close(this.dbP);
222
+ }
223
+ async registerOnTableChange(callback) {
224
+ return this.registerListener({
225
+ tablesUpdated: (event) => callback(event)
226
+ });
227
+ }
228
+ /**
229
+ * This requests a lock for executing statements.
230
+ * Should only be used internally.
231
+ */
232
+ acquireExecuteLock = (callback) => {
233
+ return this.statementMutex.runExclusive(callback);
234
+ };
235
+ /**
236
+ * This executes a single statement using SQLite3.
237
+ */
238
+ async executeSingleStatement(sql, bindings) {
239
+ const results = [];
240
+ for await (const stmt of this.sqliteAPI.statements(this.dbP, sql)) {
241
+ let columns;
242
+ const wrappedBindings = bindings ? [bindings] : [[]];
243
+ for (const binding of wrappedBindings) {
244
+ // TODO not sure why this is needed currently, but booleans break
245
+ binding.forEach((b, index, arr) => {
246
+ if (typeof b == 'boolean') {
247
+ arr[index] = b ? 1 : 0;
248
+ }
249
+ });
250
+ this.sqliteAPI.reset(stmt);
251
+ if (bindings) {
252
+ this.sqliteAPI.bind_collection(stmt, binding);
253
+ }
254
+ const rows = [];
255
+ while ((await this.sqliteAPI.step(stmt)) === SQLite.SQLITE_ROW) {
256
+ const row = this.sqliteAPI.row(stmt);
257
+ rows.push(row);
258
+ }
259
+ columns = columns ?? this.sqliteAPI.column_names(stmt);
260
+ if (columns.length) {
261
+ results.push({ columns, rows });
262
+ }
263
+ }
264
+ // When binding parameters, only a single statement is executed.
265
+ if (bindings) {
266
+ break;
267
+ }
268
+ }
269
+ const rows = [];
270
+ for (const resultSet of results) {
271
+ for (const row of resultSet.rows) {
272
+ const outRow = {};
273
+ resultSet.columns.forEach((key, index) => {
274
+ outRow[key] = row[index];
275
+ });
276
+ rows.push(outRow);
277
+ }
278
+ }
279
+ const result = {
280
+ insertId: this.sqliteAPI.last_insert_id(this.dbP),
281
+ rowsAffected: this.sqliteAPI.changes(this.dbP),
282
+ rows: {
283
+ _array: rows,
284
+ length: rows.length
285
+ }
286
+ };
287
+ return result;
288
+ }
289
+ }
@@ -1,5 +1,7 @@
1
- import { type DBAdapter, type DBAdapterListener, type DBLockOptions, type LockContext, type PowerSyncOpenFactoryOptions, type QueryResult, type Transaction, BaseObserver } from '@powersync/common';
2
- import { ResolvedWebSQLOpenOptions, WebSQLFlags } from '../web-sql-flags';
1
+ import { type PowerSyncOpenFactoryOptions } from '@powersync/common';
2
+ import { LockedAsyncDatabaseAdapter } from '../LockedAsyncDatabaseAdapter';
3
+ import { ResolvedWebSQLOpenOptions, TemporaryStorageOption, WebSQLFlags } from '../web-sql-flags';
4
+ import { WASQLiteVFS } from './WASQLiteConnection';
3
5
  /**
4
6
  * These flags are the same as {@link WebSQLFlags}.
5
7
  * This export is maintained only for API consistency
@@ -13,50 +15,12 @@ export interface WASQLiteDBAdapterOptions extends Omit<PowerSyncOpenFactoryOptio
13
15
  */
14
16
  workerPort?: MessagePort;
15
17
  worker?: string | URL | ((options: ResolvedWebSQLOpenOptions) => Worker | SharedWorker);
18
+ vfs?: WASQLiteVFS;
19
+ temporaryStorage?: TemporaryStorageOption;
16
20
  }
17
21
  /**
18
22
  * Adapter for WA-SQLite SQLite connections.
19
23
  */
20
- export declare class WASQLiteDBAdapter extends BaseObserver<DBAdapterListener> implements DBAdapter {
21
- protected options: WASQLiteDBAdapterOptions;
22
- private initialized;
23
- private logger;
24
- private dbGetHelpers;
25
- private methods;
26
- private debugMode;
24
+ export declare class WASQLiteDBAdapter extends LockedAsyncDatabaseAdapter {
27
25
  constructor(options: WASQLiteDBAdapterOptions);
28
- get name(): string;
29
- protected get flags(): Required<WASQLiteFlags>;
30
- getWorker(): void;
31
- protected init(): Promise<void>;
32
- execute(query: string, params?: any[] | undefined): Promise<QueryResult>;
33
- executeBatch(query: string, params?: any[][]): Promise<QueryResult>;
34
- /**
35
- * Wraps the worker execute function, awaiting for it to be available
36
- */
37
- private _execute;
38
- /**
39
- * Wraps the worker executeBatch function, awaiting for it to be available
40
- */
41
- private _executeBatch;
42
- /**
43
- * Attempts to close the connection.
44
- * Shared workers might not actually close the connection if other
45
- * tabs are still using it.
46
- */
47
- close(): void;
48
- getAll<T>(sql: string, parameters?: any[] | undefined): Promise<T[]>;
49
- getOptional<T>(sql: string, parameters?: any[] | undefined): Promise<T | null>;
50
- get<T>(sql: string, parameters?: any[] | undefined): Promise<T>;
51
- readLock<T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions | undefined): Promise<T>;
52
- writeLock<T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions | undefined): Promise<T>;
53
- protected acquireLock(callback: () => Promise<any>): Promise<any>;
54
- readTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions | undefined): Promise<T>;
55
- writeTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions | undefined): Promise<T>;
56
- /**
57
- * Wraps a lock context into a transaction context
58
- */
59
- private wrapTransaction;
60
- private generateDBHelpers;
61
- refreshSchema(): Promise<void>;
62
26
  }