@izara_project/izara-core-generate-service-code 1.0.69 → 1.0.71

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 (67) hide show
  1. package/package.json +1 -1
  2. package/scripts/format-ejs.js +35 -30
  3. package/src/compile/loadSchemas.js +84 -45
  4. package/src/emit/coreFunction/emitCoreFunctionArtifacts.js +163 -0
  5. package/src/emit/coreFunction/templates/CoreFunction_Yaml.ejs +38 -0
  6. package/src/emit/coreFunction/templates/CoreResource_Yaml.ejs +235 -0
  7. package/src/emit/coreFunction/templates/GenerateSeedDataDynamo_HdrInv.ejs +16 -0
  8. package/src/emit/coreFunction/templates/GenerateSeedDataDynamo_Main.ejs +38 -0
  9. package/src/emit/coreFunction/templates/GenerateSeedDataGraphData_HdrInv.ejs +16 -0
  10. package/src/emit/coreFunction/templates/GenerateSeedDataGraphData_Main.ejs +32 -0
  11. package/src/emit/coreFunction/templates/GenerateSeedDataGraphSchema_HdrInv.ejs +16 -0
  12. package/src/emit/coreFunction/templates/GenerateSeedDataGraphSchema_Main.ejs +71 -0
  13. package/src/emit/coreFunction/templates/GeneratedGraphNodeSchemas.ejs +47 -0
  14. package/src/emit/coreFunction/templates/GeneratedGraphRelSchemas.ejs +27 -0
  15. package/src/emit/coreFunction/templates/GeneratedTableConfigs.ejs +34 -0
  16. package/src/emit/coreFunction/templates/InitialSetupConfig.ejs +108 -0
  17. package/src/emit/coreFunction/templates/InitialSetup_HdrInv.ejs +12 -0
  18. package/src/emit/coreFunction/templates/InitialSetup_Main.ejs +51 -0
  19. package/src/emit/coreFunction/templates/RemoveSeedDataDynamo_HdrInv.ejs +16 -0
  20. package/src/emit/coreFunction/templates/RemoveSeedDataDynamo_Main.ejs +31 -0
  21. package/src/emit/coreFunction/templates/UploadSchema_HdrInv.ejs +37 -0
  22. package/src/emit/coreFunction/templates/UploadSchema_Main.ejs +52 -0
  23. package/src/emit/crud/emitCrudApplicationArtifacts.js +12 -6
  24. package/src/emit/crud/templates/CreateEndpoint_Main.ejs +1 -1
  25. package/src/emit/crud/templates/DeleteEndpoint_Main.ejs +1 -1
  26. package/src/emit/crud/templates/GetEndpoint_Main.ejs +1 -1
  27. package/src/emit/crud/templates/GetRangeEndpoint_Main.ejs +1 -1
  28. package/src/emit/crud/templates/UpdateEndpoint_Main.ejs +1 -1
  29. package/src/emit/custom/emitCustomFlowApplicationArtifacts.js +30 -11
  30. package/src/emit/custom/templates/FlowEndpoint_Main.ejs +2 -2
  31. package/src/emit/custom/templates/FlowStep_Main.ejs +1 -1
  32. package/src/emit/custom/templates/s3/CreateObject_Main.ejs +1 -1
  33. package/src/emit/custom/templates/s3/ReservedLimit_Main.ejs +1 -1
  34. package/src/emit/custom/templates/triggerCache/CheckTriggerCache_HdrSqs.ejs +4 -4
  35. package/src/emit/function/functionYamlArtifact.js +5 -2
  36. package/src/emit/relationship/emitRelationshipApplicationArtifacts.js +13 -3
  37. package/src/emit/relationship/templates/ChangeRelationship_Main.ejs +1 -1
  38. package/src/emit/relationship/templates/CreateRelationship_Main.ejs +1 -1
  39. package/src/emit/relationship/templates/DeleteRelationship_Main.ejs +1 -1
  40. package/src/emit/relationship/templates/GetRelationship_Main.ejs +1 -1
  41. package/src/emit/relationship/templates/MoveRelationship_Main.ejs +1 -1
  42. package/src/emit/relationship/templates/UpdateRelationship_Main.ejs +1 -1
  43. package/src/emit/resource/emitResourceArtifacts.js +71 -15
  44. package/src/emit/resource/templates/SystemDynamoDB_Yaml.ejs +17 -0
  45. package/src/emit/shared/templates/FindData_HdrSqs.ejs +120 -0
  46. package/src/emit/shared/templates/FindData_Main.ejs +345 -0
  47. package/src/emit/{crud → shared}/templates/FlowHandler_HdrApi.ejs +1 -1
  48. package/src/emit/{relationship → shared}/templates/FlowHandler_HdrDsq.ejs +4 -4
  49. package/src/emit/{crud → shared}/templates/FlowHandler_HdrInv.ejs +1 -1
  50. package/src/emit/{crud → shared}/templates/FlowHandler_HdrSqs.ejs +4 -4
  51. package/src/emit/shared/templates/PaginateProcessLogical_HdrDsq.ejs +162 -0
  52. package/src/emit/shared/templates/PaginateProcessLogical_HdrSqs.ejs +140 -0
  53. package/src/emit/shared/templates/PaginateProcessLogical_Main.ejs +268 -0
  54. package/src/emit/{relationship/templates/FlowHandler_HdrSqs.ejs → shared/templates/ProcessLogical_HdrSqs.ejs} +40 -55
  55. package/src/emit/shared/templates/ProcessLogical_Main.ejs +448 -0
  56. package/src/emit/system/emitSystemFindDataArtifacts.js +266 -0
  57. package/src/emit/system/templates/WebSocketComplete_HdrSqs.ejs +27 -11
  58. package/src/emit/system/templates/WebSocketComplete_Main.ejs +63 -18
  59. package/src/emit/system/templates/WebSocketConnect.ejs +26 -6
  60. package/src/generate.js +31 -4
  61. package/src/output/mergeHooks.js +18 -19
  62. package/test/core.test.js +4 -12
  63. package/test/crudApplicationArtifacts.test.js +14 -18
  64. package/test/publicApi.test.js +2 -2
  65. package/test/resourceArtifacts.test.js +1 -1
  66. package/src/emit/relationship/templates/FlowHandler_HdrApi.ejs +0 -59
  67. package/src/emit/relationship/templates/FlowHandler_HdrInv.ejs +0 -47
