@zuplo/cli 7.2.4 → 7.3.1

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 (50) hide show
  1. package/node_modules/@posthog/core/dist/error-tracking/parsers/base.d.ts.map +1 -1
  2. package/node_modules/@posthog/core/dist/error-tracking/parsers/base.js +2 -1
  3. package/node_modules/@posthog/core/dist/error-tracking/parsers/base.mjs +2 -1
  4. package/node_modules/@posthog/core/package.json +2 -2
  5. package/node_modules/@posthog/core/src/error-tracking/parsers/base.spec.ts +33 -0
  6. package/node_modules/@posthog/core/src/error-tracking/parsers/base.ts +9 -1
  7. package/node_modules/@posthog/types/dist/posthog-config.d.ts +12 -6
  8. package/node_modules/@posthog/types/dist/posthog-config.d.ts.map +1 -1
  9. package/node_modules/@posthog/types/package.json +1 -1
  10. package/node_modules/@posthog/types/src/posthog-config.ts +20 -6
  11. package/node_modules/@zuplo/core/package.json +1 -1
  12. package/node_modules/@zuplo/graphql/package.json +1 -1
  13. package/node_modules/@zuplo/openapi-tools/package.json +1 -1
  14. package/node_modules/@zuplo/otel/out/esm/chunk-6AFSG5YF.js +26 -0
  15. package/node_modules/@zuplo/otel/out/esm/chunk-6AFSG5YF.js.map +1 -0
  16. package/node_modules/@zuplo/otel/out/esm/index.js +1 -1
  17. package/node_modules/@zuplo/otel/out/types/index.d.ts +28 -5
  18. package/node_modules/@zuplo/otel/package.json +1 -1
  19. package/node_modules/@zuplo/runtime/package.json +1 -1
  20. package/node_modules/hono/dist/cjs/client/utils.js +1 -1
  21. package/node_modules/hono/dist/cjs/context.js +4 -0
  22. package/node_modules/hono/dist/cjs/middleware/cors/index.js +1 -1
  23. package/node_modules/hono/dist/cjs/middleware/csrf/index.js +1 -1
  24. package/node_modules/hono/dist/cjs/middleware/etag/digest.js +1 -1
  25. package/node_modules/hono/dist/cjs/middleware/etag/index.js +2 -2
  26. package/node_modules/hono/dist/cjs/middleware/pretty-json/index.js +3 -1
  27. package/node_modules/hono/dist/cjs/router/linear-router/router.js +7 -2
  28. package/node_modules/hono/dist/cjs/router/pattern-router/router.js +3 -9
  29. package/node_modules/hono/dist/cjs/router/trie-router/node.js +43 -67
  30. package/node_modules/hono/dist/cjs/router/trie-router/router.js +3 -11
  31. package/node_modules/hono/dist/cjs/utils/ipaddr.js +5 -3
  32. package/node_modules/hono/dist/client/utils.js +1 -1
  33. package/node_modules/hono/dist/context.js +4 -0
  34. package/node_modules/hono/dist/middleware/cors/index.js +1 -1
  35. package/node_modules/hono/dist/middleware/csrf/index.js +1 -1
  36. package/node_modules/hono/dist/middleware/etag/digest.js +1 -1
  37. package/node_modules/hono/dist/middleware/etag/index.js +2 -2
  38. package/node_modules/hono/dist/middleware/pretty-json/index.js +3 -1
  39. package/node_modules/hono/dist/router/linear-router/router.js +7 -2
  40. package/node_modules/hono/dist/router/pattern-router/router.js +3 -9
  41. package/node_modules/hono/dist/router/trie-router/node.js +43 -67
  42. package/node_modules/hono/dist/router/trie-router/router.js +3 -11
  43. package/node_modules/hono/dist/types/context.d.ts +4 -0
  44. package/node_modules/hono/dist/types/router/trie-router/node.d.ts +1 -2
  45. package/node_modules/hono/dist/types/router/trie-router/router.d.ts +0 -1
  46. package/node_modules/hono/dist/utils/ipaddr.js +5 -3
  47. package/node_modules/hono/package.json +1 -1
  48. package/package.json +6 -6
  49. package/node_modules/@zuplo/otel/out/esm/chunk-AHNBOCFU.js +0 -26
  50. package/node_modules/@zuplo/otel/out/esm/chunk-AHNBOCFU.js.map +0 -1
