@izara_project/izara-core-generate-service-code 1.0.39 → 1.0.40

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 (29) hide show
  1. package/package.json +6 -6
  2. package/src/generateCode/generateFlowStepWithPlugIn/byConfig/handler/data.js +56 -0
  3. package/src/generateCode/generateFlowStepWithPlugIn/byConfig/handler/templateAwaitingStep.ejs +105 -0
  4. package/src/generateCode/generateFlowStepWithPlugIn/byConfig/handler/templatePaginated.ejs +137 -0
  5. package/src/generateCode/generateFlowStepWithPlugIn/byConfig/mainFunction/data.js +57 -0
  6. package/src/generateCode/generateFlowStepWithPlugIn/byConfig/mainFunction/templateAwaitingStep.ejs +129 -0
  7. package/src/generateCode/generateFlowStepWithPlugIn/byConfig/mainFunction/templatePaginated.ejs +59 -0
  8. package/src/generateCode/generateFlowStepWithPlugIn/byConfig/sns-sqs/data.js +50 -0
  9. package/src/generateCode/generateFlowStepWithPlugIn/byConfig/sns-sqs/queueNoTopic.ejs +43 -0
  10. package/src/generateCode/generateFlowStepWithPlugIn/byConfig/sns-sqs/snsTemplate.ejs +58 -0
  11. package/src/generateCode/generateFlowStepWithPlugIn/byConfig/sns-sqs/sqsTemplate.ejs +43 -0
  12. package/src/generateCode/generateFlowStepWithPlugIn/byConfig/yaml/data.js +47 -0
  13. package/src/generateCode/generateFlowStepWithPlugIn/byConfig/yaml/template.ejs +43 -0
  14. package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/handler/data.js +7 -1
  15. package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/mainFunction/data.js +38 -6
  16. package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/mainFunction/template.ejs +5 -16
  17. package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/mainFunction/templateByConfig/awaitingSteps.ejs +63 -0
  18. package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/mainFunction/templateByConfig/templateSendPlugin.ejs +18 -0
  19. package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/queueNtopic/sqsTemplate.ejs +7 -7
  20. package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/topicOut/data.js +1 -1
  21. package/src/generateCode/generateFlowStepWithPlugIn/index(old).js +290 -0
  22. package/src/generateCode/generateFlowStepWithPlugIn/index.js +411 -155
  23. package/src/generateCode/generateInitialSetup/externalServiceComponent/lambdaRole/data.js +22 -0
  24. package/src/generateCode/generateInitialSetup/externalServiceComponent/snsTopicSubscriptions/data.js +16 -0
  25. package/src/generateCode/generateSchema/actionEndpointCompleteComponent/create/mainFunction/template.ejs +44 -4
  26. package/src/generateCode/generateSchema/actionEndpointComponent/mainFunction/create/main/template.ejs +58 -40
  27. package/src/libs/Libs.js +21 -15
  28. package/src/generateCode/generateInitialSetup/externalServiceComponent/lambdaRole/request.json +0 -18
  29. package/src/generateCode/generateInitialSetup/externalServiceComponent/snsTopicSubscriptions/request.json +0 -12
@@ -20,7 +20,6 @@ import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow
20
20
  import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
21
21
  import snsSharedLib from '@izara_project/izara-core-library-sns';
22
22
  import { sns } from '@izara_project/izara-core-library-external-request';
23
- import _ from 'lodash';
24
23
  import { objectHash as hash } from '@izara_project/izara-shared-core';
25
24
  import { consts } from '@izara_project/izara-core-library-service-schemas';
26
25
  import { NoRetryError } from '@izara_project/izara-core-library-core';
@@ -81,6 +80,30 @@ function validateInput(returnValue, status, graphServiceTag, errorsFound) {
81
80
  }
82
81
  }
83
82
 