@@ -16,47 +16,45 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
  */
17
17
 
18
18
  import { middlewareHandler as middleware } from '@izara_project/izara-middleware';
19
- import { recordHandlerSharedLib } from '@izara_project/izara-core-library-record-handler';
20
19
  import Logger from '@izara_project/izara-core-library-logger';
20
+ import { recordHandlerSharedLib } from '@izara_project/izara-core-library-record-handler';
21
21
  import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
22
- import <%= functionName %> from './<%= mainFileName %>.js';
22
+
23
+ import processLogical from './ProcessLogical_Main.js';
23
24
 
24
25
  // validate event properties in body.Message of sqs event
25
- let perRecordsValidatorSchema = {
26
- //(<validatorSchema>)
27
- <% if (typeof startConfig !== 'undefined' && startConfig !== null && startConfig.properties && startConfig.properties.length > 0) { -%>
28
- type: 'object',
29
- properties: {
30
- <% startConfig.properties.forEach((prop, index) => { %> <%- prop.propertyName %>: {
31
- type: '<%- prop.type || 'string' %>'
32
- } /*__EJS_COMMA_6__*/
33
- <% }) %>
34
- },
35
- required: [<%- startConfig.properties.filter(p => p.required !== false).map(p => `'${p.propertyName}'`).join(', ') %>]
36
- <% } -%>
37
- //(</validatorSchema>)
38
- };
26
+ middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
39
27
 