@@ -27,12 +27,19 @@ export declare class BatchTraceSpanProcessor implements TraceFlushableSpanProces
27
27
  readonly exporter: SpanExporter;
28
28
  private traces;
29
29
  private totalEvicted;
30
+ /**
31
+ * The key each span was filed under at `onStart`. `onEnd` receives only the
32
+ * span, and the key cannot be recomputed from it: the invocation lives in the
33
+ * context, which is not available there. A WeakMap keeps this from becoming a
34
+ * second thing to clean up — an entry disappears with the span itself.
35
+ */
36
+ private spanTraceKeys;
30
37
  constructor(exporter: SpanExporter);
31
- getTraceState(traceId: string): TraceState;
38
+ getTraceState(key: TraceStateKey): TraceState;
32
39
  private evictOverflow;
33
40
  onStart(span: Span, parentContext: Context): void;
34
41
  onEnd(span: ReadableSpan): void;
35
- forceFlush(traceId?: TraceId): Promise<void>;
42
+ forceFlush(key?: TraceStateKey): Promise<void>;
36
43
  shutdown(): Promise<void>;
37
44
  }
38
45
 
@@ -372,11 +379,20 @@ declare interface TraceConfigSpanProcessors extends TraceConfigBase {
372
379
  }
373
380
 
374
381
  declare type TraceFlushableSpanProcessor = SpanProcessor & {
375
- forceFlush: (traceId?: string) => Promise<void>;
382
+ /**
383
+ * Flushes one trace's buffered spans, or all of them when no key is given.
384
+ *
385
+ * The key is opaque and must be built with `traceStateKey(traceId,
386
+ * invocationId)` — its encoding is an implementation detail of
387
+ * `invocation.ts` and may change. Passing a bare traceId is correct only for
388
+ * spans started outside a handler run (background work, `root: true` outside
389
+ * the request context), which is what that helper returns when there is no
390
+ * invocation in context. See `invocation.ts` for why traceId alone is not
391
+ * sufficient in general.
392
+ */
393
+ forceFlush: (key?: string) => Promise<void>;
376
394
  };
377
395
 
