@izara_project/izara-market-library-service-schemas 1.0.34 → 1.0.36

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 (135) hide show
  1. package/package.json +1 -1
  2. package/src/GenerateCodeLibs/src/Consts.js +2 -1
  3. package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +7 -6
  4. package/src/MainLibs/src/Consts.js +47 -14
  5. package/src/MainLibs/src/GenerateCodeUtils.js +2 -0
  6. package/src/TemplateManager/src/attributeTree/relationshipSchema/data.js +1 -1
  7. package/src/TemplateManager/src/attributeTreeSchema/generateTemplateData.js +103 -0
  8. package/src/{reStructure/TemplateData/attributeTreeSchema/mainAttributeTreeSchema → TemplateManager/src/attributeTreeSchema/mainAttributeTree}/attributeLinkTemplate.ejs +3 -7
  9. package/src/TemplateManager/src/attributeTreeSchema/mainAttributeTree/data.js +134 -0
  10. package/src/TemplateManager/src/attributeTreeSchema/referenceRelationshipSchema/data.js +84 -0
  11. package/src/TemplateManager/src/attributeTreeSchema/referenceRelationshipSchema/tempReferenceRelationshipSchema.ejs +9 -0
  12. package/src/TemplateManager/src/attributeTreeSchema/relationshipSchema/data.js +172 -0
  13. package/src/TemplateManager/src/attributeTreeSchema/relationshipSchema/template.ejs +7 -0
  14. package/src/reStructure/GenerateCode.js +1 -0
  15. package/src/reStructure/SchemaConfig.js +1 -3
  16. package/src/reStructure/TemplateData/EndpointPerService/handler/api/template.ejs +2 -2
  17. package/src/reStructure/TemplateData/EndpointPerService/handler/inv/template.ejs +2 -2
  18. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/create/backupTemplate.ejs +701 -0
  19. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/create/template.ejs +34 -159
  20. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/delete/template.ejs +2 -0
  21. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/get/template.ejs +3 -4
  22. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/update/template.ejs +2 -0
  23. package/src/reStructure/TemplateData/externalService/lambdaRole/data.js +38 -12
  24. package/src/reStructure/TemplateData/externalService/lambdaRole/template.ejs +5 -2
  25. package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/data.js +22 -14
  26. package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/template.ejs +4 -1
  27. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/functionYaml/data.js +123 -0
  28. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/functionYaml/template.ejs +20 -0
  29. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/handler/data.js +57 -0
  30. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/handler/template.ejs +85 -0
  31. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/mainFunction/data.js +68 -0
  32. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/mainFunction/template.ejs +131 -0
  33. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/queue/data.js +77 -0
  34. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/queue/template.ejs +49 -0
  35. package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/handler/template.ejs +1 -1
  36. package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/mainFunction/template.ejs +1 -1
  37. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/createPresignUrl/mainFunction/template.ejs +1 -1
  38. package/src/reStructure/TemplateData/flowSchema/components/upload/relate/libs/data.js +12 -4
  39. package/src/reStructure/TemplateData/flowSchema/components/upload/relate/libs/template.ejs +13 -8
  40. package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/handler/template.ejs +4 -4
  41. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/functionYaml/data.js +141 -0
  42. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/functionYaml/template.ejs +20 -0
  43. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/handler/data.js +55 -0
  44. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/handler/template.ejs +83 -0
  45. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/mainFunction/data.js +55 -0
  46. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/mainFunction/template.ejs +131 -0
  47. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/dynamoDB/register.js +82 -0
  48. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/sns-in/data.js +64 -0
  49. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/sns-in/template.ejs +45 -0
  50. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/statusFieldTemplate.ejs +19 -6
  51. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/storedCacheTemplate.ejs +9 -15
  52. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/subscriptionOutAll/data.js +76 -0
  53. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/subscriptionOutAll/template.ejs +13 -0
  54. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/functionYaml/data.js +164 -0
  55. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/functionYaml/template.ejs +18 -0
  56. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/handler/data.js +64 -0
  57. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/handler/template.ejs +88 -0
  58. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/mainFunction/data.js +55 -0
  59. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/mainFunction/template.ejs +222 -0
  60. package/src/reStructure/TemplateData/flowSchema/dynamoDb/data.js +83 -44
  61. package/src/reStructure/TemplateData/flowSchema/eventBridge/functionYaml/data.js +26 -59
  62. package/src/reStructure/TemplateData/flowSchema/eventBridge/functionYaml/template.ejs +3 -3
  63. package/src/reStructure/TemplateData/flowSchema/eventBridge/handler/inv/data.js +8 -8
  64. package/src/reStructure/TemplateData/flowSchema/eventBridge/mainFunction/data.js +11 -9
  65. package/src/reStructure/TemplateData/flowSchema/eventBridge/mainFunction/template.ejs +3 -3
  66. package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-in-sqs/data.js +5 -9
  67. package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-in-sqs/template.ejs +1 -7
  68. package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-out/data.js +2 -3
  69. package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-out/template.ejs +2 -4
  70. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/functionYaml/data.js +37 -11
  71. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/functionYaml/template.ejs +4 -4
  72. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/handler/data.js +8 -9
  73. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/handler/template.ejs +13 -13
  74. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/mainFunction/data.js +4 -4
  75. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/mainFunction/template.ejs +44 -69
  76. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/functionYaml/data.js +7 -44
  77. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/functionYaml/template.ejs +3 -3
  78. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/handler/data.js +3 -10
  79. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/handler/template.ejs +40 -86
  80. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/mainFunction/data.js +11 -4
  81. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/mainFunction/template.ejs +11 -8
  82. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/functionYaml/data.js +17 -3
  83. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/functionYaml/template.ejs +2 -2
  84. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/mainFunction/data.js +8 -2
  85. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/mainFunction/template.ejs +49 -84
  86. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/functionYaml/data.js +55 -10
  87. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/functionYaml/template.ejs +1 -1
  88. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/handler/data.js +2 -2
  89. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/handler/template.ejs +1 -1
  90. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/mainFunction/data.js +27 -8
  91. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/mainFunction/template.ejs +50 -20
  92. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/functionYaml/data.js +20 -5
  93. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/functionYaml/template.ejs +1 -1
  94. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/handler/data.js +2 -2
  95. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/handler/template.ejs +5 -5
  96. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/mainFunction/data.js +5 -3
  97. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/mainFunction/template.ejs +7 -5
  98. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/functionYaml/data.js +6 -3
  99. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/functionYaml/template.ejs +0 -2
  100. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/handler/data.js +2 -2
  101. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/handler/template.ejs +3 -3
  102. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/mainFunction/data.js +9 -9
  103. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/mainFunction/template.ejs +17 -39
  104. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-in/data.js +14 -8
  105. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-out/data.js +4 -1
  106. package/src/reStructure/TemplateData/flowSchema/generateTemplateData.js +90 -21
  107. package/src/reStructure/TemplateData/generateRole/createSharedResource.js +22 -1
  108. package/src/reStructure/TemplateData/generateRole/sharedResourceTemplate.ejs +3 -0
  109. package/src/reStructure/TemplateData/perActionComplete/create/mainFunction/template.ejs +9 -8
  110. package/src/reStructure/TemplateData/perActionComplete/delete/mainFunction/template.ejs +5 -1
  111. package/src/reStructure/TemplateData/perActionComplete/get/mainFunction/template.ejs +2 -1
  112. package/src/reStructure/TemplateData/processLogical/mainFunction/template.ejs +1 -0
  113. package/src/reStructure/TemplateData/propertyValueSchema/generateTemplateData.js +66 -0
  114. package/src/reStructure/TemplateData/propertyValueSchema/objectPropertyValueSchema/data.js +131 -0
  115. package/src/reStructure/TemplateData/propertyValueSchema/objectPropertyValueSchema/templateObjectPropertyValueSchema.ejs +16 -0
  116. package/src/reStructure/TemplateData/propertyValueSchema/relationshipPropertyValueSchema/data.js +156 -0
  117. package/src/reStructure/TemplateData/propertyValueSchema/relationshipPropertyValueSchema/tempRelationship.ejs +13 -0
  118. package/src/reStructure/TemplateData/propertyValueSchema/relationshipPropertyValueSchema/templateRelationshipPropertyValueSchema.ejs +7 -0
  119. package/src/reStructure/TemplateData/relationshipPerAction/create/action/mainFunction/template.ejs +2 -1
  120. package/src/reStructure/TemplateData/relationshipPerAction/create/complete/mainFunction/template.ejs +2 -1
  121. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/mainFunction/template.ejs +2 -1
  122. package/src/reStructure/TemplateData/relationshipPerAction/delete/complete/handler/sqs/template.ejs +5 -5
  123. package/src/reStructure/TemplateData/relationshipPerAction/delete/complete/mainFunction/template.ejs +5 -4
  124. package/src/reStructure/TemplateData/relationshipPerAction/get/action/mainFunction/template.ejs +2 -1
  125. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/handler/sqs/template.ejs +4 -4
  126. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/mainFunction/template.ejs +4 -3
  127. package/src/reStructure/TemplateData/relationshipPerAction/update/action/mainFunction/template.ejs +2 -1
  128. package/src/reStructure/TemplateData/relationshipPerAction/update/complete/mainFunction/template.ejs +2 -1
  129. package/src/reStructure/TemplateData/resourceYaml/dynamodb/template.ejs +1 -3
  130. package/src/reStructure/TemplateData/resourceYaml/filterGenerateResource/data.js +61 -0
  131. package/src/reStructure/TemplateData/resourceYaml/generateTemplateData.js +13 -4
  132. package/src/reStructure/libs/ValidateAddOnDataStructure.js +62 -0
  133. package/src/reStructure/TemplateData/attributeTreeSchema/generateTemplateData.js +0 -104
  134. package/src/reStructure/TemplateData/attributeTreeSchema/mainAttributeTreeSchema/data.js +0 -188
  135. /package/src/{reStructure/TemplateData/attributeTreeSchema/mainAttributeTreeSchema → TemplateManager/src/attributeTreeSchema/mainAttributeTree}/request.json +0 -0
