@izara_project/izara-market-library-service-schemas 1.0.28 → 1.0.30

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 (125) hide show
  1. package/package.json +1 -1
  2. package/src/GenerateCodeLibs/src/Consts.js +10 -9
  3. package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +54 -21
  4. package/src/MainLibs/src/Consts.js +36 -18
  5. package/src/reStructure/GenerateCode.js +2 -1
  6. package/src/reStructure/TemplateConfig.js +5 -1
  7. package/src/reStructure/TemplateData/EndpointPerService/generateTemplateData.js +108 -0
  8. package/src/reStructure/TemplateData/EndpointPerService/handler/api/data.js +76 -0
  9. package/src/reStructure/TemplateData/EndpointPerService/handler/api/request.json +7 -0
  10. package/src/reStructure/TemplateData/EndpointPerService/handler/api/template.ejs +73 -0
  11. package/src/reStructure/TemplateData/EndpointPerService/handler/dsq/data.js +81 -0
  12. package/src/reStructure/TemplateData/EndpointPerService/handler/dsq/request.json +7 -0
  13. package/src/reStructure/TemplateData/EndpointPerService/handler/dsq/template.ejs +125 -0
  14. package/src/reStructure/TemplateData/EndpointPerService/handler/inv/data.js +70 -0
  15. package/src/reStructure/TemplateData/EndpointPerService/handler/inv/request.json +7 -0
  16. package/src/reStructure/TemplateData/EndpointPerService/handler/inv/template.ejs +73 -0
  17. package/src/reStructure/TemplateData/EndpointPerService/handler/sqs/data.js +79 -0
  18. package/src/reStructure/TemplateData/EndpointPerService/handler/sqs/request.json +7 -0
  19. package/src/reStructure/TemplateData/EndpointPerService/handler/sqs/template.ejs +126 -0
  20. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/create/data.js +53 -0
  21. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/create/template.ejs +624 -0
  22. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/delete/data.js +52 -0
  23. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/delete/template.ejs +177 -0
  24. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/get/data.js +56 -0
  25. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/get/template.ejs +234 -0
  26. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/update/data.js +56 -0
  27. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/update/template.ejs +330 -0
  28. package/src/reStructure/TemplateData/EndpointPerService/yaml/data.js +175 -0
  29. package/src/reStructure/TemplateData/EndpointPerService/yaml/template.ejs +26 -0
  30. package/src/reStructure/TemplateData/externalService/generateTemplateData.js +1 -1
  31. package/src/reStructure/TemplateData/externalService/lambdaRole/data.js +91 -249
  32. package/src/reStructure/TemplateData/externalService/lambdaRole/template.ejs +1 -1
  33. package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/data.js +10 -8
  34. package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/template.ejs +1 -1
  35. package/src/reStructure/TemplateData/findData/findDataYaml/data.js +2 -2
  36. package/src/reStructure/TemplateData/flowSchema/components/upload/confirmReserved/functionYaml/data.js +4 -3
  37. package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/functionYaml/data.js +3 -29
  38. package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/handler/data.js +3 -21
  39. package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/handler/template.ejs +3 -31
  40. package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/functionYaml/data.js +2 -2
  41. package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/sns-sqs/data.js +1 -1
  42. package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/sns-sqs/template.ejs +1 -1
  43. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/{getSignUrls → createPresignUrl}/functionYaml/data.js +41 -10
  44. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/{getSignUrls → createPresignUrl}/functionYaml/template.ejs +3 -0
  45. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/{getSignUrls → createPresignUrl}/handler/data.js +2 -2
  46. package/src/reStructure/TemplateData/flowSchema/components/upload/{hook/handler/templateAsyncHandler.ejs → preSignUrl/createPresignUrl/handler/template.ejs} +26 -11
  47. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/{getSignUrls → createPresignUrl}/mainFunction/data.js +10 -7
  48. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/createPresignUrl/mainFunction/template.ejs +253 -0
  49. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/{reservedLimit → createPresignUrl}/queue/data.js +1 -1
  50. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/functionYaml/data.js +10 -38
  51. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/functionYaml/template.ejs +0 -3
  52. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/handler/data.js +2 -2
  53. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/handler/template.ejs +40 -45
  54. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/mainFunction/data.js +7 -10
  55. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/mainFunction/template.ejs +100 -190
  56. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/{getSignUrls → reservedLimit}/sqs/data.js +4 -4
  57. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/{getSignUrls → reservedLimit}/sqs/template.ejs +2 -2
  58. package/src/reStructure/TemplateData/flowSchema/components/upload/processFile/functionYml/HdrS3/data.js +8 -6
  59. package/src/reStructure/TemplateData/flowSchema/components/upload/processFile/queue/s3Template.ejs +1 -1
  60. package/src/reStructure/TemplateData/flowSchema/components/upload/relate/S3/data.js +5 -2
  61. package/src/reStructure/TemplateData/flowSchema/generateTemplateData.js +41 -38
  62. package/src/reStructure/TemplateData/flowSchema/legacy/hookCode-old/queue/snsTemplate.ejs +1 -1
  63. package/src/reStructure/TemplateData/generateRole/createSharedResource.js +11 -1
  64. package/src/reStructure/TemplateData/perActionComplete/create/mainFunction/template.ejs +35 -44
  65. package/src/reStructure/TemplateData/perActionComplete/create/sns-out/template.ejs +1 -1
  66. package/src/reStructure/TemplateData/perActionComplete/create/yaml/data.js +4 -5
  67. package/src/reStructure/TemplateData/perActionComplete/delete/yaml/data.js +5 -4
  68. package/src/reStructure/TemplateData/perActionComplete/generateTemplateData.js +15 -2
  69. package/src/reStructure/TemplateData/perActionComplete/get/yaml/data.js +7 -4
  70. package/src/reStructure/TemplateData/perActionComplete/update/sns-out/data.js +1 -1
  71. package/src/reStructure/TemplateData/perActionComplete/update/yaml/data.js +5 -4
  72. package/src/reStructure/TemplateData/processLogical/yaml/data.js +3 -3
  73. package/src/reStructure/TemplateData/processLogicalPagination/yaml/dsq/data.js +1 -1
  74. package/src/reStructure/TemplateData/processLogicalPagination/yaml/sqs/data.js +2 -2
  75. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/api/data.js +16 -14
  76. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/dsq/data.js +16 -14
  77. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/inv/data.js +16 -15
  78. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/sqs/data.js +18 -16
  79. package/src/reStructure/TemplateData/relationshipPerAction/create/action/sns-in-sqs/snsTemplate.ejs +1 -1
  80. package/src/reStructure/TemplateData/relationshipPerAction/create/complete/functionYaml/data.js +2 -2
  81. package/src/reStructure/TemplateData/relationshipPerAction/create/complete/mainFunction/data.js +1 -1
  82. package/src/reStructure/TemplateData/relationshipPerAction/create/complete/sns-in-sqs/template.ejs +0 -1
  83. package/src/reStructure/TemplateData/relationshipPerAction/create/complete/sns-out/template.ejs +1 -1
  84. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/api/data.js +16 -14
  85. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/dsq/data.js +16 -15
  86. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/inv/data.js +17 -14
  87. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/sqs/data.js +18 -16
  88. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/sns-in-sqs/snsTemplate.ejs +1 -1
  89. package/src/reStructure/TemplateData/relationshipPerAction/delete/complete/functionYaml/data.js +2 -2
  90. package/src/reStructure/TemplateData/relationshipPerAction/delete/complete/sns-out/template.ejs +1 -1
  91. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/api/data.js +16 -14
  92. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/dsq/data.js +17 -14
  93. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/inv/data.js +16 -14
  94. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/sqs/data.js +20 -17
  95. package/src/reStructure/TemplateData/relationshipPerAction/get/action/sns-in-sqs/snsTemplate.ejs +1 -1
  96. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/functionYaml/data.js +2 -2
  97. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/sns-out/template.ejs +1 -1
  98. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/api/data.js +16 -14
  99. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/dsq/data.js +16 -14
  100. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/inv/data.js +16 -14
  101. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/sqs/data.js +19 -18
  102. package/src/reStructure/TemplateData/relationshipPerAction/update/action/sns-in-sqs/snsTemplate.ejs +1 -1
  103. package/src/reStructure/TemplateData/relationshipPerAction/update/complete/functionYaml/data.js +2 -2
  104. package/src/reStructure/TemplateData/relationshipPerAction/update/complete/sns-out/template.ejs +1 -1
  105. package/src/reStructure/TemplateData/resourceYaml/dynamodb/defaultDynamoDbTable.js +1 -1
  106. package/src/reStructure/TemplateData/resourceYaml/dynamodb/generateDynamoPerLink.js +40 -38
  107. package/src/reStructure/TemplateData/resourceYaml/dynamodb/mainResourcePerObjectSchemaData.js +1 -1
  108. package/src/reStructure/TemplateData/resourceYaml/generateTemplateData.js +6 -12
  109. package/src/reStructure/TemplateData/resourceYaml/sns-in-sqs/defaultSnsInSqsForFindDataAndProcessLogical.js +1 -1
  110. package/src/reStructure/TemplateData/resourceYaml/sns-in-sqs/snsAndSqsPerActionData.js +22 -49
  111. package/src/reStructure/TemplateData/resourceYaml/sns-in-sqs/snsTemplate.ejs +1 -1
  112. package/src/reStructure/TemplateData/resourceYaml/sns-out/data.js +8 -24
  113. package/src/reStructure/TemplateData/resourceYaml/sns-out/template.ejs +1 -1
  114. package/src/reStructure/TemplateData/testTemplate/template.ejs +0 -5
  115. package/src/reStructure/TemplateData/flowSchema/components/upload/hook/handler/data.js +0 -93
  116. package/src/reStructure/TemplateData/flowSchema/components/upload/hook/handler/templateSyncHandler.ejs +0 -49
  117. package/src/reStructure/TemplateData/flowSchema/components/upload/hook/hookLogic/data.js +0 -43
  118. package/src/reStructure/TemplateData/flowSchema/components/upload/hook/mainFunction/data.js +0 -65
  119. package/src/reStructure/TemplateData/flowSchema/components/upload/hook/mainFunction/template.ejs +0 -7
  120. package/src/reStructure/TemplateData/flowSchema/components/upload/hook/queue/data.js +0 -72
  121. package/src/reStructure/TemplateData/flowSchema/components/upload/hook/queue/snsTemplate.ejs +0 -59
  122. package/src/reStructure/TemplateData/flowSchema/components/upload/hook/queue/sqsTemplate.ejs +0 -43
  123. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/getSignUrls/handler/template.ejs +0 -120
  124. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/getSignUrls/mainFunction/template.ejs +0 -163
  125. /package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/{reservedLimit → createPresignUrl}/queue/template.ejs +0 -0
