@h4ad/serverless-adapter 2.16.0 → 2.17.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/lib/adapters/aws/api-gateway-v2.adapter.d.ts +2 -1
- package/lib/adapters/aws/api-gateway-v2.adapter.js +2 -1
- package/lib/adapters/aws/api-gateway-v2.adapter.js.map +1 -1
- package/lib/core/headers.d.ts +10 -0
- package/lib/core/headers.js +31 -1
- package/lib/core/headers.js.map +1 -1
- package/lib/frameworks/trpc/trpc.framework.d.ts +1 -0
- package/lib/frameworks/trpc/trpc.framework.js +1 -0
- package/lib/frameworks/trpc/trpc.framework.js.map +1 -1
- package/lib/handlers/aws/aws-stream.handler.d.ts +83 -0
- package/lib/handlers/aws/aws-stream.handler.js +169 -0
- package/lib/handlers/aws/aws-stream.handler.js.map +1 -0
- package/lib/handlers/aws/index.d.ts +1 -0
- package/lib/handlers/aws/index.js +18 -0
- package/lib/handlers/aws/index.js.map +1 -0
- package/lib/network/index.d.ts +2 -0
- package/lib/network/index.js +2 -0
- package/lib/network/index.js.map +1 -1
- package/lib/network/response-stream.d.ts +41 -0
- package/lib/network/response-stream.js +88 -0
- package/lib/network/response-stream.js.map +1 -0
- package/lib/network/response.js +2 -12
- package/lib/network/response.js.map +1 -1
- package/lib/network/utils.d.ts +7 -0
- package/lib/network/utils.js +21 -0
- package/lib/network/utils.js.map +1 -0
- package/package.json +1 -1
|
@@ -18,7 +18,8 @@ export interface ApiGatewayV2Options {
|
|
|
18
18
|
/**
|
|
19
19
|
* The adapter to handle requests from AWS Api Gateway V2
|
|
20
20
|
*
|
|
21
|
-
* As per {@link https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-known-issues.html | know issues}, we throw an exception when you send the `transfer-encoding=chunked
|
|
21
|
+
* As per {@link https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-known-issues.html | know issues}, we throw an exception when you send the `transfer-encoding=chunked`.
|
|
22
|
+
* But, if you use this adapter to accept requests from Function URL, you can accept the `transfer-encoding=chunked` changing the method of invocation from `BUFFERED` to `RESPONSE_STREAM`.
|
|
22
23
|
*
|
|
23
24
|
* @example
|
|
24
25
|
* ```typescript
|
|
@@ -10,7 +10,8 @@ exports.__ΩApiGatewayV2Options = __ΩApiGatewayV2Options;
|
|
|
10
10
|
/**
|
|
11
11
|
* The adapter to handle requests from AWS Api Gateway V2
|
|
12
12
|
*
|
|
13
|
-
* As per {@link https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-known-issues.html | know issues}, we throw an exception when you send the `transfer-encoding=chunked
|
|
13
|
+
* As per {@link https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-known-issues.html | know issues}, we throw an exception when you send the `transfer-encoding=chunked`.
|
|
14
|
+
* But, if you use this adapter to accept requests from Function URL, you can accept the `transfer-encoding=chunked` changing the method of invocation from `BUFFERED` to `RESPONSE_STREAM`.
|
|
14
15
|
*
|
|
15
16
|
* @example
|
|
16
17
|
* ```typescript
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-gateway-v2.adapter.js","sourceRoot":"","sources":["../../../src/adapters/aws/api-gateway-v2.adapter.ts"],"names":[],"mappings":";;;sCASO,iBAAiB;+CAAjB,iBAAiB;oCAAjB,iBAAiB;AACxB,qCAMoB;;;AAmBpB
|
|
1
|
+
{"version":3,"file":"api-gateway-v2.adapter.js","sourceRoot":"","sources":["../../../src/adapters/aws/api-gateway-v2.adapter.ts"],"names":[],"mappings":";;;sCASO,iBAAiB;+CAAjB,iBAAiB;oCAAjB,iBAAiB;AACxB,qCAMoB;;;AAmBpB;;;;;;;;;;;;;;;;GAgBG;AACH,MAAa,mBAAmB;IAQ9B,qBAAqB;IAErB;;;;OAIG;IACH,YAA+B,OAA6B;QAA7B,YAAO,GAAP,OAAO,CAAsB;IAAG,CAAC;IAEhE,YAAY;IAEZ,wBAAwB;IAExB;;OAEG;IACI,cAAc;QACnB,OAAO,mBAAmB,CAAC,IAAI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AAO,0CAAE,aAAa,EAC3B,EAAE,CACH,CAAC;QACF,MAAM,YAAY,GAAG,IAAI,MAAM,CAAC,IAAI,aAAa,EAAE,CAAC,CAAC;QACrD,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;QAErD,MAAM,WAAW,GAAG,KAAK,CAAC,cAAc,CAAC;QAEzC,OAAO,IAAA,mCAA4B,EAAC,IAAI,EAAE,WAAW,IAAI,EAAE,CAAC,CAAC;IAC/D,CAAC;;AArKH,kDAwKC"}
|
package/lib/core/headers.d.ts
CHANGED
|
@@ -35,3 +35,13 @@ export declare function getFlattenedHeadersMap(headersMap: BothValueHeaders, sep
|
|
|
35
35
|
* @public
|
|
36
36
|
*/
|
|
37
37
|
export declare function getMultiValueHeadersMap(headersMap: BothValueHeaders): Record<string, string[]>;
|
|
38
|
+
/**
|
|
39
|
+
* Parse HTTP Raw Headers
|
|
40
|
+
* Attribution to {@link https://github.com/kesla/parse-headers/blob/master/parse-headers.js}
|
|
41
|
+
*
|
|
42
|
+
* @param headers - The raw headers
|
|
43
|
+
*
|
|
44
|
+
* @breadcrumb Core / Headers
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
export declare function parseHeaders(headers: string): Record<string, string | string[]>;
|
package/lib/core/headers.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getMultiValueHeadersMap = exports.getFlattenedHeadersMap = void 0;
|
|
3
|
+
exports.parseHeaders = exports.getMultiValueHeadersMap = exports.getFlattenedHeadersMap = void 0;
|
|
4
4
|
const { __ΩBothValueHeaders } = require('../@types');
|
|
5
5
|
const __ΩRecord = ['K', 'T', 'l\'e#"Rb!b"Pde"!N#!'];
|
|
6
6
|
//#endregion
|
|
@@ -64,4 +64,34 @@ function getMultiValueHeadersMap(headersMap) {
|
|
|
64
64
|
}
|
|
65
65
|
exports.getMultiValueHeadersMap = getMultiValueHeadersMap;
|
|
66
66
|
getMultiValueHeadersMap.__type = [() => __ΩBothValueHeaders, 'headersMap', () => __ΩRecord, 'getMultiValueHeadersMap', 'Pn!2"&&Fo##/$'];
|
|
67
|
+
/**
|
|
68
|
+
* Parse HTTP Raw Headers
|
|
69
|
+
* Attribution to {@link https://github.com/kesla/parse-headers/blob/master/parse-headers.js}
|
|
70
|
+
*
|
|
71
|
+
* @param headers - The raw headers
|
|
72
|
+
*
|
|
73
|
+
* @breadcrumb Core / Headers
|
|
74
|
+
* @public
|
|
75
|
+
*/
|
|
76
|
+
function parseHeaders(headers) {
|
|
77
|
+
if (!headers)
|
|
78
|
+
return {};
|
|
79
|
+
const result = {};
|
|
80
|
+
const headersArr = headers.trim().split('\n');
|
|
81
|
+
for (let i = 0; i < headersArr.length; i++) {
|
|
82
|
+
const row = headersArr[i];
|
|
83
|
+
const index = row.indexOf(':');
|
|
84
|
+
const key = row.slice(0, index).trim().toLowerCase();
|
|
85
|
+
const value = row.slice(index + 1).trim();
|
|
86
|
+
if (typeof result[key] === 'undefined')
|
|
87
|
+
result[key] = value;
|
|
88
|
+
else if (Array.isArray(result[key]))
|
|
89
|
+
result[key].push(value);
|
|
90
|
+
else
|
|
91
|
+
result[key] = [result[key], value];
|
|
92
|
+
}
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
exports.parseHeaders = parseHeaders;
|
|
96
|
+
parseHeaders.__type = ['headers', () => __ΩRecord, 'parseHeaders', 'P&2!&P&&FJo"#/#'];
|
|
67
97
|
//# sourceMappingURL=headers.js.map
|
package/lib/core/headers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headers.js","sourceRoot":"","sources":["../../src/core/headers.ts"],"names":[],"mappings":";;;wCAEiC,WAAW;;AAE5C,YAAY;AAEZ;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,sBAAsB,CACpC,UAA4B,EAC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AAe;IAEf,IAAI,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IAExB,MAAM,MAAM,GAAG,EAAE,CAAC;IAClB,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAE9C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAC1C,MAAM,GAAG,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;QAC1B,MAAM,KAAK,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC/B,MAAM,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QACrD,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAE1C,IAAI,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,WAAW;YAAE,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;aACvD,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAAE,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;;YACxD,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;KACzC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AApBD,oCAoBC"}
|
|
@@ -7,6 +7,7 @@ import { FrameworkContract } from '../../contracts';
|
|
|
7
7
|
/**
|
|
8
8
|
* The transformer that is responsible to transform buffer's input to javascript objects
|
|
9
9
|
*
|
|
10
|
+
* @deprecated You should use {@link JsonBodyParserFramework} instead, is more reliable and enable you to use transformer of trpc to other things.
|
|
10
11
|
* @breadcrumb Frameworks / TrpcFramework
|
|
11
12
|
* @public
|
|
12
13
|
*/
|
|
@@ -15,6 +15,7 @@ const core_1 = require("../../core");
|
|
|
15
15
|
/**
|
|
16
16
|
* The transformer that is responsible to transform buffer's input to javascript objects
|
|
17
17
|
*
|
|
18
|
+
* @deprecated You should use {@link JsonBodyParserFramework} instead, is more reliable and enable you to use transformer of trpc to other things.
|
|
18
19
|
* @breadcrumb Frameworks / TrpcFramework
|
|
19
20
|
* @public
|
|
20
21
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trpc.framework.js","sourceRoot":"","sources":["../../../src/frameworks/trpc/trpc.framework.ts"],"names":[],"mappings":";;;0CAUmC,cAAc;;;;;;;;AANjD,+DAKyC;AAGzC,qCAA2E;AAE3E,YAAY;AAEZ
|
|
1
|
+
{"version":3,"file":"trpc.framework.js","sourceRoot":"","sources":["../../../src/frameworks/trpc/trpc.framework.ts"],"names":[],"mappings":";;;0CAUmC,cAAc;;;;;;;;AANjD,+DAKyC;AAGzC,qCAA2E;AAE3E,YAAY;AAEZ;;;;;;GAMG;AACH,MAAa,2BAA2B;IACtC;;;;OAIG;IACI,WAAW,CAAC,KAAe;QAChC,IAAI,KAAK,YAAY,MAAM;YAAE,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;QAExE,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;OAIG;IACI,SAAS,CAAC,KAAU;QACzB,OAAO,KAAK,CAAC;IACf,CAAC;;AAnBH,kEAoBC;;;;;;;;AAuGD;;;;;GAKG;AACH,MAAa,aAAa;IAGxB,qBAAqB;IAErB;;OAEG;IACH,YAA+B,OAAwC;QAAxC,YAAO,GAAP,OAAO,CAAiC;IAAG,CAAC;IAE3E,YAAY;IAEZ,wBAAwB;IAExB;;OAEG;IACI,WAAW,CAChB,GAAwB,EACxB,OAAwB,EACxB,QAAwB;QAExB,MAAM,QAAQ,GAAG,IAAI,CAAC,iBAAiB,CAAC,O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|
+
import type { APIGatewayProxyStructuredResultV2 } from 'aws-lambda/trigger/api-gateway-proxy';
|
|
5
|
+
import { BinarySettings } from '../../@types';
|
|
6
|
+
import { AdapterContract, AdapterRequest, FrameworkContract, ResolverContract, ServerlessHandler } from '../../contracts';
|
|
7
|
+
import { BaseHandler, ILogger } from '../../core';
|
|
8
|
+
export declare type AWSResponseStream = Writable;
|
|
9
|
+
export declare type AWSStreamResponseMetadata = Pick<APIGatewayProxyStructuredResultV2, 'statusCode' | 'headers' | 'cookies'>;
|
|
10
|
+
/**
|
|
11
|
+
* The interface that describes the internal context used by the {@link AwsStreamHandler}
|
|
12
|
+
*
|
|
13
|
+
* @breadcrumb Handlers / AwsStreamHandler
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export declare type AWSStreamContext = {
|
|
17
|
+
/**
|
|
18
|
+
* The response stream provided by the serverless
|
|
19
|
+
*/
|
|
20
|
+
response: AWSResponseStream;
|
|
21
|
+
/**
|
|
22
|
+
* The context provided by the serverless
|
|
23
|
+
*/
|
|
24
|
+
context: Context;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* The class that implements a default serverless handler consisting of a function with event, context and callback parameters respectively
|
|
28
|
+
*
|
|
29
|
+
* @breadcrumb Handlers / AwsStreamHandler
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
export declare class AwsStreamHandler<TApp> extends BaseHandler<TApp, APIGatewayProxyEventV2, AWSStreamContext, void, AWSStreamResponseMetadata, void> {
|
|
33
|
+
/**
|
|
34
|
+
* {@inheritDoc}
|
|
35
|
+
*/
|
|
36
|
+
getHandler(app: TApp, framework: FrameworkContract<TApp>, adapters: AdapterContract<APIGatewayProxyEventV2, AWSStreamContext, AWSStreamResponseMetadata>[], resolverFactory: ResolverContract<unknown, unknown, unknown, unknown, unknown>, binarySettings: BinarySettings, respondWithErrors: boolean, log: ILogger): ServerlessHandler<Promise<void>>;
|
|
37
|
+
/**
|
|
38
|
+
* The hook executed on receive a request, before the request is being processed
|
|
39
|
+
*
|
|
40
|
+
* @param log - The instance of logger
|
|
41
|
+
* @param event - The event sent by serverless
|
|
42
|
+
* @param context - The context sent by serverless
|
|
43
|
+
* @param binarySettings - The binary settings
|
|
44
|
+
* @param respondWithErrors - Indicates whether the error stack should be included in the response or not
|
|
45
|
+
*/
|
|
46
|
+
protected onReceiveRequest(log: ILogger, event: APIGatewayProxyEventV2, context: AWSStreamContext, binarySettings: BinarySettings, respondWithErrors: boolean): void;
|
|
47
|
+
/**
|
|
48
|
+
* The hook executed after resolve the adapter that will be used to handle the request and response
|
|
49
|
+
*
|
|
50
|
+
* @param log - The instance of logger
|
|
51
|
+
* @param adapter - The adapter resolved
|
|
52
|
+
*/
|
|
53
|
+
protected onResolveAdapter(log: ILogger, adapter: AdapterContract<APIGatewayProxyEventV2, AWSStreamContext, AWSStreamResponseMetadata>): void;
|
|
54
|
+
/**
|
|
55
|
+
* The hook executed after resolves the request values that will be sent to the framework
|
|
56
|
+
*
|
|
57
|
+
* @param log - The instance of logger
|
|
58
|
+
* @param requestValues - The request values returned by the adapter
|
|
59
|
+
*/
|
|
60
|
+
protected onResolveRequestValues(log: ILogger, requestValues: AdapterRequest): void;
|
|
61
|
+
/**
|
|
62
|
+
* The hook executed before sending response to the serverless with response from adapter
|
|
63
|
+
*
|
|
64
|
+
* @param log - The instance of logger
|
|
65
|
+
* @param successResponse - The success response resolved by the adapter
|
|
66
|
+
*/
|
|
67
|
+
protected onForwardResponseAdapterResponse(log: ILogger, successResponse: AWSStreamResponseMetadata): void;
|
|
68
|
+
/**
|
|
69
|
+
* The function to forward the event to the framework
|
|
70
|
+
*
|
|
71
|
+
* @param app - The instance of the app (express, hapi, etc...)
|
|
72
|
+
* @param framework - The framework that will process requests
|
|
73
|
+
* @param event - The event sent by serverless
|
|
74
|
+
* @param context - The context sent by serverless
|
|
75
|
+
* @param adapter - The adapter resolved to this event
|
|
76
|
+
* @param log - The instance of logger
|
|
77
|
+
* @param binarySettings - The binary settings
|
|
78
|
+
*/
|
|
79
|
+
protected forwardRequestToFramework(app: TApp, framework: FrameworkContract<TApp>, event: APIGatewayProxyEventV2, context: AWSStreamContext, adapter: AdapterContract<APIGatewayProxyEventV2, AWSStreamContext, AWSStreamResponseMetadata>, binarySettings: BinarySettings, log: ILogger): Promise<void>;
|
|
80
|
+
}
|
|
81
|
+
export declare type __ΩAWSResponseStream = any[];
|
|
82
|
+
export declare type __ΩAWSStreamResponseMetadata = any[];
|
|
83
|
+
export declare type __ΩAWSStreamContext = any[];
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AwsStreamHandler = exports.__ΩAWSStreamContext = exports.__ΩAWSStreamResponseMetadata = exports.__ΩAWSResponseStream = void 0;
|
|
7
|
+
const { __ΩFrameworkContract } = require('../../contracts');
|
|
8
|
+
const { __ΩAdapterContract } = require('../../contracts');
|
|
9
|
+
const { __ΩResolverContract } = require('../../contracts');
|
|
10
|
+
const { __ΩBinarySettings } = require('../../@types');
|
|
11
|
+
const { __ΩILogger } = require('../../core');
|
|
12
|
+
const { __ΩServerlessHandler } = require('../../contracts');
|
|
13
|
+
const { __ΩAdapterRequest } = require('../../contracts');
|
|
14
|
+
function __assignType(fn, args) {
|
|
15
|
+
fn.__type = args;
|
|
16
|
+
return fn;
|
|
17
|
+
}
|
|
18
|
+
const __ΩPick = ['T', 'K', 'l+e#!e"!fRb!b"Pde""N#!'];
|
|
19
|
+
const util_1 = __importDefault(require("util"));
|
|
20
|
+
const core_1 = require("../../core");
|
|
21
|
+
const network_1 = require("../../network");
|
|
22
|
+
const __ΩAWSResponseStream = ['!'];
|
|
23
|
+
exports.__ΩAWSResponseStream = __ΩAWSResponseStream;
|
|
24
|
+
const __ΩAWSStreamResponseMetadata = [() => __ΩPick, "statusCode", "headers", "cookies", '"P.".#.$Jo!#'];
|
|
25
|
+
exports.__ΩAWSStreamResponseMetadata = __ΩAWSStreamResponseMetadata;
|
|
26
|
+
const __ΩAWSStreamContext = [() => __ΩAWSResponseStream, 'response', 'context', 'Pn!4""4#M'];
|
|
27
|
+
exports.__ΩAWSStreamContext = __ΩAWSStreamContext;
|
|
28
|
+
/**
|
|
29
|
+
* The class that implements a default serverless handler consisting of a function with event, context and callback parameters respectively
|
|
30
|
+
*
|
|
31
|
+
* @breadcrumb Handlers / AwsStreamHandler
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
class AwsStreamHandler extends core_1.BaseHandler {
|
|
35
|
+
//#region Public Methods
|
|
36
|
+
/**
|
|
37
|
+
* {@inheritDoc}
|
|
38
|
+
*/
|
|
39
|
+
getHandler(app, framework, adapters, resolverFactory, binarySettings, respondWithErrors, log) {
|
|
40
|
+
return awslambda.streamifyResponse(__assignType(async (event, response, context) => {
|
|
41
|
+
const streamContext = { response, context };
|
|
42
|
+
this.onReceiveRequest(log, event, streamContext, binarySettings, respondWithErrors);
|
|
43
|
+
const adapter = this.getAdapterByEventAndContext(event, streamContext, adapters, log);
|
|
44
|
+
this.onResolveAdapter(log, adapter);
|
|
45
|
+
(0, core_1.setCurrentInvoke)({ event, context });
|
|
46
|
+
await this.forwardRequestToFramework(app, framework, event, streamContext, adapter, binarySettings, log);
|
|
47
|
+
}, ['event', 'response', 'context', '', 'P"2!"2""2#"/$']));
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region Hooks
|
|
51
|
+
/**
|
|
52
|
+
* The hook executed on receive a request, before the request is being processed
|
|
53
|
+
*
|
|
54
|
+
* @param log - The instance of logger
|
|
55
|
+
* @param event - The event sent by serverless
|
|
56
|
+
* @param context - The context sent by serverless
|
|
57
|
+
* @param binarySettings - The binary settings
|
|
58
|
+
* @param respondWithErrors - Indicates whether the error stack should be included in the response or not
|
|
59
|
+
*/
|
|
60
|
+
onReceiveRequest(log, event, context, binarySettings, respondWithErrors) {
|
|
61
|
+
log.debug('SERVERLESS_ADAPTER:PROXY', () => ({
|
|
62
|
+
event,
|
|
63
|
+
context: util_1.default.inspect(context, { depth: null }),
|
|
64
|
+
binarySettings,
|
|
65
|
+
respondWithErrors,
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The hook executed after resolve the adapter that will be used to handle the request and response
|
|
70
|
+
*
|
|
71
|
+
* @param log - The instance of logger
|
|
72
|
+
* @param adapter - The adapter resolved
|
|
73
|
+
*/
|
|
74
|
+
onResolveAdapter(log, adapter) {
|
|
75
|
+
log.debug('SERVERLESS_ADAPTER:RESOLVED_ADAPTER_NAME: ', adapter.getAdapterName());
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The hook executed after resolves the request values that will be sent to the framework
|
|
79
|
+
*
|
|
80
|
+
* @param log - The instance of logger
|
|
81
|
+
* @param requestValues - The request values returned by the adapter
|
|
82
|
+
*/
|
|
83
|
+
onResolveRequestValues(log, requestValues) {
|
|
84
|
+
log.debug('SERVERLESS_ADAPTER:FORWARD_REQUEST_TO_FRAMEWORK:REQUEST_VALUES', () => {
|
|
85
|
+
var _a;
|
|
86
|
+
return ({
|
|
87
|
+
requestValues: {
|
|
88
|
+
...requestValues,
|
|
89
|
+
body: (_a = requestValues.body) === null || _a === void 0 ? void 0 : _a.toString(),
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The hook executed before sending response to the serverless with response from adapter
|
|
96
|
+
*
|
|
97
|
+
* @param log - The instance of logger
|
|
98
|
+
* @param successResponse - The success response resolved by the adapter
|
|
99
|
+
*/
|
|
100
|
+
onForwardResponseAdapterResponse(log, successResponse) {
|
|
101
|
+
log.debug('SERVERLESS_ADAPTER:FORWARD_RESPONSE:EVENT_SOURCE_RESPONSE', {
|
|
102
|
+
successResponse,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region Protected Methods
|
|
107
|
+
/**
|
|
108
|
+
* The function to forward the event to the framework
|
|
109
|
+
*
|
|
110
|
+
* @param app - The instance of the app (express, hapi, etc...)
|
|
111
|
+
* @param framework - The framework that will process requests
|
|
112
|
+
* @param event - The event sent by serverless
|
|
113
|
+
* @param context - The context sent by serverless
|
|
114
|
+
* @param adapter - The adapter resolved to this event
|
|
115
|
+
* @param log - The instance of logger
|
|
116
|
+
* @param binarySettings - The binary settings
|
|
117
|
+
*/
|
|
118
|
+
async forwardRequestToFramework(app, framework, event, context, adapter, binarySettings, log) {
|
|
119
|
+
const requestValues = adapter.getRequest(event, context, log);
|
|
120
|
+
this.onResolveRequestValues(log, requestValues);
|
|
121
|
+
const request = new network_1.ServerlessRequest({
|
|
122
|
+
method: requestValues.method,
|
|
123
|
+
headers: requestValues.headers,
|
|
124
|
+
body: requestValues.body,
|
|
125
|
+
remoteAddress: requestValues.remoteAddress,
|
|
126
|
+
url: requestValues.path,
|
|
127
|
+
});
|
|
128
|
+
const response = new network_1.ServerlessStreamResponse({
|
|
129
|
+
method: requestValues.method,
|
|
130
|
+
onReceiveHeaders: __assignType((status, headers) => {
|
|
131
|
+
const flattenedHeaders = (0, core_1.getFlattenedHeadersMap)(headers);
|
|
132
|
+
const awsMetadata = {
|
|
133
|
+
statusCode: status,
|
|
134
|
+
headers: flattenedHeaders,
|
|
135
|
+
};
|
|
136
|
+
const cookies = headers['set-cookie'];
|
|
137
|
+
if (cookies) {
|
|
138
|
+
awsMetadata.cookies = Array.isArray(cookies) ? cookies : [cookies];
|
|
139
|
+
delete headers['set-cookie'];
|
|
140
|
+
delete flattenedHeaders['set-cookie'];
|
|
141
|
+
}
|
|
142
|
+
this.onForwardResponseAdapterResponse(log, awsMetadata);
|
|
143
|
+
const finalResponse = awslambda.HttpResponseStream.from(context.response, awsMetadata);
|
|
144
|
+
// some status do not return body, and
|
|
145
|
+
// for some unknown reason, we cannot finish the stream without writing at least once
|
|
146
|
+
// so I have this thing just to fix this issue
|
|
147
|
+
// ref: https://stackoverflow.com/a/37303151
|
|
148
|
+
const isHundreadStatus = status >= 100 && status < 200;
|
|
149
|
+
const isNoContentStatus = status === 304 || status === 204;
|
|
150
|
+
const isHeadRequest = requestValues.method === 'HEAD';
|
|
151
|
+
if (isHundreadStatus || isNoContentStatus || isHeadRequest) {
|
|
152
|
+
finalResponse.write('');
|
|
153
|
+
// end the response to avoid waiting for nothing
|
|
154
|
+
response.end();
|
|
155
|
+
}
|
|
156
|
+
return finalResponse;
|
|
157
|
+
}, ['status', 'headers', '', 'P"2!"2""/#']),
|
|
158
|
+
log,
|
|
159
|
+
});
|
|
160
|
+
framework.sendRequest(app, request, response);
|
|
161
|
+
log.debug('SERVERLESS_ADAPTER:FORWARD_REQUEST_TO_FRAMEWORK:WAITING_STREAM_COMPLETE');
|
|
162
|
+
await (0, core_1.waitForStreamComplete)(response);
|
|
163
|
+
log.debug('SERVERLESS_ADAPTER:FORWARD_REQUEST_TO_FRAMEWORK:STREAM_COMPLETE');
|
|
164
|
+
context.response.end();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
exports.AwsStreamHandler = AwsStreamHandler;
|
|
168
|
+
AwsStreamHandler.__type = ['TApp', () => __ΩAWSStreamContext, () => __ΩAWSStreamResponseMetadata, () => core_1.BaseHandler, 'app', () => __ΩFrameworkContract, 'framework', () => __ΩAdapterContract, () => __ΩAWSStreamContext, () => __ΩAWSStreamResponseMetadata, 'adapters', () => __ΩResolverContract, 'resolverFactory', () => __ΩBinarySettings, 'binarySettings', 'respondWithErrors', () => __ΩILogger, 'log', () => __ΩServerlessHandler, 'getHandler', () => __ΩILogger, 'event', () => __ΩAWSStreamContext, 'context', () => __ΩBinarySettings, 'onReceiveRequest', () => __ΩILogger, () => __ΩAdapterContract, () => __ΩAWSStreamContext, () => __ΩAWSStreamResponseMetadata, 'adapter', 'onResolveAdapter', () => __ΩILogger, () => __ΩAdapterRequest, 'requestValues', 'onResolveRequestValues', () => __ΩILogger, () => __ΩAWSStreamResponseMetadata, 'successResponse', 'onForwardResponseAdapterResponse', () => __ΩFrameworkContract, () => __ΩAWSStreamContext, () => __ΩAdapterContract, () => __ΩAWSStreamContext, () => __ΩAWSStreamResponseMetadata, () => __ΩBinarySettings, () => __ΩILogger, 'forwardRequestToFramework', () => __ΩAWSStreamContext, () => __ΩAWSStreamResponseMetadata, 'b!Pe"!"n"$n#$7$Pe"!2%e"!o&"2\'"n)n*o($F2+#####o,&2-n.2/)20n122$`o3"04Pn522"26n728n92/)20$0:<Pn;22"n=n>o<$2?$0@<PnA22nB2C$0D<PnE22nF2G"0H<Pe"!2%e"!oI"2\'"26nJ28"nLnMoK$2?nN2/nO22$`0P<5e!!"nQ$nR$6\''];
|
|
169
|
+
//# sourceMappingURL=aws-stream.handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aws-stream.handler.js","sourceRoot":"","sources":["../../../src/handlers/aws/aws-stream.handler.ts"],"names":[],"mappings":";;;;;;yCAaO,iBAAiB;uCAAjB,iBAAiB;wCAAjB,iBAAiB;sCAPO,cAAc;+BActC,YAAY;yCAPZ,iBAAiB;sCAAjB,iBAAiB;;;;;;AAVxB,gDAAwB;AAWxB,qCAMoB;AACpB,2CAA4E;;;;;;;AA4C5E;;;;;GAKG;AACH,MAAa,gBAAuB,SAAQ,kBAO3C;IACC,wBAAwB;IAExB;;OAEG;IACI,UAAU,CACf,GAAS,EACT,SAAkC,EAClC,QAIG,EACH,eAMC,EACD,cAA8B,EAC9B,iBAA0B,EAC1B,GAAY;QAEZ,OAAO,SAAS,CAAC,iBAAiB,cAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE;YACpE,MAAM,aAAa,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;YAE5C,IAAI,CAAC,gBAAgB,CACnB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(Object.create ? (function(o, m, k, k2) {
|
|
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("./aws-stream.handler"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/handlers/aws/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAqC"}
|
package/lib/network/index.d.ts
CHANGED
package/lib/network/index.js
CHANGED
|
@@ -16,4 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./request"), exports);
|
|
18
18
|
__exportStar(require("./response"), exports);
|
|
19
|
+
__exportStar(require("./response-stream"), exports);
|
|
20
|
+
__exportStar(require("./utils"), exports);
|
|
19
21
|
//# sourceMappingURL=index.js.map
|
package/lib/network/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/network/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,6CAA2B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/network/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,6CAA2B;AAC3B,oDAAkC;AAClC,0CAAwB"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { ServerResponse } from 'http';
|
|
4
|
+
import { Writable } from 'stream';
|
|
5
|
+
import { BothValueHeaders } from '../@types';
|
|
6
|
+
import { ILogger } from '../core';
|
|
7
|
+
/**
|
|
8
|
+
* The properties to create a {@link ServerlessStreamResponse}.
|
|
9
|
+
*
|
|
10
|
+
* @breadcrumb Network / ServerlessStreamResponse
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export interface ServerlessStreamResponseProps {
|
|
14
|
+
/**
|
|
15
|
+
* The HTTP Method from request
|
|
16
|
+
*/
|
|
17
|
+
method?: string;
|
|
18
|
+
/**
|
|
19
|
+
* The callback to receive the headers when they are written to the stream
|
|
20
|
+
* You need to return a writable stream be able to continue writing the response
|
|
21
|
+
*
|
|
22
|
+
* @param statusCode - The status code of the response
|
|
23
|
+
* @param headers - The headers of the response
|
|
24
|
+
*/
|
|
25
|
+
onReceiveHeaders: (statusCode: number, headers: BothValueHeaders) => Writable;
|
|
26
|
+
/**
|
|
27
|
+
* Instance of the logger
|
|
28
|
+
*/
|
|
29
|
+
log: ILogger;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The class that represents a response instance used to send to the framework and wait until the framework finishes processing the request.
|
|
33
|
+
* This response is specially built to deal with transfer-encoding: chunked
|
|
34
|
+
*
|
|
35
|
+
* @breadcrumb Network / ServerlessStreamResponse
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
export declare class ServerlessStreamResponse extends ServerResponse {
|
|
39
|
+
constructor({ method, onReceiveHeaders, log, }: ServerlessStreamResponseProps);
|
|
40
|
+
}
|
|
41
|
+
export declare type __ΩServerlessStreamResponseProps = any[];
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServerlessStreamResponse = exports.__ΩServerlessStreamResponseProps = void 0;
|
|
4
|
+
const { __ΩBothValueHeaders } = require('../@types');
|
|
5
|
+
const { __ΩILogger } = require('../core');
|
|
6
|
+
function __assignType(fn, args) {
|
|
7
|
+
fn.__type = args;
|
|
8
|
+
return fn;
|
|
9
|
+
}
|
|
10
|
+
const http_1 = require("http");
|
|
11
|
+
const core_1 = require("../core");
|
|
12
|
+
const utils_1 = require("./utils");
|
|
13
|
+
const endChunked = '0\r\n\r\n';
|
|
14
|
+
const headerEnd = '\r\n\r\n';
|
|
15
|
+
const endStatusSeparator = '\r\n';
|
|
16
|
+
const __ΩServerlessStreamResponseProps = ['method', 'statusCode', () => __ΩBothValueHeaders, 'headers', '', 'onReceiveHeaders', () => __ΩILogger, 'log', 'P&4!8P\'2"n#2$!/%4&n\'4(M'];
|
|
17
|
+
exports.__ΩServerlessStreamResponseProps = __ΩServerlessStreamResponseProps;
|
|
18
|
+
/**
|
|
19
|
+
* The class that represents a response instance used to send to the framework and wait until the framework finishes processing the request.
|
|
20
|
+
* This response is specially built to deal with transfer-encoding: chunked
|
|
21
|
+
*
|
|
22
|
+
* @breadcrumb Network / ServerlessStreamResponse
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
class ServerlessStreamResponse extends http_1.ServerResponse {
|
|
26
|
+
constructor({ method, onReceiveHeaders, log, }) {
|
|
27
|
+
super({ method });
|
|
28
|
+
this.useChunkedEncodingByDefault = true;
|
|
29
|
+
this.chunkedEncoding = true;
|
|
30
|
+
let internalWritable = null;
|
|
31
|
+
let isFirstCall = true;
|
|
32
|
+
// this ignore is used because I need to ignore these write calls:
|
|
33
|
+
// https://github.com/nodejs/node/blob/main/lib/_http_outgoing.js#L934-L935
|
|
34
|
+
// https://github.com/nodejs/node/blob/main/lib/_http_outgoing.js#L937
|
|
35
|
+
let writesToIgnore = 0;
|
|
36
|
+
const socket = {
|
|
37
|
+
_writableState: {},
|
|
38
|
+
writable: true,
|
|
39
|
+
on: core_1.NO_OP,
|
|
40
|
+
removeListener: core_1.NO_OP,
|
|
41
|
+
destroy: core_1.NO_OP,
|
|
42
|
+
cork: core_1.NO_OP,
|
|
43
|
+
uncork: core_1.NO_OP,
|
|
44
|
+
write: __assignType((data, encoding, cb) => {
|
|
45
|
+
// very unlikely, I don't even know how to reproduce this, but exist on types
|
|
46
|
+
// istanbul ignore if
|
|
47
|
+
if (typeof encoding === 'function') {
|
|
48
|
+
cb = encoding;
|
|
49
|
+
encoding = null;
|
|
50
|
+
}
|
|
51
|
+
log.debug('SERVERLESS_ADAPTER:RESPONSE_STREAM:DATA', () => ({
|
|
52
|
+
data: Buffer.isBuffer(data) ? data.toString('utf8') : data,
|
|
53
|
+
encoding,
|
|
54
|
+
}));
|
|
55
|
+
if (!isFirstCall && internalWritable) {
|
|
56
|
+
if (data === endChunked) {
|
|
57
|
+
internalWritable.end(cb);
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
if (writesToIgnore > 0) {
|
|
61
|
+
writesToIgnore--;
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
internalWritable.write(data, cb);
|
|
65
|
+
writesToIgnore = 3;
|
|
66
|
+
}
|
|
67
|
+
else if (isFirstCall) {
|
|
68
|
+
isFirstCall = false;
|
|
69
|
+
const stringData = (0, utils_1.getString)(data);
|
|
70
|
+
const endStatusIndex = stringData.indexOf(endStatusSeparator);
|
|
71
|
+
const status = +stringData.slice(0, endStatusIndex).split(' ')[1];
|
|
72
|
+
const headerData = stringData.slice(endStatusIndex + 2, stringData.indexOf(headerEnd));
|
|
73
|
+
const headers = (0, core_1.parseHeaders)(headerData);
|
|
74
|
+
log.debug('SERVERLESS_ADAPTER:RESPONSE_STREAM:FRAMEWORK_HEADERS', {
|
|
75
|
+
headers,
|
|
76
|
+
});
|
|
77
|
+
writesToIgnore = 1;
|
|
78
|
+
internalWritable = onReceiveHeaders(status, headers);
|
|
79
|
+
}
|
|
80
|
+
return true;
|
|
81
|
+
}, ['data', '', 'encoding', 'cb', 'PPW&J2!P&,P$/"J2#8P$/"2$8"/"']),
|
|
82
|
+
};
|
|
83
|
+
this.assignSocket(socket);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.ServerlessStreamResponse = ServerlessStreamResponse;
|
|
87
|
+
ServerlessStreamResponse.__type = [() => http_1.ServerResponse, () => __ΩServerlessStreamResponseProps, 'param0', 'constructor', 'P7!Pn"2#"0$5'];
|
|
88
|
+
//# sourceMappingURL=response-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response-stream.js","sourceRoot":"","sources":["../../src/network/response-stream.ts"],"names":[],"mappings":";;;wCAGiC,WAAW;+BACC,SAAS;;;;;AAJtD,+BAAsC;AAItC,kCAAuD;AACvD,mCAAoC;AAEpC,MAAM,UAAU,GAAG,WAAW,CAAC;AAC/B,MAAM,SAAS,GAAG,UAAU,CAAC;AAC7B,MAAM,kBAAkB,GAAG,MAAM,CAAC;;;AA6BlC;;;;;;GAMG;AACH,MAAa,wBAAyB,SAAQ,qBAAc;IAC1D,YAAY,EACV,MAAM,EACN,gBAAgB,EAChB,GAAG,GAC2B;QAC9B,KAAK,CAAC,EAAE,MAAM,EAAS,CAAC,CAAC;QAEzB,IAAI,CAAC,2BAA2B,GAAG,IAAI,CAAC;QACxC,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;QAE5B,IAAI,gBAAgB,GAAoB,IAAI,CAAC;QAC7C,IAAI,WAAW,GAAG,IAAI,CAAC;QACvB,kEAAkE;QAClE,2EAA2E;QAC3E,sEAAsE;QACtE,IAAI,cAAc,GAAG,CAAC,CAAC;QAEvB,MAAM,MAAM,GAA8C;YACxD,cAAc,EAAE,EAAE;YAClB,QAAQ,EAAE,IAAI;Y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C,CAAC,CAAC,CAAC,CAAC;oBAElE,MAAM,UAAU,GAAG,UAAU,CAAC,KAAK,CACjC,cAAc,GAAG,CAAC,EAClB,UAAU,CAAC,OAAO,CAAC,SAAS,CAAC,CAC9B,CAAC;oBACF,MAAM,OAAO,GAAG,IAAA,mBAAY,EAAC,UAAU,CAAC,CAAC;oBACzC,GAAG,CAAC,KAAK,CAAC,sDAAsD,EAAE;wBAChE,OAAO;qBACR,CAAC,CAAC;oBAEH,cAAc,GAAG,CAAC,CAAC;oBACnB,gBAAgB,GAAG,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;iBACtD;gBAED,OAAO,IAAI,CAAC;YACd,CAAC,iEAAA;SACF,CAAC;QAEF,IAAI,CAAC,YAAY,CAAC,MAA2B,CAAC,CAAC;IACjD,CAAC;;AAlFH,4DAmFC"}
|
package/lib/network/response.js
CHANGED
|
@@ -9,20 +9,10 @@ const __ΩRecord = ['K', 'T', 'l\'e#"Rb!b"Pde"!N#!'];
|
|
|
9
9
|
// ATTRIBUTION: https://github.com/dougmoscrop/serverless-http
|
|
10
10
|
const http_1 = require("http");
|
|
11
11
|
const core_1 = require("../core");
|
|
12
|
+
const utils_1 = require("./utils");
|
|
12
13
|
const headerEnd = '\r\n\r\n';
|
|
13
14
|
const BODY = Symbol('Response body');
|
|
14
15
|
const HEADERS = Symbol('Response headers');
|
|
15
|
-
function getString(data) {
|
|
16
|
-
if (Buffer.isBuffer(data))
|
|
17
|
-
return data.toString('utf8');
|
|
18
|
-
else if (typeof data === 'string')
|
|
19
|
-
return data;
|
|
20
|
-
else if (data instanceof Uint8Array)
|
|
21
|
-
return new TextDecoder().decode(data);
|
|
22
|
-
else
|
|
23
|
-
throw new Error(`response.write() of unexpected type: ${typeof data}`);
|
|
24
|
-
}
|
|
25
|
-
getString.__type = ['data', 'getString', 'PP!&#J2!"/"'];
|
|
26
16
|
function addData(stream, data) {
|
|
27
17
|
if (Buffer.isBuffer(data) ||
|
|
28
18
|
typeof data === 'string' ||
|
|
@@ -65,7 +55,7 @@ class ServerlessResponse extends http_1.ServerResponse {
|
|
|
65
55
|
if (this._header === '' || this._wroteHeader)
|
|
66
56
|
addData(this, data);
|
|
67
57
|
else {
|
|
68
|
-
const string = getString(data);
|
|
58
|
+
const string = (0, utils_1.getString)(data);
|
|
69
59
|
const index = string.indexOf(headerEnd);
|
|
70
60
|
if (index !== -1) {
|
|
71
61
|
const remainder = string.slice(index + headerEnd.length);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response.js","sourceRoot":"","sources":["../../src/network/response.ts"],"names":[],"mappings":";;;;;;;;AAAA,8DAA8D;AAC9D,+BAAuD;AAEvD,kCAAgC;
|
|
1
|
+
{"version":3,"file":"response.js","sourceRoot":"","sources":["../../src/network/response.ts"],"names":[],"mappings":";;;;;;;;AAAA,8DAA8D;AAC9D,+BAAuD;AAEvD,kCAAgC;AAChC,mCAAoC;AAEpC,MAAM,SAAS,GAAG,UAAU,CAAC;AAE7B,MAAM,IAAI,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AACrC,MAAM,OAAO,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;AAE3C,SAAS,OAAO,CAAC,MAA0B,EAAE,IAAyB;IACpE,IACE,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;QACrB,OAAO,IAAI,KAAK,QAAQ;QACxB,IAAI,YAAY,UAAU;QAE1B,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;;QAClC,MAAM,IAAI,KAAK,CAAC,wCAAwC,OAAO,IAAI,EAAE,CAAC,CAAC;AAC9E,CAAC;;;;AAeD;;;;;;GAMG;AACH,MAAa,kBAAmB,SAAQ,qBAAc;IACpD,YAAY,EAAE,MAAM,EAA2B;QAC7C,KAAK,CAAC,EAAE,MAAM,EAAS,CAAC,CAAC;QAEzB,IAAI,CAAC,IAAI,CAAC,GAAG,E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AC,aAAa,CAAC;QAE1D,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC,iBAAiB,CAAC;YACnD,CAAC,CAAC,iBAAiB;YACnB,CAAC,CAAC,CAAC,iBAAiB,IAAI,EAAE,CAAC,CAAC;QAE9B,KAAK,MAAM,OAAO,IAAI,YAAY,EAAE;YAClC,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE;gBAC1B,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAE,CAAC,CAAC;gBAErC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE;oBACtB,8CAA8C;oBAC9C,8CAA8C;oBAC9C,MAAM;iBACP;aACF;SACF;QAED,OAAO,IAAI,CAAC,mBAAmB,CAAC,UAAU,EAAE,aAAa,EAAE,GAAG,CAAC,CAAC;IAClE,CAAC;IAED;;;;;;OAMG;IACO,mBAAmB,CAC3B,UAAkB,EAClB,aAAoC,EACpC,GAAiB;QAEjB,OAAO,KAAK,CAAC,SAAS,CAAC,UAAU,EAAE,aAAa,EAAE,GAAG,CAAC,CAAC;IACzD,CAAC;;AA/HH,gDAgIC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getString = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Get the data from a buffer, string, or Uint8Array
|
|
6
|
+
*
|
|
7
|
+
* @param data - The data that was written inside the stream
|
|
8
|
+
*/
|
|
9
|
+
function getString(data) {
|
|
10
|
+
if (Buffer.isBuffer(data))
|
|
11
|
+
return data.toString('utf8');
|
|
12
|
+
else if (typeof data === 'string')
|
|
13
|
+
return data;
|
|
14
|
+
else if (data instanceof Uint8Array)
|
|
15
|
+
return new TextDecoder().decode(data);
|
|
16
|
+
else
|
|
17
|
+
throw new Error(`response.write() of unexpected type: ${typeof data}`);
|
|
18
|
+
}
|
|
19
|
+
exports.getString = getString;
|
|
20
|
+
getString.__type = ['data', 'getString', 'PP!&#J2!"/"'];
|
|
21
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/network/utils.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,SAAgB,SAAS,CAAC,IAA+B;IACvD,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;SACnD,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;SAC1C,IAAI,IAAI,YAAY,UAAU;QAAE,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;;QACtE,MAAM,IAAI,KAAK,CAAC,wCAAwC,OAAO,IAAI,EAAE,CAAC,CAAC;AAC9E,CAAC;AALD,8BAKC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@h4ad/serverless-adapter",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.17.0",
|
|
4
4
|
"description": "Run REST APIs and other web applications using your existing Node.js application framework (NestJS, Express, Koa, Hapi, Fastify and many others), on top of AWS, Azure, Digital Ocean and many other clouds.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"files": [
|