@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,219 @@
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
16
+ <http: //www.gnu.org/licenses />.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ const {
22
+ getObjSchemaS3WithHierarchy,
23
+ } = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema');
24
+
25
+ const {
26
+ getGraphServiceTagWithCache,
27
+ getServiceNameWithCache
28
+ } = require('@izara_project/izara-core-library-service-schemas/src/ServiceConfig');
29
+
30
+ const consts = require('@izara_project/izara-core-library-service-schemas/src/Consts');
31
+
32
+
33
+ const {
34
+ dynamoDbIdentifiersByStorageResource,
35
+ collectGetData
36
+ } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/GenerateCodeLibs');
37
+
38
+
39
+ const dynamodbSharedLib = require('@izara_project/izara-shared/src/DynamodbSharedLib');
40
+ const graphSharedLib = require('@izara_project/izara-shared/src/GraphSharedLib');
41
+
42
+
43
+ const NoRetryError = require('@izara_project/izara-core-library-core/src/NoRetryError');
44
+
45
+
46
+ /**
47
+ *
48
+ *
49
+ * description of function.
50
+ * @param {Object} _izContext
51
+ * @param {CorrelationIds} _izContext.correlationIds - property of _izContext
52
+ * @param {Logger} _izContext.logger - property of _izContext
53
+ * @param {Object} requestParams - request params
54
+ * @param {Object} requestParams.identifiers - identifiers for get data
55
+ * @param {Object} requestParams.additionalRequest - additionalRequest
56
+ *
57
+ *
58
+ * @returns {object} description of return value
59
+ */
60
+ module.exports.<%- functionName %>Main = async (
61
+ _izContext,
62
+ requestParams,
63
+ callingFlowConfig = {},
64
+ //(<additionalParams>)
65
+ //(</additionalParams>)
66
+ ) => {
67
+
68
+
69
+ try {
70
+ _izContext.logger.debug('<%- functionName %> _izContext: ', _izContext);
71
+ _izContext.logger.debug('<%- functionName %> requestParams: ', requestParams);
72
+ _izContext.logger.debug('<%- functionName %> callingFlowConfig: ', callingFlowConfig);
73
+
74
+
75
+ const OBJECT_TYPE = "<%- objectType %>";
76
+ const SERVICE_TAG = process.env.iz_serviceTag;
77
+
78
+ let getDataDetails = <%- getDataDetail %>
79
+ //(<beforeQuery>)
80
+ //(</beforeQuery>)
81
+
82
+ let objectSchema = await getObjSchemaS3WithHierarchy(
83
+ _izContext,
84
+ {
85
+ objectType: OBJECT_TYPE,
86
+ serviceTag: SERVICE_TAG
87
+ }
88
+ );
89
+
90
+ _izContext.logger.debug("objectSchema: ", objectSchema);
91
+
92
+
93
+ // start to get data
94
+ let getResults = {}; // for collect result data from
95
+ let getRecordStatus = {
96
+ getAtLeastOneRecord: false,
97
+ notFoundSomeRecord: false
98
+ };
99
+
100
+ await Promise.all(
101
+ Object.entries(getDataDetails).map(
102
+ async ([storageTag, getDataDetail]) => {
103
+ if (getDataDetail.storageType === consts.STORAGE_TYPES.graph) {
104
+ // get data from graph
105
+ let graphServiceName = await getServiceNameWithCache(_izContext, getDataDetail.graphServiceTag);
106
+
107
+
108
+ let versionedDataLabels = [];
109
+ if (getDataDetail.versionedDatas && Object.keys(getDataDetail.versionedDatas).length) {
110
+ // have versionedData
111
+ versionedDataLabels = Object.keys(getDataDetail.versionedDatas);
112
+ }
113
+
114
+
115
+ //(<beforeGetGraph>)
116
+ //(</beforeGetGraph>)
117
+
118
+ let dataFromGraph = await graphSharedLib.getNode(
119
+ _izContext,
120
+ graphServiceName,
121
+ {
122
+ nodeLabel: OBJECT_TYPE,
123
+ nodeProperties: {
124
+ ...requestParams.identifiers
125
+ },
126
+ },
127
+ versionedDataLabels
128
+ );
129
+
130
+ _izContext.logger.debug("dataFromGraph: ", dataFromGraph);
131
+
132
+ if (Object.keys(dataFromGraph).length) {
133
+ getRecordStatus.getAtLeastOneRecord = true;
134
+ } else {
135
+ getRecordStatus.notFoundSomeRecord = true;
136
+ }
137
+
138
+ //(<afterGetGraph>)
139
+ //(</afterGetGraph>)
140
+
141
+
142
+ // collect return data depend on getDataDetail
143
+ Object.assign(
144
+ getResults,
145
+ collectGetData(_izContext, dataFromGraph, getDataDetail)
146
+ );
147
+
148
+
149
+ } else {
150
+
151
+ let identifiersForGetData = await dynamoDbIdentifiersByStorageResource(
152
+ _izContext,
153
+ objectSchema,
154
+ getDataDetail,
155
+ requestParams.identifiers
156
+ );
157
+
158
+ _izContext.logger.debug("identifiersForGetData: ", identifiersForGetData);
159
+
160
+
161
+ //(<beforeGetDynamoDb>)
162
+ //(</beforeGetDynamoDb>)
163
+
164
+ let dataFromDynamoDb = await dynamodbSharedLib.getItem(
165
+ _izContext,
166
+ await dynamodbSharedLib.tableName(_izContext, getDataDetail.tableName),
167
+ identifiersForGetData
168
+ );
169
+
170
+ _izContext.logger.debug("dataFromDynamoDb: ", dataFromDynamoDb);
171
+
172
+
173
+ if (dataFromDynamoDb) {
174
+ getRecordStatus.getAtLeastOneRecord = true;
175
+ } else {
176
+ getRecordStatus.notFoundSomeRecord = true;
177
+ }
178
+
179
+ //(<afterGetDynamoDb>)
180
+ //(</afterGetDynamoDb>)
181
+
182
+ // collect return data depend on getDataDetail
183
+ Object.assign(
184
+ getResults,
185
+ collectGetData(_izContext, dataFromDynamoDb, getDataDetail)
186
+ );
187
+
188
+ }
189
+ })
190
+ );
191
+
192
+ _izContext.logger.debug("getRecordStatus: ", getRecordStatus);
193
+
194
+ if (getRecordStatus.getAtLeastOneRecord === true && getRecordStatus.notFoundSomeRecord === true) {
195
+ throw Error("Not found some record while get data");
196
+ }
197
+
198
+ if (Object.keys(getResults).length) {
199
+ return getResults;
200
+ } else {
201
+ return null
202
+ }
203
+
204
+ } catch (err) {
205
+ _izContext.logger.error('error <%- firstLetterUpperCase(functionName) %>Main: ', err)
206
+ throw (err)
207
+ }
208
+ }
209
+
210
+ <%_ function firstLetterUpperCase(text){ return text.charAt(0).toUpperCase() + text.slice(1) } _%>
211
+ <%_ function firstLetterLowerCase(str) { return str.charAt(0).toLowerCase() + str.slice(1) } _%>
212
+
213
+ // request input
214
+
215
+ // {
216
+ // "identifiers": {
217
+ // "personId" : "basTest"
218
+ // }
219
+ // }
@@ -0,0 +1,98 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+
20
+ const path = require("path")
21
+
22
+
23
+ // const {
24
+ // HANDLER,
25
+ // STORAGE_TYPES
26
+ // } = require('@izara_project/izara-core-library-service-schemas/src/Consts');
27
+
28
+ const STORAGE_TYPES = {
29
+ dynamoDB: "dynamoDB",
30
+ graph: "graph"
31
+ }
32
+ const templatePath = path.join(__dirname, './template.ejs')
33
+ const { SOURCE_PATH } = require('../../libs/Consts');
34
+
35
+ /**
36
+ * create param of crateSouce for FindData And processLogical
37
+ *
38
+ * @param {Object} _izContext
39
+ * @param {String} srcPath
40
+ * @returns {Object[]}
41
+ */
42
+ module.exports.createAwaitingMultipleStepDynamoDbData = (_izContext, srcPath) => {
43
+
44
+ let resultsForCreateSource = [];
45
+
46
+ const awaitingStepDynamoDbDataList = [
47
+ {
48
+ "tableName": "AwaitingMultipleSteps",
49
+ "attributes": [
50
+ {
51
+ "keyType": "partitionKey",
52
+ "AttributeName": "awaitingStepId",
53
+ "AttributeType": "S"
54
+ },
55
+ {
56
+ "keyType": "sortKey",
57
+ "AttributeName": "pendingStepId",
58
+ "AttributeType": "S"
59
+ }
60
+ ]
61
+ },
62
+ {
63
+ "tableName": "AwaitingMultipleStepByPending",
64
+ "attributes": [
65
+ {
66
+ "keyType": "partitionKey",
67
+ "AttributeName": "pendingStepId",
68
+ "AttributeType": "S"
69
+ },
70
+ {
71
+ "keyType": "sortKey",
72
+ "AttributeName": "awaitingStepId",
73
+ "AttributeType": "S"
74
+ }
75
+ ]
76
+ }
77
+ ];
78
+
79
+ // console.log("defaultlDynamoDataList: ", (awaitingStepDynamoDbDataList));
80
+
81
+ for (let defaultlDynamoData of awaitingStepDynamoDbDataList) {
82
+ resultsForCreateSource.push({
83
+ templatePath: templatePath,
84
+ templateData: defaultlDynamoData,
85
+ setting: {
86
+ initialData: 'Resources:\n',
87
+ savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
88
+ saveFileName: 'generated-dynamoDB-table',
89
+ fileExtension: '.yml',
90
+ isAppend: true
91
+ }
92
+ });
93
+ }
94
+
95
+ // console.log("resultForCreateDefaultDynamoDb: ", (resultsForCreateSource));
96
+
97
+ return resultsForCreateSource;
98
+ }
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
19
19
 
