@ubiquity-os/plugin-sdk 3.7.0 → 3.8.0

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.
package/dist/index.mjs CHANGED
@@ -190,9 +190,9 @@ var Logs = class _Logs {
190
190
  const stackLines = new Error().stack?.split("\n") || [];
191
191
  if (stackLines.length > 3) {
192
192
  const callerLine = stackLines[3];
193
- const match = callerLine.match(/at (\S+)/);
194
- if (match) {
195
- metadata.caller = match[1];
193
+ const match2 = callerLine.match(/at (\S+)/);
194
+ if (match2) {
195
+ metadata.caller = match2[1];
196
196
  }
197
197
  }
198
198
  return metadata;
@@ -348,9 +348,9 @@ function getErrorStatus(err) {
348
348
  if (Number.isFinite(parsed)) return parsed;
349
349
  }
350
350
  if (err instanceof Error) {
351
- const match = /LLM API error:\s*(\d{3})/i.exec(err.message);
352
- if (match) {
353
- const parsed = Number.parseInt(match[1], 10);
351
+ const match2 = /LLM API error:\s*(\d{3})/i.exec(err.message);
352
+ if (match2) {
353
+ const parsed = Number.parseInt(match2[1], 10);
354
354
  if (Number.isFinite(parsed)) return parsed;
355
355
  }
356
356
  }
@@ -388,7 +388,7 @@ function transformError(context, error) {
388
388
  return logByStatus(context, String(error), { err: error });
389
389
  }
390
390
 
391
- // ../../node_modules/hono/dist/helper/adapter/index.js
391
+ // ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/helper/adapter/index.js
392
392
  var env = (c, runtime) => {
393
393
  const global = globalThis;
394
394
  const globalEnv = global?.process?.env;
@@ -401,6 +401,7 @@ var env = (c, runtime) => {
401
401
  return Deno.env.toObject();
402
402
  },
403
403
  workerd: () => c.env,
404
+ // On Fastly Compute, you can use the ConfigStore to manage user-defined data.
404
405
  fastly: () => ({}),
405
406
  other: () => ({})
406
407
  };
@@ -595,6 +596,54 @@ function getPluginOptions(options) {
595
596
  }
596
597
 
597
598
  // src/comment.ts
599
+ var COMMAND_RESPONSE_KIND = "command-response";
600
+ var COMMAND_RESPONSE_MARKER = `"commentKind": "${COMMAND_RESPONSE_KIND}"`;
601
+ var COMMAND_RESPONSE_COMMENT_LIMIT = 50;
602
+ var RECENT_COMMENTS_QUERY = `
603
+ query($owner: String!, $repo: String!, $number: Int!, $last: Int!) {
604
+ repository(owner: $owner, name: $repo) {
605
+ issueOrPullRequest(number: $number) {
606
+ __typename
607
+ ... on Issue {
608
+ comments(last: $last) {
609
+ nodes {
610
+ id
611
+ body
612
+ isMinimized
613
+ minimizedReason
614
+ author {
615
+ login
616
+ }
617
+ }
618
+ }
619
+ }
620
+ ... on PullRequest {
621
+ comments(last: $last) {
622
+ nodes {
623
+ id
624
+ body
625
+ isMinimized
626
+ minimizedReason
627
+ author {
628
+ login
629
+ }
630
+ }
631
+ }
632
+ }
633
+ }
634
+ }
635
+ }
636
+ `;
637
+ var MINIMIZE_COMMENT_MUTATION = `
638
+ mutation($id: ID!, $classifier: ReportedContentClassifiers!) {
639
+ minimizeComment(input: { subjectId: $id, classifier: $classifier }) {
640
+ minimizedComment {
641
+ isMinimized
642
+ minimizedReason
643
+ }
644
+ }
645
+ }
646
+ `;
598
647
  function logByStatus2(logger, message, status, metadata) {
599
648
  const payload = { ...metadata, ...status ? { status } : {} };
600
649
  if (status && status >= 500) return logger.error(message, payload);
@@ -607,6 +656,7 @@ function logByStatus2(logger, message, status, metadata) {
607
656
  var CommentHandler = class _CommentHandler {
608
657
  static HEADER_NAME = "UbiquityOS";
609
658
  _lastCommentId = { reviewCommentId: null, issueCommentId: null };
659
+ _commandResponsePolicyApplied = false;
610
660
  async _updateIssueComment(context, params) {
611
661
  if (!this._lastCommentId.issueCommentId) {
612
662
  throw context.logger.error("issueCommentId is missing");
@@ -661,6 +711,11 @@ var CommentHandler = class _CommentHandler {
661
711
  _getCommentId(context) {
662
712
  return "pull_request" in context.payload && "comment" in context.payload ? context.payload.comment.id : void 0;
663
713
  }
714
+ _getCommentNodeId(context) {
715
+ const payload = context.payload;
716
+ const nodeId = payload.comment?.node_id;
717
+ return typeof nodeId === "string" && nodeId.trim() ? nodeId : null;
718
+ }
664
719
  _extractIssueContext(context) {
665
720
  if (!("repository" in context.payload) || !context.payload.repository?.owner?.login) {
666
721
  return null;
@@ -674,6 +729,86 @@ var CommentHandler = class _CommentHandler {
674
729
  repo: context.payload.repository.name
675
730
  };
676
731
  }
732
+ _extractIssueLocator(context) {
733
+ if (!("issue" in context.payload) && !("pull_request" in context.payload)) {
734
+ return null;
735
+ }
736
+ const issueContext = this._extractIssueContext(context);
737
+ if (!issueContext) return null;
738
+ return {
739
+ owner: issueContext.owner,
740
+ repo: issueContext.repo,
741
+ issueNumber: issueContext.issueNumber
742
+ };
743
+ }
744
+ _shouldApplyCommandResponsePolicy(context) {
745
+ const payload = context;
746
+ return Boolean(payload.command);
747
+ }
748
+ _isCommandResponseComment(body) {
749
+ return typeof body === "string" && body.includes(COMMAND_RESPONSE_MARKER);
750
+ }
751
+ _getGraphqlClient(context) {
752
+ const graphql = context.octokit.graphql;
753
+ return typeof graphql === "function" ? graphql : null;
754
+ }
755
+ async _fetchRecentComments(context, locator, last = COMMAND_RESPONSE_COMMENT_LIMIT) {
756
+ const graphql = this._getGraphqlClient(context);
757
+ if (!graphql) return [];
758
+ try {
759
+ const data = await graphql(RECENT_COMMENTS_QUERY, {
760
+ owner: locator.owner,
761
+ repo: locator.repo,
762
+ number: locator.issueNumber,
763
+ last
764
+ });
765
+ const nodes = data.repository?.issueOrPullRequest?.comments?.nodes ?? [];
766
+ return nodes.filter((node) => Boolean(node));
767
+ } catch (error) {
768
+ context.logger.debug("Failed to fetch recent comments (non-fatal)", { err: error });
769
+ return [];
770
+ }
771
+ }
772
+ _findPreviousCommandResponseComment(comments, currentCommentId) {
773
+ for (let idx = comments.length - 1; idx >= 0; idx -= 1) {
774
+ const comment = comments[idx];
775
+ if (!comment) continue;
776
+ if (currentCommentId && comment.id === currentCommentId) continue;
777
+ if (this._isCommandResponseComment(comment.body)) {
778
+ return comment;
779
+ }
780
+ }
781
+ return null;
782
+ }
783
+ async _minimizeComment(context, commentNodeId, classifier = "RESOLVED") {
784
+ const graphql = this._getGraphqlClient(context);
785
+ if (!graphql) return;
786
+ try {
787
+ await graphql(MINIMIZE_COMMENT_MUTATION, {
788
+ id: commentNodeId,
789
+ classifier
790
+ });
791
+ } catch (error) {
792
+ context.logger.debug("Failed to minimize comment (non-fatal)", { err: error, commentNodeId });
793
+ }
794
+ }
795
+ async _applyCommandResponsePolicy(context) {
796
+ if (this._commandResponsePolicyApplied) return;
797
+ this._commandResponsePolicyApplied = true;
798
+ if (!this._shouldApplyCommandResponsePolicy(context)) return;
799
+ const locator = this._extractIssueLocator(context);
800
+ const commentNodeId = this._getCommentNodeId(context);
801
+ const comments = locator ? await this._fetchRecentComments(context, locator) : [];
802
+ const current = commentNodeId ? comments.find((comment) => comment.id === commentNodeId) : null;
803
+ const currentIsMinimized = current?.isMinimized ?? false;
804
+ if (commentNodeId && !currentIsMinimized) {
805
+ await this._minimizeComment(context, commentNodeId);
806
+ }
807
+ const previous = this._findPreviousCommandResponseComment(comments, commentNodeId);
808
+ if (previous && !previous.isMinimized) {
809
+ await this._minimizeComment(context, previous.id);
810
+ }
811
+ }
677
812
  _processMessage(context, message) {
678
813
  if (message instanceof Error) {
679
814
  const metadata2 = {
@@ -725,7 +860,9 @@ var CommentHandler = class _CommentHandler {
725
860
  }
726
861
  _createCommentBody(context, message, options) {
727
862
  const { metadata, logMessage } = this._processMessage(context, message);
728
- const { header, jsonPretty } = this._createMetadataContent(context, metadata);
863
+ const shouldTagCommandResponse = options?.commentKind && typeof metadata === "object" && metadata !== null && !("commentKind" in metadata);
864
+ const metadataWithKind = shouldTagCommandResponse ? { ...metadata, commentKind: options?.commentKind } : metadata;
865
+ const { header, jsonPretty } = this._createMetadataContent(context, metadataWithKind);
729
866
  const metadataContent = this._formatMetadataContent(logMessage, header, jsonPretty);
730
867
  return `${options?.raw ? logMessage?.raw : logMessage?.diff}
731
868
 
@@ -733,12 +870,17 @@ ${metadataContent}
733
870
  `;
734
871
  }
735
872
  async postComment(context, message, options = { updateComment: true, raw: false }) {
873
+ await this._applyCommandResponsePolicy(context);
736
874
  const issueContext = this._extractIssueContext(context);
737
875
  if (!issueContext) {
738
876
  context.logger.warn("Cannot post comment: missing issue context in payload");
739
877
  return null;
740
878
  }
741
- const body = this._createCommentBody(context, message, options);
879
+ const shouldTagCommandResponse = this._shouldApplyCommandResponsePolicy(context);
880
+ const body = this._createCommentBody(context, message, {
881
+ ...options,
882
+ commentKind: options.commentKind ?? (shouldTagCommandResponse ? COMMAND_RESPONSE_KIND : void 0)
883
+ });
742
884
  const { issueNumber, commentId, owner, repo } = issueContext;
743
885
  const params = { owner, repo, body, issueNumber };
744
886
  if (options.updateComment) {
@@ -1136,12 +1278,12 @@ function cleanMarkdown(md, options = {}) {
1136
1278
  const segments = [];
1137
1279
  let lastIndex = 0;
1138
1280
  const matches = [...md.matchAll(codeBlockRegex)];
1139
- for (const match of matches) {
1140
- if (match.index > lastIndex) {
1141
- segments.push(processSegment(md.slice(lastIndex, match.index), tags, shouldCollapseEmptyLines));
1281
+ for (const match2 of matches) {
1282
+ if (match2.index > lastIndex) {
1283
+ segments.push(processSegment(md.slice(lastIndex, match2.index), tags, shouldCollapseEmptyLines));
1142
1284
  }
1143
- segments.push(match[0]);
1144
- lastIndex = match.index + match[0].length;
1285
+ segments.push(match2[0]);
1286
+ lastIndex = match2.index + match2[0].length;
1145
1287
  }
1146
1288
  if (lastIndex < md.length) {
1147
1289
  segments.push(processSegment(md.slice(lastIndex), tags, shouldCollapseEmptyLines));
@@ -1184,7 +1326,7 @@ function processSegment(segment, extraTags, shouldCollapseEmptyLines) {
1184
1326
  // src/server.ts
1185
1327
  import { Value as Value4 } from "@sinclair/typebox/value";
1186
1328
 
1187
- // ../../node_modules/hono/dist/compose.js
1329
+ // ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/compose.js
1188
1330
  var compose = (middleware, onError, onNotFound) => {
1189
1331
  return (context, next) => {
1190
1332
  let index = -1;
@@ -1228,10 +1370,43 @@ var compose = (middleware, onError, onNotFound) => {
1228
1370
  };
1229
1371
  };
1230
1372
 
1231
- // ../../node_modules/hono/dist/request/constants.js
1232
- var GET_MATCH_RESULT = Symbol();
1373
+ // ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/http-exception.js
1374
+ var HTTPException = class extends Error {
1375
+ res;
1376
+ status;
1377
+ /**
1378
+ * Creates an instance of `HTTPException`.
1379
+ * @param status - HTTP status code for the exception. Defaults to 500.
1380
+ * @param options - Additional options for the exception.
1381
+ */
1382
+ constructor(status = 500, options) {
1383
+ super(options?.message, { cause: options?.cause });
1384
+ this.res = options?.res;
1385
+ this.status = status;
1386
+ }
1387
+ /**
1388
+ * Returns the response object associated with the exception.
1389
+ * If a response object is not provided, a new response is created with the error message and status code.
1390
+ * @returns The response object.
1391
+ */
1392
+ getResponse() {
1393
+ if (this.res) {
1394
+ const newResponse = new Response(this.res.body, {
1395
+ status: this.status,
1396
+ headers: this.res.headers
1397
+ });
1398
+ return newResponse;
1399
+ }
1400
+ return new Response(this.message, {
1401
+ status: this.status
1402
+ });
1403
+ }
1404
+ };
1405
+
1406
+ // ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/request/constants.js
1407
+ var GET_MATCH_RESULT = /* @__PURE__ */ Symbol();
1233
1408
 
1234
- // ../../node_modules/hono/dist/utils/body.js
1409
+ // ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/utils/body.js
1235
1410
  var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
1236
1411
  const { all = false, dot = false } = options;
1237
1412
  const headers = request instanceof HonoRequest ? request.raw.headers : request.headers;
@@ -1300,7 +1475,7 @@ var handleParsingNestedValues = (form, key, value) => {
1300
1475
  });
1301
1476
  };
1302
1477
 
1303
- // ../../node_modules/hono/dist/utils/url.js
1478
+ // ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/utils/url.js
1304
1479
  var splitPath = (path) => {
1305
1480
  const paths = path.split("/");
1306
1481
  if (paths[0] === "") {
@@ -1315,9 +1490,9 @@ var splitRoutingPath = (routePath) => {
1315
1490
  };
1316
1491
  var extractGroupsFromPath = (path) => {
1317
1492
  const groups = [];
1318
- path = path.replace(/\{[^}]+\}/g, (match, index) => {
1493
+ path = path.replace(/\{[^}]+\}/g, (match2, index) => {
1319
1494
  const mark = `@${index}`;
1320
- groups.push([mark, match]);
1495
+ groups.push([mark, match2]);
1321
1496
  return mark;
1322
1497
  });
1323
1498
  return { groups, path };
@@ -1339,14 +1514,14 @@ var getPattern = (label, next) => {
1339
1514
  if (label === "*") {
1340
1515
  return "*";
1341
1516
  }
1342
- const match = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
1343
- if (match) {
1517
+ const match2 = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
1518
+ if (match2) {
1344
1519
  const cacheKey = `${label}#${next}`;
1345
1520
  if (!patternCache[cacheKey]) {
1346
- if (match[2]) {
1347
- patternCache[cacheKey] = next && next[0] !== ":" && next[0] !== "*" ? [cacheKey, match[1], new RegExp(`^${match[2]}(?=/${next})`)] : [label, match[1], new RegExp(`^${match[2]}$`)];
1521
+ if (match2[2]) {
1522
+ patternCache[cacheKey] = next && next[0] !== ":" && next[0] !== "*" ? [cacheKey, match2[1], new RegExp(`^${match2[2]}(?=/${next})`)] : [label, match2[1], new RegExp(`^${match2[2]}$`)];
1348
1523
  } else {
1349
- patternCache[cacheKey] = [label, match[1], true];
1524
+ patternCache[cacheKey] = [label, match2[1], true];
1350
1525
  }
1351
1526
  }
1352
1527
  return patternCache[cacheKey];
@@ -1357,11 +1532,11 @@ var tryDecode = (str, decoder) => {
1357
1532
  try {
1358
1533
  return decoder(str);
1359
1534
  } catch {
1360
- return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match) => {
1535
+ return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match2) => {
1361
1536
  try {
1362
- return decoder(match);
1537
+ return decoder(match2);
1363
1538
  } catch {
1364
- return match;
1539
+ return match2;
1365
1540
  }
1366
1541
  });
1367
1542
  }
@@ -1369,10 +1544,7 @@ var tryDecode = (str, decoder) => {
1369
1544
  var tryDecodeURI = (str) => tryDecode(str, decodeURI);
1370
1545
  var getPath = (request) => {
1371
1546
  const url = request.url;
1372
- const start = url.indexOf(
1373
- "/",
1374
- url.charCodeAt(9) === 58 ? 13 : 8
1375
- );
1547
+ const start = url.indexOf("/", url.indexOf(":") + 4);
1376
1548
  let i = start;
1377
1549
  for (; i < url.length; i++) {
1378
1550
  const charCode = url.charCodeAt(i);
@@ -1435,9 +1607,12 @@ var _decodeURI = (value) => {
1435
1607
  var _getQueryParam = (url, key, multiple) => {
1436
1608
  let encoded;
1437
1609
  if (!multiple && key && !/[%+]/.test(key)) {
1438
- let keyIndex2 = url.indexOf(`?${key}`, 8);
1610
+ let keyIndex2 = url.indexOf("?", 8);
1439
1611
  if (keyIndex2 === -1) {
1440
- keyIndex2 = url.indexOf(`&${key}`, 8);
1612
+ return void 0;
1613
+ }
1614
+ if (!url.startsWith(key, keyIndex2 + 1)) {
1615
+ keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
1441
1616
  }
1442
1617
  while (keyIndex2 !== -1) {
1443
1618
  const trailingKeyCode = url.charCodeAt(keyIndex2 + key.length + 1);
@@ -1502,13 +1677,40 @@ var getQueryParams = (url, key) => {
1502
1677
  };
1503
1678
  var decodeURIComponent_ = decodeURIComponent;
1504
1679
 
1505
- // ../../node_modules/hono/dist/request.js
1680
+ // ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/request.js
1506
1681
  var tryDecodeURIComponent = (str) => tryDecode(str, decodeURIComponent_);
1507
1682
  var HonoRequest = class {
1683
+ /**
1684
+ * `.raw` can get the raw Request object.
1685
+ *
1686
+ * @see {@link https://hono.dev/docs/api/request#raw}
1687
+ *
1688
+ * @example
1689
+ * ```ts
1690
+ * // For Cloudflare Workers
1691
+ * app.post('/', async (c) => {
1692
+ * const metadata = c.req.raw.cf?.hostMetadata?
1693
+ * ...
1694
+ * })
1695
+ * ```
1696
+ */
1508
1697
  raw;
1509
1698
  #validatedData;
1699
+ // Short name of validatedData
1510
1700
  #matchResult;
1511
1701
  routeIndex = 0;
1702
+ /**
1703
+ * `.path` can get the pathname of the request.
1704
+ *
1705
+ * @see {@link https://hono.dev/docs/api/request#path}
1706
+ *
1707
+ * @example
1708
+ * ```ts
1709
+ * app.get('/about/me', (c) => {
1710
+ * const pathname = c.req.path // `/about/me`
1711
+ * })
1712
+ * ```
1713
+ */
1512
1714
  path;
1513
1715
  bodyCache = {};
1514
1716
  constructor(request, path = "/", matchResult = [[]]) {
@@ -1523,14 +1725,14 @@ var HonoRequest = class {
1523
1725
  #getDecodedParam(key) {
1524
1726
  const paramKey = this.#matchResult[0][this.routeIndex][1][key];
1525
1727
  const param = this.#getParamValue(paramKey);
1526
- return param ? /\%/.test(param) ? tryDecodeURIComponent(param) : param : void 0;
1728
+ return param && /\%/.test(param) ? tryDecodeURIComponent(param) : param;
1527
1729
  }
1528
1730
  #getAllDecodedParams() {
1529
1731
  const decoded = {};
1530
1732
  const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]);
1531
1733
  for (const key of keys) {
1532
1734
  const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
1533
- if (value && typeof value === "string") {
1735
+ if (value !== void 0) {
1534
1736
  decoded[key] = /\%/.test(value) ? tryDecodeURIComponent(value) : value;
1535
1737
  }
1536
1738
  }
@@ -1575,45 +1777,175 @@ var HonoRequest = class {
1575
1777
  }
1576
1778
  return bodyCache[key] = raw2[key]();
1577
1779
  };
1780
+ /**
1781
+ * `.json()` can parse Request body of type `application/json`
1782
+ *
1783
+ * @see {@link https://hono.dev/docs/api/request#json}
1784
+ *
1785
+ * @example
1786
+ * ```ts
1787
+ * app.post('/entry', async (c) => {
1788
+ * const body = await c.req.json()
1789
+ * })
1790
+ * ```
1791
+ */
1578
1792
  json() {
1579
1793
  return this.#cachedBody("text").then((text) => JSON.parse(text));
1580
1794
  }
1795
+ /**
1796
+ * `.text()` can parse Request body of type `text/plain`
1797
+ *
1798
+ * @see {@link https://hono.dev/docs/api/request#text}
1799
+ *
1800
+ * @example
1801
+ * ```ts
1802
+ * app.post('/entry', async (c) => {
1803
+ * const body = await c.req.text()
1804
+ * })
1805
+ * ```
1806
+ */
1581
1807
  text() {
1582
1808
  return this.#cachedBody("text");
1583
1809
  }
1810
+ /**
1811
+ * `.arrayBuffer()` parse Request body as an `ArrayBuffer`
1812
+ *
1813
+ * @see {@link https://hono.dev/docs/api/request#arraybuffer}
1814
+ *
1815
+ * @example
1816
+ * ```ts
1817
+ * app.post('/entry', async (c) => {
1818
+ * const body = await c.req.arrayBuffer()
1819
+ * })
1820
+ * ```
1821
+ */
1584
1822
  arrayBuffer() {
1585
1823
  return this.#cachedBody("arrayBuffer");
1586
1824
  }
1825
+ /**
1826
+ * Parses the request body as a `Blob`.
1827
+ * @example
1828
+ * ```ts
1829
+ * app.post('/entry', async (c) => {
1830
+ * const body = await c.req.blob();
1831
+ * });
1832
+ * ```
1833
+ * @see https://hono.dev/docs/api/request#blob
1834
+ */
1587
1835
  blob() {
1588
1836
  return this.#cachedBody("blob");
1589
1837
  }
1838
+ /**
1839
+ * Parses the request body as `FormData`.
1840
+ * @example
1841
+ * ```ts
1842
+ * app.post('/entry', async (c) => {
1843
+ * const body = await c.req.formData();
1844
+ * });
1845
+ * ```
1846
+ * @see https://hono.dev/docs/api/request#formdata
1847
+ */
1590
1848
  formData() {
1591
1849
  return this.#cachedBody("formData");
1592
1850
  }
1851
+ /**
1852
+ * Adds validated data to the request.
1853
+ *
1854
+ * @param target - The target of the validation.
1855
+ * @param data - The validated data to add.
1856
+ */
1593
1857
  addValidatedData(target, data) {
1594
1858
  this.#validatedData[target] = data;
1595
1859
  }
1596
1860
  valid(target) {
1597
1861
  return this.#validatedData[target];
1598
1862
  }
1863
+ /**
1864
+ * `.url()` can get the request url strings.
1865
+ *
1866
+ * @see {@link https://hono.dev/docs/api/request#url}
1867
+ *
1868
+ * @example
1869
+ * ```ts
1870
+ * app.get('/about/me', (c) => {
1871
+ * const url = c.req.url // `http://localhost:8787/about/me`
1872
+ * ...
1873
+ * })
1874
+ * ```
1875
+ */
1599
1876
  get url() {
1600
1877
  return this.raw.url;
1601
1878
  }
1879
+ /**
1880
+ * `.method()` can get the method name of the request.
1881
+ *
1882
+ * @see {@link https://hono.dev/docs/api/request#method}
1883
+ *
1884
+ * @example
1885
+ * ```ts
1886
+ * app.get('/about/me', (c) => {
1887
+ * const method = c.req.method // `GET`
1888
+ * })
1889
+ * ```
1890
+ */
1602
1891
  get method() {
1603
1892
  return this.raw.method;
1604
1893
  }
1605
1894
  get [GET_MATCH_RESULT]() {
1606
1895
  return this.#matchResult;
1607
1896
  }
1897
+ /**
1898
+ * `.matchedRoutes()` can return a matched route in the handler
1899
+ *
1900
+ * @deprecated
1901
+ *
1902
+ * Use matchedRoutes helper defined in "hono/route" instead.
1903
+ *
1904
+ * @see {@link https://hono.dev/docs/api/request#matchedroutes}
1905
+ *
1906
+ * @example
1907
+ * ```ts
1908
+ * app.use('*', async function logger(c, next) {
1909
+ * await next()
1910
+ * c.req.matchedRoutes.forEach(({ handler, method, path }, i) => {
1911
+ * const name = handler.name || (handler.length < 2 ? '[handler]' : '[middleware]')
1912
+ * console.log(
1913
+ * method,
1914
+ * ' ',
1915
+ * path,
1916
+ * ' '.repeat(Math.max(10 - path.length, 0)),
1917
+ * name,
1918
+ * i === c.req.routeIndex ? '<- respond from here' : ''
1919
+ * )
1920
+ * })
1921
+ * })
1922
+ * ```
1923
+ */
1608
1924
  get matchedRoutes() {
1609
1925
  return this.#matchResult[0].map(([[, route]]) => route);
1610
1926
  }
1927
+ /**
1928
+ * `routePath()` can retrieve the path registered within the handler
1929
+ *
1930
+ * @deprecated
1931
+ *
1932
+ * Use routePath helper defined in "hono/route" instead.
1933
+ *
1934
+ * @see {@link https://hono.dev/docs/api/request#routepath}
1935
+ *
1936
+ * @example
1937
+ * ```ts
1938
+ * app.get('/posts/:id', (c) => {
1939
+ * return c.json({ path: c.req.routePath })
1940
+ * })
1941
+ * ```
1942
+ */
1611
1943
  get routePath() {
1612
1944
  return this.#matchResult[0].map(([[, route]]) => route)[this.routeIndex].path;
1613
1945
  }
1614
1946
  };
1615
1947
 
1616
- // ../../node_modules/hono/dist/utils/html.js
1948
+ // ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/utils/html.js
1617
1949
  var HtmlEscapedCallbackPhase = {
1618
1950
  Stringify: 1,
1619
1951
  BeforeStream: 2,
@@ -1655,7 +1987,7 @@ var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) =>
1655
1987
  }
1656
1988
  };
1657
1989
 
1658
- // ../../node_modules/hono/dist/context.js
1990
+ // ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/context.js
1659
1991
  var TEXT_PLAIN = "text/plain; charset=UTF-8";
1660
1992
  var setDefaultContentType = (contentType, headers) => {
1661
1993
  return {
@@ -1666,9 +1998,37 @@ var setDefaultContentType = (contentType, headers) => {
1666
1998
  var Context = class {
1667
1999
  #rawRequest;
1668
2000
  #req;
2001
+ /**
2002
+ * `.env` can get bindings (environment variables, secrets, KV namespaces, D1 database, R2 bucket etc.) in Cloudflare Workers.
2003
+ *
2004
+ * @see {@link https://hono.dev/docs/api/context#env}
2005
+ *
2006
+ * @example
2007
+ * ```ts
2008
+ * // Environment object for Cloudflare Workers
2009
+ * app.get('*', async c => {
2010
+ * const counter = c.env.COUNTER
2011
+ * })
2012
+ * ```
2013
+ */
1669
2014
  env = {};
1670
2015
  #var;
1671
2016
  finalized = false;
2017
+ /**
2018
+ * `.error` can get the error object from the middleware if the Handler throws an error.
2019
+ *
2020
+ * @see {@link https://hono.dev/docs/api/context#error}
2021
+ *
2022
+ * @example
2023
+ * ```ts
2024
+ * app.use('*', async (c, next) => {
2025
+ * await next()
2026
+ * if (c.error) {
2027
+ * // do something...
2028
+ * }
2029
+ * })
2030
+ * ```
2031
+ */
1672
2032
  error;
1673
2033
  #status;
1674
2034
  #executionCtx;
@@ -1679,6 +2039,12 @@ var Context = class {
1679
2039
  #preparedHeaders;
1680
2040
  #matchResult;
1681
2041
  #path;
2042
+ /**
2043
+ * Creates an instance of the Context class.
2044
+ *
2045
+ * @param req - The Request object.
2046
+ * @param options - Optional configuration options for the context.
2047
+ */
1682
2048
  constructor(req, options) {
1683
2049
  this.#rawRequest = req;
1684
2050
  if (options) {
@@ -1689,10 +2055,19 @@ var Context = class {
1689
2055
  this.#matchResult = options.matchResult;
1690
2056
  }
1691
2057
  }
2058
+ /**
2059
+ * `.req` is the instance of {@link HonoRequest}.
2060
+ */
1692
2061
  get req() {
1693
2062
  this.#req ??= new HonoRequest(this.#rawRequest, this.#path, this.#matchResult);
1694
2063
  return this.#req;
1695
2064
  }
2065
+ /**
2066
+ * @see {@link https://hono.dev/docs/api/context#event}
2067
+ * The FetchEvent associated with the current request.
2068
+ *
2069
+ * @throws Will throw an error if the context does not have a FetchEvent.
2070
+ */
1696
2071
  get event() {
1697
2072
  if (this.#executionCtx && "respondWith" in this.#executionCtx) {
1698
2073
  return this.#executionCtx;
@@ -1700,6 +2075,12 @@ var Context = class {
1700
2075
  throw Error("This context has no FetchEvent");
1701
2076
  }
1702
2077
  }
2078
+ /**
2079
+ * @see {@link https://hono.dev/docs/api/context#executionctx}
2080
+ * The ExecutionContext associated with the current request.
2081
+ *
2082
+ * @throws Will throw an error if the context does not have an ExecutionContext.
2083
+ */
1703
2084
  get executionCtx() {
1704
2085
  if (this.#executionCtx) {
1705
2086
  return this.#executionCtx;
@@ -1707,11 +2088,20 @@ var Context = class {
1707
2088
  throw Error("This context has no ExecutionContext");
1708
2089
  }
1709
2090
  }
2091
+ /**
2092
+ * @see {@link https://hono.dev/docs/api/context#res}
2093
+ * The Response object for the current request.
2094
+ */
1710
2095
  get res() {
1711
2096
  return this.#res ||= new Response(null, {
1712
2097
  headers: this.#preparedHeaders ??= new Headers()
1713
2098
  });
1714
2099
  }
2100
+ /**
2101
+ * Sets the Response object for the current request.
2102
+ *
2103
+ * @param _res - The Response object to set.
2104
+ */
1715
2105
  set res(_res) {
1716
2106
  if (this.#res && _res) {
1717
2107
  _res = new Response(_res.body, _res);
@@ -1733,15 +2123,75 @@ var Context = class {
1733
2123
  this.#res = _res;
1734
2124
  this.finalized = true;
1735
2125
  }
2126
+ /**
2127
+ * `.render()` can create a response within a layout.
2128
+ *
2129
+ * @see {@link https://hono.dev/docs/api/context#render-setrenderer}
2130
+ *
2131
+ * @example
2132
+ * ```ts
2133
+ * app.get('/', (c) => {
2134
+ * return c.render('Hello!')
2135
+ * })
2136
+ * ```
2137
+ */
1736
2138
  render = (...args) => {
1737
2139
  this.#renderer ??= (content) => this.html(content);
1738
2140
  return this.#renderer(...args);
1739
2141
  };
2142
+ /**
2143
+ * Sets the layout for the response.
2144
+ *
2145
+ * @param layout - The layout to set.
2146
+ * @returns The layout function.
2147
+ */
1740
2148
  setLayout = (layout) => this.#layout = layout;
2149
+ /**
2150
+ * Gets the current layout for the response.
2151
+ *
2152
+ * @returns The current layout function.
2153
+ */
1741
2154
  getLayout = () => this.#layout;
2155
+ /**
2156
+ * `.setRenderer()` can set the layout in the custom middleware.
2157
+ *
2158
+ * @see {@link https://hono.dev/docs/api/context#render-setrenderer}
2159
+ *
2160
+ * @example
2161
+ * ```tsx
2162
+ * app.use('*', async (c, next) => {
2163
+ * c.setRenderer((content) => {
2164
+ * return c.html(
2165
+ * <html>
2166
+ * <body>
2167
+ * <p>{content}</p>
2168
+ * </body>
2169
+ * </html>
2170
+ * )
2171
+ * })
2172
+ * await next()
2173
+ * })
2174
+ * ```
2175
+ */
1742
2176
  setRenderer = (renderer) => {
1743
2177
  this.#renderer = renderer;
1744
2178
  };
2179
+ /**
2180
+ * `.header()` can set headers.
2181
+ *
2182
+ * @see {@link https://hono.dev/docs/api/context#header}
2183
+ *
2184
+ * @example
2185
+ * ```ts
2186
+ * app.get('/welcome', (c) => {
2187
+ * // Set headers
2188
+ * c.header('X-Message', 'Hello!')
2189
+ * c.header('Content-Type', 'text/plain')
2190
+ *
2191
+ * return c.body('Thank you for coming')
2192
+ * })
2193
+ * ```
2194
+ */
1745
2195
  header = (name, value, options) => {
1746
2196
  if (this.finalized) {
1747
2197
  this.#res = new Response(this.#res.body, this.#res);
@@ -1758,13 +2208,50 @@ var Context = class {
1758
2208
  status = (status) => {
1759
2209
  this.#status = status;
1760
2210
  };
2211
+ /**
2212
+ * `.set()` can set the value specified by the key.
2213
+ *
2214
+ * @see {@link https://hono.dev/docs/api/context#set-get}
2215
+ *
2216
+ * @example
2217
+ * ```ts
2218
+ * app.use('*', async (c, next) => {
2219
+ * c.set('message', 'Hono is hot!!')
2220
+ * await next()
2221
+ * })
2222
+ * ```
2223
+ */
1761
2224
  set = (key, value) => {
1762
2225
  this.#var ??= /* @__PURE__ */ new Map();
1763
2226
  this.#var.set(key, value);
1764
2227
  };
2228
+ /**
2229
+ * `.get()` can use the value specified by the key.
2230
+ *
2231
+ * @see {@link https://hono.dev/docs/api/context#set-get}
2232
+ *
2233
+ * @example
2234
+ * ```ts
2235
+ * app.get('/', (c) => {
2236
+ * const message = c.get('message')
2237
+ * return c.text(`The message is "${message}"`)
2238
+ * })
2239
+ * ```
2240
+ */
1765
2241
  get = (key) => {
1766
2242
  return this.#var ? this.#var.get(key) : void 0;
1767
2243
  };
2244
+ /**
2245
+ * `.var` can access the value of a variable.
2246
+ *
2247
+ * @see {@link https://hono.dev/docs/api/context#var}
2248
+ *
2249
+ * @example
2250
+ * ```ts
2251
+ * const result = c.var.client.oneMethod()
2252
+ * ```
2253
+ */
2254
+ // c.var.propName is a read-only
1768
2255
  get var() {
1769
2256
  if (!this.#var) {
1770
2257
  return {};
@@ -1799,7 +2286,40 @@ var Context = class {
1799
2286
  return new Response(data, { status, headers: responseHeaders });
1800
2287
  }
1801
2288
  newResponse = (...args) => this.#newResponse(...args);
2289
+ /**
2290
+ * `.body()` can return the HTTP response.
2291
+ * You can set headers with `.header()` and set HTTP status code with `.status`.
2292
+ * This can also be set in `.text()`, `.json()` and so on.
2293
+ *
2294
+ * @see {@link https://hono.dev/docs/api/context#body}
2295
+ *
2296
+ * @example
2297
+ * ```ts
2298
+ * app.get('/welcome', (c) => {
2299
+ * // Set headers
2300
+ * c.header('X-Message', 'Hello!')
2301
+ * c.header('Content-Type', 'text/plain')
2302
+ * // Set HTTP status code
2303
+ * c.status(201)
2304
+ *
2305
+ * // Return the response body
2306
+ * return c.body('Thank you for coming')
2307
+ * })
2308
+ * ```
2309
+ */
1802
2310
  body = (data, arg, headers) => this.#newResponse(data, arg, headers);
2311
+ /**
2312
+ * `.text()` can render text as `Content-Type:text/plain`.
2313
+ *
2314
+ * @see {@link https://hono.dev/docs/api/context#text}
2315
+ *
2316
+ * @example
2317
+ * ```ts
2318
+ * app.get('/say', (c) => {
2319
+ * return c.text('Hello!')
2320
+ * })
2321
+ * ```
2322
+ */
1803
2323
  text = (text, arg, headers) => {
1804
2324
  return !this.#preparedHeaders && !this.#status && !arg && !headers && !this.finalized ? new Response(text) : this.#newResponse(
1805
2325
  text,
@@ -1807,6 +2327,18 @@ var Context = class {
1807
2327
  setDefaultContentType(TEXT_PLAIN, headers)
1808
2328
  );
1809
2329
  };
2330
+ /**
2331
+ * `.json()` can render JSON as `Content-Type:application/json`.
2332
+ *
2333
+ * @see {@link https://hono.dev/docs/api/context#json}
2334
+ *
2335
+ * @example
2336
+ * ```ts
2337
+ * app.get('/api', (c) => {
2338
+ * return c.json({ message: 'Hello!' })
2339
+ * })
2340
+ * ```
2341
+ */
1810
2342
  json = (object, arg, headers) => {
1811
2343
  return this.#newResponse(
1812
2344
  JSON.stringify(object),
@@ -1818,21 +2350,50 @@ var Context = class {
1818
2350
  const res = (html2) => this.#newResponse(html2, arg, setDefaultContentType("text/html; charset=UTF-8", headers));
1819
2351
  return typeof html === "object" ? resolveCallback(html, HtmlEscapedCallbackPhase.Stringify, false, {}).then(res) : res(html);
1820
2352
  };
2353
+ /**
2354
+ * `.redirect()` can Redirect, default status code is 302.
2355
+ *
2356
+ * @see {@link https://hono.dev/docs/api/context#redirect}
2357
+ *
2358
+ * @example
2359
+ * ```ts
2360
+ * app.get('/redirect', (c) => {
2361
+ * return c.redirect('/')
2362
+ * })
2363
+ * app.get('/redirect-permanently', (c) => {
2364
+ * return c.redirect('/', 301)
2365
+ * })
2366
+ * ```
2367
+ */
1821
2368
  redirect = (location, status) => {
1822
2369
  const locationString = String(location);
1823
2370
  this.header(
1824
2371
  "Location",
2372
+ // Multibyes should be encoded
2373
+ // eslint-disable-next-line no-control-regex
1825
2374
  !/[^\x00-\xFF]/.test(locationString) ? locationString : encodeURI(locationString)
1826
2375
  );
1827
2376
  return this.newResponse(null, status ?? 302);
1828
2377
  };
2378
+ /**
2379
+ * `.notFound()` can return the Not Found Response.
2380
+ *
2381
+ * @see {@link https://hono.dev/docs/api/context#notfound}
2382
+ *
2383
+ * @example
2384
+ * ```ts
2385
+ * app.get('/notfound', (c) => {
2386
+ * return c.notFound()
2387
+ * })
2388
+ * ```
2389
+ */
1829
2390
  notFound = () => {
1830
2391
  this.#notFoundHandler ??= () => new Response();
1831
2392
  return this.#notFoundHandler(this);
1832
2393
  };
1833
2394
  };
1834
2395
 
1835
- // ../../node_modules/hono/dist/router.js
2396
+ // ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/router.js
1836
2397
  var METHOD_NAME_ALL = "ALL";
1837
2398
  var METHOD_NAME_ALL_LOWERCASE = "all";
1838
2399
  var METHODS = ["get", "post", "put", "delete", "options", "patch"];
@@ -1840,10 +2401,10 @@ var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is
1840
2401
  var UnsupportedPathError = class extends Error {
1841
2402
  };
1842
2403
 
1843
- // ../../node_modules/hono/dist/utils/constants.js
2404
+ // ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/utils/constants.js
1844
2405
  var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
1845
2406
 
1846
- // ../../node_modules/hono/dist/hono-base.js
2407
+ // ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/hono-base.js
1847
2408
  var notFoundHandler = (c) => {
1848
2409
  return c.text("404 Not Found", 404);
1849
2410
  };
@@ -1855,7 +2416,7 @@ var errorHandler = (err, c) => {
1855
2416
  console.error(err);
1856
2417
  return c.text("Internal Server Error", 500);
1857
2418
  };
1858
- var Hono = class {
2419
+ var Hono = class _Hono {
1859
2420
  get;
1860
2421
  post;
1861
2422
  put;
@@ -1865,8 +2426,13 @@ var Hono = class {
1865
2426
  all;
1866
2427
  on;
1867
2428
  use;
2429
+ /*
2430
+ This class is like an abstract class and does not have a router.
2431
+ To use it, inherit the class and implement router in the constructor.
2432
+ */
1868
2433
  router;
1869
2434
  getPath;
2435
+ // Cannot use `#` because it requires visibility at JavaScript runtime.
1870
2436
  _basePath = "/";
1871
2437
  #path = "/";
1872
2438
  routes = [];
@@ -1913,7 +2479,7 @@ var Hono = class {
1913
2479
  this.getPath = strict ?? true ? options.getPath ?? getPath : getPathNoStrict;
1914
2480
  }
1915
2481
  #clone() {
1916
- const clone = new Hono({
2482
+ const clone = new _Hono({
1917
2483
  router: this.router,
1918
2484
  getPath: this.getPath
1919
2485
  });
@@ -1923,7 +2489,26 @@ var Hono = class {
1923
2489
  return clone;
1924
2490
  }
1925
2491
  #notFoundHandler = notFoundHandler;
2492
+ // Cannot use `#` because it requires visibility at JavaScript runtime.
1926
2493
  errorHandler = errorHandler;
2494
+ /**
2495
+ * `.route()` allows grouping other Hono instance in routes.
2496
+ *
2497
+ * @see {@link https://hono.dev/docs/api/routing#grouping}
2498
+ *
2499
+ * @param {string} path - base Path
2500
+ * @param {Hono} app - other Hono instance
2501
+ * @returns {Hono} routed Hono instance
2502
+ *
2503
+ * @example
2504
+ * ```ts
2505
+ * const app = new Hono()
2506
+ * const app2 = new Hono()
2507
+ *
2508
+ * app2.get("/user", (c) => c.text("user"))
2509
+ * app.route("/api", app2) // GET /api/user
2510
+ * ```
2511
+ */
1927
2512
  route(path, app) {
1928
2513
  const subApp = this.basePath(path);
1929
2514
  app.routes.map((r) => {
@@ -1938,19 +2523,95 @@ var Hono = class {
1938
2523
  });
1939
2524
  return this;
1940
2525
  }
2526
+ /**
2527
+ * `.basePath()` allows base paths to be specified.
2528
+ *
2529
+ * @see {@link https://hono.dev/docs/api/routing#base-path}
2530
+ *
2531
+ * @param {string} path - base Path
2532
+ * @returns {Hono} changed Hono instance
2533
+ *
2534
+ * @example
2535
+ * ```ts
2536
+ * const api = new Hono().basePath('/api')
2537
+ * ```
2538
+ */
1941
2539
  basePath(path) {
1942
2540
  const subApp = this.#clone();
1943
2541
  subApp._basePath = mergePath(this._basePath, path);
1944
2542
  return subApp;
1945
2543
  }
2544
+ /**
2545
+ * `.onError()` handles an error and returns a customized Response.
2546
+ *
2547
+ * @see {@link https://hono.dev/docs/api/hono#error-handling}
2548
+ *
2549
+ * @param {ErrorHandler} handler - request Handler for error
2550
+ * @returns {Hono} changed Hono instance
2551
+ *
2552
+ * @example
2553
+ * ```ts
2554
+ * app.onError((err, c) => {
2555
+ * console.error(`${err}`)
2556
+ * return c.text('Custom Error Message', 500)
2557
+ * })
2558
+ * ```
2559
+ */
1946
2560
  onError = (handler) => {
1947
2561
  this.errorHandler = handler;
1948
2562
  return this;
1949
2563
  };
2564
+ /**
2565
+ * `.notFound()` allows you to customize a Not Found Response.
2566
+ *
2567
+ * @see {@link https://hono.dev/docs/api/hono#not-found}
2568
+ *
2569
+ * @param {NotFoundHandler} handler - request handler for not-found
2570
+ * @returns {Hono} changed Hono instance
2571
+ *
2572
+ * @example
2573
+ * ```ts
2574
+ * app.notFound((c) => {
2575
+ * return c.text('Custom 404 Message', 404)
2576
+ * })
2577
+ * ```
2578
+ */
1950
2579
  notFound = (handler) => {
1951
2580
  this.#notFoundHandler = handler;
1952
2581
  return this;
1953
2582
  };
2583
+ /**
2584
+ * `.mount()` allows you to mount applications built with other frameworks into your Hono application.
2585
+ *
2586
+ * @see {@link https://hono.dev/docs/api/hono#mount}
2587
+ *
2588
+ * @param {string} path - base Path
2589
+ * @param {Function} applicationHandler - other Request Handler
2590
+ * @param {MountOptions} [options] - options of `.mount()`
2591
+ * @returns {Hono} mounted Hono instance
2592
+ *
2593
+ * @example
2594
+ * ```ts
2595
+ * import { Router as IttyRouter } from 'itty-router'
2596
+ * import { Hono } from 'hono'
2597
+ * // Create itty-router application
2598
+ * const ittyRouter = IttyRouter()
2599
+ * // GET /itty-router/hello
2600
+ * ittyRouter.get('/hello', () => new Response('Hello from itty-router'))
2601
+ *
2602
+ * const app = new Hono()
2603
+ * app.mount('/itty-router', ittyRouter.handle)
2604
+ * ```
2605
+ *
2606
+ * @example
2607
+ * ```ts
2608
+ * const app = new Hono()
2609
+ * // Send the request to another application without modification.
2610
+ * app.mount('/app', anotherApp, {
2611
+ * replaceRequest: (req) => req,
2612
+ * })
2613
+ * ```
2614
+ */
1954
2615
  mount(path, applicationHandler, options) {
1955
2616
  let replaceRequest;
1956
2617
  let optionHandler;
@@ -2050,9 +2711,32 @@ var Hono = class {
2050
2711
  }
2051
2712
  })();
2052
2713
  }
2714
+ /**
2715
+ * `.fetch()` will be entry point of your app.
2716
+ *
2717
+ * @see {@link https://hono.dev/docs/api/hono#fetch}
2718
+ *
2719
+ * @param {Request} request - request Object of request
2720
+ * @param {Env} Env - env Object
2721
+ * @param {ExecutionContext} - context of execution
2722
+ * @returns {Response | Promise<Response>} response of request
2723
+ *
2724
+ */
2053
2725
  fetch = (request, ...rest) => {
2054
2726
  return this.#dispatch(request, rest[1], rest[0], request.method);
2055
2727
  };
2728
+ /**
2729
+ * `.request()` is a useful method for testing.
2730
+ * You can pass a URL or pathname to send a GET request.
2731
+ * app will return a Response object.
2732
+ * ```ts
2733
+ * test('GET /hello is ok', async () => {
2734
+ * const res = await app.request('/hello')
2735
+ * expect(res.status).toBe(200)
2736
+ * })
2737
+ * ```
2738
+ * @see https://hono.dev/docs/api/hono#request
2739
+ */
2056
2740
  request = (input, requestInit, Env, executionCtx) => {
2057
2741
  if (input instanceof Request) {
2058
2742
  return this.fetch(requestInit ? new Request(input, requestInit) : input, Env, executionCtx);
@@ -2067,6 +2751,23 @@ var Hono = class {
2067
2751
  executionCtx
2068
2752
  );
2069
2753
  };
2754
+ /**
2755
+ * `.fire()` automatically adds a global fetch event listener.
2756
+ * This can be useful for environments that adhere to the Service Worker API, such as non-ES module Cloudflare Workers.
2757
+ * @deprecated
2758
+ * Use `fire` from `hono/service-worker` instead.
2759
+ * ```ts
2760
+ * import { Hono } from 'hono'
2761
+ * import { fire } from 'hono/service-worker'
2762
+ *
2763
+ * const app = new Hono()
2764
+ * // ...
2765
+ * fire(app)
2766
+ * ```
2767
+ * @see https://hono.dev/docs/api/hono#fire
2768
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API
2769
+ * @see https://developers.cloudflare.com/workers/reference/migrate-to-module-workers/
2770
+ */
2070
2771
  fire = () => {
2071
2772
  addEventListener("fetch", (event) => {
2072
2773
  event.respondWith(this.#dispatch(event.request, event, void 0, event.request.method));
@@ -2074,11 +2775,32 @@ var Hono = class {
2074
2775
  };
2075
2776
  };
2076
2777
 
2077
- // ../../node_modules/hono/dist/router/reg-exp-router/node.js
2778
+ // ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/router/reg-exp-router/matcher.js
2779
+ var emptyParam = [];
2780
+ function match(method, path) {
2781
+ const matchers = this.buildAllMatchers();
2782
+ const match2 = ((method2, path2) => {
2783
+ const matcher = matchers[method2] || matchers[METHOD_NAME_ALL];
2784
+ const staticMatch = matcher[2][path2];
2785
+ if (staticMatch) {
2786
+ return staticMatch;
2787
+ }
2788
+ const match3 = path2.match(matcher[0]);
2789
+ if (!match3) {
2790
+ return [[], emptyParam];
2791
+ }
2792
+ const index = match3.indexOf("", 1);
2793
+ return [matcher[1][index], match3];
2794
+ });
2795
+ this.match = match2;
2796
+ return match2(method, path);
2797
+ }
2798
+
2799
+ // ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/router/reg-exp-router/node.js
2078
2800
  var LABEL_REG_EXP_STR = "[^/]+";
2079
2801
  var ONLY_WILDCARD_REG_EXP_STR = ".*";
2080
2802
  var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
2081
- var PATH_ERROR = Symbol();
2803
+ var PATH_ERROR = /* @__PURE__ */ Symbol();
2082
2804
  var regExpMetaChars = new Set(".\\+*[^]$()");
2083
2805
  function compareKey(a, b) {
2084
2806
  if (a.length === 1) {
@@ -2099,7 +2821,7 @@ function compareKey(a, b) {
2099
2821
  }
2100
2822
  return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length;
2101
2823
  }
2102
- var Node = class {
2824
+ var Node = class _Node {
2103
2825
  #index;
2104
2826
  #varIndex;
2105
2827
  #children = /* @__PURE__ */ Object.create(null);
@@ -2139,7 +2861,7 @@ var Node = class {
2139
2861
  if (pathErrorCheckOnly) {
2140
2862
  return;
2141
2863
  }
2142
- node = this.#children[regexpStr] = new Node();
2864
+ node = this.#children[regexpStr] = new _Node();
2143
2865
  if (name !== "") {
2144
2866
  node.#varIndex = context.varIndex++;
2145
2867
  }
@@ -2158,7 +2880,7 @@ var Node = class {
2158
2880
  if (pathErrorCheckOnly) {
2159
2881
  return;
2160
2882
  }
2161
- node = this.#children[token] = new Node();
2883
+ node = this.#children[token] = new _Node();
2162
2884
  }
2163
2885
  }
2164
2886
  node.insert(restTokens, index, paramMap, context, pathErrorCheckOnly);
@@ -2182,7 +2904,7 @@ var Node = class {
2182
2904
  }
2183
2905
  };
2184
2906
 
2185
- // ../../node_modules/hono/dist/router/reg-exp-router/trie.js
2907
+ // ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/router/reg-exp-router/trie.js
2186
2908
  var Trie = class {
2187
2909
  #context = { varIndex: 0 };
2188
2910
  #root = new Node();
@@ -2238,8 +2960,7 @@ var Trie = class {
2238
2960
  }
2239
2961
  };
2240
2962
 
2241
- // ../../node_modules/hono/dist/router/reg-exp-router/router.js
2242
- var emptyParam = [];
2963
+ // ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/router/reg-exp-router/router.js
2243
2964
  var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)];
2244
2965
  var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
2245
2966
  function buildWildcardRegExp(path) {
@@ -2386,30 +3107,14 @@ var RegExpRouter = class {
2386
3107
  });
2387
3108
  }
2388
3109
  }
2389
- match(method, path) {
2390
- clearWildcardRegExpCache();
2391
- const matchers = this.#buildAllMatchers();
2392
- this.match = (method2, path2) => {
2393
- const matcher = matchers[method2] || matchers[METHOD_NAME_ALL];
2394
- const staticMatch = matcher[2][path2];
2395
- if (staticMatch) {
2396
- return staticMatch;
2397
- }
2398
- const match = path2.match(matcher[0]);
2399
- if (!match) {
2400
- return [[], emptyParam];
2401
- }
2402
- const index = match.indexOf("", 1);
2403
- return [matcher[1][index], match];
2404
- };
2405
- return this.match(method, path);
2406
- }
2407
- #buildAllMatchers() {
3110
+ match = match;
3111
+ buildAllMatchers() {
2408
3112
  const matchers = /* @__PURE__ */ Object.create(null);
2409
3113
  Object.keys(this.#routes).concat(Object.keys(this.#middleware)).forEach((method) => {
2410
3114
  matchers[method] ||= this.#buildMatcher(method);
2411
3115
  });
2412
3116
  this.#middleware = this.#routes = void 0;
3117
+ clearWildcardRegExpCache();
2413
3118
  return matchers;
2414
3119
  }
2415
3120
  #buildMatcher(method) {
@@ -2434,7 +3139,7 @@ var RegExpRouter = class {
2434
3139
  }
2435
3140
  };
2436
3141
 
2437
- // ../../node_modules/hono/dist/router/smart-router/router.js
3142
+ // ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/router/smart-router/router.js
2438
3143
  var SmartRouter = class {
2439
3144
  name = "SmartRouter";
2440
3145
  #routers = [];
@@ -2489,9 +3194,9 @@ var SmartRouter = class {
2489
3194
  }
2490
3195
  };
2491
3196
 
2492
- // ../../node_modules/hono/dist/router/trie-router/node.js
3197
+ // ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/router/trie-router/node.js
2493
3198
  var emptyParams = /* @__PURE__ */ Object.create(null);
2494
- var Node2 = class {
3199
+ var Node2 = class _Node2 {
2495
3200
  #methods;
2496
3201
  #children;
2497
3202
  #patterns;
@@ -2524,7 +3229,7 @@ var Node2 = class {
2524
3229
  }
2525
3230
  continue;
2526
3231
  }
2527
- curNode.#children[key] = new Node2();
3232
+ curNode.#children[key] = new _Node2();
2528
3233
  if (pattern) {
2529
3234
  curNode.#patterns.push(pattern);
2530
3235
  possibleKeys.push(pattern[1]);
@@ -2647,7 +3352,7 @@ var Node2 = class {
2647
3352
  }
2648
3353
  };
2649
3354
 
2650
- // ../../node_modules/hono/dist/router/trie-router/router.js
3355
+ // ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/router/trie-router/router.js
2651
3356
  var TrieRouter = class {
2652
3357
  name = "TrieRouter";
2653
3358
  #node;
@@ -2669,8 +3374,13 @@ var TrieRouter = class {
2669
3374
  }
2670
3375
  };
2671
3376
 
2672
- // ../../node_modules/hono/dist/hono.js
3377
+ // ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/hono.js
2673
3378
  var Hono2 = class extends Hono {
3379
+ /**
3380
+ * Creates an instance of the Hono class.
3381
+ *
3382
+ * @param options - Optional configuration options for the Hono instance.
3383
+ */
2674
3384
  constructor(options = {}) {
2675
3385
  super(options);
2676
3386
  this.router = options.router ?? new SmartRouter({
@@ -2679,29 +3389,6 @@ var Hono2 = class extends Hono {
2679
3389
  }
2680
3390
  };
2681
3391
 
2682
- // ../../node_modules/hono/dist/http-exception.js
2683
- var HTTPException = class extends Error {
2684
- res;
2685
- status;
2686
- constructor(status = 500, options) {
2687
- super(options?.message, { cause: options?.cause });
2688
- this.res = options?.res;
2689
- this.status = status;
2690
- }
2691
- getResponse() {
2692
- if (this.res) {
2693
- const newResponse = new Response(this.res.body, {
2694
- status: this.status,
2695
- headers: this.res.headers
2696
- });
2697
- return newResponse;
2698
- }
2699
- return new Response(this.message, {
2700
- status: this.status
2701
- });
2702
- }
2703
- };
2704
-
2705
3392
  // src/server.ts
2706
3393
  async function handleError2(context, pluginOptions, error) {
2707
3394
  console.error(error);