UNPKG

@h4ad/serverless-adapter

Version:

Run REST APIs and other web applications using your existing Node.js application framework (NestJS, Express, Koa, Hapi, Fastify and many others), on top of AWS, Azure, Digital Ocean and many other clouds.

1 lines 3.36 kB
{"version":3,"sources":["../../../src/resolvers/aws-context/aws-context.resolver.ts"],"sourcesContent":["//#region Imports\n\nimport type { Context } from 'aws-lambda';\nimport type {\n DelegatedResolver,\n Resolver,\n ResolverContract,\n ResolverProps,\n} from '../../contracts';\n\n//#endregion\n\n/**\n * The class that implements the resolver by using the AWS Context object.\n *\n * @remarks To use this resolver, you MUST leave `{@link https://docs.aws.amazon.com/lambda/latest/dg/nodejs-context.html | callbackWaitsForEmptyEventLoop}` as true, otherwise, AWS will not wait for this resolver to resolve.\n *\n * @deprecated From the AWS Documentation, describing the functions used in this resolver: Functions for compatibility with earlier Node.js Runtime v0.10.42. No longer documented, so they are deprecated, but they still work as of the 12.x runtime, so they are not removed from the types.\n *\n * @breadcrumb Resolvers / AwsContextResolver\n * @public\n */\nexport class AwsContextResolver<TEvent, TCallback, TResponse>\n implements ResolverContract<TEvent, Context, TCallback, TResponse, void>\n{\n /**\n * {@inheritDoc}\n */\n public createResolver({\n context,\n event,\n log,\n respondWithErrors,\n adapter,\n }: ResolverProps<any, Context, any, any>): Resolver<any, void> {\n if (!context) {\n throw new Error(\n 'Could not figure out how to create the resolver because the \"context\" argument was not sent.',\n );\n }\n\n if (!context.succeed) {\n throw new Error(\n 'Could not figure out how to create the resolver because the \"context\" argument didn\\'t have the \"succeed\" function.',\n );\n }\n\n if (!context.fail) {\n throw new Error(\n 'Could not figure out how to create the resolver because the \"context\" argument didn\\'t have the \"fail\" function.',\n );\n }\n\n const delegatedResolver: DelegatedResolver<any> = {\n succeed: response => context.succeed(response),\n fail: error => context.fail(error),\n };\n\n return {\n run: task => {\n task()\n .then(response => delegatedResolver.succeed(response))\n .catch(error => {\n log.error(\n 'SERVERLESS_ADAPTER:RESPOND_TO_EVENT_SOURCE_WITH_ERROR',\n error,\n );\n\n adapter.onErrorWhileForwarding({\n delegatedResolver,\n error,\n log,\n event,\n respondWithErrors,\n });\n });\n },\n };\n }\n}\n"],"mappings":"6CAsBO,IAAMA,EAAN,KAEP,CAxBA,MAwBA,CAAAC,EAAA,2BAIS,eAAe,CACpB,QAAAC,EACA,MAAAC,EACA,IAAAC,EACA,kBAAAC,EACA,QAAAC,CACF,EAA+D,CAC7D,GAAI,CAACJ,EACH,MAAM,IAAI,MACR,8FACF,EAGF,GAAI,CAACA,EAAQ,QACX,MAAM,IAAI,MACR,oHACF,EAGF,GAAI,CAACA,EAAQ,KACX,MAAM,IAAI,MACR,iHACF,EAGF,IAAMK,EAA4C,CAChD,QAASN,EAAAO,GAAYN,EAAQ,QAAQM,CAAQ,EAApC,WACT,KAAMP,EAAAQ,GAASP,EAAQ,KAAKO,CAAK,EAA3B,OACR,EAEA,MAAO,CACL,IAAKR,EAAAS,GAAQ,CACXA,EAAK,EACF,KAAKF,GAAYD,EAAkB,QAAQC,CAAQ,CAAC,EACpD,MAAMC,GAAS,CACdL,EAAI,MACF,wDACAK,CACF,EAEAH,EAAQ,uBAAuB,CAC7B,kBAAAC,EACA,MAAAE,EACA,IAAAL,EACA,MAAAD,EACA,kBAAAE,CACF,CAAC,CACH,CAAC,CACL,EAjBK,MAkBP,CACF,CACF","names":["AwsContextResolver","__name","context","event","log","respondWithErrors","adapter","delegatedResolver","response","error","task"]}