@livestore/wa-sqlite 0.4.0-dev.21 → 0.4.0-dev.23

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 (62) hide show
  1. package/README.md +46 -36
  2. package/dist/README.md +13 -13
  3. package/dist/fts5/wa-sqlite.mjs +1 -1
  4. package/dist/fts5/wa-sqlite.node.mjs +1 -1
  5. package/dist/fts5/wa-sqlite.node.wasm +0 -0
  6. package/dist/fts5/wa-sqlite.wasm +0 -0
  7. package/dist/wa-sqlite-async.mjs +1 -1
  8. package/dist/wa-sqlite-async.wasm +0 -0
  9. package/dist/wa-sqlite-jspi.mjs +1 -1
  10. package/dist/wa-sqlite-jspi.wasm +0 -0
  11. package/dist/wa-sqlite.mjs +1 -1
  12. package/dist/wa-sqlite.node.mjs +1 -1
  13. package/dist/wa-sqlite.node.wasm +0 -0
  14. package/dist/wa-sqlite.wasm +0 -0
  15. package/package.json +40 -29
  16. package/src/FacadeVFS.js +252 -261
  17. package/src/VFS.js +84 -85
  18. package/src/WebLocksMixin.js +357 -351
  19. package/src/examples/AccessHandlePoolVFS.js +185 -194
  20. package/src/examples/IDBBatchAtomicVFS.js +429 -409
  21. package/src/examples/IDBMirrorVFS.js +402 -409
  22. package/src/examples/MemoryAsyncVFS.js +32 -37
  23. package/src/examples/MemoryVFS.js +71 -75
  24. package/src/examples/OPFSAdaptiveVFS.js +206 -206
  25. package/src/examples/OPFSAnyContextVFS.js +141 -140
  26. package/src/examples/OPFSCoopSyncVFS.js +297 -299
  27. package/src/examples/OPFSPermutedVFS.js +529 -540
  28. package/src/examples/README.md +27 -15
  29. package/src/examples/tag.js +27 -27
  30. package/src/sqlite-api.js +910 -941
  31. package/src/sqlite-constants.js +246 -232
  32. package/src/types/globals.d.ts +52 -52
  33. package/src/types/index.d.ts +586 -576
  34. package/test/AccessHandlePoolVFS.test.js +21 -21
  35. package/test/IDBBatchAtomicVFS.test.js +69 -69
  36. package/test/IDBMirrorVFS.test.js +21 -21
  37. package/test/MemoryAsyncVFS.test.js +21 -21
  38. package/test/MemoryVFS.test.js +21 -21
  39. package/test/OPFSAdaptiveVFS.test.js +21 -21
  40. package/test/OPFSAnyContextVFS.test.js +21 -21
  41. package/test/OPFSCoopSyncVFS.test.js +21 -21
  42. package/test/OPFSPermutedVFS.test.js +21 -21
  43. package/test/TestContext.js +44 -41
  44. package/test/WebLocksMixin.test.js +369 -360
  45. package/test/api.test.js +23 -23
  46. package/test/api_exec.js +72 -61
  47. package/test/api_misc.js +53 -54
  48. package/test/api_statements.js +271 -279
  49. package/test/callbacks.test.js +492 -478
  50. package/test/data/idbv5.json +1135 -1
  51. package/test/sql.test.js +30 -30
  52. package/test/sql_0001.js +49 -33
  53. package/test/sql_0002.js +55 -34
  54. package/test/sql_0003.js +85 -49
  55. package/test/sql_0004.js +76 -47
  56. package/test/sql_0005.js +60 -44
  57. package/test/test-worker.js +171 -163
  58. package/test/vfs_xAccess.js +1 -2
  59. package/test/vfs_xClose.js +50 -49
  60. package/test/vfs_xOpen.js +73 -72
  61. package/test/vfs_xRead.js +31 -31
  62. package/test/vfs_xWrite.js +30 -29
package/README.md CHANGED
@@ -5,7 +5,7 @@ This fork adds synchronous APIs and session extensions needed for LiveStore's re
5
5
  ### Why this fork?
6
6
 
7
7
  - **Synchronous API**: LiveStore requires synchronous database operations for performance-critical paths
8
- - **Session extensions**: Enables change tracking and replication for collaborative features
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
11
  ## Future work
@@ -15,24 +15,27 @@ This fork adds synchronous APIs and session extensions needed for LiveStore's re
15
15
  ### Changes include:
16
16
 
17
17
  - `src/sqlite-api.js`:
18
- - Change API to expose synchronous functions
19
- - Keeps `open_v2` but additionally exposes `open_v2Sync` which is synchronous
20
- - Add `serialize`, `deserialize` and `backup` functions
18
+ - Change API to expose synchronous functions
19
+ - Keeps `open_v2` but additionally exposes `open_v2Sync` which is synchronous
20
+ - Add `serialize`, `deserialize` and `backup` functions
21
21
  - Add `session_` extension functions
22
22
  - `src/types/index.d.ts`
23
23
  - Adjust types to match the new sync API
24
- - No longer `declare` `SQLiteAPI` / `SQLiteVFS` globally but export it properly
25
- - Exposed more types from `src/examples`
24
+ - No longer `declare` `SQLiteAPI` / `SQLiteVFS` globally but export it properly
25
+ - Exposed more types from `src/examples`
26
26
  - `dist`
27
27
  - Added Node.js build target (mostly used for testing)
28
28
 
29
29
  ### Building LiveStore fork
30
+
30
31
  Use Nix to build the LiveStore variant with session and FTS5 support:
32
+
31
33
  ```bash
32
34
  nix run .#build # Builds and updates dist/
33
35
  ```
34
36
 
35
37
  ### Staying current
