@izara_project/izara-core-generate-service-code 1.0.68 → 1.0.70

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 (129) hide show
  1. package/package.json +1 -1
  2. package/scripts/format-ejs.js +36 -32
  3. package/src/compile/compileProject.js +26 -10
  4. package/src/compile/loadSchemas.js +122 -59
  5. package/src/emit/coreFunction/emitCoreFunctionArtifacts.js +163 -0
  6. package/src/emit/coreFunction/templates/CoreFunction_Yaml.ejs +38 -0
  7. package/src/emit/coreFunction/templates/CoreResource_Yaml.ejs +235 -0
  8. package/src/emit/coreFunction/templates/GenerateSeedDataDynamo_HdrInv.ejs +16 -0
  9. package/src/emit/coreFunction/templates/GenerateSeedDataDynamo_Main.ejs +38 -0
  10. package/src/emit/coreFunction/templates/GenerateSeedDataGraphData_HdrInv.ejs +16 -0
  11. package/src/emit/coreFunction/templates/GenerateSeedDataGraphData_Main.ejs +32 -0
  12. package/src/emit/coreFunction/templates/GenerateSeedDataGraphSchema_HdrInv.ejs +16 -0
  13. package/src/emit/coreFunction/templates/GenerateSeedDataGraphSchema_Main.ejs +71 -0
  14. package/src/emit/coreFunction/templates/GeneratedGraphNodeSchemas.ejs +47 -0
  15. package/src/emit/coreFunction/templates/GeneratedGraphRelSchemas.ejs +27 -0
  16. package/src/emit/coreFunction/templates/GeneratedTableConfigs.ejs +34 -0
  17. package/src/emit/coreFunction/templates/InitialSetupConfig.ejs +108 -0
  18. package/src/emit/coreFunction/templates/InitialSetup_HdrInv.ejs +12 -0
  19. package/src/emit/coreFunction/templates/InitialSetup_Main.ejs +51 -0
  20. package/src/emit/coreFunction/templates/RemoveSeedDataDynamo_HdrInv.ejs +16 -0
  21. package/src/emit/coreFunction/templates/RemoveSeedDataDynamo_Main.ejs +31 -0
  22. package/src/emit/coreFunction/templates/UploadSchema_HdrInv.ejs +37 -0
  23. package/src/emit/coreFunction/templates/UploadSchema_Main.ejs +52 -0
  24. package/src/emit/crud/emitCrudApplicationArtifacts.js +194 -41
  25. package/src/emit/crud/emitDynamicCrudFlowSchemas.js +34 -17
  26. package/src/emit/crud/generateCrudApplicationArtifacts.js +14 -6
  27. package/src/emit/crud/generateDynamicCrudFlowSchemas.js +4 -1
  28. package/src/emit/crud/templates/CreateEndpoint_Main.ejs +1 -1
  29. package/src/emit/crud/templates/DeleteEndpoint_Main.ejs +1 -1
  30. package/src/emit/crud/templates/GetEndpoint_Main.ejs +2 -2
  31. package/src/emit/crud/templates/GetRangeEndpoint_Main.ejs +1 -1
  32. package/src/emit/crud/templates/UpdateEndpoint_Main.ejs +1 -1
  33. package/src/emit/custom/customFlows.js +23 -13
  34. package/src/emit/custom/emitCustomFlowApplicationArtifacts.js +535 -114
  35. package/src/emit/custom/generateCustomFlowApplicationArtifacts.js +28 -8
  36. package/src/emit/custom/templates/FlowEndpoint_Main.ejs +2 -2
  37. package/src/emit/custom/templates/FlowStep_Main.ejs +1 -1
  38. package/src/emit/custom/templates/s3/CreateObject_Main.ejs +1 -1
  39. package/src/emit/custom/templates/s3/FlowHandler_HdrS3.ejs +2 -2
  40. package/src/emit/custom/templates/s3/ReservedLimit_HdrSqs.ejs +1 -1
  41. package/src/emit/custom/templates/s3/ReservedLimit_Main.ejs +1 -1
  42. package/src/emit/custom/templates/triggerCache/CheckTriggerCache_HdrSqs.ejs +4 -4
  43. package/src/emit/function/functionYamlArtifact.js +273 -97
  44. package/src/emit/function/templates/ApiFunction_Yaml.ejs +7 -0
  45. package/src/emit/function/templates/EventBridgeFunction_Yaml.ejs +6 -0
  46. package/src/emit/function/templates/InvFunction_Yaml.ejs +5 -0
  47. package/src/emit/function/templates/S3Function_Yaml.ejs +16 -0
  48. package/src/emit/function/templates/SqsFunction_Yaml.ejs +10 -0
  49. package/src/emit/function/templates/WbsFunction_Yaml.ejs +10 -0
  50. package/src/emit/rbac/emitDynamicRbacFlowSchemas.js +28 -30
  51. package/src/emit/rbac/emitRbacApplicationArtifacts.js +6 -6
  52. package/src/emit/rbac/generateCreateTargetRoleHandler.js +6 -4
  53. package/src/emit/rbac/generateDynamicRbacFlowSchemas.js +8 -2
  54. package/src/emit/rbac/rbacFlowTag.js +3 -1
  55. package/src/emit/rbac/templates/UserRbacFlow_Main.ejs +1 -1
  56. package/src/emit/relationship/emitDynamicRelationshipFlowSchemas.js +26 -10
  57. package/src/emit/relationship/emitRelationshipApplicationArtifacts.js +189 -37
  58. package/src/emit/relationship/generateDynamicRelationshipFlowSchemas.js +8 -2
  59. package/src/emit/relationship/generateRelationshipApplicationArtifacts.js +15 -6
  60. package/src/emit/relationship/templates/ChangeRelationship_Main.ejs +1 -1
  61. package/src/emit/relationship/templates/CreateRelationship_Main.ejs +1 -1
  62. package/src/emit/relationship/templates/DeleteRelationship_Main.ejs +1 -1
  63. package/src/emit/relationship/templates/GetRelationship_Main.ejs +1 -1
  64. package/src/emit/relationship/templates/MoveRelationship_Main.ejs +1 -1
  65. package/src/emit/relationship/templates/UpdateRelationship_Main.ejs +1 -1
  66. package/src/emit/resource/emitResourceArtifacts.js +249 -123
  67. package/src/emit/resource/generateResourceArtifacts.js +15 -6
  68. package/src/emit/resource/templates/DynamoDBTable_Yaml.ejs +18 -18
  69. package/src/emit/resource/templates/FlowOut_Yaml.ejs +5 -5
  70. package/src/emit/resource/templates/GeneratedLambdaRoleServiceConfig.ejs +10 -9
  71. package/src/emit/resource/templates/ResourceBeforeLogicalYaml.ejs +44 -44
  72. package/src/emit/resource/templates/ResourceSqsYaml.ejs +36 -36
  73. package/src/emit/resource/templates/ResourceYaml.ejs +48 -48
  74. package/src/emit/resource/templates/S3Subscription_Yaml.ejs +7 -0
  75. package/src/emit/resource/templates/SharedResource_Yaml.ejs +11 -11
  76. package/src/emit/resource/templates/SystemDynamoDB_Yaml.ejs +122 -105
  77. package/src/emit/resource/templates/WebSocketSubscription_Yaml.ejs +7 -0
  78. package/src/emit/shared/templates/FindData_HdrSqs.ejs +120 -0
  79. package/src/emit/shared/templates/FindData_Main.ejs +345 -0
  80. package/src/emit/{crud → shared}/templates/FlowHandler_HdrApi.ejs +1 -1
  81. package/src/emit/{relationship → shared}/templates/FlowHandler_HdrDsq.ejs +4 -4
  82. package/src/emit/{crud → shared}/templates/FlowHandler_HdrInv.ejs +1 -1
  83. package/src/emit/{crud → shared}/templates/FlowHandler_HdrSqs.ejs +4 -4
  84. package/src/emit/shared/templates/PaginateProcessLogical_HdrDsq.ejs +162 -0
  85. package/src/emit/shared/templates/PaginateProcessLogical_HdrSqs.ejs +140 -0
  86. package/src/emit/shared/templates/PaginateProcessLogical_Main.ejs +268 -0
  87. package/src/emit/{relationship/templates/FlowHandler_HdrSqs.ejs → shared/templates/ProcessLogical_HdrSqs.ejs} +40 -55
  88. package/src/emit/shared/templates/ProcessLogical_Main.ejs +448 -0
  89. package/src/emit/system/emitSystemFindDataArtifacts.js +266 -0
  90. package/src/emit/system/emitSystemWebSocketArtifacts.js +61 -165
  91. package/src/emit/system/templates/WebSocketComplete_HdrSqs.ejs +48 -0
  92. package/src/emit/system/templates/WebSocketComplete_Main.ejs +91 -0
  93. package/src/emit/system/templates/WebSocketComplete_Yaml.ejs +19 -0
  94. package/src/emit/system/templates/WebSocketConnect.ejs +45 -0
  95. package/src/emit/system/templates/WebSocketConnect_Yaml.ejs +11 -0
  96. package/src/generate.js +166 -36
  97. package/src/generateIntTest.js +76 -28
  98. package/src/generateResourceIntTest.js +35 -12
  99. package/src/generateResources/IntTest/generateResources/generateResources.js +5 -2
  100. package/src/generateResources/IntTest/generateResources/templateResources.ejs +18 -30
  101. package/src/generateResources/IntTest/generateTests/events/events.js +1 -1
  102. package/src/generateResources/IntTest/generateTests/events/templateEvents.ejs +13 -10
  103. package/src/generateResources/IntTest/generateTests/generateTemplate.js +2 -2
  104. package/src/generateResources/IntTest/generateTests/pathIntTest/pathIntTest.js +2 -1
  105. package/src/generateResources/IntTest/generateTests/pathIntTest/template.ejs +1 -3
  106. package/src/generateResources/IntTest/generateTests/tests/templateTests.ejs +1 -1
  107. package/src/generateResources/IntTest/generateTests/tests/tests.js +7 -3
  108. package/src/generateResources/IntTest/libs/{libs.js → IntTestGenerateLib.js} +34 -23
  109. package/src/generateResources/IntTest/upload/uploadIntTest.js +33 -19
  110. package/src/intTestGeneratorShared.js +15 -10
  111. package/src/output/commitArtifacts.js +99 -39
  112. package/src/output/mergeHooks.js +34 -21
  113. package/src/output/validateArtifacts.js +37 -27
  114. package/src/plan/buildGenerationPlan.js +24 -13
  115. package/test/core.test.js +117 -58
  116. package/test/createTargetRoleHandler.test.js +1 -1
  117. package/test/crudApplicationArtifacts.test.js +132 -31
  118. package/test/customFlowApplicationArtifacts.test.js +353 -71
  119. package/test/dynamicCrudFlowSchemas.test.js +74 -26
  120. package/test/dynamicRbacFlowSchemas.test.js +61 -14
  121. package/test/dynamicRelationshipFlowSchemas.test.js +65 -18
  122. package/test/functionYamlArtifact.test.js +67 -10
  123. package/test/intTestApi.test.js +9 -10
  124. package/test/publicApi.test.js +178 -36
  125. package/test/relationshipApplicationArtifacts.test.js +90 -19
  126. package/test/resourceArtifacts.test.js +173 -33
  127. package/src/emit/relationship/dynamicRelationshipFlowSchemaTemplate.js +0 -11
  128. package/src/emit/relationship/templates/FlowHandler_HdrApi.ejs +0 -59
  129. package/src/emit/relationship/templates/FlowHandler_HdrInv.ejs +0 -47
