@livestore/wa-sqlite 1.0.8-dev.2 → 1.0.8-dev.3

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/README.md CHANGED
@@ -8,6 +8,10 @@ This fork adds synchronous APIs and session extensions needed for LiveStore's re
8
8
  - **Session extensions**: Enables change tracking and replication for collaborative features
9
9
  - **Node.js compatibility**: Additional build targets for server-side testing
10
10
 
11
+ ## Future work
12
+
13
+ - **Async build investigation**: Some VFS implementations (e.g., IndexedDB) require async APIs ([#131](https://github.com/livestorejs/livestore/issues/131)). We're investigating whether to support this through a unified hybrid build or separate builds.
14
+
11
15
  ### Changes include:
12
16
 
13
17
  - `src/sqlite-api.js`:
File without changes
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@livestore/wa-sqlite",
3
- "version": "1.0.8-dev.2",
3
+ "version": "1.0.8-dev.3",
4
4
  "type": "module",
5
5
  "main": "src/sqlite-api.js",
6
6
  "types": "src/types/index.d.ts",
@@ -15,6 +15,12 @@
15
15
  "dist/*",
16
16
  "test/*"
17
17
  ],
18
+ "scripts": {
19
+ "build-docs": "typedoc",
20
+ "start": "web-dev-server --node-resolve",
21
+ "test": "web-test-runner",
22
+ "test-manual": "web-test-runner --manual"
23
+ },
18
24
  "devDependencies": {
19
25
  "@types/jasmine": "^5.1.4",
20
26
  "@web/dev-server": "^0.4.6",
@@ -34,11 +40,5 @@
34
40
  "web-test-runner-jasmine@0.0.6": {
35
41
  "unplugged": true
36
42
  }
37
- },
38
- "scripts": {
39
- "build-docs": "typedoc",
40
- "start": "web-dev-server --node-resolve",
41
- "test": "web-test-runner",
42
- "test-manual": "web-test-runner --manual"
43
43
  }
44
- }
44
+ }
package/src/sqlite-api.js CHANGED
@@ -260,18 +260,21 @@ export function Factory(Module) {
260
260
  return function(db, schema) {
261
261
  verifyDatabase(db);
262
262
  const piSize = tmpPtr[0];
263
- let address = f(db, schema, piSize, 0);
263
+ let address = f(db, schema, piSize, 0); // 0 means no flags
264
264
  if (address === 0) {
265
265
  address = f(db, schema, piSize, SQLITE_SERIALIZE_NOCOPY);
266
266
  const size = Module.getValue(piSize, '*');
267
267
  const result = Module.HEAPU8.subarray(address, address + size);
268
268
  // NOTE Given that the memory is owned by SQLite, we must copy it.
269
+ // Warning: We're not super confident yet about this code path. There might be dragons.
269
270
  return new Uint8Array(result.slice());
270
271
  } else {
271
272
  const size = Module.getValue(piSize, '*');
272
273
  const result = Module.HEAPU8.subarray(address, address + size);
273
- // Here we're getting a copy of the memory, so we can return it directly.
274
- return new Uint8Array(result);
274
+ // Copy the data immediately, then free the SQLite buffer to prevent ref-count issues
275
+ const copy = new Uint8Array(result);
276
+ Module._sqlite3_free(address);
277
+ return copy;
275
278
  }
276
279
  };
277
280
  })();
@@ -290,10 +293,15 @@ export function Factory(Module) {
290
293
  const errMsg = Module.ccall('sqlite3_errmsg', 'string', ['number'], [dest]);
291
294
  throw new SQLiteError(`backup failed: ${errMsg}`, SQLite.SQLITE_ERROR);
292
295
  }
293
- fStep(backup, -1);
296
+ // TODO also allow run in chunks with some yielding mechanism
297
+ fStep(backup, -1); // -1 means do it in one go
294
298
  return fFinish(backup);
295
299
  };
296
300
  })();
301
+
302
+
303
+ // TODO implement this at some point
304
+ // sqlite3.backup_step = (function() {
297
305
 
298
306
  sqlite3.clear_bindings = (function() {
299
307
  const fname = 'sqlite3_clear_bindings';