@tsed/platform-serverless 7.0.0-beta.1 → 7.0.0-beta.12

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.
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformServerless.js","sourceRoot":"","sources":["../../../src/builder/PlatformServerless.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAqC;AACrC,iCAA0E;AAC1E,yCAA0C;AAC1C,yCAAkE;AAGlE,mEAA8D;AAC9D,2EAAsE;AACtE,wDAAmD;AAMnD;;GAEG;AACH,MAAa,kBAAkB;IAA/B;QACW,SAAI,GAAW,oBAAoB,CAAC;IA6J/C,CAAC;IAvJC,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;IAChC,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,WAA4D,EAAE;QAC7E,MAAM,QAAQ,GAAG,IAAI,kBAAkB,EAAE,CAAC;QAC1C,QAAQ,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;QAElC,OAAO,QAAQ,CAAC;IAClB,CAAC;IAEM,OA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AE,KAAK,CAAA,EAAE;YAC9E,aAAI,CAAC,IAAI,EAAE,CAAC;SACb;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAES,KAAK,CAAC,YAAY;QAC1B,MAAM,SAAS,GAAG,IAAA,oBAAe,GAAE,CAAC;QAEpC,IAAA,mBAAc,EAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAE9B,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAExC,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAEpC,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACzC,CAAC;CACF;AA9JD,gDA8JC","sourcesContent":["import {Env, Type} from \"@tsed/core\";\nimport {createContainer, InjectorService, setLoggerLevel} from \"@tsed/di\";\nimport {$log, Logger} from \"@tsed/logger\";\nimport {getOperationsRoutes, JsonEntityStore} from \"@tsed/schema\";\nimport type {HTTPMethod, Instance} from \"find-my-way\";\nimport type {APIGatewayProxyResult, Handler} from \"aws-lambda\";\nimport {ServerlessContext} from \"../domain/ServerlessContext\";\nimport {PlatformServerlessHandler} from \"./PlatformServerlessHandler\";\nimport {getRequestId} from \"../utils/getRequestId\";\n\nexport interface PlatformServerlessSettings extends Partial<TsED.Configuration> {\n lambda?: Type[];\n}\n\n/**\n * @platform\n */\nexport class PlatformServerless {\n readonly name: string = \"PlatformServerless\";\n\n private _injector: InjectorService;\n private _router: Instance<any>;\n private _promise: Promise<any>;\n\n get injector(): InjectorService {\n return this._injector;\n }\n\n get settings() {\n return this.injector.settings;\n }\n\n get promise() {\n return this._promise;\n }\n\n static bootstrap(settings: Partial<TsED.Configuration> & {lambda?: Type[]} = {}): PlatformServerless {\n const platform = new PlatformServerless();\n platform.createInjector(settings);\n\n return platform;\n }\n\n public handler(): Handler {\n return async (event, context) => {\n const [router] = await Promise.all([this.initRouter(), this.init()]);\n const result = router.find(event.httpMethod as any, event.path);\n\n if (result) {\n const {handler, params} = result;\n\n event.pathParameters = {\n ...(event.pathParameters || {}),\n ...params\n };\n\n return (handler as any)(event, context);\n }\n\n return {\n statusCode: 404,\n body: \"Not found\",\n headers: {\n \"x-request-id\": getRequestId(event, context)\n },\n isBase64Encoded: false\n };\n };\n }\n\n public callbacks(tokens: Type | Type[] = [], callbacks: any = {}): Record<string, Handler> {\n return this.settings\n .get<Type[]>(\"lambda\", [])\n .concat(tokens)\n .reduce((callbacks, token) => {\n const routes = getOperationsRoutes(token);\n\n return routes.reduce((callbacks, operationRoute) => {\n const {operationId, token, propertyName, method, url} = operationRoute;\n\n // istanbul ignore next\n if (method === \"USE\") {\n return callbacks;\n }\n\n const callback = this.callback(token, propertyName);\n\n this._router?.on(method as HTTPMethod, url as string, callback as any);\n\n return {\n ...callbacks,\n [operationId]: callback\n };\n }, callbacks);\n }, callbacks);\n }\n\n public async ready() {\n await this.injector.emit(\"$onReady\");\n }\n\n public async stop() {\n await this.injector.emit(\"$onDestroy\");\n return this.injector.destroy();\n }\n\n public async init() {\n if (!this._promise) {\n this._promise = this.loadInjector().then(() => this.ready());\n }\n\n return this._promise;\n }\n\n protected callback(token: Type<any>, propertyKey: string): Handler {\n const entity = JsonEntityStore.fromMethod(token, propertyKey);\n let handler: ($ctx: ServerlessContext) => Promise<APIGatewayProxyResult>;\n\n return async (event, context) => {\n await this.init();\n\n if (!handler) {\n const platformHandler = this.injector.get<PlatformServerlessHandler>(PlatformServerlessHandler)!;\n handler = await platformHandler.createHandler(token, propertyKey);\n }\n\n const $ctx = new ServerlessContext({\n event,\n context,\n id: getRequestId(event, context),\n logger: this.injector.logger as Logger,\n injector: this.injector,\n endpoint: entity\n });\n\n return handler($ctx);\n };\n }\n\n protected async initRouter() {\n if (!this._router) {\n const {default: FindMyMay} = await import(\"find-my-way\");\n\n this._router = FindMyMay({caseSensitive: false, ignoreTrailingSlash: true});\n\n this.callbacks();\n }\n\n return this._router;\n }\n\n protected createInjector(settings: any) {\n this._injector = new InjectorService();\n this.injector.logger = $log;\n this.injector.settings.set(settings);\n\n // istanbul ignore next\n if (this.injector.settings.get(\"env\") === Env.TEST && !settings?.logger?.level) {\n $log.stop();\n }\n\n return this;\n }\n\n protected async loadInjector() {\n const container = createContainer();\n\n setLoggerLevel(this.injector);\n\n await this.injector.emit(\"$beforeInit\");\n\n await this.injector.load(container);\n\n await this.injector.emit(\"$afterInit\");\n }\n}\n"]}
1
+ {"version":3,"file":"PlatformServerless.js","sourceRoot":"","sources":["../../../src/builder/PlatformServerless.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAqC;AACrC,iCAA0E;AAC1E,yCAA0C;AAC1C,yCAAkE;AAGlE,mEAA8D;AAC9D,2EAAsE;AACtE,wDAAmD;AAMnD;;GAEG;AACH,MAAa,kBAAkB;IAA/B;QACW,SAAI,GAAW,oBAAoB,CAAC;IA6J/C,CAAC;IAvJC,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;IAChC,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,WAA4D,EAAE;QAC7E,MAAM,QAAQ,GAAG,IAAI,kBAAkB,EAAE,CAAC;QAC1C,QAAQ,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;QAElC,OAAO,QAAQ,CAAC;IAClB,CAAC;IAEM,OAAO;QACZ,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;YAC9B,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;YACrE,MAAM,MAAM,GAAG,MAAM,CAAC,IAA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AAI,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAExC,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAEpC,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACzC,CAAC;CACF;AA9JD,gDA8JC","sourcesContent":["import {Env, Type} from \"@tsed/core\";\nimport {createContainer, InjectorService, setLoggerLevel} from \"@tsed/di\";\nimport {$log, Logger} from \"@tsed/logger\";\nimport {getOperationsRoutes, JsonEntityStore} from \"@tsed/schema\";\nimport type {HTTPMethod, Instance} from \"find-my-way\";\nimport type {APIGatewayProxyResult, Handler} from \"aws-lambda\";\nimport {ServerlessContext} from \"../domain/ServerlessContext\";\nimport {PlatformServerlessHandler} from \"./PlatformServerlessHandler\";\nimport {getRequestId} from \"../utils/getRequestId\";\n\nexport interface PlatformServerlessSettings extends Partial<TsED.Configuration> {\n lambda?: Type[];\n}\n\n/**\n * @platform\n */\nexport class PlatformServerless {\n readonly name: string = \"PlatformServerless\";\n\n private _injector: InjectorService;\n private _router: Instance<any>;\n private _promise: Promise<any>;\n\n get injector(): InjectorService {\n return this._injector;\n }\n\n get settings() {\n return this.injector.settings;\n }\n\n get promise() {\n return this._promise;\n }\n\n static bootstrap(settings: Partial<TsED.Configuration> & {lambda?: Type[]} = {}): PlatformServerless {\n const platform = new PlatformServerless();\n platform.createInjector(settings);\n\n return platform;\n }\n\n public handler(): Handler {\n return async (event, context) => {\n const [router] = await Promise.all([this.initRouter(), this.init()]);\n const result = router.find(event.httpMethod as any, event.path);\n\n if (result) {\n const {handler, params} = result;\n\n event.pathParameters = {\n ...(event.pathParameters || {}),\n ...params\n };\n\n return (handler as any)(event, context);\n }\n\n return {\n statusCode: 404,\n body: \"Not found\",\n headers: {\n \"x-request-id\": getRequestId(event, context)\n },\n isBase64Encoded: false\n };\n };\n }\n\n public callbacks(tokens: Type | Type[] = [], callbacks: any = {}): Record<string, Handler> {\n return this.settings\n .get<Type[]>(\"lambda\", [])\n .concat(tokens)\n .reduce((callbacks, token) => {\n const routes = getOperationsRoutes(token);\n\n return routes.reduce((callbacks, operationRoute) => {\n const {operationId, token, propertyName, method, url} = operationRoute;\n\n // istanbul ignore next\n if (method === \"USE\") {\n return callbacks;\n }\n\n const callback = this.callback(token, propertyName);\n\n this._router?.on(method as HTTPMethod, url as string, callback as any);\n\n return {\n ...callbacks,\n [operationId]: callback\n };\n }, callbacks);\n }, callbacks);\n }\n\n public async ready() {\n await this.injector.emit(\"$onReady\");\n }\n\n public async stop() {\n await this.injector.emit(\"$onDestroy\");\n return this.injector.destroy();\n }\n\n public async init() {\n if (!this._promise) {\n this._promise = this.loadInjector().then(() => this.ready());\n }\n\n return this._promise;\n }\n\n protected callback(token: Type<any>, propertyKey: string): Handler {\n const entity = JsonEntityStore.fromMethod(token, propertyKey);\n let handler: ($ctx: ServerlessContext) => Promise<APIGatewayProxyResult>;\n\n return async (event, context) => {\n await this.init();\n\n if (!handler) {\n const platformHandler = this.injector.get<PlatformServerlessHandler>(PlatformServerlessHandler)!;\n handler = await platformHandler.createHandler(token, propertyKey);\n }\n\n const $ctx = new ServerlessContext({\n event,\n context,\n id: getRequestId(event, context),\n logger: this.injector.logger as Logger,\n injector: this.injector,\n endpoint: entity\n });\n\n return handler($ctx);\n };\n }\n\n protected async initRouter() {\n if (!this._router) {\n const {default: FindMyMay} = await import(\"find-my-way\");\n\n this._router = FindMyMay({caseSensitive: false, ignoreTrailingSlash: true});\n\n this.callbacks();\n }\n\n return this._router;\n }\n\n protected createInjector(settings: any) {\n this._injector = new InjectorService();\n this.injector.logger = $log;\n this.injector.settings.set(settings);\n\n // istanbul ignore next\n if (this.injector.settings.get(\"env\") === Env.TEST && !settings?.logger?.level) {\n $log.stop();\n }\n\n return this;\n }\n\n protected async loadInjector() {\n const container = createContainer();\n\n setLoggerLevel(this.injector);\n\n await this.injector.emit(\"$beforeInit\");\n\n await this.injector.load(container);\n\n await this.injector.emit(\"$afterInit\");\n }\n}\n"]}
@@ -15,7 +15,7 @@ let PlatformServerlessHandler = class PlatformServerlessHandler {
15
15
  });