@@ -0,0 +1,140 @@
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 { middlewareHandler as middleware } from '@izara_project/izara-middleware';
19
+ import Logger from '@izara_project/izara-core-library-logger';
20
+ import { recordHandlerSharedLib } from '@izara_project/izara-core-library-record-handler';
21
+ import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
22
+
23
+ import paginateProcessLogical from './PaginateProcessLogical_Main.js';
24
+
25
+ // validate event properties in body.Message of sqs event
26
+ middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
27
+
28
+ // set schema for record.body.Message
29
+ const perRecordsValidatorSchema = {
30
+ type: 'object',
31
+ required: [
32
+ 'logicalResultId',
33
+ 'tableName',
34
+ 'partitionKeyFieldName',
35
+ 'sortKeyFieldName',
36
+ 'dynamoDbIdentifiers',
37
+ 'overWriteCache'
38
+ ],
39
+ properties: {
40
+ logicalResultId: {
41
+ type: 'string'
42
+ },
43
+ tableName: {
44
+ type: 'string'
45
+ },
46
+ partitionKeyFieldName: {
47
+ type: 'string'
48
+ },
49
+ sortKeyFieldName: {
50
+ type: 'string'
51
+ },
52
+ dynamoDbIdentifiers: {
53
+ type: 'object'
54
+ },
55
+ comparison: {
56
+ type: 'string',
57
+ default: ''
58
+ },
59
+ startKey: {
60
+ type: 'object',
61
+ default: {}
62
+ },
63
+ overwriteUniqueRequestId: {
64
+ type: 'string',
65
+ default: ''
66
+ },
67
+ overWriteCache: {
68
+ type: 'boolean'
69
+ },
70
+ callingFlow: {
71
+ type: 'string',
72
+ default: ''
73
+ }
74
+ }
75
+ };
76
+
77
+ export const main = middleware.wrap(async (event, context) => {
78
+ try {
79
+ let recordPromises = [];
80
+
81
+ // loop each record and send to mainFunction
82
+ await Promise.all(
83
+ event.Records.map(async record => {
84
+ // promise.all for map() function
85
+
86
+ let passOnProperties = [];
87
+ record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
88
+
89
+ // validate message (and MessageAttributes)
90
+ await recordHandlerSharedLib.validateRecord(
91
+ record, // one record will send to mainFunction
92
+ 'PaginateProcessLogicalHdrSqs', // queue name that need to retry or send to dlq
93
+ perRecordsValidatorSchema // schema for record.Message
94
+ );
95
+
96
+ // add argument (to invoke lambda) to passOnProperties[]
97
+ passOnProperties.push(record.body.Message.logicalResultId);
98
+ passOnProperties.push(record.body.Message.tableName);
99
+ passOnProperties.push(record.body.Message.partitionKeyFieldName);
100
+ passOnProperties.push(record.body.Message.sortKeyFieldName);
101
+ passOnProperties.push(record.body.Message.dynamoDbIdentifiers);
102
+ passOnProperties.push(record.body.Message.comparison);
103
+ passOnProperties.push(record.body.Message.startKey);
104
+ passOnProperties.push(record.body.Message.overwriteUniqueRequestId);
105
+ passOnProperties.push(record.body.Message.overWriteCache);
106
+ passOnProperties.push(record.body.Message.callingFlow);
107
+ record._izContext.logger.debug(
108
+ 'passOnProperties in handler',
109
+ passOnProperties
110
+ );
111
+
112
+ // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
113
+ let recordPromise = recordHandlerSharedLib.recordHandler(
114
+ record, // one record will send to mainFunction
115
+ paginateProcessLogical, // mainFunction that need to invoke.
116
+ 'PaginateProcessLogicalHdrSqs', // queue name that need to retry or send to dlq
117
+ passOnProperties // all parameters that mainFunction needed.
118
+ );
119
+ record._izContext.logger.debug('after recordPromise in handler');
120
+ recordPromises.push(recordPromise); // push promise to recordPromises
121
+ })
122
+ );
123
+
124
+ Logger.debug('before Promise.all(recordPromises) in handler');
125
+ try {
126
+ // --- main await all promises
127
+ await Promise.all(recordPromises); // await all promises
128
+
129
+ return event.Records; // return all for local testing
130
+ } catch {
131
+ Logger.debug(
132
+ 'Promise.all(recordPromises) in handler threw error (at least one record did no resolve)'
133
+ );
134
+ }
135
+ Logger.debug('after Promise.all(recordPromises) in handler');
136
+ } catch (err) {
137
+ Logger.error('Unhandled Error, PaginateProcessLogicalHdrSqs: ', err);
138
+ throw err;
139
+ }
140
+ });
@@ -0,0 +1,268 @@
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 logicalResultsSharedLib from '@izara_project/izara-core-library-logical-result';
19
+ import sqsSharedLib from '@izara_project/izara-core-library-sqs';
20
+ import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
21
+ import asyncFlowSharedLib from '@izara_project/izara-core-library-asynchronous-flow';
22
+
23
+ import { sqs } from '@izara_project/izara-core-library-external-request';
24
+
25
+ import { NoRetryError } from '@izara_project/izara-core-library-core';
26
+
27
+ // set query limit
28
+ const limit = 2;
29
+
30
+ /**
31
+ * performs the logical operation/filter/search in the element, saves into LogicalResultsData table
32
+ * @param {Object} _izContext
33
+ * @param {string} logicalResultId
34
+ * @param {string} tableName
35
+ * @param {string} partitionKeyFieldName
36
+ * @param {string} sortKeyFieldName
37
+ * @param {Object} dynamoDbIdentifiers
38
+ * @param {string} comparison
39
+ * @param {Object} startKey
40
+ * @param {string} overwriteUniqueRequestId
41
+ * @param {boolean} overwriteCache
42
+ * @param {string} callingFlow
43
+ *
44
+ * @returns {string} description of return value
45
+ */
46
+
47
+ export default async function paginateProcessLogical(
48
+ _izContext,
49
+ logicalResultId,
50
+ tableName,
51
+ partitionKeyFieldName,
52
+ sortKeyFieldName,
53
+ dynamoDbIdentifiers,
54
+ comparison, // optional
55
+ startKey, // optional
56
+ overwriteUniqueRequestId, // optional
57
+ overWriteCache,
58
+ callingFlow // optional
59
+ ) {
60
+ try {
61
+ _izContext.logger.debug('----- PaginateProcessLogical event params -----', {
62
+ logicalResultId: logicalResultId,
63
+ tableName: tableName,
64
+ partitionKeyFieldName: partitionKeyFieldName,
65
+ sortKeyFieldName: sortKeyFieldName,
66
+ dynamoDbIdentifiers: dynamoDbIdentifiers,
67
+ comparison: comparison,
68
+ startKey: startKey,
69
+ overwriteUniqueRequestId: overwriteUniqueRequestId,
70
+ overWriteCache: overWriteCache,
71
+ callingFlow: callingFlow
72
+ });
73
+
74
+ // Check/Create logicalResultsMain
75
+ let [checkUniqueRequestProcessingStatus, logicalResultsMain] =
76
+ await asyncFlowSharedLib.checkUniqueRequestProcessing(
77
+ _izContext,
78
+ 'LogicalResultsMain',
79
+ {
80
+ logicalResultId: logicalResultId
81
+ },
82
+ 'paginateProcessLogical',
83
+ overwriteUniqueRequestId
84
+ );
85
+ _izContext.logger.debug('After check uniqueRequestProcessingStatus:', {
86
+ checkUniqueRequestProcessingStatus: checkUniqueRequestProcessingStatus,
87
+ logicalResultsMain: logicalResultsMain
88
+ });
89
+
90
+ if (checkUniqueRequestProcessingStatus == 'stop') {
91
+ return {
92
+ returnResponse: 'process already stop'
93
+ };
94
+ } else if (checkUniqueRequestProcessingStatus == 'recordNotFound') {
95
+ // should always have unless another request already completed it, in which case nothing to do
96
+ return {
97
+ returnResponse: 'record not found'
98
+ };
99
+ }
100
+
101
+ let errorsFound = [];
102
+ let standardErrorParams = [
103
+ _izContext,
104
+ logicalResultId,
105
+ logicalResultsMain.logicalElement,
106
+ logicalResultsMain.objType,
107
+ overWriteCache,
108
+ callingFlow,
109
+ 'error'
110
+ ];
111
+
112
+ let queryElements = {
113
+ limit: limit
114
+ };
115
+
116
+ //if received startKey validate it, if not received will return null
117
+ startKey = asyncFlowSharedLib.validateStartKeyParam(
118
+ _izContext,
119
+ startKey,
120
+ partitionKeyFieldName,
121
+ sortKeyFieldName
122
+ );
123
+
124
+ if (startKey === false) {
125
+ throw new NoRetryError('split processing received invalid startKey');
126
+ }
127
+ _izContext.logger.debug('startKey :', startKey);
128
+
129
+ if (startKey) {
130
+ queryElements['exclusiveStartKey'] = {
131
+ [partitionKeyFieldName]: startKey[partitionKeyFieldName],
132
+ [sortKeyFieldName]: startKey[sortKeyFieldName]
133
+ };
134
+ }
135
+
136
+ if (comparison) {
137
+ queryElements['sortKeyCondition'] = {
138
+ comparison: comparison,
139
+ name: sortKeyFieldName,
140
+ value: dynamoDbIdentifiers[sortKeyFieldName]
141
+ };
142
+ }
143
+
144
+ let queryDatas = await dynamodbSharedLib.query(
145
+ _izContext,
146
+ await dynamodbSharedLib.tableName(_izContext, tableName),
147
+ {
148
+ [partitionKeyFieldName]: dynamoDbIdentifiers[partitionKeyFieldName]
149
+ },
150
+ queryElements
151
+ );
152
+ _izContext.logger.debug('queryDatas result: ', queryDatas);
153
+
154
+ if (!startKey && queryDatas.Items.length == 0) {
155
+ _izContext.logger.debug(`can't find data in table ${tableName}`);
156
+ errorsFound.push(`can't find data in table ${tableName}`);
157
+ standardErrorParams.push(errorsFound);
158
+ await logicalResultsSharedLib.completeLogicalResultsMain(
159
+ ...standardErrorParams
160
+ );
161
+ return {
162
+ returnResponse: 'Cannot find data in table'
163
+ };
164
+ }
165
+
166
+ // For conditionalFieldValues
167
+ let objInstanceBases = queryDatas.Items;
168
+ const conditionalFieldValues =
169
+ logicalResultsMain.logicalElement.conditionalFieldValues;
170
+
171
+ if (
172
+ Array.isArray(conditionalFieldValues) &&
173
+ conditionalFieldValues.length > 0
174
+ ) {
175
+ for (const conditionalFieldValue of conditionalFieldValues) {
176
+ _izContext.logger.debug(
177
+ 'conditionalFieldValue: ',
178
+ conditionalFieldValue
179
+ );
180
+
181
+ let conditionalFieldName = conditionalFieldValue.fieldName;
182
+
183
+ if (conditionalFieldValue.hasOwnProperty('includeValues')) {
184
+ let includeValues = conditionalFieldValue.includeValues; // array
185
+
186
+ objInstanceBases = objInstanceBases.filter(objInstanceBase => {
187
+ return includeValues.includes(
188
+ objInstanceBase[conditionalFieldName]
189
+ );
190
+ });
191
+ } else if (conditionalFieldValue.hasOwnProperty('excludeValues')) {
192
+ let excludeValues = conditionalFieldValue.excludeValues; // array
193
+
194
+ objInstanceBases = objInstanceBases.filter(objInstanceBase => {
195
+ return !excludeValues.includes(
196
+ objInstanceBase[conditionalFieldName]
197
+ );
198
+ });
199
+ }
200
+ }
201
+ _izContext.logger.debug(
202
+ 'objInstanceBases after conditionalFieldValues: ',
203
+ objInstanceBases
204
+ );
205
+ }
206
+
207
+ for (const objInstanceBase of objInstanceBases) {
208
+ await logicalResultsSharedLib.saveLogicalData(
209
+ _izContext,
210
+ logicalResultId,
211
+ logicalResultsMain.objType,
212
+ objInstanceBase
213
+ );
214
+ }
215
+
216
+ if (queryDatas.hasOwnProperty('LastEvaluatedKey')) {
217
+ if (!overwriteUniqueRequestId) {
218
+ overwriteUniqueRequestId = _izContext.uniqueRequestId;
219
+ }
220
+
221
+ let continuePaginationMsg = {
222
+ MessageBody: JSON.stringify({
223
+ logicalResultId: logicalResultId,
224
+ tableName: tableName,
225
+ partitionKeyFieldName: partitionKeyFieldName,
226
+ sortKeyFieldName: sortKeyFieldName,
227
+ dynamoDbIdentifiers: dynamoDbIdentifiers,
228
+ comparison: comparison,
229
+ startKey: queryDatas.LastEvaluatedKey,
230
+ overwriteUniqueRequestId: overwriteUniqueRequestId,
231
+ overWriteCache: overWriteCache,
232
+ callingFlow: callingFlow
233
+ }),
234
+ QueueUrl: await sqsSharedLib.sqsQueueUrl(
235
+ _izContext,
236
+ 'PaginateProcessLogicalHdrDsq'
237
+ )
238
+ };
239
+
240
+ _izContext.logger.debug(
241
+ 'continuePaginationMessage: ',
242
+ continuePaginationMsg
243
+ );
244
+ await sqs.sendMessage(_izContext, continuePaginationMsg);
245
+
246
+ return {
247
+ returnResponse: 'Continue PaginateProcessLogical'
248
+ };
249
+ } else {
250
+ await logicalResultsSharedLib.completeLogicalResultsMain(
251
+ _izContext,
252
+ logicalResultId,
253
+ logicalResultsMain.logicalElement,
254
+ logicalResultsMain.objType,
255
+ overWriteCache,
256
+ callingFlow,
257
+ 'complete'
258
+ );
259
+ }
260
+
261
+ return {
262
+ returnResponse: 'Function PaginateProcessLogical is Finished'
263
+ };
264
+ } catch (err) {
265
+ _izContext.logger.error('error PaginateProcessLogicalMain: ', err);
266
+ throw err;
267
+ }
268
+ }
@@ -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
  });