@izara_project/izara-market-library-service-schemas 1.0.3 → 1.0.5

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 (120) hide show
  1. package/package.json +5 -5
  2. package/src/GenerateCodeLibs/src/Consts.js +46 -0
  3. package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +69 -8
  4. package/src/TemplateManager/src/CreateRelationship/createRelationship/functionYaml/HdrApi/data.js +111 -0
  5. package/src/TemplateManager/src/CreateRelationship/createRelationship/functionYaml/HdrDsq/data.js +132 -0
  6. package/src/TemplateManager/src/CreateRelationship/createRelationship/functionYaml/HdrInv/data.js +110 -0
  7. package/src/TemplateManager/src/CreateRelationship/createRelationship/functionYaml/HdrSqs/data.js +132 -0
  8. package/src/TemplateManager/src/CreateRelationship/createRelationship/mainFunction/data.js +59 -0
  9. package/src/TemplateManager/src/CreateRelationship/createRelationship/mainFunction/template.ejs +338 -0
  10. package/src/TemplateManager/src/CreateRelationship/createRelationship/perAction/HdrApi/data.js +58 -0
  11. package/src/TemplateManager/src/CreateRelationship/createRelationship/perAction/HdrApi/request.json +0 -0
  12. package/src/TemplateManager/src/CreateRelationship/createRelationship/perAction/HdrApi/template.ejs +120 -0
  13. package/src/TemplateManager/src/CreateRelationship/createRelationship/perAction/HdrDsq/data.js +60 -0
  14. package/src/TemplateManager/src/CreateRelationship/createRelationship/perAction/HdrDsq/request.json +0 -0
  15. package/src/TemplateManager/src/CreateRelationship/createRelationship/perAction/HdrDsq/template.ejs +167 -0
  16. package/src/TemplateManager/src/CreateRelationship/createRelationship/perAction/HdrInv/data.js +60 -0
  17. package/src/TemplateManager/src/CreateRelationship/createRelationship/perAction/HdrInv/request.json +0 -0
  18. package/src/TemplateManager/src/CreateRelationship/createRelationship/perAction/HdrInv/template.ejs +107 -0
  19. package/src/TemplateManager/src/CreateRelationship/createRelationship/perAction/HdrSqs/data.js +60 -0
  20. package/src/TemplateManager/src/CreateRelationship/createRelationship/perAction/HdrSqs/request.json +0 -0
  21. package/src/TemplateManager/src/CreateRelationship/createRelationship/perAction/HdrSqs/template.ejs +146 -0
  22. package/src/TemplateManager/src/CreateRelationship/createRelationship/perAction/request.json +30 -0
  23. package/src/TemplateManager/src/CreateRelationship/createRelationship/sns-in-sqs/data.js +80 -0
  24. package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/functionYaml/data.js +133 -0
  25. package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/functionYaml/request.json +0 -0
  26. package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/functionYaml/template.ejs +33 -0
  27. package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/handler/HdrSqs/data.js +62 -0
  28. package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/handler/HdrSqs/request.json +0 -0
  29. package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/handler/HdrSqs/template.ejs +125 -0
  30. package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/mainFunction/data.js +56 -0
  31. package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/mainFunction/request.json +0 -0
  32. package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/mainFunction/template.ejs +137 -0
  33. package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/sns-in-sqs/data.js +72 -0
  34. package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/sns-in-sqs/request.json +0 -0
  35. package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/sns-in-sqs/template.ejs +47 -0
  36. package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/sns-out/data.js +72 -0
  37. package/src/TemplateManager/src/CreateRelationship/createRelationshipComplete/sns-out/request.json +0 -0
  38. package/src/TemplateManager/src/GenerateCode.js +176 -43
  39. package/src/TemplateManager/src/{FunctionYaml → PerActionEndpoint/FunctionYaml}/HdrApi/data.js +7 -23
  40. package/src/TemplateManager/src/{FunctionYaml → PerActionEndpoint/FunctionYaml}/HdrDsq/data.js +10 -24
  41. package/src/TemplateManager/src/{FunctionYaml → PerActionEndpoint/FunctionYaml}/HdrInv/data.js +6 -23
  42. package/src/TemplateManager/src/{FunctionYaml → PerActionEndpoint/FunctionYaml}/HdrSqs/data.js +14 -33
  43. package/src/TemplateManager/src/{FunctionYaml → PerActionEndpoint/FunctionYaml}/HdrSqs/template.ejs +2 -2
  44. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrApi/data.js +2 -16
  45. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrDsq/data.js +3 -17
  46. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrInv/data.js +3 -16
  47. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrSqs/data.js +4 -17
  48. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/data.js +0 -15
  49. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/template.ejs +28 -30
  50. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/testParam.json +5 -0
  51. package/src/TemplateManager/src/ResourceYaml/dynamodb/awaitingMultipleStepData.js +95 -0
  52. package/src/TemplateManager/src/ResourceYaml/dynamodb/mainResourcePerObjectSchemaData.js +7 -29
  53. package/src/TemplateManager/src/ResourceYaml/dynamodb/processLogicalAndFindData.js +5 -8
  54. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/defaultSnsInSqsForFindDataAndProcessLogical.js +3 -6
  55. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/snsAndSqsPerActiondata.js +6 -6
  56. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/sqsTemplate.ejs +1 -0
  57. package/src/TemplateManager/src/ResourceYaml/sns-out/data.js +89 -0
  58. package/src/TemplateManager/src/ResourceYaml/sns-out/request.json +3 -0
  59. package/src/TemplateManager/src/ResourceYaml/sns-out/template.ejs +10 -0
  60. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/functionYaml/data.js +135 -0
  61. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/functionYaml/request.json +3 -0
  62. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/functionYaml/template.ejs +33 -0
  63. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/handler/HdrSqs/data.js +62 -0
  64. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/handler/HdrSqs/request.json +0 -0
  65. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/handler/HdrSqs/template.ejs +127 -0
  66. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/mainFunction/data.js +56 -0
  67. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/mainFunction/request.json +1 -0
  68. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/mainFunction/template.ejs +140 -0
  69. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-in-sqs/data.js +72 -0
  70. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-in-sqs/request.json +3 -0
  71. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-in-sqs/template.ejs +46 -0
  72. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-out/data.js +71 -0
  73. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-out/request.json +3 -0
  74. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrApi/data.js +112 -0
  75. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrApi/request.json +0 -0
  76. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrApi/template.ejs +33 -0
  77. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrDsq/data.js +128 -0
  78. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrDsq/request.json +0 -0
  79. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrInv/data.js +110 -0
  80. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrInv/request.json +0 -0
  81. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrSqs/data.js +131 -0
  82. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrSqs/request.json +0 -0
  83. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/mainFunction/data.js +65 -0
  84. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/mainFunction/request.json +1 -0
  85. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/mainFunction/template.ejs +331 -0
  86. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrApi/data.js +59 -0
  87. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrApi/request.json +7 -0
  88. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrApi/template.ejs +120 -0
  89. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrDsq/data.js +59 -0
  90. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrDsq/request.json +7 -0
  91. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrDsq/template.ejs +167 -0
  92. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrInv/data.js +62 -0
  93. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrInv/request.json +5 -0
  94. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrInv/template.ejs +126 -0
  95. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrSqs/data.js +59 -0
  96. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrSqs/request.json +7 -0
  97. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrSqs/template.ejs +146 -0
  98. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/request.json +30 -0
  99. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/sns-in-sqs/data.js +90 -0
  100. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/sns-in-sqs/request.json +3 -0
  101. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/sns-out/data.js +70 -0
  102. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/sns-out/request.json +3 -0
  103. package/src/TemplateManager/src/externalService/LambdaRole/data.js +72 -25
  104. package/src/TemplateManager/src/externalService/LambdaRole/template.ejs +8 -3
  105. package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/data.js +51 -3
  106. package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/request.json +12 -0
  107. package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/template.ejs +10 -14
  108. package/src/TemplateManager/src/libs/Consts.js +52 -23
  109. package/src/TemplateManager/src/MainResourcesYaml/CreateSourceData.js +0 -76
  110. package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Data/MainDynamoDbYamlData.js +0 -155
  111. package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.ejs +0 -31
  112. package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.exampleData.js +0 -12
  113. /package/src/TemplateManager/src/{FunctionYaml → PerActionEndpoint/FunctionYaml}/HdrApi/request.json +0 -0
  114. /package/src/TemplateManager/src/{FunctionYaml → PerActionEndpoint/FunctionYaml}/HdrApi/template.ejs +0 -0
  115. /package/src/TemplateManager/src/{FunctionYaml → PerActionEndpoint/FunctionYaml}/HdrDsq/request.json +0 -0
  116. /package/src/TemplateManager/src/{FunctionYaml → PerActionEndpoint/FunctionYaml}/HdrDsq/template.ejs +0 -0
  117. /package/src/TemplateManager/src/{FunctionYaml → PerActionEndpoint/FunctionYaml}/HdrInv/example req.js +0 -0
  118. /package/src/TemplateManager/src/{FunctionYaml → PerActionEndpoint/FunctionYaml}/HdrInv/request.json +0 -0
  119. /package/src/TemplateManager/src/{FunctionYaml → PerActionEndpoint/FunctionYaml}/HdrInv/template.ejs +0 -0
  120. /package/src/TemplateManager/src/{FunctionYaml → PerActionEndpoint/FunctionYaml}/HdrSqs/request.json +0 -0
