hono 4.3.5 → 4.3.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.
@@ -62,8 +62,12 @@ const cache = (options) => {
62
62
  }
63
63
  };
64
64
  return async function cache2(c, next) {
65
- const key = c.req.url;
66
- const cache3 = await caches.open(options.cacheName);
65
+ let key = c.req.url;
66
+ if (options.keyGenerator) {
67
+ key = await options.keyGenerator(c);
68
+ }
69
+ const cacheName = typeof options.cacheName === "function" ? await options.cacheName(c) : options.cacheName;
70
+ const cache3 = await caches.open(cacheName);
67
71
  const response = await cache3.match(key);
68
72
  if (response) {
69
73
  return new Response(response.body, response);
@@ -33,6 +33,9 @@ class MockCache {
33
33
  async match(key) {
34
34
  return this.store.get(key) || null;
35
35
  }
36
+ async keys() {
37
+ return this.store.keys();
38
+ }
36
39
  async put(key, response) {
37
40
  this.store.set(key, response);
38
41
  }
@@ -51,11 +51,11 @@ function convertFormDataToBodyData(formData, options) {
51
51
  }
52
52
  const handleParsingAllValues = (form, key, value) => {
53
53
  const formKey = form[key];
54
- if (form[key] && Array.isArray(form[key])) {
55
- formKey.push(value);
56
- } else if (form[key]) {
57
- const parsedKey = [...formKey].join("").replace(",", "");
58
- form[key] = [parsedKey, value];
54
+ if (formKey && Array.isArray(formKey)) {
55
+ ;
56
+ form[key].push(value);
57
+ } else if (formKey) {
58
+ form[key] = [formKey, value];
59
59
  } else {
60
60
  form[key] = value;
61
61
  }
@@ -40,8 +40,12 @@ var cache = (options) => {
40
40
  }
41
41
  };
42
42
  return async function cache2(c, next) {
43
- const key = c.req.url;
44
- const cache3 = await caches.open(options.cacheName);
43
+ let key = c.req.url;
44
+ if (options.keyGenerator) {
45
+ key = await options.keyGenerator(c);
46
+ }
47
+ const cacheName = typeof options.cacheName === "function" ? await options.cacheName(c) : options.cacheName;
48
+ const cache3 = await caches.open(cacheName);
45
49
  const response = await cache3.match(key);
46
50
  if (response) {
47
51
  return new Response(response.body, response);
@@ -15,6 +15,9 @@ var MockCache = class {
15
15
  async match(key) {
16
16
  return this.store.get(key) || null;
17
17
  }
18
+ async keys() {
19
+ return this.store.keys();
20
+ }
18
21
  async put(key, response) {
19
22
  this.store.set(key, response);
20
23
  }
@@ -1,7 +1,9 @@
1
+ import type { Context } from '../../context';
1
2
  import type { MiddlewareHandler } from '../../types';
2
3
  export declare const cache: (options: {
3
- cacheName: string;
4
- wait?: boolean;
5
- cacheControl?: string;
6
- vary?: string | string[];
4
+ cacheName: string | ((c: Context) => Promise<string> | string);
5
+ wait?: boolean | undefined;
6
+ cacheControl?: string | undefined;
7
+ vary?: string | string[] | undefined;
8
+ keyGenerator?: ((c: Context) => Promise<string> | string) | undefined;
7
9
  }) => MiddlewareHandler;
@@ -29,11 +29,11 @@ function convertFormDataToBodyData(formData, options) {
29
29
  }
30
30
  var handleParsingAllValues = (form, key, value) => {
31
31
  const formKey = form[key];
32
- if (form[key] && Array.isArray(form[key])) {
33
- formKey.push(value);
34
- } else if (form[key]) {
35
- const parsedKey = [...formKey].join("").replace(",", "");
36
- form[key] = [parsedKey, value];
32
+ if (formKey && Array.isArray(formKey)) {
33
+ ;
34
+ form[key].push(value);
35
+ } else if (formKey) {
36
+ form[key] = [formKey, value];
37
37
  } else {
38
38
  form[key] = value;
39
39
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "4.3.5",
3
+ "version": "4.3.6",
4
4
  "description": "Ultrafast web framework for the Edges",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",