@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powersync/web",
3
- "version": "0.0.0-dev-20241119081147",
3
+ "version": "0.0.0-dev-20241203152232",
4
4
  "description": "A Web SDK for JourneyApps PowerSync",
5
5
  "main": "lib/src/index.js",
6
6
  "types": "lib/src/index.d.ts",
@@ -50,19 +50,19 @@
50
50
  "author": "JOURNEYAPPS",
51
51
  "license": "Apache-2.0",
52
52
  "peerDependencies": {
53
- "@journeyapps/wa-sqlite": "^0.4.2",
54
- "@powersync/common": "^1.21.0"
53
+ "@journeyapps/wa-sqlite": "^1.0.0",
54
+ "@powersync/common": "^1.22.0"
55
55
  },
56
56
  "dependencies": {
57
57
  "async-mutex": "^0.4.0",
58
58
  "bson": "^6.6.0",
59
- "comlink": "^4.4.1",
59
+ "comlink": "^4.4.2",
60
60
  "commander": "^12.1.0",
61
61
  "js-logger": "^1.6.1",
62
- "@powersync/common": "1.21.0"
62
+ "@powersync/common": "1.22.0"
63
63
  },
64
64
  "devDependencies": {
65
- "@journeyapps/wa-sqlite": "^0.4.2",
65
+ "@journeyapps/wa-sqlite": "^1.0.0",
66
66
  "@types/uuid": "^9.0.6",
67
67
  "@vitest/browser": "^2.1.4",
68
68
  "crypto-browserify": "^3.12.0",
Binary file
@@ -1,5 +0,0 @@
1
- import '@journeyapps/wa-sqlite';
2
- import type { DBFunctionsInterface } from './types';
3
- export declare function _openDB(dbFileName: string, options?: {
4
- useWebWorker: boolean;
5
- }): Promise<DBFunctionsInterface>;
@@ -1,192 +0,0 @@
1
- import * as SQLite from '@journeyapps/wa-sqlite';
2
- import '@journeyapps/wa-sqlite';
3
- import * as Comlink from 'comlink';
4
- import { Mutex } from 'async-mutex';
5
- let nextId = 1;
6
- export async function _openDB(dbFileName, options = { useWebWorker: true }) {
7
- const { default: moduleFactory } = await import('@journeyapps/wa-sqlite/dist/wa-sqlite-async.mjs');
8
- const module = await moduleFactory();
9
- const sqlite3 = SQLite.Factory(module);
10
- const { IDBBatchAtomicVFS } = await import('@journeyapps/wa-sqlite/src/examples/IDBBatchAtomicVFS.js');
11
- const vfs = new IDBBatchAtomicVFS(dbFileName);
12
- sqlite3.vfs_register(vfs, true);
13
- const db = await sqlite3.open_v2(dbFileName);
14
- const statementMutex = new Mutex();
15
- /**
16
- * Listeners are exclusive to the DB connection.
17
- */
18
- const listeners = new Map();
19
- let updatedTables = new Set();
20
- let updateTimer = null;
21
- function fireUpdates() {
22
- updateTimer = null;
23
- const event = { tables: [...updatedTables], groupedUpdates: {}, rawUpdates: [] };
24
- updatedTables.clear();
25
- Array.from(listeners.values()).forEach((l) => l(event));
26
- }
27
- sqlite3.register_table_onchange_hook(db, (opType, tableName, rowId) => {
28
- updatedTables.add(tableName);
29
- if (updateTimer == null) {
30
- updateTimer = setTimeout(fireUpdates, 0);
31
- }
32
- });
33
- /**
34
- * This executes single SQL statements inside a requested lock.
35
- */
36
- const execute = async (sql, bindings) => {
37
- // Running multiple statements on the same connection concurrently should not be allowed
38
- return _acquireExecuteLock(async () => {
39
- return executeSingleStatement(sql, bindings);
40
- });
41
- };
42
- /**
43
- * This requests a lock for executing statements.
44
- * Should only be used internally.
45
- */
46
- const _acquireExecuteLock = (callback) => {
47
- return statementMutex.runExclusive(callback);
48
- };
49
- /**
50
- * This executes a single statement using SQLite3.
51
- */
52
- const executeSingleStatement = async (sql, bindings) => {
53
- const results = [];
54
- for await (const stmt of sqlite3.statements(db, sql)) {
55
- let columns;
56
- const wrappedBindings = bindings ? [bindings] : [[]];
57
- for (const binding of wrappedBindings) {
58
- // TODO not sure why this is needed currently, but booleans break
59
- binding.forEach((b, index, arr) => {
60
- if (typeof b == 'boolean') {
61
- arr[index] = b ? 1 : 0;
62
- }
63
- });
64
- sqlite3.reset(stmt);
65
- if (bindings) {
66
- sqlite3.bind_collection(stmt, binding);
67
- }
68
- const rows = [];
69
- while ((await sqlite3.step(stmt)) === SQLite.SQLITE_ROW) {
70
- const row = sqlite3.row(stmt);
71
- rows.push(row);
72
- }
73
- columns = columns ?? sqlite3.column_names(stmt);
74
- if (columns.length) {
75
- results.push({ columns, rows });
76
- }
77
- }
78
- // When binding parameters, only a single statement is executed.
79
- if (bindings) {
80
- break;
81
- }
82
- }
83
- const rows = [];
84
- for (const resultset of results) {
85
- for (const row of resultset.rows) {
86
- const outRow = {};
87
- resultset.columns.forEach((key, index) => {
88
- outRow[key] = row[index];
89
- });
90
- rows.push(outRow);
91
- }
92
- }
93
- const result = {
94
- insertId: sqlite3.last_insert_id(db),
95
- rowsAffected: sqlite3.changes(db),
96
- rows: {
97
- _array: rows,
98
- length: rows.length
99
- }
100
- };
101
- return result;
102
- };
103
- /**
104
- * This executes SQL statements in a batch.
105
- */
106
- const executeBatch = async (sql, bindings) => {
107
- return _acquireExecuteLock(async () => {
108
- let affectedRows = 0;
109
- const str = sqlite3.str_new(db, sql);
110
- const query = sqlite3.str_value(str);
111
- try {
112
- await executeSingleStatement('BEGIN TRANSACTION');
113
- //Prepare statement once
114
- const prepared = await sqlite3.prepare_v2(db, query);
115
- if (prepared === null) {
116
- return {
117
- rowsAffected: 0,
118
- rows: { _array: [], length: 0 }
119
- };
120
- }
121
- const wrappedBindings = bindings ? bindings : [];
122
- for (const binding of wrappedBindings) {
123
- // TODO not sure why this is needed currently, but booleans break
124
- for (let i = 0; i < binding.length; i++) {
125
- const b = binding[i];
126
- if (typeof b == 'boolean') {
127
- binding[i] = b ? 1 : 0;
128
- }
129
- }
130
- //Reset bindings
131
- sqlite3.reset(prepared.stmt);
132
- if (bindings) {
133
- sqlite3.bind_collection(prepared.stmt, binding);
134
- }
135
- const result = await sqlite3.step(prepared.stmt);
136
- if (result === SQLite.SQLITE_DONE) {
137
- //The value returned by sqlite3_changes() immediately after an INSERT, UPDATE or DELETE statement run on a view is always zero.
138
- affectedRows += sqlite3.changes(db);
139
- }
140
- }
141
- //Finalize prepared statement
142
- await sqlite3.finalize(prepared.stmt);
143
- await executeSingleStatement('COMMIT');
144
- }
145
- catch (err) {
146
- await executeSingleStatement('ROLLBACK');
147
- return {
148
- rowsAffected: 0,
149
- rows: { _array: [], length: 0 }
150
- };
151
- }
152
- finally {
153
- sqlite3.str_finish(str);
154
- }
155
- const result = {
156
- rowsAffected: affectedRows,
157
- rows: { _array: [], length: 0 }
158
- };
159
- return result;
160
- });
161
- };
162
- if (options.useWebWorker) {
163
- const registerOnTableChange = (callback) => {
164
- const id = nextId++;
165
- listeners.set(id, callback);
166
- return Comlink.proxy(() => {
167
- listeners.delete(id);
168
- });
169
- };
170
- return {
171
- execute: Comlink.proxy(execute),
172
- executeBatch: Comlink.proxy(executeBatch),
173
- registerOnTableChange: Comlink.proxy(registerOnTableChange),
174
- close: Comlink.proxy(() => {
175
- sqlite3.close(db);
176
- })
177
- };
178
- }
179
- const registerOnTableChange = (callback) => {
180
- const id = nextId++;
181
- listeners.set(id, callback);
182
- return () => {
183
- listeners.delete(id);
184
- };
185
- };
186
- return {
187
- execute: execute,
188
- executeBatch: executeBatch,
189
- registerOnTableChange: registerOnTableChange,
190
- close: () => sqlite3.close(db)
191
- };
192
- }
@@ -1,22 +0,0 @@
1
- import type { BatchedUpdateNotification, QueryResult } from '@powersync/common';
2
- export type WASQLExecuteResult = Omit<QueryResult, 'rows'> & {
3
- rows: {
4
- _array: any[];
5
- length: number;
6
- };
7
- };
8
- export type DBFunctionsInterface = {
9
- close?: () => void;
10
- execute: WASQLiteExecuteMethod;
11
- executeBatch: WASQLiteExecuteBatchMethod;
12
- registerOnTableChange: (callback: OnTableChangeCallback) => void;
13
- };
14
- /**
15
- * @deprecated use [DBFunctionsInterface instead]
16
- */
17
- export type DBWorkerInterface = DBFunctionsInterface;
18
- export type WASQLiteExecuteMethod = (sql: string, params?: any[]) => Promise<WASQLExecuteResult>;
19
- export type WASQLiteExecuteBatchMethod = (sql: string, params?: any[]) => Promise<WASQLExecuteResult>;
20
- export type OnTableChangeCallback = (event: BatchedUpdateNotification) => void;
21
- export type OpenDB = (dbFileName: string) => DBWorkerInterface;
22
- export type SQLBatchTuple = [string] | [string, Array<any> | Array<Array<any>>];