@hasna/instructions 0.4.35 → 0.4.36

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.
@@ -16,7 +16,7 @@ var __export = (target, all) => {
16
16
  };
17
17
  var __require = import.meta.require;
18
18
 
19
- // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/compose.js
19
+ // node_modules/hono/dist/compose.js
20
20
  var compose = (middleware, onError, onNotFound) => {
21
21
  return (context, next) => {
22
22
  let index = -1;
@@ -60,42 +60,21 @@ var compose = (middleware, onError, onNotFound) => {
60
60
  };
61
61
  };
62
62
 
63
- // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/request/constants.js
63
+ // node_modules/hono/dist/request/constants.js
64
64
  var GET_MATCH_RESULT = /* @__PURE__ */ Symbol();
65
65
 
66
- // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/utils/buffer.js
67
- var bufferToFormData = (arrayBuffer, contentType) => {
68
- const response = new Response(arrayBuffer, {
69
- headers: {
70
- "Content-Type": contentType.replace(/^[^;]+/, (mediaType) => mediaType.toLowerCase())
71
- }
72
- });
73
- return response.formData();
74
- };
75
-
76
- // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/utils/body.js
77
- var isRawRequest = (request) => ("headers" in request);
66
+ // node_modules/hono/dist/utils/body.js
78
67
  var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
79
68
  const { all = false, dot = false } = options;
80
- const headers = isRawRequest(request) ? request.headers : request.raw.headers;
69
+ const headers = request instanceof HonoRequest ? request.raw.headers : request.headers;
81
70
  const contentType = headers.get("Content-Type");
82
- const mediaType = contentType?.split(";")[0].trim().toLowerCase();
83
- if (mediaType === "multipart/form-data" || mediaType === "application/x-www-form-urlencoded") {
71
+ if (contentType?.startsWith("multipart/form-data") || contentType?.startsWith("application/x-www-form-urlencoded")) {
84
72
  return parseFormData(request, { all, dot });
85
73
  }
86
74
  return {};
87
75
  };
88
76
  async function parseFormData(request, options) {
89
- if (!isRawRequest(request) && request.bodyCache.formData) {
90
- return convertFormDataToBodyData(await request.bodyCache.formData, options);
91
- }
92
- const headers = isRawRequest(request) ? request.headers : request.raw.headers;
93
- const arrayBuffer = await request.arrayBuffer();
94
- const formDataPromise = bufferToFormData(arrayBuffer, headers.get("Content-Type") || "");
95
- if (!isRawRequest(request)) {
96
- request.bodyCache.formData = formDataPromise;
97
- }
98
- const formData = await formDataPromise;
77
+ const formData = await request.formData();
99
78
  if (formData) {
100
79
  return convertFormDataToBodyData(formData, options);
101
80
  }
@@ -155,7 +134,7 @@ var handleParsingNestedValues = (form, key, value) => {
155
134
  });
156
135
  };
157
136
 
158
- // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/utils/url.js
137
+ // node_modules/hono/dist/utils/url.js
159
138
  var splitPath = (path) => {
160
139
  const paths = path.split("/");
161
140
  if (paths[0] === "") {
@@ -277,16 +256,18 @@ var checkOptionalParameter = (path) => {
277
256
  });
278
257
  return results.filter((v, i, a) => a.indexOf(v) === i);
279
258
  };
280
- var tryDecodeURIComponent = (str) => str.indexOf("%") !== -1 ? tryDecode(str, decodeURIComponent_) : str;
281
259
  var _decodeURI = (value) => {
260
+ if (!/[%+]/.test(value)) {
261
+ return value;
262
+ }
282
263
  if (value.indexOf("+") !== -1) {
283
264
  value = value.replace(/\+/g, " ");
284
265
  }
285
- return tryDecodeURIComponent(value);
266
+ return value.indexOf("%") !== -1 ? tryDecode(value, decodeURIComponent_) : value;
286
267
  };
