@middy/cloudformation-router 6.1.6 → 6.2.1

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 (3) hide show
  1. package/index.d.ts +8 -8
  2. package/index.js +52 -49
  3. package/package.json +65 -68
package/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- import middy from '@middy/core'
2
- import { CloudFormationCustomResourceHandler } from 'aws-lambda'
1
+ import type middy from "@middy/core";
2
+ import type { CloudFormationCustomResourceHandler } from "aws-lambda";
3
3
 
4
4
  interface Route<T = never> {
5
- requestType: string
6
- handler: CloudFormationCustomResourceHandler<T>
5
+ requestType: string;
6
+ handler: CloudFormationCustomResourceHandler<T>;
7
7
  }
8
8
 
9
- declare function cloudformationRouterHandler (
10
- routes: Route[]
11
- ): middy.MiddyfiedHandler
9
+ declare function cloudformationRouterHandler(
10
+ routes: Route[],
11
+ ): middy.MiddyfiedHandler;
12
12
 
13
- export default cloudformationRouterHandler
13
+ export default cloudformationRouterHandler;
package/index.js CHANGED
@@ -1,57 +1,60 @@
1
1
  const defaults = {
2
- routes: [],
3
- notFoundResponse: ({ requestType }) => {
4
- const err = new Error('Route does not exist', {
5
- cause: {
6
- package: '@middy/cloudformation-router',
7
- data: { requestType }
8
- }
9
- })
10
- throw err
11
- }
12
- }
2
+ routes: [],
3
+ notFoundResponse: ({ requestType }) => {
4
+ const err = new Error("Route does not exist", {
5
+ cause: {
6
+ package: "@middy/cloudformation-router",
7
+ data: { requestType },
8
+ },
9
+ });
10
+ throw err;
11
+ },
12
+ };
13
13
  const cloudformationCustomResourceRouteHandler = (opts = {}) => {
14
- if (Array.isArray(opts)) {
15
- opts = { routes: opts }
16
- }
17
- const { routes, notFoundResponse } = { ...defaults, ...opts }
14
+ const options = { ...defaults };
15
+ if (Array.isArray(opts)) {
16
+ Object.assign(options, { routes: opts });
17
+ } else {
18
+ Object.assign(options, opts);
19
+ }
20
+ const { routes, notFoundResponse } = options;
18
21
 
19
- const routesStatic = {}
20
- for (const route of routes) {
21
- const { requestType, handler } = route
22
+ const routesStatic = {};
23
+ for (const route of routes) {
24
+ const { requestType, handler } = route;
22
25
 
23
- // Static
24
- routesStatic[requestType] = handler
25
- }
26
+ // Static
27
+ routesStatic[requestType] = handler;
28
+ }
26
29
 
27
- const requestTypes = {
28
- Create: true,
29
- Update: true,
30
- Delete: true
31
- }
32
- return (event, context, abort) => {
33
- const { RequestType: requestType } = event
34
- if (
35
- !requestType ||
36
- !Object.hasOwnProperty.call(requestTypes, requestType)
37
- ) {
38
- throw new Error('Unknown CloudFormation Custom Response event format', {
39
- cause: {
40
- package: '@middy/cloudformation-router',
41
- data: { requestType }
42
- }
43
- })
44
- }
30
+ const requestTypes = {
31
+ Create: true,
32
+ Update: true,
33
+ Delete: true,
34
+ };
35
+ return (event, context, abort) => {
36
+ const { RequestType: requestType } = event;
37
+ if (
38
+ !requestType ||
39
+ !Object.hasOwnProperty.call(requestTypes, requestType)
40
+ ) {
41
+ throw new Error("Unknown CloudFormation Custom Response event format", {
42
+ cause: {
43
+ package: "@middy/cloudformation-router",
44
+ data: { requestType },
45
+ },
46
+ });
47
+ }
45
48
 
46
- // Static
47
- if (Object.hasOwnProperty.call(routesStatic, requestType)) {
48
- const handler = routesStatic[requestType]
49
- return handler(event, context, abort)
50
- }
49
+ // Static
50
+ if (Object.hasOwnProperty.call(routesStatic, requestType)) {
51
+ const handler = routesStatic[requestType];
52
+ return handler(event, context, abort);
53
+ }
51
54
 
52
- // Not Found
53
- return notFoundResponse({ requestType })
54
- }
55
- }
55
+ // Not Found
56
+ return notFoundResponse({ requestType });
57
+ };
58
+ };
56
59
 
