flatsql 1.3.0 → 1.4.4
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/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/package.json +12 -2
- package/wasm/flatsql-io.d.ts +97 -0
- package/wasm/flatsql-io.js +618 -0
- package/wasm/flatsql-wasi-noeh.wasm +0 -0
- package/wasm/flatsql-wasi.wasm +0 -0
- package/wasm/flatsql.js +1 -1
- package/wasm/flatsql.wasm +0 -0
- package/wasm/index.js +84 -0
- package/wasm/standalone.js +79 -2
package/dist/index.d.ts
CHANGED
|
@@ -4,9 +4,8 @@ export * from './schema/index.js';
|
|
|
4
4
|
export * from './core/index.js';
|
|
5
5
|
export * from './cluster/index.js';
|
|
6
6
|
export * from './flatbuffer-accessor.js';
|
|
7
|
-
export * from './artifacts/
|
|
7
|
+
export * from './artifacts/types.js';
|
|
8
8
|
export * from './response/index.js';
|
|
9
|
-
export * from './standalone/index.js';
|
|
10
9
|
export { FlatSQLDatabase, QueryResult, FlatBufferAccessor } from './core/database.js';
|
|
11
10
|
export { TableStore, TableRecord } from './core/table-store.js';
|
|
12
11
|
export { BTree } from './btree/btree.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AAKzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AAGpC,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACtF,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACrF,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -6,9 +6,12 @@ export * from './schema/index.js';
|
|
|
6
6
|
export * from './core/index.js';
|
|
7
7
|
export * from './cluster/index.js';
|
|
8
8
|
export * from './flatbuffer-accessor.js';
|
|
9
|
-
|
|
9
|
+
// Node-only surfaces (artifacts builder: node:sqlite/node:os; standalone
|
|
10
|
+
// runners: node:child_process/node:fs) live behind the 'flatsql/artifacts'
|
|
11
|
+
// and 'flatsql/standalone/wasmedge' subpath exports so the root entry stays
|
|
12
|
+
// loadable in a browser bundle. Only their type declarations are safe here.
|
|
13
|
+
export * from './artifacts/types.js';
|
|
10
14
|
export * from './response/index.js';
|
|
11
|
-
export * from './standalone/index.js';
|
|
12
15
|
// Re-export main types for convenience
|
|
13
16
|
export { FlatSQLDatabase } from './core/database.js';
|
|
14
17
|
export { TableStore } from './core/table-store.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,sEAAsE;AAEtE,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,sEAAsE;AAEtE,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,yEAAyE;AACzE,2EAA2E;AAC3E,4EAA4E;AAC5E,4EAA4E;AAC5E,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AAEpC,uCAAuC;AACvC,OAAO,EAAE,eAAe,EAAmC,MAAM,oBAAoB,CAAC;AACtF,OAAO,EAAE,UAAU,EAAe,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAuC,MAAM,mBAAmB,CAAC;AACrF,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flatsql",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.4",
|
|
4
4
|
"description": "SQL queries over raw FlatBuffer storage - zero conversion, real-time indexing, pure streaming",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -22,6 +22,14 @@
|
|
|
22
22
|
"types": "./wasm/standalone.d.ts",
|
|
23
23
|
"import": "./wasm/standalone.js"
|
|
24
24
|
},
|
|
25
|
+
"./io": {
|
|
26
|
+
"types": "./wasm/flatsql-io.d.ts",
|
|
27
|
+
"import": "./wasm/flatsql-io.js"
|
|
28
|
+
},
|
|
29
|
+
"./artifacts": {
|
|
30
|
+
"types": "./dist/artifacts/index.d.ts",
|
|
31
|
+
"import": "./dist/artifacts/index.js"
|
|
32
|
+
},
|
|
25
33
|
"./artifacts/standalone": {
|
|
26
34
|
"types": "./dist/artifacts/standalone-builder.d.ts",
|
|
27
35
|
"import": "./dist/artifacts/standalone-builder.js"
|
|
@@ -82,7 +90,9 @@
|
|
|
82
90
|
"stress:sds:docker-smoke": "bash scripts/stress-docker.sh docker-smoke",
|
|
83
91
|
"stress:sds:docker-fleet": "bash scripts/stress-docker.sh docker-fleet",
|
|
84
92
|
"stress:sds:full-config": "bash scripts/stress-docker.sh full-config",
|
|
85
|
-
"stress:sds:full": "bash scripts/stress-docker.sh full"
|
|
93
|
+
"stress:sds:full": "bash scripts/stress-docker.sh full",
|
|
94
|
+
"check:imports": "node scripts/check-wasm-imports.mjs",
|
|
95
|
+
"test:io": "node wasm/test-io-persistence.mjs"
|
|
86
96
|
},
|
|
87
97
|
"repository": {
|
|
88
98
|
"type": "git",
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for the FlatSQL host I/O contract (cpp/include/flatsql/flatsql_io.h).
|
|
3
|
+
*
|
|
4
|
+
* These live in the flatsql package on purpose: the seven-call shape is an ABI,
|
|
5
|
+
* and an ABI that each consumer re-declares locally is an ABI that drifts.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export declare const FLATSQL_IO_READ: number;
|
|
9
|
+
export declare const FLATSQL_IO_WRITE: number;
|
|
10
|
+
export declare const FLATSQL_IO_CREATE: number;
|
|
11
|
+
export declare const FLATSQL_IO_EXCL: number;
|
|
12
|
+
export declare const FLATSQL_IO_TRUNC: number;
|
|
13
|
+
export declare const FLATSQL_IO_DELETE_ON_CLOSE: number;
|
|
14
|
+
/** Namespace op: does the path exist? Returns a status, allocates no handle. */
|
|
15
|
+
export declare const FLATSQL_IO_PROBE: number;
|
|
16
|
+
/** Namespace op: remove the path. Returns a status, allocates no handle. */
|
|
17
|
+
export declare const FLATSQL_IO_UNLINK: number;
|
|
18
|
+
|
|
19
|
+
export declare const FLATSQL_IO_ERR_GENERIC: number;
|
|
20
|
+
export declare const FLATSQL_IO_ERR_NOENT: number;
|
|
21
|
+
export declare const FLATSQL_IO_ERR_ACCESS: number;
|
|
22
|
+
export declare const FLATSQL_IO_ERR_IO: number;
|
|
23
|
+
export declare const FLATSQL_IO_ERR_NOSPACE: number;
|
|
24
|
+
export declare const FLATSQL_IO_ERR_BADHANDLE: number;
|
|
25
|
+
|
|
26
|
+
export declare const DEFAULT_CHUNK_BYTES: number;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* A backend answers the seven imports SYNCHRONOUSLY, because a wasm import is
|
|
30
|
+
* synchronous. Offsets and sizes are plain numbers (f64 on the wire — never
|
|
31
|
+
* i64, which emscripten legalizes differently in the two lanes).
|
|
32
|
+
*/
|
|
33
|
+
export interface FlatSqlIoBackend {
|
|
34
|
+
/** Returns a handle, or a negative status. PROBE/UNLINK return a status. */
|
|
35
|
+
open(path: string, flags: number): number;
|
|
36
|
+
/** Bytes read; may be short at EOF. Never moves an implicit cursor. */
|
|
37
|
+
read(handle: number, dst: Uint8Array, offset: number): number;
|
|
38
|
+
/** Bytes written. Writing past EOF extends; the gap reads as zeroes. */
|
|
39
|
+
write(handle: number, src: Uint8Array, offset: number): number;
|
|
40
|
+
truncate(handle: number, size: number): number;
|
|
41
|
+
/**
|
|
42
|
+
* Durability barrier. On a synchronous backend bytes are durable at return;
|
|
43
|
+
* on an async store they become durable when the caller awaits flush().
|
|
44
|
+
*/
|
|
45
|
+
sync(handle: number): number;
|
|
46
|
+
size(handle: number): number;
|
|
47
|
+
close(handle: number): number;
|
|
48
|
+
|
|
49
|
+
/** Pull a file into the synchronous cache BEFORE the engine opens it. */
|
|
50
|
+
hydrate(path: string): Promise<unknown>;
|
|
51
|
+
/** Persist dirty state. No-op on synchronous backends. */
|
|
52
|
+
flush(): Promise<void>;
|
|
53
|
+
/** Remove a file and every key backing it. */
|
|
54
|
+
drop(path: string): Promise<void>;
|
|
55
|
+
|
|
56
|
+
readonly kind?: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface FlatSqlIoChunkOptions {
|
|
60
|
+
/** Page-group size in bytes. */
|
|
61
|
+
chunkBytes?: number;
|
|
62
|
+
/** Key namespace inside the store. */
|
|
63
|
+
prefix?: string;
|
|
64
|
+
/** Paths already known to exist. */
|
|
65
|
+
knownPaths?: string[];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Flat key -> bytes store: the shape every browser persistence store has. */
|
|
69
|
+
export interface FlatSqlKeyValueStore {
|
|
70
|
+
readBytes(key: string): Promise<Uint8Array | null>;
|
|
71
|
+
writeBytes(key: string, bytes: Uint8Array): Promise<void>;
|
|
72
|
+
deleteKey(key: string): Promise<void>;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export declare function createMemoryBackend(
|
|
76
|
+
options?: { chunkBytes?: number },
|
|
77
|
+
): FlatSqlIoBackend;
|
|
78
|
+
|
|
79
|
+
export declare function createNodeFsBackend(
|
|
80
|
+
fs: unknown,
|
|
81
|
+
options?: { root?: string },
|
|
82
|
+
): FlatSqlIoBackend;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Give a flat key -> bytes store real pread/pwrite semantics by addressing
|
|
86
|
+
* fixed-size page groups. A flush costs O(dirty chunks), not O(file).
|
|
87
|
+
*/
|
|
88
|
+
export declare function createChunkedStoreBackend(
|
|
89
|
+
store: FlatSqlKeyValueStore,
|
|
90
|
+
options?: FlatSqlIoChunkOptions,
|
|
91
|
+
): FlatSqlIoBackend & { knownPaths(): string[]; chunkBytes: number };
|
|
92
|
+
|
|
93
|
+
/** Build the `env` import object for a directly-instantiated (WASI) module. */
|
|
94
|
+
export declare function createFlatSqlIoImports(
|
|
95
|
+
backend: FlatSqlIoBackend,
|
|
96
|
+
memoryRef: () => WebAssembly.Memory,
|
|
97
|
+
): Record<string, (...args: number[]) => number>;
|
|
@@ -0,0 +1,618 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FlatSQL host I/O backends — the JavaScript half of the seven-import contract
|
|
3
|
+
* (cpp/include/flatsql/flatsql_io.h).
|
|
4
|
+
*
|
|
5
|
+
* ONE backend interface, used by BOTH JavaScript loaders:
|
|
6
|
+
* - the emscripten browser bundle, via cpp/js/flatsql_io_library.js
|
|
7
|
+
* - the standalone/WASI shim, via wasm/standalone.js
|
|
8
|
+
* ...and matched call-for-call by the Go host and by cpp/src/flatsql_io_native.cpp.
|
|
9
|
+
*
|
|
10
|
+
* A backend is SYNCHRONOUS, because a wasm import is. Its methods are:
|
|
11
|
+
*
|
|
12
|
+
* open(path: string, flags: number): number // handle, or negative status
|
|
13
|
+
* read(handle, dst: Uint8Array, offset: number): number
|
|
14
|
+
* write(handle, src: Uint8Array, offset: number): number
|
|
15
|
+
* truncate(handle, size: number): number
|
|
16
|
+
* sync(handle): number
|
|
17
|
+
* size(handle): number
|
|
18
|
+
* close(handle): number
|
|
19
|
+
*
|
|
20
|
+
* The pointer->subarray translation is done by the loader; a backend never sees
|
|
21
|
+
* wasm memory. That is the entire reason two very different hosts can satisfy
|
|
22
|
+
* the same seven calls without one line of runtime detection inside the module.
|
|
23
|
+
*
|
|
24
|
+
* ASYNC STORES (the one honest asymmetry, and it is in the shim where it
|
|
25
|
+
* belongs): IndexedDB and an HTTP desktop store cannot answer synchronously.
|
|
26
|
+
* createChunkedStoreBackend() therefore keeps a synchronous page cache and
|
|
27
|
+
* makes durability an explicit, awaited JavaScript step:
|
|
28
|
+
*
|
|
29
|
+
* await backend.hydrate(path); // BEFORE opening the database
|
|
30
|
+
* ... engine runs entirely synchronously ...
|
|
31
|
+
* await backend.flush(); // AFTER flatsql_flush_index()
|
|
32
|
+
*
|
|
33
|
+
* Results are identical to the native lane in every case; only the moment at
|
|
34
|
+
* which bytes become durable differs, and it is observable and awaited rather
|
|
35
|
+
* than assumed. Nothing about the wasm-side contract changes.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
export const FLATSQL_IO_READ = 0x0001;
|
|
39
|
+
export const FLATSQL_IO_WRITE = 0x0002;
|
|
40
|
+
export const FLATSQL_IO_CREATE = 0x0004;
|
|
41
|
+
export const FLATSQL_IO_EXCL = 0x0008;
|
|
42
|
+
export const FLATSQL_IO_TRUNC = 0x0010;
|
|
43
|
+
export const FLATSQL_IO_DELETE_ON_CLOSE = 0x0020;
|
|
44
|
+
export const FLATSQL_IO_PROBE = 0x0040;
|
|
45
|
+
export const FLATSQL_IO_UNLINK = 0x0080;
|
|
46
|
+
|
|
47
|
+
export const FLATSQL_IO_ERR_GENERIC = -1;
|
|
48
|
+
export const FLATSQL_IO_ERR_NOENT = -2;
|
|
49
|
+
export const FLATSQL_IO_ERR_ACCESS = -3;
|
|
50
|
+
export const FLATSQL_IO_ERR_IO = -4;
|
|
51
|
+
export const FLATSQL_IO_ERR_NOSPACE = -5;
|
|
52
|
+
export const FLATSQL_IO_ERR_BADHANDLE = -6;
|
|
53
|
+
|
|
54
|
+
/** Default page-group size. One IndexedDB value per group. */
|
|
55
|
+
export const DEFAULT_CHUNK_BYTES = 64 * 1024;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* A file living in RAM as a set of fixed-size chunks. Shared by every backend
|
|
59
|
+
* so that chunk boundaries, growth and zero-fill behave identically no matter
|
|
60
|
+
* what the bytes are eventually persisted into.
|
|
61
|
+
*/
|
|
62
|
+
class ChunkedFile {
|
|
63
|
+
constructor(path, chunkBytes) {
|
|
64
|
+
this.path = path;
|
|
65
|
+
this.chunkBytes = chunkBytes;
|
|
66
|
+
this.chunks = new Map(); // index -> Uint8Array(chunkBytes)
|
|
67
|
+
this.dirty = new Set();
|
|
68
|
+
this.length = 0;
|
|
69
|
+
this.metaDirty = false;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
chunk(index, create) {
|
|
73
|
+
let buf = this.chunks.get(index);
|
|
74
|
+
if (!buf && create) {
|
|
75
|
+
buf = new Uint8Array(this.chunkBytes);
|
|
76
|
+
this.chunks.set(index, buf);
|
|
77
|
+
}
|
|
78
|
+
return buf || null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
read(dst, offset) {
|
|
82
|
+
// A read past EOF is a SHORT read, never an error — the C side zero-fills
|
|
83
|
+
// the remainder and reports SQLITE_IOERR_SHORT_READ, exactly as POSIX
|
|
84
|
+
// pread does. Getting this wrong silently corrupts pager reads.
|
|
85
|
+
const available = Math.max(0, this.length - offset);
|
|
86
|
+
const want = Math.min(dst.length, available);
|
|
87
|
+
let done = 0;
|
|
88
|
+
while (done < want) {
|
|
89
|
+
const at = offset + done;
|
|
90
|
+
const index = Math.floor(at / this.chunkBytes);
|
|
91
|
+
const within = at % this.chunkBytes;
|
|
92
|
+
const n = Math.min(this.chunkBytes - within, want - done);
|
|
93
|
+
const buf = this.chunk(index, false);
|
|
94
|
+
if (buf) {
|
|
95
|
+
dst.set(buf.subarray(within, within + n), done);
|
|
96
|
+
} else {
|
|
97
|
+
dst.fill(0, done, done + n); // sparse hole
|
|
98
|
+
}
|
|
99
|
+
done += n;
|
|
100
|
+
}
|
|
101
|
+
return want;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
write(src, offset) {
|
|
105
|
+
let done = 0;
|
|
106
|
+
while (done < src.length) {
|
|
107
|
+
const at = offset + done;
|
|
108
|
+
const index = Math.floor(at / this.chunkBytes);
|
|
109
|
+
const within = at % this.chunkBytes;
|
|
110
|
+
const n = Math.min(this.chunkBytes - within, src.length - done);
|
|
111
|
+
const buf = this.chunk(index, true);
|
|
112
|
+
buf.set(src.subarray(done, done + n), within);
|
|
113
|
+
this.dirty.add(index);
|
|
114
|
+
done += n;
|
|
115
|
+
}
|
|
116
|
+
if (offset + src.length > this.length) {
|
|
117
|
+
this.length = offset + src.length;
|
|
118
|
+
this.metaDirty = true;
|
|
119
|
+
}
|
|
120
|
+
return src.length;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
truncate(size) {
|
|
124
|
+
if (size < this.length) {
|
|
125
|
+
const lastIndex = Math.floor(size / this.chunkBytes);
|
|
126
|
+
for (const index of Array.from(this.chunks.keys())) {
|
|
127
|
+
if (index > lastIndex) {
|
|
128
|
+
this.chunks.delete(index);
|
|
129
|
+
this.dirty.add(index); // removal must be persisted too
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const tail = this.chunk(lastIndex, false);
|
|
133
|
+
if (tail) {
|
|
134
|
+
tail.fill(0, size % this.chunkBytes);
|
|
135
|
+
this.dirty.add(lastIndex);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
this.length = size;
|
|
139
|
+
this.metaDirty = true;
|
|
140
|
+
return 0;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Handle table shared by every backend: small, dense, reused after close. */
|
|
145
|
+
class HandleTable {
|
|
146
|
+
constructor() {
|
|
147
|
+
this.slots = [];
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
add(entry) {
|
|
151
|
+
for (let i = 0; i < this.slots.length; i++) {
|
|
152
|
+
if (!this.slots[i]) {
|
|
153
|
+
this.slots[i] = entry;
|
|
154
|
+
return i;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
this.slots.push(entry);
|
|
158
|
+
return this.slots.length - 1;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
get(handle) {
|
|
162
|
+
return this.slots[handle] || null;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
remove(handle) {
|
|
166
|
+
const entry = this.slots[handle];
|
|
167
|
+
this.slots[handle] = null;
|
|
168
|
+
return entry;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Pure in-memory backend. Durable for exactly as long as the process lives —
|
|
174
|
+
* which is the DOCUMENTED behaviour asserted by the Memory-store lane of the
|
|
175
|
+
* test matrix, not a skipped case.
|
|
176
|
+
*/
|
|
177
|
+
export function createMemoryBackend(options = {}) {
|
|
178
|
+
const chunkBytes = options.chunkBytes || DEFAULT_CHUNK_BYTES;
|
|
179
|
+
const files = new Map();
|
|
180
|
+
const handles = new HandleTable();
|
|
181
|
+
|
|
182
|
+
return {
|
|
183
|
+
kind: 'memory',
|
|
184
|
+
files,
|
|
185
|
+
|
|
186
|
+
open(path, flags) {
|
|
187
|
+
if (flags & FLATSQL_IO_PROBE) {
|
|
188
|
+
return files.has(path) ? 0 : FLATSQL_IO_ERR_NOENT;
|
|
189
|
+
}
|
|
190
|
+
if (flags & FLATSQL_IO_UNLINK) {
|
|
191
|
+
return files.delete(path) ? 0 : FLATSQL_IO_ERR_NOENT;
|
|
192
|
+
}
|
|
193
|
+
let file = files.get(path);
|
|
194
|
+
if (!file) {
|
|
195
|
+
if (!(flags & FLATSQL_IO_CREATE)) return FLATSQL_IO_ERR_NOENT;
|
|
196
|
+
file = new ChunkedFile(path, chunkBytes);
|
|
197
|
+
files.set(path, file);
|
|
198
|
+
} else if (flags & FLATSQL_IO_EXCL) {
|
|
199
|
+
return FLATSQL_IO_ERR_ACCESS;
|
|
200
|
+
}
|
|
201
|
+
if (flags & FLATSQL_IO_TRUNC) file.truncate(0);
|
|
202
|
+
return handles.add({ file, deleteOnClose: !!(flags & FLATSQL_IO_DELETE_ON_CLOSE) });
|
|
203
|
+
},
|
|
204
|
+
|
|
205
|
+
read(handle, dst, offset) {
|
|
206
|
+
const entry = handles.get(handle);
|
|
207
|
+
if (!entry) return FLATSQL_IO_ERR_BADHANDLE;
|
|
208
|
+
return entry.file.read(dst, offset);
|
|
209
|
+
},
|
|
210
|
+
|
|
211
|
+
write(handle, src, offset) {
|
|
212
|
+
const entry = handles.get(handle);
|
|
213
|
+
if (!entry) return FLATSQL_IO_ERR_BADHANDLE;
|
|
214
|
+
return entry.file.write(src, offset);
|
|
215
|
+
},
|
|
216
|
+
|
|
217
|
+
truncate(handle, size) {
|
|
218
|
+
const entry = handles.get(handle);
|
|
219
|
+
if (!entry) return FLATSQL_IO_ERR_BADHANDLE;
|
|
220
|
+
return entry.file.truncate(size);
|
|
221
|
+
},
|
|
222
|
+
|
|
223
|
+
sync() {
|
|
224
|
+
return 0; // RAM is already as durable as it will ever be
|
|
225
|
+
},
|
|
226
|
+
|
|
227
|
+
size(handle) {
|
|
228
|
+
const entry = handles.get(handle);
|
|
229
|
+
if (!entry) return FLATSQL_IO_ERR_BADHANDLE;
|
|
230
|
+
return entry.file.length;
|
|
231
|
+
},
|
|
232
|
+
|
|
233
|
+
close(handle) {
|
|
234
|
+
const entry = handles.remove(handle);
|
|
235
|
+
if (!entry) return FLATSQL_IO_ERR_BADHANDLE;
|
|
236
|
+
if (entry.deleteOnClose) files.delete(entry.file.path);
|
|
237
|
+
return 0;
|
|
238
|
+
},
|
|
239
|
+
|
|
240
|
+
async hydrate() {},
|
|
241
|
+
async flush() {},
|
|
242
|
+
async drop(path) {
|
|
243
|
+
files.delete(path);
|
|
244
|
+
},
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Node/desktop backend over real files. Fully synchronous, so sync() really is
|
|
250
|
+
* durable at return — this lane has no asymmetry at all.
|
|
251
|
+
*
|
|
252
|
+
* `fs` is injected rather than imported so the module stays loadable in a
|
|
253
|
+
* browser bundle that will never call this.
|
|
254
|
+
*/
|
|
255
|
+
export function createNodeFsBackend(fs, options = {}) {
|
|
256
|
+
const root = options.root || '';
|
|
257
|
+
const handles = new HandleTable();
|
|
258
|
+
const resolve = (p) => (root ? `${root}/${p.replace(/^\/+/, '')}` : p);
|
|
259
|
+
|
|
260
|
+
const statusFor = (err) => {
|
|
261
|
+
if (!err || !err.code) return FLATSQL_IO_ERR_GENERIC;
|
|
262
|
+
if (err.code === 'ENOENT') return FLATSQL_IO_ERR_NOENT;
|
|
263
|
+
if (err.code === 'EACCES' || err.code === 'EPERM') return FLATSQL_IO_ERR_ACCESS;
|
|
264
|
+
if (err.code === 'ENOSPC') return FLATSQL_IO_ERR_NOSPACE;
|
|
265
|
+
return FLATSQL_IO_ERR_IO;
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
return {
|
|
269
|
+
kind: 'node-fs',
|
|
270
|
+
|
|
271
|
+
open(path, flags) {
|
|
272
|
+
const full = resolve(path);
|
|
273
|
+
try {
|
|
274
|
+
if (flags & FLATSQL_IO_PROBE) {
|
|
275
|
+
fs.statSync(full);
|
|
276
|
+
return 0;
|
|
277
|
+
}
|
|
278
|
+
if (flags & FLATSQL_IO_UNLINK) {
|
|
279
|
+
fs.unlinkSync(full);
|
|
280
|
+
return 0;
|
|
281
|
+
}
|
|
282
|
+
let mode = 'r';
|
|
283
|
+
if (flags & FLATSQL_IO_WRITE) {
|
|
284
|
+
mode = flags & FLATSQL_IO_EXCL ? 'wx+' : flags & FLATSQL_IO_CREATE ? 'a+' : 'r+';
|
|
285
|
+
}
|
|
286
|
+
const fd = fs.openSync(full, mode);
|
|
287
|
+
return handles.add({
|
|
288
|
+
fd,
|
|
289
|
+
path: full,
|
|
290
|
+
deleteOnClose: !!(flags & FLATSQL_IO_DELETE_ON_CLOSE),
|
|
291
|
+
});
|
|
292
|
+
} catch (err) {
|
|
293
|
+
return statusFor(err);
|
|
294
|
+
}
|
|
295
|
+
},
|
|
296
|
+
|
|
297
|
+
read(handle, dst, offset) {
|
|
298
|
+
const entry = handles.get(handle);
|
|
299
|
+
if (!entry) return FLATSQL_IO_ERR_BADHANDLE;
|
|
300
|
+
try {
|
|
301
|
+
return fs.readSync(entry.fd, dst, 0, dst.length, offset);
|
|
302
|
+
} catch (err) {
|
|
303
|
+
return statusFor(err);
|
|
304
|
+
}
|
|
305
|
+
},
|
|
306
|
+
|
|
307
|
+
write(handle, src, offset) {
|
|
308
|
+
const entry = handles.get(handle);
|
|
309
|
+
if (!entry) return FLATSQL_IO_ERR_BADHANDLE;
|
|
310
|
+
try {
|
|
311
|
+
return fs.writeSync(entry.fd, src, 0, src.length, offset);
|
|
312
|
+
} catch (err) {
|
|
313
|
+
return statusFor(err);
|
|
314
|
+
}
|
|
315
|
+
},
|
|
316
|
+
|
|
317
|
+
truncate(handle, size) {
|
|
318
|
+
const entry = handles.get(handle);
|
|
319
|
+
if (!entry) return FLATSQL_IO_ERR_BADHANDLE;
|
|
320
|
+
try {
|
|
321
|
+
fs.ftruncateSync(entry.fd, size);
|
|
322
|
+
return 0;
|
|
323
|
+
} catch (err) {
|
|
324
|
+
return statusFor(err);
|
|
325
|
+
}
|
|
326
|
+
},
|
|
327
|
+
|
|
328
|
+
sync(handle) {
|
|
329
|
+
const entry = handles.get(handle);
|
|
330
|
+
if (!entry) return FLATSQL_IO_ERR_BADHANDLE;
|
|
331
|
+
try {
|
|
332
|
+
fs.fsyncSync(entry.fd);
|
|
333
|
+
return 0;
|
|
334
|
+
} catch (err) {
|
|
335
|
+
return statusFor(err);
|
|
336
|
+
}
|
|
337
|
+
},
|
|
338
|
+
|
|
339
|
+
size(handle) {
|
|
340
|
+
const entry = handles.get(handle);
|
|
341
|
+
if (!entry) return FLATSQL_IO_ERR_BADHANDLE;
|
|
342
|
+
try {
|
|
343
|
+
return fs.fstatSync(entry.fd).size;
|
|
344
|
+
} catch (err) {
|
|
345
|
+
return statusFor(err);
|
|
346
|
+
}
|
|
347
|
+
},
|
|
348
|
+
|
|
349
|
+
close(handle) {
|
|
350
|
+
const entry = handles.remove(handle);
|
|
351
|
+
if (!entry) return FLATSQL_IO_ERR_BADHANDLE;
|
|
352
|
+
try {
|
|
353
|
+
fs.closeSync(entry.fd);
|
|
354
|
+
if (entry.deleteOnClose) {
|
|
355
|
+
try {
|
|
356
|
+
fs.unlinkSync(entry.path);
|
|
357
|
+
} catch (_) {
|
|
358
|
+
/* already gone */
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
return 0;
|
|
362
|
+
} catch (err) {
|
|
363
|
+
return statusFor(err);
|
|
364
|
+
}
|
|
365
|
+
},
|
|
366
|
+
|
|
367
|
+
async hydrate() {},
|
|
368
|
+
async flush() {},
|
|
369
|
+
async drop(path) {
|
|
370
|
+
try {
|
|
371
|
+
fs.unlinkSync(resolve(path));
|
|
372
|
+
} catch (_) {
|
|
373
|
+
/* already gone */
|
|
374
|
+
}
|
|
375
|
+
},
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Backend over ANY flat key->bytes store — the shape every sdn-js persistence
|
|
381
|
+
* store already has (readBytes/writeBytes/deleteKey). This is what gives a
|
|
382
|
+
* store with no seek and no partial write real pread/pwrite semantics:
|
|
383
|
+
*
|
|
384
|
+
* <prefix><path>#<pageGroup> fixed-size chunk of file bytes
|
|
385
|
+
* <prefix><path>#meta JSON { length }
|
|
386
|
+
*
|
|
387
|
+
* Because addressing is by chunk index, a flush costs O(dirty chunks) rather
|
|
388
|
+
* than O(file), and the browser lane reads and writes the same byte ranges the
|
|
389
|
+
* POSIX lane does. It is not "the browser rewrites everything" — the two lanes
|
|
390
|
+
* are the same algorithm over a different transport.
|
|
391
|
+
*
|
|
392
|
+
* `store` must provide:
|
|
393
|
+
* readBytes(key): Promise<Uint8Array|null>
|
|
394
|
+
* writeBytes(key, bytes): Promise<void>
|
|
395
|
+
* deleteKey(key): Promise<void>
|
|
396
|
+
*/
|
|
397
|
+
export function createChunkedStoreBackend(store, options = {}) {
|
|
398
|
+
const chunkBytes = options.chunkBytes || DEFAULT_CHUNK_BYTES;
|
|
399
|
+
const prefix = options.prefix || 'flatsql-io/';
|
|
400
|
+
const files = new Map();
|
|
401
|
+
const handles = new HandleTable();
|
|
402
|
+
const known = new Set(options.knownPaths || []);
|
|
403
|
+
|
|
404
|
+
const metaKey = (path) => `${prefix}${path}#meta`;
|
|
405
|
+
const chunkKey = (path, index) => `${prefix}${path}#${index}`;
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Pull a file's chunks into the synchronous cache. MUST be awaited before
|
|
409
|
+
* the engine opens the database: after that point every call is synchronous
|
|
410
|
+
* because a wasm import cannot await.
|
|
411
|
+
*/
|
|
412
|
+
async function hydrate(path) {
|
|
413
|
+
if (files.has(path)) return files.get(path);
|
|
414
|
+
const file = new ChunkedFile(path, chunkBytes);
|
|
415
|
+
let meta = null;
|
|
416
|
+
const raw = await store.readBytes(metaKey(path));
|
|
417
|
+
if (raw) {
|
|
418
|
+
try {
|
|
419
|
+
meta = JSON.parse(new TextDecoder().decode(raw));
|
|
420
|
+
} catch (_) {
|
|
421
|
+
meta = null;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
if (meta && Number.isFinite(meta.length)) {
|
|
425
|
+
file.length = meta.length;
|
|
426
|
+
if (meta.chunkBytes && meta.chunkBytes !== chunkBytes) {
|
|
427
|
+
// A different page-group size means the persisted keys do not line up
|
|
428
|
+
// with the ones we would read. Treat it as absent: derived state is
|
|
429
|
+
// always rebuildable, so this costs a re-derivation and never a wrong
|
|
430
|
+
// answer.
|
|
431
|
+
file.length = 0;
|
|
432
|
+
} else {
|
|
433
|
+
const count = Math.ceil(file.length / chunkBytes);
|
|
434
|
+
for (let i = 0; i < count; i++) {
|
|
435
|
+
const bytes = await store.readBytes(chunkKey(path, i));
|
|
436
|
+
if (bytes) {
|
|
437
|
+
const buf = new Uint8Array(chunkBytes);
|
|
438
|
+
buf.set(bytes.subarray(0, Math.min(bytes.length, chunkBytes)));
|
|
439
|
+
file.chunks.set(i, buf);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
known.add(path);
|
|
444
|
+
}
|
|
445
|
+
files.set(path, file);
|
|
446
|
+
return file;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/** Persist every dirty chunk plus the length. Await this after a flush. */
|
|
450
|
+
async function flush() {
|
|
451
|
+
for (const [path, file] of files) {
|
|
452
|
+
if (!file.dirty.size && !file.metaDirty) continue;
|
|
453
|
+
for (const index of file.dirty) {
|
|
454
|
+
const buf = file.chunks.get(index);
|
|
455
|
+
if (buf) {
|
|
456
|
+
const start = index * chunkBytes;
|
|
457
|
+
const end = Math.min(chunkBytes, Math.max(0, file.length - start));
|
|
458
|
+
await store.writeBytes(chunkKey(path, index), buf.subarray(0, end));
|
|
459
|
+
} else {
|
|
460
|
+
await store.deleteKey(chunkKey(path, index));
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
file.dirty.clear();
|
|
464
|
+
if (file.metaDirty || file.length >= 0) {
|
|
465
|
+
await store.writeBytes(
|
|
466
|
+
metaKey(path),
|
|
467
|
+
new TextEncoder().encode(JSON.stringify({ length: file.length, chunkBytes })),
|
|
468
|
+
);
|
|
469
|
+
file.metaDirty = false;
|
|
470
|
+
}
|
|
471
|
+
known.add(path);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
async function drop(path) {
|
|
476
|
+
const file = files.get(path);
|
|
477
|
+
const count = file
|
|
478
|
+
? Math.max(Math.ceil(file.length / chunkBytes), ...[...file.chunks.keys()].map((i) => i + 1), 0)
|
|
479
|
+
: 0;
|
|
480
|
+
for (let i = 0; i < count; i++) await store.deleteKey(chunkKey(path, i));
|
|
481
|
+
await store.deleteKey(metaKey(path));
|
|
482
|
+
files.delete(path);
|
|
483
|
+
known.delete(path);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
return {
|
|
487
|
+
kind: 'chunked-store',
|
|
488
|
+
chunkBytes,
|
|
489
|
+
hydrate,
|
|
490
|
+
flush,
|
|
491
|
+
drop,
|
|
492
|
+
/** Paths this backend believes exist — used to hydrate before an open. */
|
|
493
|
+
knownPaths: () => Array.from(known),
|
|
494
|
+
|
|
495
|
+
open(path, flags) {
|
|
496
|
+
if (flags & FLATSQL_IO_PROBE) {
|
|
497
|
+
const file = files.get(path);
|
|
498
|
+
if (file) return file.length > 0 || file.chunks.size > 0 ? 0 : FLATSQL_IO_ERR_NOENT;
|
|
499
|
+
return known.has(path) ? 0 : FLATSQL_IO_ERR_NOENT;
|
|
500
|
+
}
|
|
501
|
+
if (flags & FLATSQL_IO_UNLINK) {
|
|
502
|
+
const file = files.get(path);
|
|
503
|
+
if (file) file.truncate(0);
|
|
504
|
+
known.delete(path);
|
|
505
|
+
return 0;
|
|
506
|
+
}
|
|
507
|
+
let file = files.get(path);
|
|
508
|
+
if (!file) {
|
|
509
|
+
// Not hydrated. Creating is fine (it is genuinely new); opening an
|
|
510
|
+
// existing file that was never hydrated is a caller error we refuse
|
|
511
|
+
// rather than answer with an empty file — an empty answer here is
|
|
512
|
+
// indistinguishable from data loss.
|
|
513
|
+
if (!(flags & FLATSQL_IO_CREATE)) return FLATSQL_IO_ERR_NOENT;
|
|
514
|
+
file = new ChunkedFile(path, chunkBytes);
|
|
515
|
+
file.metaDirty = true;
|
|
516
|
+
files.set(path, file);
|
|
517
|
+
} else if (flags & FLATSQL_IO_EXCL && file.length > 0) {
|
|
518
|
+
return FLATSQL_IO_ERR_ACCESS;
|
|
519
|
+
}
|
|
520
|
+
if (flags & FLATSQL_IO_TRUNC) file.truncate(0);
|
|
521
|
+
return handles.add({
|
|
522
|
+
file,
|
|
523
|
+
deleteOnClose: !!(flags & FLATSQL_IO_DELETE_ON_CLOSE),
|
|
524
|
+
});
|
|
525
|
+
},
|
|
526
|
+
|
|
527
|
+
read(handle, dst, offset) {
|
|
528
|
+
const entry = handles.get(handle);
|
|
529
|
+
if (!entry) return FLATSQL_IO_ERR_BADHANDLE;
|
|
530
|
+
return entry.file.read(dst, offset);
|
|
531
|
+
},
|
|
532
|
+
|
|
533
|
+
write(handle, src, offset) {
|
|
534
|
+
const entry = handles.get(handle);
|
|
535
|
+
if (!entry) return FLATSQL_IO_ERR_BADHANDLE;
|
|
536
|
+
return entry.file.write(src, offset);
|
|
537
|
+
},
|
|
538
|
+
|
|
539
|
+
truncate(handle, size) {
|
|
540
|
+
const entry = handles.get(handle);
|
|
541
|
+
if (!entry) return FLATSQL_IO_ERR_BADHANDLE;
|
|
542
|
+
return entry.file.truncate(size);
|
|
543
|
+
},
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* A durability BARRIER, not a durability guarantee — the underlying store
|
|
547
|
+
* is asynchronous and a wasm import cannot await. Bytes become durable when
|
|
548
|
+
* the caller awaits flush(). Stated plainly because the alternative is a
|
|
549
|
+
* shim that claims fsync semantics it cannot deliver, which is precisely
|
|
550
|
+
* the class of lie this whole task exists to remove.
|
|
551
|
+
*/
|
|
552
|
+
sync(handle) {
|
|
553
|
+
const entry = handles.get(handle);
|
|
554
|
+
if (!entry) return FLATSQL_IO_ERR_BADHANDLE;
|
|
555
|
+
return 0;
|
|
556
|
+
},
|
|
557
|
+
|
|
558
|
+
size(handle) {
|
|
559
|
+
const entry = handles.get(handle);
|
|
560
|
+
if (!entry) return FLATSQL_IO_ERR_BADHANDLE;
|
|
561
|
+
return entry.file.length;
|
|
562
|
+
},
|
|
563
|
+
|
|
564
|
+
close(handle) {
|
|
565
|
+
const entry = handles.remove(handle);
|
|
566
|
+
if (!entry) return FLATSQL_IO_ERR_BADHANDLE;
|
|
567
|
+
if (entry.deleteOnClose) {
|
|
568
|
+
entry.file.truncate(0);
|
|
569
|
+
known.delete(entry.file.path);
|
|
570
|
+
}
|
|
571
|
+
return 0;
|
|
572
|
+
},
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* Build the `env` import object for a directly-instantiated (WASI) module.
|
|
578
|
+
* The pointer->subarray translation here is the mirror image of the one in
|
|
579
|
+
* cpp/js/flatsql_io_library.js; keeping them in one file each, both feeding the
|
|
580
|
+
* same backend, is what stops the lanes drifting apart.
|
|
581
|
+
*/
|
|
582
|
+
export function createFlatSqlIoImports(backend, memoryRef) {
|
|
583
|
+
const heap = () => new Uint8Array(memoryRef().buffer);
|
|
584
|
+
const guard = (fn) => {
|
|
585
|
+
try {
|
|
586
|
+
return fn();
|
|
587
|
+
} catch (_) {
|
|
588
|
+
return FLATSQL_IO_ERR_GENERIC;
|
|
589
|
+
}
|
|
590
|
+
};
|
|
591
|
+
|
|
592
|
+
return {
|
|
593
|
+
flatsql_io_open(pathPtr, pathLen, flags) {
|
|
594
|
+
return guard(() => {
|
|
595
|
+
const bytes = heap().subarray(pathPtr, pathPtr + pathLen);
|
|
596
|
+
return backend.open(new TextDecoder().decode(bytes), flags) | 0;
|
|
597
|
+
});
|
|
598
|
+
},
|
|
599
|
+
flatsql_io_read(handle, dstPtr, len, offset) {
|
|
600
|
+
return guard(() => backend.read(handle, heap().subarray(dstPtr, dstPtr + len), offset) | 0);
|
|
601
|
+
},
|
|
602
|
+
flatsql_io_write(handle, srcPtr, len, offset) {
|
|
603
|
+
return guard(() => backend.write(handle, heap().subarray(srcPtr, srcPtr + len), offset) | 0);
|
|
604
|
+
},
|
|
605
|
+
flatsql_io_truncate(handle, size) {
|
|
606
|
+
return guard(() => backend.truncate(handle, size) | 0);
|
|
607
|
+
},
|
|
608
|
+
flatsql_io_sync(handle) {
|
|
609
|
+
return guard(() => backend.sync(handle) | 0);
|
|
610
|
+
},
|
|
611
|
+
flatsql_io_size(handle) {
|
|
612
|
+
return guard(() => backend.size(handle));
|
|
613
|
+
},
|
|
614
|
+
flatsql_io_close(handle) {
|
|
615
|
+
return guard(() => backend.close(handle) | 0);
|
|
616
|
+
},
|
|
617
|
+
};
|
|
618
|
+
}
|
|
Binary file
|
package/wasm/flatsql-wasi.wasm
CHANGED
|
Binary file
|
package/wasm/flatsql.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
async function FlatSQL(moduleArg={}){var moduleRtn;var Module=moduleArg;var ENVIRONMENT_IS_WEB=!!globalThis.window;var ENVIRONMENT_IS_WORKER=!!globalThis.WorkerGlobalScope;var ENVIRONMENT_IS_NODE=globalThis.process?.versions?.node&&globalThis.process?.type!="renderer";if(ENVIRONMENT_IS_NODE){const{createRequire}=await import("module");var require=createRequire(import.meta.url)}var arguments_=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var _scriptName=import.meta.url;var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var readAsync,readBinary;if(ENVIRONMENT_IS_NODE){var fs=require("fs");if(_scriptName.startsWith("file:")){scriptDirectory=require("path").dirname(require("url").fileURLToPath(_scriptName))+"/"}readBinary=filename=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename);return ret};readAsync=async(filename,binary=true)=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename,binary?undefined:"utf8");return ret};if(process.argv.length>1){thisProgram=process.argv[1].replace(/\\/g,"/")}arguments_=process.argv.slice(2);quit_=(status,toThrow)=>{process.exitCode=status;throw toThrow}}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){try{scriptDirectory=new URL(".",_scriptName).href}catch{}{if(ENVIRONMENT_IS_WORKER){readBinary=url=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.responseType="arraybuffer";xhr.send(null);return new Uint8Array(xhr.response)}}readAsync=async url=>{var response=await fetch(url,{credentials:"same-origin"});if(response.ok){return response.arrayBuffer()}throw new Error(response.status+" : "+response.url)}}}else{}var out=console.log.bind(console);var err=console.error.bind(console);var wasmBinary;var ABORT=false;var isFileURI=filename=>filename.startsWith("file://");var readyPromiseResolve,readyPromiseReject;var HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAPF32,HEAPF64;var HEAP64,HEAPU64;var runtimeInitialized=false;function updateMemoryViews(){var b=wasmMemory.buffer;HEAP8=new Int8Array(b);HEAP16=new Int16Array(b);Module["HEAPU8"]=HEAPU8=new Uint8Array(b);HEAPU16=new Uint16Array(b);HEAP32=new Int32Array(b);HEAPU32=new Uint32Array(b);HEAPF32=new Float32Array(b);HEAPF64=new Float64Array(b);HEAP64=new BigInt64Array(b);HEAPU64=new BigUint64Array(b)}function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift())}}callRuntimeCallbacks(onPreRuns)}function initRuntime(){runtimeInitialized=true;wasmExports["Ea"]()}function postRun(){if(Module["postRun"]){if(typeof Module["postRun"]=="function")Module["postRun"]=[Module["postRun"]];while(Module["postRun"].length){addOnPostRun(Module["postRun"].shift())}}callRuntimeCallbacks(onPostRuns)}function abort(what){Module["onAbort"]?.(what);what="Aborted("+what+")";err(what);ABORT=true;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);readyPromiseReject?.(e);throw e}var wasmBinaryFile;function findWasmBinary(){if(Module["locateFile"]){return locateFile("flatsql.wasm")}return new URL("flatsql.wasm",import.meta.url).href}function getBinarySync(file){if(file==wasmBinaryFile&&wasmBinary){return new Uint8Array(wasmBinary)}if(readBinary){return readBinary(file)}throw"both async and sync fetching of the wasm failed"}async function getWasmBinary(binaryFile){if(!wasmBinary){try{var response=await readAsync(binaryFile);return new Uint8Array(response)}catch{}}return getBinarySync(binaryFile)}async function instantiateArrayBuffer(binaryFile,imports){try{var binary=await getWasmBinary(binaryFile);var instance=await WebAssembly.instantiate(binary,imports);return instance}catch(reason){err(`failed to asynchronously prepare wasm: ${reason}`);abort(reason)}}async function instantiateAsync(binary,binaryFile,imports){if(!binary&&!ENVIRONMENT_IS_NODE){try{var response=fetch(binaryFile,{credentials:"same-origin"});var instantiationResult=await WebAssembly.instantiateStreaming(response,imports);return instantiationResult}catch(reason){err(`wasm streaming compile failed: ${reason}`);err("falling back to ArrayBuffer instantiation")}}return instantiateArrayBuffer(binaryFile,imports)}function getWasmImports(){var imports={a:wasmImports};return imports}async function createWasm(){function receiveInstance(instance,module){wasmExports=instance.exports;wasmExports=applySignatureConversions(wasmExports);assignWasmExports(wasmExports);updateMemoryViews();return wasmExports}function receiveInstantiationResult(result){return receiveInstance(result["instance"])}var info=getWasmImports();if(Module["instantiateWasm"]){return new Promise((resolve,reject)=>{Module["instantiateWasm"](info,(inst,mod)=>{resolve(receiveInstance(inst,mod))})})}wasmBinaryFile??=findWasmBinary();var result=await instantiateAsync(wasmBinary,wasmBinaryFile,info);var exports=receiveInstantiationResult(result);return exports}class ExitStatus{name="ExitStatus";constructor(status){this.message=`Program terminated with exit(${status})`;this.status=status}}var callRuntimeCallbacks=callbacks=>{while(callbacks.length>0){callbacks.shift()(Module)}};var onPostRuns=[];var addOnPostRun=cb=>onPostRuns.push(cb);var onPreRuns=[];var addOnPreRun=cb=>onPreRuns.push(cb);var noExitRuntime=true;var stackRestore=val=>__emscripten_stack_restore(val);var stackSave=()=>_emscripten_stack_get_current();var exceptionCaught=[];var uncaughtExceptionCount=0;var INT53_MAX=9007199254740992;var INT53_MIN=-9007199254740992;var bigintToI53Checked=num=>num<INT53_MIN||num>INT53_MAX?NaN:Number(num);function ___cxa_begin_catch(ptr){ptr>>>=0;var info=new ExceptionInfo(ptr);if(!info.get_caught()){info.set_caught(true);uncaughtExceptionCount--}info.set_rethrown(false);exceptionCaught.push(info);return ___cxa_get_exception_ptr(ptr)}var exceptionLast=0;var ___cxa_end_catch=()=>{_setThrew(0,0);var info=exceptionCaught.pop();___cxa_decrement_exception_refcount(info.excPtr);exceptionLast=0};class ExceptionInfo{constructor(excPtr){this.excPtr=excPtr;this.ptr=excPtr-24}set_type(type){HEAPU32[this.ptr+4>>>2>>>0]=type}get_type(){return HEAPU32[this.ptr+4>>>2>>>0]}set_destructor(destructor){HEAPU32[this.ptr+8>>>2>>>0]=destructor}get_destructor(){return HEAPU32[this.ptr+8>>>2>>>0]}set_caught(caught){caught=caught?1:0;HEAP8[this.ptr+12>>>0]=caught}get_caught(){return HEAP8[this.ptr+12>>>0]!=0}set_rethrown(rethrown){rethrown=rethrown?1:0;HEAP8[this.ptr+13>>>0]=rethrown}get_rethrown(){return HEAP8[this.ptr+13>>>0]!=0}init(type,destructor){this.set_adjusted_ptr(0);this.set_type(type);this.set_destructor(destructor)}set_adjusted_ptr(adjustedPtr){HEAPU32[this.ptr+16>>>2>>>0]=adjustedPtr}get_adjusted_ptr(){return HEAPU32[this.ptr+16>>>2>>>0]}}var setTempRet0=val=>__emscripten_tempret_set(val);var findMatchingCatch=args=>{var thrown=exceptionLast;if(!thrown){setTempRet0(0);return 0}var info=new ExceptionInfo(thrown);info.set_adjusted_ptr(thrown);var thrownType=info.get_type();if(!thrownType){setTempRet0(0);return thrown}for(var caughtType of args){if(caughtType===0||caughtType===thrownType){break}var adjusted_ptr_addr=info.ptr+16;if(___cxa_can_catch(caughtType,thrownType,adjusted_ptr_addr)){setTempRet0(caughtType);return thrown}}setTempRet0(thrownType);return thrown};function ___cxa_find_matching_catch_2(){return findMatchingCatch([])}function ___cxa_find_matching_catch_3(arg0){arg0>>>=0;return findMatchingCatch([arg0])}function ___cxa_find_matching_catch_4(arg0,arg1){arg0>>>=0;arg1>>>=0;return findMatchingCatch([arg0,arg1])}var ___cxa_rethrow=()=>{var info=exceptionCaught.pop();if(!info){abort("no exception to throw")}var ptr=info.excPtr;if(!info.get_rethrown()){exceptionCaught.push(info);info.set_rethrown(true);info.set_caught(false);uncaughtExceptionCount++}___cxa_increment_exception_refcount(ptr);exceptionLast=ptr;throw exceptionLast};function ___cxa_throw(ptr,type,destructor){ptr>>>=0;type>>>=0;destructor>>>=0;var info=new ExceptionInfo(ptr);info.init(type,destructor);___cxa_increment_exception_refcount(ptr);exceptionLast=ptr;uncaughtExceptionCount++;throw exceptionLast}var ___cxa_uncaught_exceptions=()=>uncaughtExceptionCount;function ___resumeException(ptr){ptr>>>=0;if(!exceptionLast){exceptionLast=ptr}throw exceptionLast}function ___syscall_chmod(path,mode){path>>>=0}function ___syscall_faccessat(dirfd,path,amode,flags){path>>>=0}var ___syscall_fchmod=(fd,mode)=>{};var ___syscall_fchown32=(fd,owner,group)=>{};var UTF8Decoder=globalThis.TextDecoder&&new TextDecoder;var findStringEnd=(heapOrArray,idx,maxBytesToRead,ignoreNul)=>{var maxIdx=idx+maxBytesToRead;if(ignoreNul)return maxIdx;while(heapOrArray[idx]&&!(idx>=maxIdx))++idx;return idx};var UTF8ArrayToString=(heapOrArray,idx=0,maxBytesToRead,ignoreNul)=>{idx>>>=0;var endPtr=findStringEnd(heapOrArray,idx,maxBytesToRead,ignoreNul);if(endPtr-idx>16&&heapOrArray.buffer&&UTF8Decoder){return UTF8Decoder.decode(heapOrArray.subarray(idx,endPtr))}var str="";while(idx<endPtr){var u0=heapOrArray[idx++];if(!(u0&128)){str+=String.fromCharCode(u0);continue}var u1=heapOrArray[idx++]&63;if((u0&224)==192){str+=String.fromCharCode((u0&31)<<6|u1);continue}var u2=heapOrArray[idx++]&63;if((u0&240)==224){u0=(u0&15)<<12|u1<<6|u2}else{u0=(u0&7)<<18|u1<<12|u2<<6|heapOrArray[idx++]&63}if(u0<65536){str+=String.fromCharCode(u0)}else{var ch=u0-65536;str+=String.fromCharCode(55296|ch>>10,56320|ch&1023)}}return str};var UTF8ToString=(ptr,maxBytesToRead,ignoreNul)=>{ptr>>>=0;return ptr?UTF8ArrayToString(HEAPU8,ptr,maxBytesToRead,ignoreNul):""};var SYSCALLS={varargs:undefined,getStr(ptr){var ret=UTF8ToString(ptr);return ret}};function ___syscall_fcntl64(fd,cmd,varargs){varargs>>>=0;SYSCALLS.varargs=varargs;return 0}function ___syscall_fstat64(fd,buf){buf>>>=0}function ___syscall_ftruncate64(fd,length){length=bigintToI53Checked(length)}function ___syscall_getcwd(buf,size){buf>>>=0;size>>>=0}function ___syscall_lstat64(path,buf){path>>>=0;buf>>>=0}function ___syscall_mkdirat(dirfd,path,mode){path>>>=0}function ___syscall_newfstatat(dirfd,path,buf,flags){path>>>=0;buf>>>=0}function ___syscall_openat(dirfd,path,flags,varargs){path>>>=0;varargs>>>=0;SYSCALLS.varargs=varargs}function ___syscall_readlinkat(dirfd,path,buf,bufsize){path>>>=0;buf>>>=0;bufsize>>>=0}function ___syscall_rmdir(path){path>>>=0}function ___syscall_stat64(path,buf){path>>>=0;buf>>>=0}function ___syscall_unlinkat(dirfd,path,flags){path>>>=0}function ___syscall_utimensat(dirfd,path,times,flags){path>>>=0;times>>>=0}var __abort_js=()=>abort("");var isLeapYear=year=>year%4===0&&(year%100!==0||year%400===0);var MONTH_DAYS_LEAP_CUMULATIVE=[0,31,60,91,121,152,182,213,244,274,305,335];var MONTH_DAYS_REGULAR_CUMULATIVE=[0,31,59,90,120,151,181,212,243,273,304,334];var ydayFromDate=date=>{var leap=isLeapYear(date.getFullYear());var monthDaysCumulative=leap?MONTH_DAYS_LEAP_CUMULATIVE:MONTH_DAYS_REGULAR_CUMULATIVE;var yday=monthDaysCumulative[date.getMonth()]+date.getDate()-1;return yday};function __localtime_js(time,tmPtr){time=bigintToI53Checked(time);tmPtr>>>=0;var date=new Date(time*1e3);HEAP32[tmPtr>>>2>>>0]=date.getSeconds();HEAP32[tmPtr+4>>>2>>>0]=date.getMinutes();HEAP32[tmPtr+8>>>2>>>0]=date.getHours();HEAP32[tmPtr+12>>>2>>>0]=date.getDate();HEAP32[tmPtr+16>>>2>>>0]=date.getMonth();HEAP32[tmPtr+20>>>2>>>0]=date.getFullYear()-1900;HEAP32[tmPtr+24>>>2>>>0]=date.getDay();var yday=ydayFromDate(date)|0;HEAP32[tmPtr+28>>>2>>>0]=yday;HEAP32[tmPtr+36>>>2>>>0]=-(date.getTimezoneOffset()*60);var start=new Date(date.getFullYear(),0,1);var summerOffset=new Date(date.getFullYear(),6,1).getTimezoneOffset();var winterOffset=start.getTimezoneOffset();var dst=(summerOffset!=winterOffset&&date.getTimezoneOffset()==Math.min(winterOffset,summerOffset))|0;HEAP32[tmPtr+32>>>2>>>0]=dst}var stringToUTF8Array=(str,heap,outIdx,maxBytesToWrite)=>{outIdx>>>=0;if(!(maxBytesToWrite>0))return 0;var startIdx=outIdx;var endIdx=outIdx+maxBytesToWrite-1;for(var i=0;i<str.length;++i){var u=str.codePointAt(i);if(u<=127){if(outIdx>=endIdx)break;heap[outIdx++>>>0]=u}else if(u<=2047){if(outIdx+1>=endIdx)break;heap[outIdx++>>>0]=192|u>>6;heap[outIdx++>>>0]=128|u&63}else if(u<=65535){if(outIdx+2>=endIdx)break;heap[outIdx++>>>0]=224|u>>12;heap[outIdx++>>>0]=128|u>>6&63;heap[outIdx++>>>0]=128|u&63}else{if(outIdx+3>=endIdx)break;heap[outIdx++>>>0]=240|u>>18;heap[outIdx++>>>0]=128|u>>12&63;heap[outIdx++>>>0]=128|u>>6&63;heap[outIdx++>>>0]=128|u&63;i++}}heap[outIdx>>>0]=0;return outIdx-startIdx};var stringToUTF8=(str,outPtr,maxBytesToWrite)=>stringToUTF8Array(str,HEAPU8,outPtr,maxBytesToWrite);var __tzset_js=function(timezone,daylight,std_name,dst_name){timezone>>>=0;daylight>>>=0;std_name>>>=0;dst_name>>>=0;var currentYear=(new Date).getFullYear();var winter=new Date(currentYear,0,1);var summer=new Date(currentYear,6,1);var winterOffset=winter.getTimezoneOffset();var summerOffset=summer.getTimezoneOffset();var stdTimezoneOffset=Math.max(winterOffset,summerOffset);HEAPU32[timezone>>>2>>>0]=stdTimezoneOffset*60;HEAP32[daylight>>>2>>>0]=Number(winterOffset!=summerOffset);var extractZone=timezoneOffset=>{var sign=timezoneOffset>=0?"-":"+";var absOffset=Math.abs(timezoneOffset);var hours=String(Math.floor(absOffset/60)).padStart(2,"0");var minutes=String(absOffset%60).padStart(2,"0");return`UTC${sign}${hours}${minutes}`};var winterName=extractZone(winterOffset);var summerName=extractZone(summerOffset);if(summerOffset<winterOffset){stringToUTF8(winterName,std_name,17);stringToUTF8(summerName,dst_name,17)}else{stringToUTF8(winterName,dst_name,17);stringToUTF8(summerName,std_name,17)}};var _emscripten_get_now=()=>performance.now();var _emscripten_date_now=()=>Date.now();var nowIsMonotonic=1;var checkWasiClock=clock_id=>clock_id>=0&&clock_id<=3;function _clock_time_get(clk_id,ignored_precision,ptime){ignored_precision=bigintToI53Checked(ignored_precision);ptime>>>=0;if(!checkWasiClock(clk_id)){return 28}var now;if(clk_id===0){now=_emscripten_date_now()}else if(nowIsMonotonic){now=_emscripten_get_now()}else{return 52}var nsec=Math.round(now*1e3*1e3);HEAP64[ptime>>>3>>>0]=BigInt(nsec);return 0}var getHeapMax=()=>4294901760;var alignMemory=(size,alignment)=>Math.ceil(size/alignment)*alignment;var growMemory=size=>{var oldHeapSize=wasmMemory.buffer.byteLength;var pages=(size-oldHeapSize+65535)/65536|0;try{wasmMemory.grow(pages);updateMemoryViews();return 1}catch(e){}};function _emscripten_resize_heap(requestedSize){requestedSize>>>=0;var oldSize=HEAPU8.length;var maxHeapSize=getHeapMax();if(requestedSize>maxHeapSize){return false}for(var cutDown=1;cutDown<=4;cutDown*=2){var overGrownHeapSize=oldSize*(1+.2/cutDown);overGrownHeapSize=Math.min(overGrownHeapSize,requestedSize+100663296);var newSize=Math.min(maxHeapSize,alignMemory(Math.max(requestedSize,overGrownHeapSize),65536));var replacement=growMemory(newSize);if(replacement){return true}}return false}var ENV={};var getExecutableName=()=>thisProgram||"./this.program";var getEnvStrings=()=>{if(!getEnvStrings.strings){var lang=(globalThis.navigator?.language??"C").replace("-","_")+".UTF-8";var env={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:lang,_:getExecutableName()};for(var x in ENV){if(ENV[x]===undefined)delete env[x];else env[x]=ENV[x]}var strings=[];for(var x in env){strings.push(`${x}=${env[x]}`)}getEnvStrings.strings=strings}return getEnvStrings.strings};function _environ_get(__environ,environ_buf){__environ>>>=0;environ_buf>>>=0;var bufSize=0;var envp=0;for(var string of getEnvStrings()){var ptr=environ_buf+bufSize;HEAPU32[__environ+envp>>>2>>>0]=ptr;bufSize+=stringToUTF8(string,ptr,Infinity)+1;envp+=4}return 0}var lengthBytesUTF8=str=>{var len=0;for(var i=0;i<str.length;++i){var c=str.charCodeAt(i);if(c<=127){len++}else if(c<=2047){len+=2}else if(c>=55296&&c<=57343){len+=4;++i}else{len+=3}}return len};function _environ_sizes_get(penviron_count,penviron_buf_size){penviron_count>>>=0;penviron_buf_size>>>=0;var strings=getEnvStrings();HEAPU32[penviron_count>>>2>>>0]=strings.length;var bufSize=0;for(var string of strings){bufSize+=lengthBytesUTF8(string)+1}HEAPU32[penviron_buf_size>>>2>>>0]=bufSize;return 0}var _fd_close=fd=>52;function _fd_fdstat_get(fd,pbuf){pbuf>>>=0;var rightsBase=0;var rightsInheriting=0;var flags=0;{var type=2;if(fd==0){rightsBase=2}else if(fd==1||fd==2){rightsBase=64}flags=1}HEAP8[pbuf>>>0]=type;HEAP16[pbuf+2>>>1>>>0]=flags;HEAP64[pbuf+8>>>3>>>0]=BigInt(rightsBase);HEAP64[pbuf+16>>>3>>>0]=BigInt(rightsInheriting);return 0}function _fd_read(fd,iov,iovcnt,pnum){iov>>>=0;iovcnt>>>=0;pnum>>>=0;return 52}function _fd_seek(fd,offset,whence,newOffset){offset=bigintToI53Checked(offset);newOffset>>>=0;return 70}var _fd_sync=fd=>52;var printCharBuffers=[null,[],[]];var printChar=(stream,curr)=>{var buffer=printCharBuffers[stream];if(curr===0||curr===10){(stream===1?out:err)(UTF8ArrayToString(buffer));buffer.length=0}else{buffer.push(curr)}};function _fd_write(fd,iov,iovcnt,pnum){iov>>>=0;iovcnt>>>=0;pnum>>>=0;var num=0;for(var i=0;i<iovcnt;i++){var ptr=HEAPU32[iov>>>2>>>0];var len=HEAPU32[iov+4>>>2>>>0];iov+=8;for(var j=0;j<len;j++){printChar(fd,HEAPU8[ptr+j>>>0])}num+=len}HEAPU32[pnum>>>2>>>0]=num;return 0}function _llvm_eh_typeid_for(type){type>>>=0;return type}var getCFunc=ident=>{var func=Module["_"+ident];return func};var writeArrayToMemory=(array,buffer)=>{HEAP8.set(array,buffer>>>0)};var stackAlloc=sz=>__emscripten_stack_alloc(sz);var stringToUTF8OnStack=str=>{var size=lengthBytesUTF8(str)+1;var ret=stackAlloc(size);stringToUTF8(str,ret,size);return ret};var ccall=(ident,returnType,argTypes,args,opts)=>{var toC={string:str=>{var ret=0;if(str!==null&&str!==undefined&&str!==0){ret=stringToUTF8OnStack(str)}return ret},array:arr=>{var ret=stackAlloc(arr.length);writeArrayToMemory(arr,ret);return ret}};function convertReturnValue(ret){if(returnType==="string"){return UTF8ToString(ret)}if(returnType==="pointer")return ret>>>0;if(returnType==="boolean")return Boolean(ret);return ret}var func=getCFunc(ident);var cArgs=[];var stack=0;if(args){for(var i=0;i<args.length;i++){var converter=toC[argTypes[i]];if(converter){if(stack===0)stack=stackSave();cArgs[i]=converter(args[i])}else{cArgs[i]=args[i]}}}var ret=func(...cArgs);function onDone(ret){if(stack!==0)stackRestore(stack);return convertReturnValue(ret)}ret=onDone(ret);return ret};var cwrap=(ident,returnType,argTypes,opts)=>{var numericArgs=!argTypes||argTypes.every(type=>type==="number"||type==="boolean");var numericRet=returnType!=="string";if(numericRet&&numericArgs&&!opts){return getCFunc(ident)}return(...args)=>ccall(ident,returnType,argTypes,args,opts)};{if(Module["noExitRuntime"])noExitRuntime=Module["noExitRuntime"];if(Module["print"])out=Module["print"];if(Module["printErr"])err=Module["printErr"];if(Module["wasmBinary"])wasmBinary=Module["wasmBinary"];if(Module["arguments"])arguments_=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].shift()()}}}Module["ccall"]=ccall;Module["cwrap"]=cwrap;Module["UTF8ToString"]=UTF8ToString;Module["stringToUTF8"]=stringToUTF8;Module["lengthBytesUTF8"]=lengthBytesUTF8;var _free,_malloc,_flatsql_create_db,_flatsql_destroy_db,_flatsql_register_file_id,_flatsql_enable_demo_extractors,_flatsql_ingest,_flatsql_ingest_one,_flatsql_register_source,_flatsql_create_unified_views,_flatsql_ingest_with_source,_flatsql_ingest_one_with_source,_flatsql_query,_flatsql_query_params,_flatsql_query_many,_flatsql_batch_result_count,_flatsql_select_batch_result,_flatsql_get_error,_flatsql_build_query_cache_key,_flatsql_build_response_artifact_cache_key,_flatsql_register_query_template,_flatsql_query_template,_flatsql_clear_query_cache,_flatsql_configure_query_cache,_flatsql_query_cache_hits,_flatsql_query_cache_misses,_flatsql_query_cache_size,_flatsql_query_cache_generation,_flatsql_query_cache_max_entries,_flatsql_query_cache_max_rows,_flatsql_result_column_count,_flatsql_result_row_count,_flatsql_result_column_name,_flatsql_result_cell_type,_flatsql_result_cell_number,_flatsql_result_cell_string,_flatsql_result_cell_blob,_flatsql_result_cell_blob_size,_flatsql_export_data,_flatsql_query_raw_flatbuffer_stream,_flatsql_query_sandboxed,_flatsql_response_artifact_data,_flatsql_response_artifact_size,_flatsql_response_artifact_cache_hit,_flatsql_configure_raw_stream_cache,_flatsql_raw_stream_cache_hits,_flatsql_raw_stream_cache_misses,_flatsql_raw_stream_cache_size,_flatsql_raw_stream_cache_total_bytes,_flatsql_response_artifact_row_count,_flatsql_response_artifact_column_count,_flatsql_export_size,_flatsql_load_and_rebuild,_flatsql_reserve_storage,_flatsql_load_from_db,_flatsql_create_test_user,_flatsql_test_buffer_size,_flatsql_create_test_post,_flatsql_create_test_mpe,_flatsql_create_test_telemetry,_flatsql_create_test_publish_event,_flatsql_get_stats_count,_flatsql_get_stat_table_name,_flatsql_get_stat_file_id,_flatsql_get_stat_record_count,_flatsql_reset_ingest_profile,_flatsql_get_ingest_profile_record_count,_flatsql_get_ingest_profile_byte_count,_flatsql_get_ingest_profile_decode_nanos,_flatsql_get_ingest_profile_append_nanos,_flatsql_get_ingest_profile_index_nanos,_flatsql_mark_deleted,_flatsql_get_deleted_count,_flatsql_clear_tombstones,_flatsql_get_sources_count,_flatsql_get_source_name,_flatsql_get_flatbuffer_by_id,_flatsql_get_flatbuffer_by_email,_flatsql_get_flatbuffer_by_index,_flatsql_get_raw_flatbuffer_size,_flatsql_get_raw_flatbuffer_sequence,_flatsql_get_storage_buffer,_flatsql_get_storage_size,_flatsql_set_encryption_key,_flatsql_is_encrypted,_flatsql_encrypt_buffer,_flatsql_decrypt_buffer,_flatsql_set_hmac_verification,_flatsql_is_hmac_enabled,_flatsql_compute_hmac,_flatsql_verify_hmac,_setThrew,__emscripten_tempret_set,__emscripten_stack_restore,__emscripten_stack_alloc,_emscripten_stack_get_current,___cxa_decrement_exception_refcount,___cxa_increment_exception_refcount,___cxa_can_catch,___cxa_get_exception_ptr,dynCall_v,dynCall_ii,dynCall_iii,dynCall_viiiiii,dynCall_vii,dynCall_viii,dynCall_iiii,dynCall_iiiiii,dynCall_vi,dynCall_viiii,dynCall_jii,dynCall_viiiii,dynCall_iiiiiii,dynCall_iiiii,dynCall_iiij,dynCall_iiid,dynCall_viijij,dynCall_viiijj,dynCall_jiiiii,dynCall_viiiiiiiiii,dynCall_vij,dynCall_iiji,dynCall_iijiii,dynCall_viij,dynCall_iid,dynCall_i,dynCall_dii,dynCall_di,dynCall_viidi,dynCall_vid,dynCall_vidd,dynCall_dd,dynCall_ddd,dynCall_jiiii,dynCall_viiiiiiii,dynCall_iiiddddddddi,dynCall_iijj,dynCall_iiiij,dynCall_iij,dynCall_iijii,dynCall_iidiiii,dynCall_j,dynCall_iiiiid,dynCall_viijii,dynCall_iiiiiiii,dynCall_iiiiiiiiiii,dynCall_iiiiiiiiiiiii,dynCall_fiii,dynCall_diii,dynCall_viiiiiii,dynCall_iiiiiiiiiiii,dynCall_viiiiiiiiiiiiiii,dynCall_iiiiiiiii,dynCall_iiiiij,dynCall_iiiiijj,dynCall_iiiiiijj,memory,__indirect_function_table,wasmMemory,wasmTable;function assignWasmExports(wasmExports){_free=Module["_free"]=wasmExports["Ga"];_malloc=Module["_malloc"]=wasmExports["Ha"];_flatsql_create_db=Module["_flatsql_create_db"]=wasmExports["Ia"];_flatsql_destroy_db=Module["_flatsql_destroy_db"]=wasmExports["Ja"];_flatsql_register_file_id=Module["_flatsql_register_file_id"]=wasmExports["Ka"];_flatsql_enable_demo_extractors=Module["_flatsql_enable_demo_extractors"]=wasmExports["La"];_flatsql_ingest=Module["_flatsql_ingest"]=wasmExports["Ma"];_flatsql_ingest_one=Module["_flatsql_ingest_one"]=wasmExports["Na"];_flatsql_register_source=Module["_flatsql_register_source"]=wasmExports["Oa"];_flatsql_create_unified_views=Module["_flatsql_create_unified_views"]=wasmExports["Pa"];_flatsql_ingest_with_source=Module["_flatsql_ingest_with_source"]=wasmExports["Qa"];_flatsql_ingest_one_with_source=Module["_flatsql_ingest_one_with_source"]=wasmExports["Ra"];_flatsql_query=Module["_flatsql_query"]=wasmExports["Sa"];_flatsql_query_params=Module["_flatsql_query_params"]=wasmExports["Ta"];_flatsql_query_many=Module["_flatsql_query_many"]=wasmExports["Ua"];_flatsql_batch_result_count=Module["_flatsql_batch_result_count"]=wasmExports["Va"];_flatsql_select_batch_result=Module["_flatsql_select_batch_result"]=wasmExports["Wa"];_flatsql_get_error=Module["_flatsql_get_error"]=wasmExports["Xa"];_flatsql_build_query_cache_key=Module["_flatsql_build_query_cache_key"]=wasmExports["Ya"];_flatsql_build_response_artifact_cache_key=Module["_flatsql_build_response_artifact_cache_key"]=wasmExports["Za"];_flatsql_register_query_template=Module["_flatsql_register_query_template"]=wasmExports["_a"];_flatsql_query_template=Module["_flatsql_query_template"]=wasmExports["$a"];_flatsql_clear_query_cache=Module["_flatsql_clear_query_cache"]=wasmExports["ab"];_flatsql_configure_query_cache=Module["_flatsql_configure_query_cache"]=wasmExports["bb"];_flatsql_query_cache_hits=Module["_flatsql_query_cache_hits"]=wasmExports["cb"];_flatsql_query_cache_misses=Module["_flatsql_query_cache_misses"]=wasmExports["db"];_flatsql_query_cache_size=Module["_flatsql_query_cache_size"]=wasmExports["eb"];_flatsql_query_cache_generation=Module["_flatsql_query_cache_generation"]=wasmExports["fb"];_flatsql_query_cache_max_entries=Module["_flatsql_query_cache_max_entries"]=wasmExports["gb"];_flatsql_query_cache_max_rows=Module["_flatsql_query_cache_max_rows"]=wasmExports["hb"];_flatsql_result_column_count=Module["_flatsql_result_column_count"]=wasmExports["ib"];_flatsql_result_row_count=Module["_flatsql_result_row_count"]=wasmExports["jb"];_flatsql_result_column_name=Module["_flatsql_result_column_name"]=wasmExports["kb"];_flatsql_result_cell_type=Module["_flatsql_result_cell_type"]=wasmExports["lb"];_flatsql_result_cell_number=Module["_flatsql_result_cell_number"]=wasmExports["mb"];_flatsql_result_cell_string=Module["_flatsql_result_cell_string"]=wasmExports["nb"];_flatsql_result_cell_blob=Module["_flatsql_result_cell_blob"]=wasmExports["ob"];_flatsql_result_cell_blob_size=Module["_flatsql_result_cell_blob_size"]=wasmExports["pb"];_flatsql_export_data=Module["_flatsql_export_data"]=wasmExports["qb"];_flatsql_query_raw_flatbuffer_stream=Module["_flatsql_query_raw_flatbuffer_stream"]=wasmExports["rb"];_flatsql_query_sandboxed=Module["_flatsql_query_sandboxed"]=wasmExports["sb"];_flatsql_response_artifact_data=Module["_flatsql_response_artifact_data"]=wasmExports["tb"];_flatsql_response_artifact_size=Module["_flatsql_response_artifact_size"]=wasmExports["ub"];_flatsql_response_artifact_cache_hit=Module["_flatsql_response_artifact_cache_hit"]=wasmExports["vb"];_flatsql_configure_raw_stream_cache=Module["_flatsql_configure_raw_stream_cache"]=wasmExports["wb"];_flatsql_raw_stream_cache_hits=Module["_flatsql_raw_stream_cache_hits"]=wasmExports["xb"];_flatsql_raw_stream_cache_misses=Module["_flatsql_raw_stream_cache_misses"]=wasmExports["yb"];_flatsql_raw_stream_cache_size=Module["_flatsql_raw_stream_cache_size"]=wasmExports["zb"];_flatsql_raw_stream_cache_total_bytes=Module["_flatsql_raw_stream_cache_total_bytes"]=wasmExports["Ab"];_flatsql_response_artifact_row_count=Module["_flatsql_response_artifact_row_count"]=wasmExports["Bb"];_flatsql_response_artifact_column_count=Module["_flatsql_response_artifact_column_count"]=wasmExports["Cb"];_flatsql_export_size=Module["_flatsql_export_size"]=wasmExports["Db"];_flatsql_load_and_rebuild=Module["_flatsql_load_and_rebuild"]=wasmExports["Eb"];_flatsql_reserve_storage=Module["_flatsql_reserve_storage"]=wasmExports["Fb"];_flatsql_load_from_db=Module["_flatsql_load_from_db"]=wasmExports["Gb"];_flatsql_create_test_user=Module["_flatsql_create_test_user"]=wasmExports["Hb"];_flatsql_test_buffer_size=Module["_flatsql_test_buffer_size"]=wasmExports["Ib"];_flatsql_create_test_post=Module["_flatsql_create_test_post"]=wasmExports["Jb"];_flatsql_create_test_mpe=Module["_flatsql_create_test_mpe"]=wasmExports["Kb"];_flatsql_create_test_telemetry=Module["_flatsql_create_test_telemetry"]=wasmExports["Lb"];_flatsql_create_test_publish_event=Module["_flatsql_create_test_publish_event"]=wasmExports["Mb"];_flatsql_get_stats_count=Module["_flatsql_get_stats_count"]=wasmExports["Nb"];_flatsql_get_stat_table_name=Module["_flatsql_get_stat_table_name"]=wasmExports["Ob"];_flatsql_get_stat_file_id=Module["_flatsql_get_stat_file_id"]=wasmExports["Pb"];_flatsql_get_stat_record_count=Module["_flatsql_get_stat_record_count"]=wasmExports["Qb"];_flatsql_reset_ingest_profile=Module["_flatsql_reset_ingest_profile"]=wasmExports["Rb"];_flatsql_get_ingest_profile_record_count=Module["_flatsql_get_ingest_profile_record_count"]=wasmExports["Sb"];_flatsql_get_ingest_profile_byte_count=Module["_flatsql_get_ingest_profile_byte_count"]=wasmExports["Tb"];_flatsql_get_ingest_profile_decode_nanos=Module["_flatsql_get_ingest_profile_decode_nanos"]=wasmExports["Ub"];_flatsql_get_ingest_profile_append_nanos=Module["_flatsql_get_ingest_profile_append_nanos"]=wasmExports["Vb"];_flatsql_get_ingest_profile_index_nanos=Module["_flatsql_get_ingest_profile_index_nanos"]=wasmExports["Wb"];_flatsql_mark_deleted=Module["_flatsql_mark_deleted"]=wasmExports["Xb"];_flatsql_get_deleted_count=Module["_flatsql_get_deleted_count"]=wasmExports["Yb"];_flatsql_clear_tombstones=Module["_flatsql_clear_tombstones"]=wasmExports["Zb"];_flatsql_get_sources_count=Module["_flatsql_get_sources_count"]=wasmExports["_b"];_flatsql_get_source_name=Module["_flatsql_get_source_name"]=wasmExports["$b"];_flatsql_get_flatbuffer_by_id=Module["_flatsql_get_flatbuffer_by_id"]=wasmExports["ac"];_flatsql_get_flatbuffer_by_email=Module["_flatsql_get_flatbuffer_by_email"]=wasmExports["bc"];_flatsql_get_flatbuffer_by_index=Module["_flatsql_get_flatbuffer_by_index"]=wasmExports["cc"];_flatsql_get_raw_flatbuffer_size=Module["_flatsql_get_raw_flatbuffer_size"]=wasmExports["dc"];_flatsql_get_raw_flatbuffer_sequence=Module["_flatsql_get_raw_flatbuffer_sequence"]=wasmExports["ec"];_flatsql_get_storage_buffer=Module["_flatsql_get_storage_buffer"]=wasmExports["fc"];_flatsql_get_storage_size=Module["_flatsql_get_storage_size"]=wasmExports["gc"];_flatsql_set_encryption_key=Module["_flatsql_set_encryption_key"]=wasmExports["hc"];_flatsql_is_encrypted=Module["_flatsql_is_encrypted"]=wasmExports["ic"];_flatsql_encrypt_buffer=Module["_flatsql_encrypt_buffer"]=wasmExports["jc"];_flatsql_decrypt_buffer=Module["_flatsql_decrypt_buffer"]=wasmExports["kc"];_flatsql_set_hmac_verification=Module["_flatsql_set_hmac_verification"]=wasmExports["lc"];_flatsql_is_hmac_enabled=Module["_flatsql_is_hmac_enabled"]=wasmExports["mc"];_flatsql_compute_hmac=Module["_flatsql_compute_hmac"]=wasmExports["nc"];_flatsql_verify_hmac=Module["_flatsql_verify_hmac"]=wasmExports["oc"];_setThrew=wasmExports["pc"];__emscripten_tempret_set=wasmExports["qc"];__emscripten_stack_restore=wasmExports["rc"];__emscripten_stack_alloc=wasmExports["sc"];_emscripten_stack_get_current=wasmExports["tc"];___cxa_decrement_exception_refcount=wasmExports["uc"];___cxa_increment_exception_refcount=wasmExports["vc"];___cxa_can_catch=wasmExports["wc"];___cxa_get_exception_ptr=wasmExports["xc"];dynCall_v=wasmExports["yc"];dynCall_ii=wasmExports["zc"];dynCall_iii=wasmExports["Ac"];dynCall_viiiiii=wasmExports["Bc"];dynCall_vii=wasmExports["Cc"];dynCall_viii=wasmExports["Dc"];dynCall_iiii=wasmExports["Ec"];dynCall_iiiiii=wasmExports["Fc"];dynCall_vi=wasmExports["Gc"];dynCall_viiii=wasmExports["Hc"];dynCall_jii=wasmExports["Ic"];dynCall_viiiii=wasmExports["Jc"];dynCall_iiiiiii=wasmExports["Kc"];dynCall_iiiii=wasmExports["Lc"];dynCall_iiij=wasmExports["Mc"];dynCall_iiid=wasmExports["Nc"];dynCall_viijij=wasmExports["Oc"];dynCall_viiijj=wasmExports["Pc"];dynCall_jiiiii=wasmExports["Qc"];dynCall_viiiiiiiiii=wasmExports["Rc"];dynCall_vij=wasmExports["Sc"];dynCall_iiji=wasmExports["Tc"];dynCall_iijiii=wasmExports["Uc"];dynCall_viij=wasmExports["Vc"];dynCall_iid=wasmExports["Wc"];dynCall_i=wasmExports["Xc"];dynCall_dii=wasmExports["Yc"];dynCall_di=wasmExports["Zc"];dynCall_viidi=wasmExports["_c"];dynCall_vid=wasmExports["$c"];dynCall_vidd=wasmExports["dynCall_vidd"];dynCall_dd=wasmExports["dynCall_dd"];dynCall_ddd=wasmExports["dynCall_ddd"];dynCall_jiiii=wasmExports["ad"];dynCall_viiiiiiii=wasmExports["bd"];dynCall_iiiddddddddi=wasmExports["cd"];dynCall_iijj=wasmExports["dynCall_iijj"];dynCall_iiiij=wasmExports["dynCall_iiiij"];dynCall_iij=wasmExports["dynCall_iij"];dynCall_iijii=wasmExports["dynCall_iijii"];dynCall_iidiiii=wasmExports["dynCall_iidiiii"];dynCall_j=wasmExports["dd"];dynCall_iiiiid=wasmExports["ed"];dynCall_viijii=wasmExports["dynCall_viijii"];dynCall_iiiiiiii=wasmExports["fd"];dynCall_iiiiiiiiiii=wasmExports["dynCall_iiiiiiiiiii"];dynCall_iiiiiiiiiiiii=wasmExports["dynCall_iiiiiiiiiiiii"];dynCall_fiii=wasmExports["gd"];dynCall_diii=wasmExports["hd"];dynCall_viiiiiii=wasmExports["id"];dynCall_iiiiiiiiiiii=wasmExports["jd"];dynCall_viiiiiiiiiiiiiii=wasmExports["kd"];dynCall_iiiiiiiii=wasmExports["dynCall_iiiiiiiii"];dynCall_iiiiij=wasmExports["dynCall_iiiiij"];dynCall_iiiiijj=wasmExports["dynCall_iiiiijj"];dynCall_iiiiiijj=wasmExports["dynCall_iiiiiijj"];memory=wasmMemory=wasmExports["Da"];__indirect_function_table=wasmTable=wasmExports["Fa"]}var wasmImports={l:___cxa_begin_catch,q:___cxa_end_catch,a:___cxa_find_matching_catch_2,e:___cxa_find_matching_catch_3,H:___cxa_find_matching_catch_4,R:___cxa_rethrow,o:___cxa_throw,X:___cxa_uncaught_exceptions,d:___resumeException,va:___syscall_chmod,xa:___syscall_faccessat,wa:___syscall_fchmod,ua:___syscall_fchown32,x:___syscall_fcntl64,ta:___syscall_fstat64,oa:___syscall_ftruncate64,na:___syscall_getcwd,qa:___syscall_lstat64,ja:___syscall_mkdirat,ra:___syscall_newfstatat,fa:___syscall_openat,da:___syscall_readlinkat,ca:___syscall_rmdir,sa:___syscall_stat64,aa:___syscall_unlinkat,$:___syscall_utimensat,V:__abort_js,ha:__localtime_js,ia:__tzset_js,ga:_clock_time_get,O:_emscripten_date_now,N:_emscripten_get_now,Z:_emscripten_resize_heap,la:_environ_get,ma:_environ_sizes_get,P:_fd_close,_:_fd_fdstat_get,ea:_fd_read,ka:_fd_seek,pa:_fd_sync,ba:_fd_write,w:invoke_di,F:invoke_dii,J:invoke_diii,L:invoke_fiii,t:invoke_i,c:invoke_ii,K:invoke_iid,f:invoke_iii,G:invoke_iiid,ya:invoke_iiiddddddddi,h:invoke_iiii,m:invoke_iiiii,W:invoke_iiiiid,n:invoke_iiiiii,s:invoke_iiiiiii,M:invoke_iiiiiiii,D:invoke_iiiiiiiiiiii,Ca:invoke_iiij,z:invoke_iiji,Aa:invoke_iijiii,Y:invoke_j,I:invoke_jii,B:invoke_jiiii,S:invoke_jiiiii,g:invoke_v,k:invoke_vi,E:invoke_vid,b:invoke_vii,Q:invoke_viidi,i:invoke_viii,j:invoke_viiii,u:invoke_viiiii,r:invoke_viiiiii,v:invoke_viiiiiii,za:invoke_viiiiiiii,y:invoke_viiiiiiiiii,C:invoke_viiiiiiiiiiiiiii,T:invoke_viiijj,U:invoke_viij,Ba:invoke_viijij,A:invoke_vij,p:_llvm_eh_typeid_for};function invoke_v(index){var sp=stackSave();try{dynCall_v(index)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_ii(index,a1){var sp=stackSave();try{return dynCall_ii(index,a1)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_iii(index,a1,a2){var sp=stackSave();try{return dynCall_iii(index,a1,a2)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_viiiiii(index,a1,a2,a3,a4,a5,a6){var sp=stackSave();try{dynCall_viiiiii(index,a1,a2,a3,a4,a5,a6)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_vii(index,a1,a2){var sp=stackSave();try{dynCall_vii(index,a1,a2)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_vij(index,a1,a2){var sp=stackSave();try{dynCall_vij(index,a1,a2)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_iiii(index,a1,a2,a3){var sp=stackSave();try{return dynCall_iiii(index,a1,a2,a3)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_viii(index,a1,a2,a3){var sp=stackSave();try{dynCall_viii(index,a1,a2,a3)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_iiiiii(index,a1,a2,a3,a4,a5){var sp=stackSave();try{return dynCall_iiiiii(index,a1,a2,a3,a4,a5)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_vi(index,a1){var sp=stackSave();try{dynCall_vi(index,a1)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_viiii(index,a1,a2,a3,a4){var sp=stackSave();try{dynCall_viiii(index,a1,a2,a3,a4)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_jii(index,a1,a2){var sp=stackSave();try{return dynCall_jii(index,a1,a2)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);return 0n}}function invoke_viiiii(index,a1,a2,a3,a4,a5){var sp=stackSave();try{dynCall_viiiii(index,a1,a2,a3,a4,a5)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_iiiiiii(index,a1,a2,a3,a4,a5,a6){var sp=stackSave();try{return dynCall_iiiiiii(index,a1,a2,a3,a4,a5,a6)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_iiiii(index,a1,a2,a3,a4){var sp=stackSave();try{return dynCall_iiiii(index,a1,a2,a3,a4)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_iiij(index,a1,a2,a3){var sp=stackSave();try{return dynCall_iiij(index,a1,a2,a3)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_iiid(index,a1,a2,a3){var sp=stackSave();try{return dynCall_iiid(index,a1,a2,a3)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_viijij(index,a1,a2,a3,a4,a5){var sp=stackSave();try{dynCall_viijij(index,a1,a2,a3,a4,a5)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_viij(index,a1,a2,a3){var sp=stackSave();try{dynCall_viij(index,a1,a2,a3)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_viiijj(index,a1,a2,a3,a4,a5){var sp=stackSave();try{dynCall_viiijj(index,a1,a2,a3,a4,a5)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_jiiiii(index,a1,a2,a3,a4,a5){var sp=stackSave();try{return dynCall_jiiiii(index,a1,a2,a3,a4,a5)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);return 0n}}function invoke_viiiiiiiiii(index,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10){var sp=stackSave();try{dynCall_viiiiiiiiii(index,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_iiji(index,a1,a2,a3){var sp=stackSave();try{return dynCall_iiji(index,a1,a2,a3)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_iijiii(index,a1,a2,a3,a4,a5){var sp=stackSave();try{return dynCall_iijiii(index,a1,a2,a3,a4,a5)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_iid(index,a1,a2){var sp=stackSave();try{return dynCall_iid(index,a1,a2)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_i(index){var sp=stackSave();try{return dynCall_i(index)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_dii(index,a1,a2){var sp=stackSave();try{return dynCall_dii(index,a1,a2)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_di(index,a1){var sp=stackSave();try{return dynCall_di(index,a1)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_viidi(index,a1,a2,a3,a4){var sp=stackSave();try{dynCall_viidi(index,a1,a2,a3,a4)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_vid(index,a1,a2){var sp=stackSave();try{dynCall_vid(index,a1,a2)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_jiiii(index,a1,a2,a3,a4){var sp=stackSave();try{return dynCall_jiiii(index,a1,a2,a3,a4)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);return 0n}}function invoke_viiiiiiii(index,a1,a2,a3,a4,a5,a6,a7,a8){var sp=stackSave();try{dynCall_viiiiiiii(index,a1,a2,a3,a4,a5,a6,a7,a8)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_iiiddddddddi(index,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11){var sp=stackSave();try{return dynCall_iiiddddddddi(index,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_j(index){var sp=stackSave();try{return dynCall_j(index)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);return 0n}}function invoke_iiiiid(index,a1,a2,a3,a4,a5){var sp=stackSave();try{return dynCall_iiiiid(index,a1,a2,a3,a4,a5)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_iiiiiiii(index,a1,a2,a3,a4,a5,a6,a7){var sp=stackSave();try{return dynCall_iiiiiiii(index,a1,a2,a3,a4,a5,a6,a7)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_fiii(index,a1,a2,a3){var sp=stackSave();try{return dynCall_fiii(index,a1,a2,a3)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_diii(index,a1,a2,a3){var sp=stackSave();try{return dynCall_diii(index,a1,a2,a3)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_viiiiiii(index,a1,a2,a3,a4,a5,a6,a7){var sp=stackSave();try{dynCall_viiiiiii(index,a1,a2,a3,a4,a5,a6,a7)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_iiiiiiiiiiii(index,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11){var sp=stackSave();try{return dynCall_iiiiiiiiiiii(index,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_viiiiiiiiiiiiiii(index,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15){var sp=stackSave();try{dynCall_viiiiiiiiiiiiiii(index,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function applySignatureConversions(wasmExports){wasmExports=Object.assign({},wasmExports);var makeWrapper_pp=f=>a0=>f(a0)>>>0;var makeWrapper_p=f=>()=>f()>>>0;wasmExports["Ha"]=makeWrapper_pp(wasmExports["Ha"]);wasmExports["sc"]=makeWrapper_pp(wasmExports["sc"]);wasmExports["tc"]=makeWrapper_p(wasmExports["tc"]);wasmExports["xc"]=makeWrapper_pp(wasmExports["xc"]);return wasmExports}function run(){preRun();function doRun(){Module["calledRun"]=true;if(ABORT)return;initRuntime();readyPromiseResolve?.(Module);Module["onRuntimeInitialized"]?.();postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout(()=>{setTimeout(()=>Module["setStatus"](""),1);doRun()},1)}else{doRun()}}var wasmExports;wasmExports=await (createWasm());run();if(runtimeInitialized){moduleRtn=Module}else{moduleRtn=new Promise((resolve,reject)=>{readyPromiseResolve=resolve;readyPromiseReject=reject})}
|
|
1
|
+
async function FlatSQL(moduleArg={}){var moduleRtn;var Module=moduleArg;var ENVIRONMENT_IS_WEB=!!globalThis.window;var ENVIRONMENT_IS_WORKER=!!globalThis.WorkerGlobalScope;var ENVIRONMENT_IS_NODE=globalThis.process?.versions?.node&&globalThis.process?.type!="renderer";if(ENVIRONMENT_IS_NODE){const{createRequire}=await import("module");var require=createRequire(import.meta.url)}var arguments_=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var _scriptName=import.meta.url;var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var readAsync,readBinary;if(ENVIRONMENT_IS_NODE){var fs=require("fs");if(_scriptName.startsWith("file:")){scriptDirectory=require("path").dirname(require("url").fileURLToPath(_scriptName))+"/"}readBinary=filename=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename);return ret};readAsync=async(filename,binary=true)=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename,binary?undefined:"utf8");return ret};if(process.argv.length>1){thisProgram=process.argv[1].replace(/\\/g,"/")}arguments_=process.argv.slice(2);quit_=(status,toThrow)=>{process.exitCode=status;throw toThrow}}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){try{scriptDirectory=new URL(".",_scriptName).href}catch{}{if(ENVIRONMENT_IS_WORKER){readBinary=url=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.responseType="arraybuffer";xhr.send(null);return new Uint8Array(xhr.response)}}readAsync=async url=>{var response=await fetch(url,{credentials:"same-origin"});if(response.ok){return response.arrayBuffer()}throw new Error(response.status+" : "+response.url)}}}else{}var out=console.log.bind(console);var err=console.error.bind(console);var wasmBinary;var ABORT=false;var isFileURI=filename=>filename.startsWith("file://");var readyPromiseResolve,readyPromiseReject;var HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAPF32,HEAPF64;var HEAP64,HEAPU64;var runtimeInitialized=false;function updateMemoryViews(){var b=wasmMemory.buffer;HEAP8=new Int8Array(b);HEAP16=new Int16Array(b);Module["HEAPU8"]=HEAPU8=new Uint8Array(b);HEAPU16=new Uint16Array(b);HEAP32=new Int32Array(b);HEAPU32=new Uint32Array(b);HEAPF32=new Float32Array(b);HEAPF64=new Float64Array(b);HEAP64=new BigInt64Array(b);HEAPU64=new BigUint64Array(b)}function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift())}}callRuntimeCallbacks(onPreRuns)}function initRuntime(){runtimeInitialized=true;wasmExports["Na"]()}function postRun(){if(Module["postRun"]){if(typeof Module["postRun"]=="function")Module["postRun"]=[Module["postRun"]];while(Module["postRun"].length){addOnPostRun(Module["postRun"].shift())}}callRuntimeCallbacks(onPostRuns)}function abort(what){Module["onAbort"]?.(what);what="Aborted("+what+")";err(what);ABORT=true;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);readyPromiseReject?.(e);throw e}var wasmBinaryFile;function findWasmBinary(){if(Module["locateFile"]){return locateFile("flatsql.wasm")}return new URL("flatsql.wasm",import.meta.url).href}function getBinarySync(file){if(file==wasmBinaryFile&&wasmBinary){return new Uint8Array(wasmBinary)}if(readBinary){return readBinary(file)}throw"both async and sync fetching of the wasm failed"}async function getWasmBinary(binaryFile){if(!wasmBinary){try{var response=await readAsync(binaryFile);return new Uint8Array(response)}catch{}}return getBinarySync(binaryFile)}async function instantiateArrayBuffer(binaryFile,imports){try{var binary=await getWasmBinary(binaryFile);var instance=await WebAssembly.instantiate(binary,imports);return instance}catch(reason){err(`failed to asynchronously prepare wasm: ${reason}`);abort(reason)}}async function instantiateAsync(binary,binaryFile,imports){if(!binary&&!ENVIRONMENT_IS_NODE){try{var response=fetch(binaryFile,{credentials:"same-origin"});var instantiationResult=await WebAssembly.instantiateStreaming(response,imports);return instantiationResult}catch(reason){err(`wasm streaming compile failed: ${reason}`);err("falling back to ArrayBuffer instantiation")}}return instantiateArrayBuffer(binaryFile,imports)}function getWasmImports(){var imports={a:wasmImports};return imports}async function createWasm(){function receiveInstance(instance,module){wasmExports=instance.exports;wasmExports=applySignatureConversions(wasmExports);assignWasmExports(wasmExports);updateMemoryViews();return wasmExports}function receiveInstantiationResult(result){return receiveInstance(result["instance"])}var info=getWasmImports();if(Module["instantiateWasm"]){return new Promise((resolve,reject)=>{Module["instantiateWasm"](info,(inst,mod)=>{resolve(receiveInstance(inst,mod))})})}wasmBinaryFile??=findWasmBinary();var result=await instantiateAsync(wasmBinary,wasmBinaryFile,info);var exports=receiveInstantiationResult(result);return exports}class ExitStatus{name="ExitStatus";constructor(status){this.message=`Program terminated with exit(${status})`;this.status=status}}var callRuntimeCallbacks=callbacks=>{while(callbacks.length>0){callbacks.shift()(Module)}};var onPostRuns=[];var addOnPostRun=cb=>onPostRuns.push(cb);var onPreRuns=[];var addOnPreRun=cb=>onPreRuns.push(cb);var noExitRuntime=true;var stackRestore=val=>__emscripten_stack_restore(val);var stackSave=()=>_emscripten_stack_get_current();var exceptionCaught=[];var uncaughtExceptionCount=0;var INT53_MAX=9007199254740992;var INT53_MIN=-9007199254740992;var bigintToI53Checked=num=>num<INT53_MIN||num>INT53_MAX?NaN:Number(num);function ___cxa_begin_catch(ptr){ptr>>>=0;var info=new ExceptionInfo(ptr);if(!info.get_caught()){info.set_caught(true);uncaughtExceptionCount--}info.set_rethrown(false);exceptionCaught.push(info);return ___cxa_get_exception_ptr(ptr)}var exceptionLast=0;var ___cxa_end_catch=()=>{_setThrew(0,0);var info=exceptionCaught.pop();___cxa_decrement_exception_refcount(info.excPtr);exceptionLast=0};class ExceptionInfo{constructor(excPtr){this.excPtr=excPtr;this.ptr=excPtr-24}set_type(type){HEAPU32[this.ptr+4>>>2>>>0]=type}get_type(){return HEAPU32[this.ptr+4>>>2>>>0]}set_destructor(destructor){HEAPU32[this.ptr+8>>>2>>>0]=destructor}get_destructor(){return HEAPU32[this.ptr+8>>>2>>>0]}set_caught(caught){caught=caught?1:0;HEAP8[this.ptr+12>>>0]=caught}get_caught(){return HEAP8[this.ptr+12>>>0]!=0}set_rethrown(rethrown){rethrown=rethrown?1:0;HEAP8[this.ptr+13>>>0]=rethrown}get_rethrown(){return HEAP8[this.ptr+13>>>0]!=0}init(type,destructor){this.set_adjusted_ptr(0);this.set_type(type);this.set_destructor(destructor)}set_adjusted_ptr(adjustedPtr){HEAPU32[this.ptr+16>>>2>>>0]=adjustedPtr}get_adjusted_ptr(){return HEAPU32[this.ptr+16>>>2>>>0]}}var setTempRet0=val=>__emscripten_tempret_set(val);var findMatchingCatch=args=>{var thrown=exceptionLast;if(!thrown){setTempRet0(0);return 0}var info=new ExceptionInfo(thrown);info.set_adjusted_ptr(thrown);var thrownType=info.get_type();if(!thrownType){setTempRet0(0);return thrown}for(var caughtType of args){if(caughtType===0||caughtType===thrownType){break}var adjusted_ptr_addr=info.ptr+16;if(___cxa_can_catch(caughtType,thrownType,adjusted_ptr_addr)){setTempRet0(caughtType);return thrown}}setTempRet0(thrownType);return thrown};function ___cxa_find_matching_catch_2(){return findMatchingCatch([])}function ___cxa_find_matching_catch_3(arg0){arg0>>>=0;return findMatchingCatch([arg0])}function ___cxa_find_matching_catch_4(arg0,arg1){arg0>>>=0;arg1>>>=0;return findMatchingCatch([arg0,arg1])}var ___cxa_rethrow=()=>{var info=exceptionCaught.pop();if(!info){abort("no exception to throw")}var ptr=info.excPtr;if(!info.get_rethrown()){exceptionCaught.push(info);info.set_rethrown(true);info.set_caught(false);uncaughtExceptionCount++}___cxa_increment_exception_refcount(ptr);exceptionLast=ptr;throw exceptionLast};function ___cxa_throw(ptr,type,destructor){ptr>>>=0;type>>>=0;destructor>>>=0;var info=new ExceptionInfo(ptr);info.init(type,destructor);___cxa_increment_exception_refcount(ptr);exceptionLast=ptr;uncaughtExceptionCount++;throw exceptionLast}var ___cxa_uncaught_exceptions=()=>uncaughtExceptionCount;function ___resumeException(ptr){ptr>>>=0;if(!exceptionLast){exceptionLast=ptr}throw exceptionLast}function ___syscall_chmod(path,mode){path>>>=0}function ___syscall_faccessat(dirfd,path,amode,flags){path>>>=0}var ___syscall_fchmod=(fd,mode)=>{};var ___syscall_fchown32=(fd,owner,group)=>{};var UTF8Decoder=globalThis.TextDecoder&&new TextDecoder;var findStringEnd=(heapOrArray,idx,maxBytesToRead,ignoreNul)=>{var maxIdx=idx+maxBytesToRead;if(ignoreNul)return maxIdx;while(heapOrArray[idx]&&!(idx>=maxIdx))++idx;return idx};var UTF8ArrayToString=(heapOrArray,idx=0,maxBytesToRead,ignoreNul)=>{idx>>>=0;var endPtr=findStringEnd(heapOrArray,idx,maxBytesToRead,ignoreNul);if(endPtr-idx>16&&heapOrArray.buffer&&UTF8Decoder){return UTF8Decoder.decode(heapOrArray.subarray(idx,endPtr))}var str="";while(idx<endPtr){var u0=heapOrArray[idx++];if(!(u0&128)){str+=String.fromCharCode(u0);continue}var u1=heapOrArray[idx++]&63;if((u0&224)==192){str+=String.fromCharCode((u0&31)<<6|u1);continue}var u2=heapOrArray[idx++]&63;if((u0&240)==224){u0=(u0&15)<<12|u1<<6|u2}else{u0=(u0&7)<<18|u1<<12|u2<<6|heapOrArray[idx++]&63}if(u0<65536){str+=String.fromCharCode(u0)}else{var ch=u0-65536;str+=String.fromCharCode(55296|ch>>10,56320|ch&1023)}}return str};var UTF8ToString=(ptr,maxBytesToRead,ignoreNul)=>{ptr>>>=0;return ptr?UTF8ArrayToString(HEAPU8,ptr,maxBytesToRead,ignoreNul):""};var SYSCALLS={varargs:undefined,getStr(ptr){var ret=UTF8ToString(ptr);return ret}};function ___syscall_fcntl64(fd,cmd,varargs){varargs>>>=0;SYSCALLS.varargs=varargs;return 0}function ___syscall_fstat64(fd,buf){buf>>>=0}function ___syscall_ftruncate64(fd,length){length=bigintToI53Checked(length)}function ___syscall_getcwd(buf,size){buf>>>=0;size>>>=0}function ___syscall_lstat64(path,buf){path>>>=0;buf>>>=0}function ___syscall_mkdirat(dirfd,path,mode){path>>>=0}function ___syscall_newfstatat(dirfd,path,buf,flags){path>>>=0;buf>>>=0}function ___syscall_openat(dirfd,path,flags,varargs){path>>>=0;varargs>>>=0;SYSCALLS.varargs=varargs}function ___syscall_readlinkat(dirfd,path,buf,bufsize){path>>>=0;buf>>>=0;bufsize>>>=0}function ___syscall_rmdir(path){path>>>=0}function ___syscall_stat64(path,buf){path>>>=0;buf>>>=0}function ___syscall_unlinkat(dirfd,path,flags){path>>>=0}function ___syscall_utimensat(dirfd,path,times,flags){path>>>=0;times>>>=0}var __abort_js=()=>abort("");var isLeapYear=year=>year%4===0&&(year%100!==0||year%400===0);var MONTH_DAYS_LEAP_CUMULATIVE=[0,31,60,91,121,152,182,213,244,274,305,335];var MONTH_DAYS_REGULAR_CUMULATIVE=[0,31,59,90,120,151,181,212,243,273,304,334];var ydayFromDate=date=>{var leap=isLeapYear(date.getFullYear());var monthDaysCumulative=leap?MONTH_DAYS_LEAP_CUMULATIVE:MONTH_DAYS_REGULAR_CUMULATIVE;var yday=monthDaysCumulative[date.getMonth()]+date.getDate()-1;return yday};function __localtime_js(time,tmPtr){time=bigintToI53Checked(time);tmPtr>>>=0;var date=new Date(time*1e3);HEAP32[tmPtr>>>2>>>0]=date.getSeconds();HEAP32[tmPtr+4>>>2>>>0]=date.getMinutes();HEAP32[tmPtr+8>>>2>>>0]=date.getHours();HEAP32[tmPtr+12>>>2>>>0]=date.getDate();HEAP32[tmPtr+16>>>2>>>0]=date.getMonth();HEAP32[tmPtr+20>>>2>>>0]=date.getFullYear()-1900;HEAP32[tmPtr+24>>>2>>>0]=date.getDay();var yday=ydayFromDate(date)|0;HEAP32[tmPtr+28>>>2>>>0]=yday;HEAP32[tmPtr+36>>>2>>>0]=-(date.getTimezoneOffset()*60);var start=new Date(date.getFullYear(),0,1);var summerOffset=new Date(date.getFullYear(),6,1).getTimezoneOffset();var winterOffset=start.getTimezoneOffset();var dst=(summerOffset!=winterOffset&&date.getTimezoneOffset()==Math.min(winterOffset,summerOffset))|0;HEAP32[tmPtr+32>>>2>>>0]=dst}var stringToUTF8Array=(str,heap,outIdx,maxBytesToWrite)=>{outIdx>>>=0;if(!(maxBytesToWrite>0))return 0;var startIdx=outIdx;var endIdx=outIdx+maxBytesToWrite-1;for(var i=0;i<str.length;++i){var u=str.codePointAt(i);if(u<=127){if(outIdx>=endIdx)break;heap[outIdx++>>>0]=u}else if(u<=2047){if(outIdx+1>=endIdx)break;heap[outIdx++>>>0]=192|u>>6;heap[outIdx++>>>0]=128|u&63}else if(u<=65535){if(outIdx+2>=endIdx)break;heap[outIdx++>>>0]=224|u>>12;heap[outIdx++>>>0]=128|u>>6&63;heap[outIdx++>>>0]=128|u&63}else{if(outIdx+3>=endIdx)break;heap[outIdx++>>>0]=240|u>>18;heap[outIdx++>>>0]=128|u>>12&63;heap[outIdx++>>>0]=128|u>>6&63;heap[outIdx++>>>0]=128|u&63;i++}}heap[outIdx>>>0]=0;return outIdx-startIdx};var stringToUTF8=(str,outPtr,maxBytesToWrite)=>stringToUTF8Array(str,HEAPU8,outPtr,maxBytesToWrite);var __tzset_js=function(timezone,daylight,std_name,dst_name){timezone>>>=0;daylight>>>=0;std_name>>>=0;dst_name>>>=0;var currentYear=(new Date).getFullYear();var winter=new Date(currentYear,0,1);var summer=new Date(currentYear,6,1);var winterOffset=winter.getTimezoneOffset();var summerOffset=summer.getTimezoneOffset();var stdTimezoneOffset=Math.max(winterOffset,summerOffset);HEAPU32[timezone>>>2>>>0]=stdTimezoneOffset*60;HEAP32[daylight>>>2>>>0]=Number(winterOffset!=summerOffset);var extractZone=timezoneOffset=>{var sign=timezoneOffset>=0?"-":"+";var absOffset=Math.abs(timezoneOffset);var hours=String(Math.floor(absOffset/60)).padStart(2,"0");var minutes=String(absOffset%60).padStart(2,"0");return`UTC${sign}${hours}${minutes}`};var winterName=extractZone(winterOffset);var summerName=extractZone(summerOffset);if(summerOffset<winterOffset){stringToUTF8(winterName,std_name,17);stringToUTF8(summerName,dst_name,17)}else{stringToUTF8(winterName,dst_name,17);stringToUTF8(summerName,std_name,17)}};var _emscripten_get_now=()=>performance.now();var _emscripten_date_now=()=>Date.now();var nowIsMonotonic=1;var checkWasiClock=clock_id=>clock_id>=0&&clock_id<=3;function _clock_time_get(clk_id,ignored_precision,ptime){ignored_precision=bigintToI53Checked(ignored_precision);ptime>>>=0;if(!checkWasiClock(clk_id)){return 28}var now;if(clk_id===0){now=_emscripten_date_now()}else if(nowIsMonotonic){now=_emscripten_get_now()}else{return 52}var nsec=Math.round(now*1e3*1e3);HEAP64[ptime>>>3>>>0]=BigInt(nsec);return 0}var getHeapMax=()=>4294901760;var alignMemory=(size,alignment)=>Math.ceil(size/alignment)*alignment;var growMemory=size=>{var oldHeapSize=wasmMemory.buffer.byteLength;var pages=(size-oldHeapSize+65535)/65536|0;try{wasmMemory.grow(pages);updateMemoryViews();return 1}catch(e){}};function _emscripten_resize_heap(requestedSize){requestedSize>>>=0;var oldSize=HEAPU8.length;var maxHeapSize=getHeapMax();if(requestedSize>maxHeapSize){return false}for(var cutDown=1;cutDown<=4;cutDown*=2){var overGrownHeapSize=oldSize*(1+.2/cutDown);overGrownHeapSize=Math.min(overGrownHeapSize,requestedSize+100663296);var newSize=Math.min(maxHeapSize,alignMemory(Math.max(requestedSize,overGrownHeapSize),65536));var replacement=growMemory(newSize);if(replacement){return true}}return false}var ENV={};var getExecutableName=()=>thisProgram||"./this.program";var getEnvStrings=()=>{if(!getEnvStrings.strings){var lang=(globalThis.navigator?.language??"C").replace("-","_")+".UTF-8";var env={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:lang,_:getExecutableName()};for(var x in ENV){if(ENV[x]===undefined)delete env[x];else env[x]=ENV[x]}var strings=[];for(var x in env){strings.push(`${x}=${env[x]}`)}getEnvStrings.strings=strings}return getEnvStrings.strings};function _environ_get(__environ,environ_buf){__environ>>>=0;environ_buf>>>=0;var bufSize=0;var envp=0;for(var string of getEnvStrings()){var ptr=environ_buf+bufSize;HEAPU32[__environ+envp>>>2>>>0]=ptr;bufSize+=stringToUTF8(string,ptr,Infinity)+1;envp+=4}return 0}var lengthBytesUTF8=str=>{var len=0;for(var i=0;i<str.length;++i){var c=str.charCodeAt(i);if(c<=127){len++}else if(c<=2047){len+=2}else if(c>=55296&&c<=57343){len+=4;++i}else{len+=3}}return len};function _environ_sizes_get(penviron_count,penviron_buf_size){penviron_count>>>=0;penviron_buf_size>>>=0;var strings=getEnvStrings();HEAPU32[penviron_count>>>2>>>0]=strings.length;var bufSize=0;for(var string of strings){bufSize+=lengthBytesUTF8(string)+1}HEAPU32[penviron_buf_size>>>2>>>0]=bufSize;return 0}var _fd_close=fd=>52;function _fd_fdstat_get(fd,pbuf){pbuf>>>=0;var rightsBase=0;var rightsInheriting=0;var flags=0;{var type=2;if(fd==0){rightsBase=2}else if(fd==1||fd==2){rightsBase=64}flags=1}HEAP8[pbuf>>>0]=type;HEAP16[pbuf+2>>>1>>>0]=flags;HEAP64[pbuf+8>>>3>>>0]=BigInt(rightsBase);HEAP64[pbuf+16>>>3>>>0]=BigInt(rightsInheriting);return 0}function _fd_read(fd,iov,iovcnt,pnum){iov>>>=0;iovcnt>>>=0;pnum>>>=0;return 52}function _fd_seek(fd,offset,whence,newOffset){offset=bigintToI53Checked(offset);newOffset>>>=0;return 70}var _fd_sync=fd=>52;var printCharBuffers=[null,[],[]];var printChar=(stream,curr)=>{var buffer=printCharBuffers[stream];if(curr===0||curr===10){(stream===1?out:err)(UTF8ArrayToString(buffer));buffer.length=0}else{buffer.push(curr)}};function _fd_write(fd,iov,iovcnt,pnum){iov>>>=0;iovcnt>>>=0;pnum>>>=0;var num=0;for(var i=0;i<iovcnt;i++){var ptr=HEAPU32[iov>>>2>>>0];var len=HEAPU32[iov+4>>>2>>>0];iov+=8;for(var j=0;j<len;j++){printChar(fd,HEAPU8[ptr+j>>>0])}num+=len}HEAPU32[pnum>>>2>>>0]=num;return 0}var flatsqlIoBridge={ERR_GENERIC:-1,ERR_NOENT:-2,ERR_ACCESS:-3,ERR_BADHANDLE:-6,backend:function(){return Module["flatsqlIO"]||null},path:function(ptr,len){return UTF8ToString(ptr,len)}};function _flatsql_io_close(handle){var io=flatsqlIoBridge.backend();if(!io)return flatsqlIoBridge.ERR_ACCESS;try{return io.close(handle)|0}catch(e){return flatsqlIoBridge.ERR_GENERIC}}function _flatsql_io_open(pathPtr,pathLen,flags){var io=flatsqlIoBridge.backend();if(!io)return flatsqlIoBridge.ERR_ACCESS;try{return io.open(flatsqlIoBridge.path(pathPtr,pathLen),flags)|0}catch(e){return flatsqlIoBridge.ERR_GENERIC}}function _flatsql_io_read(handle,dstPtr,len,offset){var io=flatsqlIoBridge.backend();if(!io)return flatsqlIoBridge.ERR_ACCESS;try{return io.read(handle,HEAPU8.subarray(dstPtr>>>0,dstPtr+len>>>0),offset)|0}catch(e){return flatsqlIoBridge.ERR_GENERIC}}function _flatsql_io_size(handle){var io=flatsqlIoBridge.backend();if(!io)return flatsqlIoBridge.ERR_ACCESS;try{return io.size(handle)}catch(e){return flatsqlIoBridge.ERR_GENERIC}}function _flatsql_io_sync(handle){var io=flatsqlIoBridge.backend();if(!io)return flatsqlIoBridge.ERR_ACCESS;try{return io.sync(handle)|0}catch(e){return flatsqlIoBridge.ERR_GENERIC}}function _flatsql_io_truncate(handle,size){var io=flatsqlIoBridge.backend();if(!io)return flatsqlIoBridge.ERR_ACCESS;try{return io.truncate(handle,size)|0}catch(e){return flatsqlIoBridge.ERR_GENERIC}}function _flatsql_io_write(handle,srcPtr,len,offset){var io=flatsqlIoBridge.backend();if(!io)return flatsqlIoBridge.ERR_ACCESS;try{return io.write(handle,HEAPU8.subarray(srcPtr>>>0,srcPtr+len>>>0),offset)|0}catch(e){return flatsqlIoBridge.ERR_GENERIC}}function _llvm_eh_typeid_for(type){type>>>=0;return type}var getCFunc=ident=>{var func=Module["_"+ident];return func};var writeArrayToMemory=(array,buffer)=>{HEAP8.set(array,buffer>>>0)};var stackAlloc=sz=>__emscripten_stack_alloc(sz);var stringToUTF8OnStack=str=>{var size=lengthBytesUTF8(str)+1;var ret=stackAlloc(size);stringToUTF8(str,ret,size);return ret};var ccall=(ident,returnType,argTypes,args,opts)=>{var toC={string:str=>{var ret=0;if(str!==null&&str!==undefined&&str!==0){ret=stringToUTF8OnStack(str)}return ret},array:arr=>{var ret=stackAlloc(arr.length);writeArrayToMemory(arr,ret);return ret}};function convertReturnValue(ret){if(returnType==="string"){return UTF8ToString(ret)}if(returnType==="pointer")return ret>>>0;if(returnType==="boolean")return Boolean(ret);return ret}var func=getCFunc(ident);var cArgs=[];var stack=0;if(args){for(var i=0;i<args.length;i++){var converter=toC[argTypes[i]];if(converter){if(stack===0)stack=stackSave();cArgs[i]=converter(args[i])}else{cArgs[i]=args[i]}}}var ret=func(...cArgs);function onDone(ret){if(stack!==0)stackRestore(stack);return convertReturnValue(ret)}ret=onDone(ret);return ret};var cwrap=(ident,returnType,argTypes,opts)=>{var numericArgs=!argTypes||argTypes.every(type=>type==="number"||type==="boolean");var numericRet=returnType!=="string";if(numericRet&&numericArgs&&!opts){return getCFunc(ident)}return(...args)=>ccall(ident,returnType,argTypes,args,opts)};{if(Module["noExitRuntime"])noExitRuntime=Module["noExitRuntime"];if(Module["print"])out=Module["print"];if(Module["printErr"])err=Module["printErr"];if(Module["wasmBinary"])wasmBinary=Module["wasmBinary"];if(Module["arguments"])arguments_=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].shift()()}}}Module["ccall"]=ccall;Module["cwrap"]=cwrap;Module["UTF8ToString"]=UTF8ToString;Module["stringToUTF8"]=stringToUTF8;Module["lengthBytesUTF8"]=lengthBytesUTF8;var _free,_malloc,_flatsql_create_db,_flatsql_open_db,_flatsql_is_disk_backed,_flatsql_open_state,_flatsql_reindex_all,_flatsql_flush_index,_flatsql_flushed_offset,_flatsql_stream_path,_flatsql_destroy_db,_flatsql_register_file_id,_flatsql_enable_demo_extractors,_flatsql_ingest,_flatsql_ingest_one,_flatsql_register_source,_flatsql_create_unified_views,_flatsql_ingest_with_source,_flatsql_ingest_one_with_source,_flatsql_query,_flatsql_query_params,_flatsql_query_many,_flatsql_batch_result_count,_flatsql_select_batch_result,_flatsql_get_error,_flatsql_build_query_cache_key,_flatsql_build_response_artifact_cache_key,_flatsql_register_query_template,_flatsql_query_template,_flatsql_clear_query_cache,_flatsql_configure_query_cache,_flatsql_query_cache_hits,_flatsql_query_cache_misses,_flatsql_query_cache_size,_flatsql_query_cache_generation,_flatsql_query_cache_max_entries,_flatsql_query_cache_max_rows,_flatsql_result_column_count,_flatsql_result_row_count,_flatsql_result_column_name,_flatsql_result_cell_type,_flatsql_result_cell_number,_flatsql_result_cell_string,_flatsql_result_cell_blob,_flatsql_result_cell_blob_size,_flatsql_export_data,_flatsql_query_raw_flatbuffer_stream,_flatsql_query_sandboxed,_flatsql_response_artifact_data,_flatsql_response_artifact_size,_flatsql_response_artifact_cache_hit,_flatsql_configure_raw_stream_cache,_flatsql_raw_stream_cache_hits,_flatsql_raw_stream_cache_misses,_flatsql_raw_stream_cache_size,_flatsql_raw_stream_cache_total_bytes,_flatsql_response_artifact_row_count,_flatsql_response_artifact_column_count,_flatsql_export_size,_flatsql_load_and_rebuild,_flatsql_reserve_storage,_flatsql_load_from_db,_flatsql_create_test_user,_flatsql_test_buffer_size,_flatsql_create_test_post,_flatsql_create_test_mpe,_flatsql_create_test_telemetry,_flatsql_create_test_publish_event,_flatsql_get_stats_count,_flatsql_get_stat_table_name,_flatsql_get_stat_file_id,_flatsql_get_stat_record_count,_flatsql_reset_ingest_profile,_flatsql_get_ingest_profile_record_count,_flatsql_get_ingest_profile_byte_count,_flatsql_get_ingest_profile_decode_nanos,_flatsql_get_ingest_profile_append_nanos,_flatsql_get_ingest_profile_index_nanos,_flatsql_mark_deleted,_flatsql_get_deleted_count,_flatsql_clear_tombstones,_flatsql_get_sources_count,_flatsql_get_source_name,_flatsql_get_flatbuffer_by_id,_flatsql_get_flatbuffer_by_email,_flatsql_get_flatbuffer_by_index,_flatsql_get_raw_flatbuffer_size,_flatsql_get_raw_flatbuffer_sequence,_flatsql_get_storage_buffer,_flatsql_get_storage_size,_flatsql_set_encryption_key,_flatsql_is_encrypted,_flatsql_encrypt_buffer,_flatsql_decrypt_buffer,_flatsql_set_hmac_verification,_flatsql_is_hmac_enabled,_flatsql_compute_hmac,_flatsql_verify_hmac,_setThrew,__emscripten_tempret_set,__emscripten_stack_restore,__emscripten_stack_alloc,_emscripten_stack_get_current,___cxa_decrement_exception_refcount,___cxa_increment_exception_refcount,___cxa_can_catch,___cxa_get_exception_ptr,dynCall_v,dynCall_ii,dynCall_iii,dynCall_viiiiii,dynCall_vii,dynCall_viii,dynCall_iiii,dynCall_iiiiii,dynCall_vi,dynCall_viiii,dynCall_jii,dynCall_viiiii,dynCall_iiiiiii,dynCall_iiiii,dynCall_iiij,dynCall_iiid,dynCall_viijij,dynCall_viiijj,dynCall_jiiiii,dynCall_viiiiiiiiii,dynCall_vij,dynCall_iiji,dynCall_iijiii,dynCall_viij,dynCall_iid,dynCall_i,dynCall_dii,dynCall_di,dynCall_iiiid,dynCall_iij,dynCall_viidi,dynCall_vid,dynCall_vidd,dynCall_dd,dynCall_ddd,dynCall_jiiii,dynCall_viiiiiiii,dynCall_iiiddddddddi,dynCall_iiiij,dynCall_iijj,dynCall_iijii,dynCall_iidiiii,dynCall_j,dynCall_iiiiid,dynCall_viijii,dynCall_iiiiiiii,dynCall_iiiiiiiiiii,dynCall_iiiiiiiiiiiii,dynCall_fiii,dynCall_diii,dynCall_viiiiiii,dynCall_iiiiiiiiiiii,dynCall_viiiiiiiiiiiiiii,dynCall_iiiiiiiii,dynCall_iiiiij,dynCall_iiiiijj,dynCall_iiiiiijj,memory,__indirect_function_table,wasmMemory,wasmTable;function assignWasmExports(wasmExports){_free=Module["_free"]=wasmExports["Pa"];_malloc=Module["_malloc"]=wasmExports["Qa"];_flatsql_create_db=Module["_flatsql_create_db"]=wasmExports["Ra"];_flatsql_open_db=Module["_flatsql_open_db"]=wasmExports["Sa"];_flatsql_is_disk_backed=Module["_flatsql_is_disk_backed"]=wasmExports["Ta"];_flatsql_open_state=Module["_flatsql_open_state"]=wasmExports["Ua"];_flatsql_reindex_all=Module["_flatsql_reindex_all"]=wasmExports["Va"];_flatsql_flush_index=Module["_flatsql_flush_index"]=wasmExports["Wa"];_flatsql_flushed_offset=Module["_flatsql_flushed_offset"]=wasmExports["Xa"];_flatsql_stream_path=Module["_flatsql_stream_path"]=wasmExports["Ya"];_flatsql_destroy_db=Module["_flatsql_destroy_db"]=wasmExports["Za"];_flatsql_register_file_id=Module["_flatsql_register_file_id"]=wasmExports["_a"];_flatsql_enable_demo_extractors=Module["_flatsql_enable_demo_extractors"]=wasmExports["$a"];_flatsql_ingest=Module["_flatsql_ingest"]=wasmExports["ab"];_flatsql_ingest_one=Module["_flatsql_ingest_one"]=wasmExports["bb"];_flatsql_register_source=Module["_flatsql_register_source"]=wasmExports["cb"];_flatsql_create_unified_views=Module["_flatsql_create_unified_views"]=wasmExports["db"];_flatsql_ingest_with_source=Module["_flatsql_ingest_with_source"]=wasmExports["eb"];_flatsql_ingest_one_with_source=Module["_flatsql_ingest_one_with_source"]=wasmExports["fb"];_flatsql_query=Module["_flatsql_query"]=wasmExports["gb"];_flatsql_query_params=Module["_flatsql_query_params"]=wasmExports["hb"];_flatsql_query_many=Module["_flatsql_query_many"]=wasmExports["ib"];_flatsql_batch_result_count=Module["_flatsql_batch_result_count"]=wasmExports["jb"];_flatsql_select_batch_result=Module["_flatsql_select_batch_result"]=wasmExports["kb"];_flatsql_get_error=Module["_flatsql_get_error"]=wasmExports["lb"];_flatsql_build_query_cache_key=Module["_flatsql_build_query_cache_key"]=wasmExports["mb"];_flatsql_build_response_artifact_cache_key=Module["_flatsql_build_response_artifact_cache_key"]=wasmExports["nb"];_flatsql_register_query_template=Module["_flatsql_register_query_template"]=wasmExports["ob"];_flatsql_query_template=Module["_flatsql_query_template"]=wasmExports["pb"];_flatsql_clear_query_cache=Module["_flatsql_clear_query_cache"]=wasmExports["qb"];_flatsql_configure_query_cache=Module["_flatsql_configure_query_cache"]=wasmExports["rb"];_flatsql_query_cache_hits=Module["_flatsql_query_cache_hits"]=wasmExports["sb"];_flatsql_query_cache_misses=Module["_flatsql_query_cache_misses"]=wasmExports["tb"];_flatsql_query_cache_size=Module["_flatsql_query_cache_size"]=wasmExports["ub"];_flatsql_query_cache_generation=Module["_flatsql_query_cache_generation"]=wasmExports["vb"];_flatsql_query_cache_max_entries=Module["_flatsql_query_cache_max_entries"]=wasmExports["wb"];_flatsql_query_cache_max_rows=Module["_flatsql_query_cache_max_rows"]=wasmExports["xb"];_flatsql_result_column_count=Module["_flatsql_result_column_count"]=wasmExports["yb"];_flatsql_result_row_count=Module["_flatsql_result_row_count"]=wasmExports["zb"];_flatsql_result_column_name=Module["_flatsql_result_column_name"]=wasmExports["Ab"];_flatsql_result_cell_type=Module["_flatsql_result_cell_type"]=wasmExports["Bb"];_flatsql_result_cell_number=Module["_flatsql_result_cell_number"]=wasmExports["Cb"];_flatsql_result_cell_string=Module["_flatsql_result_cell_string"]=wasmExports["Db"];_flatsql_result_cell_blob=Module["_flatsql_result_cell_blob"]=wasmExports["Eb"];_flatsql_result_cell_blob_size=Module["_flatsql_result_cell_blob_size"]=wasmExports["Fb"];_flatsql_export_data=Module["_flatsql_export_data"]=wasmExports["Gb"];_flatsql_query_raw_flatbuffer_stream=Module["_flatsql_query_raw_flatbuffer_stream"]=wasmExports["Hb"];_flatsql_query_sandboxed=Module["_flatsql_query_sandboxed"]=wasmExports["Ib"];_flatsql_response_artifact_data=Module["_flatsql_response_artifact_data"]=wasmExports["Jb"];_flatsql_response_artifact_size=Module["_flatsql_response_artifact_size"]=wasmExports["Kb"];_flatsql_response_artifact_cache_hit=Module["_flatsql_response_artifact_cache_hit"]=wasmExports["Lb"];_flatsql_configure_raw_stream_cache=Module["_flatsql_configure_raw_stream_cache"]=wasmExports["Mb"];_flatsql_raw_stream_cache_hits=Module["_flatsql_raw_stream_cache_hits"]=wasmExports["Nb"];_flatsql_raw_stream_cache_misses=Module["_flatsql_raw_stream_cache_misses"]=wasmExports["Ob"];_flatsql_raw_stream_cache_size=Module["_flatsql_raw_stream_cache_size"]=wasmExports["Pb"];_flatsql_raw_stream_cache_total_bytes=Module["_flatsql_raw_stream_cache_total_bytes"]=wasmExports["Qb"];_flatsql_response_artifact_row_count=Module["_flatsql_response_artifact_row_count"]=wasmExports["Rb"];_flatsql_response_artifact_column_count=Module["_flatsql_response_artifact_column_count"]=wasmExports["Sb"];_flatsql_export_size=Module["_flatsql_export_size"]=wasmExports["Tb"];_flatsql_load_and_rebuild=Module["_flatsql_load_and_rebuild"]=wasmExports["Ub"];_flatsql_reserve_storage=Module["_flatsql_reserve_storage"]=wasmExports["Vb"];_flatsql_load_from_db=Module["_flatsql_load_from_db"]=wasmExports["Wb"];_flatsql_create_test_user=Module["_flatsql_create_test_user"]=wasmExports["Xb"];_flatsql_test_buffer_size=Module["_flatsql_test_buffer_size"]=wasmExports["Yb"];_flatsql_create_test_post=Module["_flatsql_create_test_post"]=wasmExports["Zb"];_flatsql_create_test_mpe=Module["_flatsql_create_test_mpe"]=wasmExports["_b"];_flatsql_create_test_telemetry=Module["_flatsql_create_test_telemetry"]=wasmExports["$b"];_flatsql_create_test_publish_event=Module["_flatsql_create_test_publish_event"]=wasmExports["ac"];_flatsql_get_stats_count=Module["_flatsql_get_stats_count"]=wasmExports["bc"];_flatsql_get_stat_table_name=Module["_flatsql_get_stat_table_name"]=wasmExports["cc"];_flatsql_get_stat_file_id=Module["_flatsql_get_stat_file_id"]=wasmExports["dc"];_flatsql_get_stat_record_count=Module["_flatsql_get_stat_record_count"]=wasmExports["ec"];_flatsql_reset_ingest_profile=Module["_flatsql_reset_ingest_profile"]=wasmExports["fc"];_flatsql_get_ingest_profile_record_count=Module["_flatsql_get_ingest_profile_record_count"]=wasmExports["gc"];_flatsql_get_ingest_profile_byte_count=Module["_flatsql_get_ingest_profile_byte_count"]=wasmExports["hc"];_flatsql_get_ingest_profile_decode_nanos=Module["_flatsql_get_ingest_profile_decode_nanos"]=wasmExports["ic"];_flatsql_get_ingest_profile_append_nanos=Module["_flatsql_get_ingest_profile_append_nanos"]=wasmExports["jc"];_flatsql_get_ingest_profile_index_nanos=Module["_flatsql_get_ingest_profile_index_nanos"]=wasmExports["kc"];_flatsql_mark_deleted=Module["_flatsql_mark_deleted"]=wasmExports["lc"];_flatsql_get_deleted_count=Module["_flatsql_get_deleted_count"]=wasmExports["mc"];_flatsql_clear_tombstones=Module["_flatsql_clear_tombstones"]=wasmExports["nc"];_flatsql_get_sources_count=Module["_flatsql_get_sources_count"]=wasmExports["oc"];_flatsql_get_source_name=Module["_flatsql_get_source_name"]=wasmExports["pc"];_flatsql_get_flatbuffer_by_id=Module["_flatsql_get_flatbuffer_by_id"]=wasmExports["qc"];_flatsql_get_flatbuffer_by_email=Module["_flatsql_get_flatbuffer_by_email"]=wasmExports["rc"];_flatsql_get_flatbuffer_by_index=Module["_flatsql_get_flatbuffer_by_index"]=wasmExports["sc"];_flatsql_get_raw_flatbuffer_size=Module["_flatsql_get_raw_flatbuffer_size"]=wasmExports["tc"];_flatsql_get_raw_flatbuffer_sequence=Module["_flatsql_get_raw_flatbuffer_sequence"]=wasmExports["uc"];_flatsql_get_storage_buffer=Module["_flatsql_get_storage_buffer"]=wasmExports["vc"];_flatsql_get_storage_size=Module["_flatsql_get_storage_size"]=wasmExports["wc"];_flatsql_set_encryption_key=Module["_flatsql_set_encryption_key"]=wasmExports["xc"];_flatsql_is_encrypted=Module["_flatsql_is_encrypted"]=wasmExports["yc"];_flatsql_encrypt_buffer=Module["_flatsql_encrypt_buffer"]=wasmExports["zc"];_flatsql_decrypt_buffer=Module["_flatsql_decrypt_buffer"]=wasmExports["Ac"];_flatsql_set_hmac_verification=Module["_flatsql_set_hmac_verification"]=wasmExports["Bc"];_flatsql_is_hmac_enabled=Module["_flatsql_is_hmac_enabled"]=wasmExports["Cc"];_flatsql_compute_hmac=Module["_flatsql_compute_hmac"]=wasmExports["Dc"];_flatsql_verify_hmac=Module["_flatsql_verify_hmac"]=wasmExports["Ec"];_setThrew=wasmExports["Fc"];__emscripten_tempret_set=wasmExports["Gc"];__emscripten_stack_restore=wasmExports["Hc"];__emscripten_stack_alloc=wasmExports["Ic"];_emscripten_stack_get_current=wasmExports["Jc"];___cxa_decrement_exception_refcount=wasmExports["Kc"];___cxa_increment_exception_refcount=wasmExports["Lc"];___cxa_can_catch=wasmExports["Mc"];___cxa_get_exception_ptr=wasmExports["Nc"];dynCall_v=wasmExports["Oc"];dynCall_ii=wasmExports["Pc"];dynCall_iii=wasmExports["Qc"];dynCall_viiiiii=wasmExports["Rc"];dynCall_vii=wasmExports["Sc"];dynCall_viii=wasmExports["Tc"];dynCall_iiii=wasmExports["Uc"];dynCall_iiiiii=wasmExports["Vc"];dynCall_vi=wasmExports["Wc"];dynCall_viiii=wasmExports["Xc"];dynCall_jii=wasmExports["Yc"];dynCall_viiiii=wasmExports["Zc"];dynCall_iiiiiii=wasmExports["_c"];dynCall_iiiii=wasmExports["$c"];dynCall_iiij=wasmExports["ad"];dynCall_iiid=wasmExports["bd"];dynCall_viijij=wasmExports["cd"];dynCall_viiijj=wasmExports["dd"];dynCall_jiiiii=wasmExports["ed"];dynCall_viiiiiiiiii=wasmExports["fd"];dynCall_vij=wasmExports["gd"];dynCall_iiji=wasmExports["hd"];dynCall_iijiii=wasmExports["id"];dynCall_viij=wasmExports["jd"];dynCall_iid=wasmExports["kd"];dynCall_i=wasmExports["ld"];dynCall_dii=wasmExports["md"];dynCall_di=wasmExports["nd"];dynCall_iiiid=wasmExports["od"];dynCall_iij=wasmExports["pd"];dynCall_viidi=wasmExports["qd"];dynCall_vid=wasmExports["rd"];dynCall_vidd=wasmExports["dynCall_vidd"];dynCall_dd=wasmExports["dynCall_dd"];dynCall_ddd=wasmExports["dynCall_ddd"];dynCall_jiiii=wasmExports["sd"];dynCall_viiiiiiii=wasmExports["td"];dynCall_iiiddddddddi=wasmExports["ud"];dynCall_iiiij=wasmExports["dynCall_iiiij"];dynCall_iijj=wasmExports["dynCall_iijj"];dynCall_iijii=wasmExports["dynCall_iijii"];dynCall_iidiiii=wasmExports["dynCall_iidiiii"];dynCall_j=wasmExports["vd"];dynCall_iiiiid=wasmExports["wd"];dynCall_viijii=wasmExports["dynCall_viijii"];dynCall_iiiiiiii=wasmExports["xd"];dynCall_iiiiiiiiiii=wasmExports["dynCall_iiiiiiiiiii"];dynCall_iiiiiiiiiiiii=wasmExports["dynCall_iiiiiiiiiiiii"];dynCall_fiii=wasmExports["yd"];dynCall_diii=wasmExports["zd"];dynCall_viiiiiii=wasmExports["Ad"];dynCall_iiiiiiiiiiii=wasmExports["Bd"];dynCall_viiiiiiiiiiiiiii=wasmExports["Cd"];dynCall_iiiiiiiii=wasmExports["dynCall_iiiiiiiii"];dynCall_iiiiij=wasmExports["dynCall_iiiiij"];dynCall_iiiiijj=wasmExports["dynCall_iiiiijj"];dynCall_iiiiiijj=wasmExports["dynCall_iiiiiijj"];memory=wasmMemory=wasmExports["Ma"];__indirect_function_table=wasmTable=wasmExports["Oa"]}var wasmImports={k:___cxa_begin_catch,q:___cxa_end_catch,a:___cxa_find_matching_catch_2,d:___cxa_find_matching_catch_3,u:___cxa_find_matching_catch_4,Y:___cxa_rethrow,o:___cxa_throw,ca:___cxa_uncaught_exceptions,e:___resumeException,Ca:___syscall_chmod,Ea:___syscall_faccessat,Da:___syscall_fchmod,Ba:___syscall_fchown32,y:___syscall_fcntl64,Aa:___syscall_fstat64,va:___syscall_ftruncate64,ua:___syscall_getcwd,xa:___syscall_lstat64,qa:___syscall_mkdirat,ya:___syscall_newfstatat,ma:___syscall_openat,ka:___syscall_readlinkat,ja:___syscall_rmdir,za:___syscall_stat64,ha:___syscall_unlinkat,ga:___syscall_utimensat,aa:__abort_js,oa:__localtime_js,pa:__tzset_js,na:_clock_time_get,P:_emscripten_date_now,O:_emscripten_get_now,ea:_emscripten_resize_heap,sa:_environ_get,ta:_environ_sizes_get,Q:_fd_close,fa:_fd_fdstat_get,la:_fd_read,ra:_fd_seek,wa:_fd_sync,ia:_fd_write,U:_flatsql_io_close,z:_flatsql_io_open,W:_flatsql_io_read,X:_flatsql_io_size,S:_flatsql_io_sync,Fa:_flatsql_io_truncate,T:_flatsql_io_write,x:invoke_di,H:invoke_dii,K:invoke_diii,M:invoke_fiii,t:invoke_i,c:invoke_ii,L:invoke_iid,g:invoke_iii,I:invoke_iiid,Ga:invoke_iiiddddddddi,h:invoke_iiii,V:invoke_iiiid,n:invoke_iiiii,ba:invoke_iiiiid,m:invoke_iiiiii,s:invoke_iiiiiii,N:invoke_iiiiiiii,F:invoke_iiiiiiiiiiii,La:invoke_iiij,Ia:invoke_iij,C:invoke_iiji,Ja:invoke_iijiii,da:invoke_j,J:invoke_jii,D:invoke_jiiii,Z:invoke_jiiiii,f:invoke_v,l:invoke_vi,G:invoke_vid,b:invoke_vii,R:invoke_viidi,i:invoke_viii,j:invoke_viiii,v:invoke_viiiii,r:invoke_viiiiii,w:invoke_viiiiiii,Ha:invoke_viiiiiiii,A:invoke_viiiiiiiiii,E:invoke_viiiiiiiiiiiiiii,_:invoke_viiijj,$:invoke_viij,Ka:invoke_viijij,B:invoke_vij,p:_llvm_eh_typeid_for};function invoke_v(index){var sp=stackSave();try{dynCall_v(index)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_ii(index,a1){var sp=stackSave();try{return dynCall_ii(index,a1)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_iii(index,a1,a2){var sp=stackSave();try{return dynCall_iii(index,a1,a2)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_viiiiii(index,a1,a2,a3,a4,a5,a6){var sp=stackSave();try{dynCall_viiiiii(index,a1,a2,a3,a4,a5,a6)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_vii(index,a1,a2){var sp=stackSave();try{dynCall_vii(index,a1,a2)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_vij(index,a1,a2){var sp=stackSave();try{dynCall_vij(index,a1,a2)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_iiii(index,a1,a2,a3){var sp=stackSave();try{return dynCall_iiii(index,a1,a2,a3)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_viii(index,a1,a2,a3){var sp=stackSave();try{dynCall_viii(index,a1,a2,a3)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_iiiiii(index,a1,a2,a3,a4,a5){var sp=stackSave();try{return dynCall_iiiiii(index,a1,a2,a3,a4,a5)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_vi(index,a1){var sp=stackSave();try{dynCall_vi(index,a1)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_viiii(index,a1,a2,a3,a4){var sp=stackSave();try{dynCall_viiii(index,a1,a2,a3,a4)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_jii(index,a1,a2){var sp=stackSave();try{return dynCall_jii(index,a1,a2)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);return 0n}}function invoke_viiiii(index,a1,a2,a3,a4,a5){var sp=stackSave();try{dynCall_viiiii(index,a1,a2,a3,a4,a5)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_iiiiiii(index,a1,a2,a3,a4,a5,a6){var sp=stackSave();try{return dynCall_iiiiiii(index,a1,a2,a3,a4,a5,a6)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_iiiii(index,a1,a2,a3,a4){var sp=stackSave();try{return dynCall_iiiii(index,a1,a2,a3,a4)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_iiij(index,a1,a2,a3){var sp=stackSave();try{return dynCall_iiij(index,a1,a2,a3)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_iiid(index,a1,a2,a3){var sp=stackSave();try{return dynCall_iiid(index,a1,a2,a3)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_viijij(index,a1,a2,a3,a4,a5){var sp=stackSave();try{dynCall_viijij(index,a1,a2,a3,a4,a5)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_viij(index,a1,a2,a3){var sp=stackSave();try{dynCall_viij(index,a1,a2,a3)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_viiijj(index,a1,a2,a3,a4,a5){var sp=stackSave();try{dynCall_viiijj(index,a1,a2,a3,a4,a5)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_jiiiii(index,a1,a2,a3,a4,a5){var sp=stackSave();try{return dynCall_jiiiii(index,a1,a2,a3,a4,a5)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);return 0n}}function invoke_viiiiiiiiii(index,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10){var sp=stackSave();try{dynCall_viiiiiiiiii(index,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_iiji(index,a1,a2,a3){var sp=stackSave();try{return dynCall_iiji(index,a1,a2,a3)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_iijiii(index,a1,a2,a3,a4,a5){var sp=stackSave();try{return dynCall_iijiii(index,a1,a2,a3,a4,a5)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_iid(index,a1,a2){var sp=stackSave();try{return dynCall_iid(index,a1,a2)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_i(index){var sp=stackSave();try{return dynCall_i(index)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_dii(index,a1,a2){var sp=stackSave();try{return dynCall_dii(index,a1,a2)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_di(index,a1){var sp=stackSave();try{return dynCall_di(index,a1)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_iiiid(index,a1,a2,a3,a4){var sp=stackSave();try{return dynCall_iiiid(index,a1,a2,a3,a4)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_iij(index,a1,a2){var sp=stackSave();try{return dynCall_iij(index,a1,a2)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_viidi(index,a1,a2,a3,a4){var sp=stackSave();try{dynCall_viidi(index,a1,a2,a3,a4)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_vid(index,a1,a2){var sp=stackSave();try{dynCall_vid(index,a1,a2)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_jiiii(index,a1,a2,a3,a4){var sp=stackSave();try{return dynCall_jiiii(index,a1,a2,a3,a4)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);return 0n}}function invoke_viiiiiiii(index,a1,a2,a3,a4,a5,a6,a7,a8){var sp=stackSave();try{dynCall_viiiiiiii(index,a1,a2,a3,a4,a5,a6,a7,a8)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_iiiddddddddi(index,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11){var sp=stackSave();try{return dynCall_iiiddddddddi(index,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_j(index){var sp=stackSave();try{return dynCall_j(index)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);return 0n}}function invoke_iiiiid(index,a1,a2,a3,a4,a5){var sp=stackSave();try{return dynCall_iiiiid(index,a1,a2,a3,a4,a5)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_iiiiiiii(index,a1,a2,a3,a4,a5,a6,a7){var sp=stackSave();try{return dynCall_iiiiiiii(index,a1,a2,a3,a4,a5,a6,a7)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_fiii(index,a1,a2,a3){var sp=stackSave();try{return dynCall_fiii(index,a1,a2,a3)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_diii(index,a1,a2,a3){var sp=stackSave();try{return dynCall_diii(index,a1,a2,a3)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_viiiiiii(index,a1,a2,a3,a4,a5,a6,a7){var sp=stackSave();try{dynCall_viiiiiii(index,a1,a2,a3,a4,a5,a6,a7)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_iiiiiiiiiiii(index,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11){var sp=stackSave();try{return dynCall_iiiiiiiiiiii(index,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_viiiiiiiiiiiiiii(index,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15){var sp=stackSave();try{dynCall_viiiiiiiiiiiiiii(index,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function applySignatureConversions(wasmExports){wasmExports=Object.assign({},wasmExports);var makeWrapper_pp=f=>a0=>f(a0)>>>0;var makeWrapper_p=f=>()=>f()>>>0;wasmExports["Qa"]=makeWrapper_pp(wasmExports["Qa"]);wasmExports["Ic"]=makeWrapper_pp(wasmExports["Ic"]);wasmExports["Jc"]=makeWrapper_p(wasmExports["Jc"]);wasmExports["Nc"]=makeWrapper_pp(wasmExports["Nc"]);return wasmExports}function run(){preRun();function doRun(){Module["calledRun"]=true;if(ABORT)return;initRuntime();readyPromiseResolve?.(Module);Module["onRuntimeInitialized"]?.();postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout(()=>{setTimeout(()=>Module["setStatus"](""),1);doRun()},1)}else{doRun()}}var wasmExports;wasmExports=await (createWasm());run();if(runtimeInitialized){moduleRtn=Module}else{moduleRtn=new Promise((resolve,reject)=>{readyPromiseResolve=resolve;readyPromiseReject=reject})}
|
|
2
2
|
;return moduleRtn}export default FlatSQL;
|
package/wasm/flatsql.wasm
CHANGED
|
Binary file
|
package/wasm/index.js
CHANGED
|
@@ -144,6 +144,13 @@ async function loadIntegrityFile(basePath = '') {
|
|
|
144
144
|
* // Skip integrity check (development only)
|
|
145
145
|
* const flatsql = await initFlatSQL({ skipIntegrityCheck: true });
|
|
146
146
|
*/
|
|
147
|
+
let ioBackend = null;
|
|
148
|
+
|
|
149
|
+
/** The I/O backend this runtime was initialised with (null when ephemeral). */
|
|
150
|
+
export function getFlatSqlIoBackend() {
|
|
151
|
+
return ioBackend;
|
|
152
|
+
}
|
|
153
|
+
|
|
147
154
|
export async function initFlatSQL(moduleFactoryOrOptions) {
|
|
148
155
|
let moduleFactory = FlatSQLModule;
|
|
149
156
|
let options = {};
|
|
@@ -184,6 +191,16 @@ export async function initFlatSQL(moduleFactoryOrOptions) {
|
|
|
184
191
|
// Create module configuration
|
|
185
192
|
const moduleConfig = {};
|
|
186
193
|
|
|
194
|
+
// The seven-import host I/O contract (cpp/include/flatsql/flatsql_io.h).
|
|
195
|
+
// cpp/js/flatsql_io_library.js reads this off the Module and translates
|
|
196
|
+
// pointers into typed arrays; everything else about storage lives in the
|
|
197
|
+
// backend. With no backend, disk-backed opens fail closed with an error
|
|
198
|
+
// value — they never quietly succeed against RAM.
|
|
199
|
+
ioBackend = options.io ?? null;
|
|
200
|
+
if (ioBackend) {
|
|
201
|
+
moduleConfig.flatsqlIO = ioBackend;
|
|
202
|
+
}
|
|
203
|
+
|
|
187
204
|
// If we have an expected hash, use custom WASM instantiation with verification
|
|
188
205
|
if (expectedIntegrity && !options.skipIntegrityCheck) {
|
|
189
206
|
moduleConfig.instantiateWasm = async (imports, successCallback) => {
|
|
@@ -243,6 +260,13 @@ export async function initFlatSQL(moduleFactoryOrOptions) {
|
|
|
243
260
|
api = {
|
|
244
261
|
// Database lifecycle
|
|
245
262
|
createDb: Module.cwrap('flatsql_create_db', 'number', ['string', 'string']),
|
|
263
|
+
openDb: Module.cwrap('flatsql_open_db', 'number', ['string', 'string', 'string', 'number']),
|
|
264
|
+
isDiskBacked: Module.cwrap('flatsql_is_disk_backed', 'number', ['number']),
|
|
265
|
+
openState: Module.cwrap('flatsql_open_state', 'number', ['number']),
|
|
266
|
+
reindexAll: Module.cwrap('flatsql_reindex_all', 'number', ['number']),
|
|
267
|
+
flushIndex: Module.cwrap('flatsql_flush_index', 'number', ['number']),
|
|
268
|
+
flushedOffset: Module.cwrap('flatsql_flushed_offset', 'number', ['number']),
|
|
269
|
+
streamPath: Module.cwrap('flatsql_stream_path', 'string', ['number']),
|
|
246
270
|
destroyDb: Module.cwrap('flatsql_destroy_db', null, ['number']),
|
|
247
271
|
registerFileId: Module.cwrap('flatsql_register_file_id', null, ['number', 'string', 'string']),
|
|
248
272
|
enableDemoExtractors: Module.cwrap('flatsql_enable_demo_extractors', null, ['number']),
|
|
@@ -550,6 +574,30 @@ export class FlatSQL {
|
|
|
550
574
|
return new FlatSQLDatabase(handle);
|
|
551
575
|
}
|
|
552
576
|
|
|
577
|
+
/**
|
|
578
|
+
* Disk-backed open through the I/O backend passed to initFlatSQL.
|
|
579
|
+
*
|
|
580
|
+
* `path` is a name in the BACKEND's namespace — a real path under a WASI
|
|
581
|
+
* preopen on the server, a key prefix in a browser store. The module never
|
|
582
|
+
* learns which, which is what makes one artifact work in both.
|
|
583
|
+
*
|
|
584
|
+
* journalMode: 0 DELETE, 1 WAL (not available on wasm — no xShmMap in
|
|
585
|
+
* either lane), 2 TRUNCATE (the wasm default, crash-safe under the single
|
|
586
|
+
* writer the one-daemon-per-box law guarantees), 3 MEMORY.
|
|
587
|
+
*
|
|
588
|
+
* Async backends must be hydrated BEFORE this call and flushed after
|
|
589
|
+
* flushIndex(); see wasm/flatsql-io.js.
|
|
590
|
+
*/
|
|
591
|
+
openDatabase(schema, dbName = 'default', path = '', journalMode = 2) {
|
|
592
|
+
const handle = api.openDb(schema, dbName, path ?? '', journalMode);
|
|
593
|
+
if (!handle) {
|
|
594
|
+
throw new Error(
|
|
595
|
+
`Failed to open FlatSQL database at "${path}": ${api.getError() || 'unknown error'}`
|
|
596
|
+
);
|
|
597
|
+
}
|
|
598
|
+
return new FlatSQLDatabase(handle);
|
|
599
|
+
}
|
|
600
|
+
|
|
553
601
|
// Create test FlatBuffers
|
|
554
602
|
createTestUser(id, name, email, age) {
|
|
555
603
|
const ptr = api.createTestUser(id, name, email, age);
|
|
@@ -660,6 +708,42 @@ export class FlatSQLDatabase {
|
|
|
660
708
|
this._handle = handle;
|
|
661
709
|
}
|
|
662
710
|
|
|
711
|
+
// ---- Durable state (docs/STORAGE-DURABILITY.md §3.3) ------------------
|
|
712
|
+
// Codes are VALUES, never throws:
|
|
713
|
+
// >=0 record count / OK -1 absent -2 format or schema mismatch
|
|
714
|
+
// -3 corrupt -4 torn pair (stream shorter than the mark)
|
|
715
|
+
// -5 no filesystem
|
|
716
|
+
// Every negative is recoverable with reindexAll(); none means data loss.
|
|
717
|
+
|
|
718
|
+
isDiskBacked() {
|
|
719
|
+
return api.isDiskBacked(this._handle) === 1;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
/** Boot: verify persisted state, replay only the stream tail. */
|
|
723
|
+
openState() {
|
|
724
|
+
return api.openState(this._handle);
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
/** Full re-derivation from the stream. Always available. */
|
|
728
|
+
reindexAll() {
|
|
729
|
+
return api.reindexAll(this._handle);
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
/** Append new stream bytes, sync, then commit the index + high-water mark. */
|
|
733
|
+
flushIndex() {
|
|
734
|
+
return api.flushIndex(this._handle);
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
/** High-water mark a host may resume its own journal from. */
|
|
738
|
+
flushedOffset() {
|
|
739
|
+
return api.flushedOffset(this._handle);
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
/** Path of the SDS FlatBuffer stream backing this handle. */
|
|
743
|
+
streamPath() {
|
|
744
|
+
return api.streamPath(this._handle);
|
|
745
|
+
}
|
|
746
|
+
|
|
663
747
|
destroy() {
|
|
664
748
|
if (this._handle) {
|
|
665
749
|
api.destroyDb(this._handle);
|
package/wasm/standalone.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { createFlatSqlIoImports, createMemoryBackend } from './flatsql-io.js';
|
|
2
|
+
|
|
1
3
|
const DEFAULT_STANDALONE_URL = new URL('./flatsql-wasi.wasm', import.meta.url);
|
|
2
4
|
|
|
3
5
|
const PARAM_NULL = 0;
|
|
@@ -382,10 +384,25 @@ export async function loadFlatSQLStandalone(options = {}) {
|
|
|
382
384
|
const wasmBytes = await loadWasmBytes(options);
|
|
383
385
|
const state = { memory: null };
|
|
384
386
|
const imports = makeWasiImports(state, options.wasi ?? options);
|
|
387
|
+
|
|
388
|
+
// The seven-import host I/O contract (cpp/include/flatsql/flatsql_io.h).
|
|
389
|
+
// The module imports these unconditionally, so they are always supplied: with
|
|
390
|
+
// no backend the default is in-memory, which keeps the historical ephemeral
|
|
391
|
+
// behaviour byte-for-byte and never pretends a path is durable.
|
|
392
|
+
const io = options.io ?? createMemoryBackend();
|
|
393
|
+
imports.env = {
|
|
394
|
+
...createFlatSqlIoImports(io, () => state.memory),
|
|
395
|
+
...(imports.env ?? {}),
|
|
396
|
+
};
|
|
397
|
+
|
|
385
398
|
const mergedImports = options.imports
|
|
386
399
|
? {
|
|
387
400
|
...imports,
|
|
388
401
|
...options.imports,
|
|
402
|
+
env: {
|
|
403
|
+
...imports.env,
|
|
404
|
+
...(options.imports.env ?? {}),
|
|
405
|
+
},
|
|
389
406
|
wasi_snapshot_preview1: {
|
|
390
407
|
...imports.wasi_snapshot_preview1,
|
|
391
408
|
...(options.imports.wasi_snapshot_preview1 ?? {}),
|
|
@@ -399,16 +416,45 @@ export async function loadFlatSQLStandalone(options = {}) {
|
|
|
399
416
|
instance.exports._initialize();
|
|
400
417
|
}
|
|
401
418
|
|
|
402
|
-
return new FlatSQLStandalone(createRuntime(instance.exports), module);
|
|
419
|
+
return new FlatSQLStandalone(createRuntime(instance.exports), module, io);
|
|
403
420
|
}
|
|
404
421
|
|
|
405
422
|
export const createStandaloneFlatSQL = loadFlatSQLStandalone;
|
|
406
423
|
|
|
407
424
|
export class FlatSQLStandalone {
|
|
408
|
-
constructor(runtime, module) {
|
|
425
|
+
constructor(runtime, module, io) {
|
|
409
426
|
this._runtime = runtime;
|
|
410
427
|
this.module = module;
|
|
411
428
|
this.memory = runtime.memory;
|
|
429
|
+
// The I/O backend this instance was wired to. Callers await io.hydrate()
|
|
430
|
+
// before opening a disk-backed database and io.flush() after
|
|
431
|
+
// flushIndex(); on synchronous backends both are no-ops.
|
|
432
|
+
this.io = io ?? null;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Disk-backed open. `path` is a name in the backend's namespace — a real
|
|
437
|
+
* path under a WASI preopen, a key prefix in a browser store. The module
|
|
438
|
+
* never learns which, and that is the point.
|
|
439
|
+
*
|
|
440
|
+
* journalMode: 0 DELETE, 1 WAL (unavailable on wasm), 2 TRUNCATE, 3 MEMORY.
|
|
441
|
+
* TRUNCATE is the wasm default because WAL needs xShmMap shared memory that
|
|
442
|
+
* neither lane provides (docs/STORAGE-DURABILITY.md §3.5).
|
|
443
|
+
*/
|
|
444
|
+
openDatabase(schema, dbName = 'default', path = '', journalMode = 2) {
|
|
445
|
+
const handle = this._runtime.withCString(schema, (schemaPtr) =>
|
|
446
|
+
this._runtime.withCString(dbName, (namePtr) =>
|
|
447
|
+
this._runtime.withCString(path ?? '', (pathPtr) =>
|
|
448
|
+
this._runtime.exports.flatsql_open_db(schemaPtr, namePtr, pathPtr, journalMode)
|
|
449
|
+
)
|
|
450
|
+
)
|
|
451
|
+
);
|
|
452
|
+
if (!handle) {
|
|
453
|
+
const errPtr = this._runtime.exports.flatsql_get_error();
|
|
454
|
+
const message = errPtr ? this._runtime.readCString(errPtr) : 'unknown error';
|
|
455
|
+
throw new Error(`Failed to open FlatSQL database at "${path}": ${message}`);
|
|
456
|
+
}
|
|
457
|
+
return new FlatSQLStandaloneDatabase(this._runtime, handle);
|
|
412
458
|
}
|
|
413
459
|
|
|
414
460
|
createDatabase(schema, dbName = 'default') {
|
|
@@ -533,6 +579,37 @@ export class FlatSQLStandaloneDatabase {
|
|
|
533
579
|
}
|
|
534
580
|
}
|
|
535
581
|
|
|
582
|
+
// ---- Durable state (docs/STORAGE-DURABILITY.md §3.3) --------------------
|
|
583
|
+
// Codes are values, never throws:
|
|
584
|
+
// >=0 record count / OK -1 absent -2 format or schema -3 corrupt
|
|
585
|
+
// -4 torn pair -5 no filesystem
|
|
586
|
+
// EVERY negative is recoverable with reindexAll(); none means data loss.
|
|
587
|
+
|
|
588
|
+
isDiskBacked() {
|
|
589
|
+
return this._runtime.exports.flatsql_is_disk_backed(this._handle) === 1;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
openState() {
|
|
593
|
+
return this._runtime.exports.flatsql_open_state(this._handle);
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
reindexAll() {
|
|
597
|
+
return this._runtime.exports.flatsql_reindex_all(this._handle);
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
flushIndex() {
|
|
601
|
+
return this._runtime.exports.flatsql_flush_index(this._handle);
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
flushedOffset() {
|
|
605
|
+
return this._runtime.exports.flatsql_flushed_offset(this._handle);
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
streamPath() {
|
|
609
|
+
const ptr = this._runtime.exports.flatsql_stream_path(this._handle);
|
|
610
|
+
return ptr ? this._runtime.readCString(ptr) : '';
|
|
611
|
+
}
|
|
612
|
+
|
|
536
613
|
registerFileId(fileId, tableName) {
|
|
537
614
|
this._runtime.withCString(fileId, (filePtr) =>
|
|
538
615
|
this._runtime.withCString(tableName, (tablePtr) =>
|