hono-adapter-aws-lambda 1.0.1 → 1.2.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 +35 -4
- package/package.json +1 -1
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,24 @@ function getProcessor(event) {
|
|
|
302
302
|
return v1Processor;
|
|
303
303
|
}
|
|
304
304
|
|
|
305
|
+
function minimalEvent(method, path, baseEvent) {
|
|
306
|
+
var _a;
|
|
307
|
+
const event = baseEvent ?? {};
|
|
308
|
+
event.requestContext ?? (event.requestContext = {
|
|
309
|
+
http: {
|
|
310
|
+
method: "",
|
|
311
|
+
path: ""
|
|
312
|
+
},
|
|
313
|
+
routeKey: ""
|
|
314
|
+
});
|
|
315
|
+
event.headers ?? (event.headers = {});
|
|
316
|
+
(_a = event.headers)["content-type"] ?? (_a["content-type"] = "application/json");
|
|
317
|
+
event.routeKey = event.requestContext.routeKey = `${method} ${path}`;
|
|
318
|
+
event.requestContext.http.method = method;
|
|
319
|
+
event.rawPath = event.requestContext.http.path = path;
|
|
320
|
+
return event;
|
|
321
|
+
}
|
|
322
|
+
|
|
305
323
|
globalThis.crypto ?? (globalThis.crypto = crypto);
|
|
306
324
|
async function writableWriteReadable(writer, reader) {
|
|
307
325
|
let readResult = await reader.read();
|
|
@@ -336,9 +354,10 @@ function responseToStreamMetadata(res) {
|
|
|
336
354
|
cookies
|
|
337
355
|
};
|
|
338
356
|
}
|
|
339
|
-
function streamHandle(app) {
|
|
357
|
+
function streamHandle(app, handleConfig) {
|
|
340
358
|
return awslambda.streamifyResponse(
|
|
341
359
|
async (event, responseStream, context) => {
|
|
360
|
+
await processConfig(event, context, handleConfig);
|
|
342
361
|
const processor = getProcessor(event);
|
|
343
362
|
try {
|
|
344
363
|
const req = processor.createRequest(event);
|
|
@@ -368,18 +387,30 @@ function streamHandle(app) {
|
|
|
368
387
|
}
|
|
369
388
|
);
|
|
370
389
|
}
|
|
371
|
-
function handle(app) {
|
|
372
|
-
return async (event,
|
|
390
|
+
function handle(app, handleConfig) {
|
|
391
|
+
return async (event, context) => {
|
|
392
|
+
await processConfig(event, context, handleConfig);
|
|
373
393
|
const processor = getProcessor(event);
|
|
374
394
|
const req = processor.createRequest(event);
|
|
375
395
|
const res = await app.fetch(req, {
|
|
376
396
|
event,
|
|
377
|
-
|
|
397
|
+
context
|
|
378
398
|
});
|
|
379
399
|
if (res.headers.get("$HAAL-returnBody"))
|
|
380
400
|
return await res.json();
|
|
381
401
|
return processor.createResult(event, res);
|
|
382
402
|
};
|
|
383
403
|
}
|
|
404
|
+
async function processConfig(event, context, handleConfig) {
|
|
405
|
+
const _eventCastV2 = event;
|
|
406
|
+
if (handleConfig?.easyRouteKey) {
|
|
407
|
+
if (!_eventCastV2.routeKey)
|
|
408
|
+
return;
|
|
409
|
+
if (!_eventCastV2.requestContext?.http?.path && !_eventCastV2.requestContext?.http?.method) {
|
|
410
|
+
const [method, path] = _eventCastV2.routeKey.split(" ");
|
|
411
|
+
minimalEvent(method, path, _eventCastV2);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
384
415
|
|
|
385
416
|
export { TriggerFactory, createTriggerFactory, getTriggerPath, handle, streamHandle, triggerPathUUID };
|