57
- export default cloudformationCustomResourceRouteHandler
60
+ export default cloudformationCustomResourceRouteHandler;
package/package.json CHANGED
@@ -1,70 +1,67 @@
1
1
  {
2
- "name": "@middy/cloudformation-router",
3
- "version": "6.1.6",
4
- "description": "CloudFormation Custom Response event router for the middy framework",
5
- "type": "module",
6
- "engines": {
7
- "node": ">=20"
8
- },
9
- "engineStrict": true,
10
- "publishConfig": {
11
- "access": "public"
12
- },
13
- "module": "./index.js",
14
- "exports": {
15
- ".": {
16
- "import": {
17
- "types": "./index.d.ts",
18
- "default": "./index.js"
19
- },
20
- "require": {
21
- "default": "./index.js"
22
- }
23
- }
24
- },
25
- "types": "index.d.ts",
26
- "files": [
27
- "index.js",
28
- "index.d.ts"
29
- ],
30
- "scripts": {
31
- "test": "npm run test:unit",
32
- "test:unit": "node --test __tests__/index.js",
33
- "test:benchmark": "node __benchmarks__/index.js"
34
- },
35
- "license": "MIT",
36
- "keywords": [
37
- "Lambda",
38
- "Middleware",
39
- "Serverless",
40
- "Framework",
41
- "AWS",
42
- "AWS Lambda",
43
- "Middy",
44
- "CloudFormation",
45
- "Custom Response",
46
- "router"
47
- ],
48
- "author": {
49
- "name": "Middy contributors",
50
- "url": "https://github.com/middyjs/middy/graphs/contributors"
51
- },
52
- "repository": {
53
- "type": "git",
54
- "url": "git+https://github.com/middyjs/middy.git",
55
- "directory": "packages/cloudformation-router"
56
- },
57
- "bugs": {
58
- "url": "https://github.com/middyjs/middy/issues"
59
- },
60
- "homepage": "https://middy.js.org",
61
- "funding": {
62
- "type": "github",
63
- "url": "https://github.com/sponsors/willfarrell"
64
- },
65
- "devDependencies": {
66
- "@middy/core": "6.1.6",
67
- "@types/aws-lambda": "^8.10.100"
68
- },
69
- "gitHead": "7a6c0fbb8ab71d6a2171e678697de9f237568431"
2
+ "name": "@middy/cloudformation-router",
3
+ "version": "6.2.1",
4
+ "description": "CloudFormation Custom Response event router for the middy framework",
5
+ "type": "module",
6
+ "engines": {
7
+ "node": ">=20"
8
+ },
9
+ "engineStrict": true,
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "module": "./index.js",
14
+ "exports": {
15
+ ".": {
16
+ "import": {
17
+ "types": "./index.d.ts",
18
+ "default": "./index.js"
19
+ },
20
+ "require": {
21
+ "default": "./index.js"
22
+ }
23
+ }
24
+ },
25
+ "types": "index.d.ts",
26
+ "files": ["index.js", "index.d.ts"],
27
+ "scripts": {
28
+ "test": "npm run test:unit",
29
+ "test:unit": "node --test",
30
+ "test:perf": "node --test index.perf.js"
31
+ },
32
+ "license": "MIT",
33
+ "keywords": [
34
+ "Lambda",
35
+ "Middleware",
36
+ "Serverless",
37
+ "Framework",
38
+ "AWS",
39
+ "AWS Lambda",
40
+ "Middy",
41
+ "CloudFormation",
42
+ "Custom Response",
43
+ "router"
44
+ ],
45
+ "author": {
46
+ "name": "Middy contributors",
47
+ "url": "https://github.com/middyjs/middy/graphs/contributors"
48
+ },
49
+ "repository": {
50
+ "type": "git",
51
+ "url": "git+https://github.com/middyjs/middy.git",
52
+ "directory": "packages/cloudformation-router"
53
+ },
54
+ "bugs": {
55
+ "url": "https://github.com/middyjs/middy/issues"
56
+ },
57
+ "homepage": "https://middy.js.org",
58
+ "funding": {
59
+ "type": "github",
60
+ "url": "https://github.com/sponsors/willfarrell"
61
+ },
62
+ "devDependencies": {
63
+ "@middy/core": "6.2.1",
64
+ "@types/aws-lambda": "^8.10.100"
65
+ },
66
+ "gitHead": "7a6c0fbb8ab71d6a2171e678697de9f237568431"
70
67
  }