@izara_project/izara-market-library-service-schemas 1.0.2 → 1.0.4

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 (108) hide show
  1. package/package.json +5 -5
  2. package/src/GenerateCodeLibs/src/Consts.js +40 -0
  3. package/src/SourceManager/src/CreateSource.js +0 -1
  4. package/src/SourceManager/src/Utils.js +15 -1
  5. package/src/TemplateManager/src/FunctionYaml/HdrApi/data.js +170 -0
  6. package/src/TemplateManager/src/FunctionYaml/HdrApi/request.json +14 -0
  7. package/src/TemplateManager/src/FunctionYaml/HdrApi/template.ejs +33 -0
  8. package/src/TemplateManager/src/FunctionYaml/HdrDsq/data.js +180 -0
  9. package/src/TemplateManager/src/FunctionYaml/HdrDsq/request.json +19 -0
  10. package/src/TemplateManager/src/FunctionYaml/HdrDsq/template.ejs +30 -0
  11. package/src/TemplateManager/src/FunctionYaml/HdrInv/data.js +169 -0
  12. package/src/TemplateManager/src/{PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrInv.exampleData.js → FunctionYaml/HdrInv/example req.js } +3 -3
  13. package/src/TemplateManager/src/FunctionYaml/HdrInv/request.json +14 -0
  14. package/src/TemplateManager/src/{PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrInv.ejs → FunctionYaml/HdrInv/template.ejs} +5 -5
  15. package/src/TemplateManager/src/FunctionYaml/HdrSqs/data.js +182 -0
  16. package/src/TemplateManager/src/FunctionYaml/HdrSqs/request.json +19 -0
  17. package/src/TemplateManager/src/FunctionYaml/HdrSqs/template.ejs +30 -0
  18. package/src/TemplateManager/src/GenerateCode(Old).js +135 -0
  19. package/src/TemplateManager/src/GenerateCode.js +175 -15
  20. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrApi/data.js +100 -0
  21. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrApi/request.json +7 -0
  22. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrApi/template.ejs +76 -0
  23. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrDsq/data.js +109 -0
  24. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrDsq/request.json +7 -0
  25. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrDsq/template.ejs +105 -0
  26. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrInv/data.js +102 -0
  27. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrInv/request.json +7 -0
  28. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrInv/template.ejs +82 -0
  29. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrSqs/data.js +102 -0
  30. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrSqs/request.json +7 -0
  31. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrSqs/template.ejs +124 -0
  32. package/src/TemplateManager/src/PerActionEndpoint/Handler/testRequest.json +5 -0
  33. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/data.js +88 -0
  34. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/request.json +5 -0
  35. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/template.ejs +219 -0
  36. package/src/TemplateManager/src/ResourceYaml/dynamodb/awaitingMultipleStepData.js +98 -0
  37. package/src/TemplateManager/src/{MainResourcesYaml/TemplateAndData/DynamoDbMain/Data/MainDynamoDbYamlData.js → ResourceYaml/dynamodb/mainResourcePerObjectSchemaData.js} +66 -46
  38. package/src/TemplateManager/src/ResourceYaml/dynamodb/processLogicalAndFindData.js +103 -0
  39. package/src/TemplateManager/src/ResourceYaml/dynamodb/request.json +7 -0
  40. package/src/TemplateManager/src/ResourceYaml/dynamodb/template.ejs +31 -0
  41. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/defaultSnsInSqsForFindDataAndProcessLogical.js +81 -0
  42. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/request.json +4 -0
  43. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/snsAndSqsPerActiondata.js +108 -0
  44. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/snsTemplate.ejs +59 -0
  45. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/sqsTemplate.ejs +43 -0
  46. package/src/TemplateManager/src/ResourceYaml/sns-out/data.js +89 -0
  47. package/src/TemplateManager/src/ResourceYaml/sns-out/request.json +3 -0
  48. package/src/TemplateManager/src/ResourceYaml/sns-out/template.ejs +10 -0
  49. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/functionYaml/data.js +151 -0
  50. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/functionYaml/request.json +3 -0
  51. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/functionYaml/template.ejs +33 -0
  52. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/handler/HdrSqs/data.js +76 -0
  53. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/handler/HdrSqs/template.ejs +127 -0
  54. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/mainFunction/data.js +55 -0
  55. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/mainFunction/request.json +1 -0
  56. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/mainFunction/template.ejs +140 -0
  57. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-in-sqs/data.js +75 -0
  58. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-in-sqs/request.json +3 -0
  59. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-in-sqs/template.ejs +45 -0
  60. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-out/data.js +70 -0
  61. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-out/request.json +3 -0
  62. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrApi/data.js +127 -0
  63. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrApi/template.ejs +33 -0
  64. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrDsq/data.js +148 -0
  65. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrInv/data.js +125 -0
  66. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrSqs/data.js +148 -0
  67. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/mainFunction/data.js +80 -0
  68. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/mainFunction/request.json +1 -0
  69. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/mainFunction/template.ejs +324 -0
  70. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrApi/data.js +72 -0
  71. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrApi/request.json +7 -0
  72. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrApi/template.ejs +120 -0
  73. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrDsq/data.js +73 -0
  74. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrDsq/request.json +7 -0
  75. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrDsq/template.ejs +167 -0
  76. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrInv/data.js +73 -0
  77. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrInv/request.json +5 -0
  78. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrInv/template.ejs +126 -0
  79. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrSqs/data.js +73 -0
  80. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrSqs/request.json +7 -0
  81. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrSqs/template.ejs +146 -0
  82. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/request.json +31 -0
  83. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/sns-in-sqs/data.js +91 -0
  84. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/sns-in-sqs/request.json +3 -0
  85. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/sns-out/data.js +70 -0
  86. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/sns-out/request.json +3 -0
  87. package/src/TemplateManager/src/externalService/LambdaRole/data.js +193 -0
  88. package/src/TemplateManager/src/externalService/LambdaRole/request.json +18 -0
  89. package/src/TemplateManager/src/externalService/LambdaRole/template.ejs +56 -0
  90. package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/data.js +96 -0
  91. package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/request.json +12 -0
  92. package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/template.ejs +10 -0
  93. package/src/TemplateManager/src/libs/Consts.js +32 -3
  94. package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.ejs +0 -31
  95. package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.exampleData.js +0 -12
  96. package/src/TemplateManager/src/PerActionEndpoint/CreateSourceData.js +0 -131
  97. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplate/Create.js +0 -18
  98. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplate/Delete.js +0 -18
  99. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplate/Get.js +0 -18
  100. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplate/Update.js +0 -18
  101. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Data/LambdaYamlData.js +0 -166
  102. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrSqs.ejs +0 -0
  103. /package/src/TemplateManager/src/{MainResourcesYaml → ResourceYaml}/CreateSourceData.js +0 -0
  104. /package/src/TemplateManager/src/{PerActionEndpoint/DataPerActionEndpoint.js → UpdateRelationshipSchema/updateRalationshipComplete/handler/HdrSqs/request.json} +0 -0
  105. /package/src/TemplateManager/src/{PerActionEndpoint/TemplateAndData/Handler/Handler.js → UpdateRelationshipSchema/updateRelationship/functionYaml/HdrApi/request.json} +0 -0
  106. /package/src/TemplateManager/src/{PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplateData.js → UpdateRelationshipSchema/updateRelationship/functionYaml/HdrDsq/request.json} +0 -0
  107. /package/src/TemplateManager/src/{PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrApi.ejs → UpdateRelationshipSchema/updateRelationship/functionYaml/HdrInv/request.json} +0 -0
  108. /package/src/TemplateManager/src/{PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrDsq.ejs → UpdateRelationshipSchema/updateRelationship/functionYaml/HdrSqs/request.json} +0 -0
