@izara_project/izara-market-library-service-schemas 1.0.27 → 1.0.28

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 (127) hide show
  1. package/package.json +9 -5
  2. package/src/GenerateCodeLibs/src/Consts.js +5 -2
  3. package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +5 -5
  4. package/src/MainLibs/src/Consts.js +44 -2
  5. package/src/reStructure/GenerateCode.js +0 -4
  6. package/src/reStructure/GenerateSchema.js +17 -5
  7. package/src/reStructure/SchemaConfig.js +3 -2
  8. package/src/reStructure/TemplateData/attributeTreeSchema/generateTemplateData.js +58 -6
  9. package/src/reStructure/TemplateData/attributeTreeSchema/mainAttributeTreeSchema/data.js +161 -101
  10. package/src/reStructure/TemplateData/externalService/lambdaRole/template.ejs +3 -4
  11. package/src/reStructure/TemplateData/findData/handler/template.ejs +1 -1
  12. package/src/reStructure/TemplateData/findData/mainFunction/template.ejs +3 -3
  13. package/src/reStructure/TemplateData/flowSchema/components/upload/confirmReserved/handler/template.ejs +2 -3
  14. package/src/reStructure/TemplateData/flowSchema/components/upload/confirmReserved/mainFunction/template.ejs +2 -3
  15. package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/handler/template.ejs +2 -3
  16. package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/mainFunction/template.ejs +5 -6
  17. package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/handler/template.ejs +1 -2
  18. package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/mainFunction/template.ejs +3 -4
  19. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/getSignUrls/handler/template.ejs +2 -2
  20. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/getSignUrls/mainFunction/template.ejs +3 -4
  21. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/handler/template.ejs +2 -3
  22. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/mainFunction/template.ejs +5 -6
  23. package/src/reStructure/TemplateData/flowSchema/components/upload/processFile/handler/handlerS3/template.ejs +1 -1
  24. package/src/reStructure/TemplateData/flowSchema/components/upload/processFile/mainFunction/template.ejs +4 -5
  25. package/src/reStructure/TemplateData/flowSchema/components/websocket/dynamoDb/ReservedTableData.js +1 -0
  26. package/src/reStructure/TemplateData/flowSchema/components/websocket/dynamoDb/WebSocketTaskData.js +1 -0
  27. package/src/reStructure/TemplateData/perActionComplete/create/handler/template.ejs +2 -3
  28. package/src/reStructure/TemplateData/perActionComplete/create/mainFunction/template.ejs +4 -5
  29. package/src/reStructure/TemplateData/perActionComplete/delete/handler/template.ejs +2 -2
  30. package/src/reStructure/TemplateData/perActionComplete/delete/mainFunction/template.ejs +4 -6
  31. package/src/reStructure/TemplateData/perActionComplete/generateTemplateData.js +1 -1
  32. package/src/reStructure/TemplateData/perActionComplete/get/handler/template.ejs +2 -3
  33. package/src/reStructure/TemplateData/perActionComplete/get/mainFunction/template.ejs +4 -6
  34. package/src/reStructure/TemplateData/perActionComplete/update/handler/template.ejs +2 -3
  35. package/src/reStructure/TemplateData/perActionComplete/update/mainFunction/template.ejs +4 -6
  36. package/src/reStructure/TemplateData/perActionEndpoint/handler/api/template.ejs +1 -1
  37. package/src/reStructure/TemplateData/perActionEndpoint/handler/dsq/template.ejs +2 -2
  38. package/src/reStructure/TemplateData/perActionEndpoint/handler/inv/template.ejs +1 -3
  39. package/src/reStructure/TemplateData/perActionEndpoint/handler/sqs/template.ejs +2 -2
  40. package/src/reStructure/TemplateData/perActionEndpoint/handler/webSocket/template.ejs +3 -3
  41. package/src/reStructure/TemplateData/perActionEndpoint/mainFunction/create/template.ejs +6 -7
  42. package/src/reStructure/TemplateData/perActionEndpoint/mainFunction/delete/template.ejs +5 -4
  43. package/src/reStructure/TemplateData/perActionEndpoint/mainFunction/get/template.ejs +5 -6
  44. package/src/reStructure/TemplateData/perActionEndpoint/mainFunction/update/template.ejs +5 -6
  45. package/src/reStructure/TemplateData/processLogical/handler/template.ejs +1 -1
  46. package/src/reStructure/TemplateData/processLogical/mainFunction/template.ejs +5 -6
  47. package/src/reStructure/TemplateData/processLogicalPagination/handler/dsq/template.ejs +1 -1
  48. package/src/reStructure/TemplateData/processLogicalPagination/handler/sqs/template.ejs +1 -1
  49. package/src/reStructure/TemplateData/processLogicalPagination/mainFunction/template.ejs +6 -5
  50. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/api/data.js +27 -6
  51. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/dsq/data.js +25 -4
  52. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/inv/data.js +26 -4
  53. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/sqs/data.js +26 -4
  54. package/src/reStructure/TemplateData/relationshipPerAction/create/action/handler/api/template.ejs +1 -1
  55. package/src/reStructure/TemplateData/relationshipPerAction/create/action/handler/dsq/template.ejs +2 -2
  56. package/src/reStructure/TemplateData/relationshipPerAction/create/action/handler/inv/template.ejs +1 -1
  57. package/src/reStructure/TemplateData/relationshipPerAction/create/action/handler/sqs/template.ejs +2 -2
  58. package/src/reStructure/TemplateData/relationshipPerAction/create/action/mainFunction/template.ejs +66 -18
  59. package/src/reStructure/TemplateData/relationshipPerAction/create/complete/handler/sqs/template.ejs +2 -3
  60. package/src/reStructure/TemplateData/relationshipPerAction/create/complete/mainFunction/template.ejs +5 -6
  61. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/api/data.js +25 -4
  62. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/dsq/data.js +25 -4
  63. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/inv/data.js +25 -4
  64. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/sqs/data.js +26 -4
  65. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/handler/api/template.ejs +1 -1
  66. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/handler/dsq/template.ejs +2 -2
  67. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/handler/inv/template.ejs +1 -1
  68. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/handler/sqs/template.ejs +2 -2
  69. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/mainFunction/template.ejs +55 -5
  70. package/src/reStructure/TemplateData/relationshipPerAction/generateTemplateData.js +62 -6
  71. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/api/data.js +119 -0
  72. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/api/template.ejs +20 -0
  73. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/dsq/data.js +131 -0
  74. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/dsq/template.ejs +17 -0
  75. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/inv/data.js +119 -0
  76. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/inv/template.ejs +13 -0
  77. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/sqs/data.js +131 -0
  78. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/sqs/template.ejs +17 -0
  79. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/api/data.js +57 -0
  80. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/api/request.json +0 -0
  81. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/api/template.ejs +138 -0
  82. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/dsq/data.js +58 -0
  83. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/dsq/request.json +0 -0
  84. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/dsq/template.ejs +183 -0
  85. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/inv/data.js +59 -0
  86. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/inv/request.json +0 -0
  87. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/inv/template.ejs +125 -0
  88. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/sqs/data.js +59 -0
  89. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/sqs/request.json +0 -0
  90. package/src/reStructure/TemplateData/relationshipPerAction/get/action/handler/sqs/template.ejs +163 -0
  91. package/src/reStructure/TemplateData/relationshipPerAction/get/action/mainFunction/data.js +59 -0
  92. package/src/reStructure/TemplateData/relationshipPerAction/get/action/mainFunction/template.ejs +322 -0
  93. package/src/reStructure/TemplateData/relationshipPerAction/get/action/sns-in-sqs/data.js +77 -0
  94. package/src/reStructure/TemplateData/relationshipPerAction/get/action/sns-in-sqs/snsTemplate.ejs +59 -0
  95. package/src/reStructure/TemplateData/relationshipPerAction/get/action/sns-in-sqs/sqsTemplate.ejs +43 -0
  96. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/functionYaml/data.js +110 -0
  97. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/functionYaml/request.json +0 -0
  98. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/functionYaml/template.ejs +20 -0
  99. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/handler/sqs/data.js +60 -0
  100. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/handler/sqs/request.json +0 -0
  101. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/handler/sqs/template.ejs +125 -0
  102. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/mainFunction/data.js +55 -0
  103. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/mainFunction/request.json +0 -0
  104. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/mainFunction/template.ejs +141 -0
  105. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/sns-in-sqs/data.js +71 -0
  106. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/sns-in-sqs/request.json +0 -0
  107. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/sns-in-sqs/template.ejs +47 -0
  108. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/sns-out/data.js +71 -0
  109. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/sns-out/request.json +0 -0
  110. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/sns-out/template.ejs +10 -0
  111. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/api/data.js +25 -22
  112. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/dsq/data.js +25 -5
  113. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/inv/data.js +26 -5
  114. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/sqs/data.js +25 -4
  115. package/src/reStructure/TemplateData/relationshipPerAction/update/action/handler/api/template.ejs +1 -1
  116. package/src/reStructure/TemplateData/relationshipPerAction/update/action/handler/dsq/template.ejs +2 -2
  117. package/src/reStructure/TemplateData/relationshipPerAction/update/action/handler/inv/template.ejs +1 -1
  118. package/src/reStructure/TemplateData/relationshipPerAction/update/action/handler/sqs/template.ejs +2 -2
  119. package/src/reStructure/TemplateData/relationshipPerAction/update/action/mainFunction/template.ejs +55 -7
  120. package/src/reStructure/TemplateData/resourceYaml/dynamodb/defaultDynamoDbTable.js +50 -42
  121. package/src/reStructure/TemplateData/resourceYaml/dynamodb/generateDynamoPerLink.js +98 -0
  122. package/src/reStructure/TemplateData/resourceYaml/dynamodb/mainResourcePerObjectSchemaData.js +4 -5
  123. package/src/reStructure/TemplateData/resourceYaml/dynamodb/template.ejs +1 -1
  124. package/src/reStructure/TemplateData/resourceYaml/generateTemplateData.js +11 -2
  125. package/src/reStructure/TemplateData/testTemplate/data.js +27 -0
  126. package/src/reStructure/TemplateData/testTemplate/template.ejs +5 -0
  127. /package/src/reStructure/TemplateData/attributeTreeSchema/mainAttributeTreeSchema/{attributeLink.ejs → attributeLinkTemplate.ejs} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@izara_project/izara-market-library-service-schemas",
