@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,345 @@
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 findDataSharedLib from '@izara_project/izara-core-library-find-data';
19
+ import graphSharedLib from '@izara_project/izara-core-library-graph-service';
20
+ import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb'
21
+
22
+ import { serviceConfig, identifiersObject as identifierObj } from '@izara_project/izara-core-library-service-schemas';
23
+
24
+ //(<additionalModule>)
25
+ //(</additionalModule>)
26
+
27
+ /**
28
+ * triggered from searchResult for each requiredData field per one identifiers
29
+ * @param {Object} _izContext
30
+ * @param {string} fieldName
31
+ * @param {Object} objType
32
+ * @param {Object} identifiers
33
+ * @param {Boolean} overWriteCache
34
+ *
35
+ * @returns {object} description of return value
36
+ */
37
+
38
+ export default async function findData(
39
+ _izContext,
40
+ fieldName,
41
+ objType,
42
+ identifiers,
43
+ overWriteCache,
44
+ callingFlow,
45
+
46
+ //(<additionalParams>)
47
+ //(</additionalParams>)
48
+ ) {
49
+
50
+ try {
51
+
52
+ _izContext.logger.debug('----- findData event params -----', {
53
+ fieldName: fieldName,
54
+ objType: objType,
55
+ identifiers: identifiers,
56
+ overWriteCache: overWriteCache,
57
+ callingFlow: callingFlow
58
+ });
59
+
60
+ // removeAttributes on expired
61
+ let removeAttributes = [];
62
+ //(<removeAttributes>)
63
+ //(</removeAttributes>)
64
+
65
+ let deleteDataTableOnExpired = [];
66
+
67
+ // Check/create FindDataMain status
68
+ let [findDataMainStatus, findDataId, findDataMain] = await findDataSharedLib.checkFindDataMainStatus(
69
+ _izContext,
70
+ fieldName,
71
+ objType,
72
+ identifiers,
73
+ callingFlow,
74
+ removeAttributes,
75
+ overWriteCache
76
+ );
77
+ _izContext.logger.debug('result after checkFindDataMainStatus is', {
78
+ findDataMainStatus: findDataMainStatus,
79
+ findDataId: findDataId,
80
+ findDataMain: findDataMain
81
+ })
82
+
83
+ if (findDataMainStatus != 'process') {
84
+ _izContext.logger.debug(`findDataMainStatus status isn't process :${findDataMainStatus}`)
85
+ return {
86
+ returnResponse: 'Function FindData not process'
87
+ }
88
+ };
89
+
90
+ let errorsFound = [];
91
+
92
+ let standardErrorParams = [
93
+ _izContext,
94
+ fieldName,
95
+ objType,
96
+ identifiers,
97
+ null,
98
+ overWriteCache,
99
+ callingFlow,
100
+ 'error'
101
+ ];
102
+
103
+ <% for (let dataIndex = 0; dataIndex < datas.length; dataIndex++) {
104
+ const dataItem = datas[dataIndex];
105
+ const objectType = dataItem.objectType;
106
+ const fieldNames = dataItem.fieldNames; %>
107
+ if (objType.objectType === <%- JSON.stringify(objectType) %>) {
108
+ _izContext.logger.debug('objectType: ', objType.objectType)
109
+
110
+ <% for (let fieldIndex = 0; fieldIndex < fieldNames.length; fieldIndex++) {
111
+ const storageEntry = fieldNames[fieldIndex];
112
+ const field = Object.keys(storageEntry)[0];
113
+ const storageDetails = Object.values(storageEntry)[0];
114
+ const hasDynamo = storageDetails.dynamoDB !== undefined;
115
+ const hasGraph = storageDetails.graph !== undefined;
116
+ const graphDetail = storageDetails.graph || {};
117
+ const dynamoDetail = storageDetails.dynamoDB || {};
118
+
119
+ if (hasDynamo && hasGraph) {
120
+ // dynamoDB takes priority over graph when both exist %>
121
+ if (fieldName.fieldName === <%- JSON.stringify(field) %>) {
122
+ _izContext.logger.debug('fieldName: ', fieldName.fieldName)
123
+
124
+ //(<beforeGetItem<%- objectType %><%- field %>>)
125
+ //(</beforeGetItem<%- objectType %><%- field %>>)
126
+
127
+ let identifiersBase = await identifierObj.identifiersBaseFromIdentifiers(
128
+ _izContext,
129
+ objType,
130
+ identifiers,
131
+ );
132
+ _izContext.logger.debug('create identifiersBase from identifiers: ', identifiersBase)
133
+
134
+ let objInstanceBase = await dynamodbSharedLib.getItem(
135
+ _izContext,
136
+ await dynamodbSharedLib.tableName(_izContext, <%- JSON.stringify(dynamoDetail.tableName) %>),
137
+ identifiersBase
138
+ );
139
+ _izContext.logger.debug('objInstanceBase: ', objInstanceBase)
140
+
141
+ if (!objInstanceBase) {
142
+ errorsFound.push(`can't get data in dynamo by ${identifiersBase}`)
143
+ standardErrorParams.push(errorsFound)
144
+ await findDataSharedLib.completeFindDataMain(...standardErrorParams);
145
+ return {
146
+ returnResponse: 'FindData cannot get data in dynamo'
147
+ }
148
+ }
149
+
150
+ if (!objInstanceBase.hasOwnProperty(fieldName.fieldName)) {
151
+ errorsFound.push(`data in dynamoDB have no ${fieldName.fieldName}`)
152
+ standardErrorParams.push(errorsFound)
153
+ await findDataSharedLib.completeFindDataMain(...standardErrorParams);
154
+ return {
155
+ returnResponse: 'Data have no fieldName'
156
+ }
157
+ }
158
+
159
+ //(<afterGetItem<%- objectType %><%- field %>>)
160
+ //(</afterGetItem<%- objectType %><%- field %>>)
161
+
162
+ let dataValue = objInstanceBase[fieldName.fieldName];
163
+ _izContext.logger.debug('dataValue: ', dataValue)
164
+
165
+ await findDataSharedLib.completeFindDataMain(
166
+ _izContext,
167
+ findDataMain.fieldName,
168
+ findDataMain.objType,
169
+ findDataMain.identifiers,
170
+ dataValue,
171
+ overWriteCache,
172
+ callingFlow,
173
+ 'complete'
174
+ );
175
+
176
+ <% } else if (hasDynamo) { %>
177
+ if (fieldName.fieldName === <%- JSON.stringify(field) %>) {
178
+ _izContext.logger.debug('fieldName: ', fieldName.fieldName)
179
+
180
+ //(<beforeGetItem<%- objectType %><%- field %>>)
181
+ //(</beforeGetItem<%- objectType %><%- field %>>)
182
+
183
+ let identifiersBase = await identifierObj.identifiersBaseFromIdentifiers(
184
+ _izContext,
185
+ objType,
186
+ identifiers,
187
+ );
188
+ _izContext.logger.debug('create identifiersBase from identifiers: ', identifiersBase)
189
+
190
+ let objInstanceBase = await dynamodbSharedLib.getItem(
191
+ _izContext,
192
+ await dynamodbSharedLib.tableName(_izContext, <%- JSON.stringify(dynamoDetail.tableName) %>),
193
+ identifiersBase
194
+ );
195
+ _izContext.logger.debug('objInstanceBase: ', objInstanceBase)
196
+
197
+ if (!objInstanceBase) {
198
+ errorsFound.push(`can't get data in dynamo by ${identifiersBase}`)
199
+ standardErrorParams.push(errorsFound)
200
+ await findDataSharedLib.completeFindDataMain(...standardErrorParams);
201
+ return {
202
+ returnResponse: 'FindData cannot get data in dynamo'
203
+ }
204
+ }
205
+
206
+ if (!objInstanceBase.hasOwnProperty(fieldName.fieldName)) {
207
+ errorsFound.push(`data in dynamoDB have no ${fieldName.fieldName}`)
208
+ standardErrorParams.push(errorsFound)
209
+ await findDataSharedLib.completeFindDataMain(...standardErrorParams);
210
+ return {
211
+ returnResponse: 'Data have no fieldName'
212
+ }
213
+ }
214
+
215
+ //(<afterGetItem<%- objectType %><%- field %>>)
216
+ //(</afterGetItem<%- objectType %><%- field %>>)
217
+
218
+ let dataValue = objInstanceBase[fieldName.fieldName];
219
+ _izContext.logger.debug('dataValue: ', dataValue)
220
+
221
+ await findDataSharedLib.completeFindDataMain(
222
+ _izContext,
223
+ findDataMain.fieldName,
224
+ findDataMain.objType,
225
+ findDataMain.identifiers,
226
+ dataValue,
227
+ overWriteCache,
228
+ callingFlow,
229
+ 'complete'
230
+ );
231
+
232
+ <% } else if (hasGraph) { %>
233
+ if (fieldName.fieldName === <%- JSON.stringify(field) %>) {
234
+ _izContext.logger.debug('fieldName: ', fieldName.fieldName)
235
+
236
+ //(<beforeGetNode<%- objectType %><%- field %>>)
237
+ //(</beforeGetNode<%- objectType %><%- field %>>)
238
+
239
+ const graphHandlerServiceTag = await serviceConfig.getGraphServiceTagWithCache(
240
+ _izContext,
241
+ <%- JSON.stringify(graphDetail.graphServerTag) %>,
242
+ );
243
+ _izContext.logger.debug('graphHandlerServiceTag: ', graphHandlerServiceTag)
244
+
245
+ let getDataByGraph = await graphSharedLib.getNode(
246
+ _izContext,
247
+ graphHandlerServiceTag,
248
+ objType,
249
+ {
250
+ identifiers:identifiers
251
+ },
252
+ <%- JSON.stringify(graphDetail.versionedDataLabel || undefined) %>
253
+ );
254
+
255
+ _izContext.logger.debug('getDataByGraph: ', getDataByGraph)
256
+
257
+ if (!getDataByGraph) {
258
+ errorsFound.push(`can't get data of ${objType.objectType} in graph`)
259
+ standardErrorParams.push(errorsFound)
260
+ await findDataSharedLib.completeFindDataMain(...standardErrorParams);
261
+ return {
262
+ returnResponse: 'FindData cannot get data in graph'
263
+ }
264
+ }
265
+
266
+ //(<afterGetNode<%- objectType %><%- field %>>)
267
+ //(</afterGetNode<%- objectType %><%- field %>>)
268
+
269
+ let objInstanceFull = getDataByGraph.returnValue.queryResults.refactoredNodes.objInstanceFull;
270
+ _izContext.logger.debug('objInstanceFull: ', objInstanceFull)
271
+
272
+ <% if (graphDetail.getInIdentifiers) { %>
273
+ if (!objInstanceFull.identifiers.hasOwnProperty(fieldName.fieldName)) {
274
+ errorsFound.push(`nodeProperties have no this ${fieldName.fieldName}`)
275
+ standardErrorParams.push(errorsFound)
276
+ await findDataSharedLib.completeFindDataMain(...standardErrorParams);
277
+ return {
278
+ returnResponse: 'Data have no fieldName'
279
+ }
280
+ }
281
+
282
+ let dataValue = objInstanceFull.identifiers[fieldName.fieldName];
283
+ _izContext.logger.debug('this fieldName is identifier, get dataValue in identifiers: ', dataValue)
284
+ <% } else { %>
285
+ if (!objInstanceFull.fields.hasOwnProperty(fieldName.fieldName)) {
286
+ errorsFound.push(`nodeProperties have no this ${fieldName.fieldName}`)
287
+ standardErrorParams.push(errorsFound)
288
+ await findDataSharedLib.completeFindDataMain(...standardErrorParams);
289
+ return {
290
+ returnResponse: 'Data have no fieldName'
291
+ }
292
+ }
293
+
294
+ let dataValue = objInstanceFull.fields[fieldName.fieldName];
295
+ _izContext.logger.debug('this fieldName is not identifier, get dataValue in fields: ', dataValue)
296
+ <% } %>
297
+
298
+ await findDataSharedLib.completeFindDataMain(
299
+ _izContext,
300
+ findDataMain.fieldName,
301
+ findDataMain.objType,
302
+ findDataMain.identifiers,
303
+ dataValue,
304
+ overWriteCache,
305
+ callingFlow,
306
+ 'complete'
307
+ );
308
+
309
+ <% } %>
310
+ }<% if (fieldIndex + 1 === fieldNames.length) { %>
311
+ //(<additional<%- objectType %>FieldNames>)
312
+ //(</additional<%- objectType %>FieldNames>)
313
+ <% } %>
314
+ else
315
+
316
+ <% } %> {
317
+ errorsFound.push('unrecognized fieldName')
318
+ standardErrorParams.push(errorsFound)
319
+ await findDataSharedLib.completeFindDataMain(...standardErrorParams);
320
+ return;
321
+ }
322
+ }<% if (dataIndex + 1 === datas.length) { %>
323
+ //(<additionalObjectType>)
324
+ //(</additionalObjectType>)
325
+ <% } %>
326
+ else
327
+
328
+ <% } %> {
329
+ errorsFound.push('unrecognized objectType')
330
+ standardErrorParams.push(errorsFound)
331
+ await findDataSharedLib.completeFindDataMain(...standardErrorParams);
332
+ return {
333
+ returnResponse: 'Function FindData Error'
334
+ }
335
+ }
336
+
337
+ return {
338
+ returnResponse: 'Function FindData Finish'
339
+ }
340
+
341
+ } catch (err) {
342
+ _izContext.logger.error('error FindDataMain: ', err)
343
+ throw (err)
344
+ }
345
+ }
@@ -15,7 +15,7 @@ const validatorSchema = {
15
15
  <%- prop.propertyName %>: { type: '<%- prop.type || 'string' %>' }
16
16
  <% }) -%>
17
17
  },