@@ -35,7 +35,8 @@ const {
35
35
  TOPIC_NAME_GRAPH_HANDLER,
36
36
  TOPIC_NAME_GENERATE_CODE
37
37
  } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/Consts');
38
-
38
+ //(<optionalRequire>)
39
+ //(</optionalRequire>)
39
40
  module.exports.updateRelationshipComplete = async (
40
41
  _izContext,
41
42
  returnValue,
@@ -2,6 +2,7 @@
2
2
  Type: "AWS::DynamoDB::Table"
3
3
  Properties:
4
4
  TableName: ${self:custom.iz_resourcePrefix}<%- tableName %>
5
+ BillingMode: PAY_PER_REQUEST
5
6
  AttributeDefinitions:
6
7
  <%_ attributes.forEach(attribute => { -%>
7
8
  - AttributeName: <%- attribute['AttributeName'] %>
@@ -18,9 +19,6 @@
18
19
  KeyType: RANGE
19
20
  <%_ } -%>
20
21
  <%_ }) _%>
21
- ProvisionedThroughput:
22
- ReadCapacityUnits: 1
23
- WriteCapacityUnits: 1
24
22
  #<#<%- firstLetterUpperCase(tableName) %>DynamoDbSetting#>
25
23
  #<#/<%- firstLetterUpperCase(tableName) %>DynamoDbSetting#>
