@izara_project/izara-core-library-service-schemas 1.0.76 → 1.0.78
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 +6 -6
- package/src/Consts.js +1 -1
- package/src/GetObjectSchema.js +59 -56
- package/src/IdentifiersObject.js +27 -25
- package/src/ServiceConfig.js +4 -2
- package/src/SharedUtils.js +16 -11
- package/src/UploadObjSchema.js +38 -22
- package/src/Utils.js +2 -2
- package/src/ValidatorSchema.js +56 -52
- package/src/libs/CreateNodeLib.js +8 -8
- package/src/libs/DeliminatorTree.js +14 -12
- package/src/libs/ExplodedReqParams.js +17 -15
- package/src/libs/RelSchemaLib.js +5 -4
- package/src/libs/UploadUseCase.js +4 -0
- package/src/libs/s3Utils.js +4 -2
package/src/SharedUtils.js
CHANGED
|
@@ -77,7 +77,8 @@ async function _processNodeRelationships(
|
|
|
77
77
|
newLinkRelSchema,
|
|
78
78
|
storageResourceTags,
|
|
79
79
|
objectRelationships,
|
|
80
|
-
relationshipSchema
|
|
80
|
+
relationshipSchema,
|
|
81
|
+
bucketName
|
|
81
82
|
) {
|
|
82
83
|
const { node, isBase, relationshipDirection } = nodeConfig;
|
|
83
84
|
const results = [];
|
|
@@ -86,7 +87,7 @@ async function _processNodeRelationships(
|
|
|
86
87
|
|
|
87
88
|
// Get object relationships from S3
|
|
88
89
|
const getObjRelPathParam = {
|
|
89
|
-
Bucket: OBJECT_SCHEMA_BUCKET_NAME,
|
|
90
|
+
Bucket: bucketName ? bucketName : OBJECT_SCHEMA_BUCKET_NAME,
|
|
90
91
|
Key: UPLOAD_PATH_S3.objectRelationship(_izContext, node.objType)
|
|
91
92
|
};
|
|
92
93
|
_izContext.logger.debug('==> getObjRelPathParam:', getObjRelPathParam);
|
|
@@ -214,7 +215,7 @@ async function _processNodeRelationships(
|
|
|
214
215
|
* @param {number} loopSetting.depth - Current depth of recursion
|
|
215
216
|
* @returns {Promise<Object>} - Result of the processing
|
|
216
217
|
*/
|
|
217
|
-
async function _processObjectLinksGroup(_izContext, relationshipTag, objectLinksGroup, loopSetting = { depth: 0 }) {
|
|
218
|
+
async function _processObjectLinksGroup(_izContext, relationshipTag, objectLinksGroup, loopSetting = { depth: 0 }, bucketName = OBJECT_SCHEMA_BUCKET_NAME) {
|
|
218
219
|
// ** == initialize variables ==
|
|
219
220
|
const depthLimit = 4;
|
|
220
221
|
const results = [];
|
|
@@ -240,7 +241,7 @@ async function _processObjectLinksGroup(_izContext, relationshipTag, objectLinks
|
|
|
240
241
|
const [relationshipSchema, rawRelationshipSchema] = await getObjectS3(
|
|
241
242
|
_izContext,
|
|
242
243
|
{
|
|
243
|
-
Bucket:
|
|
244
|
+
Bucket: bucketName,
|
|
244
245
|
Key: UPLOAD_PATH_S3.relationshipTag(_izContext, relType)
|
|
245
246
|
}
|
|
246
247
|
);
|
|
@@ -282,8 +283,8 @@ async function _processObjectLinksGroup(_izContext, relationshipTag, objectLinks
|
|
|
282
283
|
_izContext.logger.debug('createObjectRelationshipConfig:', createObjectRelationshipConfig);
|
|
283
284
|
|
|
284
285
|
// ** get object schema for firstNode and secondNode
|
|
285
|
-
let firstNodeObjSchema = await getObjSchemaS3WithCache(_izContext, firstNode.objType);
|
|
286
|
-
let secondNodeObjSchema = await getObjSchemaS3WithCache(_izContext, secondNode.objType);
|
|
286
|
+
let firstNodeObjSchema = await getObjSchemaS3WithCache(_izContext, firstNode.objType, bucketName);
|
|
287
|
+
let secondNodeObjSchema = await getObjSchemaS3WithCache(_izContext, secondNode.objType, bucketName);
|
|
287
288
|
_izContext.logger.debug(`
|
|
288
289
|
firstNodeObjSchema: ${JSON.stringify(firstNodeObjSchema, null, 2)}
|
|
289
290
|
, secondNodeObjSchema: ${JSON.stringify(secondNodeObjSchema, null, 2)}`);
|
|
@@ -473,7 +474,8 @@ async function _processObjectLinksGroup(_izContext, relationshipTag, objectLinks
|
|
|
473
474
|
newLinkRelSchema,
|
|
474
475
|
storageResourceTags,
|
|
475
476
|
objectRelationships,
|
|
476
|
-
relationshipSchema
|
|
477
|
+
relationshipSchema,
|
|
478
|
+
bucketName
|
|
477
479
|
);
|
|
478
480
|
results.push(...firstNodeResults);
|
|
479
481
|
} catch (error) {
|
|
@@ -497,7 +499,8 @@ async function _processObjectLinksGroup(_izContext, relationshipTag, objectLinks
|
|
|
497
499
|
newLinkRelSchema,
|
|
498
500
|
storageResourceTags,
|
|
499
501
|
objectRelationships,
|
|
500
|
-
relationshipSchema
|
|
502
|
+
relationshipSchema,
|
|
503
|
+
bucketName
|
|
501
504
|
);
|
|
502
505
|
results.push(...secondNodeResults);
|
|
503
506
|
} catch (error) {
|
|
@@ -551,7 +554,8 @@ async function _processObjectLinksGroup(_izContext, relationshipTag, objectLinks
|
|
|
551
554
|
_izContext,
|
|
552
555
|
relType.relationshipTag,
|
|
553
556
|
objectLinksGroup,
|
|
554
|
-
{ depth: loopSetting.depth + 1 }
|
|
557
|
+
{ depth: loopSetting.depth + 1 },
|
|
558
|
+
bucketName
|
|
555
559
|
)
|
|
556
560
|
}
|
|
557
561
|
|
|
@@ -598,7 +602,7 @@ async function _processObjectLinksGroup(_izContext, relationshipTag, objectLinks
|
|
|
598
602
|
uploadObjectToS3(
|
|
599
603
|
_izContext,
|
|
600
604
|
UPLOAD_PATH_S3.objectRelationship(_izContext, objType),
|
|
601
|
-
relationships
|
|
605
|
+
relationships,
|
|
602
606
|
)
|
|
603
607
|
);
|
|
604
608
|
|
|
@@ -635,7 +639,8 @@ async function _processObjectLinksGroup(_izContext, relationshipTag, objectLinks
|
|
|
635
639
|
_izContext,
|
|
636
640
|
relType.relationshipTag,
|
|
637
641
|
objectLinksGroup,
|
|
638
|
-
{ depth: loopSetting.depth + 1 }
|
|
642
|
+
{ depth: loopSetting.depth + 1 },
|
|
643
|
+
bucketName
|
|
639
644
|
)
|
|
640
645
|
}
|
|
641
646
|
} catch (error) {
|
package/src/UploadObjSchema.js
CHANGED
|
@@ -86,6 +86,7 @@ async function uploadObjectToS3(
|
|
|
86
86
|
_izContext,
|
|
87
87
|
pathToUpload,
|
|
88
88
|
objectToUpload,
|
|
89
|
+
bucketName = OBJECT_SCHEMA_BUCKET_NAME,
|
|
89
90
|
additionalOptions = {}
|
|
90
91
|
) {
|
|
91
92
|
|
|
@@ -93,7 +94,7 @@ async function uploadObjectToS3(
|
|
|
93
94
|
const Key = pathToUpload
|
|
94
95
|
|
|
95
96
|
let data = {
|
|
96
|
-
Bucket:
|
|
97
|
+
Bucket: bucketName,
|
|
97
98
|
Key,
|
|
98
99
|
Body: buffer,
|
|
99
100
|
ContentEncoding: 'base64',
|
|
@@ -163,13 +164,13 @@ async function emptyS3Path(
|
|
|
163
164
|
*
|
|
164
165
|
* @param {object} _izContext
|
|
165
166
|
*/
|
|
166
|
-
async function uploadObjectSchemaByUseCase(_izContext) {
|
|
167
|
+
async function uploadObjectSchemaByUseCase(_izContext, bucketName = OBJECT_SCHEMA_BUCKET_NAME) {
|
|
167
168
|
let uploadList = [];
|
|
168
169
|
|
|
169
170
|
const objectTypesForCreate = [];
|
|
170
171
|
|
|
171
172
|
const allObjectSchemasResult = await getAllLocalObjectSchemasWithoutHierarchy(_izContext);
|
|
172
|
-
console.log("allObjectSchemasResult: ", allObjectSchemasResult);
|
|
173
|
+
// console.log("allObjectSchemasResult: ", allObjectSchemasResult);
|
|
173
174
|
const allObjectSchema = await allObjectSchemasResult.records;
|
|
174
175
|
// const allObjectRelationships = getDataFromPath(_izContext, LOCAL_FILENAME.OBJECT_RELATIONSHIPS, LOCAL_OBJECT_SCHEMA_PATH, { fileLimit: 1 })[0] || [];
|
|
175
176
|
// const allReferenceObjectRelationships = getDataFromPath(_izContext, LOCAL_FILENAME.REFERENCE_OBJECT_RELATIONSHIPS, LOCAL_OBJECT_SCHEMA_PATH, { fileLimit: 1 })[0] || [];
|
|
@@ -234,7 +235,7 @@ async function uploadObjectSchemaByUseCase(_izContext) {
|
|
|
234
235
|
// end validate all schema
|
|
235
236
|
|
|
236
237
|
// delete all file in servicePath before upload
|
|
237
|
-
await emptyS3Path(_izContext,
|
|
238
|
+
await emptyS3Path(_izContext, bucketName, `${PREFIX_PATH_S3.perServiceSchemas}/${process.env.iz_serviceTag}/`);
|
|
238
239
|
|
|
239
240
|
|
|
240
241
|
if (lambdaFunctions) {
|
|
@@ -242,7 +243,8 @@ async function uploadObjectSchemaByUseCase(_izContext) {
|
|
|
242
243
|
uploadObjectToS3(
|
|
243
244
|
_izContext,
|
|
244
245
|
UPLOAD_PATH_S3.lambdaFunctions(_izContext, process.env.iz_serviceTag),
|
|
245
|
-
lambdaFunctions
|
|
246
|
+
lambdaFunctions,
|
|
247
|
+
bucketName
|
|
246
248
|
)
|
|
247
249
|
);
|
|
248
250
|
}
|
|
@@ -252,7 +254,8 @@ async function uploadObjectSchemaByUseCase(_izContext) {
|
|
|
252
254
|
uploadObjectToS3(
|
|
253
255
|
_izContext,
|
|
254
256
|
UPLOAD_PATH_S3.serviceName(_izContext, process.env.iz_serviceTag),
|
|
255
|
-
{ serviceName: process.env.iz_serviceName }
|
|
257
|
+
{ serviceName: process.env.iz_serviceName },
|
|
258
|
+
bucketName
|
|
256
259
|
)
|
|
257
260
|
);
|
|
258
261
|
|
|
@@ -270,7 +273,8 @@ async function uploadObjectSchemaByUseCase(_izContext) {
|
|
|
270
273
|
objectType: objSchema.objectType
|
|
271
274
|
}
|
|
272
275
|
),
|
|
273
|
-
objSchema
|
|
276
|
+
objSchema,
|
|
277
|
+
bucketName
|
|
274
278
|
)
|
|
275
279
|
);
|
|
276
280
|
|
|
@@ -287,7 +291,8 @@ async function uploadObjectSchemaByUseCase(_izContext) {
|
|
|
287
291
|
objectType: createFieldSchema.objectType
|
|
288
292
|
}
|
|
289
293
|
),
|
|
290
|
-
createFieldSchema
|
|
294
|
+
createFieldSchema,
|
|
295
|
+
bucketName
|
|
291
296
|
)
|
|
292
297
|
);
|
|
293
298
|
|
|
@@ -306,14 +311,15 @@ async function uploadObjectSchemaByUseCase(_izContext) {
|
|
|
306
311
|
objectType: createFieldSchema.objectType
|
|
307
312
|
}
|
|
308
313
|
),
|
|
309
|
-
updateFieldSchema
|
|
314
|
+
updateFieldSchema,
|
|
315
|
+
bucketName
|
|
310
316
|
)
|
|
311
317
|
);
|
|
312
318
|
|
|
313
319
|
|
|
314
320
|
// case schema combine fieldNames
|
|
315
321
|
let combineFieldNamesObjectSchema = generateObjectSchemaForCombineFieldNames(_izContext, objSchema);
|
|
316
|
-
console.log("combineFieldNamesObjectSchema", combineFieldNamesObjectSchema)
|
|
322
|
+
// console.log("combineFieldNamesObjectSchema", combineFieldNamesObjectSchema)
|
|
317
323
|
uploadList.push(
|
|
318
324
|
uploadObjectToS3(
|
|
319
325
|
_izContext,
|
|
@@ -324,17 +330,19 @@ async function uploadObjectSchemaByUseCase(_izContext) {
|
|
|
324
330
|
objectType: combineFieldNamesObjectSchema.objectType
|
|
325
331
|
}
|
|
326
332
|
),
|
|
327
|
-
combineFieldNamesObjectSchema
|
|
333
|
+
combineFieldNamesObjectSchema,
|
|
334
|
+
bucketName
|
|
328
335
|
)
|
|
329
336
|
);
|
|
330
337
|
|
|
331
338
|
let apiLink = await getApiLinks();
|
|
332
|
-
console.log("apiLink", apiLink)
|
|
339
|
+
// console.log("apiLink", apiLink)
|
|
333
340
|
uploadList.push(
|
|
334
341
|
uploadObjectToS3(
|
|
335
342
|
_izContext,
|
|
336
343
|
UPLOAD_PATH_S3.getEndpointPerObjectType(_izContext, { objectType: objSchema.objectType, serviceTag: process.env.iz_serviceTag }),
|
|
337
|
-
apiLink
|
|
344
|
+
apiLink,
|
|
345
|
+
bucketName
|
|
338
346
|
)
|
|
339
347
|
)
|
|
340
348
|
|
|
@@ -342,7 +350,8 @@ async function uploadObjectSchemaByUseCase(_izContext) {
|
|
|
342
350
|
uploadObjectToS3(
|
|
343
351
|
_izContext,
|
|
344
352
|
UPLOAD_PATH_S3.getEndpointPerService(process.env.iz_serviceTag),
|
|
345
|
-
apiLink
|
|
353
|
+
apiLink,
|
|
354
|
+
bucketName
|
|
346
355
|
)
|
|
347
356
|
)
|
|
348
357
|
|
|
@@ -360,7 +369,8 @@ async function uploadObjectSchemaByUseCase(_izContext) {
|
|
|
360
369
|
serviceTag: process.env.iz_serviceTag
|
|
361
370
|
}
|
|
362
371
|
),
|
|
363
|
-
existsRefObjectRel
|
|
372
|
+
existsRefObjectRel,
|
|
373
|
+
bucketName
|
|
364
374
|
)
|
|
365
375
|
)
|
|
366
376
|
} else {
|
|
@@ -379,7 +389,8 @@ async function uploadObjectSchemaByUseCase(_izContext) {
|
|
|
379
389
|
serviceTag: process.env.iz_serviceTag
|
|
380
390
|
}
|
|
381
391
|
),
|
|
382
|
-
await refRelationshipPerObjectSchema(_izContext, objSchema)
|
|
392
|
+
await refRelationshipPerObjectSchema(_izContext, objSchema),
|
|
393
|
+
bucketName
|
|
383
394
|
)
|
|
384
395
|
)
|
|
385
396
|
}
|
|
@@ -392,7 +403,8 @@ async function uploadObjectSchemaByUseCase(_izContext) {
|
|
|
392
403
|
uploadObjectToS3(
|
|
393
404
|
_izContext,
|
|
394
405
|
UPLOAD_PATH_S3.objectListAll(_izContext, process.env.iz_serviceTag),
|
|
395
|
-
foundedObjectTypes
|
|
406
|
+
foundedObjectTypes,
|
|
407
|
+
bucketName
|
|
396
408
|
)
|
|
397
409
|
);
|
|
398
410
|
|
|
@@ -502,7 +514,8 @@ async function uploadObjectSchemaByUseCase(_izContext) {
|
|
|
502
514
|
{
|
|
503
515
|
relationshipServiceTag: process.env.iz_serviceTag,
|
|
504
516
|
...relTagDetail[relationshipTag],
|
|
505
|
-
}
|
|
517
|
+
},
|
|
518
|
+
bucketName
|
|
506
519
|
)
|
|
507
520
|
);
|
|
508
521
|
|
|
@@ -514,7 +527,8 @@ async function uploadObjectSchemaByUseCase(_izContext) {
|
|
|
514
527
|
uploadObjectToS3(
|
|
515
528
|
_izContext,
|
|
516
529
|
UPLOAD_PATH_S3.linkByLinkTypeId(_izContext, process.env.iz_serviceTag, linkTypeId),
|
|
517
|
-
link
|
|
530
|
+
link,
|
|
531
|
+
bucketName
|
|
518
532
|
)
|
|
519
533
|
);
|
|
520
534
|
}
|
|
@@ -553,13 +567,14 @@ async function uploadObjectSchemaByUseCase(_izContext) {
|
|
|
553
567
|
uploadObjectToS3(
|
|
554
568
|
_izContext,
|
|
555
569
|
UPLOAD_PATH_S3.objectRelationship(_izContext, { serviceTag: process.env.iz_serviceTag, objectType: relObjectType }),
|
|
556
|
-
relTagsData
|
|
570
|
+
relTagsData,
|
|
571
|
+
bucketName
|
|
557
572
|
)
|
|
558
573
|
);
|
|
559
574
|
}
|
|
560
575
|
|
|
561
576
|
|
|
562
|
-
} // All
|
|
577
|
+
} // All objectRelationship
|
|
563
578
|
|
|
564
579
|
|
|
565
580
|
// // upload refObjectRelationships
|
|
@@ -588,7 +603,8 @@ async function uploadObjectSchemaByUseCase(_izContext) {
|
|
|
588
603
|
flowTag: flowSchema.flowTag
|
|
589
604
|
}
|
|
590
605
|
),
|
|
591
|
-
flowSchema
|
|
606
|
+
flowSchema,
|
|
607
|
+
bucketName
|
|
592
608
|
)
|
|
593
609
|
)
|
|
594
610
|
}
|
package/src/Utils.js
CHANGED
|
@@ -279,7 +279,7 @@ function validateAddOnDataStructure(_izContext, objectSchema) {
|
|
|
279
279
|
|
|
280
280
|
let errors = [];
|
|
281
281
|
let fieldNameCollection = Object.keys(objectSchema.fieldNames || {});
|
|
282
|
-
let
|
|
282
|
+
let attributeTreeTags = [];
|
|
283
283
|
|
|
284
284
|
if (objectSchema.addOnDataStructure?.length) {
|
|
285
285
|
for (const [idx, addOn] of objectSchema.addOnDataStructure.entries()) {
|
|
@@ -717,7 +717,7 @@ async function getApiLinks() {
|
|
|
717
717
|
}
|
|
718
718
|
}
|
|
719
719
|
}
|
|
720
|
-
console.log("apiGateway in function getApiLink", apiGateway)
|
|
720
|
+
// console.log("apiGateway in function getApiLink", apiGateway)
|
|
721
721
|
return apiGateway
|
|
722
722
|
} catch (err) {
|
|
723
723
|
console.error("Error fetching API info:", err);
|
package/src/ValidatorSchema.js
CHANGED
|
@@ -62,7 +62,8 @@ const {
|
|
|
62
62
|
createValidationFieldNameForEachType,
|
|
63
63
|
S3_UPLOAD_TYPE,
|
|
64
64
|
FLOW_SCHEMA_HOOK_STATE,
|
|
65
|
-
HANDLER
|
|
65
|
+
HANDLER,
|
|
66
|
+
OBJECT_SCHEMA_BUCKET_NAME
|
|
66
67
|
} = require("./Consts");
|
|
67
68
|
const { validateObjType } = require('@izara_project/izara-shared-service-schemas').validateObjType;
|
|
68
69
|
|
|
@@ -76,7 +77,7 @@ const { validateObjType } = require('@izara_project/izara-shared-service-schemas
|
|
|
76
77
|
* @param {Number} iter iterate count
|
|
77
78
|
* @returns
|
|
78
79
|
*/
|
|
79
|
-
async function generateValidatorSchemaTreePerFieldName(_izContext, fieldName, fieldNameSetting, iter = 0) {
|
|
80
|
+
async function generateValidatorSchemaTreePerFieldName(_izContext, fieldName, fieldNameSetting, bucketName = OBJECT_SCHEMA_BUCKET_NAME, iter = 0) {
|
|
80
81
|
if (iter > 50) {
|
|
81
82
|
throw new NoRetryError("generateValidatorSchemaPerFieldName reach max iteration limit")
|
|
82
83
|
} else {
|
|
@@ -104,7 +105,8 @@ async function generateValidatorSchemaTreePerFieldName(_izContext, fieldName, fi
|
|
|
104
105
|
{
|
|
105
106
|
objectType: fieldNameSetting.fromObjectType,
|
|
106
107
|
serviceTag: fieldNameSetting.fromServiceNameTag
|
|
107
|
-
}
|
|
108
|
+
},
|
|
109
|
+
bucketName
|
|
108
110
|
);
|
|
109
111
|
|
|
110
112
|
if (!childObjectSchema) {
|
|
@@ -129,6 +131,7 @@ async function generateValidatorSchemaTreePerFieldName(_izContext, fieldName, fi
|
|
|
129
131
|
{ logger: Logger },
|
|
130
132
|
eachKey, // fieldName
|
|
131
133
|
childObjectSchema.fieldNames[eachKey], // fieldName setting
|
|
134
|
+
bucketName,
|
|
132
135
|
iter
|
|
133
136
|
);
|
|
134
137
|
|
|
@@ -152,7 +155,7 @@ async function generateValidatorSchemaTreePerFieldName(_izContext, fieldName, fi
|
|
|
152
155
|
return validatorTree;
|
|
153
156
|
}
|
|
154
157
|
|
|
155
|
-
async function validatorSchemaTreeIdentifiers(_izContext, objectSchema, iter = 0) {
|
|
158
|
+
async function validatorSchemaTreeIdentifiers(_izContext, objectSchema, bucketName = OBJECT_SCHEMA_BUCKET_NAME, iter = 0) {
|
|
156
159
|
if (iter > 50) {
|
|
157
160
|
throw new NoRetryError("generateValidatorSchemaPerFieldName reach max iteration limit")
|
|
158
161
|
} else {
|
|
@@ -173,7 +176,7 @@ async function validatorSchemaTreeIdentifiers(_izContext, objectSchema, iter = 0
|
|
|
173
176
|
|
|
174
177
|
let allValidatorTreeCompositeKey = {};
|
|
175
178
|
for (let compositeKey of identifier.fieldNames) {
|
|
176
|
-
let validatorTreeCompositeKey = await generateValidatorSchemaTreePerFieldName(_izContext, compositeKey, objectSchema.fieldNames[compositeKey]);
|
|
179
|
+
let validatorTreeCompositeKey = await generateValidatorSchemaTreePerFieldName(_izContext, compositeKey, objectSchema.fieldNames[compositeKey], bucketName);
|
|
177
180
|
_izContext.logger.debug("validatorTreeCompositeKey: ", JSON.stringify(validatorTreeCompositeKey));
|
|
178
181
|
|
|
179
182
|
Object.assign(allValidatorTreeCompositeKey, validatorTreeCompositeKey);
|
|
@@ -182,7 +185,7 @@ async function validatorSchemaTreeIdentifiers(_izContext, objectSchema, iter = 0
|
|
|
182
185
|
Object.assign(validatorSchemaTree, { [identifierName]: allValidatorTreeCompositeKey });
|
|
183
186
|
|
|
184
187
|
} else {
|
|
185
|
-
let validatorTreeIdentifier = await generateValidatorSchemaTreePerFieldName(_izContext, identifierName, objectSchema.fieldNames[identifierName])
|
|
188
|
+
let validatorTreeIdentifier = await generateValidatorSchemaTreePerFieldName(_izContext, identifierName, objectSchema.fieldNames[identifierName], bucketName)
|
|
186
189
|
_izContext.logger.debug("validatorTreeIdentifier: ", JSON.stringify(validatorTreeIdentifier))
|
|
187
190
|
|
|
188
191
|
Object.assign(validatorSchemaTree, validatorTreeIdentifier);
|
|
@@ -196,7 +199,7 @@ async function validatorSchemaTreeIdentifiers(_izContext, objectSchema, iter = 0
|
|
|
196
199
|
}
|
|
197
200
|
|
|
198
201
|
|
|
199
|
-
async function validatorSchemaTreeIdentifiersFieldNames(_izContext, objectSchema, iter = 0) {
|
|
202
|
+
async function validatorSchemaTreeIdentifiersFieldNames(_izContext, objectSchema, bucketName = OBJECT_SCHEMA_BUCKET_NAME, iter = 0) {
|
|
200
203
|
if (iter > 50) {
|
|
201
204
|
throw new NoRetryError("generateValidatorSchemaPerFieldName reach max iteration limit")
|
|
202
205
|
} else {
|
|
@@ -215,7 +218,7 @@ async function validatorSchemaTreeIdentifiersFieldNames(_izContext, objectSchema
|
|
|
215
218
|
await Promise.all(
|
|
216
219
|
identifierFieldNames.map(
|
|
217
220
|
async (identifierFieldName) => {
|
|
218
|
-
let validatorTreeIdentifierFieldName = await generateValidatorSchemaTreePerFieldName(_izContext, identifierFieldName, objectSchema.fieldNames[identifierFieldName]);
|
|
221
|
+
let validatorTreeIdentifierFieldName = await generateValidatorSchemaTreePerFieldName(_izContext, identifierFieldName, objectSchema.fieldNames[identifierFieldName], bucketName);
|
|
219
222
|
_izContext.logger.debug("validatorTreeIdentifierFieldName: ", validatorTreeIdentifierFieldName);
|
|
220
223
|
|
|
221
224
|
Object.assign(validatorSchemaTree, validatorTreeIdentifierFieldName);
|
|
@@ -240,7 +243,7 @@ async function validatorSchemaTreeIdentifiersFieldNames(_izContext, objectSchema
|
|
|
240
243
|
* @param {String} objType.objectType
|
|
241
244
|
* @param {String} objType.serviceTag
|
|
242
245
|
*/
|
|
243
|
-
async function generateRelationshipValidatorSchemaForCreate(_izContext, objType) {
|
|
246
|
+
async function generateRelationshipValidatorSchemaForCreate(_izContext, objType, bucketName = OBJECT_SCHEMA_BUCKET_NAME) {
|
|
244
247
|
const validateObjTypeResult = validateObjType(objType);
|
|
245
248
|
if (validateObjTypeResult.errorsFound.length > 0) {
|
|
246
249
|
_izContext.logger.error("generateRelationshipValidatorSchemaForCreate validateObjTypeResult", validateObjTypeResult);
|
|
@@ -297,7 +300,7 @@ async function generateRelationshipValidatorSchemaForCreate(_izContext, objType)
|
|
|
297
300
|
&& parent.linkConfig.requiredOnCreate === true
|
|
298
301
|
) {
|
|
299
302
|
|
|
300
|
-
let parentObjSchema = await getObjSchemaS3WithHierarchy(_izContext, parent.objType);
|
|
303
|
+
let parentObjSchema = await getObjSchemaS3WithHierarchy(_izContext, parent.objType, bucketName);
|
|
301
304
|
|
|
302
305
|
if (!parentObjSchema) {
|
|
303
306
|
throw new NoRetryError(`Not found parent ${JSON.stringify(parent.objType)} in relationship:${relTag}`);
|
|
@@ -377,7 +380,7 @@ async function generateRelationshipValidatorSchemaForCreate(_izContext, objType)
|
|
|
377
380
|
* @param {String[]} specificFieldNames
|
|
378
381
|
* @returns
|
|
379
382
|
*/
|
|
380
|
-
async function generateValidatorSchemaForCreate(_izContext, objType,
|
|
383
|
+
async function generateValidatorSchemaForCreate(_izContext, objType, settings = { specificFieldNames: [], bucketName: OBJECT_SCHEMA_BUCKET_NAME }) {
|
|
381
384
|
const validateObjTypeResult = validateObjType(objType);
|
|
382
385
|
if (validateObjTypeResult.errorsFound.length > 0) {
|
|
383
386
|
_izContext.logger.error("generateValidatorSchemaForCreate validateObjTypeResult", validateObjTypeResult);
|
|
@@ -385,10 +388,10 @@ async function generateValidatorSchemaForCreate(_izContext, objType, specificFie
|
|
|
385
388
|
}
|
|
386
389
|
_izContext.logger.debug("Function:generateValidatorSchemaForCreate ", {
|
|
387
390
|
objType,
|
|
388
|
-
specificFieldNames
|
|
391
|
+
specificFieldNames: settings.specificFieldNames
|
|
389
392
|
})
|
|
390
393
|
|
|
391
|
-
const objectSchema = await getObjSchemaS3WithHierarchy(_izContext, objType);
|
|
394
|
+
const objectSchema = await getObjSchemaS3WithHierarchy(_izContext, objType, settings.bucketName);
|
|
392
395
|
_izContext.logger.debug("objectSchema in generateValidatorSchemaForCreate", objectSchema)
|
|
393
396
|
let usedFieldNamesData = {};
|
|
394
397
|
let requiredFieldNames = [];
|
|
@@ -400,8 +403,8 @@ async function generateValidatorSchemaForCreate(_izContext, objType, specificFie
|
|
|
400
403
|
requiredFieldNames.push(mainFieldName);
|
|
401
404
|
Object.assign(usedFieldNamesData, { [mainFieldName]: objectSchema.fieldNames[mainFieldName] });
|
|
402
405
|
} else if (objectSchema.fieldNames[mainFieldName].optionalOnCreate === true) {
|
|
403
|
-
if (specificFieldNames.length) {
|
|
404
|
-
if (specificFieldNames.includes(mainFieldName)) {
|
|
406
|
+
if (settings.specificFieldNames.length) {
|
|
407
|
+
if (settings.specificFieldNames.includes(mainFieldName)) {
|
|
405
408
|
Object.assign(usedFieldNamesData, { [mainFieldName]: objectSchema.fieldNames[mainFieldName] });
|
|
406
409
|
}
|
|
407
410
|
} else {
|
|
@@ -426,8 +429,8 @@ async function generateValidatorSchemaForCreate(_izContext, objType, specificFie
|
|
|
426
429
|
);
|
|
427
430
|
} else if (versionedDataFieldSetting.optionalOnCreate === true) {
|
|
428
431
|
|
|
429
|
-
if (specificFieldNames.length) {
|
|
430
|
-
if (specificFieldNames.includes(versionedDataFieldName)) {
|
|
432
|
+
if (settings.specificFieldNames.length) {
|
|
433
|
+
if (settings.specificFieldNames.includes(versionedDataFieldName)) {
|
|
431
434
|
Object.assign(
|
|
432
435
|
usedFieldNamesData,
|
|
433
436
|
{ [versionedDataFieldName]: versionedDataFieldName }
|
|
@@ -453,7 +456,8 @@ async function generateValidatorSchemaForCreate(_izContext, objType, specificFie
|
|
|
453
456
|
let validatorSchemaFieldName = await generateValidatorSchemaTreePerFieldName(
|
|
454
457
|
_izContext,
|
|
455
458
|
fieldName,
|
|
456
|
-
usedFieldNamesData[fieldName]
|
|
459
|
+
usedFieldNamesData[fieldName],
|
|
460
|
+
settings.bucketName
|
|
457
461
|
);
|
|
458
462
|
|
|
459
463
|
Object.assign(allValidatorSchemaFieldNames, validatorSchemaFieldName);
|
|
@@ -493,19 +497,18 @@ async function generateValidatorSchemaForCreate(_izContext, objType, specificFie
|
|
|
493
497
|
|
|
494
498
|
|
|
495
499
|
/*
|
|
496
|
-
collect which field is
|
|
500
|
+
collect which field is required and optional
|
|
497
501
|
should require name of identifier instead of fieldName that part of identifiers
|
|
498
502
|
Note : should add setting for api in this function
|
|
499
503
|
*/
|
|
500
|
-
async function generateValidatorSchemaForUpdate(_izContext, objType,
|
|
504
|
+
async function generateValidatorSchemaForUpdate(_izContext, objType, settings = { specificFieldNames: [], bucketName: OBJECT_SCHEMA_BUCKET_NAME }) {
|
|
501
505
|
|
|
502
506
|
_izContext.logger.debug("Function:generateValidatorSchemaForUpdate2 ", {
|
|
503
507
|
objType,
|
|
504
|
-
setting,
|
|
508
|
+
setting: settings,
|
|
505
509
|
})
|
|
506
|
-
setting.specificFieldNames = setting?.specificFieldNames ? setting.specificFieldNames : []
|
|
507
510
|
// const objType = createObjType(objectType);
|
|
508
|
-
const objectSchema = await getObjSchemaS3WithHierarchy(_izContext, objType);
|
|
511
|
+
const objectSchema = await getObjSchemaS3WithHierarchy(_izContext, objType, settings.bucketName);
|
|
509
512
|
_izContext.logger.debug("objectSchema", objectSchema)
|
|
510
513
|
|
|
511
514
|
const objectSchemas = await uploadUseCase.generateObjectSchemaForCombineFieldNames(_izContext, objectSchema)
|
|
@@ -530,9 +533,9 @@ async function generateValidatorSchemaForUpdate(_izContext, objType, setting = {
|
|
|
530
533
|
}
|
|
531
534
|
|
|
532
535
|
// collect usedFieldNames
|
|
533
|
-
if (
|
|
534
|
-
if (
|
|
535
|
-
for (let specificFieldName of
|
|
536
|
+
if (settings?.specificFieldNames) {
|
|
537
|
+
if (settings.specificFieldNames.length) {
|
|
538
|
+
for (let specificFieldName of settings.specificFieldNames) {
|
|
536
539
|
if (canUpdateFieldNames.includes(specificFieldName)) {
|
|
537
540
|
usedFieldNames.push(specificFieldName);
|
|
538
541
|
} else {
|
|
@@ -563,7 +566,7 @@ async function generateValidatorSchemaForUpdate(_izContext, objType, setting = {
|
|
|
563
566
|
properties: {
|
|
564
567
|
identifiers: {
|
|
565
568
|
type: "object",
|
|
566
|
-
... await filteredFieldNamesOfValidatorSchema(_izContext, objType, identifiersFieldNames, identifiersFieldNames)
|
|
569
|
+
... await filteredFieldNamesOfValidatorSchema(_izContext, objType, identifiersFieldNames, identifiersFieldNames, settings.bucketName)
|
|
567
570
|
},
|
|
568
571
|
fields: {
|
|
569
572
|
type: "object",
|
|
@@ -605,7 +608,7 @@ async function generateValidatorSchemaForUpdate(_izContext, objType, setting = {
|
|
|
605
608
|
}
|
|
606
609
|
|
|
607
610
|
|
|
608
|
-
Object.assign(initialValidatorSchemaForUpdate.properties.objInstanceFull.properties.fields, await filteredFieldNamesOfValidatorSchema(_izContext, objType, [], defaultFieldNames))
|
|
611
|
+
Object.assign(initialValidatorSchemaForUpdate.properties.objInstanceFull.properties.fields, await filteredFieldNamesOfValidatorSchema(_izContext, objType, [], defaultFieldNames, settings.bucketName))
|
|
609
612
|
Object.assign(initialValidatorSchemaForUpdate.properties.objInstanceFull.properties.fields.properties, versionedDataReturnInFieldsObjInstanceFull);
|
|
610
613
|
|
|
611
614
|
_izContext.logger.debug("validatorSchema", initialValidatorSchemaForUpdate)
|
|
@@ -623,7 +626,7 @@ async function generateValidatorSchemaForUpdate(_izContext, objType, setting = {
|
|
|
623
626
|
*
|
|
624
627
|
* @returns {object} json validator schema
|
|
625
628
|
*/
|
|
626
|
-
async function generateValidatorSchemaForIdentifier(_izContext, objType) {
|
|
629
|
+
async function generateValidatorSchemaForIdentifier(_izContext, objType, settings = { bucketName: OBJECT_SCHEMA_BUCKET_NAME }) {
|
|
627
630
|
const validateObjTypeResult = validateObjType(objType);
|
|
628
631
|
if (validateObjTypeResult.errorsFound.length > 0) {
|
|
629
632
|
_izContext.logger.error("generateValidatorSchemaForIdentifier validateObjTypeResult", validateObjTypeResult);
|
|
@@ -633,9 +636,9 @@ async function generateValidatorSchemaForIdentifier(_izContext, objType) {
|
|
|
633
636
|
objType,
|
|
634
637
|
})
|
|
635
638
|
|
|
636
|
-
const objectSchema = await getObjSchemaS3WithHierarchy(_izContext, objType);
|
|
639
|
+
const objectSchema = await getObjSchemaS3WithHierarchy(_izContext, objType, settings.bucketName);
|
|
637
640
|
|
|
638
|
-
let generatedIdentifiersValidatorSchema = await validatorSchemaTreeIdentifiersFieldNames(_izContext, objectSchema);
|
|
641
|
+
let generatedIdentifiersValidatorSchema = await validatorSchemaTreeIdentifiersFieldNames(_izContext, objectSchema, settings.bucketName);
|
|
639
642
|
_izContext.logger.debug("generatedIdentifiersValidatorSchema: ", generatedIdentifiersValidatorSchema);
|
|
640
643
|
|
|
641
644
|
return {
|
|
@@ -664,7 +667,7 @@ async function generateValidatorSchemaForIdentifier(_izContext, objType) {
|
|
|
664
667
|
* @param {string[]} usedFieldNames
|
|
665
668
|
* @returns
|
|
666
669
|
*/
|
|
667
|
-
async function filteredFieldNamesOfValidatorSchema(_izContext, objType, requiredFieldNames, usedFieldNames) {
|
|
670
|
+
async function filteredFieldNamesOfValidatorSchema(_izContext, objType, requiredFieldNames, usedFieldNames, bucketName = OBJECT_SCHEMA_BUCKET_NAME) {
|
|
668
671
|
const validateObjTypeResult = validateObjType(objType);
|
|
669
672
|
if (validateObjTypeResult.errorsFound.length > 0) {
|
|
670
673
|
_izContext.logger.error("filteredFieldNamesOfValidatorSchema validateObjTypeResult", validateObjTypeResult);
|
|
@@ -676,7 +679,7 @@ async function filteredFieldNamesOfValidatorSchema(_izContext, objType, required
|
|
|
676
679
|
usedFieldNames
|
|
677
680
|
});
|
|
678
681
|
|
|
679
|
-
let allValidatorSchema = await generateValidatorSchemaForExplodedDataWithCache(_izContext, objType);
|
|
682
|
+
let allValidatorSchema = await generateValidatorSchemaForExplodedDataWithCache(_izContext, objType, bucketName);
|
|
680
683
|
_izContext.logger.debug("filteredFieldNamesOfValidatorSchema allValidatorSchema : ", allValidatorSchema)
|
|
681
684
|
|
|
682
685
|
allValidatorSchema.required = requiredFieldNames;
|
|
@@ -710,7 +713,7 @@ async function filteredFieldNamesOfValidatorSchema(_izContext, objType, required
|
|
|
710
713
|
* 2 >> create validatorSchema of fieldName and identifier
|
|
711
714
|
* 3 >> not required, Use for validate only
|
|
712
715
|
*/
|
|
713
|
-
async function generateValidatorSchemaForExplodedData(_izContext, objType) {
|
|
716
|
+
async function generateValidatorSchemaForExplodedData(_izContext, objType, bucketName = OBJECT_SCHEMA_BUCKET_NAME) {
|
|
714
717
|
const validateObjTypeResult = validateObjType(objType);
|
|
715
718
|
if (validateObjTypeResult.errorsFound.length > 0) {
|
|
716
719
|
_izContext.logger.error("generateValidatorSchemaForExplodedData validateObjTypeResult", validateObjTypeResult);
|
|
@@ -723,10 +726,10 @@ async function generateValidatorSchemaForExplodedData(_izContext, objType) {
|
|
|
723
726
|
properties: {}
|
|
724
727
|
};
|
|
725
728
|
|
|
726
|
-
let objectSchema = await getObjSchemaS3WithHierarchy(_izContext, objType);
|
|
729
|
+
let objectSchema = await getObjSchemaS3WithHierarchy(_izContext, objType, bucketName);
|
|
727
730
|
// generate validatorSchema for each fieldName
|
|
728
731
|
for (let [fieldName, fieldData] of Object.entries(objectSchema.fieldNames)) {
|
|
729
|
-
let fieldNameValidator = await generateValidatorFieldNameWithCache(_izContext, fieldName, fieldData);
|
|
732
|
+
let fieldNameValidator = await generateValidatorFieldNameWithCache(_izContext, fieldName, fieldData, bucketName);
|
|
730
733
|
Object.assign(validatorSchema.properties, fieldNameValidator);
|
|
731
734
|
}
|
|
732
735
|
|
|
@@ -810,7 +813,7 @@ const generateValidatorFieldNameWithCache = inMemoryCacheLib(
|
|
|
810
813
|
* @param {Object} fieldData
|
|
811
814
|
* @returns
|
|
812
815
|
*/
|
|
813
|
-
async function generateValidatorFieldName(_izContext, fieldName, fieldData) {
|
|
816
|
+
async function generateValidatorFieldName(_izContext, fieldName, fieldData, bucketName = OBJECT_SCHEMA_BUCKET_NAME) {
|
|
814
817
|
|
|
815
818
|
if (fieldData.hasOwnProperty("fromObjectType") || fieldData.hasOwnProperty("fromServiceNameTag")) {
|
|
816
819
|
// validate reference
|
|
@@ -823,7 +826,8 @@ async function generateValidatorFieldName(_izContext, fieldName, fieldData) {
|
|
|
823
826
|
{
|
|
824
827
|
serviceTag: fieldData.fromServiceNameTag,
|
|
825
828
|
objectType: fieldData.fromObjectType
|
|
826
|
-
}
|
|
829
|
+
},
|
|
830
|
+
bucketName
|
|
827
831
|
);
|
|
828
832
|
|
|
829
833
|
let usedIdentifier = null
|
|
@@ -854,7 +858,7 @@ async function generateValidatorFieldName(_izContext, fieldName, fieldData) {
|
|
|
854
858
|
throw new Error(`Invalid reference fieldName:${compositeKey}`);
|
|
855
859
|
}
|
|
856
860
|
|
|
857
|
-
let childValidator = await generateValidatorFieldNameWithCache(_izContext, compositeKey, objectSchemaChild.fieldNames[compositeKey]);
|
|
861
|
+
let childValidator = await generateValidatorFieldNameWithCache(_izContext, compositeKey, objectSchemaChild.fieldNames[compositeKey], bucketName);
|
|
858
862
|
|
|
859
863
|
Object.assign(returnValidator, childValidator)
|
|
860
864
|
|
|
@@ -914,7 +918,7 @@ async function generateValidatorFieldName(_izContext, fieldName, fieldData) {
|
|
|
914
918
|
* @param {String} serviceConfigPath - path that config file of service located
|
|
915
919
|
* @returns
|
|
916
920
|
*/
|
|
917
|
-
async function validateLocalSchema(_izContext, schemasPath, serviceConfigPath) {
|
|
921
|
+
async function validateLocalSchema(_izContext, schemasPath, serviceConfigPath, bucketName = OBJECT_SCHEMA_BUCKET_NAME) {
|
|
918
922
|
try {
|
|
919
923
|
const serviceConfig = readYamlFile.sync(serviceConfigPath);
|
|
920
924
|
const iz_serviceTag = serviceConfig.main_config.iz_serviceTag;
|
|
@@ -968,7 +972,7 @@ async function validateLocalSchema(_izContext, schemasPath, serviceConfigPath) {
|
|
|
968
972
|
const storageResource = objSchema.storageResources[storageTag];
|
|
969
973
|
|
|
970
974
|
if (storageResource.storageType === STORAGE_TYPES.graph) {
|
|
971
|
-
const graphServiceTag = await getGraphServiceTag(_izContext, storageResource.graphServerTag);
|
|
975
|
+
const graphServiceTag = await getGraphServiceTag(_izContext, storageResource.graphServerTag, bucketName);
|
|
972
976
|
|
|
973
977
|
if (!graphServiceTag) {
|
|
974
978
|
validateStatus.status = false;
|
|
@@ -1039,7 +1043,7 @@ async function validateLocalSchema(_izContext, schemasPath, serviceConfigPath) {
|
|
|
1039
1043
|
const storageResource = relData.storageResources[storageTag];
|
|
1040
1044
|
|
|
1041
1045
|
if (storageResource.storageType === STORAGE_TYPES.graph) {
|
|
1042
|
-
const graphServiceTag = await getGraphServiceTag(_izContext, storageResource.graphServerTag);
|
|
1046
|
+
const graphServiceTag = await getGraphServiceTag(_izContext, storageResource.graphServerTag, bucketName);
|
|
1043
1047
|
|
|
1044
1048
|
if (!graphServiceTag) {
|
|
1045
1049
|
validateStatus.status = false;
|
|
@@ -1122,7 +1126,7 @@ async function validateLocalSchema(_izContext, schemasPath, serviceConfigPath) {
|
|
|
1122
1126
|
}
|
|
1123
1127
|
return res.records[0]
|
|
1124
1128
|
})
|
|
1125
|
-
: await getObjSchemaS3WithHierarchy(_izContext, link.from.objType);
|
|
1129
|
+
: await getObjSchemaS3WithHierarchy(_izContext, link.from.objType, bucketName);
|
|
1126
1130
|
|
|
1127
1131
|
const toObjectSchema = (link.to.objType.serviceTag === iz_serviceTag)
|
|
1128
1132
|
? await getLocalObjectSchemasWithHierarchy(_izContext, link.to.objType.objectType, schemasPath)
|
|
@@ -1133,7 +1137,7 @@ async function validateLocalSchema(_izContext, schemasPath, serviceConfigPath) {
|
|
|
1133
1137
|
}
|
|
1134
1138
|
return res.records[0]
|
|
1135
1139
|
})
|
|
1136
|
-
: await getObjSchemaS3WithHierarchy(_izContext, link.to.objType);
|
|
1140
|
+
: await getObjSchemaS3WithHierarchy(_izContext, link.to.objType, bucketName);
|
|
1137
1141
|
|
|
1138
1142
|
|
|
1139
1143
|
if (!validateStatus.validateErrors.length) {
|
|
@@ -1208,14 +1212,14 @@ async function validateLocalSchema(_izContext, schemasPath, serviceConfigPath) {
|
|
|
1208
1212
|
// validate ref relationships in external path s3
|
|
1209
1213
|
await Promise.all(
|
|
1210
1214
|
allReferenceObjectRelationships.map(async (refRelSchema) => {
|
|
1211
|
-
const relSchemaFromRef = await getRelationshipSchema
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1215
|
+
const relSchemaFromRef = await getRelationshipSchema(
|
|
1216
|
+
_izContext,
|
|
1217
|
+
{
|
|
1218
|
+
serviceTag: refRelSchema.relationshipServiceTag,
|
|
1219
|
+
relationshipTag: refRelSchema.relationshipTag
|
|
1220
|
+
},
|
|
1221
|
+
bucketName
|
|
1222
|
+
)
|
|
1219
1223
|
if (!relSchemaFromRef) {
|
|
1220
1224
|
validateStatus.status = false;
|
|
1221
1225
|
validateStatus.referenceErrors.push(`Invalid reference relationship of objectType: '${refRelSchema.objectType}' >> relationshipTag: '${refRelSchema.relationshipTag}' not exists in service: '${refRelSchema.relationshipServiceTag}'`)
|