@hasna/instructions 0.4.33 → 0.4.35

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/hono/dist/compose.js
19
+ // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/compose.js
20
20
  var compose = (middleware, onError, onNotFound) => {
21
21
  return (context, next) => {
22
22
  let index = -1;
@@ -60,21 +60,42 @@ var compose = (middleware, onError, onNotFound) => {
60
60
  };
61
61
  };
62
62
 
63
- // node_modules/hono/dist/request/constants.js
63
+ // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/request/constants.js
64
64
  var GET_MATCH_RESULT = /* @__PURE__ */ Symbol();
65
65
 
66
- // node_modules/hono/dist/utils/body.js
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);
67
78
  var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
68
79
  const { all = false, dot = false } = options;
69
- const headers = request instanceof HonoRequest ? request.raw.headers : request.headers;
80
+ const headers = isRawRequest(request) ? request.headers : request.raw.headers;
70
81
  const contentType = headers.get("Content-Type");
71
- if (contentType?.startsWith("multipart/form-data") || contentType?.startsWith("application/x-www-form-urlencoded")) {
82
+ const mediaType = contentType?.split(";")[0].trim().toLowerCase();
83
+ if (mediaType === "multipart/form-data" || mediaType === "application/x-www-form-urlencoded") {
72
84
  return parseFormData(request, { all, dot });
73
85
  }
74
86
  return {};
75
87
  };
76
88
  async function parseFormData(request, options) {
77
- const formData = await request.formData();
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;
78
99
  if (formData) {
79
100
  return convertFormDataToBodyData(formData, options);
80
101
  }
@@ -134,7 +155,7 @@ var handleParsingNestedValues = (form, key, value) => {
134
155
  });
135
156
  };
136
157
 
137
- // node_modules/hono/dist/utils/url.js
158
+ // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/utils/url.js
138
159
  var splitPath = (path) => {
139
160
  const paths = path.split("/");
140
161
  if (paths[0] === "") {
@@ -256,18 +277,16 @@ var checkOptionalParameter = (path) => {
256
277
  });
257
278
  return results.filter((v, i, a) => a.indexOf(v) === i);
258
279
  };
280
+ var tryDecodeURIComponent = (str) => str.indexOf("%") !== -1 ? tryDecode(str, decodeURIComponent_) : str;
259
281
  var _decodeURI = (value) => {
260
- if (!/[%+]/.test(value)) {
261
- return value;
262
- }
263
282
  if (value.indexOf("+") !== -1) {
264
283
  value = value.replace(/\+/g, " ");
265
284
  }
266
- return value.indexOf("%") !== -1 ? tryDecode(value, decodeURIComponent_) : value;
285
+ return tryDecodeURIComponent(value);
267
286
  };