26
24
  <%_ function firstLetterUpperCase(text){
@@ -0,0 +1,61 @@
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 { SOURCE_PATH, SAVE_FILE_NAME } = require('../../../../MainLibs/src/Consts')
33
+ const { firstUpperCase: upperCase } = require('../../../../MainLibs/src/Utils')
34
+ const getObjectSchema = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema');
35
+ const { NoRetryError } = require("@izara_project/izara-core-library-core");
36
+
37
+ async function filterCreateResourceYaml(_izContext, createSourceParams, objSchemaPath) {
38
+ let tableNamesToFilter = new Set();
39
+ const allLocalFlowSchema = await getObjectSchema.getAllLocalFlowSchemas(_izContext, objSchemaPath);
40
+ for (const flowSchema of allLocalFlowSchema.records) {
41
+ if (flowSchema.statusType === "storedCache") {
42
+ const objectSchema = await getObjectSchema.getLocalObjectSchemas(_izContext, [flowSchema.objType.objectType], objSchemaPath).then(res => res.records[0])
43
+ if (objectSchema) {
44
+ for (const storageResource of Object.values(objectSchema.storageResources)) {
45
+ tableNamesToFilter.add(storageResource.tableName);
46
+ }
47
+ } else {
48
+ throw new NoRetryError('not have objectSchema in service to get')
49
+ }
50
+ }
51
+ }
52
+
53
+ const filteredCreateSourceParams = createSourceParams.filter(
54
+ (result) => !tableNamesToFilter.has(result.templateData.tableName)
55
+ )
56
+
57
+ // console.log("filteredCreateSourceParams", filteredCreateSourceParams)
58
+ return filteredCreateSourceParams
59
+ }
60
+
61
+ module.exports = filterCreateResourceYaml;
@@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
20
20
  const { join } = require('path');
21
21
 
22
22
  // lib of generateCode
23
- const { checkValidTableYaml } = require('../../../MainLibs/index.js').generateCodeUtils;
23
+ const { checkValidTableYaml } = require('../../../MainLibs/src/GenerateCodeUtils.js');
24
24
 
25
25
  const {
26
26
  getAllLocalObjectSchemasWithHierarchy,
@@ -37,6 +37,8 @@ const createDefaultSnsOutForFindDataAndProcessLogical = require('./sns-out/defau
37
37
  const createDataForCreateSourceSnsOut = require('./sns-out/data');
38
38
  const createFindDataAndProcessLogicalDefaultSnsInSqs = require('./sns-in-sqs/defaultSnsInSqsForFindDataAndProcessLogical');
39
39
  const createDynamoPerRelationshipLink = require('./dynamodb/generateDynamoPerLink.js')
40
+ const filterCreateResourceYaml = require('./filterGenerateResource/data.js');
41
+
40
42
  /**
41
43
  * Generates code from templates based on object schemas
42
44
  * @param {Object} _izContext - Context object
@@ -48,7 +50,8 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
48
50
  const saveFilePath = join(objSchemaPath, '../');
49
51
  const allObjSchemas = await getAllLocalObjectSchemasWithHierarchy(_izContext, objSchemaPath);
50
52
  const allLocalRelationshipSchema = getAllLocalRelationshipSchema(_izContext, objSchemaPath);
51
- console.log("allLocalRelationship", allLocalRelationshipSchema)
53
+ const allLocalFlowSchema = await getAllLocalFlowSchemas(_izContext, objSchemaPath);
54
+
52
55
  let createSourceParams = [];
53
56
  let createdTableYaml = {}; // Declare createdTableYaml
54
57
 
@@ -56,9 +59,12 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
56
59
  if (allObjSchemas && allObjSchemas.records) {
57
60
  for (const objectSchema of allObjSchemas.records) {
58
61
  try {
62
+
63
+ let createSourceDynamoDb = createSourceDataDynamoDB(_izContext, objectSchema, saveFilePath)
64
+
59
65
  const [dynamoResources, updatedTableYaml] = checkValidTableYaml(
60
66
  _izContext,
61
- createSourceDataDynamoDB(_izContext, objectSchema, saveFilePath),
67
+ createSourceDynamoDb,
62
68
  createdTableYaml
63
69
  );
64
70
 
@@ -91,8 +97,11 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
91
97
  ...dynamoDbResourcePerRelationshipLink
92
98
  )
93
99
  }
100
+ const filteredCreateSourceParams = await filterCreateResourceYaml(_izContext, createSourceParams, objSchemaPath);
101
+
102
+ // console.log("filteredCreateSourceParams", filteredCreateSourceParams);
94
103
 
95
- return createSourceParams;
104
+ return filteredCreateSourceParams;
96
105
  } catch (error) {
97
106
  _izContext.logger.error('Error generating code with template resourceYaml: ', error);
98
107
  return [];
@@ -0,0 +1,62 @@
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 Consts = require('@izara_project/izara-market-library-service-schemas/src/MainLibs/src/Consts')
20
+ const getObjectSchema = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema');
21
+ const { ADD_ON_DATA_STRUCTURE_TYPE } = require('@izara_project/izara-market-library-service-schemas/src/MainLibs/src/Consts');
22
+
23
+ async function validateAddOnDataStructure(
24
+ _izContext,
25
+ settings
26
+ ) {
27
+
28
+ let errorFounds = [];
29
+ let returnObjectValue = {}
30
+
31
+ const objTypeString = objType => `{ serviceTag: ${objType.serviceTag}, objectType: ${objType.objectType} }`;
32
+
33
+ const objectSchema = await getObjectSchema.getObjSchemaS3WithHierarchy(_izContext, settings.objType);
34
+
35
+ if (!objectSchema) {
36
+ errorFounds.push(`Invalid objType:${objTypeString(settings.objType)}, cannot generate attribute tree schema cause objectSchema is not exists`)
37
+ };
38
+
39
+ if (!objectSchema.hasOwnProperty("addOnDataStructure") || !Array.isArray(objectSchema.addOnDataStructure) || !objectSchema.addOnDataStructure.length) {
40
+ errorFounds.push(`objType: ${objTypeString(settings.objType)}.cause addOnDataStructure is not exists or empty`)
41
+ };
42
+
43
+
44
+ if (settings.hasOwnProperty("attributeTag")) {
45
+ let addOnAttributeTree = objectSchema.addOnDataStructure.find(addOn => {
46
+ return addOn.type === ADD_ON_DATA_STRUCTURE_TYPE.attributeTree && addOn.attributeTreeTag === settings.attributeTag;
47
+ });
48
+ Object.assign(returnObjectValue, {
49
+ addOnAttributeTree: addOnAttributeTree,
50
+ });
51
+ if (!addOnAttributeTree) {
52
+ errorFounds.push(`objType: ${objTypeString(settings.objType)}. cannot generate attribute tree schema cause not found addOnDataStructure with attributeTreeTag: ${settings.attributeTag}`)
53
+ }
54
+ };
55
+
56
+ Object.assign(returnObjectValue, {
57
+ objectSchema: objectSchema
58
+ });
59
+
60
+ return [returnObjectValue, errorFounds];
61
+ }
62
+ module.exports = validateAddOnDataStructure
@@ -1,104 +0,0 @@
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
- // Import required modules
21
- console.log("generate main attri ");
22
- const { join } = require('path');
23
-
24
-
25
- const { data: mainAttributeData } = require('./mainAttributeTreeSchema/data');
26
-
27
- const serviceSchemaCore = require("@izara_project/izara-core-library-service-schemas");
28
- const getObjectSchema = serviceSchemaCore.getObjectSchema;
29
-
30
- const serviceSchemaShared = require('@izara_project/izara-shared-service-schemas');
31
- const { validateObjType } = serviceSchemaShared.validateObjType
32
-
33
-
34
- const modules = {
35
- mainAttributeTreeSchema: require('./mainAttributeTreeSchema/data')
36
- }
37
- /**
38
- * Generates code with templates for different actions
39
- * @param {Object} _izContext - Context object
40
- * @param {string} objSchemaPath - Path to the schema
41
- * @returns {Array} Array of generated code parameters
42
- */
43
- async function generateCodeWithTemplate(_izContext, objSchemaPath, settings) {
44
- try {
45
- let allCreateSource = [];
46
- const srcPath = join(objSchemaPath, '../');
47
-
48
- // {
49
- // generateName: "mainAttributeTree",
50
- // objType: {
51
- // serviceTag: "GenerateCodeTemplate",
52
- // objectType: "person"
53
- // },
54
- // attributeTag: "productAttribute"
55
- // }
56
-
57
- if (!settings || !settings.generateName || !settings.objType || !settings.attributeTag) {
58
- validateObjType(settings.objType);
59
- throw new Error("Invalid settings object. Must contain objType and attributeTag properties.");
60
- }
61
- // const allObjectSchema = await getObjectSchema.getObjSchemaS3WithoutHierarchy(_izContext, objSchemaPath)
62
- // .then(data => data.records);
63
-
64
- // const objectSchema = await getObjectSchema.getObjSchemaS3WithHierarchy(_izContext, settings.objType)
65
- // console.log("allObjectSchema: ", allObjectSchema);
66
- // console.log("settings: ", settings);
67
- /*
68
- use settings to get main objType
69
- then check if addOnDataStructure is exist
70
- if exist, check if type is attributeTree and match with attributeTreeTag
71
- if match, start generate schema of attributeTree
72
- */
73
-
74
- /*
75
- {
76
- objectSchema
77
-
78
-
79
- }
80
- */
81
- if (settings.generateName === "mainAttributeTree") {
82
- let objSchemaAttributeTree = await modules.mainAttributeTreeSchema(_izContext, settings, srcPath);
83
- console.log("objSchemaAttributeTree: ", objSchemaAttributeTree);
84
- allCreateSource.push(...objSchemaAttributeTree);
85
-
86
- } else {
87
- throw Error(`Generate attribute tree schema Invalid generateName:${settings.generateName} `);
88
- }
89
-
90
-
91
- // will receive objSchemaPath and prepare params for each data function
92
- // then data function will return params for createSource
93
-
94
- // (template, data, { savePath, hookPath, saveFileName, fileExtension, initialData, isAppend = false, checkCreateSourcePass = false })
95
-
96
-
97
- return allCreateSource;
98
- } catch (error) {
99
- _izContext.logger.error('Error generating code with template perActionComplete:', error);
100
- return [];
101
- }
102
- }
103
-
104
- module.exports = generateCodeWithTemplate;
@@ -1,188 +0,0 @@
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
- console.log("data main attribute tree schema");
21
-
22
- const path = require('path');
23
- const fs = require('fs');
24
-
25
- const serviceSchemaCore = require("@izara_project/izara-core-library-service-schemas");
26
- const getObjectSchema = serviceSchemaCore.getObjectSchema;
27
-
28
-
29
- const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../MainLibs/src/Utils");
30
- const { SOURCE_PATH, ADD_ON_DATA_STRUCTURE_TYPE, ATTRIBUTE_TAG, fieldNameSetting, FIELD_NAME_TPYE, SAVE_FILE_NAME } = require('../../../../MainLibs/src/Consts');
31
-
32
- const templatePath = path.join(__dirname, "./attributeLinkTemplate.ejs");
33
-
34
-
35
-
36
- async function data(_izContext, settings, srcPath) {
37
- const objTypeString = objType => `{ serviceTag: ${objType.serviceTag}, objectType: ${objType.objectType} }`;
38
-
39
- const objectSchema = await getObjectSchema.getObjSchemaS3WithHierarchy(_izContext, settings.objType);
40
-
41
- /*
42
- validate settings with objectSchema
43
- */
44
-
45
- if (!objectSchema) {
46
- throw Error(`Invalid objType:${objTypeString(settings.objType)}, cannot generate attribute tree schema cause objectSchema is not exists`);
47
- }
48
-
49
- if (!objectSchema.hasOwnProperty("addOnDataStructure") || !Array.isArray(objectSchema.addOnDataStructure) || !objectSchema.addOnDataStructure.length) {
50
- throw Error(`objType: ${objTypeString(settings.objType)}. cannot generate attribute tree schema cause addOnDataStructure is not exists or empty`);
51
- }
52
-
53
- if (!objectSchema.hasOwnProperty("addOnDataStructure")) {
54
- throw Error("Invalid objectSchema does not have addOnDataStructure");
55
- }
56
- // {
57
- // generateName: "mainAttributeTree",
58
- // objType: {
59
- // serviceTag: "GenerateCodeTemplate",
60
- // objectType: "person"
61
- // },
62
- // attributeTag: "productAttribute"
63
- // }
64
-
65
- let addOnAttributeTree = objectSchema.addOnDataStructure.find(addOn => {
66
- return addOn.type === ADD_ON_DATA_STRUCTURE_TYPE.attributeTree && addOn.attributeTreeTag === settings.attributeTag;
67
- })
68
-
69
-
70
- if (!addOnAttributeTree) {
71
- throw Error(`objType: ${objTypeString(settings.objType)}. cannot generate attribute tree schema cause not found addOnDataStructure with attributeTreeTag: ${settings.attributeTag}`);
72
- }
73
-
74
- // TODO: use addOnAttributeTree to generate attribute tree schema
75
- // if addOnAttributeTree.havePropertyNode === true will generate property node schema
76
-
77
-
78
- // console.log("objectSchema", objectSchema)
79
- // console.log("srcPath", objectSchema)
80
- // const createSources = [];
81
- // let attributeTreeObjSchemas = [];
82
- // if (objectSchema.hasOwnProperty("addOnDataStructure")) {
83
-
84
- // for (const versionedData of objectSchema.addOnDataStructure) {
85
- // if (versionedData.type === ADD_ON_DATA_STRUCTURE_TYPE.attributeTree) {
86
- // const attributeTreeSubject = objectSchema.objectType; // main objectType
87
- // const storageResources = objectSchema.storageResources // storageResource from main objectType
88
- // const storageResourceTags = Object.keys(storageResources) // storage ResourceTag from main objectType
89
-
90
-
91
- // attributeTreeObjSchemas.push(
92
- // {
93
- // objectType: attributeTreeSubject + ATTRIBUTE_TAG.attributeTagLabel,
94
- // storageResources: storageResources,
95
- // fieldNames: {
96
- // labelId: fieldNameSetting(FIELD_NAME_TPYE.identifiers)
97
- // },
98
- // identifiers: [
99
- // {
100
- // type: "identifier",
101
- // fieldName: "labelId"
102
- // }
103
- // ]
104
- // },
105
- // {
106
- // objectType: attributeTreeSubject + ATTRIBUTE_TAG.attributeTagLink,
107
- // storageResources: storageResources,
108
- // fieldNames: {
109
- // [attributeTreeSubject + ATTRIBUTE_TAG.attributeTagLink + "Id"]: fieldNameSetting(FIELD_NAME_TPYE.identifiers),
110
- // [attributeTreeSubject + "Id"]: fieldNameSetting(FIELD_NAME_TPYE.requiredOnCreateFieldName),
111
- // topLevelParentIdentifierProperties: fieldNameSetting(FIELD_NAME_TPYE.requiredOnCreateFieldName),
112
- // parentNodeIdentifierLabel: fieldNameSetting(FIELD_NAME_TPYE.requiredOnCreateFieldName),
113
- // parentNodeIdentifierProperties: fieldNameSetting(FIELD_NAME_TPYE.requiredOnCreateFieldName),
114
- // },
115
- // identifiers: [
116
- // {
117
- // type: "identifier",
118
- // fieldName: `${attributeTreeSubject + ATTRIBUTE_TAG.attributeTagLink}Id`
119
- // }
120
- // ]
121
- // },
122
- // {
123
- // objectType: attributeTreeSubject + ATTRIBUTE_TAG.attributeTagProperty,
124
- // storageResources: storageResources,
125
- // fieldNames: {
126
- // propertyId: fieldNameSetting(FIELD_NAME_TPYE.identifiers),
127
- // propertyLabelId: fieldNameSetting(FIELD_NAME_TPYE.optionalOnCreate)
128
- // },
129
- // identifiers: [
130
- // {
131
- // type: "identifier",
132
- // fieldName: "propertyId"
133
- // }
134
- // ]
135
- // },
136
- // {
137
- // objectType: attributeTreeSubject + ATTRIBUTE_TAG.attributeTagPropertyLabel,
138
- // storageResources: storageResources,
139
- // fieldNames: {
140
- // propertyLabelId: fieldNameSetting(FIELD_NAME_TPYE.identifiers)
141
- // },
142
- // identifiers: [
143
- // {
144
- // type: "identifier",
145
- // fieldName: "propertyLabelId"
146
- // }
147
- // ]
148
- // }
149
- // )
150
-
151
-
152
- // for (let attributeTreeObjSchema of attributeTreeObjSchemas) {
153
- // for (let attributeTreeFieldName of Object.values(attributeTreeObjSchema.fieldNames)) {
154
- // Object.assign(attributeTreeFieldName, { storageResourceTags: storageResourceTags }) // add storageResourceTags for each fieldName
155
- // }
156
- // }
157
- // }
158
-
159
- // }
160
-
161
-
162
-
163
- // // console.log("attributeTreeObjSchemas", attributeTreeObjSchemas)
164
- // for (const attributeTreeObjSchema of attributeTreeObjSchemas) {
165
- // createSources.push({
166
- // templatePath: templatePath,
167
- // templateData: {
168
- // fieldNames: JSON.stringify(attributeTreeObjSchema.fieldNames, null, 2),
169
- // identifiers: JSON.stringify(attributeTreeObjSchema.identifiers, null, 2),
170
- // objectType: attributeTreeObjSchema.objectType,
171
- // storageResources: JSON.stringify(attributeTreeObjSchema.storageResources, null, 2),
172
- // compositeKeyDeliminator: attributeTreeObjSchema.compositeKeyDeliminator
173
- // },
174
- // setting: {
175
- // savePath: path.join(srcPath, SOURCE_PATH.generatedAttributeTree, attributeTreeObjSchema.objectType + "/"),
176
- // hookPath: path.join(srcPath, "schemaHook", attributeTreeObjSchema.objectType, "/"),
177
- // saveFileName: SAVE_FILE_NAME.attributeTreeObjectSchema,
178
- // fileExtension: ".js",
179
- // isAppend: false
180
- // }
181
- // })
182
- // }
183
- // }
184
- // console.log("createSources", createSources)
185
- return createSources;
186
- }
187
-
188
- module.exports = data