@@ -0,0 +1,59 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+ const path = require('path');
20
+ const fs = require('fs');
21
+
22
+ const { ACTIONS, HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
23
+ const { createGetDataDetails } = require('../../../../../GenerateCodeLibs/src/GenerateCodeLibs')
24
+
25
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, firstLetterUpperCase } = require("../../../../../MainLibs/src/Utils")
26
+ const { DEFAULT_HANDLER_PER_ACTION, SOURCE_PATH } = require("../../../libs/Consts");
27
+
28
+
29
+ const templatePath = path.join(__dirname, "./template.ejs")
30
+
31
+ /**
32
+ * receive objectSchema
33
+ * create data for hdrInv template
34
+ *
35
+ * @param {Object} objectSchema
36
+ * @return {{ templatePath, templateData, setting } }
37
+ */
38
+ function data(_izContext, srcPath) {
39
+ const createSourceParams = createParamForCreateSource(srcPath)
40
+ return [createSourceParams];
41
+ }
42
+
43
+
44
+ function createParamForCreateSource(srcPath) {
45
+ return {
46
+ templatePath: templatePath,
47
+ templateData: {
48
+ },
49
+ setting: {
50
+ savePath: path.join(srcPath, SOURCE_PATH.relationshipPerAction),
51
+ saveFileName: `CreateRelationship_Main`,
52
+ fileExtension: '.js',
53
+ isAppend: false
54
+ }
55
+ }
56
+ }
57
+
58
+
59
+ module.exports = data;
@@ -0,0 +1,338 @@
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
+
33
+
34
+
35
+ const {
36
+ getRelationshipSchemaWithCache,
37
+ getObjSchemaS3WithHierarchy
38
+ } = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema');
39
+
40
+ const {
41
+ createLinkTypeId
42
+ } = require('@izara_project/izara-core-library-service-schemas/src/Utils');
43
+
44
+ const {
45
+ getGraphServiceTagWithCache
46
+ } = require('@izara_project/izara-core-library-service-schemas/src/ServiceConfig');
47
+
48
+ const consts = require('@izara_project/izara-core-library-service-schemas/src/Consts');
49
+ const {
50
+ PREFIX, TOPIC_NAME_GENERATE_CODE, TOPIC_NAME_GRAPH_HANDLER
51
+ } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/Consts')
52
+
53
+ /**
54
+ * update relationship endpoint
55
+ *
56
+ * @param {Object} _izContext
57
+ * @param {CorrelationIds} _izContext.correlationIds - property of _izContext
58
+ * @param {Logger} _izContext.logger - property of _izContext
59
+ * @param {Object} requestParams - request params
60
+ * @param {Object} callingFlowConfig
61
+ *
62
+ * @returns {object} description of return value
63
+ */
64
+ module.exports.createRelationship = async (
65
+ _izContext,
66
+ requestParams,
67
+ callingFlowConfig = {},
68
+ //(<additionalParams>)
69
+ //(</additionalParams>)
70
+ ) => {
71
+
72
+
73
+ try {
74
+ _izContext.logger.debug('createRelationship _izContext: ', _izContext);
75
+ _izContext.logger.debug('createRelationship requestParams: ', requestParams);
76
+ _izContext.logger.debug('createRelationship callingFlowConfig: ', callingFlowConfig);
77
+
78
+
79
+ const {
80
+ objects,
81
+ relType,
82
+ relationshipProperties
83
+ //(<requestparamCreateRel>)
84
+ //(</requestparamCreateRel>)
85
+ } = requestParams;
86
+
87
+ let errorsFound = [];
88
+
89
+ //(<beforeValidateCreateRel>)
90
+ //(</beforeValidateCreateRel>)
91
+ // validate object and identifiers
92
+ async function validateIdentifiersExists(_izContext, objType, identifiersObject) {
93
+
94
+ const objTypeString = `objType:{ serviceTag:${objType.serviceTag}, objectType:${objType.objectType} }`;
95
+ const objectSchema = await getObjSchemaS3WithHierarchy(_izContext, objType);
96
+
97
+ if (!objectSchema) {
98
+ errorsFound.push(`validateIdentifiers, not found schema of ${objTypeString}`);
99
+ }
100
+
101
+ for (const schemaIdentifier of objectSchema.identifiers) {
102
+ let identifierName = schemaIdentifier.fieldName || schemaIdentifier.name;
103
+
104
+ if (!identifiersObject.hasOwnProperty(identifierName)) {
105
+ errorsFound.push(`validateIdentifiers, ${objTypeString} property:${identifierName} not exists`);
106
+ } else {
107
+ if (
108
+ typeof (identifiersObject[identifierName]) !== "string"
109
+ && typeof (identifiersObject[identifierName]) !== "number"
110
+ ) {
111
+ errorsFound.push(`validateIdentifiers, ${objTypeString} property:${identifierName} should be string or number`);
112
+ }
113
+ }
114
+ }
115
+ }
116
+
117
+ await validateIdentifiersExists(_izContext, objects[0].objType, objects[0].identifiers);
118
+ await validateIdentifiersExists(_izContext, objects[1].objType, objects[1].identifiers);
119
+ // finished validate object and identifiers
120
+
121
+ //(<afterValidateCreateRel>)
122
+ //(</afterValidateCreateRel>)
123
+
124
+ //(<beforeGetRelCreateRel>)
125
+ //(</beforeGetRelCreateRel>)
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
+ //(<afterGetRelCreateRel>)
177
+ //(</afterGetRelCreateRel>)
178
+ _izContext.logger.debug("targetStorageResources: ", targetStorageResources);
179
+
180
+ if (!targetStorageResources.length) {
181
+ errorsFound.push(`Not found link from relationship schema`);
182
+ }
183
+
184
+
185
+ // validate properties exists with schema
186
+ for (const propKey in relationshipProperties) {
187
+ if (!relationshipSchema.properties.hasOwnProperty(propKey)) {
188
+ errorsFound.push(`property:${propKey} not exists in relationshipSchema`);
189
+ }
190
+ }
191
+
192
+ // validate canCreate properties relationship
193
+ for (const [propName, propSetting] of Object.entries(relationshipSchema.properties)) {
194
+ if (propSetting.requiredOnCreate === true) {
195
+ if (!relationshipProperties.hasOwnProperty(propName)) {
196
+ errorsFound.push(`Missing requiredOnCreate property:${propKey}`);
197
+ }
198
+ }
199
+
200
+ if (!propSetting.optionalOnCreate && !propSetting.requiredOnCreate && relationshipProperties.hasOwnProperty(propName)) {
201
+ errorsFound.push(`property:${propName} cannot create`);
202
+ }
203
+ }
204
+
205
+ } else {
206
+ errorsFound.push(`relationshipSchema not exists`);
207
+ }
208
+
209
+
210
+ // if found errors will stop processing
211
+ if (errorsFound.length) {
212
+
213
+ let createRelCompleteMsg = {
214
+ objects: objects,
215
+ relType: relType,
216
+ relationshipProperties: relationshipProperties,
217
+ //(<inCreateRelCompleteMsgCrateRel>)
218
+ //(</inCreateRelCompleteMsgCrateRel>)
219
+ status: 'error',
220
+ errorFounds: errorsFound
221
+ };
222
+
223
+ // if have callingFlow will send to message complete
224
+ if (callingFlowConfig[callingFlowSharedLib.consts.CALLINGFLOW_PROPERTYNAME]) {
225
+ _izContext.logger.debug("HAVE CallingFlow");
226
+
227
+ createRelCompleteMsg = callingFlowSharedLib.addPassBackPropertiesToSnsResponseMessageObject(callingFlowConfig, createRelCompleteMsg);
228
+ let messageAttributes = callingFlowSharedLib.addCallingFlowToSnsResponseMessageAttributes(callingFlowConfig, {});
229
+
230
+ let messageParams = {
231
+ Message: JSON.stringify(createRelCompleteMsg),
232
+ MessageAttributes: sns.createStringMessageAttributes(_izContext, messageAttributes),
233
+ TopicArn: await snsSharedLib.snsTopicArn(_izContext, TOPIC_NAME_GENERATE_CODE.outCreateRelComplete),
234
+ };
235
+
236
+ _izContext.logger.debug("messageParams OutCreateRelationshipComplete ::::::: ", messageParams);
237
+ await sns.publishAsync(_izContext, messageParams);
238
+ }
239
+
240
+ return createRelCompleteMsg;
241
+ }
242
+
243
+
244
+ // before create awaitingStepId per graph storageResource
245
+ const linkTypeId = createLinkTypeId(_izContext, [objects[0].objType, objects[1].objType], relType);
246
+
247
+ let usedGraphServiceTag = []; // collect used graph serviceTag, use to check duplicate graph serviceTag across graph serverTag
248
+ let targetGraphStorageResources = []; // collect used graph storageResources, filtered duplicate graphServiceTag from graphServerTag out
249
+ let awaitingStepIds = [];
250
+
251
+ for (const targetStorageResource of targetStorageResources) {
252
+ if (targetStorageResource.storageType === consts.STORAGE_TYPES.graph
253
+ && !usedGraphServiceTag.includes(targetStorageResource.graphServiceTag)
254
+ ) {
255
+ usedGraphServiceTag.push(targetStorageResource.graphServiceTag);
256
+ targetGraphStorageResources.push(targetStorageResource);
257
+
258
+ // awaitingStepId per graphServiceTag
259
+ awaitingStepIds.push(
260
+ asyncFlowSharedLib.createAwaitingStepId(
261
+ hash({ linkTypeId, relationshipProperties, graphServiceTag: targetStorageResource.graphServiceTag }), // hash id
262
+ PREFIX.createRel // prefix, use constant further
263
+ )
264
+ );
265
+ }
266
+ }
267
+
268
+ /*
269
+ if have storageResource.storageType === "dynamoDB" will create relationship here
270
+ */
271
+
272
+
273
+ if (awaitingStepIds.length) {
274
+ // save awaiting
275
+ await asyncFlowSharedLib.createAwaitingMultipleSteps(
276
+ _izContext,
277
+ awaitingStepIds, // awaitingStepIds
278
+ asyncFlowSharedLib.createPendingStepId( // pendingStepId
279
+ hash({ linkTypeId, relationshipProperties, correlationId: _izContext.correlationIds.get("id") }), // hash id
280
+ PREFIX.createRel // prefix, use constant further
281
+ )
282
+ );
283
+
284
+ // prepare message body
285
+ let updateRelMessageBody = {
286
+ objects: objects,
287
+ relType: relType,
288
+ relationshipProperties
289
+ //(<inUpdateRelMessageBodyCreateRel>)
290
+ //(</inUpdateRelMessageBodyCreateRel>)
291
+ }
292
+ _izContext.logger.debug('createRelMessageBody: ', updateRelMessageBody);
293
+
294
+ await Promise.all(
295
+ targetGraphStorageResources.map(async (storageResource) => {
296
+ if (storageResource.storageType === consts.STORAGE_TYPES.graph) {
297
+
298
+ updateRelMessageBody = callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
299
+ updateRelMessageBody,
300
+ callingFlowSharedLib.addParentCallingFlowConfig(
301
+ callingFlowConfig, // receive parent callingFlowConfig.
302
+ callingFlowSharedLib.createCallingFlowConfig( // callinfflow own service
303
+ await lambdaSharedLib.lambdaFunctionName(_izContext, TOPIC_NAME_GENERATE_CODE.createRelComplete),
304
+ {
305
+ graphServiceTag: storageResource.graphServiceTag
306
+ }
307
+ )
308
+ )
309
+ );
310
+ _izContext.logger.debug("messageObject before send message:", updateRelMessageBody)
311
+
312
+ let messageToInUpdateRelationship = {
313
+ Message: JSON.stringify(updateRelMessageBody),
314
+ TopicArn: await snsSharedLib.snsTopicArn(_izContext, TOPIC_NAME_GRAPH_HANDLER.inCreateRel, storageResource.graphServiceTag),
315
+ };
316
+ _izContext.logger.debug("RequestParams before send to sqs messageToInUpdateRelationship ::::::: ", messageToInUpdateRelationship);
317
+ await sns.publishAsync(_izContext, messageToInUpdateRelationship);
318
+ }
319
+ })
320
+ )
321
+
322
+ } else {
323
+ // if relationshipSchema stored in dynamoDB only will send message to outComplete
324
+ }
325
+
326
+ return {
327
+ objects,
328
+ relType,
329
+ relationshipProperties,
330
+ errorFounds: errorsFound
331
+ };
332
+
333
+
334
+ } catch (err) {
335
+ _izContext.logger.error('error updateRelationship: ', err)
336
+ throw (err)
337
+ }
338
+ }
@@ -0,0 +1,58 @@
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 = "createRelationship";
43
+ return {
44
+ templatePath: templatePath,
45
+ templateData: {
46
+ functionName,
47
+ },
48
+ setting: {
49
+ savePath: path.join(srcPath, SOURCE_PATH.relationshipPerAction),
50
+ saveFileName: upperCase(functionName) + "_" + upperCase(HANDLER.hdrApi),
51
+ fileExtension: '.js',
52
+ isAppend: false
53
+ }
54
+ }
55
+ }
56
+
57
+
58
+ module.exports = data;
@@ -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,60 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+ const path = require('path');
20
+ const fs = require('fs');
21
+
22
+ const { ACTIONS, HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
23
+
24
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, firstLetterUpperCase } = require("../../../../../../MainLibs/src/Utils")
25
+ const { DEFAULT_HANDLER_PER_ACTION, SOURCE_PATH, FUNCTION_NAME } = require("../../../../libs/Consts");
26
+
27
+ const templatePath = path.join(__dirname, "./template.ejs")
28
+
29
+ /**
30
+ * receive objectSchema
31
+ * create data for hdrInv template
32
+ *
33
+ * @return {{ templatePath, templateData, setting } }
34
+ */
35
+ function data(_izContext, srcPath) {
36
+ const createSourceParams = createParamForCreateSource(srcPath)
37
+ return [createSourceParams];
38
+ }
39
+
40
+
41
+ function createParamForCreateSource(srcPath) {
42
+ let functionName = FUNCTION_NAME.createRel
43
+ let queueName = functionName + upperCase(HANDLER.hdrDsq)
44
+ return {
45
+ templatePath: templatePath,
46
+ templateData: {
47
+ functionName,
48
+ queueName
49
+ },
50
+ setting: {
51
+ savePath: path.join(srcPath, SOURCE_PATH.relationshipPerAction),
52
+ saveFileName: upperCase(functionName) + "_" + upperCase(HANDLER.hdrDsq),
53
+ fileExtension: '.js',
54
+ isAppend: false
55
+ }
56
+ }
57
+ }
58
+
59
+
60
+ module.exports = data;