hono 4.3.3 → 4.3.5

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) {
@@ -446,7 +446,10 @@ const update = async (context, node) => {
446
446
  };
447
447
  const render = (jsxNode, container) => {
448
448
  const node = buildNode({ tag: "", props: { children: jsxNode } });
449
- build([], node, void 0);
449
+ const context = [];
450
+ context[4] = true;
451
+ build(context, node, void 0);
452
+ context[4] = false;
450
453
  const fragment = document.createDocumentFragment();
451
454
  apply(node, fragment);
452
455
  replaceContainer(node, fragment, container);
@@ -320,19 +320,26 @@ const useImperativeHandle = (ref, createHandle, deps) => {
320
320
  };
321
321
  }, deps);
322
322
  };
323
- let useSyncExternalStoreGetServerSnapshotNotified = false;
324
323
  const useSyncExternalStore = (subscribe, getSnapshot, getServerSnapshot) => {
325
- const [state, setState] = useState(getSnapshot());
326
- useEffect(
327
- () => subscribe(() => {
328
- setState(getSnapshot());
329
- }),
330
- []
331
- );
332
- if (getServerSnapshot && !useSyncExternalStoreGetServerSnapshotNotified) {
333
- useSyncExternalStoreGetServerSnapshotNotified = true;
334
- console.info("`getServerSnapshot` is not supported yet.");
324
+ const buildData = import_render.buildDataStack.at(-1);
325
+ if (!buildData) {
326
+ if (!getServerSnapshot) {
327
+ throw new Error("getServerSnapshot is required for server side rendering");
328
+ }
329
+ return getServerSnapshot();
335
330
  }
331
+ const [serverSnapshotIsUsed] = useState(!!(buildData[0][4] && getServerSnapshot));
332
+ const [state, setState] = useState(
333
+ () => serverSnapshotIsUsed ? getServerSnapshot() : getSnapshot()
334
+ );
335
+ useEffect(() => {
336
+ if (serverSnapshotIsUsed) {
337
+ setState(getSnapshot());
338
+ }
339
+ return subscribe(() => {
340
+ setState(getSnapshot());
341
+ });
342
+ }, []);
336
343
  return state;
337
344
  };
338
345
  // Annotate the CommonJS export names for ESM import in node:
@@ -30,7 +30,7 @@ const validator = (target, validationFunc) => {
30
30
  const contentType = c.req.header("Content-Type");
31
31
  switch (target) {
32
32
  case "json":
33
- if (!contentType || !contentType.startsWith("application/json")) {
33
+ if (!contentType || !/^application\/([a-z-]+\+)?json/.test(contentType)) {
34
34
  const message = `Invalid HTTP header: Content-Type=${contentType}`;
35
35
  throw new import_http_exception.HTTPException(400, { message });
36
36
  }
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) {
@@ -419,7 +419,10 @@ var update = async (context, node) => {
419
419
  };
420
420
  var render = (jsxNode, container) => {
421
421
  const node = buildNode({ tag: "", props: { children: jsxNode } });
422
- build([], node, void 0);
422
+ const context = [];
423
+ context[4] = true;
424
+ build(context, node, void 0);
425
+ context[4] = false;
423
426
  const fragment = document.createDocumentFragment();
424
427
  apply(node, fragment);
425
428
  replaceContainer(node, fragment, container);
@@ -279,19 +279,26 @@ var useImperativeHandle = (ref, createHandle, deps) => {
279
279
  };
280
280
  }, deps);
281
281
  };
282
- var useSyncExternalStoreGetServerSnapshotNotified = false;
283
282
  var useSyncExternalStore = (subscribe, getSnapshot, getServerSnapshot) => {
284
- const [state, setState] = useState(getSnapshot());
285
- useEffect(
286
- () => subscribe(() => {
287
- setState(getSnapshot());
288
- }),
289
- []
290
- );
291
- if (getServerSnapshot && !useSyncExternalStoreGetServerSnapshotNotified) {
292
- useSyncExternalStoreGetServerSnapshotNotified = true;
293
- console.info("`getServerSnapshot` is not supported yet.");
283
+ const buildData = buildDataStack.at(-1);
284
+ if (!buildData) {
285
+ if (!getServerSnapshot) {
286
+ throw new Error("getServerSnapshot is required for server side rendering");
287
+ }
288
+ return getServerSnapshot();
294
289
  }
290
+ const [serverSnapshotIsUsed] = useState(!!(buildData[0][4] && getServerSnapshot));
291
+ const [state, setState] = useState(
292
+ () => serverSnapshotIsUsed ? getServerSnapshot() : getSnapshot()
293
+ );
294
+ useEffect(() => {
295
+ if (serverSnapshotIsUsed) {
296
+ setState(getSnapshot());
297
+ }
298
+ return subscribe(() => {
299
+ setState(getSnapshot());
300
+ });
301
+ }, []);
295
302
  return state;
296
303
  };
297
304
  export {
@@ -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.
@@ -44,8 +44,9 @@ export type Context = [
44
44
  PendingType,
45
45
  boolean,
46
46
  UpdateHook,
47
+ boolean,
47
48
  boolean
48
- ] | [PendingType, boolean, UpdateHook] | [PendingType, boolean] | [PendingType] | [];
49
+ ] | [PendingType, boolean, UpdateHook, boolean] | [PendingType, boolean, UpdateHook] | [PendingType, boolean] | [PendingType] | [];
49
50
  export declare const buildDataStack: [Context, Node][];
50
51
  export declare const build: (context: Context, node: NodeObject, topLevelErrorHandlerNode: NodeObject | undefined, children?: Child[]) => void;
51
52
  export declare const update: (context: Context, node: NodeObject) => Promise<NodeObject | undefined>;
@@ -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,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>;
@@ -8,7 +8,7 @@ var validator = (target, validationFunc) => {
8
8
  const contentType = c.req.header("Content-Type");
9
9
  switch (target) {
10
10
  case "json":
11
- if (!contentType || !contentType.startsWith("application/json")) {
11
+ if (!contentType || !/^application\/([a-z-]+\+)?json/.test(contentType)) {
12
12
  const message = `Invalid HTTP header: Content-Type=${contentType}`;
13
13
  throw new HTTPException(400, { message });
14
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "4.3.3",
3
+ "version": "4.3.5",
4
4
  "description": "Ultrafast web framework for the Edges",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",