@webiny/handler-aws 0.0.0-unstable.bca7b3e350 → 0.0.0-unstable.c27f4d8a31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/README.md +10 -14
  2. package/createHandler.d.ts +2 -0
  3. package/createHandler.js +29 -0
  4. package/createHandler.js.map +1 -0
  5. package/dynamodb/index.d.ts +5 -8
  6. package/dynamodb/index.js +26 -56
  7. package/dynamodb/index.js.map +1 -1
  8. package/dynamodb/plugins/DynamoDBEventHandler.d.ts +8 -7
  9. package/dynamodb/plugins/DynamoDBEventHandler.js +5 -22
  10. package/dynamodb/plugins/DynamoDBEventHandler.js.map +1 -1
  11. package/dynamodb/register.d.ts +1 -0
  12. package/dynamodb/register.js +26 -0
  13. package/dynamodb/register.js.map +1 -0
  14. package/eventBridge/index.d.ts +7 -10
  15. package/eventBridge/index.js +27 -57
  16. package/eventBridge/index.js.map +1 -1
  17. package/eventBridge/plugins/EventBridgeEventHandler.d.ts +8 -7
  18. package/eventBridge/plugins/EventBridgeEventHandler.js +5 -22
  19. package/eventBridge/plugins/EventBridgeEventHandler.js.map +1 -1
  20. package/eventBridge/register.d.ts +4 -0
  21. package/eventBridge/register.js +19 -0
  22. package/eventBridge/register.js.map +1 -0
  23. package/execute.d.ts +1 -1
  24. package/execute.js +18 -23
  25. package/execute.js.map +1 -1
  26. package/gateway/index.d.ts +7 -11
  27. package/gateway/index.js +27 -57
  28. package/gateway/index.js.map +1 -1
  29. package/gateway/register.d.ts +1 -0
  30. package/gateway/register.js +19 -0
  31. package/gateway/register.js.map +1 -0
  32. package/index.d.ts +35 -6
  33. package/index.js +41 -238
  34. package/index.js.map +1 -1
  35. package/package.json +15 -22
  36. package/plugins/handlerClient.js +11 -27
  37. package/plugins/handlerClient.js.map +1 -1
  38. package/plugins/index.d.ts +1 -1
  39. package/plugins/index.js +4 -12
  40. package/plugins/index.js.map +1 -1
  41. package/raw/index.d.ts +5 -10
  42. package/raw/index.js +32 -57
  43. package/raw/index.js.map +1 -1
  44. package/raw/plugins/RawEventHandler.d.ts +17 -6
  45. package/raw/plugins/RawEventHandler.js +21 -18
  46. package/raw/plugins/RawEventHandler.js.map +1 -1
  47. package/registry.d.ts +17 -0
  48. package/registry.js +38 -0
  49. package/registry.js.map +1 -0
  50. package/s3/index.d.ts +6 -9
  51. package/s3/index.js +29 -59
  52. package/s3/index.js.map +1 -1
  53. package/s3/plugins/S3EventHandler.d.ts +8 -7
  54. package/s3/plugins/S3EventHandler.js +5 -22
  55. package/s3/plugins/S3EventHandler.js.map +1 -1
  56. package/s3/register.d.ts +4 -0
  57. package/s3/register.js +23 -0
  58. package/s3/register.js.map +1 -0
  59. package/sns/index.d.ts +8 -0
  60. package/sns/index.js +57 -0
  61. package/sns/index.js.map +1 -0
  62. package/sns/plugins/SNSEventHandler.d.ts +20 -0
  63. package/sns/plugins/SNSEventHandler.js +13 -0
  64. package/sns/plugins/SNSEventHandler.js.map +1 -0
  65. package/sns/register.d.ts +1 -0
  66. package/sns/register.js +23 -0
  67. package/sns/register.js.map +1 -0
  68. package/sourceHandler.d.ts +2 -0
  69. package/sourceHandler.js +5 -0
  70. package/sourceHandler.js.map +1 -0
  71. package/sqs/index.d.ts +6 -9
  72. package/sqs/index.js +33 -60
  73. package/sqs/index.js.map +1 -1
  74. package/sqs/plugins/SQSEventHandler.d.ts +8 -7
  75. package/sqs/plugins/SQSEventHandler.js +5 -22
  76. package/sqs/plugins/SQSEventHandler.js.map +1 -1
  77. package/sqs/register.d.ts +1 -0
  78. package/sqs/register.js +26 -0
  79. package/sqs/register.js.map +1 -0
  80. package/types.d.ts +28 -5
  81. package/types.js +7 -30
  82. package/types.js.map +1 -1
  83. package/utils/composedHandler.d.ts +6 -0
  84. package/utils/composedHandler.js +17 -0
  85. package/utils/composedHandler.js.map +1 -0
  86. package/utils/index.d.ts +2 -0
  87. package/utils/index.js +4 -0
  88. package/utils/index.js.map +1 -0
  89. package/utils/timer/CustomTimer.d.ts +5 -0
  90. package/utils/timer/CustomTimer.js +12 -0
  91. package/utils/timer/CustomTimer.js.map +1 -0
  92. package/utils/timer/Timer.d.ts +10 -0
  93. package/utils/timer/Timer.js +17 -0
  94. package/utils/timer/Timer.js.map +1 -0
  95. package/utils/timer/abstractions/ITimer.d.ts +10 -0
  96. package/utils/timer/abstractions/ITimer.js +3 -0
  97. package/utils/timer/abstractions/ITimer.js.map +1 -0
  98. package/utils/timer/factory.d.ts +4 -0
  99. package/utils/timer/factory.js +13 -0
  100. package/utils/timer/factory.js.map +1 -0
  101. package/utils/timer/index.d.ts +4 -0
  102. package/utils/timer/index.js +5 -0
  103. package/utils/timer/index.js.map +1 -0
