hono-adapter-aws-lambda 1.0.0 → 1.1.0
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/index.d.mts +8 -2
- package/dist/index.mjs +32 -4
- package/package.json +11 -11
package/dist/index.d.mts
CHANGED
|
@@ -9,11 +9,17 @@ import { H } from 'hono/types';
|
|
|
9
9
|
type LambdaHandler<TEvent = any, TResult = any> = Handler<TEvent, TResult>;
|
|
10
10
|
type LambdaHandlerResult = APIGatewayProxyResult | APIGatewayProxyStructuredResultV2;
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
interface HandleConfigOptions {
|
|
13
|
+
/**
|
|
14
|
+
* This allows you to easier invoke HTTP routes manually by parsing `event.routeKey` for method and path.
|
|
15
|
+
*/
|
|
16
|
+
easyRouteKey?: boolean;
|
|
17
|
+
}
|
|
18
|
+
declare function streamHandle<E extends Env = Env, S extends Schema = {}, BasePath extends string = '/'>(app: Hono<E, S, BasePath>, handleConfig?: HandleConfigOptions): LambdaHandler<LambdaEvent>;
|
|
13
19
|
/**
|
|
14
20
|
* Accepts events from API Gateway/ELB(`APIGatewayProxyEvent`) and directly through Function Url(`APIGatewayProxyEventV2`)
|
|
15
21
|
*/
|
|
16
|
-
declare function handle<E extends Env = Env, S extends Schema = {}, BasePath extends string = '/'>(app: Hono<E, S, BasePath
|
|
22
|
+
declare function handle<E extends Env = Env, S extends Schema = {}, BasePath extends string = '/'>(app: Hono<E, S, BasePath>, handleConfig?: HandleConfigOptions): LambdaHandler<LambdaEvent, LambdaHandlerResult>;
|
|
17
23
|
|
|
18
24
|
declare class TriggerFactory<IE extends Env, HE extends Env> {
|
|
19
25
|
private simpleRouter;
|
package/dist/index.mjs
CHANGED
|
@@ -302,6 +302,21 @@ function getProcessor(event) {
|
|
|
302
302
|
return v1Processor;
|
|
303
303
|
}
|
|
304
304
|
|
|
305
|
+
function minimalEvent(method, path, baseEvent) {
|
|
306
|
+
const event = baseEvent ?? {};
|
|
307
|
+
event.requestContext ?? (event.requestContext = {
|
|
308
|
+
http: {
|
|
309
|
+
method: "",
|
|
310
|
+
path: ""
|
|
311
|
+
},
|
|
312
|
+
routeKey: ""
|
|
313
|
+
});
|
|
314
|
+
event.routeKey = event.requestContext.routeKey = `${method} ${path}`;
|
|
315
|
+
event.requestContext.http.method = method;
|
|
316
|
+
event.rawPath = event.requestContext.http.path = path;
|
|
317
|
+
return event;
|
|
318
|
+
}
|
|
319
|
+
|
|
305
320
|
globalThis.crypto ?? (globalThis.crypto = crypto);
|
|
306
321
|
async function writableWriteReadable(writer, reader) {
|
|
307
322
|
let readResult = await reader.read();
|
|
@@ -336,9 +351,10 @@ function responseToStreamMetadata(res) {
|
|
|
336
351
|
cookies
|
|
337
352
|
};
|
|
338
353
|
}
|
|
339
|
-
function streamHandle(app) {
|
|
354
|
+
function streamHandle(app, handleConfig) {
|
|
340
355
|
return awslambda.streamifyResponse(
|
|
341
356
|
async (event, responseStream, context) => {
|
|
357
|
+
await processConfig(event, context, handleConfig);
|
|
342
358
|
const processor = getProcessor(event);
|
|
343
359
|
try {
|
|
344
360
|
const req = processor.createRequest(event);
|
|
@@ -368,18 +384,30 @@ function streamHandle(app) {
|
|
|
368
384
|
}
|
|
369
385
|
);
|
|
370
386
|
}
|
|
371
|
-
function handle(app) {
|
|
372
|
-
return async (event,
|
|
387
|
+
function handle(app, handleConfig) {
|
|
388
|
+
return async (event, context) => {
|
|
389
|
+
await processConfig(event, context, handleConfig);
|
|
373
390
|
const processor = getProcessor(event);
|
|
374
391
|
const req = processor.createRequest(event);
|
|
375
392
|
const res = await app.fetch(req, {
|
|
376
393
|
event,
|
|
377
|
-
|
|
394
|
+
context
|
|
378
395
|
});
|
|
379
396
|
if (res.headers.get("$HAAL-returnBody"))
|
|
380
397
|
return await res.json();
|
|
381
398
|
return processor.createResult(event, res);
|
|
382
399
|
};
|
|
383
400
|
}
|
|
401
|
+
async function processConfig(event, context, handleConfig) {
|
|
402
|
+
const _eventCastV2 = event;
|
|
403
|
+
if (handleConfig?.easyRouteKey) {
|
|
404
|
+
if (!_eventCastV2.routeKey)
|
|
405
|
+
return;
|
|
406
|
+
if (!_eventCastV2.requestContext?.http?.path && !_eventCastV2.requestContext?.http?.method) {
|
|
407
|
+
const [method, path] = _eventCastV2.routeKey.split(" ");
|
|
408
|
+
minimalEvent(method, path, _eventCastV2);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
384
412
|
|
|
385
413
|
export { TriggerFactory, createTriggerFactory, getTriggerPath, handle, streamHandle, triggerPathUUID };
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hono-adapter-aws-lambda",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
5
|
-
"packageManager": "pnpm@9.
|
|
4
|
+
"version": "1.1.0",
|
|
5
|
+
"packageManager": "pnpm@9.8.0",
|
|
6
6
|
"description": "",
|
|
7
7
|
"author": "NamesMT <dangquoctrung123@gmail.com>",
|
|
8
8
|
"license": "MIT",
|
|
@@ -61,21 +61,21 @@
|
|
|
61
61
|
}
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@namesmt/utils-lambda": "^0.1.
|
|
65
|
-
"@types/aws-lambda": "^8.10.
|
|
64
|
+
"@namesmt/utils-lambda": "^0.1.1",
|
|
65
|
+
"@types/aws-lambda": "^8.10.143"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@antfu/eslint-config": "^2.
|
|
69
|
-
"@types/node": "^20.
|
|
70
|
-
"@vitest/coverage-v8": "^2.0.
|
|
71
|
-
"eslint": "^9.
|
|
68
|
+
"@antfu/eslint-config": "^2.27.1",
|
|
69
|
+
"@types/node": "^20.16.1",
|
|
70
|
+
"@vitest/coverage-v8": "^2.0.5",
|
|
71
|
+
"eslint": "^9.9.1",
|
|
72
72
|
"klona": "^2.0.6",
|
|
73
|
-
"lint-staged": "^15.2.
|
|
73
|
+
"lint-staged": "^15.2.9",
|
|
74
74
|
"simple-git-hooks": "^2.11.1",
|
|
75
|
-
"tsx": "^4.
|
|
75
|
+
"tsx": "^4.17.0",
|
|
76
76
|
"typescript": "^5.5.4",
|
|
77
77
|
"unbuild": "^2.0.0",
|
|
78
|
-
"vitest": "^2.0.
|
|
78
|
+
"vitest": "^2.0.5"
|
|
79
79
|
},
|
|
80
80
|
"pnpm": {
|
|
81
81
|
"overrides": {
|