18
- required: [<%- startConfig.properties.filter(p => p.required !== false).map(p => `'${p.propertyName}'`).join(', ') %>]
18
+ required: [<%- startConfig.properties.filter(p => p.required === true).map(p => `'${p.propertyName}'`).join(', ') %>]
19
19
  <% } -%>
20
20
  //(</validatorSchema>)
21
21
  };
@@ -29,10 +29,10 @@ let perRecordsValidatorSchema = {
29
29
  properties: {
30
30
  <% startConfig.properties.forEach((prop, index) => { %> <%- prop.propertyName %>: {
31
31
  type: '<%- prop.type || 'string' %>'
32
- } /*__EJS_COMMA_6__*/
32
+ },
33
33
  <% }) %>
34
34
  },
35
- required: [<%- startConfig.properties.filter(p => p.required !== false).map(p => `'${p.propertyName}'`).join(', ') %>]
35
+ required: [<%- startConfig.properties.filter(p => p.required === true).map(p => `'${p.propertyName}'`).join(', ') %>]
36
36
  <% } -%>
37
37
  //(</validatorSchema>)
38
38
  };
@@ -48,10 +48,10 @@ let messageAttributeValidatorSchema = {
48
48
  Value: { type: '<%- prop.type || 'string' %>' }
49
49
  },