38
+
36
39
  This fork is regularly rebased against [upstream wa-sqlite](https://github.com/rhashimoto/wa-sqlite) to incorporate latest improvements and security fixes.
37
40
 
38
41
  ---
@@ -40,6 +43,7 @@ This fork is regularly rebased against [upstream wa-sqlite](https://github.com/r
40
43
  [![wa-sqlite CI](https://github.com/rhashimoto/wa-sqlite/actions/workflows/ci.yml/badge.svg)](https://github.com/rhashimoto/wa-sqlite/actions/workflows/ci.yml)
41
44
 
42
45
  # wa-sqlite
46
+
43
47
  This is a WebAssembly build of SQLite with support for writing SQLite virtual filesystems completely in Javascript. This allows alternative browser storage options such as IndexedDB and Origin Private File System. Applications can opt to use either a synchronous or asynchronous (using Asyncify or JSPI) SQLite library build (an asynchronous build is required for asynchronous extensions).
44
48
 
45
49
  IndexedDB and several Origin Private File System virtual file systems are among the examples provided as proof of concept. A table comparing the different VFS classes is [here](https://github.com/rhashimoto/wa-sqlite/tree/master/src/examples#vfs-comparison).
@@ -47,6 +51,7 @@ IndexedDB and several Origin Private File System virtual file systems are among
47
51
  [Try the demo](https://rhashimoto.github.io/wa-sqlite/demo/?build=asyncify&config=IDBBatchAtomicVFS&reset) or run [benchmarks](https://rhashimoto.github.io/wa-sqlite/demo/benchmarks/?config=asyncify,IDBBatchAtomicVFS;asyncify,IDBMirrorVFS;default,AccessHandlePoolVFS;default,OPFSCoopSyncVFS;asyncify,OPFSAdaptiveVFS;asyncify,OPFSPermutedVFS) with a modern desktop web browser. More information is available in the [FAQ](https://github.com/rhashimoto/wa-sqlite/issues?q=is%3Aissue+label%3Afaq+), [discussion forums](https://github.com/rhashimoto/wa-sqlite/discussions), and [API reference](https://rhashimoto.github.io/wa-sqlite/docs/).
48
52
 
49
53
  ## Build
54
+
50
55
  The primary motivation for this project is to enable additions to SQLite with only Javascript. Most developers should be able to use the pre-built artifacts in
51
56
  [./dist](https://github.com/rhashimoto/wa-sqlite/tree/master/dist).
52
57
  Note that earlier versions of the project only provided pre-built artifacts in the
@@ -56,38 +61,40 @@ Minor build customization (e.g. changing build defines or flags) can be done wit
56
61
 
57
62
  If you do want to build yourself, here are the prerequisites:
58
63
 
59
- * Building on Debian Linux is known to work, compatibility with other platforms is unknown.
60
- * `yarn` - If you use a different package manager (e.g. `npm`) then file paths in the demo will need adjustment.
61
- * [Emscripten SDK](https://emscripten.org/docs/getting_started/downloads.html) 3.1.61+.
62
- * `curl`, `make`, `openssl`, `sed`, `tclsh`, `unzip`
64
+ - Building on Debian Linux is known to work, compatibility with other platforms is unknown.
65
+ - `yarn` - If you use a different package manager (e.g. `npm`) then file paths in the demo will need adjustment.
66
+ - [Emscripten SDK](https://emscripten.org/docs/getting_started/downloads.html) 3.1.61+.
67
+ - `curl`, `make`, `openssl`, `sed`, `tclsh`, `unzip`
63
68
 
64
69
  Here are the build steps:
65
- * Make sure `emcc` works.
66
- * `git clone git@github.com:rhashimoto/wa-sqlite.git`
67
- * `cd wa-sqlite`
68
- * `yarn install`
69
- * `make`
70
+
71
+ - Make sure `emcc` works.
72
+ - `git clone git@github.com:rhashimoto/wa-sqlite.git`
73
+ - `cd wa-sqlite`
74
+ - `yarn install`
75
+ - `make`
70
76
 
71
77
  The default build produces ES6 modules + WASM, [synchronous and asynchronous](https://github.com/rhashimoto/wa-sqlite/issues/7) (using Asyncify and JSPI) in `dist/`.
72
78
 
73
79
  ## API
80
+
74
81
  Javascript wrappers for core SQLITE C API functions (and some others) are provided. Some convenience functions are also provided to reduce boilerplate. Here is sample code to load the library and call the API:
75
82
 
76
83
  ```javascript
77
- import SQLiteESMFactory from 'wa-sqlite/dist/wa-sqlite.mjs';
78
- import * as SQLite from 'wa-sqlite';
79
-
80
- async function hello() {
81
- const module = await SQLiteESMFactory();
82
- const sqlite3 = SQLite.Factory(module);
83
- const db = await sqlite3.open_v2('myDB');
84
- await sqlite3.exec(db, `SELECT 'Hello, world!'`, (row, columns) => {
85
- console.log(row);
86
- });
87
- await sqlite3.close(db);
88
- }
89
-
90
- hello();
84
+ import SQLiteESMFactory from 'wa-sqlite/dist/wa-sqlite.mjs'
85
+ import * as SQLite from 'wa-sqlite'
86
+
87
+ async function hello() {
88
+ const module = await SQLiteESMFactory()
89
+ const sqlite3 = SQLite.Factory(module)
90
+ const db = await sqlite3.open_v2('myDB')
91
+ await sqlite3.exec(db, `SELECT 'Hello, world!'`, (row, columns) => {
92
+ console.log(row)
93
+ })
94
+ await sqlite3.close(db)
95
+ }
96
+
97
+ hello()
91
98
  ```
92
99
 
93
100
  There is a slightly more complicated example [here](https://github.com/rhashimoto/wa-sqlite/tree/master/demo/hello) that also shows how to use a virtual filesystem (VFS) for persistent storage.
@@ -97,21 +104,24 @@ The [implementation of `sqlite3.exec`](https://github.com/rhashimoto/wa-sqlite/b
97
104
  [API reference](https://rhashimoto.github.io/wa-sqlite/docs/)
98
105
 
99
106
  ## Demo
107
+
100
108
  To serve the demo directly from the source tree:
101
- * `yarn start`
102
- * Open a browser on http://localhost:8000/demo/?build=asyncify&config=IDBBatchAtomicVFS&reset
109
+
110
+ - `yarn start`
111
+ - Open a browser on http://localhost:8000/demo/?build=asyncify&config=IDBBatchAtomicVFS&reset
103
112
 
104
113
  The demo page provides access to databases on multiple VFS implementations. Query parameters on the demo page URL can be used to specify the configuration and initial state:
105
114
 
106
- | Parameter | Purpose | Values | Default |
107
- |----|----|----|----|
108
- | build | Emscripten build type | default, asyncify, jspi | default |
109
- | config | select VFS | MemoryVFS, MemoryAsyncVFS, IDBBatchAtomicVFS, IDBMirrorVFS, AccessHandlePoolVFS, OPFSAdaptiveVFS, OPFSAnyContextVFS, OPFSCoopSyncVFS, OPFSPermutedVFS | uses SQLite internal memory |
110
- | reset | clear persistent storage | | |
115
+ | Parameter | Purpose | Values | Default |
116
+ | --------- | ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------- |
117
+ | build | Emscripten build type | default, asyncify, jspi | default |
118
+ | config | select VFS | MemoryVFS, MemoryAsyncVFS, IDBBatchAtomicVFS, IDBMirrorVFS, AccessHandlePoolVFS, OPFSAdaptiveVFS, OPFSAnyContextVFS, OPFSCoopSyncVFS, OPFSPermutedVFS | uses SQLite internal memory |
119
+ | reset | clear persistent storage | | |
111
120
 
112
121
  For convenience, if any text region is selected in the editor, only that region will be executed. In addition, the editor contents are restored across page reloads using browser localStorage.
113
122
 
114
123
  ## License
124
+
115
125
  MIT License as of February 10, 2023, changed by generous sponsors
116
126
  [Fleet Device Management](https://fleetdm.com/) and [Reflect](https://reflect.app/).
117
127
  Existing licensees may continue under the GPLv3 or switch to the new license.
package/dist/README.md CHANGED
@@ -3,8 +3,8 @@
3
3
  This dist directory was built with the following configuration:
4
4
 
5
5
  ## Build Environment
6
- - **Built on:** 2025-08-28 07:48:15 UTC
7
- - **Emscripten:** emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.12-git
6
+ - **Built on:** 2026-02-10 16:25:57 UTC
7
+ - **Emscripten:** emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.23-git
8
8
  - **SQLite Version:** 3.50.4
9
9
  - **SQLite Commit:** 8ed5e7365e6f12f427910188bbf6b254daad2ef6
10
10
 
@@ -45,19 +45,19 @@ Generated via: `nix build .#wa-sqlite-livestore`
45
45
 
46
46
  ### Standard Build Sizes
47
47
  - **wa-sqlite-async.mjs**: 113K (gzip: 27.4K, brotli: 23.9K)
48
- - **wa-sqlite-jspi.mjs**: 115K (gzip: 27.0K, brotli: 23.5K)
49
- - **wa-sqlite.mjs**: 107K (gzip: 25.9K, brotli: 22.6K)
50
- - **wa-sqlite.node.mjs**: 108K (gzip: 26.0K, brotli: 22.7K)
51
- - **wa-sqlite-async.wasm**: 1.3M (gzip: 453.3K, brotli: 358.4K)
52
- - **wa-sqlite-jspi.wasm**: 611K (gzip: 298.0K, brotli: 256.4K)
53
- - **wa-sqlite.node.wasm**: 605K (gzip: 296.5K, brotli: 254.8K)
54
- - **wa-sqlite.wasm**: 605K (gzip: 296.5K, brotli: 254.8K)
48
+ - **wa-sqlite-jspi.mjs**: 115K (gzip: 26.9K, brotli: 23.3K)
49
+ - **wa-sqlite.mjs**: 107K (gzip: 25.8K, brotli: 22.6K)
50
+ - **wa-sqlite.node.mjs**: 108K (gzip: 25.9K, brotli: 22.7K)
51
+ - **wa-sqlite-async.wasm**: 1.3M (gzip: 453.1K, brotli: 357.9K)
52
+ - **wa-sqlite-jspi.wasm**: 611K (gzip: 298.0K, brotli: 256.3K)
53
+ - **wa-sqlite.node.wasm**: 605K (gzip: 296.4K, brotli: 254.8K)
54
+ - **wa-sqlite.wasm**: 605K (gzip: 296.4K, brotli: 254.8K)
55
55
 
56
56
  ### FTS5 Variant Sizes
57
- - **fts5/wa-sqlite.mjs**: 107K (gzip: 25.9K, brotli: 22.6K)
58
- - **fts5/wa-sqlite.node.mjs**: 108K (gzip: 26.0K, brotli: 22.8K)
59
- - **fts5/wa-sqlite.node.wasm**: 719K (gzip: 353.0K, brotli: 303.6K)
60
- - **fts5/wa-sqlite.wasm**: 719K (gzip: 353.0K, brotli: 303.6K)
57
+ - **fts5/wa-sqlite.mjs**: 107K (gzip: 25.8K, brotli: 22.5K)
58
+ - **fts5/wa-sqlite.node.mjs**: 108K (gzip: 26.0K, brotli: 22.7K)
59
+ - **fts5/wa-sqlite.node.wasm**: 719K (gzip: 352.2K, brotli: 303.4K)
60
+ - **fts5/wa-sqlite.wasm**: 719K (gzip: 352.2K, brotli: 303.4K)
61
61
 
62
62
  ## Notes
63
63
  - All builds include session extension for data synchronization