@tsed/platform-serverless 7.0.0-beta.2 → 7.0.0-beta.20
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/coverage.json +6 -0
- package/jest.config.js +1 -6
- package/lib/cjs/builder/PlatformServerless.js +13 -10
- package/lib/cjs/builder/PlatformServerless.js.map +1 -1
- package/lib/cjs/builder/PlatformServerlessHandler.js +15 -15
- package/lib/cjs/builder/PlatformServerlessHandler.js.map +1 -1
- package/lib/cjs/domain/ServerlessContext.js +10 -3
- package/lib/cjs/domain/ServerlessContext.js.map +1 -1
- package/lib/cjs/domain/ServerlessRequest.js +21 -12
- package/lib/cjs/domain/ServerlessRequest.js.map +1 -1
- package/lib/cjs/domain/ServerlessResponse.js +35 -34
- package/lib/cjs/domain/ServerlessResponse.js.map +1 -1
- package/lib/cjs/exports.js +16 -0
- package/lib/cjs/exports.js.map +1 -0
- package/lib/cjs/index.js +11 -18
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/package.json +3 -0
- package/lib/cjs/utils/getRequestId.js +2 -3
- package/lib/cjs/utils/getRequestId.js.map +1 -1
- package/lib/cjs/utils/setResponseHeaders.js +1 -1
- package/lib/cjs/utils/setResponseHeaders.js.map +1 -1
- package/lib/esm/builder/PlatformServerless.js +11 -12
- package/lib/esm/builder/PlatformServerless.js.map +1 -1
- package/lib/esm/builder/PlatformServerlessHandler.js +8 -8
- package/lib/esm/builder/PlatformServerlessHandler.js.map +1 -1
- package/lib/esm/domain/ServerlessContext.js +12 -5
- package/lib/esm/domain/ServerlessContext.js.map +1 -1
- package/lib/esm/domain/ServerlessRequest.js +21 -12
- package/lib/esm/domain/ServerlessRequest.js.map +1 -1
- package/lib/esm/domain/ServerlessResponse.js +33 -33
- package/lib/esm/domain/ServerlessResponse.js.map +1 -1
- package/lib/esm/exports.js +4 -0
- package/lib/esm/exports.js.map +1 -0
- package/lib/esm/index.js +11 -9
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/package.json +3 -0
- package/lib/esm/utils/getRequestId.js +2 -3
- package/lib/esm/utils/getRequestId.js.map +1 -1
- package/lib/esm/utils/setResponseHeaders.js +1 -1
- package/lib/esm/utils/setResponseHeaders.js.map +1 -1
- package/lib/types/builder/PlatformServerless.d.ts +2 -2
- package/lib/types/builder/PlatformServerlessHandler.d.ts +1 -1
- package/lib/types/domain/ServerlessContext.d.ts +1 -0
- package/lib/types/domain/ServerlessRequest.d.ts +6 -8
- package/lib/types/domain/ServerlessResponse.d.ts +6 -11
- package/lib/types/exports.d.ts +3 -0
- package/lib/types/index.d.ts +8 -5
- package/package.json +34 -16
- package/readme.md +35 -34
- package/tsconfig.compile.esm.json +1 -12
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exports.js","sourceRoot":"","sources":["../../src/exports.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,OAAO,EAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,IAAI,MAAM,EAAC,MAAM,cAAc,CAAC;AAC3F,cAAc,uBAAuB,CAAC","sourcesContent":["export * from \"@tsed/di\";\nexport {Get, Post, Put, Delete, Head, Patch, Options, Route as Lambda} from \"@tsed/schema\";\nexport * from \"@tsed/platform-params\";\n"]}
|
package/lib/esm/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./builder/PlatformServerless";
|
|
6
|
-
|
|
7
|
-
export * from "./domain/ServerlessContext";
|
|
8
|
-
export * from "./domain/
|
|
9
|
-
export * from "./domain/ServerlessResponse";
|
|
1
|
+
/**
|
|
2
|
+
* @file Automatically generated by barrelsby.
|
|
3
|
+
*/
|
|
4
|
+
export * from "./exports.js";
|
|
5
|
+
export * from "./builder/PlatformServerless.js";
|
|
6
|
+
export * from "./builder/PlatformServerlessHandler.js";
|
|
7
|
+
export * from "./domain/ServerlessContext.js";
|
|
8
|
+
export * from "./domain/ServerlessRequest.js";
|
|
9
|
+
export * from "./domain/ServerlessResponse.js";
|
|
10
|
+
export * from "./utils/getRequestId.js";
|
|
11
|
+
export * from "./utils/setResponseHeaders.js";
|
|
10
12
|
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qCAAqC,CAAC;AACpD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./exports\";\nexport * from \"./builder/PlatformServerless\";\nexport * from \"./builder/PlatformServerlessHandler\";\nexport * from \"./domain/ServerlessContext\";\nexport * from \"./domain/ServerlessRequest\";\nexport * from \"./domain/ServerlessResponse\";\nexport * from \"./utils/getRequestId\";\nexport * from \"./utils/setResponseHeaders\";\n"]}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { v4 } from "uuid";
|
|
2
2
|
export function getRequestId(event, context) {
|
|
3
|
-
|
|
4
|
-
if ((event === null || event === void 0 ? void 0 : event.headers) && event.headers["x-request-id"]) {
|
|
3
|
+
if (event?.headers && event.headers["x-request-id"]) {
|
|
5
4
|
return event.headers["x-request-id"];
|
|
6
5
|
}
|
|
7
|
-
return
|
|
6
|
+
return event?.requestContext?.requestId || context?.awsRequestId || v4().replace(/-/gi, "");
|
|
8
7
|
}
|
|
9
8
|
//# sourceMappingURL=getRequestId.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRequestId.js","sourceRoot":"","sources":["../../../src/utils/getRequestId.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,EAAE,EAAC,MAAM,MAAM,CAAC;AAExB,MAAM,UAAU,YAAY,CAAC,KAAwE,EAAE,OAAgB
|
|
1
|
+
{"version":3,"file":"getRequestId.js","sourceRoot":"","sources":["../../../src/utils/getRequestId.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,EAAE,EAAC,MAAM,MAAM,CAAC;AAExB,MAAM,UAAU,YAAY,CAAC,KAAwE,EAAE,OAAgB;IACrH,IAAI,KAAK,EAAE,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE;QACnD,OAAO,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;KACtC;IAED,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,IAAI,OAAO,EAAE,YAAY,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AAC9F,CAAC","sourcesContent":["import {APIGatewayEventDefaultAuthorizerContext, APIGatewayProxyEventBase, Context} from \"aws-lambda\";\nimport {v4} from \"uuid\";\n\nexport function getRequestId(event: APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>, context: Context) {\n if (event?.headers && event.headers[\"x-request-id\"]) {\n return event.headers[\"x-request-id\"];\n }\n\n return event?.requestContext?.requestId || context?.awsRequestId || v4().replace(/-/gi, \"\");\n}\n"]}
|
|
@@ -13,7 +13,7 @@ function mergeHeaders(specHeaders, headers) {
|
|
|
13
13
|
export function setResponseHeaders(ctx) {
|
|
14
14
|
const { response, endpoint } = ctx;
|
|
15
15
|
const operation = endpoint.operation;
|
|
16
|
-
if (
|
|
16
|
+
if (ctx.isDone()) {
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
19
|
if (!response.hasStatus()) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setResponseHeaders.js","sourceRoot":"","sources":["../../../src/utils/setResponseHeaders.ts"],"names":[],"mappings":"AAIA,SAAS,YAAY,CAAC,WAA2D,EAAE,OAAoC;IACrH,OAAO,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE;QACjE,GAAG,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;QACxB,OAAO;YACL,GAAG,OAAO;YACV,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC;SACxE,CAAC;IACJ,CAAC,EAAE,OAAO,CAAC,CAAC;AACd,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAsB;IACvD,MAAM,EAAC,QAAQ,EAAE,QAAQ,EAAC,GAAG,GAAG,CAAC;IACjC,MAAM,SAAS,GAAG,QAAQ,CAAC,SAAU,CAAC;IAEtC,IAAI,
|
|
1
|
+
{"version":3,"file":"setResponseHeaders.js","sourceRoot":"","sources":["../../../src/utils/setResponseHeaders.ts"],"names":[],"mappings":"AAIA,SAAS,YAAY,CAAC,WAA2D,EAAE,OAAoC;IACrH,OAAO,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE;QACjE,GAAG,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;QACxB,OAAO;YACL,GAAG,OAAO;YACV,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC;SACxE,CAAC;IACJ,CAAC,EAAE,OAAO,CAAC,CAAC;AACd,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAsB;IACvD,MAAM,EAAC,QAAQ,EAAE,QAAQ,EAAC,GAAG,GAAG,CAAC;IACjC,MAAM,SAAS,GAAG,QAAQ,CAAC,SAAU,CAAC;IAEtC,IAAI,GAAG,CAAC,MAAM,EAAE,EAAE;QAChB,OAAO;KACR;IAED,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE;QACzB,kDAAkD;QAClD,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC,CAAC;KACxC;IAED,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC;IACvC,MAAM,OAAO,GAAG,SAAS,CAAC,YAAY,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAC5D,MAAM,aAAa,GAAG,YAAY,CAAC,OAAO,EAAE,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;IAEnE,QAAQ,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;IAEnC,IAAI,SAAS,CAAC,aAAa,CAAC,UAAU,CAAC,EAAE;QACvC,QAAQ,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;KAClE;AACH,CAAC","sourcesContent":["import {JsonHeader} from \"@tsed/schema\";\nimport {ServerlessContext} from \"../domain/ServerlessContext\";\nimport {HeaderValue} from \"../domain/ServerlessResponse\";\n\nfunction mergeHeaders(specHeaders: Record<string, JsonHeader & {example: string}>, headers: Record<string, HeaderValue>) {\n return Object.entries(specHeaders).reduce((headers, [key, item]) => {\n key = key.toLowerCase();\n return {\n ...headers,\n [key]: headers[key] === undefined ? String(item.example) : headers[key]\n };\n }, headers);\n}\n\n/**\n * @ignore\n */\nexport function setResponseHeaders(ctx: ServerlessContext) {\n const {response, endpoint} = ctx;\n const operation = endpoint.operation!;\n\n if (ctx.isDone()) {\n return;\n }\n\n if (!response.hasStatus()) {\n // apply status only if the isn't already modified\n response.status(operation.getStatus());\n }\n\n const statusCode = response.statusCode;\n const headers = operation.getHeadersOf(response.statusCode);\n const mergedHeaders = mergeHeaders(headers, response.getHeaders());\n\n response.setHeaders(mergedHeaders);\n\n if (operation.isRedirection(statusCode)) {\n response.redirect(statusCode, String(mergedHeaders[\"location\"]));\n }\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Type } from "@tsed/core";
|
|
2
2
|
import { InjectorService } from "@tsed/di";
|
|
3
|
-
import type { Instance } from "find-my-way";
|
|
4
3
|
import type { Handler } from "aws-lambda";
|
|
4
|
+
import type { Instance } from "find-my-way";
|
|
5
5
|
export interface PlatformServerlessSettings extends Partial<TsED.Configuration> {
|
|
6
6
|
lambda?: Type[];
|
|
7
7
|
}
|
|
@@ -14,7 +14,7 @@ export declare class PlatformServerless {
|
|
|
14
14
|
private _router;
|
|
15
15
|
private _promise;
|
|
16
16
|
get injector(): InjectorService;
|
|
17
|
-
get settings():
|
|
17
|
+
get settings(): import("@tsed/di").DIConfiguration;
|
|
18
18
|
get promise(): Promise<any>;
|
|
19
19
|
static bootstrap(settings?: Partial<TsED.Configuration> & {
|
|
20
20
|
lambda?: Type[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { InjectorService, TokenProvider } from "@tsed/di";
|
|
2
|
-
import { PlatformParams } from "@tsed/platform-params";
|
|
3
2
|
import type { PlatformExceptions } from "@tsed/platform-exceptions";
|
|
3
|
+
import { PlatformParams } from "@tsed/platform-params";
|
|
4
4
|
import { ServerlessContext } from "../domain/ServerlessContext";
|
|
5
5
|
export declare class PlatformServerlessHandler {
|
|
6
6
|
protected injector: InjectorService;
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
export interface ServerlessRequestOptions {
|
|
3
|
-
event: APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;
|
|
4
|
-
context: Context;
|
|
5
|
-
}
|
|
1
|
+
import { ServerlessContext } from "./ServerlessContext";
|
|
6
2
|
/**
|
|
7
3
|
* @platform
|
|
8
4
|
*/
|
|
9
5
|
export declare class ServerlessRequest {
|
|
10
|
-
|
|
11
|
-
constructor(
|
|
6
|
+
protected $ctx: ServerlessContext;
|
|
7
|
+
constructor($ctx: ServerlessContext);
|
|
8
|
+
get event(): import("aws-lambda").APIGatewayProxyEventBase<import("aws-lambda").APIGatewayEventDefaultAuthorizerContext>;
|
|
9
|
+
get raw(): import("aws-lambda").APIGatewayProxyEventBase<import("aws-lambda").APIGatewayEventDefaultAuthorizerContext>;
|
|
10
|
+
get response(): import("./ServerlessResponse").ServerlessResponse;
|
|
12
11
|
get secure(): boolean;
|
|
13
12
|
get host(): string;
|
|
14
13
|
get protocol(): string;
|
|
@@ -51,5 +50,4 @@ export declare class ServerlessRequest {
|
|
|
51
50
|
* @param name
|
|
52
51
|
*/
|
|
53
52
|
get(name: string): any;
|
|
54
|
-
destroy(): void;
|
|
55
53
|
}
|
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { ServerlessRequest } from "./ServerlessRequest";
|
|
3
|
-
export interface ServerlessResponseOptions {
|
|
4
|
-
event: APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;
|
|
5
|
-
context: Context;
|
|
6
|
-
request: ServerlessRequest;
|
|
7
|
-
}
|
|
1
|
+
import { ServerlessContext } from "./ServerlessContext";
|
|
8
2
|
export declare type HeaderValue = boolean | number | string;
|
|
9
3
|
/**
|
|
10
4
|
* @platform
|
|
11
5
|
*/
|
|
12
6
|
export declare class ServerlessResponse {
|
|
13
7
|
#private;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
protected $ctx: ServerlessContext;
|
|
9
|
+
constructor($ctx: ServerlessContext);
|
|
10
|
+
get event(): import("aws-lambda").APIGatewayProxyEventBase<import("aws-lambda").APIGatewayEventDefaultAuthorizerContext>;
|
|
11
|
+
get raw(): import("aws-lambda").APIGatewayProxyEventBase<import("aws-lambda").APIGatewayEventDefaultAuthorizerContext>;
|
|
12
|
+
get request(): import("./ServerlessRequest").ServerlessRequest;
|
|
17
13
|
/**
|
|
18
14
|
* Get the current statusCode
|
|
19
15
|
*/
|
|
@@ -100,6 +96,5 @@ export declare class ServerlessResponse {
|
|
|
100
96
|
body(body: any): this;
|
|
101
97
|
getBody(): any;
|
|
102
98
|
isDone(): boolean;
|
|
103
|
-
onEnd(cb: Function): this;
|
|
104
99
|
destroy(): void;
|
|
105
100
|
}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export * from "./
|
|
1
|
+
/**
|
|
2
|
+
* @file Automatically generated by barrelsby.
|
|
3
|
+
*/
|
|
4
|
+
export * from "./exports";
|
|
5
5
|
export * from "./builder/PlatformServerless";
|
|
6
|
+
export * from "./builder/PlatformServerlessHandler";
|
|
6
7
|
export * from "./domain/ServerlessContext";
|
|
8
|
+
export * from "./domain/ServerlessRequest";
|
|
7
9
|
export * from "./domain/ServerlessResponse";
|
|
8
|
-
export * from "./
|
|
10
|
+
export * from "./utils/getRequestId";
|
|
11
|
+
export * from "./utils/setResponseHeaders";
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/platform-serverless",
|
|
3
|
-
"version": "7.0.0-beta.
|
|
3
|
+
"version": "7.0.0-beta.20",
|
|
4
4
|
"description": "Platform serverless module for Ts.ED Framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
7
7
|
"main": "./lib/cjs/index.js",
|
|
8
|
+
"module": "./lib/esm/index.js",
|
|
8
9
|
"typings": "./lib/types/index.d.ts",
|
|
9
10
|
"exports": {
|
|
10
11
|
"types": "./lib/types/index.d.ts",
|
|
@@ -13,37 +14,54 @@
|
|
|
13
14
|
"default": "./lib/esm/index.js"
|
|
14
15
|
},
|
|
15
16
|
"scripts": {
|
|
16
|
-
"build": "yarn run build:esm && yarn run build:cjs",
|
|
17
|
+
"build": "yarn barrels && yarn run build:esm && yarn run build:cjs",
|
|
17
18
|
"build:cjs": "tsc --build tsconfig.compile.json",
|
|
18
19
|
"build:esm": "tsc --build tsconfig.compile.esm.json",
|
|
20
|
+
"barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\" -e \".benchmark.ts\"",
|
|
19
21
|
"test": "cross-env NODE_ENV=test jest"
|
|
20
22
|
},
|
|
21
23
|
"dependencies": {
|
|
22
|
-
"@tsed/core": "7.0.0-beta.
|
|
23
|
-
"@tsed/
|
|
24
|
-
"@tsed/
|
|
25
|
-
"@tsed/
|
|
26
|
-
"@tsed/
|
|
27
|
-
"@tsed/
|
|
28
|
-
"@tsed/platform-params": "7.0.0-beta.2",
|
|
29
|
-
"@tsed/schema": "7.0.0-beta.2",
|
|
24
|
+
"@tsed/core": "7.0.0-beta.20",
|
|
25
|
+
"@tsed/exceptions": "7.0.0-beta.20",
|
|
26
|
+
"@tsed/json-mapper": "7.0.0-beta.20",
|
|
27
|
+
"@tsed/platform-exceptions": "7.0.0-beta.20",
|
|
28
|
+
"@tsed/platform-params": "7.0.0-beta.20",
|
|
29
|
+
"@tsed/schema": "7.0.0-beta.20",
|
|
30
30
|
"encodeurl": "^1.0.2",
|
|
31
31
|
"mime": "^2.5.2",
|
|
32
|
-
"tslib": "2.
|
|
32
|
+
"tslib": "2.4.0",
|
|
33
33
|
"uuid": "^8.3.2"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@tsed/platform-serverless-testing": "7.0.0-beta.
|
|
36
|
+
"@tsed/platform-serverless-testing": "7.0.0-beta.20",
|
|
37
37
|
"@types/aws-lambda": "^8.10.83",
|
|
38
38
|
"@types/encodeurl": "^1.0.0",
|
|
39
|
-
"@types/mime": "^2.0.3"
|
|
39
|
+
"@types/mime": "^2.0.3",
|
|
40
|
+
"find-my-way": "^7.0.0"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"@tsed/di": "^7.0.0-beta.20",
|
|
44
|
+
"@tsed/logger": ">=6.2.0"
|
|
45
|
+
},
|
|
46
|
+
"peerDependenciesMeta": {
|
|
47
|
+
"@tsed/di": {
|
|
48
|
+
"optional": false
|
|
49
|
+
},
|
|
50
|
+
"@tsed/logger": {
|
|
51
|
+
"optional": false
|
|
52
|
+
},
|
|
53
|
+
"find-my-way": {
|
|
54
|
+
"optional": true
|
|
55
|
+
}
|
|
40
56
|
},
|
|
41
|
-
"peerDependencies": {},
|
|
42
57
|
"repository": "https://github.com/tsedio/tsed",
|
|
43
58
|
"bugs": {
|
|
44
59
|
"url": "https://github.com/tsedio/tsed/issues"
|
|
45
60
|
},
|
|
46
|
-
"homepage": "https://github.com/tsedio/tsed/tree/
|
|
61
|
+
"homepage": "https://github.com/tsedio/tsed/tree/beta/packages/platform/platform-serverless",
|
|
47
62
|
"author": "Romain Lenzotti",
|
|
48
|
-
"license": "MIT"
|
|
63
|
+
"license": "MIT",
|
|
64
|
+
"publishConfig": {
|
|
65
|
+
"tag": "beta"
|
|
66
|
+
}
|
|
49
67
|
}
|
package/readme.md
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
[](https://badge.fury.io/js/%40tsed%2Fcommon)
|
|
12
12
|
[](https://github.com/semantic-release/semantic-release)
|
|
13
13
|
[](https://github.com/prettier/prettier)
|
|
14
|
-
[](https://github.com/sponsors/romakita)
|
|
15
|
+
[](https://opencollective.com/tsed)
|
|
15
16
|
|
|
16
17
|
</div>
|
|
17
18
|
|
|
@@ -111,16 +112,18 @@ tsed init .
|
|
|
111
112
|
? Choose extra linter tools Prettier, Lint on commit
|
|
112
113
|
? Choose the package manager: Yarn
|
|
113
114
|
```
|
|
114
|
-
|
|
115
|
+
|
|
115
116
|
This tutorial works also with NPM package manager!
|
|
116
117
|
|
|
117
118
|
Yarn:
|
|
119
|
+
|
|
118
120
|
```bash
|
|
119
121
|
yarn add @tsed/platform-serverless serverless serverless-offline
|
|
120
122
|
yarn add -D @types/aws-lambda
|
|
121
123
|
```
|
|
122
124
|
|
|
123
125
|
Npm:
|
|
126
|
+
|
|
124
127
|
```bash
|
|
125
128
|
npm install --save @tsed/platform-serverless serverless serverless-offline
|
|
126
129
|
npm install --save-dev @types/aws-lambda
|
|
@@ -161,11 +164,9 @@ import {PlatformServerless} from "@tsed/platform-serverless";
|
|
|
161
164
|
import {TimeslotsLambda} from "./lambda/TimeslotsLambda";
|
|
162
165
|
|
|
163
166
|
const platform = PlatformServerless.bootstrap({
|
|
164
|
-
lambda: [
|
|
165
|
-
TimeslotsLambda
|
|
166
|
-
]
|
|
167
|
+
lambda: [TimeslotsLambda]
|
|
167
168
|
// put your Application configuration here
|
|
168
|
-
})
|
|
169
|
+
});
|
|
169
170
|
|
|
170
171
|
// then export the lambda
|
|
171
172
|
export = platform.callbacks();
|
|
@@ -176,23 +177,23 @@ Finally, create the `serverless.yml`:
|
|
|
176
177
|
```yml
|
|
177
178
|
service: timeslots
|
|
178
179
|
|
|
179
|
-
frameworkVersion:
|
|
180
|
+
frameworkVersion: "2"
|
|
180
181
|
|
|
181
182
|
provider:
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
183
|
+
name: aws
|
|
184
|
+
runtime: nodejs14.x
|
|
185
|
+
lambdaHashingVersion: "20201221"
|
|
185
186
|
|
|
186
187
|
plugins:
|
|
187
|
-
|
|
188
|
+
- serverless-offline
|
|
188
189
|
|
|
189
190
|
functions:
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
191
|
+
timeslots:
|
|
192
|
+
handler: dist/handler.getTimeslots
|
|
193
|
+
events:
|
|
194
|
+
- http:
|
|
195
|
+
path: /timeslots
|
|
196
|
+
method: get
|
|
196
197
|
```
|
|
197
198
|
|
|
198
199
|
## Invoke a lambda with serverless
|
|
@@ -246,12 +247,12 @@ To use the embed router, change the `serverless.yml` declaration by this example
|
|
|
246
247
|
```yml
|
|
247
248
|
service: timeslots
|
|
248
249
|
|
|
249
|
-
frameworkVersion:
|
|
250
|
+
frameworkVersion: "2"
|
|
250
251
|
|
|
251
252
|
provider:
|
|
252
253
|
name: aws
|
|
253
254
|
runtime: nodejs14.x
|
|
254
|
-
lambdaHashingVersion:
|
|
255
|
+
lambdaHashingVersion: "20201221"
|
|
255
256
|
|
|
256
257
|
plugins:
|
|
257
258
|
- serverless-offline
|
|
@@ -265,7 +266,7 @@ functions:
|
|
|
265
266
|
path: /
|
|
266
267
|
- http:
|
|
267
268
|
method: ANY
|
|
268
|
-
path:
|
|
269
|
+
path: "{proxy+}"
|
|
269
270
|
```
|
|
270
271
|
|
|
271
272
|
Then, edit the `handler.ts` and change the exported functions:
|
|
@@ -304,14 +305,14 @@ import {ServerlessContext} from "./ServerlessContext";
|
|
|
304
305
|
@Injectable()
|
|
305
306
|
export class TimeslotsLambda {
|
|
306
307
|
get(@Context() $ctx: ServerlessContext) {
|
|
307
|
-
console.log($ctx.context) // AWS Context
|
|
308
|
-
console.log($ctx.event) // AWS Event
|
|
309
|
-
console.log($ctx.response) // Response Platform abstraction layer
|
|
310
|
-
console.log($ctx.request) // Request Platform abstraction layer
|
|
311
|
-
|
|
312
|
-
$ctx.response.setHeader(
|
|
313
|
-
|
|
314
|
-
return {}
|
|
308
|
+
console.log($ctx.context); // AWS Context
|
|
309
|
+
console.log($ctx.event); // AWS Event
|
|
310
|
+
console.log($ctx.response); // Response Platform abstraction layer
|
|
311
|
+
console.log($ctx.request); // Request Platform abstraction layer
|
|
312
|
+
|
|
313
|
+
$ctx.response.setHeader("x-test", "test");
|
|
314
|
+
|
|
315
|
+
return {};
|
|
315
316
|
}
|
|
316
317
|
}
|
|
317
318
|
```
|
|
@@ -364,7 +365,8 @@ describe("TimeslotsLambdaController", () => {
|
|
|
364
365
|
});
|
|
365
366
|
|
|
366
367
|
it("should call getAll Lambda", async () => {
|
|
367
|
-
const response = await PlatformServerlessTest.request
|
|
368
|
+
const response = await PlatformServerlessTest.request
|
|
369
|
+
.call("getById")
|
|
368
370
|
.params({
|
|
369
371
|
id: "1"
|
|
370
372
|
})
|
|
@@ -383,9 +385,9 @@ describe("TimeslotsLambdaController", () => {
|
|
|
383
385
|
endDate: "2020-01-10T00:00:00.000Z",
|
|
384
386
|
startDate: "2020-01-01T00:00:00.000Z"
|
|
385
387
|
});
|
|
386
|
-
});
|
|
388
|
+
});
|
|
387
389
|
});
|
|
388
|
-
|
|
390
|
+
|
|
389
391
|
describe("invoke using the router", () => {
|
|
390
392
|
it("should call getAll Lambda", async () => {
|
|
391
393
|
const response = await PlatformServerlessTest.request.get("/");
|
|
@@ -402,18 +404,17 @@ describe("TimeslotsLambdaController", () => {
|
|
|
402
404
|
```
|
|
403
405
|
|
|
404
406
|
## Contributors
|
|
407
|
+
|
|
405
408
|
Please read [contributing guidelines here](https://tsed.io/CONTRIBUTING.html).
|
|
406
409
|
|
|
407
410
|
<a href="https://github.com/tsedio/ts-express-decorators/graphs/contributors"><img src="https://opencollective.com/tsed/contributors.svg?width=890" /></a>
|
|
408
411
|
|
|
409
|
-
|
|
410
412
|
## Backers
|
|
411
413
|
|
|
412
414
|
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)]
|
|
413
415
|
|
|
414
416
|
<a href="https://opencollective.com/tsed#backers" target="_blank"><img src="https://opencollective.com/tsed/tiers/backer.svg?width=890"></a>
|
|
415
417
|
|
|
416
|
-
|
|
417
418
|
## Sponsors
|
|
418
419
|
|
|
419
420
|
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)]
|
|
@@ -422,7 +423,7 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
|
|
|
422
423
|
|
|
423
424
|
The MIT License (MIT)
|
|
424
425
|
|
|
425
|
-
Copyright (c) 2016 -
|
|
426
|
+
Copyright (c) 2016 - 2022 Romain Lenzotti
|
|
426
427
|
|
|
427
428
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
428
429
|
|
|
@@ -8,16 +8,5 @@
|
|
|
8
8
|
"declaration": true,
|
|
9
9
|
"declarationDir": "./lib/types"
|
|
10
10
|
},
|
|
11
|
-
"exclude": [
|
|
12
|
-
"node_modules",
|
|
13
|
-
"test",
|
|
14
|
-
"lib",
|
|
15
|
-
"benchmark",
|
|
16
|
-
"coverage",
|
|
17
|
-
"spec",
|
|
18
|
-
"**/*.benchmark.ts",
|
|
19
|
-
"**/*.spec.ts",
|
|
20
|
-
"keys",
|
|
21
|
-
"jest.config.js"
|
|
22
|
-
]
|
|
11
|
+
"exclude": ["node_modules", "test", "lib", "benchmark", "coverage", "spec", "**/*.benchmark.ts", "**/*.spec.ts", "keys", "jest.config.js"]
|
|
23
12
|
}
|