@zuplo/cli 7.15.4 → 7.15.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/node_modules/@hono/node-server/dist/serve-static.cjs +1 -1
  2. package/node_modules/@hono/node-server/dist/serve-static.mjs +1 -1
  3. package/node_modules/@hono/node-server/package.json +1 -1
  4. package/node_modules/@inquirer/ansi/package.json +4 -4
  5. package/node_modules/@inquirer/checkbox/package.json +8 -8
  6. package/node_modules/@inquirer/confirm/package.json +6 -6
  7. package/node_modules/@inquirer/core/dist/lib/make-theme.js +3 -0
  8. package/node_modules/@inquirer/core/package.json +8 -8
  9. package/node_modules/@inquirer/editor/package.json +7 -7
  10. package/node_modules/@inquirer/expand/package.json +6 -6
  11. package/node_modules/@inquirer/external-editor/package.json +4 -4
  12. package/node_modules/@inquirer/figures/package.json +4 -4
  13. package/node_modules/@inquirer/input/package.json +6 -6
  14. package/node_modules/@inquirer/number/dist/index.js +7 -2
  15. package/node_modules/@inquirer/number/package.json +6 -6
  16. package/node_modules/@inquirer/password/package.json +7 -7
  17. package/node_modules/@inquirer/rawlist/dist/index.js +3 -3
  18. package/node_modules/@inquirer/rawlist/package.json +6 -6
  19. package/node_modules/@inquirer/search/package.json +7 -7
  20. package/node_modules/@inquirer/select/dist/index.js +5 -1
  21. package/node_modules/@inquirer/select/package.json +8 -8
  22. package/node_modules/@inquirer/type/package.json +4 -4
  23. package/node_modules/@posthog/types/dist/feature-flags.d.ts +2 -0
  24. package/node_modules/@posthog/types/dist/feature-flags.d.ts.map +1 -1
  25. package/node_modules/@posthog/types/dist/posthog-config.d.ts +3 -0
  26. package/node_modules/@posthog/types/dist/posthog-config.d.ts.map +1 -1
  27. package/node_modules/@posthog/types/package.json +1 -1
  28. package/node_modules/@posthog/types/src/feature-flags.ts +2 -0
  29. package/node_modules/@posthog/types/src/posthog-config.ts +3 -0
  30. package/node_modules/@zuplo/core/package.json +1 -1
  31. package/node_modules/@zuplo/graphql/package.json +1 -1
  32. package/node_modules/@zuplo/openapi-tools/package.json +1 -1
  33. package/node_modules/@zuplo/otel/package.json +1 -1
  34. package/node_modules/@zuplo/runtime/out/esm/{chunk-OE2WMJXK.js → chunk-KC64BFKL.js} +84 -84
  35. package/node_modules/@zuplo/runtime/out/esm/chunk-KC64BFKL.js.map +1 -0
  36. package/node_modules/@zuplo/runtime/out/esm/index.js +1 -1
  37. package/node_modules/@zuplo/runtime/out/esm/mcp-gateway/index.js +1 -1
  38. package/node_modules/@zuplo/runtime/out/esm/mocks/index.js +1 -1
  39. package/node_modules/@zuplo/runtime/package.json +1 -1
  40. package/node_modules/hono/dist/cjs/hono-base.js +7 -2
  41. package/node_modules/hono/dist/cjs/middleware/body-limit/index.js +9 -10
  42. package/node_modules/hono/dist/cjs/middleware/method-not-allowed/index.js +1 -1
  43. package/node_modules/hono/dist/cjs/middleware/mount/index.js +3 -2
  44. package/node_modules/hono/dist/cjs/middleware/serve-static/index.js +1 -1
  45. package/node_modules/hono/dist/cjs/utils/mount.js +18 -2
  46. package/node_modules/hono/dist/cjs/utils/url.js +8 -11
  47. package/node_modules/hono/dist/cjs/validator/validator.js +5 -5
  48. package/node_modules/hono/dist/hono-base.js +7 -2
  49. package/node_modules/hono/dist/middleware/body-limit/index.js +9 -10
  50. package/node_modules/hono/dist/middleware/language/language.js +1 -1
  51. package/node_modules/hono/dist/middleware/method-not-allowed/index.js +1 -1
  52. package/node_modules/hono/dist/middleware/mount/index.js +3 -2
  53. package/node_modules/hono/dist/middleware/serve-static/index.js +1 -1
  54. package/node_modules/hono/dist/types/hono-base.d.ts +2 -0
  55. package/node_modules/hono/dist/types/middleware/mount/index.d.ts +2 -1
  56. package/node_modules/hono/dist/types/utils/url.d.ts +0 -1
  57. package/node_modules/hono/dist/utils/mount.js +19 -3
  58. package/node_modules/hono/dist/utils/url.js +9 -11
  59. package/node_modules/hono/dist/validator/validator.js +5 -5
  60. package/node_modules/hono/package.json +1 -1
  61. package/node_modules/mute-stream/package.json +13 -20
  62. package/package.json +11 -11
  63. package/node_modules/@zuplo/runtime/out/esm/chunk-OE2WMJXK.js.map +0 -1
  64. /package/node_modules/@zuplo/runtime/out/esm/{chunk-OE2WMJXK.js.LEGAL.txt → chunk-KC64BFKL.js.LEGAL.txt} +0 -0
@@ -9,5 +9,5 @@
9
9
  * See https://zuplo.com/legal/eula for more information.
10
10
  */
11
11
 
