@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
@@ -1,100 +1,95 @@
1
1
  // Copyright 2024 Roy T. Hashimoto. All Rights Reserved.
2
- import { MemoryVFS } from './MemoryVFS.js';
2
+ import { MemoryVFS } from './MemoryVFS.js'
3
3
 
4
4
  // Sample asynchronous in-memory filesystem. This filesystem requires an
5
5
  // asynchronous WebAssembly build (Asyncify or JSPI).
6
6
  export class MemoryAsyncVFS extends MemoryVFS {
7
-
8
7
  static async create(name, module) {
9
- const vfs = new MemoryVFS(name, module);
10
- await vfs.isReady();
11
- return vfs;
12
- }
13
-
14
- constructor(name, module) {
15
- super(name, module);
8
+ const vfs = new MemoryVFS(name, module)
9
+ await vfs.isReady()
10
+ return vfs
16
11
  }
17
12
 
18
13
  async close() {
19
14
  for (const fileId of this.mapIdToFile.keys()) {
20
- await this.xClose(fileId);
15
+ await this.xClose(fileId)
21
16
  }
22
17
  }
23
18
 
24
19
  /**
25
- * @param {string?} name
26
- * @param {number} fileId
27
- * @param {number} flags
28
- * @param {DataView} pOutFlags
20
+ * @param {string?} name
21
+ * @param {number} fileId
22
+ * @param {number} flags
23
+ * @param {DataView} pOutFlags
29
24
  * @returns {Promise<number>}
30
25
  */
31
26
  async jOpen(name, fileId, flags, pOutFlags) {
32
- return super.jOpen(name, fileId, flags, pOutFlags);
27
+ return super.jOpen(name, fileId, flags, pOutFlags)
33
28
  }
34
29
 
35
30
  /**
36
- * @param {number} fileId
31
+ * @param {number} fileId
37
32
  * @returns {Promise<number>}
38
33
  */
39
34
  async jClose(fileId) {
40
- return super.jClose(fileId);
35
+ return super.jClose(fileId)
41
36
  }
42
37
 
43
38
  /**
44
- * @param {number} fileId
45
- * @param {Uint8Array} pData
39
+ * @param {number} fileId
40
+ * @param {Uint8Array} pData
46
41
  * @param {number} iOffset
47
42
  * @returns {Promise<number>}
48
43
  */
49
44
  async jRead(fileId, pData, iOffset) {
50
- return super.jRead(fileId, pData, iOffset);
45
+ return super.jRead(fileId, pData, iOffset)
51
46
  }
52
47
 
53
48
  /**
54
- * @param {number} fileId
55
- * @param {Uint8Array} pData
49
+ * @param {number} fileId
50
+ * @param {Uint8Array} pData
56
51
  * @param {number} iOffset
57
52
  * @returns {Promise<number>}
58
53
  */
59
54
  async jWrite(fileId, pData, iOffset) {
60
- return super.jWrite(fileId, pData, iOffset);
55
+ return super.jWrite(fileId, pData, iOffset)
61
56
  }
62
57
 
63
58
  /**
64
- * @param {number} fileId
65
- * @param {number} iSize
59
+ * @param {number} fileId
60
+ * @param {number} iSize
66
61
  * @returns {Promise<number>}
67
62
  */
68
63
  async xTruncate(fileId, iSize) {
69
- return super.jTruncate(fileId, iSize);
64
+ return super.jTruncate(fileId, iSize)
70
65
  }
71
66
 
72
67
  /**
73
- * @param {number} fileId
74
- * @param {DataView} pSize64
68
+ * @param {number} fileId
69
+ * @param {DataView} pSize64
75
70
  * @returns {Promise<number>}
76
71
  */
77
72
  async jFileSize(fileId, pSize64) {
78
- return super.jFileSize(fileId, pSize64);
73
+ return super.jFileSize(fileId, pSize64)
79
74
  }
80
75
 
81
76
  /**
82
- *
83
- * @param {string} name
84
- * @param {number} syncDir
77
+ *
78
+ * @param {string} name
79
+ * @param {number} syncDir
85
80
  * @returns {Promise<number>}
86
81
  */
87
82
  async jDelete(name, syncDir) {
88
- return super.jDelete(name, syncDir);
83
+ return super.jDelete(name, syncDir)
89
84
  }
90
85
 
91
86
  /**
92
- * @param {string} name
93
- * @param {number} flags
94
- * @param {DataView} pResOut
87
+ * @param {string} name
88
+ * @param {number} flags
89
+ * @param {DataView} pResOut
95
90
  * @returns {Promise<number>}
96
91
  */
97
92
  async jAccess(name, flags, pResOut) {
98
- return super.jAccess(name, flags, pResOut);
93
+ return super.jAccess(name, flags, pResOut)
99
94
  }
100
95
  }
@@ -1,43 +1,39 @@
1
1
  // Copyright 2024 Roy T. Hashimoto. All Rights Reserved.
2
- import { FacadeVFS } from '../FacadeVFS.js';
3
- import * as VFS from '../VFS.js';
2
+ import { FacadeVFS } from '../FacadeVFS.js'
3
+ import * as VFS from '../VFS.js'
4
4
 
