hono 4.3.4 → 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.
@@ -115,7 +115,9 @@ const createCssContext = ({ id }) => {
115
115
  Style: Style2
116
116
  };
117
117
  };
118
- const defaultContext = createCssContext({ id: import_common.DEFAULT_STYLE_ID });
118
+ const defaultContext = createCssContext({
119
+ id: import_common.DEFAULT_STYLE_ID
120
+ });
119
121
  const css = defaultContext.css;
120
122
  const cx = defaultContext.cx;
121
123
  const keyframes = defaultContext.keyframes;
@@ -220,8 +220,8 @@ class Hono extends defineDynamicClass() {
220
220
  }
221
221
  })();
222
222
  }
223
- fetch = (request, Env, executionCtx) => {
224
- return this.dispatch(request, executionCtx, Env, request.method);
223
+ fetch = (request, ...rest) => {
224
+ return this.dispatch(request, rest[1], rest[0], request.method);
225
225
  };
226
226
  request = (input, requestInit, Env, executionCtx) => {
227
227
  if (input instanceof Request) {
@@ -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
  }
package/dist/context.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/context.ts
2
- import { resolveCallback, HtmlEscapedCallbackPhase } from "./utils/html.js";
2
+ import { HtmlEscapedCallbackPhase, resolveCallback } from "./utils/html.js";
3
3
  var TEXT_PLAIN = "text/plain; charset=UTF-8";
4
4
  var setHeaders = (headers, map = {}) => {
5
5
  Object.entries(map).forEach(([key, value]) => headers.set(key, value));
@@ -98,7 +98,9 @@ var createCssContext = ({ id }) => {
98
98
  Style: Style2
99
99
  };
100
100
  };
101
- var defaultContext = createCssContext({ id: DEFAULT_STYLE_ID });
101
+ var defaultContext = createCssContext({
102
+ id: DEFAULT_STYLE_ID
103
+ });
102
104
  var css = defaultContext.css;
103
105
  var cx = defaultContext.cx;
104
106
  var keyframes = defaultContext.keyframes;
package/dist/hono-base.js CHANGED
@@ -197,8 +197,8 @@ var Hono = class extends defineDynamicClass() {
197
197
  }
198
198
  })();
199
199
  }
