hono 4.6.20 → 4.7.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 (101) hide show
  1. package/dist/adapter/aws-lambda/handler.js +0 -2
  2. package/dist/cjs/adapter/aws-lambda/handler.js +0 -8
  3. package/dist/cjs/helper/accepts/accepts.js +4 -26
  4. package/dist/cjs/helper/factory/index.js +6 -2
  5. package/dist/cjs/helper/proxy/index.js +75 -0
  6. package/dist/cjs/middleware/combine/index.js +10 -3
  7. package/dist/cjs/middleware/etag/digest.js +3 -8
  8. package/dist/cjs/middleware/etag/index.js +18 -2
  9. package/dist/cjs/middleware/jwk/index.js +28 -0
  10. package/dist/cjs/middleware/jwk/jwk.js +124 -0
  11. package/dist/cjs/middleware/language/index.js +36 -0
  12. package/dist/cjs/middleware/language/language.js +210 -0
  13. package/dist/cjs/middleware/logger/index.js +2 -3
  14. package/dist/cjs/request.js +1 -1
  15. package/dist/cjs/router/linear-router/router.js +3 -1
  16. package/dist/cjs/router/trie-router/node.js +24 -11
  17. package/dist/cjs/utils/accept.js +86 -0
  18. package/dist/cjs/utils/jwt/index.js +1 -1
  19. package/dist/cjs/utils/jwt/jwt.js +56 -3
  20. package/dist/cjs/utils/jwt/types.js +8 -0
  21. package/dist/cjs/utils/url.js +10 -25
  22. package/dist/helper/accepts/accepts.js +2 -23
  23. package/dist/helper/factory/index.js +6 -2
  24. package/dist/helper/proxy/index.js +52 -0
  25. package/dist/middleware/combine/index.js +10 -3
  26. package/dist/middleware/etag/digest.js +3 -8
  27. package/dist/middleware/etag/index.js +18 -2
  28. package/dist/middleware/jwk/index.js +5 -0
  29. package/dist/middleware/jwk/jwk.js +101 -0
  30. package/dist/middleware/language/index.js +15 -0
  31. package/dist/middleware/language/language.js +178 -0
  32. package/dist/middleware/logger/index.js +2 -3
  33. package/dist/request.js +1 -1
  34. package/dist/router/linear-router/router.js +3 -1
  35. package/dist/router/trie-router/node.js +24 -11
  36. package/dist/types/adapter/cloudflare-pages/handler.d.ts +1 -1
  37. package/dist/types/adapter/cloudflare-workers/websocket.d.ts +1 -1
  38. package/dist/types/adapter/lambda-edge/handler.d.ts +2 -2
  39. package/dist/types/client/types.d.ts +7 -8
  40. package/dist/types/compose.d.ts +11 -1
  41. package/dist/types/context.d.ts +31 -21
  42. package/dist/types/helper/accepts/accepts.d.ts +0 -1
  43. package/dist/types/helper/adapter/index.d.ts +2 -2
  44. package/dist/types/helper/conninfo/types.d.ts +2 -2
  45. package/dist/types/helper/css/common.d.ts +6 -1
  46. package/dist/types/helper/factory/index.d.ts +289 -12
  47. package/dist/types/helper/proxy/index.d.ts +54 -0
  48. package/dist/types/helper/ssg/ssg.d.ts +1 -1
  49. package/dist/types/helper/websocket/index.d.ts +1 -2
  50. package/dist/types/hono-base.d.ts +18 -15
  51. package/dist/types/hono.d.ts +1 -1
  52. package/dist/types/jsx/base.d.ts +4 -1
  53. package/dist/types/jsx/dom/hooks/index.d.ts +9 -3
  54. package/dist/types/jsx/dom/index.d.ts +28 -7
  55. package/dist/types/jsx/dom/intrinsic-element/components.d.ts +6 -6
  56. package/dist/types/jsx/dom/render.d.ts +28 -4
  57. package/dist/types/jsx/dom/server.d.ts +28 -7
  58. package/dist/types/jsx/hooks/index.d.ts +20 -5
  59. package/dist/types/jsx/index.d.ts +28 -7
  60. package/dist/types/jsx/intrinsic-element/components.d.ts +4 -4
  61. package/dist/types/jsx/intrinsic-elements.d.ts +46 -46
  62. package/dist/types/middleware/compress/index.d.ts +4 -1
  63. package/dist/types/middleware/etag/digest.d.ts +1 -1
  64. package/dist/types/middleware/etag/index.d.ts +4 -0
  65. package/dist/types/middleware/jwk/index.d.ts +1 -0
  66. package/dist/types/middleware/jwk/jwk.d.ts +40 -0
  67. package/dist/types/middleware/language/index.d.ts +7 -0
  68. package/dist/types/middleware/language/language.d.ts +102 -0
  69. package/dist/types/middleware/secure-headers/permissions-policy.d.ts +3 -3
  70. package/dist/types/middleware/secure-headers/secure-headers.d.ts +1 -1
  71. package/dist/types/preset/quick.d.ts +1 -1
  72. package/dist/types/preset/tiny.d.ts +1 -1
  73. package/dist/types/request.d.ts +5 -3
  74. package/dist/types/router/linear-router/router.d.ts +0 -1
  75. package/dist/types/router/pattern-router/router.d.ts +0 -1
  76. package/dist/types/router/reg-exp-router/node.d.ts +4 -2
  77. package/dist/types/router/reg-exp-router/router.d.ts +0 -1
  78. package/dist/types/router/reg-exp-router/trie.d.ts +5 -2
  79. package/dist/types/router/smart-router/router.d.ts +0 -1
  80. package/dist/types/router/trie-router/node.d.ts +6 -2
  81. package/dist/types/router/trie-router/router.d.ts +0 -1
  82. package/dist/types/router.d.ts +20 -2
  83. package/dist/types/types.d.ts +2002 -111
  84. package/dist/types/utils/accept.d.ts +11 -0
  85. package/dist/types/utils/cookie.d.ts +4 -4
  86. package/dist/types/utils/headers.d.ts +3 -3
  87. package/dist/types/utils/html.d.ts +6 -2
  88. package/dist/types/utils/jwt/index.d.ts +4 -0
  89. package/dist/types/utils/jwt/jws.d.ts +4 -1
  90. package/dist/types/utils/jwt/jwt.d.ts +8 -2
  91. package/dist/types/utils/jwt/types.d.ts +4 -0
  92. package/dist/types/utils/mime.d.ts +2 -2
  93. package/dist/types/utils/stream.d.ts +0 -4
  94. package/dist/types/utils/url.d.ts +16 -2
  95. package/dist/types/validator/validator.d.ts +18 -6
  96. package/dist/utils/accept.js +63 -0
  97. package/dist/utils/jwt/index.js +2 -2
  98. package/dist/utils/jwt/jwt.js +54 -2
  99. package/dist/utils/jwt/types.js +7 -0
  100. package/dist/utils/url.js +10 -25
  101. package/package.json +24 -3
