flatsql 3.11.0 → 3.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. package/README.md +61 -795
  2. package/bin/flatsql.mjs +76 -0
  3. package/cpp/README.md +18 -0
  4. package/cpp/include/flatsql/flatsql.h +162 -0
  5. package/cpp/include/flatsql/flatsql_io.h +159 -0
  6. package/docs/API-3.12.md +114 -0
  7. package/package.json +28 -123
  8. package/wasm/flatsql.wasm +0 -0
  9. package/wasm/index.d.ts +61 -548
  10. package/wasm/index.js +280 -1281
  11. package/wasm/integrity.json +6 -26
  12. package/wasm/runtime/LICENSE.sdk.txt +190 -0
  13. package/wasm/runtime/NOTICE.txt +2 -0
  14. package/wasm/runtime/browser-guest.mjs +1 -0
  15. package/wasm/runtime/browser-host.mjs +1 -0
  16. package/wasm/runtime/node-guest.mjs +2 -0
  17. package/wasm/runtime/node-host.mjs +5 -0
  18. package/wasm/runtime/opfsIoWorker.mjs +1 -0
  19. package/wasm/runtime/wasiThreadBrowserWorker.mjs +1 -0
  20. package/dist/artifacts/index.d.ts +0 -3
  21. package/dist/artifacts/index.d.ts.map +0 -1
  22. package/dist/artifacts/index.js +0 -3
  23. package/dist/artifacts/index.js.map +0 -1
  24. package/dist/artifacts/transport.d.ts +0 -5
  25. package/dist/artifacts/transport.d.ts.map +0 -1
  26. package/dist/artifacts/transport.js +0 -45
  27. package/dist/artifacts/transport.js.map +0 -1
  28. package/dist/artifacts/types.d.ts +0 -34
  29. package/dist/artifacts/types.d.ts.map +0 -1
  30. package/dist/artifacts/types.js +0 -2
  31. package/dist/artifacts/types.js.map +0 -1
  32. package/dist/btree/btree.d.ts +0 -34
  33. package/dist/btree/btree.d.ts.map +0 -1
  34. package/dist/btree/btree.js +0 -234
  35. package/dist/btree/btree.js.map +0 -1
  36. package/dist/btree/index.d.ts +0 -3
  37. package/dist/btree/index.d.ts.map +0 -1
  38. package/dist/btree/index.js +0 -3
  39. package/dist/btree/index.js.map +0 -1
  40. package/dist/btree/types.d.ts +0 -36
  41. package/dist/btree/types.d.ts.map +0 -1
  42. package/dist/btree/types.js +0 -55
  43. package/dist/btree/types.js.map +0 -1
  44. package/dist/cluster/index.d.ts +0 -11
  45. package/dist/cluster/index.d.ts.map +0 -1
  46. package/dist/cluster/index.js +0 -59
  47. package/dist/cluster/index.js.map +0 -1
  48. package/dist/response/artifact.d.ts +0 -4
  49. package/dist/response/artifact.d.ts.map +0 -1
  50. package/dist/response/artifact.js +0 -102
  51. package/dist/response/artifact.js.map +0 -1
  52. package/dist/response/cache-key.d.ts +0 -6
  53. package/dist/response/cache-key.d.ts.map +0 -1
  54. package/dist/response/cache-key.js +0 -114
  55. package/dist/response/cache-key.js.map +0 -1
  56. package/dist/response/index.d.ts +0 -5
  57. package/dist/response/index.d.ts.map +0 -1
  58. package/dist/response/index.js +0 -5
  59. package/dist/response/index.js.map +0 -1
  60. package/dist/response/memory-cache.d.ts +0 -17
  61. package/dist/response/memory-cache.d.ts.map +0 -1
  62. package/dist/response/memory-cache.js +0 -76
  63. package/dist/response/memory-cache.js.map +0 -1
  64. package/dist/response/types.d.ts +0 -57
  65. package/dist/response/types.d.ts.map +0 -1
  66. package/dist/response/types.js +0 -2
  67. package/dist/response/types.js.map +0 -1
  68. package/dist/schema/index.d.ts +0 -3
  69. package/dist/schema/index.d.ts.map +0 -1
  70. package/dist/schema/index.js +0 -3
  71. package/dist/schema/index.js.map +0 -1
  72. package/dist/schema/parser.d.ts +0 -25
  73. package/dist/schema/parser.d.ts.map +0 -1
  74. package/dist/schema/parser.js +0 -474
  75. package/dist/schema/parser.js.map +0 -1
  76. package/dist/schema/types.d.ts +0 -33
  77. package/dist/schema/types.d.ts.map +0 -1
  78. package/dist/schema/types.js +0 -29
  79. package/dist/schema/types.js.map +0 -1
  80. package/dist/standalone/index.d.ts +0 -3
  81. package/dist/standalone/index.d.ts.map +0 -1
  82. package/dist/standalone/index.js +0 -3
  83. package/dist/standalone/index.js.map +0 -1
  84. package/dist/standalone/process-client.d.ts +0 -85
  85. package/dist/standalone/process-client.d.ts.map +0 -1
  86. package/dist/standalone/process-client.js +0 -537
  87. package/dist/standalone/process-client.js.map +0 -1
  88. package/dist/standalone/wasmedge-runner.d.ts +0 -19
  89. package/dist/standalone/wasmedge-runner.d.ts.map +0 -1
  90. package/dist/standalone/wasmedge-runner.js +0 -108
  91. package/dist/standalone/wasmedge-runner.js.map +0 -1
  92. package/dist/storage/index.d.ts +0 -3
  93. package/dist/storage/index.d.ts.map +0 -1
  94. package/dist/storage/index.js +0 -3
  95. package/dist/storage/index.js.map +0 -1
  96. package/dist/storage/stacked-flatbuffers.d.ts +0 -38
  97. package/dist/storage/stacked-flatbuffers.d.ts.map +0 -1
  98. package/dist/storage/stacked-flatbuffers.js +0 -253
  99. package/dist/storage/stacked-flatbuffers.js.map +0 -1
  100. package/dist/storage/types.d.ts +0 -23
  101. package/dist/storage/types.d.ts.map +0 -1
  102. package/dist/storage/types.js +0 -27
  103. package/dist/storage/types.js.map +0 -1
  104. package/dist/stress/aggregate.d.ts +0 -3
  105. package/dist/stress/aggregate.d.ts.map +0 -1
  106. package/dist/stress/aggregate.js +0 -61
  107. package/dist/stress/aggregate.js.map +0 -1
  108. package/dist/stress/docker-compose.d.ts +0 -17
  109. package/dist/stress/docker-compose.d.ts.map +0 -1
  110. package/dist/stress/docker-compose.js +0 -156
  111. package/dist/stress/docker-compose.js.map +0 -1
  112. package/dist/stress/index.d.ts +0 -10
  113. package/dist/stress/index.d.ts.map +0 -1
  114. package/dist/stress/index.js +0 -10
  115. package/dist/stress/index.js.map +0 -1
  116. package/dist/stress/metrics.d.ts +0 -3
  117. package/dist/stress/metrics.d.ts.map +0 -1
  118. package/dist/stress/metrics.js +0 -83
  119. package/dist/stress/metrics.js.map +0 -1
  120. package/dist/stress/native-publish-event-workload.d.ts +0 -3
  121. package/dist/stress/native-publish-event-workload.d.ts.map +0 -1
  122. package/dist/stress/native-publish-event-workload.js +0 -465
  123. package/dist/stress/native-publish-event-workload.js.map +0 -1
  124. package/dist/stress/production-gate.d.ts +0 -4
  125. package/dist/stress/production-gate.d.ts.map +0 -1
  126. package/dist/stress/production-gate.js +0 -12
  127. package/dist/stress/production-gate.js.map +0 -1
  128. package/dist/stress/report.d.ts +0 -3
  129. package/dist/stress/report.d.ts.map +0 -1
  130. package/dist/stress/report.js +0 -174
  131. package/dist/stress/report.js.map +0 -1
  132. package/dist/stress/sds-discovery.d.ts +0 -4
  133. package/dist/stress/sds-discovery.d.ts.map +0 -1
  134. package/dist/stress/sds-discovery.js +0 -40
  135. package/dist/stress/sds-discovery.js.map +0 -1
  136. package/dist/stress/smoke-runner.d.ts +0 -3
  137. package/dist/stress/smoke-runner.d.ts.map +0 -1
  138. package/dist/stress/smoke-runner.js +0 -64
  139. package/dist/stress/smoke-runner.js.map +0 -1
  140. package/dist/stress/types.d.ts +0 -219
  141. package/dist/stress/types.d.ts.map +0 -1
  142. package/dist/stress/types.js +0 -2
  143. package/dist/stress/types.js.map +0 -1
  144. package/dist/stress/workload.d.ts +0 -6
  145. package/dist/stress/workload.d.ts.map +0 -1
  146. package/dist/stress/workload.js +0 -144
  147. package/dist/stress/workload.js.map +0 -1
  148. package/docs/PARTITION-STORE-WASM.md +0 -338
  149. package/docs/PARTITION-STORE.md +0 -2380
  150. package/docs/agents/response-artifacts.md +0 -65
  151. package/docs/response-artifacts.md +0 -86
  152. package/scripts/stress-docker.sh +0 -279
  153. package/sdm/flatsql-spatial.wasm +0 -0
  154. package/sdm/index.d.ts +0 -88
  155. package/sdm/index.js +0 -253
  156. package/sdm/manifest.json +0 -402
  157. package/stress/docker/Dockerfile +0 -11
  158. package/stress/docker/docker-compose.yml +0 -51
  159. package/stress/sds/aggregate.mjs +0 -97
  160. package/stress/sds/run.mjs +0 -105
  161. package/stress/sds/write-compose.mjs +0 -96
  162. package/wasm/flatsql-client.js +0 -280
  163. package/wasm/flatsql-io.d.ts +0 -97
  164. package/wasm/flatsql-io.js +0 -621
  165. package/wasm/flatsql-p4-threads.wasm +0 -0
  166. package/wasm/flatsql-ps-threads.wasm +0 -0
  167. package/wasm/flatsql-wasi-noeh.wasm +0 -0
  168. package/wasm/flatsql-wasi.wasm +0 -0
  169. package/wasm/flatsql.js +0 -2
  170. package/wasm/flatsql.worker.js +0 -209
  171. package/wasm/native/flatsql_wasmedge_runner.cpp +0 -858
  172. package/wasm/ps-node-fault.d.mts +0 -23
  173. package/wasm/ps-node-fault.mjs +0 -381
  174. package/wasm/ps-node-guest.mjs +0 -173
  175. package/wasm/ps-node-host.d.mts +0 -95
  176. package/wasm/ps-node-host.mjs +0 -476
  177. package/wasm/ps-node-imports.mjs +0 -847
  178. package/wasm/ps.d.ts +0 -21
  179. package/wasm/ps.js +0 -75
  180. package/wasm/wasi.d.ts +0 -11
  181. package/wasm/wasi.js +0 -51
