@suveren/gateway 0.7.4 → 0.7.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 (171) hide show
  1. package/dist/control-plane/index.mjs +248 -58
  2. package/dist/mcp-server/http.mjs +408 -65
  3. package/dist/ui/assets/{index-CkWaRck1.css → index-BYVb_0oG.css} +1 -1
  4. package/dist/ui/assets/index-CsrM6RQr.js +110 -0
  5. package/dist/ui/index.html +2 -2
  6. package/node_modules/@hap/core/dist/index.d.mts +258 -9
  7. package/node_modules/@hap/core/dist/index.d.ts +258 -9
  8. package/node_modules/@hap/core/dist/index.js +227 -5
  9. package/node_modules/@hap/core/dist/index.mjs +213 -4
  10. package/node_modules/@hap/core/package.json +3 -2
  11. package/node_modules/@hap/core/src/did-key.ts +126 -0
  12. package/node_modules/@hap/core/src/identity.ts +21 -5
  13. package/node_modules/@hap/core/src/index.ts +3 -0
  14. package/node_modules/@hap/core/src/mandate.ts +207 -0
  15. package/node_modules/@hap/core/src/receipt.ts +74 -0
  16. package/node_modules/@hap/core/src/types.ts +81 -5
  17. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/lib/accept.js +54 -0
  18. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/lib/charset.js +10 -34
  19. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/lib/encoding.js +9 -30
  20. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/lib/language.js +15 -36
  21. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/lib/mediaType.js +16 -134
  22. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/node_modules/content-type/LICENSE +22 -0
  23. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/node_modules/content-type/README.md +71 -0
  24. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/node_modules/content-type/dist/index.d.ts +46 -0
  25. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/node_modules/content-type/dist/index.js +176 -0
  26. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/node_modules/content-type/dist/index.js.map +1 -0
  27. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/node_modules/content-type/package.json +52 -0
  28. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/package.json +16 -10
  29. package/node_modules/@types/node/README.md +1 -1
  30. package/node_modules/@types/node/buffer.buffer.d.ts +5 -5
  31. package/node_modules/@types/node/crypto.d.ts +2 -2
  32. package/node_modules/@types/node/http.d.ts +16 -0
  33. package/node_modules/@types/node/http2.d.ts +10 -2
  34. package/node_modules/@types/node/package.json +2 -2
  35. package/node_modules/@types/node/process.d.ts +52 -0
  36. package/node_modules/@types/node/quic.d.ts +210 -28
  37. package/node_modules/@types/node/sqlite.d.ts +6 -2
  38. package/node_modules/@types/node/test.d.ts +36 -0
  39. package/node_modules/fast-uri/index.js +201 -48
  40. package/node_modules/fast-uri/lib/schemes.js +9 -4
  41. package/node_modules/fast-uri/lib/utils.js +388 -91
  42. package/node_modules/fast-uri/package.json +1 -1
  43. package/node_modules/fast-uri/test/component-safe-serialization.test.js +105 -0
  44. package/node_modules/fast-uri/test/equal.test.js +31 -3
  45. package/node_modules/fast-uri/test/fixtures/uri-js-parse.json +2 -0
  46. package/node_modules/fast-uri/test/ipv6-canonical.test.js +34 -0
  47. package/node_modules/fast-uri/test/ipv6-validation.test.js +90 -0
  48. package/node_modules/fast-uri/test/malformed-percent.test.js +77 -0
  49. package/node_modules/fast-uri/test/malformed-urn.test.js +61 -0
  50. package/node_modules/fast-uri/test/parse.test.js +7 -3
  51. package/node_modules/fast-uri/test/query-fragment-normalization.test.js +33 -0
  52. package/node_modules/fast-uri/test/reserved-path-normalization.test.js +109 -0
  53. package/node_modules/fast-uri/test/scheme-validation.test.js +124 -0
  54. package/node_modules/fast-uri/test/security-normalization.test.js +101 -0
  55. package/node_modules/fast-uri/test/security.test.js +75 -3
  56. package/node_modules/fast-uri/test/urn-full-input.test.js +29 -0
  57. package/node_modules/fast-uri/test/websocket-query-preservation.test.js +24 -0
  58. package/node_modules/hono/dist/cjs/client/client.js +25 -11
  59. package/node_modules/hono/dist/cjs/client/utils.js +4 -1
  60. package/node_modules/hono/dist/cjs/context.js +4 -0
  61. package/node_modules/hono/dist/cjs/helper/accepts/accepts.js +36 -2
  62. package/node_modules/hono/dist/cjs/helper/ssg/ssg.js +1 -1
  63. package/node_modules/hono/dist/cjs/helper/ssg/utils.js +30 -10
  64. package/node_modules/hono/dist/cjs/jsx/dom/render.js +2 -0
  65. package/node_modules/hono/dist/cjs/middleware/cache/index.js +1 -1
  66. package/node_modules/hono/dist/cjs/middleware/cors/index.js +1 -1
  67. package/node_modules/hono/dist/cjs/middleware/csrf/index.js +1 -1
  68. package/node_modules/hono/dist/cjs/middleware/etag/digest.js +1 -1
  69. package/node_modules/hono/dist/cjs/middleware/etag/index.js +3 -3
  70. package/node_modules/hono/dist/cjs/middleware/pretty-json/index.js +3 -1
  71. package/node_modules/hono/dist/cjs/request.js +8 -4
  72. package/node_modules/hono/dist/cjs/router/linear-router/router.js +7 -2
  73. package/node_modules/hono/dist/cjs/router/pattern-router/router.js +3 -9
  74. package/node_modules/hono/dist/cjs/router/reg-exp-router/node.js +10 -3
  75. package/node_modules/hono/dist/cjs/router/reg-exp-router/router.js +47 -83
  76. package/node_modules/hono/dist/cjs/router/reg-exp-router/trie.js +2 -1
  77. package/node_modules/hono/dist/cjs/router/trie-router/node.js +46 -69
  78. package/node_modules/hono/dist/cjs/router/trie-router/router.js +3 -11
  79. package/node_modules/hono/dist/cjs/router/utils.js +27 -0
  80. package/node_modules/hono/dist/cjs/utils/body.js +15 -3
  81. package/node_modules/hono/dist/cjs/utils/cookie.js +1 -1
  82. package/node_modules/hono/dist/cjs/utils/ipaddr.js +5 -3
  83. package/node_modules/hono/dist/cjs/utils/stream.js +7 -1
  84. package/node_modules/hono/dist/cjs/utils/url.js +9 -1
  85. package/node_modules/hono/dist/client/client.js +25 -11
  86. package/node_modules/hono/dist/client/utils.js +4 -1
  87. package/node_modules/hono/dist/context.js +4 -0
  88. package/node_modules/hono/dist/helper/accepts/accepts.js +36 -2
  89. package/node_modules/hono/dist/helper/ssg/ssg.js +1 -1
  90. package/node_modules/hono/dist/helper/ssg/utils.js +30 -10
  91. package/node_modules/hono/dist/jsx/dom/render.js +2 -0
  92. package/node_modules/hono/dist/middleware/cache/index.js +1 -1
  93. package/node_modules/hono/dist/middleware/cors/index.js +1 -1
  94. package/node_modules/hono/dist/middleware/csrf/index.js +1 -1
  95. package/node_modules/hono/dist/middleware/etag/digest.js +1 -1
  96. package/node_modules/hono/dist/middleware/etag/index.js +3 -3
  97. package/node_modules/hono/dist/middleware/pretty-json/index.js +3 -1
  98. package/node_modules/hono/dist/request.js +8 -4
  99. package/node_modules/hono/dist/router/linear-router/router.js +7 -2
  100. package/node_modules/hono/dist/router/pattern-router/router.js +3 -9
  101. package/node_modules/hono/dist/router/reg-exp-router/node.js +6 -2
  102. package/node_modules/hono/dist/router/reg-exp-router/router.js +53 -84
  103. package/node_modules/hono/dist/router/reg-exp-router/trie.js +2 -1
  104. package/node_modules/hono/dist/router/trie-router/node.js +46 -69
  105. package/node_modules/hono/dist/router/trie-router/router.js +3 -11
  106. package/node_modules/hono/dist/router/utils.js +5 -0
  107. package/node_modules/hono/dist/types/context.d.ts +4 -0
  108. package/node_modules/hono/dist/types/router/reg-exp-router/node.d.ts +3 -0
  109. package/node_modules/hono/dist/types/router/trie-router/node.d.ts +1 -2
  110. package/node_modules/hono/dist/types/router/trie-router/router.d.ts +0 -1
  111. package/node_modules/hono/dist/types/router/utils.d.ts +1 -0
  112. package/node_modules/hono/dist/types/utils/url.d.ts +4 -0
  113. package/node_modules/hono/dist/utils/body.js +15 -3
  114. package/node_modules/hono/dist/utils/cookie.js +1 -1
  115. package/node_modules/hono/dist/utils/ipaddr.js +5 -3
  116. package/node_modules/hono/dist/utils/stream.js +7 -1
  117. package/node_modules/hono/dist/utils/url.js +9 -1
  118. package/node_modules/hono/package.json +1 -1
  119. package/node_modules/is-plain-object/README.md +39 -95
  120. package/node_modules/is-plain-object/dist/is-plain-object.js +0 -2
  121. package/node_modules/is-plain-object/is-plain-object.d.ts +6 -1
  122. package/node_modules/is-plain-object/package.json +8 -34
  123. package/node_modules/jose/dist/types/jwe/compact/encrypt.d.ts +4 -3
  124. package/node_modules/jose/dist/types/jwe/flattened/encrypt.d.ts +4 -3
  125. package/node_modules/jose/dist/types/jwe/general/encrypt.d.ts +4 -3
  126. package/node_modules/jose/dist/types/jwks/remote.d.ts +4 -4
  127. package/node_modules/jose/dist/types/jws/general/verify.d.ts +3 -3
  128. package/node_modules/jose/dist/types/jwt/encrypt.d.ts +12 -17
  129. package/node_modules/jose/dist/types/jwt/sign.d.ts +8 -14
  130. package/node_modules/jose/dist/types/jwt/unsecured.d.ts +9 -15
  131. package/node_modules/jose/dist/types/types.d.ts +4 -2
  132. package/node_modules/jose/dist/webapi/jwe/compact/encrypt.js +30 -8
  133. package/node_modules/jose/dist/webapi/jwe/flattened/decrypt.js +8 -4
  134. package/node_modules/jose/dist/webapi/jwe/flattened/encrypt.js +6 -13
  135. package/node_modules/jose/dist/webapi/jwe/general/decrypt.js +19 -19
  136. package/node_modules/jose/dist/webapi/jwe/general/encrypt.js +32 -21
  137. package/node_modules/jose/dist/webapi/jwk/embedded.js +15 -1
  138. package/node_modules/jose/dist/webapi/jwk/thumbprint.js +11 -5
  139. package/node_modules/jose/dist/webapi/jwks/local.js +45 -53
  140. package/node_modules/jose/dist/webapi/jwks/remote.js +82 -103
  141. package/node_modules/jose/dist/webapi/jws/compact/sign.js +10 -9
  142. package/node_modules/jose/dist/webapi/jws/flattened/sign.js +2 -1
  143. package/node_modules/jose/dist/webapi/jws/flattened/verify.js +8 -7
  144. package/node_modules/jose/dist/webapi/jws/general/sign.js +5 -3
  145. package/node_modules/jose/dist/webapi/jws/general/verify.js +51 -21
  146. package/node_modules/jose/dist/webapi/jwt/decrypt.js +7 -9
  147. package/node_modules/jose/dist/webapi/jwt/encrypt.js +21 -50
  148. package/node_modules/jose/dist/webapi/jwt/sign.js +8 -41
  149. package/node_modules/jose/dist/webapi/jwt/unsecured.js +21 -42
  150. package/node_modules/jose/dist/webapi/key/generate_key_pair.js +6 -2
  151. package/node_modules/jose/dist/webapi/key/generate_secret.js +7 -6
  152. package/node_modules/jose/dist/webapi/key/import.js +16 -12
  153. package/node_modules/jose/dist/webapi/lib/asn1.js +7 -2
  154. package/node_modules/jose/dist/webapi/lib/content_encryption.js +7 -15
  155. package/node_modules/jose/dist/webapi/lib/deflate.js +8 -0
  156. package/node_modules/jose/dist/webapi/lib/helpers.js +1 -1
  157. package/node_modules/jose/dist/webapi/lib/jwe_decrypt.js +85 -28
  158. package/node_modules/jose/dist/webapi/lib/jwe_encrypt.js +45 -13
  159. package/node_modules/jose/dist/webapi/lib/jwk_metadata.js +20 -0
  160. package/node_modules/jose/dist/webapi/lib/jws_sign.js +47 -36
  161. package/node_modules/jose/dist/webapi/lib/jws_verify.js +77 -45
  162. package/node_modules/jose/dist/webapi/lib/jwt_claims_set.js +82 -47
  163. package/node_modules/jose/dist/webapi/lib/key.js +24 -9
  164. package/node_modules/jose/dist/webapi/lib/key_management.js +10 -4
  165. package/node_modules/jose/dist/webapi/lib/key_options.js +6 -0
  166. package/node_modules/jose/dist/webapi/lib/options.js +26 -0
  167. package/node_modules/jose/dist/webapi/lib/type_checks.js +11 -13
  168. package/node_modules/jose/package.json +1 -1
  169. package/package.json +2 -2
  170. package/dist/ui/assets/index-0Q2eNytX.js +0 -110
  171. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/HISTORY.md +0 -114