@@ -0,0 +1,102 @@
1
+ /**
2
+ * @module
3
+ * Language module for Hono.
4
+ */
5
+ import type { Context } from '../../context';
6
+ import type { MiddlewareHandler } from '../../types';
7
+ export type DetectorType = "path" | "querystring" | "cookie" | "header";
8
+ export type CacheType = "cookie";
9
+ export interface DetectorOptions {
10
+ /** Order of language detection strategies */
11
+ order: DetectorType[];
12
+ /** Query parameter name for language */
13
+ lookupQueryString: string;
14
+ /** Cookie name for language */
15
+ lookupCookie: string;
16
+ /** Index in URL path where language code appears */
17
+ lookupFromPathIndex: number;
18
+ /** Header key for language detection */
19
+ lookupFromHeaderKey: string;
20
+ /** Caching strategies */
21
+ caches: CacheType[] | false;
22
+ /** Cookie configuration options */
23
+ cookieOptions?: {
24
+ domain?: string;
25
+ path?: string;
26
+ sameSite?: "Strict" | "Lax" | "None";
27
+ secure?: boolean;
28
+ maxAge?: number;
29
+ httpOnly?: boolean;
30
+ };
31
+ /** Whether to ignore case in language codes */
32
+ ignoreCase: boolean;
33
+ /** Default language if none detected */
34
+ fallbackLanguage: string;
35
+ /** List of supported language codes */
36
+ supportedLanguages: string[];
37
+ /** Optional function to transform detected language codes */
38
+ convertDetectedLanguage?: (lang: string) => string;
39
+ /** Enable debug logging */
40
+ debug?: boolean;
41
+ }
42
+ export interface LanguageVariables {
43
+ language: string;
44
+ }
45
+ export declare const DEFAULT_OPTIONS: DetectorOptions;
46
+ /**
47
+ * Parse Accept-Language header values with quality scores
48
+ * @param header Accept-Language header string
49
+ * @returns Array of parsed languages with quality scores
50
+ */
51
+ export declare function parseAcceptLanguage(header: string): Array<{
52
+ lang: string;
53
+ q: number;
54
+ }>;
55
+ /**
56
+ * Validate and normalize language codes
57
+ * @param lang Language code to normalize
58
+ * @param options Detector options
59
+ * @returns Normalized language code or undefined
60
+ */
61
+ export declare const normalizeLanguage: (lang: string | null | undefined, options: DetectorOptions) => string | undefined;
62
+ /**
63
+ * Detects language from query parameter
64
+ */
65
+ export declare const detectFromQuery: (c: Context, options: DetectorOptions) => string | undefined;
66
+ /**
67
+ * Detects language from cookie
68
+ */
69
+ export declare const detectFromCookie: (c: Context, options: DetectorOptions) => string | undefined;
70
+ /**
71
+ * Detects language from Accept-Language header
72
+ */
73
+ export declare function detectFromHeader(c: Context, options: DetectorOptions): string | undefined;
74
+ /**
75
+ * Detects language from URL path
76
+ */
77
+ export declare function detectFromPath(c: Context, options: DetectorOptions): string | undefined;
78
+ /**
79
+ * Collection of all language detection strategies
80
+ */
81
+ export declare const detectors: {
82
+ readonly querystring: (c: Context, options: DetectorOptions) => string | undefined;
83
+ readonly cookie: (c: Context, options: DetectorOptions) => string | undefined;
84
+ readonly header: typeof detectFromHeader;
85
+ readonly path: typeof detectFromPath;
86
+ };
87
+ /** Type for detector functions */
88
+ export type DetectorFunction = (c: Context, options: DetectorOptions) => string | undefined;
89
+ /** Type-safe detector map */
90
+ export type Detectors = Record<keyof typeof detectors, DetectorFunction>;
91
+ /**
92
+ * Validate detector options
93
+ * @param options Detector options to validate
94
+ * @throws Error if options are invalid
95
+ */
96
+ export declare function validateOptions(options: DetectorOptions): void;
97
+ /**
98
+ * Language detector middleware factory
99
+ * @param userOptions Configuration options for the language detector
100
+ * @returns Hono middleware function
101
+ */
102
+ export declare const languageDetector: (userOptions: Partial<DetectorOptions>) => MiddlewareHandler;
@@ -2,13 +2,13 @@ export type PermissionsPolicyDirective = StandardizedFeatures | ProposedFeatures
2
2
  /**
3
3
  * These features have been declared in a published version of the respective specification.
4
4
  */