@@ -0,0 +1,624 @@
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
+
66
+ /**
67
+ - all storageType( DB and Graph) use objInstance({identifiers,fields})
68
+ - storageType[DB] async
69
+ - storageType[Graph] sync (should be have lambda complete)
70
+ -- before DB and Graph have boolend check (allStorageTagComplete = true) if storageType == graph set allStorageTagComplete = false,
71
+ and save awaitingMultiplastep prefix(serviceTag_CreateObject{identifierId})
72
+
73
+ >>> in lambdaComplete resive message from GrapHandler
74
+ 1.1 check have returnValue.errorsFould.length > 0
75
+ -- Delete all awitingMultiplestep and senf message to callingFlow have errorFound.
76
+ 1.2 check awaitingmultipleStepall finish
77
+ -- Delete awaitingStep in come if have other multiplestep(not finish)== not send message.
78
+ --- if check awaitingmultipleStepall finish not have record ===> sendmessage to callingFlow.
79
+ */
80
+ //=========================================================================================
81
+ /**
82
+ *
83
+ * @param {*} _izContext
84
+ * @param {Object} requestParams = {fieldNames,relationships = []}
85
+ * @param {*} callingFlowConfig
86
+ */
87
+
88
+ module.exports.createMain = async (
89
+ _izContext,
90
+ requestParams,
91
+ callingFlowConfig
92
+ ) => {
93
+ try {
94
+ _izContext.logger.debug("function CreateMain:", {
95
+ requestParams,
96
+ callingFlowConfig
97
+ });
98
+
99
+ let errorsFound = [];
100
+
101
+ const userId = _izContext.correlationIds.get(coreConsts.BASE_USER_ID);
102
+ const targetId = _izContext.correlationIds.get(coreConsts.TARGET_ID)
103
+ if (!userId) {
104
+ errorsFound.push("Not have userId")
105
+ }
106
+
107
+ //(<beforeQuery>)
108
+ //(</beforeQuery>)
109
+
110
+ const objType = createObjType(requestParams.objectType);
111
+
112
+ let objectSchema = await getObjectSchema.getObjSchemaS3WithHierarchy(
113
+ _izContext,
114
+ objType
115
+ );
116
+ _izContext.logger.debug("objectSchema", objectSchema);
117
+
118
+ let objectSchemas = uploadUseCase.generateObjectSchemaForCombineFieldNames(
119
+ _izContext,
120
+ objectSchema
121
+ );
122
+ _izContext.logger.debug("objectSchemas", objectSchemas);
123
+
124
+ if (objectSchema.hasOwnProperty("belongTo") && !targetId) {
125
+ errorsFound.push('not have targetId')
126
+ }
127
+
128
+ let createDataDetails = await createDataDetailsLib(_izContext, objectSchemas);
129
+ _izContext.logger.debug("createDataDetails is =", createDataDetails);
130
+
131
+ let checkCorrectLinks = [];
132
+
133
+ //validate linkType
134
+ if ((requestParams.hasOwnProperty("relationships")) && (requestParams.relationships.length > 0)) {
135
+
136
+ for (let relationshipProperties of requestParams.relationships) {
137
+ _izContext.logger.debug("relationshipProperties", relationshipProperties);
138
+ _izContext.logger.debug("relType", relationshipProperties.relType);
139
+ let getObjectRelationship = await getObjectSchema.getRelationshipSchemaWithCache(
140
+ _izContext,
141
+ relationshipProperties.relType
142
+ )
143
+ _izContext.logger.debug("getObjectRelationship", getObjectRelationship)
144
+
145
+ for (const relationshipLink of Object.values(getObjectRelationship.links)) {
146
+ if (relationshipLink.from.linkType === "many" && relationshipLink.to.linkType === "many") {
147
+ if (relationshipLink.from.requiredOnCreate === true || relationshipLink.to.requiredOnCreate === true) {
148
+ errorsFound.push("error many to many linkType can't have requireOnCreate === true")
149
+ }
150
+ }
151
+ }
152
+ const links = await findLinksByObjTypes(_izContext, [objType, relationshipProperties.targetObjType], getObjectRelationship.links);
153
+ _izContext.logger.debug("links", links)
154
+
155
+ if (!links.length) {
156
+ errorsFound.push(`not found link between ${JSON.stringify({ mainObjType: objType })} and ${JSON.stringify({ toObjType: relationshipProperties.targetObjType })} `)
157
+ }
158
+
159
+ for (let link of links) {
160
+ const { serviceTag: fromServiceTag, objectType: fromObjectType } = objType;
161
+ const { serviceTag: toServiceTag, objectType: toObjectType } = relationshipProperties.targetObjType
162
+
163
+ const { serviceTag: firstServiceTag, objectType: firstObjectType } = link.from.objType;
164
+ const { serviceTag: secondServiceTag, objectType: secondObjectType } = link.to.objType
165
+
166
+ const matchesFromTo =
167
+ fromServiceTag === firstServiceTag && fromObjectType === firstObjectType &&
168
+ toServiceTag === secondServiceTag && toObjectType === secondObjectType;
169
+
170
+ const matchesToFrom =
171
+ fromServiceTag === secondServiceTag && fromObjectType === secondObjectType &&
172
+ toServiceTag === firstServiceTag && toObjectType === firstObjectType
173
+
174
+ if ((relationshipProperties.relationshipDirection === "from" && matchesFromTo) ||
175
+ (relationshipProperties.relationshipDirection === "to" && matchesToFrom)) {
176
+ checkCorrectLinks.push(true)
177
+ } else {
178
+ checkCorrectLinks.push(false)
179
+ }
180
+ }
181
+ }
182
+ }
183
+ for (const [index, checkCorrectLink] of checkCorrectLinks.entries()) {
184
+ if (checkCorrectLink === false) {
185
+ errorsFound.push(`relationship direction ${JSON.stringify(requestParams.relationships[index])} is invalid`)
186
+ }
187
+ }
188
+ _izContext.logger.debug("finish validate Relationships from RequestParams")
189
+ let requiredOnCreateLinks = {};
190
+ let createLinkTypeIds = [];
191
+ // validate relationships link
192
+ let objectRelationshipSchema = await getObjectSchema.getRequiredOnCreateLinksWithCache(_izContext, objType);
193
+ _izContext.logger.debug("objectRelationshipSchema", objectRelationshipSchema);
194
+
195
+ // validate requiredOnCreateLinks
196
+ let filteredRequiredOnCreatedLinks = [];
197
+
198
+ await Promise.all(
199
+ objectRelationshipSchema.map(async (requiredLink) => {
200
+ const serviceTag = await Promise.all(
201
+ requiredLink.storageResourceTags.map(async (storageTag) => {
202
+ let storageResource = requiredLink.storageResources[storageTag];
203
+ if (storageResource.storageType === consts.STORAGE_TYPES.graph) {
204
+ return await getGraphServiceTagWithCache(_izContext, storageResource.graphServerTag);
205
+ }
206
+ })
207
+ );
208
+ if (serviceTag.includes(GRAPH_HANDLER_SERVICE_NAME.graphHandler)) {
209
+ filteredRequiredOnCreatedLinks.push(requiredLink);
210
+ }
211
+ })
212
+ )
213
+ _izContext.logger.debug("filteredRequiredOnCreatedLinks", filteredRequiredOnCreatedLinks);
214
+
215
+ if (filteredRequiredOnCreatedLinks.length) {
216
+ if (!requestParams.relationships || !requestParams.relationships.length) {
217
+ // in case not send relationship to create with
218
+ for (const requireLink of filteredRequiredOnCreatedLinks) {
219
+ errorsFound.push(`missing required relationship of relType ${JSON.stringify(requireLink.relType)} when create`)
220
+ }
221
+ }
222
+
223
+ for (const requireLink of filteredRequiredOnCreatedLinks) {
224
+ const requiredOnCreateLinkTypeId = createLinkTypeId(
225
+ _izContext,
226
+ objType,
227
+ requireLink.other.objType,
228
+ requireLink.relType,
229
+ requireLink.base.direction
230
+ );
231
+
232
+ Object.assign(requiredOnCreateLinks, {
233
+ [requiredOnCreateLinkTypeId]: requireLink
234
+ })
235
+ }
236
+
237
+ if (requestParams.hasOwnProperty("relationships") && requestParams.relationships.length) {
238
+ for (const createRelationship of requestParams.relationships) {
239
+ const onCreateLinkTypeId = createLinkTypeId(
240
+ _izContext,
241
+ objType,
242
+ createRelationship.targetObjType,
243
+ createRelationship.relType,
244
+ createRelationship.relationshipDirection
245
+ );
246
+
247
+ if (!requiredOnCreateLinks.hasOwnProperty(onCreateLinkTypeId)) {
248
+ errorsFound.push(`relType:${JSON.stringify(createRelationship.relType)} not allow to create when use create action`)
249
+ continue;
250
+ } else {
251
+ createLinkTypeIds.push(onCreateLinkTypeId);
252
+ }
253
+ }
254
+ }
255
+ }
256
+
257
+
258
+ // validate missing relType when create that should create
259
+ const remainRequiredOnCreateLinkTypeIds = Object.keys(requiredOnCreateLinks)
260
+ .filter(requiredInCreateLinkTypeId => !createLinkTypeIds.includes(requiredInCreateLinkTypeId))
261
+
262
+ if (remainRequiredOnCreateLinkTypeIds.length) {
263
+ for (const remainRequiredOnCreateLinkTypeId of remainRequiredOnCreateLinkTypeIds) {
264
+ const missingLink = {
265
+ relType: requiredOnCreateLinks[remainRequiredOnCreateLinkTypeId].relType,
266
+ base: requiredOnCreateLinks[remainRequiredOnCreateLinkTypeId].base.objType,
267
+ other: requiredOnCreateLinks[remainRequiredOnCreateLinkTypeId].other.objType
268
+ };
269
+ errorsFound.push(`Missing Link:: ${JSON.stringify(missingLink)} when create`)
270
+ }
271
+ }
272
+ _izContext.logger.debug("createLinkTypeIds", createLinkTypeIds);
273
+ _izContext.logger.debug("requiredOnCreateLinks", requiredOnCreateLinks);
274
+ // end validate
275
+
276
+ let objInstanceFull = {
277
+ identifiers: {},
278
+ fields: {}
279
+ };
280
+
281
+ let listOfRequiredOnCreate = [];
282
+ let listOfOptionalOnCreate = [];
283
+
284
+ let allAwaitingStepsId = [];
285
+
286
+ // validate single identifiers
287
+ if (objectSchemas.identifiers.length === 1 && !objectSchemas.identifiers[0].hasOwnProperty("fieldNames")) {
288
+
289
+ const identifier = objectSchemas.identifiers[0];
290
+ _izContext.logger.debug(":::::case single identifer:::::", identifier);
291
+
292
+ if (objectSchemas.fieldNames[identifier.fieldName].hasOwnProperty("randomOnCreate")) {
293
+ if ((objectSchemas.fieldNames[identifier.fieldName].randomOnCreate == true)) {
294
+ Object.assign(requestParams.fieldNames, {
295
+ [identifier.fieldName]: hash({
296
+ fieldNames: identifier, //
297
+ uniqueRequestId: _izContext.uniqueRequestId,
298
+ callingFlowConfig: callingFlowConfig
299
+ })
300
+ });
301
+ _izContext.logger.debug("Assign requestParams", requestParams)
302
+
303
+ } else if ((objectSchemas.fieldNames[identifier.fieldName].randomOnCreate == false) ||
304
+ (objectSchemas.fieldNames[identifier.fieldName].randomOnCreate == null)) {
305
+
306
+ if ((objectSchemas.fieldNames[identifier.fieldName].requiredOnCreate == true) &&
307
+ (objectSchemas.fieldNames[identifier.fieldName].canUpdate == false)) {
308
+ // check Fns have resive
309
+
310
+ if (requestParams.fieldNames.hasOwnProperty([identifier.fieldName])) {
311
+ _izContext.logger.debug("identifier is exist:", {
312
+ [identifier.fieldName]: requestParams.fieldNames[identifier.fieldName]
313
+ });
314
+
315
+ } else {
316
+ errorsFound.push("[invalid]requestParams not have data fieldNames of requriedOnCreate");
317
+ }
318
+ }
319
+ };
320
+ } else if (objectSchemas.fieldNames[identifier.fieldName].hasOwnProperty("hashOnCreate")) {
321
+ if (objectSchemas.fieldNames[identifier.fieldName].hashOnCreate.length &&
322
+ objectSchemas.fieldNames[identifier.fieldName].hashOnCreate.length > 0) {
323
+ for (const fieldName of objectSchemas.fieldNames[identifier.fieldName].hashOnCreate) {
324
+ Object.assign(
325
+ requestParams.fieldNames, {
326
+ [identifier.fieldName]: hash({
327
+ [fieldName]: requestParams.fieldNames[fieldName]
328
+ })
329
+ }
330
+ )
331
+ }
332
+ } else {
333
+ errorsFound.push("[invalid] no data to hash for create")
334
+ }
335
+ } else {
336
+ if ((objectSchemas.fieldNames[identifier.fieldName].requiredOnCreate === false) &&
337
+ (objectSchemas.fieldNames[identifier.fieldName].optionalOnCreate === false) &&
338
+ (objectSchemas.fieldNames[identifier.fieldName].canUpdate === false) &&
339
+ objectSchemas.fieldNames[identifier.fieldName].hashOnCreate === false) {
340
+ errorsFound.push("[invalid]case single identifier invalid objectSchemass");
341
+ };
342
+ };
343
+ }
344
+
345
+ _izContext.logger.debug("requestParams is:", requestParams);
346
+
347
+ // check settingObjSchemas
348
+ for (let [keyFieldNames, valueFieldNames] of Object.entries(objectSchemas.fieldNames)) {
349
+
350
+ if (valueFieldNames.hasOwnProperty("randomOnCreate") && valueFieldNames.randomOnCreate === true) {
351
+ listOfRequiredOnCreate.push(keyFieldNames)
352
+ };
353
+
354
+ if (valueFieldNames.hasOwnProperty("requiredOnCreate") && valueFieldNames.requiredOnCreate === true) {
355
+ listOfRequiredOnCreate.push(keyFieldNames)
356
+ };
357
+
358
+ if (valueFieldNames.hasOwnProperty("hashOnCreate") && valueFieldNames.hashOnCreate.length) {
359
+ listOfRequiredOnCreate.push(keyFieldNames)
360
+ }
361
+
362
+ if (valueFieldNames.hasOwnProperty("optionalOnCreate") && valueFieldNames.optionalOnCreate === true) {
363
+ if ((valueFieldNames.requiredOnCreate === false) && valueFieldNames.optionalOnCreate === true) {
364
+ listOfOptionalOnCreate.push(keyFieldNames)
365
+ };
366
+ };
367
+
368
+ }; // end iteration of fieldNames
369
+
370
+ _izContext.logger.debug("listOfRequriedOnCreate", listOfRequiredOnCreate);
371
+ _izContext.logger.debug("listOfOptionalOnCreate", listOfOptionalOnCreate);
372
+ for (let fieldName of Object.keys(requestParams.fieldNames)) {
373
+
374
+ if (!listOfRequiredOnCreate.includes(fieldName)) {
375
+ if (!listOfOptionalOnCreate.includes(fieldName)) {
376
+ errorsFound.push("[invalid] over fieldNames create object");
377
+ }
378
+ };
379
+
380
+ if (listOfOptionalOnCreate.length > 0 && listOfRequiredOnCreate.includes(fieldName)) {
381
+ //(<optionalParams>)
382
+ //(</optionalParams>)
383
+ };
384
+
385
+ if (objectSchemas.identifierFieldNames.includes(fieldName)) {
386
+ _izContext.logger.debug("identifiers is", fieldName);
387
+ Object.assign(objInstanceFull.identifiers, {
388
+ [fieldName]: requestParams.fieldNames[fieldName]
389
+ });
390
+ };
391
+
392
+ if (errorsFound.length > 0) {
393
+ _izContext.logger.debug("HaveError::", errorsFound);
394
+ break
395
+ };
396
+
397
+ }; // end loop
398
+
399
+ let listOfObjectForCreates = [];
400
+
401
+ let objInstanceFullForDynamoDb = lodash.cloneDeep(objInstanceFull)
402
+ let objInstanceFullForGraph = lodash.cloneDeep(objInstanceFull)
403
+
404
+ if (errorsFound.length == 0) {
405
+
406
+ for (let [storageTag, createDataDetail] of Object.entries(createDataDetails)) {
407
+
408
+ if (createDataDetail.storageType == consts.STORAGE_TYPES.dynamoDB) {
409
+ _izContext.logger.debug("::::::DynamoDB::::::", { storageTag, objInstanceFull });
410
+
411
+
412
+ Object.assign(objInstanceFullForDynamoDb.fields, createObjInstanceFullFieldsByStorageTag(_izContext, storageTag, createDataDetail))
413
+ _izContext.logger.debug("objInstanceFull before create item in dynamoDB", objInstanceFullForDynamoDb)
414
+
415
+ let identifiersForCreateData = await dynamoDbIdentifiersByStorageResource(
416
+ _izContext,
417
+ objectSchema,
418
+ createDataDetails,
419
+ objInstanceFullForDynamoDb.identifiers
420
+ )
421
+ _izContext.logger.debug("identifiersForCreateData", identifiersForCreateData);
422
+
423
+ await dynamodbSharedLib.putItem(
424
+ _izContext,
425
+ await dynamodbSharedLib.tableName(
426
+ _izContext,
427
+ createDataDetail.tableName
428
+ ),
429
+ {
430
+ ...identifiersForCreateData,
431
+ ...objInstanceFullForDynamoDb.fields
432
+ }
433
+ );
434
+ } else if (createDataDetail.storageType == consts.STORAGE_TYPES.graph) {
435
+ _izContext.logger.debug("::::::Graph::::::", { storageTag, objInstanceFull });
436
+
437
+ Object.assign(objInstanceFullForGraph.fields, createObjInstanceFullFieldsByStorageTag(_izContext, storageTag, createDataDetail))
438
+ _izContext.logger.debug("objInstanceFull before send to Graph", objInstanceFullForGraph)
439
+
440
+ // allStorageTagComplete = false;
441
+ allAwaitingStepsId.push(await asyncFlowSharedLib.createAwaitingStepId(
442
+ (hash({
443
+ objType: objType,
444
+ graphServerTag: storageTag,
445
+ identifiers: objInstanceFullForGraph.identifiers
446
+ })),
447
+ PREFIX.CREATE_OBJECT_ASYNC
448
+ ));
449
+ listOfObjectForCreates.push({
450
+ [storageTag]: {
451
+ objInstanceFull: {
452
+ identifiers: objInstanceFullForGraph.identifiers,
453
+ fields: objInstanceFullForGraph.fields
454
+ },
455
+ allStorageTagComplete: false
456
+ }
457
+ });
458
+
459
+ _izContext.logger.debug("FIRST", listOfObjectForCreates)
460
+
461
+ };
462
+ _izContext.logger.debug("[1]listOfObjectForCreates:::", listOfObjectForCreates);
463
+ };
464
+ };
465
+
466
+ function createObjInstanceFullFieldsByStorageTag(_izContext, storageTag, createDataDetail) {
467
+ _izContext.logger.debug("createObjInstanceFullFieldsByStorageTag : ", { storageTag, createDataDetail })
468
+ let fields = {};
469
+ for (let fieldName of Object.keys(requestParams.fieldNames)) {
470
+ if ((createDataDetails[storageTag].fieldNames.includes(fieldName)) &&
471
+ (createDataDetail.fieldNames.includes(fieldName))) {
472
+ if (!objInstanceFull.identifiers.hasOwnProperty(fieldName)) {
473
+ if (!fields.hasOwnProperty(fieldName)) {
474
+ Object.assign(fields, {
475
+ [fieldName]: requestParams.fieldNames[fieldName]
476
+ })
477
+ }
478
+ }
479
+ }
480
+ }
481
+ _izContext.logger.debug({ fields })
482
+ return fields
483
+ }
484
+ /// step save awiatingMultipleStep of storageType graph ...........................................................
485
+
486
+ await asyncFlowSharedLib.createAwaitingMultipleSteps(
487
+ _izContext,
488
+ allAwaitingStepsId,
489
+ asyncFlowSharedLib.createPendingStepId((hash({ objType: objType, identifiers: objInstanceFull.identifiers })), PREFIX.CREATE_OBJECT_ASYNC_COMPLETE)
490
+ );
491
+ //............................................................................................................
492
+
493
+ // process storageType : graph
494
+ let messageObject = {};
495
+ for (let objectCreate of listOfObjectForCreates) {
496
+
497
+ for (let [graphServiceName, objecForCreate] of Object.entries(objectCreate)) {
498
+ _izContext.logger.debug("Loop each graph:", {
499
+ [graphServiceName]: objecForCreate
500
+ });
501
+
502
+ if (objecForCreate.allStorageTagComplete == false) { // needless check because in listOfObjectForCreates push case graph only!
503
+
504
+ messageObject = {
505
+ objType: objType,
506
+ objInstanceFull: objecForCreate.objInstanceFull,
507
+ relationships: requestParams.relationships || []
508
+ };
509
+ };
510
+
511
+ if (errorsFound.length > 0) {
512
+ break;
513
+ } else {
514
+ _izContext.logger.debug("SENT MESSAGE EACH GRAPH::::", { graphServiceName, messageObject, callingFlowConfig })
515
+
516
+ Object.assign(messageObject, {
517
+ settings: { updatePropertiesOnMatch: false },
518
+ originTimestamp: Date.now()
519
+ });
520
+
521
+ messageObject = callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
522
+ messageObject,
523
+ callingFlowSharedLib.addParentCallingFlowConfig(
524
+ callingFlowConfig, // resive parent callingFlowConfig.
525
+ callingFlowSharedLib.createCallingFlowConfig( // callinfflow own service
526
+ await lambdaSharedLib.lambdaFunctionName(_izContext, TOPIC_NAME_GENERATE_CODE.createNodeComplete), {}
527
+ )
528
+ )
529
+ );
530
+
531
+ let messageToCreateObject = {
532
+ Message: JSON.stringify(messageObject),
533
+ TopicArn: await snsSharedLib.snsTopicArn(_izContext, TOPIC_NAME_GRAPH_HANDLER.inCreateNode, graphServiceName)
534
+ };
535
+ _izContext.logger.debug("RequestParams before send to sqs messageToCreateObject ::::::: ", messageToCreateObject);
536
+ await sns.publishAsync(_izContext, messageToCreateObject);
537
+ };
538
+ }; // end loop of objectCreate.
539
+ if (errorsFound.length > 0) {
540
+ break;
541
+ }
542
+ }; // end loop listOfObjectForCreates
543
+
544
+ if (errorsFound.length > 0) {
545
+ _izContext.logger.debug("Case have errorFound:::", errorsFound);
546
+
547
+ // remove awaitngMultiplestep. [[[[[[[open when not test lolcal.]]]]]]]
548
+ await asyncFlowSharedLib.clearAllAwaitingSteps(
549
+ _izContext,
550
+ asyncFlowSharedLib.createPendingStepId((hash({
551
+ objType: objType,
552
+ identifiers: objInstanceFull.identifiers
553
+ })), PREFIX.CREATE_OBJECT_ASYNC_COMPLETE)); // pendingStepId
554
+
555
+ // send message to OutCreateObjectComplete.
556
+ //..
557
+ messageObject = {
558
+ objType: objType,
559
+ identifiers: null, // or {}
560
+ errorsFound: errorsFound
561
+ };
562
+
563
+ // pass back property.
564
+ messageObject = callingFlowSharedLib.addPassBackPropertiesToSnsResponseMessageObject(callingFlowConfig, messageObject);
565
+ let messageAttributes = callingFlowSharedLib.addCallingFlowToSnsResponseMessageAttributes(callingFlowConfig, {});
566
+
567
+ let sendMessageOutCreateObjectComplete = {
568
+ Message: JSON.stringify(messageObject),
569
+ MessageAttributes: sns.createStringMessageAttributes(_izContext, messageAttributes),
570
+ TopicArn: await snsSharedLib.snsTopicArn(_izContext, TOPIC_NAME_GENERATE_CODE.outCreateNodeComplete)
571
+ };
572
+ _izContext.logger.debug("Send message to OutCreateObjectComplete :::>", sendMessageOutCreateObjectComplete)
573
+ await sns.publishAsync(_izContext, sendMessageOutCreateObjectComplete);
574
+
575
+ return {
576
+ objType: objType,
577
+ fieldNames: requestParams.fieldNames,
578
+ relationship: requestParams.relationships,
579
+ status: "error",
580
+ errorsFound: errorsFound
581
+ }
582
+ } else {
583
+
584
+ if (allAwaitingStepsId.length == 0 && listOfObjectForCreates.length == 0) {
585
+ let messageObject = {
586
+ objType: {
587
+ objectType: OBJECT_TYPE,
588
+ serviceTag: SERVICE_TAG
589
+ },
590
+ objInstanceFull: {
591
+ identifiers: objInstanceFullForDynamoDb.identifiers,
592
+ fields: objInstanceFullForDynamoDb.fields
593
+ }
594
+ }
595
+
596
+ if (callingFlowConfig[callingFlowSharedLib.consts.CALLINGFLOW_PROPERTYNAME]) {
597
+ // send message to SNS OutCreateNodeComplete
598
+ _izContext.logger.debug("HAVE CallingFlow");
599
+ messageObject = callingFlowSharedLib.addPassBackPropertiesToSnsResponseMessageObject(callingFlowConfig, messageObject);
600
+
601
+ let messageAttributes = callingFlowSharedLib.addCallingFlowToSnsResponseMessageAttributes(callingFlowConfig, {});
602
+ let outCreateNodeCompleteTopic = await snsSharedLib.snsTopicArn(_izContext, TOPIC_NAME_GENERATE_CODE.outCreateNodeComplete)
603
+ let messageParams = {
604
+ Message: JSON.stringify(messageObject),
605
+ MessageAttributes: sns.createStringMessageAttributes(_izContext, messageAttributes),
606
+ TopicArn: outCreateNodeCompleteTopic,
607
+ };
608
+
609
+ _izContext.logger.debug("messageParams OutCreateNode ::::::: ", messageParams);
610
+ await sns.publishAsync(_izContext, messageParams);
611
+ }
612
+ }
613
+ return {
614
+ objType: objType,
615
+ fieldNames: requestParams.fieldNames,
616
+ relationship: requestParams.relationships,
617
+ status: "complete",
618
+ errorsFound: errorsFound
619
+ }
620
+ }
621
+ } catch (err) {
622
+ throw (err)
623
+ }
624
+ }
@@ -0,0 +1,52 @@
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
+ const { ACTIONS, HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
23
+
24
+ const {
25
+ firstLetterLowerCase: lowerCase,
26
+ firstLetterUpperCase: upperCase,
27
+ } = require("../../../../../MainLibs/index.js").utils;
28
+ const { DEFAULT_HANDLER_PER_ACTION, SOURCE_PATH } = require("../../../../../MainLibs/src/Consts.js");
29
+
30
+ const templatePath = path.join(__dirname, "./template.ejs")
31
+
32
+ function data(_izContext, srcPath) {
33
+ return [createSource(_izContext, srcPath)]
34
+ }
35
+
36
+ function createSource(_izContext, srcPath) {
37
+ let functionName = upperCase(ACTIONS.delete)
38
+ return {
39
+ templatePath: templatePath,
40
+ templateData: {
41
+ functionName,
42
+ },
43
+ setting: {
44
+ savePath: path.join(srcPath, SOURCE_PATH.endpointPerService),
45
+ saveFileName: `${upperCase(functionName)}_Main`,
46
+ fileExtension: ".js",
47
+ isAppend: false
48
+ }
49
+ }
50
+ }
51
+
52
+ module.exports = data