200
- fetch = (request, Env, executionCtx) => {
201
- return this.dispatch(request, executionCtx, Env, request.method);
200
+ fetch = (request, ...rest) => {
201
+ return this.dispatch(request, rest[1], rest[0], request.method);
202
202
  };
203
203
  request = (input, requestInit, Env, executionCtx) => {
204
204
  if (input instanceof Request) {
@@ -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,5 +1,5 @@
1
1
  import type { HonoRequest } from './request';
2
- import type { Env, FetchEventLike, NotFoundHandler, Input, TypedResponse } from './types';
2
+ import type { Env, FetchEventLike, Input, NotFoundHandler, TypedResponse } from './types';
3
3
  import type { RedirectStatusCode, StatusCode } from './utils/http-status';
4
4
  import type { JSONValue, JSONParsed, IsAny, Simplify } from './utils/types';
5
5
  type HeaderRecord = Record<string, string | string[]>;
@@ -37,8 +37,8 @@ interface TextRespond {
37
37
  <T extends string, U extends StatusCode>(text: T, init?: ResponseInit): Response & TypedResponse<T, U, 'text'>;
38
38
  }
39
39
  interface JSONRespond {
40
- <T extends JSONValue | Simplify<any>, U extends StatusCode>(object: T, status?: U, headers?: HeaderRecord): Response & TypedResponse<Simplify<T> extends JSONValue ? JSONValue extends Simplify<T> ? never : JSONParsed<T> : never, U, 'json'>;
41
- <T extends JSONValue | Simplify<any>, U extends StatusCode>(object: Simplify<T> extends JSONValue ? T : Simplify<T>, init?: ResponseInit): Response & TypedResponse<Simplify<T> extends JSONValue ? JSONValue extends Simplify<T> ? never : JSONParsed<T> : never, U, 'json'>;
40
+ <T extends JSONValue | Simplify<unknown>, U extends StatusCode>(object: T, status?: U, headers?: HeaderRecord): Response & TypedResponse<Simplify<T> extends JSONValue ? JSONValue extends Simplify<T> ? never : JSONParsed<T> : never, U, 'json'>;
41
+ <T extends JSONValue | Simplify<unknown>, U extends StatusCode>(object: Simplify<T> extends JSONValue ? T : Simplify<T>, init?: ResponseInit): Response & TypedResponse<Simplify<T> extends JSONValue ? JSONValue extends Simplify<T> ? never : JSONParsed<T> : never, U, 'json'>;
42
42
  }
43
43
  interface HTMLRespond {
44
44
  (html: string | Promise<string>, status?: StatusCode, headers?: HeaderRecord): Response | Promise<Response>;
@@ -114,7 +114,7 @@ export declare class Context<E extends Env = any, P extends string = any, I exte
114
114
  render: Renderer;
115
115
  setLayout: (layout: Layout<PropsForRenderer & {
116
116
  Layout: Layout;
117
- }>) => Layout<{
117
+ }>) => Layout<PropsForRenderer & {
118
118
  Layout: Layout;
119
119
  }>;
120
120
  getLayout: () => Layout<{
@@ -13,11 +13,7 @@ export interface acceptsConfig {
13
13
  export interface acceptsOptions extends acceptsConfig {
14
14
  match?: (accepts: Accept[], config: acceptsConfig) => string;
15
15
  }
16
- export declare const parseAccept: (acceptHeader: string) => {
17
- type: string;
18
- params: {};
19
- q: number;
20
- }[];
16
+ export declare const parseAccept: (acceptHeader: string) => Accept[];
21
17
  export declare const defaultMatch: (accepts: Accept[], config: acceptsConfig) => string;
22
18
  /**
23
19
  * Match the accept header with the given options.
@@ -1,4 +1,4 @@
1
1
  import type { Context } from '../../context';
2
2
  export type Runtime = 'node' | 'deno' | 'bun' | 'workerd' | 'fastly' | 'edge-light' | 'other';
3
3
  export declare const env: <T extends Record<string, unknown>, C extends Context<any, any, {}> = Context<{}, any, {}>>(c: C, runtime?: Runtime) => T & C["env"];
4
- export declare const getRuntimeKey: () => "other" | "node" | "deno" | "bun" | "workerd" | "fastly" | "edge-light";
4
+ export declare const getRuntimeKey: () => Runtime;
@@ -2,6 +2,25 @@ import type { HtmlEscapedString } from '../../utils/html';
2
2
  import type { CssClassName as CssClassNameCommon, CssVariableType } from './common';
3
3
  export { rawCssString } from './common';
4
4
  type CssClassName = HtmlEscapedString & CssClassNameCommon;
5
+ interface CssType {
6
+ (strings: TemplateStringsArray, ...values: CssVariableType[]): Promise<string>;
7
+ }
8
+ interface CxType {
9
+ (...args: (CssClassName | Promise<string> | string | boolean | null | undefined)[]): Promise<string>;
10
+ }
11
+ interface KeyframesType {
12
+ (strings: TemplateStringsArray, ...values: CssVariableType[]): CssClassNameCommon;
13
+ }
14
+ interface ViewTransitionType {
15
+ (strings: TemplateStringsArray, ...values: CssVariableType[]): Promise<string>;
16
+ (content: Promise<string>): Promise<string>;
17
+ (): Promise<string>;
18
+ }
19
+ interface StyleType {
20
+ (args?: {
21
+ children?: Promise<string>;
22
+ }): HtmlEscapedString;
23
+ }
5
24
  /**
6
25
  * @experimental
7
26
  * `createCssContext` is an experimental feature.
@@ -9,52 +28,41 @@ type CssClassName = HtmlEscapedString & CssClassNameCommon;
9
28
  */
10
29
  export declare const createCssContext: ({ id }: {
11
30
  id: Readonly<string>;
12
- }) => {
13
- css: (strings: TemplateStringsArray, ...values: CssVariableType[]) => Promise<string>;
14
- cx: (...args: (CssClassName | Promise<string> | string | boolean | null | undefined)[]) => Promise<string>;
15
- keyframes: (strings: TemplateStringsArray, ...values: CssVariableType[]) => CssClassNameCommon;
16
- viewTransition: {
17
- (strings: TemplateStringsArray, ...values: CssVariableType[]): Promise<string>;
18
- (content: Promise<string>): Promise<string>;
19
- (): Promise<string>;
20
- };
21
- Style: ({ children }?: {
22
- children?: Promise<string> | undefined;
23
- }) => HtmlEscapedString;
24
- };
31
+ }) => DefaultContextType;
32
+ interface DefaultContextType {
33
+ css: CssType;
34
+ cx: CxType;
35
+ keyframes: KeyframesType;
36
+ viewTransition: ViewTransitionType;
37
+ Style: StyleType;
38
+ }
25
39
  /**
26
40
  * @experimental
27
41
  * `css` is an experimental feature.
28
42
  * The API might be changed.
29
43
  */
30
- export declare const css: (strings: TemplateStringsArray, ...values: CssVariableType[]) => Promise<string>;
44
+ export declare const css: CssType;
31
45
  /**
32
46
  * @experimental
33
47
  * `cx` is an experimental feature.
34
48
  * The API might be changed.
35
49
  */
36
- export declare const cx: (...args: (CssClassName | Promise<string> | string | boolean | null | undefined)[]) => Promise<string>;
50
+ export declare const cx: CxType;
37
51
  /**
38
52
  * @experimental
39
53
  * `keyframes` is an experimental feature.
40
54
  * The API might be changed.
41
55
  */
42
- export declare const keyframes: (strings: TemplateStringsArray, ...values: CssVariableType[]) => CssClassNameCommon;
56
+ export declare const keyframes: KeyframesType;
43
57
  /**
44
58
  * @experimental
45
59
  * `viewTransition` is an experimental feature.
46
60
  * The API might be changed.
47
61
  */
48
- export declare const viewTransition: {
49
- (strings: TemplateStringsArray, ...values: CssVariableType[]): Promise<string>;
50
- (content: Promise<string>): Promise<string>;
51
- (): Promise<string>;
52
- };
62
+ export declare const viewTransition: ViewTransitionType;
53
63
  /**
54
64
  * @experimental
55
65
  * `Style` is an experimental feature.
56
66
  * The API might be changed.
57
67
  */
58
- export declare const Style: ({ children }?: {
59
- children?: Promise<string> | undefined;
60
- }) => HtmlEscapedString;
68
+ export declare const Style: StyleType;
@@ -62,7 +62,7 @@ export declare class Factory<E extends Env = any, P extends string = any> {
62
62
  * @experimental
63
63
  * `createApp` is an experimental feature.
64
64
  */
65
- createApp: () => Hono<E, import("../../types").BlankSchema, "/">;
65
+ createApp: () => Hono<E>;
66
66
  createMiddleware: <I extends Input = {}>(middleware: MiddlewareHandler<E, P, I>) => MiddlewareHandler<E, P, I>;
67
67
  createHandlers: CreateHandlersInterface<E, P>;
68
68
  }
@@ -1,5 +1,7 @@
1
+ import type { Client } from '../../client/types';
1
2
  import type { ExecutionContext } from '../../context';
2
3
  import type { Hono } from '../../hono';
4
+ import type { UnionToIntersection } from '../../utils/types';
3
5
  type ExtractEnv<T> = T extends Hono<infer E, any, any> ? E : never;
4
- export declare const testClient: <T extends Hono<any, any, any>>(app: T, Env?: {} | ExtractEnv<T>["Bindings"] | undefined, executionCtx?: ExecutionContext) => import("../../utils/types").UnionToIntersection<import("../../client/types").Client<T>>;
6
+ export declare const testClient: <T extends Hono<any, any, any>>(app: T, Env?: {} | ExtractEnv<T>["Bindings"] | undefined, executionCtx?: ExecutionContext) => UnionToIntersection<Client<T>>;
5
7
  export {};
@@ -83,7 +83,7 @@ declare class Hono<E extends Env = Env, S extends Schema = {}, BasePath extends
83
83
  * })
84
84
  * ```
85
85
  */
86
- onError: (handler: ErrorHandler<E>) => this;
86
+ onError: (handler: ErrorHandler<E>) => Hono<E, S, BasePath>;
87
87
  /**
88
88
  * `.notFound()` allows you to customize a Not Found Response.
89
89
  * ```ts
@@ -93,7 +93,7 @@ declare class Hono<E extends Env = Env, S extends Schema = {}, BasePath extends
93
93
  * ```
94
94
  * @see https://hono.dev/api/hono#not-found
95
95
  */
96
- notFound: (handler: NotFoundHandler<E>) => this;
96
+ notFound: (handler: NotFoundHandler<E>) => Hono<E, S, BasePath>;
97
97
  mount(path: string, applicationHandler: (request: Request, ...args: any) => Response | Promise<Response>, optionHandler?: (c: Context) => unknown): Hono<E, S, BasePath>;
98
98
  private addRoute;
99
99
  private matchRoute;
@@ -1,11 +1,17 @@
1
1
  import type { FC, PropsWithChildren } from '..';
2
2
  import type { CssClassName, CssVariableType } from '../../helper/css/common';
3
3
  export { rawCssString } from '../../helper/css/common';
4
- export declare const createCssJsxDomObjects: ({ id }: {
5
- id: Readonly<string>;
6
- }) => readonly [{
7
- toString(this: CssClassName): string;
8
- }, FC<PropsWithChildren<void>>];
4
+ interface CreateCssJsxDomObjectsType {
5
+ (args: {
6
+ id: Readonly<string>;
7
+ }): readonly [
8
+ {
9
+ toString(this: CssClassName): string;
10
+ },
11
+ FC<PropsWithChildren<void>>
12
+ ];
13
+ }
14
+ export declare const createCssJsxDomObjects: CreateCssJsxDomObjectsType;
9
15
  /**
10
16
  * @experimental
11
17
  * `createCssContext` is an experimental feature.
@@ -1,6 +1,7 @@
1
1
  export { jsxDEV as jsx, Fragment } from './jsx-dev-runtime';
2
2
  export { jsxDEV as jsxs } from './jsx-dev-runtime';
3
3
  import { html } from '../helper/html';
4
+ import type { HtmlEscapedString } from '../utils/html';
4
5
  export { html as jsxTemplate };
5
- export declare const jsxAttr: (name: string, value: string | Promise<string>) => import("../utils/html").HtmlEscapedString | Promise<import("../utils/html").HtmlEscapedString>;
6
+ export declare const jsxAttr: (name: string, value: string | Promise<string>) => HtmlEscapedString | Promise<HtmlEscapedString>;
6
7
  export declare const jsxEscape: (value: string) => string;
@@ -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;
@@ -1,8 +1,9 @@
1
1
  import type { Context, PropsForRenderer } from '../../context';
2
2
  import type { FC, PropsWithChildren } from '../../jsx';
3
+ import type { Context as JSXContext } from '../../jsx';
3
4
  import type { Env, Input, MiddlewareHandler } from '../../types';
4
5
  import type { HtmlEscapedString } from '../../utils/html';
5
- export declare const RequestContext: import("../../jsx").Context<Context<any, any, {}> | null>;
6
+ export declare const RequestContext: JSXContext<Context<any, any, {}> | null>;
6
7
  type RendererOptions = {
7
8
  docType?: boolean | string;
8
9
  stream?: boolean | Record<string, string>;
@@ -5,8 +5,8 @@ export declare class StreamingApi {
5
5
  private abortSubscribers;
6
6
  responseReadable: ReadableStream;
7
7
  constructor(writable: WritableStream, _readable: ReadableStream);
8
- write(input: Uint8Array | string): Promise<this>;
9
- writeln(input: string): Promise<this>;
8
+ write(input: Uint8Array | string): Promise<StreamingApi>;
9
+ writeln(input: string): Promise<StreamingApi>;
10
10
  sleep(ms: number): Promise<unknown>;
11
11
  close(): Promise<void>;
12
12
  pipe(body: ReadableStream): Promise<void>;
@@ -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.4",
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",