378
- declare type TraceId = string;
379
-
380
396
  declare class TraceState {
381
397
  private unexportedSpans;
382
398
  private inprogressSpans;
@@ -395,6 +411,13 @@ declare class TraceState {
395
411
  private exportSpans;
396
412
  }
397
413
 
414
+ /**
415
+ * Key under which a trace's buffered state is held: the traceId plus the
416
+ * invocation that produced it, so concurrent requests sharing an inbound
417
+ * `traceparent` get one buffer each. See `invocation.ts`.
418
+ */
419
+ declare type TraceStateKey = string;
420
+
398
421
  /**
399
422
  * Span exporter that ships spans to the Zuplo-managed trace ingest, where they
400
423
  * become queryable in the Zuplo portal. Add it like any other exporter — wrap
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zuplo/otel",
3
3
  "type": "module",
4
- "version": "7.2.4",
4
+ "version": "7.3.1",
5
5
  "repository": "https://github.com/zuplo/zuplo",
6
6
  "author": "Zuplo, Inc.",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zuplo/runtime",
3
3
  "type": "module",
4
- "version": "7.2.4",
4
+ "version": "7.3.1",
5
5
  "repository": "https://github.com/zuplo/zuplo",
6
6
  "author": "Zuplo, Inc.",
7
7
  "exports": {
@@ -37,7 +37,7 @@ const mergePath = (base, path) => {
37
37
  const replaceUrlParam = (urlString, params) => {
38
38
  for (const [k, v] of Object.entries(params)) {
39
39
  const reg = new RegExp("/:" + k + "(?:{[^/]+})?\\??(?=/|$)");
40
- urlString = urlString.replace(reg, v ? `/${v}` : "");
40
+ urlString = urlString.replace(reg, () => v ? `/${v}` : "");
41
41
  }
42
42
  return urlString;
43
43
  };
@@ -224,6 +224,10 @@ class Context {
224
224
  * c.header('X-Message', 'Hello!')
225
225
  * c.header('Content-Type', 'text/plain')
226
226
  *
227
+ * // Append multiple headers using the append option (e.g. Vary)
228
+ * c.header('Vary', 'Accept-Encoding', { append: true })
229
+ * c.header('Vary', 'User-Agent', { append: true })
230
+ *
227
231
  * return c.body('Thank you for coming')
228
232
  * })
229
233
  * ```
@@ -69,7 +69,7 @@ const cors = (options) => {
69
69
  }
70
70
  if (c.req.method === "OPTIONS") {
71
71
  if (opts.origin !== "*") {
72
- set("Vary", "Origin");
72
+ c.res.headers.append("Vary", "Origin");
73
73
  }
74
74
  if (opts.maxAge != null) {
75
75
  set("Access-Control-Max-Age", opts.maxAge.toString());
@@ -23,7 +23,7 @@ module.exports = __toCommonJS(csrf_exports);
23
23
  var import_http_exception = require("../../http-exception");
24
24
  const secFetchSiteValues = ["same-origin", "same-site", "none", "cross-site"];
25
25
  const isSecFetchSite = (value) => secFetchSiteValues.includes(value);
26
- const isSafeMethodRe = /^(GET|HEAD)$/;
26
+ const isSafeMethodRe = /^(GET|HEAD|OPTIONS)$/;
27
27
  const isRequestedByFormElementRe = /^\b(application\/x-www-form-urlencoded|multipart\/form-data|text\/plain)\b/i;
28
28
  const csrf = (options) => {
29
29
  const originHandler = ((optsOrigin) => {
@@ -59,7 +59,7 @@ const generateDigest = async (stream, generator) => {
59
59
  const requiredLength = chunkLength + remaining;
60
60
  if (requiredLength < CHUNK_SIZE) {
61
61
  if (!chunk) {
62
- chunk = value.subarray(offset);
62
+ chunk = value.slice(offset);
63
63
  } else {
64
64
  if (chunk.byteLength < requiredLength) {
65
65
  const nextChunk = new Uint8Array(
@@ -82,11 +82,11 @@ const etag = (options) => {
82
82
  ETag: etag3
83
83
  }
84
84
  });
85
- c.res.headers.forEach((_, key) => {
85
+ for (const key of Array.from(c.res.headers.keys())) {
86
86
  if (retainedHeaders.indexOf(key.toLowerCase()) === -1) {
87
87
  c.res.headers.delete(key);
88
88
  }
89
- });
89
+ }
90
90
  } else {
91
91
  c.res.headers.set("ETag", etag3);
92
92
  }
@@ -20,12 +20,14 @@ __export(pretty_json_exports, {
20
20
  prettyJSON: () => prettyJSON
21
21
  });
22
22
  module.exports = __toCommonJS(pretty_json_exports);
23
+ const jsonContentTypeRegex = /^application\/(?:[a-z0-9._-]+\+)?json(?=$|[;\s])/i;
23
24
  const prettyJSON = (options) => {
24
25
  const targetQuery = options?.query ?? "pretty";
25
26
  return async function prettyJSON2(c, next) {
26
27
  const pretty = options?.force || c.req.query(targetQuery) || c.req.query(targetQuery) === "";
27
28
  await next();
28
- if (pretty && c.res.headers.get("Content-Type")?.startsWith("application/json")) {
29
+ const contentType = c.res.headers.get("Content-Type");
30
+ if (pretty && contentType && jsonContentTypeRegex.test(contentType)) {
29
31
  const obj = await c.res.json();
30
32
  c.res = new Response(JSON.stringify(obj, null, options?.space ?? 2), c.res);
31
33
  }
@@ -50,7 +50,8 @@ class LinearRouter {
50
50
  }
51
51
  } else if (hasStar && !hasLabel) {
52
52
  const endsWithStar = routePath.charCodeAt(routePath.length - 1) === 42;
53
- const parts = (endsWithStar ? routePath.slice(0, -2) : routePath).split(splitByStarRe);
53
+ const endsWithSlashStar = routePath.endsWith("/*");
54
+ const parts = (endsWithStar ? routePath.slice(0, endsWithSlashStar ? -2 : -1) : routePath).split(splitByStarRe);
54
55
  const lastIndex = parts.length - 1;
55
56
  for (let j = 0, pos = 0, len2 = parts.length; j < len2; j++) {
56
57
  const part = parts[j];
@@ -60,7 +61,11 @@ class LinearRouter {
60
61
  }
61
62
  pos += part.length;
62
63
  if (j === lastIndex) {
63
- if (!endsWithStar && pos !== path.length && !(pos === path.length - 1 && path.charCodeAt(pos) === 47)) {
64
+ if (endsWithSlashStar) {
65
+ if (pos !== path.length && path.charCodeAt(pos) !== 47) {
66
+ continue ROUTES_LOOP;
67
+ }
68
+ } else if (!endsWithStar && pos !== path.length && !(pos === path.length - 1 && path.charCodeAt(pos) === 47)) {
64
69
  continue ROUTES_LOOP;
65
70
  }
66
71
  } else {
@@ -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
  }
@@ -23,76 +23,51 @@ module.exports = __toCommonJS(node_exports);
23
23
  var import_router = require("../../router");
24
24
  var import_url = require("../../utils/url");
25
25
  const emptyParams = /* @__PURE__ */ Object.create(null);
26
- const hasChildren = (children) => {
27
- for (const _ in children) {
28
- return true;
29
- }
30
- return false;
31
- };
26
+ let order = 0;
32
27
  class Node {
33
- #methods;
34
- #children;
35
- #patterns;
36
- #order = 0;
28
+ #methods = [];
29
+ #children = /* @__PURE__ */ Object.create(null);
30
+ #patterns = [];
31
+ #pattern;
37
32
  #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
33
  insert(method, path, handler) {
49
- this.#order = ++this.#order;
50
34
  let curNode = this;
51
35
  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;
36
+ const possibleKeys = /* @__PURE__ */ new Set();
37
+ let i = 0;
38
+ for (const p of parts) {
39
+ const nextP = parts[++i];
40
+ const pattern = (0, import_url.getPattern)(p, nextP) || (nextP === void 0 && p && p.indexOf("*") === p.length - 1 ? p : null);
41
+ const isParam = Array.isArray(pattern);
42
+ const key = isParam ? pattern[0] : pattern || p;
43
+ const child = curNode.#children[key] ||= new Node();
44
+ if (pattern && !child.#pattern) {
45
+ child.#pattern = pattern;
46
+ curNode.#patterns.push(child);
64
47
  }
65
- curNode.#children[key] = new Node();
66
- if (pattern) {
67
- curNode.#patterns.push(pattern);
68
- possibleKeys.push(pattern[1]);
48
+ curNode = child;
49
+ if (isParam) {
50
+ possibleKeys.add(pattern[1]);
69
51
  }
70
- curNode = curNode.#children[key];
71
52
  }
72
53
  curNode.#methods.push({
73
54
  [method]: {
74
55
  handler,
75
- possibleKeys: possibleKeys.filter((v, i, a) => a.indexOf(v) === i),
76
- score: this.#order
56
+ possibleKeys: [...possibleKeys],
57
+ score: ++order
77
58
  }
78
59
  });
79
- return curNode;
80
60
  }
81
61
  #pushHandlerSets(handlerSets, node, method, nodeParams, params) {
82
62
  for (let i = 0, len = node.#methods.length; i < len; i++) {
83
63
  const m = node.#methods[i];
84
64
  const handlerSet = m[method] || m[import_router.METHOD_NAME_ALL];
85
- const processedSet = {};
86
- if (handlerSet !== void 0) {
65
+ if (handlerSet) {
87
66
  handlerSet.params = /* @__PURE__ */ Object.create(null);
88
67
  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
- }
68
+ for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
69
+ const key = handlerSet.possibleKeys[i2];
70
+ handlerSet.params[key] = params?.[key] && !i2 ? params[key] : nodeParams[key] ?? params?.[key];
96
71
  }
97
72
  }
98
73
  }
