@izara_project/izara-market-library-service-schemas 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 (75) hide show
  1. package/package.json +1 -1
  2. package/src/MainLibs/src/Consts.js +1 -1
  3. package/src/reStructure/GenerateSchema.js +6 -6
  4. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/create/template.ejs +20 -12
  5. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/delete/template.ejs +23 -8
  6. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/update/template.ejs +28 -21
  7. package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/data.js +0 -32
  8. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/functionYaml/data.js +1 -1
  9. package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/mainFunction/template.ejs +1 -1
  10. package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/functionYaml/data.js +5 -2
  11. package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/functionYaml/template.ejs +1 -1
  12. package/src/reStructure/TemplateData/flowSchema/dynamoDb/data.js +0 -20
  13. package/src/reStructure/TemplateData/flowSchema/eventBridge/functionYaml/data.js +7 -16
  14. package/src/reStructure/TemplateData/flowSchema/eventBridge/handler/inv/data.js +2 -2
  15. package/src/reStructure/TemplateData/flowSchema/eventBridge/handler/inv/template.ejs +0 -1
  16. package/src/reStructure/TemplateData/flowSchema/externalTopic/Complete/functionYaml/data.js +112 -0
  17. package/src/reStructure/TemplateData/flowSchema/externalTopic/Complete/handler/data.js +93 -0
  18. package/src/reStructure/TemplateData/flowSchema/externalTopic/Complete/mainFunction/data.js +61 -0
  19. package/src/reStructure/TemplateData/flowSchema/externalTopic/Complete/mainFunction/template.ejs +96 -0
  20. package/src/reStructure/TemplateData/flowSchema/externalTopic/{functionYaml → Process/functionYaml}/data.js +20 -4
  21. package/src/reStructure/TemplateData/flowSchema/externalTopic/{handler → Process/handler}/data.js +3 -3
  22. package/src/reStructure/TemplateData/flowSchema/externalTopic/Process/handler/template.ejs +87 -0
  23. package/src/reStructure/TemplateData/flowSchema/externalTopic/{mainFunction → Process/mainFunction}/data.js +2 -2
  24. package/src/reStructure/TemplateData/flowSchema/externalTopic/{mainFunction → Process/mainFunction}/template.ejs +2 -2
  25. package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-in-sqs/data.js +14 -4
  26. package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-in-sqs/sqsTemplate.ejs +52 -0
  27. package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-out/data.js +1 -1
  28. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/functionYaml/data.js +10 -9
  29. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/functionYaml/template.ejs +1 -1
  30. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/handler/data.js +8 -4
  31. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/handler/template.ejs +1 -1
  32. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/mainFunction/data.js +12 -11
  33. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/mainFunction/template.ejs +93 -49
  34. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/functionYaml/data.js +1 -1
  35. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/handler/data.js +1 -1
  36. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/handler/template.ejs +2 -0
  37. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/mainFunction/data.js +3 -2
  38. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/mainFunction/template.ejs +2 -2
  39. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/functionYaml/data.js +1 -1
  40. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/mainFunction/data.js +1 -1
  41. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/mainFunction/template.ejs +2 -2
  42. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-in/data.js +9 -21
  43. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-in/sqsTemplate.ejs +0 -10
  44. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-out/data.js +1 -1
  45. package/src/reStructure/TemplateData/flowSchema/{flowSchemaOwnTopic/flowStep → flowStep}/functionYaml/data.js +37 -24
  46. package/src/reStructure/TemplateData/flowSchema/flowStep/functionYaml/template.ejs +20 -0
  47. package/src/reStructure/TemplateData/flowSchema/{flowSchemaOwnTopic/flowStep → flowStep}/handler/data.js +24 -20
  48. package/src/reStructure/TemplateData/flowSchema/{flowSchemaOwnTopic/flowStep → flowStep}/mainFunction/data.js +27 -22
  49. package/src/reStructure/TemplateData/flowSchema/flowStep/sns-in/data.js +90 -0
  50. package/src/reStructure/TemplateData/flowSchema/flowStep/sns-in/template.ejs +45 -0
  51. package/src/reStructure/TemplateData/flowSchema/generateTemplateData.js +45 -29
  52. package/src/reStructure/TemplateData/flowSchema/register/complete/functionYaml/data.js +3 -1
  53. package/src/reStructure/TemplateData/flowSchema/register/complete/handler/data.js +0 -1
  54. package/src/reStructure/TemplateData/flowSchema/register/complete/mainFunction/template.ejs +33 -29
  55. package/src/reStructure/TemplateData/flowSchema/register/dynamoDB/register.js +0 -17
  56. package/src/reStructure/TemplateData/flowSchema/register/sns-in/data.js +0 -1
  57. package/src/reStructure/TemplateData/flowSchema/register/subscriptionOutAll/data.js +1 -3
  58. package/src/reStructure/TemplateData/flowSchema/register/subscriptionOutAll/template.ejs +2 -2
  59. package/src/reStructure/TemplateData/flowSchema/register/wbs/functionYaml/data.js +0 -29
  60. package/src/reStructure/TemplateData/flowSchema/register/wbs/handler/data.js +0 -1
  61. package/src/reStructure/TemplateData/flowSchema/register/wbs/handler/template.ejs +3 -5
  62. package/src/reStructure/TemplateData/flowSchema/register/wbs/mainFunction/template.ejs +35 -32
  63. package/src/reStructure/TemplateData/flowSchema/templateBystatusType/triggerCacheTemplate.ejs +7 -1
  64. package/src/reStructure/TemplateData/flowSchema/webSocketComplete/functionYaml/data.js +1 -1
  65. package/src/reStructure/TemplateData/flowSchema/webSocketComplete/sqs/data.js +97 -0
  66. package/src/reStructure/TemplateData/flowSchema/webSocketComplete/sqs/template.ejs +52 -0
  67. package/src/reStructure/TemplateData/perActionComplete/create/mainFunction/template.ejs +1 -0
  68. package/src/reStructure/TemplateData/propertyValueSchema/generateTemplateData.js +18 -18
  69. package/src/reStructure/TemplateData/propertyValueSchema/objectPropertyValueSchema/data.js +82 -79
  70. package/src/reStructure/TemplateData/propertyValueSchema/relationshipPropertyValueSchema/data.js +33 -37
  71. /package/src/reStructure/TemplateData/flowSchema/externalTopic/{functionYaml → Complete/functionYaml}/template.ejs +0 -0
  72. /package/src/reStructure/TemplateData/flowSchema/externalTopic/{handler → Complete/handler}/template.ejs +0 -0
  73. /package/src/reStructure/TemplateData/flowSchema/{flowSchemaOwnTopic/flowStep → externalTopic/Process}/functionYaml/template.ejs +0 -0
  74. /package/src/reStructure/TemplateData/flowSchema/{flowSchemaOwnTopic/flowStep → flowStep}/handler/template.ejs +0 -0
  75. /package/src/reStructure/TemplateData/flowSchema/{flowSchemaOwnTopic/flowStep → flowStep}/mainFunction/template.ejs +0 -0