268
287
  var _getQueryParam = (url, key, multiple) => {
269
288
  let encoded;
270
- if (!multiple && key && !/[%+]/.test(key)) {
289
+ if (!multiple && key && key.indexOf("%") === -1 && key.indexOf("+") === -1) {
271
290
  let keyIndex2 = url.indexOf("?", 8);
272
291
  if (keyIndex2 === -1) {
273
292
  return;
@@ -291,7 +310,7 @@ var _getQueryParam = (url, key, multiple) => {
291
310
  return;
292
311
  }
293
312
  }
294
- const results = {};
313
+ const results = /* @__PURE__ */ Object.create(null);
295
314
  encoded ??= /[%+]/.test(url);
296
315
  let keyIndex = url.indexOf("?", 8);
297
316
  while (keyIndex !== -1) {
@@ -334,8 +353,7 @@ var getQueryParams = (url, key) => {
334
353
  };
335
354
  var decodeURIComponent_ = decodeURIComponent;
336
355
 
337
- // node_modules/hono/dist/request.js
338
- var tryDecodeURIComponent = (str) => tryDecode(str, decodeURIComponent_);
356
+ // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/request.js
339
357
  var HonoRequest = class {
340
358
  raw;
341
359
  #validatedData;
@@ -347,7 +365,6 @@ var HonoRequest = class {
347
365
  this.raw = request;
348
366
  this.path = path;
349
367
  this.#matchResult = matchResult;
350
- this.#validatedData = {};
351
368
  }
352
369
  param(key) {
353
370
  return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams();
@@ -355,7 +372,7 @@ var HonoRequest = class {
355
372
  #getDecodedParam(key) {
356
373
  const paramKey = this.#matchResult[0][this.routeIndex][1][key];
357
374
  const param = this.#getParamValue(paramKey);
358
- return param && /\%/.test(param) ? tryDecodeURIComponent(param) : param;
375
+ return param && tryDecodeURIComponent(param);
359
376
  }
360
377
  #getAllDecodedParams() {
361
378
  const decoded = {};
@@ -363,7 +380,7 @@ var HonoRequest = class {
363
380
  for (const key of keys) {
364
381
  const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
365
382
  if (value !== undefined) {
366
- decoded[key] = /\%/.test(value) ? tryDecodeURIComponent(value) : value;
383
+ decoded[key] = tryDecodeURIComponent(value);
367
384
  }
368
385
  }
369
386
  return decoded;
@@ -381,7 +398,7 @@ var HonoRequest = class {
381
398
  if (name) {
382
399
  return this.raw.headers.get(name) ?? undefined;
383
400
  }
384
- const headerData = {};
401
+ const headerData = /* @__PURE__ */ Object.create(null);
385
402
  this.raw.headers.forEach((value, key) => {
386
403
  headerData[key] = value;
387
404
  });
@@ -396,8 +413,7 @@ var HonoRequest = class {
396
413
  if (cachedBody) {
397
414
  return cachedBody;
398
415
  }
399
- const anyCachedKey = Object.keys(bodyCache)[0];
400
- if (anyCachedKey) {
416
+ for (const anyCachedKey in bodyCache) {
401
417
  return bodyCache[anyCachedKey].then((body) => {
402
418
  if (anyCachedKey === "json") {
403
419
  body = JSON.stringify(body);
@@ -416,6 +432,9 @@ var HonoRequest = class {
416
432
  arrayBuffer() {
417
433
  return this.#cachedBody("arrayBuffer");
418
434
  }
435
+ bytes() {
436
+ return this.#cachedBody("arrayBuffer").then((buffer) => new Uint8Array(buffer));
437
+ }
419
438
  blob() {
420
439
  return this.#cachedBody("blob");
421
440
  }
@@ -423,10 +442,10 @@ var HonoRequest = class {
423
442
  return this.#cachedBody("formData");
424
443
  }
425
444
  addValidatedData(target, data) {
426
- this.#validatedData[target] = data;
445
+ (this.#validatedData ??= {})[target] = data;
427
446
  }
428
447
  valid(target) {
429
- return this.#validatedData[target];
448
+ return this.#validatedData?.[target];
430
449
  }
431
450
  get url() {
432
451
  return this.raw.url;
@@ -445,7 +464,7 @@ var HonoRequest = class {
445
464
  }
446
465
  };
447
466
 
448
- // node_modules/hono/dist/utils/html.js
467
+ // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/utils/html.js
449
468
  var HtmlEscapedCallbackPhase = {
450
469
  Stringify: 1,
451
470
  BeforeStream: 2,
@@ -483,7 +502,7 @@ var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) =>
483
502
  }
484
503
  };
485
504
 
486
- // node_modules/hono/dist/context.js
505
+ // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/context.js
487
506
  var TEXT_PLAIN = "text/plain; charset=UTF-8";
488
507
  var setDefaultContentType = (contentType, headers) => {
489
508
  return {
@@ -601,11 +620,11 @@ var Context = class {
601
620
  return Object.fromEntries(this.#var);
602
621
  }
603
622
  #newResponse(data, arg, headers) {
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") {
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") {
609
628
  responseHeaders.append(key, value);
610
629
  } else {
611
630
  responseHeaders.set(key, value);
@@ -613,19 +632,34 @@ var Context = class {
613
632
  }
614
633
  }
615
634
  if (headers) {
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);
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
+ }
623
654
  }
624
655
  }
625
656
  }
626
657
  }
627
658
  const status = typeof arg === "number" ? arg : arg?.status ?? this.#status;
628
- return createResponseInstance(data, { status, headers: responseHeaders });
659
+ return createResponseInstance(data, {
660
+ status,
661
+ headers: responseHeaders ?? headers
662
+ });
629
663
  }
630
664
  newResponse = (...args) => this.#newResponse(...args);
631
665
  body = (data, arg, headers) => this.#newResponse(data, arg, headers);
@@ -650,18 +684,18 @@ var Context = class {
650
684
  };
651
685
  };
652
686
 
653
- // node_modules/hono/dist/router.js
687
+ // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/router.js
654
688
  var METHOD_NAME_ALL = "ALL";
655
689
  var METHOD_NAME_ALL_LOWERCASE = "all";
656
- var METHODS = ["get", "post", "put", "delete", "options", "patch"];
690
+ var METHODS = ["get", "post", "put", "delete", "options", "patch", "query"];
657
691
  var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built.";
658
692
  var UnsupportedPathError = class extends Error {
659
693
  };
660
694
 
661
- // node_modules/hono/dist/utils/constants.js
695
+ // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/utils/constants.js
662
696
  var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
663
697
 
664
- // node_modules/hono/dist/hono-base.js
698
+ // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/hono-base.js
665
699
  var notFoundHandler = (c) => {
666
700
  return c.text("404 Not Found", 404);
667
701
  };
@@ -680,6 +714,7 @@ var Hono = class _Hono {
680
714
  delete;
681
715
  options;
682
716
  patch;
717
+ query;
683
718
  all;
684
719
  on;
685
720
  use;
@@ -752,7 +787,7 @@ var Hono = class _Hono {
752
787
  handler = async (c, next) => (await compose([], app.errorHandler)(c, () => r.handler(c, next))).res;
753
788
  handler[COMPOSED_HANDLER] = r.handler;
754
789
  }
755
- subApp.#addRoute(r.method, r.path, handler);
790
+ subApp.#addRoute(r.method, r.path, handler, r.basePath);
756
791
  });
757
792
  return this;
758
793
  }
@@ -799,7 +834,7 @@ var Hono = class _Hono {
799
834
  const pathPrefixLength = mergedPath === "/" ? 0 : mergedPath.length;
800
835
  return (request) => {
801
836
  const url = new URL(request.url);
802
- url.pathname = url.pathname.slice(pathPrefixLength) || "/";
837
+ url.pathname = this.getPath(request).slice(pathPrefixLength) || "/";
803
838
  return new Request(url, request);
804
839
  };
805
840
  })();
@@ -813,10 +848,15 @@ var Hono = class _Hono {
813
848
  this.#addRoute(METHOD_NAME_ALL, mergePath(path, "*"), handler);
814
849
  return this;
815
850
  }
816
- #addRoute(method, path, handler) {
851
+ #addRoute(method, path, handler, baseRoutePath) {
817
852
  method = method.toUpperCase();
818
853
  path = mergePath(this._basePath, path);
819
- const r = { basePath: this._basePath, path, method, handler };
854
+ const r = {
855
+ basePath: baseRoutePath !== undefined ? mergePath(this._basePath, baseRoutePath) : this._basePath,
856
+ path,
857
+ method,
858
+ handler
859
+ };
820
860
  this.router.add(method, path, [handler, r]);
821
861
  this.routes.push(r);
822
862
  }
@@ -880,7 +920,7 @@ var Hono = class _Hono {
880
920
  };
881
921
  };
882
922
 
883
- // node_modules/hono/dist/router/reg-exp-router/matcher.js
923
+ // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/router/reg-exp-router/matcher.js
884
924
  var emptyParam = [];
885
925
  function match(method, path) {
886
926
  const matchers = this.buildAllMatchers();
@@ -901,7 +941,7 @@ function match(method, path) {
901
941
  return match2(method, path);
902
942
  }
903
943
 
904
- // node_modules/hono/dist/router/reg-exp-router/node.js
944
+ // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/router/reg-exp-router/node.js
905
945
  var LABEL_REG_EXP_STR = "[^/]+";
906
946
  var ONLY_WILDCARD_REG_EXP_STR = ".*";
907
947
  var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
@@ -915,7 +955,7 @@ function compareKey(a, b) {
915
955
  return 1;
916
956
  }
917
957
  if (a === ONLY_WILDCARD_REG_EXP_STR || a === TAIL_WILDCARD_REG_EXP_STR) {
918
- return 1;
958
+ return b === TAIL_WILDCARD_REG_EXP_STR ? -1 : 1;
919
959
  } else if (b === ONLY_WILDCARD_REG_EXP_STR || b === TAIL_WILDCARD_REG_EXP_STR) {
920
960
  return -1;
921
961
  }
@@ -930,69 +970,68 @@ var Node = class _Node {
930
970
  #index;
931
971
  #varIndex;
932
972
  #children = /* @__PURE__ */ Object.create(null);
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;
953
- }
954
- regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
955
- if (/\((?!\?:)/.test(regexpStr)) {
956
- throw PATH_ERROR;
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;
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
+ }
963
993
  }
964
- if (pathErrorCheckOnly) {
965
- return;
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;
966
1004
  }
967
- node = this.#children[regexpStr] = new _Node;
968
1005
  if (name !== "") {
969
- node.#varIndex = context.varIndex++;
970
- }
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;
1006
+ nextNode.#varIndex ??= context.varIndex++;
1007
+ paramMap.push([name, nextNode.#varIndex]);
980
1008
  }
981
- if (pathErrorCheckOnly) {
982
- return;
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;
983
1018
  }
984
- node = this.#children[token] = new _Node;
985
1019
  }
1020
+ node = nextNode;
986
1021
  }
987
- node.insert(restTokens, index, paramMap, context, pathErrorCheckOnly);
1022
+ if (node.#index !== undefined) {
1023
+ throw PATH_ERROR;
1024
+ }
1025
+ node.#index = isStatic ? -1 : index;
988
1026
  }
989
1027
  buildRegExpStr() {
990
1028
  const childKeys = Object.keys(this.#children).sort(compareKey);
991
1029
  const strList = childKeys.map((k) => {
992
1030
  const c = this.#children[k];
993
- return (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + c.buildRegExpStr();
994
- });
995
- if (typeof this.#index === "number") {
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) {
996
1035
  strList.unshift(`#${this.#index}`);
997
1036
  }
998
1037
  if (strList.length === 0) {
@@ -1005,16 +1044,23 @@ var Node = class _Node {
1005
1044
  }
1006
1045
  };
1007
1046
 
1008
- // node_modules/hono/dist/router/reg-exp-router/trie.js
1047
+ // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/router/reg-exp-router/trie.js
1009
1048
  var Trie = class {
1010
1049
  #context = { varIndex: 0 };
1011
1050
  #root = new Node;
1012
- insert(path, index, pathErrorCheckOnly) {
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
+ }
1013
1058
  const paramAssoc = [];
1014
1059
  const groups = [];
1060
+ let markedPath = path;
1015
1061
  for (let i = 0;; ) {
1016
1062
  let replaced = false;
1017
- path = path.replace(/\{[^}]+\}/g, (m) => {
1063
+ markedPath = markedPath.replace(/\{[^}]+\}/g, (m) => {
1018
1064
  const mark = `@\\${i}`;
1019
1065
  groups[i] = [mark, m];
1020
1066
  i++;
@@ -1025,7 +1071,7 @@ var Trie = class {
1025
1071
  break;
1026
1072
  }
1027
1073
  }
1028
- const tokens = path.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
1074
+ const tokens = markedPath.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
1029
1075
  for (let i = groups.length - 1;i >= 0; i--) {
1030
1076
  const [mark] = groups[i];
1031
1077
  for (let j = tokens.length - 1;j >= 0; j--) {
@@ -1035,8 +1081,8 @@ var Trie = class {
1035
1081
  }
1036
1082
  }
1037
1083
  }
1038
- this.#root.insert(tokens, index, paramAssoc, this.#context, pathErrorCheckOnly);
1039
- return paramAssoc;
1084
+ this.#root.insert(tokens, this.#index, paramAssoc, this.#context, false);
1085
+ this.paths[path] = [this.#index++, paramAssoc];
1040
1086
  }
1041
1087
  buildRegExp() {
1042
1088
  let regexp = this.#root.buildRegExpStr();
@@ -1061,8 +1107,7 @@ var Trie = class {
1061
1107
  }
1062
1108
  };
1063
1109
 
1064
- // node_modules/hono/dist/router/reg-exp-router/router.js
1065
- var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)];
1110
+ // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/router/reg-exp-router/router.js
1066
1111
  var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
1067
1112
  function buildWildcardRegExp(path) {
1068
1113
  return wildcardRegExpCache[path] ??= new RegExp(path === "*" ? "" : `^${path.replace(/\/\*$|([.\\+*[^\]$()])/g, (_, metaChar) => metaChar ? `\\${metaChar}` : "(?:|/.*)")}$`);
@@ -1070,59 +1115,6 @@ function buildWildcardRegExp(path) {
1070
1115
  function clearWildcardRegExpCache() {
1071
1116
  wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
1072
1117
  }
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
- }
1126
1118
  function findMiddleware(middleware, path) {
1127
1119
  if (!middleware) {
1128
1120
  return;
@@ -1138,9 +1130,18 @@ var RegExpRouter = class {
1138
1130
  name = "RegExpRouter";
1139
1131
  #middleware;
1140
1132
  #routes;
1133
+ #tries;
1141
1134
  constructor() {
1142
1135
  this.#middleware = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
1143
1136
  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
+ }
1144
1145
  }
1145
1146
  add(method, path, handler) {
1146
1147
  const middleware = this.#middleware;
@@ -1149,10 +1150,12 @@ var RegExpRouter = class {
1149
1150
  throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
1150
1151
  }
1151
1152
  if (!middleware[method]) {
1153
+ this.#tries[method] = new Trie;
1152
1154
  [middleware, routes].forEach((handlerMap) => {
1153
1155
  handlerMap[method] = /* @__PURE__ */ Object.create(null);
1154
1156
  Object.keys(handlerMap[METHOD_NAME_ALL]).forEach((p) => {
1155
1157
  handlerMap[method][p] = [...handlerMap[METHOD_NAME_ALL][p]];
1158
+ this.#insertPath(method, p);
1156
1159
  });
1157
1160
  });
1158
1161
  }
@@ -1162,13 +1165,12 @@ var RegExpRouter = class {
1162
1165
  const paramCount = (path.match(/\/:/g) || []).length;
1163
1166
  if (/\*$/.test(path)) {
1164
1167
  const re = buildWildcardRegExp(path);
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
- }
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
+ });
1172
1174
  Object.keys(middleware).forEach((m) => {
1173
1175
  if (method === METHOD_NAME_ALL || method === m) {
1174
1176
  Object.keys(middleware[m]).forEach((p) => {
@@ -1188,9 +1190,12 @@ var RegExpRouter = class {
1188
1190
  const path2 = paths[i];
1189
1191
  Object.keys(routes).forEach((m) => {
1190
1192
  if (method === METHOD_NAME_ALL || method === m) {
1191
- routes[m][path2] ||= [
1192
- ...findMiddleware(middleware[m], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || []
1193
- ];
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
+ }
1194
1199
  routes[m][path2].push([handler, paramCount - len + i + 1]);
1195
1200
  }
1196
1201
  });
@@ -1202,31 +1207,58 @@ var RegExpRouter = class {
1202
1207
  Object.keys(this.#routes).concat(Object.keys(this.#middleware)).forEach((method) => {
1203
1208
  matchers[method] ||= this.#buildMatcher(method);
1204
1209
  });
1205
- this.#middleware = this.#routes = undefined;
1210
+ this.#middleware = this.#routes = this.#tries = undefined;
1206
1211
  clearWildcardRegExpCache();
1207
1212
  return matchers;
1208
1213
  }
1209
1214
  #buildMatcher(method) {
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]]));
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
+ });
1219
1238
  }
1220
1239
  });
1221
- if (!hasOwnRoute) {
1222
- return null;
1223
- } else {
1224
- return buildMatcherFromPreprocessedRoutes(routes);
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
+ }
1225
1252
  }
1253
+ const handlerMap = [];
1254
+ for (const i in indexReplacementMap) {
1255
+ handlerMap[i] = handlerData[indexReplacementMap[i]];
1256
+ }
1257
+ return [regexp, handlerMap, staticMap];
1226
1258
  }
1227
1259
  };
1228
1260
 
1229
- // node_modules/hono/dist/router/reg-exp-router/prepared-router.js
1261
+ // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/router/reg-exp-router/prepared-router.js
1230
1262
  var PreparedRegExpRouter = class {
1231
1263
  name = "PreparedRegExpRouter";
1232
1264
  #matchers;
@@ -1298,7 +1330,7 @@ var PreparedRegExpRouter = class {
1298
1330
  match = match;
1299
1331
  };
1300
1332
 
1301
- // node_modules/hono/dist/router/smart-router/router.js
1333
+ // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/router/smart-router/router.js
1302
1334
  var SmartRouter = class {
1303
1335
  name = "SmartRouter";
1304
1336
  #routers = [];
@@ -1353,7 +1385,7 @@ var SmartRouter = class {
1353
1385
  }
1354
1386
  };
1355
1387
 
1356
- // node_modules/hono/dist/router/trie-router/node.js
1388
+ // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/router/trie-router/node.js
1357
1389
  var emptyParams = /* @__PURE__ */ Object.create(null);
1358
1390
  var hasChildren = (children) => {
1359
1391
  for (const _ in children) {
@@ -1487,9 +1519,12 @@ var Node2 = class _Node2 {
1487
1519
  if (m) {
1488
1520
  params[name] = m[0];
1489
1521
  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
+ }
1490
1525
  if (hasChildren(child.#children)) {
1491
1526
  child.#params = params;
1492
- const componentCount = m[0].match(/\//)?.length ?? 0;
1527
+ const componentCount = m[0].match(/\//g)?.length ?? 0;
1493
1528
  const targetCurNodes = curNodesQueue[componentCount] ||= [];
1494
1529
  targetCurNodes.push(child);
1495
1530
  }
@@ -1522,7 +1557,7 @@ var Node2 = class _Node2 {
1522
1557
  }
1523
1558
  };
1524
1559
 
1525
- // node_modules/hono/dist/router/trie-router/router.js
1560
+ // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/router/trie-router/router.js
1526
1561
  var TrieRouter = class {
1527
1562
  name = "TrieRouter";
1528
1563
  #node;
@@ -1544,7 +1579,7 @@ var TrieRouter = class {
1544
1579
  }
1545
1580
  };
1546
1581
 
1547
- // node_modules/hono/dist/hono.js
1582
+ // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/hono.js
1548
1583
  var Hono2 = class extends Hono {
1549
1584
  constructor(options = {}) {
1550
1585
  super(options);
@@ -1554,24 +1589,18 @@ var Hono2 = class extends Hono {
1554
1589
  }
1555
1590
  };
1556
1591
 
1557
- // node_modules/hono/dist/middleware/cors/index.js
1592
+ // ../../node_modules/.bun/hono@4.13.1/node_modules/hono/dist/middleware/cors/index.js
1558
1593
  var cors = (options) => {
1559
- const defaults = {
1594
+ const opts = {
1560
1595
  origin: "*",
1561
- allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"],
1596
+ allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH", "QUERY"],
1562
1597
  allowHeaders: [],
1563
- exposeHeaders: []
1564
- };
1565
- const opts = {
1566
- ...defaults,
1598
+ exposeHeaders: [],
1567
1599
  ...options
1568
1600
  };
1569
1601
  const findAllowOrigin = ((optsOrigin) => {
1570
1602
  if (typeof optsOrigin === "string") {
1571
1603
  if (optsOrigin === "*") {
1572
- if (opts.credentials) {
1573
- return (origin) => origin || null;
1574
- }
1575
1604
  return () => optsOrigin;
1576
1605
  } else {
1577
1606
  return (origin) => optsOrigin === origin ? origin : null;
@@ -1606,7 +1635,7 @@ var cors = (options) => {
1606
1635
  set("Access-Control-Expose-Headers", opts.exposeHeaders.join(","));
1607
1636
  }
1608
1637
  if (c.req.method === "OPTIONS") {
1609
- if (opts.origin !== "*" || opts.credentials) {
1638
+ if (opts.origin !== "*") {
1610
1639
  set("Vary", "Origin");
1611
1640
  }
1612
1641
  if (opts.maxAge != null) {
@@ -1620,7 +1649,7 @@ var cors = (options) => {
1620
1649
  if (!headers?.length) {
1621
1650
  const requestHeaders = c.req.header("Access-Control-Request-Headers");
1622
1651
  if (requestHeaders) {
1623
- headers = requestHeaders.split(/\s*,\s*/);
1652
+ headers = requestHeaders.split(",").map((h) => h.trim());
1624
1653
  }
1625
1654
  }
1626
1655
  if (headers?.length) {
@@ -1636,7 +1665,7 @@ var cors = (options) => {
1636
1665
  });
1637
1666
  }
1638
1667
  await next();
1639
- if (opts.origin !== "*" || opts.credentials) {
1668
+ if (opts.origin !== "*") {
1640
1669
  c.header("Vary", "Origin", { append: true });
1641
1670
  }
1642
1671
  };
@@ -1715,7 +1744,7 @@ class ProfileNotFoundError extends Error {
1715
1744
  }
1716
1745
  }
1717
1746
 
1718
- // node_modules/@hasna/contracts/dist/auth/index.js
1747
+ // ../../node_modules/.bun/@hasna+contracts@0.4.2/node_modules/@hasna/contracts/dist/auth/index.js
1719
1748
  import { createHash, createHmac, randomBytes, timingSafeEqual } from "crypto";
1720
1749
  var API_KEY_TOKEN_VERSION = 1;
1721
1750
  var API_KEY_NAMESPACE = "hasna";
@@ -2082,53 +2111,152 @@ function honoApiKey(options) {
2082
2111
  return c.json({ error: decision.message, reason: decision.reason }, decision.status);
2083
2112
  };
2084
2113
  }
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
+ }
2085
2130
  // src/generated/storage-kit/tls.ts
2086
2131
  import { readFileSync as readFileSync2 } from "fs";
2087
- function sslModeFromConnectionString(connectionString) {
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) {
2088
2153
  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))
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
+ 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")
2107
2214
  return "require";
2108
2215
  return "disable";
2109
2216
  }
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;
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");
2115
2224
  if (path && path.trim())
2116
2225
  return readFileSync2(path.trim(), "utf8");
2117
2226
  return null;
2118
2227
  }
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
+ }
2119
2242
  function resolveTlsConfig(connectionString, options = {}) {
2120
2243
  const mode = sslModeFromConnectionString(connectionString);
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 };
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 };
2127
2255
  }
2128
2256
  if (!ca) {
2129
2257
  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`);
2130
2258
  }
2131
- return { rejectUnauthorized: true, ca };
2259
+ return { rejectUnauthorized: true, ca, ...clientCertificate };
2132
2260
  }
2133
2261
  // src/generated/storage-kit/query.ts
2134
2262
  function wrapExecutor(executor) {
@@ -2185,23 +2313,58 @@ function createQueryClient(pool) {
2185
2313
  }
2186
2314
  // src/generated/storage-kit/pool.ts
2187
2315
  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
+ }
2188
2341
  function createPgPool(options) {
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 } : {}
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 } : {}
2193
2351
  });
2194
- const config = { connectionString: options.connectionString };
2352
+ const config = {
2353
+ connectionString: connectionStringWithoutTlsParameters(connectionString)
2354
+ };
2195
2355
  if (ssl !== undefined)
2196
2356
  config.ssl = ssl;
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;
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;
2205
2368
  return new pg.Pool(config);
2206
2369
  }
2207
2370
  // src/storage/schema.ts
@@ -2282,15 +2445,37 @@ function instructionsSchemaSql() {
2282
2445
  ];
2283
2446
  }
2284
2447
 
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
+
2285
2469
  // src/server/cloud.ts
2286
2470
  var INSTRUCTIONS_APP_SLUG = "instructions";
2287
2471
  function resolveCloudDatabaseUrl(env = process.env) {
2472
+ assertNoLegacyStorageMode(env);
2288
2473
  return env.HASNA_INSTRUCTIONS_DATABASE_URL || env.INSTRUCTIONS_DATABASE_URL || env.DATABASE_URL || undefined;
2289
2474
  }
2290
2475
  function resolveSigningSecret(env = process.env) {
2291
2476
  return env.HASNA_INSTRUCTIONS_API_SIGNING_KEY || env.HASNA_API_SIGNING_KEY || env.API_KEY_SIGNING_SECRET || undefined;
2292
2477
  }
2293
- function isCloudModeEnabled(env = process.env) {
2478
+ function isPostgresBackendEnabled(env = process.env) {
2294
2479
  return Boolean(resolveCloudDatabaseUrl(env));
2295
2480
  }
2296
2481
  var cachedClient = null;
@@ -2748,7 +2933,7 @@ Policy reference: \`${CODEWITH_SHARED_TODOS_STORAGE_POLICY_REFERENCE}\`
2748
2933
  // src/lib/project-context.ts
2749
2934
  import { basename, dirname as dirname2, isAbsolute, join as join2, parse, relative, resolve } from "path";
2750
2935
 
2751
- // node_modules/zod/v3/external.js
2936
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/external.js
2752
2937
  var exports_external = {};
2753
2938
  __export(exports_external, {
2754
2939
  void: () => voidType,
@@ -2860,7 +3045,7 @@ __export(exports_external, {
2860
3045
  BRAND: () => BRAND
2861
3046
  });
2862
3047
 
2863
- // node_modules/zod/v3/helpers/util.js
3048
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/util.js
2864
3049
  var util;
2865
3050
  (function(util2) {
2866
3051
  util2.assertEqual = (_) => {};
@@ -2991,7 +3176,7 @@ var getParsedType = (data) => {
2991
3176
  }
2992
3177
  };
2993
3178
 
2994
- // node_modules/zod/v3/ZodError.js
3179
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/ZodError.js
2995
3180
  var ZodIssueCode = util.arrayToEnum([
2996
3181
  "invalid_type",
2997
3182
  "invalid_literal",
@@ -3110,7 +3295,7 @@ ZodError.create = (issues) => {
3110
3295
  return error;
3111
3296
  };
3112
3297
 
3113
- // node_modules/zod/v3/locales/en.js
3298
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/locales/en.js
3114
3299
  var errorMap = (issue, _ctx) => {
3115
3300
  let message;
3116
3301
  switch (issue.code) {
@@ -3213,7 +3398,7 @@ var errorMap = (issue, _ctx) => {
3213
3398
  };
3214
3399
  var en_default = errorMap;
3215
3400
 
3216
- // node_modules/zod/v3/errors.js
3401
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/errors.js
3217
3402
  var overrideErrorMap = en_default;
3218
3403
  function setErrorMap(map) {
3219
3404
  overrideErrorMap = map;
@@ -3221,7 +3406,7 @@ function setErrorMap(map) {
3221
3406
  function getErrorMap() {
3222
3407
  return overrideErrorMap;
3223
3408
  }
3224
- // node_modules/zod/v3/helpers/parseUtil.js
3409
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js
3225
3410
  var makeIssue = (params) => {
3226
3411
  const { data, path, errorMaps, issueData } = params;
3227
3412
  const fullPath = [...path, ...issueData.path || []];
@@ -3327,14 +3512,14 @@ var isAborted = (x) => x.status === "aborted";
3327
3512
  var isDirty = (x) => x.status === "dirty";
3328
3513
  var isValid = (x) => x.status === "valid";
3329
3514
  var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
3330
- // node_modules/zod/v3/helpers/errorUtil.js
3515
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js
3331
3516
  var errorUtil;
3332
3517
  (function(errorUtil2) {
3333
3518
  errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
3334
3519
  errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
3335
3520
  })(errorUtil || (errorUtil = {}));
3336
3521
 
3337
- // node_modules/zod/v3/types.js
3522
+ // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/types.js
3338
3523
  class ParseInputLazyPath {
3339
3524
  constructor(parent, value, path, key) {
3340
3525
  this._cachedPath = [];
@@ -7257,15 +7442,15 @@ function normalizeActivation(value) {
7257
7442
  if (!INSTRUCTION_ACTIVATION_MODES.includes(record["mode"])) {
7258
7443
  throw new Error(`Invalid instruction activation mode: ${String(record["mode"])}`);
7259
7444
  }
7260
- const mode2 = record["mode"];
7445
+ const mode = record["mode"];
7261
7446
  const globs = stringArray(record["globs"], "activation.globs");
7262
7447
  const models = stringArray(record["models"], "activation.models");
7263
- if (mode2 === "glob" && (!globs || globs.length === 0))
7448
+ if (mode === "glob" && (!globs || globs.length === 0))
7264
7449
  throw new Error("Glob activation requires at least one glob.");
7265
- if (mode2 === "model" && (!models || models.length === 0))
7450
+ if (mode === "model" && (!models || models.length === 0))
7266
7451
  throw new Error("Model activation requires at least one model.");
7267
7452
  return {
7268
- mode: mode2,
7453
+ mode,
7269
7454
  ...globs ? { globs } : {},
7270
7455
  ...models ? { models } : {},
7271
7456
  ...optionalString(record["description"], "activation.description") ? { description: record["description"] } : {},
@@ -8655,22 +8840,22 @@ if (process.argv.includes("--version") || process.argv.includes("-V")) {
8655
8840
  var PORT = Number(process.env["PORT"] ?? process.env["INSTRUCTIONS_PORT"] ?? 3457);
8656
8841
  var app = new Hono2;
8657
8842
  app.use("*", cors());
8658
- function serviceMode() {
8659
- return isCloudModeEnabled() ? "cloud" : "local";
8843
+ function serviceBackend() {
8844
+ return isPostgresBackendEnabled() ? "postgresql" : "sqlite";
8660
8845
  }
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" }));
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" }));
8663
8848
  app.get("/ready", async (c) => {
8664
8849
  const version = getPackageVersion();
8665
- const mode2 = serviceMode();
8666
- if (mode2 === "cloud") {
8850
+ const backend2 = serviceBackend();
8851
+ if (backend2 === "postgresql") {
8667
8852
  try {
8668
8853
  await pingCloud();
8669
8854
  } catch (e) {
8670
- return c.json({ status: "unavailable", version, mode: mode2, error: e.message }, 503);
8855
+ return c.json({ status: "unavailable", version, backend: backend2, error: e.message }, 503);
8671
8856
  }
8672
8857
  }
8673
- return c.json({ status: "ready", version, mode: mode2 });
8858
+ return c.json({ status: "ready", version, backend: backend2 });
8674
8859
  });
8675
8860
  app.get("/openapi.json", (c) => c.json(buildV1OpenApiDocument()));
8676
8861
  app.get("/v1/openapi.json", (c) => c.json(buildV1OpenApiDocument()));
@@ -8722,7 +8907,7 @@ if (dashDir) {
8722
8907
  });
8723
8908
  }
8724
8909
  var HOST = process.env["HOST"] ?? process.env["INSTRUCTIONS_HOST"] ?? "localhost";
8725
- console.log(`instructions-serve listening on http://${HOST}:${PORT} (mode: ${serviceMode()})${dashDir ? " (dashboard: /)" : " (no dashboard)"}`);
8910
+ console.log(`instructions-serve listening on http://${HOST}:${PORT} (backend: ${serviceBackend()})${dashDir ? " (dashboard: /)" : " (no dashboard)"}`);
8726
8911
  var server_default = { port: PORT, hostname: HOST, fetch: app.fetch };
8727
8912
  export {
8728
8913
  server_default as default