@h4ad/serverless-adapter 2.16.0 → 3.0.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/README.md +7 -0
- package/lib/@types/binary-settings.js +2 -11
- package/lib/@types/binary-settings.js.map +1 -1
- package/lib/@types/digital-ocean/digital-ocean-http-event.js +2 -7
- package/lib/@types/digital-ocean/digital-ocean-http-event.js.map +1 -1
- package/lib/@types/digital-ocean/digital-ocean-http-response.js +2 -7
- package/lib/@types/digital-ocean/digital-ocean-http-response.js.map +1 -1
- package/lib/@types/digital-ocean/index.js +2 -18
- package/lib/@types/digital-ocean/index.js.map +1 -1
- package/lib/@types/headers.js +2 -11
- package/lib/@types/headers.js.map +1 -1
- package/lib/@types/helpers.js +2 -6
- package/lib/@types/helpers.js.map +1 -1
- package/lib/@types/huawei/huawei-api-gateway-event.js +2 -14
- package/lib/@types/huawei/huawei-api-gateway-event.js.map +1 -1
- package/lib/@types/huawei/huawei-api-gateway-response.js +2 -7
- package/lib/@types/huawei/huawei-api-gateway-response.js.map +1 -1
- package/lib/@types/huawei/huawei-context.js +2 -36
- package/lib/@types/huawei/huawei-context.js.map +1 -1
- package/lib/@types/huawei/index.js +2 -20
- package/lib/@types/huawei/index.js.map +1 -1
- package/lib/@types/index.js +2 -20
- package/lib/@types/index.js.map +1 -1
- package/lib/adapters/apollo-server/apollo-server-mutation.adapter.js +2 -86
- package/lib/adapters/apollo-server/apollo-server-mutation.adapter.js.map +1 -1
- package/lib/adapters/apollo-server/index.js +2 -18
- package/lib/adapters/apollo-server/index.js.map +1 -1
- package/lib/adapters/aws/alb.adapter.js +2 -129
- package/lib/adapters/aws/alb.adapter.js.map +1 -1
- package/lib/adapters/aws/api-gateway-v1.adapter.js +2 -140
- package/lib/adapters/aws/api-gateway-v1.adapter.js.map +1 -1
- package/lib/adapters/aws/api-gateway-v2.adapter.js +2 -133
- package/lib/adapters/aws/api-gateway-v2.adapter.js.map +1 -1
- package/lib/adapters/aws/base/aws-simple-adapter.js +2 -99
- package/lib/adapters/aws/base/aws-simple-adapter.js.map +1 -1
- package/lib/adapters/aws/base/index.js +2 -18
- package/lib/adapters/aws/base/index.js.map +1 -1
- package/lib/adapters/aws/dynamodb.adapter.js +2 -64
- package/lib/adapters/aws/dynamodb.adapter.js.map +1 -1
- package/lib/adapters/aws/event-bridge.adapter.js +2 -75
- package/lib/adapters/aws/event-bridge.adapter.js.map +1 -1
- package/lib/adapters/aws/index.js +2 -27
- package/lib/adapters/aws/index.js.map +1 -1
- package/lib/adapters/aws/lambda-edge.adapter.js +2 -284
- package/lib/adapters/aws/lambda-edge.adapter.js.map +1 -1
- package/lib/adapters/aws/s3.adapter.js +2 -63
- package/lib/adapters/aws/s3.adapter.js.map +1 -1
- package/lib/adapters/aws/sns.adapter.js +2 -63
- package/lib/adapters/aws/sns.adapter.js.map +1 -1
- package/lib/adapters/aws/sqs.adapter.js +2 -64
- package/lib/adapters/aws/sqs.adapter.js.map +1 -1
- package/lib/adapters/azure/http-trigger-v4.adapter.js +2 -202
- package/lib/adapters/azure/http-trigger-v4.adapter.js.map +1 -1
- package/lib/adapters/azure/index.js +2 -18
- package/lib/adapters/azure/index.js.map +1 -1
- package/lib/adapters/digital-ocean/http-function.adapter.js +2 -118
- package/lib/adapters/digital-ocean/http-function.adapter.js.map +1 -1
- package/lib/adapters/digital-ocean/index.js +2 -18
- package/lib/adapters/digital-ocean/index.js.map +1 -1
- package/lib/adapters/dummy/dummy.adapter.js +2 -54
- package/lib/adapters/dummy/dummy.adapter.js.map +1 -1
- package/lib/adapters/dummy/index.js +2 -18
- package/lib/adapters/dummy/index.js.map +1 -1
- package/lib/adapters/huawei/huawei-api-gateway.adapter.js +2 -126
- package/lib/adapters/huawei/huawei-api-gateway.adapter.js.map +1 -1
- package/lib/adapters/huawei/index.js +2 -18
- package/lib/adapters/huawei/index.js.map +1 -1
- package/lib/contracts/adapter.contract.js +2 -18
- package/lib/contracts/adapter.contract.js.map +1 -1
- package/lib/contracts/framework.contract.js +2 -7
- package/lib/contracts/framework.contract.js.map +1 -1
- package/lib/contracts/handler.contract.js +2 -13
- package/lib/contracts/handler.contract.js.map +1 -1
- package/lib/contracts/index.js +2 -21
- package/lib/contracts/index.js.map +1 -1
- package/lib/contracts/resolver.contract.js +2 -15
- package/lib/contracts/resolver.contract.js.map +1 -1
- package/lib/core/base-handler.js +2 -67
- package/lib/core/base-handler.js.map +1 -1
- package/lib/core/constants.js +2 -33
- package/lib/core/constants.js.map +1 -1
- package/lib/core/current-invoke.js +2 -46
- package/lib/core/current-invoke.js.map +1 -1
- package/lib/core/event-body.js +2 -31
- package/lib/core/event-body.js.map +1 -1
- package/lib/core/headers.js +3 -67
- package/lib/core/headers.js.map +1 -1
- package/lib/core/index.js +2 -28
- package/lib/core/index.js.map +1 -1
- package/lib/core/is-binary.js +2 -118
- package/lib/core/is-binary.js.map +1 -1
- package/lib/core/logger.js +2 -115
- package/lib/core/logger.js.map +1 -1
- package/lib/core/no-op.js +2 -12
- package/lib/core/no-op.js.map +1 -1
- package/lib/core/optional.js +2 -31
- package/lib/core/optional.js.map +1 -1
- package/lib/core/path.js +2 -68
- package/lib/core/path.js.map +1 -1
- package/lib/core/stream.js +2 -63
- package/lib/core/stream.js.map +1 -1
- package/lib/frameworks/apollo-server/apollo-server.framework.js +2 -87
- package/lib/frameworks/apollo-server/apollo-server.framework.js.map +1 -1
- package/lib/frameworks/apollo-server/index.js +2 -18
- package/lib/frameworks/apollo-server/index.js.map +1 -1
- package/lib/frameworks/body-parser/base-body-parser.framework.js +2 -66
- package/lib/frameworks/body-parser/base-body-parser.framework.js.map +1 -1
- package/lib/frameworks/body-parser/index.js +2 -22
- package/lib/frameworks/body-parser/index.js.map +1 -1
- package/lib/frameworks/body-parser/json-body-parser.framework.js +2 -29
- package/lib/frameworks/body-parser/json-body-parser.framework.js.map +1 -1
- package/lib/frameworks/body-parser/raw-body-parser.framework.js +2 -29
- package/lib/frameworks/body-parser/raw-body-parser.framework.js.map +1 -1
- package/lib/frameworks/body-parser/text-body-parser.framework.js +2 -29
- package/lib/frameworks/body-parser/text-body-parser.framework.js.map +1 -1
- package/lib/frameworks/body-parser/urlencoded-body-parser.framework.js +2 -29
- package/lib/frameworks/body-parser/urlencoded-body-parser.framework.js.map +1 -1
- package/lib/frameworks/cors/cors.framework.js +3 -145
- package/lib/frameworks/cors/cors.framework.js.map +1 -1
- package/lib/frameworks/cors/index.js +2 -18
- package/lib/frameworks/cors/index.js.map +1 -1
- package/lib/frameworks/deepkit/http-deepkit.framework.js +2 -33
- package/lib/frameworks/deepkit/http-deepkit.framework.js.map +1 -1
- package/lib/frameworks/deepkit/index.js +2 -18
- package/lib/frameworks/deepkit/index.js.map +1 -1
- package/lib/frameworks/express/express.framework.js +2 -22
- package/lib/frameworks/express/express.framework.js.map +1 -1
- package/lib/frameworks/express/index.js +2 -18
- package/lib/frameworks/express/index.js.map +1 -1
- package/lib/frameworks/fastify/fastify.framework.js +2 -23
- package/lib/frameworks/fastify/fastify.framework.js.map +1 -1
- package/lib/frameworks/fastify/helpers/no-op-content-parser.js +2 -27
- package/lib/frameworks/fastify/helpers/no-op-content-parser.js.map +1 -1
- package/lib/frameworks/fastify/index.js +2 -18
- package/lib/frameworks/fastify/index.js.map +1 -1
- package/lib/frameworks/hapi/hapi.framework.js +2 -23
- package/lib/frameworks/hapi/hapi.framework.js.map +1 -1
- package/lib/frameworks/hapi/index.js +2 -18
- package/lib/frameworks/hapi/index.js.map +1 -1
- package/lib/frameworks/koa/index.js +2 -18
- package/lib/frameworks/koa/index.js.map +1 -1
- package/lib/frameworks/koa/koa.framework.js +2 -22
- package/lib/frameworks/koa/koa.framework.js.map +1 -1
- package/lib/frameworks/lazy/index.js +2 -18
- package/lib/frameworks/lazy/index.js.map +1 -1
- package/lib/frameworks/lazy/lazy.framework.js +2 -82
- package/lib/frameworks/lazy/lazy.framework.js.map +1 -1
- package/lib/frameworks/trpc/index.js +2 -18
- package/lib/frameworks/trpc/index.js.map +1 -1
- package/lib/frameworks/trpc/trpc.framework.js +2 -152
- package/lib/frameworks/trpc/trpc.framework.js.map +1 -1
- package/lib/handlers/aws/aws-stream.handler.js +2 -0
- package/lib/handlers/aws/aws-stream.handler.js.map +1 -0
- package/lib/handlers/aws/index.js +2 -0
- package/lib/handlers/aws/index.js.map +1 -0
- package/lib/handlers/azure/azure.handler.js +2 -74
- package/lib/handlers/azure/azure.handler.js.map +1 -1
- package/lib/handlers/azure/index.js +2 -18
- package/lib/handlers/azure/index.js.map +1 -1
- package/lib/handlers/base/index.js +2 -18
- package/lib/handlers/base/index.js.map +1 -1
- package/lib/handlers/base/raw-request.js +2 -65
- package/lib/handlers/base/raw-request.js.map +1 -1
- package/lib/handlers/default/default.handler.js +2 -191
- package/lib/handlers/default/default.handler.js.map +1 -1
- package/lib/handlers/default/index.js +2 -18
- package/lib/handlers/default/index.js.map +1 -1
- package/lib/handlers/digital-ocean/digital-ocean.handler.js +2 -34
- package/lib/handlers/digital-ocean/digital-ocean.handler.js.map +1 -1
- package/lib/handlers/digital-ocean/index.js +2 -18
- package/lib/handlers/digital-ocean/index.js.map +1 -1
- package/lib/handlers/firebase/http-firebase-v2.handler.js +2 -50
- package/lib/handlers/firebase/http-firebase-v2.handler.js.map +1 -1
- package/lib/handlers/firebase/http-firebase.handler.js +2 -27
- package/lib/handlers/firebase/http-firebase.handler.js.map +1 -1
- package/lib/handlers/firebase/index.js +2 -19
- package/lib/handlers/firebase/index.js.map +1 -1
- package/lib/handlers/gcp/gcp.handler.js +2 -40
- package/lib/handlers/gcp/gcp.handler.js.map +1 -1
- package/lib/handlers/gcp/index.js +2 -18
- package/lib/handlers/gcp/index.js.map +1 -1
- package/lib/handlers/huawei/http-huawei.handler.js +2 -106
- package/lib/handlers/huawei/http-huawei.handler.js.map +1 -1
- package/lib/handlers/huawei/index.js +2 -18
- package/lib/handlers/huawei/index.js.map +1 -1
- package/lib/index.doc.js +2 -0
- package/lib/index.doc.js.map +1 -0
- package/lib/index.js +2 -22
- package/lib/index.js.map +1 -1
- package/lib/network/index.js +2 -19
- package/lib/network/index.js.map +1 -1
- package/lib/network/request.js +2 -46
- package/lib/network/request.js.map +1 -1
- package/lib/network/response-stream.js +7 -0
- package/lib/network/response-stream.js.map +1 -0
- package/lib/network/response.js +4 -137
- package/lib/network/response.js.map +1 -1
- package/lib/network/utils.js +2 -0
- package/lib/network/utils.js.map +1 -0
- package/lib/resolvers/aws-context/aws-context.resolver.js +2 -59
- package/lib/resolvers/aws-context/aws-context.resolver.js.map +1 -1
- package/lib/resolvers/aws-context/index.js +2 -18
- package/lib/resolvers/aws-context/index.js.map +1 -1
- package/lib/resolvers/callback/callback.resolver.js +2 -53
- package/lib/resolvers/callback/callback.resolver.js.map +1 -1
- package/lib/resolvers/callback/index.js +2 -18
- package/lib/resolvers/callback/index.js.map +1 -1
- package/lib/resolvers/dummy/dummy.resolver.js +2 -24
- package/lib/resolvers/dummy/dummy.resolver.js.map +1 -1
- package/lib/resolvers/dummy/index.js +2 -18
- package/lib/resolvers/dummy/index.js.map +1 -1
- package/lib/resolvers/promise/index.js +2 -18
- package/lib/resolvers/promise/index.js.map +1 -1
- package/lib/resolvers/promise/promise.resolver.js +2 -48
- package/lib/resolvers/promise/promise.resolver.js.map +1 -1
- package/lib/serverless-adapter.js +2 -176
- package/lib/serverless-adapter.js.map +1 -1
- package/package.json +61 -79
- package/lib/@types/binary-settings.d.ts +0 -43
- package/lib/@types/digital-ocean/digital-ocean-http-event.d.ts +0 -37
- package/lib/@types/digital-ocean/digital-ocean-http-response.d.ts +0 -22
- package/lib/@types/digital-ocean/index.d.ts +0 -1
- package/lib/@types/headers.d.ts +0 -39
- package/lib/@types/helpers.d.ts +0 -10
- package/lib/@types/huawei/huawei-api-gateway-event.d.ts +0 -84
- package/lib/@types/huawei/huawei-api-gateway-response.d.ts +0 -27
- package/lib/@types/huawei/huawei-context.d.ts +0 -203
- package/lib/@types/huawei/index.d.ts +0 -3
- package/lib/@types/index.d.ts +0 -3
- package/lib/adapters/apollo-server/apollo-server-mutation.adapter.d.ts +0 -56
- package/lib/adapters/apollo-server/index.d.ts +0 -1
- package/lib/adapters/aws/alb.adapter.d.ts +0 -66
- package/lib/adapters/aws/api-gateway-v1.adapter.d.ts +0 -71
- package/lib/adapters/aws/api-gateway-v2.adapter.d.ts +0 -69
- package/lib/adapters/aws/base/aws-simple-adapter.d.ts +0 -85
- package/lib/adapters/aws/base/index.d.ts +0 -1
- package/lib/adapters/aws/dynamodb.adapter.d.ts +0 -56
- package/lib/adapters/aws/event-bridge.adapter.d.ts +0 -64
- package/lib/adapters/aws/index.d.ts +0 -10
- package/lib/adapters/aws/lambda-edge.adapter.d.ts +0 -213
- package/lib/adapters/aws/s3.adapter.d.ts +0 -56
- package/lib/adapters/aws/sns.adapter.d.ts +0 -56
- package/lib/adapters/aws/sqs.adapter.d.ts +0 -56
- package/lib/adapters/azure/http-trigger-v4.adapter.d.ts +0 -81
- package/lib/adapters/azure/index.d.ts +0 -1
- package/lib/adapters/digital-ocean/http-function.adapter.d.ts +0 -65
- package/lib/adapters/digital-ocean/index.d.ts +0 -1
- package/lib/adapters/dummy/dummy.adapter.d.ts +0 -30
- package/lib/adapters/dummy/index.d.ts +0 -1
- package/lib/adapters/huawei/huawei-api-gateway.adapter.d.ts +0 -66
- package/lib/adapters/huawei/index.d.ts +0 -1
- package/lib/contracts/adapter.contract.d.ts +0 -155
- package/lib/contracts/framework.contract.d.ts +0 -19
- package/lib/contracts/handler.contract.d.ts +0 -26
- package/lib/contracts/index.d.ts +0 -4
- package/lib/contracts/resolver.contract.d.ts +0 -86
- package/lib/core/base-handler.d.ts +0 -31
- package/lib/core/constants.d.ts +0 -31
- package/lib/core/current-invoke.d.ts +0 -48
- package/lib/core/event-body.d.ts +0 -21
- package/lib/core/headers.d.ts +0 -37
- package/lib/core/index.d.ts +0 -11
- package/lib/core/is-binary.d.ts +0 -72
- package/lib/core/logger.d.ts +0 -67
- package/lib/core/no-op.d.ts +0 -7
- package/lib/core/optional.d.ts +0 -21
- package/lib/core/path.d.ts +0 -36
- package/lib/core/stream.d.ts +0 -20
- package/lib/frameworks/apollo-server/apollo-server.framework.d.ts +0 -71
- package/lib/frameworks/apollo-server/index.d.ts +0 -1
- package/lib/frameworks/body-parser/base-body-parser.framework.d.ts +0 -69
- package/lib/frameworks/body-parser/index.d.ts +0 -5
- package/lib/frameworks/body-parser/json-body-parser.framework.d.ts +0 -26
- package/lib/frameworks/body-parser/raw-body-parser.framework.d.ts +0 -26
- package/lib/frameworks/body-parser/text-body-parser.framework.d.ts +0 -26
- package/lib/frameworks/body-parser/urlencoded-body-parser.framework.d.ts +0 -26
- package/lib/frameworks/cors/cors.framework.d.ts +0 -78
- package/lib/frameworks/cors/index.d.ts +0 -1
- package/lib/frameworks/deepkit/http-deepkit.framework.d.ts +0 -17
- package/lib/frameworks/deepkit/index.d.ts +0 -1
- package/lib/frameworks/express/express.framework.d.ts +0 -16
- package/lib/frameworks/express/index.d.ts +0 -1
- package/lib/frameworks/fastify/fastify.framework.d.ts +0 -16
- package/lib/frameworks/fastify/helpers/no-op-content-parser.d.ts +0 -13
- package/lib/frameworks/fastify/index.d.ts +0 -1
- package/lib/frameworks/hapi/hapi.framework.d.ts +0 -16
- package/lib/frameworks/hapi/index.d.ts +0 -1
- package/lib/frameworks/koa/index.d.ts +0 -1
- package/lib/frameworks/koa/koa.framework.d.ts +0 -16
- package/lib/frameworks/lazy/index.d.ts +0 -1
- package/lib/frameworks/lazy/lazy.framework.d.ts +0 -55
- package/lib/frameworks/trpc/index.d.ts +0 -1
- package/lib/frameworks/trpc/trpc.framework.d.ts +0 -154
- package/lib/handlers/azure/azure.handler.d.ts +0 -45
- package/lib/handlers/azure/index.d.ts +0 -1
- package/lib/handlers/base/index.d.ts +0 -1
- package/lib/handlers/base/raw-request.d.ts +0 -30
- package/lib/handlers/default/default.handler.d.ts +0 -87
- package/lib/handlers/default/index.d.ts +0 -1
- package/lib/handlers/digital-ocean/digital-ocean.handler.d.ts +0 -16
- package/lib/handlers/digital-ocean/index.d.ts +0 -1
- package/lib/handlers/firebase/http-firebase-v2.handler.d.ts +0 -26
- package/lib/handlers/firebase/http-firebase.handler.d.ts +0 -18
- package/lib/handlers/firebase/index.d.ts +0 -2
- package/lib/handlers/gcp/gcp.handler.d.ts +0 -25
- package/lib/handlers/gcp/index.d.ts +0 -1
- package/lib/handlers/huawei/http-huawei.handler.d.ts +0 -59
- package/lib/handlers/huawei/index.d.ts +0 -1
- package/lib/index.d.ts +0 -5
- package/lib/network/index.d.ts +0 -2
- package/lib/network/request.d.ts +0 -44
- package/lib/network/response.d.ts +0 -48
- package/lib/resolvers/aws-context/aws-context.resolver.d.ts +0 -18
- package/lib/resolvers/aws-context/index.d.ts +0 -1
- package/lib/resolvers/callback/callback.resolver.d.ts +0 -23
- package/lib/resolvers/callback/index.d.ts +0 -1
- package/lib/resolvers/dummy/dummy.resolver.d.ts +0 -13
- package/lib/resolvers/dummy/index.d.ts +0 -1
- package/lib/resolvers/promise/index.d.ts +0 -1
- package/lib/resolvers/promise/promise.resolver.d.ts +0 -13
- package/lib/serverless-adapter.d.ts +0 -118
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolver.contract.js","
|
|
1
|
+
{"version":3,"file":"resolver.contract.js","sources":["../../src/contracts/resolver.contract.ts"],"sourcesContent":["//#region Imports\n\nimport { ILogger } from '../core';\nimport { AdapterContract } from './adapter.contract';\n\n//#endregion\n\n/**\n * The type that represents a resolver used to send the response, error or success, to the client\n *\n * @breadcrumb Contracts / ResolverContract\n * @public\n */\nexport type Resolver<TResponse, TReturn> = {\n /**\n * The method that will perform the task of forwarding the request to the framework and waiting for the promise to be resolved with the response\n *\n * @param task - The task to be executed\n */\n run(task: () => Promise<TResponse>): TReturn;\n};\n\n/**\n * The type that represents a delegate resolver that is passed to the adapter to handle what to do when an error occurs during forwarding.\n *\n * @breadcrumb Contracts / ResolverContract\n * @public\n */\nexport type DelegatedResolver<TResponse> = {\n /**\n * Send the success response to the client\n *\n * @param success - The serverless response\n */\n succeed: (response: TResponse) => void;\n\n /**\n * Send the error response to the client\n *\n * @param error - The error object\n */\n fail: (error: Error) => void;\n};\n\n/**\n * The createResolver contract props\n *\n * @breadcrumb Contracts / ResolverContract\n * @public\n */\nexport type ResolverProps<TEvent, TContext, TCallback, TResponse> = {\n /**\n * The event sent by the serverless environment\n */\n event: TEvent;\n\n /**\n * Indicates whether to forward the (error.stack) or not to the client\n */\n respondWithErrors: boolean;\n\n /**\n * The instance of the logger\n */\n log: ILogger;\n\n /**\n * The instance of the adapter\n */\n adapter: AdapterContract<TEvent, TContext, TResponse>;\n\n /**\n * The context sent by serverless\n */\n context?: TContext;\n\n /**\n * The callback sent by serverless\n */\n callback?: TCallback;\n};\n\n/**\n * The interface that represents the contract used to send the response to the client\n *\n * @breadcrumb Contracts / ResolverContract\n * @public\n */\nexport interface ResolverContract<\n TEvent,\n TContext,\n TCallback,\n TResponse,\n TReturn,\n> {\n /**\n * Create the resolver based on the context, callback or promise\n *\n * @param props - The props used to create the resolver\n */\n createResolver(\n props: ResolverProps<TEvent, TContext, TCallback, TResponse>,\n ): Resolver<TResponse, TReturn>;\n}\n"],"names":["resolver_contract_exports","__toCommonJS"],"mappings":"2VAAAA,EAAA,CAAA,EAAA,OAAA,QAAAC,EAAAD,CAAA"}
|
package/lib/core/base-handler.js
CHANGED
|
@@ -1,67 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.BaseHandler = void 0;
|
|
4
|
-
const { __ΩFrameworkContract } = require('../contracts');
|
|
5
|
-
const { __ΩAdapterContract } = require('../contracts');
|
|
6
|
-
const { __ΩResolverContract } = require('../contracts');
|
|
7
|
-
const { __ΩBinarySettings } = require('../@types');
|
|
8
|
-
const { __ΩILogger } = require('./index');
|
|
9
|
-
const { __ΩServerlessHandler } = require('../contracts');
|
|
10
|
-
const { __ΩAdapterRequest } = require('../contracts');
|
|
11
|
-
function __assignType(fn, args) {
|
|
12
|
-
fn.__type = args;
|
|
13
|
-
return fn;
|
|
14
|
-
}
|
|
15
|
-
const network_1 = require("../network");
|
|
16
|
-
//#endregion
|
|
17
|
-
/**
|
|
18
|
-
* The abstract class that represents the base class for a handler
|
|
19
|
-
*
|
|
20
|
-
* @breadcrumb Core
|
|
21
|
-
* @public
|
|
22
|
-
*/
|
|
23
|
-
class BaseHandler {
|
|
24
|
-
//#endregion
|
|
25
|
-
//#region Protected Methods
|
|
26
|
-
/**
|
|
27
|
-
* Get the adapter to handle a specific event and context
|
|
28
|
-
*
|
|
29
|
-
* @param event - The event sent by serverless
|
|
30
|
-
* @param context - The context sent by serverless
|
|
31
|
-
* @param adapters - The list of adapters
|
|
32
|
-
* @param log - The instance of logger
|
|
33
|
-
*/
|
|
34
|
-
getAdapterByEventAndContext(event, context, adapters, log) {
|
|
35
|
-
const resolvedAdapters = adapters.filter(__assignType(adapter => adapter.canHandle(event, context, log), ['adapter', '', 'P"2!"/"']));
|
|
36
|
-
if (resolvedAdapters.length === 0) {
|
|
37
|
-
throw new Error("SERVERLESS_ADAPTER: Couldn't find adapter to handle this event.");
|
|
38
|
-
}
|
|
39
|
-
if (resolvedAdapters.length > 1) {
|
|
40
|
-
throw new Error(`SERVERLESS_ADAPTER: Two or more adapters was resolved by the event, the adapters are: ${adapters
|
|
41
|
-
.map(__assignType(adapter => adapter.getAdapterName(), ['adapter', '', 'P"2!"/"']))
|
|
42
|
-
.join(', ')}.`);
|
|
43
|
-
}
|
|
44
|
-
return resolvedAdapters[0];
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Get serverless request and response frmo the adapter request
|
|
48
|
-
*
|
|
49
|
-
* @param requestValues - The request values from adapter
|
|
50
|
-
*/
|
|
51
|
-
getServerlessRequestResponseFromAdapterRequest(requestValues) {
|
|
52
|
-
const request = new network_1.ServerlessRequest({
|
|
53
|
-
method: requestValues.method,
|
|
54
|
-
headers: requestValues.headers,
|
|
55
|
-
body: requestValues.body,
|
|
56
|
-
remoteAddress: requestValues.remoteAddress,
|
|
57
|
-
url: requestValues.path,
|
|
58
|
-
});
|
|
59
|
-
const response = new network_1.ServerlessResponse({
|
|
60
|
-
method: requestValues.method,
|
|
61
|
-
});
|
|
62
|
-
return [request, response];
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
exports.BaseHandler = BaseHandler;
|
|
66
|
-
BaseHandler.__type = ['TApp', 'TEvent', 'TContext', 'TCallback', 'TResponse', 'TReturn', 'app', () => __ΩFrameworkContract, 'framework', () => __ΩAdapterContract, 'adapters', () => __ΩResolverContract, 'resolverFactory', () => __ΩBinarySettings, 'binarySettings', 'respondWithErrors', () => __ΩILogger, 'log', () => __ΩServerlessHandler, 'getHandler', 'event', 'context', () => __ΩAdapterContract, () => __ΩILogger, () => __ΩAdapterContract, 'getAdapterByEventAndContext', () => __ΩAdapterRequest, 'requestValues', () => network_1.ServerlessRequest, 'request', () => network_1.ServerlessResponse, 'response', 'getServerlessRequestResponseFromAdapterRequest', 'b!b"b#b$b%b&Pe"!2\'e"!o("2)e""e"#e"%o*$F2+e""e"#e"$e"%e"&o,&2-n.2/)20n122e"&o3"04=Pe""25e"#26e""e"#e"%o7$F2+n822e""e"#e"%o9$0:<Pn;2<PP7=I>P7?I@G0A<5e!!e!"e!#e!$e!%e!&6\''];
|
|
67
|
-
//# sourceMappingURL=base-handler.js.map
|
|
1
|
+
"use strict";var d=Object.defineProperty,v=Object.getOwnPropertyDescriptor,h=Object.getOwnPropertyNames,l=Object.prototype.hasOwnProperty,c=(r,e)=>{for(var t in e)d(r,t,{get:e[t],enumerable:!0})},i=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of h(e))!l.call(r,n)&&n!==t&&d(r,n,{get:()=>e[n],enumerable:!(o=v(e,n))||o.enumerable});return r},w=r=>i(d({},"__esModule",{value:!0}),r),_={};c(_,{BaseHandler:()=>y});module.exports=w(_);var p=require("../network");class y{getAdapterByEventAndContext(e,t,o,n){const a=o.filter(s=>s.canHandle(e,t,n));if(a.length===0)throw new Error("SERVERLESS_ADAPTER: Couldn't find adapter to handle this event.");if(a.length>1)throw new Error(`SERVERLESS_ADAPTER: Two or more adapters was resolved by the event, the adapters are: ${o.map(s=>s.getAdapterName()).join(", ")}.`);return a[0]}getServerlessRequestResponseFromAdapterRequest(e){const t=new p.ServerlessRequest({method:e.method,headers:e.headers,body:e.body,remoteAddress:e.remoteAddress,url:e.path}),o=new p.ServerlessResponse({method:e.method});return[t,o]}}
|
|
2
|
+
//# sourceMappingURL=base-handler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-handler.js","
|
|
1
|
+
{"version":3,"file":"base-handler.js","sources":["../../src/core/base-handler.ts"],"sourcesContent":["//#region Imports\n\nimport { BinarySettings } from '../@types';\nimport {\n AdapterContract,\n AdapterRequest,\n FrameworkContract,\n HandlerContract,\n ResolverContract,\n ServerlessHandler,\n} from '../contracts';\nimport { ServerlessRequest, ServerlessResponse } from '../network';\nimport { ILogger } from './index';\n\n//#endregion\n\n/**\n * The abstract class that represents the base class for a handler\n *\n * @breadcrumb Core\n * @public\n */\nexport abstract class BaseHandler<\n TApp,\n TEvent,\n TContext,\n TCallback,\n TResponse,\n TReturn,\n> implements\n HandlerContract<TApp, TEvent, TContext, TCallback, TResponse, TReturn>\n{\n //#region Public Methods\n\n /**\n * Get the handler that will handle serverless requests\n */\n public abstract getHandler(\n app: TApp,\n framework: FrameworkContract<TApp>,\n adapters: AdapterContract<TEvent, TContext, TResponse>[],\n resolverFactory: ResolverContract<\n TEvent,\n TContext,\n TCallback,\n TResponse,\n TReturn\n >,\n binarySettings: BinarySettings,\n respondWithErrors: boolean,\n log: ILogger,\n ): ServerlessHandler<TReturn>;\n\n //#endregion\n\n //#region Protected Methods\n\n /**\n * Get the adapter to handle a specific event and context\n *\n * @param event - The event sent by serverless\n * @param context - The context sent by serverless\n * @param adapters - The list of adapters\n * @param log - The instance of logger\n */\n protected getAdapterByEventAndContext(\n event: TEvent,\n context: TContext,\n adapters: AdapterContract<TEvent, TContext, TResponse>[],\n log: ILogger,\n ): AdapterContract<TEvent, TContext, TResponse> {\n const resolvedAdapters = adapters.filter(adapter =>\n adapter.canHandle(event, context, log),\n );\n\n if (resolvedAdapters.length === 0) {\n throw new Error(\n \"SERVERLESS_ADAPTER: Couldn't find adapter to handle this event.\",\n );\n }\n\n if (resolvedAdapters.length > 1) {\n throw new Error(\n `SERVERLESS_ADAPTER: Two or more adapters was resolved by the event, the adapters are: ${adapters\n .map(adapter => adapter.getAdapterName())\n .join(', ')}.`,\n );\n }\n\n return resolvedAdapters[0];\n }\n\n /**\n * Get serverless request and response frmo the adapter request\n *\n * @param requestValues - The request values from adapter\n */\n protected getServerlessRequestResponseFromAdapterRequest(\n requestValues: AdapterRequest,\n ): [request: ServerlessRequest, response: ServerlessResponse] {\n const request = new ServerlessRequest({\n method: requestValues.method,\n headers: requestValues.headers,\n body: requestValues.body,\n remoteAddress: requestValues.remoteAddress,\n url: requestValues.path,\n });\n\n const response = new ServerlessResponse({\n method: requestValues.method,\n });\n\n return [request, response];\n }\n\n //#endregion\n}\n"],"names":["base_handler_exports","__export","BaseHandler","__toCommonJS","import_network","event","context","adapters","log","resolvedAdapters","adapter","requestValues","request","response"],"mappings":"qZAAAA,EAAA,CAAA,EAAAC,EAAAD,EAAA,CAAA,YAAA,IAAAE,CAAA,CAAA,EAAA,OAAA,QAAAC,EAAAH,CAAA,EAWA,IAAsDI,EAAA,QAAA,YAAA,EAW/C,MAAeF,CAStB,CAkCY,4BACRG,EACAC,EACAC,EACAC,EAC8C,CAC9C,MAAMC,EAAmBF,EAAS,OAChCG,GAAAA,EAAQ,UAAUL,EAAOC,EAASE,CAAG,CAAA,EAGnC,GAAAC,EAAiB,SAAW,EAC9B,MAAM,IAAI,MACR,iEAAA,EAIA,GAAAA,EAAiB,OAAS,EAC5B,MAAM,IAAI,MACR,yFAAyFF,EACtF,IAAIG,GAAWA,EAAQ,eAAe,CAAC,EACvC,KAAK,IAAI,IAAA,EAIhB,OAAOD,EAAiB,CAAC,CAC3B,CAOU,+CACRE,EAC4D,CACtD,MAAAC,EAAU,IAAIR,EAAkB,kBAAA,CACpC,OAAQO,EAAc,OACtB,QAASA,EAAc,QACvB,KAAMA,EAAc,KACpB,cAAeA,EAAc,cAC7B,IAAKA,EAAc,IAAA,CACpB,EAEKE,EAAW,IAAIT,EAAmB,mBAAA,CACtC,OAAQO,EAAc,MAAA,CACvB,EAEM,MAAA,CAACC,EAASC,CAAQ,CAC3B,CAGF"}
|
package/lib/core/constants.js
CHANGED
|
@@ -1,33 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.EmptyResponse = exports.__ΩIEmptyResponse = exports.DEFAULT_BINARY_CONTENT_TYPES = exports.DEFAULT_BINARY_ENCODINGS = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Default encodings that are treated as binary, they are compared with the `Content-Encoding` header.
|
|
6
|
-
*
|
|
7
|
-
* @breadcrumb Core / Constants
|
|
8
|
-
* @defaultValue ['gzip', 'deflate', 'br']
|
|
9
|
-
* @public
|
|
10
|
-
*/
|
|
11
|
-
exports.DEFAULT_BINARY_ENCODINGS = ['gzip', 'deflate', 'br'];
|
|
12
|
-
/**
|
|
13
|
-
* Default content types that are treated as binary, they are compared with the `Content-Type` header.
|
|
14
|
-
*
|
|
15
|
-
* @breadcrumb Core / Constants
|
|
16
|
-
* @defaultValue [new RegExp('^image/.*$'), new RegExp('^video/.*$'), 'application/pdf']
|
|
17
|
-
* @public
|
|
18
|
-
*/
|
|
19
|
-
exports.DEFAULT_BINARY_CONTENT_TYPES = [
|
|
20
|
-
new RegExp('^image/.*$'),
|
|
21
|
-
new RegExp('^video/.*$'),
|
|
22
|
-
'application/pdf',
|
|
23
|
-
];
|
|
24
|
-
const __ΩIEmptyResponse = ['PM'];
|
|
25
|
-
exports.__ΩIEmptyResponse = __ΩIEmptyResponse;
|
|
26
|
-
/**
|
|
27
|
-
* Constant for empty response and can be used on some adapters when the adapter does not need to return a response.
|
|
28
|
-
*
|
|
29
|
-
* @breadcrumb Core / Constants
|
|
30
|
-
* @public
|
|
31
|
-
*/
|
|
32
|
-
exports.EmptyResponse = {};
|
|
33
|
-
//# sourceMappingURL=constants.js.map
|
|
1
|
+
"use strict";var a=Object.defineProperty,n=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,g=Object.prototype.hasOwnProperty,s=(t,e)=>{for(var p in e)a(t,p,{get:e[p],enumerable:!0})},c=(t,e,p,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of i(e))!g.call(t,r)&&r!==p&&a(t,r,{get:()=>e[r],enumerable:!(o=n(e,r))||o.enumerable});return t},N=t=>c(a({},"__esModule",{value:!0}),t),_={};s(_,{DEFAULT_BINARY_CONTENT_TYPES:()=>m,DEFAULT_BINARY_ENCODINGS:()=>O,EmptyResponse:()=>v});module.exports=N(_);const O=["gzip","deflate","br"],m=["image/png","image/jpeg","image/jpg","image/avif","image/bmp","image/x-png","image/gif","image/webp","video/mp4","application/pdf"],v={};
|
|
2
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../../src/core/constants.ts"],"sourcesContent":["/**\n * Default encodings that are treated as binary, they are compared with the `Content-Encoding` header.\n *\n * @breadcrumb Core / Constants\n * @defaultValue ['gzip', 'deflate', 'br']\n * @public\n */\nexport const DEFAULT_BINARY_ENCODINGS: string[] = ['gzip', 'deflate', 'br'];\n\n/**\n * Default content types that are treated as binary, they are compared with the `Content-Type` header.\n *\n * @breadcrumb Core / Constants\n * @defaultValue ['image/png', 'image/jpeg', 'image/jpg', 'image/avif', 'image/bmp', 'image/x-png', 'image/gif', 'image/webp', 'video/mp4', 'application/pdf']\n * @public\n */\nexport const DEFAULT_BINARY_CONTENT_TYPES: string[] = [\n 'image/png',\n 'image/jpeg',\n 'image/jpg',\n 'image/avif',\n 'image/bmp',\n 'image/x-png',\n 'image/gif',\n 'image/webp',\n 'video/mp4',\n 'application/pdf',\n];\n\n/**\n * Type alias for empty response and can be used on some adapters when the adapter does not need to return a response.\n *\n * @breadcrumb Core / Constants\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport type IEmptyResponse = {};\n\n/**\n * Constant for empty response and can be used on some adapters when the adapter does not need to return a response.\n *\n * @breadcrumb Core / Constants\n * @public\n */\nexport const EmptyResponse: IEmptyResponse = {};\n"],"names":["constants_exports","__export","DEFAULT_BINARY_CONTENT_TYPES","DEFAULT_BINARY_ENCODINGS","EmptyResponse","__toCommonJS"],"mappings":"qZAAAA,EAAA,CAAA,EAAAC,EAAAD,EAAA,CAAA,6BAAA,IAAAE,EAAA,yBAAA,IAAAC,EAAA,cAAA,IAAAC,CAAA,CAAA,EAAA,OAAA,QAAAC,EAAAL,CAAA,EAOO,MAAMG,EAAqC,CAAC,OAAQ,UAAW,IAAI,EAS7DD,EAAyC,CACpD,YACA,aACA,YACA,aACA,YACA,cACA,YACA,aACA,YACA,iBACF,EAiBaE,EAAgC,CAAC"}
|
|
@@ -1,46 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.setCurrentInvoke = exports.getCurrentInvoke = exports.__ΩCurrentInvoke = void 0;
|
|
4
|
-
const __ΩCurrentInvoke = ['TEvent', 'TContext', 'event', 'context', 'b!b"PPe#!,J4#Pe#",J4$M'];
|
|
5
|
-
exports.__ΩCurrentInvoke = __ΩCurrentInvoke;
|
|
6
|
-
const currentInvoke = {
|
|
7
|
-
context: null,
|
|
8
|
-
event: null,
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Get the reference to the event created by the serverless trigger or context created by the serverless environment.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* import type { ALBEvent, Context } from 'aws-lambda';
|
|
16
|
-
*
|
|
17
|
-
* // inside the method that handles the aws alb request.
|
|
18
|
-
* const { event, context } = getCurrentInvoke<ALBEvent, Context>();
|
|
19
|
-
* ```
|
|
20
|
-
*
|
|
21
|
-
* @breadcrumb Core / Current Invoke
|
|
22
|
-
* @public
|
|
23
|
-
*/
|
|
24
|
-
function getCurrentInvoke() {
|
|
25
|
-
return currentInvoke;
|
|
26
|
-
}
|
|
27
|
-
exports.getCurrentInvoke = getCurrentInvoke;
|
|
28
|
-
getCurrentInvoke.__type = [() => __ΩCurrentInvoke, 'getCurrentInvoke', 'P""o!#/"'];
|
|
29
|
-
/**
|
|
30
|
-
* Method that saves to the event created by the serverless trigger or context created by the serverless environment.
|
|
31
|
-
*
|
|
32
|
-
* @remarks This method MUST NOT be called by you, this method MUST only be used internally in this library.
|
|
33
|
-
*
|
|
34
|
-
* @param event - The event created by the serverless trigger
|
|
35
|
-
* @param context - The context created by the serverless environment
|
|
36
|
-
*
|
|
37
|
-
* @breadcrumb Core / Current Invoke
|
|
38
|
-
* @public
|
|
39
|
-
*/
|
|
40
|
-
function setCurrentInvoke({ event, context, }) {
|
|
41
|
-
currentInvoke.event = event;
|
|
42
|
-
currentInvoke.context = context;
|
|
43
|
-
}
|
|
44
|
-
exports.setCurrentInvoke = setCurrentInvoke;
|
|
45
|
-
setCurrentInvoke.__type = [() => __ΩCurrentInvoke, 'param0', 'setCurrentInvoke', 'P""o!#2""/#'];
|
|
46
|
-
//# sourceMappingURL=current-invoke.js.map
|
|
1
|
+
"use strict";var u=Object.defineProperty,_=Object.getOwnPropertyDescriptor,c=Object.getOwnPropertyNames,a=Object.prototype.hasOwnProperty,s=(t,e)=>{for(var n in e)u(t,n,{get:e[n],enumerable:!0})},i=(t,e,n,p)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of c(e))!a.call(t,r)&&r!==n&&u(t,r,{get:()=>e[r],enumerable:!(p=_(e,r))||p.enumerable});return t},l=t=>i(u({},"__esModule",{value:!0}),t),v={};s(v,{getCurrentInvoke:()=>O,setCurrentInvoke:()=>y});module.exports=l(v);const o={context:null,event:null};function O(){return o}function y({event:t,context:e}){o.event=t,o.context=e}
|
|
2
|
+
//# sourceMappingURL=current-invoke.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"current-invoke.js","
|
|
1
|
+
{"version":3,"file":"current-invoke.js","sources":["../../src/core/current-invoke.ts"],"sourcesContent":["/**\n * The type that represents the object that handles the references to the event created by the serverless trigger or context created by the serverless environment.\n *\n * @breadcrumb Core / Current Invoke\n * @public\n */\nexport type CurrentInvoke<TEvent, TContext> = {\n /**\n * The event created by the serverless trigger\n *\n * @remarks It's only null when you call {@link getCurrentInvoke} outside this library's pipeline.\n */\n event: TEvent | null;\n\n /**\n * The context created by the serverless environment\n *\n * @remarks It's only null when you call {@link getCurrentInvoke} outside this library's pipeline.\n */\n context: TContext | null;\n};\n\nconst currentInvoke: CurrentInvoke<any, any> = {\n context: null,\n event: null,\n};\n\n/**\n * Get the reference to the event created by the serverless trigger or context created by the serverless environment.\n *\n * @example\n * ```typescript\n * import type { ALBEvent, Context } from 'aws-lambda';\n *\n * // inside the method that handles the aws alb request.\n * const { event, context } = getCurrentInvoke<ALBEvent, Context>();\n * ```\n *\n * @breadcrumb Core / Current Invoke\n * @public\n */\nexport function getCurrentInvoke<TEvent = any, TContext = any>(): CurrentInvoke<\n TEvent,\n TContext\n> {\n return currentInvoke;\n}\n\n/**\n * Method that saves to the event created by the serverless trigger or context created by the serverless environment.\n *\n * @remarks This method MUST NOT be called by you, this method MUST only be used internally in this library.\n *\n * @param event - The event created by the serverless trigger\n * @param context - The context created by the serverless environment\n *\n * @breadcrumb Core / Current Invoke\n * @public\n */\nexport function setCurrentInvoke<TEvent = any, TContext = any>({\n event,\n context,\n}: CurrentInvoke<TEvent, TContext>) {\n currentInvoke.event = event;\n currentInvoke.context = context;\n}\n"],"names":["current_invoke_exports","__export","getCurrentInvoke","setCurrentInvoke","__toCommonJS","currentInvoke","event","context"],"mappings":"qZAAAA,EAAA,CAAA,EAAAC,EAAAD,EAAA,CAAA,iBAAA,IAAAE,EAAA,iBAAA,IAAAC,CAAA,CAAA,EAAA,OAAA,QAAAC,EAAAJ,CAAA,EAsBA,MAAMK,EAAyC,CAC7C,QAAS,KACT,MAAO,IACT,EAgBO,SAASH,GAGd,CACO,OAAAG,CACT,CAaO,SAASF,EAA+C,CAC7D,MAAAG,EACA,QAAAC,CACF,EAAoC,CAClCF,EAAc,MAAQC,EACtBD,EAAc,QAAUE,CAC1B"}
|
package/lib/core/event-body.js
CHANGED
|
@@ -1,31 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.getEventBodyAsBuffer = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Get the event body as buffer from body string with content length
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* const body = '{}';
|
|
10
|
-
* const [buffer, contentLength] = getEventBodyAsBuffer(body, false);
|
|
11
|
-
* console.log(buffer);
|
|
12
|
-
* // <Buffer 7b 7d>
|
|
13
|
-
* console.log(contentLength);
|
|
14
|
-
* // 2
|
|
15
|
-
* ```
|
|
16
|
-
*
|
|
17
|
-
* @param body - The body string that can be encoded or not
|
|
18
|
-
* @param isBase64Encoded - Tells if body string is encoded in base64
|
|
19
|
-
*
|
|
20
|
-
* @breadcrumb Core
|
|
21
|
-
* @public
|
|
22
|
-
*/
|
|
23
|
-
function getEventBodyAsBuffer(body, isBase64Encoded) {
|
|
24
|
-
const encoding = isBase64Encoded ? 'base64' : 'utf8';
|
|
25
|
-
const buffer = Buffer.from(body, encoding);
|
|
26
|
-
const contentLength = Buffer.byteLength(buffer, encoding);
|
|
27
|
-
return [buffer, contentLength];
|
|
28
|
-
}
|
|
29
|
-
exports.getEventBodyAsBuffer = getEventBodyAsBuffer;
|
|
30
|
-
getEventBodyAsBuffer.__type = ['body', 'isBase64Encoded', 'contentLength', 'getEventBodyAsBuffer', 'P&2!)2"P!I!\'I#G/$'];
|
|
31
|
-
//# sourceMappingURL=event-body.js.map
|
|
1
|
+
"use strict";var f=Object.defineProperty,u=Object.getOwnPropertyDescriptor,_=Object.getOwnPropertyNames,a=Object.prototype.hasOwnProperty,s=(t,e)=>{for(var r in e)f(t,r,{get:e[r],enumerable:!0})},c=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of _(e))!a.call(t,o)&&o!==r&&f(t,o,{get:()=>e[o],enumerable:!(n=u(e,o))||n.enumerable});return t},v=t=>c(f({},"__esModule",{value:!0}),t),p={};s(p,{getEventBodyAsBuffer:()=>y});module.exports=v(p);function y(t,e){const r=e?"base64":"utf8",n=Buffer.from(t,r),o=Buffer.byteLength(n,r);return[n,o]}
|
|
2
|
+
//# sourceMappingURL=event-body.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-body.js","
|
|
1
|
+
{"version":3,"file":"event-body.js","sources":["../../src/core/event-body.ts"],"sourcesContent":["/**\n * Get the event body as buffer from body string with content length\n *\n * @example\n * ```typescript\n * const body = '{}';\n * const [buffer, contentLength] = getEventBodyAsBuffer(body, false);\n * console.log(buffer);\n * // <Buffer 7b 7d>\n * console.log(contentLength);\n * // 2\n * ```\n *\n * @param body - The body string that can be encoded or not\n * @param isBase64Encoded - Tells if body string is encoded in base64\n *\n * @breadcrumb Core\n * @public\n */\nexport function getEventBodyAsBuffer(\n body: string,\n isBase64Encoded: boolean,\n): [body: Buffer, contentLength: number] {\n const encoding: BufferEncoding = isBase64Encoded ? 'base64' : 'utf8';\n\n const buffer = Buffer.from(body, encoding);\n const contentLength = Buffer.byteLength(buffer, encoding);\n\n return [buffer, contentLength];\n}\n"],"names":["event_body_exports","__export","getEventBodyAsBuffer","__toCommonJS","body","isBase64Encoded","encoding","buffer","contentLength"],"mappings":"qZAAAA,EAAA,CAAA,EAAAC,EAAAD,EAAA,CAAA,qBAAA,IAAAE,CAAA,CAAA,EAAA,OAAA,QAAAC,EAAAH,CAAA,EAmBO,SAASE,EACdE,EACAC,EACuC,CACjC,MAAAC,EAA2BD,EAAkB,SAAW,OAExDE,EAAS,OAAO,KAAKH,EAAME,CAAQ,EACnCE,EAAgB,OAAO,WAAWD,EAAQD,CAAQ,EAEjD,MAAA,CAACC,EAAQC,CAAa,CAC/B"}
|
package/lib/core/headers.js
CHANGED
|
@@ -1,67 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const { __ΩBothValueHeaders } = require('../@types');
|
|
5
|
-
const __ΩRecord = ['K', 'T', 'l\'e#"Rb!b"Pde"!N#!'];
|
|
6
|
-
//#endregion
|
|
7
|
-
/**
|
|
8
|
-
* Transform a header map and make sure the value is not an array
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* const headers = { 'accept-encoding': 'gzip', 'accept-language': ['en-US', 'en;q=0.9'] };
|
|
13
|
-
* const flattenedHeaders = getFlattenedHeadersMap(headers, ',', true);
|
|
14
|
-
* console.log(flattenedHeaders);
|
|
15
|
-
* // { 'accept-encoding': 'gzip', 'accept-language': 'en-US,en;q=0.9' }
|
|
16
|
-
* ```
|
|
17
|
-
*
|
|
18
|
-
* @param headersMap - The initial headers
|
|
19
|
-
* @param separator - The separator used when we join the array of header's value
|
|
20
|
-
* @param lowerCaseKey - Should put all keys in lowercase
|
|
21
|
-
*
|
|
22
|
-
* @breadcrumb Core / Headers
|
|
23
|
-
* @public
|
|
24
|
-
*/
|
|
25
|
-
function getFlattenedHeadersMap(headersMap, separator = ',', lowerCaseKey = false) {
|
|
26
|
-
const commaDelimitedHeaders = {};
|
|
27
|
-
const headersMapEntries = Object.entries(headersMap);
|
|
28
|
-
for (const [headerKey, headerValue] of headersMapEntries) {
|
|
29
|
-
const newKey = lowerCaseKey ? headerKey.toLowerCase() : headerKey;
|
|
30
|
-
if (Array.isArray(headerValue))
|
|
31
|
-
commaDelimitedHeaders[newKey] = headerValue.join(separator);
|
|
32
|
-
else
|
|
33
|
-
commaDelimitedHeaders[newKey] = String(headerValue !== null && headerValue !== void 0 ? headerValue : '');
|
|
34
|
-
}
|
|
35
|
-
return commaDelimitedHeaders;
|
|
36
|
-
}
|
|
37
|
-
exports.getFlattenedHeadersMap = getFlattenedHeadersMap;
|
|
38
|
-
getFlattenedHeadersMap.__type = [() => __ΩBothValueHeaders, 'headersMap', 'separator', () => ",", 'lowerCaseKey', () => false, () => __ΩRecord, 'getFlattenedHeadersMap', 'Pn!2"&2#>$)2%>&&&o\'#/('];
|
|
39
|
-
/**
|
|
40
|
-
* Transforms a header map into a multi-value map header.
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```typescript
|
|
44
|
-
* const headers = { 'accept-encoding': 'gzip', 'connection': ['keep-alive'] };
|
|
45
|
-
* const multiValueHeaders = getMultiValueHeadersMap(headers);
|
|
46
|
-
* console.log(multiValueHeaders);
|
|
47
|
-
* // { 'accept-encoding': ['gzip'], 'connection': ['keep-alive'] }
|
|
48
|
-
* ```
|
|
49
|
-
*
|
|
50
|
-
* @param headersMap - The initial headers
|
|
51
|
-
*
|
|
52
|
-
* @breadcrumb Core / Headers
|
|
53
|
-
* @public
|
|
54
|
-
*/
|
|
55
|
-
function getMultiValueHeadersMap(headersMap) {
|
|
56
|
-
const multiValueHeaders = {};
|
|
57
|
-
const headersMapEntries = Object.entries(headersMap);
|
|
58
|
-
for (const [headerKey, headerValue] of headersMapEntries) {
|
|
59
|
-
multiValueHeaders[headerKey.toLowerCase()] = Array.isArray(headerValue)
|
|
60
|
-
? headerValue.map(String)
|
|
61
|
-
: [String(headerValue)];
|
|
62
|
-
}
|
|
63
|
-
return multiValueHeaders;
|
|
64
|
-
}
|
|
65
|
-
exports.getMultiValueHeadersMap = getMultiValueHeadersMap;
|
|
66
|
-
getMultiValueHeadersMap.__type = [() => __ΩBothValueHeaders, 'headersMap', () => __ΩRecord, 'getMultiValueHeadersMap', 'Pn!2"&&Fo##/$'];
|
|
67
|
-
//# sourceMappingURL=headers.js.map
|
|
1
|
+
"use strict";var u=Object.defineProperty,p=Object.getOwnPropertyDescriptor,c=Object.getOwnPropertyNames,d=Object.prototype.hasOwnProperty,f=(t,e)=>{for(var s in e)u(t,s,{get:e[s],enumerable:!0})},y=(t,e,s,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of c(e))!d.call(t,o)&&o!==s&&u(t,o,{get:()=>e[o],enumerable:!(r=p(e,o))||r.enumerable});return t},_=t=>y(u({},"__esModule",{value:!0}),t),l={};f(l,{getFlattenedHeadersMap:()=>g,getFlattenedHeadersMapAndCookies:()=>w,getMultiValueHeadersMap:()=>O,parseHeaders:()=>k});module.exports=_(l);function g(t,e=",",s=!1){return Object.keys(t).reduce((r,o)=>{const i=s?o.toLowerCase():o,n=t[o];return Array.isArray(n)?r[i]=n.join(e):r[i]=(n??"")+"",r},{})}function O(t){return Object.keys(t).reduce((e,s)=>{const r=t[s];return e[s.toLowerCase()]=Array.isArray(r)?r.map(String):[String(r)],e},{})}function w(t){return Object.keys(t).reduce((e,s)=>{const r=t[s],o=s.toLowerCase();return Array.isArray(r)?o!=="set-cookie"?e.headers[s]=r.join(","):e.cookies.push(...r):o==="set-cookie"&&r!==void 0?e.cookies.push(r??""):e.headers[s]=String(r??""),e},{cookies:[],headers:{}})}function k(t){if(!t)return{};const e={},s=t.trim().split(`
|
|
2
|
+
`);for(let r=0;r<s.length;r++){const o=s[r],i=o.indexOf(":"),n=o.slice(0,i).trim().toLowerCase(),a=o.slice(i+1).trim();typeof e[n]>"u"?e[n]=a:Array.isArray(e[n])?e[n].push(a):e[n]=[e[n],a]}return e}
|
|
3
|
+
//# sourceMappingURL=headers.js.map
|
package/lib/core/headers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headers.js","
|
|
1
|
+
{"version":3,"file":"headers.js","sources":["../../src/core/headers.ts"],"sourcesContent":["//#region Imports\n\nimport { BothValueHeaders } from '../@types';\n\n//#endregion\n\n/**\n * Transform a header map and make sure the value is not an array\n *\n * @example\n * ```typescript\n * const headers = { 'accept-encoding': 'gzip', 'accept-language': ['en-US', 'en;q=0.9'] };\n * const flattenedHeaders = getFlattenedHeadersMap(headers, ',', true);\n * console.log(flattenedHeaders);\n * // { 'accept-encoding': 'gzip', 'accept-language': 'en-US,en;q=0.9' }\n * ```\n *\n * @param headersMap - The initial headers\n * @param separator - The separator used when we join the array of header's value\n * @param lowerCaseKey - Should put all keys in lowercase\n *\n * @breadcrumb Core / Headers\n * @public\n */\nexport function getFlattenedHeadersMap(\n headersMap: BothValueHeaders,\n separator: string = ',',\n lowerCaseKey: boolean = false,\n): Record<string, string> {\n return Object.keys(headersMap).reduce((acc, headerKey) => {\n const newKey = lowerCaseKey ? headerKey.toLowerCase() : headerKey;\n const headerValue = headersMap[headerKey];\n\n if (Array.isArray(headerValue)) acc[newKey] = headerValue.join(separator);\n else acc[newKey] = (headerValue ?? '') + '';\n\n return acc;\n }, {});\n}\n\n/**\n * Transforms a header map into a multi-value map header.\n *\n * @example\n * ```typescript\n * const headers = { 'accept-encoding': 'gzip', 'connection': ['keep-alive'] };\n * const multiValueHeaders = getMultiValueHeadersMap(headers);\n * console.log(multiValueHeaders);\n * // { 'accept-encoding': ['gzip'], 'connection': ['keep-alive'] }\n * ```\n *\n * @param headersMap - The initial headers\n *\n * @breadcrumb Core / Headers\n * @public\n */\nexport function getMultiValueHeadersMap(\n headersMap: BothValueHeaders,\n): Record<string, string[]> {\n return Object.keys(headersMap).reduce((acc, headerKey) => {\n const headerValue = headersMap[headerKey];\n\n acc[headerKey.toLowerCase()] = Array.isArray(headerValue)\n ? headerValue.map(String)\n : [String(headerValue)];\n\n return acc;\n }, {});\n}\n\n/**\n * The wrapper that holds the information about single value headers and cookies\n *\n * @breadcrumb Core / Headers\n * @public\n */\nexport type FlattenedHeadersAndCookies = {\n /**\n * Just the single value headers\n */\n headers: Record<string, string>;\n\n /**\n * The list of cookies\n */\n cookies: string[];\n};\n\n/**\n * Transforms a header map into a single value headers and cookies\n *\n * @param headersMap - The initial headers\n *\n * @breadcrumb Core / Headers\n * @public\n */\nexport function getFlattenedHeadersMapAndCookies(\n headersMap: BothValueHeaders,\n): FlattenedHeadersAndCookies {\n return Object.keys(headersMap).reduce(\n (acc, headerKey) => {\n const headerValue = headersMap[headerKey];\n const lowerHeaderKey = headerKey.toLowerCase();\n\n if (Array.isArray(headerValue)) {\n if (lowerHeaderKey !== 'set-cookie')\n acc.headers[headerKey] = headerValue.join(',');\n else acc.cookies.push(...headerValue);\n } else {\n if (lowerHeaderKey === 'set-cookie' && headerValue !== undefined)\n acc.cookies.push(headerValue ?? '');\n else acc.headers[headerKey] = String(headerValue ?? '');\n }\n\n return acc;\n },\n {\n cookies: [],\n headers: {},\n } as FlattenedHeadersAndCookies,\n );\n}\n\n/**\n * Parse HTTP Raw Headers\n * Attribution to {@link https://github.com/kesla/parse-headers/blob/master/parse-headers.js}\n *\n * @param headers - The raw headers\n *\n * @breadcrumb Core / Headers\n * @public\n */\nexport function parseHeaders(\n headers: string,\n): Record<string, string | string[]> {\n if (!headers) return {};\n\n const result = {};\n const headersArr = headers.trim().split('\\n');\n\n for (let i = 0; i < headersArr.length; i++) {\n const row = headersArr[i];\n const index = row.indexOf(':');\n const key = row.slice(0, index).trim().toLowerCase();\n const value = row.slice(index + 1).trim();\n\n if (typeof result[key] === 'undefined') result[key] = value;\n else if (Array.isArray(result[key])) result[key].push(value);\n else result[key] = [result[key], value];\n }\n\n return result;\n}\n"],"names":["headers_exports","__export","getFlattenedHeadersMap","getFlattenedHeadersMapAndCookies","getMultiValueHeadersMap","parseHeaders","__toCommonJS","headersMap","separator","lowerCaseKey","acc","headerKey","newKey","headerValue","lowerHeaderKey","headers","result","headersArr","i","row","index","key","value"],"mappings":"qZAAAA,EAAA,CAAA,EAAAC,EAAAD,EAAA,CAAA,uBAAA,IAAAE,EAAA,iCAAA,IAAAC,EAAA,wBAAA,IAAAC,EAAA,aAAA,IAAAC,CAAA,CAAA,EAAA,OAAA,QAAAC,EAAAN,CAAA,EAwBO,SAASE,EACdK,EACAC,EAAoB,IACpBC,EAAwB,GACA,CACxB,OAAO,OAAO,KAAKF,CAAU,EAAE,OAAO,CAACG,EAAKC,IAAc,CACxD,MAAMC,EAASH,EAAeE,EAAU,YAAA,EAAgBA,EAClDE,EAAcN,EAAWI,CAAS,EAEpC,OAAA,MAAM,QAAQE,CAAW,EAAGH,EAAIE,CAAM,EAAIC,EAAY,KAAKL,CAAS,EAC/DE,EAAAE,CAAM,GAAKC,GAAe,IAAM,GAElCH,CACT,EAAG,CAAE,CAAA,CACP,CAkBO,SAASN,EACdG,EAC0B,CAC1B,OAAO,OAAO,KAAKA,CAAU,EAAE,OAAO,CAACG,EAAKC,IAAc,CAClD,MAAAE,EAAcN,EAAWI,CAAS,EAExC,OAAAD,EAAIC,EAAU,YAAA,CAAa,EAAI,MAAM,QAAQE,CAAW,EACpDA,EAAY,IAAI,MAAM,EACtB,CAAC,OAAOA,CAAW,CAAC,EAEjBH,CACT,EAAG,CAAE,CAAA,CACP,CA4BO,SAASP,EACdI,EAC4B,CACrB,OAAA,OAAO,KAAKA,CAAU,EAAE,OAC7B,CAACG,EAAKC,IAAc,CACZ,MAAAE,EAAcN,EAAWI,CAAS,EAClCG,EAAiBH,EAAU,cAE7B,OAAA,MAAM,QAAQE,CAAW,EACvBC,IAAmB,aACrBJ,EAAI,QAAQC,CAAS,EAAIE,EAAY,KAAK,GAAG,EACtCH,EAAA,QAAQ,KAAK,GAAGG,CAAW,EAEhCC,IAAmB,cAAgBD,IAAgB,OACjDH,EAAA,QAAQ,KAAKG,GAAe,EAAE,EAC/BH,EAAI,QAAQC,CAAS,EAAI,OAAOE,GAAe,EAAE,EAGjDH,CACT,EACA,CACE,QAAS,CAAC,EACV,QAAS,CAAC,CACZ,CAAA,CAEJ,CAWO,SAASL,EACdU,EACmC,CACnC,GAAI,CAACA,EAAS,MAAO,GAErB,MAAMC,EAAS,CAAA,EACTC,EAAaF,EAAQ,KAAK,EAAE,MAAM;AAAA,CAAI,EAE5C,QAASG,EAAI,EAAGA,EAAID,EAAW,OAAQC,IAAK,CACpC,MAAAC,EAAMF,EAAWC,CAAC,EAClBE,EAAQD,EAAI,QAAQ,GAAG,EACvBE,EAAMF,EAAI,MAAM,EAAGC,CAAK,EAAE,OAAO,cACjCE,EAAQH,EAAI,MAAMC,EAAQ,CAAC,EAAE,OAE/B,OAAOJ,EAAOK,CAAG,EAAM,IAAaL,EAAOK,CAAG,EAAIC,EAC7C,MAAM,QAAQN,EAAOK,CAAG,CAAC,EAAUL,EAAAK,CAAG,EAAE,KAAKC,CAAK,EACtDN,EAAOK,CAAG,EAAI,CAACL,EAAOK,CAAG,EAAGC,CAAK,EAGjC,OAAAN,CACT"}
|
package/lib/core/index.js
CHANGED
|
@@ -1,28 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./base-handler"), exports);
|
|
18
|
-
__exportStar(require("./constants"), exports);
|
|
19
|
-
__exportStar(require("./current-invoke"), exports);
|
|
20
|
-
__exportStar(require("./event-body"), exports);
|
|
21
|
-
__exportStar(require("./headers"), exports);
|
|
22
|
-
__exportStar(require("./is-binary"), exports);
|
|
23
|
-
__exportStar(require("./logger"), exports);
|
|
24
|
-
__exportStar(require("./no-op"), exports);
|
|
25
|
-
__exportStar(require("./optional"), exports);
|
|
26
|
-
__exportStar(require("./path"), exports);
|
|
27
|
-
__exportStar(require("./stream"), exports);
|
|
28
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
"use strict";var i=Object.defineProperty,_=Object.getOwnPropertyDescriptor,x=Object.getOwnPropertyNames,n=Object.prototype.hasOwnProperty,u=(o,t,s,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let p of x(t))!n.call(o,p)&&p!==s&&i(o,p,{get:()=>t[p],enumerable:!(a=_(t,p))||a.enumerable});return o},r=(o,t,s)=>(u(o,t,"default"),s&&u(s,t,"default")),q=o=>u(i({},"__esModule",{value:!0}),o),e={};module.exports=q(e);r(e,require("./base-handler"),module.exports);r(e,require("./constants"),module.exports);r(e,require("./current-invoke"),module.exports);r(e,require("./event-body"),module.exports);r(e,require("./headers"),module.exports);r(e,require("./is-binary"),module.exports);r(e,require("./logger"),module.exports);r(e,require("./no-op"),module.exports);r(e,require("./optional"),module.exports);r(e,require("./path"),module.exports);r(e,require("./stream"),module.exports);
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
package/lib/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/core/index.ts"],"sourcesContent":["export * from './base-handler';\nexport * from './constants';\nexport * from './current-invoke';\nexport * from './event-body';\nexport * from './headers';\nexport * from './is-binary';\nexport * from './logger';\nexport * from './no-op';\nexport * from './optional';\nexport * from './path';\nexport * from './stream';\n"],"names":["core_exports","__toCommonJS","__reExport"],"mappings":"6YAAAA,EAAA,CAAA,EAAA,OAAA,QAAAC,EAAAD,CAAA,EAAAE,EAAAF,EAAc,QAAd,gBAAA,EAAA,OAAA,OAAA,EACAE,EAAAF,EAAc,QADd,aAAA,EAAA,OAAA,OAAA,EAEAE,EAAAF,EAAc,QAFd,kBAAA,EAAA,OAAA,OAAA,EAGAE,EAAAF,EAAc,QAHd,cAAA,EAAA,OAAA,OAAA,EAIAE,EAAAF,EAAc,QAJd,WAAA,EAAA,OAAA,OAAA,EAKAE,EAAAF,EAAc,QALd,aAAA,EAAA,OAAA,OAAA,EAMAE,EAAAF,EAAc,QANd,UAAA,EAAA,OAAA,OAAA,EAOAE,EAAAF,EAAc,QAPd,SAAA,EAAA,OAAA,OAAA,EAQAE,EAAAF,EAAc,QARd,YAAA,EAAA,OAAA,OAAA,EASAE,EAAAF,EAAc,QATd,QAAA,EAAA,OAAA,OAAA,EAUAE,EAAAF,EAAc,QAVd,UAAA,EAAA,OAAA,OAAA"}
|
package/lib/core/is-binary.js
CHANGED
|
@@ -1,118 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.isBinary = exports.isContentTypeBinary = exports.getContentType = exports.isContentEncodingBinary = void 0;
|
|
4
|
-
const { __ΩBothValueHeaders } = require('../@types');
|
|
5
|
-
const { __ΩBinarySettings } = require('../@types');
|
|
6
|
-
function __assignType(fn, args) {
|
|
7
|
-
fn.__type = args;
|
|
8
|
-
return fn;
|
|
9
|
-
}
|
|
10
|
-
const headers_1 = require("./headers");
|
|
11
|
-
//#endregion
|
|
12
|
-
/**
|
|
13
|
-
* The function that determines by the content encoding whether the response should be treated as binary
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```typescript
|
|
17
|
-
* const headers = { 'Content-Encoding': 'gzip' };
|
|
18
|
-
* const isBinary = isContentEncodingBinary(headers, ['gzip']);
|
|
19
|
-
* console.log(isBinary);
|
|
20
|
-
* // true
|
|
21
|
-
* ```
|
|
22
|
-
*
|
|
23
|
-
* @param headers - The headers of the response
|
|
24
|
-
* @param binaryEncodingTypes - The list of content encodings that will be treated as binary
|
|
25
|
-
*
|
|
26
|
-
* @breadcrumb Core / isBinary
|
|
27
|
-
* @public
|
|
28
|
-
*/
|
|
29
|
-
function isContentEncodingBinary(headers, binaryEncodingTypes) {
|
|
30
|
-
const multiValueHeaders = (0, headers_1.getMultiValueHeadersMap)(headers);
|
|
31
|
-
const contentEncodings = multiValueHeaders['content-encoding'];
|
|
32
|
-
if (!Array.isArray(contentEncodings))
|
|
33
|
-
return false;
|
|
34
|
-
return contentEncodings.some(__assignType(value => binaryEncodingTypes.some(__assignType(binaryEncoding => value.includes(binaryEncoding), ['binaryEncoding', '', 'P"2!"/"'])), ['value', '', 'P"2!"/"']));
|
|
35
|
-
}
|
|
36
|
-
exports.isContentEncodingBinary = isContentEncodingBinary;
|
|
37
|
-
isContentEncodingBinary.__type = [() => __ΩBothValueHeaders, 'headers', 'binaryEncodingTypes', 'isContentEncodingBinary', 'Pn!2"&F2#)/$'];
|
|
38
|
-
/**
|
|
39
|
-
* The function that returns the content type of headers
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* ```typescript
|
|
43
|
-
* const headers = { 'Content-Type': 'application/json' };
|
|
44
|
-
* const contentType = getContentType(headers);
|
|
45
|
-
* console.log(contentType);
|
|
46
|
-
* // application/json
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
|
-
* @param headers - The headers of the response
|
|
50
|
-
*
|
|
51
|
-
* @breadcrumb Core / isBinary
|
|
52
|
-
* @public
|
|
53
|
-
*/
|
|
54
|
-
function getContentType(headers) {
|
|
55
|
-
const flattenedHeaders = (0, headers_1.getFlattenedHeadersMap)(headers, ';', true);
|
|
56
|
-
const contentTypeHeader = flattenedHeaders['content-type'] || '';
|
|
57
|
-
// only compare mime type; ignore encoding part
|
|
58
|
-
return contentTypeHeader.split(';')[0];
|
|
59
|
-
}
|
|
60
|
-
exports.getContentType = getContentType;
|
|
61
|
-
getContentType.__type = [() => __ΩBothValueHeaders, 'headers', 'getContentType', 'Pn!2"&/#'];
|
|
62
|
-
/**
|
|
63
|
-
* The function that determines by the content type whether the response should be treated as binary
|
|
64
|
-
*
|
|
65
|
-
* @example
|
|
66
|
-
* ```typescript
|
|
67
|
-
* const headers = { 'Content-Type': 'image/png' };
|
|
68
|
-
* const isBinary = isContentTypeBinary(headers, [new RegExp('^image/.*$')]);
|
|
69
|
-
* console.log(isBinary);
|
|
70
|
-
* // true
|
|
71
|
-
* ```
|
|
72
|
-
*
|
|
73
|
-
* @param headers - The headers of the response
|
|
74
|
-
* @param binaryContentTypes - The list of content types that will be treated as binary
|
|
75
|
-
*
|
|
76
|
-
* @breadcrumb Core / isBinary
|
|
77
|
-
* @public
|
|
78
|
-
*/
|
|
79
|
-
function isContentTypeBinary(headers, binaryContentTypes) {
|
|
80
|
-
const binaryContentTypesRegexes = binaryContentTypes.map(__assignType(binaryContentType => binaryContentType instanceof RegExp
|
|
81
|
-
? binaryContentType
|
|
82
|
-
: new RegExp(`${binaryContentType}`), ['binaryContentType', '', 'P"2!"/"']));
|
|
83
|
-
const contentType = getContentType(headers);
|
|
84
|
-
if (!contentType)
|
|
85
|
-
return false;
|
|
86
|
-
return binaryContentTypesRegexes.some(__assignType(binaryContentType => binaryContentType.test(contentType), ['binaryContentType', '', 'P"2!"/"']));
|
|
87
|
-
}
|
|
88
|
-
exports.isContentTypeBinary = isContentTypeBinary;
|
|
89
|
-
isContentTypeBinary.__type = [() => __ΩBothValueHeaders, 'headers', 'binaryContentTypes', 'isContentTypeBinary', 'Pn!2"P&AJF2#"/$'];
|
|
90
|
-
/**
|
|
91
|
-
* The function used to determine from the headers and the binary settings if a response should be encoded or not
|
|
92
|
-
*
|
|
93
|
-
* @example
|
|
94
|
-
* ```typescript
|
|
95
|
-
* const headers = { 'Content-Type': 'image/png', 'Content-Encoding': 'gzip' };
|
|
96
|
-
* const isContentBinary = isBinary(headers, { contentEncodings: ['gzip'], contentTypes: [new RegExp('^image/.*$')] });
|
|
97
|
-
* console.log(isContentBinary);
|
|
98
|
-
* // true
|
|
99
|
-
* ```
|
|
100
|
-
*
|
|
101
|
-
* @param headers - The headers of the response
|
|
102
|
-
* @param binarySettings - The settings for the validation
|
|
103
|
-
*
|
|
104
|
-
* @breadcrumb Core / isBinary
|
|
105
|
-
* @public
|
|
106
|
-
*/
|
|
107
|
-
function isBinary(headers, binarySettings) {
|
|
108
|
-
if ('isBinary' in binarySettings) {
|
|
109
|
-
if (binarySettings.isBinary === false)
|
|
110
|
-
return false;
|
|
111
|
-
return binarySettings.isBinary(headers);
|
|
112
|
-
}
|
|
113
|
-
return (isContentEncodingBinary(headers, binarySettings.contentEncodings) ||
|
|
114
|
-
isContentTypeBinary(headers, binarySettings.contentTypes));
|
|
115
|
-
}
|
|
116
|
-
exports.isBinary = isBinary;
|
|
117
|
-
isBinary.__type = [() => __ΩBothValueHeaders, 'headers', () => __ΩBinarySettings, 'binarySettings', 'isBinary', 'Pn!2"n#2$)/%'];
|
|
118
|
-
//# sourceMappingURL=is-binary.js.map
|
|
1
|
+
"use strict";var i=Object.defineProperty,y=Object.getOwnPropertyDescriptor,u=Object.getOwnPropertyNames,f=Object.prototype.hasOwnProperty,_=(n,e)=>{for(var t in e)i(n,t,{get:e[t],enumerable:!0})},l=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of u(e))!f.call(n,o)&&o!==t&&i(n,o,{get:()=>e[o],enumerable:!(r=y(e,o))||r.enumerable});return n},O=n=>l(i({},"__esModule",{value:!0}),n),c={};_(c,{getContentType:()=>a,isBinary:()=>d,isContentEncodingBinary:()=>s,isContentTypeBinary:()=>p});module.exports=O(c);function s(n,e){let t=n["content-encoding"];return t?(Array.isArray(t)||(t=t.split(",")),t.some(r=>e.includes(r.trim()))):!1}function a(n){const e=n["content-type"],t=Array.isArray(e)?e[0]||"":e||"";if(!e)return"";const r=t.indexOf(";");return r===-1?t:t.slice(0,r)}function p(n,e){const t=a(n);return t?e.includes(t.trim()):!1}function d(n,e){return"isBinary"in e?e.isBinary===!1?!1:e.isBinary(n):s(n,e.contentEncodings)||p(n,e.contentTypes)}
|
|
2
|
+
//# sourceMappingURL=is-binary.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-binary.js","
|
|
1
|
+
{"version":3,"file":"is-binary.js","sources":["../../src/core/is-binary.ts"],"sourcesContent":["// ATTRIBUTION: https://github.com/dougmoscrop/serverless-http\n\n//#region Imports\n\nimport { BinarySettings, BothValueHeaders } from '../@types';\n\n//#endregion\n\n/**\n * The function that determines by the content encoding whether the response should be treated as binary\n *\n * @example\n * ```typescript\n * const headers = { 'content-encoding': 'gzip' };\n * const isBinary = isContentEncodingBinary(headers, ['gzip']);\n * console.log(isBinary);\n * // true\n * ```\n *\n * @param headers - The headers of the response\n * @param binaryEncodingTypes - The list of content encodings that will be treated as binary\n *\n * @breadcrumb Core / isBinary\n * @public\n */\nexport function isContentEncodingBinary(\n headers: BothValueHeaders,\n binaryEncodingTypes: string[],\n): boolean {\n let contentEncodings = headers['content-encoding'];\n\n if (!contentEncodings) return false;\n\n if (!Array.isArray(contentEncodings))\n contentEncodings = contentEncodings.split(',');\n\n return contentEncodings.some(value =>\n binaryEncodingTypes.includes(value.trim()),\n );\n}\n\n/**\n * The function that returns the content type of headers\n *\n * @example\n * ```typescript\n * const headers = { 'content-type': 'application/json' };\n * const contentType = getContentType(headers);\n * console.log(contentType);\n * // application/json\n * ```\n *\n * @param headers - The headers of the response\n *\n * @breadcrumb Core / isBinary\n * @public\n */\nexport function getContentType(headers: BothValueHeaders): string {\n const contentTypeHeaderRaw = headers['content-type'];\n const contentTypeHeader = Array.isArray(contentTypeHeaderRaw)\n ? contentTypeHeaderRaw[0] || ''\n : contentTypeHeaderRaw || '';\n\n if (!contentTypeHeaderRaw) return '';\n\n // only compare mime type; ignore encoding part\n const contentTypeStart = contentTypeHeader.indexOf(';');\n\n if (contentTypeStart === -1) return contentTypeHeader;\n\n return contentTypeHeader.slice(0, contentTypeStart);\n}\n\n/**\n * The function that determines by the content type whether the response should be treated as binary\n *\n * @example\n * ```typescript\n * const headers = { 'content-type': 'image/png' };\n * const isBinary = isContentTypeBinary(headers, new Map([['image/png', true]]));\n * console.log(isBinary);\n * // true\n * ```\n *\n * @param headers - The headers of the response\n * @param binaryContentTypes - The list of content types that will be treated as binary\n *\n * @breadcrumb Core / isBinary\n * @public\n */\nexport function isContentTypeBinary(\n headers: BothValueHeaders,\n binaryContentTypes: string[],\n) {\n const contentType = getContentType(headers);\n\n if (!contentType) return false;\n\n return binaryContentTypes.includes(contentType.trim());\n}\n\n/**\n * The function used to determine from the headers and the binary settings if a response should be encoded or not\n *\n * @example\n * ```typescript\n * const headers = { 'content-type': 'image/png', 'content-encoding': 'gzip' };\n * const isContentBinary = isBinary(headers, { contentEncodings: ['gzip'], contentTypes: ['image/png'] });\n * console.log(isContentBinary);\n * // true\n * ```\n *\n * @param headers - The headers of the response\n * @param binarySettings - The settings for the validation\n *\n * @breadcrumb Core / isBinary\n * @public\n */\nexport function isBinary(\n headers: BothValueHeaders,\n binarySettings: BinarySettings,\n): boolean {\n if ('isBinary' in binarySettings) {\n if (binarySettings.isBinary === false) return false;\n\n return binarySettings.isBinary(headers);\n }\n\n return (\n isContentEncodingBinary(headers, binarySettings.contentEncodings) ||\n isContentTypeBinary(headers, binarySettings.contentTypes)\n );\n}\n"],"names":["is_binary_exports","__export","getContentType","isBinary","isContentEncodingBinary","isContentTypeBinary","__toCommonJS","headers","binaryEncodingTypes","contentEncodings","value","contentTypeHeaderRaw","contentTypeHeader","contentTypeStart","binaryContentTypes","contentType","binarySettings"],"mappings":"qZAAAA,EAAA,CAAA,EAAAC,EAAAD,EAAA,CAAA,eAAA,IAAAE,EAAA,SAAA,IAAAC,EAAA,wBAAA,IAAAC,EAAA,oBAAA,IAAAC,CAAA,CAAA,EAAA,OAAA,QAAAC,EAAAN,CAAA,EAyBO,SAASI,EACdG,EACAC,EACS,CACL,IAAAC,EAAmBF,EAAQ,kBAAkB,EAEjD,OAAKE,GAEA,MAAM,QAAQA,CAAgB,IACdA,EAAAA,EAAiB,MAAM,GAAG,GAExCA,EAAiB,KACtBC,GAAAF,EAAoB,SAASE,EAAM,MAAM,CAAA,GANb,EAQhC,CAkBO,SAASR,EAAeK,EAAmC,CAC1D,MAAAI,EAAuBJ,EAAQ,cAAc,EAC7CK,EAAoB,MAAM,QAAQD,CAAoB,EACxDA,EAAqB,CAAC,GAAK,GAC3BA,GAAwB,GAE5B,GAAI,CAACA,EAA6B,MAAA,GAG5B,MAAAE,EAAmBD,EAAkB,QAAQ,GAAG,EAEtD,OAAIC,IAAqB,GAAWD,EAE7BA,EAAkB,MAAM,EAAGC,CAAgB,CACpD,CAmBO,SAASR,EACdE,EACAO,EACA,CACM,MAAAC,EAAcb,EAAeK,CAAO,EAE1C,OAAKQ,EAEED,EAAmB,SAASC,EAAY,KAAM,CAAA,EAF5B,EAG3B,CAmBO,SAASZ,EACdI,EACAS,EACS,CACT,MAAI,aAAcA,EACZA,EAAe,WAAa,GAAc,GAEvCA,EAAe,SAAST,CAAO,EAItCH,EAAwBG,EAASS,EAAe,gBAAgB,GAChEX,EAAoBE,EAASS,EAAe,YAAY,CAE5D"}
|