5
5
  // Sample in-memory filesystem.
6
6
  export class MemoryVFS extends FacadeVFS {
7
7
  // Map of existing files, keyed by filename.
8
- mapNameToFile = new Map();
8
+ mapNameToFile = new Map()
9
9
 
10
10
  // Map of open files, keyed by id (sqlite3_file pointer).
11
- mapIdToFile = new Map();
11
+ mapIdToFile = new Map()
12
12
 
13
13
  static async create(name, module) {
14
- const vfs = new MemoryVFS(name, module);
15
- await vfs.isReady();
16
- return vfs;
17
- }
18
-
19
- constructor(name, module) {
20
- super(name, module);
14
+ const vfs = new MemoryVFS(name, module)
15
+ await vfs.isReady()
16
+ return vfs
21
17
  }
22
18
 
23
19
  close() {
24
20
  for (const fileId of this.mapIdToFile.keys()) {
25
- this.jClose(fileId);
21
+ this.jClose(fileId)
26
22
  }
27
23
  }
28
24
 
29
25
  /**
30
- * @param {string?} filename
31
- * @param {number} fileId
32
- * @param {number} flags
33
- * @param {DataView} pOutFlags
26
+ * @param {string?} filename
27
+ * @param {number} fileId
28
+ * @param {number} flags
29
+ * @param {DataView} pOutFlags
34
30
  * @returns {number|Promise<number>}
35
31
  */
36
32
  jOpen(filename, fileId, flags, pOutFlags) {
37
- const url = new URL(filename || Math.random().toString(36).slice(2), 'file://');
38
- const pathname = url.pathname;
33
+ const url = new URL(filename || Math.random().toString(36).slice(2), 'file://')
34
+ const pathname = url.pathname
39
35
 
40
- let file = this.mapNameToFile.get(pathname);
36
+ let file = this.mapNameToFile.get(pathname)
41
37
  if (!file) {
42
38
  if (flags & VFS.SQLITE_OPEN_CREATE) {
43
39
  // Create a new file object.
@@ -45,132 +41,132 @@ export class MemoryVFS extends FacadeVFS {
45
41
  pathname,
46
42
  flags,
47
43
  size: 0,
48
- data: new ArrayBuffer(0)
49
- };
50
- this.mapNameToFile.set(pathname, file);
44
+ data: new ArrayBuffer(0),
45
+ }
46
+ this.mapNameToFile.set(pathname, file)
51
47
  } else {
52
- return VFS.SQLITE_CANTOPEN;
48
+ return VFS.SQLITE_CANTOPEN
53
49
  }
54
50
  }
55
51
 
56
52
  // Put the file in the opened files map.
57
- this.mapIdToFile.set(fileId, file);
58
- pOutFlags.setInt32(0, flags, true);
59
- return VFS.SQLITE_OK;
53
+ this.mapIdToFile.set(fileId, file)
54
+ pOutFlags.setInt32(0, flags, true)
55
+ return VFS.SQLITE_OK
60
56
  }
61
57
 
62
58
  /**
63
- * @param {number} fileId
59
+ * @param {number} fileId
64
60
  * @returns {number|Promise<number>}
65
61
  */
66
62
  jClose(fileId) {
67
- const file = this.mapIdToFile.get(fileId);
68
- this.mapIdToFile.delete(fileId);
63
+ const file = this.mapIdToFile.get(fileId)
64
+ this.mapIdToFile.delete(fileId)
69
65
 
70
66
  if (file.flags & VFS.SQLITE_OPEN_DELETEONCLOSE) {
71
- this.mapNameToFile.delete(file.pathname);
67
+ this.mapNameToFile.delete(file.pathname)
72
68
  }
73
- return VFS.SQLITE_OK;
69
+ return VFS.SQLITE_OK
74
70
  }
75
71
 
76
72
  /**
77
- * @param {number} fileId
78
- * @param {Uint8Array} pData
73
+ * @param {number} fileId
74
+ * @param {Uint8Array} pData
79
75
  * @param {number} iOffset
80
76
  * @returns {number|Promise<number>}
81
77
  */
82
78
  jRead(fileId, pData, iOffset) {
83
- const file = this.mapIdToFile.get(fileId);
79
+ const file = this.mapIdToFile.get(fileId)
84
80
 
85
81
  // Clip the requested read to the file boundary.
86
- const bgn = Math.min(iOffset, file.size);
87
- const end = Math.min(iOffset + pData.byteLength, file.size);
88
- const nBytes = end - bgn;
82
+ const bgn = Math.min(iOffset, file.size)
83
+ const end = Math.min(iOffset + pData.byteLength, file.size)
84
+ const nBytes = end - bgn
89
85
 
90
86
  if (nBytes) {
91
- pData.set(new Uint8Array(file.data, bgn, nBytes));
87
+ pData.set(new Uint8Array(file.data, bgn, nBytes))
92
88
  }
93
89
 
94
90
  if (nBytes < pData.byteLength) {
95
91
  // Zero unused area of read buffer.
96
- pData.fill(0, nBytes);
97
- return VFS.SQLITE_IOERR_SHORT_READ;
92
+ pData.fill(0, nBytes)
93
+ return VFS.SQLITE_IOERR_SHORT_READ
98
94
  }
99
- return VFS.SQLITE_OK;
95
+ return VFS.SQLITE_OK
100
96
  }
