@izara_project/izara-market-library-service-schemas 1.0.35 → 1.0.36

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 (111) hide show
  1. package/package.json +1 -1
  2. package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +2 -1
  3. package/src/MainLibs/src/Consts.js +8 -8
  4. package/src/MainLibs/src/GenerateCodeUtils.js +2 -0
  5. package/src/{reStructure/TemplateData → TemplateManager/src}/attributeTreeSchema/generateTemplateData.js +35 -20
  6. package/src/TemplateManager/src/attributeTreeSchema/referenceRelationshipSchema/data.js +84 -0
  7. package/src/TemplateManager/src/attributeTreeSchema/referenceRelationshipSchema/tempReferenceRelationshipSchema.ejs +9 -0
  8. package/src/{reStructure/TemplateData → TemplateManager/src}/attributeTreeSchema/relationshipSchema/data.js +1 -1
  9. package/src/reStructure/SchemaConfig.js +1 -4
  10. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/create/backupTemplate.ejs +701 -0
  11. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/create/template.ejs +34 -162
  12. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/delete/template.ejs +2 -0
  13. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/get/template.ejs +3 -4
  14. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/update/template.ejs +2 -0
  15. package/src/reStructure/TemplateData/externalService/lambdaRole/data.js +38 -12
  16. package/src/reStructure/TemplateData/externalService/lambdaRole/template.ejs +5 -2
  17. package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/data.js +22 -14
  18. package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/template.ejs +4 -1
  19. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/mainFunction/template.ejs +68 -33
  20. package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/handler/template.ejs +1 -1
  21. package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/mainFunction/template.ejs +1 -1
  22. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/createPresignUrl/mainFunction/template.ejs +1 -1
  23. package/src/reStructure/TemplateData/flowSchema/components/upload/relate/libs/data.js +12 -4
  24. package/src/reStructure/TemplateData/flowSchema/components/upload/relate/libs/template.ejs +13 -8
  25. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/functionYaml/data.js +16 -13
  26. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/functionYaml/template.ejs +9 -9
  27. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/handler/data.js +1 -1
  28. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/mainFunction/template.ejs +7 -9
  29. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/dynamoDB/register.js +82 -0
  30. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/sns-in/data.js +1 -1
  31. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/sns-in/template.ejs +34 -1
  32. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/storedCacheTemplate.ejs +10 -33
  33. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/subscriptionOutAll/data.js +5 -5
  34. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/subscriptionOutAll/template.ejs +6 -6
  35. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/functionYaml/data.js +26 -4
  36. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/functionYaml/template.ejs +5 -5
  37. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/handler/template.ejs +7 -8
  38. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/mainFunction/template.ejs +118 -16
  39. package/src/reStructure/TemplateData/flowSchema/dynamoDb/data.js +83 -44
  40. package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-in-sqs/data.js +4 -5
  41. package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-in-sqs/template.ejs +1 -7
  42. package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-out/data.js +2 -3
  43. package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-out/template.ejs +2 -4
  44. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/functionYaml/data.js +31 -3
  45. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/functionYaml/template.ejs +4 -4
  46. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/handler/data.js +7 -8
  47. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/handler/template.ejs +13 -13
  48. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/mainFunction/data.js +4 -4
  49. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/mainFunction/template.ejs +44 -69
  50. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/functionYaml/data.js +4 -6
  51. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/functionYaml/template.ejs +2 -2
  52. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/handler/data.js +2 -9
  53. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/handler/template.ejs +40 -87
  54. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/mainFunction/data.js +5 -4
  55. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/mainFunction/template.ejs +2 -10
  56. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/functionYaml/data.js +17 -3
  57. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/functionYaml/template.ejs +2 -2
  58. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/mainFunction/data.js +6 -2
  59. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/mainFunction/template.ejs +49 -84
  60. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/functionYaml/data.js +55 -10
  61. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/functionYaml/template.ejs +1 -1
  62. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/handler/data.js +2 -2
  63. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/handler/template.ejs +1 -1
  64. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/mainFunction/data.js +20 -7
  65. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/mainFunction/template.ejs +24 -33
  66. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/functionYaml/data.js +20 -5
  67. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/functionYaml/template.ejs +1 -3
  68. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/handler/data.js +2 -2
  69. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/handler/template.ejs +5 -5
  70. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/mainFunction/data.js +5 -3
  71. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/mainFunction/template.ejs +7 -5
  72. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/functionYaml/data.js +6 -3
  73. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/functionYaml/template.ejs +0 -2
  74. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/handler/data.js +2 -2
  75. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/handler/template.ejs +3 -3
  76. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/mainFunction/data.js +8 -3
  77. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/mainFunction/template.ejs +17 -11
  78. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-in/data.js +14 -8
  79. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-out/data.js +4 -1
  80. package/src/reStructure/TemplateData/flowSchema/generateTemplateData.js +50 -42
  81. package/src/reStructure/TemplateData/generateRole/createSharedResource.js +3 -2
  82. package/src/reStructure/TemplateData/generateRole/sharedResourceTemplate.ejs +3 -0
  83. package/src/reStructure/TemplateData/perActionComplete/create/mainFunction/template.ejs +9 -8
  84. package/src/reStructure/TemplateData/perActionComplete/delete/mainFunction/template.ejs +5 -1
  85. package/src/reStructure/TemplateData/perActionComplete/get/mainFunction/template.ejs +2 -1
  86. package/src/reStructure/TemplateData/processLogical/mainFunction/template.ejs +1 -0
  87. package/src/reStructure/TemplateData/{propertyNodeSchema → propertyValueSchema}/generateTemplateData.js +4 -4
  88. package/src/reStructure/TemplateData/propertyValueSchema/objectPropertyValueSchema/data.js +131 -0
  89. package/src/reStructure/TemplateData/{propertyNodeSchema/relationshipPropertyNodeSchema → propertyValueSchema/relationshipPropertyValueSchema}/data.js +32 -55
  90. package/src/reStructure/TemplateData/propertyValueSchema/relationshipPropertyValueSchema/tempRelationship.ejs +13 -0
  91. package/src/reStructure/TemplateData/propertyValueSchema/relationshipPropertyValueSchema/templateRelationshipPropertyValueSchema.ejs +7 -0
  92. package/src/reStructure/TemplateData/relationshipPerAction/create/action/mainFunction/template.ejs +2 -1
  93. package/src/reStructure/TemplateData/relationshipPerAction/create/complete/mainFunction/template.ejs +2 -1
  94. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/mainFunction/template.ejs +2 -1
  95. package/src/reStructure/TemplateData/relationshipPerAction/delete/complete/handler/sqs/template.ejs +5 -5
  96. package/src/reStructure/TemplateData/relationshipPerAction/delete/complete/mainFunction/template.ejs +5 -4
  97. package/src/reStructure/TemplateData/relationshipPerAction/get/action/mainFunction/template.ejs +2 -1
  98. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/handler/sqs/template.ejs +4 -4
  99. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/mainFunction/template.ejs +4 -3
  100. package/src/reStructure/TemplateData/relationshipPerAction/update/action/mainFunction/template.ejs +2 -1
  101. package/src/reStructure/TemplateData/relationshipPerAction/update/complete/mainFunction/template.ejs +2 -1
  102. package/src/reStructure/TemplateData/resourceYaml/dynamodb/template.ejs +1 -3
  103. package/src/reStructure/TemplateData/resourceYaml/filterGenerateResource/data.js +61 -0
  104. package/src/reStructure/TemplateData/resourceYaml/generateTemplateData.js +13 -4
  105. package/src/reStructure/TemplateData/propertyNodeSchema/objectPropertyNodeSchema/data.js +0 -151
  106. package/src/reStructure/TemplateData/propertyNodeSchema/relationshipPropertyNodeSchema/templateRelationshipPropertyNodeSchema.ejs +0 -7
  107. /package/src/{reStructure/TemplateData → TemplateManager/src}/attributeTreeSchema/mainAttributeTree/attributeLinkTemplate.ejs +0 -0
  108. /package/src/{reStructure/TemplateData → TemplateManager/src}/attributeTreeSchema/mainAttributeTree/data.js +0 -0
  109. /package/src/{reStructure/TemplateData → TemplateManager/src}/attributeTreeSchema/mainAttributeTree/request.json +0 -0
  110. /package/src/{reStructure/TemplateData → TemplateManager/src}/attributeTreeSchema/relationshipSchema/template.ejs +0 -0
  111. /package/src/reStructure/TemplateData/{propertyNodeSchema/objectPropertyNodeSchema/templateObjectPropertyNodeSchema.ejs → propertyValueSchema/objectPropertyValueSchema/templateObjectPropertyValueSchema.ejs} +0 -0
