hono 4.6.14 → 4.6.15
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.
- package/dist/cjs/context.js +4 -1
- package/dist/cjs/hono-base.js +2 -4
- package/dist/cjs/utils/constants.js +28 -0
- package/dist/cjs/utils/cookie.js +3 -0
- package/dist/cjs/utils/handler.js +2 -2
- package/dist/context.js +4 -1
- package/dist/hono-base.js +1 -2
- package/dist/types/context.d.ts +17 -12
- package/dist/types/hono-base.d.ts +0 -4
- package/dist/types/http-exception.d.ts +3 -3
- package/dist/types/utils/constants.d.ts +4 -0
- package/dist/types/utils/cookie.d.ts +1 -0
- package/dist/types/utils/http-status.d.ts +2 -0
- package/dist/utils/constants.js +5 -0
- package/dist/utils/cookie.js +3 -0
- package/dist/utils/handler.js +1 -1
- package/package.json +1 -1
package/dist/cjs/context.js
CHANGED
|
@@ -240,7 +240,10 @@ class Context {
|
|
|
240
240
|
this.#preparedHeaders = {};
|
|
241
241
|
}
|
|
242
242
|
this.#preparedHeaders["content-type"] = TEXT_PLAIN;
|
|
243
|
-
|
|
243
|
+
if (typeof arg === "number") {
|
|
244
|
+
return this.#newResponse(text, arg, headers);
|
|
245
|
+
}
|
|
246
|
+
return this.#newResponse(text, arg);
|
|
244
247
|
};
|
|
245
248
|
json = (object, arg, headers) => {
|
|
246
249
|
const body = JSON.stringify(object);
|
package/dist/cjs/hono-base.js
CHANGED
|
@@ -18,15 +18,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var hono_base_exports = {};
|
|
20
20
|
__export(hono_base_exports, {
|
|
21
|
-
COMPOSED_HANDLER: () => COMPOSED_HANDLER,
|
|
22
21
|
HonoBase: () => Hono
|
|
23
22
|
});
|
|
24
23
|
module.exports = __toCommonJS(hono_base_exports);
|
|
25
24
|
var import_compose = require("./compose");
|
|
26
25
|
var import_context = require("./context");
|
|
27
26
|
var import_router = require("./router");
|
|
27
|
+
var import_constants = require("./utils/constants");
|
|
28
28
|
var import_url = require("./utils/url");
|
|
29
|
-
const COMPOSED_HANDLER = Symbol("composedHandler");
|
|
30
29
|
const notFoundHandler = (c) => {
|
|
31
30
|
return c.text("404 Not Found", 404);
|
|
32
31
|
};
|
|
@@ -113,7 +112,7 @@ class Hono {
|
|
|
113
112
|
handler = r.handler;
|
|
114
113
|
} else {
|
|
115
114
|
handler = async (c, next) => (await (0, import_compose.compose)([], app.errorHandler)(c, () => r.handler(c, next))).res;
|
|
116
|
-
handler[COMPOSED_HANDLER] = r.handler;
|
|
115
|
+
handler[import_constants.COMPOSED_HANDLER] = r.handler;
|
|
117
116
|
}
|
|
118
117
|
subApp.#addRoute(r.method, r.path, handler);
|
|
119
118
|
});
|
|
@@ -252,6 +251,5 @@ class Hono {
|
|
|
252
251
|
}
|
|
253
252
|
// Annotate the CommonJS export names for ESM import in node:
|
|
254
253
|
0 && (module.exports = {
|
|
255
|
-
COMPOSED_HANDLER,
|
|
256
254
|
HonoBase
|
|
257
255
|
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var constants_exports = {};
|
|
20
|
+
__export(constants_exports, {
|
|
21
|
+
COMPOSED_HANDLER: () => COMPOSED_HANDLER
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(constants_exports);
|
|
24
|
+
const COMPOSED_HANDLER = "__COMPOSED_HANDLER";
|
|
25
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
26
|
+
0 && (module.exports = {
|
|
27
|
+
COMPOSED_HANDLER
|
|
28
|
+
});
|
package/dist/cjs/utils/cookie.js
CHANGED
|
@@ -143,6 +143,9 @@ const _serialize = (name, value, opt = {}) => {
|
|
|
143
143
|
if (opt.sameSite) {
|
|
144
144
|
cookie += `; SameSite=${opt.sameSite.charAt(0).toUpperCase() + opt.sameSite.slice(1)}`;
|
|
145
145
|
}
|
|
146
|
+
if (opt.priority) {
|
|
147
|
+
cookie += `; Priority=${opt.priority}`;
|
|
148
|
+
}
|
|
146
149
|
if (opt.partitioned) {
|
|
147
150
|
if (!opt.secure) {
|
|
148
151
|
throw new Error("Partitioned Cookie must have Secure attributes");
|
|
@@ -22,10 +22,10 @@ __export(handler_exports, {
|
|
|
22
22
|
isMiddleware: () => isMiddleware
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(handler_exports);
|
|
25
|
-
var
|
|
25
|
+
var import_constants = require("./constants");
|
|
26
26
|
const isMiddleware = (handler) => handler.length > 1;
|
|
27
27
|
const findTargetHandler = (handler) => {
|
|
28
|
-
return handler[
|
|
28
|
+
return handler[import_constants.COMPOSED_HANDLER] ? findTargetHandler(handler[import_constants.COMPOSED_HANDLER]) : handler;
|
|
29
29
|
};
|
|
30
30
|
// Annotate the CommonJS export names for ESM import in node:
|
|
31
31
|
0 && (module.exports = {
|
package/dist/context.js
CHANGED
|
@@ -217,7 +217,10 @@ var Context = class {
|
|
|
217
217
|
this.#preparedHeaders = {};
|
|
218
218
|
}
|
|
219
219
|
this.#preparedHeaders["content-type"] = TEXT_PLAIN;
|
|
220
|
-
|
|
220
|
+
if (typeof arg === "number") {
|
|
221
|
+
return this.#newResponse(text, arg, headers);
|
|
222
|
+
}
|
|
223
|
+
return this.#newResponse(text, arg);
|
|
221
224
|
};
|
|
222
225
|
json = (object, arg, headers) => {
|
|
223
226
|
const body = JSON.stringify(object);
|
package/dist/hono-base.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import { compose } from "./compose.js";
|
|
3
3
|
import { Context } from "./context.js";
|
|
4
4
|
import { METHODS, METHOD_NAME_ALL, METHOD_NAME_ALL_LOWERCASE } from "./router.js";
|
|
5
|
+
import { COMPOSED_HANDLER } from "./utils/constants.js";
|
|
5
6
|
import { getPath, getPathNoStrict, mergePath } from "./utils/url.js";
|
|
6
|
-
var COMPOSED_HANDLER = Symbol("composedHandler");
|
|
7
7
|
var notFoundHandler = (c) => {
|
|
8
8
|
return c.text("404 Not Found", 404);
|
|
9
9
|
};
|
|
@@ -228,6 +228,5 @@ var Hono = class {
|
|
|
228
228
|
};
|
|
229
229
|
};
|
|
230
230
|
export {
|
|
231
|
-
COMPOSED_HANDLER,
|
|
232
231
|
Hono as HonoBase
|
|
233
232
|
};
|
package/dist/types/context.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { HonoRequest } from './request';
|
|
|
2
2
|
import type { Result } from './router';
|
|
3
3
|
import type { Env, FetchEventLike, H, Input, NotFoundHandler, RouterRoute, TypedResponse } from './types';
|
|
4
4
|
import type { ResponseHeader } from './utils/headers';
|
|
5
|
-
import type { RedirectStatusCode, StatusCode } from './utils/http-status';
|
|
5
|
+
import type { ContentfulStatusCode, RedirectStatusCode, StatusCode } from './utils/http-status';
|
|
6
6
|
import type { BaseMime } from './utils/mime';
|
|
7
7
|
import type { InvalidJSONValue, IsAny, JSONParsed, JSONValue, SimplifyDeepArray } from './utils/types';
|
|
8
8
|
type HeaderRecord = Record<"Content-Type", BaseMime> | Record<ResponseHeader, string | string[]> | Record<string, string | string[]>;
|
|
@@ -82,12 +82,16 @@ interface Set<E extends Env> {
|
|
|
82
82
|
*/
|
|
83
83
|
interface NewResponse {
|
|
84
84
|
(data: Data | null, status?: StatusCode, headers?: HeaderRecord): Response;
|
|
85
|
-
(data: Data | null, init?:
|
|
85
|
+
(data: Data | null, init?: ResponseOrInit): Response;
|
|
86
86
|
}
|
|
87
87
|
/**
|
|
88
88
|
* Interface for responding with a body.
|
|
89
89
|
*/
|
|
90
|
-
interface BodyRespond
|
|
90
|
+
interface BodyRespond {
|
|
91
|
+
(data: Data, status?: ContentfulStatusCode, headers?: HeaderRecord): Response;
|
|
92
|
+
(data: null, status?: StatusCode, headers?: HeaderRecord): Response;
|
|
93
|
+
(data: Data, init?: ResponseOrInit<ContentfulStatusCode>): Response;
|
|
94
|
+
(data: null, init?: ResponseOrInit): Response;
|
|
91
95
|
}
|
|
92
96
|
/**
|
|
93
97
|
* Interface for responding with text.
|
|
@@ -103,8 +107,8 @@ interface BodyRespond extends NewResponse {
|
|
|
103
107
|
* @returns {Response & TypedResponse<T, U, 'text'>} - The response after rendering the text content, typed with the provided text and status code types.
|
|
104
108
|
*/
|
|
105
109
|
interface TextRespond {
|
|
106
|
-
<T extends string, U extends
|
|
107
|
-
<T extends string, U extends
|
|
110
|
+
<T extends string, U extends ContentfulStatusCode = ContentfulStatusCode>(text: T, status?: U, headers?: HeaderRecord): Response & TypedResponse<T, U, "text">;
|
|
111
|
+
<T extends string, U extends ContentfulStatusCode = ContentfulStatusCode>(text: T, init?: ResponseOrInit<U>): Response & TypedResponse<T, U, "text">;
|
|
108
112
|
}
|
|
109
113
|
/**
|
|
110
114
|
* Interface for responding with JSON.
|
|
@@ -120,8 +124,8 @@ interface TextRespond {
|
|
|
120
124
|
* @returns {JSONRespondReturn<T, U>} - The response after rendering the JSON object, typed with the provided object and status code types.
|
|
121
125
|
*/
|
|
122
126
|
interface JSONRespond {
|
|
123
|
-
<T extends JSONValue | SimplifyDeepArray<unknown> | InvalidJSONValue, U extends
|
|
124
|
-
<T extends JSONValue | SimplifyDeepArray<unknown> | InvalidJSONValue, U extends
|
|
127
|
+
<T extends JSONValue | SimplifyDeepArray<unknown> | InvalidJSONValue, U extends ContentfulStatusCode = ContentfulStatusCode>(object: T, status?: U, headers?: HeaderRecord): JSONRespondReturn<T, U>;
|
|
128
|
+
<T extends JSONValue | SimplifyDeepArray<unknown> | InvalidJSONValue, U extends ContentfulStatusCode = ContentfulStatusCode>(object: T, init?: ResponseOrInit<U>): JSONRespondReturn<T, U>;
|
|
125
129
|
}
|
|
126
130
|
/**
|
|
127
131
|
* @template T - The type of the JSON value or simplified unknown type.
|
|
@@ -129,7 +133,7 @@ interface JSONRespond {
|
|
|
129
133
|
*
|
|
130
134
|
* @returns {Response & TypedResponse<SimplifyDeepArray<T> extends JSONValue ? (JSONValue extends SimplifyDeepArray<T> ? never : JSONParsed<T>) : never, U, 'json'>} - The response after rendering the JSON object, typed with the provided object and status code types.
|
|
131
135
|
*/
|
|
132
|
-
type JSONRespondReturn<T extends JSONValue | SimplifyDeepArray<unknown> | InvalidJSONValue, U extends
|
|
136
|
+
type JSONRespondReturn<T extends JSONValue | SimplifyDeepArray<unknown> | InvalidJSONValue, U extends ContentfulStatusCode> = Response & TypedResponse<SimplifyDeepArray<T> extends JSONValue ? JSONValue extends SimplifyDeepArray<T> ? never : JSONParsed<T> : never, U, "json">;
|
|
133
137
|
/**
|
|
134
138
|
* Interface representing a function that responds with HTML content.
|
|
135
139
|
*
|
|
@@ -141,8 +145,8 @@ type JSONRespondReturn<T extends JSONValue | SimplifyDeepArray<unknown> | Invali
|
|
|
141
145
|
* @returns A Response object or a Promise that resolves to a Response object.
|
|
142
146
|
*/
|
|
143
147
|
interface HTMLRespond {
|
|
144
|
-
<T extends string | Promise<string>>(html: T, status?:
|
|
145
|
-
<T extends string | Promise<string>>(html: T, init?:
|
|
148
|
+
<T extends string | Promise<string>>(html: T, status?: ContentfulStatusCode, headers?: HeaderRecord): T extends string ? Response : Promise<Response>;
|
|
149
|
+
<T extends string | Promise<string>>(html: T, init?: ResponseOrInit<ContentfulStatusCode>): T extends string ? Response : Promise<Response>;
|
|
146
150
|
}
|
|
147
151
|
/**
|
|
148
152
|
* Options for configuring the context.
|
|
@@ -180,11 +184,12 @@ type ResponseHeadersInit = [
|
|
|
180
184
|
string,
|
|
181
185
|
string
|
|
182
186
|
][] | Record<"Content-Type", BaseMime> | Record<ResponseHeader, string> | Record<string, string> | Headers;
|
|
183
|
-
interface ResponseInit {
|
|
187
|
+
interface ResponseInit<T extends StatusCode = StatusCode> {
|
|
184
188
|
headers?: ResponseHeadersInit;
|
|
185
|
-
status?:
|
|
189
|
+
status?: T;
|
|
186
190
|
statusText?: string;
|
|
187
191
|
}
|
|
192
|
+
type ResponseOrInit<T extends StatusCode = StatusCode> = ResponseInit<T> | Response;
|
|
188
193
|
export declare const TEXT_PLAIN = "text/plain; charset=UTF-8";
|
|
189
194
|
export declare class Context<E extends Env = any, P extends string = any, I extends Input = {}> {
|
|
190
195
|
/**
|
|
@@ -6,10 +6,6 @@ import { Context } from './context';
|
|
|
6
6
|
import type { ExecutionContext } from './context';
|
|
7
7
|
import type { Router } from './router';
|
|
8
8
|
import type { Env, ErrorHandler, H, HandlerInterface, MergePath, MergeSchemaPath, MiddlewareHandlerInterface, NotFoundHandler, OnHandlerInterface, RouterRoute, Schema } from './types';
|
|
9
|
-
/**
|
|
10
|
-
* Symbol used to mark a composed handler.
|
|
11
|
-
*/
|
|
12
|
-
export declare const COMPOSED_HANDLER: unique symbol;
|
|
13
9
|
type GetPath<E extends Env> = (request: Request, options?: {
|
|
14
10
|
env?: E["Bindings"];
|
|
15
11
|
}) => string;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @module
|
|
3
3
|
* This module provides the `HTTPException` class.
|
|
4
4
|
*/
|
|
5
|
-
import type {
|
|
5
|
+
import type { ContentfulStatusCode } from './utils/http-status';
|
|
6
6
|
/**
|
|
7
7
|
* Options for creating an `HTTPException`.
|
|
8
8
|
* @property res - Optional response object to use.
|
|
@@ -42,13 +42,13 @@ type HTTPExceptionOptions = {
|
|
|
42
42
|
*/
|
|
43
43
|
export declare class HTTPException extends Error {
|
|
44
44
|
readonly res?: Response;
|
|
45
|
-
readonly status:
|
|
45
|
+
readonly status: ContentfulStatusCode;
|
|
46
46
|
/**
|
|
47
47
|
* Creates an instance of `HTTPException`.
|
|
48
48
|
* @param status - HTTP status code for the exception. Defaults to 500.
|
|
49
49
|
* @param options - Additional options for the exception.
|
|
50
50
|
*/
|
|
51
|
-
constructor(status?:
|
|
51
|
+
constructor(status?: ContentfulStatusCode, options?: HTTPExceptionOptions);
|
|
52
52
|
/**
|
|
53
53
|
* Returns the response object associated with the exception.
|
|
54
54
|
* If a response object is not provided, a new response is created with the error message and status code.
|
|
@@ -29,6 +29,7 @@ export type CookieOptions = {
|
|
|
29
29
|
signingSecret?: string;
|
|
30
30
|
sameSite?: "Strict" | "Lax" | "None" | "strict" | "lax" | "none";
|
|
31
31
|
partitioned?: boolean;
|
|
32
|
+
priority?: "Low" | "Medium" | "High";
|
|
32
33
|
prefix?: CookiePrefixOptions;
|
|
33
34
|
} & PartitionedCookieConstraint;
|
|
34
35
|
export type CookiePrefixOptions = "host" | "secure";
|
|
@@ -28,3 +28,5 @@ export type UnOfficalStatusCode = UnofficialStatusCode;
|
|
|
28
28
|
* If you want to use an unofficial status, use `UnofficialStatusCode`.
|
|
29
29
|
*/
|
|
30
30
|
export type StatusCode = InfoStatusCode | SuccessStatusCode | RedirectStatusCode | ClientErrorStatusCode | ServerErrorStatusCode | UnofficialStatusCode;
|
|
31
|
+
export type ContentlessStatusCode = 101 | 204 | 205 | 304;
|
|
32
|
+
export type ContentfulStatusCode = Exclude<StatusCode, ContentlessStatusCode>;
|
package/dist/utils/cookie.js
CHANGED
|
@@ -118,6 +118,9 @@ var _serialize = (name, value, opt = {}) => {
|
|
|
118
118
|
if (opt.sameSite) {
|
|
119
119
|
cookie += `; SameSite=${opt.sameSite.charAt(0).toUpperCase() + opt.sameSite.slice(1)}`;
|
|
120
120
|
}
|
|
121
|
+
if (opt.priority) {
|
|
122
|
+
cookie += `; Priority=${opt.priority}`;
|
|
123
|
+
}
|
|
121
124
|
if (opt.partitioned) {
|
|
122
125
|
if (!opt.secure) {
|
|
123
126
|
throw new Error("Partitioned Cookie must have Secure attributes");
|
package/dist/utils/handler.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/utils/handler.ts
|
|
2
|
-
import { COMPOSED_HANDLER } from "
|
|
2
|
+
import { COMPOSED_HANDLER } from "./constants.js";
|
|
3
3
|
var isMiddleware = (handler) => handler.length > 1;
|
|
4
4
|
var findTargetHandler = (handler) => {
|
|
5
5
|
return handler[COMPOSED_HANDLER] ? findTargetHandler(handler[COMPOSED_HANDLER]) : handler;
|