@webiny/handler-aws 6.3.0 → 6.4.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/createHandler.js +16 -22
- package/createHandler.js.map +1 -1
- package/dynamodb/index.js +34 -49
- package/dynamodb/index.js.map +1 -1
- package/dynamodb/plugins/DynamoDBEventHandler.js +10 -9
- package/dynamodb/plugins/DynamoDBEventHandler.js.map +1 -1
- package/dynamodb/register.js +8 -18
- package/dynamodb/register.js.map +1 -1
- package/eventBridge/index.js +34 -49
- package/eventBridge/index.js.map +1 -1
- package/eventBridge/plugins/EventBridgeEventHandler.js +10 -9
- package/eventBridge/plugins/EventBridgeEventHandler.js.map +1 -1
- package/eventBridge/register.js +3 -11
- package/eventBridge/register.js.map +1 -1
- package/execute.js +52 -60
- package/execute.js.map +1 -1
- package/gateway/index.js +39 -67
- package/gateway/index.js.map +1 -1
- package/gateway/register.js +3 -11
- package/gateway/register.js.map +1 -1
- package/index.js +8 -39
- package/package.json +8 -8
- package/plugins/index.js +3 -4
- package/plugins/index.js.map +1 -1
- package/raw/index.js +38 -63
- package/raw/index.js.map +1 -1
- package/raw/plugins/RawEventHandler.js +11 -21
- package/raw/plugins/RawEventHandler.js.map +1 -1
- package/registry.js +17 -32
- package/registry.js.map +1 -1
- package/s3/index.js +34 -49
- package/s3/index.js.map +1 -1
- package/s3/plugins/S3EventHandler.js +10 -9
- package/s3/plugins/S3EventHandler.js.map +1 -1
- package/s3/register.js +7 -15
- package/s3/register.js.map +1 -1
- package/sns/index.js +34 -49
- package/sns/index.js.map +1 -1
- package/sns/plugins/SNSEventHandler.js +10 -9
- package/sns/plugins/SNSEventHandler.js.map +1 -1
- package/sns/register.js +7 -15
- package/sns/register.js.map +1 -1
- package/sourceHandler.js +2 -3
- package/sourceHandler.js.map +1 -1
- package/sqs/index.js +35 -52
- package/sqs/index.js.map +1 -1
- package/sqs/plugins/SQSEventHandler.js +10 -9
- package/sqs/plugins/SQSEventHandler.js.map +1 -1
- package/sqs/register.js +8 -18
- package/sqs/register.js.map +1 -1
- package/types.js +5 -4
- package/types.js.map +1 -1
- package/utils/composedHandler.js +5 -14
- package/utils/composedHandler.js.map +1 -1
- package/utils/index.js +0 -2
- package/utils/timer/CustomTimer.js +9 -8
- package/utils/timer/CustomTimer.js.map +1 -1
- package/utils/timer/Timer.js +12 -13
- package/utils/timer/Timer.js.map +1 -1
- package/utils/timer/abstractions/ITimer.js +0 -3
- package/utils/timer/factory.js +7 -8
- package/utils/timer/factory.js.map +1 -1
- package/utils/timer/index.js +0 -2
- package/index.js.map +0 -1
- package/utils/index.js.map +0 -1
- package/utils/timer/abstractions/ITimer.js.map +0 -1
- package/utils/timer/index.js.map +0 -1
package/execute.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"execute.js","sources":["../src/execute.ts"],"sourcesContent":["import type { FastifyInstance } from \"@webiny/handler/types.js\";\nimport type { APIGatewayProxyResult } from \"@webiny/aws-sdk/types/index.js\";\nimport type { LightMyRequestCallback } from \"fastify\";\nimport { Base64EncodeHeader } from \"~/types.js\";\n\ninterface Resolve {\n (response: APIGatewayProxyResult | any): void;\n}\nconst createHandleResponse = (app: FastifyInstance, resolve: Resolve): LightMyRequestCallback => {\n return (err, result) => {\n if (err) {\n return resolve({\n statusCode: 500,\n body: JSON.stringify(err),\n headers: {}\n });\n }\n if (app.__webiny_raw_result) {\n return resolve(app.__webiny_raw_result);\n } else if (!result) {\n const response: APIGatewayProxyResult = {\n statusCode: 200,\n body: \"\",\n headers: {},\n isBase64Encoded: false\n };\n return resolve(response);\n }\n\n const isBase64Encoded =\n !!result.headers[Base64EncodeHeader.encoded] ||\n !!result.headers[Base64EncodeHeader.binary];\n const response: APIGatewayProxyResult = {\n statusCode: result.statusCode,\n body: isBase64Encoded ? result.rawPayload.toString(\"base64\") : result.payload,\n headers: result.headers as APIGatewayProxyResult[\"headers\"],\n isBase64Encoded\n };\n return resolve(response);\n };\n};\n\nconst getPayloadProperty = (\n payload: any,\n prop: string,\n defaults: Record<string, any> = {}\n): Record<string, any> => {\n if (payload && typeof payload === \"object\") {\n const value = payload[prop] ? payload[prop] : {};\n\n return {\n ...defaults,\n ...value\n };\n }\n return defaults;\n};\n\nexport interface ExecuteParams {\n app: FastifyInstance;\n url: string;\n payload: any;\n}\n\nexport const execute = (params: ExecuteParams): Promise<any> => {\n const { app, url, payload } = params;\n\n const query = getPayloadProperty(payload, \"query\", {});\n const headers = getPayloadProperty(payload, \"headers\", {\n [\"content-type\"]: \"application/json\"\n });\n\n const cookies = getPayloadProperty(payload, \"cookies\", {});\n\n return new Promise(resolve => {\n app.inject(\n {\n method: \"POST\",\n url,\n payload: payload || {},\n body: payload || {},\n query,\n headers,\n cookies\n },\n createHandleResponse(app, resolve)\n );\n });\n};\n"],"names":["createHandleResponse","app","resolve","err","result","JSON","response","isBase64Encoded","Base64EncodeHeader","getPayloadProperty","payload","prop","defaults","value","execute","params","url","query","headers","cookies","Promise"],"mappings":";AAQA,MAAMA,uBAAuB,CAACC,KAAsBC,UACzC,CAACC,KAAKC;QACT,IAAID,KACA,OAAOD,QAAQ;YACX,YAAY;YACZ,MAAMG,KAAK,SAAS,CAACF;YACrB,SAAS,CAAC;QACd;QAEJ,IAAIF,IAAI,mBAAmB,EACvB,OAAOC,QAAQD,IAAI,mBAAmB;QACnC,IAAI,CAACG,QAAQ;YAChB,MAAME,WAAkC;gBACpC,YAAY;gBACZ,MAAM;gBACN,SAAS,CAAC;gBACV,iBAAiB;YACrB;YACA,OAAOJ,QAAQI;QACnB;QAEA,MAAMC,kBACF,CAAC,CAACH,OAAO,OAAO,CAACI,mBAAmB,OAAO,CAAC,IAC5C,CAAC,CAACJ,OAAO,OAAO,CAACI,mBAAmB,MAAM,CAAC;QAC/C,MAAMF,WAAkC;YACpC,YAAYF,OAAO,UAAU;YAC7B,MAAMG,kBAAkBH,OAAO,UAAU,CAAC,QAAQ,CAAC,YAAYA,OAAO,OAAO;YAC7E,SAASA,OAAO,OAAO;YACvBG;QACJ;QACA,OAAOL,QAAQI;IACnB;AAGJ,MAAMG,qBAAqB,CACvBC,SACAC,MACAC,WAAgC,CAAC,CAAC;IAElC,IAAIF,WAAW,AAAmB,YAAnB,OAAOA,SAAsB;QACxC,MAAMG,QAAQH,OAAO,CAACC,KAAK,GAAGD,OAAO,CAACC,KAAK,GAAG,CAAC;QAE/C,OAAO;YACH,GAAGC,QAAQ;YACX,GAAGC,KAAK;QACZ;IACJ;IACA,OAAOD;AACX;AAQO,MAAME,UAAU,CAACC;IACpB,MAAM,EAAEd,GAAG,EAAEe,GAAG,EAAEN,OAAO,EAAE,GAAGK;IAE9B,MAAME,QAAQR,mBAAmBC,SAAS,SAAS,CAAC;IACpD,MAAMQ,UAAUT,mBAAmBC,SAAS,WAAW;QACnD,CAAC,eAAe,EAAE;IACtB;IAEA,MAAMS,UAAUV,mBAAmBC,SAAS,WAAW,CAAC;IAExD,OAAO,IAAIU,QAAQlB,CAAAA;QACfD,IAAI,MAAM,CACN;YACI,QAAQ;YACRe;YACA,SAASN,WAAW,CAAC;YACrB,MAAMA,WAAW,CAAC;YAClBO;YACAC;YACAC;QACJ,GACAnB,qBAAqBC,KAAKC;IAElC;AACJ"}
|
package/gateway/index.js
CHANGED
|
@@ -1,76 +1,48 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { createHandler
|
|
1
|
+
import aws_lambda from "@fastify/aws-lambda";
|
|
2
|
+
import { RoutePlugin, createHandler, createRoute } from "@webiny/handler";
|
|
3
3
|
import { registerDefaultPlugins } from "../plugins/index.js";
|
|
4
4
|
import { Base64EncodeHeader } from "../types.js";
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
for (const key in headers) {
|
|
8
|
-
if (key.toLowerCase() !== header) {
|
|
9
|
-
continue;
|
|
10
|
-
}
|
|
11
|
-
return headers[key];
|
|
12
|
-
}
|
|
13
|
-
return undefined;
|
|
5
|
+
const getHeader = (headers, header)=>{
|
|
6
|
+
for(const key in headers)if (key.toLowerCase() === header) return headers[key];
|
|
14
7
|
};
|
|
15
8
|
const defaultContentType = "application/json";
|
|
16
9
|
const defaultCharset = "utf-8";
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const contentType = getHeader(event.headers, "content-type");
|
|
30
|
-
/**
|
|
31
|
-
* We check the existing content type and add the default one if it does not exist.
|
|
32
|
-
*
|
|
33
|
-
* Also, if the content-type is the application/json, and the body is not sent, we add it.
|
|
34
|
-
*/
|
|
35
|
-
if (!contentType) {
|
|
36
|
-
event.headers["content-type"] = [defaultContentType, `charset=${defaultCharset}`].join(";");
|
|
37
|
-
event.body = "{}";
|
|
38
|
-
} else if (!event.body && contentType.startsWith(defaultContentType)) {
|
|
39
|
-
event.body = "{}";
|
|
40
|
-
}
|
|
41
|
-
if (!isOptions) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
event.body = null;
|
|
45
|
-
};
|
|
46
|
-
export const createHandler = params => {
|
|
47
|
-
return async (event, context) => {
|
|
48
|
-
const app = createBaseHandler({
|
|
49
|
-
...params,
|
|
50
|
-
options: {
|
|
51
|
-
logger: params.debug === true,
|
|
52
|
-
...(params.options || {})
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
/**
|
|
56
|
-
* We always must add our default plugins to the app.
|
|
57
|
-
*/
|
|
58
|
-
registerDefaultPlugins(app.webiny);
|
|
59
|
-
if (app.webiny.plugins.byType(RoutePlugin.type).length === 0) {
|
|
60
|
-
throw new Error(`To run @webiny/handler-aws/gateway, you must have at least one RoutePlugin set.`);
|
|
10
|
+
const attachRequiredProperties = (event)=>{
|
|
11
|
+
const isOptions = "options" === event.httpMethod.toLowerCase();
|
|
12
|
+
if (!event.headers) event.headers = {};
|
|
13
|
+
const contentType = getHeader(event.headers, "content-type");
|
|
14
|
+
if (contentType) {
|
|
15
|
+
if (!event.body && contentType.startsWith(defaultContentType)) event.body = "{}";
|
|
16
|
+
} else {
|
|
17
|
+
event.headers["content-type"] = [
|
|
18
|
+
defaultContentType,
|
|
19
|
+
`charset=${defaultCharset}`
|
|
20
|
+
].join(";");
|
|
21
|
+
event.body = "{}";
|
|
61
22
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
decorateRequest: true,
|
|
65
|
-
serializeLambdaArguments: true,
|
|
66
|
-
decorationPropertyName: "awsLambda",
|
|
67
|
-
enforceBase64: response => {
|
|
68
|
-
return !!response.headers[Base64EncodeHeader.encoded] || !!response.headers[Base64EncodeHeader.binary];
|
|
69
|
-
},
|
|
70
|
-
...(params.lambdaOptions || {})
|
|
71
|
-
});
|
|
72
|
-
return appLambda(event, context);
|
|
73
|
-
};
|
|
23
|
+
if (!isOptions) return;
|
|
24
|
+
event.body = null;
|
|
74
25
|
};
|
|
26
|
+
const gateway_createHandler = (params)=>async (event, context)=>{
|
|
27
|
+
const app = createHandler({
|
|
28
|
+
...params,
|
|
29
|
+
options: {
|
|
30
|
+
logger: true === params.debug,
|
|
31
|
+
...params.options || {}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
registerDefaultPlugins(app.webiny);
|
|
35
|
+
if (0 === app.webiny.plugins.byType(RoutePlugin.type).length) throw new Error("To run @webiny/handler-aws/gateway, you must have at least one RoutePlugin set.");
|
|
36
|
+
attachRequiredProperties(event);
|
|
37
|
+
const appLambda = aws_lambda(app, {
|
|
38
|
+
decorateRequest: true,
|
|
39
|
+
serializeLambdaArguments: true,
|
|
40
|
+
decorationPropertyName: "awsLambda",
|
|
41
|
+
enforceBase64: (response)=>!!response.headers[Base64EncodeHeader.encoded] || !!response.headers[Base64EncodeHeader.binary],
|
|
42
|
+
...params.lambdaOptions || {}
|
|
43
|
+
});
|
|
44
|
+
return appLambda(event, context);
|
|
45
|
+
};
|
|
46
|
+
export { RoutePlugin, createRoute, gateway_createHandler as createHandler };
|
|
75
47
|
|
|
76
48
|
//# sourceMappingURL=index.js.map
|
package/gateway/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"gateway/index.js","sources":["../../src/gateway/index.ts"],"sourcesContent":["import type {\n APIGatewayEvent,\n APIGatewayProxyEventHeaders,\n Context as LambdaContext\n} from \"@webiny/aws-sdk/types/index.js\";\nimport type { LambdaResponse } from \"@fastify/aws-lambda\";\nimport awsLambdaFastify from \"@fastify/aws-lambda\";\nimport { createHandler as createBaseHandler, createRoute, RoutePlugin } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins/index.js\";\nimport type { HandlerFactoryParams } from \"~/types.js\";\nimport { Base64EncodeHeader } from \"~/types.js\";\n\nexport { RoutePlugin, createRoute };\n\nexport type HandlerParams = HandlerFactoryParams;\n\nexport interface HandlerCallable {\n (event: APIGatewayEvent, ctx: LambdaContext): Promise<LambdaResponse>;\n}\n\nconst getHeader = (headers: APIGatewayProxyEventHeaders, header: string): string | undefined => {\n for (const key in headers) {\n if (key.toLowerCase() !== header) {\n continue;\n }\n return headers[key];\n }\n return undefined;\n};\n\nconst defaultContentType = \"application/json\";\nconst defaultCharset = \"utf-8\";\n/**\n * We need to attach default headers to the request, so it does not break if there is none sent.\n */\nconst attachRequiredProperties = (event: APIGatewayEvent): void => {\n const isOptions = event.httpMethod.toLowerCase() === \"options\";\n /**\n * A possibility that headers are not defined?\n * Maybe during testing?\n */\n if (!event.headers) {\n event.headers = {};\n }\n const contentType = getHeader(event.headers, \"content-type\");\n /**\n * We check the existing content type and add the default one if it does not exist.\n *\n * Also, if the content-type is the application/json, and the body is not sent, we add it.\n */\n if (!contentType) {\n event.headers[\"content-type\"] = [defaultContentType, `charset=${defaultCharset}`].join(\";\");\n event.body = \"{}\";\n } else if (!event.body && contentType.startsWith(defaultContentType)) {\n event.body = \"{}\";\n }\n if (!isOptions) {\n return;\n }\n event.body = null;\n};\n\nexport const createHandler = (params: HandlerParams): HandlerCallable => {\n return async (event, context) => {\n const app = createBaseHandler({\n ...params,\n options: {\n logger: params.debug === true,\n ...(params.options || {})\n }\n });\n /**\n * We always must add our default plugins to the app.\n */\n registerDefaultPlugins(app.webiny);\n\n if (app.webiny.plugins.byType<RoutePlugin>(RoutePlugin.type).length === 0) {\n throw new Error(\n `To run @webiny/handler-aws/gateway, you must have at least one RoutePlugin set.`\n );\n }\n attachRequiredProperties(event);\n\n const appLambda = awsLambdaFastify(app, {\n decorateRequest: true,\n serializeLambdaArguments: true,\n decorationPropertyName: \"awsLambda\",\n enforceBase64: response => {\n return (\n !!response.headers[Base64EncodeHeader.encoded] ||\n !!response.headers[Base64EncodeHeader.binary]\n );\n },\n ...(params.lambdaOptions || {})\n });\n return appLambda(event, context);\n };\n};\n"],"names":["getHeader","headers","header","key","defaultContentType","defaultCharset","attachRequiredProperties","event","isOptions","contentType","createHandler","params","context","app","createBaseHandler","registerDefaultPlugins","RoutePlugin","Error","appLambda","awsLambdaFastify","response","Base64EncodeHeader"],"mappings":";;;;AAoBA,MAAMA,YAAY,CAACC,SAAsCC;IACrD,IAAK,MAAMC,OAAOF,QACd,IAAIE,IAAI,WAAW,OAAOD,QAG1B,OAAOD,OAAO,CAACE,IAAI;AAG3B;AAEA,MAAMC,qBAAqB;AAC3B,MAAMC,iBAAiB;AAIvB,MAAMC,2BAA2B,CAACC;IAC9B,MAAMC,YAAYD,AAAmC,cAAnCA,MAAM,UAAU,CAAC,WAAW;IAK9C,IAAI,CAACA,MAAM,OAAO,EACdA,MAAM,OAAO,GAAG,CAAC;IAErB,MAAME,cAAcT,UAAUO,MAAM,OAAO,EAAE;IAM7C,IAAKE,aAGE;QAAA,IAAI,CAACF,MAAM,IAAI,IAAIE,YAAY,UAAU,CAACL,qBAC7CG,MAAM,IAAI,GAAG;IACjB,OALkB;QACdA,MAAM,OAAO,CAAC,eAAe,GAAG;YAACH;YAAoB,CAAC,QAAQ,EAAEC,gBAAgB;SAAC,CAAC,IAAI,CAAC;QACvFE,MAAM,IAAI,GAAG;IACjB;IAGA,IAAI,CAACC,WACD;IAEJD,MAAM,IAAI,GAAG;AACjB;AAEO,MAAMG,wBAAgB,CAACC,SACnB,OAAOJ,OAAOK;QACjB,MAAMC,MAAMC,cAAkB;YAC1B,GAAGH,MAAM;YACT,SAAS;gBACL,QAAQA,AAAiB,SAAjBA,OAAO,KAAK;gBACpB,GAAIA,OAAO,OAAO,IAAI,CAAC,CAAC;YAC5B;QACJ;QAIAI,uBAAuBF,IAAI,MAAM;QAEjC,IAAIA,AAAoE,MAApEA,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAcG,YAAY,IAAI,EAAE,MAAM,EAC/D,MAAM,IAAIC,MACN;QAGRX,yBAAyBC;QAEzB,MAAMW,YAAYC,WAAiBN,KAAK;YACpC,iBAAiB;YACjB,0BAA0B;YAC1B,wBAAwB;YACxB,eAAeO,CAAAA,WAEP,CAAC,CAACA,SAAS,OAAO,CAACC,mBAAmB,OAAO,CAAC,IAC9C,CAAC,CAACD,SAAS,OAAO,CAACC,mBAAmB,MAAM,CAAC;YAGrD,GAAIV,OAAO,aAAa,IAAI,CAAC,CAAC;QAClC;QACA,OAAOO,UAAUX,OAAOK;IAC5B"}
|
package/gateway/register.js
CHANGED
|
@@ -2,17 +2,9 @@ import { registry } from "../registry.js";
|
|
|
2
2
|
import { createSourceHandler } from "../sourceHandler.js";
|
|
3
3
|
import { createHandler } from "./index.js";
|
|
4
4
|
const handler = createSourceHandler({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
},
|
|
9
|
-
handle: async ({
|
|
10
|
-
params,
|
|
11
|
-
event,
|
|
12
|
-
context
|
|
13
|
-
}) => {
|
|
14
|
-
return createHandler(params)(event, context);
|
|
15
|
-
}
|
|
5
|
+
name: "handler-aws-api-gateway",
|
|
6
|
+
canUse: (event)=>!!event.httpMethod,
|
|
7
|
+
handle: async ({ params, event, context })=>createHandler(params)(event, context)
|
|
16
8
|
});
|
|
17
9
|
registry.register(handler);
|
|
18
10
|
|
package/gateway/register.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"gateway/register.js","sources":["../../src/gateway/register.ts"],"sourcesContent":["import type { APIGatewayEvent } from \"@webiny/aws-sdk/types/index.js\";\nimport { registry } from \"~/registry.js\";\nimport { createSourceHandler } from \"~/sourceHandler.js\";\nimport type { HandlerParams } from \"./index.js\";\nimport { createHandler } from \"./index.js\";\n\nconst handler = createSourceHandler<APIGatewayEvent, HandlerParams>({\n name: \"handler-aws-api-gateway\",\n canUse: event => {\n return !!event.httpMethod;\n },\n handle: async ({ params, event, context }) => {\n return createHandler(params)(event, context);\n }\n});\n\nregistry.register(handler);\n"],"names":["handler","createSourceHandler","event","params","context","createHandler","registry"],"mappings":";;;AAMA,MAAMA,UAAUC,oBAAoD;IAChE,MAAM;IACN,QAAQC,CAAAA,QACG,CAAC,CAACA,MAAM,UAAU;IAE7B,QAAQ,OAAO,EAAEC,MAAM,EAAED,KAAK,EAAEE,OAAO,EAAE,GAC9BC,cAAcF,QAAQD,OAAOE;AAE5C;AAEAE,SAAS,QAAQ,CAACN"}
|
package/index.js
CHANGED
|
@@ -5,44 +5,13 @@ import "./sqs/register.js";
|
|
|
5
5
|
import "./eventBridge/register.js";
|
|
6
6
|
import "./sns/register.js";
|
|
7
7
|
export * from "./utils/index.js";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* API Gateway
|
|
11
|
-
*/
|
|
12
|
-
export { createHandler as createApiGatewayHandler, RoutePlugin, createRoute as createApiGatewayRoute } from "./gateway/index.js";
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* S3
|
|
16
|
-
*/
|
|
17
|
-
//
|
|
18
|
-
export { createHandler as createS3Handler, S3EventHandler, createEventHandler as createS3EventHandler } from "./s3/index.js";
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* DynamoDB Stream
|
|
22
|
-
*/
|
|
23
|
-
//
|
|
24
|
-
export { createHandler as createDynamoDBHandler, DynamoDBEventHandler, createEventHandler as createDynamoDBEventHandler } from "./dynamodb/index.js";
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* SQS
|
|
28
|
-
*/
|
|
29
|
-
//
|
|
30
|
-
export { createHandler as createSQSHandler, SQSEventHandler, createEventHandler as createSQSEventHandler } from "./sqs/index.js";
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* SNS
|
|
34
|
-
*/
|
|
35
|
-
//
|
|
36
|
-
export { createHandler as createSNSHandler, SNSEventHandler, createEventHandler as createSNSEventHandler } from "./sns/index.js";
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* EventBridge
|
|
40
|
-
*/
|
|
41
|
-
//
|
|
42
|
-
export { createHandler as createEventBridgeHandler, EventBridgeEventHandler, createEventHandler as createEventBridgeEventHandler } from "./eventBridge/index.js";
|
|
43
|
-
export { createHandler as createRawHandler, createEventHandler as createRawEventHandler, RawEventHandler } from "./raw/index.js";
|
|
44
|
-
export { ContextPlugin, createContextPlugin } from "@webiny/handler";
|
|
45
8
|
export * from "./createHandler.js";
|
|
46
9
|
export * from "./sourceHandler.js";
|
|
47
|
-
|
|
48
|
-
|
|
10
|
+
export { RoutePlugin, createHandler as createApiGatewayHandler, createRoute as createApiGatewayRoute } from "./gateway/index.js";
|
|
11
|
+
export { S3EventHandler, createEventHandler as createS3EventHandler, createHandler as createS3Handler } from "./s3/index.js";
|
|
12
|
+
export { DynamoDBEventHandler, createEventHandler as createDynamoDBEventHandler, createHandler as createDynamoDBHandler } from "./dynamodb/index.js";
|
|
13
|
+
export { SQSEventHandler, createEventHandler as createSQSEventHandler, createHandler as createSQSHandler } from "./sqs/index.js";
|
|
14
|
+
export { SNSEventHandler, createEventHandler as createSNSEventHandler, createHandler as createSNSHandler } from "./sns/index.js";
|
|
15
|
+
export { EventBridgeEventHandler, createEventHandler as createEventBridgeEventHandler, createHandler as createEventBridgeHandler } from "./eventBridge/index.js";
|
|
16
|
+
export { RawEventHandler, createEventHandler as createRawEventHandler, createHandler as createRawHandler } from "./raw/index.js";
|
|
17
|
+
export { ContextPlugin, createContextPlugin } from "@webiny/handler";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/handler-aws",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.4.0-beta.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -17,22 +17,22 @@
|
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@fastify/aws-lambda": "6.4.0",
|
|
20
|
-
"@webiny/aws-sdk": "6.
|
|
21
|
-
"@webiny/handler": "6.
|
|
22
|
-
"@webiny/plugins": "6.
|
|
23
|
-
"@webiny/utils": "6.
|
|
20
|
+
"@webiny/aws-sdk": "6.4.0-beta.0",
|
|
21
|
+
"@webiny/handler": "6.4.0-beta.0",
|
|
22
|
+
"@webiny/plugins": "6.4.0-beta.0",
|
|
23
|
+
"@webiny/utils": "6.4.0-beta.0",
|
|
24
24
|
"fastify": "5.8.5",
|
|
25
25
|
"pino-lambda": "4.4.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@webiny/build-tools": "6.
|
|
28
|
+
"@webiny/build-tools": "6.4.0-beta.0",
|
|
29
29
|
"rimraf": "6.1.3",
|
|
30
30
|
"typescript": "6.0.3",
|
|
31
|
-
"vitest": "4.1.
|
|
31
|
+
"vitest": "4.1.6"
|
|
32
32
|
},
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public",
|
|
35
35
|
"directory": "dist"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "a545d7529828af07d08d49c3da1bcb967483b9ce"
|
|
38
38
|
}
|
package/plugins/index.js
CHANGED
package/plugins/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"plugins/index.js","sources":["../../src/plugins/index.ts"],"sourcesContent":["import type { Context } from \"@webiny/handler/types.js\";\n\nexport const registerDefaultPlugins = (context: Context): void => {\n context.plugins.register([\n //\n ]);\n};\n"],"names":["registerDefaultPlugins","context"],"mappings":"AAEO,MAAMA,yBAAyB,CAACC;IACnCA,QAAQ,OAAO,CAAC,QAAQ,CAAC,EAExB;AACL"}
|
package/raw/index.js
CHANGED
|
@@ -1,70 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
* This is the handler implementation for @webiny/handler/plugins/EventPlugin.
|
|
3
|
-
* This is mostly meant for some custom lambda calls as we are sometimes invoking lambdas directly.
|
|
4
|
-
*
|
|
5
|
-
* We should try to have some kind of standardized event type implementation at some point.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { createHandler as createBaseHandler } from "@webiny/handler";
|
|
1
|
+
import { createHandler } from "@webiny/handler";
|
|
9
2
|
import { RawEventHandler } from "./plugins/RawEventHandler.js";
|
|
10
3
|
import { registerDefaultPlugins } from "../plugins/index.js";
|
|
11
4
|
import { execute } from "../execute.js";
|
|
12
5
|
import { createComposedHandler } from "../utils/composedHandler.js";
|
|
13
|
-
|
|
14
|
-
import Reply from "fastify/lib/reply.js";
|
|
15
|
-
const url = "/webiny-raw-event";
|
|
16
|
-
export const createHandler = params => {
|
|
17
|
-
return (payload, context) => {
|
|
18
|
-
const app = createBaseHandler({
|
|
19
|
-
...params,
|
|
20
|
-
options: {
|
|
21
|
-
logger: params.debug === true,
|
|
22
|
-
...(params.options || {})
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
/**
|
|
26
|
-
* We always must add our default plugins to the app.
|
|
27
|
-
*/
|
|
28
|
-
registerDefaultPlugins(app.webiny);
|
|
29
|
-
/**
|
|
30
|
-
* There must be an event plugin for this handler to work.
|
|
31
|
-
*/
|
|
32
|
-
const plugins = app.webiny.plugins.byType(RawEventHandler.type).filter(plugin => {
|
|
33
|
-
/**
|
|
34
|
-
* Just in case check that the plugin contains canHandle method.
|
|
35
|
-
* If it does not, we assume it can handle any payload.
|
|
36
|
-
*/
|
|
37
|
-
if (typeof plugin.canHandle !== "function") {
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
return plugin.canHandle(payload);
|
|
41
|
-
}).reverse();
|
|
42
|
-
if (plugins.length === 0) {
|
|
43
|
-
throw new Error(`To run @webiny/handler-aws/raw, you must have RawEventHandler set.`);
|
|
44
|
-
}
|
|
45
|
-
const handler = createComposedHandler(plugins);
|
|
46
|
-
app.post(url, async (request, reply) => {
|
|
47
|
-
const params = {
|
|
48
|
-
request,
|
|
49
|
-
reply,
|
|
50
|
-
context: app.webiny,
|
|
51
|
-
payload,
|
|
52
|
-
lambdaContext: context
|
|
53
|
-
};
|
|
54
|
-
const result = await handler(params);
|
|
55
|
-
if (result instanceof Reply) {
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
58
|
-
app.__webiny_raw_result = result;
|
|
59
|
-
return reply.send({});
|
|
60
|
-
});
|
|
61
|
-
return execute({
|
|
62
|
-
app,
|
|
63
|
-
url,
|
|
64
|
-
payload
|
|
65
|
-
});
|
|
66
|
-
};
|
|
67
|
-
};
|
|
6
|
+
import lib_reply from "fastify/lib/reply.js";
|
|
68
7
|
export * from "./plugins/RawEventHandler.js";
|
|
8
|
+
const url = "/webiny-raw-event";
|
|
9
|
+
const raw_createHandler = (params)=>(payload, context)=>{
|
|
10
|
+
const app = createHandler({
|
|
11
|
+
...params,
|
|
12
|
+
options: {
|
|
13
|
+
logger: true === params.debug,
|
|
14
|
+
...params.options || {}
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
registerDefaultPlugins(app.webiny);
|
|
18
|
+
const plugins = app.webiny.plugins.byType(RawEventHandler.type).filter((plugin)=>{
|
|
19
|
+
if ("function" != typeof plugin.canHandle) return true;
|
|
20
|
+
return plugin.canHandle(payload);
|
|
21
|
+
}).reverse();
|
|
22
|
+
if (0 === plugins.length) throw new Error("To run @webiny/handler-aws/raw, you must have RawEventHandler set.");
|
|
23
|
+
const handler = createComposedHandler(plugins);
|
|
24
|
+
app.post(url, async (request, reply)=>{
|
|
25
|
+
const params = {
|
|
26
|
+
request,
|
|
27
|
+
reply,
|
|
28
|
+
context: app.webiny,
|
|
29
|
+
payload,
|
|
30
|
+
lambdaContext: context
|
|
31
|
+
};
|
|
32
|
+
const result = await handler(params);
|
|
33
|
+
if (result instanceof lib_reply) return result;
|
|
34
|
+
app.__webiny_raw_result = result;
|
|
35
|
+
return reply.send({});
|
|
36
|
+
});
|
|
37
|
+
return execute({
|
|
38
|
+
app,
|
|
39
|
+
url: url,
|
|
40
|
+
payload
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
export { raw_createHandler as createHandler };
|
|
69
44
|
|
|
70
45
|
//# sourceMappingURL=index.js.map
|
package/raw/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"raw/index.js","sources":["../../src/raw/index.ts"],"sourcesContent":["/**\n * This is the handler implementation for @webiny/handler/plugins/EventPlugin.\n * This is mostly meant for some custom lambda calls as we are sometimes invoking lambdas directly.\n *\n * We should try to have some kind of standardized event type implementation at some point.\n */\nimport type {\n APIGatewayProxyResult,\n Context as LambdaContext\n} from \"@webiny/aws-sdk/types/index.js\";\nimport type { CreateHandlerParams as BaseCreateHandlerParams } from \"@webiny/handler\";\nimport { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { RawEventHandler } from \"~/raw/plugins/RawEventHandler.js\";\nimport { registerDefaultPlugins } from \"~/plugins/index.js\";\nimport { execute } from \"~/execute.js\";\nimport { createComposedHandler } from \"~/utils/composedHandler.js\";\nimport type { Context, Request } from \"@webiny/handler/types.js\";\n\n// @ts-expect-error\nimport Reply from \"fastify/lib/reply.js\";\n\nconst url = \"/webiny-raw-event\";\n\nexport interface HandlerCallable<Payload, Response = APIGatewayProxyResult> {\n (payload: Payload, context: LambdaContext): Promise<Response>;\n}\n\nexport type CreateHandlerParams = BaseCreateHandlerParams;\n\ninterface HandlerParams<Payload = any> {\n request: Request;\n context: Context;\n payload: Payload;\n lambdaContext: LambdaContext;\n reply: Record<string, any>;\n next: () => Promise<Payload>;\n}\n\nexport const createHandler = <Payload = any, Response = APIGatewayProxyResult>(\n params: CreateHandlerParams\n): HandlerCallable<Payload, Response> => {\n return (payload, context) => {\n const app = createBaseHandler({\n ...params,\n options: {\n logger: params.debug === true,\n ...(params.options || {})\n }\n });\n /**\n * We always must add our default plugins to the app.\n */\n registerDefaultPlugins(app.webiny);\n /**\n * There must be an event plugin for this handler to work.\n */\n const plugins = app.webiny.plugins\n .byType<RawEventHandler<Payload, any, Response>>(RawEventHandler.type)\n .filter(plugin => {\n /**\n * Just in case check that the plugin contains canHandle method.\n * If it does not, we assume it can handle any payload.\n */\n if (typeof plugin.canHandle !== \"function\") {\n return true;\n }\n return plugin.canHandle(payload);\n })\n .reverse();\n if (plugins.length === 0) {\n throw new Error(`To run @webiny/handler-aws/raw, you must have RawEventHandler set.`);\n }\n\n const handler = createComposedHandler<\n RawEventHandler<Payload, any, Response>,\n HandlerParams,\n Response\n >(plugins);\n\n app.post(url, async (request, reply) => {\n const params: Omit<HandlerParams, \"next\"> = {\n request,\n reply,\n context: app.webiny,\n payload,\n lambdaContext: context\n };\n const result = await handler(params as unknown as HandlerParams);\n\n if (result instanceof Reply) {\n return result;\n }\n\n app.__webiny_raw_result = result;\n return reply.send({});\n });\n return execute({\n app,\n url,\n payload\n });\n };\n};\n\nexport * from \"./plugins/RawEventHandler.js\";\n"],"names":["url","createHandler","params","payload","context","app","createBaseHandler","registerDefaultPlugins","plugins","RawEventHandler","plugin","Error","handler","createComposedHandler","request","reply","result","Reply","execute"],"mappings":";;;;;;;AAqBA,MAAMA,MAAM;AAiBL,MAAMC,oBAAgB,CACzBC,SAEO,CAACC,SAASC;QACb,MAAMC,MAAMC,cAAkB;YAC1B,GAAGJ,MAAM;YACT,SAAS;gBACL,QAAQA,AAAiB,SAAjBA,OAAO,KAAK;gBACpB,GAAIA,OAAO,OAAO,IAAI,CAAC,CAAC;YAC5B;QACJ;QAIAK,uBAAuBF,IAAI,MAAM;QAIjC,MAAMG,UAAUH,IAAI,MAAM,CAAC,OAAO,CAC7B,MAAM,CAA0CI,gBAAgB,IAAI,EACpE,MAAM,CAACC,CAAAA;YAKJ,IAAI,AAA4B,cAA5B,OAAOA,OAAO,SAAS,EACvB,OAAO;YAEX,OAAOA,OAAO,SAAS,CAACP;QAC5B,GACC,OAAO;QACZ,IAAIK,AAAmB,MAAnBA,QAAQ,MAAM,EACd,MAAM,IAAIG,MAAM;QAGpB,MAAMC,UAAUC,sBAIdL;QAEFH,IAAI,IAAI,CAACL,KAAK,OAAOc,SAASC;YAC1B,MAAMb,SAAsC;gBACxCY;gBACAC;gBACA,SAASV,IAAI,MAAM;gBACnBF;gBACA,eAAeC;YACnB;YACA,MAAMY,SAAS,MAAMJ,QAAQV;YAE7B,IAAIc,kBAAkBC,WAClB,OAAOD;YAGXX,IAAI,mBAAmB,GAAGW;YAC1B,OAAOD,MAAM,IAAI,CAAC,CAAC;QACvB;QACA,OAAOG,QAAQ;YACXb;YACAL,KAAAA;YACAG;QACJ;IACJ"}
|
|
@@ -1,26 +1,16 @@
|
|
|
1
1
|
import { EventPlugin } from "@webiny/handler";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
|
-
canHandle(event) {
|
|
16
|
-
if (typeof this.params === "function" || !this.params?.canHandle) {
|
|
17
|
-
return true;
|
|
2
|
+
class RawEventHandler extends EventPlugin {
|
|
3
|
+
constructor(params){
|
|
4
|
+
const cb = "function" == typeof params ? params : params.handle;
|
|
5
|
+
super(cb);
|
|
6
|
+
this.params = params;
|
|
7
|
+
}
|
|
8
|
+
canHandle(event) {
|
|
9
|
+
if ("function" == typeof this.params || !this.params?.canHandle) return true;
|
|
10
|
+
return this.params.canHandle(event);
|
|
18
11
|
}
|
|
19
|
-
return this.params.canHandle(event);
|
|
20
|
-
}
|
|
21
12
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
13
|
+
const createEventHandler = (params)=>new RawEventHandler(params);
|
|
14
|
+
export { RawEventHandler, createEventHandler };
|
|
25
15
|
|
|
26
16
|
//# sourceMappingURL=RawEventHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"raw/plugins/RawEventHandler.js","sources":["../../../src/raw/plugins/RawEventHandler.ts"],"sourcesContent":["import type { Context as LambdaContext } from \"@webiny/aws-sdk/types/index.js\";\nimport type { Context as BaseContext, Reply } from \"@webiny/handler/types.js\";\nimport type { EventPluginCallableParams } from \"@webiny/handler\";\nimport { EventPlugin } from \"@webiny/handler\";\n\nexport interface RawEventHandlerCallableParams<\n Event,\n Context extends BaseContext\n> extends EventPluginCallableParams<Event, Context> {\n lambdaContext: LambdaContext;\n}\nexport interface RawEventHandlerCallable<Event, Context extends BaseContext, Response> {\n (params: RawEventHandlerCallableParams<Event, Context>): Promise<Response | Reply>;\n}\n\nexport interface RawEventHandlerParamsConfig<\n Event = any,\n Context extends BaseContext = BaseContext,\n Response = any\n> {\n canHandle(event: Event): boolean;\n handle: RawEventHandlerCallable<Event, Context, Response>;\n}\n\nexport type RawEventHandlerParams<\n Event = any,\n Context extends BaseContext = BaseContext,\n Response = any\n> =\n | RawEventHandlerCallable<Event, Context, Response>\n | RawEventHandlerParamsConfig<Event, Context, Response>;\n\nexport class RawEventHandler<\n Event = any,\n Context extends BaseContext = BaseContext,\n Response = any\n> extends EventPlugin<Event, Context, Response> {\n private readonly params: RawEventHandlerParams<Event, Context, Response>;\n\n public constructor(params: RawEventHandlerParams<Event, Context, Response>) {\n const cb = typeof params === \"function\" ? params : params.handle;\n /**\n * Callable is correct, TS is just having problems with the override.\n */\n // @ts-expect-error\n super(cb);\n this.params = params;\n }\n /**\n *\n */\n public canHandle(event: Event): boolean {\n if (typeof this.params === \"function\" || !this.params?.canHandle) {\n return true;\n }\n return this.params.canHandle(event);\n }\n}\n\nexport const createEventHandler = <\n Event = any,\n Context extends BaseContext = BaseContext,\n Response = any\n>(\n params: RawEventHandlerParams<Event, Context, Response>\n) => {\n return new RawEventHandler<Event, Context, Response>(params);\n};\n"],"names":["RawEventHandler","EventPlugin","params","cb","event","createEventHandler"],"mappings":";AAgCO,MAAMA,wBAIHC;IAGN,YAAmBC,MAAuD,CAAE;QACxE,MAAMC,KAAK,AAAkB,cAAlB,OAAOD,SAAwBA,SAASA,OAAO,MAAM;QAKhE,KAAK,CAACC;QACN,IAAI,CAAC,MAAM,GAAGD;IAClB;IAIO,UAAUE,KAAY,EAAW;QACpC,IAAI,AAAuB,cAAvB,OAAO,IAAI,CAAC,MAAM,IAAmB,CAAC,IAAI,CAAC,MAAM,EAAE,WACnD,OAAO;QAEX,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAACA;IACjC;AACJ;AAEO,MAAMC,qBAAqB,CAK9BH,SAEO,IAAIF,gBAA0CE"}
|
package/registry.js
CHANGED
|
@@ -1,38 +1,23 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TODO: refactor this to use a proper DI container
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
1
|
class HandlerRegistry {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* This should only happen during the development phase.
|
|
22
|
-
*/
|
|
23
|
-
throw new Error(`Handler "${handler.name}" is already registered.`);
|
|
2
|
+
constructor(){
|
|
3
|
+
this.handlers = new Map();
|
|
4
|
+
}
|
|
5
|
+
static create() {
|
|
6
|
+
return new HandlerRegistry();
|
|
7
|
+
}
|
|
8
|
+
register(handler, options) {
|
|
9
|
+
if (this.handlers.has(handler.name)) {
|
|
10
|
+
if (options?.silent) return;
|
|
11
|
+
throw new Error(`Handler "${handler.name}" is already registered.`);
|
|
12
|
+
}
|
|
13
|
+
this.handlers.set(handler.name, handler);
|
|
24
14
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
for (const handler of this.handlers.values()) {
|
|
29
|
-
if (handler.canUse(event, context)) {
|
|
30
|
-
return handler;
|
|
31
|
-
}
|
|
15
|
+
getHandler(event, context) {
|
|
16
|
+
for (const handler of this.handlers.values())if (handler.canUse(event, context)) return handler;
|
|
17
|
+
throw new Error(`There is no handler for the event: ${JSON.stringify(event)}`);
|
|
32
18
|
}
|
|
33
|
-
throw new Error(`There is no handler for the event: ${JSON.stringify(event)}`);
|
|
34
|
-
}
|
|
35
19
|
}
|
|
36
|
-
|
|
20
|
+
const registry = HandlerRegistry.create();
|
|
21
|
+
export { registry };
|
|
37
22
|
|
|
38
23
|
//# sourceMappingURL=registry.js.map
|
package/registry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"registry.js","sources":["../src/registry.ts"],"sourcesContent":["/**\n * TODO: refactor this to use a proper DI container\n */\nimport type { HandlerEvent, SourceHandler } from \"~/types.js\";\nimport type { Context as LambdaContext } from \"@webiny/aws-sdk/types/index.js\";\n\ninterface RegisterOptions {\n silent?: boolean;\n}\n\nclass HandlerRegistry {\n private readonly handlers = new Map<string, SourceHandler>();\n\n private constructor() {\n /**\n * We don't want this class to be constructed outside the static create() method\n */\n }\n\n public static create() {\n return new HandlerRegistry();\n }\n\n public register(handler: SourceHandler<any>, options?: RegisterOptions) {\n if (this.handlers.has(handler.name)) {\n if (options?.silent) {\n return;\n }\n /**\n * This should only happen during the development phase.\n */\n throw new Error(`Handler \"${handler.name}\" is already registered.`);\n }\n this.handlers.set(handler.name, handler);\n }\n\n public getHandler(event: HandlerEvent, context: LambdaContext): SourceHandler {\n for (const handler of this.handlers.values()) {\n if (handler.canUse(event, context)) {\n return handler;\n }\n }\n throw new Error(`There is no handler for the event: ${JSON.stringify(event)}`);\n }\n}\n\nexport type { HandlerRegistry };\n\nexport const registry = HandlerRegistry.create();\n"],"names":["HandlerRegistry","Map","handler","options","Error","event","context","JSON","registry"],"mappings":"AAUA,MAAMA;IAGF,aAAsB;aAFL,QAAQ,GAAG,IAAIC;IAMhC;IAEA,OAAc,SAAS;QACnB,OAAO,IAAID;IACf;IAEO,SAASE,OAA2B,EAAEC,OAAyB,EAAE;QACpE,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAACD,QAAQ,IAAI,GAAG;YACjC,IAAIC,SAAS,QACT;YAKJ,MAAM,IAAIC,MAAM,CAAC,SAAS,EAAEF,QAAQ,IAAI,CAAC,wBAAwB,CAAC;QACtE;QACA,IAAI,CAAC,QAAQ,CAAC,GAAG,CAACA,QAAQ,IAAI,EAAEA;IACpC;IAEO,WAAWG,KAAmB,EAAEC,OAAsB,EAAiB;QAC1E,KAAK,MAAMJ,WAAW,IAAI,CAAC,QAAQ,CAAC,MAAM,GACtC,IAAIA,QAAQ,MAAM,CAACG,OAAOC,UACtB,OAAOJ;QAGf,MAAM,IAAIE,MAAM,CAAC,mCAAmC,EAAEG,KAAK,SAAS,CAACF,QAAQ;IACjF;AACJ;AAIO,MAAMG,WAAWR,gBAAgB,MAAM"}
|