@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,10 +26,8 @@ class PatternRouter {
26
26
  name = "PatternRouter";
27
27
  #routes = [];
28
28
  add(method, path, handler) {
29
- const endsWithWildcard = path.at(-1) === "*";
30
- if (endsWithWildcard) {
31
- path = path.slice(0, -2);
32
- }
29
+ const suffix = path.endsWith("/*") ? "(?:$|/)" : path.endsWith("*") ? "" : "/?$";
30
+ path = path.replace(/\*$/, "");
33
31
  if (path.at(-1) === "?") {
34
32
  path = path.slice(0, -1);
35
33
  this.add(method, path.replace(/\/[^/]+$/, ""), handler);
@@ -41,11 +39,7 @@ class PatternRouter {
41
39
  }
42
40
  );
43
41
  try {
44
- this.#routes.push([
45
- new RegExp(`^${parts.join("")}${endsWithWildcard ? "" : "/?$"}`),
46
- method,
47
- handler
48
- ]);
42
+ this.#routes.push([new RegExp(`^${parts.join("")}${suffix}`), method, handler]);
49
43
  } catch {
50
44
  throw new import_router.UnsupportedPathError();
51
45
  }
@@ -17,10 +17,14 @@ var __copyProps = (to, from, except, desc) => {
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
  var node_exports = {};
19
19
  __export(node_exports, {
20
+ LABEL_REG_EXP_STR: () => LABEL_REG_EXP_STR,
20
21
  Node: () => Node,
21
- PATH_ERROR: () => PATH_ERROR
22
+ ONLY_WILDCARD_REG_EXP_STR: () => ONLY_WILDCARD_REG_EXP_STR,
23
+ PATH_ERROR: () => PATH_ERROR,
24
+ TAIL_WILDCARD_REG_EXP_STR: () => TAIL_WILDCARD_REG_EXP_STR
22
25
  });
23
26
  module.exports = __toCommonJS(node_exports);
27
+ var import_utils = require("../utils");
24
28
  const LABEL_REG_EXP_STR = "[^/]+";
25
29
  const ONLY_WILDCARD_REG_EXP_STR = ".*";
26
30
  const TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
@@ -49,7 +53,7 @@ class Node {
49
53
  // handler index of a dynamic path, or -1 for a static path terminal
50
54
  #index;
51
55
  #varIndex;
52
- #children = /* @__PURE__ */ Object.create(null);
56
+ #children = (0, import_utils.createNullObject)();
53
57
  insert(tokens, index, paramMap, context, isStatic) {
54
58
  let node = this;
55
59
  for (let i = 0, len = tokens.length; i < len; i++) {
@@ -128,6 +132,9 @@ class Node {
128
132
  }
129
133
  // Annotate the CommonJS export names for ESM import in node:
130
134
  0 && (module.exports = {
135
+ LABEL_REG_EXP_STR,
131
136
  Node,
132
- PATH_ERROR
137
+ ONLY_WILDCARD_REG_EXP_STR,
138
+ PATH_ERROR,
139
+ TAIL_WILDCARD_REG_EXP_STR
133
140
  });
@@ -22,25 +22,20 @@ __export(router_exports, {
22
22
  module.exports = __toCommonJS(router_exports);
23
23
  var import_router = require("../../router");
24
24
  var import_url = require("../../utils/url");
25
+ var import_utils = require("../utils");
25
26
  var import_matcher = require("./matcher");
26
27
  var import_node = require("./node");
27
28
  var import_trie = require("./trie");
28
- let wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
29
+ let wildcardRegExpCache = (0, import_utils.createNullObject)();
29
30
  function buildWildcardRegExp(path) {
30
31
  return wildcardRegExpCache[path] ??= new RegExp(
31
- path === "*" ? "" : `^${path.replace(
32
- /\/\*$|([.\\+*[^\]$()])/g,
33
- (_, metaChar) => metaChar ? `\\${metaChar}` : "(?:|/.*)"
32
+ `^${path.replace(
33
+ /\/:[^/{}]+(?:\{\[\^\/]\+})?(?=[/{]|$)|\/?\*$|([.\\+*[^\]$()?{}|])/g,
34
+ (match2, metaChar) => metaChar ? `\\${metaChar}` : match2 === "/*" ? import_node.TAIL_WILDCARD_REG_EXP_STR : match2 === "*" ? import_node.ONLY_WILDCARD_REG_EXP_STR : `/:${import_node.LABEL_REG_EXP_STR}`
34
35
  )}$`
35
36
  );
36
37
  }
37
- function clearWildcardRegExpCache() {
38
- wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
39
- }
40
38
  function findMiddleware(middleware, path) {
41
- if (!middleware) {
42
- return void 0;
43
- }
44
39
  for (const k of Object.keys(middleware).sort((a, b) => b.length - a.length)) {
45
40
  if (buildWildcardRegExp(k).test(path)) {
46
41
  return [...middleware[k]];
@@ -54,8 +49,8 @@ class RegExpRouter {
54
49
  #routes;
55
50
  #tries;
56
51
  constructor() {
57
- this.#middleware = { [import_router.METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
58
- this.#routes = { [import_router.METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
52
+ this.#middleware = { [import_router.METHOD_NAME_ALL]: (0, import_utils.createNullObject)() };
53
+ this.#routes = { [import_router.METHOD_NAME_ALL]: (0, import_utils.createNullObject)() };
59
54
  this.#tries = { [import_router.METHOD_NAME_ALL]: new import_trie.Trie() };
60
55
  }
61
56
  #insertPath(method, path) {
@@ -68,117 +63,86 @@ class RegExpRouter {
68
63
  add(method, path, handler) {
69
64
  const middleware = this.#middleware;
70
65
  const routes = this.#routes;
71
- if (!middleware || !routes) {
66
+ if (!middleware) {
72
67
  throw new Error(import_router.MESSAGE_MATCHER_IS_ALREADY_BUILT);
73
68
  }
74
69
  if (!middleware[method]) {
75
70
  this.#tries[method] = new import_trie.Trie();
76
- [middleware, routes].forEach((handlerMap) => {
77
- handlerMap[method] = /* @__PURE__ */ Object.create(null);
78
- Object.keys(handlerMap[import_router.METHOD_NAME_ALL]).forEach((p) => {
71
+ for (const handlerMap of [middleware, routes]) {
72
+ handlerMap[method] = (0, import_utils.createNullObject)();
73
+ for (const p in handlerMap[import_router.METHOD_NAME_ALL]) {
79
74
  handlerMap[method][p] = [...handlerMap[import_router.METHOD_NAME_ALL][p]];
80
75
  this.#insertPath(method, p);
81
- });
82
- });
76
+ }
77
+ }
83
78
  }
84
79
  if (path === "/*") {
85
80
  path = "*";
86
81
  }
87
- const paramCount = (path.match(/\/:/g) || []).length;
82
+ const methods = method === import_router.METHOD_NAME_ALL ? Object.keys(middleware) : [method];
88
83
  if (/\*$/.test(path)) {
89
84
  const re = buildWildcardRegExp(path);
90
- Object.keys(middleware).forEach((m) => {
91
- if ((method === import_router.METHOD_NAME_ALL || method === m) && !middleware[m][path]) {
85
+ for (const m of methods) {
86
+ if (!middleware[m][path]) {
92
87
  this.#insertPath(m, path);
93
88
  middleware[m][path] = findMiddleware(middleware[m], path) || findMiddleware(middleware[import_router.METHOD_NAME_ALL], path) || [];
94
89
  }
95
- });
96
- Object.keys(middleware).forEach((m) => {
97
- if (method === import_router.METHOD_NAME_ALL || method === m) {
98
- Object.keys(middleware[m]).forEach((p) => {
99
- re.test(p) && middleware[m][p].push([handler, paramCount]);
100
- });
101
- }
102
- });
103
- Object.keys(routes).forEach((m) => {
104
- if (method === import_router.METHOD_NAME_ALL || method === m) {
105
- Object.keys(routes[m]).forEach(
106
- (p) => re.test(p) && routes[m][p].push([handler, paramCount])
107
- );
90
+ }
91
+ for (const handlerMap of [middleware, routes]) {
92
+ for (const m of methods) {
93
+ for (const p in handlerMap[m]) {
94
+ re.test(p) && handlerMap[m][p].push([handler, path]);
95
+ }
108
96
  }
109
- });
97
+ }
110
98
  return;
111
99
  }
112
100
  const paths = (0, import_url.checkOptionalParameter)(path) || [path];
113
- for (let i = 0, len = paths.length; i < len; i++) {
114
- const path2 = paths[i];
115
- Object.keys(routes).forEach((m) => {
116
- if (method === import_router.METHOD_NAME_ALL || method === m) {
117
- if (!routes[m][path2]) {
118
- this.#insertPath(m, path2);
119
- routes[m][path2] = [
120
- ...findMiddleware(middleware[m], path2) || findMiddleware(middleware[import_router.METHOD_NAME_ALL], path2) || []
121
- ];
122
- }
123
- routes[m][path2].push([handler, paramCount - len + i + 1]);
101
+ for (const path2 of paths) {
102
+ for (const m of methods) {
103
+ if (!routes[m][path2]) {
104
+ this.#insertPath(m, path2);
105
+ routes[m][path2] = findMiddleware(middleware[m], path2) || findMiddleware(middleware[import_router.METHOD_NAME_ALL], path2) || [];
124
106
  }
125
- });
107
+ routes[m][path2].push([handler, path2]);
108
+ }
126
109
  }
127
110
  }
128
111
  match = import_matcher.match;
129
112
  buildAllMatchers() {
130
- const matchers = /* @__PURE__ */ Object.create(null);
131
- Object.keys(this.#routes).concat(Object.keys(this.#middleware)).forEach((method) => {
132
- matchers[method] ||= this.#buildMatcher(method);
133
- });
113
+ const matchers = (0, import_utils.createNullObject)();
114
+ for (const method of Object.keys(this.#routes)) {
115
+ matchers[method] = this.#buildMatcher(method);
116
+ }
134
117
  this.#middleware = this.#routes = this.#tries = void 0;
135
- clearWildcardRegExpCache();
118
+ wildcardRegExpCache = (0, import_utils.createNullObject)();
136
119
  return matchers;
137
120
  }
138
121
  #buildMatcher(method) {
139
122
  const middleware = this.#middleware[method];
140
123
  const routes = this.#routes[method];
141
124
  const trie = this.#tries[method];
142
- const staticMap = /* @__PURE__ */ Object.create(null);
125
+ const staticMap = (0, import_utils.createNullObject)();
143
126
  const handlerData = [];
144
- [middleware, routes].forEach((r) => {
127
+ const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
128
+ for (const r of [middleware, routes]) {
145
129
  for (const path in r) {
146
130
  const handlers = r[path];
147
131
  const pathData = trie.paths[path];
148
132
  if (!pathData) {
149
- staticMap[path] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), import_matcher.emptyParam];
133
+ staticMap[path] = [handlers.map(([h]) => [h, (0, import_utils.createNullObject)()]), import_matcher.emptyParam];
150
134
  continue;
151
135
  }
152
- const paramAssoc = pathData[1];
153
- handlerData[pathData[0]] = handlers.map(([h, paramCount]) => {
154
- const paramIndexMap = /* @__PURE__ */ Object.create(null);
155
- paramCount -= 1;
156
- for (; paramCount >= 0; paramCount--) {
157
- const [key, value] = paramAssoc[paramCount];
158
- paramIndexMap[key] = value;
159
- }
160
- return [h, paramIndexMap];
161
- });
136
+ handlerData[pathData[0]] = handlers.map(([h, handlerPath]) => [
137
+ h,
138
+ trie.paths[handlerPath][1].reduceRight((map, [key], i) => {
139
+ map[key] = paramReplacementMap[pathData[1][i][1]];
140
+ return map;
141
+ }, (0, import_utils.createNullObject)())
142
+ ]);
162
143
  }
163
- });
164
- const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
165
- for (let i = 0, len = handlerData.length; i < len; i++) {
166
- for (let j = 0, len2 = handlerData[i].length; j < len2; j++) {
167
- const map = handlerData[i][j]?.[1];
168
- if (!map) {
169
- continue;
170
- }
171
- const keys = Object.keys(map);
172
- for (let k = 0, len3 = keys.length; k < len3; k++) {
173
- map[keys[k]] = paramReplacementMap[map[keys[k]]];
174
- }
175
- }
176
- }
177
- const handlerMap = [];
178
- for (const i in indexReplacementMap) {
179
- handlerMap[i] = handlerData[indexReplacementMap[i]];
180
144
  }
181
- return [regexp, handlerMap, staticMap];
145
+ return [regexp, indexReplacementMap.map((i) => handlerData[i]), staticMap];
182
146
  }
183
147
  }
184
148
  // Annotate the CommonJS export names for ESM import in node:
@@ -20,13 +20,14 @@ __export(trie_exports, {
20
20
  Trie: () => Trie
21
21
  });
22
22
  module.exports = __toCommonJS(trie_exports);
23
+ var import_utils = require("../utils");
23
24
  var import_node = require("./node");
24
25
  class Trie {
25
26
  #context = { varIndex: 0 };
26
27
  #root = new import_node.Node();
27
28
  #index = 0;
28
29
  // dynamic path -> [handler index, param assoc]; static paths are not registered
29
- paths = /* @__PURE__ */ Object.create(null);
30
+ paths = (0, import_utils.createNullObject)();
30
31
  insert(path, isStatic) {
31
32
  if (isStatic) {
32
33
  this.#root.insert(path.split(""), 0, [], this.#context, true);
@@ -22,77 +22,53 @@ __export(node_exports, {
22
22
  module.exports = __toCommonJS(node_exports);
23
23
  var import_router = require("../../router");
24
24
  var import_url = require("../../utils/url");
25
- const emptyParams = /* @__PURE__ */ Object.create(null);
26
- const hasChildren = (children) => {
27
- for (const _ in children) {
28
- return true;
29
- }
30
- return false;
31
- };
25
+ var import_utils = require("../utils");
26
+ const emptyParams = (0, import_utils.createNullObject)();
27
+ let order = 0;
32
28
  class Node {
33
- #methods;
34
- #children;
35
- #patterns;
36
- #order = 0;
29
+ #methods = [];
30
+ #children = (0, import_utils.createNullObject)();
31
+ #patterns = [];
32
+ #pattern;
37
33
  #params = emptyParams;
38
- constructor(method, handler, children) {
39
- this.#children = children || /* @__PURE__ */ Object.create(null);
40
- this.#methods = [];
41
- if (method && handler) {
42
- const m = /* @__PURE__ */ Object.create(null);
43
- m[method] = { handler, possibleKeys: [], score: 0 };
44
- this.#methods = [m];
45
- }
46
- this.#patterns = [];
47
- }
48
34
  insert(method, path, handler) {
49
- this.#order = ++this.#order;
50
35
  let curNode = this;
51
36
  const parts = (0, import_url.splitRoutingPath)(path);
52
- const possibleKeys = [];
53
- for (let i = 0, len = parts.length; i < len; i++) {
54
- const p = parts[i];
55
- const nextP = parts[i + 1];
56
- const pattern = (0, import_url.getPattern)(p, nextP);
57
- const key = Array.isArray(pattern) ? pattern[0] : p;
58
- if (key in curNode.#children) {
59
- curNode = curNode.#children[key];
60
- if (pattern) {
61
- possibleKeys.push(pattern[1]);
62
- }
63
- continue;
37
+ const possibleKeys = /* @__PURE__ */ new Set();
38
+ let i = 0;
39
+ for (const p of parts) {
40
+ const nextP = parts[++i];
41
+ const pattern = (0, import_url.getPattern)(p, nextP) || (nextP === void 0 && p && p.indexOf("*") === p.length - 1 ? p : null);
42
+ const isParam = Array.isArray(pattern);
43
+ const key = isParam ? pattern[0] : pattern || p;
44
+ const child = curNode.#children[key] ||= new Node();
45
+ if (pattern && !child.#pattern) {
46
+ child.#pattern = pattern;
47
+ curNode.#patterns.push(child);
64
48
  }
65
- curNode.#children[key] = new Node();
66
- if (pattern) {
67
- curNode.#patterns.push(pattern);
68
- possibleKeys.push(pattern[1]);
49
+ curNode = child;
50
+ if (isParam) {
51
+ possibleKeys.add(pattern[1]);
69
52
  }
70
- curNode = curNode.#children[key];
71
53
  }
72
54
  curNode.#methods.push({
73
55
  [method]: {
74
56
  handler,
75
- possibleKeys: possibleKeys.filter((v, i, a) => a.indexOf(v) === i),
76
- score: this.#order
57
+ possibleKeys: [...possibleKeys],
58
+ score: ++order
77
59
  }
78
60
  });
79
- return curNode;
80
61
  }
81
62
  #pushHandlerSets(handlerSets, node, method, nodeParams, params) {
82
63
  for (let i = 0, len = node.#methods.length; i < len; i++) {
83
64
  const m = node.#methods[i];
84
65
  const handlerSet = m[method] || m[import_router.METHOD_NAME_ALL];
85
- const processedSet = {};
86
- if (handlerSet !== void 0) {
87
- handlerSet.params = /* @__PURE__ */ Object.create(null);
66
+ if (handlerSet) {
67
+ handlerSet.params = (0, import_utils.createNullObject)();
88
68
  handlerSets.push(handlerSet);
89
- if (nodeParams !== emptyParams || params && params !== emptyParams) {
90
- for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
91
- const key = handlerSet.possibleKeys[i2];
92
- const processed = processedSet[handlerSet.score];
93
- handlerSet.params[key] = params?.[key] && !processed ? params[key] : nodeParams[key] ?? params?.[key];
94
- processedSet[handlerSet.score] = true;
95
- }
69
+ for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
70
+ const key = handlerSet.possibleKeys[i2];
71
+ handlerSet.params[key] = params?.[key] && !i2 ? params[key] : nodeParams[key] ?? params?.[key];
96
72
  }
97
73
  }
98
74
  }
@@ -124,33 +100,33 @@ class Node {
124
100
  tempNodes.push(nextNode);
125
101
  }
126
102
  }
127
- for (let k = 0, len3 = node.#patterns.length; k < len3; k++) {
128
- const pattern = node.#patterns[k];
103
+ for (const child of node.#patterns) {
104
+ const pattern = child.#pattern;
129
105
  const params = node.#params === emptyParams ? {} : { ...node.#params };
130
- if (pattern === "*") {
131
- const astNode = node.#children["*"];
132
- if (astNode) {
133
- this.#pushHandlerSets(handlerSets, astNode, method, node.#params);
134
- astNode.#params = params;
135
- tempNodes.push(astNode);
106
+ if (typeof pattern === "string") {
107
+ if (pattern === "*" || part.startsWith(pattern.slice(0, -1))) {
108
+ this.#pushHandlerSets(handlerSets, child, method, node.#params);
109
+ if (pattern === "*") {
110
+ child.#params = params;
111
+ tempNodes.push(child);
112
+ }
136
113
  }
137
114
  continue;
138
115
  }
139
- const [key, name, matcher] = pattern;
140
- if (!part && !(matcher instanceof RegExp)) {
116
+ const [, name, matcher] = pattern;
117
+ if (!part && matcher === true) {
141
118
  continue;
142
119
  }
143
- const child = node.#children[key];
144
- if (matcher instanceof RegExp) {
145
- if (partOffsets === null) {
146
- partOffsets = new Array(len);
120
+ if (matcher !== true) {
121
+ if (!partOffsets) {
122
+ partOffsets = [];
147
123
  let offset = path[0] === "/" ? 1 : 0;
148
124
  for (let p = 0; p < len; p++) {
149
125
  partOffsets[p] = offset;
150
126
  offset += parts[p].length + 1;
151
127
  }
152
128
  }
153
- const restPathString = path.substring(partOffsets[i]);
129
+ const restPathString = path.slice(partOffsets[i]);
154
130
  const m = matcher.exec(restPathString);
155
131
  if (m) {
156
132
  params[name] = m[0];
@@ -164,11 +140,12 @@ class Node {
164
140
  params
165
141
  );
166
142
  }
167
- if (hasChildren(child.#children)) {
143
+ for (const _ in child.#children) {
168
144
  child.#params = params;
169
145
  const componentCount = m[0].match(/\//g)?.length ?? 0;
170
146
  const targetCurNodes = curNodesQueue[componentCount] ||= [];
171
147
  targetCurNodes.push(child);
148
+ break;
172
149
  }
173
150
  continue;
174
151
  }
@@ -196,7 +173,7 @@ class Node {
196
173
  const shifted = curNodesQueue.shift();
197
174
  curNodes = shifted ? tempNodes.concat(shifted) : tempNodes;
198
175
  }
199
- if (handlerSets.length > 1) {
176
+ if (handlerSets[1]) {
200
177
  handlerSets.sort((a, b) => {
201
178
  return a.score - b.score;
202
179
  });
@@ -24,19 +24,11 @@ var import_url = require("../../utils/url");
24
24
  var import_node = require("./node");
25
25
  class TrieRouter {
26
26
  name = "TrieRouter";
27
- #node;
28
- constructor() {
29
- this.#node = new import_node.Node();
30
- }
27
+ #node = new import_node.Node();
31
28
  add(method, path, handler) {
32
- const results = (0, import_url.checkOptionalParameter)(path);
33
- if (results) {
34
- for (let i = 0, len = results.length; i < len; i++) {
35
- this.#node.insert(method, results[i], handler);
36
- }
37
- return;
29
+ for (const result of (0, import_url.checkOptionalParameter)(path) || [path]) {
30
+ this.#node.insert(method, result, handler);
38
31
  }
39
- this.#node.insert(method, path, handler);
40
32
  }
41
33
  match(method, path) {
42
34
  return this.#node.search(method, path);
@@ -0,0 +1,27 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var utils_exports = {};
19
+ __export(utils_exports, {
20
+ createNullObject: () => createNullObject
21
+ });
22
+ module.exports = __toCommonJS(utils_exports);
23
+ const createNullObject = () => /* @__PURE__ */ Object.create(null);
24
+ // Annotate the CommonJS export names for ESM import in node:
25
+ 0 && (module.exports = {
26
+ createNullObject
27
+ });
@@ -21,6 +21,8 @@ __export(body_exports, {
21
21
  });
22
22
  module.exports = __toCommonJS(body_exports);
23
23
  var import_buffer = require("./buffer");
24
+ const MAX_NESTING_DEPTH = 32;
25
+ const MAX_NESTED_OBJECTS = 1e4;
24
26
  const isRawRequest = (request) => "headers" in request;
25
27
  const parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
26
28
  const { all = false, dot = false } = options;
@@ -53,6 +55,7 @@ async function parseFormData(request, options) {
53
55
  }
54
56
  function convertFormDataToBodyData(formData, options) {
55
57
  const form = /* @__PURE__ */ Object.create(null);
58
+ const nestingState = { count: 0 };
56
59
  formData.forEach((value, key) => {
57
60
  const shouldParseAllValues = options.all || key.endsWith("[]");
58
61
  if (!shouldParseAllValues) {
@@ -65,7 +68,7 @@ function convertFormDataToBodyData(formData, options) {
65
68
  Object.entries(form).forEach(([key, value]) => {
66
69
  const shouldParseDotValues = key.includes(".");
67
70
  if (shouldParseDotValues) {
68
- handleParsingNestedValues(form, key, value);
71
+ handleParsingNestedValues(form, key, value, nestingState);
69
72
  delete form[key];
70
73
  }
71
74
  });
@@ -88,23 +91,32 @@ const handleParsingAllValues = (form, key, value) => {
88
91
  }
89
92
  }
90
93
  };
91
- const handleParsingNestedValues = (form, key, value) => {
94
+ const handleParsingNestedValues = (form, key, value, state) => {
92
95
  if (/(?:^|\.)__proto__\./.test(key)) {
93
96
  return;
94
97
  }
95
98
  let nestedForm = form;
96
- const keys = key.split(".");
99
+ const keys = key.split(".", MAX_NESTING_DEPTH + 2);
100
+ if (keys.length > MAX_NESTING_DEPTH + 1) {
101
+ throwNestingLimitExceeded();
102
+ }
97
103
  keys.forEach((key2, index) => {
98
104
  if (index === keys.length - 1) {
99
105
  nestedForm[key2] = value;
100
106
  } else {
101
107
  if (!nestedForm[key2] || typeof nestedForm[key2] !== "object" || Array.isArray(nestedForm[key2]) || nestedForm[key2] instanceof File) {
108
+ if (state.count++ >= MAX_NESTED_OBJECTS) {
109
+ throwNestingLimitExceeded();
110
+ }
102
111
  nestedForm[key2] = /* @__PURE__ */ Object.create(null);
103
112
  }
104
113
  nestedForm = nestedForm[key2];
105
114
  }
106
115
  });
107
116
  };
117
+ const throwNestingLimitExceeded = () => {
118
+ throw new Error("Nesting limit exceeded");
119
+ };
108
120
  // Annotate the CommonJS export names for ESM import in node:
109
121
  0 && (module.exports = {
110
122
  parseBody
@@ -101,7 +101,7 @@ const parseSigned = async (cookie, secret, name) => {
101
101
  const secretKey = await getCryptoKey(secret);
102
102
  for (const [key, value] of Object.entries(parse(cookie, name))) {
103
103
  const signatureStartPos = value.lastIndexOf(".");
104
- if (signatureStartPos < 1) {
104
+ if (signatureStartPos < 0) {
105
105
  continue;
106
106
  }
107
107
  const signedValue = value.substring(0, signatureStartPos);
@@ -30,12 +30,14 @@ __export(ipaddr_exports, {
30
30
  module.exports = __toCommonJS(ipaddr_exports);
31
31
  const expandIPv6 = (ipV6) => {
32
32
  const sections = ipV6.split(":");
33
- if (IPV4_REGEX.test(sections.at(-1))) {
33
+ const lastSection = sections.at(-1);
34
+ if (IPV4_REGEX.test(lastSection)) {
35
+ const octets = lastSection.split(".").map(Number);
34
36
  sections.splice(
35
37
  -1,
36
38
  1,
37
- ...convertIPv6BinaryToString(convertIPv4ToBinary(sections.at(-1))).substring(2).split(":")
38
- // => ['7f00', '0001']
39
+ (octets[0] << 8 | octets[1]).toString(16),
40
+ (octets[2] << 8 | octets[3]).toString(16)
39
41
  );
40
42
  }
41
43
  for (let i = 0; i < sections.length; i++) {
@@ -96,7 +96,13 @@ class StreamingApi {
96
96
  abort() {
97
97
  if (!this.aborted) {
98
98
  this.aborted = true;
99
- this.abortSubscribers.forEach((subscriber) => subscriber());
99
+ this.abortSubscribers.forEach((subscriber) => {
100
+ try {
101
+ void Promise.resolve(subscriber()).catch(() => {
102
+ });
103
+ } catch {
104
+ }
105
+ });
100
106
  }
101
107
  }
102
108
  }
@@ -119,7 +119,11 @@ const getPath = (request) => {
119
119
  };
120
120
  const getQueryStrings = (url) => {
121
121
  const queryIndex = url.indexOf("?", 8);
122
- return queryIndex === -1 ? "" : "?" + url.slice(queryIndex + 1);
122
+ if (queryIndex === -1) {
123
+ return "";
124
+ }
125
+ const hashIndex = url.indexOf("#", 8);
126
+ return hashIndex === -1 ? url.slice(queryIndex) : queryIndex < hashIndex ? url.slice(queryIndex, hashIndex) : "";
123
127
  };
124
128
  const getPathNoStrict = (request) => {
125
129
  const result = getPath(request);
@@ -166,6 +170,10 @@ const _decodeURI = (value) => {
166
170
  return tryDecodeURIComponent(value);
167
171
  };
168
172
  const _getQueryParam = (url, key, multiple) => {
173
+ const hashIndex = url.indexOf("#", 8);
174
+ if (hashIndex !== -1) {
175
+ url = url.slice(0, hashIndex);
176
+ }
169
177
  let encoded;
170
178
  if (!multiple && key && key.indexOf("%") === -1 && key.indexOf("+") === -1) {
171
179
  let keyIndex2 = url.indexOf("?", 8);