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

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 (63) hide show
  1. package/index.js +25 -0
  2. package/package.json +6 -2
  3. package/src/GenerateCodeLibs/index.js +24 -0
  4. package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +1373 -0
  5. package/src/MainLibs/index.js +24 -0
  6. package/src/MainLibs/src/Consts.js +0 -0
  7. package/src/MainLibs/src/Utils.js +27 -0
  8. package/src/SourceManager/index.js +23 -0
  9. package/src/SourceManager/src/CreateSource.js +181 -0
  10. package/src/SourceManager/src/Utils.js +64 -0
  11. package/src/TemplateManager/index.js +23 -0
  12. package/src/TemplateManager/src/FunctionYaml/HdrApi/data.js +170 -0
  13. package/src/TemplateManager/src/FunctionYaml/HdrApi/request.json +14 -0
  14. package/src/TemplateManager/src/FunctionYaml/HdrApi/template.ejs +33 -0
  15. package/src/TemplateManager/src/FunctionYaml/HdrDsq/data.js +178 -0
  16. package/src/TemplateManager/src/FunctionYaml/HdrDsq/request.json +19 -0
  17. package/src/TemplateManager/src/FunctionYaml/HdrDsq/template.ejs +30 -0
  18. package/src/TemplateManager/src/FunctionYaml/HdrInv/data.js +169 -0
  19. package/src/TemplateManager/src/FunctionYaml/HdrInv/example req.js +15 -0
  20. package/src/TemplateManager/src/FunctionYaml/HdrInv/request.json +14 -0
  21. package/src/TemplateManager/src/FunctionYaml/HdrInv/template.ejs +26 -0
  22. package/src/TemplateManager/src/FunctionYaml/HdrSqs/data.js +184 -0
  23. package/src/TemplateManager/src/FunctionYaml/HdrSqs/request.json +19 -0
  24. package/src/TemplateManager/src/FunctionYaml/HdrSqs/template.ejs +30 -0
  25. package/src/TemplateManager/src/GenerateCode(Old).js +135 -0
  26. package/src/TemplateManager/src/GenerateCode.js +207 -0
  27. package/src/TemplateManager/src/MainResourcesYaml/CreateSourceData.js +76 -0
  28. package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Data/MainDynamoDbYamlData.js +155 -0
  29. package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.ejs +31 -0
  30. package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.exampleData.js +12 -0
  31. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrApi/data.js +100 -0
  32. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrApi/request.json +7 -0
  33. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrApi/template.ejs +76 -0
  34. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrDsq/data.js +109 -0
  35. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrDsq/request.json +7 -0
  36. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrDsq/template.ejs +105 -0
  37. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrInv/data.js +102 -0
  38. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrInv/request.json +7 -0
  39. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrInv/template.ejs +82 -0
  40. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrSqs/data.js +102 -0
  41. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrSqs/request.json +7 -0
  42. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrSqs/template.ejs +124 -0
  43. package/src/TemplateManager/src/PerActionEndpoint/Handler/testRequest.json +5 -0
  44. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/data.js +88 -0
  45. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/request.json +5 -0
  46. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/template.ejs +219 -0
  47. package/src/TemplateManager/src/ResourceYaml/CreateSourceData.js +76 -0
  48. package/src/TemplateManager/src/ResourceYaml/dynamodb/mainResourcePerObjectSchemaData.js +173 -0
  49. package/src/TemplateManager/src/ResourceYaml/dynamodb/processLogicalAndFindData.js +102 -0
  50. package/src/TemplateManager/src/ResourceYaml/dynamodb/request.json +7 -0
  51. package/src/TemplateManager/src/ResourceYaml/dynamodb/template.ejs +31 -0
  52. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/defaultSnsInSqsForFindDataAndProcessLogical.js +81 -0
  53. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/request.json +4 -0
  54. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/snsAndSqsPerActiondata.js +108 -0
  55. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/snsTemplate.ejs +59 -0
  56. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/sqsTemplate.ejs +42 -0
  57. package/src/TemplateManager/src/externalService/LambdaRole/data.js +147 -0
  58. package/src/TemplateManager/src/externalService/LambdaRole/request.json +18 -0
  59. package/src/TemplateManager/src/externalService/LambdaRole/template.ejs +52 -0
  60. package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/data.js +31 -0
  61. package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/request.json +0 -0
  62. package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/template.ejs +14 -0
  63. package/src/TemplateManager/src/libs/Consts.js +146 -0