@@ -0,0 +1,701 @@
1
+ /*
2
+ Copyright (C) 2021 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 dynamodbSharedLib = require('@izara_project/izara-core-library-dynamodb');
20
+ const snsSharedLib = require('@izara_project/izara-core-library-sns');
21
+ const asyncFlowSharedLib = require('@izara_project/izara-core-library-asynchronous-flow');
22
+ const callingFlowSharedLib = require('@izara_project/izara-core-library-calling-flow');
23
+ const lambdaSharedLib = require('@izara_project/izara-core-library-lambda');
24
+
25
+ const externalRequest = require('@izara_project/izara-core-library-external-request');
26
+ const sns = externalRequest.sns;
27
+ const lambda = externalRequest.lambda
28
+
29
+ const getObjectSchema = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema');
30
+ const serviceConfigLib = require('@izara_project/izara-core-library-service-schemas/src/ServiceConfig')
31
+
32
+ const uploadUseCase = require('@izara_project/izara-core-library-service-schemas/src/libs/UploadUseCase')
33
+
34
+ const hash = require("object-hash")
35
+ const NoRetryError = require('@izara_project/izara-core-library-core/src/NoRetryError');
36
+ const path = require('path')
37
+ const schemasPath = path.join(__dirname, '../schemas');
38
+ const consts = require('@izara_project/izara-core-library-service-schemas/src/Consts');
39
+ const coreConsts = require("@izara_project/izara-core-library-core/src/Consts");
40
+
41
+ const {
42
+ generateDynamoDbIdentifiers,
43
+ dynamoDbIdentifiersByStorageResource,
44
+ collectGetData
45
+ } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/GenerateCodeLibs');
46
+
47
+ const {
48
+ getGraphServiceTagWithCache,
49
+ getServiceNameWithCache
50
+ } = require('@izara_project/izara-core-library-service-schemas/src/ServiceConfig');
51
+
52
+ //-----------------------------------------------------------------------------------------------------------
53
+ const PREFIX = {
54
+ ONE: "one",
55
+ MANY: "many",
56
+ CREATE_OBJECT_ASYNC: "createObjectAsync",
57
+ CREATE_OBJECT_ASYNC_COMPLETE: "createObjectAsyncComplete"
58
+ }
59
+ //-----------------------------------------------------------------------------------------------------------
60
+ const { TOPIC_NAME_GENERATE_CODE, TOPIC_NAME_GRAPH_HANDLER, GRAPH_HANDLER_SERVICE_NAME } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/Consts')
61
+ const { createDataDetailsLib } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/GenerateCodeLibs')
62
+ const { createLinkTypeId, createObjType } = require('@izara_project/izara-core-library-service-schemas/src/Utils');
63
+ const { findLinksByObjTypes } = require("@izara_project/izara-core-library-service-schemas/src/libs/RelSchemaLib")
64
+ const lodash = require("lodash")
65
+ const { createRelTypeConcat } = require('@izara_project/izara-core-library-service-schemas').utils
66
+
67
+ //(<optionalRequire>)
68
+ //(</optionalRequire>)
69
+
70
+ /**
71
+ *
72
+ * @param {*} _izContext
73
+ * @param {Object} requestParams = {fieldNames,relationships = []}
74
+ * @param {*} callingFlowConfig
75
+ */
76
+
77
+ module.exports.createMain = async (
78
+ _izContext,
79
+ requestParams,
80
+ callingFlowConfig
81
+ ) => {
82
+ try {
83
+ _izContext.logger.debug("function CreateMain:", {
84
+ requestParams,
85
+ callingFlowConfig
86
+ });
87
+
88
+ let errorsFound = [];
89
+
90
+ const userId = _izContext.correlationIds.get(coreConsts.BASE_USER_ID);
91
+ const targetId = _izContext.correlationIds.get(coreConsts.TARGET_ID)
92
+ if (!userId) {
93
+ errorsFound.push("Not have userId")
94
+ }
95
+
96
+ //(<beforeQuery>)
97
+ //(</beforeQuery>)
98
+
99
+ const objType = createObjType(requestParams.objectType);
100
+
101
+ let objectSchema = await getObjectSchema.getObjSchemaS3WithHierarchy(
102
+ _izContext,
103
+ objType
104
+ );
105
+ _izContext.logger.debug("objectSchema", objectSchema);
106
+
107
+ let objectSchemas = uploadUseCase.generateObjectSchemaForCombineFieldNames(
108
+ _izContext,
109
+ objectSchema
110
+ );
111
+ _izContext.logger.debug("objectSchemas", objectSchemas);
112
+
113
+ if (objectSchema.hasOwnProperty("belongTo") && !targetId) {
114
+ errorsFound.push('not have targetId')
115
+ }
116
+
117
+ let createDataDetails = await createDataDetailsLib(_izContext, objectSchemas);
118
+ _izContext.logger.debug("createDataDetails is =", createDataDetails);
119
+
120
+ let checkCorrectLinks = [];
121
+
122
+ //validate linkType
123
+ if ((requestParams.hasOwnProperty("relationships")) && (requestParams.relationships.length > 0)) {
124
+ //(<beforeValidateRelationships>)
125
+ //(</beforeValidateRelationships>)
126
+
127
+ for (let relationshipProperties of requestParams.relationships) {
128
+ _izContext.logger.debug("relationshipProperties", relationshipProperties);
129
+ _izContext.logger.debug("relType", relationshipProperties.relType);
130
+ let getObjectRelationship = await getObjectSchema.getRelationshipSchemaWithCache(
131
+ _izContext,
132
+ relationshipProperties.relType
133
+ )
134
+ _izContext.logger.debug("getObjectRelationship", getObjectRelationship)
135
+
136
+ for (const relationshipLink of Object.values(getObjectRelationship.links)) {
137
+ if (relationshipLink.from.linkType === "many" && relationshipLink.to.linkType === "many") {
138
+ if (relationshipLink.from.requiredOnCreate === true || relationshipLink.to.requiredOnCreate === true) {
139
+ errorsFound.push("error many to many linkType can't have requireOnCreate === true")
140
+ }
141
+ }
142
+ }
143
+ const links = await findLinksByObjTypes(_izContext, [objType, relationshipProperties.targetObjType], getObjectRelationship.links);
144
+ _izContext.logger.debug("links", links)
145
+
146
+ if (!links.length) {
147
+ errorsFound.push(`not found link between ${JSON.stringify({ mainObjType: objType })} and ${JSON.stringify({ toObjType: relationshipProperties.targetObjType })} `)
148
+ }
149
+
150
+ for (let link of links) {
151
+ const { serviceTag: fromServiceTag, objectType: fromObjectType } = objType;
152
+ const { serviceTag: toServiceTag, objectType: toObjectType } = relationshipProperties.targetObjType
153
+
154
+ const { serviceTag: firstServiceTag, objectType: firstObjectType } = link.from.objType;
155
+ const { serviceTag: secondServiceTag, objectType: secondObjectType } = link.to.objType
156
+
157
+ const matchesFromTo =
158
+ fromServiceTag === firstServiceTag && fromObjectType === firstObjectType &&
159
+ toServiceTag === secondServiceTag && toObjectType === secondObjectType;
160
+
161
+ const matchesToFrom =
162
+ fromServiceTag === secondServiceTag && fromObjectType === secondObjectType &&
163
+ toServiceTag === firstServiceTag && toObjectType === firstObjectType
164
+
165
+ if ((relationshipProperties.relationshipDirection === "from" && matchesFromTo) ||
166
+ (relationshipProperties.relationshipDirection === "to" && matchesToFrom)) {
167
+ checkCorrectLinks.push(true)
168
+ } else {
169
+ checkCorrectLinks.push(false)
170
+ }
171
+ }
172
+ }
173
+ }
174
+ for (const [index, checkCorrectLink] of checkCorrectLinks.entries()) {
175
+ if (checkCorrectLink === false) {
176
+ errorsFound.push(`relationship direction ${JSON.stringify(requestParams.relationships[index])} is invalid`)
177
+ }
178
+ }
179
+
180
+ _izContext.logger.debug("finish validate Relationships from RequestParams");
181
+
182
+ let requiredOnCreateLink = new Set();
183
+ let nonRequiredOnCreateLink = new Set();
184
+ // validate relationships link
185
+ let objectRelationshipSchema = await getObjectSchema.getObjectRelationshipWithCache(_izContext, objType);
186
+ _izContext.logger.debug("objectRelationshipSchema", objectRelationshipSchema);
187
+
188
+ for (const objectRelLinks of objectRelationshipSchema) {
189
+ if (objectRelLinks.relType.serviceTag === "UserAccount") {
190
+ continue
191
+ }
192
+ const relRequired = objectRelLinks.base
193
+
194
+ if (relRequired.hasOwnProperty("requiredOnCreate") && relRequired.requiredOnCreate === true) {
195
+ requiredOnCreateLink.add(objectRelLinks);
196
+ } else if (relRequired.requiredOnCreate === false) {
197
+ nonRequiredOnCreateLink.add(objectRelLinks);
198
+ } else {
199
+ errorsFound.push(`requiredOnCreate should be true or false, not found ${objectRelLinks}`);
200
+ }
201
+ }
202
+
203
+ _izContext.logger.debug("requiredOnCreateLink=>", requiredOnCreateLink);
204
+ _izContext.logger.debug("nonRequiredOnCreateLink=> ", nonRequiredOnCreateLink);
205
+
206
+ function groupLinkByRequiredOnCreate(_izContext, links) {
207
+ let groupLink = {};
208
+
209
+ for (let link of links) {
210
+ let relTypeConcat = createRelTypeConcat(_izContext, link.relType);
211
+ if (!groupLink.hasOwnProperty(relTypeConcat)) {
212
+ groupLink[relTypeConcat] = {
213
+ from: [],
214
+ to: []
215
+ }
216
+ }
217
+
218
+ if (link.base.direction === "from") {
219
+ groupLink[relTypeConcat].from.push(link)
220
+ } else if (link.other.direction === "to") {
221
+ groupLink[relTypeConcat].to.push(link)
222
+ }
223
+ }
224
+ return groupLink
225
+ }
226
+ //**** set requiredOncreateLinkGroup = {RelType, Direction} ****
227
+
228
+ let requiredOnCreateLinkGroup = groupLinkByRequiredOnCreate(_izContext, requiredOnCreateLink);
229
+ let nonRequiredOnCreateLinkGroup = groupLinkByRequiredOnCreate(_izContext, nonRequiredOnCreateLink)
230
+
231
+ _izContext.logger.debug("requiredOnCreateLinkGroup:", requiredOnCreateLinkGroup);
232
+ _izContext.logger.debug("nonRequiredOnCreateLinkGroup=", nonRequiredOnCreateLinkGroup);
233
+
234
+ // collect requiredOnCreate linkTypeIds
235
+
236
+ let createLinkTypeIds = [];
237
+
238
+ // for (const requireLink of objectRelationshipSchema) {
239
+ function createLinkTypeIdFromLinkGroup(_izContext, links) {
240
+ let requiredOnCreateLinkSet = new Set();
241
+ for (const [relTypeConcat, objectRelationshipGroup] of Object.entries(links)) {
242
+ for (const objectRelFrom of objectRelationshipGroup.from) {
243
+ requiredOnCreateLinkSet.add(createLinkTypeId(
244
+ _izContext,
245
+ objectRelFrom.base.objType,
246
+ objectRelFrom.other.objType,
247
+ objectRelFrom.relType,
248
+ objectRelFrom.base.direction
249
+ ))
250
+ }
251
+ }
252
+ return [...requiredOnCreateLinkSet]
253
+ }
254
+ let requiredOnCreateLinks = createLinkTypeIdFromLinkGroup(_izContext, requiredOnCreateLinkGroup);
255
+ let nonRequiredOnCreateLinks = createLinkTypeIdFromLinkGroup(_izContext, nonRequiredOnCreateLinkGroup)
256
+
257
+ _izContext.logger.debug("requiredOnCreateLinks::", requiredOnCreateLinks);
258
+ _izContext.logger.debug("nonRequiredOnCreateLinks::", nonRequiredOnCreateLinks)
259
+
260
+
261
+ for (const relationship of requestParams?.relationships) {
262
+ const onCreateLinkTypeId = createLinkTypeId(
263
+ _izContext,
264
+ objType,
265
+ relationship.targetObjType,
266
+ relationship.relType,
267
+ relationship.relationshipDirection
268
+ )
269
+ createLinkTypeIds.push(onCreateLinkTypeId)
270
+ };
271
+ _izContext.logger.debug("createLinkTypeIds::", createLinkTypeIds)
272
+ return
273
+ // end validate
274
+ let objInstanceFull = {
275
+ identifiers: {},
276
+ fields: {}
277
+ };
278
+
279
+ //(<optionalObjInstanceFull>)
280
+ //(</optionalObjInstanceFull>)
281
+
282
+ let listOfRequiredOnCreate = [];
283
+ let listOfOptionalOnCreate = [];
284
+
285
+ let allAwaitingStepsId = [];
286
+
287
+ // validate single identifiers
288
+ if (objectSchemas.identifiers.length === 1 && !objectSchemas.identifiers[0].hasOwnProperty("fieldNames")) {
289
+
290
+ const identifier = objectSchemas.identifiers[0];
291
+ _izContext.logger.debug(":::::case single identifer:::::", identifier);
292
+
293
+ if (objectSchemas.fieldNames[identifier.fieldName].hasOwnProperty("randomOnCreate")) {
294
+ if ((objectSchemas.fieldNames[identifier.fieldName].randomOnCreate == true)) {
295
+ Object.assign(requestParams.fieldNames, {
296
+ [identifier.fieldName]: hash({
297
+ fieldNames: identifier, //
298
+ uniqueRequestId: _izContext.uniqueRequestId,
299
+ callingFlowConfig: callingFlowConfig
300
+ })
301
+ });
302
+ _izContext.logger.debug("Assign requestParams", requestParams)
303
+
304
+ } else if ((objectSchemas.fieldNames[identifier.fieldName].randomOnCreate == false) ||
305
+ (objectSchemas.fieldNames[identifier.fieldName].randomOnCreate == null)) {
306
+
307
+ if ((objectSchemas.fieldNames[identifier.fieldName].requiredOnCreate == true) &&
308
+ (objectSchemas.fieldNames[identifier.fieldName].canUpdate == false)) {
309
+ // check Fns have resive
310
+
311
+ if (requestParams.fieldNames.hasOwnProperty([identifier.fieldName])) {
312
+ _izContext.logger.debug("identifier is exist:", {
313
+ [identifier.fieldName]: requestParams.fieldNames[identifier.fieldName]
314
+ });
315
+
316
+ } else {
317
+ errorsFound.push("[invalid]requestParams not have data fieldNames of requriedOnCreate");
318
+ }
319
+ }
320
+ };
321
+ } else if (objectSchemas.fieldNames[identifier.fieldName].hasOwnProperty("hashOnCreate")) {
322
+ if (objectSchemas.fieldNames[identifier.fieldName].hashOnCreate.length &&
323
+ objectSchemas.fieldNames[identifier.fieldName].hashOnCreate.length > 0) {
324
+ for (const fieldName of objectSchemas.fieldNames[identifier.fieldName].hashOnCreate) {
325
+ Object.assign(
326
+ requestParams.fieldNames, {
327
+ [identifier.fieldName]: hash({
328
+ [fieldName]: requestParams.fieldNames[fieldName]
329
+ })
330
+ }
331
+ )
332
+ }
333
+ } else {
334
+ errorsFound.push("[invalid] no data to hash for create")
335
+ }
336
+ } else {
337
+ if ((objectSchemas.fieldNames[identifier.fieldName].requiredOnCreate === false) &&
338
+ (objectSchemas.fieldNames[identifier.fieldName].optionalOnCreate === false) &&
339
+ (objectSchemas.fieldNames[identifier.fieldName].canUpdate === false) &&
340
+ objectSchemas.fieldNames[identifier.fieldName].hashOnCreate === false) {
341
+ errorsFound.push("[invalid]case single identifier invalid objectSchemass");
342
+ };
343
+ };
344
+ }
345
+
346
+ _izContext.logger.debug("requestParams is:", requestParams);
347
+
348
+ // check settingObjSchemas
349
+ for (let [keyFieldNames, valueFieldNames] of Object.entries(objectSchemas.fieldNames)) {
350
+
351
+ if (valueFieldNames.hasOwnProperty("randomOnCreate") && valueFieldNames.randomOnCreate === true) {
352
+ listOfRequiredOnCreate.push(keyFieldNames)
353
+ };
354
+
355
+ if (valueFieldNames.hasOwnProperty("requiredOnCreate") && valueFieldNames.requiredOnCreate === true) {
356
+ listOfRequiredOnCreate.push(keyFieldNames)
357
+ };
358
+
359
+ if (valueFieldNames.hasOwnProperty("hashOnCreate") && valueFieldNames.hashOnCreate.length) {
360
+ listOfRequiredOnCreate.push(keyFieldNames)
361
+ }
362
+
363
+ if (valueFieldNames.hasOwnProperty("optionalOnCreate") && valueFieldNames.optionalOnCreate === true) {
364
+ if ((valueFieldNames.requiredOnCreate === false) && valueFieldNames.optionalOnCreate === true) {
365
+ listOfOptionalOnCreate.push(keyFieldNames)
366
+ };
367
+ };
368
+
369
+ }; // end iteration of fieldNames
370
+
371
+ _izContext.logger.debug("listOfRequriedOnCreate", listOfRequiredOnCreate);
372
+ _izContext.logger.debug("listOfOptionalOnCreate", listOfOptionalOnCreate);
373
+ for (let fieldName of Object.keys(requestParams.fieldNames)) {
374
+
375
+ if (!listOfRequiredOnCreate.includes(fieldName)) {
376
+ if (!listOfOptionalOnCreate.includes(fieldName)) {
377
+ errorsFound.push("[invalid] over fieldNames create object");
378
+ }
379
+ };
380
+
381
+ if (listOfOptionalOnCreate.length > 0 && listOfRequiredOnCreate.includes(fieldName)) {
382
+ //(<optionalParams>)
383
+ //(</optionalParams>)
384
+ };
385
+
386
+ if (objectSchemas.identifierFieldNames.includes(fieldName)) {
387
+ _izContext.logger.debug("identifiers is", fieldName);
388
+ Object.assign(objInstanceFull.identifiers, {
389
+ [fieldName]: requestParams.fieldNames[fieldName]
390
+ });
391
+ };
392
+
393
+ if (errorsFound.length > 0) {
394
+ _izContext.logger.debug("HaveError::", errorsFound);
395
+ break
396
+ };
397
+
398
+ }; // end loop
399
+
400
+ let listOfObjectForCreates = [];
401
+
402
+ let objInstanceFullForDynamoDb = lodash.cloneDeep(objInstanceFull)
403
+ let objInstanceFullForGraph = lodash.cloneDeep(objInstanceFull)
404
+
405
+ if (errorsFound.length == 0) {
406
+
407
+ for (let [storageTag, createDataDetail] of Object.entries(createDataDetails)) {
408
+ //(<beforeCreate>)
409
+ //(</beforeCreate>)
410
+ if (createDataDetail.storageType == consts.STORAGE_TYPES.dynamoDB) {
411
+ //(<beforeCreateRecordDynamo>)
412
+ //(</beforeCreateRecordDynamo>)
413
+ _izContext.logger.debug("::::::DynamoDB::::::", { storageTag, objInstanceFull });
414
+
415
+
416
+ Object.assign(objInstanceFullForDynamoDb.fields, createObjInstanceFullFieldsByStorageTag(_izContext, storageTag, createDataDetail))
417
+ _izContext.logger.debug("objInstanceFull before create item in dynamoDB", objInstanceFullForDynamoDb)
418
+
419
+ let identifiersForCreateData = await dynamoDbIdentifiersByStorageResource(
420
+ _izContext,
421
+ objectSchema,
422
+ createDataDetails,
423
+ objInstanceFullForDynamoDb.identifiers
424
+ )
425
+ _izContext.logger.debug("identifiersForCreateData", identifiersForCreateData);
426
+
427
+ await dynamodbSharedLib.putItem(
428
+ _izContext,
429
+ await dynamodbSharedLib.tableName(
430
+ _izContext,
431
+ createDataDetail.tableName
432
+ ),
433
+ {
434
+ ...identifiersForCreateData,
435
+ ...objInstanceFullForDynamoDb.fields
436
+ }
437
+ );
438
+ } else if (createDataDetail.storageType == consts.STORAGE_TYPES.graph) {
439
+ //(<beforeCreateNode>)
440
+ //(</beforeCreateNode>)
441
+ _izContext.logger.debug("::::::Graph::::::", { storageTag, objInstanceFull });
442
+
443
+ Object.assign(objInstanceFullForGraph.fields, createObjInstanceFullFieldsByStorageTag(_izContext, storageTag, createDataDetail))
444
+ _izContext.logger.debug("objInstanceFull before send to Graph", objInstanceFullForGraph)
445
+
446
+ // allStorageTagComplete = false;
447
+ allAwaitingStepsId.push(await asyncFlowSharedLib.createAwaitingStepId(
448
+ (hash({
449
+ objType: objType,
450
+ graphServerTag: storageTag,
451
+ identifiers: objInstanceFullForGraph.identifiers
452
+ })),
453
+ PREFIX.CREATE_OBJECT_ASYNC
454
+ ));
455
+ listOfObjectForCreates.push({
456
+ [storageTag]: {
457
+ objInstanceFull: {
458
+ identifiers: objInstanceFullForGraph.identifiers,
459
+ fields: objInstanceFullForGraph.fields
460
+ },
461
+ allStorageTagComplete: false
462
+ }
463
+ });
464
+
465
+ _izContext.logger.debug("FIRST", listOfObjectForCreates)
466
+
467
+ };
468
+ _izContext.logger.debug("[1]listOfObjectForCreates:::", listOfObjectForCreates);
469
+ };
470
+ };
471
+
472
+ function createObjInstanceFullFieldsByStorageTag(_izContext, storageTag, createDataDetail) {
473
+ _izContext.logger.debug("createObjInstanceFullFieldsByStorageTag : ", { storageTag, createDataDetail })
474
+ let fields = {};
475
+ for (let fieldName of Object.keys(requestParams.fieldNames)) {
476
+ if ((createDataDetails[storageTag].fieldNames.includes(fieldName)) &&
477
+ (createDataDetail.fieldNames.includes(fieldName))) {
478
+ if (!objInstanceFull.identifiers.hasOwnProperty(fieldName)) {
479
+ if (!fields.hasOwnProperty(fieldName)) {
480
+ Object.assign(fields, {
481
+ [fieldName]: requestParams.fieldNames[fieldName]
482
+ })
483
+ }
484
+ }
485
+ }
486
+ }
487
+ _izContext.logger.debug({ fields })
488
+ return fields
489
+ }
490
+ /// step save awiatingMultipleStep of storageType graph ...........................................................
491
+
492
+ await asyncFlowSharedLib.createAwaitingMultipleSteps(
493
+ _izContext,
494
+ allAwaitingStepsId,
495
+ asyncFlowSharedLib.createPendingStepId((hash({ objType: objType, identifiers: objInstanceFull.identifiers })), PREFIX.CREATE_OBJECT_ASYNC_COMPLETE)
496
+ );
497
+ //............................................................................................................
498
+
499
+ // process storageType : graph
500
+ let messageObject = {};
501
+ for (let objectCreate of listOfObjectForCreates) {
502
+
503
+ for (let [graphServiceName, objecForCreate] of Object.entries(objectCreate)) {
504
+ _izContext.logger.debug("Loop each graph:", {
505
+ [graphServiceName]: objecForCreate
506
+ });
507
+
508
+ if (objecForCreate.allStorageTagComplete == false) { // needless check because in listOfObjectForCreates push case graph only!
509
+ //(<beforeSendMessageToGraph>)
510
+ //(</beforeSendMessageToGraph>)
511
+ messageObject = {
512
+ objType: objType,
513
+ objInstanceFull: objecForCreate.objInstanceFull,
514
+ relationships: requestParams.relationships || []
515
+ };
516
+ };
517
+
518
+ if (errorsFound.length > 0) {
519
+ break;
520
+ } else {
521
+ _izContext.logger.debug("SENT MESSAGE EACH GRAPH::::", { graphServiceName, messageObject, callingFlowConfig })
522
+
523
+ Object.assign(messageObject, {
524
+ settings: { updatePropertiesOnMatch: false },
525
+ originTimestamp: Date.now()
526
+ });
527
+
528
+ messageObject = callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
529
+ messageObject,
530
+ callingFlowSharedLib.addParentCallingFlowConfig(
531
+ callingFlowConfig, // resive parent callingFlowConfig.
532
+ callingFlowSharedLib.createCallingFlowConfig( // callinfflow own service
533
+ await lambdaSharedLib.lambdaFunctionName(_izContext, TOPIC_NAME_GENERATE_CODE.createNodeComplete), {}
534
+ )
535
+ )
536
+ );
537
+
538
+ let messageToCreateObject = {
539
+ Message: JSON.stringify(messageObject),
540
+ TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, TOPIC_NAME_GRAPH_HANDLER.inCreateNode, graphServiceName)
541
+ };
542
+ _izContext.logger.debug("RequestParams before send to sqs messageToCreateObject ::::::: ", messageToCreateObject);
543
+ await sns.publishAsync(_izContext, messageToCreateObject);
544
+
545
+ //(<afterSendMessageToGraph>)
546
+ //(</afterSendMessageToGraph>)
547
+ return {
548
+ objType: objType,
549
+ objInstanceFull: objInstanceFullForGraph,
550
+ relationships: requestParams.relationships || [],
551
+ status: "complete",
552
+ errorsFound: errorsFound
553
+ }
554
+ };
555
+ }; // end loop of objectCreate.
556
+ if (errorsFound.length > 0) {
557
+ break;
558
+ }
559
+ }; // end loop listOfObjectForCreates
560
+
561
+ if (errorsFound.length > 0) {
562
+ _izContext.logger.debug("Case have errorFound:::", errorsFound);
563
+
564
+ // remove awaitngMultiplestep. [[[[[[[open when not test lolcal.]]]]]]]
565
+ await asyncFlowSharedLib.clearAllAwaitingSteps(
566
+ _izContext,
567
+ asyncFlowSharedLib.createPendingStepId((hash({
568
+ objType: objType,
569
+ identifiers: objInstanceFull.identifiers
570
+ })), PREFIX.CREATE_OBJECT_ASYNC_COMPLETE)); // pendingStepId
571
+
572
+ // send message to OutCreateObjectComplete.
573
+ //..
574
+ messageObject = {
575
+ objType: objType,
576
+ identifiers: null, // or {}
577
+ errorsFound: errorsFound
578
+ };
579
+
580
+ // pass back property.
581
+ messageObject = callingFlowSharedLib.addPassBackPropertiesToSnsResponseMessageObject(callingFlowConfig, messageObject);
582
+ let messageAttributes = callingFlowSharedLib.addCallingFlowToSnsResponseMessageAttributes(callingFlowConfig, {});
583
+
584
+ let sendMessageOutCreateObjectComplete = {
585
+ Message: JSON.stringify(messageObject),
586
+ MessageAttributes: sns.createStringMessageAttributes(_izContext, messageAttributes),
587
+ TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, TOPIC_NAME_GENERATE_CODE.outCreateNodeComplete)
588
+ };
589
+ _izContext.logger.debug("Send message to OutCreateObjectComplete :::>", sendMessageOutCreateObjectComplete)
590
+ await sns.publishAsync(_izContext, sendMessageOutCreateObjectComplete);
591
+
592
+ return {
593
+ objType: objType,
594
+ objInstanceFull: objInstanceFull,
595
+ relationships: requestParams.relationships || [],
596
+ status: "error",
597
+ errorsFound: errorsFound
598
+ }
599
+ } else {
600
+
601
+ if (allAwaitingStepsId.length == 0 && listOfObjectForCreates.length == 0) {
602
+ let messageObject = {
603
+ objType: {
604
+ objectType: OBJECT_TYPE,
605
+ serviceTag: SERVICE_TAG
606
+ },
607
+ objInstanceFull: {
608
+ identifiers: objInstanceFullForDynamoDb.identifiers,
609
+ fields: objInstanceFullForDynamoDb.fields
610
+ }
611
+ }
612
+
613
+ if (callingFlowConfig[callingFlowSharedLib.consts.CALLINGFLOW_PROPERTYNAME]) {
614
+ // send message to SNS OutCreateNodeComplete
615
+ _izContext.logger.debug("HAVE CallingFlow");
616
+ messageObject = callingFlowSharedLib.addPassBackPropertiesToSnsResponseMessageObject(callingFlowConfig, messageObject);
617
+
618
+ let messageAttributes = callingFlowSharedLib.addCallingFlowToSnsResponseMessageAttributes(callingFlowConfig, {});
619
+ let outCreateNodeCompleteTopic = await snsSharedLib.snsTopicArnByFlowSchema(_izContext, TOPIC_NAME_GENERATE_CODE.outCreateNodeComplete)
620
+ let messageParams = {
621
+ Message: JSON.stringify(messageObject),
622
+ MessageAttributes: sns.createStringMessageAttributes(_izContext, messageAttributes),
623
+ TopicArn: outCreateNodeCompleteTopic,
624
+ };
625
+
626
+ _izContext.logger.debug("messageParams OutCreateNode ::::::: ", messageParams);
627
+ await sns.publishAsync(_izContext, messageParams);
628
+ }
629
+ }
630
+ return {
631
+ objType: objType,
632
+ objInstanceFull: objInstanceFullForDynamoDb,
633
+ relationships: requestParams.relationships || [],
634
+ status: "complete",
635
+ errorsFound: errorsFound
636
+ }
637
+ }
638
+ } catch (err) {
639
+ throw (err)
640
+ }
641
+ }
642
+
643
+ const correlationIds = require("@izara_project/izara-core-library-correlation-ids");
644
+ const logger = require("@izara_project/izara-core-library-logger");
645
+ const integrationTestDetail = require("@izara_project/izara-core-library-integration-tests");
646
+ const resourceUse = require("@izara_project/izara-core-library-resource-use");
647
+ const { link } = require('fs');
648
+ const izaraAttributeTree = require('@izara_project/izara-attribute-tree');
649
+ let _izContext = {
650
+ correlationIds: correlationIds,
651
+ logger: logger,
652
+ integrationTestDetail: integrationTestDetail,
653
+ resourceUse: resourceUse
654
+ }
655
+ _izContext.correlationIds.set(coreConsts.BASE_USER_ID, "BasDev")
656
+ _izContext.correlationIds.set(coreConsts.TARGET_ID, "BasDevTargetId")
657
+ this.createMain(_izContext,
658
+ {
659
+ "fieldNames": {
660
+ "address": "585/2"
661
+ },
662
+ "relationships": [
663
+ {
664
+ "relType": {
665
+ "serviceTag": "GCTpBas",
666
+ "relationshipTag": "hasHouse"
667
+ },
668
+ "relationshipProperties": {
669
+ "createTimestamp": 1746758956635
670
+ },
671
+ "relationshipDirection": "to",
672
+ "targetObjType": {
673
+ "serviceTag": "GCTpBas",
674
+ "objectType": "person"
675
+ },
676
+ "targetIdentifiers": {
677
+ "personId": "05b29b450a6d11ff1f79a0ea6531d32423af3260"
678
+ }
679
+ },
680
+ {
681
+ "relType": {
682
+ "serviceTag": "GCTpBas",
683
+ "relationshipTag": "hasHouse"
684
+ },
685
+ "relationshipProperties": {
686
+ "createTimestamp": 1746758956635
687
+ },
688
+ "relationshipDirection": "to",
689
+ "targetObjType": {
690
+ "serviceTag": "GCTpBas",
691
+ "objectType": "person"
692
+ },
693
+ "targetIdentifiers": {
694
+ "personId": "5d3add2de5fdbd9611864fb529c5091f511e5985"
695
+ }
696
+ }
697
+ ],
698
+ "objectType": "house"
699
+ },
700
+ "callingFlowBasDev"
701
+ )