@xcr1234/dbhub-fork 1.0.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 (34) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +139 -0
  3. package/dist/chunk-6O5I6UAW.js +2150 -0
  4. package/dist/chunk-BRXZ5ZQB.js +127 -0
  5. package/dist/chunk-C7WEAPX4.js +485 -0
  6. package/dist/chunk-FAIJPBT5.js +40 -0
  7. package/dist/chunk-JFWX35TB.js +34 -0
  8. package/dist/chunk-RTB262PR.js +60 -0
  9. package/dist/chunk-WVVMH6FJ.js +49 -0
  10. package/dist/demo/employee-sqlite/employee.sql +117 -0
  11. package/dist/demo/employee-sqlite/load_department.sql +10 -0
  12. package/dist/demo/employee-sqlite/load_dept_emp.sql +1103 -0
  13. package/dist/demo/employee-sqlite/load_dept_manager.sql +17 -0
  14. package/dist/demo/employee-sqlite/load_employee.sql +1000 -0
  15. package/dist/demo/employee-sqlite/load_salary1.sql +9488 -0
  16. package/dist/demo/employee-sqlite/load_title.sql +1470 -0
  17. package/dist/demo-loader-WKQAEFSX.js +48 -0
  18. package/dist/index.d.ts +1 -0
  19. package/dist/index.js +1584 -0
  20. package/dist/mariadb-QHRMVK47.js +468 -0
  21. package/dist/mysql-GOLPG2Q6.js +475 -0
  22. package/dist/oracle-3V2T7ZWF.js +27739 -0
  23. package/dist/postgres-CK6N5BXI.js +520 -0
  24. package/dist/public/assets/index-BiTHVJQj.js +144 -0
  25. package/dist/public/assets/index-CfPYb3wl.css +1 -0
  26. package/dist/public/assets/postgres-BpcazhJg.svg +22 -0
  27. package/dist/public/assets/sqlserver-ByfFYYpV.svg +11 -0
  28. package/dist/public/favicon.svg +57 -0
  29. package/dist/public/index.html +14 -0
  30. package/dist/public/logo-full-light.svg +58 -0
  31. package/dist/registry-KI3KJMRY.js +13 -0
  32. package/dist/sqlite-P6NXTMYE.js +2473 -0
  33. package/dist/sqlserver-5RM44GWI.js +493 -0
  34. package/package.json +99 -0