20
20
  const path = require("path")
21
21
 
22
+
22
23
  // const {
23
24
  // HANDLER,
24
25
  // STORAGE_TYPES
@@ -30,6 +31,8 @@ const STORAGE_TYPES = {
30
31
  graph: "graph"
31
32
  }
32
33
 
34
+ const { SOURCE_PATH } = require('../../libs/Consts')
35
+ const templatePath = path.join(__dirname, './template.ejs')
33
36
 
34
37
  // ---------- End Per Lambda Handler IamRole Data ----------
35
38
 
@@ -44,20 +47,20 @@ const STORAGE_TYPES = {
44
47
  * @param {Object} objectSchema
45
48
  * @returns {Object[]} - data of multiple dynamoDb template
46
49
  */
47
- function dataForMainDynamoDbYamlFromObjectSchema(_izContext, objectSchema) {
48
- let dynamoDbYamlTemplateData = [];
49
50
 
50
- // store detail for create dynamoDb table
51
- let identifiersDetail = {};
51
+ function dataForMainDynamoDbYamlFromObjectSchema(_izContext, objectSchema, srcPath) {
52
+ let dynamoDbYamlTempleteData = [];
53
+
54
+ let identifierDetail = {};
52
55
 
53
- // add identifiersDetail for dynamoDb storage
54
- for (let identifier of objectSchema.identifiers) {
55
- if (identifier.type === "partitionKey" || identifier.type === "sortKey") {
56
- identifiersDetail[identifier.type] = {};
56
+ for (let identifier of objectSchema.identifiers) { //check identifiers from objectSchema
57
+ // console.log("identifier");
58
+ if (identifier.type === "partitionKey" || identifier.type === 'sortKey') {
59
+ identifierDetail[identifier.type] = {};
57
60
 
58
61
  if (identifier.name) {
59
62
  Object.assign(
60
- identifiersDetail[identifier.type],
63
+ identifierDetail[identifier.type],
61
64
  {
62
65
  AttributeName: identifier.name,
63
66
  AttributeType: "S"
@@ -66,38 +69,33 @@ function dataForMainDynamoDbYamlFromObjectSchema(_izContext, objectSchema) {
66
69
  } else {
67
70
  let fieldNameType = objectSchema.fieldNames[identifier.fieldName].type;
68
71
  let attributeType;
69
-
70
- if (fieldNameType === "string") {
72
+ if (fieldNameType === 'string') {
71
73
  attributeType = "S"
72
- } else if (fieldNameType === "number") {
74
+ } else if (fieldNameType === 'number') {
73
75
  attributeType = "N"
74
76
  }
75
-
76
77
  Object.assign(
77
- identifiersDetail[identifier.type],
78
+ identifierDetail[identifier.type],
78
79
  {
79
80
  AttributeName: identifier.fieldName,
80
81
  AttributeType: attributeType
81
82
  }
82
- );
83
+ )
83
84
  }
84
85
  }
85
86
  }
86
87
 
87
- if (!identifiersDetail.hasOwnProperty("partitionKey")) {
88
- return [];
88
+ // console.log("identifierDetail :", identifierDetail)
89
+ if (!identifierDetail.hasOwnProperty("partitionKey")) {
90
+ return []
89
91
  }
90
92
 
91
-
92
- // start create dynamoDb template data
93
93
  for (let storageResource of Object.values(objectSchema.storageResources)) {
94
94
  if (storageResource.storageType === STORAGE_TYPES.dynamoDB) {
95
95
  let templateData = {
96
96
  tableName: storageResource.tableName,
97
97
  attributes: []
98
98
  };
99
-
100
-
101
99
  if (storageResource.hasOwnProperty("groupByPartitionKeyField")) {
102
100
  templateData.attributes.push(
103
101
  {
@@ -107,47 +105,69 @@ function dataForMainDynamoDbYamlFromObjectSchema(_izContext, objectSchema) {
107
105
  }
108
106
  );
109
107
  } else {
110
- for (let identifierType in identifiersDetail) {
108
+ for (let identifierType in identifierDetail) {
111
109
  templateData.attributes.push(
112
110
  {
113
111
  keyType: identifierType,
114
- AttributeName: identifiersDetail[identifierType].AttributeName,
115
- AttributeType: identifiersDetail[identifierType].AttributeType
112
+ AttributeName: identifierDetail[identifierType].AttributeName,
113
+ AttributeType: identifierDetail[identifierType].AttributeType
116
114
  }
117
- );
115
+ )
118
116
  }
119
117
  }
120
- dynamoDbYamlTemplateData.push(templateData);
118
+
119
+ dynamoDbYamlTempleteData.push(templateData)
120
+ // console.log("templateData")
121
121
  }
122
122
  }
123
-
124
- return dynamoDbYamlTemplateData
123
+ return dynamoDbYamlTempleteData
125
124
  }
126
125
 
127
126
 
128
- // return array of table data
129
- // because one relSchema can create multiple dynamoDb table
130
- function dataForMainDynamoDbYamlFromRelSchema(_izContext, relSchema) {
131
- let relTag = Object.keys(relSchema)[0];
132
- let relData = relSchema[relTag];
127
+ // data for MainDynamo from RelSchema
128
+ // function dataForMainDynamoDbYamlFromRelSchema(_izContext, relSchema) {
129
+ // let relTag = Object.keys(relSchema)[0];
130
+ // let relData = relSchema[relTag];
133
131
 
134
- for (let parents of relData.parents) {
135
- let parentObjectType = parent.objType.objectType;
132
+ // for (let parents of relData.parents) {
133
+ // let parentObjectType = parent.objType.objectType;
136
134
 
137
135
 
136
+ // }
137
+
138
+ // return
139
+ // }
140
+
141
+
142
+ module.exports.createSourceDataDynamoDB = (_izContext, objectSchema, srcPath) => {
143
+
144
+ let resultsForCreateSource = [];
145
+
146
+
147
+ const dynamoDbMainYamlDataList = dataForMainDynamoDbYamlFromObjectSchema(_izContext, objectSchema, srcPath)
148
+ // console.log("dynamoDbMainYamlDataList: ", dynamoDbMainYamlDataList);
149
+
150
+ for (let dynamoDbMainYamlData of dynamoDbMainYamlDataList) {
151
+ // create iam role of handler here
152
+ resultsForCreateSource.push({
153
+ templatePath: templatePath,
154
+ templateData: dynamoDbMainYamlData,
155
+ setting: {
156
+ initialData: 'Resources:\n',
157
+ savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
158
+ saveFileName: 'generated-dynamoDB-table',
159
+ fileExtension: '.yml',
160
+ isAppend: true
161
+ }
162
+ });
138
163
  }
139
164
 
140
- return
165
+ // console.log("resultsForCreateSource: ", resultsForCreateSource);
166
+
167
+ return resultsForCreateSource;
141
168
  }
142
169
 
170
+ // module.exports.createSourceDataRelSchema = (_izContext, relSchema, saveFilePath) => {
143
171
 
144
- module.exports = {
145
- dynamoDbMainYamlFromObjectSchema: {
146
- templatePath: path.join(__dirname, '../Template/DynamoDb.ejs'),
147
- templateDataFunction: dataForMainDynamoDbYamlFromObjectSchema
148
- },
149
- dynamoDbMainYamlFromRelSchema: {
150
- templatePath: path.join(__dirname, '../Template/DynamoDb.ejs'),
151
- templateDataFunction: dataForMainDynamoDbYamlFromRelSchema
152
- },
153
- }
172
+ // return []
173
+ // }
@@ -0,0 +1,103 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+
20
+ const path = require("path")
21
+
22
+
23
+ // const {
24
+ // HANDLER,
25
+ // STORAGE_TYPES
26
+ // } = require('@izara_project/izara-core-library-service-schemas/src/Consts');
27
+
28
+ const STORAGE_TYPES = {
29
+ dynamoDB: "dynamoDB",
30
+ graph: "graph"
31
+ }
32
+ const templatePath = path.join(__dirname, './template.ejs')
33
+ const { SOURCE_PATH } = require('../../libs/Consts');
34
+
35
+ /**
36
+ * create param of crateSouce for FindData And processLogical
37
+ *
38
+ * @param {Object} _izContext
39
+ * @param {String} srcPath
40
+ * @returns {Object[]}
41
+ */
42
+ module.exports.createDefaultSourceDataDynamoDB = (_izContext, srcPath) => {
43
+
44
+ let resultsForCreateSource = [];
45
+
46
+ const defaultDynamoDataList = [
47
+ {
48
+ "tableName": "FindData",
49
+ "attributes": [
50
+ {
51
+ "keyType": "partitionKey",
52
+ "AttributeName": "findDataId",
53
+ "AttributeType": "S"
54
+ }
55
+ ]
56
+ },
57
+ {
58
+ "tableName": "LogicalResultsMain",
59
+ "attributes": [
60
+ {
61
+ "keyType": "partitionKey",
62
+ "AttributeName": "logicalResultId",
63
+ "AttributeType": "S"
64
+ }
65
+ ]
66
+ },
67
+ {
68
+ "tableName": "LogicalResultsData",
69
+ "attributes": [
70
+ {
71
+ "keyType": "partitionKey",
72
+ "AttributeName": "logicalResultId",
73
+ "AttributeType": "S"
74
+ },
75
+ {
76
+ "keyType": "sortKey",
77
+ "AttributeName": "dataId",
78
+ "AttributeType": "S"
79
+ }
80
+ ]
81
+ }
82
+ ];
83
+
84
+ // console.log("defaultlDynamoDataList: ", (defaultDynamoDataList));
85
+
86
+ for (let defaultlDynamoData of defaultDynamoDataList) {
87
+ resultsForCreateSource.push({
88
+ templatePath: templatePath,
89
+ templateData: defaultlDynamoData,
90
+ setting: {
91
+ initialData: 'Resources:\n',
92
+ savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
93
+ saveFileName: 'generated-dynamoDB-table',
94
+ fileExtension: '.yml',
95
+ isAppend: true
96
+ }
97
+ });
98
+ }
99
+
100
+ // console.log("resultForCreateDefaultDynamoDb: ", (resultsForCreateSource));
101
+
102
+ return resultsForCreateSource;
103
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "tableName": "xxx",
3
+ "attributes": {
4
+ "partitionKey": "xxx",
5
+ "sortKey": "optional"
6
+ }
7
+ }
@@ -0,0 +1,31 @@
1
+ <%- tableName %>Table:
2
+ Type: "AWS::DynamoDB::Table"
3
+ Properties:
4
+ TableName: ${self:custom.iz_resourcePrefix}<%- tableName %>
5
+ AttributeDefinitions:
6
+ <%_ attributes.forEach(attribute => { -%>
7
+ - AttributeName: <%- attribute['AttributeName'] %>
8
+ AttributeType: <%- attribute['AttributeType'] %>
9
+ <%_ }) _%>
10
+ KeySchema:
11
+ <%_ attributes.forEach(attribute => { -%>
12
+ <%_ if (attribute.keyType === 'partitionKey') { -%>
13
+ - AttributeName: <%- attribute["AttributeName"] %>
14
+ KeyType: HASH
15
+ <%_ } -%>
16
+ <%_ if(attribute.keyType === "sortKey") { -%>
17
+ - AttributeName: <%- attribute["AttributeName"] %>
18
+ KeyType: RANGE
19
+ <%_ } -%>
20
+ <%_ }) _%>
21
+ ProvisionedThroughput:
22
+ ReadCapacityUnits: 1
23
+ WriteCapacityUnits: 1
24
+ #<#<%- firstLetterUpperCase(tableName) %>DynamoDbSetting#>
25
+ #<#/<%- firstLetterUpperCase(tableName) %>DynamoDbSetting#>
26
+ <%_ function firstLetterUpperCase(text){
27
+ return text.charAt(0).toUpperCase() + text.slice(1)
28
+ } _%>
29
+ <%_ function firstLetterLowerCase(str) {
30
+ return str.charAt(0).toLowerCase() + str.slice(1)
31
+ } _%>