83
+ /**
84
+ * @param {*} value
85
+ */
86
+ function isEmpty(value) {
87
+ if (value == null) return true;
88
+
89
+ if (
90
+ Array.isArray(value) ||
91
+ typeof value === 'string'
92
+ ) {
93
+ return value.length === 0;
94
+ }
95
+
96
+ if (value instanceof Map || value instanceof Set) {
97
+ return value.size === 0;
98
+ }
99
+
100
+ if (typeof value === 'object') {
101
+ return Object.keys(value).length === 0;
102
+ }
103
+
104
+ return false;
105
+ }
106
+
84
107
  /**
85
108
  * @param {*} returnValue
86
109
  * @returns {object|null}
@@ -184,7 +207,7 @@ export default async function createObjectComplete(
184
207
  passBackProperties,
185
208
  });
186
209
 
187
- if (_.isEmpty(returnValue.requestParams)) {
210
+ if (isEmpty(returnValue.requestParams)) {
188
211
  _izContext.logger.debug('message callingFlowProperties is empty');
189
212
  throw new NoRetryError('message not an object');
190
213
  }
@@ -220,17 +243,34 @@ export default async function createObjectComplete(
220
243
  _izContext.logger.debug('record awaitingSteps::', recordAwaitingSteps);
221
244
 
222
245
  await Promise.all(
223
- recordAwaitingSteps.Items.map(async ({ pendingStepId }) => {
246
+ recordAwaitingSteps.Items.map(async (recordAwaitingStep) => {
224
247
  if (
225
248
  await asyncFlowSharedLib.checkAllAwaitingStepsFinished(
226
249
  _izContext,
227
- pendingStepId,
250
+ recordAwaitingStep.pendingStepId,
228
251
  awaitingStepId,
229
252
  errorsFound,
230
253
  )
231
254
  ) {
232
255
  _izContext.logger.debug('finish all awaitingStep');
233
256
 
257
+ await Promise.all(
258
+ recordAwaitingStep.listOfRecords.map(async (listOfRecords) => {
259
+ Object.entries(listOfRecords).map(async ([tableName, record]) => {
260
+ await dynamodbSharedLib.putItem(
261
+ _izContext,
262
+ dynamodbSharedLib.tableName(_izContext,
263
+ tableName,
264
+ record.serviceTag
265
+ ),
266
+ {
267
+ ...record.objInstanceFull.identifiers,
268
+ ...record.objInstanceFull.fields
269
+ }
270
+ );
271
+ })
272
+ }))
273
+
234
274
  const messageObject = buildMessageObject(
235
275
  returnValue,
236
276
  existsNode,
@@ -15,7 +15,6 @@ You should have received a copy of the GNU Affero General Public License
15
15
  along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
  */
17
17
 
18
- import lodash from 'lodash';
19
18
  import { objectHash as hash } from '@izara_project/izara-shared-core';
20
19
  import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
21
20
  import snsSharedLib from '@izara_project/izara-core-library-sns';
@@ -40,9 +39,9 @@ const { dynamoDbIdentifiersByStorageResource, createIdentifiersByUseCase } = ide
40
39
  const { TOPIC_NAME_GENERATE_CODE, TOPIC_NAME_GRAPH_HANDLER } = consts;
41
40
 
42
41
  const PREFIX = {
43
- ONE: 'one',
44
- MANY: 'many',
45
- CREATE_OBJECT_ASYNC: 'createObjectAsync',
42
+ ONE: 'one',
43
+ MANY: 'many',
44
+ CREATE_OBJECT_ASYNC: 'createObjectAsync',
46
45
  CREATE_OBJECT_ASYNC_COMPLETE: 'createObjectAsyncComplete',
47
46
  CREATE_OBJECT_EXTERNAL_TOPIC: 'createObjectExternalTopic'
48
47
  };
