quidproquo-actionprocessor-awslambda 0.0.187 → 0.0.188

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.
@@ -93,16 +93,9 @@ const getProcessMatchStory = (qpqConfig) => {
93
93
  return (payload) => __awaiter(void 0, void 0, void 0, function* () {
94
94
  // Sort the routes by string length
95
95
  // Note: We may need to filter variable routes out {} as the variables are length independent
96
- const sortedRoutes = routes
97
- .filter((r) => r.method === payload.transformedEventParams.method ||
98
- payload.transformedEventParams.method === 'OPTIONS')
99
- .sort((a, b) => {
100
- if (a.path.length < b.path.length)
101
- return -1;
102
- if (a.path.length > b.path.length)
103
- return 1;
104
- return 0;
105
- });
96
+ const routesWithNoOptions = routes.filter((r) => r.method === payload.transformedEventParams.method ||
97
+ payload.transformedEventParams.method === 'OPTIONS');
98
+ const sortedRoutes = quidproquo_webserver_1.qpqWebServerUtils.sortPathMatchConfigs(routesWithNoOptions);
106
99
  // Find the most relevant match
107
100
  const matchedRoute = sortedRoutes
108
101
  .map((r) => ({
@@ -41,15 +41,9 @@ const getProcessAutoRespond = () => {
41
41
  };
42
42
  const getProcessMatchStory = (seoConfigs) => {
43
43
  return (payload) => __awaiter(void 0, void 0, void 0, function* () {
44
- /// Sort the routes by string length
45
- // Note: We may need to filter variable routes out {} as the variables are length independent
46
- const sortedSeoConfigs = seoConfigs.sort((a, b) => {
47
- if (a.path.length < b.path.length)
48
- return -1;
49
- if (a.path.length > b.path.length)
50
- return 1;
51
- return 0;
52
- });
44
+ // Sort the routes by string length
45
+ // we don't sort them here for SEO... its the order they are defined.
46
+ const sortedSeoConfigs = seoConfigs; // qpqWebServerUtils.sortPathMatchConfigs(seoConfigs);
53
47
  // Find the most relevant match
54
48
  const matchedSeoConfig = sortedSeoConfigs
55
49
  .map((r) => ({
@@ -1,5 +1,5 @@
1
1
  import { AttributeValue } from '@aws-sdk/client-dynamodb';
2
- import { KvsUpdate } from 'quidproquo-core';
2
+ import { KvsUpdateActionType, KvsUpdate } from 'quidproquo-core';
3
3
  interface ExpressionAttributeNameMap {
4
4
  [key: string]: string;
5
5
  }
@@ -7,5 +7,6 @@ export declare const buildUpdateExpressionAttributeNames: (updates: KvsUpdate) =
7
7
  export declare const buildUpdateExpressionAttributeValues: (updates: KvsUpdate) => {
8
8
  [key: string]: AttributeValue;
9
9
  } | undefined;
10
+ export declare const buildDynamoUpdateExpressionForType: (type: KvsUpdateActionType, kvsUpdate: KvsUpdate) => string;
10
11
  export declare const buildDynamoUpdateExpression: (updates: KvsUpdate) => string;
11
12
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildDynamoUpdateExpression = exports.buildUpdateExpressionAttributeValues = exports.buildUpdateExpressionAttributeNames = void 0;
3
+ exports.buildDynamoUpdateExpression = exports.buildDynamoUpdateExpressionForType = exports.buildUpdateExpressionAttributeValues = exports.buildUpdateExpressionAttributeNames = void 0;
4
4
  const quidproquo_core_1 = require("quidproquo-core");
5
5
  const buildDynamoQuery_1 = require("./buildDynamoQuery");
6
6
  const buildUpdateExpressionAttributeNames = (updates) => {
@@ -43,23 +43,23 @@ const buildDynamoUpdateExpressionSet = (update) => {
43
43
  if (!update.value) {
44
44
  throw new Error("Value must be provided for 'SET' action");
45
45
  }
46
- return `SET ${getNestedItemName(update.attributePath)} = ${(0, buildDynamoQuery_1.getValueName)(update.value)}`;
46
+ return `${getNestedItemName(update.attributePath)} = ${(0, buildDynamoQuery_1.getValueName)(update.value)}`;
47
47
  };
48
48
  const buildDynamoUpdateExpressionRemove = (update) => {
49
- return `REMOVE ${getNestedItemName(update.attributePath)}`;
49
+ return `${getNestedItemName(update.attributePath)}`;
50
50
  };
51
51
  const buildDynamoUpdateExpressionAdd = (update) => {
52
52
  if (!update.value) {
53
53
  throw new Error("Value must be provided for 'ADD' action");
54
54
  }
55
- return `ADD ${getNestedItemName(update.attributePath)} ${(0, buildDynamoQuery_1.getValueName)(update.value)}`;
55
+ return `${getNestedItemName(update.attributePath)} ${(0, buildDynamoQuery_1.getValueName)(update.value)}`;
56
56
  };
57
57
  const buildDynamoUpdateExpressionDelete = (update) => {
58
58
  if (update.value) {
59
- return `DELETE ${getNestedItemName(update.attributePath)} ${(0, buildDynamoQuery_1.getValueName)(update.value)}`;
59
+ return `${getNestedItemName(update.attributePath)} ${(0, buildDynamoQuery_1.getValueName)(update.value)}`;
60
60
  }
61
61
  else {
62
- return `DELETE ${getNestedItemName(update.attributePath)}`;
62
+ return `${getNestedItemName(update.attributePath)}`;
63
63
  }
64
64
  };
65
65
  const getNestedItemName = (attributePath) => {
@@ -79,7 +79,7 @@ const getNestedItemName = (attributePath) => {
79
79
  return (0, buildDynamoQuery_1.getItemName)(attributePath);
80
80
  }
81
81
  };
82
- const buildDynamoUpdateExpressionRoot = (update) => {
82
+ const buildDynamoUpdateExpressionPart = (update, updateIndex) => {
83
83
  switch (update.action) {
84
84
  case quidproquo_core_1.KvsUpdateActionType.Set:
85
85
  return buildDynamoUpdateExpressionSet(update);
@@ -93,7 +93,38 @@ const buildDynamoUpdateExpressionRoot = (update) => {
93
93
  throw new Error(`Invalid update action type: ${update.action}`);
94
94
  }
95
95
  };
96
+ const buildDynamoUpdateExpressionForType = (type, kvsUpdate) => {
97
+ const actions = kvsUpdate.filter((update) => update.action === type);
98
+ // If there are no actions of this type, return an empty string
99
+ if (actions.length === 0) {
100
+ return '';
101
+ }
102
+ const expressions = actions
103
+ .map((update, index) => buildDynamoUpdateExpressionPart(update, index))
104
+ .join(', ');
105
+ switch (type) {
106
+ case quidproquo_core_1.KvsUpdateActionType.Set:
107
+ return `SET ${expressions}`;
108
+ case quidproquo_core_1.KvsUpdateActionType.Remove:
109
+ return `REMOVE ${expressions}`;
110
+ case quidproquo_core_1.KvsUpdateActionType.Add:
111
+ return `ADD ${expressions}`;
112
+ case quidproquo_core_1.KvsUpdateActionType.Delete:
113
+ return `DELETE ${expressions}`;
114
+ default:
115
+ throw new Error(`Invalid update action type: ${type}`);
116
+ }
117
+ };
118
+ exports.buildDynamoUpdateExpressionForType = buildDynamoUpdateExpressionForType;
96
119
  const buildDynamoUpdateExpression = (updates) => {
97
- return updates.map((update) => buildDynamoUpdateExpressionRoot(update)).join(', ');
120
+ const updatesExpressions = [
121
+ quidproquo_core_1.KvsUpdateActionType.Set,
122
+ quidproquo_core_1.KvsUpdateActionType.Remove,
123
+ quidproquo_core_1.KvsUpdateActionType.Add,
124
+ quidproquo_core_1.KvsUpdateActionType.Delete,
125
+ ]
126
+ .map((kvsUpdateActionType) => (0, exports.buildDynamoUpdateExpressionForType)(kvsUpdateActionType, updates))
127
+ .filter((expression) => !!expression);
128
+ return updatesExpressions.join(' ');
98
129
  };
99
130
  exports.buildDynamoUpdateExpression = buildDynamoUpdateExpression;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quidproquo-actionprocessor-awslambda",
3
- "version": "0.0.187",
3
+ "version": "0.0.188",
4
4
  "description": "",
5
5
  "main": "./lib/commonjs/index.js",
6
6
  "types": "./lib/commonjs/index.d.ts",
@@ -47,9 +47,9 @@
47
47
  "lodash": "^4.17.21",
48
48
  "node-cache": "^5.1.2",
49
49
  "node-match-path": "^0.6.3",
50
- "quidproquo-config-aws": "0.0.187",
51
- "quidproquo-core": "0.0.187",
52
- "quidproquo-webserver": "0.0.187"
50
+ "quidproquo-config-aws": "0.0.188",
51
+ "quidproquo-core": "0.0.188",
52
+ "quidproquo-webserver": "0.0.188"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@types/aws-lambda": "^8.10.109",
@@ -57,7 +57,7 @@
57
57
  "@types/jsonwebtoken": "^9.0.2",
58
58
  "@types/lodash": "^4.14.194",
59
59
  "@types/node": "^18.11.9",
60
- "quidproquo-tsconfig": "0.0.187",
60
+ "quidproquo-tsconfig": "0.0.188",
61
61
  "typescript": "^4.9.3"
62
62
  }
63
63
  }