@@ -26,6 +26,10 @@ var createProxy = (callback, path) => {
26
26
  });
27
27
  return proxy;
28
28
  };
29
+ var appendQueryParams = (url, searchParams) => {
30
+ const queryString = searchParams.toString();
31
+ return queryString ? `${url}?${queryString}` : url;
32
+ };
29
33
  var ClientRequestImpl = class {
30
34
  url;
31
35
  method;
@@ -52,6 +56,9 @@ var ClientRequestImpl = class {
52
56
  }
53
57
  if (Array.isArray(v)) {
54
58
  for (const v2 of v) {
59
+ if (v2 === void 0) {
60
+ continue;
61
+ }
55
62
  form.append(k, v2);
56
63
  }
57
64
  } else {
@@ -76,19 +83,29 @@ var ClientRequestImpl = class {
76
83
  if (args?.cookie) {
77
84
  const cookies = [];
78
85
  for (const [key, value] of Object.entries(args.cookie)) {
86
+ if (value === void 0) {
87
+ continue;
88
+ }
79
89
  cookies.push(serialize(key, value));
80
90
  }
81
- headerValues["Cookie"] = cookies.join("; ");
91
+ if (cookies.length > 0) {
92
+ headerValues["Cookie"] = cookies.join("; ");
93
+ }
82
94
  }
83
95
  if (this.cType) {
84
96
  headerValues["Content-Type"] = this.cType;
85
97
  }
86
- const headers = new Headers(headerValues ?? void 0);
98
+ const headers = new Headers();
99
+ for (const [key, value] of Object.entries(headerValues)) {
100
+ if (value !== void 0) {
101
+ headers.set(key, value);
102
+ }
103
+ }
87
104
  let url = this.url;
88
105
  url = removeIndexString(url);
89
106
  url = replaceUrlParam(url, this.pathParams);
90
107
  if (this.queryParams) {
91
- url = url + "?" + this.queryParams.toString();
108
+ url = appendQueryParams(url, this.queryParams);
92
109
  }
93
110
  methodUpperCase = this.method.toUpperCase();
94
111
  const setBody = !(methodUpperCase === "GET" || methodUpperCase === "HEAD");
@@ -132,7 +149,7 @@ var hc = (baseUrl, options) => createProxy(function proxyCallback(opts) {
132
149
  result = replaceUrlParam(url, opts.args[0].param);
133
150
  }
134
151
  if (opts.args[0].query) {
135
- result = result + "?" + buildSearchParamsOption(opts.args[0].query).toString();
152
+ result = appendQueryParams(result, buildSearchParamsOption(opts.args[0].query));
136
153
  }
137
154
  }
138
155
  result = removeIndexString(result);
@@ -143,18 +160,15 @@ var hc = (baseUrl, options) => createProxy(function proxyCallback(opts) {
143
160
  }
144
161
  if (method === "ws") {
145
162
  const webSocketUrl = replaceUrlProtocol(
146
- opts.args[0] && opts.args[0].param ? replaceUrlParam(url, opts.args[0].param) : url,
163
+ opts.args[0]?.param ? replaceUrlParam(url, opts.args[0].param) : url,
147
164
  "ws"
148
165
  );
149
166
  const targetUrl = new URL(webSocketUrl);
150
167
  const queryParams = opts.args[0]?.query;
151
168
  if (queryParams) {
152
- Object.entries(queryParams).forEach(([key, value]) => {
153
- if (Array.isArray(value)) {
154
- value.forEach((item) => targetUrl.searchParams.append(key, item));
155
- } else {
156
- targetUrl.searchParams.set(key, value);
157
- }
169
+ const searchParams = buildSearchParamsOption(queryParams);
170
+ searchParams.forEach((value, key) => {
171
+ targetUrl.searchParams.append(key, value);
158
172
  });
159
173
  }
160
174
  const establishWebSocket = (...args) => {
@@ -9,7 +9,7 @@ var mergePath = (base, path) => {
9
9
  var replaceUrlParam = (urlString, params) => {
10
10
  for (const [k, v] of Object.entries(params)) {
11
11
  const reg = new RegExp("/:" + k + "(?:{[^/]+})?\\??(?=/|$)");
12
- urlString = urlString.replace(reg, v ? `/${v}` : "");
12
+ urlString = urlString.replace(reg, () => v ? `/${v}` : "");
13
13
  }
14
14
  return urlString;
15
15
  };
@@ -21,6 +21,9 @@ var buildSearchParams = (query) => {
21
21
  }
22
22
  if (Array.isArray(v)) {
23
23
  for (const v2 of v) {
24
+ if (v2 === void 0) {
25
+ continue;
26
+ }
24
27
  searchParams.append(k, v2);
25
28
  }
26
29
  } else {
@@ -202,6 +202,10 @@ var Context = class {
202
202
  * c.header('X-Message', 'Hello!')
203
203
  * c.header('Content-Type', 'text/plain')
204
204
  *
205
+ * // Append multiple headers using the append option (e.g. Vary)
206
+ * c.header('Vary', 'Accept-Encoding', { append: true })
207
+ * c.header('Vary', 'User-Agent', { append: true })
208
+ *
205
209
  * return c.body('Thank you for coming')
206
210
  * })
207
211
  * ```
@@ -1,9 +1,43 @@
1
1
  // src/helper/accepts/accepts.ts
2
2
  import { parseAccept } from "../../utils/accept.js";
3
+ var matchType = (acceptType, supportedType) => {
4
+ if (acceptType === supportedType) {
5
+ return true;
6
+ }
7
+ if (acceptType === "*/*" || acceptType === "*") {
8
+ return false;
9
+ }
10
+ if (acceptType.endsWith("/*")) {
11
+ const [acceptMain] = acceptType.split("/");
12
+ const [supportedMain] = supportedType.split("/");
13
+ return acceptMain === supportedMain;
14
+ }
15
+ return false;
16
+ };
17
+ var getSpecificity = (type) => {
18
+ if (type === "*/*" || type === "*") {
19
+ return 1;
20
+ }
21
+ if (type.endsWith("/*")) {
22
+ return 2;
23
+ }
24
+ return 3;
25
+ };
3
26
  var defaultMatch = (accepts2, config) => {
4
27
  const { supports, default: defaultSupport } = config;
5
- const accept = accepts2.sort((a, b) => b.q - a.q).find((accept2) => supports.includes(accept2.type));
6
- return accept ? accept.type : defaultSupport;
28
+ const sortedAccepts = accepts2.slice().sort((a, b) => {
29
+ if (b.q !== a.q) {
30
+ return b.q - a.q;
31
+ }
32
+ return getSpecificity(b.type) - getSpecificity(a.type);
33
+ });
34
+ for (const accept of sortedAccepts) {
35
+ const matched = supports.find((supported) => matchType(accept.type, supported));
36
+ if (matched) {
37
+ return matched;
38
+ }
39
+ }
40
+ return defaultSupport;
7
41
  };
8
42
  var accepts = (c, options) => {
9
43
  const acceptHeader = c.req.header(options.header);
@@ -184,7 +184,7 @@ var saveContentToFile = async (data, fsModule, outDir, extensionMap) => {
184
184
  const { routePath, content, mimeType } = awaitedData;
185
185
  const filePath = generateFilePath(routePath, outDir, mimeType, extensionMap);
186
186
  const dirPath = dirname(filePath);
187
- if (!createdDirs.has(dirPath)) {
187
+ if (dirPath !== "" && !createdDirs.has(dirPath)) {
188
188
  await fsModule.mkdir(dirPath, { recursive: true });
189
189
  createdDirs.add(dirPath);
190
190
  }
@@ -8,8 +8,14 @@ var dirname = (path) => {
8
8
  var normalizePath = (path) => {
9
9
  return path.replace(/(\\)/g, "/").replace(/\/$/g, "");
10
10
  };
11
- var handleParent = (resultPaths, beforeParentFlag) => {
12
- if (resultPaths.length === 0 || beforeParentFlag) {
11
+ var getUncRoot = (path) => {
12
+ const uncRoot = path.replace(/\\/g, "/").match(/^\/\/([^/]+)\/([^/]+)/);
13
+ if (uncRoot) {
14
+ return `${uncRoot[1].toLowerCase()}/${uncRoot[2].toLowerCase()}`;
15
+ }
16
+ };
17
+ var handleParent = (resultPaths) => {
18
+ if (resultPaths.length === 0 || resultPaths[resultPaths.length - 1] === "..") {
13
19
  resultPaths.push("..");
14
20
  } else {
15
21
  resultPaths.pop();
@@ -22,22 +28,20 @@ var handleNonDot = (path, resultPaths) => {
22
28
  }
23
29
  };
24
30
  var handleSegments = (paths, resultPaths) => {
25
- let beforeParentFlag = false;
26
31
  for (const path of paths) {
27
32
  if (path === "..") {
28
- handleParent(resultPaths, beforeParentFlag);
29
- beforeParentFlag = true;
33
+ handleParent(resultPaths);
30
34
  } else {
31
35
  handleNonDot(path, resultPaths);
32
- beforeParentFlag = false;
33
36
  }
34
37
  }
35
38
  };
36
39
  var joinPaths = (...paths) => {
40
+ const hasUncPrefix = getUncRoot(paths[0]) !== void 0;
37
41
  paths = paths.map(normalizePath);
38
42
  const resultPaths = [];
39
43
  handleSegments(paths.join("/").split("/"), resultPaths);
40
- return (paths[0][0] === "/" ? "/" : "") + resultPaths.join("/");
44
+ return (hasUncPrefix ? "//" : paths[0][0] === "/" ? "/" : "") + resultPaths.join("/");
41
45
  };
42
46
  var filterStaticGenerateRoutes = (hono) => {
43
47
  return hono.routes.reduce((acc, { method, handler, path }) => {
@@ -51,10 +55,26 @@ var filterStaticGenerateRoutes = (hono) => {
51
55
  var isDynamicRoute = (path) => {
52
56
  return path.split("/").some((segment) => segment.startsWith(":") || segment.includes("*"));
53
57
  };
58
+ var toSegments = (path) => path === "" ? [] : path.split("/");
59
+ var getPathRoot = (path) => {
60
+ const normalizedPath = path.replace(/\\/g, "/");
61
+ const uncRoot = getUncRoot(normalizedPath);
62
+ if (uncRoot) {
63
+ return `unc:${uncRoot}`;
64
+ }
65
+ const driveRoot = normalizedPath.match(/^([A-Za-z]):/);
66
+ if (driveRoot) {
67
+ const kind = normalizedPath[2] === "/" ? "drive-absolute" : "drive-relative";
68
+ return `${kind}:${driveRoot[1].toLowerCase()}`;
69
+ }
70
+ return normalizedPath.startsWith("/") ? "absolute" : "relative";
71
+ };
54
72
  var ensureWithinOutDir = (outDir, filePath) => {
55
- const normalizedOutDir = joinPaths("/", outDir);
56
- const normalizedFilePath = joinPaths("/", filePath);
57
- if (normalizedFilePath !== normalizedOutDir && !normalizedFilePath.startsWith(`${normalizedOutDir}/`)) {
73
+ const outDirSegments = toSegments(joinPaths(outDir));
74
+ const filePathSegments = toSegments(joinPaths(filePath));
75
+ const hasMismatchedPathRoot = getPathRoot(outDir) !== getPathRoot(filePath);
76
+ const climbsAboveOutDir = filePathSegments[outDirSegments.length] === "..";
77
+ if (hasMismatchedPathRoot || filePathSegments.length <= outDirSegments.length || !outDirSegments.every((segment, i) => segment === filePathSegments[i]) || climbsAboveOutDir) {
58
78
  throw new Error(`Path traversal detected: "${filePath}" is outside the output directory`);
59
79
  }
60
80
  };
@@ -78,6 +78,7 @@ var applyProps = (container, attributes, oldAttributes) => {
78
78
  } else if (key === "dangerouslySetInnerHTML" && value) {
79
79
  container.innerHTML = value.__html;
80
80
  } else if (key === "ref") {
81
+ refCleanupMap.get(container)?.();
81
82
  let cleanup;
82
83
  if (typeof value === "function") {
83
84
  cleanup = value(container) || (() => value(null));
@@ -142,6 +143,7 @@ var applyProps = (container, attributes, oldAttributes) => {
142
143
  container.removeEventListener(eventSpec[0], value, eventSpec[1]);
143
144
  } else if (key === "ref") {
144
145
  refCleanupMap.get(container)?.();
146
+ refCleanupMap.delete(container);
145
147
  } else {
146
148
  try {
147
149
  container.removeAttribute(toAttributeName(container, key));
@@ -23,7 +23,7 @@ var parseVaryDirectives = (vary) => {
23
23
  };
24
24
  var createCacheKey = (key, requestUrl, request, varyHeaders) => {
25
25
  const url = new URL(cacheKeyPath, requestUrl);
26
- url.searchParams.append(cacheKeyParameter, key.split("#", 1)[0]);
26
+ url.searchParams.append(cacheKeyParameter, key);
27
27
  url.searchParams.append(cacheMethodKeyParameter, request.method);
28
28
  if (request.method === "QUERY") {
29
29
  url.searchParams.append(queryDigestKeyParameter, request.digest);
@@ -48,7 +48,7 @@ var cors = (options) => {
48
48
  }
49
49
  if (c.req.method === "OPTIONS") {
50
50
  if (opts.origin !== "*") {
51
- set("Vary", "Origin");
51
+ c.res.headers.append("Vary", "Origin");
52
52
  }
53
53
  if (opts.maxAge != null) {
54
54
  set("Access-Control-Max-Age", opts.maxAge.toString());
@@ -2,7 +2,7 @@
2
2
  import { HTTPException } from "../../http-exception.js";
3
3
  var secFetchSiteValues = ["same-origin", "same-site", "none", "cross-site"];
4
4
  var isSecFetchSite = (value) => secFetchSiteValues.includes(value);
5
- var isSafeMethodRe = /^(GET|HEAD)$/;
5
+ var isSafeMethodRe = /^(GET|HEAD|OPTIONS)$/;
6
6
  var isRequestedByFormElementRe = /^\b(application\/x-www-form-urlencoded|multipart\/form-data|text\/plain)\b/i;
7
7
  var csrf = (options) => {
8
8
  const originHandler = ((optsOrigin) => {
@@ -38,7 +38,7 @@ var generateDigest = async (stream, generator) => {
38
38
  const requiredLength = chunkLength + remaining;
39
39
  if (requiredLength < CHUNK_SIZE) {
40
40
  if (!chunk) {
41
- chunk = value.subarray(offset);
41
+ chunk = value.slice(offset);
42
42
  } else {
43
43
  if (chunk.byteLength < requiredLength) {
44
44
  const nextChunk = new Uint8Array(
@@ -10,7 +10,7 @@ var RETAINED_304_HEADERS = [
10
10
  ];
11
11
  var stripWeak = (tag) => tag.replace(/^W\//, "");
12
12
  function etagMatches(etag2, ifNoneMatch) {
13
- return ifNoneMatch != null && ifNoneMatch.split(/,\s*/).some((t) => stripWeak(t) === stripWeak(etag2));
13
+ return ifNoneMatch != null && ifNoneMatch.split(",").some((t) => stripWeak(t.trim()) === stripWeak(etag2));
14
14
  }
15
15
  function initializeGenerator(generator) {
16
16
  if (!generator) {
@@ -60,11 +60,11 @@ var etag = (options) => {
60
60
  ETag: etag3
61
61
  }
62
62
  });
63
- c.res.headers.forEach((_, key) => {
63
+ for (const key of Array.from(c.res.headers.keys())) {
64
64
  if (retainedHeaders.indexOf(key.toLowerCase()) === -1) {
65
65
  c.res.headers.delete(key);
66
66
  }
67
- });
67
+ }
68
68
  } else {
69
69
  c.res.headers.set("ETag", etag3);
70
70
  }
@@ -1,10 +1,12 @@
1
1
  // src/middleware/pretty-json/index.ts
2
+ var jsonContentTypeRegex = /^application\/(?:[a-z0-9._-]+\+)?json(?=$|[;\s])/i;
2
3
  var prettyJSON = (options) => {
3
4
  const targetQuery = options?.query ?? "pretty";
4
5
  return async function prettyJSON2(c, next) {
5
6
  const pretty = options?.force || c.req.query(targetQuery) || c.req.query(targetQuery) === "";
6
7
  await next();
7
- if (pretty && c.res.headers.get("Content-Type")?.startsWith("application/json")) {
8
+ const contentType = c.res.headers.get("Content-Type");
9
+ if (pretty && contentType && jsonContentTypeRegex.test(contentType)) {
8
10
  const obj = await c.res.json();
9
11
  c.res = new Response(JSON.stringify(obj, null, options?.space ?? 2), c.res);
10
12
  }
@@ -46,13 +46,13 @@ var HonoRequest = class {
46
46
  return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams();
47
47
  }
48
48
  #getDecodedParam(key) {
49
- const paramKey = this.#matchResult[0][this.routeIndex][1][key];
49
+ const paramKey = this.#matchResult[0][this.routeIndex]?.[1][key];
50
50
  const param = this.#getParamValue(paramKey);
51
51
  return param && tryDecodeURIComponent(param);
52
52
  }
53
53
  #getAllDecodedParams() {
54
54
  const decoded = {};
55
- const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]);
55
+ const keys = Object.keys(this.#matchResult[0][this.routeIndex]?.[1] ?? {});
56
56
  for (const key of keys) {
57
57
  const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
58
58
  if (value !== void 0) {
@@ -292,10 +292,14 @@ var cloneRawRequest = async (req) => {
292
292
  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."
293
293
  });
294
294
  }
295
- const body = await req[cacheKey]();
295
+ let body = await req[cacheKey]();
296
296
  const headers = req.header();
297
- if (body instanceof FormData) {
297
+ if (cacheKey === "json") {
298
+ body = JSON.stringify(body);
299
+ delete headers["content-length"];
300
+ } else if (body instanceof FormData) {
298
301
  delete headers["content-type"];
302
+ delete headers["content-length"];
299
303
  }
300
304
  const requestInit = {
301
305
  body,
@@ -29,7 +29,8 @@ var LinearRouter = class {
29
29
  }
30
30
  } else if (hasStar && !hasLabel) {
31
31
  const endsWithStar = routePath.charCodeAt(routePath.length - 1) === 42;
32
- const parts = (endsWithStar ? routePath.slice(0, -2) : routePath).split(splitByStarRe);
32
+ const endsWithSlashStar = routePath.endsWith("/*");
33
+ const parts = (endsWithStar ? routePath.slice(0, endsWithSlashStar ? -2 : -1) : routePath).split(splitByStarRe);
33
34
  const lastIndex = parts.length - 1;
34
35
  for (let j = 0, pos = 0, len2 = parts.length; j < len2; j++) {
35
36
  const part = parts[j];
@@ -39,7 +40,11 @@ var LinearRouter = class {
39
40
  }
40
41
  pos += part.length;
41
42
  if (j === lastIndex) {
42
- if (!endsWithStar && pos !== path.length && !(pos === path.length - 1 && path.charCodeAt(pos) === 47)) {
43
+ if (endsWithSlashStar) {
44
+ if (pos !== path.length && path.charCodeAt(pos) !== 47) {
45
+ continue ROUTES_LOOP;
46
+ }
47
+ } else if (!endsWithStar && pos !== path.length && !(pos === path.length - 1 && path.charCodeAt(pos) === 47)) {
43
48
  continue ROUTES_LOOP;
44
49
  }
45
50
  } else {
@@ -5,10 +5,8 @@ var PatternRouter = class {
5
5
  name = "PatternRouter";
6
6
  #routes = [];
7
7
  add(method, path, handler) {
8
- const endsWithWildcard = path.at(-1) === "*";
9
- if (endsWithWildcard) {
10
- path = path.slice(0, -2);
11
- }
8
+ const suffix = path.endsWith("/*") ? "(?:$|/)" : path.endsWith("*") ? "" : "/?$";
9
+ path = path.replace(/\*$/, "");
12
10
  if (path.at(-1) === "?") {
13
11
  path = path.slice(0, -1);
14
12
  this.add(method, path.replace(/\/[^/]+$/, ""), handler);
@@ -20,11 +18,7 @@ var PatternRouter = class {
20
18
  }
21
19
  );
22
20
  try {
23
- this.#routes.push([
24
- new RegExp(`^${parts.join("")}${endsWithWildcard ? "" : "/?$"}`),
25
- method,
26
- handler
27
- ]);
21
+ this.#routes.push([new RegExp(`^${parts.join("")}${suffix}`), method, handler]);
28
22
  } catch {
29
23
  throw new UnsupportedPathError();
30
24
  }
@@ -1,4 +1,5 @@
1
1
  // src/router/reg-exp-router/node.ts
2
+ import { createNullObject } from "../utils.js";
2
3
  var LABEL_REG_EXP_STR = "[^/]+";
3
4
  var ONLY_WILDCARD_REG_EXP_STR = ".*";
4
5
  var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
@@ -27,7 +28,7 @@ var Node = class _Node {
27
28
  // handler index of a dynamic path, or -1 for a static path terminal
28
29
  #index;
29
30
  #varIndex;
30
- #children = /* @__PURE__ */ Object.create(null);
31
+ #children = createNullObject();
31
32
  insert(tokens, index, paramMap, context, isStatic) {
32
33
  let node = this;
33
34
  for (let i = 0, len = tokens.length; i < len; i++) {
@@ -105,6 +106,9 @@ var Node = class _Node {
105
106
  }
106
107
  };
107
108
  export {
109
+ LABEL_REG_EXP_STR,
108
110
  Node,
109
- PATH_ERROR
111
+ ONLY_WILDCARD_REG_EXP_STR,
112
+ PATH_ERROR,
113
+ TAIL_WILDCARD_REG_EXP_STR
110
114
  };
@@ -5,25 +5,25 @@ import {
5
5
  UnsupportedPathError
6
6
  } from "../../router.js";
7
7
  import { checkOptionalParameter } from "../../utils/url.js";
8
+ import { createNullObject } from "../utils.js";
8
9
  import { match, emptyParam } from "./matcher.js";
9
- import { PATH_ERROR } from "./node.js";
10
+ import {
11
+ LABEL_REG_EXP_STR,
12
+ ONLY_WILDCARD_REG_EXP_STR,
13
+ PATH_ERROR,
14
+ TAIL_WILDCARD_REG_EXP_STR
15
+ } from "./node.js";
10
16
  import { Trie } from "./trie.js";
11
- var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
17
+ var wildcardRegExpCache = createNullObject();
12
18
  function buildWildcardRegExp(path) {
13
19
  return wildcardRegExpCache[path] ??= new RegExp(
14
- path === "*" ? "" : `^${path.replace(
15
- /\/\*$|([.\\+*[^\]$()])/g,
16
- (_, metaChar) => metaChar ? `\\${metaChar}` : "(?:|/.*)"
20
+ `^${path.replace(
21
+ /\/:[^/{}]+(?:\{\[\^\/]\+})?(?=[/{]|$)|\/?\*$|([.\\+*[^\]$()?{}|])/g,
22
+ (match2, metaChar) => metaChar ? `\\${metaChar}` : match2 === "/*" ? TAIL_WILDCARD_REG_EXP_STR : match2 === "*" ? ONLY_WILDCARD_REG_EXP_STR : `/:${LABEL_REG_EXP_STR}`
17
23
  )}$`
18
24
  );
19
25
  }
20
- function clearWildcardRegExpCache() {
21
- wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
22
- }
23
26
  function findMiddleware(middleware, path) {
24
- if (!middleware) {
25
- return void 0;
26
- }
27
27
  for (const k of Object.keys(middleware).sort((a, b) => b.length - a.length)) {
28
28
  if (buildWildcardRegExp(k).test(path)) {
29
29
  return [...middleware[k]];
@@ -37,8 +37,8 @@ var RegExpRouter = class {
37
37
  #routes;
38
38
  #tries;
39
39
  constructor() {
40
- this.#middleware = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
41
- this.#routes = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
40
+ this.#middleware = { [METHOD_NAME_ALL]: createNullObject() };
41
+ this.#routes = { [METHOD_NAME_ALL]: createNullObject() };
42
42
  this.#tries = { [METHOD_NAME_ALL]: new Trie() };
43
43
  }
44
44
  #insertPath(method, path) {
@@ -51,117 +51,86 @@ var RegExpRouter = class {
51
51
  add(method, path, handler) {
52
52
  const middleware = this.#middleware;
53
53
  const routes = this.#routes;
54
- if (!middleware || !routes) {
54
+ if (!middleware) {
55
55
  throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
56
56
  }
57
57
  if (!middleware[method]) {
58
58
  this.#tries[method] = new Trie();
59
- [middleware, routes].forEach((handlerMap) => {
60
- handlerMap[method] = /* @__PURE__ */ Object.create(null);
61
- Object.keys(handlerMap[METHOD_NAME_ALL]).forEach((p) => {
59
+ for (const handlerMap of [middleware, routes]) {
60
+ handlerMap[method] = createNullObject();
61
+ for (const p in handlerMap[METHOD_NAME_ALL]) {
62
62
  handlerMap[method][p] = [...handlerMap[METHOD_NAME_ALL][p]];
63
63
  this.#insertPath(method, p);
64
- });
65
- });
64
+ }
65
+ }
66
66
  }
67
67
  if (path === "/*") {
68
68
  path = "*";
69
69
  }
70
- const paramCount = (path.match(/\/:/g) || []).length;
70
+ const methods = method === METHOD_NAME_ALL ? Object.keys(middleware) : [method];
71
71
  if (/\*$/.test(path)) {
72
72
  const re = buildWildcardRegExp(path);
73
- Object.keys(middleware).forEach((m) => {
74
- if ((method === METHOD_NAME_ALL || method === m) && !middleware[m][path]) {
73
+ for (const m of methods) {
74
+ if (!middleware[m][path]) {
75
75
  this.#insertPath(m, path);
76
76
  middleware[m][path] = findMiddleware(middleware[m], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
77
77
  }
78
- });
79
- Object.keys(middleware).forEach((m) => {
80
- if (method === METHOD_NAME_ALL || method === m) {
81
- Object.keys(middleware[m]).forEach((p) => {
82
- re.test(p) && middleware[m][p].push([handler, paramCount]);
83
- });
84
- }
85
- });
86
- Object.keys(routes).forEach((m) => {
87
- if (method === METHOD_NAME_ALL || method === m) {
88
- Object.keys(routes[m]).forEach(
89
- (p) => re.test(p) && routes[m][p].push([handler, paramCount])
90
- );
78
+ }
79
+ for (const handlerMap of [middleware, routes]) {
80
+ for (const m of methods) {
81
+ for (const p in handlerMap[m]) {
82
+ re.test(p) && handlerMap[m][p].push([handler, path]);
83
+ }
91
84
  }
92
- });
85
+ }
93
86
  return;
94
87
  }
95
88
  const paths = checkOptionalParameter(path) || [path];
96
- for (let i = 0, len = paths.length; i < len; i++) {
97
- const path2 = paths[i];
98
- Object.keys(routes).forEach((m) => {
99
- if (method === METHOD_NAME_ALL || method === m) {
100
- if (!routes[m][path2]) {
101
- this.#insertPath(m, path2);
102
- routes[m][path2] = [
103
- ...findMiddleware(middleware[m], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || []
104
- ];
105
- }
106
- routes[m][path2].push([handler, paramCount - len + i + 1]);
89
+ for (const path2 of paths) {
90
+ for (const m of methods) {
91
+ if (!routes[m][path2]) {
92
+ this.#insertPath(m, path2);
93
+ routes[m][path2] = findMiddleware(middleware[m], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || [];
107
94
  }
108
- });
95
+ routes[m][path2].push([handler, path2]);
96
+ }
109
97
  }
110
98
  }
111
99
  match = match;
112
100
  buildAllMatchers() {
113
- const matchers = /* @__PURE__ */ Object.create(null);
114
- Object.keys(this.#routes).concat(Object.keys(this.#middleware)).forEach((method) => {
115
- matchers[method] ||= this.#buildMatcher(method);
116
- });
101
+ const matchers = createNullObject();
102
+ for (const method of Object.keys(this.#routes)) {
103
+ matchers[method] = this.#buildMatcher(method);
104
+ }
117
105
  this.#middleware = this.#routes = this.#tries = void 0;
118
- clearWildcardRegExpCache();
106
+ wildcardRegExpCache = createNullObject();
119
107
  return matchers;
120
108
  }
121
109
  #buildMatcher(method) {
122
110
  const middleware = this.#middleware[method];
123
111
  const routes = this.#routes[method];
124
112
  const trie = this.#tries[method];
125
- const staticMap = /* @__PURE__ */ Object.create(null);
113
+ const staticMap = createNullObject();
126
114
  const handlerData = [];
127
- [middleware, routes].forEach((r) => {
115
+ const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
116
+ for (const r of [middleware, routes]) {
128
117
  for (const path in r) {
129
118
  const handlers = r[path];
130
119
  const pathData = trie.paths[path];
131
120
  if (!pathData) {
132
- staticMap[path] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
133
- continue;
134
- }
135
- const paramAssoc = pathData[1];
136
- handlerData[pathData[0]] = handlers.map(([h, paramCount]) => {
137
- const paramIndexMap = /* @__PURE__ */ Object.create(null);
138
- paramCount -= 1;
139
- for (; paramCount >= 0; paramCount--) {
140
- const [key, value] = paramAssoc[paramCount];
141
- paramIndexMap[key] = value;
142
- }
143
- return [h, paramIndexMap];
144
- });
145
- }
146
- });
147
- const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
148
- for (let i = 0, len = handlerData.length; i < len; i++) {
149
- for (let j = 0, len2 = handlerData[i].length; j < len2; j++) {
150
- const map = handlerData[i][j]?.[1];
151
- if (!map) {
121
+ staticMap[path] = [handlers.map(([h]) => [h, createNullObject()]), emptyParam];
152
122
  continue;
153
123
  }
154
- const keys = Object.keys(map);
155
- for (let k = 0, len3 = keys.length; k < len3; k++) {
156
- map[keys[k]] = paramReplacementMap[map[keys[k]]];
157
- }
124
+ handlerData[pathData[0]] = handlers.map(([h, handlerPath]) => [
125
+ h,
126
+ trie.paths[handlerPath][1].reduceRight((map, [key], i) => {
127
+ map[key] = paramReplacementMap[pathData[1][i][1]];
128
+ return map;
129
+ }, createNullObject())
130
+ ]);
158
131
  }
159
132
  }
160
- const handlerMap = [];
161
- for (const i in indexReplacementMap) {
162
- handlerMap[i] = handlerData[indexReplacementMap[i]];
163
- }
164
- return [regexp, handlerMap, staticMap];
133
+ return [regexp, indexReplacementMap.map((i) => handlerData[i]), staticMap];
165
134
  }
166
135
  };
167
136
  export {