50
50
  required: ['Type', 'Value']
51
- } /*__EJS_COMMA_14__*/
51
+ },
52
52
  <% }) %>
53
53
  },
54
- required: [<%- startConfig.messageAttributes.filter(p => p.required !== false).map(p => `'${p.propertyName}'`).join(', ') %>]
54
+ required: [<%- startConfig.messageAttributes.filter(p => p.required === true).map(p => `'${p.propertyName}'`).join(', ') %>]
55
55
  };
56
56
  <% } else { -%>
57
57
  let messageAttributeValidatorSchema = null;
@@ -12,7 +12,7 @@ const validatorSchema = {
12
12
  <%- prop.propertyName %>: { type: '<%- prop.type || 'string' %>' }
13
13
  <% }) -%>
14
14
  },
15
- required: [<%- startConfig.properties.filter(p => p.required !== false).map(p => `'${p.propertyName}'`).join(', ') %>]
15
+ required: [<%- startConfig.properties.filter(p => p.required === true).map(p => `'${p.propertyName}'`).join(', ') %>]
16
16
  <% } -%>
17
17
  //(</validatorSchema>)
18
18
  };
@@ -29,10 +29,10 @@ let perRecordsValidatorSchema = {
29
29
  properties: {
30
30
  <% startConfig.properties.forEach((prop, index) => { %> <%- prop.propertyName %>: {
31
31
  type: '<%- prop.type || 'string' %>'
32
- } /*__EJS_COMMA_6__*/
32
+ },
33
33
  <% }) %>
34
34
  },