@@ -56,7 +55,7 @@ const PREFIX = {
56
55
  * @param {Object} beforeLogicalResults - Results from beforeLogical
57
56
  * @returns {Promise<Object>} Result with objType, objInstanceFull, relationships, status, errorsFound
58
57
  */
59
- export async function createMainLogical(
58
+ export async function createMainLogical(
60
59
  _izContext,
61
60
  requestParams,
62
61
  callingFlowConfig = {},
@@ -90,7 +89,7 @@ const PREFIX = {
90
89
 
91
90
  // ── Detect invocation type ────────────────────────────────────────────────
92
91
  const directInvoke = requestParams.hasOwnProperty('__context__') &&
93
- requestParams.izEventSource?.eventSourceTag === 'DirectInvoke';
92
+ requestParams.izEventSource?.eventSourceTag === 'DirectInvoke';
94
93
 
95
94
  // ── Build createDataDetails ───────────────────────────────────────────────
96
95
  const createDataDetails = await createDataDetailsLib(_izContext, objectSchemas);
@@ -122,11 +121,12 @@ const PREFIX = {
122
121
  }
123
122
 
124
123
  // ── Process storage resources ─────────────────────────────────────────────
125
- const objInstanceFullForDynamoDb = lodash.cloneDeep(objInstanceFull);
126
- const objInstanceFullForGraph = lodash.cloneDeep(objInstanceFull);
127
- const objInstanceFullForExternalTopic = lodash.cloneDeep(objInstanceFull);
128
- const allAwaitingStepsId = [];
129
- const listOfObjectForCreates = [];
124
+ const objInstanceFullForDynamoDb = structuredClone(objInstanceFull);
125
+ const objInstanceFullForGraph = structuredClone(objInstanceFull);
126
+ const objInstanceFullForExternalTopic = structuredClone(objInstanceFull);
127
+ const allAwaitingStepsId = [];
128
+ const listOfObjectForCreates = [];
129
+ const listOfRecords = [];
130
130
 
131
131
  if (errorsFound.length === 0) {
132
132
  //(<validateBeforeCreate>)
@@ -146,7 +146,9 @@ const PREFIX = {
146
146
  Object.assign(objInstanceFullForDynamoDb.fields, { [`${parentObject.objectType}HandlerServiceTag`]: process.env.iz_serviceTag });
147
147
  }
148
148
 
149
- Object.assign(objInstanceFullForDynamoDb.fields, createObjInstanceFullFieldsByStorageTag(_izContext, storageTag, createDataDetail));
149
+ Object.assign(objInstanceFullForDynamoDb.fields,
150
+ createObjInstanceFullFieldsByStorageTag(_izContext, storageTag, createDataDetail));
151
+
150
152
  _izContext.logger.debug('objInstanceFull before create item in dynamoDB', objInstanceFullForDynamoDb);
151
153
 
152
154
  const identifiersForCreateData = await dynamoDbIdentifiersByStorageResource(
@@ -154,43 +156,59 @@ const PREFIX = {
154
156
  );
155
157
  _izContext.logger.debug('identifiersForCreateData', identifiersForCreateData);
156
158
 
157
- await dynamodbSharedLib.putItem(
158
- _izContext,
159
- await dynamodbSharedLib.tableName(_izContext, createDataDetail.tableName, createDataDetail.serviceTag),
160
- { ...identifiersForCreateData, ...objInstanceFullForDynamoDb.fields }
161
- );
162
-
163
- objInstanceFullForDynamoDb.fields = {};
159
+ // await dynamodbSharedLib.putItem(
160
+ // _izContext,
161
+ // await dynamodbSharedLib.tableName(_izContext, createDataDetail.tableName, createDataDetail.serviceTag),
162
+ // { ...identifiersForCreateData, ...objInstanceFullForDynamoDb.fields }
163
+ // );
164
+
165
+ listOfRecords.push({
166
+ [createDataDetail.tableName]: {
167
+ serviceTag: createDataDetail.serviceTag,
168
+ objInstanceFull: {
169
+ identifiers: identifiersForCreateData,
170
+ fields: objInstanceFullForDynamoDb.fields
171
+ }
172
+ }
173
+ })
164
174
  //(<afterCreateRecordDynamo>)
165
175
  //(</afterCreateRecordDynamo>)
166
176
 
167
- // ── Graph ─────────────────────────────────────────────────────────────
177
+ // ── Graph ─────────────────────────────────────────────────────────────
168
178
  } else if (createDataDetail.storageType === consts.STORAGE_TYPES.graph) {
169
179
  //(<beforeCreateNode>)
170
180
  //(</beforeCreateNode>)
171
181
  _izContext.logger.debug('::::::Graph::::::', { storageTag, objInstanceFull });
172
182
 
173
- Object.assign(objInstanceFullForGraph.fields, createObjInstanceFullFieldsByStorageTag(_izContext, storageTag, createDataDetail));
183
+ Object.assign(objInstanceFullForGraph.fields,
184
+ createObjInstanceFullFieldsByStorageTag(_izContext, storageTag, createDataDetail));
174
185
  _izContext.logger.debug('objInstanceFull before send to Graph', objInstanceFullForGraph);
175
186
 
176
187
  allAwaitingStepsId.push({
177
188
  awaitingStepId: await asyncFlowSharedLib.createAwaitingStepId(
178
- hash({ objType, graphServerTag: storageTag, identifiers: objInstanceFullForGraph.identifiers, callingFlowProperties: callingFlowConfig.callingFlowProperties || {} }),
189
+ hash({ objType,
190
+ graphServerTag: storageTag,
191
+ identifiers: objInstanceFullForGraph.identifiers,
192
+ callingFlowProperties: callingFlowConfig.callingFlowProperties || {}
193
+ }),
179
194
  PREFIX.CREATE_OBJECT_ASYNC
180
195
  ),
181
196
  //(<additionalAttributeCreateNode>)
182
- additionalAttributes: {}
197
+ additionalAttributes: { listOfRecords: listOfRecords }
183
198
  //(</additionalAttributeCreateNode>)
184
199
  });
185
200
 
186
201
  listOfObjectForCreates.push({
187
202
  [storageTag]: {
188
- objInstanceFull: { identifiers: objInstanceFullForGraph.identifiers, fields: objInstanceFullForGraph.fields },
203
+ objInstanceFull: {
204
+ identifiers: objInstanceFullForGraph.identifiers,
205
+ fields: objInstanceFullForGraph.fields
206
+ },
189
207
  allStorageTagComplete: false
190
208
  }
191
209
  });
192
210
 
193
- // ── External Topic ────────────────────────────────────────────────────
211
+ // ── External Topic ────────────────────────────────────────────────────
194
212
  } else if (createDataDetail.storageType === consts.STORAGE_TYPES.externalTopic) {
195
213
  _izContext.logger.debug('::::::externalTopic::::::', { storageTag, createDataDetail });
196
214
  //(<beforeSendMessageToExternalTopic>)
@@ -210,7 +228,7 @@ const PREFIX = {
210
228
  });
211
229
 
212
230
  await sns.publishAsync(_izContext, {
213
- Message: JSON.stringify(objInstanceFullForExternalTopic),
231
+ Message: JSON.stringify(objInstanceFullForExternalTopic),
214
232
  TopicArn: `arn:aws:sns:${createDataDetail.region}:${createDataDetail.accountId}:${createDataDetail.serviceTag}_${createDataDetail.stage}_Create_In`
215
233
  });
216
234
  }
@@ -272,7 +290,7 @@ const PREFIX = {
272
290
  );
273
291
 
274
292
  await sns.publishAsync(_izContext, {
275
- Message: JSON.stringify(messageObject),
293
+ Message: JSON.stringify(messageObject),
276
294
  TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, TOPIC_NAME_GRAPH_HANDLER.inCreateNode, graphServiceName)
277
295
  });
278
296
 
@@ -281,8 +299,8 @@ const PREFIX = {
281
299
  return {
282
300
  objType,
283
301
  objInstanceFull: objInstanceFullForGraph,
284
- relationships: requestParams.relationships || [],
285
- status: 'complete',
302
+ relationships: requestParams.relationships || [],
303
+ status: 'complete',
286
304
  errorsFound
287
305
  };
288
306
  }
@@ -307,7 +325,7 @@ const PREFIX = {
307
325
  );
308
326
 
309
327
  await sns.publishAsync(_izContext, {
310
- Message: JSON.stringify(messageObject),
328
+ Message: JSON.stringify(messageObject),
311
329
  MessageAttributes: sns.createStringMessageAttributes(
312
330
  _izContext,
313
331
  callingFlowSharedLib.addCallingFlowToSnsResponseMessageAttributes(callingFlowConfig, {})
@@ -328,7 +346,7 @@ const PREFIX = {
328
346
  if (callingFlowConfig[callingFlowSharedLib.consts.CALLINGFLOW_PROPERTYNAME]) {
329
347
  _izContext.logger.debug('HAVE CallingFlow');
330
348
  await sns.publishAsync(_izContext, {
331
- Message: JSON.stringify(outMessage),
349
+ Message: JSON.stringify(outMessage),
332
350
  MessageAttributes: sns.createStringMessageAttributes(
333
351
  _izContext,
334
352
  callingFlowSharedLib.addCallingFlowToSnsResponseMessageAttributes(callingFlowConfig, {})
@@ -341,8 +359,8 @@ const PREFIX = {
341
359
  return {
342
360
  objType,
343
361
  objInstanceFull: objInstanceFullForDynamoDb,
344
- relationships: requestParams.relationships || [],
345
- status: 'complete',
362
+ relationships: requestParams.relationships || [],
363
+ status: 'complete',
346
364
  errorsFound
347
365
  };
348
366
 
@@ -378,7 +396,7 @@ export default async function createMain(
378
396
  // ── Resolve userId / targetId ─────────────────────────────────────────────
379
397
  let userId, targetId;
380
398
  if (objectSchema.generatedBy === 'userGenerated') {
381
- userId = _izContext.correlationIds.get(coreConsts.BASE_USER_ID);
399
+ userId = _izContext.correlationIds.get(coreConsts.BASE_USER_ID);
382
400
  targetId = _izContext.correlationIds.get(coreConsts.TARGET_ID);
383
401
  if (!userId) errorsFound.push('Not have userId');
384
402
  if (objectSchema.hasOwnProperty('belongTo') && !targetId) errorsFound.push('not have targetId');
@@ -444,12 +462,12 @@ export default async function createMain(
444
462
  _izContext.logger.debug('errorsFound::', errorsFound);
445
463
 
446
464
  if (errorsFound.length > 0)
447
- return await createMainLogical(
448
- _izContext,
449
- requestParams,
450
- callingFlowConfig,
451
- errorsFound
452
- );
465
+ return await createMainLogical(
466
+ _izContext,
467
+ requestParams,
468
+ callingFlowConfig,
469
+ errorsFound
470
+ );
453
471
 
454
472
  // ── Validate fieldNames ───────────────────────────────────────────────────
455
473
  const objInstanceFull = { identifiers: {}, fields: {} };
package/src/libs/Libs.js CHANGED
@@ -120,28 +120,32 @@ function externalResourceName(resourceClass, resourceName, serviceTag) {
120
120
  }
121
121
 
122
122
  function externalResourceYaml(resourceClass, resourceName, serviceTag) {
123
- if (!serviceTag) {
124
- serviceTag = '${self:custom.iz_resourcePrefix}';
125
- } else {
126
- serviceTag = serviceTag + 'Test';
127
- }
123
+ // if (!serviceTag) {
124
+ // serviceTag = '${self:custom.iz_resourcePrefix}';
125
+ // } else {
126
+ // serviceTag = serviceTag + '${self:custom.iz_stage}';
127
+ // }
128
128
  return {
129
129
  [RESOURCE_CLASSES.dynamoDbTable]:
130
130
  'arn:aws:dynamodb:${self:custom.iz_region}:${self:custom.iz_accountId}:table/' +
131
- `${serviceTag}` +
132
- `${resourceName}`,
131
+ serviceTag ?
132
+ '${self:custom.iz_resourcePrefix}' : serviceTag + '${self:custom.iz_stage}' +
133
+ `${resourceName}`,
134
+ // `${serviceTag}` +
135
+ // `${resourceName}`,
133
136
  [RESOURCE_CLASSES.lambda]:
134
137
  'arn:aws:lambda:${self:custom.iz_region}:${self:custom.iz_accountId}:function:' +
135
- `${serviceTag}` +
136
- `${resourceName}`,
138
+ serviceTag ?
139
+ '${self:custom.iz_resourcePrefix}' : serviceTag + '${self:custom.iz_stage}' +
140
+ `${resourceName}`,
137
141
  [RESOURCE_CLASSES.sns]:
138
142
  'arn:aws:sns:${self:custom.iz_region}:${self:custom.iz_accountId}:' +
139
- `${serviceTag}` +
140
- `${resourceName}`,
143
+ `${serviceTag}` + '_${self:custom.iz_stage}_' + `${resourceName}`,
141
144
  [RESOURCE_CLASSES.sqs]:
142
145
  'arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:' +
143
- `${serviceTag}` +
144
- `${resourceName}`
146
+ serviceTag ?
147
+ '${self:custom.iz_resourcePrefix}' : serviceTag + '${self:custom.iz_stage}' +
148
+ `${resourceName}`,
145
149
  }[resourceClass];
146
150
  }
147
151
 
@@ -529,7 +533,7 @@ async function getLocalOrS3ObjectSchema(_izContext, objType, schemasPath) {
529
533
  async function getLocalOrS3FlowSchema(_izContext, flowType, schemasPath) {
530
534
  const iz_serviceTag = getLocalConfig('iz_serviceTag');
531
535
  const iz_serviceSchemaBucketName = getLocalConfig('iz_serviceSchemaBucketName');
532
-
536
+ console.log("schemasPath", schemasPath)
533
537
  let flowSchema;
534
538
  let errorMessage;
535
539
  if (flowType.serviceTag === iz_serviceTag) {
@@ -552,7 +556,9 @@ async function getLocalOrS3FlowSchema(_izContext, flowType, schemasPath) {
552
556
  flowType,
553
557
  iz_serviceSchemaBucketName
554
558
  );
555
- errorMessage = 's3 not exists';
559
+ if (!flowSchema) {
560
+ errorMessage = 's3 not exists';
561
+ }
556
562
  }
557
563
  return [flowSchema, errorMessage];
558
564
  }
@@ -1,18 +0,0 @@
1
- {
2
- "functionName": "xx",
3
- "additionalResourcePermission": [
4
- {
5
- "effect": "Allow",
6
- "action": {
7
- "dynamodb": [
8
- "GetItem",
9
- "PutItem"
10
- ]
11
- },
12
- "resource": [
13
- "aws:sqs",
14
- "..."
15
- ]
16
- }
17
- ]
18
- }
@@ -1,12 +0,0 @@
1
- [
2
- {
3
- "serviceName": "externalService",
4
- "topicName": "sns of external service",
5
- "sqsEndpoint": "sqs inside this service"
6
- },
7
- {
8
- "serviceName": [],
9
- "topicName": [],
10
- "sqsEndpoint": []
11
- }
12
- ]