@izara_project/izara-market-library-service-schemas 1.0.15 → 1.0.17

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 (63) hide show
  1. package/package.json +2 -2
  2. package/src/GenerateCodeLibs/src/Consts.js +3 -1
  3. package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +94 -73
  4. package/src/MainLibs/src/Utils.js +10 -9
  5. package/src/TemplateManager/src/GenerateCode.js +53 -12
  6. package/src/TemplateManager/src/OutPerActionComplete/OutGetComplete/functionYaml/data.js +86 -0
  7. package/src/TemplateManager/src/OutPerActionComplete/OutGetComplete/functionYaml/template.ejs +33 -0
  8. package/src/TemplateManager/src/OutPerActionComplete/OutGetComplete/handler/data.js +59 -0
  9. package/src/TemplateManager/src/OutPerActionComplete/OutGetComplete/handler/template.ejs +129 -0
  10. package/src/TemplateManager/src/OutPerActionComplete/OutGetComplete/mainFunction/data.js +53 -0
  11. package/src/TemplateManager/src/OutPerActionComplete/OutGetComplete/mainFunction/template.ejs +130 -0
  12. package/src/TemplateManager/src/OutPerActionComplete/OutGetComplete/sns-out/data.js +62 -0
  13. package/src/TemplateManager/src/OutPerActionComplete/OutGetComplete/sqs-in-sns/data.js +58 -0
  14. package/src/TemplateManager/src/OutPerActionComplete/OutGetComplete/sqs-in-sns/template.ejs +47 -0
  15. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrApi/data.js +15 -7
  16. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrDsq/data.js +14 -6
  17. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrInv/data.js +14 -4
  18. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrSqs/data.js +14 -4
  19. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrWbs/data.js +171 -0
  20. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrWbs/request.json +19 -0
  21. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrWbs/template.ejs +29 -0
  22. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/webSocketConnect/data.js +60 -0
  23. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/webSocketConnect/template.ejs +10 -0
  24. package/src/TemplateManager/src/PerActionEndpoint/Handler/WebSocket/data.js +76 -0
  25. package/src/TemplateManager/src/PerActionEndpoint/Handler/WebSocket/template.ejs +141 -0
  26. package/src/TemplateManager/src/PerActionEndpoint/Handler/WebSocketConnect/data.js +56 -0
  27. package/src/TemplateManager/src/PerActionEndpoint/Handler/WebSocketConnect/template.ejs +55 -0
  28. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Create/template.ejs +40 -36
  29. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/template.ejs +54 -22
  30. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Update/template.ejs +59 -25
  31. package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/functionYaml/HdrSqs/template.ejs +4 -0
  32. package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/perAction/HdrApi/template.ejs +2 -1
  33. package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/perAction/HdrDsq/template.ejs +1 -5
  34. package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/perAction/HdrSqs/template.ejs +1 -5
  35. package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationshipComplete/mainFunction/template.ejs +11 -7
  36. package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/functionYaml/HdrSqs/template.ejs +4 -0
  37. package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/mainFunction/template.ejs +1 -1
  38. package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/perAction/HdrApi/template.ejs +5 -4
  39. package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/perAction/HdrInv/template.ejs +3 -2
  40. package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationshipComplete/mainFunction/template.ejs +16 -13
  41. package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRalationshipComplete/mainFunction/template.ejs +9 -6
  42. package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrSqs/template.ejs +4 -0
  43. package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/perAction/HdrApi/template.ejs +8 -5
  44. package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/perAction/HdrDsq/template.ejs +1 -1
  45. package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/perAction/HdrInv/template.ejs +10 -8
  46. package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/perAction/HdrSqs/template.ejs +1 -1
  47. package/src/TemplateManager/src/ResourceYaml/dynamodb/{awaitingMultipleStepData.js → defaultDynamoDbTable.js} +39 -3
  48. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/defaultSnsInSqsForFindDataAndProcessLogical.js +6 -3
  49. package/src/TemplateManager/src/externalService/FunctionNameConfig/data.js +1 -1
  50. package/src/TemplateManager/src/externalService/LambdaRole/data.js +5 -10
  51. package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/data.js +14 -0
  52. package/src/TemplateManager/src/flowTag/resources/dynamoDb/data.js +65 -0
  53. package/src/TemplateManager/src/flowTag/webSocket/webSocketConnect/functionYaml/data.js +56 -0
  54. package/src/TemplateManager/src/flowTag/webSocket/webSocketConnect/functionYaml/template.ejs +10 -0
  55. package/src/TemplateManager/src/flowTag/webSocket/webSocketConnect/handler/data.js +55 -0
  56. package/src/TemplateManager/src/flowTag/webSocket/webSocketConnect/handler/template.ejs +63 -0
  57. package/src/TemplateManager/src/flowTag/webSocket/websocketHandler/functionYaml/data.js +75 -0
  58. package/src/TemplateManager/src/flowTag/webSocket/websocketHandler/functionYaml/template.ejs +33 -0
  59. package/src/TemplateManager/src/flowTag/webSocket/websocketHandler/lambda/data.js +57 -0
  60. package/src/TemplateManager/src/flowTag/webSocket/websocketHandler/lambda/template.ejs +131 -0
  61. package/src/TemplateManager/src/libs/Consts.js +7 -2
  62. package/src/TemplateManager/src/libs/GenerateCodeUtils.js +3 -1
  63. package/src/TemplateManager/src/ResourceYaml/dynamodb/processLogicalAndFindData.js +0 -99
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@izara_project/izara-market-library-service-schemas",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "description": "Schemas for Izara Market project",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -22,7 +22,7 @@
22
22
  "dependencies": {
23
23
  "@izara_project/izara-core-library-core": "^1.0.14",
24
24
  "@izara_project/izara-core-library-external-request": "^1.0.16",
25
- "@izara_project/izara-core-library-service-schemas": "^1.0.32",
25
+ "@izara_project/izara-core-library-service-schemas": "^1.0.33",
26
26
  "@izara_project/izara-shared": "^1.0.113",
27
27
  "ejs": "^3.1.10",
28
28
  "js-beautify": "^1.15.1",
@@ -54,7 +54,9 @@ const TOPIC_NAME_GENERATE_CODE = {
54
54
  createNodeComplete: "CreateObjectComplete",
55
55
  outCreateNodeComplete: "OutCreateObjectComplete",
56
56
  deleteNodeComplete: "DeleteNodeComplete",
57
- outDeleteNodeComplete: "OutDeleteNodeComplete"
57
+ outDeleteNodeComplete: "OutDeleteNodeComplete",
58
+ getNodeComplete: "GetNodeComplete",
59
+ outGetNodeComplete: "OutGetNodeComplete"
58
60
  }
59
61
 
60
62
  const GRAPH_HANDLER_SERVICE_NAME = {
@@ -48,11 +48,6 @@ const Logger = require("@izara_project/izara-core-library-logger");
48
48
 
49
49
  const nodeLabelRegexPattern = "^[a-zA-Z0-9_-]+(?:\:[a-zA-Z0-9_-]+)?$"
50
50
 
51
- const RETURN_GET_DATA_FORMAT = {
52
- std: "STD", // { identifiers:{...}, fields:{...}} , data depend on getDataDetails
53
- full: "FULL", // {storageTag:{...getResult from database}}
54
- onlyField: "ONLY_FIELD" // {graphHandler only return main fieldName (not versionedData) }
55
- }
56
51
 
57
52
  const schemaFunctionPerAction = {
58
53
  [consts.ACTIONS.create]: validatorSchema.generateValidatorSchemaForCreate,
@@ -160,13 +155,67 @@ async function validateSchemaPerRecord(
160
155
  record._izError = new Error(validateStatus.error)
161
156
  }
162
157
  } catch (error) {
158
+ record._izContext.logger.debug("validate PerSchema Record error", error)
163
159
  await messageToDlq(record, error.message, await sqsSharedLib.sqsQueueUrlDLQ(record._izContext, lambdaFunctionName));
164
160
  record._izError = new Error(error)
165
161
  }
166
162
 
167
163
  }
168
164
 
165
+ // /**
166
+ // * use to validate record for Lambda handler hdrSqs/hdrDsq
167
+ // * Note!: cannot throw error when use this function outside recordHandler
168
+
169
+ // * @param {string} objectType - name of ObjectType
170
+ // * @param {string} action - action type of Lambda create | update | get | delete
171
+ // * @param {object} [setting]
172
+ // */
173
+ // async function validateSchemaPerWebSocket(
174
+ // _izContext,
175
+ // requestParams,
176
+ // objectType,
177
+ // action,
178
+ // setting = {}
179
+ // ) {
180
+ // _izContext.logger.debug("validateSchema Per WebSocketFunction", {
181
+ // objectType,
182
+ // requestParams,
183
+ // action,
184
+ // setting
185
+ // })
186
+ // try {
187
+ // if (action === "update") {
188
+ // setting.updateScenario = "versionedData"
189
+ // }
190
+
191
+ // const objType = utils.createObjType(objectType)
192
+ // _izContext.logger.debug("objType in validatorSchema per WebSocket", objType)
193
+
194
+ // const objectSchema = await getObjectSchema.getObjSchemaS3WithHierarchy(_izContext, objType);
195
+ // _izContext.logger.debug("objectSchema", objectSchema)
196
+ // const generateValidatorSchema = schemaFunctionPerAction[action];
197
+ // const explodeDataFunction = explodeDataPerAction[action];
198
+
199
+ // const generateValidatorSchemaPerWebSocket = await generateValidatorSchema(_izContext, objType, setting);
200
+ // _izContext.logger.debug("Generate Validator Schema For WebSocket :", generateValidatorSchemaPerWebSocket);
201
+
202
+ // const explodedDataPerWebSocket = await explodeDataFunction(_izContext, requestParams, objectSchema, setting);
169
203
 
204
+ // _izContext.logger.debug("exploded RequestParams Data in GeneratorValidatorSchema :", explodedDataPerWebSocket);
205
+
206
+
207
+ // let validateStatus = validateObject(_izContext, generateValidatorSchemaPerWebSocket, explodedDataPerWebSocket);
208
+ // _izContext.logger.debug('validateStatus : ', validateStatus);
209
+
210
+ // if (!validateStatus.pass) {
211
+ // const validatorError = new Error(`validation failed: ${validateStatus.error}`)
212
+ // throw validatorError;
213
+ // }
214
+ // } catch (err) {
215
+ // _izContext.logger.error("Error in validateSchemaPerWebSocket:", err);
216
+ // throw err;
217
+ // }
218
+ // }
170
219
 
171
220
  async function sendMsgOutComplete(_izContext, topicName, messageObj, callingFlowConfig) {
172
221
 
@@ -557,41 +606,24 @@ async function dynamoDbIdentifiersByStorageResource(_izContext, objectSchema, dy
557
606
  * @param {object} _izContext
558
607
  * @param {object[]} getResults
559
608
  * @param {object} objectSchema
560
- * @param {string} returnFormat
561
609
  * @returns
562
610
  */
563
- function collectGetData(_izContext, getResults, objectSchema, returnFormat = RETURN_GET_DATA_FORMAT.std) {
611
+ function collectGetData(_izContext, getResults, objectSchema, returnSystemFieldsName) {
564
612
  _izContext.logger.debug("collectGetData: ", {
565
613
  getResults,
566
614
  objectSchema,
567
- returnFormat
615
+ returnSystemFieldsName
568
616
  });
569
617
 
570
- if (returnFormat === "STD") {
571
- return collectGetDataStdFormat(_izContext, getResults, objectSchema);
572
- } else if (returnFormat === "FULL") {
573
- return collectGetDataFullFormat(_izContext, getResults,)
574
- } else {
575
- throw new NoRetryError("invalid format");
576
- }
577
- }
578
-
579
-
580
- /**
581
- * helper function for collectGetData
582
- *
583
- * @param {object} _izContext
584
- * @param {object[]} getResults
585
- * @param {set} identifierFieldNames
586
- * @returns
587
- */
588
- function collectGetDataStdFormat(_izContext, getResults, objectSchema) {
589
618
 
590
619
  let collectedData = {
591
620
  identifiers: {},
592
621
  fields: {}
593
- };
622
+ }
594
623
 
624
+ if (returnSystemFieldsName) {
625
+ Object.assign(collectedData, { versionDataSystemFields: {} })
626
+ }
595
627
  const identifierFieldNames = new Set(utils.getUsedFieldNamesOfIdentifiers(_izContext, objectSchema.identifiers));
596
628
 
597
629
  let addedFieldNames = new Set();
@@ -630,6 +662,9 @@ function collectGetDataStdFormat(_izContext, getResults, objectSchema) {
630
662
  }
631
663
  }
632
664
  }
665
+ if (getData.versionDataSystemFields || returnSystemFieldsName == true) {
666
+ Object.assign(collectedData.versionDataSystemFields, getData.versionDataSystemFields)
667
+ }
633
668
  } else if (getDataDetail.storageType === consts.STORAGE_TYPES.dynamoDB) {
634
669
  for (const getDetailFieldName of getDataDetail.fieldNames) {
635
670
  if (addedFieldNames.has(getDetailFieldName)) {
@@ -666,50 +701,6 @@ function collectGetDataStdFormat(_izContext, getResults, objectSchema) {
666
701
  }
667
702
  }
668
703
 
669
- /**
670
- *
671
- * helper function for collectGetData
672
- *
673
- * @param {object} _izContext
674
- * @param {objects[]} getResults
675
- * @returns
676
- */
677
- function collectGetDataFullFormat(_izContext, getResults) {
678
- let collectedData = {};
679
-
680
- // if isFound === true then return null from this function
681
- let isFound = false;
682
-
683
-
684
- for (const [getData, getDataDetail] of getResults) {
685
- if (!getData || !Object.keys(getData).length) {
686
- continue;
687
- }
688
-
689
- // this process will add result from graph and dynamo to collectedData object by add identifiers and fieldName from getData
690
- if (getDataDetail.storageType === consts.STORAGE_TYPES.graph) {
691
- if (getData.objInstanceFull?.identifiers && Object.keys(getData.objInstanceFull?.identifiers).length) {
692
- Object.assign(collectedData, { [getDataDetail.graphServiceTag]: getData });
693
- isFound = true;
694
- }
695
- } else if (getDataDetail.storageType === consts.STORAGE_TYPES.dynamoDB) {
696
-
697
- if (getData && Object.keys(getData).length) {
698
- Object.assign(collectedData, { [getDataDetail.tableName]: getData });
699
- isFound = true;
700
- }
701
- } else {
702
- throw new NoRetryError("collectGetData unhandled storageType");
703
- }
704
- }
705
-
706
- if (isFound) {
707
- return collectedData;
708
- } else {
709
- return null;
710
- }
711
- }
712
-
713
704
 
714
705
  async function createUpdateDataDetail(_izContext, objectSchema) {
715
706
  let getGraphDataDetails = {};
@@ -945,6 +936,34 @@ async function createDeleteDataDetail(_izContext, objectSchema) {
945
936
  return allDeleteDataDetail
946
937
  }
947
938
 
939
+ function createFieldForUpdateDynamoDb(_izContext, objectSchema, dynamoDataDetail, fields) {
940
+ console.log("createFieldForUpdateDynamoDb", {
941
+ objectSchema,
942
+ dynamoDataDetail,
943
+ fields
944
+ })
945
+
946
+ let fieldsForUpdateDynamo = {};
947
+
948
+ for (let [fieldName, fieldSetting] of Object.entries(objectSchema.fieldNames)) {
949
+ if (fieldSetting.canUpdate == true || !fieldSetting.hasOwnProperty("canUpdate")) {
950
+ if (dynamoDataDetail.fieldNames.includes(fieldName)) {
951
+ if (fields[fieldName]) {
952
+ if (!fieldsForUpdateDynamo.hasOwnProperty(fields[fieldName])) {
953
+ console.log(fields[fieldName])
954
+ Object.assign(fieldsForUpdateDynamo, {
955
+ [fieldName]: fields[fieldName]
956
+ }
957
+ )
958
+ }
959
+ } else {
960
+ fieldsForUpdateDynamo = {}
961
+ }
962
+ }
963
+ }
964
+ }
965
+ return fieldsForUpdateDynamo
966
+ }
948
967
 
949
968
  module.exports = {
950
969
  sendMsgOutComplete,
@@ -961,7 +980,9 @@ module.exports = {
961
980
  dynamoDbIdentifiersByStorageResource,
962
981
  createUpdateDataDetail,
963
982
  createDataDetailsLib,
964
- createDeleteDataDetail
983
+ createDeleteDataDetail,
984
+
985
+ createFieldForUpdateDynamoDb
965
986
  }
966
987
 
967
988
 
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
18
18
  'use strict';
19
19
 
20
20
  const lodash = require("lodash")
21
+ const ACTIONS = require("../../TemplateManager/src/libs/Consts");
21
22
 
22
23
  module.exports.firstLetterUpperCase = (text) => {
23
24
  return text.charAt(0).toUpperCase() + text.slice(1)
@@ -37,14 +38,14 @@ module.exports.checkOverWriteGenerateMainFunction = (objectSchema, action) => {
37
38
  return overWriteStatus
38
39
  }
39
40
 
40
- module.exports.renameObjectType = (objectSchema, srcPath) => {
41
- const shortNamePath = path.join(srcPath, "./schemas/ShortNameObjectType.js");
42
- const shortName = fs.existsSync(shortNamePath) ? require(shortNamePath) : {};
41
+ // module.exports.renameObjectType = (objectSchema, srcPath) => {
42
+ // const shortNamePath = path.join(srcPath, "./schemas/ShortNameObjectType.js");
43
+ // const shortName = fs.existsSync(shortNamePath) ? require(shortNamePath) : {};
43
44
 
44
- let newObjectSchema = lodash.cloneDeep(objectSchema)
45
+ // let newObjectSchema = lodash.cloneDeep(objectSchema)
45
46
 
46
- if (shortName[objectSchema.objectType]) {
47
- newObjectSchema.shortNameObjectType = shortName[objectSchema.objectType]
48
- }
49
- return newObjectSchema
50
- }
47
+ // if (shortName[objectSchema.objectType]) {
48
+ // newObjectSchema.shortNameObjectType = shortName[objectSchema.objectType]
49
+ // }
50
+ // return newObjectSchema
51
+ // }
@@ -24,6 +24,7 @@ const { readFileSync } = require('fs');
24
24
  const {
25
25
  getAllLocalObjectSchemasWithHierarchy,
26
26
  getAllLocalRelationshipSchemas,
27
+ getAllLocalFlowSchemas
27
28
  } = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema');
28
29
 
29
30
  const {
@@ -73,11 +74,10 @@ const snsInSqsOutDeleteNodeComplete = require("./OutPerActionComplete/OutDeleteC
73
74
 
74
75
  // create Main resource
75
76
  const createSourceDataDynamoDB = require('./ResourceYaml/dynamodb/mainResourcePerObjectSchemaData');
76
- const createDefaultSourceDataDynamoDB = require('./ResourceYaml/dynamodb/processLogicalAndFindData');
77
77
  const createSourceSnsAndSqs = require('./ResourceYaml/sns-in-sqs/snsAndSqsPerActiondata');
78
78
  const createDataForCreateSourceSnsOut = require('./ResourceYaml/sns-out/data')
79
79
  const createFindDataAndProcessLogicalDefaultSnsInSqs = require('./ResourceYaml/sns-in-sqs/defaultSnsInSqsForFindDataAndProcessLogical');
80
- const createAwaitingMultipleStepDynamoDbData = require('./ResourceYaml/dynamodb/awaitingMultipleStepData');
80
+ const createDefaultDynamoDb = require('./ResourceYaml/dynamodb/defaultDynamoDbTable');
81
81
  const createDefaultSnsOutForFindDataAndProcessLogical = require('./ResourceYaml/sns-out/defaultSnsOutForFindDataAndProcessLogical')
82
82
 
83
83
  // create External Service
@@ -177,11 +177,25 @@ const createProcessLogicalPaginateMainFunction = require('./ProcessLogicalPagina
177
177
  const createProcessLogicalPaginateFunctionYamlHdrDsq = require('./ProcessLogicalPagination/FunctionYaml/HdrDsq/data')
178
178
  const createProcessLogicalPaginateFunctionYamlHdrSqs = require('./ProcessLogicalPagination/FunctionYaml/HdrSqs/data')
179
179
 
180
+ // getNode complete
181
+ // const createGetNodeCompleteFunctionYaml = require('./OutPerActionComplete/OutGetComplete/functionYaml/data');
182
+ // const createGetNodeCompleteHandler = require('./OutPerActionComplete/OutGetComplete/handler/data');
183
+ // const createGetNodeCompleteMainFunction = require('./OutPerActionComplete/OutGetComplete/mainFunction/data');
184
+ // const createGetNodeSnsInSqs = require('./OutPerActionComplete/OutGetComplete/sqs-in-sns/data');
185
+ const createGetNodeSnsOut = require('./OutPerActionComplete/OutGetComplete/sns-out/data');
186
+
187
+ const createWebSocketDynamoDb = require('./flowTag/resources/dynamoDb/data');
188
+ const createWebSocketConnectYaml = require('./flowTag/webSocket/webSocketConnect/functionYaml/data');
189
+ const createWebSocketConnectHandler = require('./flowTag/webSocket/webSocketConnect/handler/data');
190
+ const createWebSocketHandlerYaml = require('./flowTag/webSocket/websocketHandler/functionYaml/data')
191
+ const createWebSocketHandler = require('./flowTag/webSocket/websocketHandler/lambda/data');
192
+
180
193
  //get functionNameConfig
181
- const functionNameConfigYamldata = require('./externalService/FunctionNameConfig/data')
194
+ const functionNameConfigYamldata = require('./externalService/FunctionNameConfig/data');
182
195
 
183
196
  //lib of generateCode
184
- const { checkValidTableYaml } = require('./libs/GenerateCodeUtils');
197
+ const { checkValidTableYaml,
198
+ } = require('./libs/GenerateCodeUtils');
185
199
 
186
200
  const { NoRetryError } = require('@izara_project/izara-core-library-core');
187
201
 
@@ -216,6 +230,9 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
216
230
  updateRelationship: join(saveFilePath, `../src/generatedCode/RelationshipPerAction/source/`),
217
231
  };
218
232
 
233
+ let createSourceParams = [];
234
+
235
+ let createdTableYaml = {};
219
236
 
220
237
  // from app/src/shcemas
221
238
  let allObjSchemas = await getAllLocalObjectSchemasWithHierarchy(_izContext, objSchemaPath);
@@ -227,17 +244,35 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
227
244
  const processLogicalPaginateFunctionYamlHdrSqs = await createProcessLogicalPaginateFunctionYamlHdrSqs(_izContext, allObjSchemas, saveFilePath);
228
245
 
229
246
  const allObjectRelationships = await getAllLocalRelationshipSchemas(_izContext, objSchemaPath);
247
+ // _izContext.logger.debug("allObjectRelationships::", allObjectRelationships);
248
+
249
+ const allLocalFlowSchemas = await getAllLocalFlowSchemas(_izContext, objSchemaPath);
250
+ _izContext.logger.debug("allLocalFlowSchemas::", allLocalFlowSchemas)
251
+ for (const flowSchema of allLocalFlowSchemas.records) {
252
+
253
+ }
254
+ const webSocketTaskTable = createWebSocketDynamoDb(_izContext, saveFilePath);
255
+ const webSocketConnectYaml = createWebSocketConnectYaml(_izContext, saveFilePath);
256
+ const webSocketConnectHandler = createWebSocketConnectHandler(_izContext, saveFilePath);
257
+ const webSocketHandlerYaml = createWebSocketHandlerYaml(_izContext, saveFilePath);
258
+ const webSocketHandler = createWebSocketHandler(_izContext, saveFilePath);
259
+ // const webSocketHandler
260
+
261
+ const webSocketResource = [...webSocketTaskTable, ...webSocketConnectYaml, ...webSocketConnectHandler, ...webSocketHandler, ...webSocketHandlerYaml]
262
+ if (allLocalFlowSchemas.records.length) {
263
+ createSourceParams.push(
264
+ ...webSocketResource
265
+ )
266
+ }
267
+
230
268
 
231
- // _izContext.logger.debug("allObjectRelationships: ", allObjectRelationships)
232
269
  /*
233
270
  Should we generateCode with objectSchema that not in hierarchy or not?
234
271
  Should use objectSchema with hierarchy because we use storageResource of parent to create lambda iam role in .yml file
235
272
  */
236
273
 
237
- let createSourceParams = [];
238
274
 
239
275
  // use to check dynamoDB table yaml, to prevent duplicate tableName
240
- let createdTableYaml = {};
241
276
 
242
277
  for (const relTag in allObjectRelationships) {
243
278
  // const relTagData = allObjectRelationships[relTag];
@@ -249,10 +284,12 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
249
284
  // createSourceParams = createSourceParams.concat(createSourceMainResourcesRelSchema);
250
285
  }
251
286
 
287
+
252
288
  // create External service
253
289
  const createFunctionIamRole = await createExternalLambdaRole(_izContext, allObjSchemas.records, allObjectRelationships, saveFilePath);
254
290
  const createSnsSubscription = await createExternalSnsSubscriptions(_izContext, allObjectRelationships, allObjSchemas.records, saveFilePath);
255
291
  for (let objectSchema of allObjSchemas.records) {
292
+
256
293
  // generate handler perAction
257
294
  const createSourceHdrInv = perActionGetHdrInvData(_izContext, objectSchema, saveFilePath);
258
295
  const createSourceHdrApi = perActionGetHdrApiData(_izContext, objectSchema, saveFilePath);
@@ -274,10 +311,8 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
274
311
  const createFunctionYamlHdrApi = functionYamlDataHdrApi(_izContext, objectSchema, saveFilePath);
275
312
  const createFunctionYamlHdrSqs = functionYamlDataHdrSqs(_izContext, objectSchema, saveFilePath);
276
313
  const createFunctionYamlHdrDsq = functionYamlDataHdrDsq(_izContext, objectSchema, saveFilePath);
277
-
278
314
  // wrapMain Function
279
315
  const createFunctionYaml = [...createFunctionYamlHdrApi, ...createFunctionYamlHdrDsq, ...createFunctionYamlHdrInv, ...createFunctionYamlHdrSqs];
280
-
281
316
  // generate Resource ..via dynamoDb sns-in-sqs sns-put
282
317
  let [createResourceDynamo, newCreatedTableYaml] = checkValidTableYaml(
283
318
  _izContext,
@@ -335,11 +370,10 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
335
370
  const createDeleteNodeResource = [...createFunctionYamlDeleteNodeComplete, ...createHandlerOutDeleteNodeComplete, ...createMainFunctionDeleteNodeComplete, ...createSnsOutDeleteNodeComplete, ...createSnsInSqsDeleteNodeComplete]
336
371
 
337
372
  // create default data resource such as findData ProcessLogical and awaitingMultipleStep
338
- const createResourceFindDataAndProcessLogical = createDefaultSourceDataDynamoDB(_izContext, saveFilePath);
339
- const createResourceAwaitingMultipleStep = createAwaitingMultipleStepDynamoDbData(_izContext, saveFilePath);
373
+ const createResourceDefaultDynamoDb = createDefaultDynamoDb(_izContext, saveFilePath);
340
374
  const createResourceDefaultSnsInSqsFindDataAndProcessLogical = createFindDataAndProcessLogicalDefaultSnsInSqs(_izContext, saveFilePath);
341
375
  const createResourceDefaultSnsOutFindDataAndProcessLogical = createDefaultSnsOutForFindDataAndProcessLogical(_izContext, saveFilePath)
342
- const createMainResourceDefault = [...createResourceFindDataAndProcessLogical, ...createResourceDefaultSnsInSqsFindDataAndProcessLogical, ...createResourceAwaitingMultipleStep, ...createResourceDefaultSnsOutFindDataAndProcessLogical];
376
+ const createMainResourceDefault = [...createResourceDefaultSnsInSqsFindDataAndProcessLogical, ...createResourceDefaultDynamoDb, ...createResourceDefaultSnsOutFindDataAndProcessLogical];
343
377
 
344
378
  // create function yaml for update relationshipSchema per handler
345
379
  const createYamlUpdateRelationshipSchemaHdrSqs = createUpdateRelationshipFunctionYamlHdrSqs(_izContext, saveFilePath);
@@ -458,7 +492,13 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
458
492
  const processLogicalPaginateMainFunction = createProcessLogicalPaginateMainFunction(_izContext, saveFilePath);
459
493
  const processLogicalPaginateResource = [processLogicalPaginateFunctionYamlHdrDsq, processLogicalPaginateFunctionYamlHdrSqs, processLogicalPaginateHandlerDsq, processLogicalPaginateHandlerSqs, processLogicalPaginateMainFunction]
460
494
 
495
+ // const getNodeCompleteFunctionYaml = createGetNodeCompleteFunctionYaml(_izContext, saveFilePath);
496
+ // const getNodeCompleteHandler = createGetNodeCompleteHandler(_izContext, saveFilePath);
497
+ // const getNodeCompleteMainFunction = createGetNodeCompleteMainFunction(_izContext, saveFilePath);
498
+ // const getNodeCompleteSnsInSqs = createGetNodeSnsInSqs(_izContext, saveFilePath);
499
+ const getNodeCompleteSnsOut = createGetNodeSnsOut(_izContext, saveFilePath);
461
500
 
501
+ const getNodeCompleteResource = [...getNodeCompleteSnsOut]
462
502
  createSourceParams.push(...createMainResourceDefault,
463
503
  createSnsSubscription,
464
504
  createFunctionIamRole,
@@ -468,6 +508,7 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
468
508
  ...processLogicalResource,
469
509
  ...processLogicalPaginateResource,
470
510
  ...createDeleteNodeResource,
511
+ ...getNodeCompleteResource
471
512
  );
472
513
  if (allObjectRelationships.length) {
473
514
  createSourceParams.push(
@@ -0,0 +1,86 @@
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
+ 'use strict';
19
+ const path = require('path');
20
+ const fs = require('fs');
21
+
22
+ const { ACTIONS, HANDLER, STORAGE_TYPES } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
23
+ const { getGraphServiceNameFromGraphServerTagWithCache, getServiceNameWithCache } = require('@izara_project/izara-core-library-service-schemas/src/ServiceConfig')
24
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../MainLibs/src/Utils")
25
+ const { DEFAULT_HANDLER_PER_ACTION, createIamRole, resourceNames, RESOURCE_CLASSES, DEFAULT_LAMBDA_ROLE_PER_ACTION, SOURCE_PATH, externalResourceName, getGraphServiceNameFromAllRelSchema, FUNCTION_NAME, SAVE_FILE_NAME, getGraphServiceNameFromObjectSchema, defaultIamRolePerAction, SQS_RESOURCE, SNS_RESOURCE, DYNAMO_RESOURCE, awaitingMultipleStepsRole, SHORT_FUNCTION_NAME } = require("../../../libs/Consts");
26
+
27
+ const templatePath = path.join(__dirname, './template.ejs');
28
+
29
+ function data(_izContext, srcPath) {
30
+ return [createFunctionYamlOutUpdateComplete(_izContext, srcPath)]
31
+ }
32
+
33
+ function createFunctionYamlOutUpdateComplete(_izContext, srcPath) {
34
+ let functionName = upperCase(FUNCTION_NAME.getNodeComplete)
35
+ let functionNameConfig = upperCase(SHORT_FUNCTION_NAME.getNodeComplete)
36
+ let additionalResourcePermission = defaultIamRolePerAction();
37
+ let handlerType = upperCase(HANDLER.hdrSqs)
38
+
39
+ additionalResourcePermission.push(
40
+ createIamRole(
41
+ {
42
+ [RESOURCE_CLASSES.sqs]: [
43
+ SQS_RESOURCE.deleteMessage,
44
+ SQS_RESOURCE.deleteMessageBatch,
45
+ SQS_RESOURCE.getQueueAttributes,
46
+ SQS_RESOURCE.getQueueUrl,
47
+ SQS_RESOURCE.receiveMessage,
48
+ SQS_RESOURCE.sendMessage
49
+ ],
50
+ [RESOURCE_CLASSES.sns]: [
51
+ SNS_RESOURCE.publish,
52
+ SNS_RESOURCE.subscription
53
+ ]
54
+ },
55
+ [
56
+ resourceNames(RESOURCE_CLASSES.sqs, upperCase(functionName)),
57
+ resourceNames(RESOURCE_CLASSES.sqs, upperCase(functionName) + "DLQ"),
58
+ resourceNames(RESOURCE_CLASSES.sns, "In" + upperCase(functionName)),
59
+ resourceNames(RESOURCE_CLASSES.sns, "Out" + upperCase(functionName)),
60
+ ]
61
+ )
62
+ )
63
+
64
+ additionalResourcePermission.push(awaitingMultipleStepsRole())
65
+
66
+
67
+ return {
68
+ templatePath: templatePath,
69
+ templateData: {
70
+ functionName,
71
+ handlerType,
72
+ additionalResourcePermission,
73
+ resourceLocation: SOURCE_PATH.resourceLocationOutPerActionComplete,
74
+ functionNameConfig
75
+ },
76
+ setting: {
77
+ savePath: path.join(srcPath, SOURCE_PATH.appYaml),
78
+ saveFileName: SAVE_FILE_NAME.functionPerActionYaml,
79
+ fileExtension: '.yml',
80
+ isAppend: true
81
+ }
82
+
83
+ }
84
+ }
85
+
86
+ module.exports = data
@@ -0,0 +1,33 @@
1
+ <%_ const join = require('path').join; _%>
2
+ <%- firstLetterUpperCase(functionNameConfig) %>:
3
+ handler: <%- join(resourceLocation, `${firstLetterUpperCase(functionName)}_${firstLetterUpperCase(handlerType)}.main`)%>
4
+ name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %>
5
+ events:
6
+ - sqs:
7
+ arn: arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %>
8
+ batchSize: 10
9
+ filterPatterns: #**** need to update serverless framwork upper v.2.69.1
10
+ - body: {"MessageAttributes":{"callingFlow":{"Value":["${self:custom.iz_resourcePrefix}<%-firstLetterUpperCase(functionName) %>"]}}} # functionName of callingFlow
11
+ - body: {"MessageAttributes":{"callingFlow":{"Value":[{"exists":false}]}}}
12
+ iamRoleStatements:
13
+ <%_ additionalResourcePermission.forEach(resourcePermission => { _%>
14
+ - Effect: <%- resourcePermission.effect %>
15
+ Action:
16
+ <%_ Object.keys(resourcePermission.action).forEach(resourcePerAction => { _%>
17
+ <%_ resourcePermission.action[resourcePerAction].forEach(permission => { _%>
18
+ - <%- resourcePerAction %>:<%- permission %>
19
+ <%_}) _%>
20
+ <%_ }) _%>
21
+ Resource:
22
+ <%_ resourcePermission.resource.forEach(resource => { _%>
23
+ - <%- resource %>
24
+ <%_ }) _%>
25
+ <%_}) _%>
26
+ #<#<%- functionName %><%- handlerType %>IamRole#>
27
+ #<#/<%- functionName %><%- handlerType %>IamRole#>
28
+ <%_ function firstLetterUpperCase(text){
29
+ return text.charAt(0).toUpperCase() + text.slice(1)
30
+ } _%>
31
+ <%_ function firstLetterLowerCase(str) {
32
+ return str.charAt(0).toLowerCase() + str.slice(1)
33
+ } _%>
@@ -0,0 +1,59 @@
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
+ 'use strict';
19
+ const path = require('path');
20
+ const fs = require('fs');
21
+
22
+ const { ACTIONS, HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
23
+
24
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, firstLetterUpperCase } = require("../../../../../MainLibs/src/Utils")
25
+ const { DEFAULT_HANDLER_PER_ACTION, SOURCE_PATH, FUNCTION_NAME } = require("../../../libs/Consts");
26
+
27
+ const templatePath = path.join(__dirname, "./template.ejs")
28
+
29
+ /**
30
+ * receive objectSchema
31
+ * create data for hdrInv template
32
+ *
33
+ * @return {{ templatePath, templateData, setting } }
34
+ */
35
+ function data(_izContext, srcPath) {
36
+ const createSourceParams = createParamForCreateSource(srcPath)
37
+ return [createSourceParams];
38
+ }
39
+
40
+ function createParamForCreateSource(srcPath) {
41
+ const functionName = FUNCTION_NAME.getNodeComplete;
42
+
43
+ return {
44
+ templatePath: templatePath,
45
+ templateData: {
46
+ functionName,
47
+ queueName: upperCase(functionName),
48
+ functionName,
49
+ },
50
+ setting: {
51
+ savePath: path.join(srcPath, SOURCE_PATH.outPerActionComplete),
52
+ saveFileName: `${upperCase(functionName)}_${upperCase(HANDLER.hdrSqs)}`,
53
+ fileExtension: ".js",
54
+ isAppend: false
55
+ }
56
+ }
57
+ }
58
+
59
+ module.exports = data