@@ -0,0 +1,135 @@
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 join = require('path').join;
21
+ const { readFileSync } = require('fs');
22
+
23
+
24
+ const {
25
+ getAllLocalObjectSchemasWithHierarchy,
26
+ getAllLocalRelationshipSchemas
27
+ } = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema');
28
+
29
+
30
+
31
+ const { createSource } = require("../../SourceManager/src/CreateSource");
32
+ const { deleteFileInDir } = require("../../SourceManager/src/Utils");
33
+
34
+ const perAction = require("./PerActionEndpoint/CreateSourceData");
35
+
36
+ const mainResources = require("./MainResourcesYaml/CreateSourceData");
37
+
38
+
39
+ /**
40
+ *
41
+ * get template and send to
42
+ *
43
+ * @param {object} objSchemaPath
44
+ * @returns
45
+ *
46
+ * add another param
47
+ * {string[]} objectTypes
48
+ * {string[]} templates
49
+ * {string} saveFilePath
50
+ */
51
+ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
52
+
53
+ try {
54
+
55
+ // point to app/src
56
+ let saveFilePath = join(objSchemaPath, `../`);
57
+
58
+ // define path for store yml file
59
+ const GENERATECODE_SOURCE_PATH = {
60
+ appYaml: join(saveFilePath, `../sls_yaml/generatedCode/source/`),
61
+ resourceYaml: join(saveFilePath, `../../resource/sls_yaml/generatedCode/source/`),
62
+ lambdaPerObjectTypePath: join(saveFilePath, `/generatedCode/lambdaPerObjectType/source/`), // test
63
+ lamdaPerCombindActionPath: join(saveFilePath, `/generatedCode/lamdaPerCombindAction/source/`), // test
64
+ };
65
+
66
+
67
+ // from app/src/shcemas
68
+ let allObjSchemas = await getAllLocalObjectSchemasWithHierarchy(_izContext, objSchemaPath);
69
+
70
+ const allObjectRelationships = await getAllLocalRelationshipSchemas(_izContext, objSchemaPath);
71
+
72
+ /*
73
+ Should we generateCode with objectSchema that not in hierarchy or not?
74
+ Should use objectSchema with hierarchy because we use storageResource of parent to create lambda iam role in .yml file
75
+ */
76
+
77
+ let createSourceParams = [];
78
+
79
+ for (const relTag in allObjectRelationships) {
80
+ const relTagData = allObjectRelationships[relTag];
81
+
82
+ // create main resource per relationshipSchema
83
+ const createSourceMainResourcesRelSchema = mainResources.createSourceDataRelSchema(_izContext, { [relTag]: relTagData }, saveFilePath);
84
+ console.log("createSourceMainResourcesRelSchema: ", createSourceMainResourcesRelSchema);
85
+
86
+ createSourceParams = createSourceParams.concat(createSourceMainResourcesRelSchema);
87
+ }
88
+
89
+
90
+ //
91
+ for (let objectSchema of allObjSchemas.records) {
92
+
93
+ // create main resource per objectSchema
94
+ let createSourceMainResourcesObjectSchema = mainResources.createSourceDataObjectSchema(_izContext, objectSchema, saveFilePath);
95
+ // console.log("createSourceMainResourcesObjectSchema: ", createSourceMainResourcesObjectSchema);
96
+
97
+ // mainFunction, handlerFunction, resourceYaml per action
98
+ let createSourcePerAction = perAction.createSourceDataObjectSchema(_izContext, objectSchema, saveFilePath);
99
+ // console.log("createSourcePerAction: ", createSourcePerAction)
100
+
101
+
102
+
103
+ // console.log("createSourceParams begore concat: ", createSourceParams);
104
+
105
+ createSourceParams = createSourceParams.concat([...createSourcePerAction, ...createSourceMainResourcesObjectSchema]);
106
+
107
+ // console.log("createSourceParams after concat: ", createSourceParams);
108
+ }
109
+
110
+
111
+ // delete file .yml before start to prevent confilct of data
112
+ for (let folderPathToEmpty of Object.keys(GENERATECODE_SOURCE_PATH)) {
113
+ await deleteFileInDir(GENERATECODE_SOURCE_PATH[folderPathToEmpty]);
114
+ }
115
+
116
+
117
+ // start create source
118
+ for (let { templatePath, templateData, setting } of createSourceParams) {
119
+ await createSource(
120
+ readFileSync(templatePath, 'utf8'),
121
+ templateData,
122
+ setting,
123
+ );
124
+ }
125
+
126
+
127
+ return "return values";
128
+
129
+ } catch (err) {
130
+ console.log('error templateManager: ', err);
131
+ throw (err);
132
+ }
133
+ };
134
+
135
+ module.exports = { generateCodeWithTemplate };
@@ -0,0 +1,207 @@
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 join = require('path').join;
21
+ const { readFileSync } = require('fs');
22
+
23
+
24
+ const {
25
+ getAllLocalObjectSchemasWithHierarchy,
26
+ getAllLocalRelationshipSchemas
27
+ } = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema');
28
+
29
+
30
+ const {
31
+ getGraphServiceNameFromGraphServerTagWithCache
32
+ } = require('@izara_project/izara-core-library-service-schemas/src/ServiceConfig');
33
+
34
+ const { createSource } = require("../../SourceManager/src/CreateSource");
35
+ const { deleteFileInDir } = require("../../SourceManager/src/Utils");
36
+ // create handler function
37
+ const perActionHdrInvData = require("./PerActionEndpoint/Handler/HdrInv/data");
38
+ const perActionHdrApiData = require("./PerActionEndpoint/Handler/HdrApi/data");
39
+ const perActionHdrSqsData = require("./PerActionEndpoint/Handler/HdrSqs/data");
40
+ const perActionHdrDsqData = require("./PerActionEndpoint/Handler/HdrDsq/data");
41
+
42
+ // create Main funcion
43
+ const mainFunctionGetData = require('./PerActionEndpoint/MainFunction/Get/data');
44
+
45
+ // create function.yaml
46
+ const functionGetYamlDataHdrInv = require('./FunctionYaml/HdrInv/data');
47
+ const functionGetYamlDataHdrApi = require('./FunctionYaml/HdrApi/data');
48
+ const functionGetYamlDataHdrSqs = require('./FunctionYaml/HdrSqs/data');
49
+ const functionGetYamlDataHdrDsq = require('./FunctionYaml/HdrDsq/data');
50
+
51
+
52
+ // create Main resource
53
+ const { createSourceDataDynamoDB } = require('./ResourceYaml/dynamodb/mainResourcePerObjectSchemaData');
54
+ const { createDefaultSourceDataDynamoDB } = require('./ResourceYaml/dynamodb/processLogicalAndFindData')
55
+ const { createSourceSnsAndSqs } = require('./ResourceYaml/sns-in-sqs/snsAndSqsPerActiondata');
56
+ const createFindDataAndProcessLogicalDefaultSnsInSqs = require('./ResourceYaml/sns-in-sqs/defaultSnsInSqsForFindDataAndProcessLogical')
57
+
58
+ // create External Service
59
+ const createSnsSubscriptions = require('./externalService/SnsTopicSubscriotions/data');
60
+ const createLambdaRole = require('./externalService/LambdaRole/data');
61
+
62
+
63
+
64
+ //create resource
65
+ // const mainResources = require("./MainResourcesYaml/CreateSourceData");
66
+
67
+
68
+ /**
69
+ *
70
+ * get template and send to
71
+ *
72
+ * @param {object} objSchemaPath
73
+ * @returns
74
+ *
75
+ * add another param
76
+ * {string[]} objectTypes
77
+ * {string[]} templates
78
+ * {string} saveFilePath
79
+ */
80
+ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
81
+
82
+ try {
83
+
84
+ // point to app/src
85
+ let saveFilePath = join(objSchemaPath, `../`);
86
+
87
+ // define path for store yml file
88
+ const GENERATECODE_SOURCE_PATH = {
89
+ appYaml: join(saveFilePath, `../sls_yaml/generatedCode/source/`),
90
+ resourceYaml: join(saveFilePath, `../../resource/sls_yaml/generatedCode/source/`),
91
+ lambdaPerObjectTypePath: join(saveFilePath, `/generatedCode/perAction/source/`), // test
92
+ lamdaPerCombindActionPath: join(saveFilePath, `/generatedCode/lamdaPerCombindAction/source/`), // test,
93
+ externalService: join(saveFilePath, '../initial_setup/generatedCode/source/')
94
+ };
95
+
96
+
97
+ // from app/src/shcemas
98
+ let allObjSchemas = await getAllLocalObjectSchemasWithHierarchy(_izContext, objSchemaPath);
99
+ // _izContext.logger.debug("allObjSchemas: ", allObjSchemas)
100
+
101
+ const allObjectRelationships = await getAllLocalRelationshipSchemas(_izContext, objSchemaPath);
102
+
103
+ // _izContext.logger.debug("allObjectRelationships: ", allObjectRelationships)
104
+ /*
105
+ Should we generateCode with objectSchema that not in hierarchy or not?
106
+ Should use objectSchema with hierarchy because we use storageResource of parent to create lambda iam role in .yml file
107
+ */
108
+
109
+ let createSourceParams = [];
110
+
111
+ for (const relTag in allObjectRelationships) {
112
+ // const relTagData = allObjectRelationships[relTag];
113
+
114
+ // create main resource per relationshipSchema
115
+ // const createSourceMainResourcesRelSchema = mainResources.createSourceDataRelSchema(_izContext, { [relTag]: relTagData }, saveFilePath);
116
+ // console.log("createSourceMainResourcesRelSchema: ", createSourceMainResourcesRelSchema);
117
+
118
+ // createSourceParams = createSourceParams.concat(createSourceMainResourcesRelSchema);
119
+ }
120
+
121
+ // create External service
122
+ const createFunctionIamRole = await createLambdaRole(_izContext, allObjSchemas.records, saveFilePath);
123
+ //
124
+ for (let objectSchema of allObjSchemas.records) {
125
+ console.log("objectSchema: ", objectSchema);
126
+
127
+ // create main resource per objectSchema
128
+ // const createSourceMainResourcesObjectSchema = mainResources.createSourceDataObjectSchema(_izContext, objectSchema, saveFilePath);
129
+ // console.log("createSourceMainResourcesObjectSchema: ", createSourceMainResourcesObjectSchema);
130
+
131
+ // mainFunction, handlerFunction, resourceYaml per action
132
+ // let createSourcePerAction = perAction.createSourceDataObjectSchema(_izContext, objectSchema, saveFilePath);
133
+ // console.log("createSourcePerAction: ", createSourcePerAction)
134
+
135
+ // generate handler
136
+ const createSourceHdrInv = perActionHdrInvData(_izContext, objectSchema, saveFilePath);
137
+ const createSourceHdrApi = perActionHdrApiData(_izContext, objectSchema, saveFilePath);
138
+ const createSourceHdrSqs = perActionHdrSqsData(_izContext, objectSchema, saveFilePath);
139
+ const createSourceHdrDsq = perActionHdrDsqData(_izContext, objectSchema, saveFilePath)
140
+
141
+ // wrap Handler Function
142
+ const createSourceHandler = [...createSourceHdrInv, ...createSourceHdrApi, ...createSourceHdrSqs, ...createSourceHdrDsq]
143
+
144
+ // generate main function
145
+ const createMainFunctionGet = await mainFunctionGetData(_izContext, objectSchema, saveFilePath)
146
+
147
+ // generate functionYaml File
148
+ const createFunctionGetYamlHdrInv = functionGetYamlDataHdrInv(_izContext, objectSchema, saveFilePath)
149
+ const createFunctionGetYamlHdrApi = functionGetYamlDataHdrApi(_izContext, objectSchema, saveFilePath)
150
+ const createFunctionGetYamlHdrSqs = functionGetYamlDataHdrSqs(_izContext, objectSchema, saveFilePath)
151
+ const createFunctionGetYamlHdrDsq = functionGetYamlDataHdrDsq(_izContext, objectSchema, saveFilePath)
152
+
153
+ // wrapMain Function
154
+ const createFunctionYaml = [...createFunctionGetYamlHdrApi, ...createFunctionGetYamlHdrDsq, ...createFunctionGetYamlHdrInv, ...createFunctionGetYamlHdrSqs]
155
+
156
+
157
+ // const createSnsSunbscription = createSnsSubscriptions.createSnsSubscription(_izContext, objectSchema, saveFilePath)
158
+
159
+ // generate Resource ..via dynamoDb sns-in-sqs sns-put
160
+ const createResourceDynamo = createSourceDataDynamoDB(_izContext, objectSchema, saveFilePath);
161
+ const createResourceSnsInSqs = createSourceSnsAndSqs(_izContext, objectSchema, saveFilePath);
162
+ const createResourceFindDataAndProcessLogical = createDefaultSourceDataDynamoDB(_izContext, saveFilePath);
163
+ const createResourceDefaultSnsInSqsFindDataAndProcessLogical = createFindDataAndProcessLogicalDefaultSnsInSqs(_izContext, saveFilePath);
164
+
165
+ // wrap main Resource
166
+ const createMainResource = [...createResourceDynamo, ...createResourceSnsInSqs, ...createResourceFindDataAndProcessLogical, ...createResourceDefaultSnsInSqsFindDataAndProcessLogical]
167
+
168
+ createSourceParams = createSourceParams.concat([
169
+ // ...createSourceMainResourcesObjectSchema,
170
+ ...createSourceHandler, // create handler function
171
+ ...createMainFunctionGet, // create main function
172
+ ...createFunctionYaml, // create function.yaml
173
+ ...createMainResource, // create resource yaml
174
+ createFunctionIamRole,
175
+ ]);
176
+
177
+ // console.log("createSourceParams after concat: ", createSourceParams);
178
+ }
179
+
180
+
181
+ // delete file .yml before start to prevent confilct of data
182
+ for (let folderPathToEmpty of Object.keys(GENERATECODE_SOURCE_PATH)) {
183
+ await deleteFileInDir(GENERATECODE_SOURCE_PATH[folderPathToEmpty]);
184
+ }
185
+
186
+ // console.log("createSourceParams: ", createSourceParams)
187
+ // start create source
188
+ for (let { templatePath, templateData, setting } of createSourceParams) {
189
+ // console.log("templatePath in GenerateCode", templatePath);
190
+ // console.log("setting.savePath in GenerateCode", setting.savePath);
191
+ await createSource(
192
+ readFileSync(templatePath, 'utf8'),
193
+ templateData,
194
+ setting,
195
+ );
196
+ }
197
+
198
+
199
+ return "return values";
200
+
201
+ } catch (err) {
202
+ console.log('error templateManager: ', err);
203
+ throw (err);
204
+ }
205
+ };
206
+
207
+ module.exports = { generateCodeWithTemplate };
@@ -0,0 +1,76 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+
20
+ const path = require('path');
21
+
22
+ const schemaConsts = require('@izara_project/izara-core-library-service-schemas/src/Consts');
23
+
24
+
25
+
26
+ // const lambdaYaml = require("./Template/Resource/Lambda/LambdaYamlTemplateData");
27
+
28
+ const config = require('../libs/Consts')
29
+
30
+
31
+ const dynamoDbMainYaml = require("./TemplateAndData/DynamoDbMain/Data/MainDynamoDbYamlData")
32
+
33
+ /**
34
+ * @param {Object} _izContext
35
+ * @param {Object} objectSchema
36
+ */
37
+ module.exports.createSourceDataObjectSchema = (_izContext, objectSchema, saveFilePath) => {
38
+
39
+ let resultsForCreateSource = [];
40
+
41
+
42
+ const dynamoDbMainYamlDataList = dynamoDbMainYaml.dynamoDbMainYamlFromObjectSchema.templateDataFunction(_izContext, objectSchema);
43
+ // console.log("dynamoDbMainYamlDataList: ", dynamoDbMainYamlDataList);
44
+
45
+ for (let dynamoDbMainYamlData of dynamoDbMainYamlDataList) {
46
+ // create iam role of handler here
47
+ resultsForCreateSource.push({
48
+ templatePath: dynamoDbMainYaml.dynamoDbMainYamlFromObjectSchema.templatePath,
49
+ templateData: dynamoDbMainYamlData,
50
+ setting: {
51
+ initialData: 'Resources:\n',
52
+ savePath: path.join(saveFilePath, config.SOURCE_PATH.resourceYaml),
53
+ saveFileName: 'generate-dynamodb-table',
54
+ fileExtension: '.yml',
55
+ isAppend: true
56
+ }
57
+ });
58
+ }
59
+
60
+ // console.log("resultsForCreateSource: ", resultsForCreateSource);
61
+
62
+ return resultsForCreateSource;
63
+ }
64
+
65
+
66
+ /**
67
+ *
68
+ * @param {Object} _izContext
69
+ * @param {Object} relSchema
70
+ * @param {String} saveFilePath
71
+ * @returns
72
+ */
73
+ module.exports.createSourceDataRelSchema = (_izContext, relSchema, saveFilePath) => {
74
+
75
+ return []
76
+ }
@@ -0,0 +1,155 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+
20
+ const path = require("path")
21
+
22
+ // const {
23
+ // HANDLER,
24
+ // STORAGE_TYPES
25
+ // } = require('@izara_project/izara-core-library-service-schemas/src/Consts');
26
+
27
+
28
+ const STORAGE_TYPES = {
29
+ dynamoDB: "dynamoDB",
30
+ graph: "graph"
31
+ }
32
+
33
+
34
+ // ---------- End Per Lambda Handler IamRole Data ----------
35
+
36
+
37
+
38
+ /**
39
+ * create data for dynamoDbYaml tempalte from objectSchema
40
+ * return array of dynamoDb data
41
+ * because one objectSchema can create multiple dynamoDb table
42
+ *
43
+ * @param {Object} _izContext
44
+ * @param {Object} objectSchema
45
+ * @returns {Object[]} - data of multiple dynamoDb template
46
+ */
47
+ function dataForMainDynamoDbYamlFromObjectSchema(_izContext, objectSchema) {
48
+ let dynamoDbYamlTemplateData = [];
49
+
50
+ // store detail for create dynamoDb table
51
+ let identifiersDetail = {};
52
+
53
+ // add identifiersDetail for dynamoDb storage
54
+ for (let identifier of objectSchema.identifiers) {
55
+ // console.log("in identifiers")
56
+ if (identifier.type === "partitionKey" || identifier.type === "sortKey") {
57
+ identifiersDetail[identifier.type] = {};
58
+
59
+ if (identifier.name) {
60
+ Object.assign(
61
+ identifiersDetail[identifier.type],
62
+ {
63
+ AttributeName: identifier.name,
64
+ AttributeType: "S"
65
+ }
66
+ );
67
+ } else {
68
+ let fieldNameType = objectSchema.fieldNames[identifier.fieldName].type;
69
+ let attributeType;
70
+
71
+ if (fieldNameType === "string") {
72
+ attributeType = "S"
73
+ } else if (fieldNameType === "number") {
74
+ attributeType = "N"
75
+ }
76
+
77
+ Object.assign(
78
+ identifiersDetail[identifier.type],
79
+ {
80
+ AttributeName: identifier.fieldName,
81
+ AttributeType: attributeType
82
+ }
83
+ );
84
+ }
85
+ }
86
+ }
87
+ // console.log("identifiersDetail: ", identifiersDetail)
88
+ if (!identifiersDetail.hasOwnProperty("partitionKey")) {
89
+ return [];
90
+ }
91
+
92
+
93
+ // start create dynamoDb template data
94
+ for (let storageResource of Object.values(objectSchema.storageResources)) {
95
+ if (storageResource.storageType === STORAGE_TYPES.dynamoDB) {
96
+ let templateData = {
97
+ tableName: storageResource.tableName,
98
+ attributes: []
99
+ };
100
+
101
+
102
+ if (storageResource.hasOwnProperty("groupByPartitionKeyField")) {
103
+ templateData.attributes.push(
104
+ {
105
+ keyType: "partitionKey",
106
+ AttributeName: storageResource.groupByPartitionKeyField,
107
+ AttributeType: "S"
108
+ }
109
+ );
110
+ } else {
111
+ for (let identifierType in identifiersDetail) {
112
+ templateData.attributes.push(
113
+ {
114
+ keyType: identifierType,
115
+ AttributeName: identifiersDetail[identifierType].AttributeName,
116
+ AttributeType: identifiersDetail[identifierType].AttributeType
117
+ }
118
+ );
119
+ }
120
+ }
121
+ dynamoDbYamlTemplateData.push(templateData);
122
+ // console.log("templateData: ", templateData)
123
+ }
124
+ }
125
+
126
+ return dynamoDbYamlTemplateData
127
+ }
128
+
129
+
130
+ // return array of table data
131
+ // because one relSchema can create multiple dynamoDb table
132
+ function dataForMainDynamoDbYamlFromRelSchema(_izContext, relSchema) {
133
+ let relTag = Object.keys(relSchema)[0];
134
+ let relData = relSchema[relTag];
135
+
136
+ for (let parents of relData.parents) {
137
+ let parentObjectType = parent.objType.objectType;
138
+
139
+
140
+ }
141
+
142
+ return
143
+ }
144
+
145
+
146
+ module.exports = {
147
+ dynamoDbMainYamlFromObjectSchema: {
148
+ templatePath: path.join(__dirname, '../Template/DynamoDb.ejs'),
149
+ templateDataFunction: dataForMainDynamoDbYamlFromObjectSchema
150
+ },
151
+ dynamoDbMainYamlFromRelSchema: {
152
+ templatePath: path.join(__dirname, '../Template/DynamoDb.ejs'),
153
+ templateDataFunction: dataForMainDynamoDbYamlFromRelSchema
154
+ },
155
+ }
@@ -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
+ } _%>
@@ -0,0 +1,12 @@
1
+ // example template data for dynamoDb
2
+ const templateData = {
3
+ tableName: "xx",
4
+ attributes: [
5
+ {
6
+ keyType: "xx", // partitionKey || sortKey
7
+ AttributeName: "", // any
8
+ AttributeType: "" // S, N, B
9
+ },
10
+ //...
11
+ ]
12
+ }