hono 3.4.1 → 3.4.3
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/adapter/aws-lambda/custom-context.js +0 -0
- package/dist/adapter/aws-lambda/handler.js +5 -1
- package/dist/cjs/adapter/aws-lambda/custom-context.js +16 -0
- package/dist/cjs/adapter/aws-lambda/handler.js +5 -1
- package/dist/cjs/hono-base.js +5 -5
- package/dist/cjs/utils/mime.js +1 -0
- package/dist/hono-base.js +5 -5
- package/dist/types/adapter/aws-lambda/custom-context.d.ts +78 -0
- package/dist/types/adapter/aws-lambda/handler.d.ts +4 -12
- package/dist/types/adapter/aws-lambda/index.d.ts +1 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/middleware/cookie/index.d.ts +1 -1
- package/dist/types/request.d.ts +2 -2
- package/dist/types/types.d.ts +7 -18
- package/dist/utils/mime.js +1 -0
- package/package.json +3 -3
|
File without changes
|
|
@@ -2,10 +2,14 @@
|
|
|
2
2
|
import crypto from "crypto";
|
|
3
3
|
import { encodeBase64 } from "../../utils/encode.js";
|
|
4
4
|
globalThis.crypto ?? (globalThis.crypto = crypto);
|
|
5
|
+
var getRequestContext = (event) => {
|
|
6
|
+
return event.requestContext;
|
|
7
|
+
};
|
|
5
8
|
var handle = (app) => {
|
|
6
9
|
return async (event) => {
|
|
7
10
|
const req = createRequest(event);
|
|
8
|
-
const
|
|
11
|
+
const requestContext = getRequestContext(event);
|
|
12
|
+
const res = await app.fetch(req, { requestContext });
|
|
9
13
|
return createResult(res);
|
|
10
14
|
};
|
|
11
15
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var custom_context_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(custom_context_exports);
|
|
@@ -32,10 +32,14 @@ module.exports = __toCommonJS(handler_exports);
|
|
|
32
32
|
var import_crypto = __toESM(require("crypto"), 1);
|
|
33
33
|
var import_encode = require("../../utils/encode");
|
|
34
34
|
globalThis.crypto ?? (globalThis.crypto = import_crypto.default);
|
|
35
|
+
const getRequestContext = (event) => {
|
|
36
|
+
return event.requestContext;
|
|
37
|
+
};
|
|
35
38
|
const handle = (app) => {
|
|
36
39
|
return async (event) => {
|
|
37
40
|
const req = createRequest(event);
|
|
38
|
-
const
|
|
41
|
+
const requestContext = getRequestContext(event);
|
|
42
|
+
const res = await app.fetch(req, { requestContext });
|
|
39
43
|
return createResult(res);
|
|
40
44
|
};
|
|
41
45
|
};
|
package/dist/cjs/hono-base.js
CHANGED
|
@@ -44,8 +44,8 @@ const errorHandler = (err, c) => {
|
|
|
44
44
|
class Hono extends defineDynamicClass() {
|
|
45
45
|
constructor(init = {}) {
|
|
46
46
|
super();
|
|
47
|
-
this._basePath = "";
|
|
48
|
-
this.path = "
|
|
47
|
+
this._basePath = "/";
|
|
48
|
+
this.path = "/";
|
|
49
49
|
this.routes = [];
|
|
50
50
|
this.notFoundHandler = notFoundHandler;
|
|
51
51
|
this.errorHandler = errorHandler;
|
|
@@ -231,12 +231,12 @@ class Hono extends defineDynamicClass() {
|
|
|
231
231
|
} catch (err) {
|
|
232
232
|
return this.handleError(err, c);
|
|
233
233
|
}
|
|
234
|
-
if (res
|
|
234
|
+
if (res.constructor.name === "Response")
|
|
235
235
|
return res;
|
|
236
236
|
if ("response" in res) {
|
|
237
237
|
res = res.response;
|
|
238
238
|
}
|
|
239
|
-
if (res
|
|
239
|
+
if (res.constructor.name === "Response")
|
|
240
240
|
return res;
|
|
241
241
|
return (async () => {
|
|
242
242
|
let awaited;
|
|
@@ -258,7 +258,7 @@ class Hono extends defineDynamicClass() {
|
|
|
258
258
|
return (async () => {
|
|
259
259
|
try {
|
|
260
260
|
const tmp = composed(c);
|
|
261
|
-
const context = tmp
|
|
261
|
+
const context = tmp.constructor.name === "Promise" ? await tmp : tmp;
|
|
262
262
|
if (!context.finalized) {
|
|
263
263
|
throw new Error(
|
|
264
264
|
"Context is not finalized. You may forget returning Response object or `await next()`"
|
package/dist/cjs/utils/mime.js
CHANGED
package/dist/hono-base.js
CHANGED
|
@@ -22,8 +22,8 @@ var errorHandler = (err, c) => {
|
|
|
22
22
|
var Hono = class extends defineDynamicClass() {
|
|
23
23
|
constructor(init = {}) {
|
|
24
24
|
super();
|
|
25
|
-
this._basePath = "";
|
|
26
|
-
this.path = "
|
|
25
|
+
this._basePath = "/";
|
|
26
|
+
this.path = "/";
|
|
27
27
|
this.routes = [];
|
|
28
28
|
this.notFoundHandler = notFoundHandler;
|
|
29
29
|
this.errorHandler = errorHandler;
|
|
@@ -209,12 +209,12 @@ var Hono = class extends defineDynamicClass() {
|
|
|
209
209
|
} catch (err) {
|
|
210
210
|
return this.handleError(err, c);
|
|
211
211
|
}
|
|
212
|
-
if (res
|
|
212
|
+
if (res.constructor.name === "Response")
|
|
213
213
|
return res;
|
|
214
214
|
if ("response" in res) {
|
|
215
215
|
res = res.response;
|
|
216
216
|
}
|
|
217
|
-
if (res
|
|
217
|
+
if (res.constructor.name === "Response")
|
|
218
218
|
return res;
|
|
219
219
|
return (async () => {
|
|
220
220
|
let awaited;
|
|
@@ -236,7 +236,7 @@ var Hono = class extends defineDynamicClass() {
|
|
|
236
236
|
return (async () => {
|
|
237
237
|
try {
|
|
238
238
|
const tmp = composed(c);
|
|
239
|
-
const context = tmp
|
|
239
|
+
const context = tmp.constructor.name === "Promise" ? await tmp : tmp;
|
|
240
240
|
if (!context.finalized) {
|
|
241
241
|
throw new Error(
|
|
242
242
|
"Context is not finalized. You may forget returning Response object or `await next()`"
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
interface ClientCert {
|
|
2
|
+
clientCertPem: string;
|
|
3
|
+
subjectDN: string;
|
|
4
|
+
issuerDN: string;
|
|
5
|
+
serialNumber: string;
|
|
6
|
+
validity: {
|
|
7
|
+
notBefore: string;
|
|
8
|
+
notAfter: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
interface Identity {
|
|
12
|
+
accessKey?: string;
|
|
13
|
+
accountId?: string;
|
|
14
|
+
caller?: string;
|
|
15
|
+
cognitoAuthenticationProvider?: string;
|
|
16
|
+
cognitoAuthenticationType?: string;
|
|
17
|
+
cognitoIdentityId?: string;
|
|
18
|
+
cognitoIdentityPoolId?: string;
|
|
19
|
+
principalOrgId?: string;
|
|
20
|
+
sourceIp: string;
|
|
21
|
+
user?: string;
|
|
22
|
+
userAgent: string;
|
|
23
|
+
userArn?: string;
|
|
24
|
+
clientCert?: ClientCert;
|
|
25
|
+
}
|
|
26
|
+
export interface ApiGatewayRequestContext {
|
|
27
|
+
accountId: string;
|
|
28
|
+
apiId: string;
|
|
29
|
+
authorizer: {
|
|
30
|
+
claims?: unknown;
|
|
31
|
+
scopes?: unknown;
|
|
32
|
+
};
|
|
33
|
+
domainName: string;
|
|
34
|
+
domainPrefix: string;
|
|
35
|
+
extendedRequestId: string;
|
|
36
|
+
httpMethod: string;
|
|
37
|
+
identity: Identity;
|
|
38
|
+
path: string;
|
|
39
|
+
protocol: string;
|
|
40
|
+
requestId: string;
|
|
41
|
+
requestTime: string;
|
|
42
|
+
requestTimeEpoch: number;
|
|
43
|
+
resourceId?: string;
|
|
44
|
+
resourcePath: string;
|
|
45
|
+
stage: string;
|
|
46
|
+
}
|
|
47
|
+
interface Authorizer {
|
|
48
|
+
iam?: {
|
|
49
|
+
accessKey: string;
|
|
50
|
+
accountId: string;
|
|
51
|
+
callerId: string;
|
|
52
|
+
cognitoIdentity: null;
|
|
53
|
+
principalOrgId: null;
|
|
54
|
+
userArn: string;
|
|
55
|
+
userId: string;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export interface LambdaFunctionUrlRequestContext {
|
|
59
|
+
accountId: string;
|
|
60
|
+
apiId: string;
|
|
61
|
+
authentication: null;
|
|
62
|
+
authorizer: Authorizer;
|
|
63
|
+
domainName: string;
|
|
64
|
+
domainPrefix: string;
|
|
65
|
+
http: {
|
|
66
|
+
method: string;
|
|
67
|
+
path: string;
|
|
68
|
+
protocol: string;
|
|
69
|
+
sourceIp: string;
|
|
70
|
+
userAgent: string;
|
|
71
|
+
};
|
|
72
|
+
requestId: string;
|
|
73
|
+
routeKey: string;
|
|
74
|
+
stage: string;
|
|
75
|
+
time: string;
|
|
76
|
+
timeEpoch: number;
|
|
77
|
+
}
|
|
78
|
+
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Hono } from '../../hono';
|
|
2
2
|
import type { Env } from '../../types';
|
|
3
|
+
import type { ApiGatewayRequestContext, LambdaFunctionUrlRequestContext } from './custom-context';
|
|
3
4
|
interface APIGatewayProxyEventV2 {
|
|
4
5
|
httpMethod: string;
|
|
5
6
|
headers: Record<string, string | undefined>;
|
|
@@ -7,9 +8,7 @@ interface APIGatewayProxyEventV2 {
|
|
|
7
8
|
rawQueryString: string;
|
|
8
9
|
body: string | null;
|
|
9
10
|
isBase64Encoded: boolean;
|
|
10
|
-
requestContext:
|
|
11
|
-
domainName: string;
|
|
12
|
-
};
|
|
11
|
+
requestContext: ApiGatewayRequestContext;
|
|
13
12
|
}
|
|
14
13
|
interface APIGatewayProxyEvent {
|
|
15
14
|
httpMethod: string;
|
|
@@ -18,9 +17,7 @@ interface APIGatewayProxyEvent {
|
|
|
18
17
|
body: string | null;
|
|
19
18
|
isBase64Encoded: boolean;
|
|
20
19
|
queryStringParameters?: Record<string, string | undefined>;
|
|
21
|
-
requestContext:
|
|
22
|
-
domainName: string;
|
|
23
|
-
};
|
|
20
|
+
requestContext: ApiGatewayRequestContext;
|
|
24
21
|
}
|
|
25
22
|
interface LambdaFunctionUrlEvent {
|
|
26
23
|
headers: Record<string, string | undefined>;
|
|
@@ -28,12 +25,7 @@ interface LambdaFunctionUrlEvent {
|
|
|
28
25
|
rawQueryString: string;
|
|
29
26
|
body: string | null;
|
|
30
27
|
isBase64Encoded: boolean;
|
|
31
|
-
requestContext:
|
|
32
|
-
domainName: string;
|
|
33
|
-
http: {
|
|
34
|
-
method: string;
|
|
35
|
-
};
|
|
36
|
-
};
|
|
28
|
+
requestContext: LambdaFunctionUrlRequestContext;
|
|
37
29
|
}
|
|
38
30
|
interface APIGatewayProxyResult {
|
|
39
31
|
statusCode: number;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Hono } from './hono';
|
|
2
|
-
export type { Env, ErrorHandler, Handler, MiddlewareHandler, Next, NotFoundHandler, ValidationTargets, Input, TypedResponse, } from './types';
|
|
2
|
+
export type { Env, ErrorHandler, Handler, MiddlewareHandler, Next, NotFoundHandler, ValidationTargets, Input, Schema, TypedResponse, } from './types';
|
|
3
3
|
export type { Context, ContextVariableMap } from './context';
|
|
4
4
|
export type { HonoRequest } from './request';
|
|
5
5
|
export type { InferRequestType, InferResponseType, ClientRequestOptions } from './client';
|
|
@@ -5,7 +5,7 @@ interface GetCookie {
|
|
|
5
5
|
(c: Context): Cookie;
|
|
6
6
|
}
|
|
7
7
|
interface GetSignedCookie {
|
|
8
|
-
(c: Context,
|
|
8
|
+
(c: Context, secret: string, key: string): Promise<string | undefined | false>;
|
|
9
9
|
(c: Context, secret: string): Promise<SignedCookie>;
|
|
10
10
|
}
|
|
11
11
|
export declare const getCookie: GetCookie;
|
package/dist/types/request.d.ts
CHANGED
|
@@ -8,8 +8,8 @@ export declare class HonoRequest<P extends string = '/', I extends Input['out']
|
|
|
8
8
|
private vData;
|
|
9
9
|
path: string;
|
|
10
10
|
constructor(request: Request, path?: string, paramData?: Record<string, string> | undefined);
|
|
11
|
-
param(key: RemoveQuestion<ParamKeys<
|
|
12
|
-
param(): UnionToIntersection<ParamKeyToRecord<ParamKeys<
|
|
11
|
+
param<P2 extends string = P>(key: RemoveQuestion<ParamKeys<P2>>): UndefinedIfHavingQuestion<ParamKeys<P2>>;
|
|
12
|
+
param<P2 extends string = P>(): UnionToIntersection<ParamKeyToRecord<ParamKeys<P2>>>;
|
|
13
13
|
query(key: string): string | undefined;
|
|
14
14
|
query(): Record<string, string>;
|
|
15
15
|
queries(key: string): string[] | undefined;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -19,23 +19,12 @@ export declare type MiddlewareHandler<E extends Env = any, P extends string = an
|
|
|
19
19
|
export declare type H<E extends Env = any, P extends string = any, I extends Input = {}, O = {}> = Handler<E, P, I, O> | MiddlewareHandler<E, P, I>;
|
|
20
20
|
export declare type NotFoundHandler<E extends Env = any> = (c: Context<E>) => Response | Promise<Response>;
|
|
21
21
|
export declare type ErrorHandler<E extends Env = any> = (err: Error, c: Context<E>) => Response | Promise<Response>;
|
|
22
|
-
export interface HandlerInterface<E extends Env = Env, M extends string = any, S = {}, BasePath extends string = ''> {
|
|
23
|
-
<I extends Input = {}, O = {}>(...handlers: [H<E,
|
|
24
|
-
<P extends string
|
|
25
|
-
<P extends string
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
H<E, ExtractKey<S>, I3, O>,
|
|
29
|
-
H<E, ExtractKey<S>, I4, O>
|
|
30
|
-
]): Hono<E, RemoveBlankRecord<S | Schema<M, ExtractKey<S>, I4['in'], O>>, BasePath>;
|
|
31
|
-
<P extends string, O = {}, I extends Input = {}, I2 extends Input = I, I3 extends Input = I & I2, I4 extends Input = I2 & I3, I5 extends Input = I3 & I4>(...handlers: [
|
|
32
|
-
H<E, ExtractKey<S>, I, O>,
|
|
33
|
-
H<E, ExtractKey<S>, I2, O>,
|
|
34
|
-
H<E, ExtractKey<S>, I3, O>,
|
|
35
|
-
H<E, ExtractKey<S>, I4, O>,
|
|
36
|
-
H<E, ExtractKey<S>, I5, O>
|
|
37
|
-
]): Hono<E, RemoveBlankRecord<S | Schema<M, ExtractKey<S>, I5['in'], O>>, BasePath>;
|
|
38
|
-
<I extends Input = {}, O = {}>(...handlers: Handler<E, ExtractKey<S>, I, O>[]): Hono<E, RemoveBlankRecord<S | Schema<M, ExtractKey<S>, I['in'], O>>, BasePath>;
|
|
22
|
+
export interface HandlerInterface<E extends Env = Env, M extends string = any, S = {}, BasePath extends string = '/'> {
|
|
23
|
+
<P extends string = ExtractKey<S> extends never ? BasePath : ExtractKey<S>, I extends Input = {}, O = {}>(...handlers: [H<E, P, I, O>, H<E, P, I, O>]): Hono<E, RemoveBlankRecord<S | Schema<M, P, I['in'], O>>, BasePath>;
|
|
24
|
+
<P extends string = ExtractKey<S> extends never ? BasePath : ExtractKey<S>, O = {}, I extends Input = {}, I2 extends Input = I, I3 extends Input = I & I2>(...handlers: [H<E, P, I, O>, H<E, P, I2, O>, H<E, P, I3, O>]): Hono<E, RemoveBlankRecord<S | Schema<M, P, I3['in'], O>>, BasePath>;
|
|
25
|
+
<P extends string = ExtractKey<S> extends never ? BasePath : ExtractKey<S>, O = {}, I extends Input = {}, I2 extends Input = I, I3 extends Input = I & I2, I4 extends Input = I2 & I3>(...handlers: [H<E, P, I, O>, H<E, P, I2, O>, H<E, P, I3, O>, H<E, P, I4, O>]): Hono<E, RemoveBlankRecord<S | Schema<M, P, I4['in'], O>>, BasePath>;
|
|
26
|
+
<P extends string = ExtractKey<S> extends never ? BasePath : ExtractKey<S>, O = {}, I extends Input = {}, I2 extends Input = I, I3 extends Input = I & I2, I4 extends Input = I2 & I3, I5 extends Input = I3 & I4>(...handlers: [H<E, P, I, O>, H<E, P, I2, O>, H<E, P, I3, O>, H<E, P, I4, O>, H<E, P, I5, O>]): Hono<E, RemoveBlankRecord<S | Schema<M, P, I5['in'], O>>, BasePath>;
|
|
27
|
+
<P extends string = ExtractKey<S> extends never ? BasePath : ExtractKey<S>, I extends Input = {}, O = {}>(...handlers: Handler<E, P, I, O>[]): Hono<E, RemoveBlankRecord<Schema<M, P, I['in'], O>>, BasePath>;
|
|
39
28
|
<P extends string, O = {}, I extends Input = {}>(path: P, handler: H<E, MergePath<BasePath, P>, I, O>): Hono<E, RemoveBlankRecord<S | Schema<M, MergePath<BasePath, P>, I['in'], O>>, BasePath>;
|
|
40
29
|
<P extends string, O = {}, I extends Input = {}>(path: P, ...handlers: [H<E, MergePath<BasePath, P>, I, O>, H<E, MergePath<BasePath, P>, I, O>]): Hono<E, RemoveBlankRecord<S | Schema<M, MergePath<BasePath, P>, I['in'], O>>, BasePath>;
|
|
41
30
|
<P extends string, O = {}, I extends Input = {}, I2 extends Input = I, I3 extends Input = I & I2>(path: P, ...handlers: [
|
|
@@ -125,7 +114,7 @@ export declare type InputToDataByTarget<T extends Input['out'], Target extends k
|
|
|
125
114
|
} ? R : never;
|
|
126
115
|
export declare type RemoveQuestion<T> = T extends `${infer R}?` ? R : T;
|
|
127
116
|
export declare type UndefinedIfHavingQuestion<T> = T extends `${infer _}?` ? string | undefined : string;
|
|
128
|
-
export declare type ExtractSchema<T> = T extends Hono<infer _, infer S> ? S : never;
|
|
117
|
+
export declare type ExtractSchema<T> = T extends Hono<infer _, infer S, any> ? S : never;
|
|
129
118
|
export declare abstract class FetchEventLike {
|
|
130
119
|
abstract readonly request: Request;
|
|
131
120
|
abstract respondWith(promise: Response | Promise<Response>): void;
|
package/dist/utils/mime.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hono",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.3",
|
|
4
4
|
"description": "Ultrafast web framework for the Edges",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"test:lambda": "env NAME=Node jest --config ./runtime_tests/lambda/jest.config.js",
|
|
21
21
|
"test:lambda-edge": "env NAME=Node jest --config ./runtime_tests/lambda-edge/jest.config.js",
|
|
22
22
|
"test:all": "yarn test && yarn test:deno && yarn test:bun && yarn test:fastly && yarn test:lagon && yarn test:node && yarn test:wrangler && yarn test:lambda && yarn test:lambda-edge",
|
|
23
|
-
"lint": "eslint --ext js,ts src .eslintrc.cjs",
|
|
24
|
-
"lint:fix": "eslint --ext js,ts src .eslintrc.cjs --fix",
|
|
23
|
+
"lint": "eslint --ext js,ts src runtime_tests .eslintrc.cjs",
|
|
24
|
+
"lint:fix": "eslint --ext js,ts src runtime_tests .eslintrc.cjs --fix",
|
|
25
25
|
"denoify": "rimraf deno_dist && denoify && rimraf 'deno_dist/**/*.test.ts'",
|
|
26
26
|
"copy:package.cjs.json": "cp ./package.cjs.json ./dist/cjs/package.json && cp ./package.cjs.json ./dist/types/package.json ",
|
|
27
27
|
"build": "rimraf dist && tsx ./build.ts && yarn copy:package.cjs.json",
|