5
- type StandardizedFeatures = 'accelerometer' | 'ambientLightSensor' | 'attributionReporting' | 'autoplay' | 'battery' | 'bluetooth' | 'camera' | 'chUa' | 'chUaArch' | 'chUaBitness' | 'chUaFullVersion' | 'chUaFullVersionList' | 'chUaMobile' | 'chUaModel' | 'chUaPlatform' | 'chUaPlatformVersion' | 'chUaWow64' | 'computePressure' | 'crossOriginIsolated' | 'directSockets' | 'displayCapture' | 'encryptedMedia' | 'executionWhileNotRendered' | 'executionWhileOutOfViewport' | 'fullscreen' | 'geolocation' | 'gyroscope' | 'hid' | 'identityCredentialsGet' | 'idleDetection' | 'keyboardMap' | 'magnetometer' | 'microphone' | 'midi' | 'navigationOverride' | 'payment' | 'pictureInPicture' | 'publickeyCredentialsGet' | 'screenWakeLock' | 'serial' | 'storageAccess' | 'syncXhr' | 'usb' | 'webShare' | 'windowManagement' | 'xrSpatialTracking';
5
+ type StandardizedFeatures = "accelerometer" | "ambientLightSensor" | "attributionReporting" | "autoplay" | "battery" | "bluetooth" | "camera" | "chUa" | "chUaArch" | "chUaBitness" | "chUaFullVersion" | "chUaFullVersionList" | "chUaMobile" | "chUaModel" | "chUaPlatform" | "chUaPlatformVersion" | "chUaWow64" | "computePressure" | "crossOriginIsolated" | "directSockets" | "displayCapture" | "encryptedMedia" | "executionWhileNotRendered" | "executionWhileOutOfViewport" | "fullscreen" | "geolocation" | "gyroscope" | "hid" | "identityCredentialsGet" | "idleDetection" | "keyboardMap" | "magnetometer" | "microphone" | "midi" | "navigationOverride" | "payment" | "pictureInPicture" | "publickeyCredentialsGet" | "screenWakeLock" | "serial" | "storageAccess" | "syncXhr" | "usb" | "webShare" | "windowManagement" | "xrSpatialTracking";
6
6
  /**
7
7
  * These features have been proposed, but the definitions have not yet been integrated into their respective specs.
8
8
  */
