From 7908c833d2f12870cddf7801bb91d46a2007dcc1 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Sun, 7 Dec 2025 15:37:31 -0800 Subject: Bump pengueno --- .ci/ci.cjs | 5251 +++++++++++++++++++++++++------------------------ .ci/package-lock.json | 45 +- .ci/package.json | 3 +- 3 files changed, 2684 insertions(+), 2615 deletions(-) (limited to '.ci') diff --git a/.ci/ci.cjs b/.ci/ci.cjs index eb1854e..2555c6c 100755 --- a/.ci/ci.cjs +++ b/.ci/ci.cjs @@ -26,9 +26,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge mod )); -// node_modules/@emprespresso/pengueno/dist/leftpadesque/prepend.js +// ../node_modules/@emprespresso/pengueno/dist/leftpadesque/prepend.js var require_prepend = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/leftpadesque/prepend.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/leftpadesque/prepend.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.prependWith = void 0; @@ -37,9 +37,9 @@ var require_prepend = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/leftpadesque/debug.js +// ../node_modules/@emprespresso/pengueno/dist/leftpadesque/debug.js var require_debug = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/leftpadesque/debug.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/leftpadesque/debug.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.isDebug = exports2.isProd = void 0; @@ -53,9 +53,9 @@ var require_debug = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/leftpadesque/memoize.js +// ../node_modules/@emprespresso/pengueno/dist/leftpadesque/memoize.js var require_memoize = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/leftpadesque/memoize.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/leftpadesque/memoize.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.memoize = void 0; @@ -75,9 +75,9 @@ var require_memoize = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/leftpadesque/index.js +// ../node_modules/@emprespresso/pengueno/dist/leftpadesque/index.js var require_leftpadesque = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/leftpadesque/index.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/leftpadesque/index.js"(exports2) { "use strict"; var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) { if (k2 === void 0) k2 = k; @@ -102,28 +102,28 @@ var require_leftpadesque = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/types/misc.js +// ../node_modules/@emprespresso/pengueno/dist/types/misc.js var require_misc = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/types/misc.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/types/misc.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); } }); -// node_modules/@emprespresso/pengueno/dist/types/object.js +// ../node_modules/@emprespresso/pengueno/dist/types/object.js var require_object = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/types/object.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/types/object.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.isObject = void 0; - var isObject3 = (o) => typeof o === "object" && !Array.isArray(o) && !!o; - exports2.isObject = isObject3; + var isObject5 = (o) => typeof o === "object" && !Array.isArray(o) && !!o; + exports2.isObject = isObject5; } }); -// node_modules/@emprespresso/pengueno/dist/types/tagged.js +// ../node_modules/@emprespresso/pengueno/dist/types/tagged.js var require_tagged = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/types/tagged.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/types/tagged.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.isTagged = void 0; @@ -133,17 +133,17 @@ var require_tagged = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/types/fn/callable.js +// ../node_modules/@emprespresso/pengueno/dist/types/fn/callable.js var require_callable = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/types/fn/callable.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/types/fn/callable.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); } }); -// node_modules/@emprespresso/pengueno/dist/types/fn/optional.js +// ../node_modules/@emprespresso/pengueno/dist/types/fn/optional.js var require_optional = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/types/fn/optional.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/types/fn/optional.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.Optional = exports2.IOptionalEmptyError = exports2.isOptional = exports2.IOptionalTag = void 0; @@ -222,9 +222,9 @@ var require_optional = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/types/fn/either.js +// ../node_modules/@emprespresso/pengueno/dist/types/fn/either.js var require_either = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/types/fn/either.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/types/fn/either.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.Either = exports2.isRight = exports2.isLeft = exports2.isEither = exports2.IEitherTag = void 0; @@ -244,7 +244,7 @@ var require_either = __commonJS({ this._tag = _tag; } }; - var Either2 = class _Either extends _Tagged { + var Either3 = class _Either extends _Tagged { self; constructor(self) { super(); @@ -345,13 +345,13 @@ var require_either = __commonJS({ return new Promise((res) => setTimeout(res, wait)); } }; - exports2.Either = Either2; + exports2.Either = Either3; } }); -// node_modules/@emprespresso/pengueno/dist/types/fn/index.js +// ../node_modules/@emprespresso/pengueno/dist/types/fn/index.js var require_fn = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/types/fn/index.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/types/fn/index.js"(exports2) { "use strict"; var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) { if (k2 === void 0) k2 = k; @@ -376,9 +376,9 @@ var require_fn = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/types/collections/cons.js +// ../node_modules/@emprespresso/pengueno/dist/types/collections/cons.js var require_cons = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/types/collections/cons.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/types/collections/cons.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.ListZipper = exports2.Cons = void 0; @@ -458,9 +458,9 @@ var require_cons = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/types/collections/jsonds.js +// ../node_modules/@emprespresso/pengueno/dist/types/collections/jsonds.js var require_jsonds = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/types/collections/jsonds.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/types/collections/jsonds.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.JSONHashMap = exports2.JSONSet = void 0; @@ -524,9 +524,9 @@ var require_jsonds = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/types/collections/index.js +// ../node_modules/@emprespresso/pengueno/dist/types/collections/index.js var require_collections = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/types/collections/index.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/types/collections/index.js"(exports2) { "use strict"; var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) { if (k2 === void 0) k2 = k; @@ -550,9 +550,9 @@ var require_collections = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/types/index.js +// ../node_modules/@emprespresso/pengueno/dist/types/index.js var require_types = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/types/index.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/types/index.js"(exports2) { "use strict"; var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) { if (k2 === void 0) k2 = k; @@ -579,9 +579,9 @@ var require_types = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/trace/itrace.js +// ../node_modules/@emprespresso/pengueno/dist/trace/itrace.js var require_itrace = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/trace/itrace.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/trace/itrace.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.TraceableImpl = void 0; @@ -628,9 +628,9 @@ var require_itrace = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/trace/metric/emittable.js +// ../node_modules/@emprespresso/pengueno/dist/trace/metric/emittable.js var require_emittable = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/trace/metric/emittable.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/trace/metric/emittable.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.EmittableMetric = void 0; @@ -656,9 +656,9 @@ var require_emittable = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/trace/metric/metric.js +// ../node_modules/@emprespresso/pengueno/dist/trace/metric/metric.js var require_metric = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/trace/metric/metric.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/trace/metric/metric.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.ResultMetric = exports2.Metric = void 0; @@ -722,9 +722,9 @@ var require_metric = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/trace/metric/trace.js +// ../node_modules/@emprespresso/pengueno/dist/trace/metric/trace.js var require_trace = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/trace/metric/trace.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/trace/metric/trace.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.MetricsTrace = exports2.isMetricsTraceSupplier = void 0; @@ -788,9 +788,9 @@ var require_trace = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/trace/metric/index.js +// ../node_modules/@emprespresso/pengueno/dist/trace/metric/index.js var require_metric2 = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/trace/metric/index.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/trace/metric/index.js"(exports2) { "use strict"; var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) { if (k2 === void 0) k2 = k; @@ -828,9 +828,9 @@ var require_metric2 = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/trace/log/ansi.js +// ../node_modules/@emprespresso/pengueno/dist/trace/log/ansi.js var require_ansi = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/trace/log/ansi.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/trace/log/ansi.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.ANSI = void 0; @@ -852,9 +852,9 @@ var require_ansi = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/trace/log/level.js +// ../node_modules/@emprespresso/pengueno/dist/trace/log/level.js var require_level = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/trace/log/level.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/trace/log/level.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.isLogLevel = exports2.logLevelOrder = exports2.LogLevel = void 0; @@ -879,17 +879,17 @@ var require_level = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/trace/log/logger.js +// ../node_modules/@emprespresso/pengueno/dist/trace/log/logger.js var require_logger = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/trace/log/logger.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/trace/log/logger.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); } }); -// node_modules/@emprespresso/pengueno/dist/trace/log/pretty_json_console.js +// ../node_modules/@emprespresso/pengueno/dist/trace/log/pretty_json_console.js var require_pretty_json_console = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/trace/log/pretty_json_console.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/trace/log/pretty_json_console.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.PrettyJsonConsoleLogger = void 0; @@ -930,9 +930,9 @@ var require_pretty_json_console = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/trace/log/trace.js +// ../node_modules/@emprespresso/pengueno/dist/trace/log/trace.js var require_trace2 = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/trace/log/trace.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/trace/log/trace.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.LogTrace = void 0; @@ -989,9 +989,9 @@ var require_trace2 = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/trace/log/index.js +// ../node_modules/@emprespresso/pengueno/dist/trace/log/index.js var require_log = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/trace/log/index.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/trace/log/index.js"(exports2) { "use strict"; var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) { if (k2 === void 0) k2 = k; @@ -1018,9 +1018,9 @@ var require_log = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/trace/trace.js +// ../node_modules/@emprespresso/pengueno/dist/trace/trace.js var require_trace3 = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/trace/trace.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/trace/trace.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.LogMetricTraceable = exports2.LogMetricTrace = exports2.EmbeddedMetricsTraceable = exports2.LogTraceable = void 0; @@ -1081,9 +1081,9 @@ var require_trace3 = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/trace/util.js +// ../node_modules/@emprespresso/pengueno/dist/trace/util.js var require_util = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/trace/util.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/trace/util.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.TraceUtil = void 0; @@ -1116,9 +1116,9 @@ var require_util = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/trace/index.js +// ../node_modules/@emprespresso/pengueno/dist/trace/index.js var require_trace4 = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/trace/index.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/trace/index.js"(exports2) { "use strict"; var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) { if (k2 === void 0) k2 = k; @@ -1145,9 +1145,9 @@ var require_trace4 = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/process/exec.js +// ../node_modules/@emprespresso/pengueno/dist/process/exec.js var require_exec = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/process/exec.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/process/exec.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.getStdoutMany = exports2.getStdout = exports2.CmdMetric = void 0; @@ -1199,9 +1199,9 @@ var require_exec = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/process/env.js +// ../node_modules/@emprespresso/pengueno/dist/process/env.js var require_env = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/process/env.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/process/env.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.getRequiredEnvVars = exports2.getRequiredEnv = exports2.getEnv = void 0; @@ -1222,15 +1222,15 @@ var require_env = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/process/validate_identifier.js +// ../node_modules/@emprespresso/pengueno/dist/process/validate_identifier.js var require_validate_identifier = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/process/validate_identifier.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/process/validate_identifier.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.validateExecutionEntries = exports2.validateIdentifier = void 0; var pengueno_1 = require_dist2(); var validateIdentifier = (token) => { - return /^[a-zA-Z0-9_\-:. \/]+$/.test(token) && !token.includes(".."); + return /^[a-zA-Z0-9_\?\&\=\-:. \/]+$/.test(token) && !token.includes(".."); }; exports2.validateIdentifier = validateIdentifier; var validateExecutionEntries = (obj) => { @@ -1243,9 +1243,9 @@ var require_validate_identifier = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/process/argv.js +// ../node_modules/@emprespresso/pengueno/dist/process/argv.js var require_argv = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/process/argv.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/process/argv.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.argv = exports2.getArg = exports2.isArgKey = void 0; @@ -1276,9 +1276,9 @@ var require_argv = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/process/signals.js +// ../node_modules/@emprespresso/pengueno/dist/process/signals.js var require_signals = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/process/signals.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/process/signals.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.Signals = exports2.SigTermMetric = exports2.SigIntMetric = void 0; @@ -1301,9 +1301,9 @@ var require_signals = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/process/index.js +// ../node_modules/@emprespresso/pengueno/dist/process/index.js var require_process = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/process/index.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/process/index.js"(exports2) { "use strict"; var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) { if (k2 === void 0) k2 = k; @@ -1330,17 +1330,17 @@ var require_process = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/server/http/body.js +// ../node_modules/@emprespresso/pengueno/dist/server/http/body.js var require_body = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/server/http/body.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/server/http/body.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); } }); -// node_modules/@emprespresso/pengueno/dist/server/http/status.js +// ../node_modules/@emprespresso/pengueno/dist/server/http/status.js var require_status = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/server/http/status.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/server/http/status.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.HttpStatusCodes = void 0; @@ -1418,17 +1418,17 @@ var require_status = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/server/http/method.js +// ../node_modules/@emprespresso/pengueno/dist/server/http/method.js var require_method = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/server/http/method.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/server/http/method.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); } }); -// node_modules/@emprespresso/pengueno/dist/server/http/index.js +// ../node_modules/@emprespresso/pengueno/dist/server/http/index.js var require_http = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/server/http/index.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/server/http/index.js"(exports2) { "use strict"; var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) { if (k2 === void 0) k2 = k; @@ -1453,9 +1453,9 @@ var require_http = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/server/response/pengueno.js +// ../node_modules/@emprespresso/pengueno/dist/server/response/pengueno.js var require_pengueno = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/server/response/pengueno.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/server/response/pengueno.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.JsonResponse = exports2.PenguenoResponse = exports2.getResponseMetrics = void 0; @@ -1505,9 +1505,9 @@ var require_pengueno = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/server/response/index.js +// ../node_modules/@emprespresso/pengueno/dist/server/response/index.js var require_response = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/server/response/index.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/server/response/index.js"(exports2) { "use strict"; var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) { if (k2 === void 0) k2 = k; @@ -1530,9 +1530,9 @@ var require_response = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/server/request/pengueno.js +// ../node_modules/@emprespresso/pengueno/dist/server/request/pengueno.js var require_pengueno2 = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/server/request/pengueno.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/server/request/pengueno.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.PenguenoRequest = void 0; @@ -1579,9 +1579,9 @@ var require_pengueno2 = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/server/request/index.js +// ../node_modules/@emprespresso/pengueno/dist/server/request/index.js var require_request = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/server/request/index.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/server/request/index.js"(exports2) { "use strict"; var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) { if (k2 === void 0) k2 = k; @@ -1604,9 +1604,9 @@ var require_request = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/server/activity/health.js +// ../node_modules/@emprespresso/pengueno/dist/server/activity/health.js var require_health = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/server/activity/health.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/server/activity/health.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.HealthCheckActivityImpl = exports2.HealthCheckOutput = exports2.HealthCheckInput = void 0; @@ -1636,9 +1636,9 @@ var require_health = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/server/activity/fourohfour.js +// ../node_modules/@emprespresso/pengueno/dist/server/activity/fourohfour.js var require_fourohfour = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/server/activity/fourohfour.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/server/activity/fourohfour.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.FourOhFourActivityImpl = void 0; @@ -1659,9 +1659,9 @@ var require_fourohfour = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/server/activity/index.js +// ../node_modules/@emprespresso/pengueno/dist/server/activity/index.js var require_activity = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/server/activity/index.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/server/activity/index.js"(exports2) { "use strict"; var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) { if (k2 === void 0) k2 = k; @@ -1685,9 +1685,9 @@ var require_activity = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/server/filter/method.js +// ../node_modules/@emprespresso/pengueno/dist/server/filter/method.js var require_method2 = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/server/filter/method.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/server/filter/method.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.requireMethod = void 0; @@ -1705,9 +1705,9 @@ var require_method2 = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/server/filter/json.js +// ../node_modules/@emprespresso/pengueno/dist/server/filter/json.js var require_json = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/server/filter/json.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/server/filter/json.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.jsonModel = void 0; @@ -1721,9 +1721,9 @@ var require_json = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/server/filter/index.js +// ../node_modules/@emprespresso/pengueno/dist/server/filter/index.js var require_filter = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/server/filter/index.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/server/filter/index.js"(exports2) { "use strict"; var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) { if (k2 === void 0) k2 = k; @@ -1766,15 +1766,13 @@ var require_filter = __commonJS({ } }); -// ../node_modules/@hono/node-server/dist/index.js -var require_dist = __commonJS({ - "../node_modules/@hono/node-server/dist/index.js"(exports2, module2) { +// ../node_modules/hono/dist/cjs/compose.js +var require_compose = __commonJS({ + "../node_modules/hono/dist/cjs/compose.js"(exports2, module2) { "use strict"; - var __create2 = Object.create; var __defProp2 = Object.defineProperty; var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor; var __getOwnPropNames2 = Object.getOwnPropertyNames; - var __getProtoOf2 = Object.getPrototypeOf; var __hasOwnProp2 = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) @@ -1788,589 +1786,481 @@ var require_dist = __commonJS({ } return to; }; - var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2( - // If the importer is in node compatibility mode or this is not an ESM - // file that has been converted to a CommonJS file using a Babel- - // compatible transform (i.e. "__esModule" has not been set), then set - // "default" to the CommonJS "module.exports" for node compatibility. - isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target, - mod - )); var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod); - var src_exports = {}; - __export(src_exports, { - RequestError: () => RequestError, - createAdaptorServer: () => createAdaptorServer, - getRequestListener: () => getRequestListener, - serve: () => serve + var compose_exports = {}; + __export(compose_exports, { + compose: () => compose }); - module2.exports = __toCommonJS(src_exports); - var import_node_http = require("http"); - var import_node_http22 = require("http2"); - var import_node_http2 = require("http2"); - var import_node_stream = require("stream"); - var RequestError = class extends Error { - constructor(message, options) { - super(message, options); - this.name = "RequestError"; - } - }; - var toRequestError = (e) => { - if (e instanceof RequestError) { - return e; - } - return new RequestError(e.message, { cause: e }); - }; - var GlobalRequest = global.Request; - var Request2 = class extends GlobalRequest { - constructor(input, options) { - if (typeof input === "object" && getRequestCache in input) { - input = input[getRequestCache](); - } - if (typeof options?.body?.getReader !== "undefined") { - ; - options.duplex ??= "half"; + module2.exports = __toCommonJS(compose_exports); + var compose = (middleware, onError, onNotFound) => { + return (context, next) => { + let index = -1; + return dispatch(0); + async function dispatch(i) { + if (i <= index) { + throw new Error("next() called multiple times"); + } + index = i; + let res; + let isError = false; + let handler; + if (middleware[i]) { + handler = middleware[i][0][0]; + context.req.routeIndex = i; + } else { + handler = i === middleware.length && next || void 0; + } + if (handler) { + try { + res = await handler(context, () => dispatch(i + 1)); + } catch (err) { + if (err instanceof Error && onError) { + context.error = err; + res = await onError(err, context); + isError = true; + } else { + throw err; + } + } + } else { + if (context.finalized === false && onNotFound) { + res = await onNotFound(context); + } + } + if (res && (context.finalized === false || isError)) { + context.res = res; + } + return context; } - super(input, options); - } + }; }; - var newHeadersFromIncoming = (incoming) => { - const headerRecord = []; - const rawHeaders = incoming.rawHeaders; - for (let i = 0; i < rawHeaders.length; i += 2) { - const { [i]: key, [i + 1]: value } = rawHeaders; - if (key.charCodeAt(0) !== /*:*/ - 58) { - headerRecord.push([key, value]); - } + } +}); + +// ../node_modules/hono/dist/cjs/http-exception.js +var require_http_exception = __commonJS({ + "../node_modules/hono/dist/cjs/http-exception.js"(exports2, module2) { + "use strict"; + var __defProp2 = Object.defineProperty; + var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor; + var __getOwnPropNames2 = Object.getOwnPropertyNames; + var __hasOwnProp2 = Object.prototype.hasOwnProperty; + var __export = (target, all) => { + for (var name in all) + __defProp2(target, name, { get: all[name], enumerable: true }); + }; + var __copyProps2 = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames2(from)) + if (!__hasOwnProp2.call(to, key) && key !== except) + __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable }); } - return new Headers(headerRecord); + return to; }; - var wrapBodyStream = Symbol("wrapBodyStream"); - var newRequestFromIncoming = (method, url, headers, incoming, abortController) => { - const init = { - method, - headers, - signal: abortController.signal - }; - if (method === "TRACE") { - init.method = "GET"; - const req = new Request2(url, init); - Object.defineProperty(req, "method", { - get() { - return "TRACE"; - } - }); - return req; + var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod); + var http_exception_exports = {}; + __export(http_exception_exports, { + HTTPException: () => HTTPException + }); + module2.exports = __toCommonJS(http_exception_exports); + var HTTPException = class extends Error { + res; + status; + constructor(status = 500, options) { + super(options?.message, { cause: options?.cause }); + this.res = options?.res; + this.status = status; } - if (!(method === "GET" || method === "HEAD")) { - if ("rawBody" in incoming && incoming.rawBody instanceof Buffer) { - init.body = new ReadableStream({ - start(controller) { - controller.enqueue(incoming.rawBody); - controller.close(); - } - }); - } else if (incoming[wrapBodyStream]) { - let reader; - init.body = new ReadableStream({ - async pull(controller) { - try { - reader ||= import_node_stream.Readable.toWeb(incoming).getReader(); - const { done, value } = await reader.read(); - if (done) { - controller.close(); - } else { - controller.enqueue(value); - } - } catch (error) { - controller.error(error); - } - } + getResponse() { + if (this.res) { + const newResponse = new Response(this.res.body, { + status: this.status, + headers: this.res.headers }); - } else { - init.body = import_node_stream.Readable.toWeb(incoming); + return newResponse; } + return new Response(this.message, { + status: this.status + }); } - return new Request2(url, init); }; - var getRequestCache = Symbol("getRequestCache"); - var requestCache = Symbol("requestCache"); - var incomingKey = Symbol("incomingKey"); - var urlKey = Symbol("urlKey"); - var headersKey = Symbol("headersKey"); - var abortControllerKey = Symbol("abortControllerKey"); - var getAbortController = Symbol("getAbortController"); - var requestPrototype = { - get method() { - return this[incomingKey].method || "GET"; - }, - get url() { - return this[urlKey]; - }, - get headers() { - return this[headersKey] ||= newHeadersFromIncoming(this[incomingKey]); - }, - [getAbortController]() { - this[getRequestCache](); - return this[abortControllerKey]; - }, - [getRequestCache]() { - this[abortControllerKey] ||= new AbortController(); - return this[requestCache] ||= newRequestFromIncoming( - this.method, - this[urlKey], - this.headers, - this[incomingKey], - this[abortControllerKey] - ); + } +}); + +// ../node_modules/hono/dist/cjs/request/constants.js +var require_constants = __commonJS({ + "../node_modules/hono/dist/cjs/request/constants.js"(exports2, module2) { + "use strict"; + var __defProp2 = Object.defineProperty; + var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor; + var __getOwnPropNames2 = Object.getOwnPropertyNames; + var __hasOwnProp2 = Object.prototype.hasOwnProperty; + var __export = (target, all) => { + for (var name in all) + __defProp2(target, name, { get: all[name], enumerable: true }); + }; + var __copyProps2 = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames2(from)) + if (!__hasOwnProp2.call(to, key) && key !== except) + __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable }); } + return to; }; - [ - "body", - "bodyUsed", - "cache", - "credentials", - "destination", - "integrity", - "mode", - "redirect", - "referrer", - "referrerPolicy", - "signal", - "keepalive" - ].forEach((k) => { - Object.defineProperty(requestPrototype, k, { - get() { - return this[getRequestCache]()[k]; - } - }); - }); - ["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => { - Object.defineProperty(requestPrototype, k, { - value: function() { - return this[getRequestCache]()[k](); - } - }); + var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod); + var constants_exports = {}; + __export(constants_exports, { + GET_MATCH_RESULT: () => GET_MATCH_RESULT }); - Object.setPrototypeOf(requestPrototype, Request2.prototype); - var newRequest = (incoming, defaultHostname) => { - const req = Object.create(requestPrototype); - req[incomingKey] = incoming; - const incomingUrl = incoming.url || ""; - if (incomingUrl[0] !== "/" && // short-circuit for performance. most requests are relative URL. - (incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) { - if (incoming instanceof import_node_http2.Http2ServerRequest) { - throw new RequestError("Absolute URL for :path is not allowed in HTTP/2"); - } - try { - const url2 = new URL(incomingUrl); - req[urlKey] = url2.href; - } catch (e) { - throw new RequestError("Invalid absolute URL", { cause: e }); - } - return req; - } - const host = (incoming instanceof import_node_http2.Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname; - if (!host) { - throw new RequestError("Missing host header"); - } - let scheme; - if (incoming instanceof import_node_http2.Http2ServerRequest) { - scheme = incoming.scheme; - if (!(scheme === "http" || scheme === "https")) { - throw new RequestError("Unsupported scheme"); - } - } else { - scheme = incoming.socket && incoming.socket.encrypted ? "https" : "http"; + module2.exports = __toCommonJS(constants_exports); + var GET_MATCH_RESULT = Symbol(); + } +}); + +// ../node_modules/hono/dist/cjs/utils/body.js +var require_body2 = __commonJS({ + "../node_modules/hono/dist/cjs/utils/body.js"(exports2, module2) { + "use strict"; + var __defProp2 = Object.defineProperty; + var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor; + var __getOwnPropNames2 = Object.getOwnPropertyNames; + var __hasOwnProp2 = Object.prototype.hasOwnProperty; + var __export = (target, all) => { + for (var name in all) + __defProp2(target, name, { get: all[name], enumerable: true }); + }; + var __copyProps2 = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames2(from)) + if (!__hasOwnProp2.call(to, key) && key !== except) + __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable }); } - const url = new URL(`${scheme}://${host}${incomingUrl}`); - if (url.hostname.length !== host.length && url.hostname !== host.replace(/:\d+$/, "")) { - throw new RequestError("Invalid host header"); + return to; + }; + var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod); + var body_exports = {}; + __export(body_exports, { + parseBody: () => parseBody + }); + module2.exports = __toCommonJS(body_exports); + var import_request = require_request2(); + var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => { + const { all = false, dot = false } = options; + const headers = request instanceof import_request.HonoRequest ? request.raw.headers : request.headers; + const contentType = headers.get("Content-Type"); + if (contentType?.startsWith("multipart/form-data") || contentType?.startsWith("application/x-www-form-urlencoded")) { + return parseFormData(request, { all, dot }); } - req[urlKey] = url.href; - return req; + return {}; }; - var responseCache = Symbol("responseCache"); - var getResponseCache = Symbol("getResponseCache"); - var cacheKey = Symbol("cache"); - var GlobalResponse = global.Response; - var Response2 = class _Response { - #body; - #init; - [getResponseCache]() { - delete this[cacheKey]; - return this[responseCache] ||= new GlobalResponse(this.#body, this.#init); + async function parseFormData(request, options) { + const formData = await request.formData(); + if (formData) { + return convertFormDataToBodyData(formData, options); } - constructor(body, init) { - let headers; - this.#body = body; - if (init instanceof _Response) { - const cachedGlobalResponse = init[responseCache]; - if (cachedGlobalResponse) { - this.#init = cachedGlobalResponse; - this[getResponseCache](); - return; - } else { - this.#init = init.#init; - headers = new Headers(init.#init.headers); + return {}; + } + function convertFormDataToBodyData(formData, options) { + const form = /* @__PURE__ */ Object.create(null); + formData.forEach((value, key) => { + const shouldParseAllValues = options.all || key.endsWith("[]"); + if (!shouldParseAllValues) { + form[key] = value; + } else { + handleParsingAllValues(form, key, value); + } + }); + if (options.dot) { + Object.entries(form).forEach(([key, value]) => { + const shouldParseDotValues = key.includes("."); + if (shouldParseDotValues) { + handleParsingNestedValues(form, key, value); + delete form[key]; } + }); + } + return form; + } + var handleParsingAllValues = (form, key, value) => { + if (form[key] !== void 0) { + if (Array.isArray(form[key])) { + ; + form[key].push(value); } else { - this.#init = init; + form[key] = [form[key], value]; } - if (typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) { - headers ||= init?.headers || { "content-type": "text/plain; charset=UTF-8" }; - this[cacheKey] = [init?.status || 200, body, headers]; + } else { + if (!key.endsWith("[]")) { + form[key] = value; + } else { + form[key] = [value]; } } - get headers() { - const cache = this[cacheKey]; - if (cache) { - if (!(cache[2] instanceof Headers)) { - cache[2] = new Headers(cache[2]); + }; + var handleParsingNestedValues = (form, key, value) => { + let nestedForm = form; + const keys = key.split("."); + keys.forEach((key2, index) => { + if (index === keys.length - 1) { + nestedForm[key2] = value; + } else { + if (!nestedForm[key2] || typeof nestedForm[key2] !== "object" || Array.isArray(nestedForm[key2]) || nestedForm[key2] instanceof File) { + nestedForm[key2] = /* @__PURE__ */ Object.create(null); } - return cache[2]; + nestedForm = nestedForm[key2]; } - return this[getResponseCache]().headers; - } - get status() { - return this[cacheKey]?.[0] ?? this[getResponseCache]().status; + }); + }; + } +}); + +// ../node_modules/hono/dist/cjs/utils/url.js +var require_url = __commonJS({ + "../node_modules/hono/dist/cjs/utils/url.js"(exports2, module2) { + "use strict"; + var __defProp2 = Object.defineProperty; + var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor; + var __getOwnPropNames2 = Object.getOwnPropertyNames; + var __hasOwnProp2 = Object.prototype.hasOwnProperty; + var __export = (target, all) => { + for (var name in all) + __defProp2(target, name, { get: all[name], enumerable: true }); + }; + var __copyProps2 = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames2(from)) + if (!__hasOwnProp2.call(to, key) && key !== except) + __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable }); } - get ok() { - const status = this.status; - return status >= 200 && status < 300; + return to; + }; + var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod); + var url_exports = {}; + __export(url_exports, { + checkOptionalParameter: () => checkOptionalParameter, + decodeURIComponent_: () => decodeURIComponent_, + getPath: () => getPath, + getPathNoStrict: () => getPathNoStrict, + getPattern: () => getPattern, + getQueryParam: () => getQueryParam, + getQueryParams: () => getQueryParams, + getQueryStrings: () => getQueryStrings, + mergePath: () => mergePath, + splitPath: () => splitPath, + splitRoutingPath: () => splitRoutingPath, + tryDecode: () => tryDecode + }); + module2.exports = __toCommonJS(url_exports); + var splitPath = (path) => { + const paths = path.split("/"); + if (paths[0] === "") { + paths.shift(); } + return paths; }; - ["body", "bodyUsed", "redirected", "statusText", "trailers", "type", "url"].forEach((k) => { - Object.defineProperty(Response2.prototype, k, { - get() { - return this[getResponseCache]()[k]; - } + var splitRoutingPath = (routePath) => { + const { groups, path } = extractGroupsFromPath(routePath); + const paths = splitPath(path); + return replaceGroupMarks(paths, groups); + }; + var extractGroupsFromPath = (path) => { + const groups = []; + path = path.replace(/\{[^}]+\}/g, (match, index) => { + const mark = `@${index}`; + groups.push([mark, match]); + return mark; }); - }); - ["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => { - Object.defineProperty(Response2.prototype, k, { - value: function() { - return this[getResponseCache]()[k](); - } - }); - }); - Object.setPrototypeOf(Response2, GlobalResponse); - Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype); - async function readWithoutBlocking(readPromise) { - return Promise.race([readPromise, Promise.resolve().then(() => Promise.resolve(void 0))]); - } - function writeFromReadableStreamDefaultReader(reader, writable, currentReadPromise) { - const cancel = (error) => { - reader.cancel(error).catch(() => { - }); - }; - writable.on("close", cancel); - writable.on("error", cancel); - (currentReadPromise ?? reader.read()).then(flow, handleStreamError); - return reader.closed.finally(() => { - writable.off("close", cancel); - writable.off("error", cancel); - }); - function handleStreamError(error) { - if (error) { - writable.destroy(error); + return { groups, path }; + }; + var replaceGroupMarks = (paths, groups) => { + for (let i = groups.length - 1; i >= 0; i--) { + const [mark] = groups[i]; + for (let j = paths.length - 1; j >= 0; j--) { + if (paths[j].includes(mark)) { + paths[j] = paths[j].replace(mark, groups[i][1]); + break; + } } } - function onDrain() { - reader.read().then(flow, handleStreamError); + return paths; + }; + var patternCache = {}; + var getPattern = (label, next) => { + if (label === "*") { + return "*"; } - function flow({ done, value }) { - try { - if (done) { - writable.end(); - } else if (!writable.write(value)) { - writable.once("drain", onDrain); + const match = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/); + if (match) { + const cacheKey = `${label}#${next}`; + if (!patternCache[cacheKey]) { + if (match[2]) { + patternCache[cacheKey] = next && next[0] !== ":" && next[0] !== "*" ? [cacheKey, match[1], new RegExp(`^${match[2]}(?=/${next})`)] : [label, match[1], new RegExp(`^${match[2]}$`)]; } else { - return reader.read().then(flow, handleStreamError); + patternCache[cacheKey] = [label, match[1], true]; } - } catch (e) { - handleStreamError(e); } + return patternCache[cacheKey]; } - } - function writeFromReadableStream(stream, writable) { - if (stream.locked) { - throw new TypeError("ReadableStream is locked."); - } else if (writable.destroyed) { - return; - } - return writeFromReadableStreamDefaultReader(stream.getReader(), writable); - } - var buildOutgoingHttpHeaders = (headers) => { - const res = {}; - if (!(headers instanceof Headers)) { - headers = new Headers(headers ?? void 0); + return null; + }; + var tryDecode = (str, decoder) => { + try { + return decoder(str); + } catch { + return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match) => { + try { + return decoder(match); + } catch { + return match; + } + }); } - const cookies = []; - for (const [k, v] of headers) { - if (k === "set-cookie") { - cookies.push(v); - } else { - res[k] = v; + }; + var tryDecodeURI = (str) => tryDecode(str, decodeURI); + var getPath = (request) => { + const url = request.url; + const start = url.indexOf("/", url.indexOf(":") + 4); + let i = start; + for (; i < url.length; i++) { + const charCode = url.charCodeAt(i); + if (charCode === 37) { + const queryIndex = url.indexOf("?", i); + const path = url.slice(start, queryIndex === -1 ? void 0 : queryIndex); + return tryDecodeURI(path.includes("%25") ? path.replace(/%25/g, "%2525") : path); + } else if (charCode === 63) { + break; } } - if (cookies.length > 0) { - res["set-cookie"] = cookies; - } - res["content-type"] ??= "text/plain; charset=UTF-8"; - return res; + return url.slice(start, i); }; - var X_ALREADY_SENT = "x-hono-already-sent"; - var import_node_crypto = __toESM2(require("crypto")); - var webFetch = global.fetch; - if (typeof global.crypto === "undefined") { - global.crypto = import_node_crypto.default; - } - global.fetch = (info, init) => { - init = { - // Disable compression handling so people can return the result of a fetch - // directly in the loader without messing with the Content-Encoding header. - compress: false, - ...init - }; - return webFetch(info, init); + var getQueryStrings = (url) => { + const queryIndex = url.indexOf("?", 8); + return queryIndex === -1 ? "" : "?" + url.slice(queryIndex + 1); }; - var outgoingEnded = Symbol("outgoingEnded"); - var handleRequestError = () => new Response(null, { - status: 400 - }); - var handleFetchError = (e) => new Response(null, { - status: e instanceof Error && (e.name === "TimeoutError" || e.constructor.name === "TimeoutError") ? 504 : 500 - }); - var handleResponseError = (e, outgoing) => { - const err = e instanceof Error ? e : new Error("unknown error", { cause: e }); - if (err.code === "ERR_STREAM_PREMATURE_CLOSE") { - console.info("The user aborted a request."); - } else { - console.error(e); - if (!outgoing.headersSent) { - outgoing.writeHead(500, { "Content-Type": "text/plain" }); - } - outgoing.end(`Error: ${err.message}`); - outgoing.destroy(err); - } + var getPathNoStrict = (request) => { + const result = getPath(request); + return result.length > 1 && result.at(-1) === "/" ? result.slice(0, -1) : result; }; - var flushHeaders = (outgoing) => { - if ("flushHeaders" in outgoing && outgoing.writable) { - outgoing.flushHeaders(); + var mergePath = (base, sub, ...rest) => { + if (rest.length) { + sub = mergePath(sub, ...rest); } + return `${base?.[0] === "/" ? "" : "/"}${base}${sub === "/" ? "" : `${base?.at(-1) === "/" ? "" : "/"}${sub?.[0] === "/" ? sub.slice(1) : sub}`}`; }; - var responseViaCache = async (res, outgoing) => { - let [status, body, header] = res[cacheKey]; - if (header instanceof Headers) { - header = buildOutgoingHttpHeaders(header); - } - if (typeof body === "string") { - header["Content-Length"] = Buffer.byteLength(body); - } else if (body instanceof Uint8Array) { - header["Content-Length"] = body.byteLength; - } else if (body instanceof Blob) { - header["Content-Length"] = body.size; - } - outgoing.writeHead(status, header); - if (typeof body === "string" || body instanceof Uint8Array) { - outgoing.end(body); - } else if (body instanceof Blob) { - outgoing.end(new Uint8Array(await body.arrayBuffer())); - } else { - flushHeaders(outgoing); - await writeFromReadableStream(body, outgoing)?.catch( - (e) => handleResponseError(e, outgoing) - ); + var checkOptionalParameter = (path) => { + if (path.charCodeAt(path.length - 1) !== 63 || !path.includes(":")) { + return null; } - ; - outgoing[outgoingEnded]?.(); - }; - var isPromise = (res) => typeof res.then === "function"; - var responseViaResponseObject = async (res, outgoing, options = {}) => { - if (isPromise(res)) { - if (options.errorHandler) { - try { - res = await res; - } catch (err) { - const errRes = await options.errorHandler(err); - if (!errRes) { - return; + const segments = path.split("/"); + const results = []; + let basePath = ""; + segments.forEach((segment) => { + if (segment !== "" && !/\:/.test(segment)) { + basePath += "/" + segment; + } else if (/\:/.test(segment)) { + if (/\?/.test(segment)) { + if (results.length === 0 && basePath === "") { + results.push("/"); + } else { + results.push(basePath); } - res = errRes; + const optionalSegment = segment.replace("?", ""); + basePath += "/" + optionalSegment; + results.push(basePath); + } else { + basePath += "/" + segment; } - } else { - res = await res.catch(handleFetchError); } + }); + return results.filter((v, i, a) => a.indexOf(v) === i); + }; + var _decodeURI = (value) => { + if (!/[%+]/.test(value)) { + return value; } - if (cacheKey in res) { - return responseViaCache(res, outgoing); + if (value.indexOf("+") !== -1) { + value = value.replace(/\+/g, " "); } - const resHeaderRecord = buildOutgoingHttpHeaders(res.headers); - if (res.body) { - const reader = res.body.getReader(); - const values = []; - let done = false; - let currentReadPromise = void 0; - if (resHeaderRecord["transfer-encoding"] !== "chunked") { - let maxReadCount = 2; - for (let i = 0; i < maxReadCount; i++) { - currentReadPromise ||= reader.read(); - const chunk = await readWithoutBlocking(currentReadPromise).catch((e) => { - console.error(e); - done = true; - }); - if (!chunk) { - if (i === 1) { - await new Promise((resolve) => setTimeout(resolve)); - maxReadCount = 3; - continue; - } - break; - } - currentReadPromise = void 0; - if (chunk.value) { - values.push(chunk.value); - } - if (chunk.done) { - done = true; - break; - } - } - if (done && !("content-length" in resHeaderRecord)) { - resHeaderRecord["content-length"] = values.reduce((acc, value) => acc + value.length, 0); - } + return value.indexOf("%") !== -1 ? tryDecode(value, decodeURIComponent_) : value; + }; + var _getQueryParam = (url, key, multiple) => { + let encoded; + if (!multiple && key && !/[%+]/.test(key)) { + let keyIndex2 = url.indexOf("?", 8); + if (keyIndex2 === -1) { + return void 0; } - outgoing.writeHead(res.status, resHeaderRecord); - values.forEach((value) => { - ; - outgoing.write(value); - }); - if (done) { - outgoing.end(); - } else { - if (values.length === 0) { - flushHeaders(outgoing); + if (!url.startsWith(key, keyIndex2 + 1)) { + keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1); + } + while (keyIndex2 !== -1) { + const trailingKeyCode = url.charCodeAt(keyIndex2 + key.length + 1); + if (trailingKeyCode === 61) { + const valueIndex = keyIndex2 + key.length + 2; + const endIndex = url.indexOf("&", valueIndex); + return _decodeURI(url.slice(valueIndex, endIndex === -1 ? void 0 : endIndex)); + } else if (trailingKeyCode == 38 || isNaN(trailingKeyCode)) { + return ""; } - await writeFromReadableStreamDefaultReader(reader, outgoing, currentReadPromise); + keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1); + } + encoded = /[%+]/.test(url); + if (!encoded) { + return void 0; } - } else if (resHeaderRecord[X_ALREADY_SENT]) { - } else { - outgoing.writeHead(res.status, resHeaderRecord); - outgoing.end(); - } - ; - outgoing[outgoingEnded]?.(); - }; - var getRequestListener = (fetchCallback, options = {}) => { - const autoCleanupIncoming = options.autoCleanupIncoming ?? true; - if (options.overrideGlobalObjects !== false && global.Request !== Request2) { - Object.defineProperty(global, "Request", { - value: Request2 - }); - Object.defineProperty(global, "Response", { - value: Response2 - }); } - return async (incoming, outgoing) => { - let res, req; - try { - req = newRequest(incoming, options.hostname); - let incomingEnded = !autoCleanupIncoming || incoming.method === "GET" || incoming.method === "HEAD"; - if (!incomingEnded) { - ; - incoming[wrapBodyStream] = true; - incoming.on("end", () => { - incomingEnded = true; - }); - if (incoming instanceof import_node_http22.Http2ServerRequest) { - ; - outgoing[outgoingEnded] = () => { - if (!incomingEnded) { - setTimeout(() => { - if (!incomingEnded) { - setTimeout(() => { - incoming.destroy(); - outgoing.destroy(); - }); - } - }); - } - }; - } - } - outgoing.on("close", () => { - const abortController = req[abortControllerKey]; - if (abortController) { - if (incoming.errored) { - req[abortControllerKey].abort(incoming.errored.toString()); - } else if (!outgoing.writableFinished) { - req[abortControllerKey].abort("Client connection prematurely closed."); - } - } - if (!incomingEnded) { - setTimeout(() => { - if (!incomingEnded) { - setTimeout(() => { - incoming.destroy(); - }); - } - }); - } - }); - res = fetchCallback(req, { incoming, outgoing }); - if (cacheKey in res) { - return responseViaCache(res, outgoing); - } - } catch (e) { - if (!res) { - if (options.errorHandler) { - res = await options.errorHandler(req ? e : toRequestError(e)); - if (!res) { - return; - } - } else if (!req) { - res = handleRequestError(); - } else { - res = handleFetchError(e); - } - } else { - return handleResponseError(e, outgoing); + const results = {}; + encoded ??= /[%+]/.test(url); + let keyIndex = url.indexOf("?", 8); + while (keyIndex !== -1) { + const nextKeyIndex = url.indexOf("&", keyIndex + 1); + let valueIndex = url.indexOf("=", keyIndex); + if (valueIndex > nextKeyIndex && nextKeyIndex !== -1) { + valueIndex = -1; + } + let name = url.slice( + keyIndex + 1, + valueIndex === -1 ? nextKeyIndex === -1 ? void 0 : nextKeyIndex : valueIndex + ); + if (encoded) { + name = _decodeURI(name); + } + keyIndex = nextKeyIndex; + if (name === "") { + continue; + } + let value; + if (valueIndex === -1) { + value = ""; + } else { + value = url.slice(valueIndex + 1, nextKeyIndex === -1 ? void 0 : nextKeyIndex); + if (encoded) { + value = _decodeURI(value); } } - try { - return await responseViaResponseObject(res, outgoing, options); - } catch (e) { - return handleResponseError(e, outgoing); + if (multiple) { + if (!(results[name] && Array.isArray(results[name]))) { + results[name] = []; + } + ; + results[name].push(value); + } else { + results[name] ??= value; } - }; - }; - var createAdaptorServer = (options) => { - const fetchCallback = options.fetch; - const requestListener = getRequestListener(fetchCallback, { - hostname: options.hostname, - overrideGlobalObjects: options.overrideGlobalObjects, - autoCleanupIncoming: options.autoCleanupIncoming - }); - const createServer = options.createServer || import_node_http.createServer; - const server = createServer(options.serverOptions || {}, requestListener); - return server; + } + return key ? results[key] : results; }; - var serve = (options, listeningListener) => { - const server = createAdaptorServer(options); - server.listen(options?.port ?? 3e3, options.hostname, () => { - const serverInfo = server.address(); - listeningListener && listeningListener(serverInfo); - }); - return server; + var getQueryParam = _getQueryParam; + var getQueryParams = (url, key) => { + return _getQueryParam(url, key, true); }; + var decodeURIComponent_ = decodeURIComponent; } }); -// ../node_modules/hono/dist/cjs/compose.js -var require_compose = __commonJS({ - "../node_modules/hono/dist/cjs/compose.js"(exports2, module2) { +// ../node_modules/hono/dist/cjs/request.js +var require_request2 = __commonJS({ + "../node_modules/hono/dist/cjs/request.js"(exports2, module2) { "use strict"; var __defProp2 = Object.defineProperty; var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor; @@ -2389,59 +2279,157 @@ var require_compose = __commonJS({ return to; }; var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod); - var compose_exports = {}; - __export(compose_exports, { - compose: () => compose + var request_exports = {}; + __export(request_exports, { + HonoRequest: () => HonoRequest, + cloneRawRequest: () => cloneRawRequest }); - module2.exports = __toCommonJS(compose_exports); - var compose = (middleware, onError, onNotFound) => { - return (context, next) => { - let index = -1; - return dispatch(0); - async function dispatch(i) { - if (i <= index) { - throw new Error("next() called multiple times"); - } - index = i; - let res; - let isError = false; - let handler; - if (middleware[i]) { - handler = middleware[i][0][0]; - context.req.routeIndex = i; - } else { - handler = i === middleware.length && next || void 0; - } - if (handler) { - try { - res = await handler(context, () => dispatch(i + 1)); - } catch (err) { - if (err instanceof Error && onError) { - context.error = err; - res = await onError(err, context); - isError = true; - } else { - throw err; - } - } - } else { - if (context.finalized === false && onNotFound) { - res = await onNotFound(context); - } - } - if (res && (context.finalized === false || isError)) { - context.res = res; + module2.exports = __toCommonJS(request_exports); + var import_http_exception = require_http_exception(); + var import_constants = require_constants(); + var import_body = require_body2(); + var import_url = require_url(); + var tryDecodeURIComponent = (str) => (0, import_url.tryDecode)(str, import_url.decodeURIComponent_); + var HonoRequest = class { + raw; + #validatedData; + #matchResult; + routeIndex = 0; + path; + bodyCache = {}; + constructor(request, path = "/", matchResult = [[]]) { + this.raw = request; + this.path = path; + this.#matchResult = matchResult; + this.#validatedData = {}; + } + param(key) { + return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams(); + } + #getDecodedParam(key) { + const paramKey = this.#matchResult[0][this.routeIndex][1][key]; + const param = this.#getParamValue(paramKey); + return param && /\%/.test(param) ? tryDecodeURIComponent(param) : param; + } + #getAllDecodedParams() { + const decoded = {}; + const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]); + for (const key of keys) { + const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]); + if (value !== void 0) { + decoded[key] = /\%/.test(value) ? tryDecodeURIComponent(value) : value; } - return context; } - }; - }; + return decoded; + } + #getParamValue(paramKey) { + return this.#matchResult[1] ? this.#matchResult[1][paramKey] : paramKey; + } + query(key) { + return (0, import_url.getQueryParam)(this.url, key); + } + queries(key) { + return (0, import_url.getQueryParams)(this.url, key); + } + header(name) { + if (name) { + return this.raw.headers.get(name) ?? void 0; + } + const headerData = {}; + this.raw.headers.forEach((value, key) => { + headerData[key] = value; + }); + return headerData; + } + async parseBody(options) { + return this.bodyCache.parsedBody ??= await (0, import_body.parseBody)(this, options); + } + #cachedBody = (key) => { + const { bodyCache, raw } = this; + const cachedBody = bodyCache[key]; + if (cachedBody) { + return cachedBody; + } + const anyCachedKey = Object.keys(bodyCache)[0]; + if (anyCachedKey) { + return bodyCache[anyCachedKey].then((body) => { + if (anyCachedKey === "json") { + body = JSON.stringify(body); + } + return new Response(body)[key](); + }); + } + return bodyCache[key] = raw[key](); + }; + json() { + return this.#cachedBody("text").then((text) => JSON.parse(text)); + } + text() { + return this.#cachedBody("text"); + } + arrayBuffer() { + return this.#cachedBody("arrayBuffer"); + } + blob() { + return this.#cachedBody("blob"); + } + formData() { + return this.#cachedBody("formData"); + } + addValidatedData(target, data) { + this.#validatedData[target] = data; + } + valid(target) { + return this.#validatedData[target]; + } + get url() { + return this.raw.url; + } + get method() { + return this.raw.method; + } + get [import_constants.GET_MATCH_RESULT]() { + return this.#matchResult; + } + get matchedRoutes() { + return this.#matchResult[0].map(([[, route]]) => route); + } + get routePath() { + return this.#matchResult[0].map(([[, route]]) => route)[this.routeIndex].path; + } + }; + var cloneRawRequest = async (req) => { + if (!req.raw.bodyUsed) { + return req.raw.clone(); + } + const cacheKey = Object.keys(req.bodyCache)[0]; + if (!cacheKey) { + throw new import_http_exception.HTTPException(500, { + message: "Cannot clone request: body was already consumed and not cached. Please use HonoRequest methods (e.g., req.json(), req.text()) instead of consuming req.raw directly." + }); + } + const requestInit = { + body: await req[cacheKey](), + cache: req.raw.cache, + credentials: req.raw.credentials, + headers: req.header(), + integrity: req.raw.integrity, + keepalive: req.raw.keepalive, + method: req.method, + mode: req.raw.mode, + redirect: req.raw.redirect, + referrer: req.raw.referrer, + referrerPolicy: req.raw.referrerPolicy, + signal: req.raw.signal + }; + return new Request(req.url, requestInit); + }; } }); -// ../node_modules/hono/dist/cjs/http-exception.js -var require_http_exception = __commonJS({ - "../node_modules/hono/dist/cjs/http-exception.js"(exports2, module2) { +// ../node_modules/hono/dist/cjs/utils/html.js +var require_html = __commonJS({ + "../node_modules/hono/dist/cjs/utils/html.js"(exports2, module2) { "use strict"; var __defProp2 = Object.defineProperty; var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor; @@ -2460,38 +2448,136 @@ var require_http_exception = __commonJS({ return to; }; var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod); - var http_exception_exports = {}; - __export(http_exception_exports, { - HTTPException: () => HTTPException + var html_exports = {}; + __export(html_exports, { + HtmlEscapedCallbackPhase: () => HtmlEscapedCallbackPhase, + escapeToBuffer: () => escapeToBuffer, + raw: () => raw, + resolveCallback: () => resolveCallback, + resolveCallbackSync: () => resolveCallbackSync, + stringBufferToString: () => stringBufferToString }); - module2.exports = __toCommonJS(http_exception_exports); - var HTTPException = class extends Error { - res; - status; - constructor(status = 500, options) { - super(options?.message, { cause: options?.cause }); - this.res = options?.res; - this.status = status; + module2.exports = __toCommonJS(html_exports); + var HtmlEscapedCallbackPhase = { + Stringify: 1, + BeforeStream: 2, + Stream: 3 + }; + var raw = (value, callbacks) => { + const escapedString = new String(value); + escapedString.isEscaped = true; + escapedString.callbacks = callbacks; + return escapedString; + }; + var escapeRe = /[&<>'"]/; + var stringBufferToString = async (buffer, callbacks) => { + let str = ""; + callbacks ||= []; + const resolvedBuffer = await Promise.all(buffer); + for (let i = resolvedBuffer.length - 1; ; i--) { + str += resolvedBuffer[i]; + i--; + if (i < 0) { + break; + } + let r = resolvedBuffer[i]; + if (typeof r === "object") { + callbacks.push(...r.callbacks || []); + } + const isEscaped = r.isEscaped; + r = await (typeof r === "object" ? r.toString() : r); + if (typeof r === "object") { + callbacks.push(...r.callbacks || []); + } + if (r.isEscaped ?? isEscaped) { + str += r; + } else { + const buf = [str]; + escapeToBuffer(r, buf); + str = buf[0]; + } } - getResponse() { - if (this.res) { - const newResponse = new Response(this.res.body, { - status: this.status, - headers: this.res.headers - }); - return newResponse; + return raw(str, callbacks); + }; + var escapeToBuffer = (str, buffer) => { + const match = str.search(escapeRe); + if (match === -1) { + buffer[0] += str; + return; + } + let escape; + let index; + let lastIndex = 0; + for (index = match; index < str.length; index++) { + switch (str.charCodeAt(index)) { + case 34: + escape = """; + break; + case 39: + escape = "'"; + break; + case 38: + escape = "&"; + break; + case 60: + escape = "<"; + break; + case 62: + escape = ">"; + break; + default: + continue; } - return new Response(this.message, { - status: this.status - }); + buffer[0] += str.substring(lastIndex, index) + escape; + lastIndex = index + 1; + } + buffer[0] += str.substring(lastIndex, index); + }; + var resolveCallbackSync = (str) => { + const callbacks = str.callbacks; + if (!callbacks?.length) { + return str; + } + const buffer = [str]; + const context = {}; + callbacks.forEach((c) => c({ phase: HtmlEscapedCallbackPhase.Stringify, buffer, context })); + return buffer[0]; + }; + var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) => { + if (typeof str === "object" && !(str instanceof String)) { + if (!(str instanceof Promise)) { + str = str.toString(); + } + if (str instanceof Promise) { + str = await str; + } + } + const callbacks = str.callbacks; + if (!callbacks?.length) { + return Promise.resolve(str); + } + if (buffer) { + buffer[0] += str; + } else { + buffer = [str]; + } + const resStr = Promise.all(callbacks.map((c) => c({ phase, buffer, context }))).then( + (res) => Promise.all( + res.filter(Boolean).map((str2) => resolveCallback(str2, phase, false, context, buffer)) + ).then(() => buffer[0]) + ); + if (preserveCallbacks) { + return raw(await resStr, callbacks); + } else { + return resStr; } }; } }); -// ../node_modules/hono/dist/cjs/request/constants.js -var require_constants = __commonJS({ - "../node_modules/hono/dist/cjs/request/constants.js"(exports2, module2) { +// ../node_modules/hono/dist/cjs/context.js +var require_context = __commonJS({ + "../node_modules/hono/dist/cjs/context.js"(exports2, module2) { "use strict"; var __defProp2 = Object.defineProperty; var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor; @@ -2510,18 +2596,195 @@ var require_constants = __commonJS({ return to; }; var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod); - var constants_exports = {}; - __export(constants_exports, { - GET_MATCH_RESULT: () => GET_MATCH_RESULT + var context_exports = {}; + __export(context_exports, { + Context: () => Context, + TEXT_PLAIN: () => TEXT_PLAIN }); - module2.exports = __toCommonJS(constants_exports); - var GET_MATCH_RESULT = Symbol(); + module2.exports = __toCommonJS(context_exports); + var import_request = require_request2(); + var import_html = require_html(); + var TEXT_PLAIN = "text/plain; charset=UTF-8"; + var setDefaultContentType = (contentType, headers) => { + return { + "Content-Type": contentType, + ...headers + }; + }; + var Context = class { + #rawRequest; + #req; + env = {}; + #var; + finalized = false; + error; + #status; + #executionCtx; + #res; + #layout; + #renderer; + #notFoundHandler; + #preparedHeaders; + #matchResult; + #path; + constructor(req, options) { + this.#rawRequest = req; + if (options) { + this.#executionCtx = options.executionCtx; + this.env = options.env; + this.#notFoundHandler = options.notFoundHandler; + this.#path = options.path; + this.#matchResult = options.matchResult; + } + } + get req() { + this.#req ??= new import_request.HonoRequest(this.#rawRequest, this.#path, this.#matchResult); + return this.#req; + } + get event() { + if (this.#executionCtx && "respondWith" in this.#executionCtx) { + return this.#executionCtx; + } else { + throw Error("This context has no FetchEvent"); + } + } + get executionCtx() { + if (this.#executionCtx) { + return this.#executionCtx; + } else { + throw Error("This context has no ExecutionContext"); + } + } + get res() { + return this.#res ||= new Response(null, { + headers: this.#preparedHeaders ??= new Headers() + }); + } + set res(_res) { + if (this.#res && _res) { + _res = new Response(_res.body, _res); + for (const [k, v] of this.#res.headers.entries()) { + if (k === "content-type") { + continue; + } + if (k === "set-cookie") { + const cookies = this.#res.headers.getSetCookie(); + _res.headers.delete("set-cookie"); + for (const cookie of cookies) { + _res.headers.append("set-cookie", cookie); + } + } else { + _res.headers.set(k, v); + } + } + } + this.#res = _res; + this.finalized = true; + } + render = (...args) => { + this.#renderer ??= (content) => this.html(content); + return this.#renderer(...args); + }; + setLayout = (layout) => this.#layout = layout; + getLayout = () => this.#layout; + setRenderer = (renderer) => { + this.#renderer = renderer; + }; + header = (name, value, options) => { + if (this.finalized) { + this.#res = new Response(this.#res.body, this.#res); + } + const headers = this.#res ? this.#res.headers : this.#preparedHeaders ??= new Headers(); + if (value === void 0) { + headers.delete(name); + } else if (options?.append) { + headers.append(name, value); + } else { + headers.set(name, value); + } + }; + status = (status) => { + this.#status = status; + }; + set = (key, value) => { + this.#var ??= /* @__PURE__ */ new Map(); + this.#var.set(key, value); + }; + get = (key) => { + return this.#var ? this.#var.get(key) : void 0; + }; + get var() { + if (!this.#var) { + return {}; + } + return Object.fromEntries(this.#var); + } + #newResponse(data, arg, headers) { + const responseHeaders = this.#res ? new Headers(this.#res.headers) : this.#preparedHeaders ?? new Headers(); + if (typeof arg === "object" && "headers" in arg) { + const argHeaders = arg.headers instanceof Headers ? arg.headers : new Headers(arg.headers); + for (const [key, value] of argHeaders) { + if (key.toLowerCase() === "set-cookie") { + responseHeaders.append(key, value); + } else { + responseHeaders.set(key, value); + } + } + } + if (headers) { + for (const [k, v] of Object.entries(headers)) { + if (typeof v === "string") { + responseHeaders.set(k, v); + } else { + responseHeaders.delete(k); + for (const v2 of v) { + responseHeaders.append(k, v2); + } + } + } + } + const status = typeof arg === "number" ? arg : arg?.status ?? this.#status; + return new Response(data, { status, headers: responseHeaders }); + } + newResponse = (...args) => this.#newResponse(...args); + body = (data, arg, headers) => this.#newResponse(data, arg, headers); + text = (text, arg, headers) => { + return !this.#preparedHeaders && !this.#status && !arg && !headers && !this.finalized ? new Response(text) : this.#newResponse( + text, + arg, + setDefaultContentType(TEXT_PLAIN, headers) + ); + }; + json = (object, arg, headers) => { + return this.#newResponse( + JSON.stringify(object), + arg, + setDefaultContentType("application/json", headers) + ); + }; + html = (html, arg, headers) => { + const res = (html2) => this.#newResponse(html2, arg, setDefaultContentType("text/html; charset=UTF-8", headers)); + return typeof html === "object" ? (0, import_html.resolveCallback)(html, import_html.HtmlEscapedCallbackPhase.Stringify, false, {}).then(res) : res(html); + }; + redirect = (location, status) => { + const locationString = String(location); + this.header( + "Location", + !/[^\x00-\xFF]/.test(locationString) ? locationString : encodeURI(locationString) + ); + return this.newResponse(null, status ?? 302); + }; + notFound = () => { + this.#notFoundHandler ??= () => new Response(); + return this.#notFoundHandler(this); + }; + }; } }); -// ../node_modules/hono/dist/cjs/utils/body.js -var require_body2 = __commonJS({ - "../node_modules/hono/dist/cjs/utils/body.js"(exports2, module2) { +// ../node_modules/hono/dist/cjs/router.js +var require_router = __commonJS({ + "../node_modules/hono/dist/cjs/router.js"(exports2, module2) { "use strict"; var __defProp2 = Object.defineProperty; var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor; @@ -2540,85 +2803,57 @@ var require_body2 = __commonJS({ return to; }; var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod); - var body_exports = {}; - __export(body_exports, { - parseBody: () => parseBody + var router_exports = {}; + __export(router_exports, { + MESSAGE_MATCHER_IS_ALREADY_BUILT: () => MESSAGE_MATCHER_IS_ALREADY_BUILT, + METHODS: () => METHODS, + METHOD_NAME_ALL: () => METHOD_NAME_ALL, + METHOD_NAME_ALL_LOWERCASE: () => METHOD_NAME_ALL_LOWERCASE, + UnsupportedPathError: () => UnsupportedPathError }); - module2.exports = __toCommonJS(body_exports); - var import_request = require_request2(); - var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => { - const { all = false, dot = false } = options; - const headers = request instanceof import_request.HonoRequest ? request.raw.headers : request.headers; - const contentType = headers.get("Content-Type"); - if (contentType?.startsWith("multipart/form-data") || contentType?.startsWith("application/x-www-form-urlencoded")) { - return parseFormData(request, { all, dot }); - } - return {}; + module2.exports = __toCommonJS(router_exports); + var METHOD_NAME_ALL = "ALL"; + var METHOD_NAME_ALL_LOWERCASE = "all"; + var METHODS = ["get", "post", "put", "delete", "options", "patch"]; + var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built."; + var UnsupportedPathError = class extends Error { }; - async function parseFormData(request, options) { - const formData = await request.formData(); - if (formData) { - return convertFormDataToBodyData(formData, options); + } +}); + +// ../node_modules/hono/dist/cjs/utils/constants.js +var require_constants2 = __commonJS({ + "../node_modules/hono/dist/cjs/utils/constants.js"(exports2, module2) { + "use strict"; + var __defProp2 = Object.defineProperty; + var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor; + var __getOwnPropNames2 = Object.getOwnPropertyNames; + var __hasOwnProp2 = Object.prototype.hasOwnProperty; + var __export = (target, all) => { + for (var name in all) + __defProp2(target, name, { get: all[name], enumerable: true }); + }; + var __copyProps2 = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames2(from)) + if (!__hasOwnProp2.call(to, key) && key !== except) + __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable }); } - return {}; - } - function convertFormDataToBodyData(formData, options) { - const form = /* @__PURE__ */ Object.create(null); - formData.forEach((value, key) => { - const shouldParseAllValues = options.all || key.endsWith("[]"); - if (!shouldParseAllValues) { - form[key] = value; - } else { - handleParsingAllValues(form, key, value); - } - }); - if (options.dot) { - Object.entries(form).forEach(([key, value]) => { - const shouldParseDotValues = key.includes("."); - if (shouldParseDotValues) { - handleParsingNestedValues(form, key, value); - delete form[key]; - } - }); - } - return form; - } - var handleParsingAllValues = (form, key, value) => { - if (form[key] !== void 0) { - if (Array.isArray(form[key])) { - ; - form[key].push(value); - } else { - form[key] = [form[key], value]; - } - } else { - if (!key.endsWith("[]")) { - form[key] = value; - } else { - form[key] = [value]; - } - } - }; - var handleParsingNestedValues = (form, key, value) => { - let nestedForm = form; - const keys = key.split("."); - keys.forEach((key2, index) => { - if (index === keys.length - 1) { - nestedForm[key2] = value; - } else { - if (!nestedForm[key2] || typeof nestedForm[key2] !== "object" || Array.isArray(nestedForm[key2]) || nestedForm[key2] instanceof File) { - nestedForm[key2] = /* @__PURE__ */ Object.create(null); - } - nestedForm = nestedForm[key2]; - } - }); + return to; }; + var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod); + var constants_exports = {}; + __export(constants_exports, { + COMPOSED_HANDLER: () => COMPOSED_HANDLER + }); + module2.exports = __toCommonJS(constants_exports); + var COMPOSED_HANDLER = "__COMPOSED_HANDLER"; } }); -// ../node_modules/hono/dist/cjs/utils/url.js -var require_url = __commonJS({ - "../node_modules/hono/dist/cjs/utils/url.js"(exports2, module2) { +// ../node_modules/hono/dist/cjs/hono-base.js +var require_hono_base = __commonJS({ + "../node_modules/hono/dist/cjs/hono-base.js"(exports2, module2) { "use strict"; var __defProp2 = Object.defineProperty; var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor; @@ -2637,232 +2872,251 @@ var require_url = __commonJS({ return to; }; var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod); - var url_exports = {}; - __export(url_exports, { - checkOptionalParameter: () => checkOptionalParameter, - decodeURIComponent_: () => decodeURIComponent_, - getPath: () => getPath, - getPathNoStrict: () => getPathNoStrict, - getPattern: () => getPattern, - getQueryParam: () => getQueryParam, - getQueryParams: () => getQueryParams, - getQueryStrings: () => getQueryStrings, - mergePath: () => mergePath, - splitPath: () => splitPath, - splitRoutingPath: () => splitRoutingPath, - tryDecode: () => tryDecode + var hono_base_exports = {}; + __export(hono_base_exports, { + HonoBase: () => Hono2 }); - module2.exports = __toCommonJS(url_exports); - var splitPath = (path) => { - const paths = path.split("/"); - if (paths[0] === "") { - paths.shift(); - } - return paths; - }; - var splitRoutingPath = (routePath) => { - const { groups, path } = extractGroupsFromPath(routePath); - const paths = splitPath(path); - return replaceGroupMarks(paths, groups); + module2.exports = __toCommonJS(hono_base_exports); + var import_compose = require_compose(); + var import_context = require_context(); + var import_router = require_router(); + var import_constants = require_constants2(); + var import_url = require_url(); + var notFoundHandler = (c) => { + return c.text("404 Not Found", 404); }; - var extractGroupsFromPath = (path) => { - const groups = []; - path = path.replace(/\{[^}]+\}/g, (match, index) => { - const mark = `@${index}`; - groups.push([mark, match]); - return mark; - }); - return { groups, path }; + var errorHandler = (err, c) => { + if ("getResponse" in err) { + const res = err.getResponse(); + return c.newResponse(res.body, res); + } + console.error(err); + return c.text("Internal Server Error", 500); }; - var replaceGroupMarks = (paths, groups) => { - for (let i = groups.length - 1; i >= 0; i--) { - const [mark] = groups[i]; - for (let j = paths.length - 1; j >= 0; j--) { - if (paths[j].includes(mark)) { - paths[j] = paths[j].replace(mark, groups[i][1]); - break; + var Hono2 = class _Hono { + get; + post; + put; + delete; + options; + patch; + all; + on; + use; + router; + getPath; + _basePath = "/"; + #path = "/"; + routes = []; + constructor(options = {}) { + const allMethods = [...import_router.METHODS, import_router.METHOD_NAME_ALL_LOWERCASE]; + allMethods.forEach((method) => { + this[method] = (args1, ...args) => { + if (typeof args1 === "string") { + this.#path = args1; + } else { + this.#addRoute(method, this.#path, args1); + } + args.forEach((handler) => { + this.#addRoute(method, this.#path, handler); + }); + return this; + }; + }); + this.on = (method, path, ...handlers) => { + for (const p of [path].flat()) { + this.#path = p; + for (const m of [method].flat()) { + handlers.map((handler) => { + this.#addRoute(m.toUpperCase(), this.#path, handler); + }); + } } - } + return this; + }; + this.use = (arg1, ...handlers) => { + if (typeof arg1 === "string") { + this.#path = arg1; + } else { + this.#path = "*"; + handlers.unshift(arg1); + } + handlers.forEach((handler) => { + this.#addRoute(import_router.METHOD_NAME_ALL, this.#path, handler); + }); + return this; + }; + const { strict, ...optionsWithoutStrict } = options; + Object.assign(this, optionsWithoutStrict); + this.getPath = strict ?? true ? options.getPath ?? import_url.getPath : import_url.getPathNoStrict; } - return paths; - }; - var patternCache = {}; - var getPattern = (label, next) => { - if (label === "*") { - return "*"; + #clone() { + const clone = new _Hono({ + router: this.router, + getPath: this.getPath + }); + clone.errorHandler = this.errorHandler; + clone.#notFoundHandler = this.#notFoundHandler; + clone.routes = this.routes; + return clone; } - const match = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/); - if (match) { - const cacheKey = `${label}#${next}`; - if (!patternCache[cacheKey]) { - if (match[2]) { - patternCache[cacheKey] = next && next[0] !== ":" && next[0] !== "*" ? [cacheKey, match[1], new RegExp(`^${match[2]}(?=/${next})`)] : [label, match[1], new RegExp(`^${match[2]}$`)]; + #notFoundHandler = notFoundHandler; + errorHandler = errorHandler; + route(path, app) { + const subApp = this.basePath(path); + app.routes.map((r) => { + let handler; + if (app.errorHandler === errorHandler) { + handler = r.handler; } else { - patternCache[cacheKey] = [label, match[1], true]; + handler = async (c, next) => (await (0, import_compose.compose)([], app.errorHandler)(c, () => r.handler(c, next))).res; + handler[import_constants.COMPOSED_HANDLER] = r.handler; } - } - return patternCache[cacheKey]; + subApp.#addRoute(r.method, r.path, handler); + }); + return this; } - return null; - }; - var tryDecode = (str, decoder) => { - try { - return decoder(str); - } catch { - return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match) => { + basePath(path) { + const subApp = this.#clone(); + subApp._basePath = (0, import_url.mergePath)(this._basePath, path); + return subApp; + } + onError = (handler) => { + this.errorHandler = handler; + return this; + }; + notFound = (handler) => { + this.#notFoundHandler = handler; + return this; + }; + mount(path, applicationHandler, options) { + let replaceRequest; + let optionHandler; + if (options) { + if (typeof options === "function") { + optionHandler = options; + } else { + optionHandler = options.optionHandler; + if (options.replaceRequest === false) { + replaceRequest = (request) => request; + } else { + replaceRequest = options.replaceRequest; + } + } + } + const getOptions = optionHandler ? (c) => { + const options2 = optionHandler(c); + return Array.isArray(options2) ? options2 : [options2]; + } : (c) => { + let executionContext = void 0; try { - return decoder(match); + executionContext = c.executionCtx; } catch { - return match; } - }); - } - }; - var tryDecodeURI = (str) => tryDecode(str, decodeURI); - var getPath = (request) => { - const url = request.url; - const start = url.indexOf("/", url.indexOf(":") + 4); - let i = start; - for (; i < url.length; i++) { - const charCode = url.charCodeAt(i); - if (charCode === 37) { - const queryIndex = url.indexOf("?", i); - const path = url.slice(start, queryIndex === -1 ? void 0 : queryIndex); - return tryDecodeURI(path.includes("%25") ? path.replace(/%25/g, "%2525") : path); - } else if (charCode === 63) { - break; - } - } - return url.slice(start, i); - }; - var getQueryStrings = (url) => { - const queryIndex = url.indexOf("?", 8); - return queryIndex === -1 ? "" : "?" + url.slice(queryIndex + 1); - }; - var getPathNoStrict = (request) => { - const result = getPath(request); - return result.length > 1 && result.at(-1) === "/" ? result.slice(0, -1) : result; - }; - var mergePath = (base, sub, ...rest) => { - if (rest.length) { - sub = mergePath(sub, ...rest); - } - return `${base?.[0] === "/" ? "" : "/"}${base}${sub === "/" ? "" : `${base?.at(-1) === "/" ? "" : "/"}${sub?.[0] === "/" ? sub.slice(1) : sub}`}`; - }; - var checkOptionalParameter = (path) => { - if (path.charCodeAt(path.length - 1) !== 63 || !path.includes(":")) { - return null; - } - const segments = path.split("/"); - const results = []; - let basePath = ""; - segments.forEach((segment) => { - if (segment !== "" && !/\:/.test(segment)) { - basePath += "/" + segment; - } else if (/\:/.test(segment)) { - if (/\?/.test(segment)) { - if (results.length === 0 && basePath === "") { - results.push("/"); - } else { - results.push(basePath); - } - const optionalSegment = segment.replace("?", ""); - basePath += "/" + optionalSegment; - results.push(basePath); - } else { - basePath += "/" + segment; + return [c.env, executionContext]; + }; + replaceRequest ||= (() => { + const mergedPath = (0, import_url.mergePath)(this._basePath, path); + const pathPrefixLength = mergedPath === "/" ? 0 : mergedPath.length; + return (request) => { + const url = new URL(request.url); + url.pathname = url.pathname.slice(pathPrefixLength) || "/"; + return new Request(url, request); + }; + })(); + const handler = async (c, next) => { + const res = await applicationHandler(replaceRequest(c.req.raw), ...getOptions(c)); + if (res) { + return res; } - } - }); - return results.filter((v, i, a) => a.indexOf(v) === i); - }; - var _decodeURI = (value) => { - if (!/[%+]/.test(value)) { - return value; + await next(); + }; + this.#addRoute(import_router.METHOD_NAME_ALL, (0, import_url.mergePath)(path, "*"), handler); + return this; } - if (value.indexOf("+") !== -1) { - value = value.replace(/\+/g, " "); + #addRoute(method, path, handler) { + method = method.toUpperCase(); + path = (0, import_url.mergePath)(this._basePath, path); + const r = { basePath: this._basePath, path, method, handler }; + this.router.add(method, path, [handler, r]); + this.routes.push(r); } - return value.indexOf("%") !== -1 ? tryDecode(value, decodeURIComponent_) : value; - }; - var _getQueryParam = (url, key, multiple) => { - let encoded; - if (!multiple && key && !/[%+]/.test(key)) { - let keyIndex2 = url.indexOf("?", 8); - if (keyIndex2 === -1) { - return void 0; - } - if (!url.startsWith(key, keyIndex2 + 1)) { - keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1); - } - while (keyIndex2 !== -1) { - const trailingKeyCode = url.charCodeAt(keyIndex2 + key.length + 1); - if (trailingKeyCode === 61) { - const valueIndex = keyIndex2 + key.length + 2; - const endIndex = url.indexOf("&", valueIndex); - return _decodeURI(url.slice(valueIndex, endIndex === -1 ? void 0 : endIndex)); - } else if (trailingKeyCode == 38 || isNaN(trailingKeyCode)) { - return ""; - } - keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1); - } - encoded = /[%+]/.test(url); - if (!encoded) { - return void 0; + #handleError(err, c) { + if (err instanceof Error) { + return this.errorHandler(err, c); } + throw err; } - const results = {}; - encoded ??= /[%+]/.test(url); - let keyIndex = url.indexOf("?", 8); - while (keyIndex !== -1) { - const nextKeyIndex = url.indexOf("&", keyIndex + 1); - let valueIndex = url.indexOf("=", keyIndex); - if (valueIndex > nextKeyIndex && nextKeyIndex !== -1) { - valueIndex = -1; - } - let name = url.slice( - keyIndex + 1, - valueIndex === -1 ? nextKeyIndex === -1 ? void 0 : nextKeyIndex : valueIndex - ); - if (encoded) { - name = _decodeURI(name); - } - keyIndex = nextKeyIndex; - if (name === "") { - continue; + #dispatch(request, executionCtx, env, method) { + if (method === "HEAD") { + return (async () => new Response(null, await this.#dispatch(request, executionCtx, env, "GET")))(); } - let value; - if (valueIndex === -1) { - value = ""; - } else { - value = url.slice(valueIndex + 1, nextKeyIndex === -1 ? void 0 : nextKeyIndex); - if (encoded) { - value = _decodeURI(value); + const path = this.getPath(request, { env }); + const matchResult = this.router.match(method, path); + const c = new import_context.Context(request, { + path, + matchResult, + env, + executionCtx, + notFoundHandler: this.#notFoundHandler + }); + if (matchResult[0].length === 1) { + let res; + try { + res = matchResult[0][0][0][0](c, async () => { + c.res = await this.#notFoundHandler(c); + }); + } catch (err) { + return this.#handleError(err, c); } + return res instanceof Promise ? res.then( + (resolved) => resolved || (c.finalized ? c.res : this.#notFoundHandler(c)) + ).catch((err) => this.#handleError(err, c)) : res ?? this.#notFoundHandler(c); } - if (multiple) { - if (!(results[name] && Array.isArray(results[name]))) { - results[name] = []; + const composed = (0, import_compose.compose)(matchResult[0], this.errorHandler, this.#notFoundHandler); + return (async () => { + try { + const context = await composed(c); + if (!context.finalized) { + throw new Error( + "Context is not finalized. Did you forget to return a Response object or `await next()`?" + ); + } + return context.res; + } catch (err) { + return this.#handleError(err, c); } - ; - results[name].push(value); - } else { - results[name] ??= value; - } + })(); } - return key ? results[key] : results; - }; - var getQueryParam = _getQueryParam; - var getQueryParams = (url, key) => { - return _getQueryParam(url, key, true); + fetch = (request, ...rest) => { + return this.#dispatch(request, rest[1], rest[0], request.method); + }; + request = (input, requestInit, Env, executionCtx) => { + if (input instanceof Request) { + return this.fetch(requestInit ? new Request(input, requestInit) : input, Env, executionCtx); + } + input = input.toString(); + return this.fetch( + new Request( + /^https?:\/\//.test(input) ? input : `http://localhost${(0, import_url.mergePath)("/", input)}`, + requestInit + ), + Env, + executionCtx + ); + }; + fire = () => { + addEventListener("fetch", (event) => { + event.respondWith(this.#dispatch(event.request, event, void 0, event.request.method)); + }); + }; }; - var decodeURIComponent_ = decodeURIComponent; } }); -// ../node_modules/hono/dist/cjs/request.js -var require_request2 = __commonJS({ - "../node_modules/hono/dist/cjs/request.js"(exports2, module2) { +// ../node_modules/hono/dist/cjs/router/reg-exp-router/matcher.js +var require_matcher = __commonJS({ + "../node_modules/hono/dist/cjs/router/reg-exp-router/matcher.js"(exports2, module2) { "use strict"; var __defProp2 = Object.defineProperty; var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor; @@ -2881,157 +3135,174 @@ var require_request2 = __commonJS({ return to; }; var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod); - var request_exports = {}; - __export(request_exports, { - HonoRequest: () => HonoRequest, - cloneRawRequest: () => cloneRawRequest + var matcher_exports = {}; + __export(matcher_exports, { + emptyParam: () => emptyParam, + match: () => match }); - module2.exports = __toCommonJS(request_exports); - var import_http_exception = require_http_exception(); - var import_constants = require_constants(); - var import_body = require_body2(); - var import_url = require_url(); - var tryDecodeURIComponent = (str) => (0, import_url.tryDecode)(str, import_url.decodeURIComponent_); - var HonoRequest = class { - raw; - #validatedData; - #matchResult; - routeIndex = 0; - path; - bodyCache = {}; - constructor(request, path = "/", matchResult = [[]]) { - this.raw = request; - this.path = path; - this.#matchResult = matchResult; - this.#validatedData = {}; - } - param(key) { - return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams(); - } - #getDecodedParam(key) { - const paramKey = this.#matchResult[0][this.routeIndex][1][key]; - const param = this.#getParamValue(paramKey); - return param && /\%/.test(param) ? tryDecodeURIComponent(param) : param; - } - #getAllDecodedParams() { - const decoded = {}; - const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]); - for (const key of keys) { - const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]); - if (value !== void 0) { - decoded[key] = /\%/.test(value) ? tryDecodeURIComponent(value) : value; - } + module2.exports = __toCommonJS(matcher_exports); + var import_router = require_router(); + var emptyParam = []; + function match(method, path) { + const matchers = this.buildAllMatchers(); + const match2 = (method2, path2) => { + const matcher = matchers[method2] || matchers[import_router.METHOD_NAME_ALL]; + const staticMatch = matcher[2][path2]; + if (staticMatch) { + return staticMatch; } - return decoded; - } - #getParamValue(paramKey) { - return this.#matchResult[1] ? this.#matchResult[1][paramKey] : paramKey; + const match3 = path2.match(matcher[0]); + if (!match3) { + return [[], emptyParam]; + } + const index = match3.indexOf("", 1); + return [matcher[1][index], match3]; + }; + this.match = match2; + return match2(method, path); + } + } +}); + +// ../node_modules/hono/dist/cjs/router/reg-exp-router/node.js +var require_node = __commonJS({ + "../node_modules/hono/dist/cjs/router/reg-exp-router/node.js"(exports2, module2) { + "use strict"; + var __defProp2 = Object.defineProperty; + var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor; + var __getOwnPropNames2 = Object.getOwnPropertyNames; + var __hasOwnProp2 = Object.prototype.hasOwnProperty; + var __export = (target, all) => { + for (var name in all) + __defProp2(target, name, { get: all[name], enumerable: true }); + }; + var __copyProps2 = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames2(from)) + if (!__hasOwnProp2.call(to, key) && key !== except) + __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable }); } - query(key) { - return (0, import_url.getQueryParam)(this.url, key); + return to; + }; + var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod); + var node_exports = {}; + __export(node_exports, { + Node: () => Node, + PATH_ERROR: () => PATH_ERROR + }); + module2.exports = __toCommonJS(node_exports); + var LABEL_REG_EXP_STR = "[^/]+"; + var ONLY_WILDCARD_REG_EXP_STR = ".*"; + var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)"; + var PATH_ERROR = Symbol(); + var regExpMetaChars = new Set(".\\+*[^]$()"); + function compareKey(a, b) { + if (a.length === 1) { + return b.length === 1 ? a < b ? -1 : 1 : -1; } - queries(key) { - return (0, import_url.getQueryParams)(this.url, key); + if (b.length === 1) { + return 1; } - header(name) { - if (name) { - return this.raw.headers.get(name) ?? void 0; - } - const headerData = {}; - this.raw.headers.forEach((value, key) => { - headerData[key] = value; - }); - return headerData; + if (a === ONLY_WILDCARD_REG_EXP_STR || a === TAIL_WILDCARD_REG_EXP_STR) { + return 1; + } else if (b === ONLY_WILDCARD_REG_EXP_STR || b === TAIL_WILDCARD_REG_EXP_STR) { + return -1; } - async parseBody(options) { - return this.bodyCache.parsedBody ??= await (0, import_body.parseBody)(this, options); + if (a === LABEL_REG_EXP_STR) { + return 1; + } else if (b === LABEL_REG_EXP_STR) { + return -1; } - #cachedBody = (key) => { - const { bodyCache, raw } = this; - const cachedBody = bodyCache[key]; - if (cachedBody) { - return cachedBody; + return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length; + } + var Node = class _Node { + #index; + #varIndex; + #children = /* @__PURE__ */ Object.create(null); + insert(tokens, index, paramMap, context, pathErrorCheckOnly) { + if (tokens.length === 0) { + if (this.#index !== void 0) { + throw PATH_ERROR; + } + if (pathErrorCheckOnly) { + return; + } + this.#index = index; + return; } - const anyCachedKey = Object.keys(bodyCache)[0]; - if (anyCachedKey) { - return bodyCache[anyCachedKey].then((body) => { - if (anyCachedKey === "json") { - body = JSON.stringify(body); + const [token, ...restTokens] = tokens; + const pattern = token === "*" ? restTokens.length === 0 ? ["", "", ONLY_WILDCARD_REG_EXP_STR] : ["", "", LABEL_REG_EXP_STR] : token === "/*" ? ["", "", TAIL_WILDCARD_REG_EXP_STR] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/); + let node; + if (pattern) { + const name = pattern[1]; + let regexpStr = pattern[2] || LABEL_REG_EXP_STR; + if (name && pattern[2]) { + if (regexpStr === ".*") { + throw PATH_ERROR; } - return new Response(body)[key](); - }); + regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:"); + if (/\((?!\?:)/.test(regexpStr)) { + throw PATH_ERROR; + } + } + node = this.#children[regexpStr]; + if (!node) { + if (Object.keys(this.#children).some( + (k) => k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR + )) { + throw PATH_ERROR; + } + if (pathErrorCheckOnly) { + return; + } + node = this.#children[regexpStr] = new _Node(); + if (name !== "") { + node.#varIndex = context.varIndex++; + } + } + if (!pathErrorCheckOnly && name !== "") { + paramMap.push([name, node.#varIndex]); + } + } else { + node = this.#children[token]; + if (!node) { + if (Object.keys(this.#children).some( + (k) => k.length > 1 && k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR + )) { + throw PATH_ERROR; + } + if (pathErrorCheckOnly) { + return; + } + node = this.#children[token] = new _Node(); + } } - return bodyCache[key] = raw[key](); - }; - json() { - return this.#cachedBody("text").then((text) => JSON.parse(text)); - } - text() { - return this.#cachedBody("text"); - } - arrayBuffer() { - return this.#cachedBody("arrayBuffer"); - } - blob() { - return this.#cachedBody("blob"); - } - formData() { - return this.#cachedBody("formData"); - } - addValidatedData(target, data) { - this.#validatedData[target] = data; - } - valid(target) { - return this.#validatedData[target]; - } - get url() { - return this.raw.url; - } - get method() { - return this.raw.method; - } - get [import_constants.GET_MATCH_RESULT]() { - return this.#matchResult; - } - get matchedRoutes() { - return this.#matchResult[0].map(([[, route]]) => route); - } - get routePath() { - return this.#matchResult[0].map(([[, route]]) => route)[this.routeIndex].path; - } - }; - var cloneRawRequest = async (req) => { - if (!req.raw.bodyUsed) { - return req.raw.clone(); + node.insert(restTokens, index, paramMap, context, pathErrorCheckOnly); } - const cacheKey = Object.keys(req.bodyCache)[0]; - if (!cacheKey) { - throw new import_http_exception.HTTPException(500, { - message: "Cannot clone request: body was already consumed and not cached. Please use HonoRequest methods (e.g., req.json(), req.text()) instead of consuming req.raw directly." + buildRegExpStr() { + const childKeys = Object.keys(this.#children).sort(compareKey); + const strList = childKeys.map((k) => { + const c = this.#children[k]; + return (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + c.buildRegExpStr(); }); + if (typeof this.#index === "number") { + strList.unshift(`#${this.#index}`); + } + if (strList.length === 0) { + return ""; + } + if (strList.length === 1) { + return strList[0]; + } + return "(?:" + strList.join("|") + ")"; } - const requestInit = { - body: await req[cacheKey](), - cache: req.raw.cache, - credentials: req.raw.credentials, - headers: req.header(), - integrity: req.raw.integrity, - keepalive: req.raw.keepalive, - method: req.method, - mode: req.raw.mode, - redirect: req.raw.redirect, - referrer: req.raw.referrer, - referrerPolicy: req.raw.referrerPolicy, - signal: req.raw.signal - }; - return new Request(req.url, requestInit); }; } }); -// ../node_modules/hono/dist/cjs/utils/html.js -var require_html = __commonJS({ - "../node_modules/hono/dist/cjs/utils/html.js"(exports2, module2) { +// ../node_modules/hono/dist/cjs/router/reg-exp-router/trie.js +var require_trie = __commonJS({ + "../node_modules/hono/dist/cjs/router/reg-exp-router/trie.js"(exports2, module2) { "use strict"; var __defProp2 = Object.defineProperty; var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor; @@ -3050,136 +3321,72 @@ var require_html = __commonJS({ return to; }; var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod); - var html_exports = {}; - __export(html_exports, { - HtmlEscapedCallbackPhase: () => HtmlEscapedCallbackPhase, - escapeToBuffer: () => escapeToBuffer, - raw: () => raw, - resolveCallback: () => resolveCallback, - resolveCallbackSync: () => resolveCallbackSync, - stringBufferToString: () => stringBufferToString + var trie_exports = {}; + __export(trie_exports, { + Trie: () => Trie }); - module2.exports = __toCommonJS(html_exports); - var HtmlEscapedCallbackPhase = { - Stringify: 1, - BeforeStream: 2, - Stream: 3 - }; - var raw = (value, callbacks) => { - const escapedString = new String(value); - escapedString.isEscaped = true; - escapedString.callbacks = callbacks; - return escapedString; - }; - var escapeRe = /[&<>'"]/; - var stringBufferToString = async (buffer, callbacks) => { - let str = ""; - callbacks ||= []; - const resolvedBuffer = await Promise.all(buffer); - for (let i = resolvedBuffer.length - 1; ; i--) { - str += resolvedBuffer[i]; - i--; - if (i < 0) { - break; - } - let r = resolvedBuffer[i]; - if (typeof r === "object") { - callbacks.push(...r.callbacks || []); - } - const isEscaped = r.isEscaped; - r = await (typeof r === "object" ? r.toString() : r); - if (typeof r === "object") { - callbacks.push(...r.callbacks || []); - } - if (r.isEscaped ?? isEscaped) { - str += r; - } else { - const buf = [str]; - escapeToBuffer(r, buf); - str = buf[0]; - } - } - return raw(str, callbacks); - }; - var escapeToBuffer = (str, buffer) => { - const match = str.search(escapeRe); - if (match === -1) { - buffer[0] += str; - return; - } - let escape; - let index; - let lastIndex = 0; - for (index = match; index < str.length; index++) { - switch (str.charCodeAt(index)) { - case 34: - escape = """; - break; - case 39: - escape = "'"; - break; - case 38: - escape = "&"; - break; - case 60: - escape = "<"; - break; - case 62: - escape = ">"; + module2.exports = __toCommonJS(trie_exports); + var import_node = require_node(); + var Trie = class { + #context = { varIndex: 0 }; + #root = new import_node.Node(); + insert(path, index, pathErrorCheckOnly) { + const paramAssoc = []; + const groups = []; + for (let i = 0; ; ) { + let replaced = false; + path = path.replace(/\{[^}]+\}/g, (m) => { + const mark = `@\\${i}`; + groups[i] = [mark, m]; + i++; + replaced = true; + return mark; + }); + if (!replaced) { break; - default: - continue; - } - buffer[0] += str.substring(lastIndex, index) + escape; - lastIndex = index + 1; - } - buffer[0] += str.substring(lastIndex, index); - }; - var resolveCallbackSync = (str) => { - const callbacks = str.callbacks; - if (!callbacks?.length) { - return str; - } - const buffer = [str]; - const context = {}; - callbacks.forEach((c) => c({ phase: HtmlEscapedCallbackPhase.Stringify, buffer, context })); - return buffer[0]; - }; - var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) => { - if (typeof str === "object" && !(str instanceof String)) { - if (!(str instanceof Promise)) { - str = str.toString(); + } } - if (str instanceof Promise) { - str = await str; + const tokens = path.match(/(?::[^\/]+)|(?:\/\*$)|./g) || []; + for (let i = groups.length - 1; i >= 0; i--) { + const [mark] = groups[i]; + for (let j = tokens.length - 1; j >= 0; j--) { + if (tokens[j].indexOf(mark) !== -1) { + tokens[j] = tokens[j].replace(mark, groups[i][1]); + break; + } + } } + this.#root.insert(tokens, index, paramAssoc, this.#context, pathErrorCheckOnly); + return paramAssoc; } - const callbacks = str.callbacks; - if (!callbacks?.length) { - return Promise.resolve(str); - } - if (buffer) { - buffer[0] += str; - } else { - buffer = [str]; - } - const resStr = Promise.all(callbacks.map((c) => c({ phase, buffer, context }))).then( - (res) => Promise.all( - res.filter(Boolean).map((str2) => resolveCallback(str2, phase, false, context, buffer)) - ).then(() => buffer[0]) - ); - if (preserveCallbacks) { - return raw(await resStr, callbacks); - } else { - return resStr; + buildRegExp() { + let regexp = this.#root.buildRegExpStr(); + if (regexp === "") { + return [/^$/, [], []]; + } + let captureIndex = 0; + const indexReplacementMap = []; + const paramReplacementMap = []; + regexp = regexp.replace(/#(\d+)|@(\d+)|\.\*\$/g, (_, handlerIndex, paramIndex) => { + if (handlerIndex !== void 0) { + indexReplacementMap[++captureIndex] = Number(handlerIndex); + return "$()"; + } + if (paramIndex !== void 0) { + paramReplacementMap[Number(paramIndex)] = ++captureIndex; + return ""; + } + return ""; + }); + return [new RegExp(`^${regexp}`), indexReplacementMap, paramReplacementMap]; } }; } }); -// ../node_modules/hono/dist/cjs/context.js -var require_context = __commonJS({ - "../node_modules/hono/dist/cjs/context.js"(exports2, module2) { +// ../node_modules/hono/dist/cjs/router/reg-exp-router/router.js +var require_router2 = __commonJS({ + "../node_modules/hono/dist/cjs/router/reg-exp-router/router.js"(exports2, module2) { "use strict"; var __defProp2 = Object.defineProperty; var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor; @@ -3198,195 +3405,199 @@ var require_context = __commonJS({ return to; }; var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod); - var context_exports = {}; - __export(context_exports, { - Context: () => Context, - TEXT_PLAIN: () => TEXT_PLAIN + var router_exports = {}; + __export(router_exports, { + RegExpRouter: () => RegExpRouter2 }); - module2.exports = __toCommonJS(context_exports); - var import_request = require_request2(); - var import_html = require_html(); - var TEXT_PLAIN = "text/plain; charset=UTF-8"; - var setDefaultContentType = (contentType, headers) => { - return { - "Content-Type": contentType, - ...headers - }; - }; - var Context = class { - #rawRequest; - #req; - env = {}; - #var; - finalized = false; - error; - #status; - #executionCtx; - #res; - #layout; - #renderer; - #notFoundHandler; - #preparedHeaders; - #matchResult; - #path; - constructor(req, options) { - this.#rawRequest = req; - if (options) { - this.#executionCtx = options.executionCtx; - this.env = options.env; - this.#notFoundHandler = options.notFoundHandler; - this.#path = options.path; - this.#matchResult = options.matchResult; - } - } - get req() { - this.#req ??= new import_request.HonoRequest(this.#rawRequest, this.#path, this.#matchResult); - return this.#req; + module2.exports = __toCommonJS(router_exports); + var import_router = require_router(); + var import_url = require_url(); + var import_matcher = require_matcher(); + var import_node = require_node(); + var import_trie = require_trie(); + var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)]; + var wildcardRegExpCache = /* @__PURE__ */ Object.create(null); + function buildWildcardRegExp(path) { + return wildcardRegExpCache[path] ??= new RegExp( + path === "*" ? "" : `^${path.replace( + /\/\*$|([.\\+*[^\]$()])/g, + (_, metaChar) => metaChar ? `\\${metaChar}` : "(?:|/.*)" + )}$` + ); + } + function clearWildcardRegExpCache() { + wildcardRegExpCache = /* @__PURE__ */ Object.create(null); + } + function buildMatcherFromPreprocessedRoutes(routes) { + const trie = new import_trie.Trie(); + const handlerData = []; + if (routes.length === 0) { + return nullMatcher; } - get event() { - if (this.#executionCtx && "respondWith" in this.#executionCtx) { - return this.#executionCtx; + const routesWithStaticPathFlag = routes.map( + (route) => [!/\*|\/:/.test(route[0]), ...route] + ).sort( + ([isStaticA, pathA], [isStaticB, pathB]) => isStaticA ? 1 : isStaticB ? -1 : pathA.length - pathB.length + ); + const staticMap = /* @__PURE__ */ Object.create(null); + for (let i = 0, j = -1, len = routesWithStaticPathFlag.length; i < len; i++) { + const [pathErrorCheckOnly, path, handlers] = routesWithStaticPathFlag[i]; + if (pathErrorCheckOnly) { + staticMap[path] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), import_matcher.emptyParam]; } else { - throw Error("This context has no FetchEvent"); + j++; } - } - get executionCtx() { - if (this.#executionCtx) { - return this.#executionCtx; - } else { - throw Error("This context has no ExecutionContext"); + let paramAssoc; + try { + paramAssoc = trie.insert(path, j, pathErrorCheckOnly); + } catch (e) { + throw e === import_node.PATH_ERROR ? new import_router.UnsupportedPathError(path) : e; } - } - get res() { - return this.#res ||= new Response(null, { - headers: this.#preparedHeaders ??= new Headers() + if (pathErrorCheckOnly) { + continue; + } + handlerData[j] = handlers.map(([h, paramCount]) => { + const paramIndexMap = /* @__PURE__ */ Object.create(null); + paramCount -= 1; + for (; paramCount >= 0; paramCount--) { + const [key, value] = paramAssoc[paramCount]; + paramIndexMap[key] = value; + } + return [h, paramIndexMap]; }); } - set res(_res) { - if (this.#res && _res) { - _res = new Response(_res.body, _res); - for (const [k, v] of this.#res.headers.entries()) { - if (k === "content-type") { - continue; - } - if (k === "set-cookie") { - const cookies = this.#res.headers.getSetCookie(); - _res.headers.delete("set-cookie"); - for (const cookie of cookies) { - _res.headers.append("set-cookie", cookie); - } - } else { - _res.headers.set(k, v); - } + const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp(); + for (let i = 0, len = handlerData.length; i < len; i++) { + for (let j = 0, len2 = handlerData[i].length; j < len2; j++) { + const map = handlerData[i][j]?.[1]; + if (!map) { + continue; + } + const keys = Object.keys(map); + for (let k = 0, len3 = keys.length; k < len3; k++) { + map[keys[k]] = paramReplacementMap[map[keys[k]]]; } } - this.#res = _res; - this.finalized = true; } - render = (...args) => { - this.#renderer ??= (content) => this.html(content); - return this.#renderer(...args); - }; - setLayout = (layout) => this.#layout = layout; - getLayout = () => this.#layout; - setRenderer = (renderer) => { - this.#renderer = renderer; - }; - header = (name, value, options) => { - if (this.finalized) { - this.#res = new Response(this.#res.body, this.#res); + const handlerMap = []; + for (const i in indexReplacementMap) { + handlerMap[i] = handlerData[indexReplacementMap[i]]; + } + return [regexp, handlerMap, staticMap]; + } + function findMiddleware(middleware, path) { + if (!middleware) { + return void 0; + } + for (const k of Object.keys(middleware).sort((a, b) => b.length - a.length)) { + if (buildWildcardRegExp(k).test(path)) { + return [...middleware[k]]; } - const headers = this.#res ? this.#res.headers : this.#preparedHeaders ??= new Headers(); - if (value === void 0) { - headers.delete(name); - } else if (options?.append) { - headers.append(name, value); - } else { - headers.set(name, value); + } + return void 0; + } + var RegExpRouter2 = class { + name = "RegExpRouter"; + #middleware; + #routes; + constructor() { + this.#middleware = { [import_router.METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) }; + this.#routes = { [import_router.METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) }; + } + add(method, path, handler) { + const middleware = this.#middleware; + const routes = this.#routes; + if (!middleware || !routes) { + throw new Error(import_router.MESSAGE_MATCHER_IS_ALREADY_BUILT); } - }; - status = (status) => { - this.#status = status; - }; - set = (key, value) => { - this.#var ??= /* @__PURE__ */ new Map(); - this.#var.set(key, value); - }; - get = (key) => { - return this.#var ? this.#var.get(key) : void 0; - }; - get var() { - if (!this.#var) { - return {}; + if (!middleware[method]) { + ; + [middleware, routes].forEach((handlerMap) => { + handlerMap[method] = /* @__PURE__ */ Object.create(null); + Object.keys(handlerMap[import_router.METHOD_NAME_ALL]).forEach((p) => { + handlerMap[method][p] = [...handlerMap[import_router.METHOD_NAME_ALL][p]]; + }); + }); } - return Object.fromEntries(this.#var); - } - #newResponse(data, arg, headers) { - const responseHeaders = this.#res ? new Headers(this.#res.headers) : this.#preparedHeaders ?? new Headers(); - if (typeof arg === "object" && "headers" in arg) { - const argHeaders = arg.headers instanceof Headers ? arg.headers : new Headers(arg.headers); - for (const [key, value] of argHeaders) { - if (key.toLowerCase() === "set-cookie") { - responseHeaders.append(key, value); - } else { - responseHeaders.set(key, value); - } + if (path === "/*") { + path = "*"; + } + const paramCount = (path.match(/\/:/g) || []).length; + if (/\*$/.test(path)) { + const re = buildWildcardRegExp(path); + if (method === import_router.METHOD_NAME_ALL) { + Object.keys(middleware).forEach((m) => { + middleware[m][path] ||= findMiddleware(middleware[m], path) || findMiddleware(middleware[import_router.METHOD_NAME_ALL], path) || []; + }); + } else { + middleware[method][path] ||= findMiddleware(middleware[method], path) || findMiddleware(middleware[import_router.METHOD_NAME_ALL], path) || []; } + Object.keys(middleware).forEach((m) => { + if (method === import_router.METHOD_NAME_ALL || method === m) { + Object.keys(middleware[m]).forEach((p) => { + re.test(p) && middleware[m][p].push([handler, paramCount]); + }); + } + }); + Object.keys(routes).forEach((m) => { + if (method === import_router.METHOD_NAME_ALL || method === m) { + Object.keys(routes[m]).forEach( + (p) => re.test(p) && routes[m][p].push([handler, paramCount]) + ); + } + }); + return; } - if (headers) { - for (const [k, v] of Object.entries(headers)) { - if (typeof v === "string") { - responseHeaders.set(k, v); - } else { - responseHeaders.delete(k); - for (const v2 of v) { - responseHeaders.append(k, v2); - } + const paths = (0, import_url.checkOptionalParameter)(path) || [path]; + for (let i = 0, len = paths.length; i < len; i++) { + const path2 = paths[i]; + Object.keys(routes).forEach((m) => { + if (method === import_router.METHOD_NAME_ALL || method === m) { + routes[m][path2] ||= [ + ...findMiddleware(middleware[m], path2) || findMiddleware(middleware[import_router.METHOD_NAME_ALL], path2) || [] + ]; + routes[m][path2].push([handler, paramCount - len + i + 1]); } + }); + } + } + match = import_matcher.match; + buildAllMatchers() { + const matchers = /* @__PURE__ */ Object.create(null); + Object.keys(this.#routes).concat(Object.keys(this.#middleware)).forEach((method) => { + matchers[method] ||= this.#buildMatcher(method); + }); + this.#middleware = this.#routes = void 0; + clearWildcardRegExpCache(); + return matchers; + } + #buildMatcher(method) { + const routes = []; + let hasOwnRoute = method === import_router.METHOD_NAME_ALL; + [this.#middleware, this.#routes].forEach((r) => { + const ownRoute = r[method] ? Object.keys(r[method]).map((path) => [path, r[method][path]]) : []; + if (ownRoute.length !== 0) { + hasOwnRoute ||= true; + routes.push(...ownRoute); + } else if (method !== import_router.METHOD_NAME_ALL) { + routes.push( + ...Object.keys(r[import_router.METHOD_NAME_ALL]).map((path) => [path, r[import_router.METHOD_NAME_ALL][path]]) + ); } + }); + if (!hasOwnRoute) { + return null; + } else { + return buildMatcherFromPreprocessedRoutes(routes); } - const status = typeof arg === "number" ? arg : arg?.status ?? this.#status; - return new Response(data, { status, headers: responseHeaders }); } - newResponse = (...args) => this.#newResponse(...args); - body = (data, arg, headers) => this.#newResponse(data, arg, headers); - text = (text, arg, headers) => { - return !this.#preparedHeaders && !this.#status && !arg && !headers && !this.finalized ? new Response(text) : this.#newResponse( - text, - arg, - setDefaultContentType(TEXT_PLAIN, headers) - ); - }; - json = (object, arg, headers) => { - return this.#newResponse( - JSON.stringify(object), - arg, - setDefaultContentType("application/json", headers) - ); - }; - html = (html, arg, headers) => { - const res = (html2) => this.#newResponse(html2, arg, setDefaultContentType("text/html; charset=UTF-8", headers)); - return typeof html === "object" ? (0, import_html.resolveCallback)(html, import_html.HtmlEscapedCallbackPhase.Stringify, false, {}).then(res) : res(html); - }; - redirect = (location, status) => { - const locationString = String(location); - this.header( - "Location", - !/[^\x00-\xFF]/.test(locationString) ? locationString : encodeURI(locationString) - ); - return this.newResponse(null, status ?? 302); - }; - notFound = () => { - this.#notFoundHandler ??= () => new Response(); - return this.#notFoundHandler(this); - }; }; } }); -// ../node_modules/hono/dist/cjs/router.js -var require_router = __commonJS({ - "../node_modules/hono/dist/cjs/router.js"(exports2, module2) { +// ../node_modules/hono/dist/cjs/router/reg-exp-router/prepared-router.js +var require_prepared_router = __commonJS({ + "../node_modules/hono/dist/cjs/router/reg-exp-router/prepared-router.js"(exports2, module2) { "use strict"; var __defProp2 = Object.defineProperty; var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor; @@ -3405,27 +3616,155 @@ var require_router = __commonJS({ return to; }; var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod); - var router_exports = {}; - __export(router_exports, { - MESSAGE_MATCHER_IS_ALREADY_BUILT: () => MESSAGE_MATCHER_IS_ALREADY_BUILT, - METHODS: () => METHODS, - METHOD_NAME_ALL: () => METHOD_NAME_ALL, - METHOD_NAME_ALL_LOWERCASE: () => METHOD_NAME_ALL_LOWERCASE, - UnsupportedPathError: () => UnsupportedPathError - }); - module2.exports = __toCommonJS(router_exports); - var METHOD_NAME_ALL = "ALL"; - var METHOD_NAME_ALL_LOWERCASE = "all"; - var METHODS = ["get", "post", "put", "delete", "options", "patch"]; - var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built."; - var UnsupportedPathError = class extends Error { + var prepared_router_exports = {}; + __export(prepared_router_exports, { + PreparedRegExpRouter: () => PreparedRegExpRouter2, + buildInitParams: () => buildInitParams2, + serializeInitParams: () => serializeInitParams2 + }); + module2.exports = __toCommonJS(prepared_router_exports); + var import_router = require_router(); + var import_matcher = require_matcher(); + var import_router2 = require_router2(); + var PreparedRegExpRouter2 = class { + name = "PreparedRegExpRouter"; + #matchers; + #relocateMap; + constructor(matchers, relocateMap) { + this.#matchers = matchers; + this.#relocateMap = relocateMap; + } + #addWildcard(method, handlerData) { + const matcher = this.#matchers[method]; + matcher[1].forEach((list) => list && list.push(handlerData)); + Object.values(matcher[2]).forEach((list) => list[0].push(handlerData)); + } + #addPath(method, path, handler, indexes, map) { + const matcher = this.#matchers[method]; + if (!map) { + matcher[2][path][0].push([handler, {}]); + } else { + indexes.forEach((index) => { + if (typeof index === "number") { + matcher[1][index].push([handler, map]); + } else { + ; + matcher[2][index || path][0].push([handler, map]); + } + }); + } + } + add(method, path, handler) { + if (!this.#matchers[method]) { + const all = this.#matchers[import_router.METHOD_NAME_ALL]; + const staticMap = {}; + for (const key in all[2]) { + staticMap[key] = [all[2][key][0].slice(), import_matcher.emptyParam]; + } + this.#matchers[method] = [ + all[0], + all[1].map((list) => Array.isArray(list) ? list.slice() : 0), + staticMap + ]; + } + if (path === "/*" || path === "*") { + const handlerData = [handler, {}]; + if (method === import_router.METHOD_NAME_ALL) { + for (const m in this.#matchers) { + this.#addWildcard(m, handlerData); + } + } else { + this.#addWildcard(method, handlerData); + } + return; + } + const data = this.#relocateMap[path]; + if (!data) { + throw new Error(`Path ${path} is not registered`); + } + for (const [indexes, map] of data) { + if (method === import_router.METHOD_NAME_ALL) { + for (const m in this.#matchers) { + this.#addPath(m, path, handler, indexes, map); + } + } else { + this.#addPath(method, path, handler, indexes, map); + } + } + } + buildAllMatchers() { + return this.#matchers; + } + match = import_matcher.match; + }; + var buildInitParams2 = ({ paths }) => { + const RegExpRouterWithMatcherExport = class extends import_router2.RegExpRouter { + buildAndExportAllMatchers() { + return this.buildAllMatchers(); + } + }; + const router = new RegExpRouterWithMatcherExport(); + for (const path of paths) { + router.add(import_router.METHOD_NAME_ALL, path, path); + } + const matchers = router.buildAndExportAllMatchers(); + const all = matchers[import_router.METHOD_NAME_ALL]; + const relocateMap = {}; + for (const path of paths) { + if (path === "/*" || path === "*") { + continue; + } + all[1].forEach((list, i) => { + list.forEach(([p, map]) => { + if (p === path) { + if (relocateMap[path]) { + relocateMap[path][0][1] = { + ...relocateMap[path][0][1], + ...map + }; + } else { + relocateMap[path] = [[[], map]]; + } + if (relocateMap[path][0][0].findIndex((j) => j === i) === -1) { + relocateMap[path][0][0].push(i); + } + } + }); + }); + for (const path2 in all[2]) { + all[2][path2][0].forEach(([p]) => { + if (p === path) { + relocateMap[path] ||= [[[]]]; + const value = path2 === path ? "" : path2; + if (relocateMap[path][0][0].findIndex((v) => v === value) === -1) { + relocateMap[path][0][0].push(value); + } + } + }); + } + } + for (let i = 0, len = all[1].length; i < len; i++) { + all[1][i] = all[1][i] ? [] : 0; + } + for (const path in all[2]) { + all[2][path][0] = []; + } + return [matchers, relocateMap]; + }; + var serializeInitParams2 = ([matchers, relocateMap]) => { + const matchersStr = JSON.stringify( + matchers, + (_, value) => value instanceof RegExp ? `##${value.toString()}##` : value + ).replace(/"##(.+?)##"/g, (_, str) => str.replace(/\\\\/g, "\\")); + const relocateMapStr = JSON.stringify(relocateMap); + return `[${matchersStr},${relocateMapStr}]`; }; } }); -// ../node_modules/hono/dist/cjs/utils/constants.js -var require_constants2 = __commonJS({ - "../node_modules/hono/dist/cjs/utils/constants.js"(exports2, module2) { +// ../node_modules/hono/dist/cjs/router/reg-exp-router/index.js +var require_reg_exp_router = __commonJS({ + "../node_modules/hono/dist/cjs/router/reg-exp-router/index.js"(exports2, module2) { "use strict"; var __defProp2 = Object.defineProperty; var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor; @@ -3444,18 +3783,22 @@ var require_constants2 = __commonJS({ return to; }; var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod); - var constants_exports = {}; - __export(constants_exports, { - COMPOSED_HANDLER: () => COMPOSED_HANDLER + var reg_exp_router_exports = {}; + __export(reg_exp_router_exports, { + PreparedRegExpRouter: () => import_prepared_router.PreparedRegExpRouter, + RegExpRouter: () => import_router.RegExpRouter, + buildInitParams: () => import_prepared_router.buildInitParams, + serializeInitParams: () => import_prepared_router.serializeInitParams }); - module2.exports = __toCommonJS(constants_exports); - var COMPOSED_HANDLER = "__COMPOSED_HANDLER"; + module2.exports = __toCommonJS(reg_exp_router_exports); + var import_router = require_router2(); + var import_prepared_router = require_prepared_router(); } }); -// ../node_modules/hono/dist/cjs/hono-base.js -var require_hono_base = __commonJS({ - "../node_modules/hono/dist/cjs/hono-base.js"(exports2, module2) { +// ../node_modules/hono/dist/cjs/router/smart-router/router.js +var require_router3 = __commonJS({ + "../node_modules/hono/dist/cjs/router/smart-router/router.js"(exports2, module2) { "use strict"; var __defProp2 = Object.defineProperty; var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor; @@ -3474,251 +3817,71 @@ var require_hono_base = __commonJS({ return to; }; var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod); - var hono_base_exports = {}; - __export(hono_base_exports, { - HonoBase: () => Hono2 + var router_exports = {}; + __export(router_exports, { + SmartRouter: () => SmartRouter2 }); - module2.exports = __toCommonJS(hono_base_exports); - var import_compose = require_compose(); - var import_context = require_context(); + module2.exports = __toCommonJS(router_exports); var import_router = require_router(); - var import_constants = require_constants2(); - var import_url = require_url(); - var notFoundHandler = (c) => { - return c.text("404 Not Found", 404); - }; - var errorHandler = (err, c) => { - if ("getResponse" in err) { - const res = err.getResponse(); - return c.newResponse(res.body, res); + var SmartRouter2 = class { + name = "SmartRouter"; + #routers = []; + #routes = []; + constructor(init) { + this.#routers = init.routers; } - console.error(err); - return c.text("Internal Server Error", 500); - }; - var Hono2 = class _Hono { - get; - post; - put; - delete; - options; - patch; - all; - on; - use; - router; - getPath; - _basePath = "/"; - #path = "/"; - routes = []; - constructor(options = {}) { - const allMethods = [...import_router.METHODS, import_router.METHOD_NAME_ALL_LOWERCASE]; - allMethods.forEach((method) => { - this[method] = (args1, ...args) => { - if (typeof args1 === "string") { - this.#path = args1; - } else { - this.#addRoute(method, this.#path, args1); - } - args.forEach((handler) => { - this.#addRoute(method, this.#path, handler); - }); - return this; - }; - }); - this.on = (method, path, ...handlers) => { - for (const p of [path].flat()) { - this.#path = p; - for (const m of [method].flat()) { - handlers.map((handler) => { - this.#addRoute(m.toUpperCase(), this.#path, handler); - }); + add(method, path, handler) { + if (!this.#routes) { + throw new Error(import_router.MESSAGE_MATCHER_IS_ALREADY_BUILT); + } + this.#routes.push([method, path, handler]); + } + match(method, path) { + if (!this.#routes) { + throw new Error("Fatal error"); + } + const routers = this.#routers; + const routes = this.#routes; + const len = routers.length; + let i = 0; + let res; + for (; i < len; i++) { + const router = routers[i]; + try { + for (let i2 = 0, len2 = routes.length; i2 < len2; i2++) { + router.add(...routes[i2]); } - } - return this; - }; - this.use = (arg1, ...handlers) => { - if (typeof arg1 === "string") { - this.#path = arg1; - } else { - this.#path = "*"; - handlers.unshift(arg1); - } - handlers.forEach((handler) => { - this.#addRoute(import_router.METHOD_NAME_ALL, this.#path, handler); - }); - return this; - }; - const { strict, ...optionsWithoutStrict } = options; - Object.assign(this, optionsWithoutStrict); - this.getPath = strict ?? true ? options.getPath ?? import_url.getPath : import_url.getPathNoStrict; - } - #clone() { - const clone = new _Hono({ - router: this.router, - getPath: this.getPath - }); - clone.errorHandler = this.errorHandler; - clone.#notFoundHandler = this.#notFoundHandler; - clone.routes = this.routes; - return clone; - } - #notFoundHandler = notFoundHandler; - errorHandler = errorHandler; - route(path, app) { - const subApp = this.basePath(path); - app.routes.map((r) => { - let handler; - if (app.errorHandler === errorHandler) { - handler = r.handler; - } else { - handler = async (c, next) => (await (0, import_compose.compose)([], app.errorHandler)(c, () => r.handler(c, next))).res; - handler[import_constants.COMPOSED_HANDLER] = r.handler; - } - subApp.#addRoute(r.method, r.path, handler); - }); - return this; - } - basePath(path) { - const subApp = this.#clone(); - subApp._basePath = (0, import_url.mergePath)(this._basePath, path); - return subApp; - } - onError = (handler) => { - this.errorHandler = handler; - return this; - }; - notFound = (handler) => { - this.#notFoundHandler = handler; - return this; - }; - mount(path, applicationHandler, options) { - let replaceRequest; - let optionHandler; - if (options) { - if (typeof options === "function") { - optionHandler = options; - } else { - optionHandler = options.optionHandler; - if (options.replaceRequest === false) { - replaceRequest = (request) => request; - } else { - replaceRequest = options.replaceRequest; + res = router.match(method, path); + } catch (e) { + if (e instanceof import_router.UnsupportedPathError) { + continue; } + throw e; } + this.match = router.match.bind(router); + this.#routers = [router]; + this.#routes = void 0; + break; } - const getOptions = optionHandler ? (c) => { - const options2 = optionHandler(c); - return Array.isArray(options2) ? options2 : [options2]; - } : (c) => { - let executionContext = void 0; - try { - executionContext = c.executionCtx; - } catch { - } - return [c.env, executionContext]; - }; - replaceRequest ||= (() => { - const mergedPath = (0, import_url.mergePath)(this._basePath, path); - const pathPrefixLength = mergedPath === "/" ? 0 : mergedPath.length; - return (request) => { - const url = new URL(request.url); - url.pathname = url.pathname.slice(pathPrefixLength) || "/"; - return new Request(url, request); - }; - })(); - const handler = async (c, next) => { - const res = await applicationHandler(replaceRequest(c.req.raw), ...getOptions(c)); - if (res) { - return res; - } - await next(); - }; - this.#addRoute(import_router.METHOD_NAME_ALL, (0, import_url.mergePath)(path, "*"), handler); - return this; - } - #addRoute(method, path, handler) { - method = method.toUpperCase(); - path = (0, import_url.mergePath)(this._basePath, path); - const r = { basePath: this._basePath, path, method, handler }; - this.router.add(method, path, [handler, r]); - this.routes.push(r); - } - #handleError(err, c) { - if (err instanceof Error) { - return this.errorHandler(err, c); + if (i === len) { + throw new Error("Fatal error"); } - throw err; + this.name = `SmartRouter + ${this.activeRouter.name}`; + return res; } - #dispatch(request, executionCtx, env, method) { - if (method === "HEAD") { - return (async () => new Response(null, await this.#dispatch(request, executionCtx, env, "GET")))(); - } - const path = this.getPath(request, { env }); - const matchResult = this.router.match(method, path); - const c = new import_context.Context(request, { - path, - matchResult, - env, - executionCtx, - notFoundHandler: this.#notFoundHandler - }); - if (matchResult[0].length === 1) { - let res; - try { - res = matchResult[0][0][0][0](c, async () => { - c.res = await this.#notFoundHandler(c); - }); - } catch (err) { - return this.#handleError(err, c); - } - return res instanceof Promise ? res.then( - (resolved) => resolved || (c.finalized ? c.res : this.#notFoundHandler(c)) - ).catch((err) => this.#handleError(err, c)) : res ?? this.#notFoundHandler(c); + get activeRouter() { + if (this.#routes || this.#routers.length !== 1) { + throw new Error("No active router has been determined yet."); } - const composed = (0, import_compose.compose)(matchResult[0], this.errorHandler, this.#notFoundHandler); - return (async () => { - try { - const context = await composed(c); - if (!context.finalized) { - throw new Error( - "Context is not finalized. Did you forget to return a Response object or `await next()`?" - ); - } - return context.res; - } catch (err) { - return this.#handleError(err, c); - } - })(); + return this.#routers[0]; } - fetch = (request, ...rest) => { - return this.#dispatch(request, rest[1], rest[0], request.method); - }; - request = (input, requestInit, Env, executionCtx) => { - if (input instanceof Request) { - return this.fetch(requestInit ? new Request(input, requestInit) : input, Env, executionCtx); - } - input = input.toString(); - return this.fetch( - new Request( - /^https?:\/\//.test(input) ? input : `http://localhost${(0, import_url.mergePath)("/", input)}`, - requestInit - ), - Env, - executionCtx - ); - }; - fire = () => { - addEventListener("fetch", (event) => { - event.respondWith(this.#dispatch(event.request, event, void 0, event.request.method)); - }); - }; }; } }); -// ../node_modules/hono/dist/cjs/router/reg-exp-router/matcher.js -var require_matcher = __commonJS({ - "../node_modules/hono/dist/cjs/router/reg-exp-router/matcher.js"(exports2, module2) { +// ../node_modules/hono/dist/cjs/router/smart-router/index.js +var require_smart_router = __commonJS({ + "../node_modules/hono/dist/cjs/router/smart-router/index.js"(exports2, module2) { "use strict"; var __defProp2 = Object.defineProperty; var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor; @@ -3737,38 +3900,18 @@ var require_matcher = __commonJS({ return to; }; var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod); - var matcher_exports = {}; - __export(matcher_exports, { - emptyParam: () => emptyParam, - match: () => match + var smart_router_exports = {}; + __export(smart_router_exports, { + SmartRouter: () => import_router.SmartRouter }); - module2.exports = __toCommonJS(matcher_exports); - var import_router = require_router(); - var emptyParam = []; - function match(method, path) { - const matchers = this.buildAllMatchers(); - const match2 = (method2, path2) => { - const matcher = matchers[method2] || matchers[import_router.METHOD_NAME_ALL]; - const staticMatch = matcher[2][path2]; - if (staticMatch) { - return staticMatch; - } - const match3 = path2.match(matcher[0]); - if (!match3) { - return [[], emptyParam]; - } - const index = match3.indexOf("", 1); - return [matcher[1][index], match3]; - }; - this.match = match2; - return match2(method, path); - } + module2.exports = __toCommonJS(smart_router_exports); + var import_router = require_router3(); } }); -// ../node_modules/hono/dist/cjs/router/reg-exp-router/node.js -var require_node = __commonJS({ - "../node_modules/hono/dist/cjs/router/reg-exp-router/node.js"(exports2, module2) { +// ../node_modules/hono/dist/cjs/router/trie-router/node.js +var require_node2 = __commonJS({ + "../node_modules/hono/dist/cjs/router/trie-router/node.js"(exports2, module2) { "use strict"; var __defProp2 = Object.defineProperty; var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor; @@ -3789,122 +3932,173 @@ var require_node = __commonJS({ var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod); var node_exports = {}; __export(node_exports, { - Node: () => Node, - PATH_ERROR: () => PATH_ERROR + Node: () => Node }); module2.exports = __toCommonJS(node_exports); - var LABEL_REG_EXP_STR = "[^/]+"; - var ONLY_WILDCARD_REG_EXP_STR = ".*"; - var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)"; - var PATH_ERROR = Symbol(); - var regExpMetaChars = new Set(".\\+*[^]$()"); - function compareKey(a, b) { - if (a.length === 1) { - return b.length === 1 ? a < b ? -1 : 1 : -1; - } - if (b.length === 1) { - return 1; - } - if (a === ONLY_WILDCARD_REG_EXP_STR || a === TAIL_WILDCARD_REG_EXP_STR) { - return 1; - } else if (b === ONLY_WILDCARD_REG_EXP_STR || b === TAIL_WILDCARD_REG_EXP_STR) { - return -1; - } - if (a === LABEL_REG_EXP_STR) { - return 1; - } else if (b === LABEL_REG_EXP_STR) { - return -1; - } - return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length; - } + var import_router = require_router(); + var import_url = require_url(); + var emptyParams = /* @__PURE__ */ Object.create(null); var Node = class _Node { - #index; - #varIndex; - #children = /* @__PURE__ */ Object.create(null); - insert(tokens, index, paramMap, context, pathErrorCheckOnly) { - if (tokens.length === 0) { - if (this.#index !== void 0) { - throw PATH_ERROR; - } - if (pathErrorCheckOnly) { - return; - } - this.#index = index; - return; + #methods; + #children; + #patterns; + #order = 0; + #params = emptyParams; + constructor(method, handler, children) { + this.#children = children || /* @__PURE__ */ Object.create(null); + this.#methods = []; + if (method && handler) { + const m = /* @__PURE__ */ Object.create(null); + m[method] = { handler, possibleKeys: [], score: 0 }; + this.#methods = [m]; } - const [token, ...restTokens] = tokens; - const pattern = token === "*" ? restTokens.length === 0 ? ["", "", ONLY_WILDCARD_REG_EXP_STR] : ["", "", LABEL_REG_EXP_STR] : token === "/*" ? ["", "", TAIL_WILDCARD_REG_EXP_STR] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/); - let node; - if (pattern) { - const name = pattern[1]; - let regexpStr = pattern[2] || LABEL_REG_EXP_STR; - if (name && pattern[2]) { - if (regexpStr === ".*") { - throw PATH_ERROR; - } - regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:"); - if (/\((?!\?:)/.test(regexpStr)) { - throw PATH_ERROR; + this.#patterns = []; + } + insert(method, path, handler) { + this.#order = ++this.#order; + let curNode = this; + const parts = (0, import_url.splitRoutingPath)(path); + const possibleKeys = []; + for (let i = 0, len = parts.length; i < len; i++) { + const p = parts[i]; + const nextP = parts[i + 1]; + const pattern = (0, import_url.getPattern)(p, nextP); + const key = Array.isArray(pattern) ? pattern[0] : p; + if (key in curNode.#children) { + curNode = curNode.#children[key]; + if (pattern) { + possibleKeys.push(pattern[1]); } + continue; } - node = this.#children[regexpStr]; - if (!node) { - if (Object.keys(this.#children).some( - (k) => k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR - )) { - throw PATH_ERROR; - } - if (pathErrorCheckOnly) { - return; - } - node = this.#children[regexpStr] = new _Node(); - if (name !== "") { - node.#varIndex = context.varIndex++; - } + curNode.#children[key] = new _Node(); + if (pattern) { + curNode.#patterns.push(pattern); + possibleKeys.push(pattern[1]); } - if (!pathErrorCheckOnly && name !== "") { - paramMap.push([name, node.#varIndex]); + curNode = curNode.#children[key]; + } + curNode.#methods.push({ + [method]: { + handler, + possibleKeys: possibleKeys.filter((v, i, a) => a.indexOf(v) === i), + score: this.#order } - } else { - node = this.#children[token]; - if (!node) { - if (Object.keys(this.#children).some( - (k) => k.length > 1 && k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR - )) { - throw PATH_ERROR; - } - if (pathErrorCheckOnly) { - return; + }); + return curNode; + } + #getHandlerSets(node, method, nodeParams, params) { + const handlerSets = []; + for (let i = 0, len = node.#methods.length; i < len; i++) { + const m = node.#methods[i]; + const handlerSet = m[method] || m[import_router.METHOD_NAME_ALL]; + const processedSet = {}; + if (handlerSet !== void 0) { + handlerSet.params = /* @__PURE__ */ Object.create(null); + handlerSets.push(handlerSet); + if (nodeParams !== emptyParams || params && params !== emptyParams) { + for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) { + const key = handlerSet.possibleKeys[i2]; + const processed = processedSet[handlerSet.score]; + handlerSet.params[key] = params?.[key] && !processed ? params[key] : nodeParams[key] ?? params?.[key]; + processedSet[handlerSet.score] = true; + } } - node = this.#children[token] = new _Node(); } } - node.insert(restTokens, index, paramMap, context, pathErrorCheckOnly); + return handlerSets; } - buildRegExpStr() { - const childKeys = Object.keys(this.#children).sort(compareKey); - const strList = childKeys.map((k) => { - const c = this.#children[k]; - return (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + c.buildRegExpStr(); - }); - if (typeof this.#index === "number") { - strList.unshift(`#${this.#index}`); - } - if (strList.length === 0) { - return ""; + search(method, path) { + const handlerSets = []; + this.#params = emptyParams; + const curNode = this; + let curNodes = [curNode]; + const parts = (0, import_url.splitPath)(path); + const curNodesQueue = []; + for (let i = 0, len = parts.length; i < len; i++) { + const part = parts[i]; + const isLast = i === len - 1; + const tempNodes = []; + for (let j = 0, len2 = curNodes.length; j < len2; j++) { + const node = curNodes[j]; + const nextNode = node.#children[part]; + if (nextNode) { + nextNode.#params = node.#params; + if (isLast) { + if (nextNode.#children["*"]) { + handlerSets.push( + ...this.#getHandlerSets(nextNode.#children["*"], method, node.#params) + ); + } + handlerSets.push(...this.#getHandlerSets(nextNode, method, node.#params)); + } else { + tempNodes.push(nextNode); + } + } + for (let k = 0, len3 = node.#patterns.length; k < len3; k++) { + const pattern = node.#patterns[k]; + const params = node.#params === emptyParams ? {} : { ...node.#params }; + if (pattern === "*") { + const astNode = node.#children["*"]; + if (astNode) { + handlerSets.push(...this.#getHandlerSets(astNode, method, node.#params)); + astNode.#params = params; + tempNodes.push(astNode); + } + continue; + } + const [key, name, matcher] = pattern; + if (!part && !(matcher instanceof RegExp)) { + continue; + } + const child = node.#children[key]; + const restPathString = parts.slice(i).join("/"); + if (matcher instanceof RegExp) { + const m = matcher.exec(restPathString); + if (m) { + params[name] = m[0]; + handlerSets.push(...this.#getHandlerSets(child, method, node.#params, params)); + if (Object.keys(child.#children).length) { + child.#params = params; + const componentCount = m[0].match(/\//)?.length ?? 0; + const targetCurNodes = curNodesQueue[componentCount] ||= []; + targetCurNodes.push(child); + } + continue; + } + } + if (matcher === true || matcher.test(part)) { + params[name] = part; + if (isLast) { + handlerSets.push(...this.#getHandlerSets(child, method, params, node.#params)); + if (child.#children["*"]) { + handlerSets.push( + ...this.#getHandlerSets(child.#children["*"], method, params, node.#params) + ); + } + } else { + child.#params = params; + tempNodes.push(child); + } + } + } + } + curNodes = tempNodes.concat(curNodesQueue.shift() ?? []); } - if (strList.length === 1) { - return strList[0]; + if (handlerSets.length > 1) { + handlerSets.sort((a, b) => { + return a.score - b.score; + }); } - return "(?:" + strList.join("|") + ")"; + return [handlerSets.map(({ handler, params }) => [handler, params])]; } }; } }); -// ../node_modules/hono/dist/cjs/router/reg-exp-router/trie.js -var require_trie = __commonJS({ - "../node_modules/hono/dist/cjs/router/reg-exp-router/trie.js"(exports2, module2) { +// ../node_modules/hono/dist/cjs/router/trie-router/router.js +var require_router4 = __commonJS({ + "../node_modules/hono/dist/cjs/router/trie-router/router.js"(exports2, module2) { "use strict"; var __defProp2 = Object.defineProperty; var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor; @@ -3923,72 +4117,39 @@ var require_trie = __commonJS({ return to; }; var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod); - var trie_exports = {}; - __export(trie_exports, { - Trie: () => Trie + var router_exports = {}; + __export(router_exports, { + TrieRouter: () => TrieRouter2 }); - module2.exports = __toCommonJS(trie_exports); - var import_node = require_node(); - var Trie = class { - #context = { varIndex: 0 }; - #root = new import_node.Node(); - insert(path, index, pathErrorCheckOnly) { - const paramAssoc = []; - const groups = []; - for (let i = 0; ; ) { - let replaced = false; - path = path.replace(/\{[^}]+\}/g, (m) => { - const mark = `@\\${i}`; - groups[i] = [mark, m]; - i++; - replaced = true; - return mark; - }); - if (!replaced) { - break; - } - } - const tokens = path.match(/(?::[^\/]+)|(?:\/\*$)|./g) || []; - for (let i = groups.length - 1; i >= 0; i--) { - const [mark] = groups[i]; - for (let j = tokens.length - 1; j >= 0; j--) { - if (tokens[j].indexOf(mark) !== -1) { - tokens[j] = tokens[j].replace(mark, groups[i][1]); - break; - } - } - } - this.#root.insert(tokens, index, paramAssoc, this.#context, pathErrorCheckOnly); - return paramAssoc; + module2.exports = __toCommonJS(router_exports); + var import_url = require_url(); + var import_node = require_node2(); + var TrieRouter2 = class { + name = "TrieRouter"; + #node; + constructor() { + this.#node = new import_node.Node(); } - buildRegExp() { - let regexp = this.#root.buildRegExpStr(); - if (regexp === "") { - return [/^$/, [], []]; - } - let captureIndex = 0; - const indexReplacementMap = []; - const paramReplacementMap = []; - regexp = regexp.replace(/#(\d+)|@(\d+)|\.\*\$/g, (_, handlerIndex, paramIndex) => { - if (handlerIndex !== void 0) { - indexReplacementMap[++captureIndex] = Number(handlerIndex); - return "$()"; - } - if (paramIndex !== void 0) { - paramReplacementMap[Number(paramIndex)] = ++captureIndex; - return ""; + add(method, path, handler) { + const results = (0, import_url.checkOptionalParameter)(path); + if (results) { + for (let i = 0, len = results.length; i < len; i++) { + this.#node.insert(method, results[i], handler); } - return ""; - }); - return [new RegExp(`^${regexp}`), indexReplacementMap, paramReplacementMap]; + return; + } + this.#node.insert(method, path, handler); + } + match(method, path) { + return this.#node.search(method, path); } }; } }); -// ../node_modules/hono/dist/cjs/router/reg-exp-router/router.js -var require_router2 = __commonJS({ - "../node_modules/hono/dist/cjs/router/reg-exp-router/router.js"(exports2, module2) { +// ../node_modules/hono/dist/cjs/router/trie-router/index.js +var require_trie_router = __commonJS({ + "../node_modules/hono/dist/cjs/router/trie-router/index.js"(exports2, module2) { "use strict"; var __defProp2 = Object.defineProperty; var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor; @@ -4007,199 +4168,18 @@ var require_router2 = __commonJS({ return to; }; var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod); - var router_exports = {}; - __export(router_exports, { - RegExpRouter: () => RegExpRouter2 + var trie_router_exports = {}; + __export(trie_router_exports, { + TrieRouter: () => import_router.TrieRouter }); - module2.exports = __toCommonJS(router_exports); - var import_router = require_router(); - var import_url = require_url(); - var import_matcher = require_matcher(); - var import_node = require_node(); - var import_trie = require_trie(); - var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)]; - var wildcardRegExpCache = /* @__PURE__ */ Object.create(null); - function buildWildcardRegExp(path) { - return wildcardRegExpCache[path] ??= new RegExp( - path === "*" ? "" : `^${path.replace( - /\/\*$|([.\\+*[^\]$()])/g, - (_, metaChar) => metaChar ? `\\${metaChar}` : "(?:|/.*)" - )}$` - ); - } - function clearWildcardRegExpCache() { - wildcardRegExpCache = /* @__PURE__ */ Object.create(null); - } - function buildMatcherFromPreprocessedRoutes(routes) { - const trie = new import_trie.Trie(); - const handlerData = []; - if (routes.length === 0) { - return nullMatcher; - } - const routesWithStaticPathFlag = routes.map( - (route) => [!/\*|\/:/.test(route[0]), ...route] - ).sort( - ([isStaticA, pathA], [isStaticB, pathB]) => isStaticA ? 1 : isStaticB ? -1 : pathA.length - pathB.length - ); - const staticMap = /* @__PURE__ */ Object.create(null); - for (let i = 0, j = -1, len = routesWithStaticPathFlag.length; i < len; i++) { - const [pathErrorCheckOnly, path, handlers] = routesWithStaticPathFlag[i]; - if (pathErrorCheckOnly) { - staticMap[path] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), import_matcher.emptyParam]; - } else { - j++; - } - let paramAssoc; - try { - paramAssoc = trie.insert(path, j, pathErrorCheckOnly); - } catch (e) { - throw e === import_node.PATH_ERROR ? new import_router.UnsupportedPathError(path) : e; - } - if (pathErrorCheckOnly) { - continue; - } - handlerData[j] = handlers.map(([h, paramCount]) => { - const paramIndexMap = /* @__PURE__ */ Object.create(null); - paramCount -= 1; - for (; paramCount >= 0; paramCount--) { - const [key, value] = paramAssoc[paramCount]; - paramIndexMap[key] = value; - } - return [h, paramIndexMap]; - }); - } - const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp(); - for (let i = 0, len = handlerData.length; i < len; i++) { - for (let j = 0, len2 = handlerData[i].length; j < len2; j++) { - const map = handlerData[i][j]?.[1]; - if (!map) { - continue; - } - const keys = Object.keys(map); - for (let k = 0, len3 = keys.length; k < len3; k++) { - map[keys[k]] = paramReplacementMap[map[keys[k]]]; - } - } - } - const handlerMap = []; - for (const i in indexReplacementMap) { - handlerMap[i] = handlerData[indexReplacementMap[i]]; - } - return [regexp, handlerMap, staticMap]; - } - function findMiddleware(middleware, path) { - if (!middleware) { - return void 0; - } - for (const k of Object.keys(middleware).sort((a, b) => b.length - a.length)) { - if (buildWildcardRegExp(k).test(path)) { - return [...middleware[k]]; - } - } - return void 0; - } - var RegExpRouter2 = class { - name = "RegExpRouter"; - #middleware; - #routes; - constructor() { - this.#middleware = { [import_router.METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) }; - this.#routes = { [import_router.METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) }; - } - add(method, path, handler) { - const middleware = this.#middleware; - const routes = this.#routes; - if (!middleware || !routes) { - throw new Error(import_router.MESSAGE_MATCHER_IS_ALREADY_BUILT); - } - if (!middleware[method]) { - ; - [middleware, routes].forEach((handlerMap) => { - handlerMap[method] = /* @__PURE__ */ Object.create(null); - Object.keys(handlerMap[import_router.METHOD_NAME_ALL]).forEach((p) => { - handlerMap[method][p] = [...handlerMap[import_router.METHOD_NAME_ALL][p]]; - }); - }); - } - if (path === "/*") { - path = "*"; - } - const paramCount = (path.match(/\/:/g) || []).length; - if (/\*$/.test(path)) { - const re = buildWildcardRegExp(path); - if (method === import_router.METHOD_NAME_ALL) { - Object.keys(middleware).forEach((m) => { - middleware[m][path] ||= findMiddleware(middleware[m], path) || findMiddleware(middleware[import_router.METHOD_NAME_ALL], path) || []; - }); - } else { - middleware[method][path] ||= findMiddleware(middleware[method], path) || findMiddleware(middleware[import_router.METHOD_NAME_ALL], path) || []; - } - Object.keys(middleware).forEach((m) => { - if (method === import_router.METHOD_NAME_ALL || method === m) { - Object.keys(middleware[m]).forEach((p) => { - re.test(p) && middleware[m][p].push([handler, paramCount]); - }); - } - }); - Object.keys(routes).forEach((m) => { - if (method === import_router.METHOD_NAME_ALL || method === m) { - Object.keys(routes[m]).forEach( - (p) => re.test(p) && routes[m][p].push([handler, paramCount]) - ); - } - }); - return; - } - const paths = (0, import_url.checkOptionalParameter)(path) || [path]; - for (let i = 0, len = paths.length; i < len; i++) { - const path2 = paths[i]; - Object.keys(routes).forEach((m) => { - if (method === import_router.METHOD_NAME_ALL || method === m) { - routes[m][path2] ||= [ - ...findMiddleware(middleware[m], path2) || findMiddleware(middleware[import_router.METHOD_NAME_ALL], path2) || [] - ]; - routes[m][path2].push([handler, paramCount - len + i + 1]); - } - }); - } - } - match = import_matcher.match; - buildAllMatchers() { - const matchers = /* @__PURE__ */ Object.create(null); - Object.keys(this.#routes).concat(Object.keys(this.#middleware)).forEach((method) => { - matchers[method] ||= this.#buildMatcher(method); - }); - this.#middleware = this.#routes = void 0; - clearWildcardRegExpCache(); - return matchers; - } - #buildMatcher(method) { - const routes = []; - let hasOwnRoute = method === import_router.METHOD_NAME_ALL; - [this.#middleware, this.#routes].forEach((r) => { - const ownRoute = r[method] ? Object.keys(r[method]).map((path) => [path, r[method][path]]) : []; - if (ownRoute.length !== 0) { - hasOwnRoute ||= true; - routes.push(...ownRoute); - } else if (method !== import_router.METHOD_NAME_ALL) { - routes.push( - ...Object.keys(r[import_router.METHOD_NAME_ALL]).map((path) => [path, r[import_router.METHOD_NAME_ALL][path]]) - ); - } - }); - if (!hasOwnRoute) { - return null; - } else { - return buildMatcherFromPreprocessedRoutes(routes); - } - } - }; + module2.exports = __toCommonJS(trie_router_exports); + var import_router = require_router4(); } }); -// ../node_modules/hono/dist/cjs/router/reg-exp-router/prepared-router.js -var require_prepared_router = __commonJS({ - "../node_modules/hono/dist/cjs/router/reg-exp-router/prepared-router.js"(exports2, module2) { +// ../node_modules/hono/dist/cjs/hono.js +var require_hono = __commonJS({ + "../node_modules/hono/dist/cjs/hono.js"(exports2, module2) { "use strict"; var __defProp2 = Object.defineProperty; var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor; @@ -4218,155 +4198,29 @@ var require_prepared_router = __commonJS({ return to; }; var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod); - var prepared_router_exports = {}; - __export(prepared_router_exports, { - PreparedRegExpRouter: () => PreparedRegExpRouter2, - buildInitParams: () => buildInitParams2, - serializeInitParams: () => serializeInitParams2 + var hono_exports = {}; + __export(hono_exports, { + Hono: () => Hono2 }); - module2.exports = __toCommonJS(prepared_router_exports); - var import_router = require_router(); - var import_matcher = require_matcher(); - var import_router2 = require_router2(); - var PreparedRegExpRouter2 = class { - name = "PreparedRegExpRouter"; - #matchers; - #relocateMap; - constructor(matchers, relocateMap) { - this.#matchers = matchers; - this.#relocateMap = relocateMap; - } - #addWildcard(method, handlerData) { - const matcher = this.#matchers[method]; - matcher[1].forEach((list) => list && list.push(handlerData)); - Object.values(matcher[2]).forEach((list) => list[0].push(handlerData)); - } - #addPath(method, path, handler, indexes, map) { - const matcher = this.#matchers[method]; - if (!map) { - matcher[2][path][0].push([handler, {}]); - } else { - indexes.forEach((index) => { - if (typeof index === "number") { - matcher[1][index].push([handler, map]); - } else { - ; - matcher[2][index || path][0].push([handler, map]); - } - }); - } - } - add(method, path, handler) { - if (!this.#matchers[method]) { - const all = this.#matchers[import_router.METHOD_NAME_ALL]; - const staticMap = {}; - for (const key in all[2]) { - staticMap[key] = [all[2][key][0].slice(), import_matcher.emptyParam]; - } - this.#matchers[method] = [ - all[0], - all[1].map((list) => Array.isArray(list) ? list.slice() : 0), - staticMap - ]; - } - if (path === "/*" || path === "*") { - const handlerData = [handler, {}]; - if (method === import_router.METHOD_NAME_ALL) { - for (const m in this.#matchers) { - this.#addWildcard(m, handlerData); - } - } else { - this.#addWildcard(method, handlerData); - } - return; - } - const data = this.#relocateMap[path]; - if (!data) { - throw new Error(`Path ${path} is not registered`); - } - for (const [indexes, map] of data) { - if (method === import_router.METHOD_NAME_ALL) { - for (const m in this.#matchers) { - this.#addPath(m, path, handler, indexes, map); - } - } else { - this.#addPath(method, path, handler, indexes, map); - } - } - } - buildAllMatchers() { - return this.#matchers; - } - match = import_matcher.match; - }; - var buildInitParams2 = ({ paths }) => { - const RegExpRouterWithMatcherExport = class extends import_router2.RegExpRouter { - buildAndExportAllMatchers() { - return this.buildAllMatchers(); - } - }; - const router = new RegExpRouterWithMatcherExport(); - for (const path of paths) { - router.add(import_router.METHOD_NAME_ALL, path, path); - } - const matchers = router.buildAndExportAllMatchers(); - const all = matchers[import_router.METHOD_NAME_ALL]; - const relocateMap = {}; - for (const path of paths) { - if (path === "/*" || path === "*") { - continue; - } - all[1].forEach((list, i) => { - list.forEach(([p, map]) => { - if (p === path) { - if (relocateMap[path]) { - relocateMap[path][0][1] = { - ...relocateMap[path][0][1], - ...map - }; - } else { - relocateMap[path] = [[[], map]]; - } - if (relocateMap[path][0][0].findIndex((j) => j === i) === -1) { - relocateMap[path][0][0].push(i); - } - } - }); + module2.exports = __toCommonJS(hono_exports); + var import_hono_base = require_hono_base(); + var import_reg_exp_router = require_reg_exp_router(); + var import_smart_router = require_smart_router(); + var import_trie_router = require_trie_router(); + var Hono2 = class extends import_hono_base.HonoBase { + constructor(options = {}) { + super(options); + this.router = options.router ?? new import_smart_router.SmartRouter({ + routers: [new import_reg_exp_router.RegExpRouter(), new import_trie_router.TrieRouter()] }); - for (const path2 in all[2]) { - all[2][path2][0].forEach(([p]) => { - if (p === path) { - relocateMap[path] ||= [[[]]]; - const value = path2 === path ? "" : path2; - if (relocateMap[path][0][0].findIndex((v) => v === value) === -1) { - relocateMap[path][0][0].push(value); - } - } - }); - } - } - for (let i = 0, len = all[1].length; i < len; i++) { - all[1][i] = all[1][i] ? [] : 0; } - for (const path in all[2]) { - all[2][path][0] = []; - } - return [matchers, relocateMap]; - }; - var serializeInitParams2 = ([matchers, relocateMap]) => { - const matchersStr = JSON.stringify( - matchers, - (_, value) => value instanceof RegExp ? `##${value.toString()}##` : value - ).replace(/"##(.+?)##"/g, (_, str) => str.replace(/\\\\/g, "\\")); - const relocateMapStr = JSON.stringify(relocateMap); - return `[${matchersStr},${relocateMapStr}]`; }; } }); -// ../node_modules/hono/dist/cjs/router/reg-exp-router/index.js -var require_reg_exp_router = __commonJS({ - "../node_modules/hono/dist/cjs/router/reg-exp-router/index.js"(exports2, module2) { +// ../node_modules/hono/dist/cjs/index.js +var require_cjs = __commonJS({ + "../node_modules/hono/dist/cjs/index.js"(exports2, module2) { "use strict"; var __defProp2 = Object.defineProperty; var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor; @@ -4385,26 +4239,24 @@ var require_reg_exp_router = __commonJS({ return to; }; var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod); - var reg_exp_router_exports = {}; - __export(reg_exp_router_exports, { - PreparedRegExpRouter: () => import_prepared_router.PreparedRegExpRouter, - RegExpRouter: () => import_router.RegExpRouter, - buildInitParams: () => import_prepared_router.buildInitParams, - serializeInitParams: () => import_prepared_router.serializeInitParams + var src_exports = {}; + __export(src_exports, { + Hono: () => import_hono.Hono }); - module2.exports = __toCommonJS(reg_exp_router_exports); - var import_router = require_router2(); - var import_prepared_router = require_prepared_router(); + module2.exports = __toCommonJS(src_exports); + var import_hono = require_hono(); } }); -// ../node_modules/hono/dist/cjs/router/smart-router/router.js -var require_router3 = __commonJS({ - "../node_modules/hono/dist/cjs/router/smart-router/router.js"(exports2, module2) { +// ../node_modules/@hono/node-server/dist/index.js +var require_dist = __commonJS({ + "../node_modules/@hono/node-server/dist/index.js"(exports2, module2) { "use strict"; + var __create2 = Object.create; var __defProp2 = Object.defineProperty; var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor; var __getOwnPropNames2 = Object.getOwnPropertyNames; + var __getProtoOf2 = Object.getPrototypeOf; var __hasOwnProp2 = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) @@ -4418,464 +4270,656 @@ var require_router3 = __commonJS({ } return to; }; + var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2( + // If the importer is in node compatibility mode or this is not an ESM + // file that has been converted to a CommonJS file using a Babel- + // compatible transform (i.e. "__esModule" has not been set), then set + // "default" to the CommonJS "module.exports" for node compatibility. + isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target, + mod + )); var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod); - var router_exports = {}; - __export(router_exports, { - SmartRouter: () => SmartRouter2 + var src_exports = {}; + __export(src_exports, { + RequestError: () => RequestError, + createAdaptorServer: () => createAdaptorServer, + getRequestListener: () => getRequestListener, + serve: () => serve }); - module2.exports = __toCommonJS(router_exports); - var import_router = require_router(); - var SmartRouter2 = class { - name = "SmartRouter"; - #routers = []; - #routes = []; - constructor(init) { - this.#routers = init.routers; + module2.exports = __toCommonJS(src_exports); + var import_node_http = require("http"); + var import_node_http22 = require("http2"); + var import_node_http2 = require("http2"); + var import_node_stream = require("stream"); + var RequestError = class extends Error { + constructor(message, options) { + super(message, options); + this.name = "RequestError"; } - add(method, path, handler) { - if (!this.#routes) { - throw new Error(import_router.MESSAGE_MATCHER_IS_ALREADY_BUILT); - } - this.#routes.push([method, path, handler]); + }; + var toRequestError = (e) => { + if (e instanceof RequestError) { + return e; } - match(method, path) { - if (!this.#routes) { - throw new Error("Fatal error"); - } - const routers = this.#routers; - const routes = this.#routes; - const len = routers.length; - let i = 0; - let res; - for (; i < len; i++) { - const router = routers[i]; - try { - for (let i2 = 0, len2 = routes.length; i2 < len2; i2++) { - router.add(...routes[i2]); - } - res = router.match(method, path); - } catch (e) { - if (e instanceof import_router.UnsupportedPathError) { - continue; - } - throw e; - } - this.match = router.match.bind(router); - this.#routers = [router]; - this.#routes = void 0; - break; + return new RequestError(e.message, { cause: e }); + }; + var GlobalRequest = global.Request; + var Request2 = class extends GlobalRequest { + constructor(input, options) { + if (typeof input === "object" && getRequestCache in input) { + input = input[getRequestCache](); } - if (i === len) { - throw new Error("Fatal error"); + if (typeof options?.body?.getReader !== "undefined") { + ; + options.duplex ??= "half"; } - this.name = `SmartRouter + ${this.activeRouter.name}`; - return res; + super(input, options); } - get activeRouter() { - if (this.#routes || this.#routers.length !== 1) { - throw new Error("No active router has been determined yet."); - } - return this.#routers[0]; + }; + var newHeadersFromIncoming = (incoming) => { + const headerRecord = []; + const rawHeaders = incoming.rawHeaders; + for (let i = 0; i < rawHeaders.length; i += 2) { + const { [i]: key, [i + 1]: value } = rawHeaders; + if (key.charCodeAt(0) !== /*:*/ + 58) { + headerRecord.push([key, value]); + } } + return new Headers(headerRecord); }; - } -}); - -// ../node_modules/hono/dist/cjs/router/smart-router/index.js -var require_smart_router = __commonJS({ - "../node_modules/hono/dist/cjs/router/smart-router/index.js"(exports2, module2) { - "use strict"; - var __defProp2 = Object.defineProperty; - var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor; - var __getOwnPropNames2 = Object.getOwnPropertyNames; - var __hasOwnProp2 = Object.prototype.hasOwnProperty; - var __export = (target, all) => { - for (var name in all) - __defProp2(target, name, { get: all[name], enumerable: true }); + var wrapBodyStream = Symbol("wrapBodyStream"); + var newRequestFromIncoming = (method, url, headers, incoming, abortController) => { + const init = { + method, + headers, + signal: abortController.signal + }; + if (method === "TRACE") { + init.method = "GET"; + const req = new Request2(url, init); + Object.defineProperty(req, "method", { + get() { + return "TRACE"; + } + }); + return req; + } + if (!(method === "GET" || method === "HEAD")) { + if ("rawBody" in incoming && incoming.rawBody instanceof Buffer) { + init.body = new ReadableStream({ + start(controller) { + controller.enqueue(incoming.rawBody); + controller.close(); + } + }); + } else if (incoming[wrapBodyStream]) { + let reader; + init.body = new ReadableStream({ + async pull(controller) { + try { + reader ||= import_node_stream.Readable.toWeb(incoming).getReader(); + const { done, value } = await reader.read(); + if (done) { + controller.close(); + } else { + controller.enqueue(value); + } + } catch (error) { + controller.error(error); + } + } + }); + } else { + init.body = import_node_stream.Readable.toWeb(incoming); + } + } + return new Request2(url, init); }; - var __copyProps2 = (to, from, except, desc) => { - if (from && typeof from === "object" || typeof from === "function") { - for (let key of __getOwnPropNames2(from)) - if (!__hasOwnProp2.call(to, key) && key !== except) - __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable }); + var getRequestCache = Symbol("getRequestCache"); + var requestCache = Symbol("requestCache"); + var incomingKey = Symbol("incomingKey"); + var urlKey = Symbol("urlKey"); + var headersKey = Symbol("headersKey"); + var abortControllerKey = Symbol("abortControllerKey"); + var getAbortController = Symbol("getAbortController"); + var requestPrototype = { + get method() { + return this[incomingKey].method || "GET"; + }, + get url() { + return this[urlKey]; + }, + get headers() { + return this[headersKey] ||= newHeadersFromIncoming(this[incomingKey]); + }, + [getAbortController]() { + this[getRequestCache](); + return this[abortControllerKey]; + }, + [getRequestCache]() { + this[abortControllerKey] ||= new AbortController(); + return this[requestCache] ||= newRequestFromIncoming( + this.method, + this[urlKey], + this.headers, + this[incomingKey], + this[abortControllerKey] + ); } - return to; }; - var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod); - var smart_router_exports = {}; - __export(smart_router_exports, { - SmartRouter: () => import_router.SmartRouter + [ + "body", + "bodyUsed", + "cache", + "credentials", + "destination", + "integrity", + "mode", + "redirect", + "referrer", + "referrerPolicy", + "signal", + "keepalive" + ].forEach((k) => { + Object.defineProperty(requestPrototype, k, { + get() { + return this[getRequestCache]()[k]; + } + }); }); - module2.exports = __toCommonJS(smart_router_exports); - var import_router = require_router3(); - } -}); - -// ../node_modules/hono/dist/cjs/router/trie-router/node.js -var require_node2 = __commonJS({ - "../node_modules/hono/dist/cjs/router/trie-router/node.js"(exports2, module2) { - "use strict"; - var __defProp2 = Object.defineProperty; - var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor; - var __getOwnPropNames2 = Object.getOwnPropertyNames; - var __hasOwnProp2 = Object.prototype.hasOwnProperty; - var __export = (target, all) => { - for (var name in all) - __defProp2(target, name, { get: all[name], enumerable: true }); + ["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => { + Object.defineProperty(requestPrototype, k, { + value: function() { + return this[getRequestCache]()[k](); + } + }); + }); + Object.setPrototypeOf(requestPrototype, Request2.prototype); + var newRequest = (incoming, defaultHostname) => { + const req = Object.create(requestPrototype); + req[incomingKey] = incoming; + const incomingUrl = incoming.url || ""; + if (incomingUrl[0] !== "/" && // short-circuit for performance. most requests are relative URL. + (incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) { + if (incoming instanceof import_node_http2.Http2ServerRequest) { + throw new RequestError("Absolute URL for :path is not allowed in HTTP/2"); + } + try { + const url2 = new URL(incomingUrl); + req[urlKey] = url2.href; + } catch (e) { + throw new RequestError("Invalid absolute URL", { cause: e }); + } + return req; + } + const host = (incoming instanceof import_node_http2.Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname; + if (!host) { + throw new RequestError("Missing host header"); + } + let scheme; + if (incoming instanceof import_node_http2.Http2ServerRequest) { + scheme = incoming.scheme; + if (!(scheme === "http" || scheme === "https")) { + throw new RequestError("Unsupported scheme"); + } + } else { + scheme = incoming.socket && incoming.socket.encrypted ? "https" : "http"; + } + const url = new URL(`${scheme}://${host}${incomingUrl}`); + if (url.hostname.length !== host.length && url.hostname !== host.replace(/:\d+$/, "")) { + throw new RequestError("Invalid host header"); + } + req[urlKey] = url.href; + return req; + }; + var responseCache = Symbol("responseCache"); + var getResponseCache = Symbol("getResponseCache"); + var cacheKey = Symbol("cache"); + var GlobalResponse = global.Response; + var Response2 = class _Response { + #body; + #init; + [getResponseCache]() { + delete this[cacheKey]; + return this[responseCache] ||= new GlobalResponse(this.#body, this.#init); + } + constructor(body, init) { + let headers; + this.#body = body; + if (init instanceof _Response) { + const cachedGlobalResponse = init[responseCache]; + if (cachedGlobalResponse) { + this.#init = cachedGlobalResponse; + this[getResponseCache](); + return; + } else { + this.#init = init.#init; + headers = new Headers(init.#init.headers); + } + } else { + this.#init = init; + } + if (typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) { + headers ||= init?.headers || { "content-type": "text/plain; charset=UTF-8" }; + this[cacheKey] = [init?.status || 200, body, headers]; + } + } + get headers() { + const cache = this[cacheKey]; + if (cache) { + if (!(cache[2] instanceof Headers)) { + cache[2] = new Headers(cache[2]); + } + return cache[2]; + } + return this[getResponseCache]().headers; + } + get status() { + return this[cacheKey]?.[0] ?? this[getResponseCache]().status; + } + get ok() { + const status = this.status; + return status >= 200 && status < 300; + } + }; + ["body", "bodyUsed", "redirected", "statusText", "trailers", "type", "url"].forEach((k) => { + Object.defineProperty(Response2.prototype, k, { + get() { + return this[getResponseCache]()[k]; + } + }); + }); + ["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => { + Object.defineProperty(Response2.prototype, k, { + value: function() { + return this[getResponseCache]()[k](); + } + }); + }); + Object.setPrototypeOf(Response2, GlobalResponse); + Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype); + async function readWithoutBlocking(readPromise) { + return Promise.race([readPromise, Promise.resolve().then(() => Promise.resolve(void 0))]); + } + function writeFromReadableStreamDefaultReader(reader, writable, currentReadPromise) { + const cancel = (error) => { + reader.cancel(error).catch(() => { + }); + }; + writable.on("close", cancel); + writable.on("error", cancel); + (currentReadPromise ?? reader.read()).then(flow, handleStreamError); + return reader.closed.finally(() => { + writable.off("close", cancel); + writable.off("error", cancel); + }); + function handleStreamError(error) { + if (error) { + writable.destroy(error); + } + } + function onDrain() { + reader.read().then(flow, handleStreamError); + } + function flow({ done, value }) { + try { + if (done) { + writable.end(); + } else if (!writable.write(value)) { + writable.once("drain", onDrain); + } else { + return reader.read().then(flow, handleStreamError); + } + } catch (e) { + handleStreamError(e); + } + } + } + function writeFromReadableStream(stream, writable) { + if (stream.locked) { + throw new TypeError("ReadableStream is locked."); + } else if (writable.destroyed) { + return; + } + return writeFromReadableStreamDefaultReader(stream.getReader(), writable); + } + var buildOutgoingHttpHeaders = (headers) => { + const res = {}; + if (!(headers instanceof Headers)) { + headers = new Headers(headers ?? void 0); + } + const cookies = []; + for (const [k, v] of headers) { + if (k === "set-cookie") { + cookies.push(v); + } else { + res[k] = v; + } + } + if (cookies.length > 0) { + res["set-cookie"] = cookies; + } + res["content-type"] ??= "text/plain; charset=UTF-8"; + return res; + }; + var X_ALREADY_SENT = "x-hono-already-sent"; + var import_node_crypto = __toESM2(require("crypto")); + var webFetch = global.fetch; + if (typeof global.crypto === "undefined") { + global.crypto = import_node_crypto.default; + } + global.fetch = (info, init) => { + init = { + // Disable compression handling so people can return the result of a fetch + // directly in the loader without messing with the Content-Encoding header. + compress: false, + ...init + }; + return webFetch(info, init); + }; + var outgoingEnded = Symbol("outgoingEnded"); + var handleRequestError = () => new Response(null, { + status: 400 + }); + var handleFetchError = (e) => new Response(null, { + status: e instanceof Error && (e.name === "TimeoutError" || e.constructor.name === "TimeoutError") ? 504 : 500 + }); + var handleResponseError = (e, outgoing) => { + const err = e instanceof Error ? e : new Error("unknown error", { cause: e }); + if (err.code === "ERR_STREAM_PREMATURE_CLOSE") { + console.info("The user aborted a request."); + } else { + console.error(e); + if (!outgoing.headersSent) { + outgoing.writeHead(500, { "Content-Type": "text/plain" }); + } + outgoing.end(`Error: ${err.message}`); + outgoing.destroy(err); + } }; - var __copyProps2 = (to, from, except, desc) => { - if (from && typeof from === "object" || typeof from === "function") { - for (let key of __getOwnPropNames2(from)) - if (!__hasOwnProp2.call(to, key) && key !== except) - __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable }); + var flushHeaders = (outgoing) => { + if ("flushHeaders" in outgoing && outgoing.writable) { + outgoing.flushHeaders(); } - return to; }; - var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod); - var node_exports = {}; - __export(node_exports, { - Node: () => Node - }); - module2.exports = __toCommonJS(node_exports); - var import_router = require_router(); - var import_url = require_url(); - var emptyParams = /* @__PURE__ */ Object.create(null); - var Node = class _Node { - #methods; - #children; - #patterns; - #order = 0; - #params = emptyParams; - constructor(method, handler, children) { - this.#children = children || /* @__PURE__ */ Object.create(null); - this.#methods = []; - if (method && handler) { - const m = /* @__PURE__ */ Object.create(null); - m[method] = { handler, possibleKeys: [], score: 0 }; - this.#methods = [m]; - } - this.#patterns = []; + var responseViaCache = async (res, outgoing) => { + let [status, body, header] = res[cacheKey]; + if (header instanceof Headers) { + header = buildOutgoingHttpHeaders(header); } - insert(method, path, handler) { - this.#order = ++this.#order; - let curNode = this; - const parts = (0, import_url.splitRoutingPath)(path); - const possibleKeys = []; - for (let i = 0, len = parts.length; i < len; i++) { - const p = parts[i]; - const nextP = parts[i + 1]; - const pattern = (0, import_url.getPattern)(p, nextP); - const key = Array.isArray(pattern) ? pattern[0] : p; - if (key in curNode.#children) { - curNode = curNode.#children[key]; - if (pattern) { - possibleKeys.push(pattern[1]); + if (typeof body === "string") { + header["Content-Length"] = Buffer.byteLength(body); + } else if (body instanceof Uint8Array) { + header["Content-Length"] = body.byteLength; + } else if (body instanceof Blob) { + header["Content-Length"] = body.size; + } + outgoing.writeHead(status, header); + if (typeof body === "string" || body instanceof Uint8Array) { + outgoing.end(body); + } else if (body instanceof Blob) { + outgoing.end(new Uint8Array(await body.arrayBuffer())); + } else { + flushHeaders(outgoing); + await writeFromReadableStream(body, outgoing)?.catch( + (e) => handleResponseError(e, outgoing) + ); + } + ; + outgoing[outgoingEnded]?.(); + }; + var isPromise = (res) => typeof res.then === "function"; + var responseViaResponseObject = async (res, outgoing, options = {}) => { + if (isPromise(res)) { + if (options.errorHandler) { + try { + res = await res; + } catch (err) { + const errRes = await options.errorHandler(err); + if (!errRes) { + return; } - continue; - } - curNode.#children[key] = new _Node(); - if (pattern) { - curNode.#patterns.push(pattern); - possibleKeys.push(pattern[1]); + res = errRes; } - curNode = curNode.#children[key]; + } else { + res = await res.catch(handleFetchError); } - curNode.#methods.push({ - [method]: { - handler, - possibleKeys: possibleKeys.filter((v, i, a) => a.indexOf(v) === i), - score: this.#order - } - }); - return curNode; } - #getHandlerSets(node, method, nodeParams, params) { - const handlerSets = []; - for (let i = 0, len = node.#methods.length; i < len; i++) { - const m = node.#methods[i]; - const handlerSet = m[method] || m[import_router.METHOD_NAME_ALL]; - const processedSet = {}; - if (handlerSet !== void 0) { - handlerSet.params = /* @__PURE__ */ Object.create(null); - handlerSets.push(handlerSet); - if (nodeParams !== emptyParams || params && params !== emptyParams) { - for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) { - const key = handlerSet.possibleKeys[i2]; - const processed = processedSet[handlerSet.score]; - handlerSet.params[key] = params?.[key] && !processed ? params[key] : nodeParams[key] ?? params?.[key]; - processedSet[handlerSet.score] = true; + if (cacheKey in res) { + return responseViaCache(res, outgoing); + } + const resHeaderRecord = buildOutgoingHttpHeaders(res.headers); + if (res.body) { + const reader = res.body.getReader(); + const values = []; + let done = false; + let currentReadPromise = void 0; + if (resHeaderRecord["transfer-encoding"] !== "chunked") { + let maxReadCount = 2; + for (let i = 0; i < maxReadCount; i++) { + currentReadPromise ||= reader.read(); + const chunk = await readWithoutBlocking(currentReadPromise).catch((e) => { + console.error(e); + done = true; + }); + if (!chunk) { + if (i === 1) { + await new Promise((resolve) => setTimeout(resolve)); + maxReadCount = 3; + continue; } + break; + } + currentReadPromise = void 0; + if (chunk.value) { + values.push(chunk.value); + } + if (chunk.done) { + done = true; + break; } } + if (done && !("content-length" in resHeaderRecord)) { + resHeaderRecord["content-length"] = values.reduce((acc, value) => acc + value.length, 0); + } } - return handlerSets; + outgoing.writeHead(res.status, resHeaderRecord); + values.forEach((value) => { + ; + outgoing.write(value); + }); + if (done) { + outgoing.end(); + } else { + if (values.length === 0) { + flushHeaders(outgoing); + } + await writeFromReadableStreamDefaultReader(reader, outgoing, currentReadPromise); + } + } else if (resHeaderRecord[X_ALREADY_SENT]) { + } else { + outgoing.writeHead(res.status, resHeaderRecord); + outgoing.end(); } - search(method, path) { - const handlerSets = []; - this.#params = emptyParams; - const curNode = this; - let curNodes = [curNode]; - const parts = (0, import_url.splitPath)(path); - const curNodesQueue = []; - for (let i = 0, len = parts.length; i < len; i++) { - const part = parts[i]; - const isLast = i === len - 1; - const tempNodes = []; - for (let j = 0, len2 = curNodes.length; j < len2; j++) { - const node = curNodes[j]; - const nextNode = node.#children[part]; - if (nextNode) { - nextNode.#params = node.#params; - if (isLast) { - if (nextNode.#children["*"]) { - handlerSets.push( - ...this.#getHandlerSets(nextNode.#children["*"], method, node.#params) - ); - } - handlerSets.push(...this.#getHandlerSets(nextNode, method, node.#params)); - } else { - tempNodes.push(nextNode); - } - } - for (let k = 0, len3 = node.#patterns.length; k < len3; k++) { - const pattern = node.#patterns[k]; - const params = node.#params === emptyParams ? {} : { ...node.#params }; - if (pattern === "*") { - const astNode = node.#children["*"]; - if (astNode) { - handlerSets.push(...this.#getHandlerSets(astNode, method, node.#params)); - astNode.#params = params; - tempNodes.push(astNode); - } - continue; - } - const [key, name, matcher] = pattern; - if (!part && !(matcher instanceof RegExp)) { - continue; - } - const child = node.#children[key]; - const restPathString = parts.slice(i).join("/"); - if (matcher instanceof RegExp) { - const m = matcher.exec(restPathString); - if (m) { - params[name] = m[0]; - handlerSets.push(...this.#getHandlerSets(child, method, node.#params, params)); - if (Object.keys(child.#children).length) { - child.#params = params; - const componentCount = m[0].match(/\//)?.length ?? 0; - const targetCurNodes = curNodesQueue[componentCount] ||= []; - targetCurNodes.push(child); - } - continue; + ; + outgoing[outgoingEnded]?.(); + }; + var getRequestListener = (fetchCallback, options = {}) => { + const autoCleanupIncoming = options.autoCleanupIncoming ?? true; + if (options.overrideGlobalObjects !== false && global.Request !== Request2) { + Object.defineProperty(global, "Request", { + value: Request2 + }); + Object.defineProperty(global, "Response", { + value: Response2 + }); + } + return async (incoming, outgoing) => { + let res, req; + try { + req = newRequest(incoming, options.hostname); + let incomingEnded = !autoCleanupIncoming || incoming.method === "GET" || incoming.method === "HEAD"; + if (!incomingEnded) { + ; + incoming[wrapBodyStream] = true; + incoming.on("end", () => { + incomingEnded = true; + }); + if (incoming instanceof import_node_http22.Http2ServerRequest) { + ; + outgoing[outgoingEnded] = () => { + if (!incomingEnded) { + setTimeout(() => { + if (!incomingEnded) { + setTimeout(() => { + incoming.destroy(); + outgoing.destroy(); + }); + } + }); } + }; + } + } + outgoing.on("close", () => { + const abortController = req[abortControllerKey]; + if (abortController) { + if (incoming.errored) { + req[abortControllerKey].abort(incoming.errored.toString()); + } else if (!outgoing.writableFinished) { + req[abortControllerKey].abort("Client connection prematurely closed."); } - if (matcher === true || matcher.test(part)) { - params[name] = part; - if (isLast) { - handlerSets.push(...this.#getHandlerSets(child, method, params, node.#params)); - if (child.#children["*"]) { - handlerSets.push( - ...this.#getHandlerSets(child.#children["*"], method, params, node.#params) - ); - } - } else { - child.#params = params; - tempNodes.push(child); + } + if (!incomingEnded) { + setTimeout(() => { + if (!incomingEnded) { + setTimeout(() => { + incoming.destroy(); + }); } + }); + } + }); + res = fetchCallback(req, { incoming, outgoing }); + if (cacheKey in res) { + return responseViaCache(res, outgoing); + } + } catch (e) { + if (!res) { + if (options.errorHandler) { + res = await options.errorHandler(req ? e : toRequestError(e)); + if (!res) { + return; } + } else if (!req) { + res = handleRequestError(); + } else { + res = handleFetchError(e); } + } else { + return handleResponseError(e, outgoing); } - curNodes = tempNodes.concat(curNodesQueue.shift() ?? []); - } - if (handlerSets.length > 1) { - handlerSets.sort((a, b) => { - return a.score - b.score; - }); } - return [handlerSets.map(({ handler, params }) => [handler, params])]; - } - }; - } -}); - -// ../node_modules/hono/dist/cjs/router/trie-router/router.js -var require_router4 = __commonJS({ - "../node_modules/hono/dist/cjs/router/trie-router/router.js"(exports2, module2) { - "use strict"; - var __defProp2 = Object.defineProperty; - var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor; - var __getOwnPropNames2 = Object.getOwnPropertyNames; - var __hasOwnProp2 = Object.prototype.hasOwnProperty; - var __export = (target, all) => { - for (var name in all) - __defProp2(target, name, { get: all[name], enumerable: true }); - }; - var __copyProps2 = (to, from, except, desc) => { - if (from && typeof from === "object" || typeof from === "function") { - for (let key of __getOwnPropNames2(from)) - if (!__hasOwnProp2.call(to, key) && key !== except) - __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable }); - } - return to; - }; - var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod); - var router_exports = {}; - __export(router_exports, { - TrieRouter: () => TrieRouter2 - }); - module2.exports = __toCommonJS(router_exports); - var import_url = require_url(); - var import_node = require_node2(); - var TrieRouter2 = class { - name = "TrieRouter"; - #node; - constructor() { - this.#node = new import_node.Node(); - } - add(method, path, handler) { - const results = (0, import_url.checkOptionalParameter)(path); - if (results) { - for (let i = 0, len = results.length; i < len; i++) { - this.#node.insert(method, results[i], handler); - } - return; + try { + return await responseViaResponseObject(res, outgoing, options); + } catch (e) { + return handleResponseError(e, outgoing); } - this.#node.insert(method, path, handler); - } - match(method, path) { - return this.#node.search(method, path); - } + }; }; - } -}); - -// ../node_modules/hono/dist/cjs/router/trie-router/index.js -var require_trie_router = __commonJS({ - "../node_modules/hono/dist/cjs/router/trie-router/index.js"(exports2, module2) { - "use strict"; - var __defProp2 = Object.defineProperty; - var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor; - var __getOwnPropNames2 = Object.getOwnPropertyNames; - var __hasOwnProp2 = Object.prototype.hasOwnProperty; - var __export = (target, all) => { - for (var name in all) - __defProp2(target, name, { get: all[name], enumerable: true }); + var createAdaptorServer = (options) => { + const fetchCallback = options.fetch; + const requestListener = getRequestListener(fetchCallback, { + hostname: options.hostname, + overrideGlobalObjects: options.overrideGlobalObjects, + autoCleanupIncoming: options.autoCleanupIncoming + }); + const createServer = options.createServer || import_node_http.createServer; + const server = createServer(options.serverOptions || {}, requestListener); + return server; }; - var __copyProps2 = (to, from, except, desc) => { - if (from && typeof from === "object" || typeof from === "function") { - for (let key of __getOwnPropNames2(from)) - if (!__hasOwnProp2.call(to, key) && key !== except) - __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable }); - } - return to; + var serve = (options, listeningListener) => { + const server = createAdaptorServer(options); + server.listen(options?.port ?? 3e3, options.hostname, () => { + const serverInfo = server.address(); + listeningListener && listeningListener(serverInfo); + }); + return server; }; - var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod); - var trie_router_exports = {}; - __export(trie_router_exports, { - TrieRouter: () => import_router.TrieRouter - }); - module2.exports = __toCommonJS(trie_router_exports); - var import_router = require_router4(); } }); -// ../node_modules/hono/dist/cjs/hono.js -var require_hono = __commonJS({ - "../node_modules/hono/dist/cjs/hono.js"(exports2, module2) { +// ../node_modules/@emprespresso/pengueno/dist/server/hono/proxy.js +var require_proxy = __commonJS({ + "../node_modules/@emprespresso/pengueno/dist/server/hono/proxy.js"(exports2) { "use strict"; - var __defProp2 = Object.defineProperty; - var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor; - var __getOwnPropNames2 = Object.getOwnPropertyNames; - var __hasOwnProp2 = Object.prototype.hasOwnProperty; - var __export = (target, all) => { - for (var name in all) - __defProp2(target, name, { get: all[name], enumerable: true }); - }; - var __copyProps2 = (to, from, except, desc) => { - if (from && typeof from === "object" || typeof from === "function") { - for (let key of __getOwnPropNames2(from)) - if (!__hasOwnProp2.call(to, key) && key !== except) - __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable }); + var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) { + if (k2 === void 0) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { + return m[k]; + } }; } - return to; - }; - var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod); - var hono_exports = {}; - __export(hono_exports, { - Hono: () => Hono2 + Object.defineProperty(o, k2, desc); + } : function(o, m, k, k2) { + if (k2 === void 0) k2 = k; + o[k2] = m[k]; }); - module2.exports = __toCommonJS(hono_exports); - var import_hono_base = require_hono_base(); - var import_reg_exp_router = require_reg_exp_router(); - var import_smart_router = require_smart_router(); - var import_trie_router = require_trie_router(); - var Hono2 = class extends import_hono_base.HonoBase { - constructor(options = {}) { - super(options); - this.router = options.router ?? new import_smart_router.SmartRouter({ - routers: [new import_reg_exp_router.RegExpRouter(), new import_trie_router.TrieRouter()] - }); - } - }; - } -}); - -// ../node_modules/hono/dist/cjs/index.js -var require_cjs = __commonJS({ - "../node_modules/hono/dist/cjs/index.js"(exports2, module2) { - "use strict"; - var __defProp2 = Object.defineProperty; - var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor; - var __getOwnPropNames2 = Object.getOwnPropertyNames; - var __hasOwnProp2 = Object.prototype.hasOwnProperty; - var __export = (target, all) => { - for (var name in all) - __defProp2(target, name, { get: all[name], enumerable: true }); - }; - var __copyProps2 = (to, from, except, desc) => { - if (from && typeof from === "object" || typeof from === "function") { - for (let key of __getOwnPropNames2(from)) - if (!__hasOwnProp2.call(to, key) && key !== except) - __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable }); - } - return to; - }; - var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod); - var src_exports = {}; - __export(src_exports, { - Hono: () => import_hono.Hono + var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); + } : function(o, v) { + o["default"] = v; }); - module2.exports = __toCommonJS(src_exports); - var import_hono = require_hono(); - } -}); - -// node_modules/@emprespresso/pengueno/dist/server/hono/proxy.js -var require_proxy = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/server/hono/proxy.js"(exports2) { - "use strict"; + var __importStar = exports2 && exports2.__importStar || /* @__PURE__ */ function() { + var ownKeys = function(o) { + ownKeys = Object.getOwnPropertyNames || function(o2) { + var ar = []; + for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k; + return ar; + }; + return ownKeys(o); + }; + return function(mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) { + for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); + } + __setModuleDefault(result, mod); + return result; + }; + }(); Object.defineProperty(exports2, "__esModule", { value: true }); exports2.HonoProxy = void 0; var pengueno_1 = require_dist2(); - var node_server_1 = require_dist(); - var hono_1 = require_cjs(); var AppLifetimeMetric = pengueno_1.Metric.fromName("HonoAppLifetime").asResult(); var AppRequestMetric = pengueno_1.Metric.fromName("HonoAppRequest"); var HonoProxy = class { server; - app = pengueno_1.LogMetricTraceable.of(new hono_1.Hono()).flatMap(pengueno_1.TraceUtil.withTrace(`AppId = ${crypto.randomUUID()}`)).flatMap(pengueno_1.TraceUtil.withMetricTrace(AppLifetimeMetric)); + app; constructor(server) { this.server = server; } + async initializeApp() { + if (this.app) + return this.app; + const { Hono: Hono2 } = await Promise.resolve().then(() => __importStar(require_cjs())); + this.app = pengueno_1.LogMetricTraceable.of(new Hono2()).flatMap(pengueno_1.TraceUtil.withTrace(`AppId = ${crypto.randomUUID()}`)).flatMap(pengueno_1.TraceUtil.withMetricTrace(AppLifetimeMetric)); + return this.app; + } async serve(port, hostname) { - return this.app.map((tApp) => pengueno_1.Either.fromFailable(() => { - const app = tApp.get(); - app.all("*", async (c) => tApp.flatMap(pengueno_1.TraceUtil.withMetricTrace(AppRequestMetric)).move(c.req).flatMap((tRequest) => pengueno_1.PenguenoRequest.from(tRequest)).map((req) => this.server.serve(req)).map(pengueno_1.TraceUtil.promiseify((tResponse) => { + const { serve } = await Promise.resolve().then(() => __importStar(require_dist())); + const app = await this.initializeApp(); + return app.map((tApp) => pengueno_1.Either.fromFailable(() => { + const app2 = tApp.get(); + app2.all("*", async (c) => tApp.flatMap(pengueno_1.TraceUtil.withMetricTrace(AppRequestMetric)).move(c.req).flatMap((tRequest) => pengueno_1.PenguenoRequest.from(tRequest)).map((req) => this.server.serve(req)).map(pengueno_1.TraceUtil.promiseify((tResponse) => { tResponse.trace.trace(AppRequestMetric.count.withValue(1)); return new Response(tResponse.get().body(), tResponse.get()); })).get()); - return (0, node_server_1.serve)({ - fetch: (_r) => app.fetch(_r), + return serve({ + fetch: (_r) => app2.fetch(_r), port, hostname }); @@ -4886,9 +4930,9 @@ var require_proxy = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/server/hono/index.js +// ../node_modules/@emprespresso/pengueno/dist/server/hono/index.js var require_hono2 = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/server/hono/index.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/server/hono/index.js"(exports2) { "use strict"; var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) { if (k2 === void 0) k2 = k; @@ -4911,9 +4955,9 @@ var require_hono2 = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/server/index.js +// ../node_modules/@emprespresso/pengueno/dist/server/index.js var require_server = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/server/index.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/server/index.js"(exports2) { "use strict"; var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) { if (k2 === void 0) k2 = k; @@ -4941,9 +4985,9 @@ var require_server = __commonJS({ } }); -// node_modules/@emprespresso/pengueno/dist/index.js +// ../node_modules/@emprespresso/pengueno/dist/index.js var require_dist2 = __commonJS({ - "node_modules/@emprespresso/pengueno/dist/index.js"(exports2) { + "../node_modules/@emprespresso/pengueno/dist/index.js"(exports2) { "use strict"; var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) { if (k2 === void 0) k2 = k; @@ -4970,8 +5014,14 @@ var require_dist2 = __commonJS({ } }); -// node_modules/@emprespresso/ci_model/dist/job/index.js +// ../model/dist/job/index.js var import_pengueno = __toESM(require_dist2(), 1); + +// ../model/dist/pipeline/index.js +var import_pengueno6 = __toESM(require_dist2(), 1); + +// ../model/job/index.ts +var import_pengueno2 = __toESM(require_dist2(), 1); var JobTypes = [ "fetch_code", "ci_pipeline", @@ -4982,12 +5032,15 @@ var JobTypes = [ "coolify_webhook.js" ]; var isJobType = (j) => typeof j === "string" && JobTypes.includes(j); -var isJob = (j) => !!((0, import_pengueno.isObject)(j) && "arguments" in j && (0, import_pengueno.isObject)(j.arguments) && "type" in j && isJobType(j.type) && j); +var isJob = (j) => !!((0, import_pengueno2.isObject)(j) && "arguments" in j && (0, import_pengueno2.isObject)(j.arguments) && "type" in j && isJobType(j.type) && j); -// node_modules/@emprespresso/ci_model/dist/pipeline/index.js +// ../model/pipeline/index.ts +var import_pengueno4 = __toESM(require_dist2(), 1); + +// ../model/pipeline/impl.ts var import_pengueno3 = __toESM(require_dist2(), 1); -// node_modules/@emprespresso/ci_model/dist/pipeline/builder.js +// ../model/dist/pipeline/builder.js var BasePipelineBuilder = class { stages = []; addStage(stage) { @@ -4995,7 +5048,7 @@ var BasePipelineBuilder = class { return this; } build() { - return new PipelineImpl(this.stages); + return new PipelineImpl2(this.stages); } }; var DefaultGitHookPipelineBuilder = class extends BasePipelineBuilder { @@ -5027,9 +5080,9 @@ var DefaultGitHookPipelineBuilder = class extends BasePipelineBuilder { } }; -// node_modules/@emprespresso/ci_model/dist/pipeline/impl.js -var import_pengueno2 = __toESM(require_dist2(), 1); -var PipelineImpl = class _PipelineImpl { +// ../model/dist/pipeline/impl.js +var import_pengueno5 = __toESM(require_dist2(), 1); +var PipelineImpl2 = class _PipelineImpl { serialJobs; constructor(serialJobs) { this.serialJobs = serialJobs; @@ -5038,13 +5091,13 @@ var PipelineImpl = class _PipelineImpl { return JSON.stringify({ serialJobs: this.serialJobs }); } static from(s) { - return import_pengueno2.Either.fromFailable(() => JSON.parse(s)).flatMap((eitherPipelineJson) => isPipeline(eitherPipelineJson) ? import_pengueno2.Either.right(eitherPipelineJson) : import_pengueno2.Either.left(new Error("oh noes D: its a bad pipewine :(("))).mapRight((pipeline) => new _PipelineImpl(pipeline.serialJobs)); + return import_pengueno5.Either.fromFailable(() => JSON.parse(s)).flatMap((eitherPipelineJson) => isPipeline2(eitherPipelineJson) ? import_pengueno5.Either.right(eitherPipelineJson) : import_pengueno5.Either.left(new Error("oh noes D: its a bad pipewine :(("))).mapRight((pipeline) => new _PipelineImpl(pipeline.serialJobs)); } }; -// node_modules/@emprespresso/ci_model/dist/pipeline/index.js -var isPipelineStage = (t) => (0, import_pengueno3.isObject)(t) && "parallelJobs" in t && Array.isArray(t.parallelJobs) && t.parallelJobs.every((j) => isJob(j)); -var isPipeline = (t) => (0, import_pengueno3.isObject)(t) && "serialJobs" in t && Array.isArray(t.serialJobs) && t.serialJobs.every((p) => isPipelineStage(p)); +// ../model/dist/pipeline/index.js +var isPipelineStage = (t) => (0, import_pengueno6.isObject)(t) && "parallelJobs" in t && Array.isArray(t.parallelJobs) && t.parallelJobs.every((j) => isJob(j)); +var isPipeline2 = (t) => (0, import_pengueno6.isObject)(t) && "serialJobs" in t && Array.isArray(t.serialJobs) && t.serialJobs.every((p) => isPipelineStage(p)); // dist/ci.js var import_path = require("path"); diff --git a/.ci/package-lock.json b/.ci/package-lock.json index 5e5dc79..a57dcec 100644 --- a/.ci/package-lock.json +++ b/.ci/package-lock.json @@ -5,29 +5,27 @@ "packages": { "": { "dependencies": { - "@emprespresso/ci_model": "^0.2.0" + "@emprespresso/ci_model": "^0.3.0" }, "devDependencies": { + "@types/node": "^24.10.1", "esbuild": "0.25.5" } }, - "node_modules/@emprespresso/ci_model": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/@emprespresso/ci_model/-/ci_model-0.2.0.tgz", - "integrity": "sha512-yFr0WdAPxf0jhLwdjUUv8KikXVRuT7n81vWt+Km8w6FeKqFtf6h8+ZSIm301X/lEB9x77+CnAN+29NkpyQbPHA==", + "../model": { + "name": "@emprespresso/ci_model", + "version": "0.3.0", "dependencies": { - "@emprespresso/pengueno": "^0.0.13" + "@emprespresso/pengueno": "^0.0.17" + }, + "devDependencies": { + "@types/node": "^24.10.1", + "typescript": "^5.9.3" } }, - "node_modules/@emprespresso/pengueno": { - "version": "0.0.13", - "resolved": "https://registry.npmjs.org/@emprespresso/pengueno/-/pengueno-0.0.13.tgz", - "integrity": "sha512-eEMwbuF1hJsWNmVp8I5zCmWnIVlgTV+9w6wrkfcX6SMvEliotZ4ROZ/njndbFqzLRSID/+RptfYXLGYw2ZbswQ==", - "license": "MIT", - "engines": { - "node": ">=22.16.0", - "npm": ">=10.0.0" - } + "node_modules/@emprespresso/ci_model": { + "resolved": "../model", + "link": true }, "node_modules/@esbuild/linux-x64": { "version": "0.25.5", @@ -44,6 +42,16 @@ "node": ">=18" } }, + "node_modules/@types/node": { + "version": "24.10.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-24.10.1.tgz", + "integrity": "sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~7.16.0" + } + }, "node_modules/esbuild": { "version": "0.25.5", "dev": true, @@ -82,6 +90,13 @@ "@esbuild/win32-ia32": "0.25.5", "@esbuild/win32-x64": "0.25.5" } + }, + "node_modules/undici-types": { + "version": "7.16.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.16.0.tgz", + "integrity": "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==", + "dev": true, + "license": "MIT" } } } diff --git a/.ci/package.json b/.ci/package.json index 181970e..e8b3c72 100644 --- a/.ci/package.json +++ b/.ci/package.json @@ -4,9 +4,10 @@ "clean": "rm -rf dist ci.cjs" }, "dependencies": { - "@emprespresso/ci_model": "^0.2.0" + "@emprespresso/ci_model": "^0.3.0" }, "devDependencies": { + "@types/node": "^24.10.1", "esbuild": "0.25.5" }, "files": [ -- cgit v1.2.3-70-g09d2