@@ -0,0 +1,2473 @@
1
+ import {
2
+ quoteIdentifier
3
+ } from "./chunk-JFWX35TB.js";
4
+ import {
5
+ SQLRowLimiter
6
+ } from "./chunk-BRXZ5ZQB.js";
7
+ import {
8
+ ConnectorRegistry,
9
+ SafeURL,
10
+ obfuscateDSNPassword,
11
+ splitSQLStatements
12
+ } from "./chunk-C7WEAPX4.js";
13
+ import {
14
+ __commonJS,
15
+ __publicField,
16
+ __require,
17
+ __toESM
18
+ } from "./chunk-FAIJPBT5.js";
19
+
20
+ // node_modules/sql.js/dist/sql-wasm.js
21
+ var require_sql_wasm = __commonJS({
22
+ "node_modules/sql.js/dist/sql-wasm.js"(exports, module) {
23
+ "use strict";
24
+ var initSqlJsPromise = void 0;
25
+ var initSqlJs2 = function(moduleConfig) {
26
+ if (initSqlJsPromise) {
27
+ return initSqlJsPromise;
28
+ }
29
+ initSqlJsPromise = new Promise(function(resolveModule, reject) {
30
+ var Module = typeof moduleConfig !== "undefined" ? moduleConfig : {};
31
+ var originalOnAbortFunction = Module["onAbort"];
32
+ Module["onAbort"] = function(errorThatCausedAbort) {
33
+ reject(new Error(errorThatCausedAbort));
34
+ if (originalOnAbortFunction) {
35
+ originalOnAbortFunction(errorThatCausedAbort);
36
+ }
37
+ };
38
+ Module["postRun"] = Module["postRun"] || [];
39
+ Module["postRun"].push(function() {
40
+ resolveModule(Module);
41
+ });
42
+ module = void 0;
43
+ var k;
44
+ k || (k = typeof Module != "undefined" ? Module : {});
45
+ var aa = !!globalThis.window, ba = !!globalThis.WorkerGlobalScope, ca = globalThis.process?.versions?.node && "renderer" != globalThis.process?.type;
46
+ k.onRuntimeInitialized = function() {
47
+ function a(f, l) {
48
+ switch (typeof l) {
49
+ case "boolean":
50
+ bc(f, l ? 1 : 0);
51
+ break;
52
+ case "number":
53
+ cc(f, l);
54
+ break;
55
+ case "string":
56
+ dc(f, l, -1, -1);
57
+ break;
58
+ case "object":
59
+ if (null === l) lb(f);
60
+ else if (null != l.length) {
61
+ var n = da(l.length);
62
+ m.set(l, n);
63
+ ec(f, n, l.length, -1);
64
+ ea(n);
65
+ } else sa(f, "Wrong API use : tried to return a value of an unknown type (" + l + ").", -1);
66
+ break;
67
+ default:
68
+ lb(f);
69
+ }
70
+ }
71
+ function b(f, l) {
72
+ for (var n = [], p = 0; p < f; p += 1) {
73
+ var u = r(l + 4 * p, "i32"), v = fc(u);
74
+ if (1 === v || 2 === v) u = gc(u);
75
+ else if (3 === v) u = hc(u);
76
+ else if (4 === v) {
77
+ v = u;
78
+ u = ic(v);
79
+ v = jc(v);
80
+ for (var K = new Uint8Array(u), I = 0; I < u; I += 1) K[I] = m[v + I];
81
+ u = K;
82
+ } else u = null;
83
+ n.push(u);
84
+ }
85
+ return n;
86
+ }
87
+ function c(f, l) {
88
+ this.Qa = f;
89
+ this.db = l;
90
+ this.Oa = 1;
91
+ this.mb = [];
92
+ }
93
+ function d(f, l) {
94
+ this.db = l;
95
+ this.fb = fa(f);
96
+ if (null === this.fb) throw Error("Unable to allocate memory for the SQL string");
97
+ this.lb = this.fb;
98
+ this.$a = this.sb = null;
99
+ }
100
+ function e(f) {
101
+ this.filename = "dbfile_" + (4294967295 * Math.random() >>> 0);
102
+ if (null != f) {
103
+ var l = this.filename, n = "/", p = l;
104
+ n && (n = "string" == typeof n ? n : ha(n), p = l ? ia(n + "/" + l) : n);
105
+ l = ja(true, true);
106
+ p = ka(
107
+ p,
108
+ l
109
+ );
110
+ if (f) {
111
+ if ("string" == typeof f) {
112
+ n = Array(f.length);
113
+ for (var u = 0, v = f.length; u < v; ++u) n[u] = f.charCodeAt(u);
114
+ f = n;
115
+ }
116
+ la(p, l | 146);
117
+ n = ma(p, 577);
118
+ na(n, f, 0, f.length, 0);
119
+ oa(n);
120
+ la(p, l);
121
+ }
122
+ }
123
+ this.handleError(q(this.filename, g));
124
+ this.db = r(g, "i32");
125
+ ob(this.db);
126
+ this.gb = {};
127
+ this.Sa = {};
128
+ }
129
+ var g = y(4), h = k.cwrap, q = h("sqlite3_open", "number", ["string", "number"]), w = h("sqlite3_close_v2", "number", ["number"]), t = h("sqlite3_exec", "number", ["number", "string", "number", "number", "number"]), x = h("sqlite3_changes", "number", ["number"]), D = h(
130
+ "sqlite3_prepare_v2",
131
+ "number",
132
+ ["number", "string", "number", "number", "number"]
133
+ ), pb = h("sqlite3_sql", "string", ["number"]), lc = h("sqlite3_normalized_sql", "string", ["number"]), qb = h("sqlite3_prepare_v2", "number", ["number", "number", "number", "number", "number"]), mc = h("sqlite3_bind_text", "number", ["number", "number", "number", "number", "number"]), rb = h("sqlite3_bind_blob", "number", ["number", "number", "number", "number", "number"]), nc = h("sqlite3_bind_double", "number", ["number", "number", "number"]), oc = h("sqlite3_bind_int", "number", [
134
+ "number",
135
+ "number",
136
+ "number"
137
+ ]), pc = h("sqlite3_bind_parameter_index", "number", ["number", "string"]), qc = h("sqlite3_step", "number", ["number"]), rc = h("sqlite3_errmsg", "string", ["number"]), sc = h("sqlite3_column_count", "number", ["number"]), tc = h("sqlite3_data_count", "number", ["number"]), uc = h("sqlite3_column_double", "number", ["number", "number"]), sb = h("sqlite3_column_text", "string", ["number", "number"]), vc = h("sqlite3_column_blob", "number", ["number", "number"]), wc = h("sqlite3_column_bytes", "number", ["number", "number"]), xc = h(
138
+ "sqlite3_column_type",
139
+ "number",
140
+ ["number", "number"]
141
+ ), yc = h("sqlite3_column_name", "string", ["number", "number"]), zc = h("sqlite3_reset", "number", ["number"]), Ac = h("sqlite3_clear_bindings", "number", ["number"]), Bc = h("sqlite3_finalize", "number", ["number"]), tb = h("sqlite3_create_function_v2", "number", "number string number number number number number number number".split(" ")), fc = h("sqlite3_value_type", "number", ["number"]), ic = h("sqlite3_value_bytes", "number", ["number"]), hc = h("sqlite3_value_text", "string", ["number"]), jc = h(
142
+ "sqlite3_value_blob",
143
+ "number",
144
+ ["number"]
145
+ ), gc = h("sqlite3_value_double", "number", ["number"]), cc = h("sqlite3_result_double", "", ["number", "number"]), lb = h("sqlite3_result_null", "", ["number"]), dc = h("sqlite3_result_text", "", ["number", "string", "number", "number"]), ec = h("sqlite3_result_blob", "", ["number", "number", "number", "number"]), bc = h("sqlite3_result_int", "", ["number", "number"]), sa = h("sqlite3_result_error", "", ["number", "string", "number"]), ub = h("sqlite3_aggregate_context", "number", ["number", "number"]), ob = h(
146
+ "RegisterExtensionFunctions",
147
+ "number",
148
+ ["number"]
149
+ ), vb = h("sqlite3_update_hook", "number", ["number", "number", "number"]);
150
+ c.prototype.bind = function(f) {
151
+ if (!this.Qa) throw "Statement closed";
152
+ this.reset();
153
+ return Array.isArray(f) ? this.Gb(f) : null != f && "object" === typeof f ? this.Hb(f) : true;
154
+ };
155
+ c.prototype.step = function() {
156
+ if (!this.Qa) throw "Statement closed";
157
+ this.Oa = 1;
158
+ var f = qc(this.Qa);
159
+ switch (f) {
160
+ case 100:
161
+ return true;
162
+ case 101:
163
+ return false;
164
+ default:
165
+ throw this.db.handleError(f);
166
+ }
167
+ };
168
+ c.prototype.Ab = function(f) {
169
+ null == f && (f = this.Oa, this.Oa += 1);
170
+ return uc(this.Qa, f);
171
+ };
172
+ c.prototype.Ob = function(f) {
173
+ null == f && (f = this.Oa, this.Oa += 1);
174
+ f = sb(this.Qa, f);
175
+ if ("function" !== typeof BigInt) throw Error("BigInt is not supported");
176
+ return BigInt(f);
177
+ };
178
+ c.prototype.Tb = function(f) {
179
+ null == f && (f = this.Oa, this.Oa += 1);
180
+ return sb(this.Qa, f);
181
+ };
182
+ c.prototype.getBlob = function(f) {
183
+ null == f && (f = this.Oa, this.Oa += 1);
184
+ var l = wc(this.Qa, f);
185
+ f = vc(this.Qa, f);
186
+ for (var n = new Uint8Array(l), p = 0; p < l; p += 1) n[p] = m[f + p];
187
+ return n;
188
+ };
189
+ c.prototype.get = function(f, l) {
190
+ l = l || {};
191
+ null != f && this.bind(f) && this.step();
192
+ f = [];
193
+ for (var n = tc(this.Qa), p = 0; p < n; p += 1) switch (xc(this.Qa, p)) {
194
+ case 1:
195
+ var u = l.useBigInt ? this.Ob(p) : this.Ab(p);
196
+ f.push(u);
197
+ break;
198
+ case 2:
199
+ f.push(this.Ab(p));
200
+ break;
201
+ case 3:
202
+ f.push(this.Tb(p));
203
+ break;
204
+ case 4:
205
+ f.push(this.getBlob(p));
206
+ break;
207
+ default:
208
+ f.push(null);
209
+ }
210
+ return f;
211
+ };
212
+ c.prototype.qb = function() {
213
+ for (var f = [], l = sc(this.Qa), n = 0; n < l; n += 1) f.push(yc(this.Qa, n));
214
+ return f;
215
+ };
216
+ c.prototype.zb = function(f, l) {
217
+ f = this.get(f, l);
218
+ l = this.qb();
219
+ for (var n = {}, p = 0; p < l.length; p += 1) n[l[p]] = f[p];
220
+ return n;
221
+ };
222
+ c.prototype.Sb = function() {
223
+ return pb(this.Qa);
224
+ };
225
+ c.prototype.Pb = function() {
226
+ return lc(this.Qa);
227
+ };
228
+ c.prototype.run = function(f) {
229
+ null != f && this.bind(f);
230
+ this.step();
231
+ return this.reset();
232
+ };
233
+ c.prototype.wb = function(f, l) {
234
+ null == l && (l = this.Oa, this.Oa += 1);
235
+ f = fa(f);
236
+ this.mb.push(f);
237
+ this.db.handleError(mc(this.Qa, l, f, -1, 0));
238
+ };
239
+ c.prototype.Fb = function(f, l) {
240
+ null == l && (l = this.Oa, this.Oa += 1);
241
+ var n = da(f.length);
242
+ m.set(f, n);
243
+ this.mb.push(n);
244
+ this.db.handleError(rb(this.Qa, l, n, f.length, 0));
245
+ };
246
+ c.prototype.vb = function(f, l) {
247
+ null == l && (l = this.Oa, this.Oa += 1);
248
+ this.db.handleError((f === (f | 0) ? oc : nc)(
249
+ this.Qa,
250
+ l,
251
+ f
252
+ ));
253
+ };
254
+ c.prototype.Ib = function(f) {
255
+ null == f && (f = this.Oa, this.Oa += 1);
256
+ rb(this.Qa, f, 0, 0, 0);
257
+ };
258
+ c.prototype.xb = function(f, l) {
259
+ null == l && (l = this.Oa, this.Oa += 1);
260
+ switch (typeof f) {
261
+ case "string":
262
+ this.wb(f, l);
263
+ return;
264
+ case "number":
265
+ this.vb(f, l);
266
+ return;
267
+ case "bigint":
268
+ this.wb(f.toString(), l);
269
+ return;
270
+ case "boolean":
271
+ this.vb(f + 0, l);
272
+ return;
273
+ case "object":
274
+ if (null === f) {
275
+ this.Ib(l);
276
+ return;
277
+ }
278
+ if (null != f.length) {
279
+ this.Fb(f, l);
280
+ return;
281
+ }
282
+ }
283
+ throw "Wrong API use : tried to bind a value of an unknown type (" + f + ").";
284
+ };
285
+ c.prototype.Hb = function(f) {
286
+ var l = this;
287
+ Object.keys(f).forEach(function(n) {
288
+ var p = pc(l.Qa, n);
289
+ 0 !== p && l.xb(f[n], p);
290
+ });
291
+ return true;
292
+ };
293
+ c.prototype.Gb = function(f) {
294
+ for (var l = 0; l < f.length; l += 1) this.xb(f[l], l + 1);
295
+ return true;
296
+ };
297
+ c.prototype.reset = function() {
298
+ this.freemem();
299
+ return 0 === Ac(this.Qa) && 0 === zc(this.Qa);
300
+ };
301
+ c.prototype.freemem = function() {
302
+ for (var f; void 0 !== (f = this.mb.pop()); ) ea(f);
303
+ };
304
+ c.prototype.Ya = function() {
305
+ this.freemem();
306
+ var f = 0 === Bc(this.Qa);
307
+ delete this.db.gb[this.Qa];
308
+ this.Qa = 0;
309
+ return f;
310
+ };
311
+ d.prototype.next = function() {
312
+ if (null === this.fb) return { done: true };
313
+ null !== this.$a && (this.$a.Ya(), this.$a = null);
314
+ if (!this.db.db) throw this.ob(), Error("Database closed");
315
+ var f = pa(), l = y(4);
316
+ qa(g);
317
+ qa(l);
318
+ try {
319
+ this.db.handleError(qb(this.db.db, this.lb, -1, g, l));
320
+ this.lb = r(l, "i32");
321
+ var n = r(g, "i32");
322
+ if (0 === n) return this.ob(), { done: true };
323
+ this.$a = new c(n, this.db);
324
+ this.db.gb[n] = this.$a;
325
+ return { value: this.$a, done: false };
326
+ } catch (p) {
327
+ throw this.sb = z(this.lb), this.ob(), p;
328
+ } finally {
329
+ ra(f);
330
+ }
331
+ };
332
+ d.prototype.ob = function() {
333
+ ea(this.fb);
334
+ this.fb = null;
335
+ };
336
+ d.prototype.Qb = function() {
337
+ return null !== this.sb ? this.sb : z(this.lb);
338
+ };
339
+ "function" === typeof Symbol && "symbol" === typeof Symbol.iterator && (d.prototype[Symbol.iterator] = function() {
340
+ return this;
341
+ });
342
+ e.prototype.run = function(f, l) {
343
+ if (!this.db) throw "Database closed";
344
+ if (l) {
345
+ f = this.tb(f, l);
346
+ try {
347
+ f.step();
348
+ } finally {
349
+ f.Ya();
350
+ }
351
+ } else this.handleError(t(this.db, f, 0, 0, g));
352
+ return this;
353
+ };
354
+ e.prototype.exec = function(f, l, n) {
355
+ if (!this.db) throw "Database closed";
356
+ var p = null, u = null, v = null;
357
+ try {
358
+ v = u = fa(f);
359
+ var K = y(4);
360
+ for (f = []; 0 !== r(v, "i8"); ) {
361
+ qa(g);
362
+ qa(K);
363
+ this.handleError(qb(this.db, v, -1, g, K));
364
+ var I = r(
365
+ g,
366
+ "i32"
367
+ );
368
+ v = r(K, "i32");
369
+ if (0 !== I) {
370
+ var H = null;
371
+ p = new c(I, this);
372
+ for (null != l && p.bind(l); p.step(); ) null === H && (H = { columns: p.qb(), values: [] }, f.push(H)), H.values.push(p.get(null, n));
373
+ p.Ya();
374
+ }
375
+ }
376
+ return f;
377
+ } catch (L) {
378
+ throw p && p.Ya(), L;
379
+ } finally {
380
+ u && ea(u);
381
+ }
382
+ };
383
+ e.prototype.Mb = function(f, l, n, p, u) {
384
+ "function" === typeof l && (p = n, n = l, l = void 0);
385
+ f = this.tb(f, l);
386
+ try {
387
+ for (; f.step(); ) n(f.zb(null, u));
388
+ } finally {
389
+ f.Ya();
390
+ }
391
+ if ("function" === typeof p) return p();
392
+ };
393
+ e.prototype.tb = function(f, l) {
394
+ qa(g);
395
+ this.handleError(D(this.db, f, -1, g, 0));
396
+ f = r(g, "i32");
397
+ if (0 === f) throw "Nothing to prepare";
398
+ var n = new c(f, this);
399
+ null != l && n.bind(l);
400
+ return this.gb[f] = n;
401
+ };
402
+ e.prototype.Ub = function(f) {
403
+ return new d(f, this);
404
+ };
405
+ e.prototype.Nb = function() {
406
+ Object.values(this.gb).forEach(function(l) {
407
+ l.Ya();
408
+ });
409
+ Object.values(this.Sa).forEach(A);
410
+ this.Sa = {};
411
+ this.handleError(w(this.db));
412
+ var f = ta(this.filename);
413
+ this.handleError(q(this.filename, g));
414
+ this.db = r(g, "i32");
415
+ ob(this.db);
416
+ return f;
417
+ };
418
+ e.prototype.close = function() {
419
+ null !== this.db && (Object.values(this.gb).forEach(function(f) {
420
+ f.Ya();
421
+ }), Object.values(this.Sa).forEach(A), this.Sa = {}, this.Za && (A(this.Za), this.Za = void 0), this.handleError(w(this.db)), ua("/" + this.filename), this.db = null);
422
+ };
423
+ e.prototype.handleError = function(f) {
424
+ if (0 === f) return null;
425
+ f = rc(this.db);
426
+ throw Error(f);
427
+ };
428
+ e.prototype.Rb = function() {
429
+ return x(this.db);
430
+ };
431
+ e.prototype.Kb = function(f, l) {
432
+ Object.prototype.hasOwnProperty.call(this.Sa, f) && (A(this.Sa[f]), delete this.Sa[f]);
433
+ var n = va(function(p, u, v) {
434
+ u = b(u, v);
435
+ try {
436
+ var K = l.apply(null, u);
437
+ } catch (I) {
438
+ sa(p, I, -1);
439
+ return;
440
+ }
441
+ a(p, K);
442
+ }, "viii");
443
+ this.Sa[f] = n;
444
+ this.handleError(tb(
445
+ this.db,
446
+ f,
447
+ l.length,
448
+ 1,
449
+ 0,
450
+ n,
451
+ 0,
452
+ 0,
453
+ 0
454
+ ));
455
+ return this;
456
+ };
457
+ e.prototype.Jb = function(f, l) {
458
+ var n = l.init || function() {
459
+ return null;
460
+ }, p = l.finalize || function(H) {
461
+ return H;
462
+ }, u = l.step;
463
+ if (!u) throw "An aggregate function must have a step function in " + f;
464
+ var v = {};
465
+ Object.hasOwnProperty.call(this.Sa, f) && (A(this.Sa[f]), delete this.Sa[f]);
466
+ l = f + "__finalize";
467
+ Object.hasOwnProperty.call(this.Sa, l) && (A(this.Sa[l]), delete this.Sa[l]);
468
+ var K = va(function(H, L, Pa) {
469
+ var V = ub(H, 1);
470
+ Object.hasOwnProperty.call(v, V) || (v[V] = n());
471
+ L = b(L, Pa);
472
+ L = [v[V]].concat(L);
473
+ try {
474
+ v[V] = u.apply(null, L);
475
+ } catch (Dc) {
476
+ delete v[V], sa(H, Dc, -1);
477
+ }
478
+ }, "viii"), I = va(function(H) {
479
+ var L = ub(H, 1);
480
+ try {
481
+ var Pa = p(v[L]);
482
+ } catch (V) {
483
+ delete v[L];
484
+ sa(H, V, -1);
485
+ return;
486
+ }
487
+ a(H, Pa);
488
+ delete v[L];
489
+ }, "vi");
490
+ this.Sa[f] = K;
491
+ this.Sa[l] = I;
492
+ this.handleError(tb(this.db, f, u.length - 1, 1, 0, 0, K, I, 0));
493
+ return this;
494
+ };
495
+ e.prototype.Zb = function(f) {
496
+ this.Za && (vb(this.db, 0, 0), A(this.Za), this.Za = void 0);
497
+ if (!f) return this;
498
+ this.Za = va(function(l, n, p, u, v) {
499
+ switch (n) {
500
+ case 18:
501
+ l = "insert";
502
+ break;
503
+ case 23:
504
+ l = "update";
505
+ break;
506
+ case 9:
507
+ l = "delete";
508
+ break;
509
+ default:
510
+ throw "unknown operationCode in updateHook callback: " + n;
511
+ }
512
+ p = z(p);
513
+ u = z(u);
514
+ if (v > Number.MAX_SAFE_INTEGER) throw "rowId too big to fit inside a Number";
515
+ f(l, p, u, Number(v));
516
+ }, "viiiij");
517
+ vb(this.db, this.Za, 0);
518
+ return this;
519
+ };
520
+ c.prototype.bind = c.prototype.bind;
521
+ c.prototype.step = c.prototype.step;
522
+ c.prototype.get = c.prototype.get;
523
+ c.prototype.getColumnNames = c.prototype.qb;
524
+ c.prototype.getAsObject = c.prototype.zb;
525
+ c.prototype.getSQL = c.prototype.Sb;
526
+ c.prototype.getNormalizedSQL = c.prototype.Pb;
527
+ c.prototype.run = c.prototype.run;
528
+ c.prototype.reset = c.prototype.reset;
529
+ c.prototype.freemem = c.prototype.freemem;
530
+ c.prototype.free = c.prototype.Ya;
531
+ d.prototype.next = d.prototype.next;
532
+ d.prototype.getRemainingSQL = d.prototype.Qb;
533
+ e.prototype.run = e.prototype.run;
534
+ e.prototype.exec = e.prototype.exec;
535
+ e.prototype.each = e.prototype.Mb;
536
+ e.prototype.prepare = e.prototype.tb;
537
+ e.prototype.iterateStatements = e.prototype.Ub;
538
+ e.prototype["export"] = e.prototype.Nb;
539
+ e.prototype.close = e.prototype.close;
540
+ e.prototype.handleError = e.prototype.handleError;
541
+ e.prototype.getRowsModified = e.prototype.Rb;
542
+ e.prototype.create_function = e.prototype.Kb;
543
+ e.prototype.create_aggregate = e.prototype.Jb;
544
+ e.prototype.updateHook = e.prototype.Zb;
545
+ k.Database = e;
546
+ };
547
+ var wa = "./this.program", xa = (a, b) => {
548
+ throw b;
549
+ }, ya = globalThis.document?.currentScript?.src;
550
+ "undefined" != typeof __filename ? ya = __filename : ba && (ya = self.location.href);
551
+ var za = "", Aa, Ba;
552
+ if (ca) {
553
+ var fs2 = __require("fs");
554
+ za = __dirname + "/";
555
+ Ba = (a) => {
556
+ a = Ca(a) ? new URL(a) : a;
557
+ return fs2.readFileSync(a);
558
+ };
559
+ Aa = async (a) => {
560
+ a = Ca(a) ? new URL(a) : a;
561
+ return fs2.readFileSync(a, void 0);
562
+ };
563
+ 1 < process.argv.length && (wa = process.argv[1].replace(/\\/g, "/"));
564
+ process.argv.slice(2);
565
+ "undefined" != typeof module && (module.exports = k);
566
+ xa = (a, b) => {
567
+ process.exitCode = a;
568
+ throw b;
569
+ };
570
+ } else if (aa || ba) {
571
+ try {
572
+ za = new URL(".", ya).href;
573
+ } catch {
574
+ }
575
+ ba && (Ba = (a) => {
576
+ var b = new XMLHttpRequest();
577
+ b.open("GET", a, false);
578
+ b.responseType = "arraybuffer";
579
+ b.send(null);
580
+ return new Uint8Array(b.response);
581
+ });
582
+ Aa = async (a) => {
583
+ if (Ca(a)) return new Promise((c, d) => {
584
+ var e = new XMLHttpRequest();
585
+ e.open("GET", a, true);
586
+ e.responseType = "arraybuffer";
587
+ e.onload = () => {
588
+ 200 == e.status || 0 == e.status && e.response ? c(e.response) : d(e.status);
589
+ };
590
+ e.onerror = d;
591
+ e.send(null);
592
+ });
593
+ var b = await fetch(a, { credentials: "same-origin" });
594
+ if (b.ok) return b.arrayBuffer();
595
+ throw Error(b.status + " : " + b.url);
596
+ };
597
+ }
598
+ var Da = console.log.bind(console), B = console.error.bind(console), Ea, Fa = false, Ga, Ca = (a) => a.startsWith("file://"), m, C, Ha, E, F, Ia, Ja, G;
599
+ function Ka() {
600
+ var a = La.buffer;
601
+ m = new Int8Array(a);
602
+ Ha = new Int16Array(a);
603
+ C = new Uint8Array(a);
604
+ new Uint16Array(a);
605
+ E = new Int32Array(a);
606
+ F = new Uint32Array(a);
607
+ Ia = new Float32Array(a);
608
+ Ja = new Float64Array(a);
609
+ G = new BigInt64Array(a);
610
+ new BigUint64Array(a);
611
+ }
612
+ function Ma(a) {
613
+ k.onAbort?.(a);
614
+ a = "Aborted(" + a + ")";
615
+ B(a);
616
+ Fa = true;
617
+ throw new WebAssembly.RuntimeError(a + ". Build with -sASSERTIONS for more info.");
618
+ }
619
+ var Na;
620
+ async function Oa(a) {
621
+ if (!Ea) try {
622
+ var b = await Aa(a);
623
+ return new Uint8Array(b);
624
+ } catch {
625
+ }
626
+ if (a == Na && Ea) a = new Uint8Array(Ea);
627
+ else if (Ba) a = Ba(a);
628
+ else throw "both async and sync fetching of the wasm failed";
629
+ return a;
630
+ }
631
+ async function Qa(a, b) {
632
+ try {
633
+ var c = await Oa(a);
634
+ return await WebAssembly.instantiate(c, b);
635
+ } catch (d) {
636
+ B(`failed to asynchronously prepare wasm: ${d}`), Ma(d);
637
+ }
638
+ }
639
+ async function Ra(a) {
640
+ var b = Na;
641
+ if (!Ea && !Ca(b) && !ca) try {
642
+ var c = fetch(b, { credentials: "same-origin" });
643
+ return await WebAssembly.instantiateStreaming(c, a);
644
+ } catch (d) {
645
+ B(`wasm streaming compile failed: ${d}`), B("falling back to ArrayBuffer instantiation");
646
+ }
647
+ return Qa(b, a);
648
+ }
649
+ class Sa {
650
+ constructor(a) {
651
+ __publicField(this, "name", "ExitStatus");
652
+ this.message = `Program terminated with exit(${a})`;
653
+ this.status = a;
654
+ }
655
+ }
656
+ var Ta = (a) => {
657
+ for (; 0 < a.length; ) a.shift()(k);
658
+ }, Ua = [], Va = [], Wa = () => {
659
+ var a = k.preRun.shift();
660
+ Va.push(a);
661
+ }, J = 0, Xa = null;
662
+ function r(a, b = "i8") {
663
+ b.endsWith("*") && (b = "*");
664
+ switch (b) {
665
+ case "i1":
666
+ return m[a];
667
+ case "i8":
668
+ return m[a];
669
+ case "i16":
670
+ return Ha[a >> 1];
671
+ case "i32":
672
+ return E[a >> 2];
673
+ case "i64":
674
+ return G[a >> 3];
675
+ case "float":
676
+ return Ia[a >> 2];
677
+ case "double":
678
+ return Ja[a >> 3];
679
+ case "*":
680
+ return F[a >> 2];
681
+ default:
682
+ Ma(`invalid type for getValue: ${b}`);
683
+ }
684
+ }
685
+ var Ya = true;
686
+ function qa(a) {
687
+ var b = "i32";
688
+ b.endsWith("*") && (b = "*");
689
+ switch (b) {
690
+ case "i1":
691
+ m[a] = 0;
692
+ break;
693
+ case "i8":
694
+ m[a] = 0;
695
+ break;
696
+ case "i16":
697
+ Ha[a >> 1] = 0;
698
+ break;
699
+ case "i32":
700
+ E[a >> 2] = 0;
701
+ break;
702
+ case "i64":
703
+ G[a >> 3] = BigInt(0);
704
+ break;
705
+ case "float":
706
+ Ia[a >> 2] = 0;
707
+ break;
708
+ case "double":
709
+ Ja[a >> 3] = 0;
710
+ break;
711
+ case "*":
712
+ F[a >> 2] = 0;
713
+ break;
714
+ default:
715
+ Ma(`invalid type for setValue: ${b}`);
716
+ }
717
+ }
718
+ var Za = new TextDecoder(), $a = (a, b, c, d) => {
719
+ c = b + c;
720
+ if (d) return c;
721
+ for (; a[b] && !(b >= c); ) ++b;
722
+ return b;
723
+ }, z = (a, b, c) => a ? Za.decode(C.subarray(a, $a(C, a, b, c))) : "", ab = (a, b) => {
724
+ for (var c = 0, d = a.length - 1; 0 <= d; d--) {
725
+ var e = a[d];
726
+ "." === e ? a.splice(d, 1) : ".." === e ? (a.splice(d, 1), c++) : c && (a.splice(d, 1), c--);
727
+ }
728
+ if (b) for (; c; c--) a.unshift("..");
729
+ return a;
730
+ }, ia = (a) => {
731
+ var b = "/" === a.charAt(0), c = "/" === a.slice(-1);
732
+ (a = ab(a.split("/").filter((d) => !!d), !b).join("/")) || b || (a = ".");
733
+ a && c && (a += "/");
734
+ return (b ? "/" : "") + a;
735
+ }, bb = (a) => {
736
+ var b = /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/.exec(a).slice(1);
737
+ a = b[0];
738
+ b = b[1];
739
+ if (!a && !b) return ".";
740
+ b && (b = b.slice(0, -1));
741
+ return a + b;
742
+ }, cb = (a) => a && a.match(/([^\/]+|\/)\/*$/)[1], db = () => {
743
+ if (ca) {
744
+ var a = __require("crypto");
745
+ return (b) => a.randomFillSync(b);
746
+ }
747
+ return (b) => crypto.getRandomValues(b);
748
+ }, eb = (a) => {
749
+ (eb = db())(a);
750
+ }, fb = (...a) => {
751
+ for (var b = "", c = false, d = a.length - 1; -1 <= d && !c; d--) {
752
+ c = 0 <= d ? a[d] : "/";
753
+ if ("string" != typeof c) throw new TypeError("Arguments to path.resolve must be strings");
754
+ if (!c) return "";
755
+ b = c + "/" + b;
756
+ c = "/" === c.charAt(0);
757
+ }
758
+ b = ab(b.split("/").filter((e) => !!e), !c).join("/");
759
+ return (c ? "/" : "") + b || ".";
760
+ }, gb = (a) => {
761
+ var b = $a(a, 0);
762
+ return Za.decode(a.buffer ? a.subarray(0, b) : new Uint8Array(a.slice(0, b)));
763
+ }, hb = [], ib = (a) => {
764
+ for (var b = 0, c = 0; c < a.length; ++c) {
765
+ var d = a.charCodeAt(c);
766
+ 127 >= d ? b++ : 2047 >= d ? b += 2 : 55296 <= d && 57343 >= d ? (b += 4, ++c) : b += 3;
767
+ }
768
+ return b;
769
+ }, M = (a, b, c, d) => {
770
+ if (!(0 < d)) return 0;
771
+ var e = c;
772
+ d = c + d - 1;
773
+ for (var g = 0; g < a.length; ++g) {
774
+ var h = a.codePointAt(g);
775
+ if (127 >= h) {
776
+ if (c >= d) break;
777
+ b[c++] = h;
778
+ } else if (2047 >= h) {
779
+ if (c + 1 >= d) break;
780
+ b[c++] = 192 | h >> 6;
781
+ b[c++] = 128 | h & 63;
782
+ } else if (65535 >= h) {
783
+ if (c + 2 >= d) break;
784
+ b[c++] = 224 | h >> 12;
785
+ b[c++] = 128 | h >> 6 & 63;
786
+ b[c++] = 128 | h & 63;
787
+ } else {
788
+ if (c + 3 >= d) break;
789
+ b[c++] = 240 | h >> 18;
790
+ b[c++] = 128 | h >> 12 & 63;
791
+ b[c++] = 128 | h >> 6 & 63;
792
+ b[c++] = 128 | h & 63;
793
+ g++;
794
+ }
795
+ }
796
+ b[c] = 0;
797
+ return c - e;
798
+ }, jb = [];
799
+ function kb(a, b) {
800
+ jb[a] = { input: [], output: [], eb: b };
801
+ mb(a, nb);
802
+ }
803
+ var nb = { open(a) {
804
+ var b = jb[a.node.rdev];
805
+ if (!b) throw new N(43);
806
+ a.tty = b;
807
+ a.seekable = false;
808
+ }, close(a) {
809
+ a.tty.eb.fsync(a.tty);
810
+ }, fsync(a) {
811
+ a.tty.eb.fsync(a.tty);
812
+ }, read(a, b, c, d) {
813
+ if (!a.tty || !a.tty.eb.Bb) throw new N(60);
814
+ for (var e = 0, g = 0; g < d; g++) {
815
+ try {
816
+ var h = a.tty.eb.Bb(a.tty);
817
+ } catch (q) {
818
+ throw new N(29);
819
+ }
820
+ if (void 0 === h && 0 === e) throw new N(6);
821
+ if (null === h || void 0 === h) break;
822
+ e++;
823
+ b[c + g] = h;
824
+ }
825
+ e && (a.node.atime = Date.now());
826
+ return e;
827
+ }, write(a, b, c, d) {
828
+ if (!a.tty || !a.tty.eb.ub) throw new N(60);
829
+ try {
830
+ for (var e = 0; e < d; e++) a.tty.eb.ub(a.tty, b[c + e]);
831
+ } catch (g) {
832
+ throw new N(29);
833
+ }
834
+ d && (a.node.mtime = a.node.ctime = Date.now());
835
+ return e;
836
+ } }, wb = { Bb() {
837
+ a: {
838
+ if (!hb.length) {
839
+ var a = null;
840
+ if (ca) {
841
+ var b = Buffer.alloc(256), c = 0, d = process.stdin.fd;
842
+ try {
843
+ c = fs2.readSync(d, b, 0, 256);
844
+ } catch (e) {
845
+ if (e.toString().includes("EOF")) c = 0;
846
+ else throw e;
847
+ }
848
+ 0 < c && (a = b.slice(0, c).toString("utf-8"));
849
+ } else globalThis.window?.prompt && (a = window.prompt("Input: "), null !== a && (a += "\n"));
850
+ if (!a) {
851
+ a = null;
852
+ break a;
853
+ }
854
+ b = Array(ib(a) + 1);
855
+ a = M(a, b, 0, b.length);
856
+ b.length = a;
857
+ hb = b;
858
+ }
859
+ a = hb.shift();
860
+ }
861
+ return a;
862
+ }, ub(a, b) {
863
+ null === b || 10 === b ? (Da(gb(a.output)), a.output = []) : 0 != b && a.output.push(b);
864
+ }, fsync(a) {
865
+ 0 < a.output?.length && (Da(gb(a.output)), a.output = []);
866
+ }, hc() {
867
+ return { bc: 25856, dc: 5, ac: 191, cc: 35387, $b: [3, 28, 127, 21, 4, 0, 1, 0, 17, 19, 26, 0, 18, 15, 23, 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] };
868
+ }, ic() {
869
+ return 0;
870
+ }, jc() {
871
+ return [24, 80];
872
+ } }, xb = { ub(a, b) {
873
+ null === b || 10 === b ? (B(gb(a.output)), a.output = []) : 0 != b && a.output.push(b);
874
+ }, fsync(a) {
875
+ 0 < a.output?.length && (B(gb(a.output)), a.output = []);
876
+ } }, O = { Wa: null, Xa() {
877
+ return O.createNode(null, "/", 16895, 0);
878
+ }, createNode(a, b, c, d) {
879
+ if (24576 === (c & 61440) || 4096 === (c & 61440)) throw new N(63);
880
+ O.Wa || (O.Wa = { dir: { node: { Ta: O.La.Ta, Ua: O.La.Ua, lookup: O.La.lookup, ib: O.La.ib, rename: O.La.rename, unlink: O.La.unlink, rmdir: O.La.rmdir, readdir: O.La.readdir, symlink: O.La.symlink }, stream: { Va: O.Ma.Va } }, file: { node: { Ta: O.La.Ta, Ua: O.La.Ua }, stream: { Va: O.Ma.Va, read: O.Ma.read, write: O.Ma.write, jb: O.Ma.jb, kb: O.Ma.kb } }, link: { node: { Ta: O.La.Ta, Ua: O.La.Ua, readlink: O.La.readlink }, stream: {} }, yb: { node: { Ta: O.La.Ta, Ua: O.La.Ua }, stream: yb } });
881
+ c = zb(a, b, c, d);
882
+ P(c.mode) ? (c.La = O.Wa.dir.node, c.Ma = O.Wa.dir.stream, c.Na = {}) : 32768 === (c.mode & 61440) ? (c.La = O.Wa.file.node, c.Ma = O.Wa.file.stream, c.Ra = 0, c.Na = null) : 40960 === (c.mode & 61440) ? (c.La = O.Wa.link.node, c.Ma = O.Wa.link.stream) : 8192 === (c.mode & 61440) && (c.La = O.Wa.yb.node, c.Ma = O.Wa.yb.stream);
883
+ c.atime = c.mtime = c.ctime = Date.now();
884
+ a && (a.Na[b] = c, a.atime = a.mtime = a.ctime = c.atime);
885
+ return c;
886
+ }, fc(a) {
887
+ return a.Na ? a.Na.subarray ? a.Na.subarray(0, a.Ra) : new Uint8Array(a.Na) : new Uint8Array(0);
888
+ }, La: {
889
+ Ta(a) {
890
+ var b = {};
891
+ b.dev = 8192 === (a.mode & 61440) ? a.id : 1;
892
+ b.ino = a.id;
893
+ b.mode = a.mode;
894
+ b.nlink = 1;
895
+ b.uid = 0;
896
+ b.gid = 0;
897
+ b.rdev = a.rdev;
898
+ P(a.mode) ? b.size = 4096 : 32768 === (a.mode & 61440) ? b.size = a.Ra : 40960 === (a.mode & 61440) ? b.size = a.link.length : b.size = 0;
899
+ b.atime = new Date(a.atime);
900
+ b.mtime = new Date(a.mtime);
901
+ b.ctime = new Date(a.ctime);
902
+ b.blksize = 4096;
903
+ b.blocks = Math.ceil(b.size / b.blksize);
904
+ return b;
905
+ },
906
+ Ua(a, b) {
907
+ for (var c of ["mode", "atime", "mtime", "ctime"]) null != b[c] && (a[c] = b[c]);
908
+ void 0 !== b.size && (b = b.size, a.Ra != b && (0 == b ? (a.Na = null, a.Ra = 0) : (c = a.Na, a.Na = new Uint8Array(b), c && a.Na.set(c.subarray(0, Math.min(b, a.Ra))), a.Ra = b)));
909
+ },
910
+ lookup() {
911
+ O.nb || (O.nb = new N(44), O.nb.stack = "<generic error, no stack>");
912
+ throw O.nb;
913
+ },
914
+ ib(a, b, c, d) {
915
+ return O.createNode(a, b, c, d);
916
+ },
917
+ rename(a, b, c) {
918
+ try {
919
+ var d = Q(b, c);
920
+ } catch (g) {
921
+ }
922
+ if (d) {
923
+ if (P(a.mode)) for (var e in d.Na) throw new N(55);
924
+ Ab(d);
925
+ }
926
+ delete a.parent.Na[a.name];
927
+ b.Na[c] = a;
928
+ a.name = c;
929
+ b.ctime = b.mtime = a.parent.ctime = a.parent.mtime = Date.now();
930
+ },
931
+ unlink(a, b) {
932
+ delete a.Na[b];
933
+ a.ctime = a.mtime = Date.now();
934
+ },
935
+ rmdir(a, b) {
936
+ var c = Q(a, b), d;
937
+ for (d in c.Na) throw new N(55);
938
+ delete a.Na[b];
939
+ a.ctime = a.mtime = Date.now();
940
+ },
941
+ readdir(a) {
942
+ return [".", "..", ...Object.keys(a.Na)];
943
+ },
944
+ symlink(a, b, c) {
945
+ a = O.createNode(a, b, 41471, 0);
946
+ a.link = c;
947
+ return a;
948
+ },
949
+ readlink(a) {
950
+ if (40960 !== (a.mode & 61440)) throw new N(28);
951
+ return a.link;
952
+ }
953
+ }, Ma: { read(a, b, c, d, e) {
954
+ var g = a.node.Na;
955
+ if (e >= a.node.Ra) return 0;
956
+ a = Math.min(a.node.Ra - e, d);
957
+ if (8 < a && g.subarray) b.set(g.subarray(e, e + a), c);
958
+ else for (d = 0; d < a; d++) b[c + d] = g[e + d];
959
+ return a;
960
+ }, write(a, b, c, d, e, g) {
961
+ b.buffer === m.buffer && (g = false);
962
+ if (!d) return 0;
963
+ a = a.node;
964
+ a.mtime = a.ctime = Date.now();
965
+ if (b.subarray && (!a.Na || a.Na.subarray)) {
966
+ if (g) return a.Na = b.subarray(c, c + d), a.Ra = d;
967
+ if (0 === a.Ra && 0 === e) return a.Na = b.slice(c, c + d), a.Ra = d;
968
+ if (e + d <= a.Ra) return a.Na.set(b.subarray(c, c + d), e), d;
969
+ }
970
+ g = e + d;
971
+ var h = a.Na ? a.Na.length : 0;
972
+ h >= g || (g = Math.max(g, h * (1048576 > h ? 2 : 1.125) >>> 0), 0 != h && (g = Math.max(g, 256)), h = a.Na, a.Na = new Uint8Array(g), 0 < a.Ra && a.Na.set(h.subarray(0, a.Ra), 0));
973
+ if (a.Na.subarray && b.subarray) a.Na.set(b.subarray(c, c + d), e);
974
+ else for (g = 0; g < d; g++) a.Na[e + g] = b[c + g];
975
+ a.Ra = Math.max(a.Ra, e + d);
976
+ return d;
977
+ }, Va(a, b, c) {
978
+ 1 === c ? b += a.position : 2 === c && 32768 === (a.node.mode & 61440) && (b += a.node.Ra);
979
+ if (0 > b) throw new N(28);
980
+ return b;
981
+ }, jb(a, b, c, d, e) {
982
+ if (32768 !== (a.node.mode & 61440)) throw new N(43);
983
+ a = a.node.Na;
984
+ if (e & 2 || !a || a.buffer !== m.buffer) {
985
+ e = true;
986
+ d = 65536 * Math.ceil(b / 65536);
987
+ var g = Bb(65536, d);
988
+ g && C.fill(0, g, g + d);
989
+ d = g;
990
+ if (!d) throw new N(48);
991
+ if (a) {
992
+ if (0 < c || c + b < a.length) a.subarray ? a = a.subarray(c, c + b) : a = Array.prototype.slice.call(a, c, c + b);
993
+ m.set(a, d);
994
+ }
995
+ } else e = false, d = a.byteOffset;
996
+ return { Xb: d, Eb: e };
997
+ }, kb(a, b, c, d) {
998
+ O.Ma.write(a, b, 0, d, c, false);
999
+ return 0;
1000
+ } } }, ja = (a, b) => {
1001
+ var c = 0;
1002
+ a && (c |= 365);
1003
+ b && (c |= 146);
1004
+ return c;
1005
+ }, Cb = null, Db = {}, Eb = [], Fb = 1, R = null, Gb = false, Hb = true, N = class {
1006
+ constructor(a) {
1007
+ __publicField(this, "name", "ErrnoError");
1008
+ this.Pa = a;
1009
+ }
1010
+ }, Ib = class {
1011
+ constructor() {
1012
+ __publicField(this, "hb", {});
1013
+ __publicField(this, "node", null);
1014
+ }
1015
+ get flags() {
1016
+ return this.hb.flags;
1017
+ }
1018
+ set flags(a) {
1019
+ this.hb.flags = a;
1020
+ }
1021
+ get position() {
1022
+ return this.hb.position;
1023
+ }
1024
+ set position(a) {
1025
+ this.hb.position = a;
1026
+ }
1027
+ }, Jb = class {
1028
+ constructor(a, b, c, d) {
1029
+ __publicField(this, "La", {});
1030
+ __publicField(this, "Ma", {});
1031
+ __publicField(this, "bb", null);
1032
+ a || (a = this);
1033
+ this.parent = a;
1034
+ this.Xa = a.Xa;
1035
+ this.id = Fb++;
1036
+ this.name = b;
1037
+ this.mode = c;
1038
+ this.rdev = d;
1039
+ this.atime = this.mtime = this.ctime = Date.now();
1040
+ }
1041
+ get read() {
1042
+ return 365 === (this.mode & 365);
1043
+ }
1044
+ set read(a) {
1045
+ a ? this.mode |= 365 : this.mode &= -366;
1046
+ }
1047
+ get write() {
1048
+ return 146 === (this.mode & 146);
1049
+ }
1050
+ set write(a) {
1051
+ a ? this.mode |= 146 : this.mode &= -147;
1052
+ }
1053
+ };
1054
+ function S(a, b = {}) {
1055
+ if (!a) throw new N(44);
1056
+ b.pb ?? (b.pb = true);
1057
+ "/" === a.charAt(0) || (a = "//" + a);
1058
+ var c = 0;
1059
+ a: for (; 40 > c; c++) {
1060
+ a = a.split("/").filter((q) => !!q);
1061
+ for (var d = Cb, e = "/", g = 0; g < a.length; g++) {
1062
+ var h = g === a.length - 1;
1063
+ if (h && b.parent) break;
1064
+ if ("." !== a[g]) if (".." === a[g]) if (e = bb(e), d === d.parent) {
1065
+ a = e + "/" + a.slice(g + 1).join("/");
1066
+ c--;
1067
+ continue a;
1068
+ } else d = d.parent;
1069
+ else {
1070
+ e = ia(e + "/" + a[g]);
1071
+ try {
1072
+ d = Q(d, a[g]);
1073
+ } catch (q) {
1074
+ if (44 === q?.Pa && h && b.Wb) return { path: e };
1075
+ throw q;
1076
+ }
1077
+ !d.bb || h && !b.pb || (d = d.bb.root);
1078
+ if (40960 === (d.mode & 61440) && (!h || b.ab)) {
1079
+ if (!d.La.readlink) throw new N(52);
1080
+ d = d.La.readlink(d);
1081
+ "/" === d.charAt(0) || (d = bb(e) + "/" + d);
1082
+ a = d + "/" + a.slice(g + 1).join("/");
1083
+ continue a;
1084
+ }
1085
+ }
1086
+ }
1087
+ return { path: e, node: d };
1088
+ }
1089
+ throw new N(32);
1090
+ }
1091
+ function ha(a) {
1092
+ for (var b; ; ) {
1093
+ if (a === a.parent) return a = a.Xa.Db, b ? "/" !== a[a.length - 1] ? `${a}/${b}` : a + b : a;
1094
+ b = b ? `${a.name}/${b}` : a.name;
1095
+ a = a.parent;
1096
+ }
1097
+ }
1098
+ function Kb(a, b) {
1099
+ for (var c = 0, d = 0; d < b.length; d++) c = (c << 5) - c + b.charCodeAt(d) | 0;
1100
+ return (a + c >>> 0) % R.length;
1101
+ }
1102
+ function Ab(a) {
1103
+ var b = Kb(a.parent.id, a.name);
1104
+ if (R[b] === a) R[b] = a.cb;
1105
+ else for (b = R[b]; b; ) {
1106
+ if (b.cb === a) {
1107
+ b.cb = a.cb;
1108
+ break;
1109
+ }
1110
+ b = b.cb;
1111
+ }
1112
+ }
1113
+ function Q(a, b) {
1114
+ var c = P(a.mode) ? (c = Lb(a, "x")) ? c : a.La.lookup ? 0 : 2 : 54;
1115
+ if (c) throw new N(c);
1116
+ for (c = R[Kb(a.id, b)]; c; c = c.cb) {
1117
+ var d = c.name;
1118
+ if (c.parent.id === a.id && d === b) return c;
1119
+ }
1120
+ return a.La.lookup(a, b);
1121
+ }
1122
+ function zb(a, b, c, d) {
1123
+ a = new Jb(a, b, c, d);
1124
+ b = Kb(a.parent.id, a.name);
1125
+ a.cb = R[b];
1126
+ return R[b] = a;
1127
+ }
1128
+ function P(a) {
1129
+ return 16384 === (a & 61440);
1130
+ }
1131
+ function Lb(a, b) {
1132
+ return Hb ? 0 : b.includes("r") && !(a.mode & 292) || b.includes("w") && !(a.mode & 146) || b.includes("x") && !(a.mode & 73) ? 2 : 0;
1133
+ }
1134
+ function Mb(a, b) {
1135
+ if (!P(a.mode)) return 54;
1136
+ try {
1137
+ return Q(a, b), 20;
1138
+ } catch (c) {
1139
+ }
1140
+ return Lb(a, "wx");
1141
+ }
1142
+ function Nb(a, b, c) {
1143
+ try {
1144
+ var d = Q(a, b);
1145
+ } catch (e) {
1146
+ return e.Pa;
1147
+ }
1148
+ if (a = Lb(a, "wx")) return a;
1149
+ if (c) {
1150
+ if (!P(d.mode)) return 54;
1151
+ if (d === d.parent || "/" === ha(d)) return 10;
1152
+ } else if (P(d.mode)) return 31;
1153
+ return 0;
1154
+ }
1155
+ function Ob(a) {
1156
+ if (!a) throw new N(63);
1157
+ return a;
1158
+ }
1159
+ function T(a) {
1160
+ a = Eb[a];
1161
+ if (!a) throw new N(8);
1162
+ return a;
1163
+ }
1164
+ function Pb(a, b = -1) {
1165
+ a = Object.assign(new Ib(), a);
1166
+ if (-1 == b) a: {
1167
+ for (b = 0; 4096 >= b; b++) if (!Eb[b]) break a;
1168
+ throw new N(33);
1169
+ }
1170
+ a.fd = b;
1171
+ return Eb[b] = a;
1172
+ }
1173
+ function Qb(a, b = -1) {
1174
+ a = Pb(a, b);
1175
+ a.Ma?.ec?.(a);
1176
+ return a;
1177
+ }
1178
+ function Rb(a, b, c) {
1179
+ var d = a?.Ma.Ua;
1180
+ a = d ? a : b;
1181
+ d ?? (d = b.La.Ua);
1182
+ Ob(d);
1183
+ d(a, c);
1184
+ }
1185
+ var yb = { open(a) {
1186
+ a.Ma = Db[a.node.rdev].Ma;
1187
+ a.Ma.open?.(a);
1188
+ }, Va() {
1189
+ throw new N(70);
1190
+ } };
1191
+ function mb(a, b) {
1192
+ Db[a] = { Ma: b };
1193
+ }
1194
+ function Sb(a, b) {
1195
+ var c = "/" === b;
1196
+ if (c && Cb) throw new N(10);
1197
+ if (!c && b) {
1198
+ var d = S(b, { pb: false });
1199
+ b = d.path;
1200
+ d = d.node;
1201
+ if (d.bb) throw new N(10);
1202
+ if (!P(d.mode)) throw new N(54);
1203
+ }
1204
+ b = { type: a, kc: {}, Db: b, Vb: [] };
1205
+ a = a.Xa(b);
1206
+ a.Xa = b;
1207
+ b.root = a;
1208
+ c ? Cb = a : d && (d.bb = b, d.Xa && d.Xa.Vb.push(b));
1209
+ }
1210
+ function Tb(a, b, c) {
1211
+ var d = S(a, { parent: true }).node;
1212
+ a = cb(a);
1213
+ if (!a) throw new N(28);
1214
+ if ("." === a || ".." === a) throw new N(20);
1215
+ var e = Mb(d, a);
1216
+ if (e) throw new N(e);
1217
+ if (!d.La.ib) throw new N(63);
1218
+ return d.La.ib(d, a, b, c);
1219
+ }
1220
+ function ka(a, b = 438) {
1221
+ return Tb(a, b & 4095 | 32768, 0);
1222
+ }
1223
+ function U(a, b = 511) {
1224
+ return Tb(a, b & 1023 | 16384, 0);
1225
+ }
1226
+ function Ub(a, b, c) {
1227
+ "undefined" == typeof c && (c = b, b = 438);
1228
+ Tb(a, b | 8192, c);
1229
+ }
1230
+ function Vb(a, b) {
1231
+ if (!fb(a)) throw new N(44);
1232
+ var c = S(b, { parent: true }).node;
1233
+ if (!c) throw new N(44);
1234
+ b = cb(b);
1235
+ var d = Mb(c, b);
1236
+ if (d) throw new N(d);
1237
+ if (!c.La.symlink) throw new N(63);
1238
+ c.La.symlink(c, b, a);
1239
+ }
1240
+ function Wb(a) {
1241
+ var b = S(a, { parent: true }).node;
1242
+ a = cb(a);
1243
+ var c = Q(b, a), d = Nb(b, a, true);
1244
+ if (d) throw new N(d);
1245
+ if (!b.La.rmdir) throw new N(63);
1246
+ if (c.bb) throw new N(10);
1247
+ b.La.rmdir(b, a);
1248
+ Ab(c);
1249
+ }
1250
+ function ua(a) {
1251
+ var b = S(a, { parent: true }).node;
1252
+ if (!b) throw new N(44);
1253
+ a = cb(a);
1254
+ var c = Q(b, a), d = Nb(b, a, false);
1255
+ if (d) throw new N(d);
1256
+ if (!b.La.unlink) throw new N(63);
1257
+ if (c.bb) throw new N(10);
1258
+ b.La.unlink(b, a);
1259
+ Ab(c);
1260
+ }
1261
+ function Xb(a, b) {
1262
+ a = S(a, { ab: !b }).node;
1263
+ return Ob(a.La.Ta)(a);
1264
+ }
1265
+ function Yb(a, b, c, d) {
1266
+ Rb(a, b, { mode: c & 4095 | b.mode & -4096, ctime: Date.now(), Lb: d });
1267
+ }
1268
+ function la(a, b) {
1269
+ a = "string" == typeof a ? S(a, { ab: true }).node : a;
1270
+ Yb(null, a, b);
1271
+ }
1272
+ function Zb(a, b, c) {
1273
+ if (P(b.mode)) throw new N(31);
1274
+ if (32768 !== (b.mode & 61440)) throw new N(28);
1275
+ var d = Lb(b, "w");
1276
+ if (d) throw new N(d);
1277
+ Rb(a, b, { size: c, timestamp: Date.now() });
1278
+ }
1279
+ function ma(a, b, c = 438) {
1280
+ if ("" === a) throw new N(44);
1281
+ if ("string" == typeof b) {
1282
+ var d = { r: 0, "r+": 2, w: 577, "w+": 578, a: 1089, "a+": 1090 }[b];
1283
+ if ("undefined" == typeof d) throw Error(`Unknown file open mode: ${b}`);
1284
+ b = d;
1285
+ }
1286
+ c = b & 64 ? c & 4095 | 32768 : 0;
1287
+ if ("object" == typeof a) d = a;
1288
+ else {
1289
+ var e = a.endsWith("/");
1290
+ var g = S(a, { ab: !(b & 131072), Wb: true });
1291
+ d = g.node;
1292
+ a = g.path;
1293
+ }
1294
+ g = false;
1295
+ if (b & 64) if (d) {
1296
+ if (b & 128) throw new N(20);
1297
+ } else {
1298
+ if (e) throw new N(31);
1299
+ d = Tb(a, c | 511, 0);
1300
+ g = true;
1301
+ }
1302
+ if (!d) throw new N(44);
1303
+ 8192 === (d.mode & 61440) && (b &= -513);
1304
+ if (b & 65536 && !P(d.mode)) throw new N(54);
1305
+ if (!g && (d ? 40960 === (d.mode & 61440) ? e = 32 : (e = ["r", "w", "rw"][b & 3], b & 512 && (e += "w"), e = P(d.mode) && ("r" !== e || b & 576) ? 31 : Lb(d, e)) : e = 44, e)) throw new N(e);
1306
+ b & 512 && !g && (e = d, e = "string" == typeof e ? S(e, { ab: true }).node : e, Zb(null, e, 0));
1307
+ b = Pb({ node: d, path: ha(d), flags: b & -131713, seekable: true, position: 0, Ma: d.Ma, Yb: [], error: false });
1308
+ b.Ma.open && b.Ma.open(b);
1309
+ g && la(d, c & 511);
1310
+ return b;
1311
+ }
1312
+ function oa(a) {
1313
+ if (null === a.fd) throw new N(8);
1314
+ a.rb && (a.rb = null);
1315
+ try {
1316
+ a.Ma.close && a.Ma.close(a);
1317
+ } catch (b) {
1318
+ throw b;
1319
+ } finally {
1320
+ Eb[a.fd] = null;
1321
+ }
1322
+ a.fd = null;
1323
+ }
1324
+ function $b(a, b, c) {
1325
+ if (null === a.fd) throw new N(8);
1326
+ if (!a.seekable || !a.Ma.Va) throw new N(70);
1327
+ if (0 != c && 1 != c && 2 != c) throw new N(28);
1328
+ a.position = a.Ma.Va(a, b, c);
1329
+ a.Yb = [];
1330
+ }
1331
+ function ac(a, b, c, d, e) {
1332
+ if (0 > d || 0 > e) throw new N(28);
1333
+ if (null === a.fd) throw new N(8);
1334
+ if (1 === (a.flags & 2097155)) throw new N(8);
1335
+ if (P(a.node.mode)) throw new N(31);
1336
+ if (!a.Ma.read) throw new N(28);
1337
+ var g = "undefined" != typeof e;
1338
+ if (!g) e = a.position;
1339
+ else if (!a.seekable) throw new N(70);
1340
+ b = a.Ma.read(a, b, c, d, e);
1341
+ g || (a.position += b);
1342
+ return b;
1343
+ }
1344
+ function na(a, b, c, d, e) {
1345
+ if (0 > d || 0 > e) throw new N(28);
1346
+ if (null === a.fd) throw new N(8);
1347
+ if (0 === (a.flags & 2097155)) throw new N(8);
1348
+ if (P(a.node.mode)) throw new N(31);
1349
+ if (!a.Ma.write) throw new N(28);
1350
+ a.seekable && a.flags & 1024 && $b(a, 0, 2);
1351
+ var g = "undefined" != typeof e;
1352
+ if (!g) e = a.position;
1353
+ else if (!a.seekable) throw new N(70);
1354
+ b = a.Ma.write(a, b, c, d, e, void 0);
1355
+ g || (a.position += b);
1356
+ return b;
1357
+ }
1358
+ function ta(a) {
1359
+ var b = b || 0;
1360
+ var c = "binary";
1361
+ "utf8" !== c && "binary" !== c && Ma(`Invalid encoding type "${c}"`);
1362
+ b = ma(a, b);
1363
+ a = Xb(a).size;
1364
+ var d = new Uint8Array(a);
1365
+ ac(b, d, 0, a, 0);
1366
+ "utf8" === c && (d = gb(d));
1367
+ oa(b);
1368
+ return d;
1369
+ }
1370
+ function W(a, b, c) {
1371
+ a = ia("/dev/" + a);
1372
+ var d = ja(!!b, !!c);
1373
+ W.Cb ?? (W.Cb = 64);
1374
+ var e = W.Cb++ << 8 | 0;
1375
+ mb(e, { open(g) {
1376
+ g.seekable = false;
1377
+ }, close() {
1378
+ c?.buffer?.length && c(10);
1379
+ }, read(g, h, q, w) {
1380
+ for (var t = 0, x = 0; x < w; x++) {
1381
+ try {
1382
+ var D = b();
1383
+ } catch (pb) {
1384
+ throw new N(29);
1385
+ }
1386
+ if (void 0 === D && 0 === t) throw new N(6);
1387
+ if (null === D || void 0 === D) break;
1388
+ t++;
1389
+ h[q + x] = D;
1390
+ }
1391
+ t && (g.node.atime = Date.now());
1392
+ return t;
1393
+ }, write(g, h, q, w) {
1394
+ for (var t = 0; t < w; t++) try {
1395
+ c(h[q + t]);
1396
+ } catch (x) {
1397
+ throw new N(29);
1398
+ }
1399
+ w && (g.node.mtime = g.node.ctime = Date.now());
1400
+ return t;
1401
+ } });
1402
+ Ub(a, d, e);
1403
+ }
1404
+ var X = {};
1405
+ function Y(a, b, c) {
1406
+ if ("/" === b.charAt(0)) return b;
1407
+ a = -100 === a ? "/" : T(a).path;
1408
+ if (0 == b.length) {
1409
+ if (!c) throw new N(44);
1410
+ return a;
1411
+ }
1412
+ return a + "/" + b;
1413
+ }
1414
+ function kc(a, b) {
1415
+ F[a >> 2] = b.dev;
1416
+ F[a + 4 >> 2] = b.mode;
1417
+ F[a + 8 >> 2] = b.nlink;
1418
+ F[a + 12 >> 2] = b.uid;
1419
+ F[a + 16 >> 2] = b.gid;
1420
+ F[a + 20 >> 2] = b.rdev;
1421
+ G[a + 24 >> 3] = BigInt(b.size);
1422
+ E[a + 32 >> 2] = 4096;
1423
+ E[a + 36 >> 2] = b.blocks;
1424
+ var c = b.atime.getTime(), d = b.mtime.getTime(), e = b.ctime.getTime();
1425
+ G[a + 40 >> 3] = BigInt(Math.floor(c / 1e3));
1426
+ F[a + 48 >> 2] = c % 1e3 * 1e6;
1427
+ G[a + 56 >> 3] = BigInt(Math.floor(d / 1e3));
1428
+ F[a + 64 >> 2] = d % 1e3 * 1e6;
1429
+ G[a + 72 >> 3] = BigInt(Math.floor(e / 1e3));
1430
+ F[a + 80 >> 2] = e % 1e3 * 1e6;
1431
+ G[a + 88 >> 3] = BigInt(b.ino);
1432
+ return 0;
1433
+ }
1434
+ var Cc = void 0, Ec = () => {
1435
+ var a = E[+Cc >> 2];
1436
+ Cc += 4;
1437
+ return a;
1438
+ }, Fc = 0, Gc = [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335], Hc = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334], Ic = {}, Jc = (a) => {
1439
+ Ga = a;
1440
+ Ya || 0 < Fc || (k.onExit?.(a), Fa = true);
1441
+ xa(a, new Sa(a));
1442
+ }, Kc = (a) => {
1443
+ if (!Fa) try {
1444
+ a();
1445
+ } catch (b) {
1446
+ b instanceof Sa || "unwind" == b || xa(1, b);
1447
+ } finally {
1448
+ if (!(Ya || 0 < Fc)) try {
1449
+ Ga = a = Ga, Jc(a);
1450
+ } catch (b) {
1451
+ b instanceof Sa || "unwind" == b || xa(1, b);
1452
+ }
1453
+ }
1454
+ }, Lc = {}, Nc = () => {
1455
+ if (!Mc) {
1456
+ var a = { USER: "web_user", LOGNAME: "web_user", PATH: "/", PWD: "/", HOME: "/home/web_user", LANG: (globalThis.navigator?.language ?? "C").replace("-", "_") + ".UTF-8", _: wa || "./this.program" }, b;
1457
+ for (b in Lc) void 0 === Lc[b] ? delete a[b] : a[b] = Lc[b];
1458
+ var c = [];
1459
+ for (b in a) c.push(`${b}=${a[b]}`);
1460
+ Mc = c;
1461
+ }
1462
+ return Mc;
1463
+ }, Mc, Oc = (a, b, c, d) => {
1464
+ var e = { string: (t) => {
1465
+ var x = 0;
1466
+ if (null !== t && void 0 !== t && 0 !== t) {
1467
+ x = ib(t) + 1;
1468
+ var D = y(x);
1469
+ M(t, C, D, x);
1470
+ x = D;
1471
+ }
1472
+ return x;
1473
+ }, array: (t) => {
1474
+ var x = y(t.length);
1475
+ m.set(t, x);
1476
+ return x;
1477
+ } };
1478
+ a = k["_" + a];
1479
+ var g = [], h = 0;
1480
+ if (d) for (var q = 0; q < d.length; q++) {
1481
+ var w = e[c[q]];
1482
+ w ? (0 === h && (h = pa()), g[q] = w(d[q])) : g[q] = d[q];
1483
+ }
1484
+ c = a(...g);
1485
+ return c = (function(t) {
1486
+ 0 !== h && ra(h);
1487
+ return "string" === b ? z(t) : "boolean" === b ? !!t : t;
1488
+ })(c);
1489
+ }, fa = (a) => {
1490
+ var b = ib(a) + 1, c = da(b);
1491
+ c && M(a, C, c, b);
1492
+ return c;
1493
+ }, Pc, Qc = [], A = (a) => {
1494
+ Pc.delete(Z.get(a));
1495
+ Z.set(a, null);
1496
+ Qc.push(a);
1497
+ }, Rc = (a) => {
1498
+ const b = a.length;
1499
+ return [b % 128 | 128, b >> 7, ...a];
1500
+ }, Sc = { i: 127, p: 127, j: 126, f: 125, d: 124, e: 111 }, Tc = (a) => Rc(Array.from(a, (b) => Sc[b])), va = (a, b) => {
1501
+ if (!Pc) {
1502
+ Pc = /* @__PURE__ */ new WeakMap();
1503
+ var c = Z.length;
1504
+ if (Pc) for (var d = 0; d < 0 + c; d++) {
1505
+ var e = Z.get(d);
1506
+ e && Pc.set(e, d);
1507
+ }
1508
+ }
1509
+ if (c = Pc.get(a) || 0) return c;
1510
+ c = Qc.length ? Qc.pop() : Z.grow(1);
1511
+ try {
1512
+ Z.set(c, a);
1513
+ } catch (g) {
1514
+ if (!(g instanceof TypeError)) throw g;
1515
+ b = Uint8Array.of(0, 97, 115, 109, 1, 0, 0, 0, 1, ...Rc([1, 96, ...Tc(b.slice(1)), ...Tc("v" === b[0] ? "" : b[0])]), 2, 7, 1, 1, 101, 1, 102, 0, 0, 7, 5, 1, 1, 102, 0, 0);
1516
+ b = new WebAssembly.Module(b);
1517
+ b = new WebAssembly.Instance(b, { e: { f: a } }).exports.f;
1518
+ Z.set(c, b);
1519
+ }
1520
+ Pc.set(a, c);
1521
+ return c;
1522
+ };
1523
+ R = Array(4096);
1524
+ Sb(O, "/");
1525
+ U("/tmp");
1526
+ U("/home");
1527
+ U("/home/web_user");
1528
+ (function() {
1529
+ U("/dev");
1530
+ mb(259, { read: () => 0, write: (d, e, g, h) => h, Va: () => 0 });
1531
+ Ub("/dev/null", 259);
1532
+ kb(1280, wb);
1533
+ kb(1536, xb);
1534
+ Ub("/dev/tty", 1280);
1535
+ Ub("/dev/tty1", 1536);
1536
+ var a = new Uint8Array(1024), b = 0, c = () => {
1537
+ 0 === b && (eb(a), b = a.byteLength);
1538
+ return a[--b];
1539
+ };
1540
+ W("random", c);
1541
+ W("urandom", c);
1542
+ U("/dev/shm");
1543
+ U("/dev/shm/tmp");
1544
+ })();
1545
+ (function() {
1546
+ U("/proc");
1547
+ var a = U("/proc/self");
1548
+ U("/proc/self/fd");
1549
+ Sb({ Xa() {
1550
+ var b = zb(a, "fd", 16895, 73);
1551
+ b.Ma = { Va: O.Ma.Va };
1552
+ b.La = { lookup(c, d) {
1553
+ c = +d;
1554
+ var e = T(c);
1555
+ c = { parent: null, Xa: { Db: "fake" }, La: { readlink: () => e.path }, id: c + 1 };
1556
+ return c.parent = c;
1557
+ }, readdir() {
1558
+ return Array.from(Eb.entries()).filter(([, c]) => c).map(([c]) => c.toString());
1559
+ } };
1560
+ return b;
1561
+ } }, "/proc/self/fd");
1562
+ })();
1563
+ k.noExitRuntime && (Ya = k.noExitRuntime);
1564
+ k.print && (Da = k.print);
1565
+ k.printErr && (B = k.printErr);
1566
+ k.wasmBinary && (Ea = k.wasmBinary);
1567
+ k.thisProgram && (wa = k.thisProgram);
1568
+ if (k.preInit) for ("function" == typeof k.preInit && (k.preInit = [k.preInit]); 0 < k.preInit.length; ) k.preInit.shift()();
1569
+ k.stackSave = () => pa();
1570
+ k.stackRestore = (a) => ra(a);
1571
+ k.stackAlloc = (a) => y(a);
1572
+ k.cwrap = (a, b, c, d) => {
1573
+ var e = !c || c.every((g) => "number" === g || "boolean" === g);
1574
+ return "string" !== b && e && !d ? k["_" + a] : (...g) => Oc(a, b, c, g);
1575
+ };
1576
+ k.addFunction = va;
1577
+ k.removeFunction = A;
1578
+ k.UTF8ToString = z;
1579
+ k.stringToNewUTF8 = fa;
1580
+ k.writeArrayToMemory = (a, b) => {
1581
+ m.set(a, b);
1582
+ };
1583
+ var da, ea, Bb, Uc, ra, y, pa, La, Z, Vc = {
1584
+ a: (a, b, c, d) => Ma(`Assertion failed: ${z(a)}, at: ` + [b ? z(b) : "unknown filename", c, d ? z(d) : "unknown function"]),
1585
+ i: function(a, b) {
1586
+ try {
1587
+ return a = z(a), la(a, b), 0;
1588
+ } catch (c) {
1589
+ if ("undefined" == typeof X || "ErrnoError" !== c.name) throw c;
1590
+ return -c.Pa;
1591
+ }
1592
+ },
1593
+ L: function(a, b, c) {
1594
+ try {
1595
+ b = z(b);
1596
+ b = Y(a, b);
1597
+ if (c & -8) return -28;
1598
+ var d = S(b, { ab: true }).node;
1599
+ if (!d) return -44;
1600
+ a = "";
1601
+ c & 4 && (a += "r");
1602
+ c & 2 && (a += "w");
1603
+ c & 1 && (a += "x");
1604
+ return a && Lb(d, a) ? -2 : 0;
1605
+ } catch (e) {
1606
+ if ("undefined" == typeof X || "ErrnoError" !== e.name) throw e;
1607
+ return -e.Pa;
1608
+ }
1609
+ },
1610
+ j: function(a, b) {
1611
+ try {
1612
+ var c = T(a);
1613
+ Yb(c, c.node, b, false);
1614
+ return 0;
1615
+ } catch (d) {
1616
+ if ("undefined" == typeof X || "ErrnoError" !== d.name) throw d;
1617
+ return -d.Pa;
1618
+ }
1619
+ },
1620
+ h: function(a) {
1621
+ try {
1622
+ var b = T(a);
1623
+ Rb(b, b.node, { timestamp: Date.now(), Lb: false });
1624
+ return 0;
1625
+ } catch (c) {
1626
+ if ("undefined" == typeof X || "ErrnoError" !== c.name) throw c;
1627
+ return -c.Pa;
1628
+ }
1629
+ },
1630
+ b: function(a, b, c) {
1631
+ Cc = c;
1632
+ try {
1633
+ var d = T(a);
1634
+ switch (b) {
1635
+ case 0:
1636
+ var e = Ec();
1637
+ if (0 > e) break;
1638
+ for (; Eb[e]; ) e++;
1639
+ return Qb(d, e).fd;
1640
+ case 1:
1641
+ case 2:
1642
+ return 0;
1643
+ case 3:
1644
+ return d.flags;
1645
+ case 4:
1646
+ return e = Ec(), d.flags |= e, 0;
1647
+ case 12:
1648
+ return e = Ec(), Ha[e + 0 >> 1] = 2, 0;
1649
+ case 13:
1650
+ case 14:
1651
+ return 0;
1652
+ }
1653
+ return -28;
1654
+ } catch (g) {
1655
+ if ("undefined" == typeof X || "ErrnoError" !== g.name) throw g;
1656
+ return -g.Pa;
1657
+ }
1658
+ },
1659
+ g: function(a, b) {
1660
+ try {
1661
+ var c = T(a), d = c.node, e = c.Ma.Ta;
1662
+ a = e ? c : d;
1663
+ e ?? (e = d.La.Ta);
1664
+ Ob(e);
1665
+ var g = e(a);
1666
+ return kc(b, g);
1667
+ } catch (h) {
1668
+ if ("undefined" == typeof X || "ErrnoError" !== h.name) throw h;
1669
+ return -h.Pa;
1670
+ }
1671
+ },
1672
+ H: function(a, b) {
1673
+ b = -9007199254740992 > b || 9007199254740992 < b ? NaN : Number(b);
1674
+ try {
1675
+ if (isNaN(b)) return -61;
1676
+ var c = T(a);
1677
+ if (0 > b || 0 === (c.flags & 2097155)) throw new N(28);
1678
+ Zb(c, c.node, b);
1679
+ return 0;
1680
+ } catch (d) {
1681
+ if ("undefined" == typeof X || "ErrnoError" !== d.name) throw d;
1682
+ return -d.Pa;
1683
+ }
1684
+ },
1685
+ G: function(a, b) {
1686
+ try {
1687
+ if (0 === b) return -28;
1688
+ var c = ib("/") + 1;
1689
+ if (b < c) return -68;
1690
+ M("/", C, a, b);
1691
+ return c;
1692
+ } catch (d) {
1693
+ if ("undefined" == typeof X || "ErrnoError" !== d.name) throw d;
1694
+ return -d.Pa;
1695
+ }
1696
+ },
1697
+ K: function(a, b) {
1698
+ try {
1699
+ return a = z(a), kc(b, Xb(a, true));
1700
+ } catch (c) {
1701
+ if ("undefined" == typeof X || "ErrnoError" !== c.name) throw c;
1702
+ return -c.Pa;
1703
+ }
1704
+ },
1705
+ C: function(a, b, c) {
1706
+ try {
1707
+ return b = z(b), b = Y(a, b), U(b, c), 0;
1708
+ } catch (d) {
1709
+ if ("undefined" == typeof X || "ErrnoError" !== d.name) throw d;
1710
+ return -d.Pa;
1711
+ }
1712
+ },
1713
+ J: function(a, b, c, d) {
1714
+ try {
1715
+ b = z(b);
1716
+ var e = d & 256;
1717
+ b = Y(a, b, d & 4096);
1718
+ return kc(c, e ? Xb(b, true) : Xb(b));
1719
+ } catch (g) {
1720
+ if ("undefined" == typeof X || "ErrnoError" !== g.name) throw g;
1721
+ return -g.Pa;
1722
+ }
1723
+ },
1724
+ x: function(a, b, c, d) {
1725
+ Cc = d;
1726
+ try {
1727
+ b = z(b);
1728
+ b = Y(a, b);
1729
+ var e = d ? Ec() : 0;
1730
+ return ma(b, c, e).fd;
1731
+ } catch (g) {
1732
+ if ("undefined" == typeof X || "ErrnoError" !== g.name) throw g;
1733
+ return -g.Pa;
1734
+ }
1735
+ },
1736
+ v: function(a, b, c, d) {
1737
+ try {
1738
+ b = z(b);
1739
+ b = Y(a, b);
1740
+ if (0 >= d) return -28;
1741
+ var e = S(b).node;
1742
+ if (!e) throw new N(44);
1743
+ if (!e.La.readlink) throw new N(28);
1744
+ var g = e.La.readlink(e);
1745
+ var h = Math.min(d, ib(g)), q = m[c + h];
1746
+ M(
1747
+ g,
1748
+ C,
1749
+ c,
1750
+ d + 1
1751
+ );
1752
+ m[c + h] = q;
1753
+ return h;
1754
+ } catch (w) {
1755
+ if ("undefined" == typeof X || "ErrnoError" !== w.name) throw w;
1756
+ return -w.Pa;
1757
+ }
1758
+ },
1759
+ u: function(a) {
1760
+ try {
1761
+ return a = z(a), Wb(a), 0;
1762
+ } catch (b) {
1763
+ if ("undefined" == typeof X || "ErrnoError" !== b.name) throw b;
1764
+ return -b.Pa;
1765
+ }
1766
+ },
1767
+ f: function(a, b) {
1768
+ try {
1769
+ return a = z(a), kc(b, Xb(a));
1770
+ } catch (c) {
1771
+ if ("undefined" == typeof X || "ErrnoError" !== c.name) throw c;
1772
+ return -c.Pa;
1773
+ }
1774
+ },
1775
+ r: function(a, b, c) {
1776
+ try {
1777
+ b = z(b);
1778
+ b = Y(a, b);
1779
+ if (c) if (512 === c) Wb(b);
1780
+ else return -28;
1781
+ else ua(b);
1782
+ return 0;
1783
+ } catch (d) {
1784
+ if ("undefined" == typeof X || "ErrnoError" !== d.name) throw d;
1785
+ return -d.Pa;
1786
+ }
1787
+ },
1788
+ q: function(a, b, c) {
1789
+ try {
1790
+ b = z(b);
1791
+ b = Y(a, b, true);
1792
+ var d = Date.now(), e, g;
1793
+ if (c) {
1794
+ var h = F[c >> 2] + 4294967296 * E[c + 4 >> 2], q = E[c + 8 >> 2];
1795
+ 1073741823 == q ? e = d : 1073741822 == q ? e = null : e = 1e3 * h + q / 1e6;
1796
+ c += 16;
1797
+ h = F[c >> 2] + 4294967296 * E[c + 4 >> 2];
1798
+ q = E[c + 8 >> 2];
1799
+ 1073741823 == q ? g = d : 1073741822 == q ? g = null : g = 1e3 * h + q / 1e6;
1800
+ } else g = e = d;
1801
+ if (null !== (g ?? e)) {
1802
+ a = e;
1803
+ var w = S(b, { ab: true }).node;
1804
+ Ob(w.La.Ua)(w, { atime: a, mtime: g });
1805
+ }
1806
+ return 0;
1807
+ } catch (t) {
1808
+ if ("undefined" == typeof X || "ErrnoError" !== t.name) throw t;
1809
+ return -t.Pa;
1810
+ }
1811
+ },
1812
+ m: () => Ma(""),
1813
+ l: () => {
1814
+ Ya = false;
1815
+ Fc = 0;
1816
+ },
1817
+ A: function(a, b) {
1818
+ a = -9007199254740992 > a || 9007199254740992 < a ? NaN : Number(a);
1819
+ a = new Date(1e3 * a);
1820
+ E[b >> 2] = a.getSeconds();
1821
+ E[b + 4 >> 2] = a.getMinutes();
1822
+ E[b + 8 >> 2] = a.getHours();
1823
+ E[b + 12 >> 2] = a.getDate();
1824
+ E[b + 16 >> 2] = a.getMonth();
1825
+ E[b + 20 >> 2] = a.getFullYear() - 1900;
1826
+ E[b + 24 >> 2] = a.getDay();
1827
+ var c = a.getFullYear();
1828
+ E[b + 28 >> 2] = (0 !== c % 4 || 0 === c % 100 && 0 !== c % 400 ? Hc : Gc)[a.getMonth()] + a.getDate() - 1 | 0;
1829
+ E[b + 36 >> 2] = -(60 * a.getTimezoneOffset());
1830
+ c = new Date(a.getFullYear(), 6, 1).getTimezoneOffset();
1831
+ var d = new Date(a.getFullYear(), 0, 1).getTimezoneOffset();
1832
+ E[b + 32 >> 2] = (c != d && a.getTimezoneOffset() == Math.min(d, c)) | 0;
1833
+ },
1834
+ y: function(a, b, c, d, e, g, h) {
1835
+ e = -9007199254740992 > e || 9007199254740992 < e ? NaN : Number(e);
1836
+ try {
1837
+ var q = T(d);
1838
+ if (0 !== (b & 2) && 0 === (c & 2) && 2 !== (q.flags & 2097155)) throw new N(2);
1839
+ if (1 === (q.flags & 2097155)) throw new N(2);
1840
+ if (!q.Ma.jb) throw new N(43);
1841
+ if (!a) throw new N(28);
1842
+ var w = q.Ma.jb(q, a, e, b, c);
1843
+ var t = w.Xb;
1844
+ E[g >> 2] = w.Eb;
1845
+ F[h >> 2] = t;
1846
+ return 0;
1847
+ } catch (x) {
1848
+ if ("undefined" == typeof X || "ErrnoError" !== x.name) throw x;
1849
+ return -x.Pa;
1850
+ }
1851
+ },
1852
+ z: function(a, b, c, d, e, g) {
1853
+ g = -9007199254740992 > g || 9007199254740992 < g ? NaN : Number(g);
1854
+ try {
1855
+ var h = T(e);
1856
+ if (c & 2) {
1857
+ c = g;
1858
+ if (32768 !== (h.node.mode & 61440)) throw new N(43);
1859
+ if (!(d & 2)) {
1860
+ var q = C.slice(a, a + b);
1861
+ h.Ma.kb && h.Ma.kb(h, q, c, b, d);
1862
+ }
1863
+ }
1864
+ } catch (w) {
1865
+ if ("undefined" == typeof X || "ErrnoError" !== w.name) throw w;
1866
+ return -w.Pa;
1867
+ }
1868
+ },
1869
+ n: (a, b) => {
1870
+ Ic[a] && (clearTimeout(Ic[a].id), delete Ic[a]);
1871
+ if (!b) return 0;
1872
+ var c = setTimeout(() => {
1873
+ delete Ic[a];
1874
+ Kc(() => Uc(a, performance.now()));
1875
+ }, b);
1876
+ Ic[a] = { id: c, lc: b };
1877
+ return 0;
1878
+ },
1879
+ B: (a, b, c, d) => {
1880
+ var e = (/* @__PURE__ */ new Date()).getFullYear(), g = new Date(e, 0, 1).getTimezoneOffset();
1881
+ e = new Date(e, 6, 1).getTimezoneOffset();
1882
+ F[a >> 2] = 60 * Math.max(g, e);
1883
+ E[b >> 2] = Number(g != e);
1884
+ b = (h) => {
1885
+ var q = Math.abs(h);
1886
+ return `UTC${0 <= h ? "-" : "+"}${String(Math.floor(q / 60)).padStart(2, "0")}${String(q % 60).padStart(2, "0")}`;
1887
+ };
1888
+ a = b(g);
1889
+ b = b(e);
1890
+ e < g ? (M(a, C, c, 17), M(b, C, d, 17)) : (M(a, C, d, 17), M(b, C, c, 17));
1891
+ },
1892
+ d: () => Date.now(),
1893
+ s: () => 2147483648,
1894
+ c: () => performance.now(),
1895
+ o: (a) => {
1896
+ var b = C.length;
1897
+ a >>>= 0;
1898
+ if (2147483648 < a) return false;
1899
+ for (var c = 1; 4 >= c; c *= 2) {
1900
+ var d = b * (1 + 0.2 / c);
1901
+ d = Math.min(d, a + 100663296);
1902
+ a: {
1903
+ d = (Math.min(2147483648, 65536 * Math.ceil(Math.max(
1904
+ a,
1905
+ d
1906
+ ) / 65536)) - La.buffer.byteLength + 65535) / 65536 | 0;
1907
+ try {
1908
+ La.grow(d);
1909
+ Ka();
1910
+ var e = 1;
1911
+ break a;
1912
+ } catch (g) {
1913
+ }
1914
+ e = void 0;
1915
+ }
1916
+ if (e) return true;
1917
+ }
1918
+ return false;
1919
+ },
1920
+ E: (a, b) => {
1921
+ var c = 0, d = 0, e;
1922
+ for (e of Nc()) {
1923
+ var g = b + c;
1924
+ F[a + d >> 2] = g;
1925
+ c += M(e, C, g, Infinity) + 1;
1926
+ d += 4;
1927
+ }
1928
+ return 0;
1929
+ },
1930
+ F: (a, b) => {
1931
+ var c = Nc();
1932
+ F[a >> 2] = c.length;
1933
+ a = 0;
1934
+ for (var d of c) a += ib(d) + 1;
1935
+ F[b >> 2] = a;
1936
+ return 0;
1937
+ },
1938
+ e: function(a) {
1939
+ try {
1940
+ var b = T(a);
1941
+ oa(b);
1942
+ return 0;
1943
+ } catch (c) {
1944
+ if ("undefined" == typeof X || "ErrnoError" !== c.name) throw c;
1945
+ return c.Pa;
1946
+ }
1947
+ },
1948
+ p: function(a, b) {
1949
+ try {
1950
+ var c = T(a);
1951
+ m[b] = c.tty ? 2 : P(c.mode) ? 3 : 40960 === (c.mode & 61440) ? 7 : 4;
1952
+ Ha[b + 2 >> 1] = 0;
1953
+ G[b + 8 >> 3] = BigInt(0);
1954
+ G[b + 16 >> 3] = BigInt(0);
1955
+ return 0;
1956
+ } catch (d) {
1957
+ if ("undefined" == typeof X || "ErrnoError" !== d.name) throw d;
1958
+ return d.Pa;
1959
+ }
1960
+ },
1961
+ w: function(a, b, c, d) {
1962
+ try {
1963
+ a: {
1964
+ var e = T(a);
1965
+ a = b;
1966
+ for (var g, h = b = 0; h < c; h++) {
1967
+ var q = F[a >> 2], w = F[a + 4 >> 2];
1968
+ a += 8;
1969
+ var t = ac(e, m, q, w, g);
1970
+ if (0 > t) {
1971
+ var x = -1;
1972
+ break a;
1973
+ }
1974
+ b += t;
1975
+ if (t < w) break;
1976
+ "undefined" != typeof g && (g += t);
1977
+ }
1978
+ x = b;
1979
+ }
1980
+ F[d >> 2] = x;
1981
+ return 0;
1982
+ } catch (D) {
1983
+ if ("undefined" == typeof X || "ErrnoError" !== D.name) throw D;
1984
+ return D.Pa;
1985
+ }
1986
+ },
1987
+ D: function(a, b, c, d) {
1988
+ b = -9007199254740992 > b || 9007199254740992 < b ? NaN : Number(b);
1989
+ try {
1990
+ if (isNaN(b)) return 61;
1991
+ var e = T(a);
1992
+ $b(e, b, c);
1993
+ G[d >> 3] = BigInt(e.position);
1994
+ e.rb && 0 === b && 0 === c && (e.rb = null);
1995
+ return 0;
1996
+ } catch (g) {
1997
+ if ("undefined" == typeof X || "ErrnoError" !== g.name) throw g;
1998
+ return g.Pa;
1999
+ }
2000
+ },
2001
+ I: function(a) {
2002
+ try {
2003
+ var b = T(a);
2004
+ return b.Ma?.fsync?.(b);
2005
+ } catch (c) {
2006
+ if ("undefined" == typeof X || "ErrnoError" !== c.name) throw c;
2007
+ return c.Pa;
2008
+ }
2009
+ },
2010
+ t: function(a, b, c, d) {
2011
+ try {
2012
+ a: {
2013
+ var e = T(a);
2014
+ a = b;
2015
+ for (var g, h = b = 0; h < c; h++) {
2016
+ var q = F[a >> 2], w = F[a + 4 >> 2];
2017
+ a += 8;
2018
+ var t = na(e, m, q, w, g);
2019
+ if (0 > t) {
2020
+ var x = -1;
2021
+ break a;
2022
+ }
2023
+ b += t;
2024
+ if (t < w) break;
2025
+ "undefined" != typeof g && (g += t);
2026
+ }
2027
+ x = b;
2028
+ }
2029
+ F[d >> 2] = x;
2030
+ return 0;
2031
+ } catch (D) {
2032
+ if ("undefined" == typeof X || "ErrnoError" !== D.name) throw D;
2033
+ return D.Pa;
2034
+ }
2035
+ },
2036
+ k: Jc
2037
+ };
2038
+ function Wc() {
2039
+ function a() {
2040
+ k.calledRun = true;
2041
+ if (!Fa) {
2042
+ if (!k.noFSInit && !Gb) {
2043
+ var b, c;
2044
+ Gb = true;
2045
+ b ?? (b = k.stdin);
2046
+ c ?? (c = k.stdout);
2047
+ d ?? (d = k.stderr);
2048
+ b ? W("stdin", b) : Vb("/dev/tty", "/dev/stdin");
2049
+ c ? W("stdout", null, c) : Vb("/dev/tty", "/dev/stdout");
2050
+ d ? W("stderr", null, d) : Vb("/dev/tty1", "/dev/stderr");
2051
+ ma("/dev/stdin", 0);
2052
+ ma("/dev/stdout", 1);
2053
+ ma("/dev/stderr", 1);
2054
+ }
2055
+ Xc.N();
2056
+ Hb = false;
2057
+ k.onRuntimeInitialized?.();
2058
+ if (k.postRun) for ("function" == typeof k.postRun && (k.postRun = [k.postRun]); k.postRun.length; ) {
2059
+ var d = k.postRun.shift();
2060
+ Ua.push(d);
2061
+ }
2062
+ Ta(Ua);
2063
+ }
2064
+ }
2065
+ if (0 < J) Xa = Wc;
2066
+ else {
2067
+ if (k.preRun) for ("function" == typeof k.preRun && (k.preRun = [k.preRun]); k.preRun.length; ) Wa();
2068
+ Ta(Va);
2069
+ 0 < J ? Xa = Wc : k.setStatus ? (k.setStatus("Running..."), setTimeout(() => {
2070
+ setTimeout(() => k.setStatus(""), 1);
2071
+ a();
2072
+ }, 1)) : a();
2073
+ }
2074
+ }
2075
+ var Xc;
2076
+ (async function() {
2077
+ function a(c) {
2078
+ c = Xc = c.exports;
2079
+ k._sqlite3_free = c.P;
2080
+ k._sqlite3_value_text = c.Q;
2081
+ k._sqlite3_prepare_v2 = c.R;
2082
+ k._sqlite3_step = c.S;
2083
+ k._sqlite3_reset = c.T;
2084
+ k._sqlite3_exec = c.U;
2085
+ k._sqlite3_finalize = c.V;
2086
+ k._sqlite3_column_name = c.W;
2087
+ k._sqlite3_column_text = c.X;
2088
+ k._sqlite3_column_type = c.Y;
2089
+ k._sqlite3_errmsg = c.Z;
2090
+ k._sqlite3_clear_bindings = c._;
2091
+ k._sqlite3_value_blob = c.$;
2092
+ k._sqlite3_value_bytes = c.aa;
2093
+ k._sqlite3_value_double = c.ba;
2094
+ k._sqlite3_value_int = c.ca;
2095
+ k._sqlite3_value_type = c.da;
2096
+ k._sqlite3_result_blob = c.ea;
2097
+ k._sqlite3_result_double = c.fa;
2098
+ k._sqlite3_result_error = c.ga;
2099
+ k._sqlite3_result_int = c.ha;
2100
+ k._sqlite3_result_int64 = c.ia;
2101
+ k._sqlite3_result_null = c.ja;
2102
+ k._sqlite3_result_text = c.ka;
2103
+ k._sqlite3_aggregate_context = c.la;
2104
+ k._sqlite3_column_count = c.ma;
2105
+ k._sqlite3_data_count = c.na;
2106
+ k._sqlite3_column_blob = c.oa;
2107
+ k._sqlite3_column_bytes = c.pa;
2108
+ k._sqlite3_column_double = c.qa;
2109
+ k._sqlite3_bind_blob = c.ra;
2110
+ k._sqlite3_bind_double = c.sa;
2111
+ k._sqlite3_bind_int = c.ta;
2112
+ k._sqlite3_bind_text = c.ua;
2113
+ k._sqlite3_bind_parameter_index = c.va;
2114
+ k._sqlite3_sql = c.wa;
2115
+ k._sqlite3_normalized_sql = c.xa;
2116
+ k._sqlite3_changes = c.ya;
2117
+ k._sqlite3_close_v2 = c.za;
2118
+ k._sqlite3_create_function_v2 = c.Aa;
2119
+ k._sqlite3_update_hook = c.Ba;
2120
+ k._sqlite3_open = c.Ca;
2121
+ da = k._malloc = c.Da;
2122
+ ea = k._free = c.Ea;
2123
+ k._RegisterExtensionFunctions = c.Fa;
2124
+ Bb = c.Ga;
2125
+ Uc = c.Ha;
2126
+ ra = c.Ia;
2127
+ y = c.Ja;
2128
+ pa = c.Ka;
2129
+ La = c.M;
2130
+ Z = c.O;
2131
+ Ka();
2132
+ J--;
2133
+ k.monitorRunDependencies?.(J);
2134
+ 0 == J && Xa && (c = Xa, Xa = null, c());
2135
+ return Xc;
2136
+ }
2137
+ J++;
2138
+ k.monitorRunDependencies?.(J);
2139
+ var b = { a: Vc };
2140
+ if (k.instantiateWasm) return new Promise((c) => {
2141
+ k.instantiateWasm(b, (d, e) => {
2142
+ c(a(d, e));
2143
+ });
2144
+ });
2145
+ Na ?? (Na = k.locateFile ? k.locateFile("sql-wasm.wasm", za) : za + "sql-wasm.wasm");
2146
+ return a((await Ra(b)).instance);
2147
+ })();
2148
+ Wc();
2149
+ return Module;
2150
+ });
2151
+ return initSqlJsPromise;
2152
+ };
2153
+ if (typeof exports === "object" && typeof module === "object") {
2154
+ module.exports = initSqlJs2;
2155
+ module.exports.default = initSqlJs2;
2156
+ } else if (typeof define === "function" && define["amd"]) {
2157
+ define([], function() {
2158
+ return initSqlJs2;
2159
+ });
2160
+ } else if (typeof exports === "object") {
2161
+ exports["Module"] = initSqlJs2;
2162
+ }
2163
+ }
2164
+ });
2165
+
2166
+ // src/connectors/sqlite/index.ts
2167
+ var import_sql = __toESM(require_sql_wasm(), 1);
2168
+ import fs from "fs/promises";
2169
+ var SQLiteDSNParser = class {
2170
+ async parse(dsn, config) {
2171
+ if (!this.isValidDSN(dsn)) {
2172
+ const obfuscatedDSN = obfuscateDSNPassword(dsn);
2173
+ const expectedFormat = this.getSampleDSN();
2174
+ throw new Error(
2175
+ `Invalid SQLite DSN format.
2176
+ Provided: ${obfuscatedDSN}
2177
+ Expected: ${expectedFormat}`
2178
+ );
2179
+ }
2180
+ try {
2181
+ const url = new SafeURL(dsn);
2182
+ let dbPath;
2183
+ if (url.hostname === "" && url.pathname === "/:memory:") {
2184
+ dbPath = ":memory:";
2185
+ } else {
2186
+ if (url.pathname.startsWith("//")) {
2187
+ dbPath = url.pathname.substring(2);
2188
+ } else if (url.pathname.match(/^\/[A-Za-z]:\//)) {
2189
+ dbPath = url.pathname.substring(1);
2190
+ } else {
2191
+ dbPath = url.pathname;
2192
+ }
2193
+ }
2194
+ return { dbPath };
2195
+ } catch (error) {
2196
+ throw new Error(
2197
+ `Failed to parse SQLite DSN: ${error instanceof Error ? error.message : String(error)}`
2198
+ );
2199
+ }
2200
+ }
2201
+ getSampleDSN() {
2202
+ return "sqlite:///path/to/database.db";
2203
+ }
2204
+ isValidDSN(dsn) {
2205
+ try {
2206
+ return dsn.startsWith("sqlite://");
2207
+ } catch (error) {
2208
+ return false;
2209
+ }
2210
+ }
2211
+ };
2212
+ var SQLiteConnector = class _SQLiteConnector {
2213
+ constructor() {
2214
+ this.id = "sqlite";
2215
+ this.name = "SQLite";
2216
+ this.dsnParser = new SQLiteDSNParser();
2217
+ this.db = null;
2218
+ this.dbPath = ":memory:";
2219
+ this.SQL = null;
2220
+ this.sourceId = "default";
2221
+ }
2222
+ getId() {
2223
+ return this.sourceId;
2224
+ }
2225
+ clone() {
2226
+ return new _SQLiteConnector();
2227
+ }
2228
+ // Helper method to save in-memory database to disk
2229
+ async saveToDisk() {
2230
+ if (this.dbPath !== ":memory:" && this.db) {
2231
+ const data = this.db.export();
2232
+ const buffer = Buffer.from(data);
2233
+ await fs.writeFile(this.dbPath, buffer);
2234
+ }
2235
+ }
2236
+ // Wrapper equivalent to sqlite3 db.all()
2237
+ async dbAll(sql, params = []) {
2238
+ if (!this.db) throw new Error("Not connected to SQLite database");
2239
+ const stmt = this.db.prepare(sql);
2240
+ try {
2241
+ if (params && params.length > 0) {
2242
+ stmt.bind(params);
2243
+ }
2244
+ const rows = [];
2245
+ while (stmt.step()) {
2246
+ rows.push(stmt.getAsObject());
2247
+ }
2248
+ return rows;
2249
+ } finally {
2250
+ stmt.free();
2251
+ }
2252
+ }
2253
+ // Wrapper equivalent to sqlite3 db.get()
2254
+ async dbGet(sql, params = []) {
2255
+ const rows = await this.dbAll(sql, params);
2256
+ return rows.length > 0 ? rows[0] : void 0;
2257
+ }
2258
+ // Wrapper equivalent to sqlite3 db.run()
2259
+ async dbRun(sql, params = []) {
2260
+ if (!this.db) throw new Error("Not connected to SQLite database");
2261
+ this.db.run(sql, params);
2262
+ return { changes: this.db.getRowsModified() };
2263
+ }
2264
+ async connect(dsn, initScript, config) {
2265
+ const parsedConfig = await this.dsnParser.parse(dsn, config);
2266
+ this.dbPath = parsedConfig.dbPath;
2267
+ try {
2268
+ if (!this.SQL) {
2269
+ this.SQL = await (0, import_sql.default)();
2270
+ }
2271
+ if (this.dbPath === ":memory:") {
2272
+ this.db = new this.SQL.Database();
2273
+ } else {
2274
+ try {
2275
+ const fileBuffer = await fs.readFile(this.dbPath);
2276
+ this.db = new this.SQL.Database(fileBuffer);
2277
+ } catch (err) {
2278
+ if (err.code === "ENOENT") {
2279
+ if (config?.readonly) {
2280
+ throw new Error(`Database file not found in readonly mode: ${this.dbPath}`);
2281
+ }
2282
+ this.db = new this.SQL.Database();
2283
+ await this.saveToDisk();
2284
+ } else {
2285
+ throw err;
2286
+ }
2287
+ }
2288
+ }
2289
+ if (initScript) {
2290
+ this.db.run(initScript);
2291
+ await this.saveToDisk();
2292
+ }
2293
+ } catch (error) {
2294
+ console.error("Failed to connect to SQLite database (sql.js):", error);
2295
+ throw error;
2296
+ }
2297
+ }
2298
+ async disconnect() {
2299
+ if (this.db) {
2300
+ try {
2301
+ await this.saveToDisk();
2302
+ this.db.close();
2303
+ this.db = null;
2304
+ } catch (error) {
2305
+ console.error("Error during SQLite disconnect:", error);
2306
+ this.db = null;
2307
+ }
2308
+ }
2309
+ return Promise.resolve();
2310
+ }
2311
+ async getSchemas() {
2312
+ if (!this.db) throw new Error("Not connected to SQLite database");
2313
+ return ["main"];
2314
+ }
2315
+ async getTables(schema) {
2316
+ try {
2317
+ const rows = await this.dbAll(`
2318
+ SELECT name FROM sqlite_master
2319
+ WHERE type='table' AND name NOT LIKE 'sqlite_%'
2320
+ ORDER BY name
2321
+ `);
2322
+ return rows.map((row) => row.name);
2323
+ } catch (error) {
2324
+ throw error;
2325
+ }
2326
+ }
2327
+ async tableExists(tableName, schema) {
2328
+ try {
2329
+ const row = await this.dbGet(`
2330
+ SELECT name FROM sqlite_master
2331
+ WHERE type='table' AND name = ?
2332
+ `, [tableName]);
2333
+ return !!row;
2334
+ } catch (error) {
2335
+ throw error;
2336
+ }
2337
+ }
2338
+ async getTableIndexes(tableName, schema) {
2339
+ try {
2340
+ const indexInfoRows = await this.dbAll(`
2341
+ SELECT name as index_name, 0 as is_unique
2342
+ FROM sqlite_master
2343
+ WHERE type = 'index' AND tbl_name = ?
2344
+ `, [tableName]);
2345
+ const quotedTableName = quoteIdentifier(tableName, "sqlite");
2346
+ const indexListRows = await this.dbAll(
2347
+ `PRAGMA index_list(${quotedTableName})`
2348
+ );
2349
+ const indexUniqueMap = /* @__PURE__ */ new Map();
2350
+ for (const indexListRow of indexListRows) {
2351
+ indexUniqueMap.set(indexListRow.name, indexListRow.unique === 1);
2352
+ }
2353
+ const tableInfo = await this.dbAll(
2354
+ `PRAGMA table_info(${quotedTableName})`
2355
+ );
2356
+ const pkColumns = tableInfo.filter((col) => col.pk > 0).map((col) => col.name);
2357
+ const results = [];
2358
+ for (const indexInfo of indexInfoRows) {
2359
+ const quotedIndexName = quoteIdentifier(indexInfo.index_name, "sqlite");
2360
+ const indexDetailRows = await this.dbAll(
2361
+ `PRAGMA index_info(${quotedIndexName})`
2362
+ );
2363
+ const columnNames = indexDetailRows.map((row) => row.name);
2364
+ results.push({
2365
+ index_name: indexInfo.index_name,
2366
+ column_names: columnNames,
2367
+ is_unique: indexUniqueMap.get(indexInfo.index_name) || false,
2368
+ is_primary: false
2369
+ });
2370
+ }
2371
+ if (pkColumns.length > 0) {
2372
+ results.push({
2373
+ index_name: "PRIMARY",
2374
+ column_names: pkColumns,
2375
+ is_unique: true,
2376
+ is_primary: true
2377
+ });
2378
+ }
2379
+ return results;
2380
+ } catch (error) {
2381
+ throw error;
2382
+ }
2383
+ }
2384
+ async getTableSchema(tableName, schema) {
2385
+ try {
2386
+ const quotedTableName = quoteIdentifier(tableName, "sqlite");
2387
+ const rows = await this.dbAll(`PRAGMA table_info(${quotedTableName})`);
2388
+ return rows.map((row) => ({
2389
+ column_name: row.name,
2390
+ data_type: row.type,
2391
+ is_nullable: row.notnull === 1 || row.pk > 0 ? "NO" : "YES",
2392
+ column_default: row.dflt_value,
2393
+ description: null
2394
+ }));
2395
+ } catch (error) {
2396
+ throw error;
2397
+ }
2398
+ }
2399
+ async getStoredProcedures(schema, routineType) {
2400
+ if (!this.db) throw new Error("Not connected to SQLite database");
2401
+ return [];
2402
+ }
2403
+ async getStoredProcedureDetail(procedureName, schema) {
2404
+ throw new Error(
2405
+ "SQLite does not support stored procedures. Functions are defined programmatically through the SQLite API, not stored in the database."
2406
+ );
2407
+ }
2408
+ async executeSQL(sql, options, parameters) {
2409
+ if (!this.db) throw new Error("Not connected to SQLite database");
2410
+ try {
2411
+ const statements = splitSQLStatements(sql, "sqlite");
2412
+ let dataModified = false;
2413
+ if (statements.length === 1) {
2414
+ let processedStatement = statements[0];
2415
+ const trimmedStatement = statements[0].toLowerCase().trim();
2416
+ const isReadStatement = trimmedStatement.startsWith("select") || trimmedStatement.startsWith("with") || trimmedStatement.startsWith("explain") || trimmedStatement.startsWith("analyze") || trimmedStatement.startsWith("pragma") && (trimmedStatement.includes("table_info") || trimmedStatement.includes("index_info") || trimmedStatement.includes("index_list") || trimmedStatement.includes("foreign_key_list"));
2417
+ if (options.maxRows) {
2418
+ processedStatement = SQLRowLimiter.applyMaxRows(processedStatement, options.maxRows);
2419
+ }
2420
+ if (isReadStatement) {
2421
+ try {
2422
+ const params = parameters || [];
2423
+ const rows = await this.dbAll(processedStatement, params);
2424
+ return { rows, rowCount: rows.length };
2425
+ } catch (error) {
2426
+ console.error(`[SQLite executeSQL] ERROR: ${error.message}`);
2427
+ throw error;
2428
+ }
2429
+ } else {
2430
+ try {
2431
+ const params = parameters || [];
2432
+ const result = await this.dbRun(processedStatement, params);
2433
+ await this.saveToDisk();
2434
+ return { rows: [], rowCount: result.changes ?? 0 };
2435
+ } catch (error) {
2436
+ console.error(`[SQLite executeSQL] ERROR: ${error.message}`);
2437
+ throw error;
2438
+ }
2439
+ }
2440
+ } else {
2441
+ if (parameters && parameters.length > 0) {
2442
+ throw new Error("Parameters are not supported for multi-statement queries in SQLite");
2443
+ }
2444
+ let totalChanges = 0;
2445
+ let allRows = [];
2446
+ for (let statement of statements) {
2447
+ const trimmedStatement = statement.toLowerCase().trim();
2448
+ const isReadStatement = trimmedStatement.startsWith("select") || trimmedStatement.startsWith("with") || trimmedStatement.startsWith("explain") || trimmedStatement.startsWith("analyze") || trimmedStatement.startsWith("pragma") && (trimmedStatement.includes("table_info") || trimmedStatement.includes("index_info") || trimmedStatement.includes("index_list") || trimmedStatement.includes("foreign_key_list"));
2449
+ if (isReadStatement) {
2450
+ statement = SQLRowLimiter.applyMaxRows(statement, options.maxRows);
2451
+ const rows = await this.dbAll(statement);
2452
+ allRows.push(...rows);
2453
+ } else {
2454
+ const result = await this.dbRun(statement);
2455
+ totalChanges += result.changes ?? 0;
2456
+ dataModified = true;
2457
+ }
2458
+ }
2459
+ if (dataModified) {
2460
+ await this.saveToDisk();
2461
+ }
2462
+ return { rows: allRows, rowCount: totalChanges + allRows.length };
2463
+ }
2464
+ } catch (error) {
2465
+ throw error;
2466
+ }
2467
+ }
2468
+ };
2469
+ var sqliteConnector = new SQLiteConnector();
2470
+ ConnectorRegistry.register(sqliteConnector);
2471
+ export {
2472
+ SQLiteConnector
2473
+ };