@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/configuration.d.mts +1 -1
- package/dist/configuration.d.ts +1 -1
- package/dist/{context-Ckj1HMjz.d.mts → context-Dwl3aRX-.d.mts} +28 -0
- package/dist/{context-BE4WjJZf.d.ts → context-zLHgu52i.d.ts} +28 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +788 -101
- package/dist/index.mjs +788 -101
- package/dist/llm.d.mts +1 -1
- package/dist/llm.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -231,9 +231,9 @@ var Logs = class _Logs {
|
|
|
231
231
|
const stackLines = new Error().stack?.split("\n") || [];
|
|
232
232
|
if (stackLines.length > 3) {
|
|
233
233
|
const callerLine = stackLines[3];
|
|
234
|
-
const
|
|
235
|
-
if (
|
|
236
|
-
metadata.caller =
|
|
234
|
+
const match2 = callerLine.match(/at (\S+)/);
|
|
235
|
+
if (match2) {
|
|
236
|
+
metadata.caller = match2[1];
|
|
237
237
|
}
|
|
238
238
|
}
|
|
239
239
|
return metadata;
|
|
@@ -389,9 +389,9 @@ function getErrorStatus(err) {
|
|
|
389
389
|
if (Number.isFinite(parsed)) return parsed;
|
|
390
390
|
}
|
|
391
391
|
if (err instanceof Error) {
|
|
392
|
-
const
|
|
393
|
-
if (
|
|
394
|
-
const parsed = Number.parseInt(
|
|
392
|
+
const match2 = /LLM API error:\s*(\d{3})/i.exec(err.message);
|
|
393
|
+
if (match2) {
|
|
394
|
+
const parsed = Number.parseInt(match2[1], 10);
|
|
395
395
|
if (Number.isFinite(parsed)) return parsed;
|
|
396
396
|
}
|
|
397
397
|
}
|
|
@@ -429,7 +429,7 @@ function transformError(context, error) {
|
|
|
429
429
|
return logByStatus(context, String(error), { err: error });
|
|
430
430
|
}
|
|
431
431
|
|
|
432
|
-
// ../../node_modules/hono/dist/helper/adapter/index.js
|
|
432
|
+
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/helper/adapter/index.js
|
|
433
433
|
var env = (c, runtime) => {
|
|
434
434
|
const global = globalThis;
|
|
435
435
|
const globalEnv = global?.process?.env;
|
|
@@ -442,6 +442,7 @@ var env = (c, runtime) => {
|
|
|
442
442
|
return Deno.env.toObject();
|
|
443
443
|
},
|
|
444
444
|
workerd: () => c.env,
|
|
445
|
+
// On Fastly Compute, you can use the ConfigStore to manage user-defined data.
|
|
445
446
|
fastly: () => ({}),
|
|
446
447
|
other: () => ({})
|
|
447
448
|
};
|
|
@@ -636,6 +637,54 @@ function getPluginOptions(options) {
|
|
|
636
637
|
}
|
|
637
638
|
|
|
638
639
|
// src/comment.ts
|
|
640
|
+
var COMMAND_RESPONSE_KIND = "command-response";
|
|
641
|
+
var COMMAND_RESPONSE_MARKER = `"commentKind": "${COMMAND_RESPONSE_KIND}"`;
|
|
642
|
+
var COMMAND_RESPONSE_COMMENT_LIMIT = 50;
|
|
643
|
+
var RECENT_COMMENTS_QUERY = `
|
|
644
|
+
query($owner: String!, $repo: String!, $number: Int!, $last: Int!) {
|
|
645
|
+
repository(owner: $owner, name: $repo) {
|
|
646
|
+
issueOrPullRequest(number: $number) {
|
|
647
|
+
__typename
|
|
648
|
+
... on Issue {
|
|
649
|
+
comments(last: $last) {
|
|
650
|
+
nodes {
|
|
651
|
+
id
|
|
652
|
+
body
|
|
653
|
+
isMinimized
|
|
654
|
+
minimizedReason
|
|
655
|
+
author {
|
|
656
|
+
login
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
... on PullRequest {
|
|
662
|
+
comments(last: $last) {
|
|
663
|
+
nodes {
|
|
664
|
+
id
|
|
665
|
+
body
|
|
666
|
+
isMinimized
|
|
667
|
+
minimizedReason
|
|
668
|
+
author {
|
|
669
|
+
login
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
`;
|
|
678
|
+
var MINIMIZE_COMMENT_MUTATION = `
|
|
679
|
+
mutation($id: ID!, $classifier: ReportedContentClassifiers!) {
|
|
680
|
+
minimizeComment(input: { subjectId: $id, classifier: $classifier }) {
|
|
681
|
+
minimizedComment {
|
|
682
|
+
isMinimized
|
|
683
|
+
minimizedReason
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
`;
|
|
639
688
|
function logByStatus2(logger, message, status, metadata) {
|
|
640
689
|
const payload = { ...metadata, ...status ? { status } : {} };
|
|
641
690
|
if (status && status >= 500) return logger.error(message, payload);
|
|
@@ -648,6 +697,7 @@ function logByStatus2(logger, message, status, metadata) {
|
|
|
648
697
|
var CommentHandler = class _CommentHandler {
|
|
649
698
|
static HEADER_NAME = "UbiquityOS";
|
|
650
699
|
_lastCommentId = { reviewCommentId: null, issueCommentId: null };
|
|
700
|
+
_commandResponsePolicyApplied = false;
|
|
651
701
|
async _updateIssueComment(context, params) {
|
|
652
702
|
if (!this._lastCommentId.issueCommentId) {
|
|
653
703
|
throw context.logger.error("issueCommentId is missing");
|
|
@@ -702,6 +752,11 @@ var CommentHandler = class _CommentHandler {
|
|
|
702
752
|
_getCommentId(context) {
|
|
703
753
|
return "pull_request" in context.payload && "comment" in context.payload ? context.payload.comment.id : void 0;
|
|
704
754
|
}
|
|
755
|
+
_getCommentNodeId(context) {
|
|
756
|
+
const payload = context.payload;
|
|
757
|
+
const nodeId = payload.comment?.node_id;
|
|
758
|
+
return typeof nodeId === "string" && nodeId.trim() ? nodeId : null;
|
|
759
|
+
}
|
|
705
760
|
_extractIssueContext(context) {
|
|
706
761
|
if (!("repository" in context.payload) || !context.payload.repository?.owner?.login) {
|
|
707
762
|
return null;
|
|
@@ -715,6 +770,86 @@ var CommentHandler = class _CommentHandler {
|
|
|
715
770
|
repo: context.payload.repository.name
|
|
716
771
|
};
|
|
717
772
|
}
|
|
773
|
+
_extractIssueLocator(context) {
|
|
774
|
+
if (!("issue" in context.payload) && !("pull_request" in context.payload)) {
|
|
775
|
+
return null;
|
|
776
|
+
}
|
|
777
|
+
const issueContext = this._extractIssueContext(context);
|
|
778
|
+
if (!issueContext) return null;
|
|
779
|
+
return {
|
|
780
|
+
owner: issueContext.owner,
|
|
781
|
+
repo: issueContext.repo,
|
|
782
|
+
issueNumber: issueContext.issueNumber
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
_shouldApplyCommandResponsePolicy(context) {
|
|
786
|
+
const payload = context;
|
|
787
|
+
return Boolean(payload.command);
|
|
788
|
+
}
|
|
789
|
+
_isCommandResponseComment(body) {
|
|
790
|
+
return typeof body === "string" && body.includes(COMMAND_RESPONSE_MARKER);
|
|
791
|
+
}
|
|
792
|
+
_getGraphqlClient(context) {
|
|
793
|
+
const graphql = context.octokit.graphql;
|
|
794
|
+
return typeof graphql === "function" ? graphql : null;
|
|
795
|
+
}
|
|
796
|
+
async _fetchRecentComments(context, locator, last = COMMAND_RESPONSE_COMMENT_LIMIT) {
|
|
797
|
+
const graphql = this._getGraphqlClient(context);
|
|
798
|
+
if (!graphql) return [];
|
|
799
|
+
try {
|
|
800
|
+
const data = await graphql(RECENT_COMMENTS_QUERY, {
|
|
801
|
+
owner: locator.owner,
|
|
802
|
+
repo: locator.repo,
|
|
803
|
+
number: locator.issueNumber,
|
|
804
|
+
last
|
|
805
|
+
});
|
|
806
|
+
const nodes = data.repository?.issueOrPullRequest?.comments?.nodes ?? [];
|
|
807
|
+
return nodes.filter((node) => Boolean(node));
|
|
808
|
+
} catch (error) {
|
|
809
|
+
context.logger.debug("Failed to fetch recent comments (non-fatal)", { err: error });
|
|
810
|
+
return [];
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
_findPreviousCommandResponseComment(comments, currentCommentId) {
|
|
814
|
+
for (let idx = comments.length - 1; idx >= 0; idx -= 1) {
|
|
815
|
+
const comment = comments[idx];
|
|
816
|
+
if (!comment) continue;
|
|
817
|
+
if (currentCommentId && comment.id === currentCommentId) continue;
|
|
818
|
+
if (this._isCommandResponseComment(comment.body)) {
|
|
819
|
+
return comment;
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
return null;
|
|
823
|
+
}
|
|
824
|
+
async _minimizeComment(context, commentNodeId, classifier = "RESOLVED") {
|
|
825
|
+
const graphql = this._getGraphqlClient(context);
|
|
826
|
+
if (!graphql) return;
|
|
827
|
+
try {
|
|
828
|
+
await graphql(MINIMIZE_COMMENT_MUTATION, {
|
|
829
|
+
id: commentNodeId,
|
|
830
|
+
classifier
|
|
831
|
+
});
|
|
832
|
+
} catch (error) {
|
|
833
|
+
context.logger.debug("Failed to minimize comment (non-fatal)", { err: error, commentNodeId });
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
async _applyCommandResponsePolicy(context) {
|
|
837
|
+
if (this._commandResponsePolicyApplied) return;
|
|
838
|
+
this._commandResponsePolicyApplied = true;
|
|
839
|
+
if (!this._shouldApplyCommandResponsePolicy(context)) return;
|
|
840
|
+
const locator = this._extractIssueLocator(context);
|
|
841
|
+
const commentNodeId = this._getCommentNodeId(context);
|
|
842
|
+
const comments = locator ? await this._fetchRecentComments(context, locator) : [];
|
|
843
|
+
const current = commentNodeId ? comments.find((comment) => comment.id === commentNodeId) : null;
|
|
844
|
+
const currentIsMinimized = current?.isMinimized ?? false;
|
|
845
|
+
if (commentNodeId && !currentIsMinimized) {
|
|
846
|
+
await this._minimizeComment(context, commentNodeId);
|
|
847
|
+
}
|
|
848
|
+
const previous = this._findPreviousCommandResponseComment(comments, commentNodeId);
|
|
849
|
+
if (previous && !previous.isMinimized) {
|
|
850
|
+
await this._minimizeComment(context, previous.id);
|
|
851
|
+
}
|
|
852
|
+
}
|
|
718
853
|
_processMessage(context, message) {
|
|
719
854
|
if (message instanceof Error) {
|
|
720
855
|
const metadata2 = {
|
|
@@ -766,7 +901,9 @@ var CommentHandler = class _CommentHandler {
|
|
|
766
901
|
}
|
|
767
902
|
_createCommentBody(context, message, options) {
|
|
768
903
|
const { metadata, logMessage } = this._processMessage(context, message);
|
|
769
|
-
const
|
|
904
|
+
const shouldTagCommandResponse = options?.commentKind && typeof metadata === "object" && metadata !== null && !("commentKind" in metadata);
|
|
905
|
+
const metadataWithKind = shouldTagCommandResponse ? { ...metadata, commentKind: options?.commentKind } : metadata;
|
|
906
|
+
const { header, jsonPretty } = this._createMetadataContent(context, metadataWithKind);
|
|
770
907
|
const metadataContent = this._formatMetadataContent(logMessage, header, jsonPretty);
|
|
771
908
|
return `${options?.raw ? logMessage?.raw : logMessage?.diff}
|
|
772
909
|
|
|
@@ -774,12 +911,17 @@ ${metadataContent}
|
|
|
774
911
|
`;
|
|
775
912
|
}
|
|
776
913
|
async postComment(context, message, options = { updateComment: true, raw: false }) {
|
|
914
|
+
await this._applyCommandResponsePolicy(context);
|
|
777
915
|
const issueContext = this._extractIssueContext(context);
|
|
778
916
|
if (!issueContext) {
|
|
779
917
|
context.logger.warn("Cannot post comment: missing issue context in payload");
|
|
780
918
|
return null;
|
|
781
919
|
}
|
|
782
|
-
const
|
|
920
|
+
const shouldTagCommandResponse = this._shouldApplyCommandResponsePolicy(context);
|
|
921
|
+
const body = this._createCommentBody(context, message, {
|
|
922
|
+
...options,
|
|
923
|
+
commentKind: options.commentKind ?? (shouldTagCommandResponse ? COMMAND_RESPONSE_KIND : void 0)
|
|
924
|
+
});
|
|
783
925
|
const { issueNumber, commentId, owner, repo } = issueContext;
|
|
784
926
|
const params = { owner, repo, body, issueNumber };
|
|
785
927
|
if (options.updateComment) {
|
|
@@ -1177,12 +1319,12 @@ function cleanMarkdown(md, options = {}) {
|
|
|
1177
1319
|
const segments = [];
|
|
1178
1320
|
let lastIndex = 0;
|
|
1179
1321
|
const matches = [...md.matchAll(codeBlockRegex)];
|
|
1180
|
-
for (const
|
|
1181
|
-
if (
|
|
1182
|
-
segments.push(processSegment(md.slice(lastIndex,
|
|
1322
|
+
for (const match2 of matches) {
|
|
1323
|
+
if (match2.index > lastIndex) {
|
|
1324
|
+
segments.push(processSegment(md.slice(lastIndex, match2.index), tags, shouldCollapseEmptyLines));
|
|
1183
1325
|
}
|
|
1184
|
-
segments.push(
|
|
1185
|
-
lastIndex =
|
|
1326
|
+
segments.push(match2[0]);
|
|
1327
|
+
lastIndex = match2.index + match2[0].length;
|
|
1186
1328
|
}
|
|
1187
1329
|
if (lastIndex < md.length) {
|
|
1188
1330
|
segments.push(processSegment(md.slice(lastIndex), tags, shouldCollapseEmptyLines));
|
|
@@ -1225,7 +1367,7 @@ function processSegment(segment, extraTags, shouldCollapseEmptyLines) {
|
|
|
1225
1367
|
// src/server.ts
|
|
1226
1368
|
var import_value4 = require("@sinclair/typebox/value");
|
|
1227
1369
|
|
|
1228
|
-
// ../../node_modules/hono/dist/compose.js
|
|
1370
|
+
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/compose.js
|
|
1229
1371
|
var compose = (middleware, onError, onNotFound) => {
|
|
1230
1372
|
return (context, next) => {
|
|
1231
1373
|
let index = -1;
|
|
@@ -1269,10 +1411,43 @@ var compose = (middleware, onError, onNotFound) => {
|
|
|
1269
1411
|
};
|
|
1270
1412
|
};
|
|
1271
1413
|
|
|
1272
|
-
// ../../node_modules/hono/dist/
|
|
1273
|
-
var
|
|
1414
|
+
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/http-exception.js
|
|
1415
|
+
var HTTPException = class extends Error {
|
|
1416
|
+
res;
|
|
1417
|
+
status;
|
|
1418
|
+
/**
|
|
1419
|
+
* Creates an instance of `HTTPException`.
|
|
1420
|
+
* @param status - HTTP status code for the exception. Defaults to 500.
|
|
1421
|
+
* @param options - Additional options for the exception.
|
|
1422
|
+
*/
|
|
1423
|
+
constructor(status = 500, options) {
|
|
1424
|
+
super(options?.message, { cause: options?.cause });
|
|
1425
|
+
this.res = options?.res;
|
|
1426
|
+
this.status = status;
|
|
1427
|
+
}
|
|
1428
|
+
/**
|
|
1429
|
+
* Returns the response object associated with the exception.
|
|
1430
|
+
* If a response object is not provided, a new response is created with the error message and status code.
|
|
1431
|
+
* @returns The response object.
|
|
1432
|
+
*/
|
|
1433
|
+
getResponse() {
|
|
1434
|
+
if (this.res) {
|
|
1435
|
+
const newResponse = new Response(this.res.body, {
|
|
1436
|
+
status: this.status,
|
|
1437
|
+
headers: this.res.headers
|
|
1438
|
+
});
|
|
1439
|
+
return newResponse;
|
|
1440
|
+
}
|
|
1441
|
+
return new Response(this.message, {
|
|
1442
|
+
status: this.status
|
|
1443
|
+
});
|
|
1444
|
+
}
|
|
1445
|
+
};
|
|
1446
|
+
|
|
1447
|
+
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/request/constants.js
|
|
1448
|
+
var GET_MATCH_RESULT = /* @__PURE__ */ Symbol();
|
|
1274
1449
|
|
|
1275
|
-
// ../../node_modules/hono/dist/utils/body.js
|
|
1450
|
+
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/utils/body.js
|
|
1276
1451
|
var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
|
|
1277
1452
|
const { all = false, dot = false } = options;
|
|
1278
1453
|
const headers = request instanceof HonoRequest ? request.raw.headers : request.headers;
|
|
@@ -1341,7 +1516,7 @@ var handleParsingNestedValues = (form, key, value) => {
|
|
|
1341
1516
|
});
|
|
1342
1517
|
};
|
|
1343
1518
|
|
|
1344
|
-
// ../../node_modules/hono/dist/utils/url.js
|
|
1519
|
+
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/utils/url.js
|
|
1345
1520
|
var splitPath = (path) => {
|
|
1346
1521
|
const paths = path.split("/");
|
|
1347
1522
|
if (paths[0] === "") {
|
|
@@ -1356,9 +1531,9 @@ var splitRoutingPath = (routePath) => {
|
|
|
1356
1531
|
};
|
|
1357
1532
|
var extractGroupsFromPath = (path) => {
|
|
1358
1533
|
const groups = [];
|
|
1359
|
-
path = path.replace(/\{[^}]+\}/g, (
|
|
1534
|
+
path = path.replace(/\{[^}]+\}/g, (match2, index) => {
|
|
1360
1535
|
const mark = `@${index}`;
|
|
1361
|
-
groups.push([mark,
|
|
1536
|
+
groups.push([mark, match2]);
|
|
1362
1537
|
return mark;
|
|
1363
1538
|
});
|
|
1364
1539
|
return { groups, path };
|
|
@@ -1380,14 +1555,14 @@ var getPattern = (label, next) => {
|
|
|
1380
1555
|
if (label === "*") {
|
|
1381
1556
|
return "*";
|
|
1382
1557
|
}
|
|
1383
|
-
const
|
|
1384
|
-
if (
|
|
1558
|
+
const match2 = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
1559
|
+
if (match2) {
|
|
1385
1560
|
const cacheKey = `${label}#${next}`;
|
|
1386
1561
|
if (!patternCache[cacheKey]) {
|
|
1387
|
-
if (
|
|
1388
|
-
patternCache[cacheKey] = next && next[0] !== ":" && next[0] !== "*" ? [cacheKey,
|
|
1562
|
+
if (match2[2]) {
|
|
1563
|
+
patternCache[cacheKey] = next && next[0] !== ":" && next[0] !== "*" ? [cacheKey, match2[1], new RegExp(`^${match2[2]}(?=/${next})`)] : [label, match2[1], new RegExp(`^${match2[2]}$`)];
|
|
1389
1564
|
} else {
|
|
1390
|
-
patternCache[cacheKey] = [label,
|
|
1565
|
+
patternCache[cacheKey] = [label, match2[1], true];
|
|
1391
1566
|
}
|
|
1392
1567
|
}
|
|
1393
1568
|
return patternCache[cacheKey];
|
|
@@ -1398,11 +1573,11 @@ var tryDecode = (str, decoder) => {
|
|
|
1398
1573
|
try {
|
|
1399
1574
|
return decoder(str);
|
|
1400
1575
|
} catch {
|
|
1401
|
-
return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (
|
|
1576
|
+
return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match2) => {
|
|
1402
1577
|
try {
|
|
1403
|
-
return decoder(
|
|
1578
|
+
return decoder(match2);
|
|
1404
1579
|
} catch {
|
|
1405
|
-
return
|
|
1580
|
+
return match2;
|
|
1406
1581
|
}
|
|
1407
1582
|
});
|
|
1408
1583
|
}
|
|
@@ -1410,10 +1585,7 @@ var tryDecode = (str, decoder) => {
|
|
|
1410
1585
|
var tryDecodeURI = (str) => tryDecode(str, decodeURI);
|
|
1411
1586
|
var getPath = (request) => {
|
|
1412
1587
|
const url = request.url;
|
|
1413
|
-
const start = url.indexOf(
|
|
1414
|
-
"/",
|
|
1415
|
-
url.charCodeAt(9) === 58 ? 13 : 8
|
|
1416
|
-
);
|
|
1588
|
+
const start = url.indexOf("/", url.indexOf(":") + 4);
|
|
1417
1589
|
let i = start;
|
|
1418
1590
|
for (; i < url.length; i++) {
|
|
1419
1591
|
const charCode = url.charCodeAt(i);
|
|
@@ -1476,9 +1648,12 @@ var _decodeURI = (value) => {
|
|
|
1476
1648
|
var _getQueryParam = (url, key, multiple) => {
|
|
1477
1649
|
let encoded;
|
|
1478
1650
|
if (!multiple && key && !/[%+]/.test(key)) {
|
|
1479
|
-
let keyIndex2 = url.indexOf(
|
|
1651
|
+
let keyIndex2 = url.indexOf("?", 8);
|
|
1480
1652
|
if (keyIndex2 === -1) {
|
|
1481
|
-
|
|
1653
|
+
return void 0;
|
|
1654
|
+
}
|
|
1655
|
+
if (!url.startsWith(key, keyIndex2 + 1)) {
|
|
1656
|
+
keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
|
|
1482
1657
|
}
|
|
1483
1658
|
while (keyIndex2 !== -1) {
|
|
1484
1659
|
const trailingKeyCode = url.charCodeAt(keyIndex2 + key.length + 1);
|
|
@@ -1543,13 +1718,40 @@ var getQueryParams = (url, key) => {
|
|
|
1543
1718
|
};
|
|
1544
1719
|
var decodeURIComponent_ = decodeURIComponent;
|
|
1545
1720
|
|
|
1546
|
-
// ../../node_modules/hono/dist/request.js
|
|
1721
|
+
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/request.js
|
|
1547
1722
|
var tryDecodeURIComponent = (str) => tryDecode(str, decodeURIComponent_);
|
|
1548
1723
|
var HonoRequest = class {
|
|
1724
|
+
/**
|
|
1725
|
+
* `.raw` can get the raw Request object.
|
|
1726
|
+
*
|
|
1727
|
+
* @see {@link https://hono.dev/docs/api/request#raw}
|
|
1728
|
+
*
|
|
1729
|
+
* @example
|
|
1730
|
+
* ```ts
|
|
1731
|
+
* // For Cloudflare Workers
|
|
1732
|
+
* app.post('/', async (c) => {
|
|
1733
|
+
* const metadata = c.req.raw.cf?.hostMetadata?
|
|
1734
|
+
* ...
|
|
1735
|
+
* })
|
|
1736
|
+
* ```
|
|
1737
|
+
*/
|
|
1549
1738
|
raw;
|
|
1550
1739
|
#validatedData;
|
|
1740
|
+
// Short name of validatedData
|
|
1551
1741
|
#matchResult;
|
|
1552
1742
|
routeIndex = 0;
|
|
1743
|
+
/**
|
|
1744
|
+
* `.path` can get the pathname of the request.
|
|
1745
|
+
*
|
|
1746
|
+
* @see {@link https://hono.dev/docs/api/request#path}
|
|
1747
|
+
*
|
|
1748
|
+
* @example
|
|
1749
|
+
* ```ts
|
|
1750
|
+
* app.get('/about/me', (c) => {
|
|
1751
|
+
* const pathname = c.req.path // `/about/me`
|
|
1752
|
+
* })
|
|
1753
|
+
* ```
|
|
1754
|
+
*/
|
|
1553
1755
|
path;
|
|
1554
1756
|
bodyCache = {};
|
|
1555
1757
|
constructor(request, path = "/", matchResult = [[]]) {
|
|
@@ -1564,14 +1766,14 @@ var HonoRequest = class {
|
|
|
1564
1766
|
#getDecodedParam(key) {
|
|
1565
1767
|
const paramKey = this.#matchResult[0][this.routeIndex][1][key];
|
|
1566
1768
|
const param = this.#getParamValue(paramKey);
|
|
1567
|
-
return param
|
|
1769
|
+
return param && /\%/.test(param) ? tryDecodeURIComponent(param) : param;
|
|
1568
1770
|
}
|
|
1569
1771
|
#getAllDecodedParams() {
|
|
1570
1772
|
const decoded = {};
|
|
1571
1773
|
const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]);
|
|
1572
1774
|
for (const key of keys) {
|
|
1573
1775
|
const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
|
|
1574
|
-
if (value
|
|
1776
|
+
if (value !== void 0) {
|
|
1575
1777
|
decoded[key] = /\%/.test(value) ? tryDecodeURIComponent(value) : value;
|
|
1576
1778
|
}
|
|
1577
1779
|
}
|
|
@@ -1616,45 +1818,175 @@ var HonoRequest = class {
|
|
|
1616
1818
|
}
|
|
1617
1819
|
return bodyCache[key] = raw2[key]();
|
|
1618
1820
|
};
|
|
1821
|
+
/**
|
|
1822
|
+
* `.json()` can parse Request body of type `application/json`
|
|
1823
|
+
*
|
|
1824
|
+
* @see {@link https://hono.dev/docs/api/request#json}
|
|
1825
|
+
*
|
|
1826
|
+
* @example
|
|
1827
|
+
* ```ts
|
|
1828
|
+
* app.post('/entry', async (c) => {
|
|
1829
|
+
* const body = await c.req.json()
|
|
1830
|
+
* })
|
|
1831
|
+
* ```
|
|
1832
|
+
*/
|
|
1619
1833
|
json() {
|
|
1620
1834
|
return this.#cachedBody("text").then((text) => JSON.parse(text));
|
|
1621
1835
|
}
|
|
1836
|
+
/**
|
|
1837
|
+
* `.text()` can parse Request body of type `text/plain`
|
|
1838
|
+
*
|
|
1839
|
+
* @see {@link https://hono.dev/docs/api/request#text}
|
|
1840
|
+
*
|
|
1841
|
+
* @example
|
|
1842
|
+
* ```ts
|
|
1843
|
+
* app.post('/entry', async (c) => {
|
|
1844
|
+
* const body = await c.req.text()
|
|
1845
|
+
* })
|
|
1846
|
+
* ```
|
|
1847
|
+
*/
|
|
1622
1848
|
text() {
|
|
1623
1849
|
return this.#cachedBody("text");
|
|
1624
1850
|
}
|
|
1851
|
+
/**
|
|
1852
|
+
* `.arrayBuffer()` parse Request body as an `ArrayBuffer`
|
|
1853
|
+
*
|
|
1854
|
+
* @see {@link https://hono.dev/docs/api/request#arraybuffer}
|
|
1855
|
+
*
|
|
1856
|
+
* @example
|
|
1857
|
+
* ```ts
|
|
1858
|
+
* app.post('/entry', async (c) => {
|
|
1859
|
+
* const body = await c.req.arrayBuffer()
|
|
1860
|
+
* })
|
|
1861
|
+
* ```
|
|
1862
|
+
*/
|
|
1625
1863
|
arrayBuffer() {
|
|
1626
1864
|
return this.#cachedBody("arrayBuffer");
|
|
1627
1865
|
}
|
|
1866
|
+
/**
|
|
1867
|
+
* Parses the request body as a `Blob`.
|
|
1868
|
+
* @example
|
|
1869
|
+
* ```ts
|
|
1870
|
+
* app.post('/entry', async (c) => {
|
|
1871
|
+
* const body = await c.req.blob();
|
|
1872
|
+
* });
|
|
1873
|
+
* ```
|
|
1874
|
+
* @see https://hono.dev/docs/api/request#blob
|
|
1875
|
+
*/
|
|
1628
1876
|
blob() {
|
|
1629
1877
|
return this.#cachedBody("blob");
|
|
1630
1878
|
}
|
|
1879
|
+
/**
|
|
1880
|
+
* Parses the request body as `FormData`.
|
|
1881
|
+
* @example
|
|
1882
|
+
* ```ts
|
|
1883
|
+
* app.post('/entry', async (c) => {
|
|
1884
|
+
* const body = await c.req.formData();
|
|
1885
|
+
* });
|
|
1886
|
+
* ```
|
|
1887
|
+
* @see https://hono.dev/docs/api/request#formdata
|
|
1888
|
+
*/
|
|
1631
1889
|
formData() {
|
|
1632
1890
|
return this.#cachedBody("formData");
|
|
1633
1891
|
}
|
|
1892
|
+
/**
|
|
1893
|
+
* Adds validated data to the request.
|
|
1894
|
+
*
|
|
1895
|
+
* @param target - The target of the validation.
|
|
1896
|
+
* @param data - The validated data to add.
|
|
1897
|
+
*/
|
|
1634
1898
|
addValidatedData(target, data) {
|
|
1635
1899
|
this.#validatedData[target] = data;
|
|
1636
1900
|
}
|
|
1637
1901
|
valid(target) {
|
|
1638
1902
|
return this.#validatedData[target];
|
|
1639
1903
|
}
|
|
1904
|
+
/**
|
|
1905
|
+
* `.url()` can get the request url strings.
|
|
1906
|
+
*
|
|
1907
|
+
* @see {@link https://hono.dev/docs/api/request#url}
|
|
1908
|
+
*
|
|
1909
|
+
* @example
|
|
1910
|
+
* ```ts
|
|
1911
|
+
* app.get('/about/me', (c) => {
|
|
1912
|
+
* const url = c.req.url // `http://localhost:8787/about/me`
|
|
1913
|
+
* ...
|
|
1914
|
+
* })
|
|
1915
|
+
* ```
|
|
1916
|
+
*/
|
|
1640
1917
|
get url() {
|
|
1641
1918
|
return this.raw.url;
|
|
1642
1919
|
}
|
|
1920
|
+
/**
|
|
1921
|
+
* `.method()` can get the method name of the request.
|
|
1922
|
+
*
|
|
1923
|
+
* @see {@link https://hono.dev/docs/api/request#method}
|
|
1924
|
+
*
|
|
1925
|
+
* @example
|
|
1926
|
+
* ```ts
|
|
1927
|
+
* app.get('/about/me', (c) => {
|
|
1928
|
+
* const method = c.req.method // `GET`
|
|
1929
|
+
* })
|
|
1930
|
+
* ```
|
|
1931
|
+
*/
|
|
1643
1932
|
get method() {
|
|
1644
1933
|
return this.raw.method;
|
|
1645
1934
|
}
|
|
1646
1935
|
get [GET_MATCH_RESULT]() {
|
|
1647
1936
|
return this.#matchResult;
|
|
1648
1937
|
}
|
|
1938
|
+
/**
|
|
1939
|
+
* `.matchedRoutes()` can return a matched route in the handler
|
|
1940
|
+
*
|
|
1941
|
+
* @deprecated
|
|
1942
|
+
*
|
|
1943
|
+
* Use matchedRoutes helper defined in "hono/route" instead.
|
|
1944
|
+
*
|
|
1945
|
+
* @see {@link https://hono.dev/docs/api/request#matchedroutes}
|
|
1946
|
+
*
|
|
1947
|
+
* @example
|
|
1948
|
+
* ```ts
|
|
1949
|
+
* app.use('*', async function logger(c, next) {
|
|
1950
|
+
* await next()
|
|
1951
|
+
* c.req.matchedRoutes.forEach(({ handler, method, path }, i) => {
|
|
1952
|
+
* const name = handler.name || (handler.length < 2 ? '[handler]' : '[middleware]')
|
|
1953
|
+
* console.log(
|
|
1954
|
+
* method,
|
|
1955
|
+
* ' ',
|
|
1956
|
+
* path,
|
|
1957
|
+
* ' '.repeat(Math.max(10 - path.length, 0)),
|
|
1958
|
+
* name,
|
|
1959
|
+
* i === c.req.routeIndex ? '<- respond from here' : ''
|
|
1960
|
+
* )
|
|
1961
|
+
* })
|
|
1962
|
+
* })
|
|
1963
|
+
* ```
|
|
1964
|
+
*/
|
|
1649
1965
|
get matchedRoutes() {
|
|
1650
1966
|
return this.#matchResult[0].map(([[, route]]) => route);
|
|
1651
1967
|
}
|
|
1968
|
+
/**
|
|
1969
|
+
* `routePath()` can retrieve the path registered within the handler
|
|
1970
|
+
*
|
|
1971
|
+
* @deprecated
|
|
1972
|
+
*
|
|
1973
|
+
* Use routePath helper defined in "hono/route" instead.
|
|
1974
|
+
*
|
|
1975
|
+
* @see {@link https://hono.dev/docs/api/request#routepath}
|
|
1976
|
+
*
|
|
1977
|
+
* @example
|
|
1978
|
+
* ```ts
|
|
1979
|
+
* app.get('/posts/:id', (c) => {
|
|
1980
|
+
* return c.json({ path: c.req.routePath })
|
|
1981
|
+
* })
|
|
1982
|
+
* ```
|
|
1983
|
+
*/
|
|
1652
1984
|
get routePath() {
|
|
1653
1985
|
return this.#matchResult[0].map(([[, route]]) => route)[this.routeIndex].path;
|
|
1654
1986
|
}
|
|
1655
1987
|
};
|
|
1656
1988
|
|
|
1657
|
-
// ../../node_modules/hono/dist/utils/html.js
|
|
1989
|
+
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/utils/html.js
|
|
1658
1990
|
var HtmlEscapedCallbackPhase = {
|
|
1659
1991
|
Stringify: 1,
|
|
1660
1992
|
BeforeStream: 2,
|
|
@@ -1696,7 +2028,7 @@ var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) =>
|
|
|
1696
2028
|
}
|
|
1697
2029
|
};
|
|
1698
2030
|
|
|
1699
|
-
// ../../node_modules/hono/dist/context.js
|
|
2031
|
+
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/context.js
|
|
1700
2032
|
var TEXT_PLAIN = "text/plain; charset=UTF-8";
|
|
1701
2033
|
var setDefaultContentType = (contentType, headers) => {
|
|
1702
2034
|
return {
|
|
@@ -1707,9 +2039,37 @@ var setDefaultContentType = (contentType, headers) => {
|
|
|
1707
2039
|
var Context = class {
|
|
1708
2040
|
#rawRequest;
|
|
1709
2041
|
#req;
|
|
2042
|
+
/**
|
|
2043
|
+
* `.env` can get bindings (environment variables, secrets, KV namespaces, D1 database, R2 bucket etc.) in Cloudflare Workers.
|
|
2044
|
+
*
|
|
2045
|
+
* @see {@link https://hono.dev/docs/api/context#env}
|
|
2046
|
+
*
|
|
2047
|
+
* @example
|
|
2048
|
+
* ```ts
|
|
2049
|
+
* // Environment object for Cloudflare Workers
|
|
2050
|
+
* app.get('*', async c => {
|
|
2051
|
+
* const counter = c.env.COUNTER
|
|
2052
|
+
* })
|
|
2053
|
+
* ```
|
|
2054
|
+
*/
|
|
1710
2055
|
env = {};
|
|
1711
2056
|
#var;
|
|
1712
2057
|
finalized = false;
|
|
2058
|
+
/**
|
|
2059
|
+
* `.error` can get the error object from the middleware if the Handler throws an error.
|
|
2060
|
+
*
|
|
2061
|
+
* @see {@link https://hono.dev/docs/api/context#error}
|
|
2062
|
+
*
|
|
2063
|
+
* @example
|
|
2064
|
+
* ```ts
|
|
2065
|
+
* app.use('*', async (c, next) => {
|
|
2066
|
+
* await next()
|
|
2067
|
+
* if (c.error) {
|
|
2068
|
+
* // do something...
|
|
2069
|
+
* }
|
|
2070
|
+
* })
|
|
2071
|
+
* ```
|
|
2072
|
+
*/
|
|
1713
2073
|
error;
|
|
1714
2074
|
#status;
|
|
1715
2075
|
#executionCtx;
|
|
@@ -1720,6 +2080,12 @@ var Context = class {
|
|
|
1720
2080
|
#preparedHeaders;
|
|
1721
2081
|
#matchResult;
|
|
1722
2082
|
#path;
|
|
2083
|
+
/**
|
|
2084
|
+
* Creates an instance of the Context class.
|
|
2085
|
+
*
|
|
2086
|
+
* @param req - The Request object.
|
|
2087
|
+
* @param options - Optional configuration options for the context.
|
|
2088
|
+
*/
|
|
1723
2089
|
constructor(req, options) {
|
|
1724
2090
|
this.#rawRequest = req;
|
|
1725
2091
|
if (options) {
|
|
@@ -1730,10 +2096,19 @@ var Context = class {
|
|
|
1730
2096
|
this.#matchResult = options.matchResult;
|
|
1731
2097
|
}
|
|
1732
2098
|
}
|
|
2099
|
+
/**
|
|
2100
|
+
* `.req` is the instance of {@link HonoRequest}.
|
|
2101
|
+
*/
|
|
1733
2102
|
get req() {
|
|
1734
2103
|
this.#req ??= new HonoRequest(this.#rawRequest, this.#path, this.#matchResult);
|
|
1735
2104
|
return this.#req;
|
|
1736
2105
|
}
|
|
2106
|
+
/**
|
|
2107
|
+
* @see {@link https://hono.dev/docs/api/context#event}
|
|
2108
|
+
* The FetchEvent associated with the current request.
|
|
2109
|
+
*
|
|
2110
|
+
* @throws Will throw an error if the context does not have a FetchEvent.
|
|
2111
|
+
*/
|
|
1737
2112
|
get event() {
|
|
1738
2113
|
if (this.#executionCtx && "respondWith" in this.#executionCtx) {
|
|
1739
2114
|
return this.#executionCtx;
|
|
@@ -1741,6 +2116,12 @@ var Context = class {
|
|
|
1741
2116
|
throw Error("This context has no FetchEvent");
|
|
1742
2117
|
}
|
|
1743
2118
|
}
|
|
2119
|
+
/**
|
|
2120
|
+
* @see {@link https://hono.dev/docs/api/context#executionctx}
|
|
2121
|
+
* The ExecutionContext associated with the current request.
|
|
2122
|
+
*
|
|
2123
|
+
* @throws Will throw an error if the context does not have an ExecutionContext.
|
|
2124
|
+
*/
|
|
1744
2125
|
get executionCtx() {
|
|
1745
2126
|
if (this.#executionCtx) {
|
|
1746
2127
|
return this.#executionCtx;
|
|
@@ -1748,11 +2129,20 @@ var Context = class {
|
|
|
1748
2129
|
throw Error("This context has no ExecutionContext");
|
|
1749
2130
|
}
|
|
1750
2131
|
}
|
|
2132
|
+
/**
|
|
2133
|
+
* @see {@link https://hono.dev/docs/api/context#res}
|
|
2134
|
+
* The Response object for the current request.
|
|
2135
|
+
*/
|
|
1751
2136
|
get res() {
|
|
1752
2137
|
return this.#res ||= new Response(null, {
|
|
1753
2138
|
headers: this.#preparedHeaders ??= new Headers()
|
|
1754
2139
|
});
|
|
1755
2140
|
}
|
|
2141
|
+
/**
|
|
2142
|
+
* Sets the Response object for the current request.
|
|
2143
|
+
*
|
|
2144
|
+
* @param _res - The Response object to set.
|
|
2145
|
+
*/
|
|
1756
2146
|
set res(_res) {
|
|
1757
2147
|
if (this.#res && _res) {
|
|
1758
2148
|
_res = new Response(_res.body, _res);
|
|
@@ -1774,15 +2164,75 @@ var Context = class {
|
|
|
1774
2164
|
this.#res = _res;
|
|
1775
2165
|
this.finalized = true;
|
|
1776
2166
|
}
|
|
2167
|
+
/**
|
|
2168
|
+
* `.render()` can create a response within a layout.
|
|
2169
|
+
*
|
|
2170
|
+
* @see {@link https://hono.dev/docs/api/context#render-setrenderer}
|
|
2171
|
+
*
|
|
2172
|
+
* @example
|
|
2173
|
+
* ```ts
|
|
2174
|
+
* app.get('/', (c) => {
|
|
2175
|
+
* return c.render('Hello!')
|
|
2176
|
+
* })
|
|
2177
|
+
* ```
|
|
2178
|
+
*/
|
|
1777
2179
|
render = (...args) => {
|
|
1778
2180
|
this.#renderer ??= (content) => this.html(content);
|
|
1779
2181
|
return this.#renderer(...args);
|
|
1780
2182
|
};
|
|
2183
|
+
/**
|
|
2184
|
+
* Sets the layout for the response.
|
|
2185
|
+
*
|
|
2186
|
+
* @param layout - The layout to set.
|
|
2187
|
+
* @returns The layout function.
|
|
2188
|
+
*/
|
|
1781
2189
|
setLayout = (layout) => this.#layout = layout;
|
|
2190
|
+
/**
|
|
2191
|
+
* Gets the current layout for the response.
|
|
2192
|
+
*
|
|
2193
|
+
* @returns The current layout function.
|
|
2194
|
+
*/
|
|
1782
2195
|
getLayout = () => this.#layout;
|
|
2196
|
+
/**
|
|
2197
|
+
* `.setRenderer()` can set the layout in the custom middleware.
|
|
2198
|
+
*
|
|
2199
|
+
* @see {@link https://hono.dev/docs/api/context#render-setrenderer}
|
|
2200
|
+
*
|
|
2201
|
+
* @example
|
|
2202
|
+
* ```tsx
|
|
2203
|
+
* app.use('*', async (c, next) => {
|
|
2204
|
+
* c.setRenderer((content) => {
|
|
2205
|
+
* return c.html(
|
|
2206
|
+
* <html>
|
|
2207
|
+
* <body>
|
|
2208
|
+
* <p>{content}</p>
|
|
2209
|
+
* </body>
|
|
2210
|
+
* </html>
|
|
2211
|
+
* )
|
|
2212
|
+
* })
|
|
2213
|
+
* await next()
|
|
2214
|
+
* })
|
|
2215
|
+
* ```
|
|
2216
|
+
*/
|
|
1783
2217
|
setRenderer = (renderer) => {
|
|
1784
2218
|
this.#renderer = renderer;
|
|
1785
2219
|
};
|
|
2220
|
+
/**
|
|
2221
|
+
* `.header()` can set headers.
|
|
2222
|
+
*
|
|
2223
|
+
* @see {@link https://hono.dev/docs/api/context#header}
|
|
2224
|
+
*
|
|
2225
|
+
* @example
|
|
2226
|
+
* ```ts
|
|
2227
|
+
* app.get('/welcome', (c) => {
|
|
2228
|
+
* // Set headers
|
|
2229
|
+
* c.header('X-Message', 'Hello!')
|
|
2230
|
+
* c.header('Content-Type', 'text/plain')
|
|
2231
|
+
*
|
|
2232
|
+
* return c.body('Thank you for coming')
|
|
2233
|
+
* })
|
|
2234
|
+
* ```
|
|
2235
|
+
*/
|
|
1786
2236
|
header = (name, value, options) => {
|
|
1787
2237
|
if (this.finalized) {
|
|
1788
2238
|
this.#res = new Response(this.#res.body, this.#res);
|
|
@@ -1799,13 +2249,50 @@ var Context = class {
|
|
|
1799
2249
|
status = (status) => {
|
|
1800
2250
|
this.#status = status;
|
|
1801
2251
|
};
|
|
2252
|
+
/**
|
|
2253
|
+
* `.set()` can set the value specified by the key.
|
|
2254
|
+
*
|
|
2255
|
+
* @see {@link https://hono.dev/docs/api/context#set-get}
|
|
2256
|
+
*
|
|
2257
|
+
* @example
|
|
2258
|
+
* ```ts
|
|
2259
|
+
* app.use('*', async (c, next) => {
|
|
2260
|
+
* c.set('message', 'Hono is hot!!')
|
|
2261
|
+
* await next()
|
|
2262
|
+
* })
|
|
2263
|
+
* ```
|
|
2264
|
+
*/
|
|
1802
2265
|
set = (key, value) => {
|
|
1803
2266
|
this.#var ??= /* @__PURE__ */ new Map();
|
|
1804
2267
|
this.#var.set(key, value);
|
|
1805
2268
|
};
|
|
2269
|
+
/**
|
|
2270
|
+
* `.get()` can use the value specified by the key.
|
|
2271
|
+
*
|
|
2272
|
+
* @see {@link https://hono.dev/docs/api/context#set-get}
|
|
2273
|
+
*
|
|
2274
|
+
* @example
|
|
2275
|
+
* ```ts
|
|
2276
|
+
* app.get('/', (c) => {
|
|
2277
|
+
* const message = c.get('message')
|
|
2278
|
+
* return c.text(`The message is "${message}"`)
|
|
2279
|
+
* })
|
|
2280
|
+
* ```
|
|
2281
|
+
*/
|
|
1806
2282
|
get = (key) => {
|
|
1807
2283
|
return this.#var ? this.#var.get(key) : void 0;
|
|
1808
2284
|
};
|
|
2285
|
+
/**
|
|
2286
|
+
* `.var` can access the value of a variable.
|
|
2287
|
+
*
|
|
2288
|
+
* @see {@link https://hono.dev/docs/api/context#var}
|
|
2289
|
+
*
|
|
2290
|
+
* @example
|
|
2291
|
+
* ```ts
|
|
2292
|
+
* const result = c.var.client.oneMethod()
|
|
2293
|
+
* ```
|
|
2294
|
+
*/
|
|
2295
|
+
// c.var.propName is a read-only
|
|
1809
2296
|
get var() {
|
|
1810
2297
|
if (!this.#var) {
|
|
1811
2298
|
return {};
|
|
@@ -1840,7 +2327,40 @@ var Context = class {
|
|
|
1840
2327
|
return new Response(data, { status, headers: responseHeaders });
|
|
1841
2328
|
}
|
|
1842
2329
|
newResponse = (...args) => this.#newResponse(...args);
|
|
2330
|
+
/**
|
|
2331
|
+
* `.body()` can return the HTTP response.
|
|
2332
|
+
* You can set headers with `.header()` and set HTTP status code with `.status`.
|
|
2333
|
+
* This can also be set in `.text()`, `.json()` and so on.
|
|
2334
|
+
*
|
|
2335
|
+
* @see {@link https://hono.dev/docs/api/context#body}
|
|
2336
|
+
*
|
|
2337
|
+
* @example
|
|
2338
|
+
* ```ts
|
|
2339
|
+
* app.get('/welcome', (c) => {
|
|
2340
|
+
* // Set headers
|
|
2341
|
+
* c.header('X-Message', 'Hello!')
|
|
2342
|
+
* c.header('Content-Type', 'text/plain')
|
|
2343
|
+
* // Set HTTP status code
|
|
2344
|
+
* c.status(201)
|
|
2345
|
+
*
|
|
2346
|
+
* // Return the response body
|
|
2347
|
+
* return c.body('Thank you for coming')
|
|
2348
|
+
* })
|
|
2349
|
+
* ```
|
|
2350
|
+
*/
|
|
1843
2351
|
body = (data, arg, headers) => this.#newResponse(data, arg, headers);
|
|
2352
|
+
/**
|
|
2353
|
+
* `.text()` can render text as `Content-Type:text/plain`.
|
|
2354
|
+
*
|
|
2355
|
+
* @see {@link https://hono.dev/docs/api/context#text}
|
|
2356
|
+
*
|
|
2357
|
+
* @example
|
|
2358
|
+
* ```ts
|
|
2359
|
+
* app.get('/say', (c) => {
|
|
2360
|
+
* return c.text('Hello!')
|
|
2361
|
+
* })
|
|
2362
|
+
* ```
|
|
2363
|
+
*/
|
|
1844
2364
|
text = (text, arg, headers) => {
|
|
1845
2365
|
return !this.#preparedHeaders && !this.#status && !arg && !headers && !this.finalized ? new Response(text) : this.#newResponse(
|
|
1846
2366
|
text,
|
|
@@ -1848,6 +2368,18 @@ var Context = class {
|
|
|
1848
2368
|
setDefaultContentType(TEXT_PLAIN, headers)
|
|
1849
2369
|
);
|
|
1850
2370
|
};
|
|
2371
|
+
/**
|
|
2372
|
+
* `.json()` can render JSON as `Content-Type:application/json`.
|
|
2373
|
+
*
|
|
2374
|
+
* @see {@link https://hono.dev/docs/api/context#json}
|
|
2375
|
+
*
|
|
2376
|
+
* @example
|
|
2377
|
+
* ```ts
|
|
2378
|
+
* app.get('/api', (c) => {
|
|
2379
|
+
* return c.json({ message: 'Hello!' })
|
|
2380
|
+
* })
|
|
2381
|
+
* ```
|
|
2382
|
+
*/
|
|
1851
2383
|
json = (object, arg, headers) => {
|
|
1852
2384
|
return this.#newResponse(
|
|
1853
2385
|
JSON.stringify(object),
|
|
@@ -1859,21 +2391,50 @@ var Context = class {
|
|
|
1859
2391
|
const res = (html2) => this.#newResponse(html2, arg, setDefaultContentType("text/html; charset=UTF-8", headers));
|
|
1860
2392
|
return typeof html === "object" ? resolveCallback(html, HtmlEscapedCallbackPhase.Stringify, false, {}).then(res) : res(html);
|
|
1861
2393
|
};
|
|
2394
|
+
/**
|
|
2395
|
+
* `.redirect()` can Redirect, default status code is 302.
|
|
2396
|
+
*
|
|
2397
|
+
* @see {@link https://hono.dev/docs/api/context#redirect}
|
|
2398
|
+
*
|
|
2399
|
+
* @example
|
|
2400
|
+
* ```ts
|
|
2401
|
+
* app.get('/redirect', (c) => {
|
|
2402
|
+
* return c.redirect('/')
|
|
2403
|
+
* })
|
|
2404
|
+
* app.get('/redirect-permanently', (c) => {
|
|
2405
|
+
* return c.redirect('/', 301)
|
|
2406
|
+
* })
|
|
2407
|
+
* ```
|
|
2408
|
+
*/
|
|
1862
2409
|
redirect = (location, status) => {
|
|
1863
2410
|
const locationString = String(location);
|
|
1864
2411
|
this.header(
|
|
1865
2412
|
"Location",
|
|
2413
|
+
// Multibyes should be encoded
|
|
2414
|
+
// eslint-disable-next-line no-control-regex
|
|
1866
2415
|
!/[^\x00-\xFF]/.test(locationString) ? locationString : encodeURI(locationString)
|
|
1867
2416
|
);
|
|
1868
2417
|
return this.newResponse(null, status ?? 302);
|
|
1869
2418
|
};
|
|
2419
|
+
/**
|
|
2420
|
+
* `.notFound()` can return the Not Found Response.
|
|
2421
|
+
*
|
|
2422
|
+
* @see {@link https://hono.dev/docs/api/context#notfound}
|
|
2423
|
+
*
|
|
2424
|
+
* @example
|
|
2425
|
+
* ```ts
|
|
2426
|
+
* app.get('/notfound', (c) => {
|
|
2427
|
+
* return c.notFound()
|
|
2428
|
+
* })
|
|
2429
|
+
* ```
|
|
2430
|
+
*/
|
|
1870
2431
|
notFound = () => {
|
|
1871
2432
|
this.#notFoundHandler ??= () => new Response();
|
|
1872
2433
|
return this.#notFoundHandler(this);
|
|
1873
2434
|
};
|
|
1874
2435
|
};
|
|
1875
2436
|
|
|
1876
|
-
// ../../node_modules/hono/dist/router.js
|
|
2437
|
+
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/router.js
|
|
1877
2438
|
var METHOD_NAME_ALL = "ALL";
|
|
1878
2439
|
var METHOD_NAME_ALL_LOWERCASE = "all";
|
|
1879
2440
|
var METHODS = ["get", "post", "put", "delete", "options", "patch"];
|
|
@@ -1881,10 +2442,10 @@ var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is
|
|
|
1881
2442
|
var UnsupportedPathError = class extends Error {
|
|
1882
2443
|
};
|
|
1883
2444
|
|
|
1884
|
-
// ../../node_modules/hono/dist/utils/constants.js
|
|
2445
|
+
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/utils/constants.js
|
|
1885
2446
|
var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
|
|
1886
2447
|
|
|
1887
|
-
// ../../node_modules/hono/dist/hono-base.js
|
|
2448
|
+
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/hono-base.js
|
|
1888
2449
|
var notFoundHandler = (c) => {
|
|
1889
2450
|
return c.text("404 Not Found", 404);
|
|
1890
2451
|
};
|
|
@@ -1896,7 +2457,7 @@ var errorHandler = (err, c) => {
|
|
|
1896
2457
|
console.error(err);
|
|
1897
2458
|
return c.text("Internal Server Error", 500);
|
|
1898
2459
|
};
|
|
1899
|
-
var Hono = class {
|
|
2460
|
+
var Hono = class _Hono {
|
|
1900
2461
|
get;
|
|
1901
2462
|
post;
|
|
1902
2463
|
put;
|
|
@@ -1906,8 +2467,13 @@ var Hono = class {
|
|
|
1906
2467
|
all;
|
|
1907
2468
|
on;
|
|
1908
2469
|
use;
|
|
2470
|
+
/*
|
|
2471
|
+
This class is like an abstract class and does not have a router.
|
|
2472
|
+
To use it, inherit the class and implement router in the constructor.
|
|
2473
|
+
*/
|
|
1909
2474
|
router;
|
|
1910
2475
|
getPath;
|
|
2476
|
+
// Cannot use `#` because it requires visibility at JavaScript runtime.
|
|
1911
2477
|
_basePath = "/";
|
|
1912
2478
|
#path = "/";
|
|
1913
2479
|
routes = [];
|
|
@@ -1954,7 +2520,7 @@ var Hono = class {
|
|
|
1954
2520
|
this.getPath = strict ?? true ? options.getPath ?? getPath : getPathNoStrict;
|
|
1955
2521
|
}
|
|
1956
2522
|
#clone() {
|
|
1957
|
-
const clone = new
|
|
2523
|
+
const clone = new _Hono({
|
|
1958
2524
|
router: this.router,
|
|
1959
2525
|
getPath: this.getPath
|
|
1960
2526
|
});
|
|
@@ -1964,7 +2530,26 @@ var Hono = class {
|
|
|
1964
2530
|
return clone;
|
|
1965
2531
|
}
|
|
1966
2532
|
#notFoundHandler = notFoundHandler;
|
|
2533
|
+
// Cannot use `#` because it requires visibility at JavaScript runtime.
|
|
1967
2534
|
errorHandler = errorHandler;
|
|
2535
|
+
/**
|
|
2536
|
+
* `.route()` allows grouping other Hono instance in routes.
|
|
2537
|
+
*
|
|
2538
|
+
* @see {@link https://hono.dev/docs/api/routing#grouping}
|
|
2539
|
+
*
|
|
2540
|
+
* @param {string} path - base Path
|
|
2541
|
+
* @param {Hono} app - other Hono instance
|
|
2542
|
+
* @returns {Hono} routed Hono instance
|
|
2543
|
+
*
|
|
2544
|
+
* @example
|
|
2545
|
+
* ```ts
|
|
2546
|
+
* const app = new Hono()
|
|
2547
|
+
* const app2 = new Hono()
|
|
2548
|
+
*
|
|
2549
|
+
* app2.get("/user", (c) => c.text("user"))
|
|
2550
|
+
* app.route("/api", app2) // GET /api/user
|
|
2551
|
+
* ```
|
|
2552
|
+
*/
|
|
1968
2553
|
route(path, app) {
|
|
1969
2554
|
const subApp = this.basePath(path);
|
|
1970
2555
|
app.routes.map((r) => {
|
|
@@ -1979,19 +2564,95 @@ var Hono = class {
|
|
|
1979
2564
|
});
|
|
1980
2565
|
return this;
|
|
1981
2566
|
}
|
|
2567
|
+
/**
|
|
2568
|
+
* `.basePath()` allows base paths to be specified.
|
|
2569
|
+
*
|
|
2570
|
+
* @see {@link https://hono.dev/docs/api/routing#base-path}
|
|
2571
|
+
*
|
|
2572
|
+
* @param {string} path - base Path
|
|
2573
|
+
* @returns {Hono} changed Hono instance
|
|
2574
|
+
*
|
|
2575
|
+
* @example
|
|
2576
|
+
* ```ts
|
|
2577
|
+
* const api = new Hono().basePath('/api')
|
|
2578
|
+
* ```
|
|
2579
|
+
*/
|
|
1982
2580
|
basePath(path) {
|
|
1983
2581
|
const subApp = this.#clone();
|
|
1984
2582
|
subApp._basePath = mergePath(this._basePath, path);
|
|
1985
2583
|
return subApp;
|
|
1986
2584
|
}
|
|
2585
|
+
/**
|
|
2586
|
+
* `.onError()` handles an error and returns a customized Response.
|
|
2587
|
+
*
|
|
2588
|
+
* @see {@link https://hono.dev/docs/api/hono#error-handling}
|
|
2589
|
+
*
|
|
2590
|
+
* @param {ErrorHandler} handler - request Handler for error
|
|
2591
|
+
* @returns {Hono} changed Hono instance
|
|
2592
|
+
*
|
|
2593
|
+
* @example
|
|
2594
|
+
* ```ts
|
|
2595
|
+
* app.onError((err, c) => {
|
|
2596
|
+
* console.error(`${err}`)
|
|
2597
|
+
* return c.text('Custom Error Message', 500)
|
|
2598
|
+
* })
|
|
2599
|
+
* ```
|
|
2600
|
+
*/
|
|
1987
2601
|
onError = (handler) => {
|
|
1988
2602
|
this.errorHandler = handler;
|
|
1989
2603
|
return this;
|
|
1990
2604
|
};
|
|
2605
|
+
/**
|
|
2606
|
+
* `.notFound()` allows you to customize a Not Found Response.
|
|
2607
|
+
*
|
|
2608
|
+
* @see {@link https://hono.dev/docs/api/hono#not-found}
|
|
2609
|
+
*
|
|
2610
|
+
* @param {NotFoundHandler} handler - request handler for not-found
|
|
2611
|
+
* @returns {Hono} changed Hono instance
|
|
2612
|
+
*
|
|
2613
|
+
* @example
|
|
2614
|
+
* ```ts
|
|
2615
|
+
* app.notFound((c) => {
|
|
2616
|
+
* return c.text('Custom 404 Message', 404)
|
|
2617
|
+
* })
|
|
2618
|
+
* ```
|
|
2619
|
+
*/
|
|
1991
2620
|
notFound = (handler) => {
|
|
1992
2621
|
this.#notFoundHandler = handler;
|
|
1993
2622
|
return this;
|
|
1994
2623
|
};
|
|
2624
|
+
/**
|
|
2625
|
+
* `.mount()` allows you to mount applications built with other frameworks into your Hono application.
|
|
2626
|
+
*
|
|
2627
|
+
* @see {@link https://hono.dev/docs/api/hono#mount}
|
|
2628
|
+
*
|
|
2629
|
+
* @param {string} path - base Path
|
|
2630
|
+
* @param {Function} applicationHandler - other Request Handler
|
|
2631
|
+
* @param {MountOptions} [options] - options of `.mount()`
|
|
2632
|
+
* @returns {Hono} mounted Hono instance
|
|
2633
|
+
*
|
|
2634
|
+
* @example
|
|
2635
|
+
* ```ts
|
|
2636
|
+
* import { Router as IttyRouter } from 'itty-router'
|
|
2637
|
+
* import { Hono } from 'hono'
|
|
2638
|
+
* // Create itty-router application
|
|
2639
|
+
* const ittyRouter = IttyRouter()
|
|
2640
|
+
* // GET /itty-router/hello
|
|
2641
|
+
* ittyRouter.get('/hello', () => new Response('Hello from itty-router'))
|
|
2642
|
+
*
|
|
2643
|
+
* const app = new Hono()
|
|
2644
|
+
* app.mount('/itty-router', ittyRouter.handle)
|
|
2645
|
+
* ```
|
|
2646
|
+
*
|
|
2647
|
+
* @example
|
|
2648
|
+
* ```ts
|
|
2649
|
+
* const app = new Hono()
|
|
2650
|
+
* // Send the request to another application without modification.
|
|
2651
|
+
* app.mount('/app', anotherApp, {
|
|
2652
|
+
* replaceRequest: (req) => req,
|
|
2653
|
+
* })
|
|
2654
|
+
* ```
|
|
2655
|
+
*/
|
|
1995
2656
|
mount(path, applicationHandler, options) {
|
|
1996
2657
|
let replaceRequest;
|
|
1997
2658
|
let optionHandler;
|
|
@@ -2091,9 +2752,32 @@ var Hono = class {
|
|
|
2091
2752
|
}
|
|
2092
2753
|
})();
|
|
2093
2754
|
}
|
|
2755
|
+
/**
|
|
2756
|
+
* `.fetch()` will be entry point of your app.
|
|
2757
|
+
*
|
|
2758
|
+
* @see {@link https://hono.dev/docs/api/hono#fetch}
|
|
2759
|
+
*
|
|
2760
|
+
* @param {Request} request - request Object of request
|
|
2761
|
+
* @param {Env} Env - env Object
|
|
2762
|
+
* @param {ExecutionContext} - context of execution
|
|
2763
|
+
* @returns {Response | Promise<Response>} response of request
|
|
2764
|
+
*
|
|
2765
|
+
*/
|
|
2094
2766
|
fetch = (request, ...rest) => {
|
|
2095
2767
|
return this.#dispatch(request, rest[1], rest[0], request.method);
|
|
2096
2768
|
};
|
|
2769
|
+
/**
|
|
2770
|
+
* `.request()` is a useful method for testing.
|
|
2771
|
+
* You can pass a URL or pathname to send a GET request.
|
|
2772
|
+
* app will return a Response object.
|
|
2773
|
+
* ```ts
|
|
2774
|
+
* test('GET /hello is ok', async () => {
|
|
2775
|
+
* const res = await app.request('/hello')
|
|
2776
|
+
* expect(res.status).toBe(200)
|
|
2777
|
+
* })
|
|
2778
|
+
* ```
|
|
2779
|
+
* @see https://hono.dev/docs/api/hono#request
|
|
2780
|
+
*/
|
|
2097
2781
|
request = (input, requestInit, Env, executionCtx) => {
|
|
2098
2782
|
if (input instanceof Request) {
|
|
2099
2783
|
return this.fetch(requestInit ? new Request(input, requestInit) : input, Env, executionCtx);
|
|
@@ -2108,6 +2792,23 @@ var Hono = class {
|
|
|
2108
2792
|
executionCtx
|
|
2109
2793
|
);
|
|
2110
2794
|
};
|
|
2795
|
+
/**
|
|
2796
|
+
* `.fire()` automatically adds a global fetch event listener.
|
|
2797
|
+
* This can be useful for environments that adhere to the Service Worker API, such as non-ES module Cloudflare Workers.
|
|
2798
|
+
* @deprecated
|
|
2799
|
+
* Use `fire` from `hono/service-worker` instead.
|
|
2800
|
+
* ```ts
|
|
2801
|
+
* import { Hono } from 'hono'
|
|
2802
|
+
* import { fire } from 'hono/service-worker'
|
|
2803
|
+
*
|
|
2804
|
+
* const app = new Hono()
|
|
2805
|
+
* // ...
|
|
2806
|
+
* fire(app)
|
|
2807
|
+
* ```
|
|
2808
|
+
* @see https://hono.dev/docs/api/hono#fire
|
|
2809
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API
|
|
2810
|
+
* @see https://developers.cloudflare.com/workers/reference/migrate-to-module-workers/
|
|
2811
|
+
*/
|
|
2111
2812
|
fire = () => {
|
|
2112
2813
|
addEventListener("fetch", (event) => {
|
|
2113
2814
|
event.respondWith(this.#dispatch(event.request, event, void 0, event.request.method));
|
|
@@ -2115,11 +2816,32 @@ var Hono = class {
|
|
|
2115
2816
|
};
|
|
2116
2817
|
};
|
|
2117
2818
|
|
|
2118
|
-
// ../../node_modules/hono/dist/router/reg-exp-router/
|
|
2819
|
+
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/router/reg-exp-router/matcher.js
|
|
2820
|
+
var emptyParam = [];
|
|
2821
|
+
function match(method, path) {
|
|
2822
|
+
const matchers = this.buildAllMatchers();
|
|
2823
|
+
const match2 = ((method2, path2) => {
|
|
2824
|
+
const matcher = matchers[method2] || matchers[METHOD_NAME_ALL];
|
|
2825
|
+
const staticMatch = matcher[2][path2];
|
|
2826
|
+
if (staticMatch) {
|
|
2827
|
+
return staticMatch;
|
|
2828
|
+
}
|
|
2829
|
+
const match3 = path2.match(matcher[0]);
|
|
2830
|
+
if (!match3) {
|
|
2831
|
+
return [[], emptyParam];
|
|
2832
|
+
}
|
|
2833
|
+
const index = match3.indexOf("", 1);
|
|
2834
|
+
return [matcher[1][index], match3];
|
|
2835
|
+
});
|
|
2836
|
+
this.match = match2;
|
|
2837
|
+
return match2(method, path);
|
|
2838
|
+
}
|
|
2839
|
+
|
|
2840
|
+
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/router/reg-exp-router/node.js
|
|
2119
2841
|
var LABEL_REG_EXP_STR = "[^/]+";
|
|
2120
2842
|
var ONLY_WILDCARD_REG_EXP_STR = ".*";
|
|
2121
2843
|
var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
|
|
2122
|
-
var PATH_ERROR = Symbol();
|
|
2844
|
+
var PATH_ERROR = /* @__PURE__ */ Symbol();
|
|
2123
2845
|
var regExpMetaChars = new Set(".\\+*[^]$()");
|
|
2124
2846
|
function compareKey(a, b) {
|
|
2125
2847
|
if (a.length === 1) {
|
|
@@ -2140,7 +2862,7 @@ function compareKey(a, b) {
|
|
|
2140
2862
|
}
|
|
2141
2863
|
return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length;
|
|
2142
2864
|
}
|
|
2143
|
-
var Node = class {
|
|
2865
|
+
var Node = class _Node {
|
|
2144
2866
|
#index;
|
|
2145
2867
|
#varIndex;
|
|
2146
2868
|
#children = /* @__PURE__ */ Object.create(null);
|
|
@@ -2180,7 +2902,7 @@ var Node = class {
|
|
|
2180
2902
|
if (pathErrorCheckOnly) {
|
|
2181
2903
|
return;
|
|
2182
2904
|
}
|
|
2183
|
-
node = this.#children[regexpStr] = new
|
|
2905
|
+
node = this.#children[regexpStr] = new _Node();
|
|
2184
2906
|
if (name !== "") {
|
|
2185
2907
|
node.#varIndex = context.varIndex++;
|
|
2186
2908
|
}
|
|
@@ -2199,7 +2921,7 @@ var Node = class {
|
|
|
2199
2921
|
if (pathErrorCheckOnly) {
|
|
2200
2922
|
return;
|
|
2201
2923
|
}
|
|
2202
|
-
node = this.#children[token] = new
|
|
2924
|
+
node = this.#children[token] = new _Node();
|
|
2203
2925
|
}
|
|
2204
2926
|
}
|
|
2205
2927
|
node.insert(restTokens, index, paramMap, context, pathErrorCheckOnly);
|
|
@@ -2223,7 +2945,7 @@ var Node = class {
|
|
|
2223
2945
|
}
|
|
2224
2946
|
};
|
|
2225
2947
|
|
|
2226
|
-
// ../../node_modules/hono/dist/router/reg-exp-router/trie.js
|
|
2948
|
+
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/router/reg-exp-router/trie.js
|
|
2227
2949
|
var Trie = class {
|
|
2228
2950
|
#context = { varIndex: 0 };
|
|
2229
2951
|
#root = new Node();
|
|
@@ -2279,8 +3001,7 @@ var Trie = class {
|
|
|
2279
3001
|
}
|
|
2280
3002
|
};
|
|
2281
3003
|
|
|
2282
|
-
// ../../node_modules/hono/dist/router/reg-exp-router/router.js
|
|
2283
|
-
var emptyParam = [];
|
|
3004
|
+
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/router/reg-exp-router/router.js
|
|
2284
3005
|
var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)];
|
|
2285
3006
|
var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
2286
3007
|
function buildWildcardRegExp(path) {
|
|
@@ -2427,30 +3148,14 @@ var RegExpRouter = class {
|
|
|
2427
3148
|
});
|
|
2428
3149
|
}
|
|
2429
3150
|
}
|
|
2430
|
-
match
|
|
2431
|
-
|
|
2432
|
-
const matchers = this.#buildAllMatchers();
|
|
2433
|
-
this.match = (method2, path2) => {
|
|
2434
|
-
const matcher = matchers[method2] || matchers[METHOD_NAME_ALL];
|
|
2435
|
-
const staticMatch = matcher[2][path2];
|
|
2436
|
-
if (staticMatch) {
|
|
2437
|
-
return staticMatch;
|
|
2438
|
-
}
|
|
2439
|
-
const match = path2.match(matcher[0]);
|
|
2440
|
-
if (!match) {
|
|
2441
|
-
return [[], emptyParam];
|
|
2442
|
-
}
|
|
2443
|
-
const index = match.indexOf("", 1);
|
|
2444
|
-
return [matcher[1][index], match];
|
|
2445
|
-
};
|
|
2446
|
-
return this.match(method, path);
|
|
2447
|
-
}
|
|
2448
|
-
#buildAllMatchers() {
|
|
3151
|
+
match = match;
|
|
3152
|
+
buildAllMatchers() {
|
|
2449
3153
|
const matchers = /* @__PURE__ */ Object.create(null);
|
|
2450
3154
|
Object.keys(this.#routes).concat(Object.keys(this.#middleware)).forEach((method) => {
|
|
2451
3155
|
matchers[method] ||= this.#buildMatcher(method);
|
|
2452
3156
|
});
|
|
2453
3157
|
this.#middleware = this.#routes = void 0;
|
|
3158
|
+
clearWildcardRegExpCache();
|
|
2454
3159
|
return matchers;
|
|
2455
3160
|
}
|
|
2456
3161
|
#buildMatcher(method) {
|
|
@@ -2475,7 +3180,7 @@ var RegExpRouter = class {
|
|
|
2475
3180
|
}
|
|
2476
3181
|
};
|
|
2477
3182
|
|
|
2478
|
-
// ../../node_modules/hono/dist/router/smart-router/router.js
|
|
3183
|
+
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/router/smart-router/router.js
|
|
2479
3184
|
var SmartRouter = class {
|
|
2480
3185
|
name = "SmartRouter";
|
|
2481
3186
|
#routers = [];
|
|
@@ -2530,9 +3235,9 @@ var SmartRouter = class {
|
|
|
2530
3235
|
}
|
|
2531
3236
|
};
|
|
2532
3237
|
|
|
2533
|
-
// ../../node_modules/hono/dist/router/trie-router/node.js
|
|
3238
|
+
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/router/trie-router/node.js
|
|
2534
3239
|
var emptyParams = /* @__PURE__ */ Object.create(null);
|
|
2535
|
-
var Node2 = class {
|
|
3240
|
+
var Node2 = class _Node2 {
|
|
2536
3241
|
#methods;
|
|
2537
3242
|
#children;
|
|
2538
3243
|
#patterns;
|
|
@@ -2565,7 +3270,7 @@ var Node2 = class {
|
|
|
2565
3270
|
}
|
|
2566
3271
|
continue;
|
|
2567
3272
|
}
|
|
2568
|
-
curNode.#children[key] = new
|
|
3273
|
+
curNode.#children[key] = new _Node2();
|
|
2569
3274
|
if (pattern) {
|
|
2570
3275
|
curNode.#patterns.push(pattern);
|
|
2571
3276
|
possibleKeys.push(pattern[1]);
|
|
@@ -2688,7 +3393,7 @@ var Node2 = class {
|
|
|
2688
3393
|
}
|
|
2689
3394
|
};
|
|
2690
3395
|
|
|
2691
|
-
// ../../node_modules/hono/dist/router/trie-router/router.js
|
|
3396
|
+
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/router/trie-router/router.js
|
|
2692
3397
|
var TrieRouter = class {
|
|
2693
3398
|
name = "TrieRouter";
|
|
2694
3399
|
#node;
|
|
@@ -2710,8 +3415,13 @@ var TrieRouter = class {
|
|
|
2710
3415
|
}
|
|
2711
3416
|
};
|
|
2712
3417
|
|
|
2713
|
-
// ../../node_modules/hono/dist/hono.js
|
|
3418
|
+
// ../../node_modules/.deno/hono@4.11.3/node_modules/hono/dist/hono.js
|
|
2714
3419
|
var Hono2 = class extends Hono {
|
|
3420
|
+
/**
|
|
3421
|
+
* Creates an instance of the Hono class.
|
|
3422
|
+
*
|
|
3423
|
+
* @param options - Optional configuration options for the Hono instance.
|
|
3424
|
+
*/
|
|
2715
3425
|
constructor(options = {}) {
|
|
2716
3426
|
super(options);
|
|
2717
3427
|
this.router = options.router ?? new SmartRouter({
|
|
@@ -2720,29 +3430,6 @@ var Hono2 = class extends Hono {
|
|
|
2720
3430
|
}
|
|
2721
3431
|
};
|
|
2722
3432
|
|
|
2723
|
-
// ../../node_modules/hono/dist/http-exception.js
|
|
2724
|
-
var HTTPException = class extends Error {
|
|
2725
|
-
res;
|
|
2726
|
-
status;
|
|
2727
|
-
constructor(status = 500, options) {
|
|
2728
|
-
super(options?.message, { cause: options?.cause });
|
|
2729
|
-
this.res = options?.res;
|
|
2730
|
-
this.status = status;
|
|
2731
|
-
}
|
|
2732
|
-
getResponse() {
|
|
2733
|
-
if (this.res) {
|
|
2734
|
-
const newResponse = new Response(this.res.body, {
|
|
2735
|
-
status: this.status,
|
|
2736
|
-
headers: this.res.headers
|
|
2737
|
-
});
|
|
2738
|
-
return newResponse;
|
|
2739
|
-
}
|
|
2740
|
-
return new Response(this.message, {
|
|
2741
|
-
status: this.status
|
|
2742
|
-
});
|
|
2743
|
-
}
|
|
2744
|
-
};
|
|
2745
|
-
|
|
2746
3433
|
// src/server.ts
|
|
2747
3434
|
async function handleError2(context, pluginOptions, error) {
|
|
2748
3435
|
console.error(error);
|