@@ -0,0 +1,23 @@
1
+ import { registry } from "../registry.js";
2
+ import { createHandler } from "./index.js";
3
+ import { createSourceHandler } from "../sourceHandler.js";
4
+ const handler = createSourceHandler({
5
+ name: "handler-aws-sns",
6
+ canUse: event => {
7
+ if (!Array.isArray(event.Records) || event.Records.length === 0) {
8
+ return false;
9
+ }
10
+ const [record] = event.Records;
11
+ return !!record.Sns;
12
+ },
13
+ handle: async ({
14
+ params,
15
+ event,
16
+ context
17
+ }) => {
18
+ return createHandler(params)(event, context);
19
+ }
20
+ });
21
+ registry.register(handler);
22
+
23
+ //# sourceMappingURL=register.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["registry","createHandler","createSourceHandler","handler","name","canUse","event","Array","isArray","Records","length","record","Sns","handle","params","context","register"],"sources":["register.ts"],"sourcesContent":["import type { SNSEvent } from \"@webiny/aws-sdk/types/index.js\";\nimport { registry } from \"~/registry.js\";\nimport type { HandlerParams } from \"./index.js\";\nimport { createHandler } from \"./index.js\";\nimport { createSourceHandler } from \"~/sourceHandler.js\";\n\nconst handler = createSourceHandler<SNSEvent, HandlerParams>({\n name: \"handler-aws-sns\",\n canUse: event => {\n if (!Array.isArray(event.Records) || event.Records.length === 0) {\n return false;\n }\n const [record] = event.Records;\n return !!record.Sns;\n },\n handle: async ({ params, event, context }) => {\n return createHandler(params)(event, context);\n }\n});\n\nregistry.register(handler);\n"],"mappings":"AACA,SAASA,QAAQ;AAEjB,SAASC,aAAa;AACtB,SAASC,mBAAmB;AAE5B,MAAMC,OAAO,GAAGD,mBAAmB,CAA0B;EACzDE,IAAI,EAAE,iBAAiB;EACvBC,MAAM,EAAEC,KAAK,IAAI;IACb,IAAI,CAACC,KAAK,CAACC,OAAO,CAACF,KAAK,CAACG,OAAO,CAAC,IAAIH,KAAK,CAACG,OAAO,CAACC,MAAM,KAAK,CAAC,EAAE;MAC7D,OAAO,KAAK;IAChB;IACA,MAAM,CAACC,MAAM,CAAC,GAAGL,KAAK,CAACG,OAAO;IAC9B,OAAO,CAAC,CAACE,MAAM,CAACC,GAAG;EACvB,CAAC;EACDC,MAAM,EAAE,MAAAA,CAAO;IAAEC,MAAM;IAAER,KAAK;IAAES;EAAQ,CAAC,KAAK;IAC1C,OAAOd,aAAa,CAACa,MAAM,CAAC,CAACR,KAAK,EAAES,OAAO,CAAC;EAChD;AACJ,CAAC,CAAC;AAEFf,QAAQ,CAACgB,QAAQ,CAACb,OAAO,CAAC","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ import type { SourceHandler, HandlerEvent, HandlerFactoryParams } from "./types.js";
2
+ export declare const createSourceHandler: <TEvent = HandlerEvent, TParams extends HandlerFactoryParams = HandlerFactoryParams>(handler: SourceHandler<TEvent, TParams>) => SourceHandler<TEvent, TParams, any>;
@@ -0,0 +1,5 @@
1
+ export const createSourceHandler = handler => {
2
+ return handler;
3
+ };
4
+
5
+ //# sourceMappingURL=sourceHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createSourceHandler","handler"],"sources":["sourceHandler.ts"],"sourcesContent":["import type { SourceHandler, HandlerEvent, HandlerFactoryParams } from \"~/types.js\";\n\nexport const createSourceHandler = <\n TEvent = HandlerEvent,\n TParams extends HandlerFactoryParams = HandlerFactoryParams\n>(\n handler: SourceHandler<TEvent, TParams>\n) => {\n return handler;\n};\n"],"mappings":"AAEA,OAAO,MAAMA,mBAAmB,GAI5BC,OAAuC,IACtC;EACD,OAAOA,OAAO;AAClB,CAAC","ignoreList":[]}
package/sqs/index.d.ts CHANGED
@@ -1,11 +1,8 @@
1
- import { CreateHandlerParams as BaseCreateHandlerParams } from "@webiny/handler";
2
- import { SQSEvent, Context as LambdaContext } from "aws-lambda";
3
- import { APIGatewayProxyResult } from "aws-lambda/trigger/api-gateway-proxy";
1
+ import type { APIGatewayProxyResult, Context as LambdaContext, SQSEvent } from "@webiny/aws-sdk/types/index.js";
2
+ import type { HandlerFactoryParams } from "../types.js";
3
+ export * from "./plugins/SQSEventHandler.js";
4
4
  export interface HandlerCallable {
5
- (payload: SQSEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;
5
+ (event: SQSEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;
6
6
  }
7
- export interface CreateHandlerParams extends BaseCreateHandlerParams {
8
- debug?: boolean;
9
- }
10
- export declare const createHandler: (params: CreateHandlerParams) => HandlerCallable;
11
- export * from "./plugins/SQSEventHandler";
7
+ export type HandlerParams = HandlerFactoryParams;
8
+ export declare const createHandler: (params: HandlerParams) => HandlerCallable;
package/sqs/index.js CHANGED
@@ -1,87 +1,60 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- var _exportNames = {
9
- createHandler: true
10
- };
11
- exports.createHandler = void 0;
12
-
13
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
14
-
15
- var _handler = require("@webiny/handler");
16
-
17
- var _SQSEventHandler = require("./plugins/SQSEventHandler");
18
-
19
- Object.keys(_SQSEventHandler).forEach(function (key) {
20
- if (key === "default" || key === "__esModule") return;
21
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
22
- if (key in exports && exports[key] === _SQSEventHandler[key]) return;
23
- Object.defineProperty(exports, key, {
24
- enumerable: true,
25
- get: function () {
26
- return _SQSEventHandler[key];
27
- }
28
- });
29
- });
30
-
31
- var _plugins = require("../plugins");
32
-
33
- var _execute = require("../execute");
34
-
35
- const Reply = require("fastify/lib/reply");
36
-
1
+ import { createHandler as createBaseHandler } from "@webiny/handler";
2
+ import { registerDefaultPlugins } from "../plugins/index.js";
3
+ import { SQSEventHandler } from "./plugins/SQSEventHandler.js";
4
+ import { execute } from "../execute.js";
5
+ /**
6
+ * We need a class, not an interface exported from types.
7
+ */
8
+ // @ts-expect-error
9
+ import Reply from "fastify/lib/reply.js";
10
+ import { createComposedHandler } from "../utils/composedHandler.js";
11
+ export * from "./plugins/SQSEventHandler.js";
37
12
  const url = "/webiny-sqs-event";
38
-
39
- const createHandler = params => {
40
- return (payload, context) => {
41
- const app = (0, _handler.createHandler)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
42
- options: (0, _objectSpread2.default)({
43
- logger: params.debug === true
44
- }, params.options || {})
45
- }));
13
+ export const createHandler = params => {
14
+ return async (event, context) => {
15
+ const app = createBaseHandler({
16
+ ...params,
17
+ options: {
18
+ logger: params.debug === true,
19
+ ...(params.options || {})
20
+ }
21
+ });
46
22
  /**
47
23
  * We always must add our default plugins to the app.
48
24
  */
49
-
50
- (0, _plugins.registerDefaultPlugins)(app.webiny);
25
+ registerDefaultPlugins(app.webiny);
51
26
  /**
52
27
  * There must be an event plugin for this handler to work.
53
28
  */
54
-
55
- const plugins = app.webiny.plugins.byType(_SQSEventHandler.SQSEventHandler.type);
56
- const handler = plugins.shift();
57
-
58
- if (!handler) {
29
+ const plugins = app.webiny.plugins.byType(SQSEventHandler.type).reverse();
30
+ if (plugins.length === 0) {
59
31
  throw new Error(`To run @webiny/handler-aws/sqs, you must have SQSEventHandler set.`);
60
32
  }
61
-
33
+ const handler = createComposedHandler(plugins);
62
34
  app.post(url, async (request, reply) => {
63
35
  const params = {
64
36
  request,
65
37
  reply,
66
38
  context: app.webiny,
67
- event: payload,
39
+ event,
68
40
  lambdaContext: context
69
41
  };
70
- const result = await handler.cb(params);
71
-
42
+ const result = await handler(params);
72
43
  if (result instanceof Reply) {
73
44
  return result;
74
45
  }
75
-
76
46
  app.__webiny_raw_result = result;
77
- return reply.send({});
47
+ if (!reply.sent) {
48
+ reply.send({});
49
+ }
50
+ return reply;
78
51
  });
79
- return (0, _execute.execute)({
52
+ return execute({
80
53
  app,
81
54
  url,
82
- payload
55
+ payload: event
83
56
  });
84
57
  };
85
58
  };
86
59
 
87
- exports.createHandler = createHandler;
60
+ //# sourceMappingURL=index.js.map
package/sqs/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["Reply","require","url","createHandler","params","payload","context","app","createBaseHandler","options","logger","debug","registerDefaultPlugins","webiny","plugins","byType","SQSEventHandler","type","handler","shift","Error","post","request","reply","event","lambdaContext","result","cb","__webiny_raw_result","send","execute"],"sources":["index.ts"],"sourcesContent":["import {\n createHandler as createBaseHandler,\n CreateHandlerParams as BaseCreateHandlerParams\n} from \"@webiny/handler\";\nconst Reply = require(\"fastify/lib/reply\");\nimport { SQSEvent, Context as LambdaContext } from \"aws-lambda\";\nimport { SQSEventHandler, SQSEventHandlerCallableParams } from \"./plugins/SQSEventHandler\";\nimport { APIGatewayProxyResult } from \"aws-lambda/trigger/api-gateway-proxy\";\nimport { registerDefaultPlugins } from \"~/plugins\";\nimport { execute } from \"~/execute\";\n\nconst url = \"/webiny-sqs-event\";\n\nexport interface HandlerCallable {\n (payload: SQSEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;\n}\n\nexport interface CreateHandlerParams extends BaseCreateHandlerParams {\n debug?: boolean;\n}\n\nexport const createHandler = (params: CreateHandlerParams): HandlerCallable => {\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.byType<SQSEventHandler>(SQSEventHandler.type);\n const handler = plugins.shift();\n if (!handler) {\n throw new Error(`To run @webiny/handler-aws/sqs, you must have SQSEventHandler set.`);\n }\n\n app.post(url, async (request, reply) => {\n const params: SQSEventHandlerCallableParams = {\n request,\n reply,\n context: app.webiny,\n event: payload,\n lambdaContext: context\n };\n const result = await handler.cb(params);\n\n if (result instanceof Reply) {\n return result;\n }\n\n (app as any).__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/SQSEventHandler\";\n"],"mappings":";;;;;;;;;;;;;;AAAA;;AAMA;;AA8DA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AA5DA;;AACA;;AALA,MAAMA,KAAK,GAAGC,OAAO,CAAC,mBAAD,CAArB;;AAOA,MAAMC,GAAG,GAAG,mBAAZ;;AAUO,MAAMC,aAAa,GAAIC,MAAD,IAAkD;EAC3E,OAAO,CAACC,OAAD,EAAUC,OAAV,KAAsB;IACzB,MAAMC,GAAG,GAAG,IAAAC,sBAAA,8DACLJ,MADK;MAERK,OAAO;QACHC,MAAM,EAAEN,MAAM,CAACO,KAAP,KAAiB;MADtB,GAECP,MAAM,CAACK,OAAP,IAAkB,EAFnB;IAFC,GAAZ;IAOA;AACR;AACA;;IACQ,IAAAG,+BAAA,EAAuBL,GAAG,CAACM,MAA3B;IACA;AACR;AACA;;IACQ,MAAMC,OAAO,GAAGP,GAAG,CAACM,MAAJ,CAAWC,OAAX,CAAmBC,MAAnB,CAA2CC,gCAAA,CAAgBC,IAA3D,CAAhB;IACA,MAAMC,OAAO,GAAGJ,OAAO,CAACK,KAAR,EAAhB;;IACA,IAAI,CAACD,OAAL,EAAc;MACV,MAAM,IAAIE,KAAJ,CAAW,oEAAX,CAAN;IACH;;IAEDb,GAAG,CAACc,IAAJ,CAASnB,GAAT,EAAc,OAAOoB,OAAP,EAAgBC,KAAhB,KAA0B;MACpC,MAAMnB,MAAqC,GAAG;QAC1CkB,OAD0C;QAE1CC,KAF0C;QAG1CjB,OAAO,EAAEC,GAAG,CAACM,MAH6B;QAI1CW,KAAK,EAAEnB,OAJmC;QAK1CoB,aAAa,EAAEnB;MAL2B,CAA9C;MAOA,MAAMoB,MAAM,GAAG,MAAMR,OAAO,CAACS,EAAR,CAAWvB,MAAX,CAArB;;MAEA,IAAIsB,MAAM,YAAY1B,KAAtB,EAA6B;QACzB,OAAO0B,MAAP;MACH;;MAEAnB,GAAD,CAAaqB,mBAAb,GAAmCF,MAAnC;MACA,OAAOH,KAAK,CAACM,IAAN,CAAW,EAAX,CAAP;IACH,CAhBD;IAiBA,OAAO,IAAAC,gBAAA,EAAQ;MACXvB,GADW;MAEXL,GAFW;MAGXG;IAHW,CAAR,CAAP;EAKH,CA3CD;AA4CH,CA7CM"}
1
+ {"version":3,"names":["createHandler","createBaseHandler","registerDefaultPlugins","SQSEventHandler","execute","Reply","createComposedHandler","url","params","event","context","app","options","logger","debug","webiny","plugins","byType","type","reverse","length","Error","handler","post","request","reply","lambdaContext","result","__webiny_raw_result","sent","send","payload"],"sources":["index.ts"],"sourcesContent":["import type {\n APIGatewayProxyResult,\n Context as LambdaContext,\n SQSEvent\n} from \"@webiny/aws-sdk/types/index.js\";\nimport { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins/index.js\";\nimport type { SQSEventHandlerCallableParams } from \"~/sqs/plugins/SQSEventHandler.js\";\nimport { SQSEventHandler } from \"~/sqs/plugins/SQSEventHandler.js\";\nimport { execute } from \"~/execute.js\";\nimport type { HandlerFactoryParams } from \"~/types.js\";\n/**\n * We need a class, not an interface exported from types.\n */\n// @ts-expect-error\nimport Reply from \"fastify/lib/reply.js\";\nimport { createComposedHandler } from \"~/utils/composedHandler.js\";\n\nexport * from \"./plugins/SQSEventHandler.js\";\n\nexport interface HandlerCallable {\n (event: SQSEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;\n}\n\nexport type HandlerParams = HandlerFactoryParams;\n\nconst url = \"/webiny-sqs-event\";\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 * There must be an event plugin for this handler to work.\n */\n const plugins = app.webiny.plugins.byType<SQSEventHandler>(SQSEventHandler.type).reverse();\n if (plugins.length === 0) {\n throw new Error(`To run @webiny/handler-aws/sqs, you must have SQSEventHandler set.`);\n }\n\n const handler = createComposedHandler<\n SQSEventHandler,\n SQSEventHandlerCallableParams<APIGatewayProxyResult>,\n APIGatewayProxyResult\n >(plugins);\n\n app.post(url, async (request, reply) => {\n const params: Omit<SQSEventHandlerCallableParams<APIGatewayProxyResult>, \"next\"> = {\n request,\n reply,\n context: app.webiny,\n event,\n lambdaContext: context\n };\n\n const result = await handler(\n params as unknown as SQSEventHandlerCallableParams<APIGatewayProxyResult>\n );\n\n if (result instanceof Reply) {\n return result;\n }\n\n app.__webiny_raw_result = result;\n if (!reply.sent) {\n reply.send({});\n }\n return reply;\n });\n return execute({\n app,\n url,\n payload: event\n });\n };\n};\n"],"mappings":"AAKA,SAASA,aAAa,IAAIC,iBAAiB,QAAQ,iBAAiB;AACpE,SAASC,sBAAsB;AAE/B,SAASC,eAAe;AACxB,SAASC,OAAO;AAEhB;AACA;AACA;AACA;AACA,OAAOC,KAAK,MAAM,sBAAsB;AACxC,SAASC,qBAAqB;AAE9B;AAQA,MAAMC,GAAG,GAAG,mBAAmB;AAE/B,OAAO,MAAMP,aAAa,GAAIQ,MAAqB,IAAsB;EACrE,OAAO,OAAOC,KAAK,EAAEC,OAAO,KAAK;IAC7B,MAAMC,GAAG,GAAGV,iBAAiB,CAAC;MAC1B,GAAGO,MAAM;MACTI,OAAO,EAAE;QACLC,MAAM,EAAEL,MAAM,CAACM,KAAK,KAAK,IAAI;QAC7B,IAAIN,MAAM,CAACI,OAAO,IAAI,CAAC,CAAC;MAC5B;IACJ,CAAC,CAAC;IACF;AACR;AACA;IACQV,sBAAsB,CAACS,GAAG,CAACI,MAAM,CAAC;IAClC;AACR;AACA;IACQ,MAAMC,OAAO,GAAGL,GAAG,CAACI,MAAM,CAACC,OAAO,CAACC,MAAM,CAAkBd,eAAe,CAACe,IAAI,CAAC,CAACC,OAAO,CAAC,CAAC;IAC1F,IAAIH,OAAO,CAACI,MAAM,KAAK,CAAC,EAAE;MACtB,MAAM,IAAIC,KAAK,CAAC,oEAAoE,CAAC;IACzF;IAEA,MAAMC,OAAO,GAAGhB,qBAAqB,CAInCU,OAAO,CAAC;IAEVL,GAAG,CAACY,IAAI,CAAChB,GAAG,EAAE,OAAOiB,OAAO,EAAEC,KAAK,KAAK;MACpC,MAAMjB,MAA0E,GAAG;QAC/EgB,OAAO;QACPC,KAAK;QACLf,OAAO,EAAEC,GAAG,CAACI,MAAM;QACnBN,KAAK;QACLiB,aAAa,EAAEhB;MACnB,CAAC;MAED,MAAMiB,MAAM,GAAG,MAAML,OAAO,CACxBd,MACJ,CAAC;MAED,IAAImB,MAAM,YAAYtB,KAAK,EAAE;QACzB,OAAOsB,MAAM;MACjB;MAEAhB,GAAG,CAACiB,mBAAmB,GAAGD,MAAM;MAChC,IAAI,CAACF,KAAK,CAACI,IAAI,EAAE;QACbJ,KAAK,CAACK,IAAI,CAAC,CAAC,CAAC,CAAC;MAClB;MACA,OAAOL,KAAK;IAChB,CAAC,CAAC;IACF,OAAOrB,OAAO,CAAC;MACXO,GAAG;MACHJ,GAAG;MACHwB,OAAO,EAAEtB;IACb,CAAC,CAAC;EACN,CAAC;AACL,CAAC","ignoreList":[]}
@@ -1,19 +1,20 @@
1
- import { Plugin } from "@webiny/plugins/Plugin";
2
- import { Request, Reply, Context } from "@webiny/handler/types";
3
- import { SQSEvent, Context as LambdaContext } from "aws-lambda";
4
- export interface SQSEventHandlerCallableParams {
1
+ import type { Context as LambdaContext, SQSEvent } from "@webiny/aws-sdk/types/index.js";
2
+ import { Plugin } from "@webiny/plugins/Plugin.js";
3
+ import type { Context, Reply, Request } from "@webiny/handler/types.js";
4
+ export interface SQSEventHandlerCallableParams<Response = Reply> {
5
5
  request: Request;
6
6
  reply: Reply;
7
7
  context: Context;
8
8
  event: SQSEvent;
9
9
  lambdaContext: LambdaContext;
10
+ next: () => Promise<Response>;
10
11
  }
11
- export interface SQSEventHandlerCallable<Response> {
12
- (params: SQSEventHandlerCallableParams): Promise<Response | Reply>;
12
+ export interface SQSEventHandlerCallable<Response = Reply> {
13
+ (params: SQSEventHandlerCallableParams<Response>): Promise<Response>;
13
14
  }
14
15
  export declare class SQSEventHandler<Response = any> extends Plugin {
15
16
  static type: string;
16
17
  readonly cb: SQSEventHandlerCallable<Response>;
17
18
  constructor(cb: SQSEventHandlerCallable<Response>);
18
19
  }
19
- export declare const createEventHandler: <Response_1>(cb: SQSEventHandlerCallable<Response_1>) => SQSEventHandler<Response_1>;
20
+ export declare const createEventHandler: <Response>(cb: SQSEventHandlerCallable<Response>) => SQSEventHandler<Response>;
@@ -1,30 +1,13 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.createEventHandler = exports.SQSEventHandler = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
- var _Plugin = require("@webiny/plugins/Plugin");
13
-
14
- class SQSEventHandler extends _Plugin.Plugin {
1
+ import { Plugin } from "@webiny/plugins/Plugin.js";
2
+ export class SQSEventHandler extends Plugin {
3
+ static type = "handler.fastify.aws.sqs.eventHandler";
15
4
  constructor(cb) {
16
5
  super();
17
- (0, _defineProperty2.default)(this, "cb", void 0);
18
6
  this.cb = cb;
19
7
  }
20
-
21
8
  }
22
-
23
- exports.SQSEventHandler = SQSEventHandler;
24
- (0, _defineProperty2.default)(SQSEventHandler, "type", "handler.fastify.aws.sqs.eventHandler");
25
-
26
- const createEventHandler = cb => {
9
+ export const createEventHandler = cb => {
27
10
  return new SQSEventHandler(cb);
28
11
  };
29
12
 
30
- exports.createEventHandler = createEventHandler;
13
+ //# sourceMappingURL=SQSEventHandler.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["SQSEventHandler","Plugin","constructor","cb","createEventHandler"],"sources":["SQSEventHandler.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport { Request, Reply, Context } from \"@webiny/handler/types\";\nimport { SQSEvent, Context as LambdaContext } from \"aws-lambda\";\n\nexport interface SQSEventHandlerCallableParams {\n request: Request;\n reply: Reply;\n context: Context;\n event: SQSEvent;\n lambdaContext: LambdaContext;\n}\nexport interface SQSEventHandlerCallable<Response> {\n (params: SQSEventHandlerCallableParams): Promise<Response | Reply>;\n}\n\nexport class SQSEventHandler<Response = any> extends Plugin {\n public static override type = \"handler.fastify.aws.sqs.eventHandler\";\n\n public readonly cb: SQSEventHandlerCallable<Response>;\n\n public constructor(cb: SQSEventHandlerCallable<Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEventHandler = <Response>(cb: SQSEventHandlerCallable<Response>) => {\n return new SQSEventHandler<Response>(cb);\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAeO,MAAMA,eAAN,SAA8CC,cAA9C,CAAqD;EAKjDC,WAAW,CAACC,EAAD,EAAwC;IACtD;IADsD;IAEtD,KAAKA,EAAL,GAAUA,EAAV;EACH;;AARuD;;;8BAA/CH,e,UACqB,sC;;AAU3B,MAAMI,kBAAkB,GAAcD,EAAX,IAAqD;EACnF,OAAO,IAAIH,eAAJ,CAA8BG,EAA9B,CAAP;AACH,CAFM"}
1
+ {"version":3,"names":["Plugin","SQSEventHandler","type","constructor","cb","createEventHandler"],"sources":["SQSEventHandler.ts"],"sourcesContent":["import type { Context as LambdaContext, SQSEvent } from \"@webiny/aws-sdk/types/index.js\";\nimport { Plugin } from \"@webiny/plugins/Plugin.js\";\nimport type { Context, Reply, Request } from \"@webiny/handler/types.js\";\n\nexport interface SQSEventHandlerCallableParams<Response = Reply> {\n request: Request;\n reply: Reply;\n context: Context;\n event: SQSEvent;\n lambdaContext: LambdaContext;\n next: () => Promise<Response>;\n}\n\nexport interface SQSEventHandlerCallable<Response = Reply> {\n (params: SQSEventHandlerCallableParams<Response>): Promise<Response>;\n}\n\nexport class SQSEventHandler<Response = any> extends Plugin {\n public static override type = \"handler.fastify.aws.sqs.eventHandler\";\n\n public readonly cb: SQSEventHandlerCallable<Response>;\n\n public constructor(cb: SQSEventHandlerCallable<Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEventHandler = <Response>(cb: SQSEventHandlerCallable<Response>) => {\n return new SQSEventHandler<Response>(cb);\n};\n"],"mappings":"AACA,SAASA,MAAM,QAAQ,2BAA2B;AAgBlD,OAAO,MAAMC,eAAe,SAAyBD,MAAM,CAAC;EACxD,OAAuBE,IAAI,GAAG,sCAAsC;EAI7DC,WAAWA,CAACC,EAAqC,EAAE;IACtD,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;AACJ;AAEA,OAAO,MAAMC,kBAAkB,GAAcD,EAAqC,IAAK;EACnF,OAAO,IAAIH,eAAe,CAAWG,EAAE,CAAC;AAC5C,CAAC","ignoreList":[]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,26 @@
1
+ import { registry } from "../registry.js";
2
+ import { createHandler } from "./index.js";
3
+ import { createSourceHandler } from "../sourceHandler.js";
4
+ const handler = createSourceHandler({
5
+ name: "handler-aws-sqs",
6
+ canUse: event => {
7
+ if (!Array.isArray(event.Records) || event.Records.length === 0) {
8
+ return false;
9
+ }
10
+ const [record] = event.Records;
11
+ if (typeof record.eventSource !== "string") {
12
+ return false;
13
+ }
14
+ return record.eventSource.toLowerCase() === "aws:sqs";
15
+ },
16
+ handle: async ({
17
+ params,
18
+ event,
19
+ context
20
+ }) => {
21
+ return createHandler(params)(event, context);
22
+ }
23
+ });
24
+ registry.register(handler);
25
+
26
+ //# sourceMappingURL=register.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["registry","createHandler","createSourceHandler","handler","name","canUse","event","Array","isArray","Records","length","record","eventSource","toLowerCase","handle","params","context","register"],"sources":["register.ts"],"sourcesContent":["import type { SQSEvent } from \"@webiny/aws-sdk/types/index.js\";\nimport { registry } from \"~/registry.js\";\nimport type { HandlerParams } from \"./index.js\";\nimport { createHandler } from \"./index.js\";\nimport { createSourceHandler } from \"~/sourceHandler.js\";\n\nconst handler = createSourceHandler<SQSEvent, HandlerParams>({\n name: \"handler-aws-sqs\",\n canUse: event => {\n if (!Array.isArray(event.Records) || event.Records.length === 0) {\n return false;\n }\n const [record] = event.Records;\n if (typeof record.eventSource !== \"string\") {\n return false;\n }\n return record.eventSource.toLowerCase() === \"aws:sqs\";\n },\n handle: async ({ params, event, context }) => {\n return createHandler(params)(event, context);\n }\n});\n\nregistry.register(handler);\n"],"mappings":"AACA,SAASA,QAAQ;AAEjB,SAASC,aAAa;AACtB,SAASC,mBAAmB;AAE5B,MAAMC,OAAO,GAAGD,mBAAmB,CAA0B;EACzDE,IAAI,EAAE,iBAAiB;EACvBC,MAAM,EAAEC,KAAK,IAAI;IACb,IAAI,CAACC,KAAK,CAACC,OAAO,CAACF,KAAK,CAACG,OAAO,CAAC,IAAIH,KAAK,CAACG,OAAO,CAACC,MAAM,KAAK,CAAC,EAAE;MAC7D,OAAO,KAAK;IAChB;IACA,MAAM,CAACC,MAAM,CAAC,GAAGL,KAAK,CAACG,OAAO;IAC9B,IAAI,OAAOE,MAAM,CAACC,WAAW,KAAK,QAAQ,EAAE;MACxC,OAAO,KAAK;IAChB;IACA,OAAOD,MAAM,CAACC,WAAW,CAACC,WAAW,CAAC,CAAC,KAAK,SAAS;EACzD,CAAC;EACDC,MAAM,EAAE,MAAAA,CAAO;IAAEC,MAAM;IAAET,KAAK;IAAEU;EAAQ,CAAC,KAAK;IAC1C,OAAOf,aAAa,CAACc,MAAM,CAAC,CAACT,KAAK,EAAEU,OAAO,CAAC;EAChD;AACJ,CAAC,CAAC;AAEFhB,QAAQ,CAACiB,QAAQ,CAACd,OAAO,CAAC","ignoreList":[]}
package/types.d.ts CHANGED
@@ -1,14 +1,37 @@
1
- import { APIGatewayEvent, Context as LambdaContext } from "aws-lambda";
1
+ import type { APIGatewayEvent, APIGatewayEventRequestContextWithAuthorizer, AttributeValue, Context as LambdaContext, DynamoDBRecord, DynamoDBStreamEvent, EventBridgeEvent, S3Event, SNSEvent, SQSEvent } from "@webiny/aws-sdk/types/index.js";
2
2
  import "fastify";
3
- export * from "@webiny/handler/types";
3
+ import type { CreateHandlerParams as BaseCreateHandlerParams } from "@webiny/handler";
4
+ import type { LambdaFastifyOptions as LambdaOptions } from "@fastify/aws-lambda";
5
+ import type { GenericRecord } from "@webiny/utils";
6
+ export type { AttributeValue, DynamoDBRecord };
7
+ export type { HandlerRegistry } from "./registry.js";
8
+ export * from "@webiny/handler/types.js";
9
+ export type { APIGatewayEvent, LambdaContext, APIGatewayEventRequestContextWithAuthorizer };
10
+ export type HandlerEvent = APIGatewayEvent | SNSEvent | SQSEvent | S3Event | EventBridgeEvent<string, string> | DynamoDBStreamEvent | GenericRecord<string>;
11
+ export interface EventResolver<T = any> {
12
+ (event: HandlerEvent, context: LambdaContext): T;
13
+ }
14
+ export interface HandlerFactoryParams extends BaseCreateHandlerParams {
15
+ lambdaOptions?: LambdaOptions;
16
+ }
17
+ export interface HandlerFactory<T extends HandlerFactoryParams = HandlerFactoryParams, R = any> {
18
+ (params: T): EventResolver<R>;
19
+ }
20
+ export interface HandlerParams<E, P extends HandlerFactoryParams> {
21
+ params: P;
22
+ event: E;
23
+ context: LambdaContext;
24
+ }
25
+ export interface SourceHandler<E = HandlerEvent, P extends HandlerFactoryParams = HandlerFactoryParams, T = any> {
26
+ name: string;
27
+ canUse: (event: Partial<E>, context: LambdaContext) => boolean;
28
+ handle: (params: HandlerParams<E, P>) => Promise<T>;
29
+ }
4
30
  export declare enum Base64EncodeHeader {
5
31
  encoded = "x-webiny-base64-encoded",
6
32
  binary = "x-webiny-binary"
7
33
  }
8
34
  declare module "fastify" {
9
- interface FastifyInstance {
10
- __webiny_raw_result: any;
11
- }
12
35
  interface FastifyRequest {
13
36
  awsLambda: {
14
37
  event: APIGatewayEvent;
package/types.js CHANGED
@@ -1,32 +1,9 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _exportNames = {
7
- Base64EncodeHeader: true
8
- };
9
- exports.Base64EncodeHeader = void 0;
10
-
11
- require("fastify");
12
-
13
- var _types = require("@webiny/handler/types");
14
-
15
- Object.keys(_types).forEach(function (key) {
16
- if (key === "default" || key === "__esModule") return;
17
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
18
- if (key in exports && exports[key] === _types[key]) return;
19
- Object.defineProperty(exports, key, {
20
- enumerable: true,
21
- get: function () {
22
- return _types[key];
23
- }
24
- });
25
- });
26
- let Base64EncodeHeader;
27
- exports.Base64EncodeHeader = Base64EncodeHeader;
28
-
29
- (function (Base64EncodeHeader) {
1
+ import "fastify";
2
+ export * from "@webiny/handler/types.js";
3
+ export let Base64EncodeHeader = /*#__PURE__*/function (Base64EncodeHeader) {
30
4
  Base64EncodeHeader["encoded"] = "x-webiny-base64-encoded";
31
5
  Base64EncodeHeader["binary"] = "x-webiny-binary";
32
- })(Base64EncodeHeader || (exports.Base64EncodeHeader = Base64EncodeHeader = {}));
6
+ return Base64EncodeHeader;
7
+ }({});
8
+
9
+ //# sourceMappingURL=types.js.map
package/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["Base64EncodeHeader"],"sources":["types.ts"],"sourcesContent":["import { APIGatewayEvent, Context as LambdaContext } from \"aws-lambda\";\nimport \"fastify\";\nexport * from \"@webiny/handler/types\";\n\nexport enum Base64EncodeHeader {\n encoded = \"x-webiny-base64-encoded\",\n binary = \"x-webiny-binary\"\n}\n\ndeclare module \"fastify\" {\n interface FastifyInstance {\n __webiny_raw_result: any;\n }\n interface FastifyRequest {\n awsLambda: {\n event: APIGatewayEvent;\n context: LambdaContext;\n };\n }\n}\n"],"mappings":";;;;;;;;;;AACA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;IAEYA,kB;;;WAAAA,kB;EAAAA,kB;EAAAA,kB;GAAAA,kB,kCAAAA,kB"}
1
+ {"version":3,"names":["Base64EncodeHeader"],"sources":["types.ts"],"sourcesContent":["import type {\n APIGatewayEvent,\n APIGatewayEventRequestContextWithAuthorizer,\n AttributeValue,\n Context as LambdaContext,\n DynamoDBRecord,\n DynamoDBStreamEvent,\n EventBridgeEvent,\n S3Event,\n SNSEvent,\n SQSEvent\n} from \"@webiny/aws-sdk/types/index.js\";\nimport \"fastify\";\nimport type { CreateHandlerParams as BaseCreateHandlerParams } from \"@webiny/handler\";\nimport type { LambdaFastifyOptions as LambdaOptions } from \"@fastify/aws-lambda\";\nimport type { GenericRecord } from \"@webiny/utils\";\n\nexport type { AttributeValue, DynamoDBRecord };\n\nexport type { HandlerRegistry } from \"~/registry.js\";\n\nexport * from \"@webiny/handler/types.js\";\n\nexport type { APIGatewayEvent, LambdaContext, APIGatewayEventRequestContextWithAuthorizer };\n\nexport type HandlerEvent =\n | APIGatewayEvent\n | SNSEvent\n | SQSEvent\n | S3Event\n | EventBridgeEvent<string, string>\n | DynamoDBStreamEvent\n | GenericRecord<string>;\n\nexport interface EventResolver<T = any> {\n (event: HandlerEvent, context: LambdaContext): T;\n}\n\nexport interface HandlerFactoryParams extends BaseCreateHandlerParams {\n lambdaOptions?: LambdaOptions;\n}\n\nexport interface HandlerFactory<T extends HandlerFactoryParams = HandlerFactoryParams, R = any> {\n (params: T): EventResolver<R>;\n}\n\nexport interface HandlerParams<E, P extends HandlerFactoryParams> {\n params: P;\n event: E;\n context: LambdaContext;\n}\n\nexport interface SourceHandler<\n E = HandlerEvent,\n P extends HandlerFactoryParams = HandlerFactoryParams,\n T = any\n> {\n name: string;\n canUse: (event: Partial<E>, context: LambdaContext) => boolean;\n handle: (params: HandlerParams<E, P>) => Promise<T>;\n}\n\nexport enum Base64EncodeHeader {\n encoded = \"x-webiny-base64-encoded\",\n binary = \"x-webiny-binary\"\n}\n\ndeclare module \"fastify\" {\n interface FastifyRequest {\n awsLambda: {\n event: APIGatewayEvent;\n context: LambdaContext;\n };\n }\n}\n"],"mappings":"AAYA,OAAO,SAAS;AAShB,cAAc,0BAA0B;AAyCxC,WAAYA,kBAAkB,0BAAlBA,kBAAkB;EAAlBA,kBAAkB;EAAlBA,kBAAkB;EAAA,OAAlBA,kBAAkB;AAAA","ignoreList":[]}
@@ -0,0 +1,6 @@
1
+ import type { Plugin } from "@webiny/plugins/types.js";
2
+ type WrappedInput<TInput, TOutput> = TInput & {
3
+ next: () => Promise<TOutput>;
4
+ };
5
+ export declare const createComposedHandler: <P extends Plugin, TInput, TOutput>(plugins: P[]) => import("@webiny/utils").NextAsyncProcessor<WrappedInput<TInput, TOutput>, TOutput>;
6
+ export {};
@@ -0,0 +1,17 @@
1
+ import { composeAsync } from "@webiny/utils";
2
+ export const createComposedHandler = plugins => {
3
+ return composeAsync(plugins.map(plugin => {
4
+ return next => {
5
+ return async params => {
6
+ return plugin.cb({
7
+ ...params,
8
+ next: () => {
9
+ return next(params);
10
+ }
11
+ });
12
+ };
13
+ };
14
+ }));
15
+ };
16
+
17
+ //# sourceMappingURL=composedHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["composeAsync","createComposedHandler","plugins","map","plugin","next","params","cb"],"sources":["composedHandler.ts"],"sourcesContent":["import type { Plugin } from \"@webiny/plugins/types.js\";\nimport { composeAsync } from \"@webiny/utils\";\n\ntype WrappedInput<TInput, TOutput> = TInput & {\n next: () => Promise<TOutput>;\n};\n\nexport const createComposedHandler = <P extends Plugin, TInput, TOutput>(plugins: P[]) => {\n return composeAsync<WrappedInput<TInput, TOutput>, TOutput>(\n plugins.map(plugin => {\n return next => {\n return async params => {\n return plugin.cb({\n ...params,\n next: () => {\n return next(params);\n }\n });\n };\n };\n })\n );\n};\n"],"mappings":"AACA,SAASA,YAAY,QAAQ,eAAe;AAM5C,OAAO,MAAMC,qBAAqB,GAAuCC,OAAY,IAAK;EACtF,OAAOF,YAAY,CACfE,OAAO,CAACC,GAAG,CAACC,MAAM,IAAI;IAClB,OAAOC,IAAI,IAAI;MACX,OAAO,MAAMC,MAAM,IAAI;QACnB,OAAOF,MAAM,CAACG,EAAE,CAAC;UACb,GAAGD,MAAM;UACTD,IAAI,EAAEA,CAAA,KAAM;YACR,OAAOA,IAAI,CAACC,MAAM,CAAC;UACvB;QACJ,CAAC,CAAC;MACN,CAAC;IACL,CAAC;EACL,CAAC,CACL,CAAC;AACL,CAAC","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ export * from "./composedHandler.js";
2
+ export * from "./timer/index.js";
package/utils/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./composedHandler.js";
2
+ export * from "./timer/index.js";
3
+
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./composedHandler.js\";\nexport * from \"./timer/index.js\";\n"],"mappings":"AAAA;AACA","ignoreList":[]}
@@ -0,0 +1,5 @@
1
+ export declare class CustomTimer {
2
+ private readonly startTime;
3
+ constructor();
4
+ getRemainingMilliseconds(): number;
5
+ }
@@ -0,0 +1,12 @@
1
+ const MAX_RUNNING_MINUTES = 14;
2
+ const MAX_RUNNING_MILLISECONDS = MAX_RUNNING_MINUTES * 60 * 1000;
3
+ export class CustomTimer {
4
+ constructor() {
5
+ this.startTime = Date.now();
6
+ }
7
+ getRemainingMilliseconds() {
8
+ return this.startTime + MAX_RUNNING_MILLISECONDS - Date.now(); // 14 minutes
9
+ }
10
+ }
11
+
12
+ //# sourceMappingURL=CustomTimer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["MAX_RUNNING_MINUTES","MAX_RUNNING_MILLISECONDS","CustomTimer","constructor","startTime","Date","now","getRemainingMilliseconds"],"sources":["CustomTimer.ts"],"sourcesContent":["const MAX_RUNNING_MINUTES = 14;\nconst MAX_RUNNING_MILLISECONDS = MAX_RUNNING_MINUTES * 60 * 1000;\n\nexport class CustomTimer {\n private readonly startTime: number;\n\n public constructor() {\n this.startTime = Date.now();\n }\n\n public getRemainingMilliseconds(): number {\n return this.startTime + MAX_RUNNING_MILLISECONDS - Date.now(); // 14 minutes\n }\n}\n"],"mappings":"AAAA,MAAMA,mBAAmB,GAAG,EAAE;AAC9B,MAAMC,wBAAwB,GAAGD,mBAAmB,GAAG,EAAE,GAAG,IAAI;AAEhE,OAAO,MAAME,WAAW,CAAC;EAGdC,WAAWA,CAAA,EAAG;IACjB,IAAI,CAACC,SAAS,GAAGC,IAAI,CAACC,GAAG,CAAC,CAAC;EAC/B;EAEOC,wBAAwBA,CAAA,EAAW;IACtC,OAAO,IAAI,CAACH,SAAS,GAAGH,wBAAwB,GAAGI,IAAI,CAACC,GAAG,CAAC,CAAC,CAAC,CAAC;EACnE;AACJ","ignoreList":[]}
@@ -0,0 +1,10 @@
1
+ import type { ITimer } from "./abstractions/ITimer.js";
2
+ export interface ITimerCb {
3
+ (): number;
4
+ }
5
+ export declare class Timer implements ITimer {
6
+ private readonly cb;
7
+ constructor(cb: ITimerCb);
8
+ getRemainingMilliseconds(): number;
9
+ getRemainingSeconds(): number;
10
+ }
@@ -0,0 +1,17 @@
1
+ export class Timer {
2
+ constructor(cb) {
3
+ this.cb = cb;
4
+ }
5
+ getRemainingMilliseconds() {
6
+ return this.cb();
7
+ }
8
+ getRemainingSeconds() {
9
+ const result = this.cb();
10
+ if (result > 0) {
11
+ return Math.floor(result / 1000);
12
+ }
13
+ return 0;
14
+ }
15
+ }
16
+
17
+ //# sourceMappingURL=Timer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Timer","constructor","cb","getRemainingMilliseconds","getRemainingSeconds","result","Math","floor"],"sources":["Timer.ts"],"sourcesContent":["import type { ITimer } from \"./abstractions/ITimer.js\";\n\nexport interface ITimerCb {\n (): number;\n}\n\nexport class Timer implements ITimer {\n private readonly cb: ITimerCb;\n\n public constructor(cb: ITimerCb) {\n this.cb = cb;\n }\n public getRemainingMilliseconds(): number {\n return this.cb();\n }\n\n public getRemainingSeconds(): number {\n const result = this.cb();\n if (result > 0) {\n return Math.floor(result / 1000);\n }\n return 0;\n }\n}\n"],"mappings":"AAMA,OAAO,MAAMA,KAAK,CAAmB;EAG1BC,WAAWA,CAACC,EAAY,EAAE;IAC7B,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;EACOC,wBAAwBA,CAAA,EAAW;IACtC,OAAO,IAAI,CAACD,EAAE,CAAC,CAAC;EACpB;EAEOE,mBAAmBA,CAAA,EAAW;IACjC,MAAMC,MAAM,GAAG,IAAI,CAACH,EAAE,CAAC,CAAC;IACxB,IAAIG,MAAM,GAAG,CAAC,EAAE;MACZ,OAAOC,IAAI,CAACC,KAAK,CAACF,MAAM,GAAG,IAAI,CAAC;IACpC;IACA,OAAO,CAAC;EACZ;AACJ","ignoreList":[]}
@@ -0,0 +1,10 @@
1
+ export interface ITimer {
2
+ /**
3
+ * Return value must be in milliseconds.
4
+ */
5
+ getRemainingMilliseconds(): number;
6
+ /**
7
+ * Return value must be in seconds.
8
+ */
9
+ getRemainingSeconds(): number;
10
+ }
@@ -0,0 +1,3 @@
1
+ export {};
2
+
3
+ //# sourceMappingURL=ITimer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["ITimer.ts"],"sourcesContent":["export interface ITimer {\n /**\n * Return value must be in milliseconds.\n */\n getRemainingMilliseconds(): number;\n /**\n * Return value must be in seconds.\n */\n getRemainingSeconds(): number;\n}\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ import type { ITimer } from "./abstractions/ITimer.js";
2
+ import type { Context as LambdaContext } from "@webiny/aws-sdk/types/index.js";
3
+ export type ITimerFactoryParams = Pick<LambdaContext, "getRemainingTimeInMillis">;
4
+ export declare const timerFactory: (params?: Partial<ITimerFactoryParams>) => ITimer;
@@ -0,0 +1,13 @@
1
+ import { CustomTimer } from "./CustomTimer.js";
2
+ import { Timer } from "./Timer.js";
3
+ export const timerFactory = params => {
4
+ const customTimer = new CustomTimer();
5
+ return new Timer(() => {
6
+ if (params?.getRemainingTimeInMillis) {
7
+ return params.getRemainingTimeInMillis();
8
+ }
9
+ return customTimer.getRemainingMilliseconds();
10
+ });
11
+ };
12
+
13
+ //# sourceMappingURL=factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["CustomTimer","Timer","timerFactory","params","customTimer","getRemainingTimeInMillis","getRemainingMilliseconds"],"sources":["factory.ts"],"sourcesContent":["import type { ITimer } from \"./abstractions/ITimer.js\";\nimport { CustomTimer } from \"./CustomTimer.js\";\nimport type { Context as LambdaContext } from \"@webiny/aws-sdk/types/index.js\";\nimport { Timer } from \"./Timer.js\";\n\nexport type ITimerFactoryParams = Pick<LambdaContext, \"getRemainingTimeInMillis\">;\n\nexport const timerFactory = (params?: Partial<ITimerFactoryParams>): ITimer => {\n const customTimer = new CustomTimer();\n\n return new Timer(() => {\n if (params?.getRemainingTimeInMillis) {\n return params.getRemainingTimeInMillis();\n }\n return customTimer.getRemainingMilliseconds();\n });\n};\n"],"mappings":"AACA,SAASA,WAAW;AAEpB,SAASC,KAAK;AAId,OAAO,MAAMC,YAAY,GAAIC,MAAqC,IAAa;EAC3E,MAAMC,WAAW,GAAG,IAAIJ,WAAW,CAAC,CAAC;EAErC,OAAO,IAAIC,KAAK,CAAC,MAAM;IACnB,IAAIE,MAAM,EAAEE,wBAAwB,EAAE;MAClC,OAAOF,MAAM,CAACE,wBAAwB,CAAC,CAAC;IAC5C;IACA,OAAOD,WAAW,CAACE,wBAAwB,CAAC,CAAC;EACjD,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ export type * from "./abstractions/ITimer.js";
2
+ export * from "./CustomTimer.js";
3
+ export * from "./factory.js";
4
+ export * from "./Timer.js";
@@ -0,0 +1,5 @@
1
+ export * from "./CustomTimer.js";
2
+ export * from "./factory.js";
3
+ export * from "./Timer.js";
4
+
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export type * from \"./abstractions/ITimer.js\";\nexport * from \"./CustomTimer.js\";\nexport * from \"./factory.js\";\nexport * from \"./Timer.js\";\n"],"mappings":"AACA;AACA;AACA","ignoreList":[]}