@rljson/io-sqlite 0.0.12 → 0.0.17

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.
@@ -0,0 +1,3128 @@
1
+ import { hsh, hip } from "@rljson/hash";
2
+ import { IoDbNameMapping, IoTools } from "@rljson/io";
3
+ import { IsReady } from "@rljson/is-ready";
4
+ import { iterateTables } from "@rljson/rljson";
5
+ function getDefaultExportFromCjs(x) {
6
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
7
+ }
8
+ function getAugmentedNamespace(n) {
9
+ if (Object.prototype.hasOwnProperty.call(n, "__esModule")) return n;
10
+ var f = n.default;
11
+ if (typeof f == "function") {
12
+ var a = function a2() {
13
+ var isInstance = false;
14
+ try {
15
+ isInstance = this instanceof a2;
16
+ } catch {
17
+ }
18
+ if (isInstance) {
19
+ return Reflect.construct(f, arguments, this.constructor);
20
+ }
21
+ return f.apply(this, arguments);
22
+ };
23
+ a.prototype = f.prototype;
24
+ } else a = {};
25
+ Object.defineProperty(a, "__esModule", { value: true });
26
+ Object.keys(n).forEach(function(k) {
27
+ var d = Object.getOwnPropertyDescriptor(n, k);
28
+ Object.defineProperty(a, k, d.get ? d : {
29
+ enumerable: true,
30
+ get: function() {
31
+ return n[k];
32
+ }
33
+ });
34
+ });
35
+ return a;
36
+ }
37
+ var sqlWasm = { exports: {} };
38
+ const __viteBrowserExternal = {};
39
+ const __viteBrowserExternal$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
40
+ __proto__: null,
41
+ default: __viteBrowserExternal
42
+ }, Symbol.toStringTag, { value: "Module" }));
43
+ const require$$2 = /* @__PURE__ */ getAugmentedNamespace(__viteBrowserExternal$1);
44
+ var pathBrowserify;
45
+ var hasRequiredPathBrowserify;
46
+ function requirePathBrowserify() {
47
+ if (hasRequiredPathBrowserify) return pathBrowserify;
48
+ hasRequiredPathBrowserify = 1;
49
+ function assertPath(path) {
50
+ if (typeof path !== "string") {
51
+ throw new TypeError("Path must be a string. Received " + JSON.stringify(path));
52
+ }
53
+ }
54
+ function normalizeStringPosix(path, allowAboveRoot) {
55
+ var res = "";
56
+ var lastSegmentLength = 0;
57
+ var lastSlash = -1;
58
+ var dots = 0;
59
+ var code;
60
+ for (var i = 0; i <= path.length; ++i) {
61
+ if (i < path.length)
62
+ code = path.charCodeAt(i);
63
+ else if (code === 47)
64
+ break;
65
+ else
66
+ code = 47;
67
+ if (code === 47) {
68
+ if (lastSlash === i - 1 || dots === 1) ;
69
+ else if (lastSlash !== i - 1 && dots === 2) {
70
+ if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 || res.charCodeAt(res.length - 2) !== 46) {
71
+ if (res.length > 2) {
72
+ var lastSlashIndex = res.lastIndexOf("/");
73
+ if (lastSlashIndex !== res.length - 1) {
74
+ if (lastSlashIndex === -1) {
75
+ res = "";
76
+ lastSegmentLength = 0;
77
+ } else {
78
+ res = res.slice(0, lastSlashIndex);
79
+ lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
80
+ }
81
+ lastSlash = i;
82
+ dots = 0;
83
+ continue;
84
+ }
85
+ } else if (res.length === 2 || res.length === 1) {
86
+ res = "";
87
+ lastSegmentLength = 0;
88
+ lastSlash = i;
89
+ dots = 0;
90
+ continue;
91
+ }
92
+ }
93
+ if (allowAboveRoot) {
94
+ if (res.length > 0)
95
+ res += "/..";
96
+ else
97
+ res = "..";
98
+ lastSegmentLength = 2;
99
+ }
100
+ } else {
101
+ if (res.length > 0)
102
+ res += "/" + path.slice(lastSlash + 1, i);
103
+ else
104
+ res = path.slice(lastSlash + 1, i);
105
+ lastSegmentLength = i - lastSlash - 1;
106
+ }
107
+ lastSlash = i;
108
+ dots = 0;
109
+ } else if (code === 46 && dots !== -1) {
110
+ ++dots;
111
+ } else {
112
+ dots = -1;
113
+ }
114
+ }
115
+ return res;
116
+ }
117
+ function _format(sep, pathObject) {
118
+ var dir = pathObject.dir || pathObject.root;
119
+ var base = pathObject.base || (pathObject.name || "") + (pathObject.ext || "");
120
+ if (!dir) {
121
+ return base;
122
+ }
123
+ if (dir === pathObject.root) {
124
+ return dir + base;
125
+ }
126
+ return dir + sep + base;
127
+ }
128
+ var posix = {
129
+ // path.resolve([from ...], to)
130
+ resolve: function resolve() {
131
+ var resolvedPath = "";
132
+ var resolvedAbsolute = false;
133
+ var cwd;
134
+ for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
135
+ var path;
136
+ if (i >= 0)
137
+ path = arguments[i];
138
+ else {
139
+ if (cwd === void 0)
140
+ cwd = process.cwd();
141
+ path = cwd;
142
+ }
143
+ assertPath(path);
144
+ if (path.length === 0) {
145
+ continue;
146
+ }
147
+ resolvedPath = path + "/" + resolvedPath;
148
+ resolvedAbsolute = path.charCodeAt(0) === 47;
149
+ }
150
+ resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute);
151
+ if (resolvedAbsolute) {
152
+ if (resolvedPath.length > 0)
153
+ return "/" + resolvedPath;
154
+ else
155
+ return "/";
156
+ } else if (resolvedPath.length > 0) {
157
+ return resolvedPath;
158
+ } else {
159
+ return ".";
160
+ }
161
+ },
162
+ normalize: function normalize(path) {
163
+ assertPath(path);
164
+ if (path.length === 0) return ".";
165
+ var isAbsolute = path.charCodeAt(0) === 47;
166
+ var trailingSeparator = path.charCodeAt(path.length - 1) === 47;
167
+ path = normalizeStringPosix(path, !isAbsolute);
168
+ if (path.length === 0 && !isAbsolute) path = ".";
169
+ if (path.length > 0 && trailingSeparator) path += "/";
170
+ if (isAbsolute) return "/" + path;
171
+ return path;
172
+ },
173
+ isAbsolute: function isAbsolute(path) {
174
+ assertPath(path);
175
+ return path.length > 0 && path.charCodeAt(0) === 47;
176
+ },
177
+ join: function join() {
178
+ if (arguments.length === 0)
179
+ return ".";
180
+ var joined;
181
+ for (var i = 0; i < arguments.length; ++i) {
182
+ var arg = arguments[i];
183
+ assertPath(arg);
184
+ if (arg.length > 0) {
185
+ if (joined === void 0)
186
+ joined = arg;
187
+ else
188
+ joined += "/" + arg;
189
+ }
190
+ }
191
+ if (joined === void 0)
192
+ return ".";
193
+ return posix.normalize(joined);
194
+ },
195
+ relative: function relative(from, to) {
196
+ assertPath(from);
197
+ assertPath(to);
198
+ if (from === to) return "";
199
+ from = posix.resolve(from);
200
+ to = posix.resolve(to);
201
+ if (from === to) return "";
202
+ var fromStart = 1;
203
+ for (; fromStart < from.length; ++fromStart) {
204
+ if (from.charCodeAt(fromStart) !== 47)
205
+ break;
206
+ }
207
+ var fromEnd = from.length;
208
+ var fromLen = fromEnd - fromStart;
209
+ var toStart = 1;
210
+ for (; toStart < to.length; ++toStart) {
211
+ if (to.charCodeAt(toStart) !== 47)
212
+ break;
213
+ }
214
+ var toEnd = to.length;
215
+ var toLen = toEnd - toStart;
216
+ var length = fromLen < toLen ? fromLen : toLen;
217
+ var lastCommonSep = -1;
218
+ var i = 0;
219
+ for (; i <= length; ++i) {
220
+ if (i === length) {
221
+ if (toLen > length) {
222
+ if (to.charCodeAt(toStart + i) === 47) {
223
+ return to.slice(toStart + i + 1);
224
+ } else if (i === 0) {
225
+ return to.slice(toStart + i);
226
+ }
227
+ } else if (fromLen > length) {
228
+ if (from.charCodeAt(fromStart + i) === 47) {
229
+ lastCommonSep = i;
230
+ } else if (i === 0) {
231
+ lastCommonSep = 0;
232
+ }
233
+ }
234
+ break;
235
+ }
236
+ var fromCode = from.charCodeAt(fromStart + i);
237
+ var toCode = to.charCodeAt(toStart + i);
238
+ if (fromCode !== toCode)
239
+ break;
240
+ else if (fromCode === 47)
241
+ lastCommonSep = i;
242
+ }
243
+ var out = "";
244
+ for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
245
+ if (i === fromEnd || from.charCodeAt(i) === 47) {
246
+ if (out.length === 0)
247
+ out += "..";
248
+ else
249
+ out += "/..";
250
+ }
251
+ }
252
+ if (out.length > 0)
253
+ return out + to.slice(toStart + lastCommonSep);
254
+ else {
255
+ toStart += lastCommonSep;
256
+ if (to.charCodeAt(toStart) === 47)
257
+ ++toStart;
258
+ return to.slice(toStart);
259
+ }
260
+ },
261
+ _makeLong: function _makeLong(path) {
262
+ return path;
263
+ },
264
+ dirname: function dirname(path) {
265
+ assertPath(path);
266
+ if (path.length === 0) return ".";
267
+ var code = path.charCodeAt(0);
268
+ var hasRoot = code === 47;
269
+ var end = -1;
270
+ var matchedSlash = true;
271
+ for (var i = path.length - 1; i >= 1; --i) {
272
+ code = path.charCodeAt(i);
273
+ if (code === 47) {
274
+ if (!matchedSlash) {
275
+ end = i;
276
+ break;
277
+ }
278
+ } else {
279
+ matchedSlash = false;
280
+ }
281
+ }
282
+ if (end === -1) return hasRoot ? "/" : ".";
283
+ if (hasRoot && end === 1) return "//";
284
+ return path.slice(0, end);
285
+ },
286
+ basename: function basename(path, ext) {
287
+ if (ext !== void 0 && typeof ext !== "string") throw new TypeError('"ext" argument must be a string');
288
+ assertPath(path);
289
+ var start = 0;
290
+ var end = -1;
291
+ var matchedSlash = true;
292
+ var i;
293
+ if (ext !== void 0 && ext.length > 0 && ext.length <= path.length) {
294
+ if (ext.length === path.length && ext === path) return "";
295
+ var extIdx = ext.length - 1;
296
+ var firstNonSlashEnd = -1;
297
+ for (i = path.length - 1; i >= 0; --i) {
298
+ var code = path.charCodeAt(i);
299
+ if (code === 47) {
300
+ if (!matchedSlash) {
301
+ start = i + 1;
302
+ break;
303
+ }
304
+ } else {
305
+ if (firstNonSlashEnd === -1) {
306
+ matchedSlash = false;
307
+ firstNonSlashEnd = i + 1;
308
+ }
309
+ if (extIdx >= 0) {
310
+ if (code === ext.charCodeAt(extIdx)) {
311
+ if (--extIdx === -1) {
312
+ end = i;
313
+ }
314
+ } else {
315
+ extIdx = -1;
316
+ end = firstNonSlashEnd;
317
+ }
318
+ }
319
+ }
320
+ }
321
+ if (start === end) end = firstNonSlashEnd;
322
+ else if (end === -1) end = path.length;
323
+ return path.slice(start, end);
324
+ } else {
325
+ for (i = path.length - 1; i >= 0; --i) {
326
+ if (path.charCodeAt(i) === 47) {
327
+ if (!matchedSlash) {
328
+ start = i + 1;
329
+ break;
330
+ }
331
+ } else if (end === -1) {
332
+ matchedSlash = false;
333
+ end = i + 1;
334
+ }
335
+ }
336
+ if (end === -1) return "";
337
+ return path.slice(start, end);
338
+ }
339
+ },
340
+ extname: function extname(path) {
341
+ assertPath(path);
342
+ var startDot = -1;
343
+ var startPart = 0;
344
+ var end = -1;
345
+ var matchedSlash = true;
346
+ var preDotState = 0;
347
+ for (var i = path.length - 1; i >= 0; --i) {
348
+ var code = path.charCodeAt(i);
349
+ if (code === 47) {
350
+ if (!matchedSlash) {
351
+ startPart = i + 1;
352
+ break;
353
+ }
354
+ continue;
355
+ }
356
+ if (end === -1) {
357
+ matchedSlash = false;
358
+ end = i + 1;
359
+ }
360
+ if (code === 46) {
361
+ if (startDot === -1)
362
+ startDot = i;
363
+ else if (preDotState !== 1)
364
+ preDotState = 1;
365
+ } else if (startDot !== -1) {
366
+ preDotState = -1;
367
+ }
368
+ }
369
+ if (startDot === -1 || end === -1 || // We saw a non-dot character immediately before the dot
370
+ preDotState === 0 || // The (right-most) trimmed path component is exactly '..'
371
+ preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
372
+ return "";
373
+ }
374
+ return path.slice(startDot, end);
375
+ },
376
+ format: function format(pathObject) {
377
+ if (pathObject === null || typeof pathObject !== "object") {
378
+ throw new TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof pathObject);
379
+ }
380
+ return _format("/", pathObject);
381
+ },
382
+ parse: function parse(path) {
383
+ assertPath(path);
384
+ var ret = { root: "", dir: "", base: "", ext: "", name: "" };
385
+ if (path.length === 0) return ret;
386
+ var code = path.charCodeAt(0);
387
+ var isAbsolute = code === 47;
388
+ var start;
389
+ if (isAbsolute) {
390
+ ret.root = "/";
391
+ start = 1;
392
+ } else {
393
+ start = 0;
394
+ }
395
+ var startDot = -1;
396
+ var startPart = 0;
397
+ var end = -1;
398
+ var matchedSlash = true;
399
+ var i = path.length - 1;
400
+ var preDotState = 0;
401
+ for (; i >= start; --i) {
402
+ code = path.charCodeAt(i);
403
+ if (code === 47) {
404
+ if (!matchedSlash) {
405
+ startPart = i + 1;
406
+ break;
407
+ }
408
+ continue;
409
+ }
410
+ if (end === -1) {
411
+ matchedSlash = false;
412
+ end = i + 1;
413
+ }
414
+ if (code === 46) {
415
+ if (startDot === -1) startDot = i;
416
+ else if (preDotState !== 1) preDotState = 1;
417
+ } else if (startDot !== -1) {
418
+ preDotState = -1;
419
+ }
420
+ }
421
+ if (startDot === -1 || end === -1 || // We saw a non-dot character immediately before the dot
422
+ preDotState === 0 || // The (right-most) trimmed path component is exactly '..'
423
+ preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
424
+ if (end !== -1) {
425
+ if (startPart === 0 && isAbsolute) ret.base = ret.name = path.slice(1, end);
426
+ else ret.base = ret.name = path.slice(startPart, end);
427
+ }
428
+ } else {
429
+ if (startPart === 0 && isAbsolute) {
430
+ ret.name = path.slice(1, startDot);
431
+ ret.base = path.slice(1, end);
432
+ } else {
433
+ ret.name = path.slice(startPart, startDot);
434
+ ret.base = path.slice(startPart, end);
435
+ }
436
+ ret.ext = path.slice(startDot, end);
437
+ }
438
+ if (startPart > 0) ret.dir = path.slice(0, startPart - 1);
439
+ else if (isAbsolute) ret.dir = "/";
440
+ return ret;
441
+ },
442
+ sep: "/",
443
+ delimiter: ":",
444
+ win32: null,
445
+ posix: null
446
+ };
447
+ posix.posix = posix;
448
+ pathBrowserify = posix;
449
+ return pathBrowserify;
450
+ }
451
+ var hasRequiredSqlWasm;
452
+ function requireSqlWasm() {
453
+ if (hasRequiredSqlWasm) return sqlWasm.exports;
454
+ hasRequiredSqlWasm = 1;
455
+ (function(module, exports$1) {
456
+ var initSqlJsPromise = void 0;
457
+ var initSqlJs2 = function(moduleConfig) {
458
+ if (initSqlJsPromise) {
459
+ return initSqlJsPromise;
460
+ }
461
+ initSqlJsPromise = new Promise(function(resolveModule, reject) {
462
+ var Module = typeof moduleConfig !== "undefined" ? moduleConfig : {};
463
+ var originalOnAbortFunction = Module["onAbort"];
464
+ Module["onAbort"] = function(errorThatCausedAbort) {
465
+ reject(new Error(errorThatCausedAbort));
466
+ if (originalOnAbortFunction) {
467
+ originalOnAbortFunction(errorThatCausedAbort);
468
+ }
469
+ };
470
+ Module["postRun"] = Module["postRun"] || [];
471
+ Module["postRun"].push(function() {
472
+ resolveModule(Module);
473
+ });
474
+ module = void 0;
475
+ var f;
476
+ f ||= typeof Module != "undefined" ? Module : {};
477
+ var aa = "object" == typeof window, ba = "undefined" != typeof WorkerGlobalScope, ca = "object" == typeof process && "object" == typeof process.versions && "string" == typeof process.versions.node && "renderer" != process.type;
478
+ f.onRuntimeInitialized = function() {
479
+ function a(g, l) {
480
+ switch (typeof l) {
481
+ case "boolean":
482
+ dc(g, l ? 1 : 0);
483
+ break;
484
+ case "number":
485
+ ec(g, l);
486
+ break;
487
+ case "string":
488
+ fc(g, l, -1, -1);
489
+ break;
490
+ case "object":
491
+ if (null === l) lb(g);
492
+ else if (null != l.length) {
493
+ var n = da(l, ea);
494
+ gc(g, n, l.length, -1);
495
+ fa(n);
496
+ } else va(g, "Wrong API use : tried to return a value of an unknown type (" + l + ").", -1);
497
+ break;
498
+ default:
499
+ lb(g);
500
+ }
501
+ }
502
+ function b(g, l) {
503
+ for (var n = [], r = 0; r < g; r += 1) {
504
+ var t = m(l + 4 * r, "i32"), y = hc(t);
505
+ if (1 === y || 2 === y) t = ic(t);
506
+ else if (3 === y) t = jc(t);
507
+ else if (4 === y) {
508
+ y = t;
509
+ t = kc(y);
510
+ y = lc(y);
511
+ for (var L = new Uint8Array(t), J = 0; J < t; J += 1) L[J] = p[y + J];
512
+ t = L;
513
+ } else t = null;
514
+ n.push(t);
515
+ }
516
+ return n;
517
+ }
518
+ function c(g, l) {
519
+ this.Qa = g;
520
+ this.db = l;
521
+ this.Oa = 1;
522
+ this.lb = [];
523
+ }
524
+ function d(g, l) {
525
+ this.db = l;
526
+ l = ha(g) + 1;
527
+ this.eb = ia(l);
528
+ if (null === this.eb) throw Error("Unable to allocate memory for the SQL string");
529
+ u(g, x, this.eb, l);
530
+ this.kb = this.eb;
531
+ this.Za = this.pb = null;
532
+ }
533
+ function e(g) {
534
+ this.filename = "dbfile_" + (4294967295 * Math.random() >>> 0);
535
+ if (null != g) {
536
+ var l = this.filename, n = "/", r = l;
537
+ n && (n = "string" == typeof n ? n : ja(n), r = l ? ka(n + "/" + l) : n);
538
+ l = la(true, true);
539
+ r = ma(r, l);
540
+ if (g) {
541
+ if ("string" == typeof g) {
542
+ n = Array(g.length);
543
+ for (var t = 0, y = g.length; t < y; ++t) n[t] = g.charCodeAt(t);
544
+ g = n;
545
+ }
546
+ na(r, l | 146);
547
+ n = oa(r, 577);
548
+ pa(n, g, 0, g.length, 0);
549
+ qa(n);
550
+ na(r, l);
551
+ }
552
+ }
553
+ this.handleError(q(this.filename, h));
554
+ this.db = m(h, "i32");
555
+ ob(this.db);
556
+ this.fb = {};
557
+ this.Sa = {};
558
+ }
559
+ var h = z(4), k = f.cwrap, q = k("sqlite3_open", "number", ["string", "number"]), w = k("sqlite3_close_v2", "number", ["number"]), v = k("sqlite3_exec", "number", ["number", "string", "number", "number", "number"]), C = k("sqlite3_changes", "number", ["number"]), G = k("sqlite3_prepare_v2", "number", ["number", "string", "number", "number", "number"]), pb = k("sqlite3_sql", "string", ["number"]), nc = k("sqlite3_normalized_sql", "string", ["number"]), qb = k("sqlite3_prepare_v2", "number", ["number", "number", "number", "number", "number"]), oc = k("sqlite3_bind_text", "number", ["number", "number", "number", "number", "number"]), rb = k("sqlite3_bind_blob", "number", ["number", "number", "number", "number", "number"]), pc = k("sqlite3_bind_double", "number", ["number", "number", "number"]), qc = k(
560
+ "sqlite3_bind_int",
561
+ "number",
562
+ ["number", "number", "number"]
563
+ ), rc = k("sqlite3_bind_parameter_index", "number", ["number", "string"]), sc = k("sqlite3_step", "number", ["number"]), tc = k("sqlite3_errmsg", "string", ["number"]), uc = k("sqlite3_column_count", "number", ["number"]), vc = k("sqlite3_data_count", "number", ["number"]), wc = k("sqlite3_column_double", "number", ["number", "number"]), sb = k("sqlite3_column_text", "string", ["number", "number"]), xc = k("sqlite3_column_blob", "number", ["number", "number"]), yc = k("sqlite3_column_bytes", "number", [
564
+ "number",
565
+ "number"
566
+ ]), zc = k("sqlite3_column_type", "number", ["number", "number"]), Ac = k("sqlite3_column_name", "string", ["number", "number"]), Bc = k("sqlite3_reset", "number", ["number"]), Cc = k("sqlite3_clear_bindings", "number", ["number"]), Dc = k("sqlite3_finalize", "number", ["number"]), tb = k("sqlite3_create_function_v2", "number", "number string number number number number number number number".split(" ")), hc = k("sqlite3_value_type", "number", ["number"]), kc = k("sqlite3_value_bytes", "number", ["number"]), jc = k(
567
+ "sqlite3_value_text",
568
+ "string",
569
+ ["number"]
570
+ ), lc = k("sqlite3_value_blob", "number", ["number"]), ic = k("sqlite3_value_double", "number", ["number"]), ec = k("sqlite3_result_double", "", ["number", "number"]), lb = k("sqlite3_result_null", "", ["number"]), fc = k("sqlite3_result_text", "", ["number", "string", "number", "number"]), gc = k("sqlite3_result_blob", "", ["number", "number", "number", "number"]), dc = k("sqlite3_result_int", "", ["number", "number"]), va = k("sqlite3_result_error", "", ["number", "string", "number"]), ub = k(
571
+ "sqlite3_aggregate_context",
572
+ "number",
573
+ ["number", "number"]
574
+ ), ob = k("RegisterExtensionFunctions", "number", ["number"]), vb = k("sqlite3_update_hook", "number", ["number", "number", "number"]);
575
+ c.prototype.bind = function(g) {
576
+ if (!this.Qa) throw "Statement closed";
577
+ this.reset();
578
+ return Array.isArray(g) ? this.Cb(g) : null != g && "object" === typeof g ? this.Db(g) : true;
579
+ };
580
+ c.prototype.step = function() {
581
+ if (!this.Qa) throw "Statement closed";
582
+ this.Oa = 1;
583
+ var g = sc(this.Qa);
584
+ switch (g) {
585
+ case 100:
586
+ return true;
587
+ case 101:
588
+ return false;
589
+ default:
590
+ throw this.db.handleError(g);
591
+ }
592
+ };
593
+ c.prototype.wb = function(g) {
594
+ null == g && (g = this.Oa, this.Oa += 1);
595
+ return wc(this.Qa, g);
596
+ };
597
+ c.prototype.Gb = function(g) {
598
+ null == g && (g = this.Oa, this.Oa += 1);
599
+ g = sb(this.Qa, g);
600
+ if ("function" !== typeof BigInt) throw Error("BigInt is not supported");
601
+ return BigInt(g);
602
+ };
603
+ c.prototype.Hb = function(g) {
604
+ null == g && (g = this.Oa, this.Oa += 1);
605
+ return sb(this.Qa, g);
606
+ };
607
+ c.prototype.getBlob = function(g) {
608
+ null == g && (g = this.Oa, this.Oa += 1);
609
+ var l = yc(this.Qa, g);
610
+ g = xc(this.Qa, g);
611
+ for (var n = new Uint8Array(l), r = 0; r < l; r += 1) n[r] = p[g + r];
612
+ return n;
613
+ };
614
+ c.prototype.get = function(g, l) {
615
+ l = l || {};
616
+ null != g && this.bind(g) && this.step();
617
+ g = [];
618
+ for (var n = vc(this.Qa), r = 0; r < n; r += 1) switch (zc(this.Qa, r)) {
619
+ case 1:
620
+ var t = l.useBigInt ? this.Gb(r) : this.wb(r);
621
+ g.push(t);
622
+ break;
623
+ case 2:
624
+ g.push(this.wb(r));
625
+ break;
626
+ case 3:
627
+ g.push(this.Hb(r));
628
+ break;
629
+ case 4:
630
+ g.push(this.getBlob(r));
631
+ break;
632
+ default:
633
+ g.push(null);
634
+ }
635
+ return g;
636
+ };
637
+ c.prototype.getColumnNames = function() {
638
+ for (var g = [], l = uc(this.Qa), n = 0; n < l; n += 1) g.push(Ac(this.Qa, n));
639
+ return g;
640
+ };
641
+ c.prototype.getAsObject = function(g, l) {
642
+ g = this.get(g, l);
643
+ l = this.getColumnNames();
644
+ for (var n = {}, r = 0; r < l.length; r += 1) n[l[r]] = g[r];
645
+ return n;
646
+ };
647
+ c.prototype.getSQL = function() {
648
+ return pb(this.Qa);
649
+ };
650
+ c.prototype.getNormalizedSQL = function() {
651
+ return nc(this.Qa);
652
+ };
653
+ c.prototype.run = function(g) {
654
+ null != g && this.bind(g);
655
+ this.step();
656
+ return this.reset();
657
+ };
658
+ c.prototype.sb = function(g, l) {
659
+ null == l && (l = this.Oa, this.Oa += 1);
660
+ g = ra(g);
661
+ var n = da(g, ea);
662
+ this.lb.push(n);
663
+ this.db.handleError(oc(this.Qa, l, n, g.length - 1, 0));
664
+ };
665
+ c.prototype.Bb = function(g, l) {
666
+ null == l && (l = this.Oa, this.Oa += 1);
667
+ var n = da(g, ea);
668
+ this.lb.push(n);
669
+ this.db.handleError(rb(
670
+ this.Qa,
671
+ l,
672
+ n,
673
+ g.length,
674
+ 0
675
+ ));
676
+ };
677
+ c.prototype.rb = function(g, l) {
678
+ null == l && (l = this.Oa, this.Oa += 1);
679
+ this.db.handleError((g === (g | 0) ? qc : pc)(this.Qa, l, g));
680
+ };
681
+ c.prototype.Eb = function(g) {
682
+ null == g && (g = this.Oa, this.Oa += 1);
683
+ rb(this.Qa, g, 0, 0, 0);
684
+ };
685
+ c.prototype.tb = function(g, l) {
686
+ null == l && (l = this.Oa, this.Oa += 1);
687
+ switch (typeof g) {
688
+ case "string":
689
+ this.sb(g, l);
690
+ return;
691
+ case "number":
692
+ this.rb(g, l);
693
+ return;
694
+ case "bigint":
695
+ this.sb(g.toString(), l);
696
+ return;
697
+ case "boolean":
698
+ this.rb(g + 0, l);
699
+ return;
700
+ case "object":
701
+ if (null === g) {
702
+ this.Eb(l);
703
+ return;
704
+ }
705
+ if (null != g.length) {
706
+ this.Bb(
707
+ g,
708
+ l
709
+ );
710
+ return;
711
+ }
712
+ }
713
+ throw "Wrong API use : tried to bind a value of an unknown type (" + g + ").";
714
+ };
715
+ c.prototype.Db = function(g) {
716
+ var l = this;
717
+ Object.keys(g).forEach(function(n) {
718
+ var r = rc(l.Qa, n);
719
+ 0 !== r && l.tb(g[n], r);
720
+ });
721
+ return true;
722
+ };
723
+ c.prototype.Cb = function(g) {
724
+ for (var l = 0; l < g.length; l += 1) this.tb(g[l], l + 1);
725
+ return true;
726
+ };
727
+ c.prototype.reset = function() {
728
+ this.freemem();
729
+ return 0 === Cc(this.Qa) && 0 === Bc(this.Qa);
730
+ };
731
+ c.prototype.freemem = function() {
732
+ for (var g; void 0 !== (g = this.lb.pop()); ) fa(g);
733
+ };
734
+ c.prototype.free = function() {
735
+ this.freemem();
736
+ var g = 0 === Dc(this.Qa);
737
+ delete this.db.fb[this.Qa];
738
+ this.Qa = 0;
739
+ return g;
740
+ };
741
+ d.prototype.next = function() {
742
+ if (null === this.eb) return { done: true };
743
+ null !== this.Za && (this.Za.free(), this.Za = null);
744
+ if (!this.db.db) throw this.mb(), Error("Database closed");
745
+ var g = sa(), l = z(4);
746
+ ta(h);
747
+ ta(l);
748
+ try {
749
+ this.db.handleError(qb(this.db.db, this.kb, -1, h, l));
750
+ this.kb = m(l, "i32");
751
+ var n = m(h, "i32");
752
+ if (0 === n) return this.mb(), { done: true };
753
+ this.Za = new c(n, this.db);
754
+ this.db.fb[n] = this.Za;
755
+ return { value: this.Za, done: false };
756
+ } catch (r) {
757
+ throw this.pb = ua(this.kb), this.mb(), r;
758
+ } finally {
759
+ wa(g);
760
+ }
761
+ };
762
+ d.prototype.mb = function() {
763
+ fa(this.eb);
764
+ this.eb = null;
765
+ };
766
+ d.prototype.getRemainingSQL = function() {
767
+ return null !== this.pb ? this.pb : ua(this.kb);
768
+ };
769
+ "function" === typeof Symbol && "symbol" === typeof Symbol.iterator && (d.prototype[Symbol.iterator] = function() {
770
+ return this;
771
+ });
772
+ e.prototype.run = function(g, l) {
773
+ if (!this.db) throw "Database closed";
774
+ if (l) {
775
+ g = this.prepare(g, l);
776
+ try {
777
+ g.step();
778
+ } finally {
779
+ g.free();
780
+ }
781
+ } else this.handleError(v(this.db, g, 0, 0, h));
782
+ return this;
783
+ };
784
+ e.prototype.exec = function(g, l, n) {
785
+ if (!this.db) throw "Database closed";
786
+ var r = sa(), t = null;
787
+ try {
788
+ var y = xa(g), L = z(4);
789
+ for (g = []; 0 !== m(y, "i8"); ) {
790
+ ta(h);
791
+ ta(L);
792
+ this.handleError(qb(this.db, y, -1, h, L));
793
+ var J = m(h, "i32");
794
+ y = m(L, "i32");
795
+ if (0 !== J) {
796
+ var I = null;
797
+ t = new c(J, this);
798
+ for (null != l && t.bind(l); t.step(); ) null === I && (I = { columns: t.getColumnNames(), values: [] }, g.push(I)), I.values.push(t.get(null, n));
799
+ t.free();
800
+ }
801
+ }
802
+ return g;
803
+ } catch (M) {
804
+ throw t && t.free(), M;
805
+ } finally {
806
+ wa(r);
807
+ }
808
+ };
809
+ e.prototype.each = function(g, l, n, r, t) {
810
+ "function" === typeof l && (r = n, n = l, l = void 0);
811
+ g = this.prepare(g, l);
812
+ try {
813
+ for (; g.step(); ) n(g.getAsObject(
814
+ null,
815
+ t
816
+ ));
817
+ } finally {
818
+ g.free();
819
+ }
820
+ if ("function" === typeof r) return r();
821
+ };
822
+ e.prototype.prepare = function(g, l) {
823
+ ta(h);
824
+ this.handleError(G(this.db, g, -1, h, 0));
825
+ g = m(h, "i32");
826
+ if (0 === g) throw "Nothing to prepare";
827
+ var n = new c(g, this);
828
+ null != l && n.bind(l);
829
+ return this.fb[g] = n;
830
+ };
831
+ e.prototype.iterateStatements = function(g) {
832
+ return new d(g, this);
833
+ };
834
+ e.prototype["export"] = function() {
835
+ Object.values(this.fb).forEach(function(l) {
836
+ l.free();
837
+ });
838
+ Object.values(this.Sa).forEach(A);
839
+ this.Sa = {};
840
+ this.handleError(w(this.db));
841
+ var g = ya(this.filename);
842
+ this.handleError(q(
843
+ this.filename,
844
+ h
845
+ ));
846
+ this.db = m(h, "i32");
847
+ ob(this.db);
848
+ return g;
849
+ };
850
+ e.prototype.close = function() {
851
+ null !== this.db && (Object.values(this.fb).forEach(function(g) {
852
+ g.free();
853
+ }), Object.values(this.Sa).forEach(A), this.Sa = {}, this.Ya && (A(this.Ya), this.Ya = void 0), this.handleError(w(this.db)), za("/" + this.filename), this.db = null);
854
+ };
855
+ e.prototype.handleError = function(g) {
856
+ if (0 === g) return null;
857
+ g = tc(this.db);
858
+ throw Error(g);
859
+ };
860
+ e.prototype.getRowsModified = function() {
861
+ return C(this.db);
862
+ };
863
+ e.prototype.create_function = function(g, l) {
864
+ Object.prototype.hasOwnProperty.call(
865
+ this.Sa,
866
+ g
867
+ ) && (A(this.Sa[g]), delete this.Sa[g]);
868
+ var n = Aa(function(r, t, y) {
869
+ t = b(t, y);
870
+ try {
871
+ var L = l.apply(null, t);
872
+ } catch (J) {
873
+ va(r, J, -1);
874
+ return;
875
+ }
876
+ a(r, L);
877
+ }, "viii");
878
+ this.Sa[g] = n;
879
+ this.handleError(tb(this.db, g, l.length, 1, 0, n, 0, 0, 0));
880
+ return this;
881
+ };
882
+ e.prototype.create_aggregate = function(g, l) {
883
+ var n = l.init || function() {
884
+ return null;
885
+ }, r = l.finalize || function(I) {
886
+ return I;
887
+ }, t = l.step;
888
+ if (!t) throw "An aggregate function must have a step function in " + g;
889
+ var y = {};
890
+ Object.hasOwnProperty.call(this.Sa, g) && (A(this.Sa[g]), delete this.Sa[g]);
891
+ l = g + "__finalize";
892
+ Object.hasOwnProperty.call(this.Sa, l) && (A(this.Sa[l]), delete this.Sa[l]);
893
+ var L = Aa(function(I, M, Ra) {
894
+ var X = ub(I, 1);
895
+ Object.hasOwnProperty.call(y, X) || (y[X] = n());
896
+ M = b(M, Ra);
897
+ M = [y[X]].concat(M);
898
+ try {
899
+ y[X] = t.apply(null, M);
900
+ } catch (Fc) {
901
+ delete y[X], va(I, Fc, -1);
902
+ }
903
+ }, "viii"), J = Aa(function(I) {
904
+ var M = ub(I, 1);
905
+ try {
906
+ var Ra = r(y[M]);
907
+ } catch (X) {
908
+ delete y[M];
909
+ va(I, X, -1);
910
+ return;
911
+ }
912
+ a(I, Ra);
913
+ delete y[M];
914
+ }, "vi");
915
+ this.Sa[g] = L;
916
+ this.Sa[l] = J;
917
+ this.handleError(tb(this.db, g, t.length - 1, 1, 0, 0, L, J, 0));
918
+ return this;
919
+ };
920
+ e.prototype.updateHook = function(g) {
921
+ this.Ya && (vb(this.db, 0, 0), A(this.Ya), this.Ya = void 0);
922
+ g && (this.Ya = Aa(function(l, n, r, t, y) {
923
+ switch (n) {
924
+ case 18:
925
+ l = "insert";
926
+ break;
927
+ case 23:
928
+ l = "update";
929
+ break;
930
+ case 9:
931
+ l = "delete";
932
+ break;
933
+ default:
934
+ throw "unknown operationCode in updateHook callback: " + n;
935
+ }
936
+ r = r ? B(x, r) : "";
937
+ t = t ? B(x, t) : "";
938
+ if (y > Number.MAX_SAFE_INTEGER) throw "rowId too big to fit inside a Number";
939
+ g(l, r, t, Number(y));
940
+ }, "viiiij"), vb(this.db, this.Ya, 0));
941
+ };
942
+ f.Database = e;
943
+ };
944
+ var Ba = { ...f }, Ca = "./this.program", Da = (a, b) => {
945
+ throw b;
946
+ }, D = "", Ea, Fa;
947
+ if (ca) {
948
+ var fs = require$$2;
949
+ requirePathBrowserify();
950
+ D = __dirname + "/";
951
+ Fa = (a) => {
952
+ a = Ga(a) ? new URL(a) : a;
953
+ return fs.readFileSync(a);
954
+ };
955
+ Ea = async (a) => {
956
+ a = Ga(a) ? new URL(a) : a;
957
+ return fs.readFileSync(a, void 0);
958
+ };
959
+ !f.thisProgram && 1 < process.argv.length && (Ca = process.argv[1].replace(/\\/g, "/"));
960
+ process.argv.slice(2);
961
+ module.exports = f;
962
+ Da = (a, b) => {
963
+ process.exitCode = a;
964
+ throw b;
965
+ };
966
+ } else if (aa || ba) ba ? D = self.location.href : "undefined" != typeof document && document.currentScript && (D = document.currentScript.src), D = D.startsWith("blob:") ? "" : D.slice(0, D.replace(/[?#].*/, "").lastIndexOf("/") + 1), ba && (Fa = (a) => {
967
+ var b = new XMLHttpRequest();
968
+ b.open("GET", a, false);
969
+ b.responseType = "arraybuffer";
970
+ b.send(null);
971
+ return new Uint8Array(b.response);
972
+ }), Ea = async (a) => {
973
+ if (Ga(a)) return new Promise((c, d) => {
974
+ var e = new XMLHttpRequest();
975
+ e.open("GET", a, true);
976
+ e.responseType = "arraybuffer";
977
+ e.onload = () => {
978
+ 200 == e.status || 0 == e.status && e.response ? c(e.response) : d(e.status);
979
+ };
980
+ e.onerror = d;
981
+ e.send(null);
982
+ });
983
+ var b = await fetch(a, { credentials: "same-origin" });
984
+ if (b.ok) return b.arrayBuffer();
985
+ throw Error(b.status + " : " + b.url);
986
+ };
987
+ var Ha = f.print || console.log.bind(console), Ia = f.printErr || console.error.bind(console);
988
+ Object.assign(f, Ba);
989
+ Ba = null;
990
+ f.thisProgram && (Ca = f.thisProgram);
991
+ var Ja = f.wasmBinary, Ka, La = false, Ma, p, x, Na, E, F, Oa, H, Pa, Ga = (a) => a.startsWith("file://");
992
+ function Qa() {
993
+ var a = Ka.buffer;
994
+ f.HEAP8 = p = new Int8Array(a);
995
+ f.HEAP16 = Na = new Int16Array(a);
996
+ f.HEAPU8 = x = new Uint8Array(a);
997
+ f.HEAPU16 = new Uint16Array(a);
998
+ f.HEAP32 = E = new Int32Array(a);
999
+ f.HEAPU32 = F = new Uint32Array(a);
1000
+ f.HEAPF32 = Oa = new Float32Array(a);
1001
+ f.HEAPF64 = Pa = new Float64Array(a);
1002
+ f.HEAP64 = H = new BigInt64Array(a);
1003
+ f.HEAPU64 = new BigUint64Array(a);
1004
+ }
1005
+ var K = 0, Sa = null;
1006
+ function Ta(a) {
1007
+ f.onAbort?.(a);
1008
+ a = "Aborted(" + a + ")";
1009
+ Ia(a);
1010
+ La = true;
1011
+ throw new WebAssembly.RuntimeError(a + ". Build with -sASSERTIONS for more info.");
1012
+ }
1013
+ var Ua;
1014
+ async function Va(a) {
1015
+ if (!Ja) try {
1016
+ var b = await Ea(a);
1017
+ return new Uint8Array(b);
1018
+ } catch {
1019
+ }
1020
+ if (a == Ua && Ja) a = new Uint8Array(Ja);
1021
+ else if (Fa) a = Fa(a);
1022
+ else throw "both async and sync fetching of the wasm failed";
1023
+ return a;
1024
+ }
1025
+ async function Wa(a, b) {
1026
+ try {
1027
+ var c = await Va(a);
1028
+ return await WebAssembly.instantiate(c, b);
1029
+ } catch (d) {
1030
+ Ia(`failed to asynchronously prepare wasm: ${d}`), Ta(d);
1031
+ }
1032
+ }
1033
+ async function Xa(a) {
1034
+ var b = Ua;
1035
+ if (!Ja && "function" == typeof WebAssembly.instantiateStreaming && !Ga(b) && !ca) try {
1036
+ var c = fetch(b, { credentials: "same-origin" });
1037
+ return await WebAssembly.instantiateStreaming(c, a);
1038
+ } catch (d) {
1039
+ Ia(`wasm streaming compile failed: ${d}`), Ia("falling back to ArrayBuffer instantiation");
1040
+ }
1041
+ return Wa(b, a);
1042
+ }
1043
+ class Ya {
1044
+ name = "ExitStatus";
1045
+ constructor(a) {
1046
+ this.message = `Program terminated with exit(${a})`;
1047
+ this.status = a;
1048
+ }
1049
+ }
1050
+ var Za = (a) => {
1051
+ for (; 0 < a.length; ) a.shift()(f);
1052
+ }, $a = [], ab = [], bb = () => {
1053
+ var a = f.preRun.shift();
1054
+ ab.unshift(a);
1055
+ };
1056
+ function m(a, b = "i8") {
1057
+ b.endsWith("*") && (b = "*");
1058
+ switch (b) {
1059
+ case "i1":
1060
+ return p[a];
1061
+ case "i8":
1062
+ return p[a];
1063
+ case "i16":
1064
+ return Na[a >> 1];
1065
+ case "i32":
1066
+ return E[a >> 2];
1067
+ case "i64":
1068
+ return H[a >> 3];
1069
+ case "float":
1070
+ return Oa[a >> 2];
1071
+ case "double":
1072
+ return Pa[a >> 3];
1073
+ case "*":
1074
+ return F[a >> 2];
1075
+ default:
1076
+ Ta(`invalid type for getValue: ${b}`);
1077
+ }
1078
+ }
1079
+ var cb = f.noExitRuntime || true;
1080
+ function ta(a) {
1081
+ var b = "i32";
1082
+ b.endsWith("*") && (b = "*");
1083
+ switch (b) {
1084
+ case "i1":
1085
+ p[a] = 0;
1086
+ break;
1087
+ case "i8":
1088
+ p[a] = 0;
1089
+ break;
1090
+ case "i16":
1091
+ Na[a >> 1] = 0;
1092
+ break;
1093
+ case "i32":
1094
+ E[a >> 2] = 0;
1095
+ break;
1096
+ case "i64":
1097
+ H[a >> 3] = BigInt(0);
1098
+ break;
1099
+ case "float":
1100
+ Oa[a >> 2] = 0;
1101
+ break;
1102
+ case "double":
1103
+ Pa[a >> 3] = 0;
1104
+ break;
1105
+ case "*":
1106
+ F[a >> 2] = 0;
1107
+ break;
1108
+ default:
1109
+ Ta(`invalid type for setValue: ${b}`);
1110
+ }
1111
+ }
1112
+ var db = "undefined" != typeof TextDecoder ? new TextDecoder() : void 0, B = (a, b = 0, c = NaN) => {
1113
+ var d = b + c;
1114
+ for (c = b; a[c] && !(c >= d); ) ++c;
1115
+ if (16 < c - b && a.buffer && db) return db.decode(a.subarray(b, c));
1116
+ for (d = ""; b < c; ) {
1117
+ var e = a[b++];
1118
+ if (e & 128) {
1119
+ var h = a[b++] & 63;
1120
+ if (192 == (e & 224)) d += String.fromCharCode((e & 31) << 6 | h);
1121
+ else {
1122
+ var k = a[b++] & 63;
1123
+ e = 224 == (e & 240) ? (e & 15) << 12 | h << 6 | k : (e & 7) << 18 | h << 12 | k << 6 | a[b++] & 63;
1124
+ 65536 > e ? d += String.fromCharCode(e) : (e -= 65536, d += String.fromCharCode(55296 | e >> 10, 56320 | e & 1023));
1125
+ }
1126
+ } else d += String.fromCharCode(e);
1127
+ }
1128
+ return d;
1129
+ }, ua = (a, b) => a ? B(x, a, b) : "", eb = (a, b) => {
1130
+ for (var c = 0, d = a.length - 1; 0 <= d; d--) {
1131
+ var e = a[d];
1132
+ "." === e ? a.splice(d, 1) : ".." === e ? (a.splice(d, 1), c++) : c && (a.splice(d, 1), c--);
1133
+ }
1134
+ if (b) for (; c; c--) a.unshift("..");
1135
+ return a;
1136
+ }, ka = (a) => {
1137
+ var b = "/" === a.charAt(0), c = "/" === a.slice(-1);
1138
+ (a = eb(a.split("/").filter((d) => !!d), !b).join("/")) || b || (a = ".");
1139
+ a && c && (a += "/");
1140
+ return (b ? "/" : "") + a;
1141
+ }, fb = (a) => {
1142
+ var b = /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/.exec(a).slice(1);
1143
+ a = b[0];
1144
+ b = b[1];
1145
+ if (!a && !b) return ".";
1146
+ b &&= b.slice(0, -1);
1147
+ return a + b;
1148
+ }, gb = (a) => a && a.match(/([^\/]+|\/)\/*$/)[1], hb = () => {
1149
+ if (ca) {
1150
+ var a = require$$2;
1151
+ return (b) => a.randomFillSync(b);
1152
+ }
1153
+ return (b) => crypto.getRandomValues(b);
1154
+ }, ib = (a) => {
1155
+ (ib = hb())(a);
1156
+ }, jb = (...a) => {
1157
+ for (var b = "", c = false, d = a.length - 1; -1 <= d && !c; d--) {
1158
+ c = 0 <= d ? a[d] : "/";
1159
+ if ("string" != typeof c) throw new TypeError("Arguments to path.resolve must be strings");
1160
+ if (!c) return "";
1161
+ b = c + "/" + b;
1162
+ c = "/" === c.charAt(0);
1163
+ }
1164
+ b = eb(b.split("/").filter((e) => !!e), !c).join("/");
1165
+ return (c ? "/" : "") + b || ".";
1166
+ }, kb = [], ha = (a) => {
1167
+ for (var b = 0, c = 0; c < a.length; ++c) {
1168
+ var d = a.charCodeAt(c);
1169
+ 127 >= d ? b++ : 2047 >= d ? b += 2 : 55296 <= d && 57343 >= d ? (b += 4, ++c) : b += 3;
1170
+ }
1171
+ return b;
1172
+ }, u = (a, b, c, d) => {
1173
+ if (!(0 < d)) return 0;
1174
+ var e = c;
1175
+ d = c + d - 1;
1176
+ for (var h = 0; h < a.length; ++h) {
1177
+ var k = a.charCodeAt(h);
1178
+ if (55296 <= k && 57343 >= k) {
1179
+ var q = a.charCodeAt(++h);
1180
+ k = 65536 + ((k & 1023) << 10) | q & 1023;
1181
+ }
1182
+ if (127 >= k) {
1183
+ if (c >= d) break;
1184
+ b[c++] = k;
1185
+ } else {
1186
+ if (2047 >= k) {
1187
+ if (c + 1 >= d) break;
1188
+ b[c++] = 192 | k >> 6;
1189
+ } else {
1190
+ if (65535 >= k) {
1191
+ if (c + 2 >= d) break;
1192
+ b[c++] = 224 | k >> 12;
1193
+ } else {
1194
+ if (c + 3 >= d) break;
1195
+ b[c++] = 240 | k >> 18;
1196
+ b[c++] = 128 | k >> 12 & 63;
1197
+ }
1198
+ b[c++] = 128 | k >> 6 & 63;
1199
+ }
1200
+ b[c++] = 128 | k & 63;
1201
+ }
1202
+ }
1203
+ b[c] = 0;
1204
+ return c - e;
1205
+ }, ra = (a, b) => {
1206
+ var c = Array(ha(a) + 1);
1207
+ a = u(a, c, 0, c.length);
1208
+ b && (c.length = a);
1209
+ return c;
1210
+ }, mb = [];
1211
+ function nb(a, b) {
1212
+ mb[a] = { input: [], output: [], cb: b };
1213
+ wb(a, xb);
1214
+ }
1215
+ var xb = { open(a) {
1216
+ var b = mb[a.node.rdev];
1217
+ if (!b) throw new N(43);
1218
+ a.tty = b;
1219
+ a.seekable = false;
1220
+ }, close(a) {
1221
+ a.tty.cb.fsync(a.tty);
1222
+ }, fsync(a) {
1223
+ a.tty.cb.fsync(a.tty);
1224
+ }, read(a, b, c, d) {
1225
+ if (!a.tty || !a.tty.cb.xb) throw new N(60);
1226
+ for (var e = 0, h = 0; h < d; h++) {
1227
+ try {
1228
+ var k = a.tty.cb.xb(a.tty);
1229
+ } catch (q) {
1230
+ throw new N(29);
1231
+ }
1232
+ if (void 0 === k && 0 === e) throw new N(6);
1233
+ if (null === k || void 0 === k) break;
1234
+ e++;
1235
+ b[c + h] = k;
1236
+ }
1237
+ e && (a.node.atime = Date.now());
1238
+ return e;
1239
+ }, write(a, b, c, d) {
1240
+ if (!a.tty || !a.tty.cb.qb) throw new N(60);
1241
+ try {
1242
+ for (var e = 0; e < d; e++) a.tty.cb.qb(a.tty, b[c + e]);
1243
+ } catch (h) {
1244
+ throw new N(29);
1245
+ }
1246
+ d && (a.node.mtime = a.node.ctime = Date.now());
1247
+ return e;
1248
+ } }, yb = { xb() {
1249
+ a: {
1250
+ if (!kb.length) {
1251
+ var a = null;
1252
+ if (ca) {
1253
+ var b = Buffer.alloc(256), c = 0, d = process.stdin.fd;
1254
+ try {
1255
+ c = fs.readSync(d, b, 0, 256);
1256
+ } catch (e) {
1257
+ if (e.toString().includes("EOF")) c = 0;
1258
+ else throw e;
1259
+ }
1260
+ 0 < c && (a = b.slice(0, c).toString("utf-8"));
1261
+ } else "undefined" != typeof window && "function" == typeof window.prompt && (a = window.prompt("Input: "), null !== a && (a += "\n"));
1262
+ if (!a) {
1263
+ a = null;
1264
+ break a;
1265
+ }
1266
+ kb = ra(a, true);
1267
+ }
1268
+ a = kb.shift();
1269
+ }
1270
+ return a;
1271
+ }, qb(a, b) {
1272
+ null === b || 10 === b ? (Ha(B(a.output)), a.output = []) : 0 != b && a.output.push(b);
1273
+ }, fsync(a) {
1274
+ 0 < a.output?.length && (Ha(B(a.output)), a.output = []);
1275
+ }, Tb() {
1276
+ return { Ob: 25856, Qb: 5, Nb: 191, Pb: 35387, Mb: [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] };
1277
+ }, Ub() {
1278
+ return 0;
1279
+ }, Vb() {
1280
+ return [24, 80];
1281
+ } }, zb = { qb(a, b) {
1282
+ null === b || 10 === b ? (Ia(B(a.output)), a.output = []) : 0 != b && a.output.push(b);
1283
+ }, fsync(a) {
1284
+ 0 < a.output?.length && (Ia(B(a.output)), a.output = []);
1285
+ } }, O = { Wa: null, Xa() {
1286
+ return O.createNode(null, "/", 16895, 0);
1287
+ }, createNode(a, b, c, d) {
1288
+ if (24576 === (c & 61440) || 4096 === (c & 61440)) throw new N(63);
1289
+ O.Wa || (O.Wa = { dir: { node: { Ta: O.La.Ta, Ua: O.La.Ua, lookup: O.La.lookup, hb: O.La.hb, 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, ib: O.Ma.ib, jb: O.Ma.jb } }, link: { node: { Ta: O.La.Ta, Ua: O.La.Ua, readlink: O.La.readlink }, stream: {} }, ub: { node: { Ta: O.La.Ta, Ua: O.La.Ua }, stream: Ab } });
1290
+ c = Bb(a, b, c, d);
1291
+ 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.ub.node, c.Ma = O.Wa.ub.stream);
1292
+ c.atime = c.mtime = c.ctime = Date.now();
1293
+ a && (a.Na[b] = c, a.atime = a.mtime = a.ctime = c.atime);
1294
+ return c;
1295
+ }, Sb(a) {
1296
+ return a.Na ? a.Na.subarray ? a.Na.subarray(0, a.Ra) : new Uint8Array(a.Na) : new Uint8Array(0);
1297
+ }, La: { Ta(a) {
1298
+ var b = {};
1299
+ b.dev = 8192 === (a.mode & 61440) ? a.id : 1;
1300
+ b.ino = a.id;
1301
+ b.mode = a.mode;
1302
+ b.nlink = 1;
1303
+ b.uid = 0;
1304
+ b.gid = 0;
1305
+ b.rdev = a.rdev;
1306
+ 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;
1307
+ b.atime = new Date(a.atime);
1308
+ b.mtime = new Date(a.mtime);
1309
+ b.ctime = new Date(a.ctime);
1310
+ b.blksize = 4096;
1311
+ b.blocks = Math.ceil(b.size / b.blksize);
1312
+ return b;
1313
+ }, Ua(a, b) {
1314
+ for (var c of ["mode", "atime", "mtime", "ctime"]) null != b[c] && (a[c] = b[c]);
1315
+ 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)));
1316
+ }, lookup() {
1317
+ throw O.vb;
1318
+ }, hb(a, b, c, d) {
1319
+ return O.createNode(a, b, c, d);
1320
+ }, rename(a, b, c) {
1321
+ try {
1322
+ var d = Q(b, c);
1323
+ } catch (h) {
1324
+ }
1325
+ if (d) {
1326
+ if (P(a.mode)) for (var e in d.Na) throw new N(55);
1327
+ Cb(d);
1328
+ }
1329
+ delete a.parent.Na[a.name];
1330
+ b.Na[c] = a;
1331
+ a.name = c;
1332
+ b.ctime = b.mtime = a.parent.ctime = a.parent.mtime = Date.now();
1333
+ }, unlink(a, b) {
1334
+ delete a.Na[b];
1335
+ a.ctime = a.mtime = Date.now();
1336
+ }, rmdir(a, b) {
1337
+ var c = Q(a, b), d;
1338
+ for (d in c.Na) throw new N(55);
1339
+ delete a.Na[b];
1340
+ a.ctime = a.mtime = Date.now();
1341
+ }, readdir(a) {
1342
+ return [".", "..", ...Object.keys(a.Na)];
1343
+ }, symlink(a, b, c) {
1344
+ a = O.createNode(a, b, 41471, 0);
1345
+ a.link = c;
1346
+ return a;
1347
+ }, readlink(a) {
1348
+ if (40960 !== (a.mode & 61440)) throw new N(28);
1349
+ return a.link;
1350
+ } }, Ma: { read(a, b, c, d, e) {
1351
+ var h = a.node.Na;
1352
+ if (e >= a.node.Ra) return 0;
1353
+ a = Math.min(a.node.Ra - e, d);
1354
+ if (8 < a && h.subarray) b.set(h.subarray(e, e + a), c);
1355
+ else for (d = 0; d < a; d++) b[c + d] = h[e + d];
1356
+ return a;
1357
+ }, write(a, b, c, d, e, h) {
1358
+ b.buffer === p.buffer && (h = false);
1359
+ if (!d) return 0;
1360
+ a = a.node;
1361
+ a.mtime = a.ctime = Date.now();
1362
+ if (b.subarray && (!a.Na || a.Na.subarray)) {
1363
+ if (h) return a.Na = b.subarray(c, c + d), a.Ra = d;
1364
+ if (0 === a.Ra && 0 === e) return a.Na = b.slice(c, c + d), a.Ra = d;
1365
+ if (e + d <= a.Ra) return a.Na.set(b.subarray(
1366
+ c,
1367
+ c + d
1368
+ ), e), d;
1369
+ }
1370
+ h = e + d;
1371
+ var k = a.Na ? a.Na.length : 0;
1372
+ k >= h || (h = Math.max(h, k * (1048576 > k ? 2 : 1.125) >>> 0), 0 != k && (h = Math.max(h, 256)), k = a.Na, a.Na = new Uint8Array(h), 0 < a.Ra && a.Na.set(k.subarray(0, a.Ra), 0));
1373
+ if (a.Na.subarray && b.subarray) a.Na.set(b.subarray(c, c + d), e);
1374
+ else for (h = 0; h < d; h++) a.Na[e + h] = b[c + h];
1375
+ a.Ra = Math.max(a.Ra, e + d);
1376
+ return d;
1377
+ }, Va(a, b, c) {
1378
+ 1 === c ? b += a.position : 2 === c && 32768 === (a.node.mode & 61440) && (b += a.node.Ra);
1379
+ if (0 > b) throw new N(28);
1380
+ return b;
1381
+ }, ib(a, b, c, d, e) {
1382
+ if (32768 !== (a.node.mode & 61440)) throw new N(43);
1383
+ a = a.node.Na;
1384
+ if (e & 2 || !a || a.buffer !== p.buffer) {
1385
+ e = true;
1386
+ d = 65536 * Math.ceil(b / 65536);
1387
+ var h = Db(65536, d);
1388
+ h && x.fill(0, h, h + d);
1389
+ d = h;
1390
+ if (!d) throw new N(48);
1391
+ if (a) {
1392
+ if (0 < c || c + b < a.length) a.subarray ? a = a.subarray(c, c + b) : a = Array.prototype.slice.call(a, c, c + b);
1393
+ p.set(a, d);
1394
+ }
1395
+ } else e = false, d = a.byteOffset;
1396
+ return { Kb: d, Ab: e };
1397
+ }, jb(a, b, c, d) {
1398
+ O.Ma.write(a, b, 0, d, c, false);
1399
+ return 0;
1400
+ } } }, la = (a, b) => {
1401
+ var c = 0;
1402
+ a && (c |= 365);
1403
+ b && (c |= 146);
1404
+ return c;
1405
+ }, Eb = null, Fb = {}, Gb = [], Hb = 1, R = null, Ib = false, Jb = true, Kb = {}, N = class {
1406
+ name = "ErrnoError";
1407
+ constructor(a) {
1408
+ this.Pa = a;
1409
+ }
1410
+ }, Lb = class {
1411
+ gb = {};
1412
+ node = null;
1413
+ get flags() {
1414
+ return this.gb.flags;
1415
+ }
1416
+ set flags(a) {
1417
+ this.gb.flags = a;
1418
+ }
1419
+ get position() {
1420
+ return this.gb.position;
1421
+ }
1422
+ set position(a) {
1423
+ this.gb.position = a;
1424
+ }
1425
+ }, Mb = class {
1426
+ La = {};
1427
+ Ma = {};
1428
+ ab = null;
1429
+ constructor(a, b, c, d) {
1430
+ a ||= this;
1431
+ this.parent = a;
1432
+ this.Xa = a.Xa;
1433
+ this.id = Hb++;
1434
+ this.name = b;
1435
+ this.mode = c;
1436
+ this.rdev = d;
1437
+ this.atime = this.mtime = this.ctime = Date.now();
1438
+ }
1439
+ get read() {
1440
+ return 365 === (this.mode & 365);
1441
+ }
1442
+ set read(a) {
1443
+ a ? this.mode |= 365 : this.mode &= -366;
1444
+ }
1445
+ get write() {
1446
+ return 146 === (this.mode & 146);
1447
+ }
1448
+ set write(a) {
1449
+ a ? this.mode |= 146 : this.mode &= -147;
1450
+ }
1451
+ };
1452
+ function S(a, b = {}) {
1453
+ if (!a) throw new N(44);
1454
+ b.nb ?? (b.nb = true);
1455
+ "/" === a.charAt(0) || (a = "//" + a);
1456
+ var c = 0;
1457
+ a: for (; 40 > c; c++) {
1458
+ a = a.split("/").filter((q) => !!q);
1459
+ for (var d = Eb, e = "/", h = 0; h < a.length; h++) {
1460
+ var k = h === a.length - 1;
1461
+ if (k && b.parent) break;
1462
+ if ("." !== a[h]) if (".." === a[h]) e = fb(e), d = d.parent;
1463
+ else {
1464
+ e = ka(e + "/" + a[h]);
1465
+ try {
1466
+ d = Q(d, a[h]);
1467
+ } catch (q) {
1468
+ if (44 === q?.Pa && k && b.Jb) return { path: e };
1469
+ throw q;
1470
+ }
1471
+ !d.ab || k && !b.nb || (d = d.ab.root);
1472
+ if (40960 === (d.mode & 61440) && (!k || b.$a)) {
1473
+ if (!d.La.readlink) throw new N(52);
1474
+ d = d.La.readlink(d);
1475
+ "/" === d.charAt(0) || (d = fb(e) + "/" + d);
1476
+ a = d + "/" + a.slice(h + 1).join("/");
1477
+ continue a;
1478
+ }
1479
+ }
1480
+ }
1481
+ return { path: e, node: d };
1482
+ }
1483
+ throw new N(32);
1484
+ }
1485
+ function ja(a) {
1486
+ for (var b; ; ) {
1487
+ if (a === a.parent) return a = a.Xa.zb, b ? "/" !== a[a.length - 1] ? `${a}/${b}` : a + b : a;
1488
+ b = b ? `${a.name}/${b}` : a.name;
1489
+ a = a.parent;
1490
+ }
1491
+ }
1492
+ function Nb(a, b) {
1493
+ for (var c = 0, d = 0; d < b.length; d++) c = (c << 5) - c + b.charCodeAt(d) | 0;
1494
+ return (a + c >>> 0) % R.length;
1495
+ }
1496
+ function Cb(a) {
1497
+ var b = Nb(a.parent.id, a.name);
1498
+ if (R[b] === a) R[b] = a.bb;
1499
+ else for (b = R[b]; b; ) {
1500
+ if (b.bb === a) {
1501
+ b.bb = a.bb;
1502
+ break;
1503
+ }
1504
+ b = b.bb;
1505
+ }
1506
+ }
1507
+ function Q(a, b) {
1508
+ var c = P(a.mode) ? (c = Ob(a, "x")) ? c : a.La.lookup ? 0 : 2 : 54;
1509
+ if (c) throw new N(c);
1510
+ for (c = R[Nb(a.id, b)]; c; c = c.bb) {
1511
+ var d = c.name;
1512
+ if (c.parent.id === a.id && d === b) return c;
1513
+ }
1514
+ return a.La.lookup(a, b);
1515
+ }
1516
+ function Bb(a, b, c, d) {
1517
+ a = new Mb(a, b, c, d);
1518
+ b = Nb(a.parent.id, a.name);
1519
+ a.bb = R[b];
1520
+ return R[b] = a;
1521
+ }
1522
+ function P(a) {
1523
+ return 16384 === (a & 61440);
1524
+ }
1525
+ function Pb(a) {
1526
+ var b = ["r", "w", "rw"][a & 3];
1527
+ a & 512 && (b += "w");
1528
+ return b;
1529
+ }
1530
+ function Ob(a, b) {
1531
+ if (Jb) return 0;
1532
+ if (!b.includes("r") || a.mode & 292) {
1533
+ if (b.includes("w") && !(a.mode & 146) || b.includes("x") && !(a.mode & 73)) return 2;
1534
+ } else return 2;
1535
+ return 0;
1536
+ }
1537
+ function Qb(a, b) {
1538
+ if (!P(a.mode)) return 54;
1539
+ try {
1540
+ return Q(a, b), 20;
1541
+ } catch (c) {
1542
+ }
1543
+ return Ob(a, "wx");
1544
+ }
1545
+ function Rb(a, b, c) {
1546
+ try {
1547
+ var d = Q(a, b);
1548
+ } catch (e) {
1549
+ return e.Pa;
1550
+ }
1551
+ if (a = Ob(a, "wx")) return a;
1552
+ if (c) {
1553
+ if (!P(d.mode)) return 54;
1554
+ if (d === d.parent || "/" === ja(d)) return 10;
1555
+ } else if (P(d.mode)) return 31;
1556
+ return 0;
1557
+ }
1558
+ function Sb(a) {
1559
+ if (!a) throw new N(63);
1560
+ return a;
1561
+ }
1562
+ function T(a) {
1563
+ a = Gb[a];
1564
+ if (!a) throw new N(8);
1565
+ return a;
1566
+ }
1567
+ function Tb(a, b = -1) {
1568
+ a = Object.assign(new Lb(), a);
1569
+ if (-1 == b) a: {
1570
+ for (b = 0; 4096 >= b; b++) if (!Gb[b]) break a;
1571
+ throw new N(33);
1572
+ }
1573
+ a.fd = b;
1574
+ return Gb[b] = a;
1575
+ }
1576
+ function Ub(a, b = -1) {
1577
+ a = Tb(a, b);
1578
+ a.Ma?.Rb?.(a);
1579
+ return a;
1580
+ }
1581
+ function Vb(a, b, c) {
1582
+ var d = a?.Ma.Ua;
1583
+ a = d ? a : b;
1584
+ d ??= b.La.Ua;
1585
+ Sb(d);
1586
+ d(a, c);
1587
+ }
1588
+ var Ab = { open(a) {
1589
+ a.Ma = Fb[a.node.rdev].Ma;
1590
+ a.Ma.open?.(a);
1591
+ }, Va() {
1592
+ throw new N(70);
1593
+ } };
1594
+ function wb(a, b) {
1595
+ Fb[a] = { Ma: b };
1596
+ }
1597
+ function Wb(a, b) {
1598
+ var c = "/" === b;
1599
+ if (c && Eb) throw new N(10);
1600
+ if (!c && b) {
1601
+ var d = S(b, { nb: false });
1602
+ b = d.path;
1603
+ d = d.node;
1604
+ if (d.ab) throw new N(10);
1605
+ if (!P(d.mode)) throw new N(54);
1606
+ }
1607
+ b = { type: a, Wb: {}, zb: b, Ib: [] };
1608
+ a = a.Xa(b);
1609
+ a.Xa = b;
1610
+ b.root = a;
1611
+ c ? Eb = a : d && (d.ab = b, d.Xa && d.Xa.Ib.push(b));
1612
+ }
1613
+ function Xb(a, b, c) {
1614
+ var d = S(a, { parent: true }).node;
1615
+ a = gb(a);
1616
+ if (!a) throw new N(28);
1617
+ if ("." === a || ".." === a) throw new N(20);
1618
+ var e = Qb(d, a);
1619
+ if (e) throw new N(e);
1620
+ if (!d.La.hb) throw new N(63);
1621
+ return d.La.hb(d, a, b, c);
1622
+ }
1623
+ function ma(a, b = 438) {
1624
+ return Xb(a, b & 4095 | 32768, 0);
1625
+ }
1626
+ function U(a, b = 511) {
1627
+ return Xb(a, b & 1023 | 16384, 0);
1628
+ }
1629
+ function Yb(a, b, c) {
1630
+ "undefined" == typeof c && (c = b, b = 438);
1631
+ Xb(a, b | 8192, c);
1632
+ }
1633
+ function Zb(a, b) {
1634
+ if (!jb(a)) throw new N(44);
1635
+ var c = S(b, { parent: true }).node;
1636
+ if (!c) throw new N(44);
1637
+ b = gb(b);
1638
+ var d = Qb(c, b);
1639
+ if (d) throw new N(d);
1640
+ if (!c.La.symlink) throw new N(63);
1641
+ c.La.symlink(c, b, a);
1642
+ }
1643
+ function $b(a) {
1644
+ var b = S(a, { parent: true }).node;
1645
+ a = gb(a);
1646
+ var c = Q(b, a), d = Rb(b, a, true);
1647
+ if (d) throw new N(d);
1648
+ if (!b.La.rmdir) throw new N(63);
1649
+ if (c.ab) throw new N(10);
1650
+ b.La.rmdir(b, a);
1651
+ Cb(c);
1652
+ }
1653
+ function za(a) {
1654
+ var b = S(a, { parent: true }).node;
1655
+ if (!b) throw new N(44);
1656
+ a = gb(a);
1657
+ var c = Q(b, a), d = Rb(b, a, false);
1658
+ if (d) throw new N(d);
1659
+ if (!b.La.unlink) throw new N(63);
1660
+ if (c.ab) throw new N(10);
1661
+ b.La.unlink(b, a);
1662
+ Cb(c);
1663
+ }
1664
+ function ac(a, b) {
1665
+ a = S(a, { $a: !b }).node;
1666
+ return Sb(a.La.Ta)(a);
1667
+ }
1668
+ function bc(a, b, c, d) {
1669
+ Vb(a, b, { mode: c & 4095 | b.mode & -4096, ctime: Date.now(), Fb: d });
1670
+ }
1671
+ function na(a, b) {
1672
+ a = "string" == typeof a ? S(a, { $a: true }).node : a;
1673
+ bc(null, a, b);
1674
+ }
1675
+ function cc(a, b, c) {
1676
+ if (P(b.mode)) throw new N(31);
1677
+ if (32768 !== (b.mode & 61440)) throw new N(28);
1678
+ var d = Ob(b, "w");
1679
+ if (d) throw new N(d);
1680
+ Vb(a, b, { size: c, timestamp: Date.now() });
1681
+ }
1682
+ function oa(a, b, c = 438) {
1683
+ if ("" === a) throw new N(44);
1684
+ if ("string" == typeof b) {
1685
+ var d = { r: 0, "r+": 2, w: 577, "w+": 578, a: 1089, "a+": 1090 }[b];
1686
+ if ("undefined" == typeof d) throw Error(`Unknown file open mode: ${b}`);
1687
+ b = d;
1688
+ }
1689
+ c = b & 64 ? c & 4095 | 32768 : 0;
1690
+ if ("object" == typeof a) d = a;
1691
+ else {
1692
+ var e = a.endsWith("/");
1693
+ a = S(a, { $a: !(b & 131072), Jb: true });
1694
+ d = a.node;
1695
+ a = a.path;
1696
+ }
1697
+ var h = false;
1698
+ if (b & 64) if (d) {
1699
+ if (b & 128) throw new N(20);
1700
+ } else {
1701
+ if (e) throw new N(31);
1702
+ d = Xb(a, c | 511, 0);
1703
+ h = true;
1704
+ }
1705
+ if (!d) throw new N(44);
1706
+ 8192 === (d.mode & 61440) && (b &= -513);
1707
+ if (b & 65536 && !P(d.mode)) throw new N(54);
1708
+ if (!h && (e = d ? 40960 === (d.mode & 61440) ? 32 : P(d.mode) && ("r" !== Pb(b) || b & 576) ? 31 : Ob(d, Pb(b)) : 44)) throw new N(e);
1709
+ b & 512 && !h && (e = d, e = "string" == typeof e ? S(e, { $a: true }).node : e, cc(null, e, 0));
1710
+ b &= -131713;
1711
+ e = Tb({ node: d, path: ja(d), flags: b, seekable: true, position: 0, Ma: d.Ma, Lb: [], error: false });
1712
+ e.Ma.open && e.Ma.open(e);
1713
+ h && na(d, c & 511);
1714
+ !f.logReadFiles || b & 1 || a in Kb || (Kb[a] = 1);
1715
+ return e;
1716
+ }
1717
+ function qa(a) {
1718
+ if (null === a.fd) throw new N(8);
1719
+ a.ob && (a.ob = null);
1720
+ try {
1721
+ a.Ma.close && a.Ma.close(a);
1722
+ } catch (b) {
1723
+ throw b;
1724
+ } finally {
1725
+ Gb[a.fd] = null;
1726
+ }
1727
+ a.fd = null;
1728
+ }
1729
+ function mc(a, b, c) {
1730
+ if (null === a.fd) throw new N(8);
1731
+ if (!a.seekable || !a.Ma.Va) throw new N(70);
1732
+ if (0 != c && 1 != c && 2 != c) throw new N(28);
1733
+ a.position = a.Ma.Va(a, b, c);
1734
+ a.Lb = [];
1735
+ }
1736
+ function Ec(a, b, c, d, e) {
1737
+ if (0 > d || 0 > e) throw new N(28);
1738
+ if (null === a.fd) throw new N(8);
1739
+ if (1 === (a.flags & 2097155)) throw new N(8);
1740
+ if (P(a.node.mode)) throw new N(31);
1741
+ if (!a.Ma.read) throw new N(28);
1742
+ var h = "undefined" != typeof e;
1743
+ if (!h) e = a.position;
1744
+ else if (!a.seekable) throw new N(70);
1745
+ b = a.Ma.read(a, b, c, d, e);
1746
+ h || (a.position += b);
1747
+ return b;
1748
+ }
1749
+ function pa(a, b, c, d, e) {
1750
+ if (0 > d || 0 > e) throw new N(28);
1751
+ if (null === a.fd) throw new N(8);
1752
+ if (0 === (a.flags & 2097155)) throw new N(8);
1753
+ if (P(a.node.mode)) throw new N(31);
1754
+ if (!a.Ma.write) throw new N(28);
1755
+ a.seekable && a.flags & 1024 && mc(a, 0, 2);
1756
+ var h = "undefined" != typeof e;
1757
+ if (!h) e = a.position;
1758
+ else if (!a.seekable) throw new N(70);
1759
+ b = a.Ma.write(a, b, c, d, e, void 0);
1760
+ h || (a.position += b);
1761
+ return b;
1762
+ }
1763
+ function ya(a) {
1764
+ var c;
1765
+ var d = oa(a, d || 0);
1766
+ a = ac(a).size;
1767
+ var e = new Uint8Array(a);
1768
+ Ec(d, e, 0, a, 0);
1769
+ c = e;
1770
+ qa(d);
1771
+ return c;
1772
+ }
1773
+ function V(a, b, c) {
1774
+ a = ka("/dev/" + a);
1775
+ var d = la(!!b, !!c);
1776
+ V.yb ?? (V.yb = 64);
1777
+ var e = V.yb++ << 8 | 0;
1778
+ wb(e, { open(h) {
1779
+ h.seekable = false;
1780
+ }, close() {
1781
+ c?.buffer?.length && c(10);
1782
+ }, read(h, k, q, w) {
1783
+ for (var v = 0, C = 0; C < w; C++) {
1784
+ try {
1785
+ var G = b();
1786
+ } catch (pb) {
1787
+ throw new N(29);
1788
+ }
1789
+ if (void 0 === G && 0 === v) throw new N(6);
1790
+ if (null === G || void 0 === G) break;
1791
+ v++;
1792
+ k[q + C] = G;
1793
+ }
1794
+ v && (h.node.atime = Date.now());
1795
+ return v;
1796
+ }, write(h, k, q, w) {
1797
+ for (var v = 0; v < w; v++) try {
1798
+ c(k[q + v]);
1799
+ } catch (C) {
1800
+ throw new N(29);
1801
+ }
1802
+ w && (h.node.mtime = h.node.ctime = Date.now());
1803
+ return v;
1804
+ } });
1805
+ Yb(a, d, e);
1806
+ }
1807
+ var W = {};
1808
+ function Gc(a, b, c) {
1809
+ if ("/" === b.charAt(0)) return b;
1810
+ a = -100 === a ? "/" : T(a).path;
1811
+ if (0 == b.length) {
1812
+ if (!c) throw new N(44);
1813
+ return a;
1814
+ }
1815
+ return a + "/" + b;
1816
+ }
1817
+ function Hc(a, b) {
1818
+ E[a >> 2] = b.dev;
1819
+ E[a + 4 >> 2] = b.mode;
1820
+ F[a + 8 >> 2] = b.nlink;
1821
+ E[a + 12 >> 2] = b.uid;
1822
+ E[a + 16 >> 2] = b.gid;
1823
+ E[a + 20 >> 2] = b.rdev;
1824
+ H[a + 24 >> 3] = BigInt(b.size);
1825
+ E[a + 32 >> 2] = 4096;
1826
+ E[a + 36 >> 2] = b.blocks;
1827
+ var c = b.atime.getTime(), d = b.mtime.getTime(), e = b.ctime.getTime();
1828
+ H[a + 40 >> 3] = BigInt(Math.floor(c / 1e3));
1829
+ F[a + 48 >> 2] = c % 1e3 * 1e6;
1830
+ H[a + 56 >> 3] = BigInt(Math.floor(d / 1e3));
1831
+ F[a + 64 >> 2] = d % 1e3 * 1e6;
1832
+ H[a + 72 >> 3] = BigInt(Math.floor(e / 1e3));
1833
+ F[a + 80 >> 2] = e % 1e3 * 1e6;
1834
+ H[a + 88 >> 3] = BigInt(b.ino);
1835
+ return 0;
1836
+ }
1837
+ var Ic = void 0, Jc = () => {
1838
+ var a = E[+Ic >> 2];
1839
+ Ic += 4;
1840
+ return a;
1841
+ }, Kc = 0, Lc = [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335], Mc = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334], Nc = {}, Oc = (a) => {
1842
+ Ma = a;
1843
+ cb || 0 < Kc || (f.onExit?.(a), La = true);
1844
+ Da(a, new Ya(a));
1845
+ }, Pc = (a) => {
1846
+ if (!La) try {
1847
+ if (a(), !(cb || 0 < Kc)) try {
1848
+ Ma = a = Ma, Oc(a);
1849
+ } catch (b) {
1850
+ b instanceof Ya || "unwind" == b || Da(1, b);
1851
+ }
1852
+ } catch (b) {
1853
+ b instanceof Ya || "unwind" == b || Da(1, b);
1854
+ }
1855
+ }, Qc = {}, Sc = () => {
1856
+ if (!Rc) {
1857
+ var a = { USER: "web_user", LOGNAME: "web_user", PATH: "/", PWD: "/", HOME: "/home/web_user", LANG: ("object" == typeof navigator && navigator.languages && navigator.languages[0] || "C").replace("-", "_") + ".UTF-8", _: Ca || "./this.program" }, b;
1858
+ for (b in Qc) void 0 === Qc[b] ? delete a[b] : a[b] = Qc[b];
1859
+ var c = [];
1860
+ for (b in a) c.push(`${b}=${a[b]}`);
1861
+ Rc = c;
1862
+ }
1863
+ return Rc;
1864
+ }, Rc, xa = (a) => {
1865
+ var b = ha(a) + 1, c = z(b);
1866
+ u(a, x, c, b);
1867
+ return c;
1868
+ }, Tc = (a, b, c, d) => {
1869
+ var e = { string: (v) => {
1870
+ var C = 0;
1871
+ null !== v && void 0 !== v && 0 !== v && (C = xa(v));
1872
+ return C;
1873
+ }, array: (v) => {
1874
+ var C = z(v.length);
1875
+ p.set(v, C);
1876
+ return C;
1877
+ } };
1878
+ a = f["_" + a];
1879
+ var h = [], k = 0;
1880
+ if (d) for (var q = 0; q < d.length; q++) {
1881
+ var w = e[c[q]];
1882
+ w ? (0 === k && (k = sa()), h[q] = w(d[q])) : h[q] = d[q];
1883
+ }
1884
+ c = a(...h);
1885
+ return c = (function(v) {
1886
+ 0 !== k && wa(k);
1887
+ return "string" === b ? v ? B(x, v) : "" : "boolean" === b ? !!v : v;
1888
+ })(c);
1889
+ }, ea = 0, da = (a, b) => {
1890
+ b = 1 == b ? z(a.length) : ia(a.length);
1891
+ a.subarray || a.slice || (a = new Uint8Array(a));
1892
+ x.set(a, b);
1893
+ return b;
1894
+ }, Uc, Vc = [], Y, A = (a) => {
1895
+ Uc.delete(Y.get(a));
1896
+ Y.set(a, null);
1897
+ Vc.push(a);
1898
+ }, Aa = (a, b) => {
1899
+ if (!Uc) {
1900
+ Uc = /* @__PURE__ */ new WeakMap();
1901
+ var c = Y.length;
1902
+ if (Uc) for (var d = 0; d < 0 + c; d++) {
1903
+ var e = Y.get(d);
1904
+ e && Uc.set(e, d);
1905
+ }
1906
+ }
1907
+ if (c = Uc.get(a) || 0) return c;
1908
+ if (Vc.length) c = Vc.pop();
1909
+ else {
1910
+ try {
1911
+ Y.grow(1);
1912
+ } catch (w) {
1913
+ if (!(w instanceof RangeError)) throw w;
1914
+ throw "Unable to grow wasm table. Set ALLOW_TABLE_GROWTH.";
1915
+ }
1916
+ c = Y.length - 1;
1917
+ }
1918
+ try {
1919
+ Y.set(c, a);
1920
+ } catch (w) {
1921
+ if (!(w instanceof TypeError)) throw w;
1922
+ if ("function" == typeof WebAssembly.Function) {
1923
+ var h = WebAssembly.Function;
1924
+ d = { i: "i32", j: "i64", f: "f32", d: "f64", e: "externref", p: "i32" };
1925
+ e = { parameters: [], results: "v" == b[0] ? [] : [d[b[0]]] };
1926
+ for (var k = 1; k < b.length; ++k) e.parameters.push(d[b[k]]);
1927
+ b = new h(e, a);
1928
+ } else {
1929
+ d = [1];
1930
+ e = b.slice(0, 1);
1931
+ b = b.slice(1);
1932
+ k = { i: 127, p: 127, j: 126, f: 125, d: 124, e: 111 };
1933
+ d.push(96);
1934
+ var q = b.length;
1935
+ 128 > q ? d.push(q) : d.push(q % 128 | 128, q >> 7);
1936
+ for (h of b) d.push(k[h]);
1937
+ "v" == e ? d.push(0) : d.push(1, k[e]);
1938
+ b = [0, 97, 115, 109, 1, 0, 0, 0, 1];
1939
+ h = d.length;
1940
+ 128 > h ? b.push(h) : b.push(h % 128 | 128, h >> 7);
1941
+ b.push(...d);
1942
+ b.push(2, 7, 1, 1, 101, 1, 102, 0, 0, 7, 5, 1, 1, 102, 0, 0);
1943
+ b = new WebAssembly.Module(new Uint8Array(b));
1944
+ b = new WebAssembly.Instance(b, { e: { f: a } }).exports.f;
1945
+ }
1946
+ Y.set(c, b);
1947
+ }
1948
+ Uc.set(a, c);
1949
+ return c;
1950
+ };
1951
+ R = Array(4096);
1952
+ Wb(O, "/");
1953
+ U("/tmp");
1954
+ U("/home");
1955
+ U("/home/web_user");
1956
+ (function() {
1957
+ U("/dev");
1958
+ wb(259, { read: () => 0, write: (d, e, h, k) => k, Va: () => 0 });
1959
+ Yb("/dev/null", 259);
1960
+ nb(1280, yb);
1961
+ nb(1536, zb);
1962
+ Yb("/dev/tty", 1280);
1963
+ Yb("/dev/tty1", 1536);
1964
+ var a = new Uint8Array(1024), b = 0, c = () => {
1965
+ 0 === b && (ib(a), b = a.byteLength);
1966
+ return a[--b];
1967
+ };
1968
+ V("random", c);
1969
+ V("urandom", c);
1970
+ U("/dev/shm");
1971
+ U("/dev/shm/tmp");
1972
+ })();
1973
+ (function() {
1974
+ U("/proc");
1975
+ var a = U("/proc/self");
1976
+ U("/proc/self/fd");
1977
+ Wb({ Xa() {
1978
+ var b = Bb(a, "fd", 16895, 73);
1979
+ b.Ma = { Va: O.Ma.Va };
1980
+ b.La = { lookup(c, d) {
1981
+ c = +d;
1982
+ var e = T(c);
1983
+ c = { parent: null, Xa: { zb: "fake" }, La: { readlink: () => e.path }, id: c + 1 };
1984
+ return c.parent = c;
1985
+ }, readdir() {
1986
+ return Array.from(Gb.entries()).filter(([, c]) => c).map(([c]) => c.toString());
1987
+ } };
1988
+ return b;
1989
+ } }, "/proc/self/fd");
1990
+ })();
1991
+ O.vb = new N(44);
1992
+ O.vb.stack = "<generic error, no stack>";
1993
+ var Xc = { a: (a, b, c, d) => Ta(`Assertion failed: ${a ? B(x, a) : ""}, at: ` + [b ? b ? B(x, b) : "" : "unknown filename", c, d ? d ? B(x, d) : "" : "unknown function"]), i: function(a, b) {
1994
+ try {
1995
+ return a = a ? B(x, a) : "", na(a, b), 0;
1996
+ } catch (c) {
1997
+ if ("undefined" == typeof W || "ErrnoError" !== c.name) throw c;
1998
+ return -c.Pa;
1999
+ }
2000
+ }, L: function(a, b, c) {
2001
+ try {
2002
+ b = b ? B(x, b) : "";
2003
+ b = Gc(a, b);
2004
+ if (c & -8) return -28;
2005
+ var d = S(b, { $a: true }).node;
2006
+ if (!d) return -44;
2007
+ a = "";
2008
+ c & 4 && (a += "r");
2009
+ c & 2 && (a += "w");
2010
+ c & 1 && (a += "x");
2011
+ return a && Ob(d, a) ? -2 : 0;
2012
+ } catch (e) {
2013
+ if ("undefined" == typeof W || "ErrnoError" !== e.name) throw e;
2014
+ return -e.Pa;
2015
+ }
2016
+ }, j: function(a, b) {
2017
+ try {
2018
+ var c = T(a);
2019
+ bc(c, c.node, b, false);
2020
+ return 0;
2021
+ } catch (d) {
2022
+ if ("undefined" == typeof W || "ErrnoError" !== d.name) throw d;
2023
+ return -d.Pa;
2024
+ }
2025
+ }, h: function(a) {
2026
+ try {
2027
+ var b = T(a);
2028
+ Vb(b, b.node, { timestamp: Date.now(), Fb: false });
2029
+ return 0;
2030
+ } catch (c) {
2031
+ if ("undefined" == typeof W || "ErrnoError" !== c.name) throw c;
2032
+ return -c.Pa;
2033
+ }
2034
+ }, b: function(a, b, c) {
2035
+ Ic = c;
2036
+ try {
2037
+ var d = T(a);
2038
+ switch (b) {
2039
+ case 0:
2040
+ var e = Jc();
2041
+ if (0 > e) break;
2042
+ for (; Gb[e]; ) e++;
2043
+ return Ub(d, e).fd;
2044
+ case 1:
2045
+ case 2:
2046
+ return 0;
2047
+ case 3:
2048
+ return d.flags;
2049
+ case 4:
2050
+ return e = Jc(), d.flags |= e, 0;
2051
+ case 12:
2052
+ return e = Jc(), Na[e + 0 >> 1] = 2, 0;
2053
+ case 13:
2054
+ case 14:
2055
+ return 0;
2056
+ }
2057
+ return -28;
2058
+ } catch (h) {
2059
+ if ("undefined" == typeof W || "ErrnoError" !== h.name) throw h;
2060
+ return -h.Pa;
2061
+ }
2062
+ }, g: function(a, b) {
2063
+ try {
2064
+ var c = T(a), d = c.node, e = c.Ma.Ta;
2065
+ a = e ? c : d;
2066
+ e ??= d.La.Ta;
2067
+ Sb(e);
2068
+ var h = e(a);
2069
+ return Hc(b, h);
2070
+ } catch (k) {
2071
+ if ("undefined" == typeof W || "ErrnoError" !== k.name) throw k;
2072
+ return -k.Pa;
2073
+ }
2074
+ }, H: function(a, b) {
2075
+ b = -9007199254740992 > b || 9007199254740992 < b ? NaN : Number(b);
2076
+ try {
2077
+ if (isNaN(b)) return 61;
2078
+ var c = T(a);
2079
+ if (0 > b || 0 === (c.flags & 2097155)) throw new N(28);
2080
+ cc(c, c.node, b);
2081
+ return 0;
2082
+ } catch (d) {
2083
+ if ("undefined" == typeof W || "ErrnoError" !== d.name) throw d;
2084
+ return -d.Pa;
2085
+ }
2086
+ }, G: function(a, b) {
2087
+ try {
2088
+ if (0 === b) return -28;
2089
+ var c = ha("/") + 1;
2090
+ if (b < c) return -68;
2091
+ u("/", x, a, b);
2092
+ return c;
2093
+ } catch (d) {
2094
+ if ("undefined" == typeof W || "ErrnoError" !== d.name) throw d;
2095
+ return -d.Pa;
2096
+ }
2097
+ }, K: function(a, b) {
2098
+ try {
2099
+ return a = a ? B(x, a) : "", Hc(b, ac(a, true));
2100
+ } catch (c) {
2101
+ if ("undefined" == typeof W || "ErrnoError" !== c.name) throw c;
2102
+ return -c.Pa;
2103
+ }
2104
+ }, C: function(a, b, c) {
2105
+ try {
2106
+ return b = b ? B(x, b) : "", b = Gc(a, b), U(b, c), 0;
2107
+ } catch (d) {
2108
+ if ("undefined" == typeof W || "ErrnoError" !== d.name) throw d;
2109
+ return -d.Pa;
2110
+ }
2111
+ }, J: function(a, b, c, d) {
2112
+ try {
2113
+ b = b ? B(x, b) : "";
2114
+ var e = d & 256;
2115
+ b = Gc(a, b, d & 4096);
2116
+ return Hc(c, e ? ac(b, true) : ac(b));
2117
+ } catch (h) {
2118
+ if ("undefined" == typeof W || "ErrnoError" !== h.name) throw h;
2119
+ return -h.Pa;
2120
+ }
2121
+ }, x: function(a, b, c, d) {
2122
+ Ic = d;
2123
+ try {
2124
+ b = b ? B(x, b) : "";
2125
+ b = Gc(a, b);
2126
+ var e = d ? Jc() : 0;
2127
+ return oa(b, c, e).fd;
2128
+ } catch (h) {
2129
+ if ("undefined" == typeof W || "ErrnoError" !== h.name) throw h;
2130
+ return -h.Pa;
2131
+ }
2132
+ }, v: function(a, b, c, d) {
2133
+ try {
2134
+ b = b ? B(x, b) : "";
2135
+ b = Gc(a, b);
2136
+ if (0 >= d) return -28;
2137
+ var e = S(b).node;
2138
+ if (!e) throw new N(44);
2139
+ if (!e.La.readlink) throw new N(28);
2140
+ var h = e.La.readlink(e);
2141
+ var k = Math.min(d, ha(h)), q = p[c + k];
2142
+ u(h, x, c, d + 1);
2143
+ p[c + k] = q;
2144
+ return k;
2145
+ } catch (w) {
2146
+ if ("undefined" == typeof W || "ErrnoError" !== w.name) throw w;
2147
+ return -w.Pa;
2148
+ }
2149
+ }, u: function(a) {
2150
+ try {
2151
+ return a = a ? B(x, a) : "", $b(a), 0;
2152
+ } catch (b) {
2153
+ if ("undefined" == typeof W || "ErrnoError" !== b.name) throw b;
2154
+ return -b.Pa;
2155
+ }
2156
+ }, f: function(a, b) {
2157
+ try {
2158
+ return a = a ? B(x, a) : "", Hc(b, ac(a));
2159
+ } catch (c) {
2160
+ if ("undefined" == typeof W || "ErrnoError" !== c.name) throw c;
2161
+ return -c.Pa;
2162
+ }
2163
+ }, r: function(a, b, c) {
2164
+ try {
2165
+ return b = b ? B(x, b) : "", b = Gc(a, b), 0 === c ? za(b) : 512 === c ? $b(b) : Ta("Invalid flags passed to unlinkat"), 0;
2166
+ } catch (d) {
2167
+ if ("undefined" == typeof W || "ErrnoError" !== d.name) throw d;
2168
+ return -d.Pa;
2169
+ }
2170
+ }, q: function(a, b, c) {
2171
+ try {
2172
+ b = b ? B(x, b) : "";
2173
+ b = Gc(a, b, true);
2174
+ var d = Date.now(), e, h;
2175
+ if (c) {
2176
+ var k = F[c >> 2] + 4294967296 * E[c + 4 >> 2], q = E[c + 8 >> 2];
2177
+ 1073741823 == q ? e = d : 1073741822 == q ? e = null : e = 1e3 * k + q / 1e6;
2178
+ c += 16;
2179
+ k = F[c >> 2] + 4294967296 * E[c + 4 >> 2];
2180
+ q = E[c + 8 >> 2];
2181
+ 1073741823 == q ? h = d : 1073741822 == q ? h = null : h = 1e3 * k + q / 1e6;
2182
+ } else h = e = d;
2183
+ if (null !== (h ?? e)) {
2184
+ a = e;
2185
+ var w = S(b, { $a: true }).node;
2186
+ Sb(w.La.Ua)(w, { atime: a, mtime: h });
2187
+ }
2188
+ return 0;
2189
+ } catch (v) {
2190
+ if ("undefined" == typeof W || "ErrnoError" !== v.name) throw v;
2191
+ return -v.Pa;
2192
+ }
2193
+ }, m: () => Ta(""), l: () => {
2194
+ cb = false;
2195
+ Kc = 0;
2196
+ }, A: function(a, b) {
2197
+ a = -9007199254740992 > a || 9007199254740992 < a ? NaN : Number(a);
2198
+ a = new Date(1e3 * a);
2199
+ E[b >> 2] = a.getSeconds();
2200
+ E[b + 4 >> 2] = a.getMinutes();
2201
+ E[b + 8 >> 2] = a.getHours();
2202
+ E[b + 12 >> 2] = a.getDate();
2203
+ E[b + 16 >> 2] = a.getMonth();
2204
+ E[b + 20 >> 2] = a.getFullYear() - 1900;
2205
+ E[b + 24 >> 2] = a.getDay();
2206
+ var c = a.getFullYear();
2207
+ E[b + 28 >> 2] = (0 !== c % 4 || 0 === c % 100 && 0 !== c % 400 ? Mc : Lc)[a.getMonth()] + a.getDate() - 1 | 0;
2208
+ E[b + 36 >> 2] = -(60 * a.getTimezoneOffset());
2209
+ c = new Date(
2210
+ a.getFullYear(),
2211
+ 6,
2212
+ 1
2213
+ ).getTimezoneOffset();
2214
+ var d = new Date(a.getFullYear(), 0, 1).getTimezoneOffset();
2215
+ E[b + 32 >> 2] = (c != d && a.getTimezoneOffset() == Math.min(d, c)) | 0;
2216
+ }, y: function(a, b, c, d, e, h, k) {
2217
+ e = -9007199254740992 > e || 9007199254740992 < e ? NaN : Number(e);
2218
+ try {
2219
+ if (isNaN(e)) return 61;
2220
+ var q = T(d);
2221
+ if (0 !== (b & 2) && 0 === (c & 2) && 2 !== (q.flags & 2097155)) throw new N(2);
2222
+ if (1 === (q.flags & 2097155)) throw new N(2);
2223
+ if (!q.Ma.ib) throw new N(43);
2224
+ if (!a) throw new N(28);
2225
+ var w = q.Ma.ib(q, a, e, b, c);
2226
+ var v = w.Kb;
2227
+ E[h >> 2] = w.Ab;
2228
+ F[k >> 2] = v;
2229
+ return 0;
2230
+ } catch (C) {
2231
+ if ("undefined" == typeof W || "ErrnoError" !== C.name) throw C;
2232
+ return -C.Pa;
2233
+ }
2234
+ }, z: function(a, b, c, d, e, h) {
2235
+ h = -9007199254740992 > h || 9007199254740992 < h ? NaN : Number(h);
2236
+ try {
2237
+ var k = T(e);
2238
+ if (c & 2) {
2239
+ c = h;
2240
+ if (32768 !== (k.node.mode & 61440)) throw new N(43);
2241
+ if (!(d & 2)) {
2242
+ var q = x.slice(a, a + b);
2243
+ k.Ma.jb && k.Ma.jb(k, q, c, b, d);
2244
+ }
2245
+ }
2246
+ } catch (w) {
2247
+ if ("undefined" == typeof W || "ErrnoError" !== w.name) throw w;
2248
+ return -w.Pa;
2249
+ }
2250
+ }, n: (a, b) => {
2251
+ Nc[a] && (clearTimeout(Nc[a].id), delete Nc[a]);
2252
+ if (!b) return 0;
2253
+ var c = setTimeout(() => {
2254
+ delete Nc[a];
2255
+ Pc(() => Wc(a, performance.now()));
2256
+ }, b);
2257
+ Nc[a] = {
2258
+ id: c,
2259
+ Xb: b
2260
+ };
2261
+ return 0;
2262
+ }, B: (a, b, c, d) => {
2263
+ var e = (/* @__PURE__ */ new Date()).getFullYear(), h = new Date(e, 0, 1).getTimezoneOffset();
2264
+ e = new Date(e, 6, 1).getTimezoneOffset();
2265
+ F[a >> 2] = 60 * Math.max(h, e);
2266
+ E[b >> 2] = Number(h != e);
2267
+ b = (k) => {
2268
+ var q = Math.abs(k);
2269
+ return `UTC${0 <= k ? "-" : "+"}${String(Math.floor(q / 60)).padStart(2, "0")}${String(q % 60).padStart(2, "0")}`;
2270
+ };
2271
+ a = b(h);
2272
+ b = b(e);
2273
+ e < h ? (u(a, x, c, 17), u(b, x, d, 17)) : (u(a, x, d, 17), u(b, x, c, 17));
2274
+ }, d: () => Date.now(), s: () => 2147483648, c: () => performance.now(), o: (a) => {
2275
+ var b = x.length;
2276
+ a >>>= 0;
2277
+ if (2147483648 < a) return false;
2278
+ for (var c = 1; 4 >= c; c *= 2) {
2279
+ var d = b * (1 + 0.2 / c);
2280
+ d = Math.min(d, a + 100663296);
2281
+ a: {
2282
+ d = (Math.min(2147483648, 65536 * Math.ceil(Math.max(a, d) / 65536)) - Ka.buffer.byteLength + 65535) / 65536 | 0;
2283
+ try {
2284
+ Ka.grow(d);
2285
+ Qa();
2286
+ var e = 1;
2287
+ break a;
2288
+ } catch (h) {
2289
+ }
2290
+ e = void 0;
2291
+ }
2292
+ if (e) return true;
2293
+ }
2294
+ return false;
2295
+ }, E: (a, b) => {
2296
+ var c = 0;
2297
+ Sc().forEach((d, e) => {
2298
+ var h = b + c;
2299
+ e = F[a + 4 * e >> 2] = h;
2300
+ for (h = 0; h < d.length; ++h) p[e++] = d.charCodeAt(h);
2301
+ p[e] = 0;
2302
+ c += d.length + 1;
2303
+ });
2304
+ return 0;
2305
+ }, F: (a, b) => {
2306
+ var c = Sc();
2307
+ F[a >> 2] = c.length;
2308
+ var d = 0;
2309
+ c.forEach((e) => d += e.length + 1);
2310
+ F[b >> 2] = d;
2311
+ return 0;
2312
+ }, e: function(a) {
2313
+ try {
2314
+ var b = T(a);
2315
+ qa(b);
2316
+ return 0;
2317
+ } catch (c) {
2318
+ if ("undefined" == typeof W || "ErrnoError" !== c.name) throw c;
2319
+ return c.Pa;
2320
+ }
2321
+ }, p: function(a, b) {
2322
+ try {
2323
+ var c = T(a);
2324
+ p[b] = c.tty ? 2 : P(c.mode) ? 3 : 40960 === (c.mode & 61440) ? 7 : 4;
2325
+ Na[b + 2 >> 1] = 0;
2326
+ H[b + 8 >> 3] = BigInt(0);
2327
+ H[b + 16 >> 3] = BigInt(0);
2328
+ return 0;
2329
+ } catch (d) {
2330
+ if ("undefined" == typeof W || "ErrnoError" !== d.name) throw d;
2331
+ return d.Pa;
2332
+ }
2333
+ }, w: function(a, b, c, d) {
2334
+ try {
2335
+ a: {
2336
+ var e = T(a);
2337
+ a = b;
2338
+ for (var h, k = b = 0; k < c; k++) {
2339
+ var q = F[a >> 2], w = F[a + 4 >> 2];
2340
+ a += 8;
2341
+ var v = Ec(e, p, q, w, h);
2342
+ if (0 > v) {
2343
+ var C = -1;
2344
+ break a;
2345
+ }
2346
+ b += v;
2347
+ if (v < w) break;
2348
+ "undefined" != typeof h && (h += v);
2349
+ }
2350
+ C = b;
2351
+ }
2352
+ F[d >> 2] = C;
2353
+ return 0;
2354
+ } catch (G) {
2355
+ if ("undefined" == typeof W || "ErrnoError" !== G.name) throw G;
2356
+ return G.Pa;
2357
+ }
2358
+ }, D: function(a, b, c, d) {
2359
+ b = -9007199254740992 > b || 9007199254740992 < b ? NaN : Number(b);
2360
+ try {
2361
+ if (isNaN(b)) return 61;
2362
+ var e = T(a);
2363
+ mc(e, b, c);
2364
+ H[d >> 3] = BigInt(e.position);
2365
+ e.ob && 0 === b && 0 === c && (e.ob = null);
2366
+ return 0;
2367
+ } catch (h) {
2368
+ if ("undefined" == typeof W || "ErrnoError" !== h.name) throw h;
2369
+ return h.Pa;
2370
+ }
2371
+ }, I: function(a) {
2372
+ try {
2373
+ var b = T(a);
2374
+ return b.Ma?.fsync ? b.Ma.fsync(b) : 0;
2375
+ } catch (c) {
2376
+ if ("undefined" == typeof W || "ErrnoError" !== c.name) throw c;
2377
+ return c.Pa;
2378
+ }
2379
+ }, t: function(a, b, c, d) {
2380
+ try {
2381
+ a: {
2382
+ var e = T(a);
2383
+ a = b;
2384
+ for (var h, k = b = 0; k < c; k++) {
2385
+ var q = F[a >> 2], w = F[a + 4 >> 2];
2386
+ a += 8;
2387
+ var v = pa(e, p, q, w, h);
2388
+ if (0 > v) {
2389
+ var C = -1;
2390
+ break a;
2391
+ }
2392
+ b += v;
2393
+ if (v < w) break;
2394
+ "undefined" != typeof h && (h += v);
2395
+ }
2396
+ C = b;
2397
+ }
2398
+ F[d >> 2] = C;
2399
+ return 0;
2400
+ } catch (G) {
2401
+ if ("undefined" == typeof W || "ErrnoError" !== G.name) throw G;
2402
+ return G.Pa;
2403
+ }
2404
+ }, k: Oc }, Z;
2405
+ (async function() {
2406
+ function a(c) {
2407
+ Z = c.exports;
2408
+ Ka = Z.M;
2409
+ Qa();
2410
+ Y = Z.O;
2411
+ K--;
2412
+ f.monitorRunDependencies?.(K);
2413
+ 0 == K && Sa && (c = Sa, Sa = null, c());
2414
+ return Z;
2415
+ }
2416
+ K++;
2417
+ f.monitorRunDependencies?.(K);
2418
+ var b = { a: Xc };
2419
+ if (f.instantiateWasm) return new Promise((c) => {
2420
+ f.instantiateWasm(b, (d, e) => {
2421
+ a(d);
2422
+ c(d.exports);
2423
+ });
2424
+ });
2425
+ Ua ??= f.locateFile ? f.locateFile("sql-wasm.wasm", D) : D + "sql-wasm.wasm";
2426
+ return a((await Xa(b)).instance);
2427
+ })();
2428
+ f._sqlite3_free = (a) => (f._sqlite3_free = Z.P)(a);
2429
+ f._sqlite3_value_text = (a) => (f._sqlite3_value_text = Z.Q)(a);
2430
+ f._sqlite3_prepare_v2 = (a, b, c, d, e) => (f._sqlite3_prepare_v2 = Z.R)(a, b, c, d, e);
2431
+ f._sqlite3_step = (a) => (f._sqlite3_step = Z.S)(a);
2432
+ f._sqlite3_reset = (a) => (f._sqlite3_reset = Z.T)(a);
2433
+ f._sqlite3_exec = (a, b, c, d, e) => (f._sqlite3_exec = Z.U)(a, b, c, d, e);
2434
+ f._sqlite3_finalize = (a) => (f._sqlite3_finalize = Z.V)(a);
2435
+ f._sqlite3_column_name = (a, b) => (f._sqlite3_column_name = Z.W)(a, b);
2436
+ f._sqlite3_column_text = (a, b) => (f._sqlite3_column_text = Z.X)(a, b);
2437
+ f._sqlite3_column_type = (a, b) => (f._sqlite3_column_type = Z.Y)(a, b);
2438
+ f._sqlite3_errmsg = (a) => (f._sqlite3_errmsg = Z.Z)(a);
2439
+ f._sqlite3_clear_bindings = (a) => (f._sqlite3_clear_bindings = Z._)(a);
2440
+ f._sqlite3_value_blob = (a) => (f._sqlite3_value_blob = Z.$)(a);
2441
+ f._sqlite3_value_bytes = (a) => (f._sqlite3_value_bytes = Z.aa)(a);
2442
+ f._sqlite3_value_double = (a) => (f._sqlite3_value_double = Z.ba)(a);
2443
+ f._sqlite3_value_int = (a) => (f._sqlite3_value_int = Z.ca)(a);
2444
+ f._sqlite3_value_type = (a) => (f._sqlite3_value_type = Z.da)(a);
2445
+ f._sqlite3_result_blob = (a, b, c, d) => (f._sqlite3_result_blob = Z.ea)(a, b, c, d);
2446
+ f._sqlite3_result_double = (a, b) => (f._sqlite3_result_double = Z.fa)(a, b);
2447
+ f._sqlite3_result_error = (a, b, c) => (f._sqlite3_result_error = Z.ga)(a, b, c);
2448
+ f._sqlite3_result_int = (a, b) => (f._sqlite3_result_int = Z.ha)(a, b);
2449
+ f._sqlite3_result_int64 = (a, b) => (f._sqlite3_result_int64 = Z.ia)(a, b);
2450
+ f._sqlite3_result_null = (a) => (f._sqlite3_result_null = Z.ja)(a);
2451
+ f._sqlite3_result_text = (a, b, c, d) => (f._sqlite3_result_text = Z.ka)(a, b, c, d);
2452
+ f._sqlite3_aggregate_context = (a, b) => (f._sqlite3_aggregate_context = Z.la)(a, b);
2453
+ f._sqlite3_column_count = (a) => (f._sqlite3_column_count = Z.ma)(a);
2454
+ f._sqlite3_data_count = (a) => (f._sqlite3_data_count = Z.na)(a);
2455
+ f._sqlite3_column_blob = (a, b) => (f._sqlite3_column_blob = Z.oa)(a, b);
2456
+ f._sqlite3_column_bytes = (a, b) => (f._sqlite3_column_bytes = Z.pa)(a, b);
2457
+ f._sqlite3_column_double = (a, b) => (f._sqlite3_column_double = Z.qa)(a, b);
2458
+ f._sqlite3_bind_blob = (a, b, c, d, e) => (f._sqlite3_bind_blob = Z.ra)(a, b, c, d, e);
2459
+ f._sqlite3_bind_double = (a, b, c) => (f._sqlite3_bind_double = Z.sa)(a, b, c);
2460
+ f._sqlite3_bind_int = (a, b, c) => (f._sqlite3_bind_int = Z.ta)(a, b, c);
2461
+ f._sqlite3_bind_text = (a, b, c, d, e) => (f._sqlite3_bind_text = Z.ua)(a, b, c, d, e);
2462
+ f._sqlite3_bind_parameter_index = (a, b) => (f._sqlite3_bind_parameter_index = Z.va)(a, b);
2463
+ f._sqlite3_sql = (a) => (f._sqlite3_sql = Z.wa)(a);
2464
+ f._sqlite3_normalized_sql = (a) => (f._sqlite3_normalized_sql = Z.xa)(a);
2465
+ f._sqlite3_changes = (a) => (f._sqlite3_changes = Z.ya)(a);
2466
+ f._sqlite3_close_v2 = (a) => (f._sqlite3_close_v2 = Z.za)(a);
2467
+ f._sqlite3_create_function_v2 = (a, b, c, d, e, h, k, q, w) => (f._sqlite3_create_function_v2 = Z.Aa)(a, b, c, d, e, h, k, q, w);
2468
+ f._sqlite3_update_hook = (a, b, c) => (f._sqlite3_update_hook = Z.Ba)(a, b, c);
2469
+ f._sqlite3_open = (a, b) => (f._sqlite3_open = Z.Ca)(a, b);
2470
+ var ia = f._malloc = (a) => (ia = f._malloc = Z.Da)(a), fa = f._free = (a) => (fa = f._free = Z.Ea)(a);
2471
+ f._RegisterExtensionFunctions = (a) => (f._RegisterExtensionFunctions = Z.Fa)(a);
2472
+ var Db = (a, b) => (Db = Z.Ga)(a, b), Wc = (a, b) => (Wc = Z.Ha)(a, b), wa = (a) => (wa = Z.Ia)(a), z = (a) => (z = Z.Ja)(a), sa = () => (sa = Z.Ka)();
2473
+ f.stackSave = () => sa();
2474
+ f.stackRestore = (a) => wa(a);
2475
+ f.stackAlloc = (a) => z(a);
2476
+ f.cwrap = (a, b, c, d) => {
2477
+ var e = !c || c.every((h) => "number" === h || "boolean" === h);
2478
+ return "string" !== b && e && !d ? f["_" + a] : (...h) => Tc(a, b, c, h);
2479
+ };
2480
+ f.addFunction = Aa;
2481
+ f.removeFunction = A;
2482
+ f.UTF8ToString = ua;
2483
+ f.ALLOC_NORMAL = ea;
2484
+ f.allocate = da;
2485
+ f.allocateUTF8OnStack = xa;
2486
+ function Yc() {
2487
+ function a() {
2488
+ f.calledRun = true;
2489
+ if (!La) {
2490
+ if (!f.noFSInit && !Ib) {
2491
+ var b, c;
2492
+ Ib = true;
2493
+ d ??= f.stdin;
2494
+ b ??= f.stdout;
2495
+ c ??= f.stderr;
2496
+ d ? V("stdin", d) : Zb("/dev/tty", "/dev/stdin");
2497
+ b ? V("stdout", null, b) : Zb("/dev/tty", "/dev/stdout");
2498
+ c ? V("stderr", null, c) : Zb("/dev/tty1", "/dev/stderr");
2499
+ oa("/dev/stdin", 0);
2500
+ oa("/dev/stdout", 1);
2501
+ oa("/dev/stderr", 1);
2502
+ }
2503
+ Z.N();
2504
+ Jb = false;
2505
+ f.onRuntimeInitialized?.();
2506
+ if (f.postRun) for ("function" == typeof f.postRun && (f.postRun = [f.postRun]); f.postRun.length; ) {
2507
+ var d = f.postRun.shift();
2508
+ $a.unshift(d);
2509
+ }
2510
+ Za($a);
2511
+ }
2512
+ }
2513
+ if (0 < K) Sa = Yc;
2514
+ else {
2515
+ if (f.preRun) for ("function" == typeof f.preRun && (f.preRun = [f.preRun]); f.preRun.length; ) bb();
2516
+ Za(ab);
2517
+ 0 < K ? Sa = Yc : f.setStatus ? (f.setStatus("Running..."), setTimeout(() => {
2518
+ setTimeout(() => f.setStatus(""), 1);
2519
+ a();
2520
+ }, 1)) : a();
2521
+ }
2522
+ }
2523
+ if (f.preInit) for ("function" == typeof f.preInit && (f.preInit = [f.preInit]); 0 < f.preInit.length; ) f.preInit.pop()();
2524
+ Yc();
2525
+ return Module;
2526
+ });
2527
+ return initSqlJsPromise;
2528
+ };
2529
+ {
2530
+ module.exports = initSqlJs2;
2531
+ module.exports.default = initSqlJs2;
2532
+ }
2533
+ })(sqlWasm);
2534
+ return sqlWasm.exports;
2535
+ }
2536
+ var sqlWasmExports = requireSqlWasm();
2537
+ const initSqlJs = /* @__PURE__ */ getDefaultExportFromCjs(sqlWasmExports);
2538
+ class SqlStatements {
2539
+ _map = new IoDbNameMapping();
2540
+ /**
2541
+ * Converts a JSON value type to an SQLite data type.
2542
+ * @param dataType - The JSON value type to convert.
2543
+ * @returns - The corresponding SQLite data type.
2544
+ */
2545
+ jsonToSqlType(dataType) {
2546
+ switch (dataType) {
2547
+ case "string":
2548
+ return "TEXT";
2549
+ case "jsonArray":
2550
+ return "TEXT";
2551
+ case "json":
2552
+ return "TEXT";
2553
+ case "number":
2554
+ return "REAL";
2555
+ case "boolean":
2556
+ return "INTEGER";
2557
+ case "jsonValue":
2558
+ return "TEXT";
2559
+ }
2560
+ }
2561
+ get tableKey() {
2562
+ return `SELECT name FROM sqlite_master WHERE type='table' AND name=?`;
2563
+ }
2564
+ get tableKeys() {
2565
+ return `SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'`;
2566
+ }
2567
+ rowCount(tableKey) {
2568
+ return `SELECT COUNT(*) FROM ${this._map.addTableSuffix(tableKey)}`;
2569
+ }
2570
+ allData(tableKey, namedColumns) {
2571
+ if (!namedColumns) {
2572
+ namedColumns = `*`;
2573
+ }
2574
+ return `SELECT ${namedColumns} FROM ${tableKey}`;
2575
+ }
2576
+ get tableCfg() {
2577
+ return `SELECT * FROM ${this._map.addTableSuffix(
2578
+ this._map.tableNames.main
2579
+ )} WHERE ${this._map.addColumnSuffix("key")} = ?`;
2580
+ }
2581
+ get tableCfgs() {
2582
+ return `SELECT * FROM ${this._map.addTableSuffix(
2583
+ this._map.tableNames.main
2584
+ )}`;
2585
+ }
2586
+ /* v8 ignore next -- @preserve */
2587
+ get currentTableCfg() {
2588
+ const sql = [
2589
+ "WITH versions AS (",
2590
+ " SELECT _hash_col, key_col, MAX(json_each.key) AS max_val",
2591
+ " FROM tableCfgs_tbl, json_each(columns_col)",
2592
+ " WHERE json_each.value IS NOT NULL",
2593
+ " AND key_col = ? GROUP BY _hash_col, key_col)",
2594
+ "SELECT * FROM tableCfgs_tbl tt",
2595
+ " LEFT JOIN versions ON tt._hash_col = versions._hash_col",
2596
+ " WHERE versions.max_val = (SELECT MAX(max_val) FROM versions);"
2597
+ ];
2598
+ return sql.join("\n");
2599
+ }
2600
+ get currentTableCfgs() {
2601
+ const sql = [
2602
+ "SELECT",
2603
+ " *",
2604
+ "FROM",
2605
+ " tableCfgs_tbl",
2606
+ "WHERE",
2607
+ " _hash_col IN (",
2608
+ " WITH",
2609
+ " column_count AS (",
2610
+ " SELECT",
2611
+ " _hash_col,",
2612
+ " key_col,",
2613
+ " MAX(json_each.key) AS max_val",
2614
+ " FROM",
2615
+ " tableCfgs_tbl,",
2616
+ " json_each (columns_col)",
2617
+ " WHERE",
2618
+ " json_each.value IS NOT NULL",
2619
+ " GROUP BY",
2620
+ " _hash_col,",
2621
+ " key_col",
2622
+ " ),",
2623
+ " max_tables AS (",
2624
+ " SELECT",
2625
+ " key_col,",
2626
+ " MAX(max_val) AS newest",
2627
+ " FROM",
2628
+ " column_count",
2629
+ " GROUP BY",
2630
+ " key_col",
2631
+ " )",
2632
+ " SELECT",
2633
+ " cc._hash_col",
2634
+ " FROM",
2635
+ " column_count cc",
2636
+ " LEFT JOIN max_tables mt ON cc.key_col = mt.key_col",
2637
+ " AND cc.max_val = mt.newest",
2638
+ " WHERE",
2639
+ " mt.newest IS NOT NULL",
2640
+ " );"
2641
+ ];
2642
+ return sql.join("\n");
2643
+ }
2644
+ get articleExists() {
2645
+ return "SELECT cl.layer, ar.assign FROM catalogLayers cl\nLEFT JOIN articleSets ar\nON cl.articleSetsRef = ar._hash\nWHERE cl.winNumber = ? ";
2646
+ }
2647
+ get catalogExists() {
2648
+ return "SELECT 1 FROM catalogLayers WHERE winNumber = ?";
2649
+ }
2650
+ contentType() {
2651
+ const sourceTable = this._map.addTableSuffix(this._map.tableNames.main);
2652
+ const resultCol = this._map.addColumnSuffix("type");
2653
+ const sql = `SELECT ${resultCol} FROM [${sourceTable}] WHERE key_col =?`;
2654
+ return sql;
2655
+ }
2656
+ insertTableCfg() {
2657
+ const columnKeys = IoTools.tableCfgsTableCfg.columns.map((col) => col.key);
2658
+ const columnKeysWithPostfix = columnKeys.map(
2659
+ (col) => this._map.addColumnSuffix(col)
2660
+ );
2661
+ const columnsSql = columnKeysWithPostfix.join(", ");
2662
+ const valuesSql = "?, ".repeat(columnKeys.length - 1) + "?";
2663
+ return `INSERT INTO ${this._map.addTableSuffix(
2664
+ this._map.tableNames.main
2665
+ )} ( ${columnsSql} ) VALUES (${valuesSql})`;
2666
+ }
2667
+ tableExists() {
2668
+ return `SELECT name FROM sqlite_master WHERE type='table' AND name=?;`;
2669
+ }
2670
+ get tableType() {
2671
+ return `SELECT ${this._map.addColumnSuffix(
2672
+ "type"
2673
+ )} AS type FROM ${this._map.addTableSuffix(this._map.tableNames.main)}
2674
+ WHERE ${this._map.addColumnSuffix("key")} = ?
2675
+ AND ${this._map.addColumnSuffix("version")}
2676
+ = (SELECT MAX(${this._map.addColumnSuffix("version")})
2677
+ FROM ${this._map.addTableSuffix(this._map.tableNames.main)}
2678
+ WHERE ${this._map.addColumnSuffix("key")} = ?)`;
2679
+ }
2680
+ columnKeys(tableKey) {
2681
+ return `PRAGMA table_info(${tableKey})`;
2682
+ }
2683
+ createFullTable(tableKey, columnsDefinition, foreignKeys) {
2684
+ return `CREATE TABLE ${tableKey} (${columnsDefinition}, ${foreignKeys})`;
2685
+ }
2686
+ dropTable(tableKey) {
2687
+ return `DROP TABLE IF EXISTS ${this._map.addTableSuffix(tableKey)}`;
2688
+ }
2689
+ createTempTable(tableKey) {
2690
+ return `CREATE TABLE ${this._map.addTmpSuffix(
2691
+ tableKey
2692
+ )} AS SELECT * FROM ${this._map.addTableSuffix(tableKey)}`;
2693
+ }
2694
+ dropTempTable(tableKey) {
2695
+ return `DROP TABLE IF EXISTS ${this._map.addTmpSuffix(tableKey)}`;
2696
+ }
2697
+ fillTable(tableKey, commonColumns) {
2698
+ return `INSERT INTO ${this._map.addTableSuffix(
2699
+ tableKey
2700
+ )} (${commonColumns}) SELECT ${commonColumns} FROM ${this._map.addTmpSuffix(
2701
+ tableKey
2702
+ )}`;
2703
+ }
2704
+ deleteFromTable(tableKey, winNumber) {
2705
+ return `DELETE FROM ${tableKey} WHERE winNumber = '${winNumber}'`;
2706
+ }
2707
+ addColumn(tableKey, columnName, columnType) {
2708
+ return `ALTER TABLE ${tableKey} ADD COLUMN ${columnName} ${columnType}`;
2709
+ }
2710
+ selection(tableKey, columns, whereClause) {
2711
+ return `SELECT ${columns} FROM ${tableKey} WHERE ${whereClause}`;
2712
+ }
2713
+ articleSetsRefs(winNumber) {
2714
+ return `SELECT layer, articleSetsRef FROM catalogLayers WHERE winNumber = '${winNumber}'`;
2715
+ }
2716
+ currentCount(tableKey) {
2717
+ return `SELECT COUNT(*) FROM ${this._map.addTableSuffix(tableKey)}`;
2718
+ }
2719
+ createTable(tableCfg) {
2720
+ const sqltableKey = this._map.addTableSuffix(tableCfg.key);
2721
+ const columnsCfg = tableCfg.columns;
2722
+ const sqlCreateColumns = columnsCfg.map((col) => {
2723
+ const sqliteType = this.jsonToSqlType(col.type);
2724
+ return `${this._map.addColumnSuffix(col.key)} ${sqliteType}`;
2725
+ }).join(", ");
2726
+ const conKey = `${this._map.addColumnSuffix(
2727
+ this._map.primaryKeyColumn
2728
+ )} TEXT`;
2729
+ const primaryKey = `${conKey} PRIMARY KEY`;
2730
+ const colsWithPrimaryKey = sqlCreateColumns.replace(conKey, primaryKey);
2731
+ return `CREATE TABLE ${sqltableKey} (${colsWithPrimaryKey})`;
2732
+ }
2733
+ alterTable(tableKey, addedColumns) {
2734
+ const tableKeyWithSuffix = this._map.addTableSuffix(tableKey);
2735
+ const statements = [];
2736
+ for (const col of addedColumns) {
2737
+ const columnKey = this._map.addColumnSuffix(col.key);
2738
+ const columnType = this.jsonToSqlType(col.type);
2739
+ statements.push(
2740
+ `ALTER TABLE ${tableKeyWithSuffix} ADD COLUMN ${columnKey} ${columnType};`
2741
+ );
2742
+ }
2743
+ return statements;
2744
+ }
2745
+ get createTableCfgsTable() {
2746
+ return this.createTable(IoTools.tableCfgsTableCfg);
2747
+ }
2748
+ get tableTypeCheck() {
2749
+ return `SELECT ${this._map.addColumnSuffix(
2750
+ "type"
2751
+ )} FROM ${this._map.addTableSuffix(
2752
+ this._map.tableNames.main
2753
+ )} WHERE ${this._map.addColumnSuffix("key")} = ?`;
2754
+ }
2755
+ }
2756
+ const SQL = await initSqlJs();
2757
+ class IoSqlite {
2758
+ _ioTools;
2759
+ _isReady = new IsReady();
2760
+ _sql;
2761
+ _map = new IoDbNameMapping();
2762
+ constructor() {
2763
+ this._sql = new SqlStatements();
2764
+ }
2765
+ async init() {
2766
+ this.db = new SQL.Database();
2767
+ this._isOpen = true;
2768
+ this._ioTools = new IoTools(this);
2769
+ this._initTableCfgs();
2770
+ await this._ioTools.initRevisionsTable();
2771
+ this._isReady.resolve();
2772
+ }
2773
+ db;
2774
+ /**
2775
+ * Returns an example database
2776
+ */
2777
+ static example = async () => {
2778
+ const ioSqlite = new IoSqlite();
2779
+ await ioSqlite.init();
2780
+ return ioSqlite;
2781
+ };
2782
+ async contentType(request) {
2783
+ const result = this.db.prepare(this._sql.contentType()).get([request.table]);
2784
+ return result[0];
2785
+ }
2786
+ async deleteDatabase() {
2787
+ this.db.close();
2788
+ }
2789
+ // ...........................................................................
2790
+ // General
2791
+ isReady() {
2792
+ return this._isReady.promise;
2793
+ }
2794
+ // ...........................................................................
2795
+ // Dump (export all data from database)
2796
+ dump() {
2797
+ return this._dump();
2798
+ }
2799
+ dumpTable(request) {
2800
+ return this._dumpTable(request);
2801
+ }
2802
+ // ...........................................................................
2803
+ // Rows
2804
+ readRows(request) {
2805
+ return this._readRows(request);
2806
+ }
2807
+ async rowCount(table) {
2808
+ await this._ioTools.throwWhenTableDoesNotExist(table);
2809
+ const stmt = this.db.exec(this._sql.rowCount(table));
2810
+ const countRaw = stmt[0]?.values?.[0]?.[0] ?? 0;
2811
+ const count = Number(countRaw);
2812
+ return count;
2813
+ }
2814
+ // ...........................................................................
2815
+ async tableExists(tableKey) {
2816
+ return this._tableExists(tableKey);
2817
+ }
2818
+ // ...........................................................................
2819
+ async rawTableCfgs() {
2820
+ const tableCfg = IoTools.tableCfgsTableCfg;
2821
+ const result = this.db.exec(this._sql.tableCfgs);
2822
+ const rows = result[0]?.values;
2823
+ const columns = result[0]?.columns;
2824
+ const jsonRows = rows.map((row) => {
2825
+ const obj = {};
2826
+ columns.forEach((col, idx) => {
2827
+ obj[col] = row[idx];
2828
+ });
2829
+ return obj;
2830
+ });
2831
+ const returnValue = jsonRows;
2832
+ const parsedReturnValue = this._parseData(returnValue, tableCfg);
2833
+ return parsedReturnValue;
2834
+ }
2835
+ async alltableKeys() {
2836
+ const returnValue = this.db.exec(this._sql.tableKeys)[0].values;
2837
+ const returnValueStr = returnValue.map((row) => String(row[0]));
2838
+ console.log("Extracted table keys:", returnValueStr);
2839
+ const tableKeys = returnValueStr.map(
2840
+ (key) => this._map.removeTableSuffix(key)
2841
+ );
2842
+ return tableKeys;
2843
+ }
2844
+ // ...........................................................................
2845
+ // Write data into the respective table
2846
+ async write(request) {
2847
+ await this._write(request);
2848
+ }
2849
+ async createOrExtendTable(request) {
2850
+ return this._createOrExtendTable(request);
2851
+ }
2852
+ // ######################
2853
+ // Private
2854
+ // ######################
2855
+ // ...........................................................................
2856
+ _initTableCfgs = () => {
2857
+ const tableCfg = IoTools.tableCfgsTableCfg;
2858
+ this.db.prepare(this._sql.createTable(tableCfg)).run();
2859
+ const values = this._serializeRow(tableCfg, tableCfg);
2860
+ const p = this.db.prepare(this._sql.insertTableCfg());
2861
+ p.run(values);
2862
+ };
2863
+ // ...........................................................................
2864
+ async _createOrExtendTable(request) {
2865
+ await this._ioTools.throwWhenTableIsNotCompatible(request.tableCfg);
2866
+ const tableKey = request.tableCfg.key;
2867
+ const tableCfgHashed = hsh(request.tableCfg);
2868
+ const stmt = this.db.prepare(this._sql.tableCfg);
2869
+ const exists = stmt.get([tableKey]);
2870
+ if (exists.length === 0) {
2871
+ this._createTable(tableCfgHashed, request);
2872
+ } else {
2873
+ await this._extendTable(tableCfgHashed);
2874
+ }
2875
+ stmt.free();
2876
+ }
2877
+ // ...........................................................................
2878
+ _createTable(tableCfgHashed, request) {
2879
+ this._insertTableCfg(tableCfgHashed);
2880
+ this.db.exec(this._sql.createTable(request.tableCfg));
2881
+ }
2882
+ // ...........................................................................
2883
+ _insertTableCfg(tableCfgHashed) {
2884
+ hip(tableCfgHashed);
2885
+ const values = this._serializeRow(
2886
+ tableCfgHashed,
2887
+ IoTools.tableCfgsTableCfg
2888
+ );
2889
+ const p = this.db.prepare(this._sql.insertTableCfg());
2890
+ p.run(values);
2891
+ }
2892
+ // ...........................................................................
2893
+ _addMissingHashes(rljson) {
2894
+ hip(rljson, { updateExistingHashes: false, throwOnWrongHashes: false });
2895
+ }
2896
+ // ...........................................................................
2897
+ async _extendTable(newTableCfg) {
2898
+ const tableKey = newTableCfg.key;
2899
+ const oldTableCfg = await this._ioTools.tableCfg(tableKey);
2900
+ const addedColumns = [];
2901
+ for (let i = oldTableCfg.columns.length; i < newTableCfg.columns.length; i++) {
2902
+ const newColumn = newTableCfg.columns[i];
2903
+ addedColumns.push(newColumn);
2904
+ }
2905
+ if (addedColumns.length === 0) {
2906
+ return;
2907
+ }
2908
+ this._insertTableCfg(newTableCfg);
2909
+ const alter = this._sql.alterTable(tableKey, addedColumns);
2910
+ for (const statement of alter) {
2911
+ this.db.prepare(statement).run();
2912
+ }
2913
+ }
2914
+ // ...........................................................................
2915
+ async _readRows(request) {
2916
+ await this._ioTools.throwWhenTableDoesNotExist(request.table);
2917
+ await this._ioTools.throwWhenColumnDoesNotExist(request.table, [
2918
+ ...Object.keys(request.where)
2919
+ ]);
2920
+ const tableKeyWithSuffix = this._map.addTableSuffix(request.table);
2921
+ const tableCfg = await this._ioTools.tableCfg(request.table);
2922
+ const whereString = this._whereString(Object.entries(request.where));
2923
+ const query = `SELECT * FROM ${tableKeyWithSuffix} WHERE${whereString}`;
2924
+ const returnValue = this.db.exec(query);
2925
+ const rows = returnValue[0]?.values || [];
2926
+ const columns = returnValue[0]?.columns || [];
2927
+ const jsonRows = rows.map((row) => {
2928
+ const obj = {};
2929
+ columns.forEach((col, idx) => {
2930
+ obj[col] = row[idx];
2931
+ });
2932
+ return obj;
2933
+ });
2934
+ const convertedResult = this._parseData(jsonRows, tableCfg);
2935
+ const table = {
2936
+ _data: convertedResult,
2937
+ _type: tableCfg.type
2938
+ };
2939
+ this._ioTools.sortTableDataAndUpdateHash(table);
2940
+ const result = {
2941
+ [request.table]: table
2942
+ };
2943
+ return result;
2944
+ }
2945
+ // ...........................................................................
2946
+ _serializeRow(rowAsJson, tableCfg) {
2947
+ const result = [];
2948
+ for (const col of tableCfg.columns) {
2949
+ const key = col.key;
2950
+ let value = rowAsJson[key] ?? null;
2951
+ const valueType = typeof value;
2952
+ if (value !== null && valueType === "object") {
2953
+ value = JSON.stringify(value);
2954
+ } else if (valueType === "boolean") {
2955
+ value = value ? 1 : 0;
2956
+ }
2957
+ result.push(value);
2958
+ }
2959
+ return result;
2960
+ }
2961
+ _parseData(data, tableCfg) {
2962
+ const columnTypes = tableCfg.columns.map((col) => col.type);
2963
+ const columnKeys = tableCfg.columns.map((col) => col.key);
2964
+ const convertedResult = [];
2965
+ for (const row of data) {
2966
+ const convertedRow = {};
2967
+ for (let colNum = 0; colNum < columnKeys.length; colNum++) {
2968
+ const key = columnKeys[colNum];
2969
+ const keyWithSuffix = this._map.addColumnSuffix(key);
2970
+ const type = columnTypes[colNum];
2971
+ const val = row[keyWithSuffix];
2972
+ if (val === void 0) {
2973
+ continue;
2974
+ }
2975
+ if (val === null) {
2976
+ continue;
2977
+ }
2978
+ switch (type) {
2979
+ case "boolean":
2980
+ convertedRow[key] = val !== 0;
2981
+ break;
2982
+ case "jsonArray":
2983
+ case "json":
2984
+ convertedRow[key] = JSON.parse(val);
2985
+ break;
2986
+ case "string":
2987
+ case "number":
2988
+ convertedRow[key] = val;
2989
+ break;
2990
+ /* v8 ignore next -- @preserve */
2991
+ default:
2992
+ throw new Error("Unsupported column type " + type);
2993
+ }
2994
+ }
2995
+ convertedResult.push(convertedRow);
2996
+ }
2997
+ return convertedResult;
2998
+ }
2999
+ parseDataTest(data, tableCfg) {
3000
+ return this._parseData(data, tableCfg);
3001
+ }
3002
+ // ...........................................................................
3003
+ async _dump() {
3004
+ const returnFile = {};
3005
+ const result = this.db.exec(this._sql.tableKeys);
3006
+ const tableNames = result[0]?.values?.map((row) => row[0]);
3007
+ for (const table of tableNames) {
3008
+ const tableDump = await this._dumpTable({
3009
+ table: this._map.removeTableSuffix(table)
3010
+ });
3011
+ returnFile[this._map.removeTableSuffix(table)] = tableDump[this._map.removeTableSuffix(table)];
3012
+ }
3013
+ this._addMissingHashes(returnFile);
3014
+ return returnFile;
3015
+ }
3016
+ // ...........................................................................
3017
+ async _dumpTable(request) {
3018
+ await this._ioTools.throwWhenTableDoesNotExist(request.table);
3019
+ const tableKey = this._map.addTableSuffix(request.table);
3020
+ const tableCfg = await this._ioTools.tableCfg(request.table);
3021
+ const columnKeys = tableCfg.columns.map((col) => col.key);
3022
+ const columnKeysWithSuffix = columnKeys.map(
3023
+ (col) => this._map.addColumnSuffix(col)
3024
+ );
3025
+ const result = this.db.exec(
3026
+ this._sql.allData(tableKey, columnKeysWithSuffix.join(", "))
3027
+ );
3028
+ const rows = result[0]?.values || [];
3029
+ const columns = result[0]?.columns || [];
3030
+ const jsonRows = rows.map((row) => {
3031
+ const obj = {};
3032
+ columns.forEach((col, idx) => {
3033
+ obj[col] = row[idx];
3034
+ });
3035
+ return obj;
3036
+ });
3037
+ const parsedReturnData = this._parseData(jsonRows, tableCfg);
3038
+ const tableCfgHash = tableCfg._hash;
3039
+ const table = {
3040
+ _type: tableCfg.type,
3041
+ _data: parsedReturnData,
3042
+ _tableCfg: tableCfgHash,
3043
+ _hash: ""
3044
+ };
3045
+ this._ioTools.sortTableDataAndUpdateHash(table);
3046
+ const returnFile = {};
3047
+ returnFile[request.table] = table;
3048
+ return returnFile;
3049
+ }
3050
+ // ...........................................................................
3051
+ async _write(request) {
3052
+ const hashedData = hsh(request.data);
3053
+ const errorStore = /* @__PURE__ */ new Map();
3054
+ let errorCount = 0;
3055
+ await this._ioTools.throwWhenTablesDoNotExist(request.data);
3056
+ await this._ioTools.throwWhenTableDataDoesNotMatchCfg(request.data);
3057
+ await iterateTables(hashedData, async (tableName, tableData) => {
3058
+ const tableCfg = await this._ioTools.tableCfg(tableName);
3059
+ const tableKeyWithSuffix = this._map.addTableSuffix(tableName);
3060
+ for (const row of tableData._data) {
3061
+ const columnKeys = tableCfg.columns.map((col) => col.key);
3062
+ const columnKeysWithPostfix = columnKeys.map(
3063
+ (column) => this._map.addColumnSuffix(column)
3064
+ );
3065
+ const placeholders = columnKeys.map(() => "?").join(", ");
3066
+ const query = `INSERT OR IGNORE INTO ${tableKeyWithSuffix} (${columnKeysWithPostfix.join(
3067
+ ", "
3068
+ )}) VALUES (${placeholders})`;
3069
+ const serializedRow = this._serializeRow(row, tableCfg);
3070
+ try {
3071
+ this.db.prepare(query).run(serializedRow);
3072
+ } catch (error) {
3073
+ if (error.code === "SQLITE_CONSTRAINT_PRIMARYKEY") {
3074
+ return;
3075
+ }
3076
+ const errorMessage = error instanceof Error ? error.message : "Unknown error";
3077
+ errorCount++;
3078
+ errorStore.set(
3079
+ errorCount,
3080
+ `Error inserting into table ${tableName}: ${errorMessage}`
3081
+ );
3082
+ }
3083
+ }
3084
+ });
3085
+ if (errorCount > 0) {
3086
+ const errorMessages = Array.from(errorStore.values()).join(", ");
3087
+ throw new Error(`Errors occurred: ${errorMessages}`);
3088
+ }
3089
+ }
3090
+ async _tableExists(tableKey) {
3091
+ const tableKeyWithSuffix = this._map.addTableSuffix(tableKey);
3092
+ const result = this.db.prepare(this._sql.tableExists()).get([tableKeyWithSuffix]);
3093
+ return result[0] === tableKeyWithSuffix ? true : false;
3094
+ }
3095
+ _whereString(whereClause) {
3096
+ let whereString = " ";
3097
+ for (const [column, value] of whereClause) {
3098
+ const columnWithFix = this._map.addColumnSuffix(column);
3099
+ if (typeof value === "string") {
3100
+ whereString += `${columnWithFix} = '${value}' AND `;
3101
+ } else if (typeof value === "number") {
3102
+ whereString += `${columnWithFix} = ${value} AND `;
3103
+ } else if (typeof value === "boolean") {
3104
+ whereString += `${columnWithFix} = ${value ? 1 : 0} AND `;
3105
+ } else if (value === null) {
3106
+ whereString += `${columnWithFix} IS NULL AND `;
3107
+ } else if (typeof value === "object") {
3108
+ whereString += `${columnWithFix} = '${JSON.stringify(value)}' AND `;
3109
+ } else {
3110
+ throw new Error(`Unsupported value type for column ${column}`);
3111
+ }
3112
+ }
3113
+ whereString = whereString.endsWith("AND ") ? whereString.slice(0, -5) : whereString;
3114
+ return whereString;
3115
+ }
3116
+ _isOpen = false;
3117
+ get isOpen() {
3118
+ return this._isOpen;
3119
+ }
3120
+ async close() {
3121
+ this._isOpen = false;
3122
+ this.db.close();
3123
+ }
3124
+ }
3125
+ export {
3126
+ IoSqlite,
3127
+ SqlStatements
3128
+ };