40
- <% if (typeof startConfig !== 'undefined' && startConfig !== null && startConfig.messageAttributes && startConfig.messageAttributes.length > 0) { -%>
41
- let messageAttributeValidatorSchema = {
28
+ // set schema for record.body.Message
29
+ const perRecordsValidatorSchema = {
42
30
  type: 'object',
31
+ required: ['objType', 'element', 'overWriteCache'],
43
32
  properties: {
44
- <% startConfig.messageAttributes.forEach((prop, index) => { %> <%- prop.propertyName %>: {
33
+ objType: {
45
34
  type: 'object',
35
+ required: ['serviceTag', 'objectType'],
46
36
  properties: {
47
- Type: { type: 'string' },
48
- Value: { type: '<%- prop.type || 'string' %>' }
49
- },
50
- required: ['Type', 'Value']
51
- } /*__EJS_COMMA_14__*/
52
- <% }) %>
53
- },
54
- required: [<%- startConfig.messageAttributes.filter(p => p.required !== false).map(p => `'${p.propertyName}'`).join(', ') %>]
37
+ serviceTag: {
38
+ type: 'string',
39
+ enum: [process.env.iz_serviceTag]
40
+ },
41
+ objectType: {
42
+ type: 'string'
43
+ }
44
+ }
45
+ },
46
+ element: {
47
+ type: 'object'
48
+ },
49
+ overWriteCache: {
50
+ type: 'boolean'
51
+ },
52
+ callingFlow: {
53
+ type: 'string',
54
+ default: ''
55
+ }
56
+ }
55
57
  };
56
- <% } else { -%>
57
- let messageAttributeValidatorSchema = null;
58
- <% } -%>
59
- middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
60
58
 