287
268
  var _getQueryParam = (url, key, multiple) => {
288
269
  let encoded;
289
- if (!multiple && key && key.indexOf("%") === -1 && key.indexOf("+") === -1) {
270
+ if (!multiple && key && !/[%+]/.test(key)) {
290
271
  let keyIndex2 = url.indexOf("?", 8);
291
272
  if (keyIndex2 === -1) {
292
273
  return;
@@ -310,7 +291,7 @@ var _getQueryParam = (url, key, multiple) => {
310
291
  return;
311
292
  }
312
293
  }
313
- const results = /* @__PURE__ */ Object.create(null);
294
+ const results = {};
314
295
  encoded ??= /[%+]/.test(url);
315
296
  let keyIndex = url.indexOf("?", 8);
316
297
  while (keyIndex !== -1) {
@@ -353,7 +334,8 @@ var getQueryParams = (url, key) => {
353
334
  };
354
335
  var decodeURIComponent_ = decodeURIComponent;
355
336
 
356
- // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/request.js
337
+ // node_modules/hono/dist/request.js
338
+ var tryDecodeURIComponent = (str) => tryDecode(str, decodeURIComponent_);
357
339
  var HonoRequest = class {
358
340
  raw;
359
341
  #validatedData;
@@ -365,6 +347,7 @@ var HonoRequest = class {
365
347
  this.raw = request;
366
348
  this.path = path;
367
349
  this.#matchResult = matchResult;
350
+ this.#validatedData = {};
368
351
  }
369
352
  param(key) {
370
353
  return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams();
@@ -372,7 +355,7 @@ var HonoRequest = class {
372
355
  #getDecodedParam(key) {
373
356
  const paramKey = this.#matchResult[0][this.routeIndex][1][key];
374
357
  const param = this.#getParamValue(paramKey);
375
- return param && tryDecodeURIComponent(param);
358
+ return param && /\%/.test(param) ? tryDecodeURIComponent(param) : param;
376
359
  }
377
360
  #getAllDecodedParams() {
378
361
  const decoded = {};
@@ -380,7 +363,7 @@ var HonoRequest = class {
380
363
  for (const key of keys) {
381
364
  const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
382
365
  if (value !== undefined) {
383
- decoded[key] = tryDecodeURIComponent(value);
366
+ decoded[key] = /\%/.test(value) ? tryDecodeURIComponent(value) : value;
384
367
  }
385
368
  }
386
369
  return decoded;
@@ -398,7 +381,7 @@ var HonoRequest = class {
398
381
  if (name) {
399
382
  return this.raw.headers.get(name) ?? undefined;
400
383
  }
401
- const headerData = /* @__PURE__ */ Object.create(null);
384
+ const headerData = {};
402
385
  this.raw.headers.forEach((value, key) => {
403
386
  headerData[key] = value;
404
387
  });
@@ -413,7 +396,8 @@ var HonoRequest = class {
413
396
  if (cachedBody) {
414
397
  return cachedBody;
415
398
  }
416
- for (const anyCachedKey in bodyCache) {
399
+ const anyCachedKey = Object.keys(bodyCache)[0];
400
+ if (anyCachedKey) {
417
401
  return bodyCache[anyCachedKey].then((body) => {
418
402
  if (anyCachedKey === "json") {
419
403
  body = JSON.stringify(body);
@@ -432,9 +416,6 @@ var HonoRequest = class {
432
416
  arrayBuffer() {
433
417
  return this.#cachedBody("arrayBuffer");
434
418
  }
435
- bytes() {
436
- return this.#cachedBody("arrayBuffer").then((buffer) => new Uint8Array(buffer));
437
- }
438
419
  blob() {
439
420
  return this.#cachedBody("blob");
440
421
  }
@@ -442,10 +423,10 @@ var HonoRequest = class {
442
423
  return this.#cachedBody("formData");
443
424
  }
444
425
  addValidatedData(target, data) {
445
- (this.#validatedData ??= {})[target] = data;
426
+ this.#validatedData[target] = data;
446
427
  }
447
428
  valid(target) {
448
- return this.#validatedData?.[target];
429
+ return this.#validatedData[target];
449
430
  }
450
431
  get url() {
451
432
  return this.raw.url;
@@ -464,7 +445,7 @@ var HonoRequest = class {
464
445
  }
465
446
  };
466
447
 
467
- // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/utils/html.js
448
+ // node_modules/hono/dist/utils/html.js
468
449
  var HtmlEscapedCallbackPhase = {
469
450
  Stringify: 1,
470
451
  BeforeStream: 2,
@@ -502,7 +483,7 @@ var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) =>
502
483
  }
503
484
  };
504
485
 
505
- // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/context.js
486
+ // node_modules/hono/dist/context.js
506
487
  var TEXT_PLAIN = "text/plain; charset=UTF-8";
507
488
  var setDefaultContentType = (contentType, headers) => {
508
489
  return {
@@ -620,11 +601,11 @@ var Context = class {
620
601
  return Object.fromEntries(this.#var);
621
602
  }
622
603
  #newResponse(data, arg, headers) {
623
- let responseHeaders = this.#res ? new Headers(this.#res.headers) : this.#preparedHeaders;
624
- if (typeof arg === "object" && arg.headers) {
625
- responseHeaders ??= new Headers;
626
- for (const [key, value] of new Headers(arg.headers)) {
627
- if (key === "set-cookie") {
604
+ const responseHeaders = this.#res ? new Headers(this.#res.headers) : this.#preparedHeaders ?? new Headers;
605
+ if (typeof arg === "object" && "headers" in arg) {
606
+ const argHeaders = arg.headers instanceof Headers ? arg.headers : new Headers(arg.headers);
607
+ for (const [key, value] of argHeaders) {
608
+ if (key.toLowerCase() === "set-cookie") {
628
609
  responseHeaders.append(key, value);
629
610
  } else {
630
611
  responseHeaders.set(key, value);
@@ -632,34 +613,19 @@ var Context = class {
632
613
  }
633
614
  }
634
615
  if (headers) {
635
- if (!responseHeaders) {
636
- let count = 0;
637
- for (const k in headers) {
638
- if (++count > 1 || typeof headers[k] !== "string") {
639
- responseHeaders = new Headers;
640
- break;
641
- }
642
- }
643
- }
644
- if (responseHeaders) {
645
- for (const k in headers) {
646
- const v = headers[k];
647
- if (typeof v === "string") {
648
- responseHeaders.set(k, v);
649
- } else {
650
- responseHeaders.delete(k);
651
- for (const v2 of v) {
652
- responseHeaders.append(k, v2);
653
- }
616
+ for (const [k, v] of Object.entries(headers)) {
617
+ if (typeof v === "string") {
618
+ responseHeaders.set(k, v);
619
+ } else {
620
+ responseHeaders.delete(k);
621
+ for (const v2 of v) {
622
+ responseHeaders.append(k, v2);
654
623
  }
655
624
  }
656
625
  }
657
626
  }
658
627
  const status = typeof arg === "number" ? arg : arg?.status ?? this.#status;
659
- return createResponseInstance(data, {
660
- status,
661
- headers: responseHeaders ?? headers
662
- });
628
+ return createResponseInstance(data, { status, headers: responseHeaders });
663
629
  }
664
630
  newResponse = (...args) => this.#newResponse(...args);
665
631
  body = (data, arg, headers) => this.#newResponse(data, arg, headers);
@@ -684,18 +650,18 @@ var Context = class {
684
650
  };
685
651
  };
686
652
 
687
- // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/router.js
653
+ // node_modules/hono/dist/router.js
688
654
  var METHOD_NAME_ALL = "ALL";
689
655
  var METHOD_NAME_ALL_LOWERCASE = "all";
690
- var METHODS = ["get", "post", "put", "delete", "options", "patch", "query"];
656
+ var METHODS = ["get", "post", "put", "delete", "options", "patch"];
691
657
  var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built.";
692
658
  var UnsupportedPathError = class extends Error {
693
659
  };
694
660
 
695
- // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/utils/constants.js
661
+ // node_modules/hono/dist/utils/constants.js
696
662
  var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
697
663
 
698
- // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/hono-base.js
664
+ // node_modules/hono/dist/hono-base.js
699
665
  var notFoundHandler = (c) => {
700
666
  return c.text("404 Not Found", 404);
701
667
  };
@@ -714,7 +680,6 @@ var Hono = class _Hono {
714
680
  delete;
715
681
  options;
716
682
  patch;
717
- query;
718
683
  all;
719
684
  on;
720
685
  use;
@@ -787,7 +752,7 @@ var Hono = class _Hono {
787
752
  handler = async (c, next) => (await compose([], app.errorHandler)(c, () => r.handler(c, next))).res;
788
753
  handler[COMPOSED_HANDLER] = r.handler;
789
754
  }
790
- subApp.#addRoute(r.method, r.path, handler, r.basePath);
755
+ subApp.#addRoute(r.method, r.path, handler);
791
756
  });
792
757
  return this;
793
758
  }
@@ -834,7 +799,7 @@ var Hono = class _Hono {
834
799
  const pathPrefixLength = mergedPath === "/" ? 0 : mergedPath.length;
835
800
  return (request) => {
836
801
  const url = new URL(request.url);
837
- url.pathname = this.getPath(request).slice(pathPrefixLength) || "/";
802
+ url.pathname = url.pathname.slice(pathPrefixLength) || "/";
838
803
  return new Request(url, request);
839
804
  };
840
805
  })();
@@ -848,15 +813,10 @@ var Hono = class _Hono {
848
813
  this.#addRoute(METHOD_NAME_ALL, mergePath(path, "*"), handler);
849
814
  return this;
850
815
  }
851
- #addRoute(method, path, handler, baseRoutePath) {
816
+ #addRoute(method, path, handler) {
852
817
  method = method.toUpperCase();
853
818
  path = mergePath(this._basePath, path);
854
- const r = {
855
- basePath: baseRoutePath !== undefined ? mergePath(this._basePath, baseRoutePath) : this._basePath,
856
- path,
857
- method,
858
- handler
859
- };
819
+ const r = { basePath: this._basePath, path, method, handler };
860
820
  this.router.add(method, path, [handler, r]);
861
821
  this.routes.push(r);
862
822
  }
@@ -920,7 +880,7 @@ var Hono = class _Hono {
920
880
  };
921
881
  };
922
882
 
923
- // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/router/reg-exp-router/matcher.js
883
+ // node_modules/hono/dist/router/reg-exp-router/matcher.js
924
884
  var emptyParam = [];
925
885
  function match(method, path) {
926
886
  const matchers = this.buildAllMatchers();
@@ -941,7 +901,7 @@ function match(method, path) {
941
901
  return match2(method, path);
942
902
  }
943
903
 
944
- // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/router/reg-exp-router/node.js
904
+ // node_modules/hono/dist/router/reg-exp-router/node.js
945
905
  var LABEL_REG_EXP_STR = "[^/]+";
946
906
  var ONLY_WILDCARD_REG_EXP_STR = ".*";
947
907
  var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
@@ -955,7 +915,7 @@ function compareKey(a, b) {
955
915
  return 1;
956
916
  }
957
917
  if (a === ONLY_WILDCARD_REG_EXP_STR || a === TAIL_WILDCARD_REG_EXP_STR) {
958
- return b === TAIL_WILDCARD_REG_EXP_STR ? -1 : 1;
918
+ return 1;
959
919
  } else if (b === ONLY_WILDCARD_REG_EXP_STR || b === TAIL_WILDCARD_REG_EXP_STR) {
960
920
  return -1;
961
921
  }
@@ -970,68 +930,69 @@ var Node = class _Node {
970
930
  #index;
971
931
  #varIndex;
972
932
  #children = /* @__PURE__ */ Object.create(null);
973
- insert(tokens, index, paramMap, context, isStatic) {
974
- let node = this;
975
- for (let i = 0, len = tokens.length;i < len; i++) {
976
- const token = tokens[i];
977
- const pattern = token.length === 1 ? token === "*" ? i === len - 1 ? ["", "", ONLY_WILDCARD_REG_EXP_STR] : ["", "", LABEL_REG_EXP_STR] : null : token === "/*" ? ["", "", TAIL_WILDCARD_REG_EXP_STR] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
978
- let nextNode;
979
- if (pattern) {
980
- const name = pattern[1];
981
- let regexpStr = pattern[2] || LABEL_REG_EXP_STR;
982
- if (name && pattern[2]) {
983
- if (regexpStr === ".*") {
984
- throw PATH_ERROR;
985
- }
986
- regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
987
- if (/\((?!\?:)/.test(regexpStr)) {
988
- throw PATH_ERROR;
989
- }
990
- if (regexpStr.length === 1 && regExpMetaChars.has(regexpStr)) {
991
- throw PATH_ERROR;
992
- }
933
+ insert(tokens, index, paramMap, context, pathErrorCheckOnly) {
934
+ if (tokens.length === 0) {
935
+ if (this.#index !== undefined) {
936
+ throw PATH_ERROR;
937
+ }
938
+ if (pathErrorCheckOnly) {
939
+ return;
940
+ }
941
+ this.#index = index;
942
+ return;
943
+ }
944
+ const [token, ...restTokens] = tokens;
945
+ const pattern = token === "*" ? restTokens.length === 0 ? ["", "", ONLY_WILDCARD_REG_EXP_STR] : ["", "", LABEL_REG_EXP_STR] : token === "/*" ? ["", "", TAIL_WILDCARD_REG_EXP_STR] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
946
+ let node;
947
+ if (pattern) {
948
+ const name = pattern[1];
949
+ let regexpStr = pattern[2] || LABEL_REG_EXP_STR;
950
+ if (name && pattern[2]) {
951
+ if (regexpStr === ".*") {
952
+ throw PATH_ERROR;
993
953
  }
994
- nextNode = node.#children[regexpStr];
995
- if (!nextNode) {
996
- if (regexpStr !== ONLY_WILDCARD_REG_EXP_STR && regexpStr !== TAIL_WILDCARD_REG_EXP_STR) {
997
- for (const k in node.#children) {
998
- if ((regexpStr.length > 1 || k.length > 1) && k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR) {
999
- throw PATH_ERROR;
1000
- }
1001
- }
1002
- }
1003
- nextNode = node.#children[regexpStr] = new _Node;
954
+ regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
955
+ if (/\((?!\?:)/.test(regexpStr)) {
956
+ throw PATH_ERROR;
1004
957
  }
958
+ }
959
+ node = this.#children[regexpStr];
960
+ if (!node) {
961
+ if (Object.keys(this.#children).some((k) => k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR)) {
962
+ throw PATH_ERROR;
963
+ }
964
+ if (pathErrorCheckOnly) {
965
+ return;
966
+ }
967
+ node = this.#children[regexpStr] = new _Node;
1005
968
  if (name !== "") {
1006
- nextNode.#varIndex ??= context.varIndex++;
1007
- paramMap.push([name, nextNode.#varIndex]);
969
+ node.#varIndex = context.varIndex++;
1008
970
  }
1009
- } else {
1010
- nextNode = node.#children[token];
1011
- if (!nextNode) {
1012
- for (const k in node.#children) {
1013
- if (k.length > 1 && k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR) {
1014
- throw PATH_ERROR;
1015
- }
1016
- }
1017
- nextNode = node.#children[token] = new _Node;
971
+ }
972
+ if (!pathErrorCheckOnly && name !== "") {
973
+ paramMap.push([name, node.#varIndex]);
974
+ }
975
+ } else {
976
+ node = this.#children[token];
977
+ if (!node) {
978
+ if (Object.keys(this.#children).some((k) => k.length > 1 && k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR)) {
979
+ throw PATH_ERROR;
980
+ }
981
+ if (pathErrorCheckOnly) {
982
+ return;
1018
983
  }
984
+ node = this.#children[token] = new _Node;
1019
985
  }
1020
- node = nextNode;
1021
986
  }
1022
- if (node.#index !== undefined) {
1023
- throw PATH_ERROR;
1024
- }
1025
- node.#index = isStatic ? -1 : index;
987
+ node.insert(restTokens, index, paramMap, context, pathErrorCheckOnly);
1026
988
  }
1027
989
  buildRegExpStr() {
1028
990
  const childKeys = Object.keys(this.#children).sort(compareKey);
1029
991
  const strList = childKeys.map((k) => {
1030
992
  const c = this.#children[k];
1031
- const childStr = c.buildRegExpStr();
1032
- return childStr === "" ? "" : (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + childStr;
1033
- }).filter(Boolean);
1034
- if (typeof this.#index === "number" && this.#index !== -1) {
993
+ return (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + c.buildRegExpStr();
994
+ });
995
+ if (typeof this.#index === "number") {
1035
996
  strList.unshift(`#${this.#index}`);
1036
997
  }
1037
998
  if (strList.length === 0) {
@@ -1044,23 +1005,16 @@ var Node = class _Node {
1044
1005
  }
1045
1006
  };
1046
1007
 
1047
- // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/router/reg-exp-router/trie.js
1008
+ // node_modules/hono/dist/router/reg-exp-router/trie.js
1048
1009
  var Trie = class {
1049
1010
  #context = { varIndex: 0 };
1050
1011
  #root = new Node;
1051
- #index = 0;
1052
- paths = /* @__PURE__ */ Object.create(null);
1053
- insert(path, isStatic) {
1054
- if (isStatic) {
1055
- this.#root.insert(path.split(""), 0, [], this.#context, true);
1056
- return;
1057
- }
1012
+ insert(path, index, pathErrorCheckOnly) {
1058
1013
  const paramAssoc = [];
1059
1014
  const groups = [];
1060
- let markedPath = path;
1061
1015
  for (let i = 0;; ) {
1062
1016
  let replaced = false;
1063
- markedPath = markedPath.replace(/\{[^}]+\}/g, (m) => {
1017
+ path = path.replace(/\{[^}]+\}/g, (m) => {
1064
1018
  const mark = `@\\${i}`;
1065
1019
  groups[i] = [mark, m];
1066
1020
  i++;
@@ -1071,7 +1025,7 @@ var Trie = class {
1071
1025
  break;
1072
1026
  }
1073
1027
  }
1074
- const tokens = markedPath.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
1028
+ const tokens = path.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
1075
1029
  for (let i = groups.length - 1;i >= 0; i--) {
1076
1030
  const [mark] = groups[i];
1077
1031
  for (let j = tokens.length - 1;j >= 0; j--) {
@@ -1081,8 +1035,8 @@ var Trie = class {
1081
1035
  }
1082
1036
  }
1083
1037
  }
1084
- this.#root.insert(tokens, this.#index, paramAssoc, this.#context, false);
1085
- this.paths[path] = [this.#index++, paramAssoc];
1038
+ this.#root.insert(tokens, index, paramAssoc, this.#context, pathErrorCheckOnly);
1039
+ return paramAssoc;
1086
1040
  }
1087
1041
  buildRegExp() {
1088
1042
  let regexp = this.#root.buildRegExpStr();
@@ -1107,7 +1061,8 @@ var Trie = class {
1107
1061
  }
1108
1062
  };
1109
1063
 
1110
- // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/router/reg-exp-router/router.js
1064
+ // node_modules/hono/dist/router/reg-exp-router/router.js
1065
+ var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)];
1111
1066
  var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
1112
1067
  function buildWildcardRegExp(path) {
1113
1068
  return wildcardRegExpCache[path] ??= new RegExp(path === "*" ? "" : `^${path.replace(/\/\*$|([.\\+*[^\]$()])/g, (_, metaChar) => metaChar ? `\\${metaChar}` : "(?:|/.*)")}$`);
@@ -1115,6 +1070,59 @@ function buildWildcardRegExp(path) {
1115
1070
  function clearWildcardRegExpCache() {
1116
1071
  wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
1117
1072
  }
1073
+ function buildMatcherFromPreprocessedRoutes(routes) {
1074
+ const trie = new Trie;
1075
+ const handlerData = [];
1076
+ if (routes.length === 0) {
1077
+ return nullMatcher;
1078
+ }
1079
+ const routesWithStaticPathFlag = routes.map((route) => [!/\*|\/:/.test(route[0]), ...route]).sort(([isStaticA, pathA], [isStaticB, pathB]) => isStaticA ? 1 : isStaticB ? -1 : pathA.length - pathB.length);
1080
+ const staticMap = /* @__PURE__ */ Object.create(null);
1081
+ for (let i = 0, j = -1, len = routesWithStaticPathFlag.length;i < len; i++) {
1082
+ const [pathErrorCheckOnly, path, handlers] = routesWithStaticPathFlag[i];
1083
+ if (pathErrorCheckOnly) {
1084
+ staticMap[path] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
1085
+ } else {
1086
+ j++;
1087
+ }
1088
+ let paramAssoc;
1089
+ try {
1090
+ paramAssoc = trie.insert(path, j, pathErrorCheckOnly);
1091
+ } catch (e) {
1092
+ throw e === PATH_ERROR ? new UnsupportedPathError(path) : e;
1093
+ }
1094
+ if (pathErrorCheckOnly) {
1095
+ continue;
1096
+ }
1097
+ handlerData[j] = handlers.map(([h, paramCount]) => {
1098
+ const paramIndexMap = /* @__PURE__ */ Object.create(null);
1099
+ paramCount -= 1;
1100
+ for (;paramCount >= 0; paramCount--) {
1101
+ const [key, value] = paramAssoc[paramCount];
1102
+ paramIndexMap[key] = value;
1103
+ }
1104
+ return [h, paramIndexMap];
1105
+ });
1106
+ }
1107
+ const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
1108
+ for (let i = 0, len = handlerData.length;i < len; i++) {
1109
+ for (let j = 0, len2 = handlerData[i].length;j < len2; j++) {
1110
+ const map = handlerData[i][j]?.[1];
1111
+ if (!map) {
1112
+ continue;
1113
+ }
1114
+ const keys = Object.keys(map);
1115
+ for (let k = 0, len3 = keys.length;k < len3; k++) {
1116
+ map[keys[k]] = paramReplacementMap[map[keys[k]]];
1117
+ }
1118
+ }
1119
+ }
1120
+ const handlerMap = [];
1121
+ for (const i in indexReplacementMap) {
1122
+ handlerMap[i] = handlerData[indexReplacementMap[i]];
1123
+ }
1124
+ return [regexp, handlerMap, staticMap];
1125
+ }
1118
1126
  function findMiddleware(middleware, path) {
1119
1127
  if (!middleware) {
1120
1128
  return;
@@ -1130,18 +1138,9 @@ var RegExpRouter = class {
1130
1138
  name = "RegExpRouter";
1131
1139
  #middleware;
1132
1140
  #routes;
1133
- #tries;
1134
1141
  constructor() {
1135
1142
  this.#middleware = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
1136
1143
  this.#routes = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
1137
- this.#tries = { [METHOD_NAME_ALL]: new Trie };
1138
- }
1139
- #insertPath(method, path) {
1140
- try {
1141
- this.#tries[method].insert(path, !/\*|\/:/.test(path));
1142
- } catch (e) {
1143
- throw e === PATH_ERROR ? new UnsupportedPathError(path) : e;
1144
- }
1145
1144
  }
1146
1145
  add(method, path, handler) {
1147
1146
  const middleware = this.#middleware;
@@ -1150,12 +1149,10 @@ var RegExpRouter = class {
1150
1149
  throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
1151
1150
  }
1152
1151
  if (!middleware[method]) {
1153
- this.#tries[method] = new Trie;
1154
1152
  [middleware, routes].forEach((handlerMap) => {
1155
1153
  handlerMap[method] = /* @__PURE__ */ Object.create(null);
1156
1154
  Object.keys(handlerMap[METHOD_NAME_ALL]).forEach((p) => {
1157
1155
  handlerMap[method][p] = [...handlerMap[METHOD_NAME_ALL][p]];
1158
- this.#insertPath(method, p);
1159
1156
  });
1160
1157
  });
1161
1158
  }
@@ -1165,12 +1162,13 @@ var RegExpRouter = class {
1165
1162
  const paramCount = (path.match(/\/:/g) || []).length;
1166
1163
  if (/\*$/.test(path)) {
1167
1164
  const re = buildWildcardRegExp(path);
1168
- Object.keys(middleware).forEach((m) => {
1169
- if ((method === METHOD_NAME_ALL || method === m) && !middleware[m][path]) {
1170
- this.#insertPath(m, path);
1171
- middleware[m][path] = findMiddleware(middleware[m], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
1172
- }
1173
- });
1165
+ if (method === METHOD_NAME_ALL) {
1166
+ Object.keys(middleware).forEach((m) => {
1167
+ middleware[m][path] ||= findMiddleware(middleware[m], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
1168
+ });
1169
+ } else {
1170
+ middleware[method][path] ||= findMiddleware(middleware[method], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
1171
+ }
1174
1172
  Object.keys(middleware).forEach((m) => {
1175
1173
  if (method === METHOD_NAME_ALL || method === m) {
1176
1174
  Object.keys(middleware[m]).forEach((p) => {
@@ -1190,12 +1188,9 @@ var RegExpRouter = class {
1190
1188
  const path2 = paths[i];
1191
1189
  Object.keys(routes).forEach((m) => {
1192
1190
  if (method === METHOD_NAME_ALL || method === m) {
1193
- if (!routes[m][path2]) {
1194
- this.#insertPath(m, path2);
1195
- routes[m][path2] = [
1196
- ...findMiddleware(middleware[m], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || []
1197
- ];
1198
- }
1191
+ routes[m][path2] ||= [
1192
+ ...findMiddleware(middleware[m], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || []
1193
+ ];
1199
1194
  routes[m][path2].push([handler, paramCount - len + i + 1]);
1200
1195
  }
1201
1196
  });
@@ -1207,58 +1202,31 @@ var RegExpRouter = class {
1207
1202
  Object.keys(this.#routes).concat(Object.keys(this.#middleware)).forEach((method) => {
1208
1203
  matchers[method] ||= this.#buildMatcher(method);
1209
1204
  });
1210
- this.#middleware = this.#routes = this.#tries = undefined;
1205
+ this.#middleware = this.#routes = undefined;
1211
1206
  clearWildcardRegExpCache();
1212
1207
  return matchers;
1213
1208
  }
1214
1209
  #buildMatcher(method) {
1215
- const middleware = this.#middleware[method];
1216
- const routes = this.#routes[method];
1217
- const trie = this.#tries[method];
1218
- const staticMap = /* @__PURE__ */ Object.create(null);
1219
- const handlerData = [];
1220
- [middleware, routes].forEach((r) => {
1221
- for (const path in r) {
1222
- const handlers = r[path];
1223
- const pathData = trie.paths[path];
1224
- if (!pathData) {
1225
- staticMap[path] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
1226
- continue;
1227
- }
1228
- const paramAssoc = pathData[1];
1229
- handlerData[pathData[0]] = handlers.map(([h, paramCount]) => {
1230
- const paramIndexMap = /* @__PURE__ */ Object.create(null);
1231
- paramCount -= 1;
1232
- for (;paramCount >= 0; paramCount--) {
1233
- const [key, value] = paramAssoc[paramCount];
1234
- paramIndexMap[key] = value;
1235
- }
1236
- return [h, paramIndexMap];
1237
- });
1210
+ const routes = [];
1211
+ let hasOwnRoute = method === METHOD_NAME_ALL;
1212
+ [this.#middleware, this.#routes].forEach((r) => {
1213
+ const ownRoute = r[method] ? Object.keys(r[method]).map((path) => [path, r[method][path]]) : [];
1214
+ if (ownRoute.length !== 0) {
1215
+ hasOwnRoute ||= true;
1216
+ routes.push(...ownRoute);
1217
+ } else if (method !== METHOD_NAME_ALL) {
1218
+ routes.push(...Object.keys(r[METHOD_NAME_ALL]).map((path) => [path, r[METHOD_NAME_ALL][path]]));
1238
1219
  }
1239
1220
  });
1240
- const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
1241
- for (let i = 0, len = handlerData.length;i < len; i++) {
1242
- for (let j = 0, len2 = handlerData[i].length;j < len2; j++) {
1243
- const map = handlerData[i][j]?.[1];
1244
- if (!map) {
1245
- continue;
1246
- }
1247
- const keys = Object.keys(map);
1248
- for (let k = 0, len3 = keys.length;k < len3; k++) {
1249
- map[keys[k]] = paramReplacementMap[map[keys[k]]];
1250
- }
1251
- }
1252
- }
1253
- const handlerMap = [];
1254
- for (const i in indexReplacementMap) {
1255
- handlerMap[i] = handlerData[indexReplacementMap[i]];
1221
+ if (!hasOwnRoute) {
1222
+ return null;
1223
+ } else {
1224
+ return buildMatcherFromPreprocessedRoutes(routes);
1256
1225
  }
1257
- return [regexp, handlerMap, staticMap];
1258
1226
  }
1259
1227
  };
1260
1228
 
1261
- // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/router/reg-exp-router/prepared-router.js
1229
+ // node_modules/hono/dist/router/reg-exp-router/prepared-router.js
1262
1230
  var PreparedRegExpRouter = class {
1263
1231
  name = "PreparedRegExpRouter";
1264
1232
  #matchers;
@@ -1330,7 +1298,7 @@ var PreparedRegExpRouter = class {
1330
1298
  match = match;
1331
1299
  };
1332
1300
 
1333
- // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/router/smart-router/router.js
1301
+ // node_modules/hono/dist/router/smart-router/router.js
1334
1302
  var SmartRouter = class {
1335
1303
  name = "SmartRouter";
1336
1304
  #routers = [];
@@ -1385,7 +1353,7 @@ var SmartRouter = class {
1385
1353
  }
1386
1354
  };
1387
1355
 
1388
- // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/router/trie-router/node.js
1356
+ // node_modules/hono/dist/router/trie-router/node.js
1389
1357
  var emptyParams = /* @__PURE__ */ Object.create(null);
1390
1358
  var hasChildren = (children) => {
1391
1359
  for (const _ in children) {
@@ -1519,12 +1487,9 @@ var Node2 = class _Node2 {
1519
1487
  if (m) {
1520
1488
  params[name] = m[0];
1521
1489
  this.#pushHandlerSets(handlerSets, child, method, node.#params, params);
1522
- if (m[0].length === restPathString.length && child.#children["*"]) {
1523
- this.#pushHandlerSets(handlerSets, child.#children["*"], method, node.#params, params);
1524
- }
1525
1490
  if (hasChildren(child.#children)) {
1526
1491
  child.#params = params;
1527
- const componentCount = m[0].match(/\//g)?.length ?? 0;
1492
+ const componentCount = m[0].match(/\//)?.length ?? 0;
1528
1493
  const targetCurNodes = curNodesQueue[componentCount] ||= [];
1529
1494
  targetCurNodes.push(child);
1530
1495
  }
@@ -1557,7 +1522,7 @@ var Node2 = class _Node2 {
1557
1522
  }
1558
1523
  };
1559
1524
 
1560
- // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/router/trie-router/router.js
1525
+ // node_modules/hono/dist/router/trie-router/router.js
1561
1526
  var TrieRouter = class {
1562
1527
  name = "TrieRouter";
1563
1528
  #node;
@@ -1579,7 +1544,7 @@ var TrieRouter = class {
1579
1544
  }
1580
1545
  };
1581
1546
 
1582
- // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/hono.js
1547
+ // node_modules/hono/dist/hono.js
1583
1548
  var Hono2 = class extends Hono {
1584
1549
  constructor(options = {}) {
1585
1550
  super(options);
@@ -1589,18 +1554,24 @@ var Hono2 = class extends Hono {
1589
1554
  }
1590
1555
  };
1591
1556
 
1592
- // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/middleware/cors/index.js
1557
+ // node_modules/hono/dist/middleware/cors/index.js
1593
1558
  var cors = (options) => {
1594
- const opts = {
1559
+ const defaults = {
1595
1560
  origin: "*",
1596
- allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH", "QUERY"],
1561
+ allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"],
1597
1562
  allowHeaders: [],
1598
- exposeHeaders: [],
1563
+ exposeHeaders: []
1564
+ };
1565
+ const opts = {
1566
+ ...defaults,
1599
1567
  ...options
1600
1568
  };
1601
1569
  const findAllowOrigin = ((optsOrigin) => {
1602
1570
  if (typeof optsOrigin === "string") {
1603
1571
  if (optsOrigin === "*") {
1572
+ if (opts.credentials) {
1573
+ return (origin) => origin || null;
1574
+ }
1604
1575
  return () => optsOrigin;
1605
1576
  } else {
1606
1577
  return (origin) => optsOrigin === origin ? origin : null;
@@ -1635,7 +1606,7 @@ var cors = (options) => {
1635
1606
  set("Access-Control-Expose-Headers", opts.exposeHeaders.join(","));
1636
1607
  }
1637
1608
  if (c.req.method === "OPTIONS") {
1638
- if (opts.origin !== "*") {
1609
+ if (opts.origin !== "*" || opts.credentials) {
1639
1610
  set("Vary", "Origin");
1640
1611
  }
1641
1612
  if (opts.maxAge != null) {
@@ -1649,7 +1620,7 @@ var cors = (options) => {
1649
1620
  if (!headers?.length) {
1650
1621
  const requestHeaders = c.req.header("Access-Control-Request-Headers");
1651
1622
  if (requestHeaders) {
1652
- headers = requestHeaders.split(",").map((h) => h.trim());
1623
+ headers = requestHeaders.split(/\s*,\s*/);
1653
1624
  }
1654
1625
  }
1655
1626
  if (headers?.length) {
@@ -1665,7 +1636,7 @@ var cors = (options) => {
1665
1636
  });
1666
1637
  }
1667
1638
  await next();
1668
- if (opts.origin !== "*") {
1639
+ if (opts.origin !== "*" || opts.credentials) {
1669
1640
  c.header("Vary", "Origin", { append: true });
1670
1641
  }
1671
1642
  };
@@ -1744,7 +1715,7 @@ class ProfileNotFoundError extends Error {
1744
1715
  }
1745
1716
  }
1746
1717
 
1747
- // ../../node_modules/.bun/@hasna+contracts@0.4.2/node_modules/@hasna/contracts/dist/auth/index.js
1718
+ // node_modules/@hasna/contracts/dist/auth/index.js
1748
1719
  import { createHash, createHmac, randomBytes, timingSafeEqual } from "crypto";
1749
1720
  var API_KEY_TOKEN_VERSION = 1;
1750
1721
  var API_KEY_NAMESPACE = "hasna";
@@ -2111,152 +2082,53 @@ function honoApiKey(options) {
2111
2082
  return c.json({ error: decision.message, reason: decision.reason }, decision.status);
2112
2083
  };
2113
2084
  }
2114
-
2115
- // src/generated/storage-kit/own.ts
2116
- function ownProp(source, key) {
2117
- if (source === null || source === undefined)
2118
- return;
2119
- const kind = typeof source;
2120
- if (kind !== "object" && kind !== "function")
2121
- return;
2122
- if (!Object.hasOwn(source, key))
2123
- return;
2124
- return source[key];
2125
- }
2126
- function ownString(source, key) {
2127
- const value = ownProp(source, key);
2128
- return typeof value === "string" ? value : undefined;
2129
- }
2130
2085
  // src/generated/storage-kit/tls.ts
2131
2086
  import { readFileSync as readFileSync2 } from "fs";
2132
- var PG_TLS_QUERY_PARAMETERS = new Set([
2133
- "ssl",
2134
- "sslmode",
2135
- "sslrootcert",
2136
- "sslcert",
2137
- "sslkey",
2138
- "sslpassword",
2139
- "sslnegotiation",
2140
- "uselibpqcompat"
2141
- ]);
2142
- var EXPLICIT_SSL_ON_VALUES = new Set(["1", "true", "yes", "on", "require"]);
2143
- var EXPLICIT_SSL_OFF_VALUES = new Set(["0", "false", "no", "off", "disable"]);
2144
- var SSLMODE_VALUES = new Map([
2145
- ["disable", "disable"],
2146
- ["allow", "prefer"],
2147
- ["prefer", "prefer"],
2148
- ["require", "require"],
2149
- ["verify-ca", "verify-ca"],
2150
- ["verify-full", "verify-full"]
2151
- ]);
2152
- function connectionStringParts(connectionString) {
2153
- const queryStart = connectionString.indexOf("?");
2154
- if (queryStart === -1) {
2155
- return { base: connectionString, fragment: "", params: new URLSearchParams };
2156
- }
2157
- const base = connectionString.slice(0, queryStart);
2158
- const queryAndFragment = connectionString.slice(queryStart + 1);
2159
- const fragmentStart = queryAndFragment.indexOf("#");
2160
- const query = fragmentStart === -1 ? queryAndFragment : queryAndFragment.slice(0, fragmentStart);
2161
- const fragment = fragmentStart === -1 ? "" : queryAndFragment.slice(fragmentStart);
2162
- return { base, fragment, params: new URLSearchParams(query) };
2163
- }
2164
- function tlsQueryValues(connectionString) {
2165
- const values = new Map;
2166
- for (const [key, value] of connectionStringParts(connectionString).params) {
2167
- const normalized = key.toLowerCase();
2168
- if (PG_TLS_QUERY_PARAMETERS.has(normalized))
2169
- values.set(normalized, value);
2170
- }
2171
- return values;
2172
- }
2173
- function connectionStringWithoutTlsParameters(connectionString) {
2174
- const { base, fragment, params } = connectionStringParts(connectionString);
2175
- for (const key of [...params.keys()]) {
2176
- if (PG_TLS_QUERY_PARAMETERS.has(key.toLowerCase()))
2177
- params.delete(key);
2178
- }
2179
- const query = params.toString();
2180
- return `${base}${query ? `?${query}` : ""}${fragment}`;
2181
- }
2182
- function rawSslMode(values) {
2183
- const raw2 = values.get("sslmode");
2184
- return raw2 === undefined ? undefined : raw2.trim().toLowerCase();
2185
- }
2186
- function sslNegotiationFromConnectionString(connectionString) {
2187
- const value = tlsQueryValues(connectionString).get("sslnegotiation")?.trim().toLowerCase();
2188
- if (!value)
2189
- return;
2190
- if (value === "postgres" || value === "direct")
2191
- return value;
2192
- throw new Error(`Unknown sslnegotiation '${value}' in connection string; expected postgres or direct.`);
2193
- }
2194
2087
  function sslModeFromConnectionString(connectionString) {
2195
- const values = tlsQueryValues(connectionString);
2196
- const sslmode = rawSslMode(values);
2197
- if (sslmode !== undefined) {
2198
- const resolved = SSLMODE_VALUES.get(sslmode);
2199
- if (resolved)
2200
- return resolved;
2201
- throw new Error(`Unknown sslmode '${sslmode}' in connection string; expected one of ` + `${[...SSLMODE_VALUES.keys()].join(", ")}. Remove the parameter entirely to defer to ` + `PGSSLMODE \u2014 an empty value is not how that is spelled.`);
2202
- }
2203
- if (values.has("ssl")) {
2204
- const ssl = values.get("ssl")?.trim().toLowerCase() ?? "";
2205
- if (EXPLICIT_SSL_ON_VALUES.has(ssl))
2206
- return "require";
2207
- if (!EXPLICIT_SSL_OFF_VALUES.has(ssl)) {
2208
- throw new Error(`Unknown ssl value '${ssl}' in connection string.`);
2209
- }
2210
- return "disable";
2211
- }
2212
- const sslnegotiation = values.get("sslnegotiation")?.trim().toLowerCase();
2213
- if (sslnegotiation === "direct")
2088
+ const queryStart = connectionString.indexOf("?");
2089
+ const params = new URLSearchParams(queryStart === -1 ? "" : connectionString.slice(queryStart + 1));
2090
+ const sslmode = params.get("sslmode")?.trim().toLowerCase();
2091
+ if (sslmode) {
2092
+ switch (sslmode) {
2093
+ case "disable":
2094
+ case "prefer":
2095
+ case "require":
2096
+ case "verify-ca":
2097
+ case "verify-full":
2098
+ return sslmode;
2099
+ case "allow":
2100
+ return "prefer";
2101
+ default:
2102
+ throw new Error(`Unknown sslmode '${sslmode}' in connection string.`);
2103
+ }
2104
+ }
2105
+ const ssl = params.get("ssl")?.trim().toLowerCase();
2106
+ if (ssl && ["1", "true", "yes", "on", "require"].includes(ssl))
2214
2107
  return "require";
2215
2108
  return "disable";
2216
2109
  }
2217
- function loadCaBundle(connectionString, options) {
2218
- const env = ownProp(options, "env") ?? process.env;
2219
- const ca = ownString(options, "ca");
2220
- if (ca && ca.trim())
2221
- return ca;
2222
- const sslRootCert = tlsQueryValues(connectionString).get("sslrootcert")?.trim();
2223
- const path = ownString(options, "caCertPath") ?? (sslRootCert ? sslRootCert : undefined) ?? ownString(env, "PGSSLROOTCERT") ?? ownString(env, "NODE_EXTRA_CA_CERTS");
2110
+ function loadCaBundle(options) {
2111
+ const env = options.env ?? process.env;
2112
+ if (options.ca && options.ca.trim())
2113
+ return options.ca;
2114
+ const path = options.caCertPath ?? env.PGSSLROOTCERT ?? env.NODE_EXTRA_CA_CERTS;
2224
2115
  if (path && path.trim())
2225
2116
  return readFileSync2(path.trim(), "utf8");
2226
2117
  return null;
2227
2118
  }
2228
- function loadClientCertificate(connectionString) {
2229
- const values = tlsQueryValues(connectionString);
2230
- const material = {};
2231
- const certPath = values.get("sslcert")?.trim();
2232
- if (certPath)
2233
- material.cert = readFileSync2(certPath, "utf8");
2234
- const keyPath = values.get("sslkey")?.trim();
2235
- if (keyPath)
2236
- material.key = readFileSync2(keyPath, "utf8");
2237
- const passphrase = values.get("sslpassword");
2238
- if (passphrase)
2239
- material.passphrase = passphrase;
2240
- return material;
2241
- }
2242
2119
  function resolveTlsConfig(connectionString, options = {}) {
2243
2120
  const mode = sslModeFromConnectionString(connectionString);
2244
- if (mode === "disable") {
2245
- const values = tlsQueryValues(connectionString);
2246
- const sslmode = rawSslMode(values);
2247
- const ssl = values.get("ssl")?.trim().toLowerCase();
2248
- const explicitlyOff = sslmode === "disable" || ssl !== undefined && EXPLICIT_SSL_OFF_VALUES.has(ssl);
2249
- return explicitlyOff ? false : undefined;
2250
- }
2251
- const ca = loadCaBundle(connectionString, options);
2252
- const clientCertificate = loadClientCertificate(connectionString);
2253
- if (mode === "prefer" || mode === "require") {
2254
- return { rejectUnauthorized: true, ...ca ? { ca } : {}, ...clientCertificate };
2121
+ if (mode === "disable" || mode === "prefer") {
2122
+ return;
2123
+ }
2124
+ const ca = loadCaBundle(options);
2125
+ if (mode === "require") {
2126
+ return ca ? { rejectUnauthorized: false, ca } : { rejectUnauthorized: false };
2255
2127
  }
2256
2128
  if (!ca) {
2257
2129
  throw new Error(`sslmode=${mode} requires a CA bundle. Set PGSSLROOTCERT (or pass caCertPath/ca) to the ` + `Amazon RDS global bundle: https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem`);
2258
2130
  }
2259
- return { rejectUnauthorized: true, ca, ...clientCertificate };
2131
+ return { rejectUnauthorized: true, ca };
2260
2132
  }
2261
2133
  // src/generated/storage-kit/query.ts
2262
2134
  function wrapExecutor(executor) {
@@ -2313,58 +2185,23 @@ function createQueryClient(pool) {
2313
2185
  }
2314
2186
  // src/generated/storage-kit/pool.ts
2315
2187
  import pg from "pg";
2316
- function ownPoolOptions(options) {
2317
- const own = Object.create(null);
2318
- const ca = ownString(options, "ca");
2319
- if (ca !== undefined)
2320
- own.ca = ca;
2321
- const caCertPath = ownString(options, "caCertPath");
2322
- if (caCertPath !== undefined)
2323
- own.caCertPath = caCertPath;
2324
- const env = ownProp(options, "env");
2325
- if (env !== undefined)
2326
- own.env = env;
2327
- const max = ownProp(options, "max");
2328
- if (max !== undefined)
2329
- own.max = max;
2330
- const idleTimeoutMillis = ownProp(options, "idleTimeoutMillis");
2331
- if (idleTimeoutMillis !== undefined)
2332
- own.idleTimeoutMillis = idleTimeoutMillis;
2333
- const connectionTimeoutMillis = ownProp(options, "connectionTimeoutMillis");
2334
- if (connectionTimeoutMillis !== undefined)
2335
- own.connectionTimeoutMillis = connectionTimeoutMillis;
2336
- const applicationName = ownString(options, "applicationName");
2337
- if (applicationName !== undefined)
2338
- own.applicationName = applicationName;
2339
- return own;
2340
- }
2341
2188
  function createPgPool(options) {
2342
- const connectionString = ownString(options, "connectionString");
2343
- if (!connectionString || !connectionString.trim()) {
2344
- throw new Error("createPgPool requires an own `connectionString` on the options object.");
2345
- }
2346
- const own = ownPoolOptions(options);
2347
- const ssl = resolveTlsConfig(connectionString, {
2348
- ...own.ca !== undefined ? { ca: own.ca } : {},
2349
- ...own.caCertPath !== undefined ? { caCertPath: own.caCertPath } : {},
2350
- ...own.env !== undefined ? { env: own.env } : {}
2189
+ const ssl = resolveTlsConfig(options.connectionString, {
2190
+ ...options.ca !== undefined ? { ca: options.ca } : {},
2191
+ ...options.caCertPath !== undefined ? { caCertPath: options.caCertPath } : {},
2192
+ ...options.env !== undefined ? { env: options.env } : {}
2351
2193
  });
2352
- const config = {
2353
- connectionString: connectionStringWithoutTlsParameters(connectionString)
2354
- };
2194
+ const config = { connectionString: options.connectionString };
2355
2195
  if (ssl !== undefined)
2356
2196
  config.ssl = ssl;
2357
- const sslnegotiation = sslNegotiationFromConnectionString(connectionString);
2358
- if (sslnegotiation !== undefined)
2359
- config.sslnegotiation = sslnegotiation;
2360
- if (own.max !== undefined)
2361
- config.max = own.max;
2362
- if (own.idleTimeoutMillis !== undefined)
2363
- config.idleTimeoutMillis = own.idleTimeoutMillis;
2364
- if (own.connectionTimeoutMillis !== undefined)
2365
- config.connectionTimeoutMillis = own.connectionTimeoutMillis;
2366
- if (own.applicationName !== undefined)
2367
- config.application_name = own.applicationName;
2197
+ if (options.max !== undefined)
2198
+ config.max = options.max;
2199
+ if (options.idleTimeoutMillis !== undefined)
2200
+ config.idleTimeoutMillis = options.idleTimeoutMillis;
2201
+ if (options.connectionTimeoutMillis !== undefined)
2202
+ config.connectionTimeoutMillis = options.connectionTimeoutMillis;
2203
+ if (options.applicationName !== undefined)
2204
+ config.application_name = options.applicationName;
2368
2205
  return new pg.Pool(config);
2369
2206
  }
2370
2207
  // src/storage/schema.ts
@@ -2445,37 +2282,15 @@ function instructionsSchemaSql() {
2445
2282
  ];
2446
2283
  }
2447
2284
 
2448
- // src/lib/retired-storage-mode.ts
2449
- var LEGACY_STORAGE_MODE_KEYS = [
2450
- "HASNA_INSTRUCTIONS_STORAGE_MODE",
2451
- "HASNA_INSTRUCTIONS_MODE",
2452
- "INSTRUCTIONS_STORAGE_MODE",
2453
- "INSTRUCTIONS_MODE"
2454
- ];
2455
- function firstDefinedEnvKey(env, keys) {
2456
- for (const key of keys) {
2457
- if (Object.hasOwn(env, key) && env[key] !== undefined)
2458
- return key;
2459
- }
2460
- return null;
2461
- }
2462
- function assertNoLegacyStorageMode(env = process.env) {
2463
- const legacyKey = firstDefinedEnvKey(env, LEGACY_STORAGE_MODE_KEYS);
2464
- if (!legacyKey)
2465
- return;
2466
- throw new Error(`${legacyKey} was removed. Deployment modes no longer exist: delete the storage-mode variable. ` + `The client uses the local SQLite store, or the HTTP API selected by ` + `HASNA_INSTRUCTIONS_API_URL + HASNA_INSTRUCTIONS_API_KEY. ` + `On the server, set HASNA_INSTRUCTIONS_DATABASE_URL to select the postgresql backend, ` + `or leave it unset for sqlite.`);
2467
- }
2468
-
2469
2285
  // src/server/cloud.ts
2470
2286
  var INSTRUCTIONS_APP_SLUG = "instructions";
2471
2287
  function resolveCloudDatabaseUrl(env = process.env) {
2472
- assertNoLegacyStorageMode(env);
2473
2288
  return env.HASNA_INSTRUCTIONS_DATABASE_URL || env.INSTRUCTIONS_DATABASE_URL || env.DATABASE_URL || undefined;
2474
2289
  }
2475
2290
  function resolveSigningSecret(env = process.env) {
2476
2291
  return env.HASNA_INSTRUCTIONS_API_SIGNING_KEY || env.HASNA_API_SIGNING_KEY || env.API_KEY_SIGNING_SECRET || undefined;
2477
2292
  }
2478
- function isPostgresBackendEnabled(env = process.env) {
2293
+ function isCloudModeEnabled(env = process.env) {
2479
2294
  return Boolean(resolveCloudDatabaseUrl(env));
2480
2295
  }
2481
2296
  var cachedClient = null;
@@ -2933,7 +2748,7 @@ Policy reference: \`${CODEWITH_SHARED_TODOS_STORAGE_POLICY_REFERENCE}\`
2933
2748
  // src/lib/project-context.ts
2934
2749
  import { basename, dirname as dirname2, isAbsolute, join as join2, parse, relative, resolve } from "path";
2935
2750
 
2936
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/external.js
2751
+ // node_modules/zod/v3/external.js
2937
2752
  var exports_external = {};
2938
2753
  __export(exports_external, {
2939
2754
  void: () => voidType,
@@ -3045,7 +2860,7 @@ __export(exports_external, {
3045
2860
  BRAND: () => BRAND
3046
2861
  });
3047
2862
 
3048
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/util.js
2863
+ // node_modules/zod/v3/helpers/util.js
3049
2864
  var util;
3050
2865
  (function(util2) {
3051
2866
  util2.assertEqual = (_) => {};
@@ -3176,7 +2991,7 @@ var getParsedType = (data) => {
3176
2991
  }
3177
2992
  };
3178
2993
 
3179
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/ZodError.js
2994
+ // node_modules/zod/v3/ZodError.js
3180
2995
  var ZodIssueCode = util.arrayToEnum([
3181
2996
  "invalid_type",
3182
2997
  "invalid_literal",
@@ -3295,7 +3110,7 @@ ZodError.create = (issues) => {
3295
3110
  return error;
3296
3111
  };
3297
3112
 
3298
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/locales/en.js
3113
+ // node_modules/zod/v3/locales/en.js
3299
3114
  var errorMap = (issue, _ctx) => {
3300
3115
  let message;
3301
3116
  switch (issue.code) {
@@ -3398,7 +3213,7 @@ var errorMap = (issue, _ctx) => {
3398
3213
  };
3399
3214
  var en_default = errorMap;
3400
3215
 
3401
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/errors.js
3216
+ // node_modules/zod/v3/errors.js
3402
3217
  var overrideErrorMap = en_default;
3403
3218
  function setErrorMap(map) {
3404
3219
  overrideErrorMap = map;
@@ -3406,7 +3221,7 @@ function setErrorMap(map) {
3406
3221
  function getErrorMap() {
3407
3222
  return overrideErrorMap;
3408
3223
  }
3409
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js
3224
+ // node_modules/zod/v3/helpers/parseUtil.js
3410
3225
  var makeIssue = (params) => {
3411
3226
  const { data, path, errorMaps, issueData } = params;
3412
3227
  const fullPath = [...path, ...issueData.path || []];
@@ -3512,14 +3327,14 @@ var isAborted = (x) => x.status === "aborted";
3512
3327
  var isDirty = (x) => x.status === "dirty";
3513
3328
  var isValid = (x) => x.status === "valid";
3514
3329
  var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
3515
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js
3330
+ // node_modules/zod/v3/helpers/errorUtil.js
3516
3331
  var errorUtil;
3517
3332
  (function(errorUtil2) {
3518
3333
  errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
3519
3334
  errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
3520
3335
  })(errorUtil || (errorUtil = {}));
3521
3336
 
3522
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/types.js
3337
+ // node_modules/zod/v3/types.js
3523
3338
  class ParseInputLazyPath {
3524
3339
  constructor(parent, value, path, key) {
3525
3340
  this._cachedPath = [];
@@ -7442,15 +7257,15 @@ function normalizeActivation(value) {
7442
7257
  if (!INSTRUCTION_ACTIVATION_MODES.includes(record["mode"])) {
7443
7258
  throw new Error(`Invalid instruction activation mode: ${String(record["mode"])}`);
7444
7259
  }
7445
- const mode = record["mode"];
7260
+ const mode2 = record["mode"];
7446
7261
  const globs = stringArray(record["globs"], "activation.globs");
7447
7262
  const models = stringArray(record["models"], "activation.models");
7448
- if (mode === "glob" && (!globs || globs.length === 0))
7263
+ if (mode2 === "glob" && (!globs || globs.length === 0))
7449
7264
  throw new Error("Glob activation requires at least one glob.");
7450
- if (mode === "model" && (!models || models.length === 0))
7265
+ if (mode2 === "model" && (!models || models.length === 0))
7451
7266
  throw new Error("Model activation requires at least one model.");
7452
7267
  return {
7453
- mode,
7268
+ mode: mode2,
7454
7269
  ...globs ? { globs } : {},
7455
7270
  ...models ? { models } : {},
7456
7271
  ...optionalString(record["description"], "activation.description") ? { description: record["description"] } : {},
@@ -8840,22 +8655,22 @@ if (process.argv.includes("--version") || process.argv.includes("-V")) {
8840
8655
  var PORT = Number(process.env["PORT"] ?? process.env["INSTRUCTIONS_PORT"] ?? 3457);
8841
8656
  var app = new Hono2;
8842
8657
  app.use("*", cors());
8843
- function serviceBackend() {
8844
- return isPostgresBackendEnabled() ? "postgresql" : "sqlite";
8658
+ function serviceMode() {
8659
+ return isCloudModeEnabled() ? "cloud" : "local";
8845
8660
  }
8846
- app.get("/health", (c) => c.json({ status: "ok", version: getPackageVersion(), backend: serviceBackend(), name: "instructions" }));
8847
- app.get("/version", (c) => c.json({ status: "ok", version: getPackageVersion(), backend: serviceBackend(), name: "instructions" }));
8661
+ app.get("/health", (c) => c.json({ status: "ok", version: getPackageVersion(), mode: serviceMode(), name: "instructions" }));
8662
+ app.get("/version", (c) => c.json({ status: "ok", version: getPackageVersion(), mode: serviceMode(), name: "instructions" }));
8848
8663
  app.get("/ready", async (c) => {
8849
8664
  const version = getPackageVersion();
8850
- const backend2 = serviceBackend();
8851
- if (backend2 === "postgresql") {
8665
+ const mode2 = serviceMode();
8666
+ if (mode2 === "cloud") {
8852
8667
  try {
8853
8668
  await pingCloud();
8854
8669
  } catch (e) {
8855
- return c.json({ status: "unavailable", version, backend: backend2, error: e.message }, 503);
8670
+ return c.json({ status: "unavailable", version, mode: mode2, error: e.message }, 503);
8856
8671
  }
8857
8672
  }
8858
- return c.json({ status: "ready", version, backend: backend2 });
8673
+ return c.json({ status: "ready", version, mode: mode2 });
8859
8674
  });
8860
8675
  app.get("/openapi.json", (c) => c.json(buildV1OpenApiDocument()));
8861
8676
  app.get("/v1/openapi.json", (c) => c.json(buildV1OpenApiDocument()));
@@ -8907,7 +8722,7 @@ if (dashDir) {
8907
8722
  });
8908
8723
  }
8909
8724
  var HOST = process.env["HOST"] ?? process.env["INSTRUCTIONS_HOST"] ?? "localhost";
8910
- console.log(`instructions-serve listening on http://${HOST}:${PORT} (backend: ${serviceBackend()})${dashDir ? " (dashboard: /)" : " (no dashboard)"}`);
8725
+ console.log(`instructions-serve listening on http://${HOST}:${PORT} (mode: ${serviceMode()})${dashDir ? " (dashboard: /)" : " (no dashboard)"}`);
8911
8726
  var server_default = { port: PORT, hostname: HOST, fetch: app.fetch };
8912
8727
  export {
8913
8728
  server_default as default