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

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 (15) hide show
  1. package/package.json +1 -1
  2. package/src/generateCode/generateFlowSchema/event/ownTopicComponent/flowSchemaComponent/handler/template.ejs +6 -3
  3. package/src/generateCode/generateFlowSchema/event/ownTopicComponent/flowSchemaComponent/mainFunction/template.ejs +7 -3
  4. package/src/generateCode/generateFlowSchema/event/s3Component/upload/createObject/handler/template.ejs +2 -1
  5. package/src/generateCode/generateFlowSchema/event/s3Component/upload/createObjectComplete/mainFunction/template.ejs +3 -2
  6. package/src/generateCode/generateFlowSchema/event/s3Component/upload/preSignUrl/reservedLimit/mainFunction/template.ejs +3 -2
  7. package/src/generateCode/generateFlowSchema/registerComponent/complete/mainFunction/template.ejs +2 -2
  8. package/src/generateCode/generateFlowSchema/registerComponent/wbs/handler/template.ejs +3 -1
  9. package/src/generateCode/generateFlowSchema/registerComponent/wbs/mainFunction/template.ejs +3 -4
  10. package/src/generateCode/generateFlowSchema/webSocketComponent/webSocketComplete/mainFunction/template.ejs +2 -1
  11. package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/mainFunction/data.js +1 -16
  12. package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/mainFunction/template.ejs +1 -1
  13. package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/mainFunction/templateByConfig/awaitingSteps.ejs +0 -4
  14. package/src/generateCode/generateFlowStepWithPlugIn/index.js +19 -19
  15. package/src/generateCode/generateSchema/actionEndpointComponent/mainFunction/create/main/template.ejs +49 -21
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@izara_project/izara-core-generate-service-code",
3
- "version": "1.0.40",
3
+ "version": "1.0.42",
4
4
  "description": "Code for locally generating per service files",
5
5
  "author": "Sven Mason <thebarbariansven@gmail.com>",
6
6
  "license": "AGPL-3.0-or-later",
@@ -21,10 +21,13 @@ import { middlewareHandler as middleware, validatorSchema, consts, response } fr
21
21
  import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
22
22
  import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
23
23
  import { objectHash as hash } from '@izara_project/izara-shared-core';
24
- import { postToConnection } from '../../../../libs/source/GenerateCodeLibs.js';
25
- import <%- functionName %> from './<%- functionName %>_Main.js';
26
24
  import { utils, getObjectSchema } from "@izara_project/izara-core-library-service-schemas";
27
- const { createFlowTypeConcat } = utils
25
+ const { createFlowTypeConcat } = utils;
26
+
27
+ import { webSocket } from '@izara_project/izara-core-library-external-request';
28
+ const { postToConnection } = webSocket;
29
+
30
+ import <%- functionName %> from './<%- functionName %>_Main.js';
28
31
 