9
- type ProposedFeatures = 'clipboardRead' | 'clipboardWrite' | 'gemepad' | 'sharedAutofill' | 'speakerSelection';
9
+ type ProposedFeatures = "clipboardRead" | "clipboardWrite" | "gemepad" | "sharedAutofill" | "speakerSelection";
10
10
  /**
11
11
  * These features generally have an explainer only, but may be available for experimentation by web developers.
12
12
  */
13
- type ExperimentalFeatures = 'allScreensCapture' | 'browsingTopics' | 'capturedSurfaceControl' | 'conversionMeasurement' | 'digitalCredentialsGet' | 'focusWithoutUserActivation' | 'joinAdInterestGroup' | 'localFonts' | 'runAdAuction' | 'smartCard' | 'syncScript' | 'trustTokenRedemption' | 'unload' | 'verticalScroll';
13
+ type ExperimentalFeatures = "allScreensCapture" | "browsingTopics" | "capturedSurfaceControl" | "conversionMeasurement" | "digitalCredentialsGet" | "focusWithoutUserActivation" | "joinAdInterestGroup" | "localFonts" | "runAdAuction" | "smartCard" | "syncScript" | "trustTokenRedemption" | "unload" | "verticalScroll";
14
14
  export {};
@@ -46,7 +46,7 @@ interface ReportingEndpointOptions {
46
46
  name: string;
47
47
  url: string;
48
48
  }
49
- type PermissionsPolicyValue = '*' | 'self' | 'src' | 'none' | string;
49
+ type PermissionsPolicyValue = "*" | "self" | "src" | "none" | string;
50
50
  type PermissionsPolicyOptions = Partial<Record<PermissionsPolicyDirective, PermissionsPolicyValue[] | boolean>>;
51
51
  type overridableHeader = boolean | string;
