cc-dejavu 0.3.0 → 0.4.1

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