@polka-codes/cli-shared 0.9.89 → 0.9.90

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 (2) hide show
  1. package/dist/index.js +2900 -1036
  2. package/package.json +3 -4
package/dist/index.js CHANGED
@@ -9179,8 +9179,8 @@ var require_retry = __commonJS((exports) => {
9179
9179
  }
9180
9180
  const delay2 = getNextRetryDelay(config3);
9181
9181
  err.config.retryConfig.currentRetryAttempt += 1;
9182
- const backoff2 = config3.retryBackoff ? config3.retryBackoff(err, delay2) : new Promise((resolve2) => {
9183
- setTimeout(resolve2, delay2);
9182
+ const backoff2 = config3.retryBackoff ? config3.retryBackoff(err, delay2) : new Promise((resolve3) => {
9183
+ setTimeout(resolve3, delay2);
9184
9184
  });
9185
9185
  if (config3.onRetryAttempt) {
9186
9186
  await config3.onRetryAttempt(err);
@@ -10054,8 +10054,8 @@ var require_helpers = __commonJS((exports) => {
10054
10054
  function req(url2, opts = {}) {
10055
10055
  const href = typeof url2 === "string" ? url2 : url2.href;
10056
10056
  const req2 = (href.startsWith("https:") ? https : http).request(url2, opts);
10057
- const promise2 = new Promise((resolve2, reject) => {
10058
- req2.once("response", resolve2).once("error", reject).end();
10057
+ const promise2 = new Promise((resolve3, reject) => {
10058
+ req2.once("response", resolve3).once("error", reject).end();
10059
10059
  });
10060
10060
  req2.then = promise2.then.bind(promise2);
10061
10061
  return req2;
@@ -10224,7 +10224,7 @@ var require_parse_proxy_response = __commonJS((exports) => {
10224
10224
  var debug_1 = __importDefault(require_src2());
10225
10225
  var debug = (0, debug_1.default)("https-proxy-agent:parse-proxy-response");
10226
10226
  function parseProxyResponse(socket) {
10227
- return new Promise((resolve2, reject) => {
10227
+ return new Promise((resolve3, reject) => {
10228
10228
  let buffersLength = 0;
10229
10229
  const buffers = [];
10230
10230
  function read() {
@@ -10293,7 +10293,7 @@ var require_parse_proxy_response = __commonJS((exports) => {
10293
10293
  }
10294
10294
  debug("got proxy server response: %o %o", firstLine, headers);
10295
10295
  cleanup();
10296
- resolve2({
10296
+ resolve3({
10297
10297
  connect: {
10298
10298
  statusCode,
10299
10299
  statusText,
@@ -10527,7 +10527,7 @@ var require_ponyfill_es2018 = __commonJS((exports, module) => {
10527
10527
  return new originalPromise(executor);
10528
10528
  }
10529
10529
  function promiseResolvedWith(value) {
10530
- return newPromise((resolve2) => resolve2(value));
10530
+ return newPromise((resolve3) => resolve3(value));
10531
10531
  }
10532
10532
  function promiseRejectedWith(reason) {
10533
10533
  return originalPromiseReject(reason);
@@ -10682,8 +10682,8 @@ var require_ponyfill_es2018 = __commonJS((exports, module) => {
10682
10682
  return new TypeError("Cannot " + name17 + " a stream using a released reader");
10683
10683
  }
10684
10684
  function defaultReaderClosedPromiseInitialize(reader) {
10685
- reader._closedPromise = newPromise((resolve2, reject) => {
10686
- reader._closedPromise_resolve = resolve2;
10685
+ reader._closedPromise = newPromise((resolve3, reject) => {
10686
+ reader._closedPromise_resolve = resolve3;
10687
10687
  reader._closedPromise_reject = reject;
10688
10688
  });
10689
10689
  }
@@ -10846,8 +10846,8 @@ var require_ponyfill_es2018 = __commonJS((exports, module) => {
10846
10846
  }
10847
10847
  let resolvePromise;
10848
10848
  let rejectPromise;
10849
- const promise2 = newPromise((resolve2, reject) => {
10850
- resolvePromise = resolve2;
10849
+ const promise2 = newPromise((resolve3, reject) => {
10850
+ resolvePromise = resolve3;
10851
10851
  rejectPromise = reject;
10852
10852
  });
10853
10853
  const readRequest = {
@@ -10943,8 +10943,8 @@ var require_ponyfill_es2018 = __commonJS((exports, module) => {
10943
10943
  const reader = this._reader;
10944
10944
  let resolvePromise;
10945
10945
  let rejectPromise;
10946
- const promise2 = newPromise((resolve2, reject) => {
10947
- resolvePromise = resolve2;
10946
+ const promise2 = newPromise((resolve3, reject) => {
10947
+ resolvePromise = resolve3;
10948
10948
  rejectPromise = reject;
10949
10949
  });
10950
10950
  const readRequest = {
@@ -11941,8 +11941,8 @@ var require_ponyfill_es2018 = __commonJS((exports, module) => {
11941
11941
  }
11942
11942
  let resolvePromise;
11943
11943
  let rejectPromise;
11944
- const promise2 = newPromise((resolve2, reject) => {
11945
- resolvePromise = resolve2;
11944
+ const promise2 = newPromise((resolve3, reject) => {
11945
+ resolvePromise = resolve3;
11946
11946
  rejectPromise = reject;
11947
11947
  });
11948
11948
  const readIntoRequest = {
@@ -12218,10 +12218,10 @@ var require_ponyfill_es2018 = __commonJS((exports, module) => {
12218
12218
  wasAlreadyErroring = true;
12219
12219
  reason = undefined;
12220
12220
  }
12221
- const promise2 = newPromise((resolve2, reject) => {
12221
+ const promise2 = newPromise((resolve3, reject) => {
12222
12222
  stream._pendingAbortRequest = {
12223
12223
  _promise: undefined,
12224
- _resolve: resolve2,
12224
+ _resolve: resolve3,
12225
12225
  _reject: reject,
12226
12226
  _reason: reason,
12227
12227
  _wasAlreadyErroring: wasAlreadyErroring
@@ -12238,9 +12238,9 @@ var require_ponyfill_es2018 = __commonJS((exports, module) => {
12238
12238
  if (state === "closed" || state === "errored") {
12239
12239
  return promiseRejectedWith(new TypeError(`The stream (in ${state} state) is not in the writable state and cannot be closed`));
12240
12240
  }
12241
- const promise2 = newPromise((resolve2, reject) => {
12241
+ const promise2 = newPromise((resolve3, reject) => {
12242
12242
  const closeRequest = {
12243
- _resolve: resolve2,
12243
+ _resolve: resolve3,
12244
12244
  _reject: reject
12245
12245
  };
12246
12246
  stream._closeRequest = closeRequest;
@@ -12253,9 +12253,9 @@ var require_ponyfill_es2018 = __commonJS((exports, module) => {
12253
12253
  return promise2;
12254
12254
  }
12255
12255
  function WritableStreamAddWriteRequest(stream) {
12256
- const promise2 = newPromise((resolve2, reject) => {
12256
+ const promise2 = newPromise((resolve3, reject) => {
12257
12257
  const writeRequest = {
12258
- _resolve: resolve2,
12258
+ _resolve: resolve3,
12259
12259
  _reject: reject
12260
12260
  };
12261
12261
  stream._writeRequests.push(writeRequest);
@@ -12820,8 +12820,8 @@ var require_ponyfill_es2018 = __commonJS((exports, module) => {
12820
12820
  return new TypeError("Cannot " + name17 + " a stream using a released writer");
12821
12821
  }
12822
12822
  function defaultWriterClosedPromiseInitialize(writer) {
12823
- writer._closedPromise = newPromise((resolve2, reject) => {
12824
- writer._closedPromise_resolve = resolve2;
12823
+ writer._closedPromise = newPromise((resolve3, reject) => {
12824
+ writer._closedPromise_resolve = resolve3;
12825
12825
  writer._closedPromise_reject = reject;
12826
12826
  writer._closedPromiseState = "pending";
12827
12827
  });
@@ -12857,8 +12857,8 @@ var require_ponyfill_es2018 = __commonJS((exports, module) => {
12857
12857
  writer._closedPromiseState = "resolved";
12858
12858
  }
12859
12859
  function defaultWriterReadyPromiseInitialize(writer) {
12860
- writer._readyPromise = newPromise((resolve2, reject) => {
12861
- writer._readyPromise_resolve = resolve2;
12860
+ writer._readyPromise = newPromise((resolve3, reject) => {
12861
+ writer._readyPromise_resolve = resolve3;
12862
12862
  writer._readyPromise_reject = reject;
12863
12863
  });
12864
12864
  writer._readyPromiseState = "pending";
@@ -12945,7 +12945,7 @@ var require_ponyfill_es2018 = __commonJS((exports, module) => {
12945
12945
  source._disturbed = true;
12946
12946
  let shuttingDown = false;
12947
12947
  let currentWrite = promiseResolvedWith(undefined);
12948
- return newPromise((resolve2, reject) => {
12948
+ return newPromise((resolve3, reject) => {
12949
12949
  let abortAlgorithm;
12950
12950
  if (signal !== undefined) {
12951
12951
  abortAlgorithm = () => {
@@ -13090,7 +13090,7 @@ var require_ponyfill_es2018 = __commonJS((exports, module) => {
13090
13090
  if (isError) {
13091
13091
  reject(error48);
13092
13092
  } else {
13093
- resolve2(undefined);
13093
+ resolve3(undefined);
13094
13094
  }
13095
13095
  return null;
13096
13096
  }
@@ -13359,8 +13359,8 @@ var require_ponyfill_es2018 = __commonJS((exports, module) => {
13359
13359
  let branch1;
13360
13360
  let branch2;
13361
13361
  let resolveCancelPromise;
13362
- const cancelPromise = newPromise((resolve2) => {
13363
- resolveCancelPromise = resolve2;
13362
+ const cancelPromise = newPromise((resolve3) => {
13363
+ resolveCancelPromise = resolve3;
13364
13364
  });
13365
13365
  function pullAlgorithm() {
13366
13366
  if (reading) {
@@ -13450,8 +13450,8 @@ var require_ponyfill_es2018 = __commonJS((exports, module) => {
13450
13450
  let branch1;
13451
13451
  let branch2;
13452
13452
  let resolveCancelPromise;
13453
- const cancelPromise = newPromise((resolve2) => {
13454
- resolveCancelPromise = resolve2;
13453
+ const cancelPromise = newPromise((resolve3) => {
13454
+ resolveCancelPromise = resolve3;
13455
13455
  });
13456
13456
  function forwardReaderError(thisReader) {
13457
13457
  uponRejection(thisReader._closedPromise, (r) => {
@@ -14196,8 +14196,8 @@ var require_ponyfill_es2018 = __commonJS((exports, module) => {
14196
14196
  const writableHighWaterMark = ExtractHighWaterMark(writableStrategy, 1);
14197
14197
  const writableSizeAlgorithm = ExtractSizeAlgorithm(writableStrategy);
14198
14198
  let startPromise_resolve;
14199
- const startPromise = newPromise((resolve2) => {
14200
- startPromise_resolve = resolve2;
14199
+ const startPromise = newPromise((resolve3) => {
14200
+ startPromise_resolve = resolve3;
14201
14201
  });
14202
14202
  InitializeTransformStream(this, startPromise, writableHighWaterMark, writableSizeAlgorithm, readableHighWaterMark, readableSizeAlgorithm);
14203
14203
  SetUpTransformStreamDefaultControllerFromTransformer(this, transformer);
@@ -14284,8 +14284,8 @@ var require_ponyfill_es2018 = __commonJS((exports, module) => {
14284
14284
  if (stream._backpressureChangePromise !== undefined) {
14285
14285
  stream._backpressureChangePromise_resolve();
14286
14286
  }
14287
- stream._backpressureChangePromise = newPromise((resolve2) => {
14288
- stream._backpressureChangePromise_resolve = resolve2;
14287
+ stream._backpressureChangePromise = newPromise((resolve3) => {
14288
+ stream._backpressureChangePromise_resolve = resolve3;
14289
14289
  });
14290
14290
  stream._backpressure = backpressure;
14291
14291
  }
@@ -14443,8 +14443,8 @@ var require_ponyfill_es2018 = __commonJS((exports, module) => {
14443
14443
  return controller._finishPromise;
14444
14444
  }
14445
14445
  const readable = stream._readable;
14446
- controller._finishPromise = newPromise((resolve2, reject) => {
14447
- controller._finishPromise_resolve = resolve2;
14446
+ controller._finishPromise = newPromise((resolve3, reject) => {
14447
+ controller._finishPromise_resolve = resolve3;
14448
14448
  controller._finishPromise_reject = reject;
14449
14449
  });
14450
14450
  const cancelPromise = controller._cancelAlgorithm(reason);
@@ -14470,8 +14470,8 @@ var require_ponyfill_es2018 = __commonJS((exports, module) => {
14470
14470
  return controller._finishPromise;
14471
14471
  }
14472
14472
  const readable = stream._readable;
14473
- controller._finishPromise = newPromise((resolve2, reject) => {
14474
- controller._finishPromise_resolve = resolve2;
14473
+ controller._finishPromise = newPromise((resolve3, reject) => {
14474
+ controller._finishPromise_resolve = resolve3;
14475
14475
  controller._finishPromise_reject = reject;
14476
14476
  });
14477
14477
  const flushPromise = controller._flushAlgorithm();
@@ -14501,8 +14501,8 @@ var require_ponyfill_es2018 = __commonJS((exports, module) => {
14501
14501
  return controller._finishPromise;
14502
14502
  }
14503
14503
  const writable = stream._writable;
14504
- controller._finishPromise = newPromise((resolve2, reject) => {
14505
- controller._finishPromise_resolve = resolve2;
14504
+ controller._finishPromise = newPromise((resolve3, reject) => {
14505
+ controller._finishPromise_resolve = resolve3;
14506
14506
  controller._finishPromise_reject = reject;
14507
14507
  });
14508
14508
  const cancelPromise = controller._cancelAlgorithm(reason);
@@ -16224,7 +16224,7 @@ import zlib from "node:zlib";
16224
16224
  import Stream2, { PassThrough as PassThrough2, pipeline as pump } from "node:stream";
16225
16225
  import { Buffer as Buffer5 } from "node:buffer";
16226
16226
  async function fetch2(url2, options_) {
16227
- return new Promise((resolve2, reject) => {
16227
+ return new Promise((resolve3, reject) => {
16228
16228
  const request = new Request(url2, options_);
16229
16229
  const { parsedURL, options } = getNodeRequestOptions(request);
16230
16230
  if (!supportedSchemas.has(parsedURL.protocol)) {
@@ -16233,7 +16233,7 @@ async function fetch2(url2, options_) {
16233
16233
  if (parsedURL.protocol === "data:") {
16234
16234
  const data = dist_default(request.url);
16235
16235
  const response2 = new Response2(data, { headers: { "Content-Type": data.typeFull } });
16236
- resolve2(response2);
16236
+ resolve3(response2);
16237
16237
  return;
16238
16238
  }
16239
16239
  const send = (parsedURL.protocol === "https:" ? https : http2).request;
@@ -16355,7 +16355,7 @@ async function fetch2(url2, options_) {
16355
16355
  if (responseReferrerPolicy) {
16356
16356
  requestOptions.referrerPolicy = responseReferrerPolicy;
16357
16357
  }
16358
- resolve2(fetch2(new Request(locationURL, requestOptions)));
16358
+ resolve3(fetch2(new Request(locationURL, requestOptions)));
16359
16359
  finalize2();
16360
16360
  return;
16361
16361
  }
@@ -16388,7 +16388,7 @@ async function fetch2(url2, options_) {
16388
16388
  const codings = headers.get("Content-Encoding");
16389
16389
  if (!request.compress || request.method === "HEAD" || codings === null || response_.statusCode === 204 || response_.statusCode === 304) {
16390
16390
  response = new Response2(body, responseOptions);
16391
- resolve2(response);
16391
+ resolve3(response);
16392
16392
  return;
16393
16393
  }
16394
16394
  const zlibOptions = {
@@ -16402,7 +16402,7 @@ async function fetch2(url2, options_) {
16402
16402
  }
16403
16403
  });
16404
16404
  response = new Response2(body, responseOptions);
16405
- resolve2(response);
16405
+ resolve3(response);
16406
16406
  return;
16407
16407
  }
16408
16408
  if (codings === "deflate" || codings === "x-deflate") {
@@ -16426,12 +16426,12 @@ async function fetch2(url2, options_) {
16426
16426
  });
16427
16427
  }
16428
16428
  response = new Response2(body, responseOptions);
16429
- resolve2(response);
16429
+ resolve3(response);
16430
16430
  });
16431
16431
  raw.once("end", () => {
16432
16432
  if (!response) {
16433
16433
  response = new Response2(body, responseOptions);
16434
- resolve2(response);
16434
+ resolve3(response);
16435
16435
  }
16436
16436
  });
16437
16437
  return;
@@ -16443,11 +16443,11 @@ async function fetch2(url2, options_) {
16443
16443
  }
16444
16444
  });
16445
16445
  response = new Response2(body, responseOptions);
16446
- resolve2(response);
16446
+ resolve3(response);
16447
16447
  return;
16448
16448
  }
16449
16449
  response = new Response2(body, responseOptions);
16450
- resolve2(response);
16450
+ resolve3(response);
16451
16451
  });
16452
16452
  writeToStream(request_, request).catch(reject);
16453
16453
  });
@@ -22359,7 +22359,7 @@ var require_jwtaccess = __commonJS((exports) => {
22359
22359
  }
22360
22360
  }
22361
22361
  fromStreamAsync(inputStream) {
22362
- return new Promise((resolve2, reject) => {
22362
+ return new Promise((resolve3, reject) => {
22363
22363
  if (!inputStream) {
22364
22364
  reject(new Error("Must pass in a stream containing the service account auth settings."));
22365
22365
  }
@@ -22368,7 +22368,7 @@ var require_jwtaccess = __commonJS((exports) => {
22368
22368
  try {
22369
22369
  const data = JSON.parse(s2);
22370
22370
  this.fromJSON(data);
22371
- resolve2();
22371
+ resolve3();
22372
22372
  } catch (err) {
22373
22373
  reject(err);
22374
22374
  }
@@ -22554,7 +22554,7 @@ var require_jwtclient = __commonJS((exports) => {
22554
22554
  }
22555
22555
  }
22556
22556
  fromStreamAsync(inputStream) {
22557
- return new Promise((resolve2, reject) => {
22557
+ return new Promise((resolve3, reject) => {
22558
22558
  if (!inputStream) {
22559
22559
  throw new Error("Must pass in a stream containing the service account auth settings.");
22560
22560
  }
@@ -22563,7 +22563,7 @@ var require_jwtclient = __commonJS((exports) => {
22563
22563
  try {
22564
22564
  const data = JSON.parse(s2);
22565
22565
  this.fromJSON(data);
22566
- resolve2();
22566
+ resolve3();
22567
22567
  } catch (e2) {
22568
22568
  reject(e2);
22569
22569
  }
@@ -22663,7 +22663,7 @@ var require_refreshclient = __commonJS((exports) => {
22663
22663
  }
22664
22664
  }
22665
22665
  async fromStreamAsync(inputStream) {
22666
- return new Promise((resolve2, reject) => {
22666
+ return new Promise((resolve3, reject) => {
22667
22667
  if (!inputStream) {
22668
22668
  return reject(new Error("Must pass in a stream containing the user refresh token."));
22669
22669
  }
@@ -22672,7 +22672,7 @@ var require_refreshclient = __commonJS((exports) => {
22672
22672
  try {
22673
22673
  const data = JSON.parse(s2);
22674
22674
  this.fromJSON(data);
22675
- return resolve2();
22675
+ return resolve3();
22676
22676
  } catch (err) {
22677
22677
  return reject(err);
22678
22678
  }
@@ -24028,7 +24028,7 @@ var require_pluggable_auth_handler = __commonJS((exports) => {
24028
24028
  this.outputFile = options.outputFile;
24029
24029
  }
24030
24030
  retrieveResponseFromExecutable(envMap) {
24031
- return new Promise((resolve2, reject) => {
24031
+ return new Promise((resolve3, reject) => {
24032
24032
  const child = childProcess.spawn(this.commandComponents[0], this.commandComponents.slice(1), {
24033
24033
  env: { ...process.env, ...Object.fromEntries(envMap) }
24034
24034
  });
@@ -24050,7 +24050,7 @@ var require_pluggable_auth_handler = __commonJS((exports) => {
24050
24050
  try {
24051
24051
  const responseJson = JSON.parse(output);
24052
24052
  const response = new executable_response_1.ExecutableResponse(responseJson);
24053
- return resolve2(response);
24053
+ return resolve3(response);
24054
24054
  } catch (error48) {
24055
24055
  if (error48 instanceof executable_response_1.ExecutableResponseError) {
24056
24056
  return reject(error48);
@@ -24701,7 +24701,7 @@ var require_googleauth = __commonJS((exports) => {
24701
24701
  }
24702
24702
  }
24703
24703
  fromStreamAsync(inputStream, options) {
24704
- return new Promise((resolve2, reject) => {
24704
+ return new Promise((resolve3, reject) => {
24705
24705
  if (!inputStream) {
24706
24706
  throw new Error("Must pass in a stream containing the Google auth settings.");
24707
24707
  }
@@ -24711,7 +24711,7 @@ var require_googleauth = __commonJS((exports) => {
24711
24711
  try {
24712
24712
  const data = JSON.parse(chunks.join(""));
24713
24713
  const r2 = this._cacheClientFromJSON(data, options);
24714
- return resolve2(r2);
24714
+ return resolve3(r2);
24715
24715
  } catch (err) {
24716
24716
  if (!this.keyFilename)
24717
24717
  throw err;
@@ -24721,7 +24721,7 @@ var require_googleauth = __commonJS((exports) => {
24721
24721
  });
24722
24722
  this.cachedCredential = client;
24723
24723
  this.setGapicJWTValues(client);
24724
- return resolve2(client);
24724
+ return resolve3(client);
24725
24725
  }
24726
24726
  } catch (err) {
24727
24727
  return reject(err);
@@ -24742,16 +24742,16 @@ var require_googleauth = __commonJS((exports) => {
24742
24742
  return false;
24743
24743
  }
24744
24744
  async getDefaultServiceProjectId() {
24745
- return new Promise((resolve2) => {
24745
+ return new Promise((resolve3) => {
24746
24746
  (0, child_process_1.exec)("gcloud config config-helper --format json", (err, stdout) => {
24747
24747
  if (!err && stdout) {
24748
24748
  try {
24749
24749
  const projectId = JSON.parse(stdout).configuration.properties.core.project;
24750
- resolve2(projectId);
24750
+ resolve3(projectId);
24751
24751
  return;
24752
24752
  } catch (e2) {}
24753
24753
  }
24754
- resolve2(null);
24754
+ resolve3(null);
24755
24755
  });
24756
24756
  });
24757
24757
  }
@@ -35104,769 +35104,2288 @@ var require_mimeScore = __commonJS((exports, module) => {
35104
35104
  };
35105
35105
  });
35106
35106
 
35107
- // ../../node_modules/better-sqlite3/lib/util.js
35108
- var require_util3 = __commonJS((exports) => {
35109
- exports.getBooleanOption = (options, key) => {
35110
- let value = false;
35111
- if (key in options && typeof (value = options[key]) !== "boolean") {
35112
- throw new TypeError(`Expected the "${key}" option to be a boolean`);
35113
- }
35114
- return value;
35115
- };
35116
- exports.cppdb = Symbol();
35117
- exports.inspect = Symbol.for("nodejs.util.inspect.custom");
35118
- });
35119
-
35120
- // ../../node_modules/better-sqlite3/lib/sqlite-error.js
35121
- var require_sqlite_error = __commonJS((exports, module) => {
35122
- var descriptor = { value: "SqliteError", writable: true, enumerable: false, configurable: true };
35123
- function SqliteError(message, code) {
35124
- if (new.target !== SqliteError) {
35125
- return new SqliteError(message, code);
35126
- }
35127
- if (typeof code !== "string") {
35128
- throw new TypeError("Expected second argument to be a string");
35129
- }
35130
- Error.call(this, message);
35131
- descriptor.value = "" + message;
35132
- Object.defineProperty(this, "message", descriptor);
35133
- Error.captureStackTrace(this, SqliteError);
35134
- this.code = code;
35135
- }
35136
- Object.setPrototypeOf(SqliteError, Error);
35137
- Object.setPrototypeOf(SqliteError.prototype, Error.prototype);
35138
- Object.defineProperty(SqliteError.prototype, "name", descriptor);
35139
- module.exports = SqliteError;
35140
- });
35141
-
35142
- // ../../node_modules/file-uri-to-path/index.js
35143
- var require_file_uri_to_path = __commonJS((exports, module) => {
35144
- var sep = __require("path").sep || "/";
35145
- module.exports = fileUriToPath;
35146
- function fileUriToPath(uri) {
35147
- if (typeof uri != "string" || uri.length <= 7 || uri.substring(0, 7) != "file://") {
35148
- throw new TypeError("must pass in a file:// URI to convert to a file path");
35149
- }
35150
- var rest = decodeURI(uri.substring(7));
35151
- var firstSlash = rest.indexOf("/");
35152
- var host = rest.substring(0, firstSlash);
35153
- var path = rest.substring(firstSlash + 1);
35154
- if (host == "localhost")
35155
- host = "";
35156
- if (host) {
35157
- host = sep + sep + host;
35158
- }
35159
- path = path.replace(/^(.+)\|/, "$1:");
35160
- if (sep == "\\") {
35161
- path = path.replace(/\//g, "\\");
35162
- }
35163
- if (/^.+\:/.test(path)) {} else {
35164
- path = sep + path;
35165
- }
35166
- return host + path;
35167
- }
35168
- });
35169
-
35170
- // ../../node_modules/bindings/bindings.js
35171
- var require_bindings = __commonJS((exports, module) => {
35172
- var __filename = "/Users/xiliangchen/projects/polka-codes/node_modules/bindings/bindings.js";
35173
- var fs4 = __require("fs");
35174
- var path = __require("path");
35175
- var fileURLToPath = require_file_uri_to_path();
35176
- var join3 = path.join;
35177
- var dirname2 = path.dirname;
35178
- var exists = fs4.accessSync && function(path2) {
35179
- try {
35180
- fs4.accessSync(path2);
35181
- } catch (e2) {
35182
- return false;
35183
- }
35184
- return true;
35185
- } || fs4.existsSync || path.existsSync;
35186
- var defaults = {
35187
- arrow: process.env.NODE_BINDINGS_ARROW || " → ",
35188
- compiled: process.env.NODE_BINDINGS_COMPILED_DIR || "compiled",
35189
- platform: process.platform,
35190
- arch: process.arch,
35191
- nodePreGyp: "node-v" + process.versions.modules + "-" + process.platform + "-" + process.arch,
35192
- version: process.versions.node,
35193
- bindings: "bindings.node",
35194
- try: [
35195
- ["module_root", "build", "bindings"],
35196
- ["module_root", "build", "Debug", "bindings"],
35197
- ["module_root", "build", "Release", "bindings"],
35198
- ["module_root", "out", "Debug", "bindings"],
35199
- ["module_root", "Debug", "bindings"],
35200
- ["module_root", "out", "Release", "bindings"],
35201
- ["module_root", "Release", "bindings"],
35202
- ["module_root", "build", "default", "bindings"],
35203
- ["module_root", "compiled", "version", "platform", "arch", "bindings"],
35204
- ["module_root", "addon-build", "release", "install-root", "bindings"],
35205
- ["module_root", "addon-build", "debug", "install-root", "bindings"],
35206
- ["module_root", "addon-build", "default", "install-root", "bindings"],
35207
- ["module_root", "lib", "binding", "nodePreGyp", "bindings"]
35208
- ]
35209
- };
35210
- function bindings(opts) {
35211
- if (typeof opts == "string") {
35212
- opts = { bindings: opts };
35213
- } else if (!opts) {
35214
- opts = {};
35215
- }
35216
- Object.keys(defaults).map(function(i3) {
35217
- if (!(i3 in opts))
35218
- opts[i3] = defaults[i3];
35219
- });
35220
- if (!opts.module_root) {
35221
- opts.module_root = exports.getRoot(exports.getFileName());
35222
- }
35223
- if (path.extname(opts.bindings) != ".node") {
35224
- opts.bindings += ".node";
35225
- }
35226
- var requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : __require;
35227
- var tries = [], i2 = 0, l = opts.try.length, n, b, err;
35228
- for (;i2 < l; i2++) {
35229
- n = join3.apply(null, opts.try[i2].map(function(p) {
35230
- return opts[p] || p;
35231
- }));
35232
- tries.push(n);
35233
- try {
35234
- b = opts.path ? requireFunc.resolve(n) : requireFunc(n);
35235
- if (!opts.path) {
35236
- b.path = n;
35107
+ // ../../node_modules/sql.js/dist/sql-wasm.js
35108
+ var require_sql_wasm = __commonJS((exports, module) => {
35109
+ var __dirname = "/Users/xiliangchen/projects/polka-codes/node_modules/sql.js/dist";
35110
+ var initSqlJsPromise = undefined;
35111
+ var initSqlJs = function(moduleConfig) {
35112
+ if (initSqlJsPromise) {
35113
+ return initSqlJsPromise;
35114
+ }
35115
+ initSqlJsPromise = new Promise(function(resolveModule, reject) {
35116
+ var Module = typeof moduleConfig !== "undefined" ? moduleConfig : {};
35117
+ var originalOnAbortFunction = Module["onAbort"];
35118
+ Module["onAbort"] = function(errorThatCausedAbort) {
35119
+ reject(new Error(errorThatCausedAbort));
35120
+ if (originalOnAbortFunction) {
35121
+ originalOnAbortFunction(errorThatCausedAbort);
35237
35122
  }
35238
- return b;
35239
- } catch (e2) {
35240
- if (e2.code !== "MODULE_NOT_FOUND" && e2.code !== "QUALIFIED_PATH_RESOLUTION_FAILED" && !/not find/i.test(e2.message)) {
35241
- throw e2;
35123
+ };
35124
+ Module["postRun"] = Module["postRun"] || [];
35125
+ Module["postRun"].push(function() {
35126
+ resolveModule(Module);
35127
+ });
35128
+ module = undefined;
35129
+ var f3;
35130
+ f3 ||= typeof Module != "undefined" ? Module : {};
35131
+ 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";
35132
+ f3.onRuntimeInitialized = function() {
35133
+ function a(g, l) {
35134
+ switch (typeof l) {
35135
+ case "boolean":
35136
+ dc(g, l ? 1 : 0);
35137
+ break;
35138
+ case "number":
35139
+ ec(g, l);
35140
+ break;
35141
+ case "string":
35142
+ fc(g, l, -1, -1);
35143
+ break;
35144
+ case "object":
35145
+ if (l === null)
35146
+ lb(g);
35147
+ else if (l.length != null) {
35148
+ var n = da(l, ea);
35149
+ gc(g, n, l.length, -1);
35150
+ fa(n);
35151
+ } else
35152
+ va(g, "Wrong API use : tried to return a value of an unknown type (" + l + ").", -1);
35153
+ break;
35154
+ default:
35155
+ lb(g);
35156
+ }
35242
35157
  }
35243
- }
35244
- }
35245
- err = new Error(`Could not locate the bindings file. Tried:
35246
- ` + tries.map(function(a) {
35247
- return opts.arrow + a;
35248
- }).join(`
35249
- `));
35250
- err.tries = tries;
35251
- throw err;
35252
- }
35253
- module.exports = exports = bindings;
35254
- exports.getFileName = function getFileName(calling_file) {
35255
- var { prepareStackTrace: origPST, stackTraceLimit: origSTL } = Error, dummy = {}, fileName;
35256
- Error.stackTraceLimit = 10;
35257
- Error.prepareStackTrace = function(e2, st) {
35258
- for (var i2 = 0, l = st.length;i2 < l; i2++) {
35259
- fileName = st[i2].getFileName();
35260
- if (fileName !== __filename) {
35261
- if (calling_file) {
35262
- if (fileName !== calling_file) {
35158
+ function b(g, l) {
35159
+ for (var n = [], r2 = 0;r2 < g; r2 += 1) {
35160
+ var t2 = m2(l + 4 * r2, "i32"), y = hc(t2);
35161
+ if (y === 1 || y === 2)
35162
+ t2 = ic(t2);
35163
+ else if (y === 3)
35164
+ t2 = jc(t2);
35165
+ else if (y === 4) {
35166
+ y = t2;
35167
+ t2 = kc(y);
35168
+ y = lc(y);
35169
+ for (var L = new Uint8Array(t2), J = 0;J < t2; J += 1)
35170
+ L[J] = p[y + J];
35171
+ t2 = L;
35172
+ } else
35173
+ t2 = null;
35174
+ n.push(t2);
35175
+ }
35176
+ return n;
35177
+ }
35178
+ function c(g, l) {
35179
+ this.Qa = g;
35180
+ this.db = l;
35181
+ this.Oa = 1;
35182
+ this.lb = [];
35183
+ }
35184
+ function d(g, l) {
35185
+ this.db = l;
35186
+ l = ha(g) + 1;
35187
+ this.eb = ia(l);
35188
+ if (this.eb === null)
35189
+ throw Error("Unable to allocate memory for the SQL string");
35190
+ u(g, x2, this.eb, l);
35191
+ this.kb = this.eb;
35192
+ this.Za = this.pb = null;
35193
+ }
35194
+ function e2(g) {
35195
+ this.filename = "dbfile_" + (4294967295 * Math.random() >>> 0);
35196
+ if (g != null) {
35197
+ var l = this.filename, n = "/", r2 = l;
35198
+ n && (n = typeof n == "string" ? n : ja(n), r2 = l ? ka(n + "/" + l) : n);
35199
+ l = la(true, true);
35200
+ r2 = ma(r2, l);
35201
+ if (g) {
35202
+ if (typeof g == "string") {
35203
+ n = Array(g.length);
35204
+ for (var t2 = 0, y = g.length;t2 < y; ++t2)
35205
+ n[t2] = g.charCodeAt(t2);
35206
+ g = n;
35207
+ }
35208
+ na(r2, l | 146);
35209
+ n = oa(r2, 577);
35210
+ pa(n, g, 0, g.length, 0);
35211
+ qa(n);
35212
+ na(r2, l);
35213
+ }
35214
+ }
35215
+ this.handleError(q(this.filename, h2));
35216
+ this.db = m2(h2, "i32");
35217
+ ob(this.db);
35218
+ this.fb = {};
35219
+ this.Sa = {};
35220
+ }
35221
+ var h2 = z2(4), k = f3.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", [
35222
+ "number",
35223
+ "number"
35224
+ ]), 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"]);
35225
+ c.prototype.bind = function(g) {
35226
+ if (!this.Qa)
35227
+ throw "Statement closed";
35228
+ this.reset();
35229
+ return Array.isArray(g) ? this.Cb(g) : g != null && typeof g === "object" ? this.Db(g) : true;
35230
+ };
35231
+ c.prototype.step = function() {
35232
+ if (!this.Qa)
35233
+ throw "Statement closed";
35234
+ this.Oa = 1;
35235
+ var g = sc(this.Qa);
35236
+ switch (g) {
35237
+ case 100:
35238
+ return true;
35239
+ case 101:
35240
+ return false;
35241
+ default:
35242
+ throw this.db.handleError(g);
35243
+ }
35244
+ };
35245
+ c.prototype.wb = function(g) {
35246
+ g == null && (g = this.Oa, this.Oa += 1);
35247
+ return wc(this.Qa, g);
35248
+ };
35249
+ c.prototype.Gb = function(g) {
35250
+ g == null && (g = this.Oa, this.Oa += 1);
35251
+ g = sb(this.Qa, g);
35252
+ if (typeof BigInt !== "function")
35253
+ throw Error("BigInt is not supported");
35254
+ return BigInt(g);
35255
+ };
35256
+ c.prototype.Hb = function(g) {
35257
+ g == null && (g = this.Oa, this.Oa += 1);
35258
+ return sb(this.Qa, g);
35259
+ };
35260
+ c.prototype.getBlob = function(g) {
35261
+ g == null && (g = this.Oa, this.Oa += 1);
35262
+ var l = yc(this.Qa, g);
35263
+ g = xc(this.Qa, g);
35264
+ for (var n = new Uint8Array(l), r2 = 0;r2 < l; r2 += 1)
35265
+ n[r2] = p[g + r2];
35266
+ return n;
35267
+ };
35268
+ c.prototype.get = function(g, l) {
35269
+ l = l || {};
35270
+ g != null && this.bind(g) && this.step();
35271
+ g = [];
35272
+ for (var n = vc(this.Qa), r2 = 0;r2 < n; r2 += 1)
35273
+ switch (zc(this.Qa, r2)) {
35274
+ case 1:
35275
+ var t2 = l.useBigInt ? this.Gb(r2) : this.wb(r2);
35276
+ g.push(t2);
35277
+ break;
35278
+ case 2:
35279
+ g.push(this.wb(r2));
35280
+ break;
35281
+ case 3:
35282
+ g.push(this.Hb(r2));
35283
+ break;
35284
+ case 4:
35285
+ g.push(this.getBlob(r2));
35286
+ break;
35287
+ default:
35288
+ g.push(null);
35289
+ }
35290
+ return g;
35291
+ };
35292
+ c.prototype.getColumnNames = function() {
35293
+ for (var g = [], l = uc(this.Qa), n = 0;n < l; n += 1)
35294
+ g.push(Ac(this.Qa, n));
35295
+ return g;
35296
+ };
35297
+ c.prototype.getAsObject = function(g, l) {
35298
+ g = this.get(g, l);
35299
+ l = this.getColumnNames();
35300
+ for (var n = {}, r2 = 0;r2 < l.length; r2 += 1)
35301
+ n[l[r2]] = g[r2];
35302
+ return n;
35303
+ };
35304
+ c.prototype.getSQL = function() {
35305
+ return pb(this.Qa);
35306
+ };
35307
+ c.prototype.getNormalizedSQL = function() {
35308
+ return nc(this.Qa);
35309
+ };
35310
+ c.prototype.run = function(g) {
35311
+ g != null && this.bind(g);
35312
+ this.step();
35313
+ return this.reset();
35314
+ };
35315
+ c.prototype.sb = function(g, l) {
35316
+ l == null && (l = this.Oa, this.Oa += 1);
35317
+ g = ra(g);
35318
+ var n = da(g, ea);
35319
+ this.lb.push(n);
35320
+ this.db.handleError(oc(this.Qa, l, n, g.length - 1, 0));
35321
+ };
35322
+ c.prototype.Bb = function(g, l) {
35323
+ l == null && (l = this.Oa, this.Oa += 1);
35324
+ var n = da(g, ea);
35325
+ this.lb.push(n);
35326
+ this.db.handleError(rb(this.Qa, l, n, g.length, 0));
35327
+ };
35328
+ c.prototype.rb = function(g, l) {
35329
+ l == null && (l = this.Oa, this.Oa += 1);
35330
+ this.db.handleError((g === (g | 0) ? qc : pc)(this.Qa, l, g));
35331
+ };
35332
+ c.prototype.Eb = function(g) {
35333
+ g == null && (g = this.Oa, this.Oa += 1);
35334
+ rb(this.Qa, g, 0, 0, 0);
35335
+ };
35336
+ c.prototype.tb = function(g, l) {
35337
+ l == null && (l = this.Oa, this.Oa += 1);
35338
+ switch (typeof g) {
35339
+ case "string":
35340
+ this.sb(g, l);
35341
+ return;
35342
+ case "number":
35343
+ this.rb(g, l);
35344
+ return;
35345
+ case "bigint":
35346
+ this.sb(g.toString(), l);
35263
35347
  return;
35348
+ case "boolean":
35349
+ this.rb(g + 0, l);
35350
+ return;
35351
+ case "object":
35352
+ if (g === null) {
35353
+ this.Eb(l);
35354
+ return;
35355
+ }
35356
+ if (g.length != null) {
35357
+ this.Bb(g, l);
35358
+ return;
35359
+ }
35360
+ }
35361
+ throw "Wrong API use : tried to bind a value of an unknown type (" + g + ").";
35362
+ };
35363
+ c.prototype.Db = function(g) {
35364
+ var l = this;
35365
+ Object.keys(g).forEach(function(n) {
35366
+ var r2 = rc(l.Qa, n);
35367
+ r2 !== 0 && l.tb(g[n], r2);
35368
+ });
35369
+ return true;
35370
+ };
35371
+ c.prototype.Cb = function(g) {
35372
+ for (var l = 0;l < g.length; l += 1)
35373
+ this.tb(g[l], l + 1);
35374
+ return true;
35375
+ };
35376
+ c.prototype.reset = function() {
35377
+ this.freemem();
35378
+ return Cc(this.Qa) === 0 && Bc(this.Qa) === 0;
35379
+ };
35380
+ c.prototype.freemem = function() {
35381
+ for (var g;(g = this.lb.pop()) !== undefined; )
35382
+ fa(g);
35383
+ };
35384
+ c.prototype.free = function() {
35385
+ this.freemem();
35386
+ var g = Dc(this.Qa) === 0;
35387
+ delete this.db.fb[this.Qa];
35388
+ this.Qa = 0;
35389
+ return g;
35390
+ };
35391
+ d.prototype.next = function() {
35392
+ if (this.eb === null)
35393
+ return { done: true };
35394
+ this.Za !== null && (this.Za.free(), this.Za = null);
35395
+ if (!this.db.db)
35396
+ throw this.mb(), Error("Database closed");
35397
+ var g = sa(), l = z2(4);
35398
+ ta(h2);
35399
+ ta(l);
35400
+ try {
35401
+ this.db.handleError(qb(this.db.db, this.kb, -1, h2, l));
35402
+ this.kb = m2(l, "i32");
35403
+ var n = m2(h2, "i32");
35404
+ if (n === 0)
35405
+ return this.mb(), { done: true };
35406
+ this.Za = new c(n, this.db);
35407
+ this.db.fb[n] = this.Za;
35408
+ return { value: this.Za, done: false };
35409
+ } catch (r2) {
35410
+ throw this.pb = ua(this.kb), this.mb(), r2;
35411
+ } finally {
35412
+ wa(g);
35413
+ }
35414
+ };
35415
+ d.prototype.mb = function() {
35416
+ fa(this.eb);
35417
+ this.eb = null;
35418
+ };
35419
+ d.prototype.getRemainingSQL = function() {
35420
+ return this.pb !== null ? this.pb : ua(this.kb);
35421
+ };
35422
+ typeof Symbol === "function" && typeof Symbol.iterator === "symbol" && (d.prototype[Symbol.iterator] = function() {
35423
+ return this;
35424
+ });
35425
+ e2.prototype.run = function(g, l) {
35426
+ if (!this.db)
35427
+ throw "Database closed";
35428
+ if (l) {
35429
+ g = this.prepare(g, l);
35430
+ try {
35431
+ g.step();
35432
+ } finally {
35433
+ g.free();
35264
35434
  }
35265
- } else {
35266
- return;
35435
+ } else
35436
+ this.handleError(v(this.db, g, 0, 0, h2));
35437
+ return this;
35438
+ };
35439
+ e2.prototype.exec = function(g, l, n) {
35440
+ if (!this.db)
35441
+ throw "Database closed";
35442
+ var r2 = sa(), t2 = null;
35443
+ try {
35444
+ var y = xa(g), L = z2(4);
35445
+ for (g = [];m2(y, "i8") !== 0; ) {
35446
+ ta(h2);
35447
+ ta(L);
35448
+ this.handleError(qb(this.db, y, -1, h2, L));
35449
+ var J = m2(h2, "i32");
35450
+ y = m2(L, "i32");
35451
+ if (J !== 0) {
35452
+ var I = null;
35453
+ t2 = new c(J, this);
35454
+ for (l != null && t2.bind(l);t2.step(); )
35455
+ I === null && (I = { columns: t2.getColumnNames(), values: [] }, g.push(I)), I.values.push(t2.get(null, n));
35456
+ t2.free();
35457
+ }
35458
+ }
35459
+ return g;
35460
+ } catch (M) {
35461
+ throw t2 && t2.free(), M;
35462
+ } finally {
35463
+ wa(r2);
35267
35464
  }
35268
- }
35269
- }
35270
- };
35271
- Error.captureStackTrace(dummy);
35272
- dummy.stack;
35273
- Error.prepareStackTrace = origPST;
35274
- Error.stackTraceLimit = origSTL;
35275
- var fileSchema = "file://";
35276
- if (fileName.indexOf(fileSchema) === 0) {
35277
- fileName = fileURLToPath(fileName);
35278
- }
35279
- return fileName;
35280
- };
35281
- exports.getRoot = function getRoot(file2) {
35282
- var dir = dirname2(file2), prev;
35283
- while (true) {
35284
- if (dir === ".") {
35285
- dir = process.cwd();
35465
+ };
35466
+ e2.prototype.each = function(g, l, n, r2, t2) {
35467
+ typeof l === "function" && (r2 = n, n = l, l = undefined);
35468
+ g = this.prepare(g, l);
35469
+ try {
35470
+ for (;g.step(); )
35471
+ n(g.getAsObject(null, t2));
35472
+ } finally {
35473
+ g.free();
35474
+ }
35475
+ if (typeof r2 === "function")
35476
+ return r2();
35477
+ };
35478
+ e2.prototype.prepare = function(g, l) {
35479
+ ta(h2);
35480
+ this.handleError(G(this.db, g, -1, h2, 0));
35481
+ g = m2(h2, "i32");
35482
+ if (g === 0)
35483
+ throw "Nothing to prepare";
35484
+ var n = new c(g, this);
35485
+ l != null && n.bind(l);
35486
+ return this.fb[g] = n;
35487
+ };
35488
+ e2.prototype.iterateStatements = function(g) {
35489
+ return new d(g, this);
35490
+ };
35491
+ e2.prototype["export"] = function() {
35492
+ Object.values(this.fb).forEach(function(l) {
35493
+ l.free();
35494
+ });
35495
+ Object.values(this.Sa).forEach(A2);
35496
+ this.Sa = {};
35497
+ this.handleError(w(this.db));
35498
+ var g = ya(this.filename);
35499
+ this.handleError(q(this.filename, h2));
35500
+ this.db = m2(h2, "i32");
35501
+ ob(this.db);
35502
+ return g;
35503
+ };
35504
+ e2.prototype.close = function() {
35505
+ this.db !== null && (Object.values(this.fb).forEach(function(g) {
35506
+ g.free();
35507
+ }), Object.values(this.Sa).forEach(A2), this.Sa = {}, this.Ya && (A2(this.Ya), this.Ya = undefined), this.handleError(w(this.db)), za("/" + this.filename), this.db = null);
35508
+ };
35509
+ e2.prototype.handleError = function(g) {
35510
+ if (g === 0)
35511
+ return null;
35512
+ g = tc(this.db);
35513
+ throw Error(g);
35514
+ };
35515
+ e2.prototype.getRowsModified = function() {
35516
+ return C(this.db);
35517
+ };
35518
+ e2.prototype.create_function = function(g, l) {
35519
+ Object.prototype.hasOwnProperty.call(this.Sa, g) && (A2(this.Sa[g]), delete this.Sa[g]);
35520
+ var n = Aa(function(r2, t2, y) {
35521
+ t2 = b(t2, y);
35522
+ try {
35523
+ var L = l.apply(null, t2);
35524
+ } catch (J) {
35525
+ va(r2, J, -1);
35526
+ return;
35527
+ }
35528
+ a(r2, L);
35529
+ }, "viii");
35530
+ this.Sa[g] = n;
35531
+ this.handleError(tb(this.db, g, l.length, 1, 0, n, 0, 0, 0));
35532
+ return this;
35533
+ };
35534
+ e2.prototype.create_aggregate = function(g, l) {
35535
+ var n = l.init || function() {
35536
+ return null;
35537
+ }, r2 = l.finalize || function(I) {
35538
+ return I;
35539
+ }, t2 = l.step;
35540
+ if (!t2)
35541
+ throw "An aggregate function must have a step function in " + g;
35542
+ var y = {};
35543
+ Object.hasOwnProperty.call(this.Sa, g) && (A2(this.Sa[g]), delete this.Sa[g]);
35544
+ l = g + "__finalize";
35545
+ Object.hasOwnProperty.call(this.Sa, l) && (A2(this.Sa[l]), delete this.Sa[l]);
35546
+ var L = Aa(function(I, M, Ra) {
35547
+ var X = ub(I, 1);
35548
+ Object.hasOwnProperty.call(y, X) || (y[X] = n());
35549
+ M = b(M, Ra);
35550
+ M = [y[X]].concat(M);
35551
+ try {
35552
+ y[X] = t2.apply(null, M);
35553
+ } catch (Fc) {
35554
+ delete y[X], va(I, Fc, -1);
35555
+ }
35556
+ }, "viii"), J = Aa(function(I) {
35557
+ var M = ub(I, 1);
35558
+ try {
35559
+ var Ra = r2(y[M]);
35560
+ } catch (X) {
35561
+ delete y[M];
35562
+ va(I, X, -1);
35563
+ return;
35564
+ }
35565
+ a(I, Ra);
35566
+ delete y[M];
35567
+ }, "vi");
35568
+ this.Sa[g] = L;
35569
+ this.Sa[l] = J;
35570
+ this.handleError(tb(this.db, g, t2.length - 1, 1, 0, 0, L, J, 0));
35571
+ return this;
35572
+ };
35573
+ e2.prototype.updateHook = function(g) {
35574
+ this.Ya && (vb(this.db, 0, 0), A2(this.Ya), this.Ya = undefined);
35575
+ g && (this.Ya = Aa(function(l, n, r2, t2, y) {
35576
+ switch (n) {
35577
+ case 18:
35578
+ l = "insert";
35579
+ break;
35580
+ case 23:
35581
+ l = "update";
35582
+ break;
35583
+ case 9:
35584
+ l = "delete";
35585
+ break;
35586
+ default:
35587
+ throw "unknown operationCode in updateHook callback: " + n;
35588
+ }
35589
+ r2 = r2 ? B(x2, r2) : "";
35590
+ t2 = t2 ? B(x2, t2) : "";
35591
+ if (y > Number.MAX_SAFE_INTEGER)
35592
+ throw "rowId too big to fit inside a Number";
35593
+ g(l, r2, t2, Number(y));
35594
+ }, "viiiij"), vb(this.db, this.Ya, 0));
35595
+ };
35596
+ f3.Database = e2;
35597
+ };
35598
+ var Ba = { ...f3 }, Ca = "./this.program", Da = (a, b) => {
35599
+ throw b;
35600
+ }, D = "", Ea, Fa;
35601
+ if (ca) {
35602
+ var fs4 = __require("fs");
35603
+ __require("path");
35604
+ D = __dirname + "/";
35605
+ Fa = (a) => {
35606
+ a = Ga(a) ? new URL(a) : a;
35607
+ return fs4.readFileSync(a);
35608
+ };
35609
+ Ea = async (a) => {
35610
+ a = Ga(a) ? new URL(a) : a;
35611
+ return fs4.readFileSync(a, undefined);
35612
+ };
35613
+ !f3.thisProgram && 1 < process.argv.length && (Ca = process.argv[1].replace(/\\/g, "/"));
35614
+ process.argv.slice(2);
35615
+ typeof module != "undefined" && (module.exports = f3);
35616
+ Da = (a, b) => {
35617
+ process.exitCode = a;
35618
+ throw b;
35619
+ };
35620
+ } else if (aa || ba)
35621
+ 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) => {
35622
+ var b = new XMLHttpRequest;
35623
+ b.open("GET", a, false);
35624
+ b.responseType = "arraybuffer";
35625
+ b.send(null);
35626
+ return new Uint8Array(b.response);
35627
+ }), Ea = async (a) => {
35628
+ if (Ga(a))
35629
+ return new Promise((c, d) => {
35630
+ var e2 = new XMLHttpRequest;
35631
+ e2.open("GET", a, true);
35632
+ e2.responseType = "arraybuffer";
35633
+ e2.onload = () => {
35634
+ e2.status == 200 || e2.status == 0 && e2.response ? c(e2.response) : d(e2.status);
35635
+ };
35636
+ e2.onerror = d;
35637
+ e2.send(null);
35638
+ });
35639
+ var b = await fetch(a, { credentials: "same-origin" });
35640
+ if (b.ok)
35641
+ return b.arrayBuffer();
35642
+ throw Error(b.status + " : " + b.url);
35643
+ };
35644
+ var Ha = f3.print || console.log.bind(console), Ia = f3.printErr || console.error.bind(console);
35645
+ Object.assign(f3, Ba);
35646
+ Ba = null;
35647
+ f3.thisProgram && (Ca = f3.thisProgram);
35648
+ var Ja = f3.wasmBinary, Ka, La = false, Ma, p, x2, Na, E, F2, Oa, H, Pa, Ga = (a) => a.startsWith("file://");
35649
+ function Qa() {
35650
+ var a = Ka.buffer;
35651
+ f3.HEAP8 = p = new Int8Array(a);
35652
+ f3.HEAP16 = Na = new Int16Array(a);
35653
+ f3.HEAPU8 = x2 = new Uint8Array(a);
35654
+ f3.HEAPU16 = new Uint16Array(a);
35655
+ f3.HEAP32 = E = new Int32Array(a);
35656
+ f3.HEAPU32 = F2 = new Uint32Array(a);
35657
+ f3.HEAPF32 = Oa = new Float32Array(a);
35658
+ f3.HEAPF64 = Pa = new Float64Array(a);
35659
+ f3.HEAP64 = H = new BigInt64Array(a);
35660
+ f3.HEAPU64 = new BigUint64Array(a);
35661
+ }
35662
+ var K = 0, Sa = null;
35663
+ function Ta(a) {
35664
+ f3.onAbort?.(a);
35665
+ a = "Aborted(" + a + ")";
35666
+ Ia(a);
35667
+ La = true;
35668
+ throw new WebAssembly.RuntimeError(a + ". Build with -sASSERTIONS for more info.");
35669
+ }
35670
+ var Ua;
35671
+ async function Va(a) {
35672
+ if (!Ja)
35673
+ try {
35674
+ var b = await Ea(a);
35675
+ return new Uint8Array(b);
35676
+ } catch {}
35677
+ if (a == Ua && Ja)
35678
+ a = new Uint8Array(Ja);
35679
+ else if (Fa)
35680
+ a = Fa(a);
35681
+ else
35682
+ throw "both async and sync fetching of the wasm failed";
35683
+ return a;
35286
35684
  }
35287
- if (exists(join3(dir, "package.json")) || exists(join3(dir, "node_modules"))) {
35288
- return dir;
35685
+ async function Wa(a, b) {
35686
+ try {
35687
+ var c = await Va(a);
35688
+ return await WebAssembly.instantiate(c, b);
35689
+ } catch (d) {
35690
+ Ia(`failed to asynchronously prepare wasm: ${d}`), Ta(d);
35691
+ }
35289
35692
  }
35290
- if (prev === dir) {
35291
- throw new Error('Could not find module root given file: "' + file2 + '". Do you have a `package.json` file? ');
35693
+ async function Xa(a) {
35694
+ var b = Ua;
35695
+ if (!Ja && typeof WebAssembly.instantiateStreaming == "function" && !Ga(b) && !ca)
35696
+ try {
35697
+ var c = fetch(b, { credentials: "same-origin" });
35698
+ return await WebAssembly.instantiateStreaming(c, a);
35699
+ } catch (d) {
35700
+ Ia(`wasm streaming compile failed: ${d}`), Ia("falling back to ArrayBuffer instantiation");
35701
+ }
35702
+ return Wa(b, a);
35292
35703
  }
35293
- prev = dir;
35294
- dir = join3(dir, "..");
35295
- }
35296
- };
35297
- });
35298
-
35299
- // ../../node_modules/better-sqlite3/lib/methods/wrappers.js
35300
- var require_wrappers = __commonJS((exports) => {
35301
- var { cppdb } = require_util3();
35302
- exports.prepare = function prepare(sql) {
35303
- return this[cppdb].prepare(sql, this, false);
35304
- };
35305
- exports.exec = function exec(sql) {
35306
- this[cppdb].exec(sql);
35307
- return this;
35308
- };
35309
- exports.close = function close() {
35310
- this[cppdb].close();
35311
- return this;
35312
- };
35313
- exports.loadExtension = function loadExtension(...args) {
35314
- this[cppdb].loadExtension(...args);
35315
- return this;
35316
- };
35317
- exports.defaultSafeIntegers = function defaultSafeIntegers(...args) {
35318
- this[cppdb].defaultSafeIntegers(...args);
35319
- return this;
35320
- };
35321
- exports.unsafeMode = function unsafeMode(...args) {
35322
- this[cppdb].unsafeMode(...args);
35323
- return this;
35324
- };
35325
- exports.getters = {
35326
- name: {
35327
- get: function name() {
35328
- return this[cppdb].name;
35329
- },
35330
- enumerable: true
35331
- },
35332
- open: {
35333
- get: function open() {
35334
- return this[cppdb].open;
35335
- },
35336
- enumerable: true
35337
- },
35338
- inTransaction: {
35339
- get: function inTransaction() {
35340
- return this[cppdb].inTransaction;
35341
- },
35342
- enumerable: true
35343
- },
35344
- readonly: {
35345
- get: function readonly() {
35346
- return this[cppdb].readonly;
35347
- },
35348
- enumerable: true
35349
- },
35350
- memory: {
35351
- get: function memory() {
35352
- return this[cppdb].memory;
35353
- },
35354
- enumerable: true
35355
- }
35356
- };
35357
- });
35358
35704
 
35359
- // ../../node_modules/better-sqlite3/lib/methods/transaction.js
35360
- var require_transaction = __commonJS((exports, module) => {
35361
- var { cppdb } = require_util3();
35362
- var controllers = new WeakMap;
35363
- module.exports = function transaction(fn) {
35364
- if (typeof fn !== "function")
35365
- throw new TypeError("Expected first argument to be a function");
35366
- const db2 = this[cppdb];
35367
- const controller = getController(db2, this);
35368
- const { apply: apply2 } = Function.prototype;
35369
- const properties = {
35370
- default: { value: wrapTransaction(apply2, fn, db2, controller.default) },
35371
- deferred: { value: wrapTransaction(apply2, fn, db2, controller.deferred) },
35372
- immediate: { value: wrapTransaction(apply2, fn, db2, controller.immediate) },
35373
- exclusive: { value: wrapTransaction(apply2, fn, db2, controller.exclusive) },
35374
- database: { value: this, enumerable: true }
35375
- };
35376
- Object.defineProperties(properties.default.value, properties);
35377
- Object.defineProperties(properties.deferred.value, properties);
35378
- Object.defineProperties(properties.immediate.value, properties);
35379
- Object.defineProperties(properties.exclusive.value, properties);
35380
- return properties.default.value;
35381
- };
35382
- var getController = (db2, self2) => {
35383
- let controller = controllers.get(db2);
35384
- if (!controller) {
35385
- const shared = {
35386
- commit: db2.prepare("COMMIT", self2, false),
35387
- rollback: db2.prepare("ROLLBACK", self2, false),
35388
- savepoint: db2.prepare("SAVEPOINT `\t_bs3.\t`", self2, false),
35389
- release: db2.prepare("RELEASE `\t_bs3.\t`", self2, false),
35390
- rollbackTo: db2.prepare("ROLLBACK TO `\t_bs3.\t`", self2, false)
35391
- };
35392
- controllers.set(db2, controller = {
35393
- default: Object.assign({ begin: db2.prepare("BEGIN", self2, false) }, shared),
35394
- deferred: Object.assign({ begin: db2.prepare("BEGIN DEFERRED", self2, false) }, shared),
35395
- immediate: Object.assign({ begin: db2.prepare("BEGIN IMMEDIATE", self2, false) }, shared),
35396
- exclusive: Object.assign({ begin: db2.prepare("BEGIN EXCLUSIVE", self2, false) }, shared)
35397
- });
35398
- }
35399
- return controller;
35400
- };
35401
- var wrapTransaction = (apply2, fn, db2, { begin, commit, rollback, savepoint, release, rollbackTo }) => function sqliteTransaction() {
35402
- let before, after, undo;
35403
- if (db2.inTransaction) {
35404
- before = savepoint;
35405
- after = release;
35406
- undo = rollbackTo;
35407
- } else {
35408
- before = begin;
35409
- after = commit;
35410
- undo = rollback;
35411
- }
35412
- before.run();
35413
- try {
35414
- const result = apply2.call(fn, this, arguments);
35415
- if (result && typeof result.then === "function") {
35416
- throw new TypeError("Transaction function cannot return a promise");
35705
+ class Ya {
35706
+ name = "ExitStatus";
35707
+ constructor(a) {
35708
+ this.message = `Program terminated with exit(${a})`;
35709
+ this.status = a;
35710
+ }
35417
35711
  }
35418
- after.run();
35419
- return result;
35420
- } catch (ex) {
35421
- if (db2.inTransaction) {
35422
- undo.run();
35423
- if (undo !== rollback)
35424
- after.run();
35712
+ var Za = (a) => {
35713
+ for (;0 < a.length; )
35714
+ a.shift()(f3);
35715
+ }, $a = [], ab = [], bb = () => {
35716
+ var a = f3.preRun.shift();
35717
+ ab.unshift(a);
35718
+ };
35719
+ function m2(a, b = "i8") {
35720
+ b.endsWith("*") && (b = "*");
35721
+ switch (b) {
35722
+ case "i1":
35723
+ return p[a];
35724
+ case "i8":
35725
+ return p[a];
35726
+ case "i16":
35727
+ return Na[a >> 1];
35728
+ case "i32":
35729
+ return E[a >> 2];
35730
+ case "i64":
35731
+ return H[a >> 3];
35732
+ case "float":
35733
+ return Oa[a >> 2];
35734
+ case "double":
35735
+ return Pa[a >> 3];
35736
+ case "*":
35737
+ return F2[a >> 2];
35738
+ default:
35739
+ Ta(`invalid type for getValue: ${b}`);
35740
+ }
35425
35741
  }
35426
- throw ex;
35427
- }
35428
- };
35429
- });
35430
-
35431
- // ../../node_modules/better-sqlite3/lib/methods/pragma.js
35432
- var require_pragma = __commonJS((exports, module) => {
35433
- var { getBooleanOption, cppdb } = require_util3();
35434
- module.exports = function pragma(source, options) {
35435
- if (options == null)
35436
- options = {};
35437
- if (typeof source !== "string")
35438
- throw new TypeError("Expected first argument to be a string");
35439
- if (typeof options !== "object")
35440
- throw new TypeError("Expected second argument to be an options object");
35441
- const simple = getBooleanOption(options, "simple");
35442
- const stmt = this[cppdb].prepare(`PRAGMA ${source}`, this, true);
35443
- return simple ? stmt.pluck().get() : stmt.all();
35444
- };
35445
- });
35446
-
35447
- // ../../node_modules/better-sqlite3/lib/methods/backup.js
35448
- var require_backup = __commonJS((exports, module) => {
35449
- var fs4 = __require("fs");
35450
- var path = __require("path");
35451
- var { promisify: promisify2 } = __require("util");
35452
- var { cppdb } = require_util3();
35453
- var fsAccess = promisify2(fs4.access);
35454
- module.exports = async function backup(filename, options) {
35455
- if (options == null)
35456
- options = {};
35457
- if (typeof filename !== "string")
35458
- throw new TypeError("Expected first argument to be a string");
35459
- if (typeof options !== "object")
35460
- throw new TypeError("Expected second argument to be an options object");
35461
- filename = filename.trim();
35462
- const attachedName = "attached" in options ? options.attached : "main";
35463
- const handler13 = "progress" in options ? options.progress : null;
35464
- if (!filename)
35465
- throw new TypeError("Backup filename cannot be an empty string");
35466
- if (filename === ":memory:")
35467
- throw new TypeError('Invalid backup filename ":memory:"');
35468
- if (typeof attachedName !== "string")
35469
- throw new TypeError('Expected the "attached" option to be a string');
35470
- if (!attachedName)
35471
- throw new TypeError('The "attached" option cannot be an empty string');
35472
- if (handler13 != null && typeof handler13 !== "function")
35473
- throw new TypeError('Expected the "progress" option to be a function');
35474
- await fsAccess(path.dirname(filename)).catch(() => {
35475
- throw new TypeError("Cannot save backup because the directory does not exist");
35476
- });
35477
- const isNewFile = await fsAccess(filename).then(() => false, () => true);
35478
- return runBackup(this[cppdb].backup(this, attachedName, filename, isNewFile), handler13 || null);
35479
- };
35480
- var runBackup = (backup, handler13) => {
35481
- let rate = 0;
35482
- let useDefault = true;
35483
- return new Promise((resolve4, reject) => {
35484
- setImmediate(function step() {
35485
- try {
35486
- const progress = backup.transfer(rate);
35487
- if (!progress.remainingPages) {
35488
- backup.close();
35489
- resolve4(progress);
35490
- return;
35742
+ var cb = f3.noExitRuntime || true;
35743
+ function ta(a) {
35744
+ var b = "i32";
35745
+ b.endsWith("*") && (b = "*");
35746
+ switch (b) {
35747
+ case "i1":
35748
+ p[a] = 0;
35749
+ break;
35750
+ case "i8":
35751
+ p[a] = 0;
35752
+ break;
35753
+ case "i16":
35754
+ Na[a >> 1] = 0;
35755
+ break;
35756
+ case "i32":
35757
+ E[a >> 2] = 0;
35758
+ break;
35759
+ case "i64":
35760
+ H[a >> 3] = BigInt(0);
35761
+ break;
35762
+ case "float":
35763
+ Oa[a >> 2] = 0;
35764
+ break;
35765
+ case "double":
35766
+ Pa[a >> 3] = 0;
35767
+ break;
35768
+ case "*":
35769
+ F2[a >> 2] = 0;
35770
+ break;
35771
+ default:
35772
+ Ta(`invalid type for setValue: ${b}`);
35773
+ }
35774
+ }
35775
+ var db2 = typeof TextDecoder != "undefined" ? new TextDecoder : undefined, B = (a, b = 0, c = NaN) => {
35776
+ var d = b + c;
35777
+ for (c = b;a[c] && !(c >= d); )
35778
+ ++c;
35779
+ if (16 < c - b && a.buffer && db2)
35780
+ return db2.decode(a.subarray(b, c));
35781
+ for (d = "";b < c; ) {
35782
+ var e2 = a[b++];
35783
+ if (e2 & 128) {
35784
+ var h2 = a[b++] & 63;
35785
+ if ((e2 & 224) == 192)
35786
+ d += String.fromCharCode((e2 & 31) << 6 | h2);
35787
+ else {
35788
+ var k = a[b++] & 63;
35789
+ e2 = (e2 & 240) == 224 ? (e2 & 15) << 12 | h2 << 6 | k : (e2 & 7) << 18 | h2 << 12 | k << 6 | a[b++] & 63;
35790
+ 65536 > e2 ? d += String.fromCharCode(e2) : (e2 -= 65536, d += String.fromCharCode(55296 | e2 >> 10, 56320 | e2 & 1023));
35791
+ }
35792
+ } else
35793
+ d += String.fromCharCode(e2);
35794
+ }
35795
+ return d;
35796
+ }, ua = (a, b) => a ? B(x2, a, b) : "", eb = (a, b) => {
35797
+ for (var c = 0, d = a.length - 1;0 <= d; d--) {
35798
+ var e2 = a[d];
35799
+ e2 === "." ? a.splice(d, 1) : e2 === ".." ? (a.splice(d, 1), c++) : c && (a.splice(d, 1), c--);
35800
+ }
35801
+ if (b)
35802
+ for (;c; c--)
35803
+ a.unshift("..");
35804
+ return a;
35805
+ }, ka = (a) => {
35806
+ var b = a.charAt(0) === "/", c = a.slice(-1) === "/";
35807
+ (a = eb(a.split("/").filter((d) => !!d), !b).join("/")) || b || (a = ".");
35808
+ a && c && (a += "/");
35809
+ return (b ? "/" : "") + a;
35810
+ }, fb = (a) => {
35811
+ var b = /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/.exec(a).slice(1);
35812
+ a = b[0];
35813
+ b = b[1];
35814
+ if (!a && !b)
35815
+ return ".";
35816
+ b &&= b.slice(0, -1);
35817
+ return a + b;
35818
+ }, gb = (a) => a && a.match(/([^\/]+|\/)\/*$/)[1], hb = () => {
35819
+ if (ca) {
35820
+ var a = __require("crypto");
35821
+ return (b) => a.randomFillSync(b);
35822
+ }
35823
+ return (b) => crypto.getRandomValues(b);
35824
+ }, ib = (a) => {
35825
+ (ib = hb())(a);
35826
+ }, jb = (...a) => {
35827
+ for (var b = "", c = false, d = a.length - 1;-1 <= d && !c; d--) {
35828
+ c = 0 <= d ? a[d] : "/";
35829
+ if (typeof c != "string")
35830
+ throw new TypeError("Arguments to path.resolve must be strings");
35831
+ if (!c)
35832
+ return "";
35833
+ b = c + "/" + b;
35834
+ c = c.charAt(0) === "/";
35835
+ }
35836
+ b = eb(b.split("/").filter((e2) => !!e2), !c).join("/");
35837
+ return (c ? "/" : "") + b || ".";
35838
+ }, kb = [], ha = (a) => {
35839
+ for (var b = 0, c = 0;c < a.length; ++c) {
35840
+ var d = a.charCodeAt(c);
35841
+ 127 >= d ? b++ : 2047 >= d ? b += 2 : 55296 <= d && 57343 >= d ? (b += 4, ++c) : b += 3;
35842
+ }
35843
+ return b;
35844
+ }, u = (a, b, c, d) => {
35845
+ if (!(0 < d))
35846
+ return 0;
35847
+ var e2 = c;
35848
+ d = c + d - 1;
35849
+ for (var h2 = 0;h2 < a.length; ++h2) {
35850
+ var k = a.charCodeAt(h2);
35851
+ if (55296 <= k && 57343 >= k) {
35852
+ var q = a.charCodeAt(++h2);
35853
+ k = 65536 + ((k & 1023) << 10) | q & 1023;
35491
35854
  }
35492
- if (useDefault) {
35493
- useDefault = false;
35494
- rate = 100;
35855
+ if (127 >= k) {
35856
+ if (c >= d)
35857
+ break;
35858
+ b[c++] = k;
35859
+ } else {
35860
+ if (2047 >= k) {
35861
+ if (c + 1 >= d)
35862
+ break;
35863
+ b[c++] = 192 | k >> 6;
35864
+ } else {
35865
+ if (65535 >= k) {
35866
+ if (c + 2 >= d)
35867
+ break;
35868
+ b[c++] = 224 | k >> 12;
35869
+ } else {
35870
+ if (c + 3 >= d)
35871
+ break;
35872
+ b[c++] = 240 | k >> 18;
35873
+ b[c++] = 128 | k >> 12 & 63;
35874
+ }
35875
+ b[c++] = 128 | k >> 6 & 63;
35876
+ }
35877
+ b[c++] = 128 | k & 63;
35495
35878
  }
35496
- if (handler13) {
35497
- const ret = handler13(progress);
35498
- if (ret !== undefined) {
35499
- if (typeof ret === "number" && ret === ret)
35500
- rate = Math.max(0, Math.min(2147483647, Math.round(ret)));
35501
- else
35502
- throw new TypeError("Expected progress callback to return a number or undefined");
35879
+ }
35880
+ b[c] = 0;
35881
+ return c - e2;
35882
+ }, ra = (a, b) => {
35883
+ var c = Array(ha(a) + 1);
35884
+ a = u(a, c, 0, c.length);
35885
+ b && (c.length = a);
35886
+ return c;
35887
+ }, mb = [];
35888
+ function nb(a, b) {
35889
+ mb[a] = { input: [], output: [], cb: b };
35890
+ wb(a, xb);
35891
+ }
35892
+ var xb = { open(a) {
35893
+ var b = mb[a.node.rdev];
35894
+ if (!b)
35895
+ throw new N(43);
35896
+ a.tty = b;
35897
+ a.seekable = false;
35898
+ }, close(a) {
35899
+ a.tty.cb.fsync(a.tty);
35900
+ }, fsync(a) {
35901
+ a.tty.cb.fsync(a.tty);
35902
+ }, read(a, b, c, d) {
35903
+ if (!a.tty || !a.tty.cb.xb)
35904
+ throw new N(60);
35905
+ for (var e2 = 0, h2 = 0;h2 < d; h2++) {
35906
+ try {
35907
+ var k = a.tty.cb.xb(a.tty);
35908
+ } catch (q) {
35909
+ throw new N(29);
35910
+ }
35911
+ if (k === undefined && e2 === 0)
35912
+ throw new N(6);
35913
+ if (k === null || k === undefined)
35914
+ break;
35915
+ e2++;
35916
+ b[c + h2] = k;
35917
+ }
35918
+ e2 && (a.node.atime = Date.now());
35919
+ return e2;
35920
+ }, write(a, b, c, d) {
35921
+ if (!a.tty || !a.tty.cb.qb)
35922
+ throw new N(60);
35923
+ try {
35924
+ for (var e2 = 0;e2 < d; e2++)
35925
+ a.tty.cb.qb(a.tty, b[c + e2]);
35926
+ } catch (h2) {
35927
+ throw new N(29);
35928
+ }
35929
+ d && (a.node.mtime = a.node.ctime = Date.now());
35930
+ return e2;
35931
+ } }, yb = { xb() {
35932
+ a: {
35933
+ if (!kb.length) {
35934
+ var a = null;
35935
+ if (ca) {
35936
+ var b = Buffer.alloc(256), c = 0, d = process.stdin.fd;
35937
+ try {
35938
+ c = fs4.readSync(d, b, 0, 256);
35939
+ } catch (e2) {
35940
+ if (e2.toString().includes("EOF"))
35941
+ c = 0;
35942
+ else
35943
+ throw e2;
35944
+ }
35945
+ 0 < c && (a = b.slice(0, c).toString("utf-8"));
35946
+ } else
35947
+ typeof window != "undefined" && typeof window.prompt == "function" && (a = window.prompt("Input: "), a !== null && (a += `
35948
+ `));
35949
+ if (!a) {
35950
+ a = null;
35951
+ break a;
35503
35952
  }
35953
+ kb = ra(a, true);
35504
35954
  }
35505
- setImmediate(step);
35506
- } catch (err) {
35507
- backup.close();
35508
- reject(err);
35955
+ a = kb.shift();
35956
+ }
35957
+ return a;
35958
+ }, qb(a, b) {
35959
+ b === null || b === 10 ? (Ha(B(a.output)), a.output = []) : b != 0 && a.output.push(b);
35960
+ }, fsync(a) {
35961
+ 0 < a.output?.length && (Ha(B(a.output)), a.output = []);
35962
+ }, Tb() {
35963
+ 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] };
35964
+ }, Ub() {
35965
+ return 0;
35966
+ }, Vb() {
35967
+ return [24, 80];
35968
+ } }, zb = { qb(a, b) {
35969
+ b === null || b === 10 ? (Ia(B(a.output)), a.output = []) : b != 0 && a.output.push(b);
35970
+ }, fsync(a) {
35971
+ 0 < a.output?.length && (Ia(B(a.output)), a.output = []);
35972
+ } }, O = { Wa: null, Xa() {
35973
+ return O.createNode(null, "/", 16895, 0);
35974
+ }, createNode(a, b, c, d) {
35975
+ if ((c & 61440) === 24576 || (c & 61440) === 4096)
35976
+ throw new N(63);
35977
+ 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 } });
35978
+ c = Bb(a, b, c, d);
35979
+ 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);
35980
+ c.atime = c.mtime = c.ctime = Date.now();
35981
+ a && (a.Na[b] = c, a.atime = a.mtime = a.ctime = c.atime);
35982
+ return c;
35983
+ }, Sb(a) {
35984
+ return a.Na ? a.Na.subarray ? a.Na.subarray(0, a.Ra) : new Uint8Array(a.Na) : new Uint8Array(0);
35985
+ }, La: { Ta(a) {
35986
+ var b = {};
35987
+ b.dev = (a.mode & 61440) === 8192 ? a.id : 1;
35988
+ b.ino = a.id;
35989
+ b.mode = a.mode;
35990
+ b.nlink = 1;
35991
+ b.uid = 0;
35992
+ b.gid = 0;
35993
+ b.rdev = a.rdev;
35994
+ 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;
35995
+ b.atime = new Date(a.atime);
35996
+ b.mtime = new Date(a.mtime);
35997
+ b.ctime = new Date(a.ctime);
35998
+ b.blksize = 4096;
35999
+ b.blocks = Math.ceil(b.size / b.blksize);
36000
+ return b;
36001
+ }, Ua(a, b) {
36002
+ for (var c of ["mode", "atime", "mtime", "ctime"])
36003
+ b[c] != null && (a[c] = b[c]);
36004
+ 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)));
36005
+ }, lookup() {
36006
+ throw O.vb;
36007
+ }, hb(a, b, c, d) {
36008
+ return O.createNode(a, b, c, d);
36009
+ }, rename(a, b, c) {
36010
+ try {
36011
+ var d = Q(b, c);
36012
+ } catch (h2) {}
36013
+ if (d) {
36014
+ if (P(a.mode))
36015
+ for (var e2 in d.Na)
36016
+ throw new N(55);
36017
+ Cb(d);
36018
+ }
36019
+ delete a.parent.Na[a.name];
36020
+ b.Na[c] = a;
36021
+ a.name = c;
36022
+ b.ctime = b.mtime = a.parent.ctime = a.parent.mtime = Date.now();
36023
+ }, unlink(a, b) {
36024
+ delete a.Na[b];
36025
+ a.ctime = a.mtime = Date.now();
36026
+ }, rmdir(a, b) {
36027
+ var c = Q(a, b), d;
36028
+ for (d in c.Na)
36029
+ throw new N(55);
36030
+ delete a.Na[b];
36031
+ a.ctime = a.mtime = Date.now();
36032
+ }, readdir(a) {
36033
+ return [".", "..", ...Object.keys(a.Na)];
36034
+ }, symlink(a, b, c) {
36035
+ a = O.createNode(a, b, 41471, 0);
36036
+ a.link = c;
36037
+ return a;
36038
+ }, readlink(a) {
36039
+ if ((a.mode & 61440) !== 40960)
36040
+ throw new N(28);
36041
+ return a.link;
36042
+ } }, Ma: { read(a, b, c, d, e2) {
36043
+ var h2 = a.node.Na;
36044
+ if (e2 >= a.node.Ra)
36045
+ return 0;
36046
+ a = Math.min(a.node.Ra - e2, d);
36047
+ if (8 < a && h2.subarray)
36048
+ b.set(h2.subarray(e2, e2 + a), c);
36049
+ else
36050
+ for (d = 0;d < a; d++)
36051
+ b[c + d] = h2[e2 + d];
36052
+ return a;
36053
+ }, write(a, b, c, d, e2, h2) {
36054
+ b.buffer === p.buffer && (h2 = false);
36055
+ if (!d)
36056
+ return 0;
36057
+ a = a.node;
36058
+ a.mtime = a.ctime = Date.now();
36059
+ if (b.subarray && (!a.Na || a.Na.subarray)) {
36060
+ if (h2)
36061
+ return a.Na = b.subarray(c, c + d), a.Ra = d;
36062
+ if (a.Ra === 0 && e2 === 0)
36063
+ return a.Na = b.slice(c, c + d), a.Ra = d;
36064
+ if (e2 + d <= a.Ra)
36065
+ return a.Na.set(b.subarray(c, c + d), e2), d;
36066
+ }
36067
+ h2 = e2 + d;
36068
+ var k = a.Na ? a.Na.length : 0;
36069
+ k >= h2 || (h2 = Math.max(h2, k * (1048576 > k ? 2 : 1.125) >>> 0), k != 0 && (h2 = Math.max(h2, 256)), k = a.Na, a.Na = new Uint8Array(h2), 0 < a.Ra && a.Na.set(k.subarray(0, a.Ra), 0));
36070
+ if (a.Na.subarray && b.subarray)
36071
+ a.Na.set(b.subarray(c, c + d), e2);
36072
+ else
36073
+ for (h2 = 0;h2 < d; h2++)
36074
+ a.Na[e2 + h2] = b[c + h2];
36075
+ a.Ra = Math.max(a.Ra, e2 + d);
36076
+ return d;
36077
+ }, Va(a, b, c) {
36078
+ c === 1 ? b += a.position : c === 2 && (a.node.mode & 61440) === 32768 && (b += a.node.Ra);
36079
+ if (0 > b)
36080
+ throw new N(28);
36081
+ return b;
36082
+ }, ib(a, b, c, d, e2) {
36083
+ if ((a.node.mode & 61440) !== 32768)
36084
+ throw new N(43);
36085
+ a = a.node.Na;
36086
+ if (e2 & 2 || !a || a.buffer !== p.buffer) {
36087
+ e2 = true;
36088
+ d = 65536 * Math.ceil(b / 65536);
36089
+ var h2 = Db(65536, d);
36090
+ h2 && x2.fill(0, h2, h2 + d);
36091
+ d = h2;
36092
+ if (!d)
36093
+ throw new N(48);
36094
+ if (a) {
36095
+ if (0 < c || c + b < a.length)
36096
+ a.subarray ? a = a.subarray(c, c + b) : a = Array.prototype.slice.call(a, c, c + b);
36097
+ p.set(a, d);
36098
+ }
36099
+ } else
36100
+ e2 = false, d = a.byteOffset;
36101
+ return { Kb: d, Ab: e2 };
36102
+ }, jb(a, b, c, d) {
36103
+ O.Ma.write(a, b, 0, d, c, false);
36104
+ return 0;
36105
+ } } }, la = (a, b) => {
36106
+ var c = 0;
36107
+ a && (c |= 365);
36108
+ b && (c |= 146);
36109
+ return c;
36110
+ }, Eb = null, Fb = {}, Gb = [], Hb = 1, R = null, Ib = false, Jb = true, Kb = {}, N = class {
36111
+ name = "ErrnoError";
36112
+ constructor(a) {
36113
+ this.Pa = a;
36114
+ }
36115
+ }, Lb = class {
36116
+ gb = {};
36117
+ node = null;
36118
+ get flags() {
36119
+ return this.gb.flags;
36120
+ }
36121
+ set flags(a) {
36122
+ this.gb.flags = a;
36123
+ }
36124
+ get position() {
36125
+ return this.gb.position;
36126
+ }
36127
+ set position(a) {
36128
+ this.gb.position = a;
36129
+ }
36130
+ }, Mb = class {
36131
+ La = {};
36132
+ Ma = {};
36133
+ ab = null;
36134
+ constructor(a, b, c, d) {
36135
+ a ||= this;
36136
+ this.parent = a;
36137
+ this.Xa = a.Xa;
36138
+ this.id = Hb++;
36139
+ this.name = b;
36140
+ this.mode = c;
36141
+ this.rdev = d;
36142
+ this.atime = this.mtime = this.ctime = Date.now();
36143
+ }
36144
+ get read() {
36145
+ return (this.mode & 365) === 365;
36146
+ }
36147
+ set read(a) {
36148
+ a ? this.mode |= 365 : this.mode &= -366;
36149
+ }
36150
+ get write() {
36151
+ return (this.mode & 146) === 146;
36152
+ }
36153
+ set write(a) {
36154
+ a ? this.mode |= 146 : this.mode &= -147;
35509
36155
  }
35510
- });
35511
- });
35512
- };
35513
- });
35514
-
35515
- // ../../node_modules/better-sqlite3/lib/methods/serialize.js
35516
- var require_serialize = __commonJS((exports, module) => {
35517
- var { cppdb } = require_util3();
35518
- module.exports = function serialize(options) {
35519
- if (options == null)
35520
- options = {};
35521
- if (typeof options !== "object")
35522
- throw new TypeError("Expected first argument to be an options object");
35523
- const attachedName = "attached" in options ? options.attached : "main";
35524
- if (typeof attachedName !== "string")
35525
- throw new TypeError('Expected the "attached" option to be a string');
35526
- if (!attachedName)
35527
- throw new TypeError('The "attached" option cannot be an empty string');
35528
- return this[cppdb].serialize(attachedName);
35529
- };
35530
- });
35531
-
35532
- // ../../node_modules/better-sqlite3/lib/methods/function.js
35533
- var require_function = __commonJS((exports, module) => {
35534
- var { getBooleanOption, cppdb } = require_util3();
35535
- module.exports = function defineFunction(name17, options, fn) {
35536
- if (options == null)
35537
- options = {};
35538
- if (typeof options === "function") {
35539
- fn = options;
35540
- options = {};
35541
- }
35542
- if (typeof name17 !== "string")
35543
- throw new TypeError("Expected first argument to be a string");
35544
- if (typeof fn !== "function")
35545
- throw new TypeError("Expected last argument to be a function");
35546
- if (typeof options !== "object")
35547
- throw new TypeError("Expected second argument to be an options object");
35548
- if (!name17)
35549
- throw new TypeError("User-defined function name cannot be an empty string");
35550
- const safeIntegers = "safeIntegers" in options ? +getBooleanOption(options, "safeIntegers") : 2;
35551
- const deterministic = getBooleanOption(options, "deterministic");
35552
- const directOnly = getBooleanOption(options, "directOnly");
35553
- const varargs = getBooleanOption(options, "varargs");
35554
- let argCount = -1;
35555
- if (!varargs) {
35556
- argCount = fn.length;
35557
- if (!Number.isInteger(argCount) || argCount < 0)
35558
- throw new TypeError("Expected function.length to be a positive integer");
35559
- if (argCount > 100)
35560
- throw new RangeError("User-defined functions cannot have more than 100 arguments");
35561
- }
35562
- this[cppdb].function(fn, name17, argCount, safeIntegers, deterministic, directOnly);
35563
- return this;
35564
- };
35565
- });
35566
-
35567
- // ../../node_modules/better-sqlite3/lib/methods/aggregate.js
35568
- var require_aggregate = __commonJS((exports, module) => {
35569
- var { getBooleanOption, cppdb } = require_util3();
35570
- module.exports = function defineAggregate(name17, options) {
35571
- if (typeof name17 !== "string")
35572
- throw new TypeError("Expected first argument to be a string");
35573
- if (typeof options !== "object" || options === null)
35574
- throw new TypeError("Expected second argument to be an options object");
35575
- if (!name17)
35576
- throw new TypeError("User-defined function name cannot be an empty string");
35577
- const start = "start" in options ? options.start : null;
35578
- const step = getFunctionOption(options, "step", true);
35579
- const inverse = getFunctionOption(options, "inverse", false);
35580
- const result = getFunctionOption(options, "result", false);
35581
- const safeIntegers = "safeIntegers" in options ? +getBooleanOption(options, "safeIntegers") : 2;
35582
- const deterministic = getBooleanOption(options, "deterministic");
35583
- const directOnly = getBooleanOption(options, "directOnly");
35584
- const varargs = getBooleanOption(options, "varargs");
35585
- let argCount = -1;
35586
- if (!varargs) {
35587
- argCount = Math.max(getLength(step), inverse ? getLength(inverse) : 0);
35588
- if (argCount > 0)
35589
- argCount -= 1;
35590
- if (argCount > 100)
35591
- throw new RangeError("User-defined functions cannot have more than 100 arguments");
35592
- }
35593
- this[cppdb].aggregate(start, step, inverse, result, name17, argCount, safeIntegers, deterministic, directOnly);
35594
- return this;
35595
- };
35596
- var getFunctionOption = (options, key, required2) => {
35597
- const value = key in options ? options[key] : null;
35598
- if (typeof value === "function")
35599
- return value;
35600
- if (value != null)
35601
- throw new TypeError(`Expected the "${key}" option to be a function`);
35602
- if (required2)
35603
- throw new TypeError(`Missing required option "${key}"`);
35604
- return null;
35605
- };
35606
- var getLength = ({ length }) => {
35607
- if (Number.isInteger(length) && length >= 0)
35608
- return length;
35609
- throw new TypeError("Expected function.length to be a positive integer");
35610
- };
35611
- });
35612
-
35613
- // ../../node_modules/better-sqlite3/lib/methods/table.js
35614
- var require_table = __commonJS((exports, module) => {
35615
- var { cppdb } = require_util3();
35616
- module.exports = function defineTable(name17, factory) {
35617
- if (typeof name17 !== "string")
35618
- throw new TypeError("Expected first argument to be a string");
35619
- if (!name17)
35620
- throw new TypeError("Virtual table module name cannot be an empty string");
35621
- let eponymous = false;
35622
- if (typeof factory === "object" && factory !== null) {
35623
- eponymous = true;
35624
- factory = defer(parseTableDefinition(factory, "used", name17));
35625
- } else {
35626
- if (typeof factory !== "function")
35627
- throw new TypeError("Expected second argument to be a function or a table definition object");
35628
- factory = wrapFactory(factory);
35629
- }
35630
- this[cppdb].table(factory, name17, eponymous);
35631
- return this;
35632
- };
35633
- function wrapFactory(factory) {
35634
- return function virtualTableFactory(moduleName, databaseName, tableName, ...args) {
35635
- const thisObject = {
35636
- module: moduleName,
35637
- database: databaseName,
35638
- table: tableName
35639
36156
  };
35640
- const def = apply2.call(factory, thisObject, args);
35641
- if (typeof def !== "object" || def === null) {
35642
- throw new TypeError(`Virtual table module "${moduleName}" did not return a table definition object`);
36157
+ function S2(a, b = {}) {
36158
+ if (!a)
36159
+ throw new N(44);
36160
+ b.nb ?? (b.nb = true);
36161
+ a.charAt(0) === "/" || (a = "//" + a);
36162
+ var c = 0;
36163
+ a:
36164
+ for (;40 > c; c++) {
36165
+ a = a.split("/").filter((q) => !!q);
36166
+ for (var d = Eb, e2 = "/", h2 = 0;h2 < a.length; h2++) {
36167
+ var k = h2 === a.length - 1;
36168
+ if (k && b.parent)
36169
+ break;
36170
+ if (a[h2] !== ".")
36171
+ if (a[h2] === "..")
36172
+ e2 = fb(e2), d = d.parent;
36173
+ else {
36174
+ e2 = ka(e2 + "/" + a[h2]);
36175
+ try {
36176
+ d = Q(d, a[h2]);
36177
+ } catch (q) {
36178
+ if (q?.Pa === 44 && k && b.Jb)
36179
+ return { path: e2 };
36180
+ throw q;
36181
+ }
36182
+ !d.ab || k && !b.nb || (d = d.ab.root);
36183
+ if ((d.mode & 61440) === 40960 && (!k || b.$a)) {
36184
+ if (!d.La.readlink)
36185
+ throw new N(52);
36186
+ d = d.La.readlink(d);
36187
+ d.charAt(0) === "/" || (d = fb(e2) + "/" + d);
36188
+ a = d + "/" + a.slice(h2 + 1).join("/");
36189
+ continue a;
36190
+ }
36191
+ }
36192
+ }
36193
+ return { path: e2, node: d };
36194
+ }
36195
+ throw new N(32);
35643
36196
  }
35644
- return parseTableDefinition(def, "returned", moduleName);
35645
- };
35646
- }
35647
- function parseTableDefinition(def, verb, moduleName) {
35648
- if (!hasOwnProperty10.call(def, "rows")) {
35649
- throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition without a "rows" property`);
35650
- }
35651
- if (!hasOwnProperty10.call(def, "columns")) {
35652
- throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition without a "columns" property`);
35653
- }
35654
- const rows = def.rows;
35655
- if (typeof rows !== "function" || Object.getPrototypeOf(rows) !== GeneratorFunctionPrototype) {
35656
- throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "rows" property (should be a generator function)`);
35657
- }
35658
- let columns = def.columns;
35659
- if (!Array.isArray(columns) || !(columns = [...columns]).every((x2) => typeof x2 === "string")) {
35660
- throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "columns" property (should be an array of strings)`);
35661
- }
35662
- if (columns.length !== new Set(columns).size) {
35663
- throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with duplicate column names`);
35664
- }
35665
- if (!columns.length) {
35666
- throw new RangeError(`Virtual table module "${moduleName}" ${verb} a table definition with zero columns`);
35667
- }
35668
- let parameters;
35669
- if (hasOwnProperty10.call(def, "parameters")) {
35670
- parameters = def.parameters;
35671
- if (!Array.isArray(parameters) || !(parameters = [...parameters]).every((x2) => typeof x2 === "string")) {
35672
- throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "parameters" property (should be an array of strings)`);
36197
+ function ja(a) {
36198
+ for (var b;; ) {
36199
+ if (a === a.parent)
36200
+ return a = a.Xa.zb, b ? a[a.length - 1] !== "/" ? `${a}/${b}` : a + b : a;
36201
+ b = b ? `${a.name}/${b}` : a.name;
36202
+ a = a.parent;
36203
+ }
35673
36204
  }
35674
- } else {
35675
- parameters = inferParameters(rows);
35676
- }
35677
- if (parameters.length !== new Set(parameters).size) {
35678
- throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with duplicate parameter names`);
35679
- }
35680
- if (parameters.length > 32) {
35681
- throw new RangeError(`Virtual table module "${moduleName}" ${verb} a table definition with more than the maximum number of 32 parameters`);
35682
- }
35683
- for (const parameter of parameters) {
35684
- if (columns.includes(parameter)) {
35685
- throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with column "${parameter}" which was ambiguously defined as both a column and parameter`);
36205
+ function Nb(a, b) {
36206
+ for (var c = 0, d = 0;d < b.length; d++)
36207
+ c = (c << 5) - c + b.charCodeAt(d) | 0;
36208
+ return (a + c >>> 0) % R.length;
35686
36209
  }
35687
- }
35688
- let safeIntegers = 2;
35689
- if (hasOwnProperty10.call(def, "safeIntegers")) {
35690
- const bool = def.safeIntegers;
35691
- if (typeof bool !== "boolean") {
35692
- throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "safeIntegers" property (should be a boolean)`);
36210
+ function Cb(a) {
36211
+ var b = Nb(a.parent.id, a.name);
36212
+ if (R[b] === a)
36213
+ R[b] = a.bb;
36214
+ else
36215
+ for (b = R[b];b; ) {
36216
+ if (b.bb === a) {
36217
+ b.bb = a.bb;
36218
+ break;
36219
+ }
36220
+ b = b.bb;
36221
+ }
35693
36222
  }
35694
- safeIntegers = +bool;
35695
- }
35696
- let directOnly = false;
35697
- if (hasOwnProperty10.call(def, "directOnly")) {
35698
- directOnly = def.directOnly;
35699
- if (typeof directOnly !== "boolean") {
35700
- throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "directOnly" property (should be a boolean)`);
36223
+ function Q(a, b) {
36224
+ var c = P(a.mode) ? (c = Ob(a, "x")) ? c : a.La.lookup ? 0 : 2 : 54;
36225
+ if (c)
36226
+ throw new N(c);
36227
+ for (c = R[Nb(a.id, b)];c; c = c.bb) {
36228
+ var d = c.name;
36229
+ if (c.parent.id === a.id && d === b)
36230
+ return c;
36231
+ }
36232
+ return a.La.lookup(a, b);
36233
+ }
36234
+ function Bb(a, b, c, d) {
36235
+ a = new Mb(a, b, c, d);
36236
+ b = Nb(a.parent.id, a.name);
36237
+ a.bb = R[b];
36238
+ return R[b] = a;
36239
+ }
36240
+ function P(a) {
36241
+ return (a & 61440) === 16384;
36242
+ }
36243
+ function Pb(a) {
36244
+ var b = ["r", "w", "rw"][a & 3];
36245
+ a & 512 && (b += "w");
36246
+ return b;
35701
36247
  }
35702
- }
35703
- const columnDefinitions = [
35704
- ...parameters.map(identifier).map((str) => `${str} HIDDEN`),
35705
- ...columns.map(identifier)
35706
- ];
35707
- return [
35708
- `CREATE TABLE x(${columnDefinitions.join(", ")});`,
35709
- wrapGenerator(rows, new Map(columns.map((x2, i2) => [x2, parameters.length + i2])), moduleName),
35710
- parameters,
35711
- safeIntegers,
35712
- directOnly
35713
- ];
35714
- }
35715
- function wrapGenerator(generator, columnMap, moduleName) {
35716
- return function* virtualTable(...args) {
35717
- const output = args.map((x2) => Buffer.isBuffer(x2) ? Buffer.from(x2) : x2);
35718
- for (let i2 = 0;i2 < columnMap.size; ++i2) {
35719
- output.push(null);
35720
- }
35721
- for (const row of generator(...args)) {
35722
- if (Array.isArray(row)) {
35723
- extractRowArray(row, output, columnMap.size, moduleName);
35724
- yield output;
35725
- } else if (typeof row === "object" && row !== null) {
35726
- extractRowObject(row, output, columnMap, moduleName);
35727
- yield output;
35728
- } else {
35729
- throw new TypeError(`Virtual table module "${moduleName}" yielded something that isn't a valid row object`);
36248
+ function Ob(a, b) {
36249
+ if (Jb)
36250
+ return 0;
36251
+ if (!b.includes("r") || a.mode & 292) {
36252
+ if (b.includes("w") && !(a.mode & 146) || b.includes("x") && !(a.mode & 73))
36253
+ return 2;
36254
+ } else
36255
+ return 2;
36256
+ return 0;
36257
+ }
36258
+ function Qb(a, b) {
36259
+ if (!P(a.mode))
36260
+ return 54;
36261
+ try {
36262
+ return Q(a, b), 20;
36263
+ } catch (c) {}
36264
+ return Ob(a, "wx");
36265
+ }
36266
+ function Rb(a, b, c) {
36267
+ try {
36268
+ var d = Q(a, b);
36269
+ } catch (e2) {
36270
+ return e2.Pa;
35730
36271
  }
36272
+ if (a = Ob(a, "wx"))
36273
+ return a;
36274
+ if (c) {
36275
+ if (!P(d.mode))
36276
+ return 54;
36277
+ if (d === d.parent || ja(d) === "/")
36278
+ return 10;
36279
+ } else if (P(d.mode))
36280
+ return 31;
36281
+ return 0;
35731
36282
  }
35732
- };
35733
- }
35734
- function extractRowArray(row, output, columnCount, moduleName) {
35735
- if (row.length !== columnCount) {
35736
- throw new TypeError(`Virtual table module "${moduleName}" yielded a row with an incorrect number of columns`);
35737
- }
35738
- const offset = output.length - columnCount;
35739
- for (let i2 = 0;i2 < columnCount; ++i2) {
35740
- output[i2 + offset] = row[i2];
35741
- }
35742
- }
35743
- function extractRowObject(row, output, columnMap, moduleName) {
35744
- let count = 0;
35745
- for (const key of Object.keys(row)) {
35746
- const index = columnMap.get(key);
35747
- if (index === undefined) {
35748
- throw new TypeError(`Virtual table module "${moduleName}" yielded a row with an undeclared column "${key}"`);
36283
+ function Sb(a) {
36284
+ if (!a)
36285
+ throw new N(63);
36286
+ return a;
36287
+ }
36288
+ function T(a) {
36289
+ a = Gb[a];
36290
+ if (!a)
36291
+ throw new N(8);
36292
+ return a;
36293
+ }
36294
+ function Tb(a, b = -1) {
36295
+ a = Object.assign(new Lb, a);
36296
+ if (b == -1)
36297
+ a: {
36298
+ for (b = 0;4096 >= b; b++)
36299
+ if (!Gb[b])
36300
+ break a;
36301
+ throw new N(33);
36302
+ }
36303
+ a.fd = b;
36304
+ return Gb[b] = a;
36305
+ }
36306
+ function Ub(a, b = -1) {
36307
+ a = Tb(a, b);
36308
+ a.Ma?.Rb?.(a);
36309
+ return a;
36310
+ }
36311
+ function Vb(a, b, c) {
36312
+ var d = a?.Ma.Ua;
36313
+ a = d ? a : b;
36314
+ d ??= b.La.Ua;
36315
+ Sb(d);
36316
+ d(a, c);
36317
+ }
36318
+ var Ab = { open(a) {
36319
+ a.Ma = Fb[a.node.rdev].Ma;
36320
+ a.Ma.open?.(a);
36321
+ }, Va() {
36322
+ throw new N(70);
36323
+ } };
36324
+ function wb(a, b) {
36325
+ Fb[a] = { Ma: b };
36326
+ }
36327
+ function Wb(a, b) {
36328
+ var c = b === "/";
36329
+ if (c && Eb)
36330
+ throw new N(10);
36331
+ if (!c && b) {
36332
+ var d = S2(b, { nb: false });
36333
+ b = d.path;
36334
+ d = d.node;
36335
+ if (d.ab)
36336
+ throw new N(10);
36337
+ if (!P(d.mode))
36338
+ throw new N(54);
36339
+ }
36340
+ b = { type: a, Wb: {}, zb: b, Ib: [] };
36341
+ a = a.Xa(b);
36342
+ a.Xa = b;
36343
+ b.root = a;
36344
+ c ? Eb = a : d && (d.ab = b, d.Xa && d.Xa.Ib.push(b));
36345
+ }
36346
+ function Xb(a, b, c) {
36347
+ var d = S2(a, { parent: true }).node;
36348
+ a = gb(a);
36349
+ if (!a)
36350
+ throw new N(28);
36351
+ if (a === "." || a === "..")
36352
+ throw new N(20);
36353
+ var e2 = Qb(d, a);
36354
+ if (e2)
36355
+ throw new N(e2);
36356
+ if (!d.La.hb)
36357
+ throw new N(63);
36358
+ return d.La.hb(d, a, b, c);
36359
+ }
36360
+ function ma(a, b = 438) {
36361
+ return Xb(a, b & 4095 | 32768, 0);
36362
+ }
36363
+ function U(a, b = 511) {
36364
+ return Xb(a, b & 1023 | 16384, 0);
36365
+ }
36366
+ function Yb(a, b, c) {
36367
+ typeof c == "undefined" && (c = b, b = 438);
36368
+ Xb(a, b | 8192, c);
36369
+ }
36370
+ function Zb(a, b) {
36371
+ if (!jb(a))
36372
+ throw new N(44);
36373
+ var c = S2(b, { parent: true }).node;
36374
+ if (!c)
36375
+ throw new N(44);
36376
+ b = gb(b);
36377
+ var d = Qb(c, b);
36378
+ if (d)
36379
+ throw new N(d);
36380
+ if (!c.La.symlink)
36381
+ throw new N(63);
36382
+ c.La.symlink(c, b, a);
36383
+ }
36384
+ function $b(a) {
36385
+ var b = S2(a, { parent: true }).node;
36386
+ a = gb(a);
36387
+ var c = Q(b, a), d = Rb(b, a, true);
36388
+ if (d)
36389
+ throw new N(d);
36390
+ if (!b.La.rmdir)
36391
+ throw new N(63);
36392
+ if (c.ab)
36393
+ throw new N(10);
36394
+ b.La.rmdir(b, a);
36395
+ Cb(c);
36396
+ }
36397
+ function za(a) {
36398
+ var b = S2(a, { parent: true }).node;
36399
+ if (!b)
36400
+ throw new N(44);
36401
+ a = gb(a);
36402
+ var c = Q(b, a), d = Rb(b, a, false);
36403
+ if (d)
36404
+ throw new N(d);
36405
+ if (!b.La.unlink)
36406
+ throw new N(63);
36407
+ if (c.ab)
36408
+ throw new N(10);
36409
+ b.La.unlink(b, a);
36410
+ Cb(c);
36411
+ }
36412
+ function ac(a, b) {
36413
+ a = S2(a, { $a: !b }).node;
36414
+ return Sb(a.La.Ta)(a);
36415
+ }
36416
+ function bc(a, b, c, d) {
36417
+ Vb(a, b, { mode: c & 4095 | b.mode & -4096, ctime: Date.now(), Fb: d });
36418
+ }
36419
+ function na(a, b) {
36420
+ a = typeof a == "string" ? S2(a, { $a: true }).node : a;
36421
+ bc(null, a, b);
36422
+ }
36423
+ function cc(a, b, c) {
36424
+ if (P(b.mode))
36425
+ throw new N(31);
36426
+ if ((b.mode & 61440) !== 32768)
36427
+ throw new N(28);
36428
+ var d = Ob(b, "w");
36429
+ if (d)
36430
+ throw new N(d);
36431
+ Vb(a, b, { size: c, timestamp: Date.now() });
36432
+ }
36433
+ function oa(a, b, c = 438) {
36434
+ if (a === "")
36435
+ throw new N(44);
36436
+ if (typeof b == "string") {
36437
+ var d = { r: 0, "r+": 2, w: 577, "w+": 578, a: 1089, "a+": 1090 }[b];
36438
+ if (typeof d == "undefined")
36439
+ throw Error(`Unknown file open mode: ${b}`);
36440
+ b = d;
36441
+ }
36442
+ c = b & 64 ? c & 4095 | 32768 : 0;
36443
+ if (typeof a == "object")
36444
+ d = a;
36445
+ else {
36446
+ var e2 = a.endsWith("/");
36447
+ a = S2(a, { $a: !(b & 131072), Jb: true });
36448
+ d = a.node;
36449
+ a = a.path;
36450
+ }
36451
+ var h2 = false;
36452
+ if (b & 64)
36453
+ if (d) {
36454
+ if (b & 128)
36455
+ throw new N(20);
36456
+ } else {
36457
+ if (e2)
36458
+ throw new N(31);
36459
+ d = Xb(a, c | 511, 0);
36460
+ h2 = true;
36461
+ }
36462
+ if (!d)
36463
+ throw new N(44);
36464
+ (d.mode & 61440) === 8192 && (b &= -513);
36465
+ if (b & 65536 && !P(d.mode))
36466
+ throw new N(54);
36467
+ if (!h2 && (e2 = d ? (d.mode & 61440) === 40960 ? 32 : P(d.mode) && (Pb(b) !== "r" || b & 576) ? 31 : Ob(d, Pb(b)) : 44))
36468
+ throw new N(e2);
36469
+ b & 512 && !h2 && (e2 = d, e2 = typeof e2 == "string" ? S2(e2, { $a: true }).node : e2, cc(null, e2, 0));
36470
+ b &= -131713;
36471
+ e2 = Tb({ node: d, path: ja(d), flags: b, seekable: true, position: 0, Ma: d.Ma, Lb: [], error: false });
36472
+ e2.Ma.open && e2.Ma.open(e2);
36473
+ h2 && na(d, c & 511);
36474
+ !f3.logReadFiles || b & 1 || a in Kb || (Kb[a] = 1);
36475
+ return e2;
36476
+ }
36477
+ function qa(a) {
36478
+ if (a.fd === null)
36479
+ throw new N(8);
36480
+ a.ob && (a.ob = null);
36481
+ try {
36482
+ a.Ma.close && a.Ma.close(a);
36483
+ } catch (b) {
36484
+ throw b;
36485
+ } finally {
36486
+ Gb[a.fd] = null;
36487
+ }
36488
+ a.fd = null;
36489
+ }
36490
+ function mc(a, b, c) {
36491
+ if (a.fd === null)
36492
+ throw new N(8);
36493
+ if (!a.seekable || !a.Ma.Va)
36494
+ throw new N(70);
36495
+ if (c != 0 && c != 1 && c != 2)
36496
+ throw new N(28);
36497
+ a.position = a.Ma.Va(a, b, c);
36498
+ a.Lb = [];
36499
+ }
36500
+ function Ec(a, b, c, d, e2) {
36501
+ if (0 > d || 0 > e2)
36502
+ throw new N(28);
36503
+ if (a.fd === null)
36504
+ throw new N(8);
36505
+ if ((a.flags & 2097155) === 1)
36506
+ throw new N(8);
36507
+ if (P(a.node.mode))
36508
+ throw new N(31);
36509
+ if (!a.Ma.read)
36510
+ throw new N(28);
36511
+ var h2 = typeof e2 != "undefined";
36512
+ if (!h2)
36513
+ e2 = a.position;
36514
+ else if (!a.seekable)
36515
+ throw new N(70);
36516
+ b = a.Ma.read(a, b, c, d, e2);
36517
+ h2 || (a.position += b);
36518
+ return b;
35749
36519
  }
35750
- output[index] = row[key];
35751
- count += 1;
35752
- }
35753
- if (count !== columnMap.size) {
35754
- throw new TypeError(`Virtual table module "${moduleName}" yielded a row with missing columns`);
35755
- }
35756
- }
35757
- function inferParameters({ length }) {
35758
- if (!Number.isInteger(length) || length < 0) {
35759
- throw new TypeError("Expected function.length to be a positive integer");
35760
- }
35761
- const params = [];
35762
- for (let i2 = 0;i2 < length; ++i2) {
35763
- params.push(`$${i2 + 1}`);
35764
- }
35765
- return params;
35766
- }
35767
- var { hasOwnProperty: hasOwnProperty10 } = Object.prototype;
35768
- var { apply: apply2 } = Function.prototype;
35769
- var GeneratorFunctionPrototype = Object.getPrototypeOf(function* () {});
35770
- var identifier = (str) => `"${str.replace(/"/g, '""')}"`;
35771
- var defer = (x2) => () => x2;
35772
- });
35773
-
35774
- // ../../node_modules/better-sqlite3/lib/methods/inspect.js
35775
- var require_inspect = __commonJS((exports, module) => {
35776
- var DatabaseInspection = function Database() {};
35777
- module.exports = function inspect(depth, opts) {
35778
- return Object.assign(new DatabaseInspection, this);
35779
- };
35780
- });
35781
-
35782
- // ../../node_modules/better-sqlite3/lib/database.js
35783
- var require_database = __commonJS((exports, module) => {
35784
- var fs4 = __require("fs");
35785
- var path = __require("path");
35786
- var util2 = require_util3();
35787
- var SqliteError = require_sqlite_error();
35788
- var DEFAULT_ADDON;
35789
- function Database(filenameGiven, options) {
35790
- if (new.target == null) {
35791
- return new Database(filenameGiven, options);
35792
- }
35793
- let buffer;
35794
- if (Buffer.isBuffer(filenameGiven)) {
35795
- buffer = filenameGiven;
35796
- filenameGiven = ":memory:";
35797
- }
35798
- if (filenameGiven == null)
35799
- filenameGiven = "";
35800
- if (options == null)
35801
- options = {};
35802
- if (typeof filenameGiven !== "string")
35803
- throw new TypeError("Expected first argument to be a string");
35804
- if (typeof options !== "object")
35805
- throw new TypeError("Expected second argument to be an options object");
35806
- if ("readOnly" in options)
35807
- throw new TypeError('Misspelled option "readOnly" should be "readonly"');
35808
- if ("memory" in options)
35809
- throw new TypeError('Option "memory" was removed in v7.0.0 (use ":memory:" filename instead)');
35810
- const filename = filenameGiven.trim();
35811
- const anonymous = filename === "" || filename === ":memory:";
35812
- const readonly2 = util2.getBooleanOption(options, "readonly");
35813
- const fileMustExist = util2.getBooleanOption(options, "fileMustExist");
35814
- const timeout = "timeout" in options ? options.timeout : 5000;
35815
- const verbose = "verbose" in options ? options.verbose : null;
35816
- const nativeBinding = "nativeBinding" in options ? options.nativeBinding : null;
35817
- if (readonly2 && anonymous && !buffer)
35818
- throw new TypeError("In-memory/temporary databases cannot be readonly");
35819
- if (!Number.isInteger(timeout) || timeout < 0)
35820
- throw new TypeError('Expected the "timeout" option to be a positive integer');
35821
- if (timeout > 2147483647)
35822
- throw new RangeError('Option "timeout" cannot be greater than 2147483647');
35823
- if (verbose != null && typeof verbose !== "function")
35824
- throw new TypeError('Expected the "verbose" option to be a function');
35825
- if (nativeBinding != null && typeof nativeBinding !== "string" && typeof nativeBinding !== "object")
35826
- throw new TypeError('Expected the "nativeBinding" option to be a string or addon object');
35827
- let addon;
35828
- if (nativeBinding == null) {
35829
- addon = DEFAULT_ADDON || (DEFAULT_ADDON = require_bindings()("better_sqlite3.node"));
35830
- } else if (typeof nativeBinding === "string") {
35831
- const requireFunc = typeof __non_webpack_require__ === "function" ? __non_webpack_require__ : __require;
35832
- addon = requireFunc(path.resolve(nativeBinding).replace(/(\.node)?$/, ".node"));
35833
- } else {
35834
- addon = nativeBinding;
35835
- }
35836
- if (!addon.isInitialized) {
35837
- addon.setErrorConstructor(SqliteError);
35838
- addon.isInitialized = true;
35839
- }
35840
- if (!anonymous && !filename.startsWith("file:") && !fs4.existsSync(path.dirname(filename))) {
35841
- throw new TypeError("Cannot open database because the directory does not exist");
35842
- }
35843
- Object.defineProperties(this, {
35844
- [util2.cppdb]: { value: new addon.Database(filename, filenameGiven, anonymous, readonly2, fileMustExist, timeout, verbose || null, buffer || null) },
35845
- ...wrappers.getters
36520
+ function pa(a, b, c, d, e2) {
36521
+ if (0 > d || 0 > e2)
36522
+ throw new N(28);
36523
+ if (a.fd === null)
36524
+ throw new N(8);
36525
+ if ((a.flags & 2097155) === 0)
36526
+ throw new N(8);
36527
+ if (P(a.node.mode))
36528
+ throw new N(31);
36529
+ if (!a.Ma.write)
36530
+ throw new N(28);
36531
+ a.seekable && a.flags & 1024 && mc(a, 0, 2);
36532
+ var h2 = typeof e2 != "undefined";
36533
+ if (!h2)
36534
+ e2 = a.position;
36535
+ else if (!a.seekable)
36536
+ throw new N(70);
36537
+ b = a.Ma.write(a, b, c, d, e2, undefined);
36538
+ h2 || (a.position += b);
36539
+ return b;
36540
+ }
36541
+ function ya(a) {
36542
+ var b = "binary";
36543
+ if (b !== "utf8" && b !== "binary")
36544
+ throw Error(`Invalid encoding type "${b}"`);
36545
+ var c;
36546
+ var d = oa(a, d || 0);
36547
+ a = ac(a).size;
36548
+ var e2 = new Uint8Array(a);
36549
+ Ec(d, e2, 0, a, 0);
36550
+ b === "utf8" ? c = B(e2) : b === "binary" && (c = e2);
36551
+ qa(d);
36552
+ return c;
36553
+ }
36554
+ function V(a, b, c) {
36555
+ a = ka("/dev/" + a);
36556
+ var d = la(!!b, !!c);
36557
+ V.yb ?? (V.yb = 64);
36558
+ var e2 = V.yb++ << 8 | 0;
36559
+ wb(e2, { open(h2) {
36560
+ h2.seekable = false;
36561
+ }, close() {
36562
+ c?.buffer?.length && c(10);
36563
+ }, read(h2, k, q, w) {
36564
+ for (var v = 0, C = 0;C < w; C++) {
36565
+ try {
36566
+ var G = b();
36567
+ } catch (pb) {
36568
+ throw new N(29);
36569
+ }
36570
+ if (G === undefined && v === 0)
36571
+ throw new N(6);
36572
+ if (G === null || G === undefined)
36573
+ break;
36574
+ v++;
36575
+ k[q + C] = G;
36576
+ }
36577
+ v && (h2.node.atime = Date.now());
36578
+ return v;
36579
+ }, write(h2, k, q, w) {
36580
+ for (var v = 0;v < w; v++)
36581
+ try {
36582
+ c(k[q + v]);
36583
+ } catch (C) {
36584
+ throw new N(29);
36585
+ }
36586
+ w && (h2.node.mtime = h2.node.ctime = Date.now());
36587
+ return v;
36588
+ } });
36589
+ Yb(a, d, e2);
36590
+ }
36591
+ var W = {};
36592
+ function Gc(a, b, c) {
36593
+ if (b.charAt(0) === "/")
36594
+ return b;
36595
+ a = a === -100 ? "/" : T(a).path;
36596
+ if (b.length == 0) {
36597
+ if (!c)
36598
+ throw new N(44);
36599
+ return a;
36600
+ }
36601
+ return a + "/" + b;
36602
+ }
36603
+ function Hc(a, b) {
36604
+ E[a >> 2] = b.dev;
36605
+ E[a + 4 >> 2] = b.mode;
36606
+ F2[a + 8 >> 2] = b.nlink;
36607
+ E[a + 12 >> 2] = b.uid;
36608
+ E[a + 16 >> 2] = b.gid;
36609
+ E[a + 20 >> 2] = b.rdev;
36610
+ H[a + 24 >> 3] = BigInt(b.size);
36611
+ E[a + 32 >> 2] = 4096;
36612
+ E[a + 36 >> 2] = b.blocks;
36613
+ var c = b.atime.getTime(), d = b.mtime.getTime(), e2 = b.ctime.getTime();
36614
+ H[a + 40 >> 3] = BigInt(Math.floor(c / 1000));
36615
+ F2[a + 48 >> 2] = c % 1000 * 1e6;
36616
+ H[a + 56 >> 3] = BigInt(Math.floor(d / 1000));
36617
+ F2[a + 64 >> 2] = d % 1000 * 1e6;
36618
+ H[a + 72 >> 3] = BigInt(Math.floor(e2 / 1000));
36619
+ F2[a + 80 >> 2] = e2 % 1000 * 1e6;
36620
+ H[a + 88 >> 3] = BigInt(b.ino);
36621
+ return 0;
36622
+ }
36623
+ var Ic = undefined, Jc = () => {
36624
+ var a = E[+Ic >> 2];
36625
+ Ic += 4;
36626
+ return a;
36627
+ }, 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) => {
36628
+ Ma = a;
36629
+ cb || 0 < Kc || (f3.onExit?.(a), La = true);
36630
+ Da(a, new Ya(a));
36631
+ }, Pc = (a) => {
36632
+ if (!La)
36633
+ try {
36634
+ if (a(), !(cb || 0 < Kc))
36635
+ try {
36636
+ Ma = a = Ma, Oc(a);
36637
+ } catch (b) {
36638
+ b instanceof Ya || b == "unwind" || Da(1, b);
36639
+ }
36640
+ } catch (b) {
36641
+ b instanceof Ya || b == "unwind" || Da(1, b);
36642
+ }
36643
+ }, Qc = {}, Sc = () => {
36644
+ if (!Rc) {
36645
+ 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;
36646
+ for (b in Qc)
36647
+ Qc[b] === undefined ? delete a[b] : a[b] = Qc[b];
36648
+ var c = [];
36649
+ for (b in a)
36650
+ c.push(`${b}=${a[b]}`);
36651
+ Rc = c;
36652
+ }
36653
+ return Rc;
36654
+ }, Rc, xa = (a) => {
36655
+ var b = ha(a) + 1, c = z2(b);
36656
+ u(a, x2, c, b);
36657
+ return c;
36658
+ }, Tc = (a, b, c, d) => {
36659
+ var e2 = { string: (v) => {
36660
+ var C = 0;
36661
+ v !== null && v !== undefined && v !== 0 && (C = xa(v));
36662
+ return C;
36663
+ }, array: (v) => {
36664
+ var C = z2(v.length);
36665
+ p.set(v, C);
36666
+ return C;
36667
+ } };
36668
+ a = f3["_" + a];
36669
+ var h2 = [], k = 0;
36670
+ if (d)
36671
+ for (var q = 0;q < d.length; q++) {
36672
+ var w = e2[c[q]];
36673
+ w ? (k === 0 && (k = sa()), h2[q] = w(d[q])) : h2[q] = d[q];
36674
+ }
36675
+ c = a(...h2);
36676
+ return c = function(v) {
36677
+ k !== 0 && wa(k);
36678
+ return b === "string" ? v ? B(x2, v) : "" : b === "boolean" ? !!v : v;
36679
+ }(c);
36680
+ }, ea = 0, da = (a, b) => {
36681
+ b = b == 1 ? z2(a.length) : ia(a.length);
36682
+ a.subarray || a.slice || (a = new Uint8Array(a));
36683
+ x2.set(a, b);
36684
+ return b;
36685
+ }, Uc, Vc = [], Y, A2 = (a) => {
36686
+ Uc.delete(Y.get(a));
36687
+ Y.set(a, null);
36688
+ Vc.push(a);
36689
+ }, Aa = (a, b) => {
36690
+ if (!Uc) {
36691
+ Uc = new WeakMap;
36692
+ var c = Y.length;
36693
+ if (Uc)
36694
+ for (var d = 0;d < 0 + c; d++) {
36695
+ var e2 = Y.get(d);
36696
+ e2 && Uc.set(e2, d);
36697
+ }
36698
+ }
36699
+ if (c = Uc.get(a) || 0)
36700
+ return c;
36701
+ if (Vc.length)
36702
+ c = Vc.pop();
36703
+ else {
36704
+ try {
36705
+ Y.grow(1);
36706
+ } catch (w) {
36707
+ if (!(w instanceof RangeError))
36708
+ throw w;
36709
+ throw "Unable to grow wasm table. Set ALLOW_TABLE_GROWTH.";
36710
+ }
36711
+ c = Y.length - 1;
36712
+ }
36713
+ try {
36714
+ Y.set(c, a);
36715
+ } catch (w) {
36716
+ if (!(w instanceof TypeError))
36717
+ throw w;
36718
+ if (typeof WebAssembly.Function == "function") {
36719
+ var h2 = WebAssembly.Function;
36720
+ d = { i: "i32", j: "i64", f: "f32", d: "f64", e: "externref", p: "i32" };
36721
+ e2 = { parameters: [], results: b[0] == "v" ? [] : [d[b[0]]] };
36722
+ for (var k = 1;k < b.length; ++k)
36723
+ e2.parameters.push(d[b[k]]);
36724
+ b = new h2(e2, a);
36725
+ } else {
36726
+ d = [1];
36727
+ e2 = b.slice(0, 1);
36728
+ b = b.slice(1);
36729
+ k = { i: 127, p: 127, j: 126, f: 125, d: 124, e: 111 };
36730
+ d.push(96);
36731
+ var q = b.length;
36732
+ 128 > q ? d.push(q) : d.push(q % 128 | 128, q >> 7);
36733
+ for (h2 of b)
36734
+ d.push(k[h2]);
36735
+ e2 == "v" ? d.push(0) : d.push(1, k[e2]);
36736
+ b = [0, 97, 115, 109, 1, 0, 0, 0, 1];
36737
+ h2 = d.length;
36738
+ 128 > h2 ? b.push(h2) : b.push(h2 % 128 | 128, h2 >> 7);
36739
+ b.push(...d);
36740
+ b.push(2, 7, 1, 1, 101, 1, 102, 0, 0, 7, 5, 1, 1, 102, 0, 0);
36741
+ b = new WebAssembly.Module(new Uint8Array(b));
36742
+ b = new WebAssembly.Instance(b, { e: { f: a } }).exports.f;
36743
+ }
36744
+ Y.set(c, b);
36745
+ }
36746
+ Uc.set(a, c);
36747
+ return c;
36748
+ };
36749
+ R = Array(4096);
36750
+ Wb(O, "/");
36751
+ U("/tmp");
36752
+ U("/home");
36753
+ U("/home/web_user");
36754
+ (function() {
36755
+ U("/dev");
36756
+ wb(259, { read: () => 0, write: (d, e2, h2, k) => k, Va: () => 0 });
36757
+ Yb("/dev/null", 259);
36758
+ nb(1280, yb);
36759
+ nb(1536, zb);
36760
+ Yb("/dev/tty", 1280);
36761
+ Yb("/dev/tty1", 1536);
36762
+ var a = new Uint8Array(1024), b = 0, c = () => {
36763
+ b === 0 && (ib(a), b = a.byteLength);
36764
+ return a[--b];
36765
+ };
36766
+ V("random", c);
36767
+ V("urandom", c);
36768
+ U("/dev/shm");
36769
+ U("/dev/shm/tmp");
36770
+ })();
36771
+ (function() {
36772
+ U("/proc");
36773
+ var a = U("/proc/self");
36774
+ U("/proc/self/fd");
36775
+ Wb({ Xa() {
36776
+ var b = Bb(a, "fd", 16895, 73);
36777
+ b.Ma = { Va: O.Ma.Va };
36778
+ b.La = { lookup(c, d) {
36779
+ c = +d;
36780
+ var e2 = T(c);
36781
+ c = { parent: null, Xa: { zb: "fake" }, La: { readlink: () => e2.path }, id: c + 1 };
36782
+ return c.parent = c;
36783
+ }, readdir() {
36784
+ return Array.from(Gb.entries()).filter(([, c]) => c).map(([c]) => c.toString());
36785
+ } };
36786
+ return b;
36787
+ } }, "/proc/self/fd");
36788
+ })();
36789
+ O.vb = new N(44);
36790
+ O.vb.stack = "<generic error, no stack>";
36791
+ var Xc = { a: (a, b, c, d) => Ta(`Assertion failed: ${a ? B(x2, a) : ""}, at: ` + [b ? b ? B(x2, b) : "" : "unknown filename", c, d ? d ? B(x2, d) : "" : "unknown function"]), i: function(a, b) {
36792
+ try {
36793
+ return a = a ? B(x2, a) : "", na(a, b), 0;
36794
+ } catch (c) {
36795
+ if (typeof W == "undefined" || c.name !== "ErrnoError")
36796
+ throw c;
36797
+ return -c.Pa;
36798
+ }
36799
+ }, L: function(a, b, c) {
36800
+ try {
36801
+ b = b ? B(x2, b) : "";
36802
+ b = Gc(a, b);
36803
+ if (c & -8)
36804
+ return -28;
36805
+ var d = S2(b, { $a: true }).node;
36806
+ if (!d)
36807
+ return -44;
36808
+ a = "";
36809
+ c & 4 && (a += "r");
36810
+ c & 2 && (a += "w");
36811
+ c & 1 && (a += "x");
36812
+ return a && Ob(d, a) ? -2 : 0;
36813
+ } catch (e2) {
36814
+ if (typeof W == "undefined" || e2.name !== "ErrnoError")
36815
+ throw e2;
36816
+ return -e2.Pa;
36817
+ }
36818
+ }, j: function(a, b) {
36819
+ try {
36820
+ var c = T(a);
36821
+ bc(c, c.node, b, false);
36822
+ return 0;
36823
+ } catch (d) {
36824
+ if (typeof W == "undefined" || d.name !== "ErrnoError")
36825
+ throw d;
36826
+ return -d.Pa;
36827
+ }
36828
+ }, h: function(a) {
36829
+ try {
36830
+ var b = T(a);
36831
+ Vb(b, b.node, { timestamp: Date.now(), Fb: false });
36832
+ return 0;
36833
+ } catch (c) {
36834
+ if (typeof W == "undefined" || c.name !== "ErrnoError")
36835
+ throw c;
36836
+ return -c.Pa;
36837
+ }
36838
+ }, b: function(a, b, c) {
36839
+ Ic = c;
36840
+ try {
36841
+ var d = T(a);
36842
+ switch (b) {
36843
+ case 0:
36844
+ var e2 = Jc();
36845
+ if (0 > e2)
36846
+ break;
36847
+ for (;Gb[e2]; )
36848
+ e2++;
36849
+ return Ub(d, e2).fd;
36850
+ case 1:
36851
+ case 2:
36852
+ return 0;
36853
+ case 3:
36854
+ return d.flags;
36855
+ case 4:
36856
+ return e2 = Jc(), d.flags |= e2, 0;
36857
+ case 12:
36858
+ return e2 = Jc(), Na[e2 + 0 >> 1] = 2, 0;
36859
+ case 13:
36860
+ case 14:
36861
+ return 0;
36862
+ }
36863
+ return -28;
36864
+ } catch (h2) {
36865
+ if (typeof W == "undefined" || h2.name !== "ErrnoError")
36866
+ throw h2;
36867
+ return -h2.Pa;
36868
+ }
36869
+ }, g: function(a, b) {
36870
+ try {
36871
+ var c = T(a), d = c.node, e2 = c.Ma.Ta;
36872
+ a = e2 ? c : d;
36873
+ e2 ??= d.La.Ta;
36874
+ Sb(e2);
36875
+ var h2 = e2(a);
36876
+ return Hc(b, h2);
36877
+ } catch (k) {
36878
+ if (typeof W == "undefined" || k.name !== "ErrnoError")
36879
+ throw k;
36880
+ return -k.Pa;
36881
+ }
36882
+ }, H: function(a, b) {
36883
+ b = -9007199254740992 > b || 9007199254740992 < b ? NaN : Number(b);
36884
+ try {
36885
+ if (isNaN(b))
36886
+ return 61;
36887
+ var c = T(a);
36888
+ if (0 > b || (c.flags & 2097155) === 0)
36889
+ throw new N(28);
36890
+ cc(c, c.node, b);
36891
+ return 0;
36892
+ } catch (d) {
36893
+ if (typeof W == "undefined" || d.name !== "ErrnoError")
36894
+ throw d;
36895
+ return -d.Pa;
36896
+ }
36897
+ }, G: function(a, b) {
36898
+ try {
36899
+ if (b === 0)
36900
+ return -28;
36901
+ var c = ha("/") + 1;
36902
+ if (b < c)
36903
+ return -68;
36904
+ u("/", x2, a, b);
36905
+ return c;
36906
+ } catch (d) {
36907
+ if (typeof W == "undefined" || d.name !== "ErrnoError")
36908
+ throw d;
36909
+ return -d.Pa;
36910
+ }
36911
+ }, K: function(a, b) {
36912
+ try {
36913
+ return a = a ? B(x2, a) : "", Hc(b, ac(a, true));
36914
+ } catch (c) {
36915
+ if (typeof W == "undefined" || c.name !== "ErrnoError")
36916
+ throw c;
36917
+ return -c.Pa;
36918
+ }
36919
+ }, C: function(a, b, c) {
36920
+ try {
36921
+ return b = b ? B(x2, b) : "", b = Gc(a, b), U(b, c), 0;
36922
+ } catch (d) {
36923
+ if (typeof W == "undefined" || d.name !== "ErrnoError")
36924
+ throw d;
36925
+ return -d.Pa;
36926
+ }
36927
+ }, J: function(a, b, c, d) {
36928
+ try {
36929
+ b = b ? B(x2, b) : "";
36930
+ var e2 = d & 256;
36931
+ b = Gc(a, b, d & 4096);
36932
+ return Hc(c, e2 ? ac(b, true) : ac(b));
36933
+ } catch (h2) {
36934
+ if (typeof W == "undefined" || h2.name !== "ErrnoError")
36935
+ throw h2;
36936
+ return -h2.Pa;
36937
+ }
36938
+ }, x: function(a, b, c, d) {
36939
+ Ic = d;
36940
+ try {
36941
+ b = b ? B(x2, b) : "";
36942
+ b = Gc(a, b);
36943
+ var e2 = d ? Jc() : 0;
36944
+ return oa(b, c, e2).fd;
36945
+ } catch (h2) {
36946
+ if (typeof W == "undefined" || h2.name !== "ErrnoError")
36947
+ throw h2;
36948
+ return -h2.Pa;
36949
+ }
36950
+ }, v: function(a, b, c, d) {
36951
+ try {
36952
+ b = b ? B(x2, b) : "";
36953
+ b = Gc(a, b);
36954
+ if (0 >= d)
36955
+ return -28;
36956
+ var e2 = S2(b).node;
36957
+ if (!e2)
36958
+ throw new N(44);
36959
+ if (!e2.La.readlink)
36960
+ throw new N(28);
36961
+ var h2 = e2.La.readlink(e2);
36962
+ var k = Math.min(d, ha(h2)), q = p[c + k];
36963
+ u(h2, x2, c, d + 1);
36964
+ p[c + k] = q;
36965
+ return k;
36966
+ } catch (w) {
36967
+ if (typeof W == "undefined" || w.name !== "ErrnoError")
36968
+ throw w;
36969
+ return -w.Pa;
36970
+ }
36971
+ }, u: function(a) {
36972
+ try {
36973
+ return a = a ? B(x2, a) : "", $b(a), 0;
36974
+ } catch (b) {
36975
+ if (typeof W == "undefined" || b.name !== "ErrnoError")
36976
+ throw b;
36977
+ return -b.Pa;
36978
+ }
36979
+ }, f: function(a, b) {
36980
+ try {
36981
+ return a = a ? B(x2, a) : "", Hc(b, ac(a));
36982
+ } catch (c) {
36983
+ if (typeof W == "undefined" || c.name !== "ErrnoError")
36984
+ throw c;
36985
+ return -c.Pa;
36986
+ }
36987
+ }, r: function(a, b, c) {
36988
+ try {
36989
+ return b = b ? B(x2, b) : "", b = Gc(a, b), c === 0 ? za(b) : c === 512 ? $b(b) : Ta("Invalid flags passed to unlinkat"), 0;
36990
+ } catch (d) {
36991
+ if (typeof W == "undefined" || d.name !== "ErrnoError")
36992
+ throw d;
36993
+ return -d.Pa;
36994
+ }
36995
+ }, q: function(a, b, c) {
36996
+ try {
36997
+ b = b ? B(x2, b) : "";
36998
+ b = Gc(a, b, true);
36999
+ var d = Date.now(), e2, h2;
37000
+ if (c) {
37001
+ var k = F2[c >> 2] + 4294967296 * E[c + 4 >> 2], q = E[c + 8 >> 2];
37002
+ q == 1073741823 ? e2 = d : q == 1073741822 ? e2 = null : e2 = 1000 * k + q / 1e6;
37003
+ c += 16;
37004
+ k = F2[c >> 2] + 4294967296 * E[c + 4 >> 2];
37005
+ q = E[c + 8 >> 2];
37006
+ q == 1073741823 ? h2 = d : q == 1073741822 ? h2 = null : h2 = 1000 * k + q / 1e6;
37007
+ } else
37008
+ h2 = e2 = d;
37009
+ if ((h2 ?? e2) !== null) {
37010
+ a = e2;
37011
+ var w = S2(b, { $a: true }).node;
37012
+ Sb(w.La.Ua)(w, { atime: a, mtime: h2 });
37013
+ }
37014
+ return 0;
37015
+ } catch (v) {
37016
+ if (typeof W == "undefined" || v.name !== "ErrnoError")
37017
+ throw v;
37018
+ return -v.Pa;
37019
+ }
37020
+ }, m: () => Ta(""), l: () => {
37021
+ cb = false;
37022
+ Kc = 0;
37023
+ }, A: function(a, b) {
37024
+ a = -9007199254740992 > a || 9007199254740992 < a ? NaN : Number(a);
37025
+ a = new Date(1000 * a);
37026
+ E[b >> 2] = a.getSeconds();
37027
+ E[b + 4 >> 2] = a.getMinutes();
37028
+ E[b + 8 >> 2] = a.getHours();
37029
+ E[b + 12 >> 2] = a.getDate();
37030
+ E[b + 16 >> 2] = a.getMonth();
37031
+ E[b + 20 >> 2] = a.getFullYear() - 1900;
37032
+ E[b + 24 >> 2] = a.getDay();
37033
+ var c = a.getFullYear();
37034
+ E[b + 28 >> 2] = (c % 4 !== 0 || c % 100 === 0 && c % 400 !== 0 ? Mc : Lc)[a.getMonth()] + a.getDate() - 1 | 0;
37035
+ E[b + 36 >> 2] = -(60 * a.getTimezoneOffset());
37036
+ c = new Date(a.getFullYear(), 6, 1).getTimezoneOffset();
37037
+ var d = new Date(a.getFullYear(), 0, 1).getTimezoneOffset();
37038
+ E[b + 32 >> 2] = (c != d && a.getTimezoneOffset() == Math.min(d, c)) | 0;
37039
+ }, y: function(a, b, c, d, e2, h2, k) {
37040
+ e2 = -9007199254740992 > e2 || 9007199254740992 < e2 ? NaN : Number(e2);
37041
+ try {
37042
+ if (isNaN(e2))
37043
+ return 61;
37044
+ var q = T(d);
37045
+ if ((b & 2) !== 0 && (c & 2) === 0 && (q.flags & 2097155) !== 2)
37046
+ throw new N(2);
37047
+ if ((q.flags & 2097155) === 1)
37048
+ throw new N(2);
37049
+ if (!q.Ma.ib)
37050
+ throw new N(43);
37051
+ if (!a)
37052
+ throw new N(28);
37053
+ var w = q.Ma.ib(q, a, e2, b, c);
37054
+ var v = w.Kb;
37055
+ E[h2 >> 2] = w.Ab;
37056
+ F2[k >> 2] = v;
37057
+ return 0;
37058
+ } catch (C) {
37059
+ if (typeof W == "undefined" || C.name !== "ErrnoError")
37060
+ throw C;
37061
+ return -C.Pa;
37062
+ }
37063
+ }, z: function(a, b, c, d, e2, h2) {
37064
+ h2 = -9007199254740992 > h2 || 9007199254740992 < h2 ? NaN : Number(h2);
37065
+ try {
37066
+ var k = T(e2);
37067
+ if (c & 2) {
37068
+ c = h2;
37069
+ if ((k.node.mode & 61440) !== 32768)
37070
+ throw new N(43);
37071
+ if (!(d & 2)) {
37072
+ var q = x2.slice(a, a + b);
37073
+ k.Ma.jb && k.Ma.jb(k, q, c, b, d);
37074
+ }
37075
+ }
37076
+ } catch (w) {
37077
+ if (typeof W == "undefined" || w.name !== "ErrnoError")
37078
+ throw w;
37079
+ return -w.Pa;
37080
+ }
37081
+ }, n: (a, b) => {
37082
+ Nc[a] && (clearTimeout(Nc[a].id), delete Nc[a]);
37083
+ if (!b)
37084
+ return 0;
37085
+ var c = setTimeout(() => {
37086
+ delete Nc[a];
37087
+ Pc(() => Wc(a, performance.now()));
37088
+ }, b);
37089
+ Nc[a] = {
37090
+ id: c,
37091
+ Xb: b
37092
+ };
37093
+ return 0;
37094
+ }, B: (a, b, c, d) => {
37095
+ var e2 = new Date().getFullYear(), h2 = new Date(e2, 0, 1).getTimezoneOffset();
37096
+ e2 = new Date(e2, 6, 1).getTimezoneOffset();
37097
+ F2[a >> 2] = 60 * Math.max(h2, e2);
37098
+ E[b >> 2] = Number(h2 != e2);
37099
+ b = (k) => {
37100
+ var q = Math.abs(k);
37101
+ return `UTC${0 <= k ? "-" : "+"}${String(Math.floor(q / 60)).padStart(2, "0")}${String(q % 60).padStart(2, "0")}`;
37102
+ };
37103
+ a = b(h2);
37104
+ b = b(e2);
37105
+ e2 < h2 ? (u(a, x2, c, 17), u(b, x2, d, 17)) : (u(a, x2, d, 17), u(b, x2, c, 17));
37106
+ }, d: () => Date.now(), s: () => 2147483648, c: () => performance.now(), o: (a) => {
37107
+ var b = x2.length;
37108
+ a >>>= 0;
37109
+ if (2147483648 < a)
37110
+ return false;
37111
+ for (var c = 1;4 >= c; c *= 2) {
37112
+ var d = b * (1 + 0.2 / c);
37113
+ d = Math.min(d, a + 100663296);
37114
+ a: {
37115
+ d = (Math.min(2147483648, 65536 * Math.ceil(Math.max(a, d) / 65536)) - Ka.buffer.byteLength + 65535) / 65536 | 0;
37116
+ try {
37117
+ Ka.grow(d);
37118
+ Qa();
37119
+ var e2 = 1;
37120
+ break a;
37121
+ } catch (h2) {}
37122
+ e2 = undefined;
37123
+ }
37124
+ if (e2)
37125
+ return true;
37126
+ }
37127
+ return false;
37128
+ }, E: (a, b) => {
37129
+ var c = 0;
37130
+ Sc().forEach((d, e2) => {
37131
+ var h2 = b + c;
37132
+ e2 = F2[a + 4 * e2 >> 2] = h2;
37133
+ for (h2 = 0;h2 < d.length; ++h2)
37134
+ p[e2++] = d.charCodeAt(h2);
37135
+ p[e2] = 0;
37136
+ c += d.length + 1;
37137
+ });
37138
+ return 0;
37139
+ }, F: (a, b) => {
37140
+ var c = Sc();
37141
+ F2[a >> 2] = c.length;
37142
+ var d = 0;
37143
+ c.forEach((e2) => d += e2.length + 1);
37144
+ F2[b >> 2] = d;
37145
+ return 0;
37146
+ }, e: function(a) {
37147
+ try {
37148
+ var b = T(a);
37149
+ qa(b);
37150
+ return 0;
37151
+ } catch (c) {
37152
+ if (typeof W == "undefined" || c.name !== "ErrnoError")
37153
+ throw c;
37154
+ return c.Pa;
37155
+ }
37156
+ }, p: function(a, b) {
37157
+ try {
37158
+ var c = T(a);
37159
+ p[b] = c.tty ? 2 : P(c.mode) ? 3 : (c.mode & 61440) === 40960 ? 7 : 4;
37160
+ Na[b + 2 >> 1] = 0;
37161
+ H[b + 8 >> 3] = BigInt(0);
37162
+ H[b + 16 >> 3] = BigInt(0);
37163
+ return 0;
37164
+ } catch (d) {
37165
+ if (typeof W == "undefined" || d.name !== "ErrnoError")
37166
+ throw d;
37167
+ return d.Pa;
37168
+ }
37169
+ }, w: function(a, b, c, d) {
37170
+ try {
37171
+ a: {
37172
+ var e2 = T(a);
37173
+ a = b;
37174
+ for (var h2, k = b = 0;k < c; k++) {
37175
+ var q = F2[a >> 2], w = F2[a + 4 >> 2];
37176
+ a += 8;
37177
+ var v = Ec(e2, p, q, w, h2);
37178
+ if (0 > v) {
37179
+ var C = -1;
37180
+ break a;
37181
+ }
37182
+ b += v;
37183
+ if (v < w)
37184
+ break;
37185
+ typeof h2 != "undefined" && (h2 += v);
37186
+ }
37187
+ C = b;
37188
+ }
37189
+ F2[d >> 2] = C;
37190
+ return 0;
37191
+ } catch (G) {
37192
+ if (typeof W == "undefined" || G.name !== "ErrnoError")
37193
+ throw G;
37194
+ return G.Pa;
37195
+ }
37196
+ }, D: function(a, b, c, d) {
37197
+ b = -9007199254740992 > b || 9007199254740992 < b ? NaN : Number(b);
37198
+ try {
37199
+ if (isNaN(b))
37200
+ return 61;
37201
+ var e2 = T(a);
37202
+ mc(e2, b, c);
37203
+ H[d >> 3] = BigInt(e2.position);
37204
+ e2.ob && b === 0 && c === 0 && (e2.ob = null);
37205
+ return 0;
37206
+ } catch (h2) {
37207
+ if (typeof W == "undefined" || h2.name !== "ErrnoError")
37208
+ throw h2;
37209
+ return h2.Pa;
37210
+ }
37211
+ }, I: function(a) {
37212
+ try {
37213
+ var b = T(a);
37214
+ return b.Ma?.fsync ? b.Ma.fsync(b) : 0;
37215
+ } catch (c) {
37216
+ if (typeof W == "undefined" || c.name !== "ErrnoError")
37217
+ throw c;
37218
+ return c.Pa;
37219
+ }
37220
+ }, t: function(a, b, c, d) {
37221
+ try {
37222
+ a: {
37223
+ var e2 = T(a);
37224
+ a = b;
37225
+ for (var h2, k = b = 0;k < c; k++) {
37226
+ var q = F2[a >> 2], w = F2[a + 4 >> 2];
37227
+ a += 8;
37228
+ var v = pa(e2, p, q, w, h2);
37229
+ if (0 > v) {
37230
+ var C = -1;
37231
+ break a;
37232
+ }
37233
+ b += v;
37234
+ if (v < w)
37235
+ break;
37236
+ typeof h2 != "undefined" && (h2 += v);
37237
+ }
37238
+ C = b;
37239
+ }
37240
+ F2[d >> 2] = C;
37241
+ return 0;
37242
+ } catch (G) {
37243
+ if (typeof W == "undefined" || G.name !== "ErrnoError")
37244
+ throw G;
37245
+ return G.Pa;
37246
+ }
37247
+ }, k: Oc }, Z2;
37248
+ (async function() {
37249
+ function a(c) {
37250
+ Z2 = c.exports;
37251
+ Ka = Z2.M;
37252
+ Qa();
37253
+ Y = Z2.O;
37254
+ K--;
37255
+ f3.monitorRunDependencies?.(K);
37256
+ K == 0 && Sa && (c = Sa, Sa = null, c());
37257
+ return Z2;
37258
+ }
37259
+ K++;
37260
+ f3.monitorRunDependencies?.(K);
37261
+ var b = { a: Xc };
37262
+ if (f3.instantiateWasm)
37263
+ return new Promise((c) => {
37264
+ f3.instantiateWasm(b, (d, e2) => {
37265
+ a(d, e2);
37266
+ c(d.exports);
37267
+ });
37268
+ });
37269
+ Ua ??= f3.locateFile ? f3.locateFile("sql-wasm.wasm", D) : D + "sql-wasm.wasm";
37270
+ return a((await Xa(b)).instance);
37271
+ })();
37272
+ f3._sqlite3_free = (a) => (f3._sqlite3_free = Z2.P)(a);
37273
+ f3._sqlite3_value_text = (a) => (f3._sqlite3_value_text = Z2.Q)(a);
37274
+ f3._sqlite3_prepare_v2 = (a, b, c, d, e2) => (f3._sqlite3_prepare_v2 = Z2.R)(a, b, c, d, e2);
37275
+ f3._sqlite3_step = (a) => (f3._sqlite3_step = Z2.S)(a);
37276
+ f3._sqlite3_reset = (a) => (f3._sqlite3_reset = Z2.T)(a);
37277
+ f3._sqlite3_exec = (a, b, c, d, e2) => (f3._sqlite3_exec = Z2.U)(a, b, c, d, e2);
37278
+ f3._sqlite3_finalize = (a) => (f3._sqlite3_finalize = Z2.V)(a);
37279
+ f3._sqlite3_column_name = (a, b) => (f3._sqlite3_column_name = Z2.W)(a, b);
37280
+ f3._sqlite3_column_text = (a, b) => (f3._sqlite3_column_text = Z2.X)(a, b);
37281
+ f3._sqlite3_column_type = (a, b) => (f3._sqlite3_column_type = Z2.Y)(a, b);
37282
+ f3._sqlite3_errmsg = (a) => (f3._sqlite3_errmsg = Z2.Z)(a);
37283
+ f3._sqlite3_clear_bindings = (a) => (f3._sqlite3_clear_bindings = Z2._)(a);
37284
+ f3._sqlite3_value_blob = (a) => (f3._sqlite3_value_blob = Z2.$)(a);
37285
+ f3._sqlite3_value_bytes = (a) => (f3._sqlite3_value_bytes = Z2.aa)(a);
37286
+ f3._sqlite3_value_double = (a) => (f3._sqlite3_value_double = Z2.ba)(a);
37287
+ f3._sqlite3_value_int = (a) => (f3._sqlite3_value_int = Z2.ca)(a);
37288
+ f3._sqlite3_value_type = (a) => (f3._sqlite3_value_type = Z2.da)(a);
37289
+ f3._sqlite3_result_blob = (a, b, c, d) => (f3._sqlite3_result_blob = Z2.ea)(a, b, c, d);
37290
+ f3._sqlite3_result_double = (a, b) => (f3._sqlite3_result_double = Z2.fa)(a, b);
37291
+ f3._sqlite3_result_error = (a, b, c) => (f3._sqlite3_result_error = Z2.ga)(a, b, c);
37292
+ f3._sqlite3_result_int = (a, b) => (f3._sqlite3_result_int = Z2.ha)(a, b);
37293
+ f3._sqlite3_result_int64 = (a, b) => (f3._sqlite3_result_int64 = Z2.ia)(a, b);
37294
+ f3._sqlite3_result_null = (a) => (f3._sqlite3_result_null = Z2.ja)(a);
37295
+ f3._sqlite3_result_text = (a, b, c, d) => (f3._sqlite3_result_text = Z2.ka)(a, b, c, d);
37296
+ f3._sqlite3_aggregate_context = (a, b) => (f3._sqlite3_aggregate_context = Z2.la)(a, b);
37297
+ f3._sqlite3_column_count = (a) => (f3._sqlite3_column_count = Z2.ma)(a);
37298
+ f3._sqlite3_data_count = (a) => (f3._sqlite3_data_count = Z2.na)(a);
37299
+ f3._sqlite3_column_blob = (a, b) => (f3._sqlite3_column_blob = Z2.oa)(a, b);
37300
+ f3._sqlite3_column_bytes = (a, b) => (f3._sqlite3_column_bytes = Z2.pa)(a, b);
37301
+ f3._sqlite3_column_double = (a, b) => (f3._sqlite3_column_double = Z2.qa)(a, b);
37302
+ f3._sqlite3_bind_blob = (a, b, c, d, e2) => (f3._sqlite3_bind_blob = Z2.ra)(a, b, c, d, e2);
37303
+ f3._sqlite3_bind_double = (a, b, c) => (f3._sqlite3_bind_double = Z2.sa)(a, b, c);
37304
+ f3._sqlite3_bind_int = (a, b, c) => (f3._sqlite3_bind_int = Z2.ta)(a, b, c);
37305
+ f3._sqlite3_bind_text = (a, b, c, d, e2) => (f3._sqlite3_bind_text = Z2.ua)(a, b, c, d, e2);
37306
+ f3._sqlite3_bind_parameter_index = (a, b) => (f3._sqlite3_bind_parameter_index = Z2.va)(a, b);
37307
+ f3._sqlite3_sql = (a) => (f3._sqlite3_sql = Z2.wa)(a);
37308
+ f3._sqlite3_normalized_sql = (a) => (f3._sqlite3_normalized_sql = Z2.xa)(a);
37309
+ f3._sqlite3_changes = (a) => (f3._sqlite3_changes = Z2.ya)(a);
37310
+ f3._sqlite3_close_v2 = (a) => (f3._sqlite3_close_v2 = Z2.za)(a);
37311
+ f3._sqlite3_create_function_v2 = (a, b, c, d, e2, h2, k, q, w) => (f3._sqlite3_create_function_v2 = Z2.Aa)(a, b, c, d, e2, h2, k, q, w);
37312
+ f3._sqlite3_update_hook = (a, b, c) => (f3._sqlite3_update_hook = Z2.Ba)(a, b, c);
37313
+ f3._sqlite3_open = (a, b) => (f3._sqlite3_open = Z2.Ca)(a, b);
37314
+ var ia = f3._malloc = (a) => (ia = f3._malloc = Z2.Da)(a), fa = f3._free = (a) => (fa = f3._free = Z2.Ea)(a);
37315
+ f3._RegisterExtensionFunctions = (a) => (f3._RegisterExtensionFunctions = Z2.Fa)(a);
37316
+ var Db = (a, b) => (Db = Z2.Ga)(a, b), Wc = (a, b) => (Wc = Z2.Ha)(a, b), wa = (a) => (wa = Z2.Ia)(a), z2 = (a) => (z2 = Z2.Ja)(a), sa = () => (sa = Z2.Ka)();
37317
+ f3.stackSave = () => sa();
37318
+ f3.stackRestore = (a) => wa(a);
37319
+ f3.stackAlloc = (a) => z2(a);
37320
+ f3.cwrap = (a, b, c, d) => {
37321
+ var e2 = !c || c.every((h2) => h2 === "number" || h2 === "boolean");
37322
+ return b !== "string" && e2 && !d ? f3["_" + a] : (...h2) => Tc(a, b, c, h2);
37323
+ };
37324
+ f3.addFunction = Aa;
37325
+ f3.removeFunction = A2;
37326
+ f3.UTF8ToString = ua;
37327
+ f3.ALLOC_NORMAL = ea;
37328
+ f3.allocate = da;
37329
+ f3.allocateUTF8OnStack = xa;
37330
+ function Yc() {
37331
+ function a() {
37332
+ f3.calledRun = true;
37333
+ if (!La) {
37334
+ if (!f3.noFSInit && !Ib) {
37335
+ var b, c;
37336
+ Ib = true;
37337
+ d ??= f3.stdin;
37338
+ b ??= f3.stdout;
37339
+ c ??= f3.stderr;
37340
+ d ? V("stdin", d) : Zb("/dev/tty", "/dev/stdin");
37341
+ b ? V("stdout", null, b) : Zb("/dev/tty", "/dev/stdout");
37342
+ c ? V("stderr", null, c) : Zb("/dev/tty1", "/dev/stderr");
37343
+ oa("/dev/stdin", 0);
37344
+ oa("/dev/stdout", 1);
37345
+ oa("/dev/stderr", 1);
37346
+ }
37347
+ Z2.N();
37348
+ Jb = false;
37349
+ f3.onRuntimeInitialized?.();
37350
+ if (f3.postRun)
37351
+ for (typeof f3.postRun == "function" && (f3.postRun = [f3.postRun]);f3.postRun.length; ) {
37352
+ var d = f3.postRun.shift();
37353
+ $a.unshift(d);
37354
+ }
37355
+ Za($a);
37356
+ }
37357
+ }
37358
+ if (0 < K)
37359
+ Sa = Yc;
37360
+ else {
37361
+ if (f3.preRun)
37362
+ for (typeof f3.preRun == "function" && (f3.preRun = [f3.preRun]);f3.preRun.length; )
37363
+ bb();
37364
+ Za(ab);
37365
+ 0 < K ? Sa = Yc : f3.setStatus ? (f3.setStatus("Running..."), setTimeout(() => {
37366
+ setTimeout(() => f3.setStatus(""), 1);
37367
+ a();
37368
+ }, 1)) : a();
37369
+ }
37370
+ }
37371
+ if (f3.preInit)
37372
+ for (typeof f3.preInit == "function" && (f3.preInit = [f3.preInit]);0 < f3.preInit.length; )
37373
+ f3.preInit.pop()();
37374
+ Yc();
37375
+ return Module;
37376
+ });
37377
+ return initSqlJsPromise;
37378
+ };
37379
+ if (typeof exports === "object" && typeof module === "object") {
37380
+ module.exports = initSqlJs;
37381
+ module.exports.default = initSqlJs;
37382
+ } else if (typeof define === "function" && define["amd"]) {
37383
+ define([], function() {
37384
+ return initSqlJs;
35846
37385
  });
37386
+ } else if (typeof exports === "object") {
37387
+ exports["Module"] = initSqlJs;
35847
37388
  }
35848
- var wrappers = require_wrappers();
35849
- Database.prototype.prepare = wrappers.prepare;
35850
- Database.prototype.transaction = require_transaction();
35851
- Database.prototype.pragma = require_pragma();
35852
- Database.prototype.backup = require_backup();
35853
- Database.prototype.serialize = require_serialize();
35854
- Database.prototype.function = require_function();
35855
- Database.prototype.aggregate = require_aggregate();
35856
- Database.prototype.table = require_table();
35857
- Database.prototype.loadExtension = wrappers.loadExtension;
35858
- Database.prototype.exec = wrappers.exec;
35859
- Database.prototype.close = wrappers.close;
35860
- Database.prototype.defaultSafeIntegers = wrappers.defaultSafeIntegers;
35861
- Database.prototype.unsafeMode = wrappers.unsafeMode;
35862
- Database.prototype[util2.inspect] = require_inspect();
35863
- module.exports = Database;
35864
- });
35865
-
35866
- // ../../node_modules/better-sqlite3/lib/index.js
35867
- var require_lib2 = __commonJS((exports, module) => {
35868
- module.exports = require_database();
35869
- module.exports.SqliteError = require_sqlite_error();
35870
37389
  });
35871
37390
 
35872
37391
  // src/config.ts
@@ -49406,13 +50925,57 @@ function date4(params) {
49406
50925
 
49407
50926
  // ../../node_modules/zod/v4/classic/external.js
49408
50927
  config(en_default());
50928
+ // ../core/src/config/base.ts
50929
+ var baseModelConfigSchema = exports_external.object({
50930
+ provider: exports_external.string().optional(),
50931
+ model: exports_external.string().optional(),
50932
+ parameters: exports_external.record(exports_external.string(), exports_external.unknown()).optional()
50933
+ });
50934
+ var baseApprovalConfigSchema = exports_external.object({
50935
+ level: exports_external.enum(["none", "destructive", "commits", "all"]).optional(),
50936
+ autoApprove: exports_external.boolean().optional(),
50937
+ maxCost: exports_external.number().positive().optional()
50938
+ });
50939
+ var providerConfigSchema = exports_external.object({
50940
+ apiKey: exports_external.string().optional(),
50941
+ defaultModel: exports_external.string().optional(),
50942
+ defaultParameters: exports_external.record(exports_external.string(), exports_external.unknown()).optional(),
50943
+ location: exports_external.string().optional(),
50944
+ project: exports_external.string().optional(),
50945
+ keyFile: exports_external.string().optional(),
50946
+ baseUrl: exports_external.string().optional(),
50947
+ name: exports_external.string().optional()
50948
+ });
50949
+ var modelConfigSchema = baseModelConfigSchema.extend({
50950
+ budget: exports_external.number().positive().optional(),
50951
+ rules: exports_external.union([exports_external.string(), exports_external.array(exports_external.string()).optional()]).optional()
50952
+ });
50953
+ var toolConfigSchema = exports_external.union([
50954
+ exports_external.boolean(),
50955
+ baseModelConfigSchema
50956
+ ]);
50957
+
49409
50958
  // ../core/src/config/memory.ts
49410
50959
  var memoryConfigSchema = exports_external.object({
49411
50960
  enabled: exports_external.boolean().optional().default(true),
49412
50961
  type: exports_external.enum(["sqlite", "memory"]).optional().default("sqlite"),
49413
50962
  path: exports_external.string().optional().default("~/.config/polka-codes/memory.sqlite")
49414
50963
  }).strict().optional();
49415
-
50964
+ var DEFAULT_MEMORY_CONFIG = {
50965
+ enabled: true,
50966
+ type: "sqlite",
50967
+ path: "~/.config/polka-codes/memory.sqlite"
50968
+ };
50969
+ function resolveHomePath(path) {
50970
+ if (path.startsWith("~")) {
50971
+ const home = process.env.HOME || process.env.USERPROFILE || ".";
50972
+ if (home === ".") {
50973
+ throw new Error("Cannot resolve home directory: HOME and USERPROFILE environment variables are not set");
50974
+ }
50975
+ return `${home}${path.slice(1)}`;
50976
+ }
50977
+ return path;
50978
+ }
49416
50979
  // ../core/src/config.ts
49417
50980
  var ruleSchema = exports_external.union([
49418
50981
  exports_external.string(),
@@ -49426,20 +50989,10 @@ var ruleSchema = exports_external.union([
49426
50989
  branch: exports_external.string().optional()
49427
50990
  }).strict()
49428
50991
  ]);
49429
- var providerConfigSchema = exports_external.object({
49430
- apiKey: exports_external.string().optional(),
49431
- defaultModel: exports_external.string().optional(),
49432
- defaultParameters: exports_external.record(exports_external.string(), exports_external.any()).optional(),
49433
- location: exports_external.string().optional(),
49434
- project: exports_external.string().optional(),
49435
- keyFile: exports_external.string().optional(),
49436
- baseUrl: exports_external.string().optional(),
49437
- name: exports_external.string().optional()
49438
- });
49439
50992
  var providerModelSchema = exports_external.object({
49440
50993
  provider: exports_external.string().optional(),
49441
50994
  model: exports_external.string().optional(),
49442
- parameters: exports_external.record(exports_external.string(), exports_external.any()).optional(),
50995
+ parameters: exports_external.record(exports_external.string(), exports_external.unknown()).optional(),
49443
50996
  budget: exports_external.number().positive().optional(),
49444
50997
  rules: exports_external.array(ruleSchema).optional().or(exports_external.string()).optional()
49445
50998
  });
@@ -49452,7 +51005,7 @@ var scriptSchema = exports_external.union([
49452
51005
  exports_external.object({
49453
51006
  workflow: exports_external.string(),
49454
51007
  description: exports_external.string().optional(),
49455
- input: exports_external.record(exports_external.string(), exports_external.any()).optional()
51008
+ input: exports_external.record(exports_external.string(), exports_external.unknown()).optional()
49456
51009
  }).strict(),
49457
51010
  exports_external.object({
49458
51011
  script: exports_external.string(),
@@ -49531,7 +51084,7 @@ var configSchema = exports_external.object({
49531
51084
  providers: exports_external.record(exports_external.string(), providerConfigSchema).optional(),
49532
51085
  defaultProvider: exports_external.string().optional(),
49533
51086
  defaultModel: exports_external.string().optional(),
49534
- defaultParameters: exports_external.record(exports_external.string(), exports_external.any()).optional(),
51087
+ defaultParameters: exports_external.record(exports_external.string(), exports_external.unknown()).optional(),
49535
51088
  maxMessageCount: exports_external.number().int().positive().optional(),
49536
51089
  budget: exports_external.number().positive().optional(),
49537
51090
  retryCount: exports_external.number().int().min(0).optional(),
@@ -60617,7 +62170,7 @@ var uiMessagesSchema = lazyValidator(() => zodSchema(exports_external.array(expo
60617
62170
  var WorkflowInputDefinitionSchema = exports_external.object({
60618
62171
  id: exports_external.string(),
60619
62172
  description: exports_external.string().nullish(),
60620
- default: exports_external.any().nullish()
62173
+ default: exports_external.unknown().nullish()
60621
62174
  });
60622
62175
  var WorkflowStepDefinitionSchema = exports_external.object({
60623
62176
  id: exports_external.string(),
@@ -60625,7 +62178,7 @@ var WorkflowStepDefinitionSchema = exports_external.object({
60625
62178
  task: exports_external.string(),
60626
62179
  output: exports_external.string().nullish(),
60627
62180
  expected_outcome: exports_external.string().nullish(),
60628
- outputSchema: exports_external.any().nullish(),
62181
+ outputSchema: exports_external.unknown().nullish(),
60629
62182
  timeout: exports_external.number().positive().nullish()
60630
62183
  });
60631
62184
  var WhileLoopStepSchema = exports_external.object({
@@ -61723,7 +63276,12 @@ function getGlobalConfigPath(home = homedir()) {
61723
63276
  function loadConfigAtPath(path) {
61724
63277
  try {
61725
63278
  return readConfig(path);
61726
- } catch (_error) {
63279
+ } catch (error48) {
63280
+ if (error48 instanceof ZodError) {
63281
+ console.warn(`Config validation failed for ${path}: ${error48.message}`);
63282
+ } else {
63283
+ console.debug(`Could not load config from ${path}: ${error48 instanceof Error ? error48.message : String(error48)}`);
63284
+ }
61727
63285
  return;
61728
63286
  }
61729
63287
  }
@@ -61751,7 +63309,7 @@ function mergeConfigs(configs) {
61751
63309
  merged.rules = mergeArray(accRules, configRules);
61752
63310
  merged.excludeFiles = mergeArray(acc.excludeFiles, config3.excludeFiles);
61753
63311
  return merged;
61754
- });
63312
+ }, {});
61755
63313
  return mergedConfig;
61756
63314
  }
61757
63315
  async function resolveRules(rules) {
@@ -61872,14 +63430,19 @@ var readConfig = (path) => {
61872
63430
  var readLocalConfig = (path) => {
61873
63431
  try {
61874
63432
  return readConfig(path ?? localConfigFileName);
61875
- } catch (_error) {
63433
+ } catch (error48) {
63434
+ if (error48 instanceof ZodError) {
63435
+ console.warn(`Local config validation failed for ${path ?? localConfigFileName}: ${error48.message}`);
63436
+ } else {
63437
+ console.debug(`Could not load local config from ${path ?? localConfigFileName}: ${error48 instanceof Error ? error48.message : String(error48)}`);
63438
+ }
61876
63439
  return;
61877
63440
  }
61878
63441
  };
61879
63442
  // src/memory-manager.ts
61880
63443
  class MemoryManager {
61881
63444
  store;
61882
- constructor(store, _cwd) {
63445
+ constructor(store) {
61883
63446
  this.store = store;
61884
63447
  }
61885
63448
  async readMemory(topic) {
@@ -61892,7 +63455,8 @@ class MemoryManager {
61892
63455
  const finalQuery = {
61893
63456
  ...query
61894
63457
  };
61895
- if (!options?.operation && !finalQuery.limit) {
63458
+ const operation = options?.operation;
63459
+ if ((operation === "select" || !operation) && !finalQuery.limit) {
61896
63460
  finalQuery.limit = 1000;
61897
63461
  }
61898
63462
  return this.store.queryMemory(finalQuery, options);
@@ -61903,14 +63467,66 @@ class MemoryManager {
61903
63467
  async getStats() {
61904
63468
  return this.store.getStats();
61905
63469
  }
61906
- close() {
61907
- this.store.close();
63470
+ async close() {
63471
+ await this.store.close();
63472
+ }
63473
+ async transaction(callback) {
63474
+ const storeWithTransaction = this.store;
63475
+ if (typeof storeWithTransaction.transaction === "function") {
63476
+ return storeWithTransaction.transaction(callback);
63477
+ }
63478
+ return callback();
63479
+ }
63480
+ }
63481
+ // src/project-scope.ts
63482
+ import { existsSync as existsSync2 } from "node:fs";
63483
+ import { dirname, normalize, resolve as resolve2, sep } from "node:path";
63484
+ function detectProjectScope(cwd) {
63485
+ const projectPath = findProjectRoot(cwd);
63486
+ if (!projectPath) {
63487
+ return "global";
63488
+ }
63489
+ const normalizedPath = normalizePath(projectPath);
63490
+ return `project:${normalizedPath}`;
63491
+ }
63492
+ function findProjectRoot(dir) {
63493
+ if (!existsSync2(dir)) {
63494
+ return null;
63495
+ }
63496
+ const primaryMarkers = [".git", "package.json"];
63497
+ const secondaryMarkers = [
63498
+ "Cargo.toml",
63499
+ "go.mod",
63500
+ "pyproject.toml",
63501
+ "requirements.txt",
63502
+ "setup.py",
63503
+ "Gemfile",
63504
+ "pom.xml",
63505
+ "build.gradle"
63506
+ ];
63507
+ for (const marker16 of primaryMarkers) {
63508
+ if (existsSync2(resolve2(dir, marker16))) {
63509
+ return dir;
63510
+ }
63511
+ }
63512
+ for (const marker16 of secondaryMarkers) {
63513
+ if (existsSync2(resolve2(dir, marker16))) {
63514
+ return dir;
63515
+ }
63516
+ }
63517
+ const parent = dirname(dir);
63518
+ if (parent === dir) {
63519
+ return null;
61908
63520
  }
63521
+ return findProjectRoot(parent);
63522
+ }
63523
+ function normalizePath(path) {
63524
+ return normalize(path).split(sep).join("/");
61909
63525
  }
61910
63526
  // src/provider.ts
61911
63527
  import { spawn as spawn2 } from "node:child_process";
61912
63528
  import { mkdir, readFile as readFile2, rename, unlink, writeFile } from "node:fs/promises";
61913
- import { dirname, normalize, resolve as resolve3 } from "node:path";
63529
+ import { dirname as dirname2, normalize as normalize2, resolve as resolve4 } from "node:path";
61914
63530
 
61915
63531
  // ../../node_modules/@ai-sdk/google-vertex/dist/index.mjs
61916
63532
  var import_google_auth_library = __toESM(require_src7(), 1);
@@ -63989,12 +65605,12 @@ function isPlainObject3(value) {
63989
65605
  }
63990
65606
  return Object.getPrototypeOf(value) === proto;
63991
65607
  }
63992
- function deepMerge(...objects) {
65608
+ function deepMerge2(...objects) {
63993
65609
  const output = {};
63994
65610
  for (const obj of objects) {
63995
65611
  for (const [key, value] of Object.entries(obj)) {
63996
65612
  const prevValue = output[key];
63997
- output[key] = isPlainObject3(prevValue) && isPlainObject3(value) ? deepMerge(prevValue, value) : value;
65613
+ output[key] = isPlainObject3(prevValue) && isPlainObject3(value) ? deepMerge2(prevValue, value) : value;
63998
65614
  }
63999
65615
  }
64000
65616
  return output;
@@ -64004,7 +65620,7 @@ function makeTheme(...themes) {
64004
65620
  defaultTheme,
64005
65621
  ...themes.filter((theme) => theme != null)
64006
65622
  ];
64007
- return deepMerge(...themesToMerge);
65623
+ return deepMerge2(...themesToMerge);
64008
65624
  }
64009
65625
 
64010
65626
  // ../../node_modules/@inquirer/core/dist/lib/use-prefix.js
@@ -64882,13 +66498,13 @@ class ScreenManager {
64882
66498
  // ../../node_modules/@inquirer/core/dist/lib/promise-polyfill.js
64883
66499
  class PromisePolyfill extends Promise {
64884
66500
  static withResolver() {
64885
- let resolve2;
66501
+ let resolve3;
64886
66502
  let reject;
64887
66503
  const promise2 = new Promise((res, rej) => {
64888
- resolve2 = res;
66504
+ resolve3 = res;
64889
66505
  reject = rej;
64890
66506
  });
64891
- return { promise: promise2, resolve: resolve2, reject };
66507
+ return { promise: promise2, resolve: resolve3, reject };
64892
66508
  }
64893
66509
  }
64894
66510
 
@@ -64922,7 +66538,7 @@ function createPrompt(view) {
64922
66538
  output
64923
66539
  });
64924
66540
  const screen = new ScreenManager(rl);
64925
- const { promise: promise2, resolve: resolve2, reject } = PromisePolyfill.withResolver();
66541
+ const { promise: promise2, resolve: resolve3, reject } = PromisePolyfill.withResolver();
64926
66542
  const cancel = () => reject(new CancelPromptError);
64927
66543
  if (signal) {
64928
66544
  const abort = () => reject(new AbortPromptError({ cause: signal.reason }));
@@ -64949,7 +66565,7 @@ function createPrompt(view) {
64949
66565
  cycle(() => {
64950
66566
  try {
64951
66567
  const nextView = view(config3, (value) => {
64952
- setImmediate(() => resolve2(value));
66568
+ setImmediate(() => resolve3(value));
64953
66569
  });
64954
66570
  if (nextView === undefined) {
64955
66571
  const callerFilename = callSites[1]?.getFileName();
@@ -65326,7 +66942,7 @@ function checkRipgrep() {
65326
66942
  // src/utils/listFiles.ts
65327
66943
  var import_ignore = __toESM(require_ignore(), 1);
65328
66944
  import { promises as fs3 } from "node:fs";
65329
- import { join as join2, relative, resolve as resolve2 } from "node:path";
66945
+ import { join as join2, relative, resolve as resolve3 } from "node:path";
65330
66946
  var DEFAULT_IGNORES = [
65331
66947
  "__pycache__",
65332
66948
  ".DS_Store",
@@ -65369,9 +66985,9 @@ async function listFiles(dirPath, recursive, maxCount, cwd, excludeFiles, includ
65369
66985
  const processedDirs = new Set;
65370
66986
  const queue = [
65371
66987
  {
65372
- path: resolve2(dirPath),
66988
+ path: resolve3(dirPath),
65373
66989
  patterns: rootPatterns,
65374
- relPath: relative(cwd, resolve2(dirPath)).replace(/\\/g, "/") || "."
66990
+ relPath: relative(cwd, resolve3(dirPath)).replace(/\\/g, "/") || "."
65375
66991
  }
65376
66992
  ];
65377
66993
  while (queue.length > 0) {
@@ -65452,7 +67068,7 @@ async function searchFiles(path, regex2, filePattern, cwd, excludeFiles) {
65452
67068
  }
65453
67069
  }
65454
67070
  args.push(regex2, path);
65455
- return new Promise((resolve3, reject) => {
67071
+ return new Promise((resolve4, reject) => {
65456
67072
  const results = [];
65457
67073
  const rg = spawn("rg", args, {
65458
67074
  cwd,
@@ -65471,7 +67087,7 @@ async function searchFiles(path, regex2, filePattern, cwd, excludeFiles) {
65471
67087
  reject(new Error(`Ripgrep process exited with code ${code}`));
65472
67088
  return;
65473
67089
  }
65474
- resolve3(results);
67090
+ resolve4(results);
65475
67091
  });
65476
67092
  });
65477
67093
  }
@@ -65486,12 +67102,59 @@ class InMemoryStore {
65486
67102
  this.#data = data;
65487
67103
  }
65488
67104
  }
67105
+ function isIMemoryStore(store) {
67106
+ return "readMemory" in store && "updateMemory" in store;
67107
+ }
65489
67108
  var getProvider = (options = {}) => {
65490
67109
  const ig = import_ignore2.default().add(options.excludeFiles ?? []);
65491
67110
  const memoryStore = options.memoryStore ?? new InMemoryStore;
65492
67111
  const todoItemStore = options.todoItemStore ?? new InMemoryStore;
65493
67112
  const defaultMemoryTopic = ":default:";
65494
67113
  const searchModel = options.getModel?.("search");
67114
+ const readMemoryKV = async (topic) => {
67115
+ if (!isIMemoryStore(memoryStore)) {
67116
+ const data = await memoryStore.read() ?? {};
67117
+ return data[topic];
67118
+ }
67119
+ return memoryStore.readMemory(topic);
67120
+ };
67121
+ const updateMemoryKV = async (operation, topic, content) => {
67122
+ if (!isIMemoryStore(memoryStore)) {
67123
+ const data = await memoryStore.read() ?? {};
67124
+ switch (operation) {
67125
+ case "append":
67126
+ if (content === undefined) {
67127
+ throw new Error("Content is required for append operation.");
67128
+ }
67129
+ data[topic] = `${data[topic] || ""}
67130
+ ${content}`;
67131
+ break;
67132
+ case "replace":
67133
+ if (content === undefined) {
67134
+ throw new Error("Content is required for replace operation.");
67135
+ }
67136
+ data[topic] = content;
67137
+ break;
67138
+ case "remove":
67139
+ delete data[topic];
67140
+ break;
67141
+ }
67142
+ await memoryStore.write(data);
67143
+ return;
67144
+ }
67145
+ await memoryStore.updateMemory(operation, topic, content);
67146
+ };
67147
+ const listMemoryTopicsKV = async () => {
67148
+ if (!isIMemoryStore(memoryStore)) {
67149
+ const data = await memoryStore.read() ?? {};
67150
+ return Object.keys(data);
67151
+ }
67152
+ const entries = await memoryStore.queryMemory({});
67153
+ if (Array.isArray(entries)) {
67154
+ return entries.map((e2) => e2.name);
67155
+ }
67156
+ return [];
67157
+ };
65495
67158
  const provider2 = {
65496
67159
  listTodoItems: async (id, status) => {
65497
67160
  const todoItems = await todoItemStore.read() ?? [];
@@ -65590,35 +67253,14 @@ var getProvider = (options = {}) => {
65590
67253
  }
65591
67254
  },
65592
67255
  listMemoryTopics: async () => {
65593
- const memory2 = await memoryStore.read() ?? {};
65594
- return Object.keys(memory2);
67256
+ return listMemoryTopicsKV();
65595
67257
  },
65596
67258
  readMemory: async (topic = defaultMemoryTopic) => {
65597
- const memory2 = await memoryStore.read() ?? {};
65598
- return memory2[topic];
67259
+ return readMemoryKV(topic);
65599
67260
  },
65600
67261
  updateMemory: async (operation, topic, content) => {
65601
67262
  const memoryTopic = topic ?? defaultMemoryTopic;
65602
- const memory2 = await memoryStore.read() ?? {};
65603
- switch (operation) {
65604
- case "append":
65605
- if (content === undefined) {
65606
- throw new Error("Content is required for append operation.");
65607
- }
65608
- memory2[memoryTopic] = `${memory2[memoryTopic] || ""}
65609
- ${content}`;
65610
- break;
65611
- case "replace":
65612
- if (content === undefined) {
65613
- throw new Error("Content is required for replace operation.");
65614
- }
65615
- memory2[memoryTopic] = content;
65616
- break;
65617
- case "remove":
65618
- delete memory2[memoryTopic];
65619
- break;
65620
- }
65621
- await memoryStore.write(memory2);
67263
+ await updateMemoryKV(operation, memoryTopic, content);
65622
67264
  },
65623
67265
  readFile: async (path, includeIgnored) => {
65624
67266
  if (!includeIgnored && ig.ignores(path)) {
@@ -65634,7 +67276,7 @@ ${content}`;
65634
67276
  if (ig.ignores(path)) {
65635
67277
  throw new Error(`Not allow to access file ${path}`);
65636
67278
  }
65637
- await mkdir(dirname(path), { recursive: true });
67279
+ await mkdir(dirname2(path), { recursive: true });
65638
67280
  return await writeFile(path, content, "utf8");
65639
67281
  },
65640
67282
  removeFile: async (path) => {
@@ -65655,7 +67297,7 @@ ${content}`;
65655
67297
  readBinaryFile: async (url2) => {
65656
67298
  if (url2.startsWith("file://")) {
65657
67299
  const filePath = decodeURIComponent(url2.substring("file://".length));
65658
- const resolvedPath = normalize(resolve3(process.cwd(), filePath));
67300
+ const resolvedPath = normalize2(resolve4(process.cwd(), filePath));
65659
67301
  if (!resolvedPath.startsWith(process.cwd())) {
65660
67302
  throw new Error(`Access to file path "${filePath}" is restricted.`);
65661
67303
  }
@@ -65678,7 +67320,7 @@ ${content}`;
65678
67320
  };
65679
67321
  },
65680
67322
  executeCommand: (command, _needApprove) => {
65681
- return new Promise((resolve4, reject) => {
67323
+ return new Promise((resolve5, reject) => {
65682
67324
  options.command?.onStarted(command);
65683
67325
  const child = spawn2(command, [], {
65684
67326
  shell: true,
@@ -65703,7 +67345,7 @@ ${content}`;
65703
67345
  try {
65704
67346
  const summary = await options.summarizeOutput(stdoutText, stderrText);
65705
67347
  if (summary) {
65706
- resolve4({
67348
+ resolve5({
65707
67349
  summary,
65708
67350
  stdout: stdoutText,
65709
67351
  stderr: stderrText,
@@ -65715,7 +67357,7 @@ ${content}`;
65715
67357
  console.error("Summarization failed:", _e);
65716
67358
  }
65717
67359
  }
65718
- resolve4({
67360
+ resolve5({
65719
67361
  stdout: stdoutText,
65720
67362
  stderr: stderrText,
65721
67363
  exitCode: code ?? 0
@@ -65786,19 +67428,144 @@ ${content}`;
65786
67428
  return provider2;
65787
67429
  };
65788
67430
  // src/sqlite-memory-store.ts
65789
- var import_better_sqlite3 = __toESM(require_lib2(), 1);
67431
+ import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
65790
67432
  import { randomUUID } from "node:crypto";
65791
- import { existsSync as existsSync2 } from "node:fs";
65792
- import { mkdir as mkdir2, rename as rename2 } from "node:fs/promises";
65793
- import { dirname as dirname2, resolve as resolve4 } from "node:path";
67433
+ import { existsSync as existsSync3 } from "node:fs";
67434
+ import { mkdir as mkdir2, readFile as readFile3, rename as rename2, writeFile as writeFile2 } from "node:fs/promises";
67435
+ import { dirname as dirname3, resolve as resolve5 } from "node:path";
67436
+ var import_sql = __toESM(require_sql_wasm(), 1);
67437
+
67438
+ class FileLock {
67439
+ lockfilePath;
67440
+ static LOCK_TIMEOUT = 30000;
67441
+ constructor(dbPath) {
67442
+ this.lockfilePath = `${dbPath}.lock`;
67443
+ }
67444
+ async acquire(retries = 10, delay2 = 100) {
67445
+ for (let i2 = 0;i2 < retries; i2++) {
67446
+ try {
67447
+ const lockData = JSON.stringify({
67448
+ pid: process.pid,
67449
+ acquiredAt: Date.now()
67450
+ });
67451
+ await writeFile2(this.lockfilePath, lockData, {
67452
+ flag: "wx",
67453
+ mode: 384
67454
+ });
67455
+ return;
67456
+ } catch (error48) {
67457
+ const errorCode = error48?.code;
67458
+ if (errorCode === "EEXIST") {
67459
+ try {
67460
+ const lockContent = await readFile3(this.lockfilePath, "utf-8");
67461
+ const lockData = JSON.parse(lockContent);
67462
+ if (!lockData || typeof lockData.acquiredAt !== "number" || lockData.acquiredAt <= 0) {
67463
+ console.warn(`[FileLock] Lock file has invalid acquiredAt, treating as stale`);
67464
+ await rename2(this.lockfilePath, `${this.lockfilePath}.invalid.${Date.now()}`);
67465
+ continue;
67466
+ }
67467
+ const lockAge = Date.now() - lockData.acquiredAt;
67468
+ if (lockAge > FileLock.LOCK_TIMEOUT) {
67469
+ console.warn(`[FileLock] Breaking stale lock (age: ${lockAge}ms)`);
67470
+ await rename2(this.lockfilePath, `${this.lockfilePath}.stale.${Date.now()}`);
67471
+ continue;
67472
+ }
67473
+ } catch (readError) {
67474
+ if (readError instanceof SyntaxError) {
67475
+ console.warn(`[FileLock] Lock file contains invalid JSON, treating as stale`);
67476
+ await rename2(this.lockfilePath, `${this.lockfilePath}.corrupt.${Date.now()}`);
67477
+ continue;
67478
+ }
67479
+ }
67480
+ if (i2 < retries - 1) {
67481
+ await new Promise((resolve6) => setTimeout(resolve6, delay2));
67482
+ } else {
67483
+ throw new Error(`Cannot acquire lock after ${retries} retries (file: ${this.lockfilePath})`);
67484
+ }
67485
+ } else {
67486
+ throw error48;
67487
+ }
67488
+ }
67489
+ }
67490
+ }
67491
+ async release() {
67492
+ try {
67493
+ await rename2(this.lockfilePath, `${this.lockfilePath}.released.${Date.now()}`);
67494
+ } catch (error48) {
67495
+ const errorCode = error48.code;
67496
+ if (errorCode !== "ENOENT") {
67497
+ console.warn(`[FileLock] Error releasing lock: ${error48 instanceof Error ? error48.message : String(error48)}`);
67498
+ }
67499
+ }
67500
+ }
67501
+ }
67502
+
67503
+ class ReentrantMutex {
67504
+ queue = [];
67505
+ locked = false;
67506
+ lockCount = 0;
67507
+ owner = null;
67508
+ async acquire(owner) {
67509
+ if (this.locked && this.owner === owner) {
67510
+ this.lockCount++;
67511
+ return () => this.release(owner);
67512
+ }
67513
+ while (this.locked) {
67514
+ await new Promise((resolve6) => this.queue.push(resolve6));
67515
+ }
67516
+ this.locked = true;
67517
+ this.owner = owner;
67518
+ this.lockCount = 1;
67519
+ return () => this.release(owner);
67520
+ }
67521
+ release(owner) {
67522
+ if (this.owner !== owner) {
67523
+ return;
67524
+ }
67525
+ this.lockCount--;
67526
+ if (this.lockCount === 0) {
67527
+ this.locked = false;
67528
+ this.owner = null;
67529
+ const next = this.queue.shift();
67530
+ if (next) {
67531
+ next();
67532
+ }
67533
+ }
67534
+ }
67535
+ }
67536
+ var SqlJs = null;
67537
+ var SqlJsInitPromise = null;
67538
+ async function getSqlJs() {
67539
+ if (SqlJs) {
67540
+ return SqlJs;
67541
+ }
67542
+ if (SqlJsInitPromise) {
67543
+ return SqlJsInitPromise;
67544
+ }
67545
+ SqlJsInitPromise = import_sql.default({});
67546
+ SqlJs = await SqlJsInitPromise;
67547
+ return SqlJs;
67548
+ }
67549
+ var transactionOwnerStorage = new AsyncLocalStorage2;
65794
67550
 
65795
67551
  class SQLiteMemoryStore {
65796
67552
  db = null;
65797
67553
  dbPromise = null;
65798
67554
  config;
65799
67555
  currentScope;
65800
- maxRetries = 3;
65801
- retryDelay = 100;
67556
+ inTransaction = false;
67557
+ transactionMutex = new ReentrantMutex;
67558
+ fileLock;
67559
+ getDbPath() {
67560
+ return this.config.path || DEFAULT_MEMORY_CONFIG.path;
67561
+ }
67562
+ getFileLock() {
67563
+ if (!this.fileLock) {
67564
+ const dbPath = this.resolvePath(this.getDbPath());
67565
+ this.fileLock = new FileLock(dbPath);
67566
+ }
67567
+ return this.fileLock;
67568
+ }
65802
67569
  static SORT_COLUMNS = {
65803
67570
  created: "created_at",
65804
67571
  updated: "updated_at",
@@ -65819,21 +67586,40 @@ class SQLiteMemoryStore {
65819
67586
  if (this.db) {
65820
67587
  return this.db;
65821
67588
  }
65822
- const dbPath = this.resolvePath(this.config.path || "~/.config/polka-codes/memory.sqlite");
67589
+ const dbPath = this.resolvePath(this.getDbPath());
65823
67590
  try {
65824
- const dir = dirname2(dbPath);
65825
- if (!existsSync2(dir)) {
67591
+ const dir = dirname3(dbPath);
67592
+ if (!existsSync3(dir)) {
65826
67593
  await mkdir2(dir, { recursive: true, mode: 448 });
65827
67594
  }
65828
- if (!existsSync2(dbPath)) {
65829
- const { openSync, closeSync } = await import("node:fs");
65830
- const fd = openSync(dbPath, "w");
65831
- closeSync(fd);
65832
- await import("node:fs/promises").then((fs4) => fs4.chmod(dbPath, 384));
67595
+ let dbData;
67596
+ if (existsSync3(dbPath)) {
67597
+ const lock = this.getFileLock();
67598
+ await lock.acquire();
67599
+ try {
67600
+ try {
67601
+ dbData = await readFile3(dbPath);
67602
+ if (dbData.length >= 16) {
67603
+ const header = String.fromCharCode(...dbData.subarray(0, 15));
67604
+ if (header !== "SQLite format 3") {
67605
+ console.warn("[SQLiteMemoryStore] Invalid SQLite database header, will recreate");
67606
+ dbData = undefined;
67607
+ }
67608
+ }
67609
+ } catch (error48) {
67610
+ const errorCode = error48?.code;
67611
+ if (errorCode === "ENOENT") {
67612
+ dbData = undefined;
67613
+ } else {
67614
+ throw new Error(`Failed to read database file at ${dbPath}: ${error48 instanceof Error ? error48.message : String(error48)}`);
67615
+ }
67616
+ }
67617
+ } finally {
67618
+ await lock.release();
67619
+ }
65833
67620
  }
65834
- const db2 = new import_better_sqlite3.default(dbPath, {
65835
- verbose: process.env.SQLITE_DEBUG ? console.log : undefined
65836
- });
67621
+ const SqlJs2 = await getSqlJs();
67622
+ const db2 = new SqlJs2.Database(dbData);
65837
67623
  this.configurePragmas(db2);
65838
67624
  this.checkIntegrity(db2);
65839
67625
  this.initializeSchema(db2);
@@ -65841,7 +67627,7 @@ class SQLiteMemoryStore {
65841
67627
  return db2;
65842
67628
  } catch (error48) {
65843
67629
  console.error("[SQLiteMemoryStore] Initialization failed:", error48);
65844
- if (existsSync2(dbPath)) {
67630
+ if (existsSync3(dbPath)) {
65845
67631
  const backupPath = `${dbPath}.corrupted.${Date.now()}`;
65846
67632
  console.warn(`[SQLiteMemoryStore] Backing up corrupted database to: ${backupPath}`);
65847
67633
  try {
@@ -65860,20 +67646,33 @@ class SQLiteMemoryStore {
65860
67646
  })();
65861
67647
  return this.dbPromise;
65862
67648
  }
67649
+ async saveDatabase() {
67650
+ if (!this.db) {
67651
+ return;
67652
+ }
67653
+ const lock = this.getFileLock();
67654
+ await lock.acquire();
67655
+ try {
67656
+ const dbPath = this.resolvePath(this.getDbPath());
67657
+ const tempPath = `${dbPath}.tmp`;
67658
+ const data = this.db.export();
67659
+ await writeFile2(tempPath, data, { mode: 384 });
67660
+ await rename2(tempPath, dbPath);
67661
+ } finally {
67662
+ await lock.release();
67663
+ }
67664
+ }
65863
67665
  configurePragmas(db2) {
65864
- db2.pragma("journal_mode = WAL");
65865
- db2.pragma("synchronous = NORMAL");
65866
- db2.pragma("busy_timeout = 5000");
65867
- db2.pragma("foreign_keys = ON");
65868
- db2.pragma("temp_store = MEMORY");
65869
- db2.pragma("mmap_size = 30000000000");
65870
- db2.pragma("page_size = 4096");
67666
+ db2.run("PRAGMA synchronous = NORMAL");
67667
+ db2.run("PRAGMA busy_timeout = 5000");
67668
+ db2.run("PRAGMA foreign_keys = ON");
67669
+ db2.run("PRAGMA temp_store = MEMORY");
65871
67670
  }
65872
67671
  checkIntegrity(db2) {
65873
67672
  try {
65874
- const result = db2.pragma("integrity_check", { simple: true });
65875
- if (result !== "ok") {
65876
- throw new Error(`Database integrity check failed: ${result}`);
67673
+ const results = db2.exec("SELECT 1");
67674
+ if (results.length === 0) {
67675
+ throw new Error("Database query returned no results");
65877
67676
  }
65878
67677
  } catch (error48) {
65879
67678
  console.error("[SQLiteMemoryStore] Integrity check failed:", error48);
@@ -65881,7 +67680,7 @@ class SQLiteMemoryStore {
65881
67680
  }
65882
67681
  }
65883
67682
  initializeSchema(db2) {
65884
- db2.exec(`
67683
+ db2.run(`
65885
67684
  CREATE TABLE IF NOT EXISTS memory_entries (
65886
67685
  id TEXT PRIMARY KEY,
65887
67686
  name TEXT NOT NULL CHECK(length(name) > 0),
@@ -65898,10 +67697,8 @@ class SQLiteMemoryStore {
65898
67697
  UNIQUE(name, scope)
65899
67698
  )
65900
67699
  `);
65901
- db2.exec(`
65902
- CREATE INDEX IF NOT EXISTS idx_memory_entries_scope_type ON memory_entries(scope, entry_type);
65903
- CREATE INDEX IF NOT EXISTS idx_memory_entries_updated ON memory_entries(updated_at);
65904
- `);
67700
+ db2.run("CREATE INDEX IF NOT EXISTS idx_memory_entries_scope_type ON memory_entries(scope, entry_type)");
67701
+ db2.run("CREATE INDEX IF NOT EXISTS idx_memory_entries_updated ON memory_entries(updated_at)");
65905
67702
  }
65906
67703
  async getDatabase() {
65907
67704
  if (!this.db) {
@@ -65910,20 +67707,8 @@ class SQLiteMemoryStore {
65910
67707
  return this.db;
65911
67708
  }
65912
67709
  resolvePath(path) {
65913
- if (path.startsWith("~")) {
65914
- const home = process.env.HOME || process.env.USERPROFILE || ".";
65915
- if (home === ".") {
65916
- throw new Error("Cannot resolve home directory");
65917
- }
65918
- const expanded = `${home}${path.slice(1)}`;
65919
- const resolved = resolve4(expanded);
65920
- const sep = process.platform === "win32" ? "\\" : "/";
65921
- if (resolved !== home && !resolved.startsWith(home + sep)) {
65922
- throw new Error(`Path escapes home directory: ${path}`);
65923
- }
65924
- return resolved;
65925
- }
65926
- return resolve4(path);
67710
+ const resolved = resolveHomePath(path);
67711
+ return resolve5(resolved);
65927
67712
  }
65928
67713
  generateUUID() {
65929
67714
  return randomUUID();
@@ -65931,66 +67716,93 @@ class SQLiteMemoryStore {
65931
67716
  now() {
65932
67717
  return Date.now();
65933
67718
  }
65934
- sleep(ms) {
65935
- return new Promise((resolve5) => setTimeout(resolve5, ms));
65936
- }
65937
- isRetryableError(error48) {
65938
- if (error48 instanceof Error) {
65939
- const message = error48.message.toLowerCase();
65940
- return message.includes("database is locked") || message.includes("database is busy") || message.includes("sqlite_busy") || message.includes("sqlite_locked");
67719
+ async transaction(callback) {
67720
+ let owner = transactionOwnerStorage.getStore();
67721
+ if (!owner) {
67722
+ owner = Symbol("transaction");
65941
67723
  }
65942
- return false;
65943
- }
65944
- async transaction(callback, options = {}) {
65945
- const db2 = await this.getDatabase();
65946
- const retries = options.retries ?? this.maxRetries;
65947
- for (let attempt = 0;attempt < retries; attempt++) {
67724
+ const release = await this.transactionMutex.acquire(owner);
67725
+ return transactionOwnerStorage.run(owner, async () => {
65948
67726
  try {
65949
- db2.exec("BEGIN IMMEDIATE");
65950
- const result = await callback();
65951
- db2.exec("COMMIT");
65952
- return result;
65953
- } catch (error48) {
67727
+ const db2 = await this.getDatabase();
67728
+ const shouldBegin = !this.inTransaction;
65954
67729
  try {
65955
- db2.exec("ROLLBACK");
65956
- } catch (rollbackError) {
65957
- console.error("[SQLiteMemoryStore] Rollback failed:", rollbackError);
65958
- }
65959
- const isRetryable = this.isRetryableError(error48);
65960
- if (isRetryable && attempt < retries - 1) {
65961
- const delay2 = this.retryDelay * 2 ** attempt;
65962
- console.warn(`[SQLiteMemoryStore] Retryable error, retrying in ${delay2}ms...`);
65963
- await this.sleep(delay2);
65964
- continue;
67730
+ if (shouldBegin) {
67731
+ db2.run("BEGIN TRANSACTION");
67732
+ this.inTransaction = true;
67733
+ }
67734
+ const result = await callback();
67735
+ if (shouldBegin) {
67736
+ db2.run("COMMIT");
67737
+ this.inTransaction = false;
67738
+ try {
67739
+ await this.saveDatabase();
67740
+ } catch (saveError) {
67741
+ console.error("[SQLiteMemoryStore] Failed to save database after commit, closing:", saveError);
67742
+ await this.close(true);
67743
+ throw saveError;
67744
+ }
67745
+ }
67746
+ return result;
67747
+ } catch (error48) {
67748
+ if (this.inTransaction) {
67749
+ try {
67750
+ db2.run("ROLLBACK");
67751
+ } catch (rollbackError) {
67752
+ console.error("[SQLiteMemoryStore] ROLLBACK failed:", rollbackError);
67753
+ }
67754
+ this.inTransaction = false;
67755
+ }
67756
+ throw error48;
65965
67757
  }
65966
- throw error48;
67758
+ } finally {
67759
+ release();
65967
67760
  }
65968
- }
65969
- throw new Error("Maximum retries exceeded");
67761
+ });
65970
67762
  }
65971
67763
  async readMemory(topic) {
65972
67764
  const db2 = await this.getDatabase();
65973
67765
  const scope = this.currentScope;
65974
- return this.transaction(async () => {
65975
- const stmt = db2.prepare("SELECT content FROM memory_entries WHERE name = ? AND scope = ?");
65976
- const row = stmt.get(topic, scope);
65977
- if (row) {
65978
- const updateStmt = db2.prepare("UPDATE memory_entries SET last_accessed = ? WHERE name = ? AND scope = ?");
65979
- updateStmt.run(this.now(), topic, scope);
65980
- }
65981
- return row?.content;
65982
- });
67766
+ const stmt = db2.prepare("SELECT content FROM memory_entries WHERE name = ? AND scope = ?");
67767
+ stmt.bind([topic, scope]);
67768
+ if (stmt.step()) {
67769
+ const row = stmt.getAsObject();
67770
+ const content = row.content;
67771
+ stmt.free();
67772
+ return content;
67773
+ }
67774
+ stmt.free();
67775
+ return;
65983
67776
  }
65984
67777
  async updateMemoryInternal(db2, operation, topic, content, metadata) {
65985
67778
  const scope = this.currentScope;
65986
67779
  const now = this.now();
67780
+ const createdAt = metadata?.created_at ?? now;
67781
+ const updatedAt = metadata?.updated_at ?? now;
67782
+ const lastAccessed = metadata?.last_accessed ?? now;
65987
67783
  if (operation === "remove") {
65988
- const stmt = db2.prepare("DELETE FROM memory_entries WHERE name = ? AND scope = ?");
65989
- stmt.run(topic, scope);
67784
+ const stmt2 = db2.prepare("DELETE FROM memory_entries WHERE name = ? AND scope = ?");
67785
+ stmt2.run([topic, scope]);
67786
+ stmt2.free();
65990
67787
  return;
65991
67788
  }
65992
- const existingStmt = db2.prepare("SELECT content, entry_type, status, priority, tags FROM memory_entries WHERE name = ? AND scope = ?");
65993
- const existing = existingStmt.get(topic, scope);
67789
+ const stmt = db2.prepare("SELECT content, entry_type, status, priority, tags FROM memory_entries WHERE name = ? AND scope = ?");
67790
+ stmt.bind([topic, scope]);
67791
+ let existing;
67792
+ if (stmt.step()) {
67793
+ const row = stmt.getAsObject();
67794
+ existing = {
67795
+ content: row.content,
67796
+ entry_type: row.entry_type,
67797
+ status: row.status,
67798
+ priority: row.priority,
67799
+ tags: row.tags
67800
+ };
67801
+ stmt.free();
67802
+ } else {
67803
+ existing = undefined;
67804
+ stmt.free();
67805
+ }
65994
67806
  let finalContent;
65995
67807
  let entry_type;
65996
67808
  let status;
@@ -66010,9 +67822,9 @@ ${content}`;
66010
67822
  finalContent = content;
66011
67823
  }
66012
67824
  entry_type = metadata?.entry_type || existing.entry_type;
66013
- status = metadata?.status || existing.status;
66014
- priority = metadata?.priority || existing.priority;
66015
- tags = metadata?.tags || existing.tags;
67825
+ status = (metadata?.status || existing.status) ?? undefined;
67826
+ priority = (metadata?.priority || existing.priority) ?? undefined;
67827
+ tags = (metadata?.tags || existing.tags) ?? undefined;
66016
67828
  } else {
66017
67829
  if (!content) {
66018
67830
  throw new Error("Content is required for new memory entries.");
@@ -66035,7 +67847,20 @@ ${content}`;
66035
67847
  updated_at = excluded.updated_at,
66036
67848
  last_accessed = excluded.last_accessed
66037
67849
  `);
66038
- upsertStmt.run(this.generateUUID(), topic, scope, finalContent, entry_type, status || null, priority || null, tags || null, now, now, now);
67850
+ upsertStmt.run([
67851
+ this.generateUUID(),
67852
+ topic,
67853
+ scope,
67854
+ finalContent,
67855
+ entry_type,
67856
+ status ?? null,
67857
+ priority ?? null,
67858
+ tags ?? null,
67859
+ createdAt,
67860
+ updatedAt,
67861
+ lastAccessed
67862
+ ]);
67863
+ upsertStmt.free();
66039
67864
  }
66040
67865
  async updateMemory(operation, topic, content, metadata) {
66041
67866
  return this.transaction(async () => {
@@ -66044,49 +67869,76 @@ ${content}`;
66044
67869
  });
66045
67870
  }
66046
67871
  async queryMemory(query = {}, options = {}) {
67872
+ if (options.operation === "delete") {
67873
+ return this.transaction(async () => {
67874
+ const db3 = await this.getDatabase();
67875
+ const { sql: sql2, params: params2 } = this.buildQuery(query);
67876
+ const deleteSql = `DELETE FROM memory_entries WHERE id IN (SELECT id FROM (${sql2}))`;
67877
+ const stmt2 = db3.prepare(deleteSql);
67878
+ stmt2.bind(params2);
67879
+ stmt2.step();
67880
+ stmt2.free();
67881
+ return db3.getRowsModified();
67882
+ });
67883
+ }
66047
67884
  const db2 = await this.getDatabase();
66048
- const { sql, params } = this.buildQuery(query, options);
67885
+ const { sql, params } = this.buildQuery(query);
66049
67886
  if (options.operation === "count") {
66050
- const countStmt = db2.prepare(`SELECT COUNT(*) as count FROM (${sql})`);
66051
- const result = countStmt.get(...params);
66052
- return result.count;
66053
- }
66054
- if (options.operation === "delete") {
66055
- const deleteStmt = db2.prepare(`DELETE FROM memory_entries WHERE id IN (SELECT id FROM (${sql}))`);
66056
- const info = deleteStmt.run(...params);
66057
- return info.changes;
67887
+ const countSql = `SELECT COUNT(*) as count FROM (${sql})`;
67888
+ const stmt2 = db2.prepare(countSql);
67889
+ stmt2.bind(params);
67890
+ let count = 0;
67891
+ if (stmt2.step()) {
67892
+ const row = stmt2.getAsObject();
67893
+ count = row.count;
67894
+ }
67895
+ stmt2.free();
67896
+ return count;
66058
67897
  }
66059
67898
  const stmt = db2.prepare(sql);
66060
- return stmt.all(...params);
67899
+ stmt.bind(params);
67900
+ const entries = [];
67901
+ while (stmt.step()) {
67902
+ entries.push(stmt.getAsObject());
67903
+ }
67904
+ stmt.free();
67905
+ return entries;
66061
67906
  }
66062
- buildQuery(query, _options) {
67907
+ buildQuery(query) {
66063
67908
  const conditions = [];
66064
67909
  const params = [];
66065
67910
  let sql = "SELECT * FROM memory_entries WHERE 1=1";
66066
67911
  const scope = query.scope === "auto" ? this.currentScope : query.scope;
66067
67912
  if (scope === "global") {
66068
- conditions.push("scope = ?");
67913
+ conditions.push(`scope = ?`);
66069
67914
  params.push("global");
66070
67915
  } else if (scope === "project" || !scope && this.currentScope !== "global") {
66071
- conditions.push("scope = ?");
67916
+ conditions.push(`scope = ?`);
66072
67917
  params.push(this.currentScope);
66073
67918
  }
67919
+ if (query.name) {
67920
+ if (!query.name.trim()) {
67921
+ throw new Error("Name cannot be empty");
67922
+ }
67923
+ conditions.push(`name = ?`);
67924
+ params.push(query.name.trim());
67925
+ }
66074
67926
  if (query.type) {
66075
67927
  if (!query.type.trim()) {
66076
67928
  throw new Error("Type cannot be empty");
66077
67929
  }
66078
- conditions.push("entry_type = ?");
67930
+ conditions.push(`entry_type = ?`);
66079
67931
  params.push(query.type.trim());
66080
67932
  }
66081
67933
  if (query.status) {
66082
- conditions.push("status = ?");
67934
+ conditions.push(`status = ?`);
66083
67935
  params.push(query.status);
66084
67936
  }
66085
67937
  if (query.priority) {
66086
67938
  if (!SQLiteMemoryStore.ALLOWED_PRIORITIES.includes(query.priority)) {
66087
67939
  throw new Error(`Invalid priority: ${query.priority}`);
66088
67940
  }
66089
- conditions.push("priority = ?");
67941
+ conditions.push(`priority = ?`);
66090
67942
  params.push(query.priority);
66091
67943
  }
66092
67944
  if (query.tags) {
@@ -66096,30 +67948,31 @@ ${content}`;
66096
67948
  if (!trimmed) {
66097
67949
  throw new Error("Tags cannot be empty");
66098
67950
  }
66099
- conditions.push("(tags = ? OR tags LIKE ? OR tags LIKE ? OR tags LIKE ?)");
66100
- params.push(trimmed, `${trimmed},%`, `%,${trimmed}`, `%,${trimmed},%`);
67951
+ const escaped = trimmed.replace(/[\\_%]/g, "\\$&");
67952
+ conditions.push(`(tags = ? OR tags LIKE ? ESCAPE '\\' OR tags LIKE ? ESCAPE '\\' OR tags LIKE ? ESCAPE '\\')`);
67953
+ params.push(trimmed, `${escaped},%`, `%,${escaped}`, `%,${escaped},%`);
66101
67954
  }
66102
67955
  }
66103
67956
  if (query.search) {
66104
67957
  const searchTerm = query.search.trim();
66105
- const sanitized = searchTerm.replace(/[\\_%]/g, "\\$&");
66106
- conditions.push("(content LIKE ? OR name LIKE ?)");
66107
- params.push(`%${sanitized}%`, `%${sanitized}%`);
67958
+ conditions.push(`(content LIKE ? ESCAPE '\\' OR name LIKE ? ESCAPE '\\')`);
67959
+ const searchPattern = `%${searchTerm.replace(/[\\_%]/g, "\\$&")}%`;
67960
+ params.push(searchPattern, searchPattern);
66108
67961
  }
66109
67962
  if (query.createdAfter) {
66110
- conditions.push("created_at >= ?");
67963
+ conditions.push(`created_at >= ?`);
66111
67964
  params.push(query.createdAfter);
66112
67965
  }
66113
67966
  if (query.createdBefore) {
66114
- conditions.push("created_at <= ?");
67967
+ conditions.push(`created_at <= ?`);
66115
67968
  params.push(query.createdBefore);
66116
67969
  }
66117
67970
  if (query.updatedAfter) {
66118
- conditions.push("updated_at >= ?");
67971
+ conditions.push(`updated_at >= ?`);
66119
67972
  params.push(query.updatedAfter);
66120
67973
  }
66121
67974
  if (query.updatedBefore) {
66122
- conditions.push("updated_at <= ?");
67975
+ conditions.push(`updated_at <= ?`);
66123
67976
  params.push(query.updatedBefore);
66124
67977
  }
66125
67978
  if (conditions.length > 0) {
@@ -66141,16 +67994,16 @@ ${content}`;
66141
67994
  if (Number.isNaN(limit) || limit < 1 || limit > 1e4) {
66142
67995
  throw new Error("Limit must be between 1 and 10000");
66143
67996
  }
66144
- sql += " LIMIT ?";
67997
+ sql += ` LIMIT ?`;
66145
67998
  params.push(limit);
66146
- if (query.offset) {
66147
- const offset = Number(query.offset);
66148
- if (Number.isNaN(offset) || offset < 0) {
66149
- throw new Error("Offset must be >= 0");
66150
- }
66151
- sql += " OFFSET ?";
66152
- params.push(offset);
67999
+ }
68000
+ if (query.offset) {
68001
+ const offset = Number(query.offset);
68002
+ if (Number.isNaN(offset) || offset < 0) {
68003
+ throw new Error("Offset must be >= 0");
66153
68004
  }
68005
+ sql += ` OFFSET ?`;
68006
+ params.push(offset);
66154
68007
  }
66155
68008
  return { sql, params };
66156
68009
  }
@@ -66162,20 +68015,34 @@ ${content}`;
66162
68015
  }
66163
68016
  });
66164
68017
  }
66165
- close() {
66166
- if (this.db) {
66167
- this.db.close();
66168
- this.db = null;
68018
+ async close(skipSave = false) {
68019
+ const db2 = this.db;
68020
+ if (db2) {
68021
+ try {
68022
+ if (!skipSave) {
68023
+ await this.saveDatabase();
68024
+ }
68025
+ } finally {
68026
+ if (this.db === db2) {
68027
+ db2.close();
68028
+ this.db = null;
68029
+ }
68030
+ }
66169
68031
  }
68032
+ this.dbPromise = null;
66170
68033
  }
66171
68034
  async getStats() {
66172
68035
  const db2 = await this.getDatabase();
66173
- const countStmt = db2.prepare("SELECT COUNT(*) as count FROM memory_entries");
66174
- const { count: totalEntries } = countStmt.get();
66175
- const typeStmt = db2.prepare("SELECT entry_type, COUNT(*) as count FROM memory_entries GROUP BY entry_type");
66176
- const typeRows = typeStmt.all();
66177
- const entriesByType = Object.fromEntries(typeRows.map((r2) => [r2.entry_type, r2.count]));
66178
- const dbPath = this.resolvePath(this.config.path || "~/.config/polka-codes/memory.sqlite");
68036
+ const results = db2.exec("SELECT COUNT(*) as count FROM memory_entries");
68037
+ const totalEntries = results[0]?.values[0]?.[0] || 0;
68038
+ const typeResults = db2.exec("SELECT entry_type, COUNT(*) as count FROM memory_entries GROUP BY entry_type");
68039
+ const entriesByType = {};
68040
+ if (typeResults.length > 0) {
68041
+ for (const row of typeResults[0].values) {
68042
+ entriesByType[row[0]] = row[1];
68043
+ }
68044
+ }
68045
+ const dbPath = this.resolvePath(this.getDbPath());
66179
68046
  let databaseSize = 0;
66180
68047
  try {
66181
68048
  const stats = await import("node:fs/promises").then((fs4) => fs4.stat(dbPath));
@@ -66681,40 +68548,36 @@ var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
66681
68548
  var source_default = chalk;
66682
68549
 
66683
68550
  // src/utils/parameterSimplifier.ts
66684
- function replaceInFileSimplifier(params) {
66685
- return { path: params.path };
66686
- }
66687
- function writeToFileSimplifier(params) {
66688
- return { path: params.path };
66689
- }
66690
- function readFileSimplifier(params) {
66691
- return { path: params.path, includeIgnored: params.includeIgnored };
66692
- }
66693
- function listFilesSimplifier(params) {
66694
- const maxCount = params.maxCount;
66695
- return {
66696
- path: params.path,
66697
- recursive: params.recursive,
66698
- ...maxCount !== 2000 && { maxCount }
68551
+ function createSimplifier(keepFields) {
68552
+ return (params) => {
68553
+ const result = {};
68554
+ for (const field of keepFields) {
68555
+ if (params[field] !== undefined) {
68556
+ result[field] = params[field];
68557
+ }
68558
+ }
68559
+ return result;
66699
68560
  };
66700
68561
  }
66701
- function searchFilesSimplifier(params) {
66702
- return { ...params };
66703
- }
66704
- function executeCommandSimplifier(params) {
66705
- return { command: params.command, requiresApproval: params.requiresApproval };
66706
- }
66707
- function updateMemorySimplifier(params) {
66708
- return { operation: params.operation, topic: params.topic };
68562
+ function createCustomSimplifier(transform2) {
68563
+ return transform2;
66709
68564
  }
66710
68565
  var SIMPLIFIERS = {
66711
- replaceInFile: replaceInFileSimplifier,
66712
- writeToFile: writeToFileSimplifier,
66713
- readFile: readFileSimplifier,
66714
- listFiles: listFilesSimplifier,
66715
- searchFiles: searchFilesSimplifier,
66716
- executeCommand: executeCommandSimplifier,
66717
- updateMemory: updateMemorySimplifier
68566
+ replaceInFile: createSimplifier(["path"]),
68567
+ writeToFile: createSimplifier(["path"]),
68568
+ readFile: createSimplifier(["path", "includeIgnored"]),
68569
+ executeCommand: createSimplifier(["command", "requiresApproval"]),
68570
+ updateMemory: createSimplifier(["operation", "topic"]),
68571
+ searchFiles: createCustomSimplifier((params) => ({ ...params })),
68572
+ listFiles: createCustomSimplifier((params) => {
68573
+ const DEFAULT_MAX_COUNT = 2000;
68574
+ const maxCount = params.maxCount;
68575
+ return {
68576
+ path: params.path,
68577
+ recursive: params.recursive,
68578
+ ...maxCount !== DEFAULT_MAX_COUNT && { maxCount }
68579
+ };
68580
+ })
66718
68581
  };
66719
68582
  function simplifyToolParameters(toolName, params) {
66720
68583
  if (params === undefined || params === null) {
@@ -66948,7 +68811,7 @@ Tool error:`, event.tool));
66948
68811
  // src/utils/readMultiline.ts
66949
68812
  import readline3 from "node:readline";
66950
68813
  function readMultiline(prompt = "Enter text (Ctrl+D to finish):") {
66951
- return new Promise((resolve5) => {
68814
+ return new Promise((resolve6) => {
66952
68815
  console.log(prompt);
66953
68816
  const rl = readline3.createInterface({
66954
68817
  input: process.stdin,
@@ -66960,7 +68823,7 @@ function readMultiline(prompt = "Enter text (Ctrl+D to finish):") {
66960
68823
  lines.push(line);
66961
68824
  });
66962
68825
  rl.on("close", () => {
66963
- resolve5(lines.join(`
68826
+ resolve6(lines.join(`
66964
68827
  `));
66965
68828
  });
66966
68829
  });
@@ -66982,6 +68845,7 @@ export {
66982
68845
  listFiles,
66983
68846
  getProvider,
66984
68847
  getGlobalConfigPath,
68848
+ detectProjectScope,
66985
68849
  configSchema,
66986
68850
  checkRipgrep,
66987
68851
  SQLiteMemoryStore,