@izara_project/izara-market-library-service-schemas 1.0.14 → 1.0.15

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@izara_project/izara-market-library-service-schemas",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "description": "Schemas for Izara Market project",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -20,10 +20,10 @@
20
20
  "testEnvironment": "node"
21
21
  },
22
22
  "dependencies": {
23
- "@izara_project/izara-core-library-core": "^1.0.13",
24
- "@izara_project/izara-core-library-external-request": "^1.0.14",
25
- "@izara_project/izara-core-library-service-schemas": "^1.0.25",
26
- "@izara_project/izara-shared": "^1.0.96",
23
+ "@izara_project/izara-core-library-core": "^1.0.14",
24
+ "@izara_project/izara-core-library-external-request": "^1.0.16",
25
+ "@izara_project/izara-core-library-service-schemas": "^1.0.32",
26
+ "@izara_project/izara-shared": "^1.0.113",
27
27
  "ejs": "^3.1.10",
28
28
  "js-beautify": "^1.15.1",
29
29
  "lodash": "^4.17.21",
@@ -44,12 +44,14 @@ const {
44
44
  generateDeliminatorTreeIdentifier,
45
45
  generateDeliminatorTreePerFieldName
46
46
  } = require('@izara_project/izara-core-library-service-schemas/src/libs/DeliminatorTree');
47
+ const Logger = require("@izara_project/izara-core-library-logger");
47
48
 
48
49
  const nodeLabelRegexPattern = "^[a-zA-Z0-9_-]+(?:\:[a-zA-Z0-9_-]+)?$"
49
50
 
50
51
  const RETURN_GET_DATA_FORMAT = {
51
52
  std: "STD", // { identifiers:{...}, fields:{...}} , data depend on getDataDetails
52
53
  full: "FULL", // {storageTag:{...getResult from database}}
54
+ onlyField: "ONLY_FIELD" // {graphHandler only return main fieldName (not versionedData) }
53
55
  }
54
56
 
55
57
  const schemaFunctionPerAction = {
@@ -76,8 +78,6 @@ const explodeDataPerAction = {
76
78
  * @param {middleware} middleware
77
79
  * @param {string} objectType - name of ObjectType
78
80
  * @param {string} action - action type of Lambda create | update | get | delete
79
- * @param {object} [setting]
80
- * @param {string[]} [setting.specificFieldNames] - optional - specific fieldNames use as param in generateValidatorFunction
81
81
  */
82
82
  function validateSchemaMiddleware(
83
83
  middleware,
@@ -89,13 +89,14 @@ function validateSchemaMiddleware(
89
89
  if (!schemaFunctionPerAction[action] || !explodeDataPerAction[action]) {
90
90
  throw new NoRetryError(`Not found function for generateValidatorSchema or explodeDataPerAction of action:${action}`);
91
91
  }
92
-
92
+ Logger.debug("setting in generateCodeLibs", setting)
93
93
  middleware.setServiceSchema(
94
94
  schemaFunctionPerAction[action],
95
95
  explodeDataPerAction[action],
96
96
  {
97
97
  objectType: objectType,
98
- specificFieldNames: setting.specificFieldNames ? setting.specificFieldNames : []
98
+ specificFieldNames: setting?.specificFieldNames ? setting.specificFieldNames : [],
99
+ action: action
99
100
  },
100
101
  );
101
102
  }
@@ -116,7 +117,7 @@ async function validateSchemaPerRecord(
116
117
  lambdaFunctionName,
117
118
  objType,
118
119
  action, // action
119
- setting = {}
120
+ setting
120
121
  ) {
121
122
  try {
122
123
  record._izContext.logger.debug("validateSchemaPerRecord: ", record,
@@ -135,14 +136,15 @@ async function validateSchemaPerRecord(
135
136
  const generateValidatorFunction = schemaFunctionPerAction[action];
136
137
  const explodeDataFunction = explodeDataPerAction[action]
137
138
 
138
- const generatedSchema = await generateValidatorFunction(record._izContext, objType, setting.specificFieldNames);
139
+ const generatedSchema = await generateValidatorFunction(record._izContext, objType, setting);
139
140
  record._izContext.logger.debug(`generatedSchema in validateSchemaPerRecord : `, generatedSchema);
140
141
 
141
142
 
142
143
  const explodedDataRequestParams = await explodeDataFunction(
143
144
  record._izContext,
144
145
  record.body.Message,
145
- objectSchema
146
+ objectSchema,
147
+ setting
146
148
  );
147
149
 
148
150
 
@@ -214,7 +216,7 @@ async function messageToDlq(record, messageFailError, queueUrl) {
214
216
 
215
217
  record._izContext.logger.debug('messageToDlq, params before sending DLQ', params);
216
218
 
217
- sqs.sendMessage(record._izContext, params);
219
+ await sqs.sendMessage(record._izContext, params);
218
220
  record._izContext.logger.debug("----- messageToDlq sendMessage success -----");
219
221
  };
220
222
 
@@ -502,16 +504,16 @@ const generateDynamoDbIdentifiersWithCache = inMemoryCacheLib.inMemoryCacheLib(
502
504
  *
503
505
  * @param {Object} _izContext
504
506
  * @param {Object} objectSchema
505
- * @param {Object} getDataDetail
507
+ * @param {Object} dynamoStorageResource
506
508
  * @param {Object} reqIdentifiers
507
509
  */
508
- async function dynamoDbIdentifiersByStorageResource(_izContext, objectSchema, getDataDetail, reqIdentifiers) {
510
+ async function dynamoDbIdentifiersByStorageResource(_izContext, objectSchema, dynamoStorageResource, reqIdentifiers) {
509
511
 
510
512
  let dynamoIdentifiers = await generateDynamoDbIdentifiersWithCache(_izContext, objectSchema, reqIdentifiers)
511
513
 
512
514
  let identifiersByStorageResource = {};
513
515
 
514
- if (getDataDetail.groupByPartitionKeyField) {
516
+ if (dynamoStorageResource.groupByPartitionKeyField) {
515
517
 
516
518
  let deliminatorTreeIdentifiers = await generateDeliminatorTreeIdentifier(_izContext, objectSchema);
517
519
  _izContext.logger.debug("deliminatorTree: ", deliminatorTreeIdentifiers);
@@ -538,7 +540,7 @@ async function dynamoDbIdentifiersByStorageResource(_izContext, objectSchema, ge
538
540
  let newIdentifierValue = sortedIdentifiersValue.join(compositeKeyDeliminator.repeat(currentDeliminatorAmount + 1));
539
541
 
540
542
  identifiersByStorageResource = {
541
- [getDataDetail.groupByPartitionKeyField]: newIdentifierValue
543
+ [dynamoStorageResource.groupByPartitionKeyField]: newIdentifierValue
542
544
  };
543
545
 
544
546
  } else {
@@ -717,7 +719,10 @@ async function createUpdateDataDetail(_izContext, objectSchema) {
717
719
  let storageFieldNames = [];
718
720
  for (let [fieldName, fieldNameProperties] of Object.entries(objectSchema.fieldNames)) {
719
721
  if (fieldNameProperties.storageResourceTags.includes(storageTag)) {
720
- storageFieldNames.push(fieldName)
722
+ let versionedDataLabel = fieldNameProperties.versionedDataLabel
723
+ if (!fieldName.includes(versionedDataLabel)) { // not get fieldNames VersionedData_VersionedDataLabel_VersionedDataFieldNames
724
+ storageFieldNames.push(fieldName)
725
+ }
721
726
  }
722
727
  }
723
728
  if (storageProperties.storageType === consts.STORAGE_TYPES.graph) {
@@ -764,10 +769,8 @@ async function createUpdateDataDetail(_izContext, objectSchema) {
764
769
 
765
770
  _izContext.logger.debug("getGraphDataDetails", getGraphDataDetails);
766
771
  _izContext.logger.debug("getDynamoDataDetail", getDynamoDbDataDetails);
767
- _izContext.logger.debug("allUpdateDataDetail", allUpdateDataDetail)
768
-
769
- Object.assign(allUpdateDataDetail, getDynamoDbDataDetails, getGraphDataDetails)
770
772
 
773
+ Object.assign(allUpdateDataDetail, getDynamoDbDataDetails, getGraphDataDetails);
771
774
  return allUpdateDataDetail
772
775
  }
773
776
 
@@ -791,13 +794,13 @@ async function createDataDetailsLib(
791
794
  if (Object.keys(objectSchemas.fieldNames).length == 1) {
792
795
 
793
796
  for (const storageIdentifiers of settingFieldName.storageResourceTags) {
794
- _izContext.logger.debug("case only 1 fieldNames identifiers in ObjectSchema")
797
+ // _izContext.logger.debug("case only 1 fieldNames identifiers in ObjectSchema")
795
798
  if (storageResources[storageIdentifiers].storageType === consts.STORAGE_TYPES.dynamoDB) {
796
799
  if (createDataDetails.hasOwnProperty(storageIdentifiers)) {
797
- _izContext.logger.debug("same table")
800
+ // _izContext.logger.debug("same table")
798
801
  createDataDetails[storageIdentifiers].fieldNames.push(keyFieldName);
799
802
  } else {
800
- _izContext.logger.debug("new table")
803
+ // _izContext.logger.debug("new table")
801
804
  Object.assign(createDataDetails, {
802
805
  [storageResources[storageIdentifiers]]: {
803
806
  storageType: consts.STORAGE_TYPES.dynamoDB,
@@ -835,23 +838,23 @@ async function createDataDetailsLib(
835
838
  }
836
839
  continue
837
840
  };
838
- _izContext.logger.debug("case multiple fieldName");
841
+ // _izContext.logger.debug("case multiple fieldName");
839
842
  // validate storageResourceTags.
840
- _izContext.logger.debug("storageResourceTags is", settingFieldName.storageResourceTags);
843
+ // _izContext.logger.debug("storageResourceTags is", settingFieldName.storageResourceTags);
841
844
 
842
845
  for (let eachStorageResourceTag of settingFieldName.storageResourceTags) {
843
- _izContext.logger.debug("Loop eachStorageResourceTags", eachStorageResourceTag);
846
+ // _izContext.logger.debug("Loop eachStorageResourceTags", eachStorageResourceTag);
844
847
 
845
848
  if (!storageResources.hasOwnProperty(eachStorageResourceTag)) {
846
849
  throw new Error("storageResources is'n exist"); // should be validata in step uplode in s3
847
850
  } else {
848
851
  if (storageResources[eachStorageResourceTag].storageType == consts.STORAGE_TYPES.dynamoDB) {
849
852
  if (createDataDetails.hasOwnProperty(eachStorageResourceTag)) {
850
- _izContext.logger.debug("SAME STG DB", eachStorageResourceTag);
853
+ // _izContext.logger.debug("SAME STG DB", eachStorageResourceTag);
851
854
  createDataDetails[eachStorageResourceTag].fieldNames.push(keyFieldName);
852
855
 
853
856
  } else {
854
- _izContext.logger.debug("NEW STG DB", eachStorageResourceTag);
857
+ // _izContext.logger.debug("NEW STG DB", eachStorageResourceTag);
855
858
  Object.assign(createDataDetails, {
856
859
  [eachStorageResourceTag]: {
857
860
  storageType: consts.STORAGE_TYPES.dynamoDB,
@@ -874,11 +877,11 @@ async function createDataDetailsLib(
874
877
  );
875
878
  if (checkGraphServerTags) {
876
879
  if (createDataDetails.hasOwnProperty(checkGraphServerTags)) {
877
- _izContext.logger.debug("SAME STG", checkGraphServerTags);
880
+ // _izContext.logger.debug("SAME STG", checkGraphServerTags);
878
881
  createDataDetails[checkGraphServerTags].fieldNames.push(keyFieldName)
879
882
 
880
883
  } else {
881
- _izContext.logger.debug("NEW STG", checkGraphServerTags);
884
+ // _izContext.logger.debug("NEW STG", checkGraphServerTags);
882
885
  Object.assign(createDataDetails, {
883
886
  [checkGraphServerTags]: {
884
887
  storageType: consts.STORAGE_TYPES.graph,
@@ -11,7 +11,8 @@ let getDataByGraph = await graphSharedLib.getNodeV2(
11
11
  graphHandlerServiceTag,
12
12
  objType,
13
13
  {
14
- identifiers: identifiers
14
+ ...identifiers,
15
+ ...fieldName
15
16
  },
16
17
  <%- JSON.stringify(versionedDataLabel) %>
17
18
  );
@@ -39,12 +39,15 @@ middleware.setValidatorSchema(
39
39
  //(</middlewareSettings>)
40
40
  )
41
41
 
42
+ /*
43
+ const perRecordsValidatorSchema = {
44
+ type: "object",
45
+ required: [],
46
+ properties: {},
47
+ }
48
+ */
49
+
42
50
  //(<globalValidatorSchema>)
43
- const perRecordsValidatorSchema = {
44
- type: "object",
45
- required: [],
46
- properties: {},
47
- }
48
51
  //(</globalValidatorSchema>)
49
52
 
50
53
  // if need to validate authorizer or additional params , add code to hook tag below
@@ -75,14 +78,14 @@ module.exports.main = middleware.wrap(async (event,context, callback) => {
75
78
  )
76
79
 
77
80
  //for validate additional params
81
+ /*
82
+ await recordHandlerSharedLib.validateRecord(
83
+ record,
84
+ "<%- functionName %><%- firstLetterUpperCase(handler) %>",
85
+ perRecordsValidatorSchema
86
+ );
87
+ */
78
88
  //(<afterGenerateValidatorSchema>)
79
- /*
80
- await recordHandlerSharedLib.validateRecord(
81
- record,
82
- "<%- functionName %><%- firstLetterUpperCase(handler) %>",
83
- perRecordsValidatorSchema
84
- );
85
- */
86
89
  //(</afterGenerateValidatorSchema>)
87
90
 
88
91
  //(<additionalParams>)
@@ -38,13 +38,14 @@ middleware.setValidatorSchema(
38
38
  //(<middlewareSettings>)
39
39
  //(</middlewareSettings>)
40
40
  )
41
-
41
+ /*
42
+ const perRecordsValidatorSchema = {
43
+ type: "object",
44
+ required: [],
45
+ properties: {},
46
+ }
47
+ */
42
48
  //(<globalValidatorSchema>)
43
- const perRecordsValidatorSchema = {
44
- type: "object",
45
- required: [],
46
- properties: {},
47
- }
48
49
  //(</globalValidatorSchema>)
49
50
 
50
51
  // if need to validate authorizer or additional params , add code to hook tag below
@@ -75,14 +76,14 @@ module.exports.main = middleware.wrap(async (event,context, callback) => {
75
76
  )
76
77
 
77
78
  //for validate additional params
79
+ /*
80
+ await recordHandlerSharedLib.validateRecord(
81
+ record,
82
+ "<%- functionName %><%- firstLetterUpperCase(handler) %>",
83
+ perRecordsValidatorSchema
84
+ );
85
+ */
78
86
  //(<afterGenerateValidatorSchema>)
79
- /*
80
- await recordHandlerSharedLib.validateRecord(
81
- record,
82
- "<%- functionName %><%- firstLetterUpperCase(handler) %>",
83
- perRecordsValidatorSchema
84
- );
85
- */
86
87
  //(</afterGenerateValidatorSchema>)
87
88
 
88
89
  //(<additionalParams>)
@@ -69,7 +69,6 @@ module.exports.<%- functionName %>Main = async (
69
69
  });
70
70
 
71
71
  let errorsFound = []
72
- _izContext.correlationIds.set(coreConsts.BASE_USER_ID,"BasDev");
73
72
  const userId = _izContext.correlationIds.get(coreConsts.BASE_USER_ID);
74
73
  if (!userId){
75
74
  errorsFound.push("not have userId");
@@ -84,8 +84,7 @@ module.exports.<%- functionName %>Main = async (
84
84
  _izContext.logger.debug("<%- functionName %> callingFlowConfig", callingFlowConfig)
85
85
 
86
86
  let errorFounds = [];
87
-
88
- _izContext.correlationIds.set(coreConsts.BASE_USER_ID, "BasDev");
87
+
89
88
  const userId = _izContext.correlationIds.get(coreConsts.BASE_USER_ID)
90
89
  if (!userId) {
91
90
  errorFounds.push("Not Have UserId")
@@ -96,11 +95,14 @@ module.exports.<%- functionName %>Main = async (
96
95
  //(<beforeQuery>)
97
96
  //(</beforeQuery>)
98
97
 
99
- const fields = requestParams.objInstanceFull.fields;
100
98
  const identifiers = requestParams.objInstanceFull.identifiers;
99
+ const fields = requestParams?.objInstanceFull?.fields || {};
100
+ const versionedDatas = requestParams?.objInstanceFull?.versionedDatas || {};
101
+
101
102
  _izContext.logger.debug("explode requestParams", {
103
+ identifiers: identifiers,
102
104
  fields: fields,
103
- identifiers: identifiers
105
+ versionedDatas: versionedDatas
104
106
  })
105
107
  let objectSchema = await getObjSchemaS3WithHierarchy(
106
108
  _izContext,
@@ -128,7 +130,8 @@ module.exports.<%- functionName %>Main = async (
128
130
  },
129
131
  objInstanceFull: {
130
132
  identifiers: identifiers,
131
- fields: fields
133
+ fields: fields,
134
+ versionedDatas: versionedDatas
132
135
  },
133
136
  status: 'error',
134
137
  errorFounds: errorFounds
@@ -166,6 +169,7 @@ module.exports.<%- functionName %>Main = async (
166
169
  serviceTag: SERVICE_TAG,
167
170
  identifiers: identifiers,
168
171
  fields: fields,
172
+ versionedDatas: versionedDatas
169
173
  // correlationIds: _izContext.correlationIds.get("id")
170
174
  }),
171
175
  PREFIX.updateNode
@@ -181,7 +185,8 @@ module.exports.<%- functionName %>Main = async (
181
185
  hash(
182
186
  {
183
187
  identifiers,
184
- fields
188
+ fields,
189
+ versionedDatas: versionedDatas
185
190
  })
186
191
  )
187
192
  )
@@ -195,7 +200,8 @@ module.exports.<%- functionName %>Main = async (
195
200
  },
196
201
  objInstanceFull: {
197
202
  identifiers: identifiers,
198
- fields: fields
203
+ fields: fields,
204
+ versionedDatas: versionedDatas
199
205
  },
200
206
  originTimestamp
201
207
  }
@@ -205,8 +211,7 @@ module.exports.<%- functionName %>Main = async (
205
211
  callingFlowSharedLib.addParentCallingFlowConfig(
206
212
  callingFlowConfig,
207
213
  callingFlowSharedLib.createCallingFlowConfig(
208
- await lambdaSharedLib.lambdaFunctionName(_izContext, TOPIC_NAME_GENERATE_CODE.updateNodeComplete),
209
- {}
214
+ await lambdaSharedLib.lambdaFunctionName(_izContext, TOPIC_NAME_GENERATE_CODE.updateNodeComplete), {}
210
215
  )
211
216
  )
212
217
  )
@@ -254,7 +259,8 @@ module.exports.<%- functionName %>Main = async (
254
259
  },
255
260
  objInstanceFull: {
256
261
  identifiers: identifiers,
257
- fields: fields
262
+ fields: fields,
263
+ versionedData: versionedData
258
264
  }
259
265
  },
260
266
  status: "complete",
@@ -167,7 +167,7 @@ module.exports.processLogical = async (
167
167
  _izContext.logger.debug("Have errorsFound: ", errorsFound)
168
168
  standardErrorParams.push(errorsFound)
169
169
  await logicalResultsSharedLib.completeLogicalResultsMain(...standardErrorParams);
170
- return;
170
+ return errorsFound;
171
171
  }
172
172
 
173
173
  const graphHandlerServiceTag = await serviceConfig.getGraphServiceTagWithCache(
@@ -347,7 +347,7 @@ module.exports.processLogical = async (
347
347
  errorsFound.push(`can't find data in table ${tableName} by query`)
348
348
  standardErrorParams.push(errorsFound)
349
349
  await logicalResultsSharedLib.completeLogicalResultsMain(...standardErrorParams);
350
- return;
350
+ return errorsFound;
351
351
  }
352
352
 
353
353
  for (const objInstanceBase of queryDatas.Items) {