52
52
  interface SecureHeadersOptions {
@@ -5,6 +5,6 @@
5
5
  import { HonoBase } from '../hono-base';
6
6
  import type { HonoOptions } from '../hono-base';
7
7
  import type { BlankEnv, BlankSchema, Env, Schema } from '../types';
8
- export declare class Hono<E extends Env = BlankEnv, S extends Schema = BlankSchema, BasePath extends string = '/'> extends HonoBase<E, S, BasePath> {
8
+ export declare class Hono<E extends Env = BlankEnv, S extends Schema = BlankSchema, BasePath extends string = "/"> extends HonoBase<E, S, BasePath> {
9
9
  constructor(options?: HonoOptions<E>);
10
10
  }
@@ -5,6 +5,6 @@
5
5
  import { HonoBase } from '../hono-base';
6
6
  import type { HonoOptions } from '../hono-base';
7
7
  import type { BlankEnv, BlankSchema, Env, Schema } from '../types';
8
- export declare class Hono<E extends Env = BlankEnv, S extends Schema = BlankSchema, BasePath extends string = '/'> extends HonoBase<E, S, BasePath> {
8
+ export declare class Hono<E extends Env = BlankEnv, S extends Schema = BlankSchema, BasePath extends string = "/"> extends HonoBase<E, S, BasePath> {
9
9
  constructor(options?: HonoOptions<E>);
10
10
  }
@@ -13,8 +13,7 @@ type Body = {
13
13
  type BodyCache = Partial<Body & {
14
14
  parsedBody: BodyData;
15
15
  }>;
16
- export declare class HonoRequest<P extends string = '/', I extends Input['out'] = {}> {
17
- #private;
16
+ export declare class HonoRequest<P extends string = "/", I extends Input["out"] = {}> {
18
17
  /**
19
18
  * `.raw` can get the raw Request object.
20
19
  *
@@ -45,7 +44,10 @@ export declare class HonoRequest<P extends string = '/', I extends Input['out']
45
44
  */
46
45
  path: string;
47
46
  bodyCache: BodyCache;
48
- constructor(request: Request, path?: string, matchResult?: Result<[unknown, RouterRoute]>);
47
+ constructor(request: Request, path?: string, matchResult?: Result<[
48
+ unknown,
49
+ RouterRoute
50
+ ]>);
49
51
  /**
50
52
  * `.req.param()` gets the path parameters.
51
53
  *
@@ -1,6 +1,5 @@
1
1
  import type { Result, Router } from '../../router';
2
2
  export declare class LinearRouter<T> implements Router<T> {
3
- #private;
4
3
  name: string;
5
4
  add(method: string, path: string, handler: T): void;
6
5
  match(method: string, path: string): Result<T>;
@@ -1,6 +1,5 @@
1
1
  import type { Result, Router } from '../../router';
2
2
  export declare class PatternRouter<T> implements Router<T> {
3
- #private;
4
3
  name: string;
5
4
  add(method: string, path: string, handler: T): void;
6
5
  match(method: string, path: string): Result<T>;
@@ -1,10 +1,12 @@
1
1
  export declare const PATH_ERROR: unique symbol;
2
- export type ParamAssocArray = [string, number][];
2
+ export type ParamAssocArray = [
3
+ string,
4
+ number
5
+ ][];
3
6
  export interface Context {
4
7
  varIndex: number;
5
8
  }
6
9
  export declare class Node {
7
- #private;
8
10
  insert(tokens: readonly string[], index: number, paramMap: ParamAssocArray, context: Context, pathErrorCheckOnly: boolean): void;
9
11
  buildRegExpStr(): string;
10
12
  }
@@ -1,6 +1,5 @@
1
1
  import type { Result, Router } from '../../router';
2
2
  export declare class RegExpRouter<T> implements Router<T> {
3
- #private;
4
3
  name: string;
5
4
  constructor();
6
5
  add(method: string, path: string, handler: T): void;
@@ -1,7 +1,10 @@
1
1
  import type { ParamAssocArray } from './node';
2
2
  export type ReplacementMap = number[];
3
3
  export declare class Trie {
4
- #private;
5
4
  insert(path: string, index: number, pathErrorCheckOnly: boolean): ParamAssocArray;
6
- buildRegExp(): [RegExp, ReplacementMap, ReplacementMap];
5
+ buildRegExp(): [
6
+ RegExp,
7
+ ReplacementMap,
8
+ ReplacementMap
9
+ ];
7
10
  }
@@ -1,6 +1,5 @@
1
1
  import type { Result, Router } from '../../router';
2
2
  export declare class SmartRouter<T> implements Router<T> {
3
- #private;
4
3
  name: string;
5
4
  constructor(init: {
6
5
  routers: Router<T>[];
@@ -1,7 +1,11 @@
1
1
  import type { Params } from '../../router';
2
2
  export declare class Node<T> {
3
- #private;
4
3
  constructor(method?: string, handler?: T, children?: Record<string, Node<T>>);
5
4
  insert(method: string, path: string, handler: T): Node<T>;
6
- search(method: string, path: string): [[T, Params][]];
5
+ search(method: string, path: string): [
6
+ [
7
+ T,
8
+ Params
9
+ ][]
10
+ ];
7
11
  }
@@ -1,6 +1,5 @@
1
1
  import type { Result, Router } from '../../router';
2
2
  export declare class TrieRouter<T> implements Router<T> {
3
- #private;
4
3
  name: string;
5
4
  constructor();
6
5
  add(method: string, path: string, handler: T): void;
@@ -13,7 +13,14 @@ export declare const METHOD_NAME_ALL_LOWERCASE: "all";
13
13
  /**
14
14
  * Array of supported HTTP methods.
15
15
  */
16
- export declare const METHODS: readonly ["get", "post", "put", "delete", "options", "patch"];
16
+ export declare const METHODS: readonly [
17
+ "get",
18
+ "post",
19
+ "put",
20
+ "delete",
21
+ "options",
22
+ "patch"
23
+ ];
17
24
  /**
18
25
  * Error message indicating that a route cannot be added because the matcher is already built.
19
26
  */
@@ -89,7 +96,18 @@ export type Params = Record<string, string>;
89
96
  * ]
90
97
  * ```
91
98
  */
92
- export type Result<T> = [[T, ParamIndexMap][], ParamStash] | [[T, Params][]];
99
+ export type Result<T> = [
100
+ [
101
+ T,
102
+ ParamIndexMap
103
+ ][],
104
+ ParamStash
105
+ ] | [
106
+ [
107
+ T,
108
+ Params
109
+ ][]
110
+ ];
93
111
  /**
94
112
  * Error class representing an unsupported path error.
95
113
  */