12
- import{P as p,V as c,Z as u}from"../chunk-OE2WMJXK.js";import"../chunk-BH4DKEES.js";import{a as d}from"../chunk-T2WKOG7J.js";import"../chunk-R6UNMRUU.js";import"../chunk-AJ3MMWJS.js";import"../chunk-5JGLAPFA.js";import{Y as i}from"../chunk-G42UYZ6V.js";import{a as o}from"../chunk-VXPFMOL5.js";function w(l={request:new Request("https://api.example.com")}){let e=[];function t(s){e.push(Promise.resolve(s))}return o(t,"waitUntil"),{context:new a({event:{waitUntil:t},route:l.route,originalRequest:l.request}),invokeResponse:o(async()=>{await Promise.all(e)},"invokeResponse")}}o(w,"createMockContext");var g={path:"/",methods:["GET"],handler:{module:{},export:"default"},raw:o(()=>({}),"raw")},a=class extends EventTarget{static{o(this,"MockZuploContext")}#e;#t;contextId;requestId;log;route;custom;incomingRequestProperties;parentContext;analyticsContext;constructor({event:e,route:t=g,parentContext:n,originalRequest:r}){super(),this.requestId=crypto.randomUUID(),this.contextId=crypto.randomUUID(),this.log={info:i.console.info,log:i.console.log,debug:i.console.debug,warn:i.console.warn,error:i.console.error,setLogProperties:o(()=>{},"setLogProperties")},this.custom={},this.route=t,this.incomingRequestProperties={ip:"203.0.113.7",asn:1234,asOrganization:"ORGANIZATION",city:"Seattle",region:"Washington",regionCode:"WA",colo:"SEA",continent:"NA",country:"US",postalCode:"98004",metroCode:"SEA",latitude:void 0,longitude:void 0,timezone:void 0,httpProtocol:void 0,clientCert:void 0,clientMtlsVerificationStatus:void 0,clientMtlsVerificationReason:void 0,clientCertFingerprintSha256:void 0,clientCertNotBefore:void 0,clientCertNotAfter:void 0,clientCertIssuerDn:void 0,clientCertSubjectDn:void 0},this.parentContext=n,this.#e=e,this.#t=r,this.analyticsContext=new c(this.requestId)}waitUntil(e){this.#e.waitUntil(e)}invokeInboundPolicy(e,t){throw new Error("Not implemented")}invokeOutboundPolicy(e,t,n){throw new Error("Not implemented")}invokeRoute(e,t){throw new Error("Not implemented")}addResponseSendingHook(e){throw new Error("Not implemented")}addResponseSendingFinalHook(e){throw new Error("Not implemented")}addPreRequestHandler(e,t){let n;try{n=u.getContextExtensions(this)}catch{n=u.initialize(this,new d(this.#t??new Request("https://api.example.com")))}n.preRequestPhase??="active",p(this,n,e,t)}get preRequestHandlers(){let e;try{e=u.getContextExtensions(this)}catch{return[]}return(e.preRequestState?.entries??[]).map(t=>({policyName:t.policyName,name:t.name}))}addEventListener(e,t,n){let r=o(s=>{try{typeof t=="function"?t(s):t.handleEvent(s)}catch(m){throw this.log.error(`Error invoking event ${e}. See following logs for details.`),m}},"wrapped");super.addEventListener(e,r,n)}};export{a as MockZuploContext,w as createMockContext};
12
+ import{P as p,V as c,Z as u}from"../chunk-KC64BFKL.js";import"../chunk-BH4DKEES.js";import{a as d}from"../chunk-T2WKOG7J.js";import"../chunk-R6UNMRUU.js";import"../chunk-AJ3MMWJS.js";import"../chunk-5JGLAPFA.js";import{Y as i}from"../chunk-G42UYZ6V.js";import{a as o}from"../chunk-VXPFMOL5.js";function w(l={request:new Request("https://api.example.com")}){let e=[];function t(s){e.push(Promise.resolve(s))}return o(t,"waitUntil"),{context:new a({event:{waitUntil:t},route:l.route,originalRequest:l.request}),invokeResponse:o(async()=>{await Promise.all(e)},"invokeResponse")}}o(w,"createMockContext");var g={path:"/",methods:["GET"],handler:{module:{},export:"default"},raw:o(()=>({}),"raw")},a=class extends EventTarget{static{o(this,"MockZuploContext")}#e;#t;contextId;requestId;log;route;custom;incomingRequestProperties;parentContext;analyticsContext;constructor({event:e,route:t=g,parentContext:n,originalRequest:r}){super(),this.requestId=crypto.randomUUID(),this.contextId=crypto.randomUUID(),this.log={info:i.console.info,log:i.console.log,debug:i.console.debug,warn:i.console.warn,error:i.console.error,setLogProperties:o(()=>{},"setLogProperties")},this.custom={},this.route=t,this.incomingRequestProperties={ip:"203.0.113.7",asn:1234,asOrganization:"ORGANIZATION",city:"Seattle",region:"Washington",regionCode:"WA",colo:"SEA",continent:"NA",country:"US",postalCode:"98004",metroCode:"SEA",latitude:void 0,longitude:void 0,timezone:void 0,httpProtocol:void 0,clientCert:void 0,clientMtlsVerificationStatus:void 0,clientMtlsVerificationReason:void 0,clientCertFingerprintSha256:void 0,clientCertNotBefore:void 0,clientCertNotAfter:void 0,clientCertIssuerDn:void 0,clientCertSubjectDn:void 0},this.parentContext=n,this.#e=e,this.#t=r,this.analyticsContext=new c(this.requestId)}waitUntil(e){this.#e.waitUntil(e)}invokeInboundPolicy(e,t){throw new Error("Not implemented")}invokeOutboundPolicy(e,t,n){throw new Error("Not implemented")}invokeRoute(e,t){throw new Error("Not implemented")}addResponseSendingHook(e){throw new Error("Not implemented")}addResponseSendingFinalHook(e){throw new Error("Not implemented")}addPreRequestHandler(e,t){let n;try{n=u.getContextExtensions(this)}catch{n=u.initialize(this,new d(this.#t??new Request("https://api.example.com")))}n.preRequestPhase??="active",p(this,n,e,t)}get preRequestHandlers(){let e;try{e=u.getContextExtensions(this)}catch{return[]}return(e.preRequestState?.entries??[]).map(t=>({policyName:t.policyName,name:t.name}))}addEventListener(e,t,n){let r=o(s=>{try{typeof t=="function"?t(s):t.handleEvent(s)}catch(m){throw this.log.error(`Error invoking event ${e}. See following logs for details.`),m}},"wrapped");super.addEventListener(e,r,n)}};export{a as MockZuploContext,w as createMockContext};
13
13
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zuplo/runtime",
3
3
  "type": "module",
4
- "version": "7.15.4",
4
+ "version": "7.15.6",
5
5
  "repository": "https://github.com/zuplo/zuplo",
6
6
  "author": "Zuplo, Inc.",
7
7
  "exports": {
@@ -2,6 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_compose = require("./compose.js");
3
3
  const require_utils_url = require("./utils/url.js");
4
4
  const require_context = require("./context.js");
5
+ const require_helper_route_index = require("./helper/route/index.js");
5
6
  const require_router = require("./router.js");
6
7
  const require_utils_constants = require("./utils/constants.js");
7
8
  const require_utils_mount = require("./utils/mount.js");
@@ -185,6 +186,8 @@ var Hono = class Hono {
185
186
  * @param {Function} applicationHandler - other Request Handler
186
187
  * @param {MountOptions} [options] - options of `.mount()`
187
188
  * @returns {Hono} mounted Hono instance
189
+ * @throws {Error} If automatic request rewriting encounters duplicate path parameter names or an optional regular expression parameter.
190
+ * @throws {HTTPException} With status 400 if automatic request rewriting cannot safely preserve the routed path.
188
191
  *
189
192
  * @example
190
193
  * ```ts
@@ -229,8 +232,10 @@ var Hono = class Hono {
229
232
  } catch {}
230
233
  return [c.env, executionContext];
231
234
  };
232
- const mergedPath = require_utils_url.mergePath(this._basePath, path);
233
- const defaultReplaceRequest = (c) => require_utils_mount.createMountedRequest(c, mergedPath.replace(/\/$/, ""), require_utils_url.mergePath(mergedPath, "*"));
235
+ const defaultReplaceRequest = (c) => {
236
+ const mountedRoutePath = require_helper_route_index.routePath(c);
237
+ return require_utils_mount.createMountedRequest(c, mountedRoutePath.replace(/\/?\*$/, ""), mountedRoutePath);
238
+ };
234
239
  const handler = async (c, next) => {
235
240
  const res = await applicationHandler(replaceRequest ? replaceRequest(c.req.raw) : defaultReplaceRequest(c), ...getOptions(c));
236
241
  if (res) return res;
@@ -45,23 +45,22 @@ const bodyLimit = (options) => {
45
45
  const hasTransferEncoding = c.req.raw.headers.has("transfer-encoding");
46
46
  if (c.req.raw.headers.has("content-length") && !hasTransferEncoding) return parseInt(c.req.raw.headers.get("content-length") || "0", 10) > maxSize ? onError(c) : next();
47
47
  let size = 0;
48
- const chunks = [];
48
+ let buffer = /* @__PURE__ */ new Uint8Array(0);
49
49
  const rawReader = c.req.raw.body.getReader();
50
50
  for (;;) {
51
51
  const { done, value } = await rawReader.read();
52
52
  if (done) break;
53
+ const offset = size;
53
54
  size += value.length;
54
55
  if (size > maxSize) return onError(c);
55
- chunks.push(value);
56
+ if (size > buffer.length) {
57
+ const grown = new Uint8Array(Math.min(maxSize, Math.max(size, buffer.length * 2)));
58
+ grown.set(buffer.subarray(0, offset));
59
+ buffer = grown;
60
+ }
61
+ buffer.set(value, offset);
56
62
  }
57
- const requestInit = {
58
- body: new ReadableStream({ start(controller) {
59
- for (const chunk of chunks) controller.enqueue(chunk);
60
- controller.close();
61
- } }),
62
- duplex: "half"
63
- };
64
- c.req.raw = new Request(c.req.raw, requestInit);
63
+ c.req.raw = new Request(c.req.raw, { body: buffer.subarray(0, size) });
65
64
  return next();
66
65
  };
67
66
  };
@@ -1,8 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_helper_route_index = require("../../helper/route/index.js");
2
3
  require("../../router.js");
3
4
  const require_router_trie_router_router = require("../../router/trie-router/router.js");
4
5
  require("../../router/trie-router/index.js");
5
- const require_helper_route_index = require("../../helper/route/index.js");
6
6
  //#region src/middleware/method-not-allowed/index.ts
7
7
  /**
8
8
  * Method Not Allowed Middleware for Hono.
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_utils_mount = require("../../utils/mount.js");
3
2
  const require_helper_route_index = require("../../helper/route/index.js");
3
+ const require_utils_mount = require("../../utils/mount.js");
4
4
  //#region src/middleware/mount/index.ts
5
5
  const defaultReplaceRequest = (c) => {
6
6
  const path = require_helper_route_index.routePath(c);
@@ -21,7 +21,8 @@ const defaultGetOptions = (c) => {
21
21
  * @param {Function} applicationHandler - other Request Handler
22
22
  * @param {MountOptions} [options] - options of `mount()`
23
23
  * @returns {MiddlewareHandler} handler to register with `app.all()`
24
- * @throws {Error} If the route ends with a wildcard inside a segment (e.g. `/assets*`), or automatic request rewriting encounters duplicate path parameter names.
24
+ * @throws {Error} If the route ends with a wildcard inside a segment (e.g. `/assets*`), or automatic request rewriting encounters duplicate path parameter names or an optional regular expression parameter.
25
+ * @throws {HTTPException} With status 400 if automatic request rewriting cannot safely preserve the routed path.
25
26
  *
26
27
  * @example
27
28
  * ```ts
@@ -25,8 +25,8 @@ const serveStatic = (options) => {
25
25
  let filename;
26
26
  if (options.path) filename = options.path;
27
27
  else try {
28
- if (!options.allowPercentInPath && c.req.path.includes("%")) throw new Error();
29
28
  filename = require_utils_url.tryDecodeURI(c.req.path);
29
+ if (c.req.path.includes("%") && (!options.allowPercentInPath || filename !== c.req.path.replace(/%25/g, "%"))) throw new Error();
30
30
  if (/(?:^|[\/\\])\.{1,2}(?:$|[\/\\])|[\/\\]{2,}|\\/.test(filename)) throw new Error();
31
31
  } catch {
32
32
  await options.onNotFound?.(c.req.path, c);
@@ -1,7 +1,13 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_http_exception = require("../http-exception.js");
2
3
  const require_request_constants = require("../request/constants.js");
3
4
  const require_utils_url = require("./url.js");
4
5
  //#region src/utils/mount.ts
6
+ const countTrailingSlashes = (path) => {
7
+ let index = path.length;
8
+ while (index > 0 && path.charCodeAt(index - 1) === 47) index--;
9
+ return path.length - index;
10
+ };
5
11
  const getPathPrefixLength = (c, pathPrefix, routePath) => {
6
12
  if (!/[:*]/.test(pathPrefix)) return pathPrefix.length;
7
13
  const path = c.req.path;
@@ -9,6 +15,7 @@ const getPathPrefixLength = (c, pathPrefix, routePath) => {
9
15
  const paramNames = /* @__PURE__ */ new Set();
10
16
  let length = 0;
11
17
  for (const part of require_utils_url.splitRoutingPath(pathPrefix)) {
18
+ if (part[0] === ":" && part.endsWith("}?")) throw new Error(`mount(): Optional regular expression parameters are not supported in "${routePath}".`);
12
19
  const pattern = require_utils_url.getPattern(part);
13
20
  if (pattern && pattern !== "*") {
14
21
  const name = pattern[1];
@@ -27,8 +34,17 @@ const getPathPrefixLength = (c, pathPrefix, routePath) => {
27
34
  };
28
35
  const createMountedRequest = (c, pathPrefix, routePath) => {
29
36
  if (/[^/]\*$/.test(routePath)) throw new Error(`mount(): Wildcard must follow "/" in "${routePath}".`);
30
- const url = new URL(c.req.raw.url);
31
- url.pathname = require_utils_url.stripPathPrefix(url.pathname, c.req.path, getPathPrefixLength(c, pathPrefix, routePath));
37
+ const prefixLength = getPathPrefixLength(c, pathPrefix, routePath);
38
+ const path = c.req.path.slice(prefixLength) || "/";
39
+ if (prefixLength > c.req.path.length || path[0] !== "/" || /\/(?:\.|%2e){1,2}(?:\/|$)/i.test(path)) throw new require_http_exception.HTTPException(400, { message: "Invalid mounted path" });
40
+ const rawUrl = c.req.raw.url;
41
+ if (/^[^/?#]*\/\/[^/?#\\]*[?#\\]/.test(rawUrl)) throw new require_http_exception.HTTPException(400, { message: "Invalid mounted path" });
42
+ const rawPathEnd = rawUrl.search(/[?#]/);
43
+ const rawTrailingSlashes = countTrailingSlashes(rawPathEnd === -1 ? rawUrl : rawUrl.slice(0, rawPathEnd));
44
+ if (rawTrailingSlashes > 1 && countTrailingSlashes(c.req.path) === rawTrailingSlashes - 1) throw new require_http_exception.HTTPException(400, { message: "Invalid mounted path" });
45
+ const url = new URL(rawUrl);
46
+ url.pathname = path.replace(/[\\\t\n\r]/g, encodeURIComponent);
47
+ if (path.includes("%")) {}
32
48
  return new Request(url, c.req.raw);
33
49
  };
34
50
  //#endregion
@@ -81,6 +81,7 @@ const tryDecode = (str, decoder) => {
81
81
  * tryDecodeURI('Hello%20World/%A4%A2') // 'Hello World/%A4%A2'
82
82
  */
83
83
  const tryDecodeURI = (str) => tryDecode(str, decodeURI);
84
+ const decodeURIWithPreservedPercent = (value) => decodeURI(value.includes("%25") ? value.replace(/%25/g, "%2525") : value);
84
85
  const getPath = (request) => {
85
86
  const url = request.url;
86
87
  const start = url.indexOf("/", url.indexOf(":") + 4);
@@ -92,7 +93,13 @@ const getPath = (request) => {
92
93
  const hashIndex = url.indexOf("#", i);
93
94
  const end = queryIndex === -1 ? hashIndex === -1 ? void 0 : hashIndex : hashIndex === -1 ? queryIndex : Math.min(queryIndex, hashIndex);
94
95
  const path = url.slice(start, end);
95
- return tryDecodeURI(path.includes("%25") ? path.replace(/%25/g, "%2525") : path);
96
+ const decoded = tryDecode(path, decodeURIWithPreservedPercent);
97
+ if (/%(?![0-9A-Fa-f]{2})/.test(path)) {
98
+ const rewritten = new URL("http://localhost");
99
+ rewritten.pathname = decoded.replace(/[\\\t\n\r]/g, encodeURIComponent);
100
+ if (tryDecode(rewritten.pathname, decodeURIWithPreservedPercent) !== decoded) return tryDecode(path.replace(/%(?![0-9A-Fa-f]{2})/g, "%25"), decodeURIWithPreservedPercent);
101
+ }
102
+ return decoded;
96
103
  } else if (charCode === 63 || charCode === 35) break;
97
104
  }
98
105
  return url.slice(start, i);
@@ -111,15 +118,6 @@ const getPathNoStrict = (request) => {
111
118
  const result = getPath(request);
112
119
  return result.length > 1 && result.at(-1) === "/" ? result.slice(0, -1) : result;
113
120
  };
114
- const stripPathPrefix = (rawPath, decodedPath, prefixLength) => {
115
- if (rawPath.at(-1) === "/" && decodedPath.at(-1) !== "/") rawPath = rawPath.slice(0, -1);
116
- let index = 0;
117
- for (let i = decodedPath.indexOf("/"); i !== -1 && i < prefixLength; i = decodedPath.indexOf("/", i + 1)) {
118
- index = rawPath.indexOf("/", index + 1);
119
- if (index === -1) return "/";
120
- }
121
- return rawPath.slice(index) || "/";
122
- };
123
121
  /**
124
122
  * Merge paths.
125
123
  * @param {string[]} ...paths - The paths to merge.
@@ -224,7 +222,6 @@ exports.getQueryStrings = getQueryStrings;
224
222
  exports.mergePath = mergePath;
225
223
  exports.splitPath = splitPath;
226
224
  exports.splitRoutingPath = splitRoutingPath;
227
- exports.stripPathPrefix = stripPathPrefix;
228
225
  exports.tryDecode = tryDecode;
229
226
  exports.tryDecodeURI = tryDecodeURI;
230
227
  exports.tryDecodeURIComponent = tryDecodeURIComponent;
@@ -3,16 +3,16 @@ const require_http_exception = require("../http-exception.js");
3
3
  const require_utils_buffer = require("../utils/buffer.js");
4
4
  const require_helper_cookie_index = require("../helper/cookie/index.js");
5
5
  //#region src/validator/validator.ts
6
- const jsonRegex = /^application\/([a-z-\.]+\+)?json(;\s*[a-zA-Z0-9\-]+\=([^;]+))*$/i;
7
- const multipartRegex = /^multipart\/form-data(;\s*[a-zA-Z0-9\-]+\=([^;]+))*$/i;
8
- const urlencodedRegex = /^application\/x-www-form-urlencoded(;\s*[a-zA-Z0-9\-]+\=([^;]+))*$/i;
6
+ const jsonRegex = /^application\/([\w.-]+\+)?json$/i;
7
+ const getMediaType = (contentType) => contentType.split(";")[0].trim().toLowerCase();
9
8
  const validator = (target, validationFunc) => {
10
9
  return async (c, next) => {
11
10
  let value = {};
12
11
  const contentType = c.req.header("Content-Type");
12
+ const mediaType = contentType ? getMediaType(contentType) : "";
13
13
  switch (target) {
14
14
  case "json":
15
- if (!contentType || !jsonRegex.test(contentType)) break;
15
+ if (!jsonRegex.test(mediaType)) break;
16
16
  try {
17
17
  value = await c.req.json();
18
18
  } catch {
@@ -20,7 +20,7 @@ const validator = (target, validationFunc) => {
20
20
  }
21
21
  break;
22
22
  case "form": {
23
- if (!contentType || !(multipartRegex.test(contentType) || urlencodedRegex.test(contentType))) break;
23
+ if (mediaType !== "multipart/form-data" && mediaType !== "application/x-www-form-urlencoded") break;
24
24
  let formData;
25
25
  if (c.req.bodyCache.formData) formData = await c.req.bodyCache.formData;
26
26
  else try {
@@ -1,6 +1,7 @@
1
1
  import { compose } from "./compose.js";
2
2
  import { getPath, getPathNoStrict, mergePath } from "./utils/url.js";
3
3
  import { Context } from "./context.js";
4
+ import { routePath } from "./helper/route/index.js";
4
5
  import { METHODS } from "./router.js";
5
6
  import { COMPOSED_HANDLER } from "./utils/constants.js";
6
7
  import { createMountedRequest } from "./utils/mount.js";
@@ -184,6 +185,8 @@ var Hono = class Hono {
184
185
  * @param {Function} applicationHandler - other Request Handler
185
186
  * @param {MountOptions} [options] - options of `.mount()`
186
187
  * @returns {Hono} mounted Hono instance
188
+ * @throws {Error} If automatic request rewriting encounters duplicate path parameter names or an optional regular expression parameter.
189
+ * @throws {HTTPException} With status 400 if automatic request rewriting cannot safely preserve the routed path.
187
190
  *
188
191
  * @example
189
192
  * ```ts
@@ -228,8 +231,10 @@ var Hono = class Hono {
228
231
  } catch {}
229
232
  return [c.env, executionContext];
230
233
  };
231
- const mergedPath = mergePath(this._basePath, path);
232
- const defaultReplaceRequest = (c) => createMountedRequest(c, mergedPath.replace(/\/$/, ""), mergePath(mergedPath, "*"));
234
+ const defaultReplaceRequest = (c) => {
235
+ const mountedRoutePath = routePath(c);
236
+ return createMountedRequest(c, mountedRoutePath.replace(/\/?\*$/, ""), mountedRoutePath);
237
+ };
233
238
  const handler = async (c, next) => {
234
239
  const res = await applicationHandler(replaceRequest ? replaceRequest(c.req.raw) : defaultReplaceRequest(c), ...getOptions(c));
235
240
  if (res) return res;
@@ -44,23 +44,22 @@ const bodyLimit = (options) => {
44
44
  const hasTransferEncoding = c.req.raw.headers.has("transfer-encoding");
45
45
  if (c.req.raw.headers.has("content-length") && !hasTransferEncoding) return parseInt(c.req.raw.headers.get("content-length") || "0", 10) > maxSize ? onError(c) : next();
46
46
  let size = 0;
47
- const chunks = [];
47
+ let buffer = /* @__PURE__ */ new Uint8Array(0);
48
48
  const rawReader = c.req.raw.body.getReader();
49
49
  for (;;) {
50
50
  const { done, value } = await rawReader.read();
51
51
  if (done) break;
52
+ const offset = size;
52
53
  size += value.length;
53
54
  if (size > maxSize) return onError(c);
54
- chunks.push(value);
55
+ if (size > buffer.length) {
56
+ const grown = new Uint8Array(Math.min(maxSize, Math.max(size, buffer.length * 2)));
57
+ grown.set(buffer.subarray(0, offset));
58
+ buffer = grown;
59
+ }
60
+ buffer.set(value, offset);
55
61
  }
56
- const requestInit = {
57
- body: new ReadableStream({ start(controller) {
58
- for (const chunk of chunks) controller.enqueue(chunk);
59
- controller.close();
60
- } }),
61
- duplex: "half"
62
- };
63
- c.req.raw = new Request(c.req.raw, requestInit);
62
+ c.req.raw = new Request(c.req.raw, { body: buffer.subarray(0, size) });
64
63
  return next();
65
64
  };
66
65
  };
@@ -1,5 +1,5 @@
1
- import { getCookie, setCookie } from "../../helper/cookie/index.js";
2
1
  import { parseAccept } from "../../utils/accept.js";
2
+ import { getCookie, setCookie } from "../../helper/cookie/index.js";
3
3
  //#region src/middleware/language/language.ts
4
4
  const DEFAULT_OPTIONS = {
5
5
  order: [
@@ -1,7 +1,7 @@
1
+ import { basePath, matchedRoutes } from "../../helper/route/index.js";
1
2
  import "../../router.js";
2
3
  import { TrieRouter } from "../../router/trie-router/router.js";
3
4
  import "../../router/trie-router/index.js";
4
- import { basePath, matchedRoutes } from "../../helper/route/index.js";
5
5
  //#region src/middleware/method-not-allowed/index.ts
6
6
  /**
7
7
  * Method Not Allowed Middleware for Hono.
@@ -1,5 +1,5 @@
1
- import { createMountedRequest } from "../../utils/mount.js";
2
1
  import { routePath } from "../../helper/route/index.js";
2
+ import { createMountedRequest } from "../../utils/mount.js";
3
3
  //#region src/middleware/mount/index.ts
4
4
  const defaultReplaceRequest = (c) => {
5
5
  const path = routePath(c);
@@ -20,7 +20,8 @@ const defaultGetOptions = (c) => {
20
20
  * @param {Function} applicationHandler - other Request Handler
21
21
  * @param {MountOptions} [options] - options of `mount()`
22
22
  * @returns {MiddlewareHandler} handler to register with `app.all()`
23
- * @throws {Error} If the route ends with a wildcard inside a segment (e.g. `/assets*`), or automatic request rewriting encounters duplicate path parameter names.
23
+ * @throws {Error} If the route ends with a wildcard inside a segment (e.g. `/assets*`), or automatic request rewriting encounters duplicate path parameter names or an optional regular expression parameter.
24
+ * @throws {HTTPException} With status 400 if automatic request rewriting cannot safely preserve the routed path.
24
25
  *
25
26
  * @example
26
27
  * ```ts
@@ -24,8 +24,8 @@ const serveStatic = (options) => {
24
24
  let filename;
25
25
  if (options.path) filename = options.path;
26
26
  else try {
27
- if (!options.allowPercentInPath && c.req.path.includes("%")) throw new Error();
28
27
  filename = tryDecodeURI(c.req.path);
28
+ if (c.req.path.includes("%") && (!options.allowPercentInPath || filename !== c.req.path.replace(/%25/g, "%"))) throw new Error();
29
29
  if (/(?:^|[\/\\])\.{1,2}(?:$|[\/\\])|[\/\\]{2,}|\\/.test(filename)) throw new Error();
30
30
  } catch {
31
31
  await options.onNotFound?.(c.req.path, c);
@@ -160,6 +160,8 @@ declare class Hono<E extends Env = Env, S extends Schema = {}, BasePath extends
160
160
  * @param {Function} applicationHandler - other Request Handler
161
161
  * @param {MountOptions} [options] - options of `.mount()`
162
162
  * @returns {Hono} mounted Hono instance
163
+ * @throws {Error} If automatic request rewriting encounters duplicate path parameter names or an optional regular expression parameter.
164
+ * @throws {HTTPException} With status 400 if automatic request rewriting cannot safely preserve the routed path.
163
165
  *
164
166
  * @example
165
167
  * ```ts
@@ -16,7 +16,8 @@ type MountOptions = MountOptionHandler | {
16
16
  * @param {Function} applicationHandler - other Request Handler
17
17
  * @param {MountOptions} [options] - options of `mount()`
18
18
  * @returns {MiddlewareHandler} handler to register with `app.all()`
19
- * @throws {Error} If the route ends with a wildcard inside a segment (e.g. `/assets*`), or automatic request rewriting encounters duplicate path parameter names.
19
+ * @throws {Error} If the route ends with a wildcard inside a segment (e.g. `/assets*`), or automatic request rewriting encounters duplicate path parameter names or an optional regular expression parameter.
20
+ * @throws {HTTPException} With status 400 if automatic request rewriting cannot safely preserve the routed path.
20
21
  *
21
22
  * @example
22
23
  * ```ts
@@ -26,7 +26,6 @@ export declare const getPath: (request: Request) => string;
26
26
  */
27
27
  export declare const getQueryStrings: (url: string) => string;
28
28
  export declare const getPathNoStrict: (request: Request) => string;
29
- export declare const stripPathPrefix: (rawPath: string, decodedPath: string, prefixLength: number) => string;
30
29
  /**
31
30
  * Merge paths.
32
31
  * @param {string[]} ...paths - The paths to merge.
@@ -1,6 +1,12 @@
1
+ import { HTTPException } from "../http-exception.js";
1
2
  import { GET_MATCH_RESULT } from "../request/constants.js";
2
- import { getPattern, splitRoutingPath, stripPathPrefix } from "./url.js";
3
+ import { getPattern, splitRoutingPath } from "./url.js";
3
4
  //#region src/utils/mount.ts
5
+ const countTrailingSlashes = (path) => {
6
+ let index = path.length;
7
+ while (index > 0 && path.charCodeAt(index - 1) === 47) index--;
8
+ return path.length - index;
9
+ };
4
10
  const getPathPrefixLength = (c, pathPrefix, routePath) => {
5
11
  if (!/[:*]/.test(pathPrefix)) return pathPrefix.length;
6
12
  const path = c.req.path;
@@ -8,6 +14,7 @@ const getPathPrefixLength = (c, pathPrefix, routePath) => {
8
14
  const paramNames = /* @__PURE__ */ new Set();
9
15
  let length = 0;
10
16
  for (const part of splitRoutingPath(pathPrefix)) {
17
+ if (part[0] === ":" && part.endsWith("}?")) throw new Error(`mount(): Optional regular expression parameters are not supported in "${routePath}".`);
11
18
  const pattern = getPattern(part);
12
19
  if (pattern && pattern !== "*") {
13
20
  const name = pattern[1];
@@ -26,8 +33,17 @@ const getPathPrefixLength = (c, pathPrefix, routePath) => {
26
33
  };
27
34
  const createMountedRequest = (c, pathPrefix, routePath) => {
28
35
  if (/[^/]\*$/.test(routePath)) throw new Error(`mount(): Wildcard must follow "/" in "${routePath}".`);
29
- const url = new URL(c.req.raw.url);
30
- url.pathname = stripPathPrefix(url.pathname, c.req.path, getPathPrefixLength(c, pathPrefix, routePath));
36
+ const prefixLength = getPathPrefixLength(c, pathPrefix, routePath);
37
+ const path = c.req.path.slice(prefixLength) || "/";
38
+ if (prefixLength > c.req.path.length || path[0] !== "/" || /\/(?:\.|%2e){1,2}(?:\/|$)/i.test(path)) throw new HTTPException(400, { message: "Invalid mounted path" });
39
+ const rawUrl = c.req.raw.url;
40
+ if (/^[^/?#]*\/\/[^/?#\\]*[?#\\]/.test(rawUrl)) throw new HTTPException(400, { message: "Invalid mounted path" });
41
+ const rawPathEnd = rawUrl.search(/[?#]/);
42
+ const rawTrailingSlashes = countTrailingSlashes(rawPathEnd === -1 ? rawUrl : rawUrl.slice(0, rawPathEnd));
43
+ if (rawTrailingSlashes > 1 && countTrailingSlashes(c.req.path) === rawTrailingSlashes - 1) throw new HTTPException(400, { message: "Invalid mounted path" });
44
+ const url = new URL(rawUrl);
45
+ url.pathname = path.replace(/[\\\t\n\r]/g, encodeURIComponent);
46
+ if (path.includes("%")) {}
31
47
  return new Request(url, c.req.raw);
32
48
  };
33
49
  //#endregion
@@ -80,6 +80,7 @@ const tryDecode = (str, decoder) => {
80
80
  * tryDecodeURI('Hello%20World/%A4%A2') // 'Hello World/%A4%A2'
81
81
  */
82
82
  const tryDecodeURI = (str) => tryDecode(str, decodeURI);
83
+ const decodeURIWithPreservedPercent = (value) => decodeURI(value.includes("%25") ? value.replace(/%25/g, "%2525") : value);
83
84
  const getPath = (request) => {
84
85
  const url = request.url;
85
86
  const start = url.indexOf("/", url.indexOf(":") + 4);
@@ -91,7 +92,13 @@ const getPath = (request) => {
91
92
  const hashIndex = url.indexOf("#", i);
92
93
  const end = queryIndex === -1 ? hashIndex === -1 ? void 0 : hashIndex : hashIndex === -1 ? queryIndex : Math.min(queryIndex, hashIndex);
93
94
  const path = url.slice(start, end);
94
- return tryDecodeURI(path.includes("%25") ? path.replace(/%25/g, "%2525") : path);
95
+ const decoded = tryDecode(path, decodeURIWithPreservedPercent);
96
+ if (/%(?![0-9A-Fa-f]{2})/.test(path)) {
97
+ const rewritten = new URL("http://localhost");
98
+ rewritten.pathname = decoded.replace(/[\\\t\n\r]/g, encodeURIComponent);
99
+ if (tryDecode(rewritten.pathname, decodeURIWithPreservedPercent) !== decoded) return tryDecode(path.replace(/%(?![0-9A-Fa-f]{2})/g, "%25"), decodeURIWithPreservedPercent);
100
+ }
101
+ return decoded;
95
102
  } else if (charCode === 63 || charCode === 35) break;
96
103
  }
97
104
  return url.slice(start, i);
@@ -110,15 +117,6 @@ const getPathNoStrict = (request) => {
110
117
  const result = getPath(request);
111
118
  return result.length > 1 && result.at(-1) === "/" ? result.slice(0, -1) : result;
112
119
  };
113
- const stripPathPrefix = (rawPath, decodedPath, prefixLength) => {
114
- if (rawPath.at(-1) === "/" && decodedPath.at(-1) !== "/") rawPath = rawPath.slice(0, -1);
115
- let index = 0;
116
- for (let i = decodedPath.indexOf("/"); i !== -1 && i < prefixLength; i = decodedPath.indexOf("/", i + 1)) {
117
- index = rawPath.indexOf("/", index + 1);
118
- if (index === -1) return "/";
119
- }
120
- return rawPath.slice(index) || "/";
121
- };
122
120
  /**
123
121
  * Merge paths.
124
122
  * @param {string[]} ...paths - The paths to merge.
@@ -212,4 +210,4 @@ const getQueryParams = (url, key) => {
212
210
  };
213
211
  const decodeURIComponent_ = decodeURIComponent;
214
212
  //#endregion
215
- export { checkOptionalParameter, decodeURIComponent_, getPath, getPathNoStrict, getPattern, getQueryParam, getQueryParams, getQueryStrings, mergePath, splitPath, splitRoutingPath, stripPathPrefix, tryDecode, tryDecodeURI, tryDecodeURIComponent };
213
+ export { checkOptionalParameter, decodeURIComponent_, getPath, getPathNoStrict, getPattern, getQueryParam, getQueryParams, getQueryStrings, mergePath, splitPath, splitRoutingPath, tryDecode, tryDecodeURI, tryDecodeURIComponent };
@@ -2,16 +2,16 @@ import { HTTPException } from "../http-exception.js";
2
2
  import { bufferToFormData } from "../utils/buffer.js";
3
3
  import { getCookie } from "../helper/cookie/index.js";
4
4
  //#region src/validator/validator.ts
5
- const jsonRegex = /^application\/([a-z-\.]+\+)?json(;\s*[a-zA-Z0-9\-]+\=([^;]+))*$/i;
6
- const multipartRegex = /^multipart\/form-data(;\s*[a-zA-Z0-9\-]+\=([^;]+))*$/i;
7
- const urlencodedRegex = /^application\/x-www-form-urlencoded(;\s*[a-zA-Z0-9\-]+\=([^;]+))*$/i;
5
+ const jsonRegex = /^application\/([\w.-]+\+)?json$/i;
6
+ const getMediaType = (contentType) => contentType.split(";")[0].trim().toLowerCase();
8
7
  const validator = (target, validationFunc) => {
9
8
  return async (c, next) => {
10
9
  let value = {};
11
10
  const contentType = c.req.header("Content-Type");
11
+ const mediaType = contentType ? getMediaType(contentType) : "";
12
12
  switch (target) {
13
13
  case "json":
14
- if (!contentType || !jsonRegex.test(contentType)) break;
14
+ if (!jsonRegex.test(mediaType)) break;
15
15
  try {
16
16
  value = await c.req.json();
17
17
  } catch {
@@ -19,7 +19,7 @@ const validator = (target, validationFunc) => {
19
19
  }
20
20
  break;
21
21
  case "form": {
22
- if (!contentType || !(multipartRegex.test(contentType) || urlencodedRegex.test(contentType))) break;
22
+ if (mediaType !== "multipart/form-data" && mediaType !== "application/x-www-form-urlencoded") break;
23
23
  let formData;
24
24
  if (c.req.bodyCache.formData) formData = await c.req.bodyCache.formData;
25
25
  else try {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "4.13.17",
3
+ "version": "4.13.18",
4
4
  "description": "Web framework built on Web Standards",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",
@@ -1,21 +1,22 @@
1
1
  {
2
2
  "name": "mute-stream",
3
- "version": "3.0.0",
3
+ "version": "4.0.0",
4
4
  "main": "lib/index.js",
5
5
  "devDependencies": {
6
- "@npmcli/eslint-config": "^5.0.0",
7
- "@npmcli/template-oss": "4.27.1",
8
- "tap": "^16.3.0"
6
+ "@npmcli/eslint-config": "^6.0.0",
7
+ "@npmcli/template-oss": "5.0.0"
9
8
  },
10
9
  "scripts": {
11
- "test": "tap",
10
+ "test": "node --test './test/**/*.js'",
12
11
  "lint": "npm run eslint",
13
12
  "postlint": "template-oss-check",
14
13
  "template-oss-apply": "template-oss-apply --force",
15
14
  "lintfix": "npm run eslint -- --fix",
16
- "snap": "tap",
15
+ "snap": "node --test --test-update-snapshots './test/**/*.js'",
17
16
  "posttest": "npm run lint",
18
- "eslint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\""
17
+ "eslint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\"",
18
+ "test:node20": "node --test test",
19
+ "test:cover": "node --test --experimental-test-coverage --test-timeout=3000 --test-coverage-lines=100 --test-coverage-functions=100 --test-coverage-branches=100 './test/**/*.js'"
19
20
  },
20
21
  "repository": {
21
22
  "type": "git",
@@ -33,22 +34,14 @@
33
34
  "bin/",
34
35
  "lib/"
35
36
  ],
36
- "tap": {
37
- "statements": 70,
38
- "branches": 60,
39
- "functions": 81,
40
- "lines": 70,
41
- "nyc-arg": [
42
- "--exclude",
43
- "tap-snapshots/**"
44
- ]
45
- },
46
37
  "engines": {
47
- "node": "^20.17.0 || >=22.9.0"
38
+ "node": "^22.22.2 || ^24.15.0 || >=26.0.0"
48
39
  },
49
40
  "templateOSS": {
50
41
  "//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
51
- "version": "4.27.1",
52
- "publish": true
42
+ "version": "5.0.0",
43
+ "publish": true,
44
+ "testRunner": "node:test",
45
+ "latestCiVersion": 24
53
46
  }
54
47
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zuplo/cli",
3
- "version": "7.15.4",
3
+ "version": "7.15.6",
4
4
  "repository": "https://github.com/zuplo/zuplo",
5
5
  "author": "Zuplo, Inc.",
6
6
  "type": "module",
@@ -32,10 +32,10 @@
32
32
  "@opentelemetry/api": "1.9.0",
33
33
  "@opentelemetry/api-logs": "0.220.0",
34
34
  "@swc/core": "1.10.18",
35
- "@zuplo/core": "7.15.4",
35
+ "@zuplo/core": "7.15.6",
36
36
  "@zuplo/editor": "1.0.39603386871",
37
- "@zuplo/openapi-tools": "7.15.4",
38
- "@zuplo/runtime": "7.15.4",
37
+ "@zuplo/openapi-tools": "7.15.6",
38
+ "@zuplo/runtime": "7.15.6",
39
39
  "chalk": "5.4.1",
40
40
  "chokidar": "3.5.3",
41
41
  "cookie": "1.0.2",
@@ -66,15 +66,15 @@
66
66
  "workerd": "1.20261002.1",
67
67
  "yargs": "17.7.2",
68
68
  "zod": "4.6.7",
69
- "@zuplo/graphql": "7.15.4",
70
- "@zuplo/otel": "7.15.4"
69
+ "@zuplo/graphql": "7.15.6",
70
+ "@zuplo/otel": "7.15.6"
71
71
  },
72
72
  "optionalDependencies": {
73
- "@zuplo/lint-darwin-arm64": "7.15.4",
74
- "@zuplo/lint-darwin-x64": "7.15.4",
75
- "@zuplo/lint-linux-x64": "7.15.4",
76
- "@zuplo/lint-linux-arm64": "7.15.4",
77
- "@zuplo/lint-win32-x64": "7.15.4"
73
+ "@zuplo/lint-darwin-arm64": "7.15.6",
74
+ "@zuplo/lint-darwin-x64": "7.15.6",
75
+ "@zuplo/lint-linux-x64": "7.15.6",
76
+ "@zuplo/lint-linux-arm64": "7.15.6",
77
+ "@zuplo/lint-win32-x64": "7.15.6"
78
78
  },
79
79
  "bundleDependencies": [
80
80
  "@inquirer/prompts",