29
32
  export const main = middleware.wrap(async (event, context) => {
30
33
 
@@ -23,13 +23,13 @@ import { getObjectSchema } from '@izara_project/izara-core-library-service-schem
23
23
  import snsSharedLib from '@izara_project/izara-core-library-sns';
24
24
  import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
25
25
  import lambdaSharedLib from '@izara_project/izara-core-library-lambda';
26
- import { sns } from '@izara_project/izara-core-library-external-request';
26
+ import { sns, webSocket } from '@izara_project/izara-core-library-external-request';
27
27
 
28
28
  import { NoRetryError } from '@izara_project/izara-core-library-core';
29
29
  import { consts as coreConsts } from "@izara_project/izara-middleware";
30
30
  import { consts as generateCodeConsts } from '@izara_project/izara-core-generate-service-code';
31
31
  const { TOPIC_NAME_GENERATE_CODE } = generateCodeConsts;
32
- import { postToConnection } from '../../../../libs/source/GenerateCodeLibs.js';
32
+ const { postToConnection } = webSocket;
33
33
 
34
34
  //(<optionalRequire>)
35
35
  //(</optionalRequire>)
@@ -66,7 +66,11 @@ export default async function <%- functionName %> (
66
66
  serviceTag: process.env.iz_serviceTag,
67
67
  })
68
68
 
69
- _izContext.logger.debug("flowSchema", flowSchema)
69
+ _izContext.logger.debug("flowSchema", flowSchema);
70
+
71
+ if (flowSchema.initiateBy === 'user') {
72
+ _izContext.correlationIds.set(coreConsts.USER_AGENT, 'webSocket');
73
+ };
70
74
 
71
75
  let connectionId = _izContext.correlationIds.get(coreConsts.CONNECTION_ID);
72
76
 
@@ -20,7 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
20
20
  import { middlewareHandler as middleware, consts, response } from "@izara_project/izara-middleware";
21
21
  import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
22
22
  import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
23
- import { postToConnection } from '../../../../libs/source/GenerateCodeLibs.js';
23
+ import { webSocket } from '@izara_project/izara-core-library-external-request';
24
+ const { postToConnection } = webSocket;
24
25
  import { utils } from "@izara_project/izara-core-library-service-schemas";
25
26
  const { createFlowTypeConcat } = utils
26
27
 
@@ -16,9 +16,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
  */
17
17
 
18
18
  import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
19
- import { consts as coreConsts } from '@izara_project/izara-middleware'
19
+ import { consts as coreConsts } from '@izara_project/izara-middleware';
20
+ import { webSocket } from '@izara_project/izara-core-library-external-request';
21
+ const { postToConnection } = webSocket;
20
22
 
21
- import { postToConnection } from '../../../../libs/source/GenerateCodeLibs.js'
22
23
  export async function webSocketTaskComplete(
23
24
  _izContext,
24
25
  updateItem
@@ -21,14 +21,15 @@ import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow
21
21
  import lambdaSharedLib from '@izara_project/izara-core-library-lambda';
22
22
  import snsSharedLib from '@izara_project/izara-core-library-sns';
23
23
  import asyncFlowSharedLib from "@izara_project/izara-core-library-asynchronous-flow";
24
- import { sns } from '@izara_project/izara-core-library-external-request';
24
+ import { sns, webSocket } from '@izara_project/izara-core-library-external-request';
25
25
  import { consts as generateCodeConsts } from '@izara_project/izara-core-generate-service-code';
26
26
  import { consts as coreConsts } from '@izara_project/izara-middleware';
27
27
  import { objectHash as hash } from '@izara_project/izara-shared-core';
28
28
  import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
29
- import { processStaticLimit, postToConnection } from '../../../../libs/source/GenerateCodeLibs.js';
29
+ import { processStaticLimit } from '../../../../libs/source/GenerateCodeLibs.js';
30
30
  import { utils } from "@izara_project/izara-core-library-service-schemas";
31
31
  const { createFlowTypeConcat } = utils
32
+ const { postToConnection } = webSocket;
32
33
 
33
34
  //(<optionalRequired>)
34
35
  //(</optionalRequired>)
@@ -24,8 +24,8 @@ import { getObjectSchema, identifiersObject } from '@izara_project/izara-core-li
24
24
  import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
25
25
  import lambdaSharedLib from '@izara_project/izara-core-library-lambda';
26
26
 
27
- import { lambda } from '@izara_project/izara-core-library-external-request';
28
- import { postToConnection } from "../../../libs/source/GenerateCodeLibs.js";
27
+ import { lambda, webSocket } from '@izara_project/izara-core-library-external-request';
28
+ const { postToConnection } = webSocket;
29
29
 
30
30
  /**
31
31
  * description of function.
@@ -22,7 +22,9 @@ import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow
22
22
 
23
23
  import registerMain from './Register_Main.js';
24
24
  import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
25
- import { postToConnection } from "../../../libs/source/GenerateCodeLibs.js";
25
+
26
+ import { webSocket } from '@izara_project/izara-core-library-external-request';
27
+ const { postToConnection } = webSocket;
26
28
 
27
29
  export const main = middleware.wrap(async (event, context) => {
28
30
 
@@ -20,13 +20,12 @@ along with this program. If not, see
20
20
 
21
21
  import { objectHash as hash } from '@izara_project/izara-shared-core';
22
22
  import { getObjectSchema, identifiersObject } from '@izara_project/izara-core-library-service-schemas';
23
- import lodash from 'lodash'
24
23
  import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
25
24
  import lambdaSharedLib from '@izara_project/izara-core-library-lambda';
26
- import { lambda } from '@izara_project/izara-core-library-external-request'
25
+ import { lambda, webSocket } from '@izara_project/izara-core-library-external-request'
27
26
  import { NoRetryError } from '@izara_project/izara-core-library-core';
28
27
  import { consts } from '@izara_project/izara-middleware';
29
- import { postToConnection } from '../../../libs/source/GenerateCodeLibs'
28
+ const { postToConnection } = webSocket;
30
29
 
31
30
  /**
32
31
  *
@@ -123,7 +122,7 @@ export default async function registerMain(
123
122
  }
124
123
  identifier = identifier;
125
124
  } else {
126
- let pureRequestParams = lodash.cloneDeep(requestParams);
125
+ let pureRequestParams = structuredClone(requestParams);
127
126
  delete pureRequestParams.flowTag
128
127
  identifier = pureRequestParams
129
128
  }
@@ -24,7 +24,8 @@ import { getObjectSchema, utils } from '@izara_project/izara-core-library-servic
24
24
  const { createFlowTypeConcat } = utils;
25
25
  import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
26
26
 
27
- import { postToConnection } from "../../../libs/source/GenerateCodeLibs.js";
27
+ import { webSocket } from '@izara_project/izara-core-library-external-request';
28
+ const { postToConnection } = webSocket;
28
29
 
29
30
  //(<optionalRequire>)
30
31
  //(</optionalRequire>)
@@ -31,7 +31,7 @@ const templateSendPlugin = path.join(__dirname, './templateByConfig/templateSend
31
31
  const templateAwaitingStep = path.join(__dirname, './templateByConfig/awaitingSteps.ejs');
32
32
 
33
33
  async function data(_izContext, data, appPath) {
34
-
34
+ console.log("dataInMain", data)
35
35
  const [mainFlow] = await getLocalOrS3FlowSchema(
36
36
  _izContext,
37
37
  {
@@ -42,25 +42,10 @@ async function data(_izContext, data, appPath) {
42
42
  appPath, './src/schemas')
43
43
  );
44
44
 
45
- const [childFlow] = await getLocalOrS3FlowSchema(
46
- _izContext,
47
- data.childFlow,
48
- path.join(
49
- appPath, './src/schemas')
50
- );
51
-
52
45
  if (mainFlow.hasOwnProperty('objType')) {
53
46
  data['mainObjType'] = mainFlow.objType;
54
47
  };
55
48
 
56
- if (!childFlow) {
57
- throw new NoRetryError(`can't get ${childFlow.flowTag} from s3 or local`);
58
- };
59
-
60
- if (childFlow && childFlow.hasOwnProperty('objType')) {
61
- data['childObjType'] = childFlow.objType;
62
- };
63
-
64
49
 
65
50
  return {
66
51
  templatePath: templatePath,
@@ -58,7 +58,7 @@ export default async function <%- functionName %>(
58
58
  //(<hookCode>)
59
59
 
60
60
  <% if (handleLogic === 'awaitingMultipleSteps') { %>
61
- <%- include(templateAwaitingStep, { childFlow, mainObjType, childObjType }) %>
61
+ <%- include(templateAwaitingStep, { childFlow, mainObjType }) %>
62
62
  <% } %>
63
63
  <% if (havePlugIn) { -%>
64
64
  <%- include(templateSendPlugin, {havePlugIn: havePlugIn, invokeType: invokeType, targetUrl: targetUrl}) %>
@@ -52,10 +52,6 @@ await asyncFlowSharedLib.createAwaitingMultipleStepsWithAdditionalAttributes(
52
52
  )
53
53
  );
54
54
 
55
- await sns.publishAsync(_izContext, {
56
- Message: JSON.stringify(messageObject),
57
- TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, "<%- childFlow.flowTag %>_In", "<%- childFlow.serviceTag %>")
58
- });
59
55
  //(</afterCreateAwatingSteps>)
60
56
 
61
57
  <%_ function firstLetterUpperCase(text) {
@@ -137,10 +137,6 @@ async function generatePlunIg(
137
137
  if (flowStepConfig.plugInHooks?.length) {
138
138
  for (let i = 0; i < flowStepConfig.plugInHooks.length; i++) {
139
139
  if (i === 0) {
140
- if (flowStepConfig.hasOwnProperty("settings")) {
141
- data["handleLogic"] = flowStepConfig.settings.handleLogic;
142
- data["childFlow"] = flowStepConfig.settings.flowType;
143
- };
144
140
  const firstResults = await buildFirstPluginHookResources(
145
141
  _izContext,
146
142
  data,
@@ -159,14 +155,10 @@ async function generatePlunIg(
159
155
  allCreateSourceParams.push(...afterResults);
160
156
  }
161
157
  } else {
162
- if (flowStepConfig.hasOwnProperty("settings")) {
163
- data["handleLogic"] = flowStepConfig.settings.handleLogic;
164
- data["childFlow"] = flowStepConfig.settings.flowType;
165
- };
166
-
167
158
  const noHookResults = await buildNoPluginHookResources(
168
159
  _izContext,
169
160
  data,
161
+ flowStepConfig,
170
162
  appPath
171
163
  );
172
164
  allCreateSourceParams.push(...noHookResults);
@@ -224,10 +216,9 @@ async function generatePlunIg(
224
216
  export default generatePlunIg;
225
217
 
226
218
 
227
- async function buildNoPluginHookResources(_izContext, data, appPath) {
219
+ async function buildNoPluginHookResources(_izContext, data, flowStepConfig, appPath) {
228
220
  const results = [];
229
221
 
230
-
231
222
  const yamlRes = await yamlFlowStep(
232
223
  _izContext,
233
224
  data,
@@ -253,7 +244,13 @@ async function buildNoPluginHookResources(_izContext, data, appPath) {
253
244
 
254
245
  const mainRes = await mainFunctionFlowStep(
255
246
  _izContext,
256
- { ...data, havePlugIn: false }, appPath);
247
+ {
248
+ ...data,
249
+ havePlugIn: false,
250
+ handleLogic: flowStepConfig.settings?.handleLogic || 'none'
251
+ },
252
+ appPath
253
+ );
257
254
 
258
255
  results.push(mainRes,
259
256
  // snsOutRes,
@@ -322,6 +319,7 @@ async function buildFirstPluginHookResources(_izContext, data, flowStepConfig, a
322
319
  havePlugIn: true,
323
320
  invokeType: targetPlugIn.invocationType,
324
321
  targetUrl,
322
+ handleLogic: flowStepConfig.settings?.handleLogic || 'none'
325
323
  };
326
324
  }
327
325
  }
@@ -442,14 +440,16 @@ function resolveHandlerConfig(data, flowStepConfig, additionalResourcePermission
442
440
  if (handleLogic === 'awaitingMultipleSteps') {
443
441
  handler = HANDLER.hdrSqs;
444
442
  additionalResourcePermission.push(awaitingMultipleStepsRole())
445
- additionalResourcePermission.push(createIamRole({
446
- [RESOURCE_CLASSES.sns]: Object.values(SNS_RESOURCE)
447
- },
443
+ additionalResourcePermission.push(createSqsResource(
448
444
  [
449
- externalResourceYaml(
450
- RESOURCE_CLASSES.sns,
451
- `${childFlow.flowTag}_In`,
452
- childFlow.serviceTag)
445
+ upperCase(flowTag) +
446
+ upperCase(flowStepName) +
447
+ upperCase(flowStepConfig.settings.handleLogic) +
448
+ upperCase(HANDLER.hdrSqs),
449
+ upperCase(flowTag) +
450
+ upperCase(flowStepName) +
451
+ upperCase(flowStepConfig.settings.handleLogic) +
452
+ upperCase(HANDLER.hdrSqs) + "DLQ"
453
453
  ]
454
454
  ))
455
455
  } else if (handleLogic === 'paginated') {
@@ -138,8 +138,6 @@ export async function createMainLogical(
138
138
 
139
139
  // ── DynamoDB ──────────────────────────────────────────────────────────
140
140
  if (createDataDetail.storageType === consts.STORAGE_TYPES.dynamoDB) {
141
- //(<beforeCreateRecordDynamo>)
142
- //(</beforeCreateRecordDynamo>)
143
141
  _izContext.logger.debug('::::::DynamoDB::::::', { storageTag, objInstanceFull });
144
142
 
145
143
  if (parentObject && createDataDetail.tableName.includes(firstLetterUpperCase(`${parentObject.objectType}Records`))) {
@@ -152,25 +150,45 @@ export async function createMainLogical(
152
150
  _izContext.logger.debug('objInstanceFull before create item in dynamoDB', objInstanceFullForDynamoDb);
153
151
 
154
152
  const identifiersForCreateData = await dynamoDbIdentifiersByStorageResource(
155
- _izContext, objectSchema, createDataDetails, objInstanceFullForDynamoDb.identifiers
153
+ _izContext,
154
+ objectSchema,
155
+ createDataDetails,
156
+ objInstanceFullForDynamoDb.identifiers
156
157
  );
157
158
  _izContext.logger.debug('identifiersForCreateData', identifiersForCreateData);
158
159
 
159
- // await dynamodbSharedLib.putItem(
160
- // _izContext,
161
- // await dynamodbSharedLib.tableName(_izContext, createDataDetail.tableName, createDataDetail.serviceTag),
162
- // { ...identifiersForCreateData, ...objInstanceFullForDynamoDb.fields }
163
- // );
160
+ //(<beforeCreateRecordDynamo>)
161
+ //(</beforeCreateRecordDynamo>)
164
162
 
165
- listOfRecords.push({
166
- [createDataDetail.tableName]: {
167
- serviceTag: createDataDetail.serviceTag,
168
- objInstanceFull: {
169
- identifiers: identifiersForCreateData,
170
- fields: objInstanceFullForDynamoDb.fields
163
+ if (Object.values(createDataDetails).some(
164
+ createDataDetail => createDataDetail.storageType === consts.STORAGE_TYPES.graph)) {
165
+ _izContext.logger.debug('must process graph first');
166
+ listOfRecords.push({
167
+ [createDataDetail.tableName]: {
168
+ serviceTag: createDataDetail.serviceTag,
169
+ objInstanceFull: {
170
+ identifiers: identifiersForCreateData,
171
+ fields: objInstanceFullForDynamoDb.fields
172
+ }
171
173
  }
172
- }
173
- })
174
+ })
175
+ } else {
176
+ _izContext.logger.debug('can process record dynamo')
177
+ await dynamodbSharedLib.putItem(
178
+ _izContext,
179
+ dynamodbSharedLib.tableName(_izContext,
180
+ createDataDetail.tableName,
181
+ createDataDetail.serviceTag
182
+ ),
183
+ {
184
+ ...identifiersForCreateData,
185
+ ...objInstanceFullForDynamoDb.fields
186
+ }
187
+ );
188
+
189
+ objInstanceFullForDynamoDb.fields = {}
190
+ }
191
+
174
192
  //(<afterCreateRecordDynamo>)
175
193
  //(</afterCreateRecordDynamo>)
176
194
 
@@ -338,10 +356,17 @@ export async function createMainLogical(
338
356
 
339
357
  // ── DynamoDB-only complete path ───────────────────────────────────────────
340
358
  if (allAwaitingStepsId.length === 0 && listOfObjectForCreates.length === 0) {
341
- const outMessage = callingFlowSharedLib.addPassBackPropertiesToSnsResponseMessageObject(
342
- callingFlowConfig,
343
- { objType, objInstanceFull: { identifiers: objInstanceFullForDynamoDb.identifiers, fields: objInstanceFullForDynamoDb.fields } }
344
- );
359
+ const outMessage =
360
+ callingFlowSharedLib.addPassBackPropertiesToSnsResponseMessageObject(
361
+ callingFlowConfig,
362
+ {
363
+ objType: objType,
364
+ objInstanceFull: {
365
+ identifiers: objInstanceFullForDynamoDb.identifiers,
366
+ fields: objInstanceFullForDynamoDb.fields
367
+ }
368
+ }
369
+ );
345
370
 
346
371
  if (callingFlowConfig[callingFlowSharedLib.consts.CALLINGFLOW_PROPERTYNAME]) {
347
372
  _izContext.logger.debug('HAVE CallingFlow');
@@ -358,7 +383,10 @@ export async function createMainLogical(
358
383
 
359
384
  return {
360
385
  objType,
361
- objInstanceFull: objInstanceFullForDynamoDb,
386
+ objInstanceFull: {
387
+ identifiers: objInstanceFullForDynamoDb.identifiers,
388
+ fields: objInstanceFullForDynamoDb.fields
389
+ },
362
390
  relationships: requestParams.relationships || [],
363
391
  status: 'complete',
364
392
  errorsFound