61
59
  export const main = middleware.wrap(async (event, context) => {
62
60
  try {
@@ -64,37 +62,24 @@ export const main = middleware.wrap(async (event, context) => {
64
62
 
65
63
  // loop each record and send to mainFunction
66
64
  await Promise.all(
67
- event.Records.map(async (record) => {
65
+ event.Records.map(async record => {
68
66
  // promise.all for map() function
69
67
 
70
68
  let passOnProperties = [];
71
69
  record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
72
70
 
73
- //validate message (and MessageAttributes)
71
+ // validate message (and MessageAttributes)
74
72
  await recordHandlerSharedLib.validateRecord(
75
73
  record, // one record will send to mainFunction
76
- '<%= queueName %>', // queue name that need to retry or send to dlq
77
- perRecordsValidatorSchema, // schema for record.Message
78
- messageAttributeValidatorSchema
74
+ 'ProcessLogicalHdrSqs', // queue name that need to retry or send to dlq
75
+ perRecordsValidatorSchema // schema for record.Message
79
76
  );
80
77
 
81
78
  // add argument (to invoke lambda) to passOnProperties[]
82
- passOnProperties.push(record.body.Message);
83
- <% if (functionName.endsWith('Complete')) { %>
84
- passOnProperties.push(
85
- callingFlowSharedLib.addPassBackPropertiesToPassOnProperties(
86
- record.body.Message
87
- )
88
- );
89
- <% } else { %>
90
- passOnProperties.push(
91
- callingFlowSharedLib.addCallingFlowToPassOnProperties(
92
- record.body.Message
93
- )
94
- );
95
- <% } %>
96
- //(<additionalParams>)
97
- //(</additionalParams>)
79
+ passOnProperties.push(record.body.Message.objType);
80
+ passOnProperties.push(record.body.Message.element);
81
+ passOnProperties.push(record.body.Message.overWriteCache);
82
+ passOnProperties.push(record.body.Message.callingFlow);
98
83
  record._izContext.logger.debug(
99
84
  'passOnProperties in handler',
100
85
  passOnProperties
@@ -103,8 +88,8 @@ export const main = middleware.wrap(async (event, context) => {
103
88
  // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
104
89
  let recordPromise = recordHandlerSharedLib.recordHandler(
105
90
  record, // one record will send to mainFunction
106
- <%= functionName %>, // mainFunction that need to invoke.
107
- '<%= queueName %>', // queue name that need to retry or send to dlq
91
+ processLogical, // mainFunction that need to invoke.
92
+ 'ProcessLogicalHdrSqs', // queue name that need to retry or send to dlq
108
93
  passOnProperties // all parameters that mainFunction needed.
109
94
  );
110
95
  record._izContext.logger.debug('after recordPromise in handler');
@@ -125,7 +110,7 @@ export const main = middleware.wrap(async (event, context) => {
125
110
  }
126
111
  Logger.debug('after Promise.all(recordPromises) in handler');
127
112
  } catch (err) {
128
- Logger.error('Unhandled Error, LambdaFunctionHdrSqs: ', err);
113
+ Logger.error('Unhandled Error, ProcessLogicalHdrSqs: ', err);
129
114
  throw err;
130
115
  }
131
116
  });
@@ -0,0 +1,448 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
19
+ import snsSharedLib from '@izara_project/izara-core-library-sns';
20
+ import logicalResultsSharedLib from '@izara_project/izara-core-library-logical-result';
21
+ import searchResultSharedLib from '@izara_project/izara-core-library-search-result';
22
+ import { sns } from '@izara_project/izara-core-library-external-request';
23
+
24
+ import {
25
+ getObjectSchema,
26
+ serviceConfig,
27
+ consts,
28
+ utils
29
+ } from '@izara_project/izara-core-library-service-schemas';
30
+ import { NoRetryError } from '@izara_project/izara-core-library-core';
31
+ const { STORAGE_TYPES } = consts;
32
+ const { getUsedFieldNamesOfIdentifiers } = utils;
33
+
34
+ //(<additionalModule>)
35
+ import { identifiersObject as identifierObj } from '@izara_project/izara-core-library-service-schemas';
36
+ //(</additionalModule>)
37
+
38
+ /**
39
+ * performs the logical operation/filter/search in the element, saves into LogicalResultsData table
40
+ * @param {Object} _izContext
41
+ * @param {Object} objType - contain objectType and serviceTag
42
+ * @param {Object} element - logical element
43
+ * @param {Object} element.filterType - 'logical'
44
+ * @param {string} element.logicalType - contain 'identifier' | 'partitionKey'
45
+ * @param {Object} [element.partitionKeyValues] - value of fieldNames that is partitionKey.
46
+ * @param {Object} [element.sortKeyValues] - value of fieldNames that is sortKey. (optional)
47
+ * @param {string} [element.comparison] - use for query in queryElements.sortKeyCondition. (optional)
48
+ * @param {string} [element.conditionalFieldValues] - user after query for filter data before save to logicalData table. (optional)
49
+ * @param {boolean} overWriteCache
50
+ *
51
+ * @returns {string} description of return value
52
+ */
53
+
54
+ export default async function processLogical(
55
+ _izContext,
56
+ objType,
57
+ element,
58
+ overWriteCache,
59
+ callingFlow
60
+ ) {
61
+ try {
62
+ _izContext.logger.debug('----- ProcessLogical event params -----', {
63
+ objType: objType,
64
+ element: element,
65
+ overWriteCache: overWriteCache,
66
+ callingFlow: callingFlow
67
+ });
68
+
69
+ let removeAttributes = ['paginateProcessLogicalUniqueRequestId'];
70
+
71
+ //(<removeAttributes>)
72
+ //(</removeAttributes>)
73
+
74
+ // Check/Create logicalResultsMain
75
+ let [logicalResultsMainStatus, logicalResultId, logicalResultMain] =
76
+ await logicalResultsSharedLib.checkLogicalMainStatus(
77
+ _izContext,
78
+ element, // for create logicalResultId
79
+ objType,
80
+ callingFlow,
81
+ removeAttributes,
82
+ overWriteCache
83
+ );
84
+ _izContext.logger.debug('After check logicalMainStatus: ', {
85
+ logicalResultsMainStatus: logicalResultsMainStatus,
86
+ logicalResultId: logicalResultId,
87
+ logicalResultMain: logicalResultMain
88
+ });
89
+
90
+ if (logicalResultsMainStatus !== 'process') {
91
+ _izContext.logger.debug(
92
+ `logicalResultsMainStatus status isn't process :${logicalResultsMainStatus}`
93
+ );
94
+ return {
95
+ returnResponse: 'logicalResultsMainStatus status is not process'
96
+ };
97
+ }
98
+
99
+ let errorsFound = [];
100
+
101
+ let standardErrorParams = [
102
+ _izContext,
103
+ logicalResultId,
104
+ logicalResultMain.logicalElement,
105
+ logicalResultMain.objType,
106
+ overWriteCache,
107
+ callingFlow,
108
+ 'error'
109
+ ];
110
+
111
+ if (
112
+ element.comparison &&
113
+ !searchResultSharedLib.consts.POSSIBLE_COMPARISON_SORTID.includes(
114
+ element.comparison
115
+ )
116
+ ) {
117
+ errorsFound.push('comparison is not possible comparison');
118
+ }
119
+
120
+ // validate partitionKeyValues
121
+ if (!element.hasOwnProperty('partitionKeyValues')) {
122
+ _izContext.logger.debug('element not have partitionKeyValues');
123
+ errorsFound.push('element not have partitionKeyValues');
124
+ } else if (Object.keys(element.partitionKeyValues).length === 0) {
125
+ _izContext.logger.debug('partitionKeyValues is empty');
126
+ errorsFound.push('partitionKeyValues is empty');
127
+ }
128
+
129
+ const objectSchemas = await getObjectSchema.getObjSchemaS3WithHierarchy(
130
+ _izContext,
131
+ objType
132
+ );
133
+ _izContext.logger.debug('objectSchemas: ', objectSchemas);
134
+
135
+ let partitionKeyFieldName = null;
136
+ let tableName = null;
137
+ let sortKeyFieldName = null;
138
+
139
+ for (const schemasIdentifier of objectSchemas.identifiers) {
140
+ if (schemasIdentifier.type === 'partitionKey') {
141
+ if (partitionKeyFieldName === null) {
142
+ if (schemasIdentifier.hasOwnProperty('fieldName')) {
143
+ partitionKeyFieldName = schemasIdentifier.fieldName;
144
+ } else {
145
+ partitionKeyFieldName = schemasIdentifier.name;
146
+ }
147
+ } else {
148
+ throw new NoRetryError(
149
+ 'Invalid object schemas have more than one partitionKey'
150
+ );
151
+ }
152
+ }
153
+
154
+ if (schemasIdentifier.type === 'sortKey') {
155
+ if (sortKeyFieldName === null) {
156
+ if (schemasIdentifier.hasOwnProperty('fieldName')) {
157
+ sortKeyFieldName = schemasIdentifier.fieldName;
158
+ } else {
159
+ sortKeyFieldName = schemasIdentifier.name;
160
+ }
161
+ } else {
162
+ throw new NoRetryError(
163
+ 'Invalid object schemas have more than one sortKey'
164
+ );
165
+ }
166
+ _izContext.logger.debug('have sortKeyFieldName: ', sortKeyFieldName);
167
+ }
168
+ }
169
+
170
+ const storageResources = objectSchemas.storageResources;
171
+
172
+ storageResourcesLoop: for (const storageResourceTag of Object.keys(
173
+ storageResources
174
+ )) {
175
+ _izContext.logger.debug('check storageResourceTag: ', storageResourceTag);
176
+
177
+ if (
178
+ storageResources[storageResourceTag].storageType ===
179
+ STORAGE_TYPES.dynamoDB
180
+ ) {
181
+ if (
182
+ storageResources[storageResourceTag].hasOwnProperty(
183
+ 'groupByPartitionKeyField'
184
+ )
185
+ ) {
186
+ if (element.hasOwnProperty('sortKeyValues')) {
187
+ continue;
188
+ } else {
189
+ errorsFound.push(
190
+ 'schema error: dynamo storageResource set to groupByPartitionKeyField but no sortKey'
191
+ );
192
+ break;
193
+ }
194
+ }
195
+
196
+ // validate conditionalFieldValues
197
+ if (
198
+ element.hasOwnProperty('conditionalFieldValues') &&
199
+ element.conditionalFieldValues.length > 0
200
+ ) {
201
+ conditionalFieldValuesLoop: for (const conditionalFieldValue of element.conditionalFieldValues) {
202
+ let conditionalFieldName = conditionalFieldValue.fieldName;
203
+ let storageResourceTagsFieldName =
204
+ objectSchemas.fieldNames[conditionalFieldName]
205
+ .storageResourceTags;
206
+
207
+ if (storageResourceTagsFieldName.includes(storageResourceTag)) {
208
+ continue conditionalFieldValuesLoop;
209
+ } else {
210
+ continue storageResourcesLoop;
211
+ }
212
+ }
213
+ }
214
+
215
+ tableName = storageResources[storageResourceTag].tableName;
216
+ _izContext.logger.debug('found tableName: ', tableName);
217
+ break;
218
+ }
219
+ }
220
+
221
+ if (!tableName) {
222
+ errorsFound.push('no valid dynamo storageResource found');
223
+ }
224
+
225
+ if (
226
+ element.hasOwnProperty('sortKeyValues') &&
227
+ Object.keys(element.sortKeyValues).length > 0 &&
228
+ !sortKeyFieldName
229
+ ) {
230
+ _izContext.logger.debug(
231
+ 'element have sortKeyValues but cannot find sortKey in object schemas'
232
+ );
233
+ errorsFound.push(
234
+ 'element have sortKeyValues but cannot find sortKey in object schemas'
235
+ );
236
+ }
237
+
238
+ if (errorsFound.length > 0) {
239
+ _izContext.logger.debug('Have errorsFound: ', errorsFound);
240
+ standardErrorParams.push(errorsFound);
241
+ await logicalResultsSharedLib.completeLogicalResultsMain(
242
+ ...standardErrorParams
243
+ );
244
+ return {
245
+ returnResponse: 'Have errorsFound'
246
+ };
247
+ }
248
+
249
+ // concatenate partitionKey
250
+ let partitionKeyReqIdentifiers = {};
251
+ for (const [fieldName, fieldNameValue] of Object.entries(
252
+ element.partitionKeyValues
253
+ )) {
254
+ partitionKeyReqIdentifiers[fieldName] = fieldNameValue.value;
255
+ }
256
+
257
+ // concatenate sortKey
258
+ if (element.hasOwnProperty('sortKeyValues')) {
259
+ for (const [fieldName, fieldNameValue] of Object.entries(
260
+ element.sortKeyValues
261
+ )) {
262
+ partitionKeyReqIdentifiers[fieldName] = fieldNameValue.value;
263
+ }
264
+ }
265
+ _izContext.logger.debug(
266
+ 'partitionKeyReqIdentifiers: ',
267
+ partitionKeyReqIdentifiers
268
+ );
269
+
270
+ let dynamoDbIdentifiers =
271
+ await identifierObj.dynamoDbIdentifiersByStorageResource(
272
+ _izContext,
273
+ objectSchemas,
274
+ storageResources,
275
+ partitionKeyReqIdentifiers
276
+ );
277
+ _izContext.logger.debug('dynamoDbIdentifiers: ', dynamoDbIdentifiers);
278
+
279
+ if (element.hasOwnProperty('sortKeyValues')) {
280
+ let comparison = 'equals';
281
+ if (element.comparison && element.comparison !== 'equals') {
282
+ comparison = element.comparison;
283
+ let sentMessageToPaginateProcessLogical = {
284
+ Message: JSON.stringify({
285
+ logicalResultId: logicalResultId,
286
+ tableName: tableName,
287
+ partitionKeyFieldName: partitionKeyFieldName,
288
+ sortKeyFieldName: sortKeyFieldName,
289
+ dynamoDbIdentifiers: dynamoDbIdentifiers,
290
+ comparison: comparison,
291
+ overWriteCache: overWriteCache,
292
+ callingFlow: callingFlow
293
+ }),
294
+ TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(
295
+ _izContext,
296
+ 'PaginateProcessLogical_In'
297
+ )
298
+ };
299
+ _izContext.logger.debug(
300
+ 'Request params before send to topic PaginateProcessLogical_In: ',
301
+ sentMessageToPaginateProcessLogical
302
+ );
303
+
304
+ let resSNS = await sns.publishAsync(
305
+ _izContext,
306
+ sentMessageToPaginateProcessLogical
307
+ );
308
+ _izContext.logger.debug(
309
+ 'resSNS send to topic ProcessSortResult finish!',
310
+ resSNS
311
+ );
312
+
313
+ return {
314
+ returnResponse: 'Send message to PaginateProcessLogical_In'
315
+ };
316
+ } else {
317
+ let queryDatas = await dynamodbSharedLib.query(
318
+ _izContext,
319
+ dynamodbSharedLib.tableName(_izContext, tableName),
320
+ {
321
+ [partitionKeyFieldName]: dynamoDbIdentifiers[partitionKeyFieldName]
322
+ },
323
+ {
324
+ sortKeyCondition: {
325
+ comparison: comparison,
326
+ name: sortKeyFieldName,
327
+ value: dynamoDbIdentifiers[sortKeyFieldName]
328
+ }
329
+ }
330
+ );
331
+ _izContext.logger.debug('queryDatas result: ', queryDatas);
332
+
333
+ if (queryDatas.Items.length == 0) {
334
+ _izContext.logger.debug(`can't find data in ${tableName}`);
335
+ errorsFound.push(`can't find data in ${tableName}`);
336
+ standardErrorParams.push(errorsFound);
337
+ await logicalResultsSharedLib.completeLogicalResultsMain(
338
+ ...standardErrorParams
339
+ );
340
+ return {
341
+ returnResponse: 'Cannot find data in table'
342
+ };
343
+ }
344
+
345
+ for (const objInstanceBase of queryDatas.Items) {
346
+ await logicalResultsSharedLib.saveLogicalData(
347
+ _izContext,
348
+ logicalResultId,
349
+ logicalResultMain.objType,
350
+ objInstanceBase
351
+ );
352
+ }
353
+ }
354
+ } else {
355
+ // element don't have sortKey
356
+
357
+ if (sortKeyFieldName) {
358
+ _izContext.logger.debug(
359
+ 'identifiers have sortKey: query dynamo in PaginateProcessLogical'
360
+ );
361
+
362
+ let sentMessageToPaginateProcessLogical = {
363
+ Message: JSON.stringify({
364
+ logicalResultId: logicalResultId,
365
+ tableName: tableName,
366
+ partitionKeyFieldName: partitionKeyFieldName,
367
+ sortKeyFieldName: sortKeyFieldName,
368
+ dynamoDbIdentifiers: dynamoDbIdentifiers,
369
+ overWriteCache: overWriteCache,
370
+ callingFlow: callingFlow
371
+ }),
372
+ TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(
373
+ _izContext,
374
+ 'PaginateProcessLogical_In'
375
+ )
376
+ };
377
+ _izContext.logger.debug(
378
+ 'Request params before send to topic PaginateProcessLogical_In: ',
379
+ sentMessageToPaginateProcessLogical
380
+ );
381
+
382
+ let resSNS = await sns.publishAsync(
383
+ _izContext,
384
+ sentMessageToPaginateProcessLogical
385
+ );
386
+ _izContext.logger.debug(
387
+ 'resSNS send to topic ProcessSortResult finish!',
388
+ resSNS
389
+ );
390
+
391
+ return {
392
+ returnResponse: 'Send message to PaginateProcessLogical_In'
393
+ };
394
+ } else {
395
+ _izContext.logger.debug('identifiers not have sortKey: save dataId');
396
+
397
+ let getDataByPartitionKey = await dynamodbSharedLib.getItem(
398
+ _izContext,
399
+ dynamodbSharedLib.tableName(_izContext, tableName),
400
+ {
401
+ [partitionKeyFieldName]: dynamoDbIdentifiers[partitionKeyFieldName]
402
+ }
403
+ );
404
+
405
+ if (getDataByPartitionKey) {
406
+ await logicalResultsSharedLib.saveLogicalData(
407
+ _izContext,
408
+ logicalResultId,
409
+ objType,
410
+ getDataByPartitionKey
411
+ );
412
+ } else {
413
+ _izContext.logger.debug(`can't find data in ${tableName}`);
414
+ errorsFound.push(`can't find data in ${tableName}`);
415
+ standardErrorParams.push(errorsFound);
416
+ await logicalResultsSharedLib.completeLogicalResultsMain(
417
+ ...standardErrorParams
418
+ );
419
+ return {
420
+ returnResponse: 'Cannot find data in table'
421
+ };
422
+ }
423
+ }
424
+ }
425
+
426
+ // complete processLogical and send message Out
427
+ await logicalResultsSharedLib.completeLogicalResultsMain(
428
+ _izContext,
429
+ logicalResultId,
430
+ element,
431
+ objType,
432
+ overWriteCache,
433
+ callingFlow,
434
+ 'complete',
435
+ []
436
+ );
437
+
438
+ //(<additionalProcessLogical>)
439
+ //(</additionalProcessLogical>)
440
+
441
+ return {
442
+ returnResponse: 'Function ProcessLogical is Finished'
443
+ };
444
+ } catch (err) {
445
+ _izContext.logger.error('error ProcessLogicalMain: ', err);
446
+ throw err;
447
+ }
448
+ }