3
- "version": "1.0.27",
3
+ "version": "1.0.28",
4
4
  "description": "Schemas for Izara Market project",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -20,15 +20,19 @@
20
20
  "testEnvironment": "node"
21
21
  },
22
22
  "dependencies": {
23
- "@izara_project/izara-core-library-core": "^1.0.16",
23
+ "@izara_project/izara-core-library-core": "^1.0.18",
24
24
  "@izara_project/izara-core-library-external-request": "^1.0.17",
25
- "@izara_project/izara-core-library-service-schemas": "^1.0.47",
25
+ "@izara_project/izara-core-library-service-schemas": "^1.0.48",
26
26
  "@izara_project/izara-shared": "^1.0.125",
27
- "@izara_project/izara-shared-service-schemas": "^1.0.4",
27
+ "@izara_project/izara-shared-service-schemas": "^1.0.5",
28
+ "@izara_project/izara-core-library-sns": "^1.0.3",
29
+ "@izara_project/izara-core-library-sqs": "^1.0.3",
30
+ "@izara_project/izara-core-library-calling-flow": "^1.0.2",
31
+ "@izara_project/izara-core-library-logger": "^1.0.6",
28
32
  "ejs": "^3.1.10",
29
33
  "js-beautify": "^1.15.4",
30
34
  "lodash": "^4.17.21",
31
35
  "object-hash": "^3.0.0",
32
- "yaml": "^2.7.0"
36
+ "yaml": "^2.7.1"
33
37
  }
