From 9f538783dce4021d32b3592786cc4c4d51da834d Mon Sep 17 00:00:00 2001 From: exoego Date: Sat, 1 Jun 2024 19:10:03 +0900 Subject: [PATCH 1/2] refactor(aws-lambda): merge custom-context into types so they are excluded from coverage --- runtime_tests/lambda/index.test.ts | 8 +- src/adapter/aws-lambda/custom-context.ts | 101 ++++------------------- src/adapter/aws-lambda/handler.ts | 5 +- src/adapter/aws-lambda/index.ts | 4 +- src/adapter/aws-lambda/types.ts | 88 ++++++++++++++++++++ 5 files changed, 114 insertions(+), 92 deletions(-) diff --git a/runtime_tests/lambda/index.test.ts b/runtime_tests/lambda/index.test.ts index 475200c36..8da3afc3c 100644 --- a/runtime_tests/lambda/index.test.ts +++ b/runtime_tests/lambda/index.test.ts @@ -1,11 +1,11 @@ import { Readable } from 'stream' +import { handle, streamHandle } from '../../src/adapter/aws-lambda/handler' +import type { LambdaEvent } from '../../src/adapter/aws-lambda/handler' import type { ApiGatewayRequestContext, ApiGatewayRequestContextV2, -} from '../../src/adapter/aws-lambda/custom-context' -import { handle, streamHandle } from '../../src/adapter/aws-lambda/handler' -import type { LambdaEvent } from '../../src/adapter/aws-lambda/handler' -import type { LambdaContext } from '../../src/adapter/aws-lambda/types' + LambdaContext, +} from '../../src/adapter/aws-lambda/types' import { getCookie, setCookie } from '../../src/helper/cookie' import { streamSSE } from '../../src/helper/streaming' import { Hono } from '../../src/hono' diff --git a/src/adapter/aws-lambda/custom-context.ts b/src/adapter/aws-lambda/custom-context.ts index b9dd48e26..3ec9bdc2a 100644 --- a/src/adapter/aws-lambda/custom-context.ts +++ b/src/adapter/aws-lambda/custom-context.ts @@ -1,87 +1,20 @@ -interface ClientCert { - clientCertPem: string - subjectDN: string - issuerDN: string - serialNumber: string - validity: { - notBefore: string - notAfter: string - } -} +import type { + ALBRequestContext as ALBRequestContext_, + ApiGatewayRequestContextV2 as ApiGatewayRequestContextV2_, + ApiGatewayRequestContext as ApiGatewayRequestContext_, +} from './types' -interface Identity { - accessKey?: string - accountId?: string - caller?: string - cognitoAuthenticationProvider?: string - cognitoAuthenticationType?: string - cognitoIdentityId?: string - cognitoIdentityPoolId?: string - principalOrgId?: string - sourceIp: string - user?: string - userAgent: string - userArn?: string - clientCert?: ClientCert -} +/** + * @deprecated Use `ApiGatewayRequestContext` from `@src/adapter/aws-lambda/types` instead. + */ +export type ApiGatewayRequestContext = ApiGatewayRequestContext_ -export interface ApiGatewayRequestContext { - accountId: string - apiId: string - authorizer: { - claims?: unknown - scopes?: unknown - } - domainName: string - domainPrefix: string - extendedRequestId: string - httpMethod: string - identity: Identity - path: string - protocol: string - requestId: string - requestTime: string - requestTimeEpoch: number - resourceId?: string - resourcePath: string - stage: string -} +/** + * @deprecated Use `ApiGatewayRequestContextV2` from `hono/aws-lambda/types` instead. + */ +export type ApiGatewayRequestContextV2 = ApiGatewayRequestContextV2_ -interface Authorizer { - iam?: { - accessKey: string - accountId: string - callerId: string - cognitoIdentity: null - principalOrgId: null - userArn: string - userId: string - } -} - -export interface ApiGatewayRequestContextV2 { - accountId: string - apiId: string - authentication: null - authorizer: Authorizer - domainName: string - domainPrefix: string - http: { - method: string - path: string - protocol: string - sourceIp: string - userAgent: string - } - requestId: string - routeKey: string - stage: string - time: string - timeEpoch: number -} - -export interface ALBRequestContext { - elb: { - targetGroupArn: string - } -} +/** + * @deprecated Use `ApiGatewayRequestContext` from `@src/adapter/aws-lambda/types` instead. + */ +export type ALBRequestContext = ALBRequestContext_ diff --git a/src/adapter/aws-lambda/handler.ts b/src/adapter/aws-lambda/handler.ts index e9d30e835..efb85eede 100644 --- a/src/adapter/aws-lambda/handler.ts +++ b/src/adapter/aws-lambda/handler.ts @@ -6,8 +6,9 @@ import type { ALBRequestContext, ApiGatewayRequestContext, ApiGatewayRequestContextV2, -} from './custom-context' -import type { Handler, LambdaContext } from './types' + Handler, + LambdaContext, +} from './types' // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore diff --git a/src/adapter/aws-lambda/index.ts b/src/adapter/aws-lambda/index.ts index 893bce23a..74d0a09ad 100644 --- a/src/adapter/aws-lambda/index.ts +++ b/src/adapter/aws-lambda/index.ts @@ -9,5 +9,5 @@ export type { ApiGatewayRequestContext, ApiGatewayRequestContextV2, ALBRequestContext, -} from './custom-context' -export type { LambdaContext } from './types' + LambdaContext, +} from './types' diff --git a/src/adapter/aws-lambda/types.ts b/src/adapter/aws-lambda/types.ts index d1054a7e0..d1ec95ebf 100644 --- a/src/adapter/aws-lambda/types.ts +++ b/src/adapter/aws-lambda/types.ts @@ -54,3 +54,91 @@ export type Handler = ( context: LambdaContext, callback: Callback ) => void | Promise + +interface ClientCert { + clientCertPem: string + subjectDN: string + issuerDN: string + serialNumber: string + validity: { + notBefore: string + notAfter: string + } +} + +interface Identity { + accessKey?: string + accountId?: string + caller?: string + cognitoAuthenticationProvider?: string + cognitoAuthenticationType?: string + cognitoIdentityId?: string + cognitoIdentityPoolId?: string + principalOrgId?: string + sourceIp: string + user?: string + userAgent: string + userArn?: string + clientCert?: ClientCert +} + +export interface ApiGatewayRequestContext { + accountId: string + apiId: string + authorizer: { + claims?: unknown + scopes?: unknown + } + domainName: string + domainPrefix: string + extendedRequestId: string + httpMethod: string + identity: Identity + path: string + protocol: string + requestId: string + requestTime: string + requestTimeEpoch: number + resourceId?: string + resourcePath: string + stage: string +} + +interface Authorizer { + iam?: { + accessKey: string + accountId: string + callerId: string + cognitoIdentity: null + principalOrgId: null + userArn: string + userId: string + } +} + +export interface ApiGatewayRequestContextV2 { + accountId: string + apiId: string + authentication: null + authorizer: Authorizer + domainName: string + domainPrefix: string + http: { + method: string + path: string + protocol: string + sourceIp: string + userAgent: string + } + requestId: string + routeKey: string + stage: string + time: string + timeEpoch: number +} + +export interface ALBRequestContext { + elb: { + targetGroupArn: string + } +} From 3082684456e962b1397d52d741671c66feb93464 Mon Sep 17 00:00:00 2001 From: exoego Date: Sun, 2 Jun 2024 23:18:45 +0900 Subject: [PATCH 2/2] refactor: custom-context.ts is not needed since it is hidden by reexport --- src/adapter/aws-lambda/custom-context.ts | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 src/adapter/aws-lambda/custom-context.ts diff --git a/src/adapter/aws-lambda/custom-context.ts b/src/adapter/aws-lambda/custom-context.ts deleted file mode 100644 index 3ec9bdc2a..000000000 --- a/src/adapter/aws-lambda/custom-context.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type { - ALBRequestContext as ALBRequestContext_, - ApiGatewayRequestContextV2 as ApiGatewayRequestContextV2_, - ApiGatewayRequestContext as ApiGatewayRequestContext_, -} from './types' - -/** - * @deprecated Use `ApiGatewayRequestContext` from `@src/adapter/aws-lambda/types` instead. - */ -export type ApiGatewayRequestContext = ApiGatewayRequestContext_ - -/** - * @deprecated Use `ApiGatewayRequestContextV2` from `hono/aws-lambda/types` instead. - */ -export type ApiGatewayRequestContextV2 = ApiGatewayRequestContextV2_ - -/** - * @deprecated Use `ApiGatewayRequestContext` from `@src/adapter/aws-lambda/types` instead. - */ -export type ALBRequestContext = ALBRequestContext_