@evolu/sqlite-wasm 2.2.4 → 3.53.4-build1
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/LICENSE +21 -0
- package/README.md +55 -218
- package/dist/src/CApi.d.ts +2108 -0
- package/dist/src/CApi.d.ts.map +1 -0
- package/dist/src/CApi.js +1919 -0
- package/dist/src/Constants.d.ts +868 -0
- package/dist/src/Constants.d.ts.map +1 -0
- package/dist/src/Constants.js +602 -0
- package/dist/src/Database.d.ts +641 -0
- package/dist/src/Database.d.ts.map +1 -0
- package/dist/src/Database.js +1177 -0
- package/dist/src/Memory.d.ts +119 -0
- package/dist/src/Memory.d.ts.map +1 -0
- package/dist/src/Memory.js +207 -0
- package/dist/src/Pointer.d.ts +100 -0
- package/dist/src/Pointer.d.ts.map +1 -0
- package/dist/src/Pointer.js +15 -0
- package/dist/src/SahPool.d.ts +744 -0
- package/dist/src/SahPool.d.ts.map +1 -0
- package/dist/src/SahPool.js +1985 -0
- package/dist/src/Wasm.d.ts +315 -0
- package/dist/src/Wasm.d.ts.map +1 -0
- package/dist/src/Wasm.js +756 -0
- package/dist/src/WasmUrl.d.ts +21 -0
- package/dist/src/WasmUrl.d.ts.map +1 -0
- package/dist/src/WasmUrl.js +20 -0
- package/dist/src/c-api/index.d.ts +9 -0
- package/dist/src/c-api/index.d.ts.map +1 -0
- package/dist/src/c-api/index.js +8 -0
- package/dist/src/index.d.ts +15 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +13 -0
- package/dist/wasm/sqlite3.wasm +0 -0
- package/package.json +60 -60
- package/src/CApi.test.ts +217 -0
- package/src/CApi.ts +3294 -0
- package/src/Constants.ts +803 -0
- package/src/Database.ts +1714 -0
- package/src/Memory.test.ts +319 -0
- package/src/Memory.ts +237 -0
- package/src/Pointer.ts +121 -0
- package/src/SahPool.test.ts +180 -0
- package/src/SahPool.ts +2627 -0
- package/src/Wasm.test.ts +444 -0
- package/src/Wasm.ts +1026 -0
- package/src/WasmUrl.ts +26 -0
- package/src/c-api/index.ts +9 -0
- package/src/index.ts +15 -0
- package/bin/index.js +0 -110
- package/index.d.ts +0 -8118
- package/index.mjs +0 -7
- package/node.mjs +0 -3
- package/sqlite-wasm/jswasm/sqlite3-bundler-friendly.mjs +0 -13659
- package/sqlite-wasm/jswasm/sqlite3-node.mjs +0 -11671
- package/sqlite-wasm/jswasm/sqlite3-opfs-async-proxy.js +0 -691
- package/sqlite-wasm/jswasm/sqlite3-worker1-bundler-friendly.mjs +0 -35
- package/sqlite-wasm/jswasm/sqlite3-worker1-promiser.js +0 -193
- package/sqlite-wasm/jswasm/sqlite3-worker1-promiser.mjs +0 -187
- package/sqlite-wasm/jswasm/sqlite3-worker1.js +0 -46
- package/sqlite-wasm/jswasm/sqlite3.js +0 -13697
- package/sqlite-wasm/jswasm/sqlite3.mjs +0 -13661
- package/sqlite-wasm/jswasm/sqlite3.wasm +0 -0
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQLite's Emscripten wasm, loaded without Emscripten's or SQLite's JavaScript.
|
|
3
|
+
*
|
|
4
|
+
* The package ships SQLite's own wasm, built with SQLite's own makefile, and
|
|
5
|
+
* replaces the generated JavaScript with a small loader and the standalone
|
|
6
|
+
* functions of `@evolu/sqlite-wasm/c-api`.
|
|
7
|
+
*
|
|
8
|
+
* ## Loading
|
|
9
|
+
*
|
|
10
|
+
* {@link createSqliteWasm} runs these steps and fails with a
|
|
11
|
+
* {@link SqliteWasmError} when one fails. Steps 1 to 3 fail before any wasm code
|
|
12
|
+
* runs, and steps 4 and 5 run only the stack setup, static constructors and
|
|
13
|
+
* `sqlite3__wasm_enum_json()`, before any SQLite API call:
|
|
14
|
+
*
|
|
15
|
+
* 1. Compile, while downloading a `Response` of type `application/wasm`.
|
|
16
|
+
* 2. Import guard: every import the binary declares must be one the loader
|
|
17
|
+
* implements, or instantiation never happens. A new Emscripten or SQLite
|
|
18
|
+
* release that adds an import is caught here, not at the first call that
|
|
19
|
+
* reaches it. The list matches the release recipe exactly.
|
|
20
|
+
* 3. A fresh `WebAssembly.Memory` of at least the size the binary declares, which
|
|
21
|
+
* the JavaScript API does not expose (256 pages covers every build so far),
|
|
22
|
+
* and a maximum of 32768 pages, so pointers stay positive i32 values. An
|
|
23
|
+
* engine that cannot allocate it, as on a device low on memory, fails
|
|
24
|
+
* loading with {@link SqliteWasmCompileError}.
|
|
25
|
+
* 4. Instantiate, then set up the C stack for Emscripten's stack check: call
|
|
26
|
+
* `emscripten_stack_init`, then `__set_stack_limits` with what
|
|
27
|
+
* `emscripten_stack_get_base` and `emscripten_stack_get_end` return. The
|
|
28
|
+
* check compares each new stack pointer with limits that start at 0, so they
|
|
29
|
+
* are set before any code moves it. Then call `__wasm_call_ctors` exactly
|
|
30
|
+
* once. A binary without one of these functions fails the build guard.
|
|
31
|
+
* 5. Build guard: the hash {@link sqliteWasmBuildHash} defines, computed from the
|
|
32
|
+
* string `sqlite3__wasm_enum_json()` returns and the names
|
|
33
|
+
* `WebAssembly.Module.exports` lists, must equal it. A match means the
|
|
34
|
+
* binary has the pinned build's export names, so it exports every function
|
|
35
|
+
* in {@link SqliteCExports}, and the generated constants, struct layouts and
|
|
36
|
+
* {@link SQLITE_WASM_DEALLOC} describe it. The hash does not cover wasm
|
|
37
|
+
* types: the generator checked the bindings against the pinned types, and
|
|
38
|
+
* `scripts/generate.mts --verify-build` checks a new binary's. A binary
|
|
39
|
+
* without `sqlite3__wasm_enum_json`, or whose call returns NULL, hashes the
|
|
40
|
+
* string as empty and fails. No JSON is parsed at runtime.
|
|
41
|
+
* 6. `sqlite3_initialize()`, whose result code is checked.
|
|
42
|
+
* 7. Register the default VFS, then run {@link initializeSqliteWasm}, which makes
|
|
43
|
+
* it the default and calls `sqlite3_randomness(0, 0)`. SQLite's random
|
|
44
|
+
* number generator seeds itself from the default VFS at its first use, and
|
|
45
|
+
* again at the first use after that call resets it. Without Emscripten's
|
|
46
|
+
* file system, SQLite's unix VFS seeds it from the time and a constant pid,
|
|
47
|
+
* so two instances seeded in the same second would share `randomblob()`
|
|
48
|
+
* values and journal nonces. Nothing uses the generator while loading, so
|
|
49
|
+
* the reset is defensive here; it matters after `sqlite3_shutdown()`. It
|
|
50
|
+
* also unregisters SQLite's kvvfs, which `sqlite3_initialize()` registers
|
|
51
|
+
* but whose storage only SQLite's JavaScript provides, so opening it, as the
|
|
52
|
+
* names `:localStorage:` and `:sessionStorage:` do on any VFS, fails with
|
|
53
|
+
* SQLITE_ERROR instead of trapping. Allocating, finding or registering the
|
|
54
|
+
* VFS fails with {@link SqliteWasmInitializeError}, and compiling the
|
|
55
|
+
* generated module that installs its methods, which a Content Security
|
|
56
|
+
* Policy without 'wasm-unsafe-eval' forbids, fails with
|
|
57
|
+
* {@link SqliteWasmCompileError}. `sqlite3_initialize()` after
|
|
58
|
+
* `sqlite3_shutdown()` makes the unix VFS the default again, so
|
|
59
|
+
* {@link initializeSqliteWasm} must run instead.
|
|
60
|
+
*
|
|
61
|
+
* ## The default VFS
|
|
62
|
+
*
|
|
63
|
+
* `evolu-memory`, of version 2, has no files, so only `:memory:` databases use
|
|
64
|
+
* it:
|
|
65
|
+
*
|
|
66
|
+
* - `xFullPathname` fails with SQLITE_CANTOPEN, so opening a file path fails
|
|
67
|
+
* before SQLite would open a file. `xOpen` is NULL: SQLite opens a file
|
|
68
|
+
* without a path only for a temporary file, which this build keeps in memory.
|
|
69
|
+
* `xAccess` finds no file, and `xDelete` returns SQLITE_IOERR_DELETE_NOENT.
|
|
70
|
+
* - `xRandomness` fills memory from {@link RandomBytes}, in chunks of at most
|
|
71
|
+
* 65536 bytes, as `crypto.getRandomValues` requires.
|
|
72
|
+
* - `xCurrentTime` and `xCurrentTimeInt64` read `Time.now` of {@link Time}.
|
|
73
|
+
* - `xSleep` returns at once, having slept 0 microseconds. Contention can only
|
|
74
|
+
* come from connections in the same thread, which sleeping cannot resolve.
|
|
75
|
+
* - `xGetLastError` reports no system error.
|
|
76
|
+
*
|
|
77
|
+
* ## Imports
|
|
78
|
+
*
|
|
79
|
+
* About ten imports do real work:
|
|
80
|
+
*
|
|
81
|
+
* - `memory`, see step 3.
|
|
82
|
+
* - `__handle_stack_overflow`, which the build's stack check
|
|
83
|
+
* (`-sSTACK_OVERFLOW_CHECK=2`) calls instead of moving the stack pointer
|
|
84
|
+
* outside the C stack, throws a `WebAssembly.RuntimeError`, as a trap does.
|
|
85
|
+
* The C stack has 512 KiB directly above SQLite's static data, and SQL that
|
|
86
|
+
* is legal but nests deeply enough, such as a chain of 600 triggers, would
|
|
87
|
+
* otherwise overwrite that data silently.
|
|
88
|
+
* - `emscripten_resize_heap` grows memory to the requested size, read as
|
|
89
|
+
* unsigned, and returns 1, or 0 when it cannot, never throwing.
|
|
90
|
+
* - The clocks read {@link Time}: `emscripten_date_now` returns `Time.now`,
|
|
91
|
+
* `emscripten_get_now` returns `Time.performance.now`, and WASI
|
|
92
|
+
* `clock_time_get` writes BigInt nanoseconds of the first for the realtime
|
|
93
|
+
* clock and of the second for the monotonic and CPU-time clocks, and returns
|
|
94
|
+
* EINVAL for any other.
|
|
95
|
+
* - `_localtime_js`, for SQL `localtime`, reads `Date` in the local time zone and
|
|
96
|
+
* fails for a time `Date` cannot represent. It fills only the `struct tm`
|
|
97
|
+
* fields SQLite reads, from `tm_sec` to `tm_year`, and zeroes the others.
|
|
98
|
+
* `_tzset_js` writes nothing: only `localtime_r` reads what it would write,
|
|
99
|
+
* to set `tm_zone`, which nothing reads.
|
|
100
|
+
* - `environ_sizes_get` and `environ_get` describe an empty environment.
|
|
101
|
+
* - `fd_write`, for C-side diagnostics, writes complete lines of stdout with
|
|
102
|
+
* {@link Console.log} and of stderr with {@link Console.error}, and fails any
|
|
103
|
+
* other descriptor with EBADF.
|
|
104
|
+
*
|
|
105
|
+
* The `__syscall_*` imports return -ENOSYS (-52), and the remaining WASI `fd_*`
|
|
106
|
+
* imports return ENOSYS (52), as WASI errors are positive: only `openat` of
|
|
107
|
+
* `/dev/urandom` is ever reached, and step 7 covers it.
|
|
108
|
+
*
|
|
109
|
+
* Every import's wasm type and the memory limits are pinned in
|
|
110
|
+
* `scripts/upstream/sqlite3-wasm-imports.json`, and `scripts/generate.mts
|
|
111
|
+
* --verify-build` checks a binary against them.
|
|
112
|
+
*
|
|
113
|
+
* ## Rules for everything that uses the instance
|
|
114
|
+
*
|
|
115
|
+
* - Synchronous only. The build has neither Asyncify nor JSPI, and nothing in the
|
|
116
|
+
* SQLite call path returns a promise.
|
|
117
|
+
* - Any call that can allocate, including a VFS callback running inside
|
|
118
|
+
* `sqlite3_step`, can grow memory, which detaches the previous `ArrayBuffer`.
|
|
119
|
+
* Take heap views with {@link SqliteWasm.getHeapU8} after such calls and never
|
|
120
|
+
* keep one across them.
|
|
121
|
+
* - No JavaScript exception may cross into wasm. Every function installed with
|
|
122
|
+
* {@link installWasmFunctions} catches what it throws, reports it as a defect
|
|
123
|
+
* and returns SQLITE_ERROR.
|
|
124
|
+
* - A trap or a C stack overflow throws a `WebAssembly.RuntimeError`, which
|
|
125
|
+
* installed functions let through. When the static constructors trap, loading
|
|
126
|
+
* fails with {@link SqliteWasmCompileError}.
|
|
127
|
+
* - Any exception or trap that escapes a wasm call is a defect. It unwound C
|
|
128
|
+
* frames without cleanup, so the C stack and SQLite's state are left
|
|
129
|
+
* inconsistent: it is rethrown, the instance refuses every later call, and
|
|
130
|
+
* its worker should end. {@link SqliteWasm.call} enforces this. The CApi
|
|
131
|
+
* functions return the exports themselves, so code that calls them directly
|
|
132
|
+
* must call through it. An installed function that returns once the instance
|
|
133
|
+
* is broken, as one that caught what a nested call rethrew, or whose
|
|
134
|
+
* {@link ReportDefect} broke it, throws that refusal instead, so SQLite never
|
|
135
|
+
* resumes on that state.
|
|
136
|
+
*
|
|
137
|
+
* @module
|
|
138
|
+
*/
|
|
139
|
+
import { type ConsoleDep, type NonEmptyReadonlyArray, type RandomBytesDep, type ReportDefectDep, type Result, type Task, type TimeDep, type Typed } from "@evolu/common";
|
|
140
|
+
import type { SqliteCExports } from "./CApi.ts";
|
|
141
|
+
import { type SqliteResultCode } from "./Constants.ts";
|
|
142
|
+
import type { SqliteFunctionPtr } from "./Pointer.ts";
|
|
143
|
+
/**
|
|
144
|
+
* A loaded SQLite wasm instance.
|
|
145
|
+
*
|
|
146
|
+
* One instance serves every database of a worker. It cannot be disposed; it
|
|
147
|
+
* lives until the worker ends.
|
|
148
|
+
*/
|
|
149
|
+
export interface SqliteWasm {
|
|
150
|
+
/**
|
|
151
|
+
* The C functions, and the build's shims of the variadic ones, as the wasm
|
|
152
|
+
* exports them.
|
|
153
|
+
*
|
|
154
|
+
* Prefer the standalone functions of `@evolu/sqlite-wasm/c-api`, which read
|
|
155
|
+
* these once per database.
|
|
156
|
+
*/
|
|
157
|
+
readonly exports: SqliteCExports;
|
|
158
|
+
/** The wasm function table, where C function pointers point. */
|
|
159
|
+
readonly functionTable: WebAssembly.Table;
|
|
160
|
+
/**
|
|
161
|
+
* Returns a view of the whole heap, created again when memory has grown since
|
|
162
|
+
* the previous call.
|
|
163
|
+
*/
|
|
164
|
+
readonly getHeapU8: () => Uint8Array<ArrayBuffer>;
|
|
165
|
+
/** Returns a `DataView` of the whole heap, like {@link SqliteWasm.getHeapU8}. */
|
|
166
|
+
readonly getHeapDataView: () => DataView<ArrayBuffer>;
|
|
167
|
+
/**
|
|
168
|
+
* Calls a function that calls into wasm, and returns its result.
|
|
169
|
+
*
|
|
170
|
+
* Anything the function throws breaks the instance, as the module
|
|
171
|
+
* documentation explains: it is rethrown, and this and every later call throw
|
|
172
|
+
* without calling the function. Databases call wasm through it, and so should
|
|
173
|
+
* code that calls the CApi functions directly.
|
|
174
|
+
*/
|
|
175
|
+
readonly call: <T>(fn: () => T) => T;
|
|
176
|
+
/**
|
|
177
|
+
* Whether an error escaped {@link SqliteWasm.call}, so the instance refuses
|
|
178
|
+
* calls.
|
|
179
|
+
*/
|
|
180
|
+
readonly isBroken: () => boolean;
|
|
181
|
+
}
|
|
182
|
+
/** Dependency wrapper for {@link SqliteWasm}. */
|
|
183
|
+
export interface SqliteWasmDep {
|
|
184
|
+
readonly sqliteWasm: SqliteWasm;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* The wasm binary, compiled or not.
|
|
188
|
+
*
|
|
189
|
+
* A `Response` or a promise of one, such as `fetch` returns, compiles while it
|
|
190
|
+
* downloads when its `Content-Type` is exactly `application/wasm`, which keeps
|
|
191
|
+
* Chromium's code cache too. That is the only type every engine's
|
|
192
|
+
* `WebAssembly.compileStreaming` accepts, so any other compiles from its bytes
|
|
193
|
+
* once it has downloaded. A failed fetch fails with
|
|
194
|
+
* {@link SqliteWasmCompileError}, and so does a response whose status is not ok,
|
|
195
|
+
* such as a 404 for a wrong URL, with a `TypeError` naming the status as its
|
|
196
|
+
* cause. A `WebAssembly.Module` suits a module compiled elsewhere. Loading
|
|
197
|
+
* compiles a small generated module, so a Content Security Policy must allow
|
|
198
|
+
* 'wasm-unsafe-eval' even for a precompiled Module.
|
|
199
|
+
*/
|
|
200
|
+
export type SqliteWasmSource = WebAssembly.Module | BufferSource | Response | PromiseLike<Response>;
|
|
201
|
+
/**
|
|
202
|
+
* Loads the wasm, following the steps in the module documentation.
|
|
203
|
+
*
|
|
204
|
+
* Start it as early as possible, in the worker's composition root, and pass the
|
|
205
|
+
* instance to everything else through {@link SqliteWasmDep}.
|
|
206
|
+
*/
|
|
207
|
+
export declare const createSqliteWasm: (source: SqliteWasmSource) => Task<SqliteWasm, SqliteWasmError, ConsoleDep & RandomBytesDep & ReportDefectDep & TimeDep>;
|
|
208
|
+
/**
|
|
209
|
+
* Initializes the library as loading steps 6 and 7 do, for use after
|
|
210
|
+
* `sqlite3_shutdown` and `sqlite3_config`.
|
|
211
|
+
*
|
|
212
|
+
* `sqlite3_initialize` alone, or any call that initializes the library itself,
|
|
213
|
+
* such as an open, makes SQLite's `unix-none` VFS the default again and
|
|
214
|
+
* registers kvvfs again, so opening `:localStorage:` or `:sessionStorage:`
|
|
215
|
+
* traps and breaks the instance. Initializing leaves SQLite's random number
|
|
216
|
+
* generator as it is, but while `unix-none` is the default, a generator reset
|
|
217
|
+
* with `sqlite3_randomness(0, 0)`, or not used since loading, seeds itself at
|
|
218
|
+
* its next use from the time and a constant pid instead of {@link RandomBytes},
|
|
219
|
+
* so instances seeded in the same second share `randomblob()` values and
|
|
220
|
+
* journal nonces. This function resets the generator once `evolu-memory` is the
|
|
221
|
+
* default.
|
|
222
|
+
*
|
|
223
|
+
* Fails with {@link SqliteWasmInitializeError}, with SQLITE_MISUSE when
|
|
224
|
+
* `sqlite3_vfs_unregister` removed `evolu-memory`.
|
|
225
|
+
*/
|
|
226
|
+
export declare const initializeSqliteWasm: (deps: SqliteWasmDep) => () => Result<void, SqliteWasmInitializeError>;
|
|
227
|
+
/** Why {@link createSqliteWasm} failed. */
|
|
228
|
+
export type SqliteWasmError = SqliteWasmCompileError | SqliteWasmUnknownImportError | SqliteWasmBuildMismatchError | SqliteWasmInitializeError;
|
|
229
|
+
/**
|
|
230
|
+
* The source could not be fetched, compiled or instantiated, its memory could
|
|
231
|
+
* not be allocated, its static constructors failed, or the module that installs
|
|
232
|
+
* the default VFS's methods could not be compiled.
|
|
233
|
+
*/
|
|
234
|
+
export interface SqliteWasmCompileError extends Typed<"SqliteWasmCompileError"> {
|
|
235
|
+
readonly cause: unknown;
|
|
236
|
+
}
|
|
237
|
+
/** The binary declares imports the loader does not implement. */
|
|
238
|
+
export interface SqliteWasmUnknownImportError extends Typed<"SqliteWasmUnknownImport"> {
|
|
239
|
+
/** Each as `module.name`. */
|
|
240
|
+
readonly imports: NonEmptyReadonlyArray<string>;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* The binary's {@link sqliteWasmBuildHash} differs, so it is not the build the
|
|
244
|
+
* generated code describes.
|
|
245
|
+
*
|
|
246
|
+
* To use this binary, pin it with `node scripts/generate.mts --pin-build
|
|
247
|
+
* <wasm>` and regenerate.
|
|
248
|
+
*/
|
|
249
|
+
export interface SqliteWasmBuildMismatchError extends Typed<"SqliteWasmBuildMismatch"> {
|
|
250
|
+
readonly expectedHash: number;
|
|
251
|
+
readonly actualHash: number;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* `sqlite3_initialize` failed, or allocating, finding or registering the
|
|
255
|
+
* default VFS did, for example when out of memory.
|
|
256
|
+
*/
|
|
257
|
+
export interface SqliteWasmInitializeError extends Typed<"SqliteWasmInitializeError"> {
|
|
258
|
+
readonly code: SqliteResultCode;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* A JavaScript function to install into the function table.
|
|
262
|
+
*
|
|
263
|
+
* The signature uses the notation of {@link sqlite3_vfs_layout}, such as
|
|
264
|
+
* `i(ppij)`: the result, then the parameters in parentheses. `i`, `p` and `s`
|
|
265
|
+
* are i32, `j` is i64 (a bigint), `d` is f64, and a `v` result is no result.
|
|
266
|
+
* The result is `i` or `v`, because every callback SQLite calls in this build
|
|
267
|
+
* returns an int or nothing.
|
|
268
|
+
*/
|
|
269
|
+
export interface SqliteWasmFunction {
|
|
270
|
+
readonly signature: string;
|
|
271
|
+
readonly fn: (...args: never) => number | void;
|
|
272
|
+
}
|
|
273
|
+
/** Functions installed by {@link installWasmFunctions}. */
|
|
274
|
+
export interface SqliteWasmFunctions extends Disposable {
|
|
275
|
+
/** The functions' pointers, in the order they were given. */
|
|
276
|
+
readonly pointers: NonEmptyReadonlyArray<SqliteFunctionPtr>;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Installs functions into the function table.
|
|
280
|
+
*
|
|
281
|
+
* No engine exposes `WebAssembly.Function`, so a JavaScript function becomes a
|
|
282
|
+
* wasm function by being imported into a generated module that re-exports it.
|
|
283
|
+
* All functions of one call share one generated module. A call through one
|
|
284
|
+
* costs a few nanoseconds more than a call to a plain import, for the wrapper
|
|
285
|
+
* that catches exceptions: 12 ns against 9 ns in Node.js 24. A signature the
|
|
286
|
+
* notation does not cover throws. Compiling the generated module needs
|
|
287
|
+
* 'wasm-unsafe-eval' under a Content Security Policy; without it, this throws a
|
|
288
|
+
* `WebAssembly.CompileError`.
|
|
289
|
+
*
|
|
290
|
+
* No exception crosses into wasm. What a function throws is reported with
|
|
291
|
+
* {@link ReportDefect}, and the call returns SQLITE_ERROR, or nothing for a `v`
|
|
292
|
+
* result. So a commit hook rolls back, an `sqlite3_exec` callback aborts, and a
|
|
293
|
+
* VFS method fails, but a busy handler retries, forever if it always throws,
|
|
294
|
+
* and a SQL function's `xFunc` returns NULL. A function whose failure must mean
|
|
295
|
+
* something else catches its own errors, such as an `xFunc` calling
|
|
296
|
+
* `sqlite3_result_error`. An `i` function that returns something other than a
|
|
297
|
+
* number, or undefined for 0, is also reported as a defect and returns
|
|
298
|
+
* SQLITE_ERROR. Two kinds pass through, because they unwound C frames without
|
|
299
|
+
* cleanup: a `WebAssembly.RuntimeError`, which comes from a trap or a C stack
|
|
300
|
+
* overflow in wasm the function called, and anything thrown once the instance
|
|
301
|
+
* is broken, such as a JavaScript stack overflow that escaped a nested
|
|
302
|
+
* {@link SqliteWasm.call}. A function that returns once the instance is broken,
|
|
303
|
+
* as one that caught what a nested call rethrew, or whose ReportDefect broke
|
|
304
|
+
* it, throws the refusal of a broken instance instead, so SQLite never resumes
|
|
305
|
+
* on that state.
|
|
306
|
+
*
|
|
307
|
+
* Disposing the result empties its slots and keeps them for later installs, so
|
|
308
|
+
* per-database callbacks, such as an update hook, do not grow the table with
|
|
309
|
+
* each open. Dispose only once SQLite can no longer call the functions, for
|
|
310
|
+
* example after closing the database that holds them or replacing a hook: a
|
|
311
|
+
* call through an emptied slot traps, and a reused slot calls another function.
|
|
312
|
+
* A VFS's methods stay installed for the lifetime of the instance.
|
|
313
|
+
*/
|
|
314
|
+
export declare const installWasmFunctions: (deps: ReportDefectDep & SqliteWasmDep) => (functions: NonEmptyReadonlyArray<SqliteWasmFunction>) => SqliteWasmFunctions;
|
|
315
|
+
//# sourceMappingUR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