@@ -19,7 +19,7 @@ along with this program. If not, see
19
19
  'use strict';
20
20
 
21
21
  const hash = require('@izara_project/izara-shared-core').objectHash;
22
- const { getObjectSchema } = require('@izara_project/izara-core-library-service-schemas');
22
+ const { getObjectSchema, identifiersObject } = require('@izara_project/izara-core-library-service-schemas');
23
23
 
24
24
  const dynamodbSharedLib = require('@izara_project/izara-core-library-dynamodb');
25
25
  const snsSharedLib = require('@izara_project/izara-core-library-sns');
@@ -59,7 +59,7 @@ module.exports.registerMain = async (
59
59
  //(</additionalParams>)
60
60
  ) => {
61
61
  try {
62
- let connecttionId = _izContext.correlationIds.get(consts.CONNECTION_ID)
62
+ let connectionId = _izContext.correlationIds.get(consts.CONNECTION_ID)
63
63
  // receive flowTag and identifiers
64
64
  let flowSchema = await getObjectSchema.getFlowSchemaS3WithCache(_izContext, {
65
65
  flowTag: requestParams.flowTag,
@@ -71,12 +71,12 @@ module.exports.registerMain = async (
71
71
  throw new NoRetryError(`flowTag not found ${requestParams.flowTag}`)
72
72
  }
73
73
 
74
- const getResult = async (objectType) => {
74
+ const getResult = async (objType) => {
75
75
  const objectSchema = await getObjectSchema.getObjSchemaS3WithCache(
76
76
  _izContext,
77
77
  {
78
- objectType: objectType,
79
- serviceTag: process.env.iz_serviceTag,
78
+ objectType: objType.objectType,
79
+ serviceTag: objType.serviceTag,
80
80
  })
81
81
 
82
82
  _izContext.logger.debug("==> objectSchema", objectSchema)
@@ -84,46 +84,47 @@ module.exports.registerMain = async (
84
84
  const result = await externalRequest.lambda.invokeSync(_izContext,
85
85
  await lambdaSharedLib.lambdaFunctionName(_izContext, "GetHdrInv"),
86
86
  {
87
- identifiers: identifiersLibs.identifiersFromIdentifiersConcat(_izContext, objectType, requestParams.identifiersTask),
88
- objectType: objectType
87
+ identifiers: await identifiersObject.identifiersFromIdentifiersConcat(_izContext, objType, requestParams.identifiersTask),
88
+ objectType: objType.objectType
89
89
  }
90
90
  )
91
91
 
92
- for (const [fieldName, fieldNameSetting] of Object.entries(objectSchema.fieldNames)) {
93
- if (fieldNameSetting.hasOwnProperty("statusField") && fieldNameSetting.statusField === true) {
94
- if (fieldName[result] !== "complete" || fieldName[result] !== "error") {
95
- // if status is not complete or error will save data into table
96
- await dynamodbSharedLib.putItem(_izContext,
97
- await dynamodbSharedLib.tableName(_izContext, "RegisterRecord"),
98
- {
99
- identifiersTask: requestParams.identifiersTask,
100
- connecttionId: connecttionId
101
- }
102
- )
103
- } else {
104
- if (!result) {
105
- await generatedCodeLibs.postToConnection({ message: "not have record" }, connecttionId)
92
+ if (!result) {
93
+ await generatedCodeLibs.postToConnection({ message: "not have record" }, connectionId)
94
+ } else {
95
+ for (const [fieldName, fieldNameSetting] of Object.entries(objectSchema.fieldNames)) {
96
+ if (fieldNameSetting.hasOwnProperty("statusField") && fieldNameSetting.statusField === true) {
97
+ if (result.fields[fieldName] !== "complete" && result.fields[fieldName] !== "error") {
98
+ // if status is not complete or error will save data into table
99
+ await dynamodbSharedLib.putItem(_izContext,
100
+ await dynamodbSharedLib.tableName(_izContext, "RegisterRecords"),
101
+ {
102
+ identifiersTask: requestParams.identifiersTask,
103
+ connectionId: connectionId
104
+ }
105
+ )
106
106
  } else {
107
- await generatedCodeLibs.postToConnection({ message: result }, connecttionId)
107
+ await generatedCodeLibs.postToConnection({ message: result }, connectionId)
108
108
  }
109
109
  }
110
110
  }
111
111
  }
112
112
  }
113
-
114
113
  // Initialize storedCacheData variable that will be used in multiple switch cases
115
114
  switch (flowSchema.statusType) {
116
115
  case "statusField":
117
- await getResult(flowSchema.objType.objectType)
116
+ await getResult(flowSchema.objType)
118
117
  break;
119
118
  case "storedCache":
120
- await getResult(flowSchema.objType.objectType)
119
+ await getResult(flowSchema.objType)
121
120
  break;
122
121
  case "none":
123
122
  let identifier = {};
124
- if (requestParams.hasOwnProperty("identifiersField") && Array.isArray(requestParams.identifierisField)) {
125
- for (const fieldNames of requestParams.identifierisField) {
126
- Object.assign(identifier, { [fieldNames]: requestParams[fieldNames] })
123
+ if (requestParams.hasOwnProperty("identifiersField") && Array.isArray(requestParams.identifiersField)) {
124
+ for (const fieldNames of requestParams.identifiersField) {
125
+ Object.assign(identifier, {
126
+ [fieldNames]: requestParams[fieldNames]
127
+ })
127
128
  }
128
129
  identifier = identifier;
129
130
  } else {
@@ -132,21 +133,23 @@ module.exports.registerMain = async (
132
133
 
133
134
  // get task before putItem
134
135
  let tasks = await dynamodbSharedLib.query(_izContext,
135
- await dynamodbSharedLib.tableName(_izContext, "ResgisterRecords"),
136
+ await dynamodbSharedLib.tableName(_izContext, "RegisterRecords"),
136
137
  {
137
138
  identifiersTask: hash(identifier)
138
139
  }
139
140
  )
140
- if (tasks && tasks.length > 0) {
141
+ if (tasks.Items && tasks.Items.length > 0) {
141
142
  await Promise.all(tasks.Items.map(async (task) => {
142
- await generatedCodeLibs.postToConnection({ message: task }, task.connecttionId)
143
+ await generatedCodeLibs.postToConnection({ message: task }, task.connectionId)
143
144
  }))
145
+ await generatedCodeLibs.postToConnection({ message: tasks.Items[0] }, connectionId)
146
+ return tasks.Items[0]
144
147
  } else {
145
148
  await dynamodbSharedLib.putItem(_izContext,
146
149
  await dynamodbSharedLib.tableName(_izContext, "RegisterRecords"),
147
150
  {
148
151
  identifiersTask: hash(identifier),
149
- connecttionId: connecttionId
152
+ connectionId: connectionId
150
153
  }
151
154
  )
152
155
  }
@@ -1,6 +1,6 @@
1
1
  let [triggerCacheStatus, triggerCache] = await triggeredCacheSharedLib.checkTriggeredCache(
2
2
  _izContext,
3
- <%- tableName %>,
3
+ "<%- tableName %>",
4
4
  {
5
5
  //(<keyValueTriggerCacheTable>)
6
6
  //(</keyValueTriggerCacheTable>)
@@ -17,4 +17,10 @@ if (triggerCacheStatus !== "process") {
17
17
  //(<afterValidateTriggerCacheStatus>)
18
18
  //(</afterValidateTriggerCacheStatus>)
19
19
  }
20
+
21
+
22
+ return {
23
+ //(<validateTriggerCacheProcessing>)
24
+ //(</validateTriggerCacheProcessing>)
25
+ }
20
26
  }
@@ -95,7 +95,7 @@ function createSourceParams(_izContext, allLocalFlowSchemas, srcPath) {
95
95
  {
96
96
  [RESOURCE_CLASSES.sns]: [SNS_RESOURCE.subscribe]
97
97
  },
98
- allLocalFlowSchemas.records.map(flowSchema => resourceNames(RESOURCE_CLASSES.sns, flowSchema.flowTag + "Complete_Out"))
98
+ allLocalFlowSchemas.records.map(flowSchema => resourceNames(RESOURCE_CLASSES.sns, flowSchema.flowTag + "_Out"))
99
99
  )
100
100
  )
101
101
 
@@ -0,0 +1,97 @@
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
+
20
+ const path = require("path")
21
+
22
+
23
+ // const {
24
+ // HANDLER,
25
+ // STORAGE_TYPES
26
+ // } = require('@izara_project/izara-core-library-service-schemas/src/Consts');
27
+
28
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../MainLibs/src/Utils.js");
29
+ const STORAGE_TYPES = {
30
+ dynamoDB: "dynamoDB",
31
+ graph: "graph"
32
+ }
33
+
34
+ const templatePath = path.join(__dirname, './template.ejs');
35
+
36
+
37
+ const { SOURCE_PATH, SAVE_FILE_NAME, FUNCTION_NAME, HANDLER } = require('../../../../../MainLibs/src/Consts.js');
38
+
39
+ /**
40
+ * create data for dynamoDbYaml tempalte from objectSchema
41
+ * return array of dynamoDb data
42
+ * because one objectSchema can create multiple dynamoDb table
43
+ *
44
+ * @param {Object} _izContext
45
+ * @param {String} saveFilePath
46
+ * @returns {Object[]} - data of multiple dynamoDb template
47
+ */
48
+
49
+ function createDataForDefaultSnsInSqs(_izContext, allFlowSchema, srcPath) {
50
+ let resultsForCreateDefaultSnsInSqs = [];
51
+ let defaultDsqQueueDataList = [];
52
+ for (const flowSchema of allFlowSchema.records) {
53
+ if (flowSchema.hasOwnProperty("flowSteps")) {
54
+
55
+ let flowSteps = Object.keys(flowSchema.flowSteps);
56
+ if (flowSteps.length && flowSteps.length > 0) {
57
+ // console.log("create topic by flowSteps", flowSteps)
58
+
59
+
60
+
61
+ if (flowSchema.outputTopic) {
62
+ if (flowSteps.includes("Out")) {
63
+ if (flowSchema.outputTopic) {
64
+ let topicOut = `${upperCase(flowSchema.flowTag)}`;
65
+ defaultDsqQueueDataList.push({
66
+ queueName: `WebSocketComplete` + upperCase(HANDLER.hdrSqs),
67
+ subscribeTo: topicOut
68
+ }
69
+ )
70
+
71
+ }
72
+ }
73
+ }
74
+ }
75
+ }
76
+ }
77
+
78
+ if (defaultDsqQueueDataList.length) {
79
+ for (let defaultDsqQueueData of defaultDsqQueueDataList) {
80
+ resultsForCreateDefaultSnsInSqs.push({
81
+ templatePath: templatePath,
82
+ templateData: defaultDsqQueueData,
83
+ setting: {
84
+ initialData: "Resources:\n",
85
+ savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
86
+ saveFileName: SAVE_FILE_NAME.snsInSqsYaml,
87
+ fileExtension: ".yml",
88
+ isAppend: true
89
+ }
90
+ })
91
+ }
92
+ }
93
+
94
+ return resultsForCreateDefaultSnsInSqs;
95
+ }
96
+
97
+ module.exports = createDataForDefaultSnsInSqs;
@@ -0,0 +1,52 @@
1
+ <% if (subscribeTo) { %>
2
+ ##===== SNS Subscription
3
+ SubscriptionToOut<%- subscribeTo %>:
4
+ Type: AWS::SNS::Subscription
5
+ Properties:
6
+ TopicArn: !Ref Out<%- subscribeTo %>
7
+ Endpoint: "arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- queueName %>"
8
+ Protocol: "sqs"
9
+ <% } %>
10
+ #------- queue ---------
11
+ <%- queueName %>:
12
+ Type: "AWS::SQS::Queue"
13
+ Properties:
14
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>
15
+ RedrivePolicy:
16
+ deadLetterTargetArn: #!GetAtt
17
+ Fn::GetAtt:
18
+ - <%- queueName %>DLQ
19
+ - Arn
20
+ maxReceiveCount: 3
21
+ VisibilityTimeout: 120
22
+
23
+ <%- queueName %>DLQ:
24
+ Type: AWS::SQS::Queue
25
+ Properties:
26
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>DLQ
27
+
28
+ <%- queueName %>Policy:
29
+ Type: AWS::SQS::QueuePolicy
30
+ Properties:
31
+ PolicyDocument:
32
+ Version: "2012-10-17"
33
+ Statement:
34
+ - Sid: "allow-sns-messages"
35
+ Effect: Allow
36
+ Principal: "*"
37
+ Resource: #!GetAtt
38
+ Fn::GetAtt:
39
+ - <%- queueName %>
40
+ - Arn
41
+ Action: "SQS:SendMessage"
42
+ Queues:
43
+ - Ref: <%- queueName %>
44
+ #<#<%- firstLetterUpperCase(queueName) %>QueueSetting#>
45
+ #<#/<%- firstLetterUpperCase(queueName) %>QueueSetting#>
46
+
47
+ <%_ function firstLetterUpperCase(text){
48
+ return text.charAt(0).toUpperCase() + text.slice(1)
49
+ } _%>
50
+ <%_ function firstLetterLowerCase(str) {
51
+ return str.charAt(0).toLowerCase() + str.slice(1)
52
+ } _%>
@@ -127,6 +127,7 @@ module.exports.createObjectComplete = async (
127
127
  identifiers: returnValue.objInstanceFull.identifiers,
128
128
  fields: returnValue.objInstanceFull.fields
129
129
  },
130
+ relationships: returnValue.relationships,
130
131
  status: status,
131
132
  errorsFound: errorsFound
132
133
  }
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
18
18
  'use strict';
19
19
 
20
20
  // Import required modules
21
- console.log("generate main PropertyValue Schema");
21
+ // console.log("generate main PropertyValue Schema");
22
22
  const { join } = require('path');
23
23
 
24
24
 
@@ -38,25 +38,25 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath, settings) {
38
38
  let allCreateSource = [];
39
39
  const srcPath = join(objSchemaPath, '../');
40
40
 
41
- if (settings.generateName === "propertyValue") {
42
- let objSchemaPropertyNode = await modules.objectPropertyNodeSchema(
43
- _izContext,
44
- settings,
45
- srcPath
46
- );
47
- allCreateSource.push(...objSchemaPropertyNode);
41
+ // if (settings.generateName === "propertyValue") {
42
+ let objSchemaPropertyNode = await modules.objectPropertyNodeSchema(
43
+ _izContext,
44
+ settings,
45
+ srcPath
46
+ );
47
+ allCreateSource.push(...objSchemaPropertyNode);
48
48
 
49
- let relationshipSchemaPropertyNode = await modules.relationshipPropertyNodeSchema(
50
- _izContext,
51
- settings,
52
- srcPath
53
- );
54
- allCreateSource.push(relationshipSchemaPropertyNode);
55
-
56
- } else {
57
- throw Error(`Generate propertyNode schema Invalid generateName:${settings.generateName} `);
58
- }
49
+ let relationshipSchemaPropertyNode = await modules.relationshipPropertyNodeSchema(
50
+ _izContext,
51
+ settings,
52
+ srcPath
53
+ );
54
+ allCreateSource.push(relationshipSchemaPropertyNode);
59
55
 
56
+ // } else {
57
+ // throw Error(`Generate propertyNode schema Invalid generateName:${settings.generateName} `);
58
+ // }
59
+ console.log("allCreateSource propertyValues", JSON.stringify(allCreateSource, null, 2))
60
60
  return allCreateSource;
61
61
  } catch (error) {
62
62
  _izContext.logger.error('Error generating code with template propertyNode schema:', error);
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
 
18
18
  'use strict';
19
19
 
20
- console.log("=== property value schema ===");
20
+ // console.log("=== property value schema ===");
21
21
 
22
22
  const path = require('path');
23
23
  const fs = require('fs');
@@ -39,89 +39,92 @@ const objectschemaLocalByPath = require('@izara_project/izara-core-library-servi
39
39
 
40
40
 
41
41
  async function data(_izContext, settings, srcPath) {
42
-
43
- let objectSchema = await objectschemaLocalByPath.getLocalObjectSchemasWithHierarchy(
44
- _izContext,
45
- settings.objType.objectType,
46
- path.join(srcPath, "./schemas")
47
- ).then(res => res.records[0]);
48
- _izContext.logger.debug("objectSchema objectSchema::", objectSchema)
49
-
50
- if (!objectSchema) {
51
- throw Error(`Invalid objType:${objTypeString(objType)}, cannot generate attribute tree schema cause objectSchema is not exists`)
52
- };
53
-
54
42
  let propertyValueObjectSchemas = [];
55
43
  let createSources = [];
56
-
57
- // let objectType = settings.objType.objectType;
58
- let propertyValueTag = settings.propertyValueTag
59
- // validate only addOnndataStructure is type propertyNode.
60
-
61
- if (!objectSchema.hasOwnProperty("addOnDataStructure") || !Array.isArray(objectSchema.addOnDataStructure) || !objectSchema.addOnDataStructure.length) {
62
- console.log(`Not have data in addOnDataStructure in objectType:${objectSchema.objectType}`);
63
- throw Error(`Not have data in addOnDataStructure in objectType:${objectSchema.objectType}`)
64
-
65
- };
66
-
67
- const storageResources = objectSchema.storageResources; // storageResource from main objectType
68
- const storageResourceTag = Object.keys(storageResources); // storage ResourceTag from main objectType
69
- const compositeKeyDeliminator = objectSchema.compositeKeyDeliminator;
70
-
71
- propertyValueObjectSchemas.push(
72
- { // {subject}property
73
- objectType: propertyValueTag + PROPERTYVALUE_TAG.property,
74
- fieldNames: {
75
- [propertyValueTag + PROPERTYVALUE_TAG.property + "Id"]: fieldNameSetting(FIELD_NAME_TPYE.randomOnCreateFieldName),
76
- },
77
- identifiers: [
78
- {
79
- type: "identifier",
80
- fieldName: propertyValueTag + PROPERTYVALUE_TAG.property + "Id"
44
+ for (const settingPropertyNode of settings) {
45
+ if (settingPropertyNode.generateName === "propertyValue") {
46
+ let objectSchema = await objectschemaLocalByPath.getLocalObjectSchemasWithHierarchy(
47
+ _izContext,
48
+ [settingPropertyNode.objType.objectType],
49
+ path.join(srcPath, "./schemas")
50
+ ).then(res => res.records[0]);
51
+ _izContext.logger.debug("objectSchema objectSchema::", objectSchema)
52
+
53
+ if (!objectSchema) {
54
+ throw Error(`Invalid objType:${objTypeString(objType)}, cannot generate attribute tree schema cause objectSchema is not exists`)
55
+ };
56
+
57
+
58
+ // let objectType = settings.objType.objectType;
59
+ let propertyValueTag = settingPropertyNode.propertyValueTag
60
+ // validate only addOnndataStructure is type propertyNode.
61
+
62
+ if (!objectSchema.hasOwnProperty("addOnDataStructure") || !Array.isArray(objectSchema.addOnDataStructure) || !objectSchema.addOnDataStructure.length) {
63
+ // console.log(`Not have data in addOnDataStructure in objectType:${objectSchema.objectType}`);
64
+ throw Error(`Not have data in addOnDataStructure in objectType:${objectSchema.objectType}`)
65
+
66
+ };
67
+
68
+ const storageResources = objectSchema.storageResources; // storageResource from main objectType
69
+ const storageResourceTag = Object.keys(storageResources); // storage ResourceTag from main objectType
70
+ const compositeKeyDeliminator = objectSchema.compositeKeyDeliminator;
71
+
72
+ propertyValueObjectSchemas.push(
73
+ { // {subject}property
74
+ objectType: propertyValueTag + PROPERTYVALUE_TAG.property,
75
+ fieldNames: {
76
+ [propertyValueTag + PROPERTYVALUE_TAG.property + "Id"]: fieldNameSetting(FIELD_NAME_TPYE.randomOnCreateFieldName),
77
+ },
78
+ identifiers: [
79
+ {
80
+ type: "identifier",
81
+ fieldName: propertyValueTag + PROPERTYVALUE_TAG.property + "Id"
82
+ }
83
+ ]
84
+ },
85
+ { // {subject}propertyLabel
86
+ objectType: propertyValueTag + PROPERTYVALUE_TAG.propertyLabel,
87
+ fieldNames: {
88
+ [propertyValueTag + PROPERTYVALUE_TAG.propertyLabel + "Id"]: fieldNameSetting(FIELD_NAME_TPYE.randomOnCreateFieldName),
89
+ },
90
+ identifiers: [
91
+ {
92
+ type: "identifier",
93
+ fieldName: propertyValueTag + PROPERTYVALUE_TAG.propertyLabel + "Id"
94
+ }
95
+ ]
81
96
  }
82
- ]
83
- },
84
- { // {subject}propertyLabel
85
- objectType: propertyValueTag + PROPERTYVALUE_TAG.propertyLabel,
86
- fieldNames: {
87
- [propertyValueTag + PROPERTYVALUE_TAG.propertyLabel + "Id"]: fieldNameSetting(FIELD_NAME_TPYE.randomOnCreateFieldName),
88
- },
89
- identifiers: [
90
- {
91
- type: "identifier",
92
- fieldName: propertyValueTag + PROPERTYVALUE_TAG.propertyLabel + "Id"
97
+ );
98
+
99
+ for (let propertyValueObjectSchema of propertyValueObjectSchemas) {
100
+ Object.assign(propertyValueObjectSchema, {
101
+ storageResources: storageResources, // add storageResources
102
+ compositeKeyDeliminator: compositeKeyDeliminator
103
+ })
104
+ for (let attributeTreeFieldName of Object.values(propertyValueObjectSchema.fieldNames)) {
105
+ Object.assign(attributeTreeFieldName, { storageResourceTags: storageResourceTag }) // add storageResourceTags for each fieldName
93
106
  }
94
- ]
95
- }
96
- );
97
-
98
- for (let propertyValueObjectSchema of propertyValueObjectSchemas) {
99
- Object.assign(propertyValueObjectSchema, {
100
- storageResources: storageResources, // add storageResources
101
- compositeKeyDeliminator: compositeKeyDeliminator
102
- })
103
- for (let attributeTreeFieldName of Object.values(propertyValueObjectSchema.fieldNames)) {
104
- Object.assign(attributeTreeFieldName, { storageResourceTags: storageResourceTag }) // add storageResourceTags for each fieldName
105
- }
106
- };
107
- for (const propertyValueObjectSchema of propertyValueObjectSchemas) {
108
- createSources.push({
109
- templatePath: templatePath,
110
- templateData: {
111
- fieldNames: JSON.stringify(propertyValueObjectSchema.fieldNames, null, 2),
112
- identifiers: JSON.stringify(propertyValueObjectSchema.identifiers, null, 2),
113
- objectType: propertyValueObjectSchema.objectType,
114
- storageResources: JSON.stringify(propertyValueObjectSchema.storageResources, null, 2),
115
- compositeKeyDeliminator: propertyValueObjectSchema.compositeKeyDeliminator
116
- },
117
- setting: {
118
- savePath: path.join(srcPath, SOURCE_PATH.generatedPropertyValue, propertyValueObjectSchema.objectType + "/"),
119
- hookPath: path.join(srcPath, "schemaHook", "propertyValue", propertyValueObjectSchema.objectType, "/"),
120
- saveFileName: SAVE_FILE_NAME.objectSchema,
121
- fileExtension: ".js",
122
- isAppend: false
107
+ };
108
+ for (const propertyValueObjectSchema of propertyValueObjectSchemas) {
109
+ createSources.push({
110
+ templatePath: templatePath,
111
+ templateData: {
112
+ fieldNames: JSON.stringify(propertyValueObjectSchema.fieldNames, null, 2),
113
+ identifiers: JSON.stringify(propertyValueObjectSchema.identifiers, null, 2),
114
+ objectType: propertyValueObjectSchema.objectType,
115
+ storageResources: JSON.stringify(propertyValueObjectSchema.storageResources, null, 2),
116
+ compositeKeyDeliminator: propertyValueObjectSchema.compositeKeyDeliminator
117
+ },
118
+ setting: {
119
+ savePath: path.join(srcPath, SOURCE_PATH.generatedPropertyValue, propertyValueObjectSchema.objectType + "/"),
120
+ hookPath: path.join(srcPath, "schemaHook", "propertyValue", propertyValueObjectSchema.objectType, "/"),
121
+ saveFileName: SAVE_FILE_NAME.objectSchema,
122
+ fileExtension: ".js",
123
+ isAppend: false
124
+ }
125
+ })
123
126
  }
124
- })
127
+ }
125
128
  };
126
129
  return createSources;
127
130
 
@@ -33,37 +33,38 @@ const objectschemaLocalByPath = require('@izara_project/izara-core-library-servi
33
33
  const { firstLetterUpperCase: upperCase, getLocalServiceTag } = require("../../../../MainLibs/src/Utils");
34
34
  const { createBasicRelationshipsProperties } = require('../../../../GenerateCodeLibs/src/GenerateCodeLibs');
35
35
  const { ADD_ON_DATA_STRUCTURE_TYPE } = require('../../../../TemplateManager/src/libs/Consts');
36
- async function data(_izContext, settings, srcPath) {
37
-
38
-
39
- let objectSchema = await objectschemaLocalByPath.getLocalObjectSchemasWithHierarchy(
40
- _izContext,
41
- settings.objType.objectType,
42
- path.join(srcPath, "./schemas")
43
- ).then(res => res.records[0]);
44
-
45
- if (!objectSchema) {
46
- throw Error(`Invalid objType:${objTypeString(objType)}, cannot generate attribute tree schema cause objectSchema is not exists`)
47
- };
48
-
49
- // validate addOnData type PropertyValues
50
- let addOn = objectSchema.addOnDataStructure.find(addOn => {
51
- return addOn.type === ADD_ON_DATA_STRUCTURE_TYPE.propertyValue && objectSchema.objectType === settings.objType.objectType
52
- })
53
- console.log("addOn in generate Relationship", addOn)
54
- if (!addOn) {
55
- throw Error(`Invalid objType:${objTypeString(objType)}, not have setting for generate propertyValues`)
56
- }
57
36
 
37
+ async function data(_izContext, settings, srcPath) {
38
+ console.log("create Data function ::", { settings })
58
39
  let createSourceRecords = []
59
- let generateRelationships = createSourceParams(
60
- _izContext,
61
- objectSchema,
62
- settings,
63
- srcPath
64
- );
65
- createSourceRecords.push(...generateRelationships);
40
+ for (const settingPropertyValue of settings) {
41
+ let objectSchema = await objectschemaLocalByPath.getLocalObjectSchemasWithHierarchy(
42
+ _izContext,
43
+ settingPropertyValue.objType.objectType,
44
+ path.join(srcPath, "./schemas")
45
+ ).then(res => res.records[0]);
46
+
47
+ if (!objectSchema) {
48
+ throw Error(`Invalid objType:${objTypeString(objType)}, cannot generate attribute tree schema cause objectSchema is not exists`)
49
+ };
50
+
51
+ // validate addOnData type PropertyValues
52
+ let addOn = objectSchema.addOnDataStructure.find(addOn => {
53
+ return addOn.type === ADD_ON_DATA_STRUCTURE_TYPE.propertyValue && objectSchema.objectType === settingPropertyValue.objType.objectType
54
+ })
55
+
56
+ if (!addOn) {
57
+ throw Error(`Invalid objType:${objTypeString(objType)}, not have setting for generate propertyValues`)
58
+ }
66
59
 
60
+ let generateRelationships = createSourceParams(
61
+ _izContext,
62
+ objectSchema,
63
+ settingPropertyValue,
64
+ srcPath
65
+ );
66
+ createSourceRecords.push(...generateRelationships);
67
+ }
67
68
  if (createSourceRecords.length) {
68
69
  return {
69
70
  templatePath: templatePath,
@@ -82,12 +83,7 @@ async function data(_izContext, settings, srcPath) {
82
83
  };
83
84
 
84
85
 
85
- function createSourceParams(
86
- _izContext,
87
- objectSchema,
88
- settings,
89
- srcPath
90
- ) {
86
+ function createSourceParams(_izContext, objectSchema, settings, srcPath) {
91
87
  const attributeRelationships = [];
92
88
  // const objectType = objectSchema.objectType; // main objectType
93
89
  let propertyValue = settings.propertyValueTag
@@ -100,7 +96,7 @@ function createSourceParams(
100
96
  relationshipProperties: createBasicRelationshipsProperties(
101
97
  {
102
98
  serviceTag: serviceTag,
103
- objectType: propertyValue,
99
+ objectType: objectSchema.objectType,
104
100
  linkType: "one",
105
101
  requiredOnCreate: false
106
102
  },
@@ -120,7 +116,7 @@ function createSourceParams(
120
116
  relationshipProperties: createBasicRelationshipsProperties(
121
117
  {
122
118
  serviceTag: serviceTag,
123
- objectType: propertyValue,
119
+ objectType: objectSchema.objectType,
124
120
  linkType: "one",
125
121
  requiredOnCreate: false
126
122
  },
@@ -128,7 +124,7 @@ function createSourceParams(
128
124
  serviceTag: serviceTag,
129
125
  objectType: propertyValue + PROPERTYVALUE_TAG.property,
130
126
  linkType: "many",
131
- requiredOnCreate: true
127
+ requiredOnCreate: false
132
128
  },
133
129
  storageResources,
134
130
  "from"