@blotout/qinto-cli 0.1.15 → 0.1.16

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.
@@ -1,7 +1,7 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value2) => __defProp(target, "name", { value: value2, configurable: true });
3
3
 
4
- // ../../node_modules/.pnpm/hono@4.12.28/node_modules/hono/dist/compose.js
4
+ // ../../node_modules/.pnpm/hono@4.13.5/node_modules/hono/dist/compose.js
5
5
  var compose = /* @__PURE__ */ __name((middleware, onError, onNotFound) => {
6
6
  return (context, next) => {
7
7
  let index = -1;
@@ -46,10 +46,10 @@ var compose = /* @__PURE__ */ __name((middleware, onError, onNotFound) => {
46
46
  };
47
47
  }, "compose");
48
48
 
49
- // ../../node_modules/.pnpm/hono@4.12.28/node_modules/hono/dist/request/constants.js
49
+ // ../../node_modules/.pnpm/hono@4.13.5/node_modules/hono/dist/request/constants.js
50
50
  var GET_MATCH_RESULT = /* @__PURE__ */ Symbol();
51
51
 
52
- // ../../node_modules/.pnpm/hono@4.12.28/node_modules/hono/dist/utils/buffer.js
52
+ // ../../node_modules/.pnpm/hono@4.13.5/node_modules/hono/dist/utils/buffer.js
53
53
  var bufferToFormData = /* @__PURE__ */ __name((arrayBuffer, contentType) => {
54
54
  const response = new Response(arrayBuffer, {
55
55
  headers: {
@@ -60,7 +60,9 @@ var bufferToFormData = /* @__PURE__ */ __name((arrayBuffer, contentType) => {
60
60
  return response.formData();
61
61
  }, "bufferToFormData");
62
62
 
63
- // ../../node_modules/.pnpm/hono@4.12.28/node_modules/hono/dist/utils/body.js
63
+ // ../../node_modules/.pnpm/hono@4.13.5/node_modules/hono/dist/utils/body.js
64
+ var MAX_NESTING_DEPTH = 32;
65
+ var MAX_NESTED_OBJECTS = 1e4;
64
66
  var isRawRequest = /* @__PURE__ */ __name((request) => "headers" in request, "isRawRequest");
65
67
  var parseBody = /* @__PURE__ */ __name(async (request, options = /* @__PURE__ */ Object.create(null)) => {
66
68
  const { all = false, dot = false } = options;
@@ -73,6 +75,12 @@ var parseBody = /* @__PURE__ */ __name(async (request, options = /* @__PURE__ */
73
75
  return {};
74
76
  }, "parseBody");
75
77
  async function parseFormData(request, options) {
78
+ if (!isRawRequest(request) && request.bodyCache.formData) {
79
+ return convertFormDataToBodyData(
80
+ await request.bodyCache.formData,
81
+ options
82
+ );
83
+ }
76
84
  const headers = isRawRequest(request) ? request.headers : request.raw.headers;
77
85
  const arrayBuffer = await request.arrayBuffer();
78
86
  const formDataPromise = bufferToFormData(arrayBuffer, headers.get("Content-Type") || "");
@@ -88,6 +96,7 @@ async function parseFormData(request, options) {
88
96
  __name(parseFormData, "parseFormData");
89
97
  function convertFormDataToBodyData(formData, options) {
90
98
  const form = /* @__PURE__ */ Object.create(null);
99
+ const nestingState = { count: 0 };
91
100
  formData.forEach((value2, key) => {
92
101
  const shouldParseAllValues = options.all || key.endsWith("[]");
93
102
  if (!shouldParseAllValues) {
@@ -100,7 +109,7 @@ function convertFormDataToBodyData(formData, options) {
100
109
  Object.entries(form).forEach(([key, value2]) => {
101
110
  const shouldParseDotValues = key.includes(".");
102
111
  if (shouldParseDotValues) {
103
- handleParsingNestedValues(form, key, value2);
112
+ handleParsingNestedValues(form, key, value2, nestingState);
104
113
  delete form[key];
105
114
  }
106
115
  });
@@ -124,25 +133,34 @@ var handleParsingAllValues = /* @__PURE__ */ __name((form, key, value2) => {
124
133
  }
125
134
  }
126
135
  }, "handleParsingAllValues");
127
- var handleParsingNestedValues = /* @__PURE__ */ __name((form, key, value2) => {
136
+ var handleParsingNestedValues = /* @__PURE__ */ __name((form, key, value2, state) => {
128
137
  if (/(?:^|\.)__proto__\./.test(key)) {
129
138
  return;
130
139
  }
131
140
  let nestedForm = form;
132
- const keys = key.split(".");
141
+ const keys = key.split(".", MAX_NESTING_DEPTH + 2);
142
+ if (keys.length > MAX_NESTING_DEPTH + 1) {
143
+ throwNestingLimitExceeded();
144
+ }
133
145
  keys.forEach((key2, index) => {
134
146
  if (index === keys.length - 1) {
135
147
  nestedForm[key2] = value2;
136
148
  } else {
137
149
  if (!nestedForm[key2] || typeof nestedForm[key2] !== "object" || Array.isArray(nestedForm[key2]) || nestedForm[key2] instanceof File) {
150
+ if (state.count++ >= MAX_NESTED_OBJECTS) {
151
+ throwNestingLimitExceeded();
152
+ }
138
153
  nestedForm[key2] = /* @__PURE__ */ Object.create(null);
139
154
  }
140
155
  nestedForm = nestedForm[key2];
141
156
  }
142
157
  });
143
158
  }, "handleParsingNestedValues");
159
+ var throwNestingLimitExceeded = /* @__PURE__ */ __name(() => {
160
+ throw new Error("Nesting limit exceeded");
161
+ }, "throwNestingLimitExceeded");
144
162
 
145
- // ../../node_modules/.pnpm/hono@4.12.28/node_modules/hono/dist/utils/url.js
163
+ // ../../node_modules/.pnpm/hono@4.13.5/node_modules/hono/dist/utils/url.js
146
164
  var splitPath = /* @__PURE__ */ __name((path) => {
147
165
  const paths = path.split("/");
148
166
  if (paths[0] === "") {
@@ -248,13 +266,13 @@ var checkOptionalParameter = /* @__PURE__ */ __name((path) => {
248
266
  if (segment !== "" && !/\:/.test(segment)) {
249
267
  basePath += "/" + segment;
250
268
  } else if (/\:/.test(segment)) {
251
- if (/\?/.test(segment)) {
269
+ if (segment.charCodeAt(segment.length - 1) === 63) {
252
270
  if (results.length === 0 && basePath === "") {
253
271
  results.push("/");
254
272
  } else {
255
273
  results.push(basePath);
256
274
  }
257
- const optionalSegment = segment.replace("?", "");
275
+ const optionalSegment = segment.slice(0, -1);
258
276
  basePath += "/" + optionalSegment;
259
277
  results.push(basePath);
260
278
  } else {
@@ -264,18 +282,20 @@ var checkOptionalParameter = /* @__PURE__ */ __name((path) => {
264
282
  });
265
283
  return results.filter((v, i, a) => a.indexOf(v) === i);
266
284
  }, "checkOptionalParameter");
285
+ var tryDecodeURIComponent = /* @__PURE__ */ __name((str) => str.indexOf("%") !== -1 ? tryDecode(str, decodeURIComponent_) : str, "tryDecodeURIComponent");
267
286
  var _decodeURI = /* @__PURE__ */ __name((value2) => {
268
- if (!/[%+]/.test(value2)) {
269
- return value2;
270
- }
271
287
  if (value2.indexOf("+") !== -1) {
272
288
  value2 = value2.replace(/\+/g, " ");
273
289
  }
274
- return value2.indexOf("%") !== -1 ? tryDecode(value2, decodeURIComponent_) : value2;
290
+ return tryDecodeURIComponent(value2);
275
291
  }, "_decodeURI");
276
292
  var _getQueryParam = /* @__PURE__ */ __name((url, key, multiple) => {
293
+ const hashIndex = url.indexOf("#", 8);
294
+ if (hashIndex !== -1) {
295
+ url = url.slice(0, hashIndex);
296
+ }
277
297
  let encoded;
278
- if (!multiple && key && !/[%+]/.test(key)) {
298
+ if (!multiple && key && key.indexOf("%") === -1 && key.indexOf("+") === -1) {
279
299
  let keyIndex2 = url.indexOf("?", 8);
280
300
  if (keyIndex2 === -1) {
281
301
  return void 0;
@@ -299,7 +319,7 @@ var _getQueryParam = /* @__PURE__ */ __name((url, key, multiple) => {
299
319
  return void 0;
300
320
  }
301
321
  }
302
- const results = {};
322
+ const results = /* @__PURE__ */ Object.create(null);
303
323
  encoded ??= /[%+]/.test(url);
304
324
  let keyIndex = url.indexOf("?", 8);
305
325
  while (keyIndex !== -1) {
@@ -346,8 +366,7 @@ var getQueryParams = /* @__PURE__ */ __name((url, key) => {
346
366
  }, "getQueryParams");
347
367
  var decodeURIComponent_ = decodeURIComponent;
348
368
 
349
- // ../../node_modules/.pnpm/hono@4.12.28/node_modules/hono/dist/request.js
350
- var tryDecodeURIComponent = /* @__PURE__ */ __name((str) => tryDecode(str, decodeURIComponent_), "tryDecodeURIComponent");
369
+ // ../../node_modules/.pnpm/hono@4.13.5/node_modules/hono/dist/request.js
351
370
  var HonoRequest = class {
352
371
  static {
353
372
  __name(this, "HonoRequest");
@@ -389,23 +408,22 @@ var HonoRequest = class {
389
408
  this.raw = request;
390
409
  this.path = path;
391
410
  this.#matchResult = matchResult;
392
- this.#validatedData = {};
393
411
  }
394
412
  param(key) {
395
413
  return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams();
396
414
  }
397
415
  #getDecodedParam(key) {
398
- const paramKey = this.#matchResult[0][this.routeIndex][1][key];
416
+ const paramKey = this.#matchResult[0][this.routeIndex]?.[1][key];
399
417
  const param = this.#getParamValue(paramKey);
400
- return param && /\%/.test(param) ? tryDecodeURIComponent(param) : param;
418
+ return param && tryDecodeURIComponent(param);
401
419
  }
402
420
  #getAllDecodedParams() {
403
421
  const decoded = {};
404
- const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]);
422
+ const keys = Object.keys(this.#matchResult[0][this.routeIndex]?.[1] ?? {});
405
423
  for (const key of keys) {
406
424
  const value2 = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
407
425
  if (value2 !== void 0) {
408
- decoded[key] = /\%/.test(value2) ? tryDecodeURIComponent(value2) : value2;
426
+ decoded[key] = tryDecodeURIComponent(value2);
409
427
  }
410
428
  }
411
429
  return decoded;
@@ -423,7 +441,7 @@ var HonoRequest = class {
423
441
  if (name) {
424
442
  return this.raw.headers.get(name) ?? void 0;
425
443
  }
426
- const headerData = {};
444
+ const headerData = /* @__PURE__ */ Object.create(null);
427
445
  this.raw.headers.forEach((value2, key) => {
428
446
  headerData[key] = value2;
429
447
  });
@@ -438,8 +456,7 @@ var HonoRequest = class {
438
456
  if (cachedBody) {
439
457
  return cachedBody;
440
458
  }
441
- const anyCachedKey = Object.keys(bodyCache)[0];
442
- if (anyCachedKey) {
459
+ for (const anyCachedKey in bodyCache) {
443
460
  return bodyCache[anyCachedKey].then((body) => {
444
461
  if (anyCachedKey === "json") {
445
462
  body = JSON.stringify(body);
@@ -542,10 +559,11 @@ var HonoRequest = class {
542
559
  * @param data - The validated data to add.
543
560
  */
544
561
  addValidatedData(target, data) {
545
- this.#validatedData[target] = data;
562
+ ;
563
+ (this.#validatedData ??= {})[target] = data;
546
564
  }
547
565
  valid(target) {
548
- return this.#validatedData[target];
566
+ return this.#validatedData?.[target];
549
567
  }
550
568
  /**
551
569
  * `.url()` can get the request url strings.
@@ -632,7 +650,7 @@ var HonoRequest = class {
632
650
  }
633
651
  };
634
652
 
635
- // ../../node_modules/.pnpm/hono@4.12.28/node_modules/hono/dist/utils/html.js
653
+ // ../../node_modules/.pnpm/hono@4.13.5/node_modules/hono/dist/utils/html.js
636
654
  var HtmlEscapedCallbackPhase = {
637
655
  Stringify: 1,
638
656
  BeforeStream: 2,
@@ -674,7 +692,7 @@ var resolveCallback = /* @__PURE__ */ __name(async (str, phase, preserveCallback
674
692
  }
675
693
  }, "resolveCallback");
676
694
 
677
- // ../../node_modules/.pnpm/hono@4.12.28/node_modules/hono/dist/context.js
695
+ // ../../node_modules/.pnpm/hono@4.13.5/node_modules/hono/dist/context.js
678
696
  var TEXT_PLAIN = "text/plain; charset=UTF-8";
679
697
  var setDefaultContentType = /* @__PURE__ */ __name((contentType, headers) => {
680
698
  return {
@@ -879,6 +897,10 @@ var Context = class {
879
897
  * c.header('X-Message', 'Hello!')
880
898
  * c.header('Content-Type', 'text/plain')
881
899
  *
900
+ * // Append multiple headers using the append option (e.g. Vary)
901
+ * c.header('Vary', 'Accept-Encoding', { append: true })
902
+ * c.header('Vary', 'User-Agent', { append: true })
903
+ *
882
904
  * return c.body('Thank you for coming')
883
905
  * })
884
906
  * ```
@@ -950,11 +972,11 @@ var Context = class {
950
972
  return Object.fromEntries(this.#var);
951
973
  }
952
974
  #newResponse(data, arg, headers) {
953
- const responseHeaders = this.#res ? new Headers(this.#res.headers) : this.#preparedHeaders ?? new Headers();
954
- if (typeof arg === "object" && "headers" in arg) {
955
- const argHeaders = arg.headers instanceof Headers ? arg.headers : new Headers(arg.headers);
956
- for (const [key, value2] of argHeaders) {
957
- if (key.toLowerCase() === "set-cookie") {
975
+ let responseHeaders = this.#res ? new Headers(this.#res.headers) : this.#preparedHeaders;
976
+ if (typeof arg === "object" && arg.headers) {
977
+ responseHeaders ??= new Headers();
978
+ for (const [key, value2] of new Headers(arg.headers)) {
979
+ if (key === "set-cookie") {
958
980
  responseHeaders.append(key, value2);
959
981
  } else {
960
982
  responseHeaders.set(key, value2);
@@ -962,19 +984,34 @@ var Context = class {
962
984
  }
963
985
  }
964
986
  if (headers) {
965
- for (const [k, v] of Object.entries(headers)) {
966
- if (typeof v === "string") {
967
- responseHeaders.set(k, v);
968
- } else {
969
- responseHeaders.delete(k);
970
- for (const v2 of v) {
971
- responseHeaders.append(k, v2);
987
+ if (!responseHeaders) {
988
+ let count = 0;
989
+ for (const k in headers) {
990
+ if (++count > 1 || typeof headers[k] !== "string") {
991
+ responseHeaders = new Headers();
992
+ break;
993
+ }
994
+ }
995
+ }
996
+ if (responseHeaders) {
997
+ for (const k in headers) {
998
+ const v = headers[k];
999
+ if (typeof v === "string") {
1000
+ responseHeaders.set(k, v);
1001
+ } else {
1002
+ responseHeaders.delete(k);
1003
+ for (const v2 of v) {
1004
+ responseHeaders.append(k, v2);
1005
+ }
972
1006
  }
973
1007
  }
974
1008
  }
975
1009
  }
976
1010
  const status = typeof arg === "number" ? arg : arg?.status ?? this.#status;
977
- return createResponseInstance(data, { status, headers: responseHeaders });
1011
+ return createResponseInstance(data, {
1012
+ status,
1013
+ headers: responseHeaders ?? headers
1014
+ });
978
1015
  }
979
1016
  newResponse = /* @__PURE__ */ __name((...args) => this.#newResponse(...args), "newResponse");
980
1017
  /**
@@ -1084,10 +1121,10 @@ var Context = class {
1084
1121
  }, "notFound");
1085
1122
  };
1086
1123
 
1087
- // ../../node_modules/.pnpm/hono@4.12.28/node_modules/hono/dist/router.js
1124
+ // ../../node_modules/.pnpm/hono@4.13.5/node_modules/hono/dist/router.js
1088
1125
  var METHOD_NAME_ALL = "ALL";
1089
1126
  var METHOD_NAME_ALL_LOWERCASE = "all";
1090
- var METHODS = ["get", "post", "put", "delete", "options", "patch"];
1127
+ var METHODS = ["get", "post", "put", "delete", "options", "patch", "query"];
1091
1128
  var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built.";
1092
1129
  var UnsupportedPathError = class extends Error {
1093
1130
  static {
@@ -1095,10 +1132,10 @@ var UnsupportedPathError = class extends Error {
1095
1132
  }
1096
1133
  };
1097
1134
 
1098
- // ../../node_modules/.pnpm/hono@4.12.28/node_modules/hono/dist/utils/constants.js
1135
+ // ../../node_modules/.pnpm/hono@4.13.5/node_modules/hono/dist/utils/constants.js
1099
1136
  var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
1100
1137
 
1101
- // ../../node_modules/.pnpm/hono@4.12.28/node_modules/hono/dist/hono-base.js
1138
+ // ../../node_modules/.pnpm/hono@4.13.5/node_modules/hono/dist/hono-base.js
1102
1139
  var notFoundHandler = /* @__PURE__ */ __name((c) => {
1103
1140
  return c.text("404 Not Found", 404);
1104
1141
  }, "notFoundHandler");
@@ -1120,6 +1157,7 @@ var Hono = class _Hono {
1120
1157
  delete;
1121
1158
  options;
1122
1159
  patch;
1160
+ query;
1123
1161
  all;
1124
1162
  on;
1125
1163
  use;
@@ -1419,8 +1457,8 @@ var Hono = class _Hono {
1419
1457
  * @see {@link https://hono.dev/docs/api/hono#fetch}
1420
1458
  *
1421
1459
  * @param {Request} request - request Object of request
1422
- * @param {Env} Env - env Object
1423
- * @param {ExecutionContext} - context of execution
1460
+ * @param {Env} env - env Object
1461
+ * @param {ExecutionContext} executionCtx - context of execution
1424
1462
  * @returns {Response | Promise<Response>} response of request
1425
1463
  *
1426
1464
  */
@@ -1477,7 +1515,10 @@ var Hono = class _Hono {
1477
1515
  }, "fire");
1478
1516
  };
1479
1517
 
1480
- // ../../node_modules/.pnpm/hono@4.12.28/node_modules/hono/dist/router/reg-exp-router/matcher.js
1518
+ // ../../node_modules/.pnpm/hono@4.13.5/node_modules/hono/dist/router/utils.js
1519
+ var createNullObject = /* @__PURE__ */ __name(() => /* @__PURE__ */ Object.create(null), "createNullObject");
1520
+
1521
+ // ../../node_modules/.pnpm/hono@4.13.5/node_modules/hono/dist/router/reg-exp-router/matcher.js
1481
1522
  var emptyParam = [];
1482
1523
  function match(method, path) {
1483
1524
  const matchers = this.buildAllMatchers();
@@ -1499,7 +1540,7 @@ function match(method, path) {
1499
1540
  }
1500
1541
  __name(match, "match");
1501
1542
 
1502
- // ../../node_modules/.pnpm/hono@4.12.28/node_modules/hono/dist/router/reg-exp-router/node.js
1543
+ // ../../node_modules/.pnpm/hono@4.13.5/node_modules/hono/dist/router/reg-exp-router/node.js
1503
1544
  var LABEL_REG_EXP_STR = "[^/]+";
1504
1545
  var ONLY_WILDCARD_REG_EXP_STR = ".*";
1505
1546
  var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
@@ -1513,7 +1554,7 @@ function compareKey(a, b) {
1513
1554
  return 1;
1514
1555
  }
1515
1556
  if (a === ONLY_WILDCARD_REG_EXP_STR || a === TAIL_WILDCARD_REG_EXP_STR) {
1516
- return 1;
1557
+ return b === TAIL_WILDCARD_REG_EXP_STR ? -1 : 1;
1517
1558
  } else if (b === ONLY_WILDCARD_REG_EXP_STR || b === TAIL_WILDCARD_REG_EXP_STR) {
1518
1559
  return -1;
1519
1560
  }
@@ -1529,76 +1570,75 @@ var Node = class _Node {
1529
1570
  static {
1530
1571
  __name(this, "_Node");
1531
1572
  }
1573
+ // handler index of a dynamic path, or -1 for a static path terminal
1532
1574
  #index;
1533
1575
  #varIndex;
1534
- #children = /* @__PURE__ */ Object.create(null);
1535
- insert(tokens, index, paramMap, context, pathErrorCheckOnly) {
1536
- if (tokens.length === 0) {
1537
- if (this.#index !== void 0) {
1538
- throw PATH_ERROR;
1539
- }
1540
- if (pathErrorCheckOnly) {
1541
- return;
1542
- }
1543
- this.#index = index;
1544
- return;
1545
- }
1546
- const [token, ...restTokens] = tokens;
1547
- const pattern = token === "*" ? restTokens.length === 0 ? ["", "", ONLY_WILDCARD_REG_EXP_STR] : ["", "", LABEL_REG_EXP_STR] : token === "/*" ? ["", "", TAIL_WILDCARD_REG_EXP_STR] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
1548
- let node;
1549
- if (pattern) {
1550
- const name = pattern[1];
1551
- let regexpStr = pattern[2] || LABEL_REG_EXP_STR;
1552
- if (name && pattern[2]) {
1553
- if (regexpStr === ".*") {
1554
- throw PATH_ERROR;
1555
- }
1556
- regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
1557
- if (/\((?!\?:)/.test(regexpStr)) {
1558
- throw PATH_ERROR;
1559
- }
1560
- }
1561
- node = this.#children[regexpStr];
1562
- if (!node) {
1563
- if (Object.keys(this.#children).some(
1564
- (k) => k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR
1565
- )) {
1566
- throw PATH_ERROR;
1576
+ #children = createNullObject();
1577
+ insert(tokens, index, paramMap, context, isStatic) {
1578
+ let node = this;
1579
+ for (let i = 0, len = tokens.length; i < len; i++) {
1580
+ const token = tokens[i];
1581
+ 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(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
1582
+ let nextNode;
1583
+ if (pattern) {
1584
+ const name = pattern[1];
1585
+ let regexpStr = pattern[2] || LABEL_REG_EXP_STR;
1586
+ if (name && pattern[2]) {
1587
+ if (regexpStr === ".*") {
1588
+ throw PATH_ERROR;
1589
+ }
1590
+ regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
1591
+ if (/\((?!\?:)/.test(regexpStr)) {
1592
+ throw PATH_ERROR;
1593
+ }
1594
+ if (regexpStr.length === 1 && regExpMetaChars.has(regexpStr)) {
1595
+ throw PATH_ERROR;
1596
+ }
1567
1597
  }
1568
- if (pathErrorCheckOnly) {
1569
- return;
1598
+ nextNode = node.#children[regexpStr];
1599
+ if (!nextNode) {
1600
+ if (regexpStr !== ONLY_WILDCARD_REG_EXP_STR && regexpStr !== TAIL_WILDCARD_REG_EXP_STR) {
1601
+ for (const k in node.#children) {
1602
+ if (
1603
+ // a single-char pattern coexists with single-char literals as a literal does
1604
+ (regexpStr.length > 1 || k.length > 1) && k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR
1605
+ ) {
1606
+ throw PATH_ERROR;
1607
+ }
1608
+ }
1609
+ }
1610
+ nextNode = node.#children[regexpStr] = new _Node();
1570
1611
  }
1571
- node = this.#children[regexpStr] = new _Node();
1572
1612
  if (name !== "") {
1573
- node.#varIndex = context.varIndex++;
1613
+ nextNode.#varIndex ??= context.varIndex++;
1614
+ paramMap.push([name, nextNode.#varIndex]);
1574
1615
  }
1575
- }
1576
- if (!pathErrorCheckOnly && name !== "") {
1577
- paramMap.push([name, node.#varIndex]);
1578
- }
1579
- } else {
1580
- node = this.#children[token];
1581
- if (!node) {
1582
- if (Object.keys(this.#children).some(
1583
- (k) => k.length > 1 && k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR
1584
- )) {
1585
- throw PATH_ERROR;
1586
- }
1587
- if (pathErrorCheckOnly) {
1588
- return;
1616
+ } else {
1617
+ nextNode = node.#children[token];
1618
+ if (!nextNode) {
1619
+ for (const k in node.#children) {
1620
+ if (k.length > 1 && k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR) {
1621
+ throw PATH_ERROR;
1622
+ }
1623
+ }
1624
+ nextNode = node.#children[token] = new _Node();
1589
1625
  }
1590
- node = this.#children[token] = new _Node();
1591
1626
  }
1627
+ node = nextNode;
1628
+ }
1629
+ if (node.#index !== void 0) {
1630
+ throw PATH_ERROR;
1592
1631
  }
1593
- node.insert(restTokens, index, paramMap, context, pathErrorCheckOnly);
1632
+ node.#index = isStatic ? -1 : index;
1594
1633
  }
1595
1634
  buildRegExpStr() {
1596
1635
  const childKeys = Object.keys(this.#children).sort(compareKey);
1597
1636
  const strList = childKeys.map((k) => {
1598
1637
  const c = this.#children[k];
1599
- return (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + c.buildRegExpStr();
1600
- });
1601
- if (typeof this.#index === "number") {
1638
+ const childStr = c.buildRegExpStr();
1639
+ return childStr === "" ? "" : (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + childStr;
1640
+ }).filter(Boolean);
1641
+ if (typeof this.#index === "number" && this.#index !== -1) {
1602
1642
  strList.unshift(`#${this.#index}`);
1603
1643
  }
1604
1644
  if (strList.length === 0) {
@@ -1611,19 +1651,27 @@ var Node = class _Node {
1611
1651
  }
1612
1652
  };
1613
1653
 
1614
- // ../../node_modules/.pnpm/hono@4.12.28/node_modules/hono/dist/router/reg-exp-router/trie.js
1654
+ // ../../node_modules/.pnpm/hono@4.13.5/node_modules/hono/dist/router/reg-exp-router/trie.js
1615
1655
  var Trie = class {
1616
1656
  static {
1617
1657
  __name(this, "Trie");
1618
1658
  }
1619
1659
  #context = { varIndex: 0 };
1620
1660
  #root = new Node();
1621
- insert(path, index, pathErrorCheckOnly) {
1661
+ #index = 0;
1662
+ // dynamic path -> [handler index, param assoc]; static paths are not registered
1663
+ paths = createNullObject();
1664
+ insert(path, isStatic) {
1665
+ if (isStatic) {
1666
+ this.#root.insert(path.split(""), 0, [], this.#context, true);
1667
+ return;
1668
+ }
1622
1669
  const paramAssoc = [];
1623
1670
  const groups = [];
1671
+ let markedPath = path;
1624
1672
  for (let i = 0; ; ) {
1625
1673
  let replaced = false;
1626
- path = path.replace(/\{[^}]+\}/g, (m) => {
1674
+ markedPath = markedPath.replace(/\{[^}]+\}/g, (m) => {
1627
1675
  const mark = `@\\${i}`;
1628
1676
  groups[i] = [mark, m];
1629
1677
  i++;
@@ -1634,7 +1682,7 @@ var Trie = class {
1634
1682
  break;
1635
1683
  }
1636
1684
  }
1637
- const tokens = path.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
1685
+ const tokens = markedPath.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
1638
1686
  for (let i = groups.length - 1; i >= 0; i--) {
1639
1687
  const [mark] = groups[i];
1640
1688
  for (let j = tokens.length - 1; j >= 0; j--) {
@@ -1644,8 +1692,8 @@ var Trie = class {
1644
1692
  }
1645
1693
  }
1646
1694
  }
1647
- this.#root.insert(tokens, index, paramAssoc, this.#context, pathErrorCheckOnly);
1648
- return paramAssoc;
1695
+ this.#root.insert(tokens, this.#index, paramAssoc, this.#context, false);
1696
+ this.paths[path] = [this.#index++, paramAssoc];
1649
1697
  }
1650
1698
  buildRegExp() {
1651
1699
  let regexp = this.#root.buildRegExpStr();
@@ -1670,84 +1718,18 @@ var Trie = class {
1670
1718
  }
1671
1719
  };
1672
1720
 
1673
- // ../../node_modules/.pnpm/hono@4.12.28/node_modules/hono/dist/router/reg-exp-router/router.js
1674
- var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)];
1675
- var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
1721
+ // ../../node_modules/.pnpm/hono@4.13.5/node_modules/hono/dist/router/reg-exp-router/router.js
1722
+ var wildcardRegExpCache = createNullObject();
1676
1723
  function buildWildcardRegExp(path) {
1677
1724
  return wildcardRegExpCache[path] ??= new RegExp(
1678
- path === "*" ? "" : `^${path.replace(
1679
- /\/\*$|([.\\+*[^\]$()])/g,
1680
- (_, metaChar) => metaChar ? `\\${metaChar}` : "(?:|/.*)"
1725
+ `^${path.replace(
1726
+ /\/:[^/{}]+(?:\{\[\^\/]\+})?(?=[/{]|$)|\/?\*$|([.\\+*[^\]$()?{}|])/g,
1727
+ (match2, metaChar) => metaChar ? `\\${metaChar}` : match2 === "/*" ? TAIL_WILDCARD_REG_EXP_STR : match2 === "*" ? ONLY_WILDCARD_REG_EXP_STR : `/:${LABEL_REG_EXP_STR}`
1681
1728
  )}$`
1682
1729
  );
1683
1730
  }
1684
1731
  __name(buildWildcardRegExp, "buildWildcardRegExp");
1685
- function clearWildcardRegExpCache() {
1686
- wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
1687
- }
1688
- __name(clearWildcardRegExpCache, "clearWildcardRegExpCache");
1689
- function buildMatcherFromPreprocessedRoutes(routes) {
1690
- const trie = new Trie();
1691
- const handlerData = [];
1692
- if (routes.length === 0) {
1693
- return nullMatcher;
1694
- }
1695
- const routesWithStaticPathFlag = routes.map(
1696
- (route) => [!/\*|\/:/.test(route[0]), ...route]
1697
- ).sort(
1698
- ([isStaticA, pathA], [isStaticB, pathB]) => isStaticA ? 1 : isStaticB ? -1 : pathA.length - pathB.length
1699
- );
1700
- const staticMap = /* @__PURE__ */ Object.create(null);
1701
- for (let i = 0, j = -1, len = routesWithStaticPathFlag.length; i < len; i++) {
1702
- const [pathErrorCheckOnly, path, handlers] = routesWithStaticPathFlag[i];
1703
- if (pathErrorCheckOnly) {
1704
- staticMap[path] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
1705
- } else {
1706
- j++;
1707
- }
1708
- let paramAssoc;
1709
- try {
1710
- paramAssoc = trie.insert(path, j, pathErrorCheckOnly);
1711
- } catch (e) {
1712
- throw e === PATH_ERROR ? new UnsupportedPathError(path) : e;
1713
- }
1714
- if (pathErrorCheckOnly) {
1715
- continue;
1716
- }
1717
- handlerData[j] = handlers.map(([h, paramCount]) => {
1718
- const paramIndexMap = /* @__PURE__ */ Object.create(null);
1719
- paramCount -= 1;
1720
- for (; paramCount >= 0; paramCount--) {
1721
- const [key, value2] = paramAssoc[paramCount];
1722
- paramIndexMap[key] = value2;
1723
- }
1724
- return [h, paramIndexMap];
1725
- });
1726
- }
1727
- const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
1728
- for (let i = 0, len = handlerData.length; i < len; i++) {
1729
- for (let j = 0, len2 = handlerData[i].length; j < len2; j++) {
1730
- const map = handlerData[i][j]?.[1];
1731
- if (!map) {
1732
- continue;
1733
- }
1734
- const keys = Object.keys(map);
1735
- for (let k = 0, len3 = keys.length; k < len3; k++) {
1736
- map[keys[k]] = paramReplacementMap[map[keys[k]]];
1737
- }
1738
- }
1739
- }
1740
- const handlerMap = [];
1741
- for (const i in indexReplacementMap) {
1742
- handlerMap[i] = handlerData[indexReplacementMap[i]];
1743
- }
1744
- return [regexp, handlerMap, staticMap];
1745
- }
1746
- __name(buildMatcherFromPreprocessedRoutes, "buildMatcherFromPreprocessedRoutes");
1747
1732
  function findMiddleware(middleware, path) {
1748
- if (!middleware) {
1749
- return void 0;
1750
- }
1751
1733
  for (const k of Object.keys(middleware).sort((a, b) => b.length - a.length)) {
1752
1734
  if (buildWildcardRegExp(k).test(path)) {
1753
1735
  return [...middleware[k]];
@@ -1763,100 +1745,106 @@ var RegExpRouter = class {
1763
1745
  name = "RegExpRouter";
1764
1746
  #middleware;
1765
1747
  #routes;
1748
+ #tries;
1766
1749
  constructor() {
1767
- this.#middleware = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
1768
- this.#routes = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
1750
+ this.#middleware = { [METHOD_NAME_ALL]: createNullObject() };
1751
+ this.#routes = { [METHOD_NAME_ALL]: createNullObject() };
1752
+ this.#tries = { [METHOD_NAME_ALL]: new Trie() };
1753
+ }
1754
+ #insertPath(method, path) {
1755
+ try {
1756
+ this.#tries[method].insert(path, !/\*|\/:/.test(path));
1757
+ } catch (e) {
1758
+ throw e === PATH_ERROR ? new UnsupportedPathError(path) : e;
1759
+ }
1769
1760
  }
1770
1761
  add(method, path, handler) {
1771
1762
  const middleware = this.#middleware;
1772
1763
  const routes = this.#routes;
1773
- if (!middleware || !routes) {
1764
+ if (!middleware) {
1774
1765
  throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
1775
1766
  }
1776
1767
  if (!middleware[method]) {
1777
- ;
1778
- [middleware, routes].forEach((handlerMap) => {
1779
- handlerMap[method] = /* @__PURE__ */ Object.create(null);
1780
- Object.keys(handlerMap[METHOD_NAME_ALL]).forEach((p) => {
1768
+ this.#tries[method] = new Trie();
1769
+ for (const handlerMap of [middleware, routes]) {
1770
+ handlerMap[method] = createNullObject();
1771
+ for (const p in handlerMap[METHOD_NAME_ALL]) {
1781
1772
  handlerMap[method][p] = [...handlerMap[METHOD_NAME_ALL][p]];
1782
- });
1783
- });
1773
+ this.#insertPath(method, p);
1774
+ }
1775
+ }
1784
1776
  }
1785
1777
  if (path === "/*") {
1786
1778
  path = "*";
1787
1779
  }
1788
- const paramCount = (path.match(/\/:/g) || []).length;
1780
+ const methods = method === METHOD_NAME_ALL ? Object.keys(middleware) : [method];
1789
1781
  if (/\*$/.test(path)) {
1790
1782
  const re = buildWildcardRegExp(path);
1791
- if (method === METHOD_NAME_ALL) {
1792
- Object.keys(middleware).forEach((m) => {
1793
- middleware[m][path] ||= findMiddleware(middleware[m], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
1794
- });
1795
- } else {
1796
- middleware[method][path] ||= findMiddleware(middleware[method], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
1797
- }
1798
- Object.keys(middleware).forEach((m) => {
1799
- if (method === METHOD_NAME_ALL || method === m) {
1800
- Object.keys(middleware[m]).forEach((p) => {
1801
- re.test(p) && middleware[m][p].push([handler, paramCount]);
1802
- });
1783
+ for (const m of methods) {
1784
+ if (!middleware[m][path]) {
1785
+ this.#insertPath(m, path);
1786
+ middleware[m][path] = findMiddleware(middleware[m], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
1803
1787
  }
1804
- });
1805
- Object.keys(routes).forEach((m) => {
1806
- if (method === METHOD_NAME_ALL || method === m) {
1807
- Object.keys(routes[m]).forEach(
1808
- (p) => re.test(p) && routes[m][p].push([handler, paramCount])
1809
- );
1788
+ }
1789
+ for (const handlerMap of [middleware, routes]) {
1790
+ for (const m of methods) {
1791
+ for (const p in handlerMap[m]) {
1792
+ re.test(p) && handlerMap[m][p].push([handler, path]);
1793
+ }
1810
1794
  }
1811
- });
1795
+ }
1812
1796
  return;
1813
1797
  }
1814
1798
  const paths = checkOptionalParameter(path) || [path];
1815
- for (let i = 0, len = paths.length; i < len; i++) {
1816
- const path2 = paths[i];
1817
- Object.keys(routes).forEach((m) => {
1818
- if (method === METHOD_NAME_ALL || method === m) {
1819
- routes[m][path2] ||= [
1820
- ...findMiddleware(middleware[m], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || []
1821
- ];
1822
- routes[m][path2].push([handler, paramCount - len + i + 1]);
1799
+ for (const path2 of paths) {
1800
+ for (const m of methods) {
1801
+ if (!routes[m][path2]) {
1802
+ this.#insertPath(m, path2);
1803
+ routes[m][path2] = findMiddleware(middleware[m], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || [];
1823
1804
  }
1824
- });
1805
+ routes[m][path2].push([handler, path2]);
1806
+ }
1825
1807
  }
1826
1808
  }
1827
1809
  match = match;
1828
1810
  buildAllMatchers() {
1829
- const matchers = /* @__PURE__ */ Object.create(null);
1830
- Object.keys(this.#routes).concat(Object.keys(this.#middleware)).forEach((method) => {
1831
- matchers[method] ||= this.#buildMatcher(method);
1832
- });
1833
- this.#middleware = this.#routes = void 0;
1834
- clearWildcardRegExpCache();
1811
+ const matchers = createNullObject();
1812
+ for (const method of Object.keys(this.#routes)) {
1813
+ matchers[method] = this.#buildMatcher(method);
1814
+ }
1815
+ this.#middleware = this.#routes = this.#tries = void 0;
1816
+ wildcardRegExpCache = createNullObject();
1835
1817
  return matchers;
1836
1818
  }
1837
1819
  #buildMatcher(method) {
1838
- const routes = [];
1839
- let hasOwnRoute = method === METHOD_NAME_ALL;
1840
- [this.#middleware, this.#routes].forEach((r) => {
1841
- const ownRoute = r[method] ? Object.keys(r[method]).map((path) => [path, r[method][path]]) : [];
1842
- if (ownRoute.length !== 0) {
1843
- hasOwnRoute ||= true;
1844
- routes.push(...ownRoute);
1845
- } else if (method !== METHOD_NAME_ALL) {
1846
- routes.push(
1847
- ...Object.keys(r[METHOD_NAME_ALL]).map((path) => [path, r[METHOD_NAME_ALL][path]])
1848
- );
1820
+ const middleware = this.#middleware[method];
1821
+ const routes = this.#routes[method];
1822
+ const trie = this.#tries[method];
1823
+ const staticMap = createNullObject();
1824
+ const handlerData = [];
1825
+ const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
1826
+ for (const r of [middleware, routes]) {
1827
+ for (const path in r) {
1828
+ const handlers = r[path];
1829
+ const pathData = trie.paths[path];
1830
+ if (!pathData) {
1831
+ staticMap[path] = [handlers.map(([h]) => [h, createNullObject()]), emptyParam];
1832
+ continue;
1833
+ }
1834
+ handlerData[pathData[0]] = handlers.map(([h, handlerPath]) => [
1835
+ h,
1836
+ trie.paths[handlerPath][1].reduceRight((map, [key], i) => {
1837
+ map[key] = paramReplacementMap[pathData[1][i][1]];
1838
+ return map;
1839
+ }, createNullObject())
1840
+ ]);
1849
1841
  }
1850
- });
1851
- if (!hasOwnRoute) {
1852
- return null;
1853
- } else {
1854
- return buildMatcherFromPreprocessedRoutes(routes);
1855
1842
  }
1843
+ return [regexp, indexReplacementMap.map((i) => handlerData[i]), staticMap];
1856
1844
  }
1857
1845
  };
1858
1846
 
1859
- // ../../node_modules/.pnpm/hono@4.12.28/node_modules/hono/dist/router/smart-router/router.js
1847
+ // ../../node_modules/.pnpm/hono@4.13.5/node_modules/hono/dist/router/smart-router/router.js
1860
1848
  var SmartRouter = class {
1861
1849
  static {
1862
1850
  __name(this, "SmartRouter");
@@ -1914,81 +1902,56 @@ var SmartRouter = class {
1914
1902
  }
1915
1903
  };
1916
1904
 
1917
- // ../../node_modules/.pnpm/hono@4.12.28/node_modules/hono/dist/router/trie-router/node.js
1918
- var emptyParams = /* @__PURE__ */ Object.create(null);
1919
- var hasChildren = /* @__PURE__ */ __name((children) => {
1920
- for (const _ in children) {
1921
- return true;
1922
- }
1923
- return false;
1924
- }, "hasChildren");
1905
+ // ../../node_modules/.pnpm/hono@4.13.5/node_modules/hono/dist/router/trie-router/node.js
1906
+ var emptyParams = createNullObject();
1907
+ var order = 0;
1925
1908
  var Node2 = class _Node2 {
1926
1909
  static {
1927
1910
  __name(this, "_Node");
1928
1911
  }
1929
- #methods;
1930
- #children;
1931
- #patterns;
1932
- #order = 0;
1912
+ #methods = [];
1913
+ #children = createNullObject();
1914
+ #patterns = [];
1915
+ #pattern;
1933
1916
  #params = emptyParams;
1934
- constructor(method, handler, children) {
1935
- this.#children = children || /* @__PURE__ */ Object.create(null);
1936
- this.#methods = [];
1937
- if (method && handler) {
1938
- const m = /* @__PURE__ */ Object.create(null);
1939
- m[method] = { handler, possibleKeys: [], score: 0 };
1940
- this.#methods = [m];
1941
- }
1942
- this.#patterns = [];
1943
- }
1944
1917
  insert(method, path, handler) {
1945
- this.#order = ++this.#order;
1946
1918
  let curNode = this;
1947
1919
  const parts = splitRoutingPath(path);
1948
- const possibleKeys = [];
1949
- for (let i = 0, len = parts.length; i < len; i++) {
1950
- const p = parts[i];
1951
- const nextP = parts[i + 1];
1952
- const pattern = getPattern(p, nextP);
1953
- const key = Array.isArray(pattern) ? pattern[0] : p;
1954
- if (key in curNode.#children) {
1955
- curNode = curNode.#children[key];
1956
- if (pattern) {
1957
- possibleKeys.push(pattern[1]);
1958
- }
1959
- continue;
1920
+ const possibleKeys = /* @__PURE__ */ new Set();
1921
+ let i = 0;
1922
+ for (const p of parts) {
1923
+ const nextP = parts[++i];
1924
+ const pattern = getPattern(p, nextP) || (nextP === void 0 && p && p.indexOf("*") === p.length - 1 ? p : null);
1925
+ const isParam = Array.isArray(pattern);
1926
+ const key = isParam ? pattern[0] : pattern || p;
1927
+ const child = curNode.#children[key] ||= new _Node2();
1928
+ if (pattern && !child.#pattern) {
1929
+ child.#pattern = pattern;
1930
+ curNode.#patterns.push(child);
1960
1931
  }
1961
- curNode.#children[key] = new _Node2();
1962
- if (pattern) {
1963
- curNode.#patterns.push(pattern);
1964
- possibleKeys.push(pattern[1]);
1932
+ curNode = child;
1933
+ if (isParam) {
1934
+ possibleKeys.add(pattern[1]);
1965
1935
  }
1966
- curNode = curNode.#children[key];
1967
1936
  }
1968
1937
  curNode.#methods.push({
1969
1938
  [method]: {
1970
1939
  handler,
1971
- possibleKeys: possibleKeys.filter((v, i, a) => a.indexOf(v) === i),
1972
- score: this.#order
1940
+ possibleKeys: [...possibleKeys],
1941
+ score: ++order
1973
1942
  }
1974
1943
  });
1975
- return curNode;
1976
1944
  }
1977
1945
  #pushHandlerSets(handlerSets, node, method, nodeParams, params) {
1978
1946
  for (let i = 0, len = node.#methods.length; i < len; i++) {
1979
1947
  const m = node.#methods[i];
1980
1948
  const handlerSet = m[method] || m[METHOD_NAME_ALL];
1981
- const processedSet = {};
1982
- if (handlerSet !== void 0) {
1983
- handlerSet.params = /* @__PURE__ */ Object.create(null);
1949
+ if (handlerSet) {
1950
+ handlerSet.params = createNullObject();
1984
1951
  handlerSets.push(handlerSet);
1985
- if (nodeParams !== emptyParams || params && params !== emptyParams) {
1986
- for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
1987
- const key = handlerSet.possibleKeys[i2];
1988
- const processed = processedSet[handlerSet.score];
1989
- handlerSet.params[key] = params?.[key] && !processed ? params[key] : nodeParams[key] ?? params?.[key];
1990
- processedSet[handlerSet.score] = true;
1991
- }
1952
+ for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
1953
+ const key = handlerSet.possibleKeys[i2];
1954
+ handlerSet.params[key] = params?.[key] && !i2 ? params[key] : nodeParams[key] ?? params?.[key];
1992
1955
  }
1993
1956
  }
1994
1957
  }
@@ -2020,42 +1983,52 @@ var Node2 = class _Node2 {
2020
1983
  tempNodes.push(nextNode);
2021
1984
  }
2022
1985
  }
2023
- for (let k = 0, len3 = node.#patterns.length; k < len3; k++) {
2024
- const pattern = node.#patterns[k];
1986
+ for (const child of node.#patterns) {
1987
+ const pattern = child.#pattern;
2025
1988
  const params = node.#params === emptyParams ? {} : { ...node.#params };
2026
- if (pattern === "*") {
2027
- const astNode = node.#children["*"];
2028
- if (astNode) {
2029
- this.#pushHandlerSets(handlerSets, astNode, method, node.#params);
2030
- astNode.#params = params;
2031
- tempNodes.push(astNode);
1989
+ if (typeof pattern === "string") {
1990
+ if (pattern === "*" || part2.startsWith(pattern.slice(0, -1))) {
1991
+ this.#pushHandlerSets(handlerSets, child, method, node.#params);
1992
+ if (pattern === "*") {
1993
+ child.#params = params;
1994
+ tempNodes.push(child);
1995
+ }
2032
1996
  }
2033
1997
  continue;
2034
1998
  }
2035
- const [key, name, matcher] = pattern;
2036
- if (!part2 && !(matcher instanceof RegExp)) {
1999
+ const [, name, matcher] = pattern;
2000
+ if (!part2 && matcher === true) {
2037
2001
  continue;
2038
2002
  }
2039
- const child = node.#children[key];
2040
- if (matcher instanceof RegExp) {
2041
- if (partOffsets === null) {
2042
- partOffsets = new Array(len);
2003
+ if (matcher !== true) {
2004
+ if (!partOffsets) {
2005
+ partOffsets = [];
2043
2006
  let offset = path[0] === "/" ? 1 : 0;
2044
2007
  for (let p = 0; p < len; p++) {
2045
2008
  partOffsets[p] = offset;
2046
2009
  offset += parts[p].length + 1;
2047
2010
  }
2048
2011
  }
2049
- const restPathString = path.substring(partOffsets[i]);
2012
+ const restPathString = path.slice(partOffsets[i]);
2050
2013
  const m = matcher.exec(restPathString);
2051
2014
  if (m) {
2052
2015
  params[name] = m[0];
2053
2016
  this.#pushHandlerSets(handlerSets, child, method, node.#params, params);
2054
- if (hasChildren(child.#children)) {
2017
+ if (m[0].length === restPathString.length && child.#children["*"]) {
2018
+ this.#pushHandlerSets(
2019
+ handlerSets,
2020
+ child.#children["*"],
2021
+ method,
2022
+ node.#params,
2023
+ params
2024
+ );
2025
+ }
2026
+ for (const _ in child.#children) {
2055
2027
  child.#params = params;
2056
- const componentCount = m[0].match(/\//)?.length ?? 0;
2028
+ const componentCount = m[0].match(/\//g)?.length ?? 0;
2057
2029
  const targetCurNodes = curNodesQueue[componentCount] ||= [];
2058
2030
  targetCurNodes.push(child);
2031
+ break;
2059
2032
  }
2060
2033
  continue;
2061
2034
  }
@@ -2083,7 +2056,7 @@ var Node2 = class _Node2 {
2083
2056
  const shifted = curNodesQueue.shift();
2084
2057
  curNodes = shifted ? tempNodes.concat(shifted) : tempNodes;
2085
2058
  }
2086
- if (handlerSets.length > 1) {
2059
+ if (handlerSets[1]) {
2087
2060
  handlerSets.sort((a, b) => {
2088
2061
  return a.score - b.score;
2089
2062
  });
@@ -2092,32 +2065,24 @@ var Node2 = class _Node2 {
2092
2065
  }
2093
2066
  };
2094
2067
 
2095
- // ../../node_modules/.pnpm/hono@4.12.28/node_modules/hono/dist/router/trie-router/router.js
2068
+ // ../../node_modules/.pnpm/hono@4.13.5/node_modules/hono/dist/router/trie-router/router.js
2096
2069
  var TrieRouter = class {
2097
2070
  static {
2098
2071
  __name(this, "TrieRouter");
2099
2072
  }
2100
2073
  name = "TrieRouter";
2101
- #node;
2102
- constructor() {
2103
- this.#node = new Node2();
2104
- }
2074
+ #node = new Node2();
2105
2075
  add(method, path, handler) {
2106
- const results = checkOptionalParameter(path);
2107
- if (results) {
2108
- for (let i = 0, len = results.length; i < len; i++) {
2109
- this.#node.insert(method, results[i], handler);
2110
- }
2111
- return;
2076
+ for (const result of checkOptionalParameter(path) || [path]) {
2077
+ this.#node.insert(method, result, handler);
2112
2078
  }
2113
- this.#node.insert(method, path, handler);
2114
2079
  }
2115
2080
  match(method, path) {
2116
2081
  return this.#node.search(method, path);
2117
2082
  }
2118
2083
  };
2119
2084
 
2120
- // ../../node_modules/.pnpm/hono@4.12.28/node_modules/hono/dist/hono.js
2085
+ // ../../node_modules/.pnpm/hono@4.13.5/node_modules/hono/dist/hono.js
2121
2086
  var Hono2 = class extends Hono {
2122
2087
  static {
2123
2088
  __name(this, "Hono");
@@ -2144,6 +2109,9 @@ var EDGETAG_PREFIXES = [
2144
2109
  "/tag",
2145
2110
  "/consent",
2146
2111
  "/audience",
2112
+ "/cloud-audience",
2113
+ "/v1/crm/",
2114
+ "/v1/segment/",
2147
2115
  "/data",
2148
2116
  "/user",
2149
2117
  "/getData",
@@ -2158,9 +2126,11 @@ var EDGETAG_PREFIXES = [
2158
2126
 
2159
2127
  // src/allowed-paths.ts
2160
2128
  var QINTO_PREFIXES = ["/open", "/q.js", "/health", "/v1/", "/openapi.json", "/apps/", "/app/"];
2161
- var ALLOWED_PREFIXES = [...QINTO_PREFIXES, ...EDGETAG_PREFIXES];
2162
- var allowedPaths = /* @__PURE__ */ __name((path) => {
2163
- return path === "/" || ALLOWED_PREFIXES.some((prefix) => path.startsWith(prefix));
2129
+ var allowedPaths = /* @__PURE__ */ __name((path, legacy) => {
2130
+ if (QINTO_PREFIXES.some((prefix) => path.startsWith(prefix))) {
2131
+ return true;
2132
+ }
2133
+ return legacy && (path === "/" || EDGETAG_PREFIXES.some((prefix) => path.startsWith(prefix)));
2164
2134
  }, "allowedPaths");
2165
2135
 
2166
2136
  // ../../libs/wfp-control-token/src/control-token.ts
@@ -2450,7 +2420,10 @@ var dispatchId = /* @__PURE__ */ __name(async (hostname, suffix) => {
2450
2420
  var dispatchToWorker = /* @__PURE__ */ __name(async (request, env) => {
2451
2421
  const hostname = new URL(request.url).hostname;
2452
2422
  const suffix = env.QINTO_URL_SUFFIX ?? "";
2453
- const ids = [await dispatchId(hostname, suffix), legacyIdFromHostname(hostname)];
2423
+ const ids = [await dispatchId(hostname, suffix)];
2424
+ if (env.CRON) {
2425
+ ids.push(legacyIdFromHostname(hostname));
2426
+ }
2454
2427
  const headers = new Headers(request.headers);
2455
2428
  headers.set(CF_DATA_HEADER, serializeCfData(request.cf));
2456
2429
  for (const [index, id] of ids.entries()) {
@@ -2619,11 +2592,61 @@ var openTailSocket = /* @__PURE__ */ __name((c) => {
2619
2592
  return c.env.TAIL.get(c.env.TAIL.idFromName(workerName)).fetch(c.req.raw);
2620
2593
  }, "openTailSocket");
2621
2594
 
2622
- // src/tail/do.ts
2595
+ // src/cron.ts
2623
2596
  import { DurableObject } from "cloudflare:workers";
2597
+ var INTERVAL_MS = 5 * 60 * 1e3;
2598
+ var Cron = class extends DurableObject {
2599
+ static {
2600
+ __name(this, "Cron");
2601
+ }
2602
+ async addWorker(registration) {
2603
+ let hash = 2166136261 >>> 0;
2604
+ const input = `alarm:${registration.deploymentId}`;
2605
+ for (let i = 0; i < input.length; i++) {
2606
+ hash = Math.imul(hash ^ input.charCodeAt(i), 16777619) >>> 0;
2607
+ }
2608
+ await this.setWorkerData({ ...registration, jitterMs: hash % INTERVAL_MS });
2609
+ const currentAlarm = await this.addAlarm();
2610
+ return new Response(JSON.stringify({ currentAlarm }), { headers: { "content-type": "application/json;charset=UTF-8" } });
2611
+ }
2612
+ async removeWorker(id) {
2613
+ const data = await this.getWorkerData();
2614
+ if (data?.deploymentId === id) {
2615
+ await this.ctx.storage.deleteAlarm();
2616
+ return { success: true, message: `Worker ${id} removed successfully.` };
2617
+ }
2618
+ return { success: false, message: `Worker ${id} not found.` };
2619
+ }
2620
+ async addAlarm() {
2621
+ const currentAlarm = await this.ctx.storage.getAlarm();
2622
+ if (currentAlarm === null) {
2623
+ const data = await this.getWorkerData();
2624
+ await this.ctx.storage.setAlarm((Math.floor(Date.now() / INTERVAL_MS) + 1) * INTERVAL_MS + (data?.jitterMs ?? 0));
2625
+ }
2626
+ return currentAlarm;
2627
+ }
2628
+ async getWorkerData() {
2629
+ return await this.ctx.storage.get("worker") ?? null;
2630
+ }
2631
+ async setWorkerData(registration) {
2632
+ await this.ctx.storage.put("worker", registration);
2633
+ }
2634
+ async alarm() {
2635
+ const data = await this.getWorkerData();
2636
+ if (!data?.deploymentId) {
2637
+ console.error("No deploymentId found in worker data.");
2638
+ return;
2639
+ }
2640
+ await fetch(`https://${data.domain}/cron`);
2641
+ await this.addAlarm();
2642
+ }
2643
+ };
2644
+
2645
+ // src/tail/do.ts
2646
+ import { DurableObject as DurableObject2 } from "cloudflare:workers";
2624
2647
  var WINDOW_MS = 1e3;
2625
2648
  var FRAMES_PER_WINDOW = 200;
2626
- var Tail = class extends DurableObject {
2649
+ var Tail = class extends DurableObject2 {
2627
2650
  static {
2628
2651
  __name(this, "Tail");
2629
2652
  }
@@ -2710,11 +2733,35 @@ var app = new Hono2();
2710
2733
  app.get("/tail", requireControlToken, openTailSocket);
2711
2734
  app.post("/control/app", requireControlToken, forwardAppControl);
2712
2735
  app.post("/control/id-graph/:action", requireControlToken, forwardIdGraph);
2736
+ app.post("/add-worker", async (c) => {
2737
+ if (!c.env.CRON) {
2738
+ return c.text("path not allowed", 403);
2739
+ }
2740
+ const payload = await c.req.json();
2741
+ if (!payload?.deploymentId || !payload.domain) {
2742
+ return c.text("Worker ID is required", 400);
2743
+ }
2744
+ const stub = c.env.CRON.get(c.env.CRON.idFromName(payload.deploymentId));
2745
+ const result = await stub.addWorker(payload);
2746
+ return c.body(JSON.stringify({ result }), 200, { "content-type": "application/json;charset=UTF-8" });
2747
+ });
2748
+ app.delete("/remove-worker", async (c) => {
2749
+ if (!c.env.CRON) {
2750
+ return c.text("path not allowed", 403);
2751
+ }
2752
+ const deploymentId = c.req.query("deploymentId");
2753
+ if (!deploymentId) {
2754
+ return c.text("Worker ID is required", 400);
2755
+ }
2756
+ const stub = c.env.CRON.get(c.env.CRON.idFromName(deploymentId));
2757
+ const result = await stub.removeWorker(deploymentId);
2758
+ return c.body(JSON.stringify({ result }), 200, { "content-type": "application/json;charset=UTF-8" });
2759
+ });
2713
2760
  app.get("/q.js", (c) => {
2714
2761
  return c.executionCtx.exports.QJs({ props: { origin: new URL(c.req.url).origin } }).fetch(c.req.raw);
2715
2762
  });
2716
2763
  app.all("*", (c) => {
2717
- if (!allowedPaths(c.req.path)) {
2764
+ if (!allowedPaths(c.req.path, c.env.CRON !== void 0)) {
2718
2765
  return c.text("path not allowed", 403);
2719
2766
  }
2720
2767
  return dispatchToWorker(c.req.raw, c.env);
@@ -2728,6 +2775,7 @@ var index_default = {
2728
2775
  }
2729
2776
  };
2730
2777
  export {
2778
+ Cron,
2731
2779
  QJs,
2732
2780
  Tail,
2733
2781
  app,