package/wasm/index.d.ts CHANGED
@@ -1,549 +1,62 @@
1
- /**
2
- * FlatSQL WASM Module
3
- * SQL queries over raw FlatBuffer storage
4
- */
5
-
6
- import type { FlatSqlIoBackend } from './flatsql-io.js';
7
-
8
- export type { FlatSqlIoBackend };
9
-
10
- export interface QueryResult {
11
- columns: string[];
12
- rows: any[][];
1
+ export class FlatSQLError extends Error { readonly status: number; }
2
+ export interface FlatSQLOptions {
3
+ /** Host filesystem directory in Node; OPFS directory in browsers. */
4
+ root?: string;
5
+ /** Absolute path inside the host's filesystem. */
6
+ path?: string;
7
+ wasmUrl?: string | URL;
8
+ wasmBytes?: Uint8Array;
9
+ verify?: (bytes: Uint8Array) => void | Promise<void>;
10
+ maximumPages?: number;
11
+ requestBytes?: number;
12
+ writers?: number;
13
+ readers?: number;
14
+ backend?: 'opfs' | 'memory';
15
+ workerUrl?: string | URL;
16
+ threadWorkerUrl?: string | URL;
17
+ ioWorkerUrl?: string | URL;
18
+ }
19
+ export interface QueryOptions {
20
+ signal?: AbortSignal;
21
+ timeoutMs?: number;
22
+ maxRows?: number;
23
+ maxRowsExamined?: number;
24
+ maxBytesRead?: number;
25
+ maxResultBytes?: number;
26
+ sandbox?: boolean;
27
+ bulk?: boolean;
28
+ /** SELECT _data returns unchanged size-prefixed records. */
29
+ records?: boolean;
30
+ }
31
+ export interface BinarySchema {
32
+ name: string;
33
+ fileIdentifier: string;
34
+ bfbs: Uint8Array;
35
+ indexRules?: string;
36
+ maxRecordBytes?: number;
37
+ maxRows?: number;
38
+ fullText?: boolean;
39
+ }
40
+ export interface IngestOptions extends QueryOptions {
41
+ /** One opaque signature per input record, in frame order. */
42
+ signatures?: Uint8Array[];
43
+ provider?: string;
44
+ source?: string;
45
+ producer?: string;
46
+ batch?: string;
47
+ timestamp?: number;
48
+ }
49
+ export class FlatSQL {
50
+ static open(options?: FlatSQLOptions): Promise<FlatSQL>;
51
+ registerSchema(schema: BinarySchema): Promise<void>;
52
+ /** Frames are [u32 little-endian length][FlatBuffer payload], concatenated. */
53
+ ingest(type: string, frames: Uint8Array, options?: IngestOptions): Promise<Uint8Array>;
54
+ /** Remove records by their original binary payloads; returns an SDS QRP receipt. */
55
+ remove(type: string, frames: Uint8Array, options?: QueryOptions): Promise<Uint8Array>;
56
+ /** QRP request in; chunks of a size-prefixed QRP result stream out. */
57
+ query(request: Uint8Array, options?: QueryOptions): AsyncGenerator<Uint8Array>;
58
+ execute(request: Uint8Array, options?: QueryOptions): Promise<Uint8Array>;
59
+ surface(options?: QueryOptions): Promise<Uint8Array>;
60
+ setQuota(bytes: number): Promise<void>;
61
+ close(): Promise<void>;
13
62
  }
14
-
15
- export type QueryParam = null | boolean | number | string | Uint8Array;
16
-
17
- export interface QueryRequest {
18
- sql: string;
19
- params?: QueryParam[];
20
- }
21
-
22
- export interface QueryCacheStats {
23
- hits: number;
24
- misses: number;
25
- size: number;
26
- generation: number;
27
- maxEntries: number;
28
- maxRows: number;
29
- }
30
-
31
- export interface QueryCacheConfig {
32
- maxEntries: number;
33
- maxRows: number;
34
- }
35
-
36
- export interface ResponseArtifactCacheKeyOptions {
37
- format?: string;
38
- publishEventKey?: string | null;
39
- projection?: string[];
40
- params?: QueryParam[];
41
- }
42
-
43
- export interface TableStats {
44
- tableName: string;
45
- fileId: string;
46
- recordCount: number;
47
- }
48
-
49
- export interface IngestProfile {
50
- recordCount: number;
51
- byteCount: number;
52
- decodeNanos: number;
53
- appendNanos: number;
54
- indexNanos: number;
55
- }
56
-
57
- export interface FlatSQLDatabase {
58
- isDiskBacked(): boolean;
59
- /** Restore the durable checkpoint and replay its tail; negative means recovery is needed. */
60
- openState(): number;
61
- /** Rebuild the entire index and return its record count, or a negative state code. */
62
- reindexAll(): number;
63
- /** Process at most maxRecords (default 4096). 1 = pending, 0 = complete, negative = error. */
64
- reindexStep(maxRecords?: number): number;
65
- flushIndex(): number;
66
- flushedOffset(): number;
67
- streamPath(): string;
68
- /**
69
- * Register a file identifier to route FlatBuffers to a table
70
- */
71
- registerFileId(fileId: string, tableName: string): void;
72
-
73
- /**
74
- * Enable built-in demo field extractors for User, Post, MPE, Telemetry, and PublishEventRecord tables
75
- */
76
- enableDemoExtractors(): void;
77
-
78
- /**
79
- * Ingest a stream of size-prefixed FlatBuffers
80
- * Format: [4-byte size LE][FlatBuffer][4-byte size LE][FlatBuffer]...
81
- * @param data Stream of size-prefixed FlatBuffers
82
- * @param source Optional source name (requires registerSource() first)
83
- */
84
- ingest(data: Uint8Array, source?: string | null): number;
85
-
86
- /**
87
- * Ingest many raw FlatBuffers through the native bulk-stream path.
88
- * Each buffer is wrapped as a size-prefixed record before transfer.
89
- * @param buffers FlatBuffers without size prefixes
90
- * @param source Optional source name (requires registerSource() first)
91
- */
92
- ingestBuffers(buffers: Uint8Array[], source?: string | null): number;
93
-
94
- /**
95
- * Ingest a single FlatBuffer (without size prefix)
96
- * @param data FlatBuffer data
97
- * @param source Optional source name (requires registerSource() first)
98
- */
99
- ingestOne(data: Uint8Array, source?: string | null): number;
100
-
101
- /**
102
- * Execute a SQL query
103
- */
104
- query(sql: string, params?: QueryParam[]): QueryResult;
105
-
106
- /**
107
- * Register a named SQL template for native cached execution.
108
- */
109
- registerQueryTemplate(queryId: string, sql: string, cacheable?: boolean): void;
110
-
111
- /**
112
- * Execute a registered SQL template through the native result cache.
113
- */
114
- queryTemplate(queryId: string, params?: QueryParam[]): QueryResult;
115
-
116
- /**
117
- * Clear cached query results without unregistering templates.
118
- */
119
- clearQueryCache(): void;
120
-
121
- /**
122
- * Configure native query result cache limits for this database handle.
123
- * Existing cached results are invalidated when limits change.
124
- */
125
- configureQueryCache(config: QueryCacheConfig): void;
126
-
127
- /**
128
- * Read native query result cache counters for this database handle.
129
- */
130
- getQueryCacheStats(): QueryCacheStats;
131
-
132
- /**
133
- * Execute multiple SQL queries and return results in request order
134
- */
135
- queryMany(queries: QueryRequest[]): QueryResult[];
136
-
137
- /**
138
- * Execute a query that returns raw FlatBuffer BLOB cells and serialize them
139
- * as a native size-prefixed response stream.
140
- */
141
- queryRawFlatBufferStream(sql: string, params?: QueryParam[]): Uint8Array;
142
-
143
- /**
144
- * Sandboxed public query (gateway loop G.5): one read-only SELECT under
145
- * the engine authorizer (record tables / shadow tables / unified views
146
- * only), single statement, statement timeout, row/byte caps (reject, not
147
- * truncate). mode "stream" returns aligned size-prefixed frames (all
148
- * cells must be BLOB); mode "json" returns UTF-8 bare-array JSON bytes
149
- * with column names verbatim. Rejections throw "sandbox: <code>: ...".
150
- */
151
- querySandboxed(
152
- sql: string,
153
- params?: QueryParam[],
154
- options?: { mode?: 'stream' | 'json'; maxRows?: number; maxBytes?: number; timeoutMs?: number }
155
- ): { payload: Uint8Array; rows: number; columns: number };
156
- lastRawStreamCacheHit(): boolean;
157
- configureRawStreamCache(maxEntries: number, maxTotalBytes: number): void;
158
- getRawStreamCacheStats(): {
159
- hits: number;
160
- misses: number;
161
- entries: number;
162
- totalBytes: number;
163
- };
164
-
165
- /**
166
- * Export all data as a stream of size-prefixed FlatBuffers
167
- */
168
- exportData(): Uint8Array;
169
-
170
- /**
171
- * Load exported data and rebuild indexes
172
- */
173
- loadAndRebuild(data: Uint8Array): void;
174
-
175
- /**
176
- * Preallocate storage bytes for known large ingest targets
177
- */
178
- reserveStorageBytes(bytes: number): void;
179
-
180
- /**
181
- * Rebuild this database from another database's in-memory storage buffer
182
- */
183
- loadAndRebuildFrom(sourceDb: FlatSQLDatabase): void;
184
-
185
- /**
186
- * Get statistics for all tables
187
- */
188
- getStats(): TableStats[];
189
-
190
- /**
191
- * Reset native ingest profile counters for this database handle.
192
- */
193
- resetIngestProfile(): void;
194
-
195
- /**
196
- * Read native ingest profile counters collected during prior ingest calls.
197
- */
198
- getIngestProfile(): IngestProfile;
199
-
200
- // ==================== Multi-Source API ====================
201
-
202
- /**
203
- * Register a named data source for source-aware ingestion.
204
- * Creates source-specific tables: User@siteA, Post@siteA, etc.
205
- *
206
- * @example
207
- * db.registerSource('siteA');
208
- * db.registerSource('siteB');
209
- * db.createUnifiedViews();
210
- *
211
- * // Now ingest to specific sources
212
- * db.ingest(streamA, 'siteA');
213
- * db.ingest(streamB, 'siteB');
214
- *
215
- * // Query specific source
216
- * db.query('SELECT * FROM "User@siteA"');
217
- *
218
- * // Query all sources (unified view)
219
- * db.query('SELECT * FROM User');
220
- */
221
- registerSource(sourceName: string): void;
222
-
223
- /**
224
- * Create unified views for cross-source queries.
225
- * Call this after registering all sources and file IDs.
226
- * Creates views like "User" that combine User@siteA, User@siteB, etc.
227
- */
228
- createUnifiedViews(): void;
229
-
230
- /**
231
- * List registered source names
232
- */
233
- listSources(): string[];
234
-
235
- // ==================== Delete Support ====================
236
-
237
- /**
238
- * Mark a record as deleted by table name and row ID
239
- */
240
- markDeleted(tableName: string, rowId: number): void;
241
-
242
- /**
243
- * Get count of deleted records in a table
244
- */
245
- getDeletedCount(tableName: string): number;
246
-
247
- /**
248
- * Clear tombstones (deleted record markers) for a table
249
- */
250
- clearTombstones(tableName: string): void;
251
-
252
- // ==================== Raw FlatBuffer Access ====================
253
-
254
- /**
255
- * Get raw FlatBuffer pointer and size by table name and id.
256
- * Returns { ptr, size, sequence } or null if not found.
257
- * Use the ptr with Module.HEAPU8.subarray(ptr, ptr + size) to access raw bytes.
258
- */
259
- getFlatBufferById(tableName: string, id: number): { ptr: number; size: number; sequence: number } | null;
260
-
261
- /**
262
- * Get raw FlatBuffer pointer and size by table name and email.
263
- * Returns { ptr, size, sequence } or null if not found.
264
- */
265
- getFlatBufferByEmail(tableName: string, email: string): { ptr: number; size: number; sequence: number } | null;
266
-
267
- /**
268
- * Get raw FlatBuffer pointer and size by table name, indexed column, and typed key.
269
- * Returns { ptr, size, sequence } or null if not found.
270
- */
271
- getFlatBufferByIndex(
272
- tableName: string,
273
- columnName: string,
274
- value: QueryParam
275
- ): { ptr: number; size: number; sequence: number } | null;
276
-
277
- /**
278
- * Get a copy of the raw FlatBuffer data as Uint8Array
279
- */
280
- getFlatBufferDataById(tableName: string, id: number): Uint8Array | null;
281
-
282
- /**
283
- * Get a copy of raw FlatBuffer data by table name, indexed column, and typed key.
284
- */
285
- getFlatBufferDataByIndex(tableName: string, columnName: string, value: QueryParam): Uint8Array | null;
286
-
287
- /**
288
- * Get the underlying storage buffer info
289
- * Returns { ptr, size } for direct WASM memory access
290
- */
291
- getStorageInfo(): { ptr: number; size: number };
292
-
293
- /**
294
- * Destroy the database and free memory
295
- */
296
- destroy(): void;
297
-
298
- // ==================== Encryption ====================
299
- //
300
- // The (encrypted) fields of a record are encrypted under FlatBuffers field
301
- // encryption format 3: each record under its own key, with its sequence
302
- // (rowid) as the record index, so no two records share a key stream.
303
-
304
- /**
305
- * Set the database key. Fields marked with (encrypted) in the schema are
306
- * decrypted when read through SQL queries.
307
- * @param key 32-byte AES-256 key
308
- * @param options.format The field-encryption format of the records the
309
- * database already holds in tables with (encrypted) columns: required (3)
310
- * when it holds any. Format 2 (records encrypted by flatsql 3.2.0 or
311
- * earlier) is refused: see README "Database-key encryption".
312
- */
313
- setEncryptionKey(key: Uint8Array, options?: { format?: 3 }): void;
314
-
315
- /**
316
- * Check if encryption is enabled
317
- */
318
- isEncrypted(): boolean;
319
-
320
- /**
321
- * Encrypt the (encrypted) fields of a FlatBuffer as the record with index
322
- * `recordIndex`, the sequence it has or gets in this database. To write
323
- * encrypted records use ingestOneEncrypted.
324
- * @param buffer FlatBuffer data (no size prefix)
325
- * @param schema Binary schema (.bfbs) with builtin attributes (flatc --bfbs-builtins)
326
- * @param recordIndex The record's sequence (1 to 4294967295)
327
- * @returns Encrypted buffer copy
328
- */
329
- encryptBuffer(buffer: Uint8Array, schema: Uint8Array, recordIndex: number): Uint8Array;
330
-
331
- /**
332
- * Decrypt the (encrypted) fields of a stored FlatBuffer
333
- * @param buffer Encrypted FlatBuffer data (no size prefix)
334
- * @param schema Binary schema (.bfbs) with builtin attributes (flatc --bfbs-builtins)
335
- * @param recordIndex The record's sequence (1 to 4294967295)
336
- * @returns Decrypted buffer copy
337
- */
338
- decryptBuffer(buffer: Uint8Array, schema: Uint8Array, recordIndex: number): Uint8Array;
339
-
340
- /**
341
- * Encrypt a plaintext FlatBuffer under the sequence it gets and ingest it
342
- * @param data FlatBuffer data (no size prefix)
343
- * @param schema Binary schema (.bfbs) with builtin attributes (flatc --bfbs-builtins)
344
- * @param source Source name, as for ingestOne
345
- * @returns The record's sequence
346
- */
347
- ingestOneEncrypted(data: Uint8Array, schema: Uint8Array, source?: string | null): number;
348
-
349
- // ==================== HMAC Authentication ====================
350
-
351
- /**
352
- * Enable or disable HMAC-SHA256 verification on ingest.
353
- * When enabled, buffers can be verified for integrity before processing.
354
- * Requires an encryption key to be set first.
355
- * @param enabled true to enable, false to disable
356
- */
357
- setHMACVerification(enabled: boolean): void;
358
-
359
- /**
360
- * Check if HMAC verification is enabled
361
- */
362
- isHMACEnabled(): boolean;
363
-
364
- /**
365
- * Compute HMAC-SHA256 for a FlatBuffer.
366
- * Use this to sign buffers before transmission/storage.
367
- * @param buffer FlatBuffer data
368
- * @returns 32-byte HMAC
369
- */
370
- computeHMAC(buffer: Uint8Array): Uint8Array;
371
-
372
- /**
373
- * Verify HMAC-SHA256 for a FlatBuffer.
374
- * Use this to verify buffer integrity before ingestion.
375
- * @param buffer FlatBuffer data
376
- * @param mac 32-byte HMAC to verify against
377
- * @returns true if the MAC is valid
378
- */
379
- verifyHMAC(buffer: Uint8Array, mac: Uint8Array): boolean;
380
- }
381
-
382
- export interface FlatSQL {
383
- /**
384
- * Create a new database with the given schema
385
- */
386
- createDatabase(schema: string, name: string): FlatSQLDatabase;
387
- openDatabase(schema: string, name?: string, path?: string, journalMode?: number): FlatSQLDatabase;
388
-
389
- /**
390
- * Create a test User FlatBuffer (for demos)
391
- */
392
- createTestUser(id: number, name: string, email: string, age: number): Uint8Array;
393
-
394
- /**
395
- * Create a test Post FlatBuffer (for demos)
396
- */
397
- createTestPost(id: number, userId: number, title: string): Uint8Array;
398
-
399
- /**
400
- * Create a test PublishEventRecord FlatBuffer with FILE_ID fields (for stress harnesses)
401
- */
402
- createTestPublishEvent(fileId: string, recordId: string, eventIndex: number, payloadSize: number): Uint8Array;
403
-
404
- /**
405
- * Create a test CCSDS OMM / MPE FlatBuffer (for demos)
406
- */
407
- createTestMPE(
408
- entityId: string,
409
- epoch: number,
410
- meanMotion: number,
411
- eccentricity: number,
412
- inclination: number,
413
- raOfAscNode: number,
414
- argOfPericenter: number,
415
- meanAnomaly: number,
416
- bstar: number,
417
- meanElementTheory?: number
418
- ): Uint8Array;
419
-
420
- /**
421
- * Create a test CCSDS-style telemetry FlatBuffer (for demos)
422
- */
423
- createTestTelemetry(
424
- packetId: number,
425
- spacecraft: string,
426
- subsystem: string,
427
- mode: string,
428
- temperatureC: number,
429
- signalDb: number,
430
- timestampS: number
431
- ): Uint8Array;
432
-
433
- /**
434
- * Check if WASM was loaded with integrity verification
435
- */
436
- wasIntegrityVerified(): boolean;
437
-
438
- /**
439
- * Build the canonical query result cache key in the WASM core.
440
- */
441
- buildQueryCacheKey(
442
- dataset: string,
443
- artifactVersion: string,
444
- queryId: string,
445
- params?: QueryParam[]
446
- ): string;
447
-
448
- /**
449
- * Build the canonical immutable response artifact cache key in the WASM core.
450
- */
451
- buildResponseArtifactCacheKey(
452
- schemaName: string,
453
- schemaVersion: string,
454
- sql: string,
455
- options?: ResponseArtifactCacheKeyOptions
456
- ): string;
457
- }
458
-
459
- /**
460
- * Options for initializing FlatSQL with integrity verification
461
- */
462
- export interface InitOptions {
463
- /**
464
- * Expected SHA-384 hash of the WASM binary (base64 encoded)
465
- * If provided, the WASM will be verified against this hash before loading
466
- */
467
- integrity?: string;
468
-
469
- /**
470
- * Custom path to WASM files directory
471
- * Default: same directory as index.js
472
- */
473
- wasmPath?: string;
474
-
475
- /**
476
- * Skip integrity verification (not recommended for production)
477
- * Default: false
478
- */
479
- skipIntegrityCheck?: boolean;
480
-
481
- /**
482
- * Fail if integrity cannot be verified (no hash available)
483
- * Default: false
484
- */
485
- requireIntegrity?: boolean;
486
-
487
- /**
488
- * SHA-384 digest provider used for browser integrity verification.
489
- * Browser WebCrypto is intentionally not used; browser callers that require
490
- * integrity verification must pass a WASM/native-backed provider.
491
- * The result may be a base64 digest string or raw digest bytes.
492
- */
493
- computeSHA384?: (
494
- data: ArrayBuffer
495
- ) => Promise<string | Uint8Array | ArrayBuffer> | string | Uint8Array | ArrayBuffer;
496
-
497
- /**
498
- * Host I/O backend for disk-backed databases — the seven-import contract in
499
- * cpp/include/flatsql/flatsql_io.h, which the runtime has always read off
500
- * this option (wasm/index.js: `ioBackend = options.io ?? null`).
501
- *
502
- * Declared here because a runtime option missing from the published types is
503
- * a contract that every TypeScript caller has to defeat with a cast, and a
504
- * cast is where drift starts. Use `flatsql/io` for the backends.
505
- */
506
- io?: FlatSqlIoBackend;
507
-
508
- /**
509
- * Custom Emscripten module factory function
510
- * Default: built-in FlatSQLModule
511
- */
512
- moduleFactory?: () => Promise<any>;
513
- }
514
-
515
- /**
516
- * Initialize FlatSQL WASM module with optional integrity verification
517
- *
518
- * @example
519
- * // Basic usage (auto-loads integrity.json if available)
520
- * const flatsql = await initFlatSQL();
521
- *
522
- * @example
523
- * // With explicit integrity hash
524
- * const flatsql = await initFlatSQL({
525
- * integrity: 'base64-hash-here',
526
- * requireIntegrity: true
527
- * });
528
- *
529
- * @example
530
- * // Skip integrity check (development only)
531
- * const flatsql = await initFlatSQL({ skipIntegrityCheck: true });
532
- *
533
- * @example
534
- * // Legacy API (still supported)
535
- * const flatsql = await initFlatSQL(customModuleFactory);
536
- */
537
- export function initFlatSQL(options?: InitOptions | (() => Promise<any>)): Promise<FlatSQL>;
538
-
539
- /**
540
- * Check if WASM was loaded with integrity verification
541
- * Can be called before or after initFlatSQL
542
- */
543
- export function wasIntegrityVerified(): boolean;
544
-
545
- export function __testWasmPointerToByteOffset(ptr: number): number;
546
-
547
- export * from './ps.js';
548
-
549
- export default initFlatSQL;