35
- required: [<%- startConfig.properties.filter(p => p.required !== false).map(p => `'${p.propertyName}'`).join(', ') %>]
35
+ required: [<%- startConfig.properties.filter(p => p.required === true).map(p => `'${p.propertyName}'`).join(', ') %>]
36
36
  <% } -%>
37
37
  //(</validatorSchema>)
38
38
  };
@@ -48,10 +48,10 @@ let messageAttributeValidatorSchema = {
48
48
  Value: { type: '<%- prop.type || 'string' %>' }
49
49
  },
50
50
  required: ['Type', 'Value']
51
- } /*__EJS_COMMA_14__*/
51
+ },
52
52
  <% }) %>
53
53
  },
54
- required: [<%- startConfig.messageAttributes.filter(p => p.required !== false).map(p => `'${p.propertyName}'`).join(', ') %>]
54
+ required: [<%- startConfig.messageAttributes.filter(p => p.required === true).map(p => `'${p.propertyName}'`).join(', ') %>]
55
55
  };
56
56
  <% } else { -%>
57
57
  let messageAttributeValidatorSchema = null;
@@ -0,0 +1,162 @@
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(
27
+ recordHandlerSharedLib.baseValidatorSchema({
28
+ type: 'object',
29
+ required: ['body', 'messageAttributes'],
30
+ properties: {
31
+ body: {
32
+ type: 'object'
33
+ },
34
+ messageAttributes: {
35
+ type: 'object'
36
+ }
37
+ }
38
+ })
39
+ );
40
+
41
+ // set schema for record.body.Message
42
+ const perRecordsValidatorSchema = {
43
+ type: 'object',
44
+ required: [
45
+ 'logicalResultId',
46
+ 'tableName',
47
+ 'partitionKeyFieldName',
48
+ 'sortKeyFieldName',
49
+ 'dynamoDbIdentifiers',
50
+ 'startKey',
51
+ 'overwriteUniqueRequestId',
52
+ 'overWriteCache'
53
+ ],
54
+ properties: {
55
+ logicalResultId: {
56
+ type: 'string'
57
+ },
58
+ tableName: {
59
+ type: 'string'
60
+ },
61
+ partitionKeyFieldName: {
62
+ type: 'string'
63
+ },
64
+ sortKeyFieldName: {
65
+ type: 'string'
66
+ },
67
+ dynamoDbIdentifiers: {
68
+ type: 'object'
69
+ },
70
+ comparison: {
71
+ type: 'string',
72
+ default: ''
73
+ },
74
+ startKey: {
75
+ type: 'object'
76
+ },
77
+ overwriteUniqueRequestId: {
78
+ type: 'string'
79
+ },
80
+ overWriteCache: {
81
+ type: 'boolean'
82
+ },
83
+ callingFlow: {
84
+ type: 'string',
85
+ default: ''
86
+ }
87
+ }
88
+ };
89
+
90
+ export const main = middleware.wrap(async (event, context) => {
91
+ try {
92
+ let recordPromises = [];
93
+
94
+ // loop each record and send to mainFunction
95
+ await Promise.all(
96
+ event.Records.map(async record => {
97
+ // promise.all for map() function
98
+
99
+ // --- reforming record.body for Dsq request
100
+ record = recordHandlerSharedLib.reformatDsqMessage(
101
+ record._izContext,
102
+ record
103
+ );
104
+ record._izContext.logger.debug(
105
+ 'record PaginateProcessLogicalHdrDsq after reform',
106
+ record
107
+ );
108
+
109
+ let passOnProperties = [];
110
+
111
+ // validate message (and MessageAttributes)
112
+ await recordHandlerSharedLib.validateRecord(
113
+ record, // one record will send to mainFunction
114
+ 'PaginateProcessLogicalHdrDsq', // queue name that need to retry or send to dlq
115
+ perRecordsValidatorSchema // schema for record.Message
116
+ );
117
+
118
+ // add argument (to invoke lambda) to passOnProperties[]
119
+ passOnProperties.push(record.body.Message.logicalResultId);
120
+ passOnProperties.push(record.body.Message.tableName);
121
+ passOnProperties.push(record.body.Message.partitionKeyFieldName);
122
+ passOnProperties.push(record.body.Message.sortKeyFieldName);
123
+ passOnProperties.push(record.body.Message.dynamoDbIdentifiers);
124
+ passOnProperties.push(record.body.Message.comparison);
125
+ passOnProperties.push(record.body.Message.startKey);
126
+ passOnProperties.push(record.body.Message.overwriteUniqueRequestId);
127
+ passOnProperties.push(record.body.Message.overWriteCache);
128
+ passOnProperties.push(record.body.Message.callingFlow);
129
+ record._izContext.logger.debug(
130
+ 'passOnProperties in handler',
131
+ passOnProperties
132
+ );
133
+
134
+ // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
135
+ let recordPromise = recordHandlerSharedLib.recordHandler(
136
+ record, // one record will send to mainFunction
137
+ paginateProcessLogical, // mainFunction that need to invoke.
138
+ 'PaginateProcessLogicalHdrDsq', // queue name that need to retry or send to dlq
139
+ passOnProperties // all parameters that mainFunction needed.
140
+ );
141
+ record._izContext.logger.debug('after recordPromise in handler');
142
+ recordPromises.push(recordPromise); // push promise to recordPromises
143
+ })
144
+ );
145
+
146
+ Logger.debug('before Promise.all(recordPromises) in handler');
147
+ try {
148
+ // --- main await all promises
149
+ await Promise.all(recordPromises); // await all promises
150
+
151
+ return event.Records; // return all for local testing
152
+ } catch {
153
+ Logger.debug(
154
+ 'Promise.all(recordPromises) in handler threw error (at least one record did no resolve)'
155
+ );
156
+ }
157
+ Logger.debug('after Promise.all(recordPromises) in handler');
158
+ } catch (err) {
159
+ Logger.error('Unhandled Error, PaginateProcessLogicalHdrDsq: ', err);
160
+ throw err;
161
+ }
162
+ });