@livestore/wa-sqlite 0.0.0-snapshot-b9a2e1dee494215d8c403be013e25cbf4d2cf380

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 (64) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +111 -0
  3. package/dist/README.md +64 -0
  4. package/dist/fts5/wa-sqlite.mjs +2 -0
  5. package/dist/fts5/wa-sqlite.node.mjs +2 -0
  6. package/dist/fts5/wa-sqlite.node.wasm +0 -0
  7. package/dist/fts5/wa-sqlite.wasm +0 -0
  8. package/dist/wa-sqlite-async.mjs +2 -0
  9. package/dist/wa-sqlite-async.wasm +0 -0
  10. package/dist/wa-sqlite-jspi.mjs +2 -0
  11. package/dist/wa-sqlite-jspi.wasm +0 -0
  12. package/dist/wa-sqlite.mjs +2 -0
  13. package/dist/wa-sqlite.node.mjs +2 -0
  14. package/dist/wa-sqlite.node.wasm +0 -0
  15. package/dist/wa-sqlite.wasm +0 -0
  16. package/package.json +57 -0
  17. package/src/FacadeVFS.js +681 -0
  18. package/src/VFS.js +222 -0
  19. package/src/WebLocksMixin.js +414 -0
  20. package/src/examples/AccessHandlePoolVFS.js +458 -0
  21. package/src/examples/IDBBatchAtomicVFS.js +827 -0
  22. package/src/examples/IDBMirrorVFS.js +889 -0
  23. package/src/examples/MemoryAsyncVFS.js +100 -0
  24. package/src/examples/MemoryVFS.js +176 -0
  25. package/src/examples/OPFSAdaptiveVFS.js +437 -0
  26. package/src/examples/OPFSAnyContextVFS.js +300 -0
  27. package/src/examples/OPFSCoopSyncVFS.js +590 -0
  28. package/src/examples/OPFSPermutedVFS.js +1217 -0
  29. package/src/examples/README.md +89 -0
  30. package/src/examples/tag.js +82 -0
  31. package/src/sqlite-api.js +1339 -0
  32. package/src/sqlite-constants.js +275 -0
  33. package/src/types/globals.d.ts +60 -0
  34. package/src/types/index.d.ts +1531 -0
  35. package/src/types/tsconfig.json +6 -0
  36. package/test/AccessHandlePoolVFS.test.js +27 -0
  37. package/test/IDBBatchAtomicVFS.test.js +97 -0
  38. package/test/IDBMirrorVFS.test.js +27 -0
  39. package/test/MemoryAsyncVFS.test.js +27 -0
  40. package/test/MemoryVFS.test.js +27 -0
  41. package/test/OPFSAdaptiveVFS.test.js +27 -0
  42. package/test/OPFSAnyContextVFS.test.js +27 -0
  43. package/test/OPFSCoopSyncVFS.test.js +27 -0
  44. package/test/OPFSPermutedVFS.test.js +27 -0
  45. package/test/TestContext.js +96 -0
  46. package/test/WebLocksMixin.test.js +521 -0
  47. package/test/api.test.js +49 -0
  48. package/test/api_exec.js +89 -0
  49. package/test/api_misc.js +63 -0
  50. package/test/api_statements.js +447 -0
  51. package/test/callbacks.test.js +581 -0
  52. package/test/data/idbv5.json +1 -0
  53. package/test/sql.test.js +64 -0
  54. package/test/sql_0001.js +49 -0
  55. package/test/sql_0002.js +52 -0
  56. package/test/sql_0003.js +83 -0
  57. package/test/sql_0004.js +81 -0
  58. package/test/sql_0005.js +76 -0
  59. package/test/test-worker.js +204 -0
  60. package/test/vfs_xAccess.js +2 -0
  61. package/test/vfs_xClose.js +52 -0
  62. package/test/vfs_xOpen.js +91 -0
  63. package/test/vfs_xRead.js +38 -0
  64. package/test/vfs_xWrite.js +36 -0