101
97
 
102
98
  /**
103
- * @param {number} fileId
104
- * @param {Uint8Array} pData
99
+ * @param {number} fileId
100
+ * @param {Uint8Array} pData
105
101
  * @param {number} iOffset
106
102
  * @returns {number|Promise<number>}
107
103
  */
108
104
  jWrite(fileId, pData, iOffset) {
109
- const file = this.mapIdToFile.get(fileId);
105
+ const file = this.mapIdToFile.get(fileId)
110
106
  if (iOffset + pData.byteLength > file.data.byteLength) {
111
107
  // Resize the ArrayBuffer to hold more data.
112
- const newSize = Math.max(iOffset + pData.byteLength, 2 * file.data.byteLength);
113
- const data = new ArrayBuffer(newSize);
114
- new Uint8Array(data).set(new Uint8Array(file.data, 0, file.size));
115
- file.data = data;
108
+ const newSize = Math.max(iOffset + pData.byteLength, 2 * file.data.byteLength)
109
+ const data = new ArrayBuffer(newSize)
110
+ new Uint8Array(data).set(new Uint8Array(file.data, 0, file.size))
111
+ file.data = data
116
112
  }
117
113
 
118
114
  // Copy data.
119
- new Uint8Array(file.data, iOffset, pData.byteLength).set(pData.subarray());
120
- file.size = Math.max(file.size, iOffset + pData.byteLength);
121
- return VFS.SQLITE_OK;
115
+ new Uint8Array(file.data, iOffset, pData.byteLength).set(pData.subarray())
116
+ file.size = Math.max(file.size, iOffset + pData.byteLength)
117
+ return VFS.SQLITE_OK
122
118
  }
123
119
 
124
120
  /**
125
- * @param {number} fileId
126
- * @param {number} iSize
121
+ * @param {number} fileId
122
+ * @param {number} iSize
127
123
  * @returns {number|Promise<number>}
128
124
  */
129
125
  jTruncate(fileId, iSize) {
130
- const file = this.mapIdToFile.get(fileId);
126
+ const file = this.mapIdToFile.get(fileId)
131
127
 
132
128
  // For simplicity we don't make the ArrayBuffer smaller.
133
- file.size = Math.min(file.size, iSize);
134
- return VFS.SQLITE_OK;
129
+ file.size = Math.min(file.size, iSize)
130
+ return VFS.SQLITE_OK
135
131
  }
136
132
 
137
133
  /**
138
- * @param {number} fileId
139
- * @param {DataView} pSize64
134
+ * @param {number} fileId
135
+ * @param {DataView} pSize64
140
136
  * @returns {number|Promise<number>}
141
137
  */
142
138
  jFileSize(fileId, pSize64) {
143
- const file = this.mapIdToFile.get(fileId);
139
+ const file = this.mapIdToFile.get(fileId)
144
140
 
145
- pSize64.setBigInt64(0, BigInt(file.size), true);
146
- return VFS.SQLITE_OK;
141
+ pSize64.setBigInt64(0, BigInt(file.size), true)
142
+ return VFS.SQLITE_OK
147
143
  }
148
144
 
149
145
  /**
150
- * @param {string} name
151
- * @param {number} syncDir
146
+ * @param {string} name
147
+ * @param {number} syncDir
152
148
  * @returns {number|Promise<number>}
153
149
  */
154
150
  jDelete(name, syncDir) {
155
- const url = new URL(name, 'file://');
156
- const pathname = url.pathname;
151
+ const url = new URL(name, 'file://')
152
+ const pathname = url.pathname
157
153
 
158
- this.mapNameToFile.delete(pathname);
159
- return VFS.SQLITE_OK;
154
+ this.mapNameToFile.delete(pathname)
155
+ return VFS.SQLITE_OK
160
156
  }
161
157
 
162
158
  /**
163
- * @param {string} name
164
- * @param {number} flags
165
- * @param {DataView} pResOut
159
+ * @param {string} name
160
+ * @param {number} flags
161
+ * @param {DataView} pResOut
166
162
  * @returns {number|Promise<number>}
167
163
  */
168
164
  jAccess(name, flags, pResOut) {
169
- const url = new URL(name, 'file://');
170
- const pathname = url.pathname;
165
+ const url = new URL(name, 'file://')
166
+ const pathname = url.pathname
171
167
 
172
- const file = this.mapNameToFile.get(pathname);
173
- pResOut.setInt32(0, file ? 1 : 0, true);
174
- return VFS.SQLITE_OK;
168
+ const file = this.mapNameToFile.get(pathname)
169
+ pResOut.setInt32(0, file ? 1 : 0, true)
170
+ return VFS.SQLITE_OK
175
171
  }
176
172
  }