34
38
  }
@@ -24,7 +24,8 @@ const PREFIX = {
24
24
  createRel: "createRelationshipEndpoint",
25
25
  deleteRel: "deleteRelationshipEndpoint",
26
26
  updateNode: "updateNodeEndpoint",
27
- createNode: "createNodeEndpoint"
27
+ createNode: "createNodeEndpoint",
28
+ getRel: "getRelationshipEndpoint"
28
29
  }
29
30
 
30
31
  const TOPIC_NAME_GRAPH_HANDLER = {
@@ -39,16 +40,18 @@ const TOPIC_NAME_GRAPH_HANDLER = {
39
40
  inCreateNode: "InCreateNodeV2",
40
41
  outCreateNode: "OutCreateNodeV2",
41
42
  inDeleteNode: "InDeleteNodeV2",
42
- outDeleteNode: "OutDeleteNodeV2"
43
+ outDeleteNode: "OutDeleteNodeV2",
43
44
  }
44
45
 
45
46
  const TOPIC_NAME_GENERATE_CODE = {
46
47
  updateRelComplete: "UpdateRelationshipComplete",
47
48
  createRelComplete: "CreateRelationshipComplete",
48
49
  deleteRelComplete: "DeleteRelationshipComplete",
50
+ getRelComplete: "GetRelationshipComplete",
49
51
  outUpdateRelComplete: "OutUpdateRelationshipComplete",
50
52
  outCreateRelComplete: "OutCreateRelationshipComplete",
51
53
  outDeleteRelComplete: "OutDeleteRelationshipComplete",
54
+ outGetRelComplete: "OutGetRelationshipComplete",
52
55
  updateNodeComplete: "UpdateNodeComplete",
53
56
  outUpdateNodeComplete: "OutUpdateNodeComplete",
54
57
  createNodeComplete: "CreateObjectComplete",
@@ -20,10 +20,10 @@ along with this program.If not, see < http://www.gnu.org/licenses/>.
20
20
  const lodash = require('lodash');
21
21
  const hash = require("object-hash")
22
22
 
23
- const sqsSharedLib = require('@izara_project/izara-shared/src/SqsSharedLib');
24
- const snsSharedLib = require('@izara_project/izara-shared/src/SnsSharedLib');
25
- const inMemoryCacheLib = require('@izara_project/izara-shared/src/InMemoryCacheLib');
26
- const callingFlowSharedLib = require('@izara_project/izara-shared/src/CallingFlowSharedLib');
23
+ const snsSharedLib = require('@izara_project/izara-core-library-sns');
24
+ const sqsSharedLib = require('@izara_project/izara-core-library-sqs');
25
+ const inMemoryCacheLib = require('@izara_project/izara-core-library-core').inMemoryCacheLib;
26
+ const callingFlowSharedLib = require('@izara_project/izara-core-library-calling-flow');
27
27
 
28
28
  const sns = require('@izara_project/izara-core-library-external-request/src/resources/Sns');
29
29
  const sqs = require('@izara_project/izara-core-library-external-request/src/resources/Sqs');
@@ -564,7 +564,7 @@ async function generateDynamoDbIdentifiers(_izContext, objectSchema, reqIdentifi
564
564
  * @param {Object} objectSchema
565
565
  * @param {Object} reqIdentifiers - input identifier from calling function
566
566
  */
567
- const generateDynamoDbIdentifiersWithCache = inMemoryCacheLib.inMemoryCacheLib(
567
+ const generateDynamoDbIdentifiersWithCache = inMemoryCacheLib(
568
568
  generateDynamoDbIdentifiers, // fn
569
569
  { // setting
570
570
  max: 20, maxAge: 86400000, promise: true, profileName: 'generateDynamoDbIdentifiers',
@@ -244,7 +244,9 @@ const FUNCTION_NAME = {
244
244
  deleteNodeComplete: "deleteNodeComplete",
245
245
  createObjectS3: "createObjectS3",
246
246
  createObjectS3Complete: "webSocketTaskComplete",
247
- processAfterUploadS3: "processAfterUploadS3"
247
+ processAfterUploadS3: "processAfterUploadS3",
248
+ getRel: "getRelationship",
249
+ getRelComplete: "getRelationshipComplete"
248
250
  };
249
251
 
250
252
  const SHORT_FUNCTION_NAME = {
@@ -266,6 +268,8 @@ const SHORT_FUNCTION_NAME = {
266
268
  deleteNode: "deleteNode",
267
269
  deleteNodeComplete: "deleteNodeComp",
268
270
  createObjectS3Complete: "webSocketTaskComp",
271
+ getRel: "getRel",
272
+ getRelComplete: "getRelComp"
269
273
  }
270
274
 
271
275
  const getGraphServiceNameFromAllRelSchema = async (_izContext, allRelSchemas) => {
@@ -452,6 +456,42 @@ const PREFIX_RELATIONSHIP = {
452
456
  disabled: "disabled"
453
457
  }
454
458
 
459
+ function checkDynamoTypeRelationship(relationship) {
460
+ let relaitonshipTag;
461
+ let links;
462
+ for (const [relTag, relProperties] of Object.entries(relationship)) {
463
+ relaitonshipTag = relTag
464
+ for (const [storageResourceTag, storageResource] of Object.entries(relProperties.storageResources)) {
465
+ if (storageResource.storageType === STORAGE_TYPES.dynamoDB) {
466
+ for (const link of relProperties.links) {
467
+ if (link.storageResourceTags.includes(storageResourceTag)) {
468
+ links = relProperties.links
469
+ }
470
+ }
471
+ }
472
+ }
473
+ }
474
+ return [relaitonshipTag, links];
475
+ }
476
+ function createDynamoDbComponentByLinks(link, relationshipTag) {
477
+ let tableNameFrom = `${link.from.objType.serviceTag}_${link.from.objType.objectType}__${relationshipTag}__${link.to.objType.serviceTag}_${link.to.objType.objectType}`
478
+ let tableNameTo = `${link.to.objType.serviceTag}_${link.to.objType.objectType}__${relationshipTag}__${link.from.objType.serviceTag}_${link.from.objType.objectType}`
479
+
480
+ let identifiersConcatFrom = `${link.from.objType.serviceTag}_${link.from.objType.objectType}__identifiersConcat`
481
+ let identifiersConcatTo = `${link.to.objType.serviceTag}_${link.to.objType.objectType}__identifiersConcat`
482
+
483
+ let resourceNameFrom = `${upperCase(link.from.objType.objectType) + upperCase(link.to.objType.objectType)}Relationship`
484
+ let resourceNameTo = `${upperCase(link.to.objType.objectType) + upperCase(link.from.objType.objectType)}Relationship`
485
+ return {
486
+ tableNameFrom,
487
+ tableNameTo,
488
+ identifiersConcatFrom,
489
+ identifiersConcatTo,
490
+ resourceNameFrom,
491
+ resourceNameTo
492
+ }
493
+ }
494
+
455
495
  module.exports = {
456
496
  ACTIONS,
457
497
  DEFAULT_HANDLER_PER_ACTION,
@@ -482,5 +522,7 @@ module.exports = {
482
522
  FIELD_NAME_TPYE,
483
523
  ADD_ON_DATA_STRUCTURE_TYPE,
484
524
  ATTRIBUTE_TAG,
485
- PREFIX_RELATIONSHIP
525
+ PREFIX_RELATIONSHIP,
526
+ checkDynamoTypeRelationship,
527
+ createDynamoDbComponentByLinks
486
528
  }
@@ -121,10 +121,6 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
121
121
 
122
122
  // generate all source
123
123
  for (let item of allCreateSource) {
124
- if (item.setting.initialData) {
125
- console.log("setting::", item.setting)
126
- console.log("templatePath::", item.templatePath)
127
- }
128
124
  // throw error if item is invalid
129
125
  if (!item || !item.templatePath || !item.templateData || !item.setting) {
130
126
  console.log('Throwing invalid source item:', item);
@@ -28,6 +28,8 @@ const { createSource } = require("../SourceManager/src/CreateSource");
28
28
 
29
29
  const { SOURCE_PATH } = require('../TemplateManager/src/libs/Consts');
30
30
 
31
+ const { validatePathWithRootServicePath } = require("./libs/GenerateCodeLibs");
32
+
31
33
 
32
34
 
33
35
  async function generateSchema(_izContext, objSchemaPath, generateSchemaSettings) {
@@ -48,7 +50,7 @@ async function generateSchema(_izContext, objSchemaPath, generateSchemaSettings)
48
50
  // collect all result of template data for execute createSource
49
51
  let allCreateSource = [];
50
52
  // collect all path that need to empty before createSource
51
- let allEmptyPath = [];
53
+ let allEmptyPath = new Set();
52
54
 
53
55
 
54
56
  // Validate that all generateNames in generateSettings are present in the schemaConfig
@@ -65,9 +67,17 @@ async function generateSchema(_izContext, objSchemaPath, generateSchemaSettings)
65
67
 
66
68
 
67
69
  // start create generateSchema depend on
68
- for (const { generateName, settingData } of generateSchemaSettings) {
69
- let generateSchemaData = require(join(__dirname, schemaConfig.TemplateAndData[generateName]));
70
- let createSourceResult = await generateSchemaData(_izContext, objSchemaPath, settingData);
70
+ for (const generateSetting of generateSchemaSettings) {
71
+ console.log('Loading template:', generateSetting.generateName);
72
+ console.log('Setting data:', generateSetting);
73
+ console.log('schemaPath:', schemaConfig.TemplateAndData[generateSetting.generateName]);
74
+ console.log('schemaPath:', join(__dirname, schemaConfig.TemplateAndData[generateSetting.generateName]));
75
+
76
+ // get generateSchema template depend on generateName
77
+ let generateSchemaData = require(join(__dirname, schemaConfig.TemplateAndData[generateSetting.generateName]));
78
+ console.log("generateSchemaData: ", generateSchemaData);
79
+
80
+ let createSourceResult = await generateSchemaData(_izContext, objSchemaPath, generateSetting);
71
81
 
72
82
  // Filter out empty or invalid objects before adding to allCreateSource
73
83
  if (Array.isArray(createSourceResult)) {
@@ -78,6 +88,7 @@ async function generateSchema(_izContext, objSchemaPath, generateSchemaSettings)
78
88
  }
79
89
  }
80
90
 
91
+
81
92
  // check each allCreateSource valid
82
93
  for (let item of allCreateSource) {
83
94
  // throw Error('Skipping invalid source item:', item);
@@ -99,11 +110,12 @@ async function generateSchema(_izContext, objSchemaPath, generateSchemaSettings)
99
110
  throw Error(errors);
100
111
  }
101
112
 
102
- allEmptyPath.push(returnEmptyPath);
113
+ allEmptyPath.add(setting.savePath);
103
114
  }
104
115
 
105
116
  // validate path before empty folder
106
117
  for (let emptyPath of allEmptyPath) {
118
+ console.log("emptyPath: ", emptyPath);
107
119
  validatePathWithRootServicePath(localServicePath, emptyPath)
108
120
  }
109
121
 
@@ -13,14 +13,15 @@ GNU Affero General Public License for more details.
13
13
 
14
14
  You should have received a copy of the GNU Affero General Public License
15
15
  along with this program. If not, see <http://www.gnu.org/licenses/>.
16
- */
16
+ */
17
17
 
18
18
  'use strict';
19
19
 
20
20
  module.exports = {
21
21
  TemplateAndData: {
22
22
  // ** mock schema config **
23
- mainAttributeTree: './TemplateData/mainAttributeTree/generateTemplateData.js',
23
+ mainAttributeTree: './TemplateData/attributeTreeSchema/generateTemplateData.js',
24
+ test: './TemplateData/testTemplate/data.js',
24
25
  },
25
26
  Plugin: {
26
27
 
@@ -18,10 +18,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
18
18
  'use strict';
19
19
 
20
20
  // Import required modules
21
+ console.log("generate main attri ");
21
22
  const { join } = require('path');
22
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
+
23
34
  const modules = {
24
- mainAttributeTreeSchema: {}
35
+ mainAttributeTreeSchema: require('./mainAttributeTreeSchema/data')
25
36
  }
26
37
  /**
27
38
  * Generates code with templates for different actions
@@ -29,9 +40,52 @@ const modules = {
29
40
  * @param {string} objSchemaPath - Path to the schema
30
41
  * @returns {Array} Array of generated code parameters
31
42
  */
32
- async function generateCodeWithTemplate(_izContext, objSchemaPath) {
43
+ async function generateCodeWithTemplate(_izContext, objSchemaPath, settings) {
33
44
  try {
34
- const saveFilePath = join(objSchemaPath, '../');
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
+ }
35
89
 
36
90
 
37
91
  // will receive objSchemaPath and prepare params for each data function
@@ -40,9 +94,7 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
40
94
  // (template, data, { savePath, hookPath, saveFileName, fileExtension, initialData, isAppend = false, checkCreateSourcePass = false })
41
95
 
42
96
 
43
- return {
44
-
45
- };
97
+ return allCreateSource;
46
98
  } catch (error) {
47
99
  _izContext.logger.error('Error generating code with template perActionComplete:', error);
48
100
  return [];
@@ -16,112 +16,172 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
  */
17
17
 
18
18
  'use strict';
19
+
20
+ console.log("data main attribute tree schema");
21
+
19
22
  const path = require('path');
20
23
  const fs = require('fs');
21
24
 
25
+ const serviceSchemaCore = require("@izara_project/izara-core-library-service-schemas");
26
+ const getObjectSchema = serviceSchemaCore.getObjectSchema;
27
+
28
+
22
29
  const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../MainLibs/src/Utils");
23
- const { SOURCE_PATH, ADD_ON_DATA_STRUCTURE_TYPE, ATTRIBUTE_TAG, fieldNameSetting, FIELD_NAME_TPYE, SAVE_FILE_NAME } = require('../../libs/Consts');
24
- const templatePath = path.join(__dirname, "./template.ejs");
25
-
26
- function data(_izContext, objectSchema, srcPath) {
27
- const createSources = [];
28
- let attributeTreeObjSchemas = [];
29
- if (objectSchema.hasOwnProperty("addOnDataStructure")) {
30
- for (const versionedData of objectSchema.addOnDataStructure) {
31
- if (versionedData.type === ADD_ON_DATA_STRUCTURE_TYPE.attributeTree) {
32
- const objectType = objectSchema.objectType; // main objectType
33
- const storageResources = objectSchema.storageResources // storageResource from main objectType
34
- const storageResourceTag = Object.keys(storageResources) // storage ResourceTag from main objectType
35
- const compositeKeyDeliminator = objectSchema.compositeKeyDeliminator
36
- attributeTreeObjSchemas.push(
37
- {
38
- objectType: objectType + ATTRIBUTE_TAG.attributeTagLabel,
39
- fieldNames: {
40
- labelId: fieldNameSetting(FIELD_NAME_TPYE.identifiers)
41
- },
42
- identifiers: [
43
- {
44
- type: "identifier",
45
- fieldName: "labelId"
46
- }
47
- ]
48
- },
49
- {
50
- objectType: objectType + ATTRIBUTE_TAG.attributeTagLink,
51
- fieldNames: {
52
- [objectType + ATTRIBUTE_TAG.attributeTagLink + "Id"]: fieldNameSetting(FIELD_NAME_TPYE.identifiers),
53
- [objectType + "Id"]: fieldNameSetting(FIELD_NAME_TPYE.requiredOnCreateFieldName),
54
- topLevelParentIdentifierProperties: fieldNameSetting(FIELD_NAME_TPYE.requiredOnCreateFieldName),
55
- parentNodeIdentifierLabel: fieldNameSetting(FIELD_NAME_TPYE.requiredOnCreateFieldName),
56
- parentNodeIdentifierProperties: fieldNameSetting(FIELD_NAME_TPYE.requiredOnCreateFieldName),
57
- },
58
- identifiers: [
59
- {
60
- type: "identifier",
61
- fieldName: `${objectType + ATTRIBUTE_TAG.attributeTagLink}Id`
62
- }
63
- ]
64
- },
65
- {
66
- objectType: objectType + ATTRIBUTE_TAG.attributeTagProperty,
67
- fieldNames: {
68
- propertyId: fieldNameSetting(FIELD_NAME_TPYE.identifiers),
69
- propertyLabelId: fieldNameSetting(FIELD_NAME_TPYE.optionalOnCreate)
70
- },
71
- identifiers: [
72
- {
73
- type: "identifier",
74
- fieldName: "propertyId"
75
- }
76
- ]
77
- },
78
- {
79
- objectType: objectType + ATTRIBUTE_TAG.attributeTagPropertyLabel,
80
- fieldNames: {
81
- propertyLabelId: fieldNameSetting(FIELD_NAME_TPYE.identifiers)
82
- },
83
- identifiers: [
84
- {
85
- type: "identifier",
86
- fieldName: "propertyLabelId"
87
- }
88
- ]
89
- }
90
- )
91
- for (let attributeTreeObjSchema of attributeTreeObjSchemas) {
92
- Object.assign(attributeTreeObjSchema, {
93
- storageResources: storageResources, // add storageResources
94
- compositeKeyDeliminator: compositeKeyDeliminator
95
- })
96
- for (let attributeTreeFieldName of Object.values(attributeTreeObjSchema.fieldNames)) {
97
- Object.assign(attributeTreeFieldName, { storageResourceTags: storageResourceTag }) // add storageResourceTags for each fieldName
98
- }
99
- }
100
- }
101
-
102
- }
103
- // console.log("attributeTreeObjSchemas", attributeTreeObjSchemas)
104
- for (const attributeTreeObjSchema of attributeTreeObjSchemas) {
105
- createSources.push({
106
- templatePath: templatePath,
107
- templateData: {
108
- fieldNames: JSON.stringify(attributeTreeObjSchema.fieldNames),
109
- identifiers: JSON.stringify(attributeTreeObjSchema.identifiers),
110
- objectType: attributeTreeObjSchema.objectType,
111
- storageResources: JSON.stringify(attributeTreeObjSchema.storageResources),
112
- compositeKeyDeliminator: attributeTreeObjSchema.compositeKeyDeliminator
113
- },
114
- setting: {
115
- savePath: path.join(srcPath, SOURCE_PATH.generatedAttributeTree, attributeTreeObjSchema.objectType + "/"),
116
- hookPath: path.join(srcPath, "schemaHook", attributeTreeObjSchema.objectType, "/"),
117
- saveFileName: SAVE_FILE_NAME.attributeTreeObjectSchema,
118
- fileExtension: ".js",
119
- isAppend: false
120
- }
121
- })
122
- }
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");
123
55
  }
124
- console.log("createSources", createSources)
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)
125
185
  return createSources;
126
186
  }
127
187
 
@@ -18,10 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
18
18
  'use strict';
19
19
 
20
20
  const Logger = require('@izara_project/izara-core-library-logger')
21
- const izaraShared = require('@izara_project/izara-shared')
22
- const dynamodbSharedLib = izaraShared.dynamodbSharedLib
23
- const lambdaSharedLib = izaraShared.lambdaSharedLib
24
- const snsSharedLib = izaraShared.snsSharedLib
21
+ const dynamodbSharedLib = require('@izara_project/izara-core-library-dynamodb')
22
+ const lambdaSharedLib = require('@izara_project/izara-core-library-lambda')
23
+ const snsSharedLib = require('@izara_project/izara-core-library-sns')
25
24
  const initialSetupConfig = require('../../config/Config') // config external serviceName
26
25
  const basicNodeSchemaLib = require('@izara_project/izara-attribute-tree').basicNodeSchemaLib
27
26
  const _izContext = {logger : Logger}
@@ -22,7 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
22
22
 
23
23
  const izara = require("@izara_project/izara-middleware");
24
24
  const middleware = izara.middlewareHandler;
25
- const recordHandlerSharedLib = require("@izara_project/izara-shared").recordHandlerSharedLib;
25
+ const recordHandlerSharedLib = require("@izara_project/izara-core-library-record-handler");
26
26
  const Logger = require('@izara_project/izara-core-library-logger');
27
27
 
28
28
  const findData = require('./FindData_Main');
@@ -18,9 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
18
18
  'use strict';
19
19
 
20
20
  const izaraShared = require("@izara_project/izara-shared");
21
- const findDataSharedLib = izaraShared.findDataSharedLib;
22
- const graphSharedLib = izaraShared.graphSharedLib;
23
- const dynamodbSharedLib = izaraShared.dynamodbSharedLib;
21
+ const findDataSharedLib = require('@izara_project/izara-core-library-find-data');
22
+ const graphSharedLib = require('@izara_project/izara-core-library-graph-service');
23
+ const dynamodbSharedLib = require('@izara_project/izara-core-library-dynamodb')
24
24
 
25
25
  const serviceSchemas = require('@izara_project/izara-core-library-service-schemas');
26
26
  const serviceConfig = serviceSchemas.serviceConfig;