@@ -0,0 +1,1531 @@
1
+ /**
2
+ * This is a WebAssembly build of SQLite with experimental support for
3
+ * writing SQLite virtual file systems and modules (for virtual tables)
4
+ * in Javascript. Also see the
5
+ * [GitHub repository](https://github.com/rhashimoto/wa-sqlite) and the
6
+ * [online demo](https://rhashimoto.github.io/wa-sqlite/demo/).
7
+ * @module
8
+ */
9
+
10
+ /**
11
+ * Javascript types that SQLite can use
12
+ *
13
+ * C integer and floating-point types both map to/from Javascript `number`.
14
+ * Blob data can be provided to SQLite as `Uint8Array<ArrayBuffer>` or `number[]` (with
15
+ * each element converted to a byte); SQLite always returns blob data as
16
+ * `Uint8Array<ArrayBuffer>`
17
+ */
18
+ type SQLiteCompatibleType = number|string|Uint8Array<ArrayBuffer>|Array<number>|bigint|null;
19
+
20
+ /**
21
+ * SQLite Virtual File System object
22
+ *
23
+ * Objects with this interface can be passed to {@link SQLiteAPI.vfs_register}
24
+ * to define a new filesystem.
25
+ *
26
+ * There are examples of a synchronous
27
+ * [MemoryVFS.js](https://github.com/rhashimoto/wa-sqlite/blob/master/src/examples/MemoryVFS.js),
28
+ * and asynchronous
29
+ * [MemoryAsyncVFS.js](https://github.com/rhashimoto/wa-sqlite/blob/master/src/examples/MemoryAsyncVFS.js)
30
+ * and
31
+ * [IndexedDbVFS.js](https://github.com/rhashimoto/wa-sqlite/blob/master/src/examples/IndexedDbVFS.js).
32
+ *
33
+ * @see https://sqlite.org/vfs.html
34
+ * @see https://sqlite.org/c3ref/io_methods.html
35
+ */
36
+ interface SQLiteVFS {
37
+ /** Maximum length of a file path in UTF-8 bytes (default 64) */
38
+ mxPathName?: number;
39
+
40
+ name: string;
41
+
42
+ close(): void|Promise<void>;
43
+ isReady(): boolean|Promise<boolean>;
44
+
45
+ /** @see https://sqlite.org/c3ref/io_methods.html */
46
+ xClose(fileId: number): number|Promise<number>;
47
+
48
+ /** @see https://sqlite.org/c3ref/io_methods.html */
49
+ xRead(
50
+ fileId: number,
51
+ pData: number,
52
+ iAmt: number,
53
+ iOffsetLo: number,
54
+ iOffsetHi: number
55
+ ): number|Promise<number>;
56
+
57
+ /** @see https://sqlite.org/c3ref/io_methods.html */
58
+ xWrite(
59
+ fileId: number,
60
+ pData: number,
61
+ iAmt: number,
62
+ iOffsetLo: number,
63
+ iOffsetHi: number
64
+ ): number|Promise<number>;
65
+
66
+ /** @see https://sqlite.org/c3ref/io_methods.html */
67
+ xTruncate(fileId: number, iSizeLo: number, iSizeHi): number|Promise<number>;
68
+
69
+ /** @see https://sqlite.org/c3ref/io_methods.html */
70
+ xSync(fileId: number, flags: number): number|Promise<number>;
71
+
72
+ /** @see https://sqlite.org/c3ref/io_methods.html */
73
+ xFileSize(
74
+ fileId: number,
75
+ pSize64: number
76
+ ): number|Promise<number>;
77
+
78
+ /** @see https://sqlite.org/c3ref/io_methods.html */
79
+ xLock(fileId: number, flags: number): number|Promise<number>;
80
+
81
+ /** @see https://sqlite.org/c3ref/io_methods.html */
82
+ xUnlock(fileId: number, flags: number): number|Promise<number>;
83
+
84
+ /** @see https://sqlite.org/c3ref/io_methods.html */
85
+ xCheckReservedLock(
86
+ fileId: number,
87
+ pResOut: number
88
+ ): number|Promise<number>;
89
+
90
+ /** @see https://sqlite.org/c3ref/io_methods.html */
91
+ xFileControl(
92
+ fileId: number,
93
+ flags: number,
94
+ pOut: number
95
+ ): number|Promise<number>;
96
+
97
+ /** @see https://sqlite.org/c3ref/io_methods.html */
98
+ xDeviceCharacteristics(fileId: number): number|Promise<number>;
99
+
100
+ /** @see https://sqlite.org/c3ref/vfs.html */
101
+ xOpen(
102
+ pVfs: number,
103
+ zName: number,
104
+ pFile: number,
105
+ flags: number,
106
+ pOutFlags: number
107
+ ): number|Promise<number>;
108
+
109
+ /** @see https://sqlite.org/c3ref/vfs.html */
110
+ xDelete(pVfs: number, zName: number, syncDir: number): number|Promise<number>;
111
+
112
+ /** @see https://sqlite.org/c3ref/vfs.html */
113
+ xAccess(
114
+ pVfs: number,
115
+ zName: number,
116
+ flags: number,
117
+ pResOut: number
118
+ ): number|Promise<number>;
119
+ }
120
+
121
+ /**
122
+ * Options object argument for {@link SQLiteAPI['statements']}
123
+ */
124
+ declare interface SQLitePrepareOptions {
125
+ /**
126
+ * Statement handles prepared and yielded by {@link SQLiteAPI['statements']}
127
+ * are normally valid only within the scope of an iteration.
128
+ * Set `unscoped` to `true` to give iterated statements an arbitrary
129
+ * lifetime.
130
+ */
131
+ unscoped?: boolean;
132
+
133
+ /**
134
+ * SQLITE_PREPARE_* flags
135
+ * @see https://www.sqlite.org/c3ref/c_prepare_normalize.html#sqlitepreparepersistent
136
+ */
137
+ flags?: number;
138
+ }
139
+
140
+ /**
141
+ * Javascript wrappers for the SQLite C API (plus a few convenience functions)
142
+ *
143
+ * Function signatures have been slightly modified to be more
144
+ * Javascript-friendly. For the C functions that return an error code,
145
+ * the corresponding Javascript wrapper will throw an exception with a
146
+ * `code` property on an error.
147
+ *
148
+ * Note that a few functions return a Promise in order to accomodate
149
+ * either a synchronous or asynchronous SQLite build, generally those
150
+ * involved with opening/closing a database or executing a statement.
151
+ *
152
+ * To create an instance of the API, follow these steps:
153
+ *
154
+ * ```javascript
155
+ * // Import an ES6 module factory function from one of the
156
+ * // package builds, either '@livestore/wa-sqlite.mjs' (synchronous) or
157
+ * // '@livestore/wa-sqlite-async.mjs' (asynchronous). You should only
158
+ * // use the asynchronous build if you plan to use an
159
+ * // asynchronous VFS or module.
160
+ * import SQLiteESMFactory from '@livestore/wa-sqlite/dist/wa-sqlite.mjs';
161
+ *
162
+ * // Import the Javascript API wrappers.
163
+ * import * as SQLite from '@livestore/wa-sqlite';
164
+ *
165
+ * // Use an async function to simplify Promise handling.
166
+ * (async function() {
167
+ * // Invoke the ES6 module factory to create the SQLite
168
+ * // Emscripten module. This will fetch and compile the
169
+ * // .wasm file.
170
+ * const module = await SQLiteESMFactory();
171
+ *
172
+ * // Use the module to build the API instance.
173
+ * const sqlite3 = SQLite.Factory(module);
174
+ *
175
+ * // Use the API to open and access a database.
176
+ * const db = await sqlite3.open_v2('myDB');
177
+ * ...
178
+ * })();
179
+ * ```
180
+ *
181
+ * @see https://sqlite.org/c3ref/funclist.html
182
+ */
183
+ interface SQLiteAPI {
184
+ /**
185
+ * Bind a collection of values to a statement
186
+ *
187
+ * This convenience function binds values from either an array or object
188
+ * to a prepared statement with placeholder parameters.
189
+ *
190
+ * Array example using numbered parameters (numbering is implicit in
191
+ * this example):
192
+ * ```
193
+ * const sql = 'INSERT INTO tbl VALUES (?, ?, ?)';
194
+ * for await (const stmt of sqlite3.statements(db, sql) {
195
+ * sqlite3.bind_collection(stmt, [42, 'hello', null]);
196
+ * ...
197
+ * }
198
+ * ```
199
+ *
200
+ * Object example using named parameters (':', '@', or '$' prefixes
201
+ * are allowed):
202
+ * ```
203
+ * const sql = 'INSERT INTO tbl VALUES (?, ?, ?)';
204
+ * for await (const stmt of sqlite3.statements(db, sql) {
205
+ * sqlite3.bind_collection(stmt, {
206
+ * '@foo': 42,
207
+ * '@bar': 'hello',
208
+ * '@baz': null,
209
+ * });
210
+ * ...
211
+ * }
212
+ * ```
213
+ *
214
+ * Note that SQLite bindings are indexed beginning with 1, but when
215
+ * binding values from an array `a` the values begin with `a[0]`.
216
+ * @param stmt prepared statement pointer
217
+ * @param bindings
218
+ * @returns `SQLITE_OK` (throws exception on error)
219
+ */
220
+ bind_collection(
221
+ stmt: number,
222
+ bindings: {[index: string]: SQLiteCompatibleType|null}|Array<SQLiteCompatibleType|null>
223
+ ): number;
224
+
225
+ /**
226
+ * Bind value to prepared statement
227
+ *
228
+ * This convenience function calls the appropriate `bind_*` function
229
+ * based on the type of `value`. Note that binding indices begin with 1.
230
+ * @param stmt prepared statement pointer
231
+ * @param i binding index
232
+ * @param value
233
+ * @returns `SQLITE_OK` (throws exception on error)
234
+ */
235
+ bind(stmt: number, i: number, value: SQLiteCompatibleType|null): number;
236
+
237
+ /**
238
+ * Bind blob to prepared statement parameter
239
+ *
240
+ * Note that binding indices begin with 1.
241
+ * @see https://www.sqlite.org/c3ref/bind_blob.html
242
+ * @param stmt prepared statement pointer
243
+ * @param i binding index
244
+ * @param value
245
+ * @returns `SQLITE_OK` (throws exception on error)
246
+ */
247
+ bind_blob(stmt: number, i: number, value: Uint8Array<ArrayBuffer>|Array<number>): number;
248
+
249
+ /**
250
+ * Bind number to prepared statement parameter
251
+ *
252
+ * Note that binding indices begin with 1.
253
+ * @see https://www.sqlite.org/c3ref/bind_blob.html
254
+ * @param stmt prepared statement pointer
255
+ * @param i binding index
256
+ * @param value
257
+ * @returns `SQLITE_OK` (throws exception on error)
258
+ */
259
+ bind_double(stmt: number, i: number, value: number): number;
260
+
261
+ /**
262
+ * Bind number to prepared statement parameter
263
+ *
264
+ * Note that binding indices begin with 1.
265
+ * @see https://www.sqlite.org/c3ref/bind_blob.html
266
+ * @param stmt prepared statement pointer
267
+ * @param i binding index
268
+ * @param value
269
+ * @returns `SQLITE_OK` (throws exception on error)
270
+ */
271
+ bind_int(stmt: number, i: number, value: number): number;
272
+
273
+ /**
274
+ * Bind number to prepared statement parameter
275
+ *
276
+ * Note that binding indices begin with 1.
277
+ * @see https://www.sqlite.org/c3ref/bind_blob.html
278
+ * @param stmt prepared statement pointer
279
+ * @param i binding index
280
+ * @param value
281
+ * @returns `SQLITE_OK` (throws exception on error)
282
+ */
283
+ bind_int64(stmt: number, i: number, value: bigint): number;
284
+
285
+ /**
286
+ * Bind null to prepared statement
287
+ *
288
+ * Note that binding indices begin with 1.
289
+ * @see https://www.sqlite.org/c3ref/bind_blob.html
290
+ * @param stmt prepared statement pointer
291
+ * @param i binding index
292
+ * @returns `SQLITE_OK` (throws exception on error)
293
+ */
294
+ bind_null(stmt: number, i: number): number;
295
+
296
+ /**
297
+ * Get number of bound parameters
298
+ * @see https://www.sqlite.org/c3ref/bind_parameter_count.html
299
+ * @param stmt prepared statement pointer
300
+ * @returns number of statement binding locations
301
+ */
302
+ bind_parameter_count(stmt: number): number;
303
+
304
+ /**
305
+ * Get name of bound parameter
306
+ *
307
+ * Note that binding indices begin with 1.
308
+ * @see https://www.sqlite.org/c3ref/bind_parameter_name.html
309
+ * @param stmt prepared statement pointer
310
+ * @param i binding index
311
+ * @returns binding name
312
+ */
313
+ bind_parameter_name(stmt: number, i: number): string;
314
+
315
+ /**
316
+ * Bind string to prepared statement
317
+ *
318
+ * Note that binding indices begin with 1.
319
+ * @see https://www.sqlite.org/c3ref/bind_blob.html
320
+ * @param stmt prepared statement pointer
321
+ * @param i binding index
322
+ * @param value
323
+ * @returns `SQLITE_OK` (throws exception on error)
324
+ */
325
+ bind_text(stmt: number, i: number, value: string): number;
326
+
327
+ /**
328
+ * Get count of rows modified by last insert/update
329
+ * @see https://www.sqlite.org/c3ref/changes.html
330
+ * @param db database pointer
331
+ * @returns number of rows modified
332
+ */
333
+ changes(db): number;
334
+
335
+ /**
336
+ * https://www.sqlite.org/c3ref/deserialize.html
337
+ * int sqlite3_deserialize(
338
+ * sqlite3 *db, The database connection
339
+ * const char *zSchema, Which DB to reopen with the deserialization
340
+ * unsigned char *pData, The serialized database content
341
+ * sqlite3_int64 szDb, Number bytes in the deserialization
342
+ * sqlite3_int64 szBuf, Total size of buffer pData[]
343
+ * unsigned mFlags Zero or more SQLITE_DESERIALIZE_* flags
344
+ * );
345
+ */
346
+ deserialize(
347
+ db: number,
348
+ zSchema: string,
349
+ pData: Uint8Array<ArrayBuffer>,
350
+ szDb: number,
351
+ szBuf: number,
352
+ mFlags: number
353
+ ): number;
354
+
355
+ /**
356
+ * unsigned char *sqlite3_serialize(
357
+ * sqlite3 *db, The database connection
358
+ * const char *zSchema, Which DB to serialize. ex: "main", "temp", ...
359
+ * sqlite3_int64 *piSize, Write size of the DB here, if not NULL
360
+ * unsigned int mFlags Zero or more SQLITE_SERIALIZE_* flags
361
+ * );
362
+ */
363
+ serialize(
364
+ db: number,
365
+ zSchema: string,
366
+ // mFlags: number
367
+ ): Uint8Array<ArrayBuffer>;
368
+
369
+ // sqlite3_backup *sqlite3_backup_init(
370
+ // sqlite3 *pDest, /* Destination database handle */
371
+ // const char *zDestName, /* Destination database name */
372
+ // sqlite3 *pSource, /* Source database handle */
373
+ // const char *zSourceName /* Source database name */
374
+ // );
375
+ // int sqlite3_backup_step(sqlite3_backup *p, int nPage);
376
+ // int sqlite3_backup_finish(sqlite3_backup *p);
377
+ // int sqlite3_backup_remaining(sqlite3_backup *p);
378
+ // int sqlite3_backup_pagecount(sqlite3_backup *p);
379
+
380
+ backup_init(
381
+ pDest: number,
382
+ zDestName: string,
383
+ pSource: number,
384
+ zSourceName: string
385
+ ): number;
386
+
387
+ backup_step(p: number, nPage: number): number;
388
+ backup_finish(p: number): number;
389
+ backup_remaining(p: number): number;
390
+ backup_pagecount(p: number): number;
391
+
392
+ /**
393
+ * Combines the `backup_init`, `backup_step`, and `backup_finish` functions.
394
+ * destName/sourceName is usually "main" or "temp".
395
+ *
396
+ * @returns `SQLITE_OK` (throws exception on error)
397
+ */
398
+ backup(pDest: number, zDestName: string, pSource: number, zSourceName: string): number;
399
+
400
+ /**
401
+ * Reset all bindings on a prepared statement.
402
+ * @see https://www.sqlite.org/c3ref/clear_bindings.html
403
+ * @param stmt prepared statement pointer
404
+ * @returns `SQLITE_OK` (throws exception on error)
405
+ */
406
+ clear_bindings(stmt: number): number;
407
+
408
+ /**
409
+ * Close database connection
410
+ * @see https://www.sqlite.org/c3ref/close.html
411
+ * @param db database pointer
412
+ * @returns `SQLITE_OK` (throws exception on error)
413
+ */
414
+ close(db): Promise<number>;
415
+
416
+ /**
417
+ * Call the appropriate `column_*` function based on the column type
418
+ *
419
+ * The type is determined by calling {@link column_type}, which may
420
+ * not match the type declared in `CREATE TABLE`. Note that if the column
421
+ * value is a blob then as with `column_blob` the result may be invalid
422
+ * after the next SQLite call; copy if it needs to be retained.
423
+ *
424
+ * Integer values are returned as Number if within the min/max safe
425
+ * integer bounds, otherwise they are returned as BigInt.
426
+ * @param stmt prepared statement pointer
427
+ * @param i column index
428
+ * @returns column value
429
+ */
430
+ column(stmt: number, i: number): SQLiteCompatibleType;
431
+
432
+ /**
433
+ * Extract a column value from a row after a prepared statment {@link step}
434
+ *
435
+ * The contents of the returned buffer may be invalid after the
436
+ * next SQLite call. Make a copy of the data (e.g. with `.slice()`)
437
+ * if longer retention is required.
438
+ * @see https://www.sqlite.org/c3ref/column_blob.html
439
+ * @param stmt prepared statement pointer
440
+ * @param i column index
441
+ * @returns column value
442
+ */
443
+ column_blob(stmt: number, i: number): Uint8Array<ArrayBuffer>;
444
+
445
+ /**
446
+ * Get storage size for column text or blob
447
+ * @see https://www.sqlite.org/c3ref/column_blob.html
448
+ * @param stmt prepared statement pointer
449
+ * @param i column index
450
+ * @returns number of bytes in column text or blob
451
+ */
452
+ column_bytes(stmt: number, i: number): number;
453
+
454
+ /**
455
+ * Get number of columns for a prepared statement
456
+ * @see https://www.sqlite.org/c3ref/column_blob.html
457
+ * @param stmt prepared statement pointer
458
+ * @returns number of columns
459
+ */
460
+ column_count(stmt: number): number;
461
+
462
+ /**
463
+ * Extract a column value from a row after a prepared statment {@link step}
464
+ * @see https://www.sqlite.org/c3ref/column_blob.html
465
+ * @param stmt prepared statement pointer
466
+ * @param i column index
467
+ * @returns column value
468
+ */
469
+ column_double(stmt: number, i: number): number;
470
+
471
+ /**
472
+ * Extract a column value from a row after a prepared statment {@link step}
473
+ * @see https://www.sqlite.org/c3ref/column_blob.html
474
+ * @param stmt prepared statement pointer
475
+ * @param i column index
476
+ * @returns column value
477
+ */
478
+ column_int(stmt: number, i: number): number;
479
+
480
+ /**
481
+ * Extract a column value from a row after a prepared statment {@link step}
482
+ * @see https://www.sqlite.org/c3ref/column_blob.html
483
+ * @param stmt prepared statement pointer
484
+ * @param i column index
485
+ * @returns column value
486
+ */
487
+ column_int64(stmt: number, i: number): bigint;
488
+
489
+ /**
490
+ * Get a column name for a prepared statement
491
+ * @see https://www.sqlite.org/c3ref/column_blob.html
492
+ * @param stmt prepared statement pointer
493
+ * @param i column index
494
+ * @returns column name
495
+ */
496
+ column_name(stmt: number, i: number): string;
497
+
498
+ /**
499
+ * Get names for all columns of a prepared statement
500
+ *
501
+ * This is a convenience function that calls {@link column_count} and
502
+ * {@link column_name}.
503
+ * @param stmt
504
+ * @returns array of column names
505
+ */
506
+ column_names(stmt: number): Array<string>;
507
+
508
+ /**
509
+ * Extract a column value from a row after a prepared statment {@link step}
510
+ * @see https://www.sqlite.org/c3ref/column_blob.html
511
+ * @param stmt prepared statement pointer
512
+ * @param i column index
513
+ * @returns column value
514
+ */
515
+ column_text(stmt: number, i: number): string;
516
+
517
+ /**
518
+ * Get column type for a prepared statement
519
+ *
520
+ * Note that this type may not match the type declared in `CREATE TABLE`.
521
+ * @see https://www.sqlite.org/c3ref/column_blob.html
522
+ * @param stmt prepared statement pointer
523
+ * @param i column index
524
+ * @returns enumeration value for type
525
+ */
526
+ column_type(stmt: number, i: number): number;
527
+
528
+ /**
529
+ * Register a commit hook
530
+ *
531
+ * @see https://www.sqlite.org/c3ref/commit_hook.html
532
+ *
533
+ * @param db database pointer
534
+ * @param callback If a non-zero value is returned, commit is converted into
535
+ * a rollback; disables callback when null
536
+ */
537
+ commit_hook(
538
+ db: number,
539
+ callback: (() => number) | null): void;
540
+
541
+ /**
542
+ * Create or redefine SQL functions
543
+ *
544
+ * The application data passed is ignored. Use closures instead.
545
+ *
546
+ * If any callback function returns a Promise, that function must
547
+ * be declared `async`, i.e. it must allow use of `await`.
548
+ * @see https://sqlite.org/c3ref/create_function.html
549
+ * @param db database pointer
550
+ * @param zFunctionName
551
+ * @param nArg number of function arguments
552
+ * @param eTextRep text encoding (and other flags)
553
+ * @param pApp application data (ignored)
554
+ * @param xFunc
555
+ * @param xStep
556
+ * @param xFinal
557
+ * @returns `SQLITE_OK` (throws exception on error)
558
+ */
559
+ create_function(
560
+ db: number,
561
+ zFunctionName: string,
562
+ nArg: number,
563
+ eTextRep: number,
564
+ pApp: number,
565
+ xFunc?: (context: number, values: Uint32Array) => void|Promise<void>,
566
+ xStep?: (context: number, values: Uint32Array) => void|Promise<void>,
567
+ xFinal?: (context: number) => void|Promise<void>): number;
568
+
569
+ /**
570
+ * Get number of columns in current row of a prepared statement
571
+ * @see https://www.sqlite.org/c3ref/data_count.html
572
+ * @param stmt prepared statement pointer
573
+ * @returns number of columns
574
+ */
575
+ data_count(stmt: number): number;
576
+
577
+ /**
578
+ * One-step query execution interface
579
+ *
580
+ * The implementation of this function uses {@link row}, which makes a
581
+ * copy of blobs and returns BigInt for integers outside the safe integer
582
+ * bounds for Number.
583
+ * @see https://www.sqlite.org/c3ref/exec.html
584
+ * @param db database pointer
585
+ * @param zSQL queries
586
+ * @param callback called for each output row
587
+ * @returns Promise resolving to `SQLITE_OK` (rejects on error)
588
+ */
589
+ exec(
590
+ db: number,
591
+ zSQL: string,
592
+ callback?: (row: Array<SQLiteCompatibleType|null>, columns: string[]) => void
593
+ // ): Promise<number>;
594
+ ): number;
595
+
596
+ /**
597
+ * Destroy a prepared statement object compiled by {@link statements}
598
+ * with the `unscoped` option set to `true`
599
+ *
600
+ * This function does *not* throw on error.
601
+ * @see https://www.sqlite.org/c3ref/finalize.html
602
+ * @param stmt prepared statement pointer
603
+ * @returns Promise resolving to `SQLITE_OK` or error status
604
+ */
605
+ // finalize(stmt: number): Promise<number>;
606
+ finalize(stmt: number): number;
607
+
608
+ /**
609
+ * Test for autocommit mode
610
+ * @see https://sqlite.org/c3ref/get_autocommit.html
611
+ * @param db database pointer
612
+ * @returns Non-zero if autocommit mode is on, zero otherwise
613
+ */
614
+ get_autocommit(db: number): number;
615
+
616
+ /**
617
+ * Get SQLite library version
618
+ * @see https://www.sqlite.org/c3ref/libversion.html
619
+ * @returns version string, e.g. '3.35.5'
620
+ */
621
+ libversion(): string;
622
+
623
+ /**
624
+ * Get SQLite library version
625
+ * @see https://www.sqlite.org/c3ref/libversion.html
626
+ * @returns version number, e.g. 3035005
627
+ */
628
+ libversion_number(): number
629
+
630
+ /**
631
+ * Set a usage limit on a connection.
632
+ * @see https://www.sqlite.org/c3ref/limit.html
633
+ * @param db database pointer
634
+ * @param id limit category
635
+ * @param newVal
636
+ * @returns previous setting
637
+ */
638
+ limit(
639
+ db: number,
640
+ id: number,
641
+ newVal: number): number;
642
+
643
+ /**
644
+ * Opening a new database connection.
645
+ *
646
+ * Note that this function differs from the C API in that it
647
+ * returns the Promise-wrapped database pointer (instead of a
648
+ * result code).
649
+ * @see https://sqlite.org/c3ref/open.html
650
+ * @param zFilename
651
+ * @param iFlags `SQLite.SQLITE_OPEN_CREATE | SQLite.SQLITE_OPEN_READWRITE` (0x6) if omitted
652
+ * @param zVfs VFS name
653
+ * @returns Promise-wrapped database pointer.
654
+ */
655
+ open_v2(
656
+ zFilename: string,
657
+ iFlags?: number,
658
+ zVfs?: string
659
+ ): Promise<number>;
660
+
661
+ open_v2Sync(
662
+ zFilename: string,
663
+ iFlags?: number,
664
+ zVfs?: string
665
+ ): number;
666
+
667
+ /**
668
+ * Specify callback to be invoked between long-running queries
669
+ *
670
+ * The application data passed is ignored. Use closures instead.
671
+ *
672
+ * If any callback function returns a Promise, that function must
673
+ * be declared `async`, i.e. it must allow use of `await`.
674
+ * @param db database pointer
675
+ * @param nProgressOps target number of database operations between handler invocations
676
+ * @param handler
677
+ * @param userData
678
+ */
679
+ progress_handler(db: number, nProgressOps: number, handler: (userData: any) => number|Promise<number>, userData);
680
+
681
+ /**
682
+ * Reset a prepared statement object
683
+ * @see https://www.sqlite.org/c3ref/reset.html
684
+ * @param stmt prepared statement pointer
685
+ * @returns `SQLITE_OK` (rejects on error)
686
+ */
687
+ reset(stmt: number): number;
688
+
689
+ /**
690
+ * Convenience function to call `result_*` based of the type of `value`
691
+ * @param context context pointer
692
+ * @param value
693
+ */
694
+ result(context: number, value: (SQLiteCompatibleType|number[])|null): void;
695
+
696
+ /**
697
+ * Set the result of a function or vtable column
698
+ * @see https://sqlite.org/c3ref/result_blob.html
699
+ * @param context context pointer
700
+ * @param value
701
+ */
702
+ result_blob(context: number, value: Uint8Array<ArrayBuffer>|number[]): void;
703
+
704
+ /**
705
+ * Set the result of a function or vtable column
706
+ * @see https://sqlite.org/c3ref/result_blob.html
707
+ * @param context context pointer
708
+ * @param value
709
+ */
710
+ result_double(context: number, value: number): void;
711
+
712
+ /**
713
+ * Set the result of a function or vtable column
714
+ * @see https://sqlite.org/c3ref/result_blob.html
715
+ * @param context context pointer
716
+ * @param value
717
+ */
718
+ result_int(context: number, value: number): void;
719
+
720
+ /**
721
+ * Set the result of a function or vtable column
722
+ * @see https://sqlite.org/c3ref/result_blob.html
723
+ * @param context context pointer
724
+ * @param value
725
+ */
726
+ result_int64(context: number, value: bigint): void;
727
+
728
+ /**
729
+ * Set the result of a function or vtable column
730
+ * @see https://sqlite.org/c3ref/result_blob.html
731
+ * @param context context pointer
732
+ */
733
+ result_null(context: number): void;
734
+
735
+ /**
736
+ * Set the result of a function or vtable column
737
+ * @see https://sqlite.org/c3ref/result_blob.html
738
+ * @param context context pointer
739
+ * @param value
740
+ */
741
+ result_text(context: number, value: string): void;
742
+
743
+ /**
744
+ * Get all column data for a row from a prepared statement step
745
+ *
746
+ * This convenience function will return a copy of any blob, unlike
747
+ * {@link column_blob} which returns a value referencing volatile WASM
748
+ * memory with short validity. Like {@link column}, it will return a
749
+ * BigInt for integers outside the safe integer bounds for Number.
750
+ * @param stmt prepared statement pointer
751
+ * @returns row data
752
+ */
753
+ row(stmt: number): Array<SQLiteCompatibleType|null>;
754
+
755
+ /**
756
+ * Register a callback function that is invoked to authorize certain SQL statement actions.
757
+ * @see https://www.sqlite.org/c3ref/set_authorizer.html
758
+ * @param db database pointer
759
+ * @param authFunction
760
+ * @param userData
761
+ */
762
+ set_authorizer(
763
+ db: number,
764
+ authFunction: (userData: any, iActionCode: number, param3: string|null, param4: string|null, param5: string|null, param6: string|null) => number|Promise<number>,
765
+ userData: any): number;
766
+
767
+ /**
768
+ * Get statement SQL
769
+ * @see https://www.sqlite.org/c3ref/expanded_sql.html
770
+ * @param stmt prepared statement pointer
771
+ * @returns SQL
772
+ */
773
+ sql(stmt: number): string;
774
+
775
+ /**
776
+ * SQL statement iterator
777
+ *
778
+ * This function manages statement compilation by creating an async
779
+ * iterator that yields a prepared statement handle on each iteration.
780
+ * It is typically used with a `for await` loop (in an async function),
781
+ * like this:
782
+ * ```javascript
783
+ * // Compile one statement on each iteration of this loop.
784
+ * for await (const stmt of sqlite3.statements(db, sql)) {
785
+ * // Bind parameters here if using SQLite placeholders.
786
+ *
787
+ * // Execute the statement with this loop.
788
+ * while (await sqlite3.step(stmt) === SQLite.SQLITE_ROW) {
789
+ * // Collect row data here.
790
+ * }
791
+ *
792
+ * // Change bindings, reset, and execute again if desired.
793
+ * }
794
+ * ```
795
+ *
796
+ * By default, the lifetime of a yielded prepared statement is managed
797
+ * automatically by the iterator, ending at the end of each iteration.
798
+ * {@link finalize} should *not* be called on a statement provided by
799
+ * the iterator unless the `unscoped` option is set to `true` (that
800
+ * option is provided for applications that wish to manage statement
801
+ * lifetimes manually).
802
+ *
803
+ * If using the iterator manually, i.e. by calling its `next`
804
+ * method, be sure to call the `return` method if iteration
805
+ * is abandoned before completion (`for await` and other implicit
806
+ * traversals provided by Javascript do this automatically)
807
+ * to ensure that all allocated resources are released.
808
+ * @see https://www.sqlite.org/c3ref/prepare.html
809
+ * @param db database pointer
810
+ * @param sql
811
+ * @param options
812
+ */
813
+ // statements(db: number, sql: string, options?: SQLitePrepareOptions): AsyncIterable<number>;
814
+ statements(db: number, sql: string, options?: SQLitePrepareOptions): ReadonlyArray<number>;
815
+
816
+ /**
817
+ * Evaluate an SQL statement
818
+ * @see https://www.sqlite.org/c3ref/step.html
819
+ * @param stmt prepared statement pointer
820
+ * @returns Promise resolving to `SQLITE_ROW` or `SQLITE_DONE`
821
+ * (rejects on error)
822
+ */
823
+ // step(stmt: number): Promise<number>;
824
+ step(stmt: number): number;
825
+
826
+ /**
827
+ * Register an update hook
828
+ *
829
+ * The callback is invoked whenever a row is updated, inserted, or deleted
830
+ * in a rowid table on this connection.
831
+ * @see https://www.sqlite.org/c3ref/update_hook.html
832
+ *
833
+ * updateType is one of:
834
+ * - SQLITE_DELETE: 9
835
+ * - SQLITE_INSERT: 18
836
+ * - SQLITE_UPDATE: 23
837
+ * @see https://www.sqlite.org/c3ref/c_alter_table.html
838
+ *
839
+ * @param db database pointer
840
+ * @param callback
841
+ */
842
+ update_hook(
843
+ db: number,
844
+ callback: (updateType: number, dbName: string|null, tblName: string|null, rowid: bigint) => void): void;
845
+
846
+
847
+
848
+ /**
849
+ * Extract a value from `sqlite3_value`
850
+ *
851
+ * This is a convenience function that calls the appropriate `value_*`
852
+ * function based on its type. Note that if the value is a blob then as
853
+ * with `value_blob` the result may be invalid after the next SQLite call.
854
+ *
855
+ * Integer values are returned as Number if within the min/max safe
856
+ * integer bounds, otherwise they are returned as BigInt.
857
+ * @param pValue `sqlite3_value` pointer
858
+ * @returns value
859
+ */
860
+ value(pValue: number): SQLiteCompatibleType;
861
+
862
+ /**
863
+ * Extract a value from `sqlite3_value`
864
+ *
865
+ * The contents of the returned buffer may be invalid after the
866
+ * next SQLite call. Make a copy of the data (e.g. with `.slice()`)
867
+ * if longer retention is required.
868
+ * @see https://sqlite.org/c3ref/value_blob.html
869
+ * @param pValue `sqlite3_value` pointer
870
+ * @returns value
871
+ */
872
+ value_blob(pValue: number): Uint8Array<ArrayBuffer>;
873
+
874
+ /**
875
+ * Get blob or text size for value
876
+ * @see https://sqlite.org/c3ref/value_blob.html
877
+ * @param pValue `sqlite3_value` pointer
878
+ * @returns size
879
+ */
880
+ value_bytes(pValue: number): number;
881
+
882
+ /**
883
+ * Extract a value from `sqlite3_value`
884
+ * @see https://sqlite.org/c3ref/value_blob.html
885
+ * @param pValue `sqlite3_value` pointer
886
+ * @returns value
887
+ */
888
+ value_double(pValue: number): number;
889
+
890
+ /**
891
+ * Extract a value from `sqlite3_value`
892
+ * @see https://sqlite.org/c3ref/value_blob.html
893
+ * @param pValue `sqlite3_value` pointer
894
+ * @returns value
895
+ */
896
+ value_int(pValue: number): number;
897
+
898
+ /**
899
+ * Extract a value from `sqlite3_value`
900
+ * @see https://sqlite.org/c3ref/value_blob.html
901
+ * @param pValue `sqlite3_value` pointer
902
+ * @returns value
903
+ */
904
+ value_int64(pValue: number): bigint;
905
+
906
+ /**
907
+ * Extract a value from `sqlite3_value`
908
+ * @see https://sqlite.org/c3ref/value_blob.html
909
+ * @param pValue `sqlite3_value` pointer
910
+ * @returns value
911
+ */
912
+ value_text(pValue: number): string;
913
+
914
+ /**
915
+ * Get type of `sqlite3_value`
916
+ * @see https://sqlite.org/c3ref/value_blob.html
917
+ * @param pValue `sqlite3_value` pointer
918
+ * @returns enumeration value for type
919
+ */
920
+ value_type(pValue: number): number;
921
+
922
+ /**
923
+ * Register a new Virtual File System.
924
+ *
925
+ * @see https://www.sqlite.org/c3ref/vfs_find.html
926
+ * @param vfs VFS object
927
+ * @param makeDefault
928
+ * @returns `SQLITE_OK` (throws exception on error)
929
+ */
930
+ vfs_register(vfs: SQLiteVFS, makeDefault?: boolean): number;
931
+
932
+ vfs_registered: Set<string>;
933
+
934
+ /**
935
+ * Create a new session object for a database.
936
+ *
937
+ * @param db database pointer
938
+ * @param zDb database name
939
+ * @returns session pointer
940
+ */
941
+ session_create(db: number, zDb: string): number;
942
+
943
+ /**
944
+ * Attach a database to a session.
945
+ *
946
+ * @param pSession session pointer
947
+ * @param zTab table name
948
+ * @returns `SQLITE_OK` (throws exception on error)
949
+ */
950
+ session_attach(pSession: number, zTab: string | null): number;
951
+
952
+ /**
953
+ * Enable or disable a session.
954
+ *
955
+ * @param pSession session pointer
956
+ * @param enable
957
+ */
958
+ session_enable(pSession: number, enable: boolean): void;
959
+
960
+ /**
961
+ * Get the changeset for a session.
962
+ *
963
+ * @param pSession session pointer
964
+ * @returns {result: number, size: number, changeset: Uint8Array<ArrayBuffer>}
965
+ */
966
+ session_changeset(pSession: number): {
967
+ result: number;
968
+ size: number;
969
+ changeset: Uint8Array<ArrayBuffer> | null;
970
+ };
971
+
972
+ session_changeset_inverted(pSession: number): {
973
+ result: number;
974
+ size: number;
975
+ changeset: Uint8Array<ArrayBuffer>;
976
+ };
977
+
978
+ /**
979
+ * Delete a session object.
980
+ *
981
+ * @param pSession session pointer
982
+ */
983
+ session_delete(pSession: number): void;
984
+
985
+ /**
986
+ * Start a changeset.
987
+ *
988
+ * @param changeset changeset blob to import from
989
+ * @returns changeset iterator pointer
990
+ */
991
+ changeset_start(changesetBlob: Uint8Array<ArrayBuffer>): number;
992
+
993
+ /**
994
+ * Finalize a changeset iterator.
995
+ *
996
+ * @param pIter changeset iterator pointer
997
+ * @returns `SQLITE_OK` (throws exception on error)
998
+ */
999
+ changeset_finalize(pIter: number): number;
1000
+
1001
+ /**
1002
+ * Invert a changeset.
1003
+ *
1004
+ * @param input changeset to invert
1005
+ * @returns inverted changeset
1006
+ */
1007
+ changeset_invert(input: Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer>;
1008
+
1009
+ /**
1010
+ * Apply a changeset to a database.
1011
+ *
1012
+ * @param db database pointer
1013
+ * @param changeset changeset to apply
1014
+ * @returns `SQLITE_OK` (throws exception on error)
1015
+ */
1016
+ changeset_apply(db: number, changeset: Uint8Array<ArrayBuffer>, options?: {
1017
+ onConflict?: (conflictType: number) => 0 | 1 | 2
1018
+ }): number;
1019
+
1020
+ }
1021
+
1022
+ type SQLiteAPI_ = SQLiteAPI;
1023
+ type SQLiteVFS_ = SQLiteVFS
1024
+
1025
+ declare module '@livestore/wa-sqlite' {
1026
+ export type SQLiteVFS = SQLiteVFS_;
1027
+ export type SQLiteAPI = SQLiteAPI_
1028
+ }
1029
+
1030
+
1031
+ /** @ignore */
1032
+ declare module '@livestore/wa-sqlite/src/sqlite-constants.js' {
1033
+ export const SQLITE_OK: 0;
1034
+ export const SQLITE_ERROR: 1;
1035
+ export const SQLITE_INTERNAL: 2;
1036
+ export const SQLITE_PERM: 3;
1037
+ export const SQLITE_ABORT: 4;
1038
+ export const SQLITE_BUSY: 5;
1039
+ export const SQLITE_LOCKED: 6;
1040
+ export const SQLITE_NOMEM: 7;
1041
+ export const SQLITE_READONLY: 8;
1042
+ export const SQLITE_INTERRUPT: 9;
1043
+ export const SQLITE_IOERR: 10;
1044
+ export const SQLITE_CORRUPT: 11;
1045
+ export const SQLITE_NOTFOUND: 12;
1046
+ export const SQLITE_FULL: 13;
1047
+ export const SQLITE_CANTOPEN: 14;
1048
+ export const SQLITE_PROTOCOL: 15;
1049
+ export const SQLITE_EMPTY: 16;
1050
+ export const SQLITE_SCHEMA: 17;
1051
+ export const SQLITE_TOOBIG: 18;
1052
+ export const SQLITE_CONSTRAINT: 19;
1053
+ export const SQLITE_MISMATCH: 20;
1054
+ export const SQLITE_MISUSE: 21;
1055
+ export const SQLITE_NOLFS: 22;
1056
+ export const SQLITE_AUTH: 23;
1057
+ export const SQLITE_FORMAT: 24;
1058
+ export const SQLITE_RANGE: 25;
1059
+ export const SQLITE_NOTADB: 26;
1060
+ export const SQLITE_NOTICE: 27;
1061
+ export const SQLITE_WARNING: 28;
1062
+ export const SQLITE_ROW: 100;
1063
+ export const SQLITE_DONE: 101;
1064
+ export const SQLITE_IOERR_ACCESS: 3338;
1065
+ export const SQLITE_IOERR_CHECKRESERVEDLOCK: 3594;
1066
+ export const SQLITE_IOERR_CLOSE: 4106;
1067
+ export const SQLITE_IOERR_DATA: 8202;
1068
+ export const SQLITE_IOERR_DELETE: 2570;
1069
+ export const SQLITE_IOERR_DELETE_NOENT: 5898;
1070
+ export const SQLITE_IOERR_DIR_FSYNC: 1290;
1071
+ export const SQLITE_IOERR_FSTAT: 1802;
1072
+ export const SQLITE_IOERR_FSYNC: 1034;
1073
+ export const SQLITE_IOERR_GETTEMPPATH: 6410;
1074
+ export const SQLITE_IOERR_LOCK: 3850;
1075
+ export const SQLITE_IOERR_NOMEM: 3082;
1076
+ export const SQLITE_IOERR_READ: 266;
1077
+ export const SQLITE_IOERR_RDLOCK: 2314;
1078
+ export const SQLITE_IOERR_SEEK: 5642;
1079
+ export const SQLITE_IOERR_SHORT_READ: 522;
1080
+ export const SQLITE_IOERR_TRUNCATE: 1546;
1081
+ export const SQLITE_IOERR_UNLOCK: 2058;
1082
+ export const SQLITE_IOERR_VNODE: 6922;
1083
+ export const SQLITE_IOERR_WRITE: 778;
1084
+ export const SQLITE_IOERR_BEGIN_ATOMIC: 7434;
1085
+ export const SQLITE_IOERR_COMMIT_ATOMIC: 7690;
1086
+ export const SQLITE_IOERR_ROLLBACK_ATOMIC: 7946;
1087
+ export const SQLITE_CONSTRAINT_CHECK: 275;
1088
+ export const SQLITE_CONSTRAINT_COMMITHOOK: 531;
1089
+ export const SQLITE_CONSTRAINT_FOREIGNKEY: 787;
1090
+ export const SQLITE_CONSTRAINT_FUNCTION: 1043;
1091
+ export const SQLITE_CONSTRAINT_NOTNULL: 1299;
1092
+ export const SQLITE_CONSTRAINT_PINNED: 2835;
1093
+ export const SQLITE_CONSTRAINT_PRIMARYKEY: 1555;
1094
+ export const SQLITE_CONSTRAINT_ROWID: 2579;
1095
+ export const SQLITE_CONSTRAINT_TRIGGER: 1811;
1096
+ export const SQLITE_CONSTRAINT_UNIQUE: 2067;
1097
+ export const SQLITE_CONSTRAINT_VTAB: 2323;
1098
+ export const SQLITE_OPEN_READONLY: 1;
1099
+ export const SQLITE_OPEN_READWRITE: 2;
1100
+ export const SQLITE_OPEN_CREATE: 4;
1101
+ export const SQLITE_OPEN_DELETEONCLOSE: 8;
1102
+ export const SQLITE_OPEN_EXCLUSIVE: 16;
1103
+ export const SQLITE_OPEN_AUTOPROXY: 32;
1104
+ export const SQLITE_OPEN_URI: 64;
1105
+ export const SQLITE_OPEN_MEMORY: 128;
1106
+ export const SQLITE_OPEN_MAIN_DB: 256;
1107
+ export const SQLITE_OPEN_TEMP_DB: 512;
1108
+ export const SQLITE_OPEN_TRANSIENT_DB: 1024;
1109
+ export const SQLITE_OPEN_MAIN_JOURNAL: 2048;
1110
+ export const SQLITE_OPEN_TEMP_JOURNAL: 4096;
1111
+ export const SQLITE_OPEN_SUBJOURNAL: 8192;
1112
+ export const SQLITE_OPEN_SUPER_JOURNAL: 16384;
1113
+ export const SQLITE_OPEN_NOMUTEX: 32768;
1114
+ export const SQLITE_OPEN_FULLMUTEX: 65536;
1115
+ export const SQLITE_OPEN_SHAREDCACHE: 131072;
1116
+ export const SQLITE_OPEN_PRIVATECACHE: 262144;
1117
+ export const SQLITE_OPEN_WAL: 524288;
1118
+ export const SQLITE_OPEN_NOFOLLOW: 16777216;
1119
+ export const SQLITE_LOCK_NONE: 0;
1120
+ export const SQLITE_LOCK_SHARED: 1;
1121
+ export const SQLITE_LOCK_RESERVED: 2;
1122
+ export const SQLITE_LOCK_PENDING: 3;
1123
+ export const SQLITE_LOCK_EXCLUSIVE: 4;
1124
+ export const SQLITE_IOCAP_ATOMIC: 1;
1125
+ export const SQLITE_IOCAP_ATOMIC512: 2;
1126
+ export const SQLITE_IOCAP_ATOMIC1K: 4;
1127
+ export const SQLITE_IOCAP_ATOMIC2K: 8;
1128
+ export const SQLITE_IOCAP_ATOMIC4K: 16;
1129
+ export const SQLITE_IOCAP_ATOMIC8K: 32;
1130
+ export const SQLITE_IOCAP_ATOMIC16K: 64;
1131
+ export const SQLITE_IOCAP_ATOMIC32K: 128;
1132
+ export const SQLITE_IOCAP_ATOMIC64K: 256;
1133
+ export const SQLITE_IOCAP_SAFE_APPEND: 512;
1134
+ export const SQLITE_IOCAP_SEQUENTIAL: 1024;
1135
+ export const SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN: 2048;
1136
+ export const SQLITE_IOCAP_POWERSAFE_OVERWRITE: 4096;
1137
+ export const SQLITE_IOCAP_IMMUTABLE: 8192;
1138
+ export const SQLITE_IOCAP_BATCH_ATOMIC: 16384;
1139
+ export const SQLITE_ACCESS_EXISTS: 0;
1140
+ export const SQLITE_ACCESS_READWRITE: 1;
1141
+ export const SQLITE_ACCESS_READ: 2;
1142
+ export const SQLITE_FCNTL_LOCKSTATE: 1;
1143
+ export const SQLITE_FCNTL_GET_LOCKPROXYFILE: 2;
1144
+ export const SQLITE_FCNTL_SET_LOCKPROXYFILE: 3;
1145
+ export const SQLITE_FCNTL_LAST_ERRNO: 4;
1146
+ export const SQLITE_FCNTL_SIZE_HINT: 5;
1147
+ export const SQLITE_FCNTL_CHUNK_SIZE: 6;
1148
+ export const SQLITE_FCNTL_FILE_POINTER: 7;
1149
+ export const SQLITE_FCNTL_SYNC_OMITTED: 8;
1150
+ export const SQLITE_FCNTL_WIN32_AV_RETRY: 9;
1151
+ export const SQLITE_FCNTL_PERSIST_WAL: 10;
1152
+ export const SQLITE_FCNTL_OVERWRITE: 11;
1153
+ export const SQLITE_FCNTL_VFSNAME: 12;
1154
+ export const SQLITE_FCNTL_POWERSAFE_OVERWRITE: 13;
1155
+ export const SQLITE_FCNTL_PRAGMA: 14;
1156
+ export const SQLITE_FCNTL_BUSYHANDLER: 15;
1157
+ export const SQLITE_FCNTL_TEMPFILENAME: 16;
1158
+ export const SQLITE_FCNTL_MMAP_SIZE: 18;
1159
+ export const SQLITE_FCNTL_TRACE: 19;
1160
+ export const SQLITE_FCNTL_HAS_MOVED: 20;
1161
+ export const SQLITE_FCNTL_SYNC: 21;
1162
+ export const SQLITE_FCNTL_COMMIT_PHASETWO: 22;
1163
+ export const SQLITE_FCNTL_WIN32_SET_HANDLE: 23;
1164
+ export const SQLITE_FCNTL_WAL_BLOCK: 24;
1165
+ export const SQLITE_FCNTL_ZIPVFS: 25;
1166
+ export const SQLITE_FCNTL_RBU: 26;
1167
+ export const SQLITE_FCNTL_VFS_POINTER: 27;
1168
+ export const SQLITE_FCNTL_JOURNAL_POINTER: 28;
1169
+ export const SQLITE_FCNTL_WIN32_GET_HANDLE: 29;
1170
+ export const SQLITE_FCNTL_PDB: 30;
1171
+ export const SQLITE_FCNTL_BEGIN_ATOMIC_WRITE: 31;
1172
+ export const SQLITE_FCNTL_COMMIT_ATOMIC_WRITE: 32;
1173
+ export const SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE: 33;
1174
+ export const SQLITE_FCNTL_LOCK_TIMEOUT: 34;
1175
+ export const SQLITE_FCNTL_DATA_VERSION: 35;
1176
+ export const SQLITE_FCNTL_SIZE_LIMIT: 36;
1177
+ export const SQLITE_FCNTL_CKPT_DONE: 37;
1178
+ export const SQLITE_FCNTL_RESERVE_BYTES: 38;
1179
+ export const SQLITE_FCNTL_CKPT_START: 39;
1180
+ export const SQLITE_INTEGER: 1;
1181
+ export const SQLITE_FLOAT: 2;
1182
+ export const SQLITE_TEXT: 3;
1183
+ export const SQLITE_BLOB: 4;
1184
+ export const SQLITE_NULL: 5;
1185
+ export const SQLITE_STATIC: 0;
1186
+ export const SQLITE_TRANSIENT: -1;
1187
+ export const SQLITE_UTF8: 1;
1188
+ export const SQLITE_UTF16LE: 2;
1189
+ export const SQLITE_UTF16BE: 3;
1190
+ export const SQLITE_UTF16: 4;
1191
+ export const SQLITE_INDEX_CONSTRAINT_EQ: 2;
1192
+ export const SQLITE_INDEX_CONSTRAINT_GT: 4;
1193
+ export const SQLITE_INDEX_CONSTRAINT_LE: 8;
1194
+ export const SQLITE_INDEX_CONSTRAINT_LT: 16;
1195
+ export const SQLITE_INDEX_CONSTRAINT_GE: 32;
1196
+ export const SQLITE_INDEX_CONSTRAINT_MATCH: 64;
1197
+ export const SQLITE_INDEX_CONSTRAINT_LIKE: 65;
1198
+ export const SQLITE_INDEX_CONSTRAINT_GLOB: 66;
1199
+ export const SQLITE_INDEX_CONSTRAINT_REGEXP: 67;
1200
+ export const SQLITE_INDEX_CONSTRAINT_NE: 68;
1201
+ export const SQLITE_INDEX_CONSTRAINT_ISNOT: 69;
1202
+ export const SQLITE_INDEX_CONSTRAINT_ISNOTNULL: 70;
1203
+ export const SQLITE_INDEX_CONSTRAINT_ISNULL: 71;
1204
+ export const SQLITE_INDEX_CONSTRAINT_IS: 72;
1205
+ export const SQLITE_INDEX_CONSTRAINT_FUNCTION: 150;
1206
+ export const SQLITE_INDEX_SCAN_UNIQUE: 1;
1207
+ export const SQLITE_DETERMINISTIC: 0x000000800;
1208
+ export const SQLITE_DIRECTONLY: 0x000080000;
1209
+ export const SQLITE_SUBTYPE: 0x000100000;
1210
+ export const SQLITE_INNOCUOUS: 0x000200000;
1211
+ export const SQLITE_SYNC_NORMAL: 0x00002;
1212
+ export const SQLITE_SYNC_FULL: 0x00003;
1213
+ export const SQLITE_SYNC_DATAONLY: 0x00010;
1214
+ export const SQLITE_CREATE_INDEX: 1;
1215
+ export const SQLITE_CREATE_TABLE: 2;
1216
+ export const SQLITE_CREATE_TEMP_INDEX: 3;
1217
+ export const SQLITE_CREATE_TEMP_TABLE: 4;
1218
+ export const SQLITE_CREATE_TEMP_TRIGGER: 5;
1219
+ export const SQLITE_CREATE_TEMP_VIEW: 6;
1220
+ export const SQLITE_CREATE_TRIGGER: 7;
1221
+ export const SQLITE_CREATE_VIEW: 8;
1222
+ export const SQLITE_DELETE: 9;
1223
+ export const SQLITE_DROP_INDEX: 10;
1224
+ export const SQLITE_DROP_TABLE: 11;
1225
+ export const SQLITE_DROP_TEMP_INDEX: 12;
1226
+ export const SQLITE_DROP_TEMP_TABLE: 13;
1227
+ export const SQLITE_DROP_TEMP_TRIGGER: 14;
1228
+ export const SQLITE_DROP_TEMP_VIEW: 15;
1229
+ export const SQLITE_DROP_TRIGGER: 16;
1230
+ export const SQLITE_DROP_VIEW: 17;
1231
+ export const SQLITE_INSERT: 18;
1232
+ export const SQLITE_PRAGMA: 19;
1233
+ export const SQLITE_READ: 20;
1234
+ export const SQLITE_SELECT: 21;
1235
+ export const SQLITE_TRANSACTION: 22;
1236
+ export const SQLITE_UPDATE: 23;
1237
+ export const SQLITE_ATTACH: 24;
1238
+ export const SQLITE_DETACH: 25;
1239
+ export const SQLITE_ALTER_TABLE: 26;
1240
+ export const SQLITE_REINDEX: 27;
1241
+ export const SQLITE_ANALYZE: 28;
1242
+ export const SQLITE_CREATE_VTABLE: 29;
1243
+ export const SQLITE_DROP_VTABLE: 30;
1244
+ export const SQLITE_FUNCTION: 31;
1245
+ export const SQLITE_SAVEPOINT: 32;
1246
+ export const SQLITE_COPY: 0;
1247
+ export const SQLITE_RECURSIVE: 33;
1248
+ export const SQLITE_DENY: 1;
1249
+ export const SQLITE_IGNORE: 2;
1250
+ export const SQLITE_LIMIT_LENGTH: 0;
1251
+ export const SQLITE_LIMIT_SQL_LENGTH: 1;
1252
+ export const SQLITE_LIMIT_COLUMN: 2;
1253
+ export const SQLITE_LIMIT_EXPR_DEPTH: 3;
1254
+ export const SQLITE_LIMIT_COMPOUND_SELECT: 4;
1255
+ export const SQLITE_LIMIT_VDBE_OP: 5;
1256
+ export const SQLITE_LIMIT_FUNCTION_ARG: 6;
1257
+ export const SQLITE_LIMIT_ATTACHED: 7;
1258
+ export const SQLITE_LIMIT_LIKE_PATTERN_LENGTH: 8;
1259
+ export const SQLITE_LIMIT_VARIABLE_NUMBER: 9;
1260
+ export const SQLITE_LIMIT_TRIGGER_DEPTH: 10;
1261
+ export const SQLITE_LIMIT_WORKER_THREADS: 11;
1262
+ export const SQLITE_PREPARE_PERSISTENT: 0x01;
1263
+ export const SQLITE_PREPARE_NORMALIZED: 0x02;
1264
+ export const SQLITE_PREPARE_NO_VTAB: 0x04;
1265
+ }
1266
+
1267
+ declare module '@livestore/wa-sqlite' {
1268
+ export * from '@livestore/wa-sqlite/src/sqlite-constants.js';
1269
+
1270
+ /**
1271
+ * @ignore
1272
+ * Builds a Javascript API from the Emscripten module. This API is still
1273
+ * low-level and closely corresponds to the C API exported by the module,
1274
+ * but differs in some specifics like throwing exceptions on errors.
1275
+ * @param {*} Module SQLite module
1276
+ * @returns {SQLiteAPI}
1277
+ */
1278
+ export function Factory(Module: any): SQLiteAPI;
1279
+
1280
+ export class SQLiteError extends Error {
1281
+ constructor(message: any, code: any);
1282
+ code: any;
1283
+ }
1284
+ }
1285
+
1286
+ /** @ignore */
1287
+ declare module '@livestore/wa-sqlite/dist/wa-sqlite.mjs' {
1288
+ function ModuleFactory(config?: object): Promise<any>;
1289
+ export = ModuleFactory;
1290
+ }
1291
+
1292
+ /** @ignore */
1293
+ declare module '@livestore/wa-sqlite/dist/wa-sqlite-async.mjs' {
1294
+ function ModuleFactory(config?: object): Promise<any>;
1295
+ export = ModuleFactory;
1296
+ }
1297
+
1298
+ /** @ignore */
1299
+ declare module '@livestore/wa-sqlite/src/VFS.js' {
1300
+ export * from '@livestore/wa-sqlite/src/sqlite-constants.js';
1301
+
1302
+ export class Base {
1303
+ name: string;
1304
+ mxPathName: number;
1305
+ /**
1306
+ * @param {number} fileId
1307
+ * @returns {number|Promise<number>}
1308
+ */
1309
+ xClose(fileId: number): number;
1310
+ /**
1311
+ * @param {number} fileId
1312
+ * @param {Uint8Array<ArrayBuffer>} pData
1313
+ * @param {number} iOffset
1314
+ * @returns {number}
1315
+ */
1316
+ xRead(fileId: number, pData: {
1317
+ size: number;
1318
+ value: Uint8Array<ArrayBuffer>;
1319
+ }, iOffset: number): number;
1320
+ /**
1321
+ * @param {number} fileId
1322
+ * @param {Uint8Array<ArrayBuffer>} pData
1323
+ * @param {number} iOffset
1324
+ * @returns {number}
1325
+ */
1326
+ xWrite(fileId: number, pData: {
1327
+ size: number;
1328
+ value: Uint8Array<ArrayBuffer>;
1329
+ }, iOffset: number): number;
1330
+ /**
1331
+ * @param {number} fileId
1332
+ * @param {number} iSize
1333
+ * @returns {number}
1334
+ */
1335
+ xTruncate(fileId: number, iSize: number): number;
1336
+ /**
1337
+ * @param {number} fileId
1338
+ * @param {*} flags
1339
+ * @returns {number}
1340
+ */
1341
+ xSync(fileId: number, flags: any): number;
1342
+ /**
1343
+ * @param {number} fileId
1344
+ * @param {DataView} pSize64
1345
+ * @returns {number|Promise<number>}
1346
+ */
1347
+ xFileSize(fileId: number, pSize64: DataView): number;
1348
+ /**
1349
+ * @param {number} fileId
1350
+ * @param {number} flags
1351
+ * @returns {number}
1352
+ */
1353
+ xLock(fileId: number, flags: number): number;
1354
+ /**
1355
+ * @param {number} fileId
1356
+ * @param {number} flags
1357
+ * @returns {number}
1358
+ */
1359
+ xUnlock(fileId: number, flags: number): number;
1360
+ /**
1361
+ * @param {number} fileId
1362
+ * @param {DataView} pResOut
1363
+ * @returns {number}
1364
+ */
1365
+ xCheckReservedLock(fileId: number, pResOut: DataView): number;
1366
+ /**
1367
+ * @param {number} fileId
1368
+ * @param {number} flags
1369
+ * @param {DataView} pArg
1370
+ * @returns {number}
1371
+ */
1372
+ xFileControl(fileId: number, flags: number, pArg: DataView): number;
1373
+ /**
1374
+ * @param {number} fileId
1375
+ * @returns {number}
1376
+ */
1377
+ xSectorSize(fileId: number): number;
1378
+ /**
1379
+ * @param {number} fileId
1380
+ * @returns {number}
1381
+ */
1382
+ xDeviceCharacteristics(fileId: number): number;
1383
+ /**
1384
+ * @param {string?} name
1385
+ * @param {number} fileId
1386
+ * @param {number} flags
1387
+ * @param {DataView} pOutFlags
1388
+ * @returns {number}
1389
+ */
1390
+ xOpen(name: string | null, fileId: number, flags: number, pOutFlags: DataView): number;
1391
+ /**
1392
+ *
1393
+ * @param {string} name
1394
+ * @param {number} syncDir
1395
+ * @returns {number}
1396
+ */
1397
+ xDelete(name: string, syncDir: number): number;
1398
+ /**
1399
+ * @param {string} name
1400
+ * @param {number} flags
1401
+ * @param {DataView} pResOut
1402
+ * @returns {number}
1403
+ */
1404
+ xAccess(name: string, flags: number, pResOut: DataView): number;
1405
+ /**
1406
+ * Handle asynchronous operation. This implementation will be overriden on
1407
+ * registration by an Asyncify build.
1408
+ * @param {function(): Promise<number>} f
1409
+ * @returns {number}
1410
+ */
1411
+ handleAsync(f: () => Promise<number>): number;
1412
+ }
1413
+ }
1414
+
1415
+ /** @ignore */
1416
+ declare module '@livestore/wa-sqlite/src/FacadeVFS.js' {
1417
+ export type FacadeVFS = any
1418
+ }
1419
+
1420
+
1421
+ declare module '@livestore/wa-sqlite/src/examples/AccessHandlePoolVFS.js' {
1422
+ import * as VFS from "@livestore/wa-sqlite/src/VFS.js";
1423
+ export class AccessHandlePoolVFS extends VFS.Base {
1424
+ constructor(name: string, module: any)
1425
+ static create(name: string, module: any): Promise<AccessHandlePoolVFS>;
1426
+ }
1427
+ }
1428
+
1429
+ declare module '@livestore/wa-sqlite/src/examples/OPFSCoopSyncVFS.js' {
1430
+ import * as VFS from "@livestore/wa-sqlite/src/VFS.js";
1431
+ export class OPFSCoopSyncVFS extends VFS.Base {
1432
+ constructor(name: string, module: any)
1433
+ static create(name: string, module: any): Promise<OPFSCoopSyncVFS>;
1434
+ }
1435
+ }
1436
+
1437
+ /** @ignore */
1438
+ declare module '@livestore/wa-sqlite/src/examples/IndexedDbVFS.js' {
1439
+ import * as VFS from "@livestore/wa-sqlite/src/VFS.js";
1440
+ export class IndexedDbVFS extends VFS.Base {
1441
+ /**
1442
+ * @param {string} idbName Name of IndexedDB database.
1443
+ */
1444
+ constructor(idbName?: string);
1445
+ name: string;
1446
+ mapIdToFile: Map<any, any>;
1447
+ cacheSize: number;
1448
+ db: any;
1449
+ // close(): Promise<void>;
1450
+ close(): void;
1451
+ /**
1452
+ * Delete a file from IndexedDB.
1453
+ * @param {string} name
1454
+ */
1455
+ deleteFile(name: string): Promise<void>;
1456
+ /**
1457
+ * Forcibly clear an orphaned file lock.
1458
+ * @param {string} name
1459
+ */
1460
+ forceClearLock(name: string): Promise<void>;
1461
+ _getStore(mode?: string): any;
1462
+ /**
1463
+ * Returns the key for file metadata.
1464
+ * @param {string} name
1465
+ * @returns
1466
+ */
1467
+ _metaKey(name: string): string;
1468
+ /**
1469
+ * Returns the key for file block data.
1470
+ * @param {string} name
1471
+ * @param {number} index
1472
+ * @returns
1473
+ */
1474
+ _blockKey(name: string, index: number): string;
1475
+ _getBlock(store: any, file: any, index: any): Promise<any>;
1476
+ _putBlock(store: any, file: any, index: any, blockData: any): void;
1477
+ _purgeCache(store: any, file: any, size?: number): void;
1478
+ _flushCache(store: any, file: any): Promise<void>;
1479
+ _sync(file: any): Promise<void>;
1480
+ /**
1481
+ * Helper function that deletes all keys greater or equal to `key`
1482
+ * provided they start with `prefix`.
1483
+ * @param {string} key
1484
+ * @param {string} [prefix]
1485
+ * @returns
1486
+ */
1487
+ _delete(key: string, prefix?: string): Promise<any>;
1488
+ }
1489
+ }
1490
+
1491
+ /** @ignore */
1492
+ declare module '@livestore/wa-sqlite/src/examples/MemoryVFS.js' {
1493
+ import * as VFS from "@livestore/wa-sqlite/src/VFS.js";
1494
+ /** @ignore */
1495
+ export class MemoryVFS extends VFS.Base {
1496
+ name: string;
1497
+ mapNameToFile: Map<any, any>;
1498
+ mapIdToFile: Map<any, any>;
1499
+ }
1500
+ }
1501
+
1502
+ /** @ignore */
1503
+ declare module '@livestore/wa-sqlite/src/examples/MemoryAsyncVFS.js' {
1504
+ import { MemoryVFS } from "@livestore/wa-sqlite/src/examples/MemoryVFS.js";
1505
+ export class MemoryAsyncVFS extends MemoryVFS {
1506
+ }
1507
+ }
1508
+
1509
+ /** @ignore */
1510
+ declare module '@livestore/wa-sqlite/src/examples/tag.js' {
1511
+ /**
1512
+ * @ignore
1513
+ * Template tag builder. This function creates a tag with an API and
1514
+ * database from the same module, then the tag can be used like this:
1515
+ * ```
1516
+ * const sql = tag(sqlite3, db);
1517
+ * const results = await sql`
1518
+ * SELECT 1 + 1;
1519
+ * SELECT 6 * 7;
1520
+ * `;
1521
+ * ```
1522
+ * The returned Promise value contains an array of results for each
1523
+ * SQL statement that produces output. Each result is an object with
1524
+ * properties `columns` (array of names) and `rows` (array of array
1525
+ * of values).
1526
+ * @param {SQLiteAPI} sqlite3
1527
+ * @param {number} db
1528
+ * @returns {function(TemplateStringsArray, ...any): Promise<object[]>}
1529
+ */
1530
+ export function tag(sqlite3: any, db: number): (arg0: TemplateStringsArray, ...args: any[]) => Promise<object[]>;
1531
+ }