16
16
  return async ($ctx) => {
17
17
  await this.injector.emit("$onRequest", $ctx);
18
- await this.injector.runInContext($ctx, async () => {
18
+ await (0, di_1.runInContext)($ctx, async () => {
19
19
  try {
20
20
  const resolver = new core_1.AnyToPromise();
21
21
  const handler = await promisedHandler;
@@ -71,19 +71,19 @@ let PlatformServerlessHandler = class PlatformServerlessHandler {
71
71
  }
72
72
  }
73
73
  };
74
- (0, tslib_1.__decorate)([
74
+ tslib_1.__decorate([
75
75
  (0, di_1.Inject)(),
76
- (0, tslib_1.__metadata)("design:type", di_1.InjectorService)
76
+ tslib_1.__metadata("design:type", di_1.InjectorService)
77
77
  ], PlatformServerlessHandler.prototype, "injector", void 0);
78
- (0, tslib_1.__decorate)([
78
+ tslib_1.__decorate([
79
79
  (0, di_1.Inject)(),
80
- (0, tslib_1.__metadata)("design:type", platform_params_1.PlatformParams)
80
+ tslib_1.__metadata("design:type", platform_params_1.PlatformParams)
81
81
  ], PlatformServerlessHandler.prototype, "params", void 0);
82
- (0, tslib_1.__decorate)([
83
- (0, di_1.LazyInject)("PlatformExceptions", () => Promise.resolve().then(() => (0, tslib_1.__importStar)(require("@tsed/platform-exceptions")))),
84
- (0, tslib_1.__metadata)("design:type", Promise)
82
+ tslib_1.__decorate([
83
+ (0, di_1.LazyInject)("PlatformExceptions", () => Promise.resolve().then(() => tslib_1.__importStar(require("@tsed/platform-exceptions")))),
84
+ tslib_1.__metadata("design:type", Promise)
85
85
  ], PlatformServerlessHandler.prototype, "exceptionsManager", void 0);
86
- PlatformServerlessHandler = (0, tslib_1.__decorate)([
86
+ PlatformServerlessHandler = tslib_1.__decorate([
87
87
  (0, di_1.Injectable)({
88
88
  scope: di_1.ProviderScope.SINGLETON,
89
89
  imports: [platform_params_1.DeserializerPipe, platform_params_1.ValidationPipe]
@@ -1 +1 @@
1
- {"version":3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;gBACxB,IAAI,GAAG,IAAA,uBAAS,EAAC,IAAI,EAAE;oBACrB,GAAG,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC;oBAC9D,QAAQ,EAAE,IAAI;oBACd,QAAQ,EAAE,IAAI;iBACf,CAAC,CAAC;aACJ;YAED,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SAC1B;IACH,CAAC;CACF,CAAA;AAtFC;IADC,IAAA,WAAM,GAAE;2CACW,oBAAe;2DAAC;AAGpC;IADC,IAAA,WAAM,GAAE;2CACS,gCAAc;yDAAC;AAGjC;IADC,IAAA,eAAU,EAAC,oBAAoB,EAAE,GAAG,EAAE,gEAAQ,2BAA2B,GAAC,CAAC;;oEACnB;AAR9C,yBAAyB;IAJrC,IAAA,eAAU,EAAC;QACV,KAAK,EAAE,kBAAa,CAAC,SAAS;QAC9B,OAAO,EAAE,CAAC,kCAAgB,EAAE,gCAAc,CAAC;KAC5C,CAAC;GACW,yBAAyB,CAwFrC;AAxFY,8DAAyB","sourcesContent":["import {AnyPromiseResult, AnyToPromise, isSerializable} from \"@tsed/core\";\nimport {BaseContext, Inject, Injectable, InjectorService, LazyInject, ProviderScope, TokenProvider} from \"@tsed/di\";\nimport {serialize} from \"@tsed/json-mapper\";\nimport {DeserializerPipe, PlatformParams, ValidationPipe} from \"@tsed/platform-params\";\nimport type {PlatformExceptions} from \"@tsed/platform-exceptions\";\nimport {ServerlessContext} from \"../domain/ServerlessContext\";\nimport {setResponseHeaders} from \"../utils/setResponseHeaders\";\n\n@Injectable({\n scope: ProviderScope.SINGLETON,\n imports: [DeserializerPipe, ValidationPipe]\n})\nexport class PlatformServerlessHandler {\n @Inject()\n protected injector: InjectorService;\n\n @Inject()\n protected params: PlatformParams;\n\n @LazyInject(\"PlatformExceptions\", () => import(\"@tsed/platform-exceptions\"))\n protected exceptionsManager: Promise<PlatformExceptions>;\n\n createHandler(token: TokenProvider, propertyKey: string | symbol) {\n const promisedHandler = this.params.compileHandler({\n token,\n propertyKey\n });\n\n return async ($ctx: ServerlessContext) => {\n await this.injector.emit(\"$onRequest\", $ctx);\n\n await this.injector.runInContext($ctx, async () => {\n try {\n const resolver = new AnyToPromise();\n const handler = await promisedHandler;\n const result = await resolver.call(() => handler({$ctx}));\n\n this.processResult(result, $ctx);\n } catch (er) {\n $ctx.response.status(500).body(er);\n const exceptions = await this.exceptionsManager;\n\n await exceptions.catch(er, ($ctx as unknown) as BaseContext);\n }\n });\n\n await this.injector.emit(\"$onResponse\", $ctx);\n\n return this.flush($ctx);\n };\n }\n\n private flush($ctx: ServerlessContext) {\n setResponseHeaders($ctx);\n\n let body: any = $ctx.response.getBody();\n\n if (isSerializable(body)) {\n $ctx.response.set(\"content-type\", \"application/json\");\n body = JSON.stringify(body);\n }\n\n const response = {\n statusCode: $ctx.response.getStatus(),\n body: body === undefined ? \"\" : body,\n headers: {\n ...$ctx.response.getHeaders(),\n \"x-request-id\": $ctx.id\n },\n isBase64Encoded: false\n };\n\n $ctx.destroy();\n\n return response;\n }\n\n private processResult({status, headers, data}: AnyPromiseResult, $ctx: ServerlessContext) {\n if (status) {\n $ctx.response.status(status);\n }\n\n if (headers) {\n $ctx.response.setHeaders(headers);\n }\n\n if (data !== undefined) {\n data = $ctx.response.getStatus() !== 204 ? data : \"\";\n\n if (isSerializable(data)) {\n data = serialize(data, {\n ...$ctx.endpoint.getResponseOptions($ctx.response.getStatus()),\n useAlias: true,\n endpoint: true\n });\n }\n\n $ctx.response.body(data);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"PlatformServerlessHandler.js","sourceRoot":"","sources":["../../../src/builder/PlatformServerlessHandler.ts"],"names":[],"mappings":";;;;AAAA,qCAA0E;AAC1E,iCAAkI;AAClI,mDAA4C;AAC5C,2DAAuF;AAGvF,oEAA+D;AAM/D,IAAa,yBAAyB,GAAtC,MAAa,yBAAyB;IAUpC,aAAa,CAAC,KAA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AQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SAC1B;IACH,CAAC;CACF,CAAA;AAtFC;IADC,IAAA,WAAM,GAAE;sCACW,oBAAe;2DAAC;AAGpC;IADC,IAAA,WAAM,GAAE;sCACS,gCAAc;yDAAC;AAGjC;IADC,IAAA,eAAU,EAAC,oBAAoB,EAAE,GAAG,EAAE,2DAAQ,2BAA2B,GAAC,CAAC;;oEACnB;AAR9C,yBAAyB;IAJrC,IAAA,eAAU,EAAC;QACV,KAAK,EAAE,kBAAa,CAAC,SAAS;QAC9B,OAAO,EAAE,CAAC,kCAAgB,EAAE,gCAAc,CAAC;KAC5C,CAAC;GACW,yBAAyB,CAwFrC;AAxFY,8DAAyB","sourcesContent":["import {AnyPromiseResult, AnyToPromise, isSerializable} from \"@tsed/core\";\nimport {BaseContext, Inject, Injectable, InjectorService, LazyInject, ProviderScope, runInContext, TokenProvider} from \"@tsed/di\";\nimport {serialize} from \"@tsed/json-mapper\";\nimport {DeserializerPipe, PlatformParams, ValidationPipe} from \"@tsed/platform-params\";\nimport type {PlatformExceptions} from \"@tsed/platform-exceptions\";\nimport {ServerlessContext} from \"../domain/ServerlessContext\";\nimport {setResponseHeaders} from \"../utils/setResponseHeaders\";\n\n@Injectable({\n scope: ProviderScope.SINGLETON,\n imports: [DeserializerPipe, ValidationPipe]\n})\nexport class PlatformServerlessHandler {\n @Inject()\n protected injector: InjectorService;\n\n @Inject()\n protected params: PlatformParams;\n\n @LazyInject(\"PlatformExceptions\", () => import(\"@tsed/platform-exceptions\"))\n protected exceptionsManager: Promise<PlatformExceptions>;\n\n createHandler(token: TokenProvider, propertyKey: string | symbol) {\n const promisedHandler = this.params.compileHandler({\n token,\n propertyKey\n });\n\n return async ($ctx: ServerlessContext) => {\n await this.injector.emit(\"$onRequest\", $ctx);\n\n await runInContext($ctx as any, async () => {\n try {\n const resolver = new AnyToPromise();\n const handler = await promisedHandler;\n const result = await resolver.call(() => handler({$ctx}));\n\n this.processResult(result, $ctx);\n } catch (er) {\n $ctx.response.status(500).body(er);\n const exceptions = await this.exceptionsManager;\n\n await exceptions.catch(er, $ctx as unknown as BaseContext);\n }\n });\n\n await this.injector.emit(\"$onResponse\", $ctx);\n\n return this.flush($ctx);\n };\n }\n\n private flush($ctx: ServerlessContext) {\n setResponseHeaders($ctx);\n\n let body: any = $ctx.response.getBody();\n\n if (isSerializable(body)) {\n $ctx.response.set(\"content-type\", \"application/json\");\n body = JSON.stringify(body);\n }\n\n const response = {\n statusCode: $ctx.response.getStatus(),\n body: body === undefined ? \"\" : body,\n headers: {\n ...$ctx.response.getHeaders(),\n \"x-request-id\": $ctx.id\n },\n isBase64Encoded: false\n };\n\n $ctx.destroy();\n\n return response;\n }\n\n private processResult({status, headers, data}: AnyPromiseResult, $ctx: ServerlessContext) {\n if (status) {\n $ctx.response.status(status);\n }\n\n if (headers) {\n $ctx.response.setHeaders(headers);\n }\n\n if (data !== undefined) {\n data = $ctx.response.getStatus() !== 204 ? data : \"\";\n\n if (isSerializable(data)) {\n data = serialize(data, {\n ...$ctx.endpoint.getResponseOptions($ctx.response.getStatus()),\n useAlias: true,\n endpoint: true\n });\n }\n\n $ctx.response.body(data);\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ServerlessContext.js","sourceRoot":"","sources":["../../../src/domain/ServerlessContext.ts"],"names":[],"mappings":";;;AAAA,iCAAsE;AAGtE,2DAAsD;AACtD,6DAAwD;AAQxD,MAAa,iBAAkB,SAAQ,cAAS;IAO9C,YAAY,EAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,OAAO,EAA2B;QAC1E,KAAK,CAAC;YACJ,GAAG,OAAO;YACV,YAAY,EAAE,CAAC;SAChB,CAAC,CAAC;QACH,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,OAAO,GAAG,IAAI,qCAAiB,CAAC,EAAC,KAAK,EAAE,OAAO,EAAC,CAAC,CAAC;QACvD,IAAI,CAAC,QAAQ,GAAG,IAAI,uCAAkB,CAAC,EAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAC,CAAC,CAAC;QAChF,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;QAEtB,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QACvB,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IAC1B,CAAC;CACF;AAzBD,8CAyBC","sourcesContent":["import {DIContext, DIContextOptions, LocalsContainer} from \"@tsed/di\";\nimport {JsonEntityStore} from \"@tsed/schema\";\nimport {APIGatewayEventDefaultAuthorizerContext, APIGatewayProxyEventBase, Context} from \"aws-lambda\";\nimport {ServerlessRequest} from \"./ServerlessRequest\";\nimport {ServerlessResponse} from \"./ServerlessResponse\";\n\nexport interface ServerlessContextOptions extends DIContextOptions {\n event: APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;\n context: Context;\n endpoint: JsonEntityStore;\n}\n\nexport class ServerlessContext extends DIContext {\n readonly response: ServerlessResponse;\n readonly request: ServerlessRequest;\n readonly context: Context;\n readonly event: APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;\n readonly endpoint: JsonEntityStore;\n\n constructor({event, context, endpoint, ...options}: ServerlessContextOptions) {\n super({\n ...options,\n maxStackSize: 0\n });\n this.context = context;\n this.event = event;\n this.request = new ServerlessRequest({event, context});\n this.response = new ServerlessResponse({event, context, request: this.request});\n this.endpoint = endpoint;\n }\n\n async destroy() {\n await super.destroy();\n\n this.request.destroy();\n this.response.destroy();\n }\n}\n"]}
1
+ {"version":3,"file":"ServerlessContext.js","sourceRoot":"","sources":["../../../src/domain/ServerlessContext.ts"],"names":[],"mappings":";;;AAAA,iCAAqD;AAGrD,2DAAsD;AACtD,6DAAwD;AAQxD,MAAa,iBAAkB,SAAQ,cAAS;IAO9C,YAAY,EAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,OAAO,EAA2B;QAC1E,KAAK,CAAC;YACJ,GAAG,OAAO;YACV,YAAY,EAAE,CAAC;SAChB,CAAC,CAAC;QACH,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,OAAO,GAAG,IAAI,qCAAiB,CAAC,EAAC,KAAK,EAAE,OAAO,EAAC,CAAC,CAAC;QACvD,IAAI,CAAC,QAAQ,GAAG,IAAI,uCAAkB,CAAC,EAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAC,CAAC,CAAC;QAChF,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;QAEtB,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QACvB,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IAC1B,CAAC;CACF;AAzBD,8CAyBC","sourcesContent":["import {DIContext, DIContextOptions} from \"@tsed/di\";\nimport {JsonEntityStore} from \"@tsed/schema\";\nimport {APIGatewayEventDefaultAuthorizerContext, APIGatewayProxyEventBase, Context} from \"aws-lambda\";\nimport {ServerlessRequest} from \"./ServerlessRequest\";\nimport {ServerlessResponse} from \"./ServerlessResponse\";\n\nexport interface ServerlessContextOptions extends DIContextOptions {\n event: APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;\n context: Context;\n endpoint: JsonEntityStore;\n}\n\nexport class ServerlessContext extends DIContext {\n readonly response: ServerlessResponse;\n readonly request: ServerlessRequest;\n readonly context: Context;\n readonly event: APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;\n readonly endpoint: JsonEntityStore;\n\n constructor({event, context, endpoint, ...options}: ServerlessContextOptions) {\n super({\n ...options,\n maxStackSize: 0\n });\n this.context = context;\n this.event = event;\n this.request = new ServerlessRequest({event, context});\n this.response = new ServerlessResponse({event, context, request: this.request});\n this.endpoint = endpoint;\n }\n\n async destroy() {\n await super.destroy();\n\n this.request.destroy();\n this.response.destroy();\n }\n}\n"]}
@@ -5,8 +5,8 @@ exports.ServerlessResponse = void 0;
5
5
  const tslib_1 = require("tslib");
6
6
  const core_1 = require("@tsed/core");
7
7
  const schema_1 = require("@tsed/schema");
8
- const encodeurl_1 = (0, tslib_1.__importDefault)(require("encodeurl"));
9
- const mime = (0, tslib_1.__importStar)(require("mime"));
8
+ const encodeurl_1 = tslib_1.__importDefault(require("encodeurl"));
9
+ const mime = tslib_1.__importStar(require("mime"));
10
10
  /**
11
11
  * @platform
12
12
  */
@@ -25,10 +25,10 @@ class ServerlessResponse {
25
25
  * Get the current statusCode
26
26
  */
27
27
  get statusCode() {
28
- return (0, tslib_1.__classPrivateFieldGet)(this, _ServerlessResponse_status, "f");
28
+ return tslib_1.__classPrivateFieldGet(this, _ServerlessResponse_status, "f");
29
29
  }
30
30
  set statusCode(status) {
31
- (0, tslib_1.__classPrivateFieldSet)(this, _ServerlessResponse_status, status, "f");
31
+ tslib_1.__classPrivateFieldSet(this, _ServerlessResponse_status, status, "f");
32
32
  }
33
33
  /**
34
34
  * 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.
@@ -36,13 +36,13 @@ class ServerlessResponse {
36
36
  * This property is useful for exposing request-level information such as the request path name, authenticated user, user settings, and so on.
37
37
  */
38
38
  get locals() {
39
- return (0, tslib_1.__classPrivateFieldGet)(this, _ServerlessResponse_locals, "f");
39
+ return tslib_1.__classPrivateFieldGet(this, _ServerlessResponse_locals, "f");
40
40
  }
41
41
  get isHeadersSent() {
42
- return (0, tslib_1.__classPrivateFieldGet)(this, _ServerlessResponse_isHeadersSent, "f");
42
+ return tslib_1.__classPrivateFieldGet(this, _ServerlessResponse_isHeadersSent, "f");
43
43
  }
44
44
  getStatus() {
45
- return (0, tslib_1.__classPrivateFieldGet)(this, _ServerlessResponse_status, "f");
45
+ return tslib_1.__classPrivateFieldGet(this, _ServerlessResponse_status, "f");
46
46
  }
47
47
  /**
48
48
  * Sets the HTTP status for the response.
@@ -50,7 +50,7 @@ class ServerlessResponse {
50
50
  * @param status
51
51
  */
52
52
  status(status) {
53
- (0, tslib_1.__classPrivateFieldSet)(this, _ServerlessResponse_status, status, "f");
53
+ tslib_1.__classPrivateFieldSet(this, _ServerlessResponse_status, status, "f");
54
54
  return this;
55
55
  }
56
56
  set(name, value) {
@@ -66,15 +66,15 @@ class ServerlessResponse {
66
66
  * @param name
67
67
  */
68
68
  get(name) {
69
- return (0, core_1.getValue)((0, tslib_1.__classPrivateFieldGet)(this, _ServerlessResponse_headers, "f"), name.toLowerCase());
69
+ return (0, core_1.getValue)(tslib_1.__classPrivateFieldGet(this, _ServerlessResponse_headers, "f"), name.toLowerCase());
70
70
  }
71
71
  getHeaders() {
72
72
  return {
73
- ...(0, tslib_1.__classPrivateFieldGet)(this, _ServerlessResponse_headers, "f")
73
+ ...tslib_1.__classPrivateFieldGet(this, _ServerlessResponse_headers, "f")
74
74
  };
75
75
  }
76
76
  hasStatus() {
77
- return (0, tslib_1.__classPrivateFieldGet)(this, _ServerlessResponse_status, "f") !== 200;
77
+ return tslib_1.__classPrivateFieldGet(this, _ServerlessResponse_status, "f") !== 200;
78
78
  }
79
79
  /**
80
80
  * Set header `field` to `val`, or pass
@@ -104,8 +104,8 @@ class ServerlessResponse {
104
104
  }
105
105
  item = (0, encodeurl_1.default)(String(item));
106
106
  }
107
- (0, tslib_1.__classPrivateFieldSet)(this, _ServerlessResponse_headers, {
108
- ...(0, tslib_1.__classPrivateFieldGet)(this, _ServerlessResponse_headers, "f"),
107
+ tslib_1.__classPrivateFieldSet(this, _ServerlessResponse_headers, {
108
+ ...tslib_1.__classPrivateFieldGet(this, _ServerlessResponse_headers, "f"),
109
109
  [key.toLowerCase()]: item
110
110
  }, "f");
111
111
  }
@@ -170,22 +170,22 @@ class ServerlessResponse {
170
170
  * @param body
171
171
  */
172
172
  body(body) {
173
- (0, tslib_1.__classPrivateFieldSet)(this, _ServerlessResponse_body, body, "f");
173
+ tslib_1.__classPrivateFieldSet(this, _ServerlessResponse_body, body, "f");
174
174
  return this;
175
175
  }
176
176
  getBody() {
177
- return (0, tslib_1.__classPrivateFieldGet)(this, _ServerlessResponse_body, "f");
177
+ return tslib_1.__classPrivateFieldGet(this, _ServerlessResponse_body, "f");
178
178
  }
179
179
  isDone() {
180
- return (0, tslib_1.__classPrivateFieldGet)(this, _ServerlessResponse_isHeadersSent, "f");
180
+ return tslib_1.__classPrivateFieldGet(this, _ServerlessResponse_isHeadersSent, "f");
181
181
  }
182
182
  onEnd(cb) {
183
- (0, tslib_1.__classPrivateFieldGet)(this, _ServerlessResponse_endListeners, "f").push(cb);
183
+ tslib_1.__classPrivateFieldGet(this, _ServerlessResponse_endListeners, "f").push(cb);
184
184
  return this;
185
185
  }
186
186
  destroy() {
187
- (0, tslib_1.__classPrivateFieldGet)(this, _ServerlessResponse_endListeners, "f").forEach((cb) => cb());
188
- (0, tslib_1.__classPrivateFieldSet)(this, _ServerlessResponse_isHeadersSent, true, "f");
187
+ tslib_1.__classPrivateFieldGet(this, _ServerlessResponse_endListeners, "f").forEach((cb) => cb());
188
+ tslib_1.__classPrivateFieldSet(this, _ServerlessResponse_isHeadersSent, true, "f");
189
189
  }
190
190
  }
191
191
  exports.ServerlessResponse = ServerlessResponse;
@@ -1 +1 @@
1
- {"version":3,"file":"ServerlessResponse.js","sourceRoot":"","sources":["../../../src/domain/ServerlessResponse.ts"],"names":[],"mappings":";;;;;AAAA,qCAAoC;AACpC,yCAA8C;AAE9C,uEAAkC;AAClC,wDAA6B;AAW7B;;GAEG;AACH,MAAa,kBAAkB;IAW7B,YAAY,EAAC,KAAK,EAAE,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AAE,EAAE,CAAC,CAAC;QACnD,oCAAA,IAAI,qCAAkB,IAAI,MAAA,CAAC;IAC7B,CAAC;CACF;AAtND,gDAsNC","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"]}
1
+ {"version":3,"file":"ServerlessResponse.js","sourceRoot":"","sources":["../../../src/domain/ServerlessResponse.ts"],"names":[],"mappings":";;;;;AAAA,qCAAoC;AACpC,yCAA8C;AAE9C,kEAAkC;AAClC,mDAA6B;AAW7B;;GAEG;AACH,MAAa,kBAAkB;IAW7B,YAAY,EAAC,KAAK,EAAE,OAAO,EAA4B;QAPvD,qCAAkB,GAAG,EAAC;QACtB,mCAAa,SAAS,EAAC;QACvB,sCAAwC,EAAE,EAAC;QAC3C,qCAA+B,EAAE,EAAC;QAClC,4CAAiB,KAAK,EAAC;QACvB,2CAA4B,EAAE,EAAC;QAG7B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,IAAI,UAAU;QACZ,OAAO,+BAAA,IAAI,kCAAQ,CAAC;IACtB,CAAC;IAED,IAAI,UAAU,CAAC,MAAM;QACnB,+BAAA,IAAI,8BAAW,MAAM,MAAA,CAAC;IACxB,CAAC;IAED;;;;OAIG;IACH,IAAI,MAAM;QACR,OAAO,+BAAA,IAAI,kCAAQ,CAAC;IACtB,CAAC;IAED,IAAI,aAAa;QACf,OAAO,+BAAA,IAAI,yCAAe,C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,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAE9E,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACH,QAAQ,CAAC,GAAW;QAClB,OAAO,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;IACnC,CAAC;IAED;;;;;;;OAOG;IACH,IAAI,CAAC,IAAS;QACZ,+BAAA,IAAI,4BAAS,IAAI,MAAA,CAAC;QAElB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO;QACL,OAAO,+BAAA,IAAI,gCAAM,CAAC;IACpB,CAAC;IAED,MAAM;QACJ,OAAO,+BAAA,IAAI,yCAAe,CAAC;IAC7B,CAAC;IAED,KAAK,CAAC,EAAY;QAChB,+BAAA,IAAI,wCAAc,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAE5B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO;QACL,+BAAA,IAAI,wCAAc,CAAC,OAAO,CAAC,CAAC,EAAY,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QACnD,+BAAA,IAAI,qCAAkB,IAAI,MAAA,CAAC;IAC7B,CAAC;CACF;AAtND,gDAsNC","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,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Lambda = exports.Options = exports.Patch = exports.Head = exports.Delete = exports.Put = exports.Post = exports.Get = void 0;
4
+ const tslib_1 = require("tslib");
5
+ tslib_1.__exportStar(require("@tsed/di"), exports);
6
+ var schema_1 = require("@tsed/schema");
7
+ Object.defineProperty(exports, "Get", { enumerable: true, get: function () { return schema_1.Get; } });
8
+ Object.defineProperty(exports, "Post", { enumerable: true, get: function () { return schema_1.Post; } });
9
+ Object.defineProperty(exports, "Put", { enumerable: true, get: function () { return schema_1.Put; } });
10
+ Object.defineProperty(exports, "Delete", { enumerable: true, get: function () { return schema_1.Delete; } });
11
+ Object.defineProperty(exports, "Head", { enumerable: true, get: function () { return schema_1.Head; } });
12
+ Object.defineProperty(exports, "Patch", { enumerable: true, get: function () { return schema_1.Patch; } });
13
+ Object.defineProperty(exports, "Options", { enumerable: true, get: function () { return schema_1.Options; } });
14
+ Object.defineProperty(exports, "Lambda", { enumerable: true, get: function () { return schema_1.Route; } });
15
+ tslib_1.__exportStar(require("@tsed/platform-params"), exports);
16
+ //# sourceMappingURL=exports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exports.js","sourceRoot":"","sources":["../../src/exports.ts"],"names":[],"mappings":";;;;AAAA,mDAAyB;AACzB,uCAA2F;AAAnF,6FAAA,GAAG,OAAA;AAAE,8FAAA,IAAI,OAAA;AAAE,6FAAA,GAAG,OAAA;AAAE,gGAAA,MAAM,OAAA;AAAE,8FAAA,IAAI,OAAA;AAAE,+FAAA,KAAK,OAAA;AAAE,iGAAA,OAAO,OAAA;AAAE,gGAAA,KAAK,OAAU;AACrE,gEAAsC","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/cjs/index.js CHANGED
@@ -1,22 +1,15 @@
1
1
  "use strict";
2
+ /**
3
+ * @file Automatically generated by barrelsby.
4
+ */
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Lambda = exports.Options = exports.Patch = exports.Head = exports.Delete = exports.Put = exports.Post = exports.Get = void 0;
4
6
  const tslib_1 = require("tslib");
5
- (0, tslib_1.__exportStar)(require("@tsed/di"), exports);
6
- var schema_1 = require("@tsed/schema");
7
- Object.defineProperty(exports, "Get", { enumerable: true, get: function () { return schema_1.Get; } });
8
- Object.defineProperty(exports, "Post", { enumerable: true, get: function () { return schema_1.Post; } });
9
- Object.defineProperty(exports, "Put", { enumerable: true, get: function () { return schema_1.Put; } });
10
- Object.defineProperty(exports, "Delete", { enumerable: true, get: function () { return schema_1.Delete; } });
11
- Object.defineProperty(exports, "Head", { enumerable: true, get: function () { return schema_1.Head; } });
12
- Object.defineProperty(exports, "Patch", { enumerable: true, get: function () { return schema_1.Patch; } });
13
- Object.defineProperty(exports, "Options", { enumerable: true, get: function () { return schema_1.Options; } });
14
- Object.defineProperty(exports, "Lambda", { enumerable: true, get: function () { return schema_1.Route; } });
15
- (0, tslib_1.__exportStar)(require("@tsed/platform-params"), exports);
16
- (0, tslib_1.__exportStar)(require("./builder/PlatformServerlessHandler"), exports);
17
- (0, tslib_1.__exportStar)(require("./builder/PlatformServerless"), exports);
18
- // decorators
19
- (0, tslib_1.__exportStar)(require("./domain/ServerlessContext"), exports);
20
- (0, tslib_1.__exportStar)(require("./domain/ServerlessResponse"), exports);
21
- (0, tslib_1.__exportStar)(require("./domain/ServerlessResponse"), exports);
7
+ tslib_1.__exportStar(require("./exports"), exports);
8
+ tslib_1.__exportStar(require("./builder/PlatformServerless"), exports);
9
+ tslib_1.__exportStar(require("./builder/PlatformServerlessHandler"), exports);
10
+ tslib_1.__exportStar(require("./domain/ServerlessContext"), exports);
11
+ tslib_1.__exportStar(require("./domain/ServerlessRequest"), exports);
12
+ tslib_1.__exportStar(require("./domain/ServerlessResponse"), exports);
13
+ tslib_1.__exportStar(require("./utils/getRequestId"), exports);
14
+ tslib_1.__exportStar(require("./utils/setResponseHeaders"), exports);
22
15
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAAA,wDAAyB;AACzB,uCAA2F;AAAnF,6FAAA,GAAG,OAAA;AAAE,8FAAA,IAAI,OAAA;AAAE,6FAAA,GAAG,OAAA;AAAE,gGAAA,MAAM,OAAA;AAAE,8FAAA,IAAI,OAAA;AAAE,+FAAA,KAAK,OAAA;AAAE,iGAAA,OAAO,OAAA;AAAE,gGAAA,KAAK,OAAU;AACrE,qEAAsC;AAEtC,mFAAoD;AACpD,4EAA6C;AAE7C,aAAa;AACb,0EAA2C;AAC3C,2EAA4C;AAC5C,2EAA4C","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"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,oDAA0B;AAC1B,uEAA6C;AAC7C,8EAAoD;AACpD,qEAA2C;AAC3C,qEAA2C;AAC3C,sEAA4C;AAC5C,+DAAqC;AACrC,qEAA2C","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"]}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -2,9 +2,9 @@ import { Env } from "@tsed/core";
2
2
  import { createContainer, InjectorService, setLoggerLevel } from "@tsed/di";
3
3
  import { $log } from "@tsed/logger";
4
4
  import { getOperationsRoutes, JsonEntityStore } from "@tsed/schema";
5
- import { ServerlessContext } from "../domain/ServerlessContext";
6
- import { PlatformServerlessHandler } from "./PlatformServerlessHandler";
7
- import { getRequestId } from "../utils/getRequestId";
5
+ import { ServerlessContext } from "../domain/ServerlessContext.js";
6
+ import { PlatformServerlessHandler } from "./PlatformServerlessHandler.js";
7
+ import { getRequestId } from "../utils/getRequestId.js";
8
8
  /**
9
9
  * @platform
10
10
  */
@@ -1,9 +1,9 @@
1
1
  import { __decorate, __metadata } from "tslib";
2
2
  import { AnyToPromise, isSerializable } from "@tsed/core";
3
- import { Inject, Injectable, InjectorService, LazyInject, ProviderScope } from "@tsed/di";
3
+ import { Inject, Injectable, InjectorService, LazyInject, ProviderScope, runInContext } from "@tsed/di";
4
4
  import { serialize } from "@tsed/json-mapper";
5
5
  import { DeserializerPipe, PlatformParams, ValidationPipe } from "@tsed/platform-params";
6
- import { setResponseHeaders } from "../utils/setResponseHeaders";
6
+ import { setResponseHeaders } from "../utils/setResponseHeaders.js";
7
7
  let PlatformServerlessHandler = class PlatformServerlessHandler {
8
8
  createHandler(token, propertyKey) {
9
9
  const promisedHandler = this.params.compileHandler({
@@ -12,7 +12,7 @@ let PlatformServerlessHandler = class PlatformServerlessHandler {
12
12
  });
13
13
  return async ($ctx) => {
14
14
  await this.injector.emit("$onRequest", $ctx);
15
- await this.injector.runInContext($ctx, async () => {
15
+ await runInContext($ctx, async () => {
16
16
  try {
17
17
  const resolver = new AnyToPromise();
18
18
  const handler = await promisedHandler;
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformServerlessHandler.js","sourceRoot":"","sources":["../../../src/builder/PlatformServerlessHandler.ts"],"names":[],"mappings":";AAAA,OAAO,EAAmB,YAAY,EAAE,cAAc,EAAC,MAAM,YAAY,CAAC;AAC1E,OAAO,EAAc,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,aAAa,EAAgB,MAAM,UAAU,CAAC;AACpH,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xB,IAAI,GAAG,SAAS,CAAC,IAAI,EAAE;oBACrB,GAAG,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC;oBAC9D,QAAQ,EAAE,IAAI;oBACd,QAAQ,EAAE,IAAI;iBACf,CAAC,CAAC;aACJ;YAED,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SAC1B;IACH,CAAC;CACF,CAAA;AAtFC;IADC,MAAM,EAAE;8BACW,eAAe;2DAAC;AAGpC;IADC,MAAM,EAAE;8BACS,cAAc;yDAAC;AAGjC;IADC,UAAU,CAAC,oBAAoB,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,2BAA2B,CAAC,CAAC;;oEACnB;AAR9C,yBAAyB;IAJrC,UAAU,CAAC;QACV,KAAK,EAAE,aAAa,CAAC,SAAS;QAC9B,OAAO,EAAE,CAAC,gBAAgB,EAAE,cAAc,CAAC;KAC5C,CAAC;GACW,yBAAyB,CAwFrC;SAxFY,yBAAyB","sourcesContent":["import {AnyPromiseResult, AnyToPromise, isSerializable} from \"@tsed/core\";\nimport {BaseContext, Inject, Injectable, InjectorService, LazyInject, ProviderScope, TokenProvider} from \"@tsed/di\";\nimport {serialize} from \"@tsed/json-mapper\";\nimport {DeserializerPipe, PlatformParams, ValidationPipe} from \"@tsed/platform-params\";\nimport type {PlatformExceptions} from \"@tsed/platform-exceptions\";\nimport {ServerlessContext} from \"../domain/ServerlessContext\";\nimport {setResponseHeaders} from \"../utils/setResponseHeaders\";\n\n@Injectable({\n scope: ProviderScope.SINGLETON,\n imports: [DeserializerPipe, ValidationPipe]\n})\nexport class PlatformServerlessHandler {\n @Inject()\n protected injector: InjectorService;\n\n @Inject()\n protected params: PlatformParams;\n\n @LazyInject(\"PlatformExceptions\", () => import(\"@tsed/platform-exceptions\"))\n protected exceptionsManager: Promise<PlatformExceptions>;\n\n createHandler(token: TokenProvider, propertyKey: string | symbol) {\n const promisedHandler = this.params.compileHandler({\n token,\n propertyKey\n });\n\n return async ($ctx: ServerlessContext) => {\n await this.injector.emit(\"$onRequest\", $ctx);\n\n await this.injector.runInContext($ctx, async () => {\n try {\n const resolver = new AnyToPromise();\n const handler = await promisedHandler;\n const result = await resolver.call(() => handler({$ctx}));\n\n this.processResult(result, $ctx);\n } catch (er) {\n $ctx.response.status(500).body(er);\n const exceptions = await this.exceptionsManager;\n\n await exceptions.catch(er, ($ctx as unknown) as BaseContext);\n }\n });\n\n await this.injector.emit(\"$onResponse\", $ctx);\n\n return this.flush($ctx);\n };\n }\n\n private flush($ctx: ServerlessContext) {\n setResponseHeaders($ctx);\n\n let body: any = $ctx.response.getBody();\n\n if (isSerializable(body)) {\n $ctx.response.set(\"content-type\", \"application/json\");\n body = JSON.stringify(body);\n }\n\n const response = {\n statusCode: $ctx.response.getStatus(),\n body: body === undefined ? \"\" : body,\n headers: {\n ...$ctx.response.getHeaders(),\n \"x-request-id\": $ctx.id\n },\n isBase64Encoded: false\n };\n\n $ctx.destroy();\n\n return response;\n }\n\n private processResult({status, headers, data}: AnyPromiseResult, $ctx: ServerlessContext) {\n if (status) {\n $ctx.response.status(status);\n }\n\n if (headers) {\n $ctx.response.setHeaders(headers);\n }\n\n if (data !== undefined) {\n data = $ctx.response.getStatus() !== 204 ? data : \"\";\n\n if (isSerializable(data)) {\n data = serialize(data, {\n ...$ctx.endpoint.getResponseOptions($ctx.response.getStatus()),\n useAlias: true,\n endpoint: true\n });\n }\n\n $ctx.response.body(data);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"PlatformServerlessHandler.js","sourceRoot":"","sources":["../../../src/builder/PlatformServerlessHandler.ts"],"names":[],"mappings":";AAAA,OAAO,EAAmB,YAAY,EAAE,cAAc,EAAC,MAAM,YAAY,CAAC;AAC1E,OAAO,EAAc,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,aAAa,EAAE,YAAY,EAAgB,MAAM,UAAU,CAAC;AAClI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AC,IAAI,EAAE;oBACrB,GAAG,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC;oBAC9D,QAAQ,EAAE,IAAI;oBACd,QAAQ,EAAE,IAAI;iBACf,CAAC,CAAC;aACJ;YAED,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SAC1B;IACH,CAAC;CACF,CAAA;AAtFC;IADC,MAAM,EAAE;8BACW,eAAe;2DAAC;AAGpC;IADC,MAAM,EAAE;8BACS,cAAc;yDAAC;AAGjC;IADC,UAAU,CAAC,oBAAoB,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,2BAA2B,CAAC,CAAC;;oEACnB;AAR9C,yBAAyB;IAJrC,UAAU,CAAC;QACV,KAAK,EAAE,aAAa,CAAC,SAAS;QAC9B,OAAO,EAAE,CAAC,gBAAgB,EAAE,cAAc,CAAC;KAC5C,CAAC;GACW,yBAAyB,CAwFrC;SAxFY,yBAAyB","sourcesContent":["import {AnyPromiseResult, AnyToPromise, isSerializable} from \"@tsed/core\";\nimport {BaseContext, Inject, Injectable, InjectorService, LazyInject, ProviderScope, runInContext, TokenProvider} from \"@tsed/di\";\nimport {serialize} from \"@tsed/json-mapper\";\nimport {DeserializerPipe, PlatformParams, ValidationPipe} from \"@tsed/platform-params\";\nimport type {PlatformExceptions} from \"@tsed/platform-exceptions\";\nimport {ServerlessContext} from \"../domain/ServerlessContext\";\nimport {setResponseHeaders} from \"../utils/setResponseHeaders\";\n\n@Injectable({\n scope: ProviderScope.SINGLETON,\n imports: [DeserializerPipe, ValidationPipe]\n})\nexport class PlatformServerlessHandler {\n @Inject()\n protected injector: InjectorService;\n\n @Inject()\n protected params: PlatformParams;\n\n @LazyInject(\"PlatformExceptions\", () => import(\"@tsed/platform-exceptions\"))\n protected exceptionsManager: Promise<PlatformExceptions>;\n\n createHandler(token: TokenProvider, propertyKey: string | symbol) {\n const promisedHandler = this.params.compileHandler({\n token,\n propertyKey\n });\n\n return async ($ctx: ServerlessContext) => {\n await this.injector.emit(\"$onRequest\", $ctx);\n\n await runInContext($ctx as any, async () => {\n try {\n const resolver = new AnyToPromise();\n const handler = await promisedHandler;\n const result = await resolver.call(() => handler({$ctx}));\n\n this.processResult(result, $ctx);\n } catch (er) {\n $ctx.response.status(500).body(er);\n const exceptions = await this.exceptionsManager;\n\n await exceptions.catch(er, $ctx as unknown as BaseContext);\n }\n });\n\n await this.injector.emit(\"$onResponse\", $ctx);\n\n return this.flush($ctx);\n };\n }\n\n private flush($ctx: ServerlessContext) {\n setResponseHeaders($ctx);\n\n let body: any = $ctx.response.getBody();\n\n if (isSerializable(body)) {\n $ctx.response.set(\"content-type\", \"application/json\");\n body = JSON.stringify(body);\n }\n\n const response = {\n statusCode: $ctx.response.getStatus(),\n body: body === undefined ? \"\" : body,\n headers: {\n ...$ctx.response.getHeaders(),\n \"x-request-id\": $ctx.id\n },\n isBase64Encoded: false\n };\n\n $ctx.destroy();\n\n return response;\n }\n\n private processResult({status, headers, data}: AnyPromiseResult, $ctx: ServerlessContext) {\n if (status) {\n $ctx.response.status(status);\n }\n\n if (headers) {\n $ctx.response.setHeaders(headers);\n }\n\n if (data !== undefined) {\n data = $ctx.response.getStatus() !== 204 ? data : \"\";\n\n if (isSerializable(data)) {\n data = serialize(data, {\n ...$ctx.endpoint.getResponseOptions($ctx.response.getStatus()),\n useAlias: true,\n endpoint: true\n });\n }\n\n $ctx.response.body(data);\n }\n }\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import { DIContext } from "@tsed/di";
2
- import { ServerlessRequest } from "./ServerlessRequest";
3
- import { ServerlessResponse } from "./ServerlessResponse";
2
+ import { ServerlessRequest } from "./ServerlessRequest.js";
3
+ import { ServerlessResponse } from "./ServerlessResponse.js";
4
4
  export class ServerlessContext extends DIContext {
5
5
  constructor({ event, context, endpoint, ...options }) {
6
6
  super({
@@ -1 +1 @@
1
- {"version":3,"file":"ServerlessContext.js","sourceRoot":"","sources":["../../../src/domain/ServerlessContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAoC,MAAM,UAAU,CAAC;AAGtE,OAAO,EAAC,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AAQxD,MAAM,OAAO,iBAAkB,SAAQ,SAAS;IAO9C,YAAY,EAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,OAAO,EAA2B;QAC1E,KAAK,CAAC;YACJ,GAAG,OAAO;YACV,YAAY,EAAE,CAAC;SAChB,CAAC,CAAC;QACH,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,OAAO,GAAG,IAAI,iBAAiB,CAAC,EAAC,KAAK,EAAE,OAAO,EAAC,CAAC,CAAC;QACvD,IAAI,CAAC,QAAQ,GAAG,IAAI,kBAAkB,CAAC,EAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAC,CAAC,CAAC;QAChF,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;QAEtB,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QACvB,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IAC1B,CAAC;CACF","sourcesContent":["import {DIContext, DIContextOptions, LocalsContainer} from \"@tsed/di\";\nimport {JsonEntityStore} from \"@tsed/schema\";\nimport {APIGatewayEventDefaultAuthorizerContext, APIGatewayProxyEventBase, Context} from \"aws-lambda\";\nimport {ServerlessRequest} from \"./ServerlessRequest\";\nimport {ServerlessResponse} from \"./ServerlessResponse\";\n\nexport interface ServerlessContextOptions extends DIContextOptions {\n event: APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;\n context: Context;\n endpoint: JsonEntityStore;\n}\n\nexport class ServerlessContext extends DIContext {\n readonly response: ServerlessResponse;\n readonly request: ServerlessRequest;\n readonly context: Context;\n readonly event: APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;\n readonly endpoint: JsonEntityStore;\n\n constructor({event, context, endpoint, ...options}: ServerlessContextOptions) {\n super({\n ...options,\n maxStackSize: 0\n });\n this.context = context;\n this.event = event;\n this.request = new ServerlessRequest({event, context});\n this.response = new ServerlessResponse({event, context, request: this.request});\n this.endpoint = endpoint;\n }\n\n async destroy() {\n await super.destroy();\n\n this.request.destroy();\n this.response.destroy();\n }\n}\n"]}
1
+ {"version":3,"file":"ServerlessContext.js","sourceRoot":"","sources":["../../../src/domain/ServerlessContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAmB,MAAM,UAAU,CAAC;AAGrD,OAAO,EAAC,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AAQxD,MAAM,OAAO,iBAAkB,SAAQ,SAAS;IAO9C,YAAY,EAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,OAAO,EAA2B;QAC1E,KAAK,CAAC;YACJ,GAAG,OAAO;YACV,YAAY,EAAE,CAAC;SAChB,CAAC,CAAC;QACH,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,OAAO,GAAG,IAAI,iBAAiB,CAAC,EAAC,KAAK,EAAE,OAAO,EAAC,CAAC,CAAC;QACvD,IAAI,CAAC,QAAQ,GAAG,IAAI,kBAAkB,CAAC,EAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAC,CAAC,CAAC;QAChF,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;QAEtB,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QACvB,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IAC1B,CAAC;CACF","sourcesContent":["import {DIContext, DIContextOptions} from \"@tsed/di\";\nimport {JsonEntityStore} from \"@tsed/schema\";\nimport {APIGatewayEventDefaultAuthorizerContext, APIGatewayProxyEventBase, Context} from \"aws-lambda\";\nimport {ServerlessRequest} from \"./ServerlessRequest\";\nimport {ServerlessResponse} from \"./ServerlessResponse\";\n\nexport interface ServerlessContextOptions extends DIContextOptions {\n event: APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;\n context: Context;\n endpoint: JsonEntityStore;\n}\n\nexport class ServerlessContext extends DIContext {\n readonly response: ServerlessResponse;\n readonly request: ServerlessRequest;\n readonly context: Context;\n readonly event: APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;\n readonly endpoint: JsonEntityStore;\n\n constructor({event, context, endpoint, ...options}: ServerlessContextOptions) {\n super({\n ...options,\n maxStackSize: 0\n });\n this.context = context;\n this.event = event;\n this.request = new ServerlessRequest({event, context});\n this.response = new ServerlessResponse({event, context, request: this.request});\n this.endpoint = endpoint;\n }\n\n async destroy() {\n await super.destroy();\n\n this.request.destroy();\n this.response.destroy();\n }\n}\n"]}
@@ -0,0 +1,4 @@
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
+ //# sourceMappingURL=exports.js.map
@@ -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
- 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";
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
@@ -1 +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"]}
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"]}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,3 @@
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";
@@ -1,8 +1,11 @@
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";
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 "./domain/ServerlessResponse";
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.1",
3
+ "version": "7.0.0-beta.12",
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,50 @@
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.1",
23
- "@tsed/di": "7.0.0-beta.1",
24
- "@tsed/exceptions": "7.0.0-beta.1",
25
- "@tsed/json-mapper": "7.0.0-beta.1",
26
- "@tsed/logger": "^6.0.0",
27
- "@tsed/platform-exceptions": "7.0.0-beta.1",
28
- "@tsed/platform-params": "7.0.0-beta.1",
29
- "@tsed/schema": "7.0.0-beta.1",
24
+ "@tsed/core": "7.0.0-beta.12",
25
+ "@tsed/exceptions": "7.0.0-beta.12",
26
+ "@tsed/json-mapper": "7.0.0-beta.12",
27
+ "@tsed/platform-exceptions": "7.0.0-beta.12",
28
+ "@tsed/platform-params": "7.0.0-beta.12",
29
+ "@tsed/schema": "7.0.0-beta.12",
30
30
  "encodeurl": "^1.0.2",
31
31
  "mime": "^2.5.2",
32
- "tslib": "2.2.0",
32
+ "tslib": "2.3.1",
33
33
  "uuid": "^8.3.2"
34
34
  },
35
35
  "devDependencies": {
36
- "@tsed/platform-serverless-testing": "7.0.0-beta.1",
36
+ "@tsed/platform-serverless-testing": "7.0.0-beta.12",
37
37
  "@types/aws-lambda": "^8.10.83",
38
38
  "@types/encodeurl": "^1.0.0",
39
39
  "@types/mime": "^2.0.3"
40
40
  },
41
- "peerDependencies": {},
41
+ "peerDependencies": {
42
+ "@tsed/di": "^7.0.0-beta.12",
43
+ "@tsed/logger": ">=6.1.1"
44
+ },
45
+ "peerDependenciesMeta": {
46
+ "@tsed/di": {
47
+ "optional": false
48
+ },
49
+ "@tsed/logger": {
50
+ "optional": false
51
+ }
52
+ },
42
53
  "repository": "https://github.com/tsedio/tsed",
43
54
  "bugs": {
44
55
  "url": "https://github.com/tsedio/tsed/issues"
45
56
  },
46
- "homepage": "https://github.com/tsedio/tsed/tree/alpha/packages/platform/platform-serverless",
57
+ "homepage": "https://github.com/tsedio/tsed/tree/beta/packages/platform/platform-serverless",
47
58
  "author": "Romain Lenzotti",
48
- "license": "MIT"
59
+ "license": "MIT",
60
+ "publishConfig": {
61
+ "tag": "beta"
62
+ }
49
63
  }
package/readme.md CHANGED
@@ -11,7 +11,8 @@
11
11
  [![npm version](https://badge.fury.io/js/%40tsed%2Fcommon.svg)](https://badge.fury.io/js/%40tsed%2Fcommon)
12
12
  [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
13
13
  [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
14
- [![backers](https://opencollective.com/tsed/tiers/badge.svg)](https://opencollective.com/tsed)
14
+ [![github](https://img.shields.io/static/v1?label=Github%20sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/romakita)
15
+ [![opencollective](https://img.shields.io/static/v1?label=OpenCollective%20sponsor&message=%E2%9D%A4&logo=OpenCollective&color=%23fe8e86)](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: '2'
180
+ frameworkVersion: "2"
180
181
 
181
182
  provider:
182
- name: aws
183
- runtime: nodejs14.x
184
- lambdaHashingVersion: '20201221'
183
+ name: aws
184
+ runtime: nodejs14.x
185
+ lambdaHashingVersion: "20201221"
185
186
 
186
187
  plugins:
187
- - serverless-offline
188
+ - serverless-offline
188
189
 
189
190
  functions:
190
- timeslots:
191
- handler: dist/handler.getTimeslots
192
- events:
193
- - http:
194
- path: /timeslots
195
- method: get
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: '2'
250
+ frameworkVersion: "2"
250
251
 
251
252
  provider:
252
253
  name: aws
253
254
  runtime: nodejs14.x
254
- lambdaHashingVersion: '20201221'
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: '{proxy+}'
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('x-test', 'test');
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.call("getById")
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)]
@@ -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
  }