@tsed/platform-serverless 6.88.1 → 6.92.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.
Files changed (65) hide show
  1. package/jest.config.js +2 -2
  2. package/lib/{builder → cjs/builder}/PlatformServerless.d.ts +0 -0
  3. package/lib/cjs/builder/PlatformServerless.js +156 -0
  4. package/lib/cjs/builder/PlatformServerless.js.map +1 -0
  5. package/lib/{builder → cjs/builder}/PlatformServerlessHandler.d.ts +0 -0
  6. package/lib/cjs/builder/PlatformServerlessHandler.js +93 -0
  7. package/lib/cjs/builder/PlatformServerlessHandler.js.map +1 -0
  8. package/lib/{domain → cjs/domain}/ServerlessContext.d.ts +0 -0
  9. package/lib/cjs/domain/ServerlessContext.js +26 -0
  10. package/lib/cjs/domain/ServerlessContext.js.map +1 -0
  11. package/lib/{domain → cjs/domain}/ServerlessRequest.d.ts +0 -0
  12. package/lib/cjs/domain/ServerlessRequest.js +80 -0
  13. package/lib/cjs/domain/ServerlessRequest.js.map +1 -0
  14. package/lib/{domain → cjs/domain}/ServerlessResponse.d.ts +0 -0
  15. package/lib/cjs/domain/ServerlessResponse.js +193 -0
  16. package/lib/cjs/domain/ServerlessResponse.js.map +1 -0
  17. package/lib/{index.d.ts → cjs/index.d.ts} +0 -1
  18. package/lib/cjs/index.js +22 -0
  19. package/lib/cjs/index.js.map +1 -0
  20. package/lib/{utils → cjs/utils}/getRequestId.d.ts +0 -0
  21. package/lib/cjs/utils/getRequestId.js +13 -0
  22. package/lib/cjs/utils/getRequestId.js.map +1 -0
  23. package/lib/{utils → cjs/utils}/setResponseHeaders.d.ts +0 -0
  24. package/lib/cjs/utils/setResponseHeaders.js +35 -0
  25. package/lib/cjs/utils/setResponseHeaders.js.map +1 -0
  26. package/lib/esm/builder/PlatformServerless.js +133 -0
  27. package/lib/esm/builder/PlatformServerless.js.map +1 -0
  28. package/lib/esm/builder/PlatformServerlessHandler.js +90 -0
  29. package/lib/esm/builder/PlatformServerlessHandler.js.map +1 -0
  30. package/lib/esm/domain/ServerlessContext.js +22 -0
  31. package/lib/esm/domain/ServerlessContext.js.map +1 -0
  32. package/lib/esm/domain/ServerlessRequest.js +76 -0
  33. package/lib/esm/domain/ServerlessRequest.js.map +1 -0
  34. package/lib/esm/domain/ServerlessResponse.js +189 -0
  35. package/lib/esm/domain/ServerlessResponse.js.map +1 -0
  36. package/lib/esm/index.js +10 -0
  37. package/lib/esm/index.js.map +1 -0
  38. package/lib/esm/utils/getRequestId.js +9 -0
  39. package/lib/esm/utils/getRequestId.js.map +1 -0
  40. package/lib/esm/utils/setResponseHeaders.js +31 -0
  41. package/lib/esm/utils/setResponseHeaders.js.map +1 -0
  42. package/lib/types/builder/PlatformServerless.d.ts +31 -0
  43. package/lib/types/builder/PlatformServerlessHandler.d.ts +19 -0
  44. package/lib/types/domain/ServerlessContext.d.ts +19 -0
  45. package/lib/types/domain/ServerlessRequest.d.ts +55 -0
  46. package/lib/types/domain/ServerlessResponse.d.ts +105 -0
  47. package/lib/types/index.d.ts +8 -0
  48. package/lib/types/utils/getRequestId.d.ts +2 -0
  49. package/lib/types/utils/setResponseHeaders.d.ts +5 -0
  50. package/package.json +18 -13
  51. package/readme.md +184 -20
  52. package/tsconfig.compile.esm.json +23 -0
  53. package/lib/index-a6c91998.js +0 -955
  54. package/lib/index-a6c91998.js.map +0 -1
  55. package/lib/index-a7574150.js +0 -975
  56. package/lib/index-a7574150.js.map +0 -1
  57. package/lib/index-b255dcf0.js +0 -2350
  58. package/lib/index-b255dcf0.js.map +0 -1
  59. package/lib/index-eeb85309.js +0 -2354
  60. package/lib/index-eeb85309.js.map +0 -1
  61. package/lib/index.js +0 -90
  62. package/lib/index.js.map +0 -1
  63. package/lib/index.modern.js +0 -12
  64. package/lib/index.modern.js.map +0 -1
  65. package/lib/services/PlatformServerlessTest.d.ts +0 -46
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ServerlessResponse.js","sourceRoot":"","sources":["../../../src/domain/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;QACJ,OAAO,uBAAA,IAAI,yCAAe,CAAC;IAC7B,CAAC;IAED,KAAK,CAAC,EAAY;QAChB,uBAAA,IAAI,wCAAc,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAE5B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO;QACL,uBAAA,IAAI,wCAAc,CAAC,OAAO,CAAC,CAAC,EAAY,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QACnD,uBAAA,IAAI,qCAAkB,IAAI,MAAA,CAAC;IAC7B,CAAC;CACF","sourcesContent":["import {getValue} from \"@tsed/core\";\nimport {getStatusMessage} from \"@tsed/schema\";\nimport type {APIGatewayEventDefaultAuthorizerContext, APIGatewayProxyEventBase, Context} from \"aws-lambda\";\nimport encodeUrl from \"encodeurl\";\nimport * as mime from \"mime\";\nimport type {ServerlessRequest} from \"./ServerlessRequest\";\n\nexport interface ServerlessResponseOptions {\n event: APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;\n context: Context;\n request: ServerlessRequest;\n}\n\nexport type HeaderValue = boolean | number | string;\n\n/**\n * @platform\n */\nexport class ServerlessResponse {\n readonly event: APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;\n readonly request: ServerlessRequest;\n\n #status: number = 200;\n #body: any = undefined;\n #headers: Record<string, HeaderValue> = {};\n #locals: Record<string, any> = {};\n #isHeadersSent = false;\n #endListeners: Function[] = [];\n\n constructor({event, request}: ServerlessResponseOptions) {\n this.event = event;\n this.request = request;\n }\n\n /**\n * Get the current statusCode\n */\n get statusCode() {\n return this.#status;\n }\n\n set statusCode(status) {\n this.#status = status;\n }\n\n /**\n * An object that contains response local variables scoped to the request, and therefore available only to the view(s) rendered during that request / response cycle (if any). Otherwise, this property is identical to app.locals.\n *\n * This property is useful for exposing request-level information such as the request path name, authenticated user, user settings, and so on.\n */\n get locals() {\n return this.#locals;\n }\n\n get isHeadersSent() {\n return this.#isHeadersSent;\n }\n\n getStatus() {\n return this.#status;\n }\n\n /**\n * Sets the HTTP status for the response.\n *\n * @param status\n */\n status(status: number) {\n this.#status = status;\n return this;\n }\n\n set(name: string, value: any) {\n return this.setHeader(name, value);\n }\n\n /**\n * Returns the HTTP response header specified by field. The match is case-insensitive.\n *\n * ```typescript\n * response.get('Content-Type') // => \"text/plain\"\n * ```\n *\n * @param name\n */\n get(name: string): string | number | boolean | undefined {\n return getValue(this.#headers, name.toLowerCase());\n }\n\n getHeaders(): Record<string, HeaderValue> {\n return {\n ...this.#headers\n };\n }\n\n hasStatus() {\n return this.#status !== 200;\n }\n\n /**\n * Set header `field` to `val`, or pass\n * an object of header fields.\n *\n * Examples:\n * ```typescript\n * response.setHeaders({ Accept: 'text/plain', 'X-API-Key': 'tobi' });\n * ```\n *\n * Aliased as `res.header()`.\n */\n setHeaders(headers: Record<string, HeaderValue>) {\n // apply headers\n Object.entries(headers).forEach(([key, item]) => {\n this.setHeader(key, item);\n });\n\n return this;\n }\n\n setHeader(key: string, item: HeaderValue | null | undefined) {\n if (item !== null && item !== undefined) {\n key = key.toLowerCase();\n\n if (key === \"location\") {\n // \"back\" is an alias for the referrer\n if (item === \"back\") {\n item = this.request.get(\"Referrer\") || \"/\";\n }\n\n item = encodeUrl(String(item));\n }\n\n this.#headers = {\n ...this.#headers,\n [key.toLowerCase()]: item as any\n };\n }\n\n return this;\n }\n\n /**\n * Set `Content-Type` response header with `type` through `mime.lookup()`\n * when it does not contain \"/\", or set the Content-Type to `type` otherwise.\n *\n * Examples:\n *\n * res.type('.html');\n * res.type('html');\n * res.type('json');\n * res.type('application/json');\n * res.type('png');\n */\n contentType(contentType: string) {\n this.setHeader(\"Content-Type\", mime.getType(contentType));\n\n return this;\n }\n\n contentLength(length: number) {\n this.setHeader(\"Content-Length\", length);\n return this;\n }\n\n getContentLength() {\n if (this.get(\"Content-Length\")) {\n return parseInt(this.get(\"Content-Length\") as any, 10) || 0;\n }\n }\n\n getContentType() {\n return String(this.get(\"Content-Type\") || \"\").split(\";\")[0];\n }\n\n /**\n * Redirects to the URL derived from the specified path, with specified status, a positive integer that corresponds to an [HTTP status code](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html).\n * If not specified, status defaults to `302 Found`.\n *\n * @param status\n * @param url\n */\n redirect(status: number, url: string) {\n // Set location header\n const address = this.location(url).get(\"Location\");\n const body = `${getStatusMessage(status)}. Redirecting to ${address}`;\n\n this.status(status).set(\"Content-Length\", Buffer.byteLength(body)).body(body);\n\n return this;\n }\n\n /**\n * Sets the response Location HTTP header to the specified path parameter.\n *\n * @param url\n */\n location(url: string) {\n return this.set(\"Location\", url);\n }\n\n /**\n * Send any data to your consumer.\n *\n * This method accept a ReadableStream, a plain object, boolean, string, number, null and undefined data.\n * It choose the better way to send the data.\n *\n * @param body\n */\n body(body: any) {\n this.#body = body;\n\n return this;\n }\n\n getBody() {\n return this.#body;\n }\n\n isDone(): boolean {\n return this.#isHeadersSent;\n }\n\n onEnd(cb: Function) {\n this.#endListeners.push(cb);\n\n return this;\n }\n\n destroy() {\n this.#endListeners.forEach((cb: Function) => cb());\n this.#isHeadersSent = true;\n }\n}\n"]}
@@ -0,0 +1,10 @@
1
+ export * from "@tsed/di";
2
+ export { Get, Post, Put, Delete, Head, Patch, Options, Route as Lambda } from "@tsed/schema";
3
+ export * from "@tsed/platform-params";
4
+ export * from "./builder/PlatformServerlessHandler";
5
+ export * from "./builder/PlatformServerless";
6
+ // decorators
7
+ export * from "./domain/ServerlessContext";
8
+ export * from "./domain/ServerlessResponse";
9
+ export * from "./domain/ServerlessResponse";
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.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;AAEtC,cAAc,qCAAqC,CAAC;AACpD,cAAc,8BAA8B,CAAC;AAE7C,aAAa;AACb,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,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\nexport * from \"./builder/PlatformServerlessHandler\";\nexport * from \"./builder/PlatformServerless\";\n\n// decorators\nexport * from \"./domain/ServerlessContext\";\nexport * from \"./domain/ServerlessResponse\";\nexport * from \"./domain/ServerlessResponse\";\n"]}
@@ -0,0 +1,9 @@
1
+ import { v4 } from "uuid";
2
+ export function getRequestId(event, context) {
3
+ var _a;
4
+ if ((event === null || event === void 0 ? void 0 : event.headers) && event.headers["x-request-id"]) {
5
+ return event.headers["x-request-id"];
6
+ }
7
+ return ((_a = event === null || event === void 0 ? void 0 : event.requestContext) === null || _a === void 0 ? void 0 : _a.requestId) || (context === null || context === void 0 ? void 0 : context.awsRequestId) || v4().replace(/-/gi, "");
8
+ }
9
+ //# sourceMappingURL=getRequestId.js.map
@@ -0,0 +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;;IACrH,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,KAAI,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE;QACnD,OAAO,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;KACtC;IAED,OAAO,CAAA,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,cAAc,0CAAE,SAAS,MAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,YAAY,CAAA,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"]}
@@ -0,0 +1,31 @@
1
+ function mergeHeaders(specHeaders, headers) {
2
+ return Object.entries(specHeaders).reduce((headers, [key, item]) => {
3
+ key = key.toLowerCase();
4
+ return {
5
+ ...headers,
6
+ [key]: headers[key] === undefined ? String(item.example) : headers[key]
7
+ };
8
+ }, headers);
9
+ }
10
+ /**
11
+ * @ignore
12
+ */
13
+ export function setResponseHeaders(ctx) {
14
+ const { response, endpoint } = ctx;
15
+ const operation = endpoint.operation;
16
+ if (response.isDone()) {
17
+ return;
18
+ }
19
+ if (!response.hasStatus()) {
20
+ // apply status only if the isn't already modified
21
+ response.status(operation.getStatus());
22
+ }
23
+ const statusCode = response.statusCode;
24
+ const headers = operation.getHeadersOf(response.statusCode);
25
+ const mergedHeaders = mergeHeaders(headers, response.getHeaders());
26
+ response.setHeaders(mergedHeaders);
27
+ if (operation.isRedirection(statusCode)) {
28
+ response.redirect(statusCode, String(mergedHeaders["location"]));
29
+ }
30
+ }
31
+ //# sourceMappingURL=setResponseHeaders.js.map
@@ -0,0 +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,QAAQ,CAAC,MAAM,EAAE,EAAE;QACrB,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 (response.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"]}
@@ -0,0 +1,31 @@
1
+ import { Type } from "@tsed/core";
2
+ import { InjectorService } from "@tsed/di";
3
+ import type { Instance } from "find-my-way";
4
+ import type { Handler } from "aws-lambda";
5
+ export interface PlatformServerlessSettings extends Partial<TsED.Configuration> {
6
+ lambda?: Type[];
7
+ }
8
+ /**
9
+ * @platform
10
+ */
11
+ export declare class PlatformServerless {
12
+ readonly name: string;
13
+ private _injector;
14
+ private _router;
15
+ private _promise;
16
+ get injector(): InjectorService;
17
+ get settings(): TsED.Configuration & import("@tsed/di").DIConfiguration;
18
+ get promise(): Promise<any>;
19
+ static bootstrap(settings?: Partial<TsED.Configuration> & {
20
+ lambda?: Type[];
21
+ }): PlatformServerless;
22
+ handler(): Handler;
23
+ callbacks(tokens?: Type | Type[], callbacks?: any): Record<string, Handler>;
24
+ ready(): Promise<void>;
25
+ stop(): Promise<void>;
26
+ init(): Promise<any>;
27
+ protected callback(token: Type<any>, propertyKey: string): Handler;
28
+ protected initRouter(): Promise<Instance<any>>;
29
+ protected createInjector(settings: any): this;
30
+ protected loadInjector(): Promise<void>;
31
+ }
@@ -0,0 +1,19 @@
1
+ import { InjectorService, TokenProvider } from "@tsed/di";
2
+ import { PlatformParams } from "@tsed/platform-params";
3
+ import type { PlatformExceptions } from "@tsed/platform-exceptions";
4
+ import { ServerlessContext } from "../domain/ServerlessContext";
5
+ export declare class PlatformServerlessHandler {
6
+ protected injector: InjectorService;
7
+ protected params: PlatformParams;
8
+ protected exceptionsManager: Promise<PlatformExceptions>;
9
+ createHandler(token: TokenProvider, propertyKey: string | symbol): ($ctx: ServerlessContext) => Promise<{
10
+ statusCode: number;
11
+ body: any;
12
+ headers: {
13
+ "x-request-id": string;
14
+ };
15
+ isBase64Encoded: boolean;
16
+ }>;
17
+ private flush;
18
+ private processResult;
19
+ }
@@ -0,0 +1,19 @@
1
+ import { DIContext, DIContextOptions } from "@tsed/di";
2
+ import { JsonEntityStore } from "@tsed/schema";
3
+ import { APIGatewayEventDefaultAuthorizerContext, APIGatewayProxyEventBase, Context } from "aws-lambda";
4
+ import { ServerlessRequest } from "./ServerlessRequest";
5
+ import { ServerlessResponse } from "./ServerlessResponse";
6
+ export interface ServerlessContextOptions extends DIContextOptions {
7
+ event: APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;
8
+ context: Context;
9
+ endpoint: JsonEntityStore;
10
+ }
11
+ export declare class ServerlessContext extends DIContext {
12
+ readonly response: ServerlessResponse;
13
+ readonly request: ServerlessRequest;
14
+ readonly context: Context;
15
+ readonly event: APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;
16
+ readonly endpoint: JsonEntityStore;
17
+ constructor({ event, context, endpoint, ...options }: ServerlessContextOptions);
18
+ destroy(): Promise<void>;
19
+ }
@@ -0,0 +1,55 @@
1
+ import type { APIGatewayEventDefaultAuthorizerContext, APIGatewayProxyEventBase, Context } from "aws-lambda";
2
+ export interface ServerlessRequestOptions {
3
+ event: APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;
4
+ context: Context;
5
+ }
6
+ /**
7
+ * @platform
8
+ */
9
+ export declare class ServerlessRequest {
10
+ readonly raw: APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;
11
+ constructor({ event }: ServerlessRequestOptions);
12
+ get secure(): boolean;
13
+ get host(): string;
14
+ get protocol(): string;
15
+ /**
16
+ * Get the url of the request.
17
+ *
18
+ * Is equivalent of `express.response.originalUrl || express.response.url`.
19
+ */
20
+ get url(): string;
21
+ get headers(): import("aws-lambda").APIGatewayProxyEventHeaders;
22
+ get method(): string;
23
+ /**
24
+ * Contains key-value pairs of data submitted in the request body. By default, it is `undefined`, and is populated when you use
25
+ * `body-parsing` middleware such as `express.json()` or `express.urlencoded()`.
26
+ */
27
+ get body(): any;
28
+ get rawBody(): any;
29
+ /**
30
+ * This property is an object containing properties mapped to the named route `parameters`.
31
+ * For example, if you have the route `/user/:name`, then the `name` property is available as `req.params.name`.
32
+ * This object defaults to `{}`.
33
+ */
34
+ get params(): {
35
+ [key: string]: any;
36
+ };
37
+ /**
38
+ * This property is an object containing a property for each query string parameter in the route.
39
+ * When query parser is set to disabled, it is an empty object `{}`, otherwise it is the result of the configured query parser.
40
+ */
41
+ get query(): {
42
+ [key: string]: any;
43
+ };
44
+ /**
45
+ * Returns the HTTP request header specified by field. The match is case-insensitive.
46
+ *
47
+ * ```typescript
48
+ * request.get('Content-Type') // => "text/plain"
49
+ * ```
50
+ *
51
+ * @param name
52
+ */
53
+ get(name: string): any;
54
+ destroy(): void;
55
+ }
@@ -0,0 +1,105 @@
1
+ import type { APIGatewayEventDefaultAuthorizerContext, APIGatewayProxyEventBase, Context } from "aws-lambda";
2
+ import type { ServerlessRequest } from "./ServerlessRequest";
3
+ export interface ServerlessResponseOptions {
4
+ event: APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;
5
+ context: Context;
6
+ request: ServerlessRequest;
7
+ }
8
+ export declare type HeaderValue = boolean | number | string;
9
+ /**
10
+ * @platform
11
+ */
12
+ export declare class ServerlessResponse {
13
+ #private;
14
+ readonly event: APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;
15
+ readonly request: ServerlessRequest;
16
+ constructor({ event, request }: ServerlessResponseOptions);
17
+ /**
18
+ * Get the current statusCode
19
+ */
20
+ get statusCode(): number;
21
+ set statusCode(status: number);
22
+ /**
23
+ * An object that contains response local variables scoped to the request, and therefore available only to the view(s) rendered during that request / response cycle (if any). Otherwise, this property is identical to app.locals.
24
+ *
25
+ * This property is useful for exposing request-level information such as the request path name, authenticated user, user settings, and so on.
26
+ */
27
+ get locals(): Record<string, any>;
28
+ get isHeadersSent(): boolean;
29
+ getStatus(): number;
30
+ /**
31
+ * Sets the HTTP status for the response.
32
+ *
33
+ * @param status
34
+ */
35
+ status(status: number): this;
36
+ set(name: string, value: any): this;
37
+ /**
38
+ * Returns the HTTP response header specified by field. The match is case-insensitive.
39
+ *
40
+ * ```typescript
41
+ * response.get('Content-Type') // => "text/plain"
42
+ * ```
43
+ *
44
+ * @param name
45
+ */
46
+ get(name: string): string | number | boolean | undefined;
47
+ getHeaders(): Record<string, HeaderValue>;
48
+ hasStatus(): boolean;
49
+ /**
50
+ * Set header `field` to `val`, or pass
51
+ * an object of header fields.
52
+ *
53
+ * Examples:
54
+ * ```typescript
55
+ * response.setHeaders({ Accept: 'text/plain', 'X-API-Key': 'tobi' });
56
+ * ```
57
+ *
58
+ * Aliased as `res.header()`.
59
+ */
60
+ setHeaders(headers: Record<string, HeaderValue>): this;
61
+ setHeader(key: string, item: HeaderValue | null | undefined): this;
62
+ /**
63
+ * Set `Content-Type` response header with `type` through `mime.lookup()`
64
+ * when it does not contain "/", or set the Content-Type to `type` otherwise.
65
+ *
66
+ * Examples:
67
+ *
68
+ * res.type('.html');
69
+ * res.type('html');
70
+ * res.type('json');
71
+ * res.type('application/json');
72
+ * res.type('png');
73
+ */
74
+ contentType(contentType: string): this;
75
+ contentLength(length: number): this;
76
+ getContentLength(): number | undefined;
77
+ getContentType(): string;
78
+ /**
79
+ * Redirects to the URL derived from the specified path, with specified status, a positive integer that corresponds to an [HTTP status code](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html).
80
+ * If not specified, status defaults to `302 Found`.
81
+ *
82
+ * @param status
83
+ * @param url
84
+ */
85
+ redirect(status: number, url: string): this;
86
+ /**
87
+ * Sets the response Location HTTP header to the specified path parameter.
88
+ *
89
+ * @param url
90
+ */
91
+ location(url: string): this;
92
+ /**
93
+ * Send any data to your consumer.
94
+ *
95
+ * This method accept a ReadableStream, a plain object, boolean, string, number, null and undefined data.
96
+ * It choose the better way to send the data.
97
+ *
98
+ * @param body
99
+ */
100
+ body(body: any): this;
101
+ getBody(): any;
102
+ isDone(): boolean;
103
+ onEnd(cb: Function): this;
104
+ destroy(): void;
105
+ }
@@ -0,0 +1,8 @@
1
+ export * from "@tsed/di";
2
+ export { Get, Post, Put, Delete, Head, Patch, Options, Route as Lambda } from "@tsed/schema";
3
+ export * from "@tsed/platform-params";
4
+ export * from "./builder/PlatformServerlessHandler";
5
+ export * from "./builder/PlatformServerless";
6
+ export * from "./domain/ServerlessContext";
7
+ export * from "./domain/ServerlessResponse";
8
+ export * from "./domain/ServerlessResponse";
@@ -0,0 +1,2 @@
1
+ import { APIGatewayEventDefaultAuthorizerContext, APIGatewayProxyEventBase, Context } from "aws-lambda";
2
+ export declare function getRequestId(event: APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>, context: Context): string;
@@ -0,0 +1,5 @@
1
+ import { ServerlessContext } from "../domain/ServerlessContext";
2
+ /**
3
+ * @ignore
4
+ */
5
+ export declare function setResponseHeaders(ctx: ServerlessContext): void;
package/package.json CHANGED
@@ -1,34 +1,39 @@
1
1
  {
2
2
  "name": "@tsed/platform-serverless",
3
- "version": "6.88.1",
3
+ "version": "6.92.0",
4
4
  "description": "Platform serverless module for Ts.ED Framework",
5
5
  "private": false,
6
6
  "source": "./src/index.ts",
7
- "main": "./lib/index.js",
8
- "typings": "./lib/index.d.ts",
7
+ "main": "./lib/cjs/index.js",
8
+ "typings": "./lib/types/index.d.ts",
9
9
  "exports": {
10
- "require": "./lib/index.js",
11
- "default": "./lib/index.modern.js"
10
+ "types": "./lib/types/index.d.ts",
11
+ "import": "./lib/esm/index.js",
12
+ "require": "./lib/cjs/index.js",
13
+ "default": "./lib/esm/index.js"
12
14
  },
13
15
  "scripts": {
14
- "build": "microbundle --target node --no-compress --format modern,cjs --tsconfig ./tsconfig.compile.json",
16
+ "build": "yarn run build:esm && yarn run build:cjs",
17
+ "build:cjs": "tsc --build tsconfig.compile.json",
18
+ "build:esm": "tsc --build tsconfig.compile.esm.json",
15
19
  "test": "cross-env NODE_ENV=test jest"
16
20
  },
17
21
  "dependencies": {
18
- "@tsed/core": "6.88.1",
19
- "@tsed/di": "6.88.1",
20
- "@tsed/exceptions": "6.88.1",
21
- "@tsed/json-mapper": "6.88.1",
22
+ "@tsed/core": "6.92.0",
23
+ "@tsed/di": "6.92.0",
24
+ "@tsed/exceptions": "6.92.0",
25
+ "@tsed/json-mapper": "6.92.0",
22
26
  "@tsed/logger": "^6.0.0",
23
- "@tsed/platform-exceptions": "6.88.1",
24
- "@tsed/platform-params": "6.88.1",
25
- "@tsed/schema": "6.88.1",
27
+ "@tsed/platform-exceptions": "6.92.0",
28
+ "@tsed/platform-params": "6.92.0",
29
+ "@tsed/schema": "6.92.0",
26
30
  "encodeurl": "^1.0.2",
27
31
  "mime": "^2.5.2",
28
32
  "tslib": "2.2.0",
29
33
  "uuid": "^8.3.2"
30
34
  },
31
35
  "devDependencies": {
36
+ "@tsed/platform-serverless-testing": "6.92.0",
32
37
  "@types/aws-lambda": "^8.10.83",
33
38
  "@types/encodeurl": "^1.0.0",
34
39
  "@types/mime": "^2.0.3"