@@ -124,33 +99,33 @@ class Node {
124
99
  tempNodes.push(nextNode);
125
100
  }
126
101
  }
127
- for (let k = 0, len3 = node.#patterns.length; k < len3; k++) {
128
- const pattern = node.#patterns[k];
102
+ for (const child of node.#patterns) {
103
+ const pattern = child.#pattern;
129
104
  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);
105
+ if (typeof pattern === "string") {
106
+ if (pattern === "*" || part.startsWith(pattern.slice(0, -1))) {
107
+ this.#pushHandlerSets(handlerSets, child, method, node.#params);
108
+ if (pattern === "*") {
109
+ child.#params = params;
110
+ tempNodes.push(child);
111
+ }
136
112
  }
137
113
  continue;
138
114
  }
139
- const [key, name, matcher] = pattern;
140
- if (!part && !(matcher instanceof RegExp)) {
115
+ const [, name, matcher] = pattern;
116
+ if (!part && matcher === true) {
141
117
  continue;
142
118
  }
143
- const child = node.#children[key];
144
- if (matcher instanceof RegExp) {
145
- if (partOffsets === null) {
146
- partOffsets = new Array(len);
119
+ if (matcher !== true) {
120
+ if (!partOffsets) {
121
+ partOffsets = [];
147
122
  let offset = path[0] === "/" ? 1 : 0;
148
123
  for (let p = 0; p < len; p++) {
149
124
  partOffsets[p] = offset;
150
125
  offset += parts[p].length + 1;
151
126
  }
152
127
  }
153
- const restPathString = path.substring(partOffsets[i]);
128
+ const restPathString = path.slice(partOffsets[i]);
154
129
  const m = matcher.exec(restPathString);
155
130
  if (m) {
156
131
  params[name] = m[0];
@@ -164,11 +139,12 @@ class Node {
164
139
  params
165
140
  );
166
141
  }
167
- if (hasChildren(child.#children)) {
142
+ for (const _ in child.#children) {
168
143
  child.#params = params;
169
144
  const componentCount = m[0].match(/\//g)?.length ?? 0;
170
145
  const targetCurNodes = curNodesQueue[componentCount] ||= [];
171
146
  targetCurNodes.push(child);
147
+ break;
172
148
  }
173
149
  continue;
174
150
  }
@@ -196,7 +172,7 @@ class Node {
196
172
  const shifted = curNodesQueue.shift();
197
173
  curNodes = shifted ? tempNodes.concat(shifted) : tempNodes;
198
174
  }
199
- if (handlerSets.length > 1) {
175
+ if (handlerSets[1]) {
200
176
  handlerSets.sort((a, b) => {
201
177
  return a.score - b.score;
202
178
  });
@@ -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);
@@ -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++) {
@@ -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
  };
@@ -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
  * ```
@@ -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(
@@ -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
  }
@@ -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
  }