@@ -0,0 +1,324 @@
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 hash = require("object-hash");
21
+
22
+ const callingFlowSharedLib = require('@izara_project/izara-shared/src/CallingFlowSharedLib');
23
+ const lambdaSharedLib = require('@izara_project/izara-shared/src/LambdaSharedLib');
24
+
25
+ const snsSharedLib = require('@izara_project/izara-shared/src/SnsSharedLib');
26
+ const sns = require("@izara_project/izara-core-library-external-request/src/resources/Sns");
27
+
28
+ const asyncFlowSharedLib = require('@izara_project/izara-shared/src/AsyncFlowSharedLib');
29
+
30
+ // const NoRetryError = require('@izara_project/izara-core-library-core/src/NoRetryError');
31
+
32
+ const { validateObject } = require('@izara_project/izara-core-library-core/src/Validator')
33
+
34
+ const {
35
+ getRelationshipSchemaWithCache,
36
+ getObjSchemaS3WithHierarchy
37
+ } = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema');
38
+
39
+
40
+ const {
41
+ createObjectTypeId,
42
+ createRelationshipTypeId,
43
+ createLinkTypeId
44
+ } = require('@izara_project/izara-core-library-service-schemas/src/Utils');
45
+
46
+ const {
47
+ getGraphServiceTagWithCache
48
+ } = require('@izara_project/izara-core-library-service-schemas/src/ServiceConfig');
49
+
50
+ const consts = require('@izara_project/izara-core-library-service-schemas/src/Consts');
51
+ const { NoRetryError } = require("@izara_project/izara-core-library-core");
52
+
53
+ const {
54
+ PREFIX,
55
+ TOPIC_NAME_GRAPH_HANDLER,
56
+ TOPIC_NAME_GENERATE_CODE
57
+ } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/Consts');
58
+
59
+ /**
60
+ * update relationship endpoint
61
+ *
62
+ * @param {Object} _izContext
63
+ * @param {CorrelationIds} _izContext.correlationIds - property of _izContext
64
+ * @param {Logger} _izContext.logger - property of _izContext
65
+ * @param {Object} requestParams - request params
66
+ * @param {Object} callingFlowConfig
67
+ *
68
+ * @returns {object} description of return value
69
+ */
70
+ module.exports.updateRelationship = async (
71
+ _izContext,
72
+ requestParams,
73
+ callingFlowConfig = {},
74
+ //(<inputParamFromHandler>)
75
+ //(</inputParamFromHandler>)
76
+ ) => {
77
+
78
+
79
+ try {
80
+ _izContext.logger.debug('updateRelationship _izContext: ', _izContext);
81
+ _izContext.logger.debug('updateRelationship requestParams: ', requestParams);
82
+ _izContext.logger.debug('updateRelationship callingFlowConfig: ', callingFlowConfig);
83
+
84
+
85
+ const {
86
+ objects,
87
+ relType,
88
+ relId,
89
+ relationshipProperties
90
+ //(<additionalParam>)
91
+ //(</additionalParam>)
92
+ } = requestParams;
93
+
94
+ let errorsFound = [];
95
+
96
+ // validate object and identifiers
97
+ async function validateIdentifiersExists(_izContext, objType, identifiersObject) {
98
+
99
+ const objTypeString = `objType:{ serviceTag:${objType.serviceTag}, objectType:${objType.objectType} }`;
100
+ const objectSchema = await getObjSchemaS3WithHierarchy(_izContext, objType);
101
+
102
+ if (!objectSchema) {
103
+ errorsFound.push(`validateIdentifiers, not found schema of ${objTypeString}`);
104
+ }
105
+
106
+ for (const schemaIdentifier of objectSchema.identifiers) {
107
+ let identifierName = schemaIdentifier.fieldName || schemaIdentifier.name;
108
+
109
+ if (!identifiersObject.hasOwnProperty(identifierName)) {
110
+ errorsFound.push(`validateIdentifiers, ${objTypeString} property:${identifierName} not exists`);
111
+ } else {
112
+ if (
113
+ typeof (identifiersObject[identifierName]) !== "string"
114
+ && typeof (identifiersObject[identifierName]) !== "number"
115
+ ) {
116
+ errorsFound.push(`validateIdentifiers, ${objTypeString} property:${identifierName} should be string or number`);
117
+ }
118
+ }
119
+ }
120
+ }
121
+
122
+ await validateIdentifiersExists(_izContext, objects[0].objType, objects[0].identifiers);
123
+ await validateIdentifiersExists(_izContext, objects[1].objType, objects[1].identifiers);
124
+ // finished validate object and identifiers
125
+
126
+
127
+ const relationshipSchema = await getRelationshipSchemaWithCache(_izContext, relType);
128
+ _izContext.logger.debug("relationshipSchema: ", relationshipSchema);
129
+
130
+ let targetStorageResources = [];
131
+
132
+ if (relationshipSchema) {
133
+ // find targetStorageResources and validate each storageResources
134
+ await Promise.all(
135
+ relationshipSchema.links.map(async ({ from, to, storageResourceTags }) => {
136
+ const { serviceTag: fromServiceTag, objectType: fromObjectType } = from.objType
137
+ const { serviceTag: toServiceTag, objectType: toObjectType } = to.objType
138
+
139
+ const { serviceTag: firstServiceTag, objectType: firstObjectType } = objects[0].objType;
140
+ const { serviceTag: secondServiceTag, objectType: secondObjectType } = objects[1].objType;
141
+
142
+ // find exists link
143
+ if (
144
+ (
145
+ (firstServiceTag === fromServiceTag && firstObjectType === fromObjectType)
146
+ && (secondServiceTag === toServiceTag && secondObjectType === toObjectType)
147
+ )
148
+ ||
149
+ (
150
+ (firstServiceTag === toServiceTag && firstObjectType === toObjectType)
151
+ && (secondServiceTag === fromServiceTag && secondObjectType === fromObjectType)
152
+ )
153
+ ) {
154
+
155
+ // check founded storageResource of link and collect used storageResources
156
+ await Promise.all(storageResourceTags.map(async storageResourceTag => {
157
+ const usedStorageResource = relationshipSchema.storageResources[storageResourceTag];
158
+
159
+ if (usedStorageResource.storageType === consts.STORAGE_TYPES.graph) {
160
+ const graphServiceTag = await getGraphServiceTagWithCache(_izContext, usedStorageResource.graphServerTag);
161
+ if (!graphServiceTag) {
162
+ errorsFound.push(`storageResourceTag:${storageResourceTag} invalid, not found graph serviceTag from graphServerTag:${usedStorageResource.graphServerTag}`)
163
+ }
164
+
165
+ targetStorageResources.push({
166
+ ...usedStorageResource,
167
+ graphServiceTag: graphServiceTag
168
+ });
169
+ } else {
170
+ targetStorageResources.push(usedStorageResource);
171
+ }
172
+ }));
173
+ }
174
+ })
175
+ );
176
+
177
+ _izContext.logger.debug("targetStorageResources: ", targetStorageResources);
178
+
179
+ if (!targetStorageResources.length) {
180
+ errorsFound.push(`Not found link from relationship schema`);
181
+ }
182
+
183
+
184
+ // validate canUpdate properties relationship
185
+ for (const [propKey, propValue] of Object.entries(relationshipProperties)) {
186
+ _izContext.logger.debug("propKey: ", propKey);
187
+ _izContext.logger.debug("propValue: ", propValue);
188
+
189
+ if (relationshipSchema.properties[propKey]) {
190
+ if (relationshipSchema.properties[propKey].canUpdate !== true) {
191
+ errorsFound.push(`property:${propKey} cannot update`);
192
+ }
193
+ } else {
194
+ errorsFound.push(`property:${propKey} not exists in relationshipSchema`);
195
+ }
196
+ }
197
+
198
+ } else {
199
+ errorsFound.push(`relationshipSchema not exists`);
200
+ }
201
+
202
+
203
+ // if found errors will stop processing
204
+ if (errorsFound.length) {
205
+
206
+ let updateCompleteMsg = {
207
+ relId: relId,
208
+ relType: relType,
209
+ status: 'error',
210
+ errorFounds: errorsFound
211
+ //(<inUpdateCompleteMsg>)
212
+ //(</inUpdateCompleteMsg>)
213
+ };
214
+
215
+ // if have callingFlow will send to message complete
216
+ if (callingFlowConfig[callingFlowSharedLib.consts.CALLINGFLOW_PROPERTYNAME]) {
217
+ _izContext.logger.debug("HAVE CallingFlow");
218
+
219
+ updateCompleteMsg = callingFlowSharedLib.addPassBackPropertiesToSnsResponseMessageObject(callingFlowConfig, updateCompleteMsg);
220
+ let messageAttributes = callingFlowSharedLib.addCallingFlowToSnsResponseMessageAttributes(callingFlowConfig, {});
221
+
222
+ let messageParams = {
223
+ Message: JSON.stringify(updateCompleteMsg),
224
+ MessageAttributes: sns.createStringMessageAttributes(_izContext, messageAttributes),
225
+ TopicArn: await snsSharedLib.snsTopicArn(_izContext, TOPIC_NAME_GRAPH_HANDLER.outUpdateRelationshipComplete),
226
+ };
227
+
228
+ _izContext.logger.debug("messageParams OutUpdateRelationshipComplete ::::::: ", messageParams);
229
+ await sns.publishAsync(_izContext, messageParams);
230
+ }
231
+
232
+ return updateCompleteMsg;
233
+ }
234
+
235
+
236
+ // before create awaitingStepId per graph storageResource
237
+ const linkTypeId = createLinkTypeId(_izContext, [objects[0].objType, objects[1].objType], relType);
238
+
239
+ let usedGraphServiceTag = []; // collect used graph serviceName, use to check duplicate graph serviceName across graph serverTag
240
+ let targetGraphStorageResources = []; // collect used graph storageResources, filtered duplicate graphServiceTag from graphServerTag out
241
+ let awaitingStepIds = [];
242
+
243
+ for (const targetStorageResource of targetStorageResources) {
244
+ if (targetStorageResource.storageType === consts.STORAGE_TYPES.graph
245
+ && !usedGraphServiceTag.includes(targetStorageResource.graphServiceTag)
246
+ ) {
247
+ usedGraphServiceTag.push(targetStorageResource.graphServiceTag);
248
+ targetGraphStorageResources.push(targetStorageResource);
249
+
250
+ // awaitingStepId per graphServiceTag
251
+ awaitingStepIds.push(
252
+ asyncFlowSharedLib.createAwaitingStepId(
253
+ hash({ linkTypeId, relId, relationshipProperties, graphServiceTag: targetStorageResource.graphServiceTag }), // hash id
254
+ PREFIX.updateRel // prefix, use constant further
255
+ )
256
+ );
257
+ }
258
+ }
259
+
260
+ if (awaitingStepIds.length) {
261
+ // save awaiting
262
+ await asyncFlowSharedLib.createAwaitingMultipleSteps(
263
+ _izContext,
264
+ awaitingStepIds, // awaitingStepIds
265
+ asyncFlowSharedLib.createPendingStepId( // pendingStepId
266
+ hash({ linkTypeId, relId, relationshipProperties, correlationId: _izContext.correlationIds.get("id") }), // hash id
267
+ PREFIX.updateRel // prefix, use constant further
268
+ )
269
+ );
270
+
271
+ // prepare message body
272
+ let updateRelMessageBody = {
273
+ objects: objects,
274
+ relId,
275
+ relType: relType,
276
+ relationshipProperties
277
+ //(<inUpdateRelMessageBody>)
278
+ //(</inUpdateRelMessageBody>)
279
+ }
280
+ _izContext.logger.debug('updateRelMessageBody: ', updateRelMessageBody);
281
+
282
+ await Promise.all(
283
+ targetGraphStorageResources.map(async (storageResource) => {
284
+ if (storageResource.storageType === consts.STORAGE_TYPES.graph) {
285
+
286
+ updateRelMessageBody = callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
287
+ updateRelMessageBody,
288
+ callingFlowSharedLib.addParentCallingFlowConfig(
289
+ callingFlowConfig, // receive parent callingFlowConfig.
290
+ callingFlowSharedLib.createCallingFlowConfig( // callinfflow own service
291
+ await lambdaSharedLib.lambdaFunctionName(_izContext, TOPIC_NAME_GENERATE_CODE.updateRelComplete),
292
+ {
293
+ graphServiceTag: storageResource.graphServiceTag
294
+ }
295
+ )
296
+ )
297
+ );
298
+ _izContext.logger.debug("messageObject before send message:", updateRelMessageBody)
299
+
300
+ let messageToInUpdateRelationship = {
301
+ Message: JSON.stringify(updateRelMessageBody),
302
+ TopicArn: await snsSharedLib.snsTopicArn(_izContext, TOPIC_NAME_GRAPH_HANDLER.inUpdateRel, storageResource.graphServiceTag),
303
+ };
304
+ _izContext.logger.debug("RequestParams before send to sqs messageToInUpdateRelationship ::::::: ", messageToInUpdateRelationship);
305
+ await sns.publishAsync(_izContext, messageToInUpdateRelationship);
306
+ }
307
+ })
308
+ )
309
+
310
+ } else {
311
+ // if relationshipSchema stored in dynamoDB only will send message to outComplete
312
+ }
313
+
314
+ return {
315
+ relId: relId,
316
+ relType: relType,
317
+ errorFounds: errorsFound
318
+ };
319
+
320
+ } catch (err) {
321
+ _izContext.logger.error('error updateRelationship: ', err)
322
+ throw (err)
323
+ }
324
+ }
@@ -0,0 +1,72 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+ const path = require('path');
20
+ const fs = require('fs');
21
+
22
+ const { ACTIONS, HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
23
+
24
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, firstLetterUpperCase } = require("../../../../../../MainLibs/src/Utils")
25
+ const { DEFAULT_HANDLER_PER_ACTION, SOURCE_PATH } = require("../../../../libs/Consts");
26
+
27
+ const templatePath = path.join(__dirname, "./template.ejs")
28
+
29
+ /**
30
+ * receive objectSchema
31
+ * create data for hdrInv template
32
+ *
33
+ * @return {{ templatePath, templateData, setting } }
34
+ */
35
+ function data(_izContext, srcPath) {
36
+ const createSourceParams = createParamForCreateSource(srcPath)
37
+ return [createSourceParams];
38
+ }
39
+
40
+
41
+ function createParamForCreateSource(srcPath) {
42
+ let functionName = "updateRelationship";
43
+ return {
44
+ templatePath: templatePath,
45
+ templateData: {
46
+ functionName,
47
+ },
48
+ setting: {
49
+ savePath: path.join(srcPath, SOURCE_PATH.updateRelationshipSchema),
50
+ saveFileName: upperCase(functionName) + "_" + upperCase(HANDLER.hdrApi),
51
+ fileExtension: '.js',
52
+ isAppend: false
53
+ }
54
+ }
55
+ }
56
+
57
+
58
+ // [
59
+ // {
60
+ // templatePath: '/home/toughnut/BasProgram/empty-service-template/app/node_modules/@izara_project/izara-market-library-service-schemas/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.ejs',
61
+ // templateData: { tableName: 'ObjectTypeSingle', attributes: [Array] },
62
+ // setting: {
63
+ // savePath: '/generatedCode/source/',
64
+ // saveFileName: 'ObjectTypeGet',
65
+ // fileExtension: '.js',
66
+ // isAppend: false
67
+ // }
68
+ // }
69
+ // ]
70
+
71
+
72
+ module.exports = data;
@@ -0,0 +1,7 @@
1
+ {
2
+ "objectType": "objectType",
3
+ "action": "get",
4
+ "mainFunction": "xxx",
5
+ "mainFunctionFile": "directoryOfMainFunction",
6
+ "isCreateMainByDev": "boolean"
7
+ }
@@ -0,0 +1,120 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+ const izara = require("@izara_project/izara-middleware");
20
+ const middleware = izara.middlewareHandler;
21
+ const callingFlowSharedLib = require('@izara_project/izara-shared/src/CallingFlowSharedLib')
22
+ const {
23
+ validateSchemaMiddleware
24
+ } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/GenerateCodeLibs');
25
+
26
+ const <%- functionName %> = require('./<%- firstLetterUpperCase(functionName) %>_Main');
27
+ // validate event params in middleware before into function
28
+ let validatorSchema = {
29
+ type: "object",
30
+ required: ["objects", "relId", "relType", "relationshipProperties"],
31
+ properties: {
32
+ objects: {
33
+ type: "array",
34
+ minItems: 2,
35
+ maxItems: 2,
36
+ Items: {
37
+ type: "object",
38
+ required: ["objType", "identifiers"],
39
+ properties: {
40
+ objType: {
41
+ type: "object",
42
+ required: ["serviceTag", "objectType"],
43
+ properties: {
44
+ serviceTag: izara.validatorSchema.stringNotEmpty(),
45
+ objectType: izara.validatorSchema.stringNotEmpty()
46
+ }
47
+ },
48
+ identifiers: {
49
+ type: "object",
50
+ minproperties: 1
51
+ }
52
+ }
53
+ }
54
+ },
55
+ relType: {
56
+ type: "object",
57
+ required: ["relationshipTag", "serviceTag"],
58
+ properties: {
59
+ relationshipTag: izara.validatorSchema.stringNotEmpty(),
60
+ serviceTag: {
61
+ type: 'string',
62
+ pattern: "^[a-zA-Z0-9_-]+$",
63
+ enum: [process.env.iz_serviceTag]
64
+ }
65
+ }
66
+ },
67
+ relId: izara.validatorSchema.stringNotEmpty(),
68
+ relationshipProperties: {
69
+ type: "object",
70
+ minProperties: 1
71
+ }
72
+ }
73
+ };
74
+
75
+
76
+ //(<globalVarible>
77
+ //</globalVarible>)
78
+
79
+ // validate event params in middleware before into main function
80
+ validatorSchema = callingFlowSharedLib.addOptionalCallingFlowToValidatorSchema(validatorSchema);
81
+ middleware.setValidatorSchema(validatorSchema)
82
+ // if need to validate authorizer or additional params , add code to hook tag below
83
+
84
+ //(<afterValidateWith>)
85
+ //(</afterValidateWith>)
86
+
87
+
88
+ module.exports.main = middleware.wrap(async (event, context, callback) => {
89
+ event._izContext.logger.debug('Event:', event);
90
+ try {
91
+ // invoke LambdaFunction
92
+ let lambdaFunctionResponse = await <%- functionName %>.<%- functionName %>(
93
+ event._izContext, // correlationId/logger/integrationTestDetail/uniqueRequestId/userId
94
+ {
95
+ objects: event.objects,
96
+ relType: event.relType,
97
+ relId: event.relId,
98
+ relationshipProperties: event.relationshipProperties
99
+ }
100
+ );
101
+
102
+ // return error to client
103
+ if (lambdaFunctionResponse instanceof Error) {
104
+ return (izara.response.failure(lambdaFunctionResponse));
105
+ }
106
+
107
+ // return success to client
108
+ return (izara.response.success(lambdaFunctionResponse));
109
+
110
+ } catch (err) {
111
+ event._izContext.logger.error('Error, <%- functionName %>HdrApi: ', err);
112
+ return (izara.response.failure(err));
113
+ }
114
+ });
115
+ <%_ function firstLetterUpperCase(text) {
116
+ return text.charAt(0).toUpperCase() + text.slice(1)
117
+ } _%>
118
+ <%_ function firstLetterLowerCase(str) {
119
+ return str.charAt(0).toLowerCase() + str.slice(1)
120
+ } _%>
@@ -0,0 +1,73 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+ const path = require('path');
20
+ const fs = require('fs');
21
+
22
+ const { ACTIONS, HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
23
+
24
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, firstLetterUpperCase } = require("../../../../../../MainLibs/src/Utils")
25
+ const { DEFAULT_HANDLER_PER_ACTION, SOURCE_PATH } = require("../../../../libs/Consts");
26
+
27
+ const templatePath = path.join(__dirname, "./template.ejs")
28
+
29
+ /**
30
+ * receive objectSchema
31
+ * create data for hdrInv template
32
+ *
33
+ * @return {{ templatePath, templateData, setting } }
34
+ */
35
+ function data(_izContext, srcPath) {
36
+ const createSourceParams = createParamForCreateSource(srcPath)
37
+ return [createSourceParams];
38
+ }
39
+
40
+
41
+ function createParamForCreateSource(srcPath) {
42
+ let functionName = "updateRelationship";
43
+ return {
44
+ templatePath: templatePath,
45
+ templateData: {
46
+ functionName,
47
+ queueName: upperCase(functionName) + upperCase(HANDLER.hdrDsq)
48
+ },
49
+ setting: {
50
+ savePath: path.join(srcPath, SOURCE_PATH.updateRelationshipSchema),
51
+ saveFileName: upperCase(functionName) + "_" + upperCase(HANDLER.hdrDsq),
52
+ fileExtension: '.js',
53
+ isAppend: false
54
+ }
55
+ }
56
+ }
57
+
58
+
59
+ // [
60
+ // {
61
+ // templatePath: '/home/toughnut/BasProgram/empty-service-template/app/node_modules/@izara_project/izara-market-library-service-schemas/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.ejs',
62
+ // templateData: { tableName: 'ObjectTypeSingle', attributes: [Array] },
63
+ // setting: {
64
+ // savePath: '/generatedCode/source/',
65
+ // saveFileName: 'ObjectTypeGet',
66
+ // fileExtension: '.js',
67
+ // isAppend: false
68
+ // }
69
+ // }
70
+ // ]
71
+
72
+
73
+ module.exports = data;
@@ -0,0 +1,7 @@
1
+ {
2
+ "objectType": "objectType",
3
+ "action": "get",
4
+ "mainFunction": "xxx",
5
+ "mainFunctionFile": "directoryOfMainFunction",
6
+ "isCreateMainByDev": "boolean"
7
+ }