@izara_frontend/service-schemas 1.0.6 → 1.0.8
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 +3 -3
- package/src/getObjectSchema.js +58 -18
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@izara_frontend/service-schemas",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@izara_project/izara-shared-core": "^1.0.
|
|
24
|
-
"@izara_project/izara-shared-service-schemas": "^1.0.
|
|
23
|
+
"@izara_project/izara-shared-core": "^1.0.9",
|
|
24
|
+
"@izara_project/izara-shared-service-schemas": "^1.0.40",
|
|
25
25
|
"lodash": "^4.17.21"
|
|
26
26
|
}
|
|
27
27
|
}
|
package/src/getObjectSchema.js
CHANGED
|
@@ -1189,9 +1189,9 @@ export function getObjectLinksWithRequestProperties() {
|
|
|
1189
1189
|
|
|
1190
1190
|
|
|
1191
1191
|
// core executor that does the actual work and optionally updates hook state
|
|
1192
|
-
const execute = useCallback(async (objType, { updateState = true } = {}) => {
|
|
1192
|
+
const execute = useCallback(async (objType, { updateState = true, returnPathLinkTypeId = false, returnLinkTypeId = false } = {}) => {
|
|
1193
1193
|
|
|
1194
|
-
async function getObjectLinksWithRequestPropertiesMain(objType) {
|
|
1194
|
+
async function getObjectLinksWithRequestPropertiesMain(objType, returnPathLinkTypeId, returnLinkTypeId) {
|
|
1195
1195
|
|
|
1196
1196
|
// validate objType (some validators throw, some return errors)
|
|
1197
1197
|
try {
|
|
@@ -1201,6 +1201,8 @@ export function getObjectLinksWithRequestProperties() {
|
|
|
1201
1201
|
}
|
|
1202
1202
|
let returnLinks = [];
|
|
1203
1203
|
let mainErrorsFound = [];
|
|
1204
|
+
let objectLinkIndexByLinkTypeId = {};
|
|
1205
|
+
let objectLinkIndexByPathLinkTypeId = {};
|
|
1204
1206
|
|
|
1205
1207
|
const [mainObjTypeConcat] = createObjTypeConcat(objType);
|
|
1206
1208
|
|
|
@@ -1228,16 +1230,55 @@ export function getObjectLinksWithRequestProperties() {
|
|
|
1228
1230
|
|
|
1229
1231
|
returnLinks.push(newLink);
|
|
1230
1232
|
}));
|
|
1231
|
-
|
|
1233
|
+
|
|
1234
|
+
|
|
1235
|
+
if (returnLinkTypeId === true || returnPathLinkTypeId === true) {
|
|
1236
|
+
for (let objectLinkIdx = 0; objectLinkIdx < objectLinks.length; objectLinkIdx++) {
|
|
1237
|
+
|
|
1238
|
+
const objectLinkData = objectLinks[objectLinkIdx];
|
|
1239
|
+
// start add index of link by linkTypeId
|
|
1240
|
+
const linkTypeId = sharedSchemaUtils.createLinkTypeId(
|
|
1241
|
+
objectLinkData.base.objType,
|
|
1242
|
+
objectLinkData.other.objType,
|
|
1243
|
+
objectLinkData.relType,
|
|
1244
|
+
objectLinkData.base.direction
|
|
1245
|
+
)
|
|
1246
|
+
|
|
1247
|
+
Object.assign(objectLinkIndexByLinkTypeId, { [linkTypeId.result]: objectLinkIdx });
|
|
1248
|
+
// end add index of link by linkTypeId
|
|
1249
|
+
|
|
1250
|
+
|
|
1251
|
+
// start add index of link by pathLinkTypeId
|
|
1252
|
+
const pathLinkTypeId = sharedSchemaUtils.createPathLinkTypeId(
|
|
1253
|
+
{
|
|
1254
|
+
objType: objectLinkData.other.objType,
|
|
1255
|
+
relType: objectLinkData.relType,
|
|
1256
|
+
relationshipDirection: objectLinkData.base.direction
|
|
1257
|
+
}
|
|
1258
|
+
)
|
|
1259
|
+
Object.assign(objectLinkIndexByPathLinkTypeId, { [pathLinkTypeId.result]: objectLinkIdx });
|
|
1260
|
+
// end add index of link by linkTypeId
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1232
1263
|
|
|
1233
1264
|
|
|
1234
1265
|
|
|
1235
|
-
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
const result = { [mainObjTypeConcat]: returnLinks };
|
|
1269
|
+
if (returnLinkTypeId === true) {
|
|
1270
|
+
Object.assign(result, { [`${mainObjTypeConcat}_linkTypeIdIndex`]: objectLinkIndexByLinkTypeId });
|
|
1271
|
+
}
|
|
1272
|
+
if (returnPathLinkTypeId === true) {
|
|
1273
|
+
Object.assign(result, { [`${mainObjTypeConcat}_pathLinkTypeIdIndex`]: objectLinkIndexByPathLinkTypeId });
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
return [result, mainErrorsFound];
|
|
1236
1277
|
}
|
|
1237
1278
|
|
|
1238
1279
|
try {
|
|
1239
1280
|
|
|
1240
|
-
const [schema, errorsFound] = await getObjectLinksWithRequestPropertiesMain(objType);
|
|
1281
|
+
const [schema, errorsFound] = await getObjectLinksWithRequestPropertiesMain(objType, returnPathLinkTypeId, returnLinkTypeId);
|
|
1241
1282
|
|
|
1242
1283
|
if (updateState) {
|
|
1243
1284
|
if (errorsFound && errorsFound.length) {
|
|
@@ -1264,19 +1305,20 @@ export function getObjectLinksWithRequestProperties() {
|
|
|
1264
1305
|
// run can be used two ways:
|
|
1265
1306
|
// 1) run(objType) -> updates hook state and returns Promise<[collected, errors]>
|
|
1266
1307
|
// 2) run().initiate(objType) -> does NOT touch hook state, returns Promise<[collected, errors]>
|
|
1267
|
-
const run = useCallback((objType) => {
|
|
1308
|
+
const run = useCallback((objType, settings = { returnPathLinkTypeId: false, returnLinkTypeId: false }) => {
|
|
1268
1309
|
if (typeof objType === "undefined") {
|
|
1269
1310
|
return {
|
|
1270
|
-
initiate: (objType) => execute(objType, { updateState: false })
|
|
1311
|
+
initiate: (objType, initiateSettings = {}) => execute(objType, { ...settings, ...initiateSettings, updateState: false }),
|
|
1271
1312
|
};
|
|
1272
1313
|
}
|
|
1273
1314
|
// direct call: update state
|
|
1274
|
-
return execute(objType, { updateState: true });
|
|
1315
|
+
return execute(objType, { ...settings, updateState: true });
|
|
1275
1316
|
}, [execute]);
|
|
1276
1317
|
|
|
1277
1318
|
return [result, run, { errorsFound }];
|
|
1278
1319
|
}
|
|
1279
1320
|
|
|
1321
|
+
|
|
1280
1322
|
export function collectObjectLinksWithRequestProperties() {
|
|
1281
1323
|
|
|
1282
1324
|
const [, getObjectLinksWithRequestPropertiesFn] = getObjectLinksWithRequestProperties();
|
|
@@ -1291,9 +1333,8 @@ export function collectObjectLinksWithRequestProperties() {
|
|
|
1291
1333
|
useEffect(() => { resultRef.current = result; }, [result]);
|
|
1292
1334
|
|
|
1293
1335
|
// core executor that does the actual work and optionally updates hook state
|
|
1294
|
-
const execute = useCallback(async (objType, { updateState = true } = {}) => {
|
|
1295
|
-
|
|
1296
|
-
async function collectObjectLinksWithRequestPropertiesMain(objType) {
|
|
1336
|
+
const execute = useCallback(async (objType, { updateState = true, returnPathLinkTypeId = false, returnLinkTypeId = false } = {}) => {
|
|
1337
|
+
async function collectObjectLinksWithRequestPropertiesMain(objType, returnPathLinkTypeId, returnLinkTypeId) {
|
|
1297
1338
|
|
|
1298
1339
|
// validate objType (some validators throw, some return errors)
|
|
1299
1340
|
try {
|
|
@@ -1315,7 +1356,7 @@ export function collectObjectLinksWithRequestProperties() {
|
|
|
1315
1356
|
|
|
1316
1357
|
|
|
1317
1358
|
|
|
1318
|
-
const [objectLinks, getSchemaErrors] = await getObjectLinksWithRequestPropertiesFn().initiate(objType);
|
|
1359
|
+
const [objectLinks, getSchemaErrors] = await getObjectLinksWithRequestPropertiesFn().initiate(objType, { returnPathLinkTypeId, returnLinkTypeId });
|
|
1319
1360
|
|
|
1320
1361
|
|
|
1321
1362
|
return [objectLinks, getSchemaErrors];
|
|
@@ -1324,12 +1365,12 @@ export function collectObjectLinksWithRequestProperties() {
|
|
|
1324
1365
|
try {
|
|
1325
1366
|
|
|
1326
1367
|
|
|
1327
|
-
const [schema, errorsFound] = await collectObjectLinksWithRequestPropertiesMain(objType);
|
|
1368
|
+
const [schema, errorsFound] = await collectObjectLinksWithRequestPropertiesMain(objType, returnPathLinkTypeId, returnLinkTypeId);
|
|
1328
1369
|
|
|
1329
1370
|
if (updateState) {
|
|
1330
1371
|
if (errorsFound && errorsFound.length) {
|
|
1331
1372
|
setErrorsFound(errorsFound);
|
|
1332
|
-
setResult(null);
|
|
1373
|
+
// setResult(null);
|
|
1333
1374
|
} else {
|
|
1334
1375
|
const [currentObjTypeConcat] = createObjTypeConcat(objType);
|
|
1335
1376
|
|
|
@@ -1366,15 +1407,15 @@ export function collectObjectLinksWithRequestProperties() {
|
|
|
1366
1407
|
// run can be used two ways:
|
|
1367
1408
|
// 1) run(objType) -> updates hook state and returns Promise<[collected, errors]>
|
|
1368
1409
|
// 2) run().initiate(objType) -> does NOT touch hook state, returns Promise<[collected, errors]>
|
|
1369
|
-
const run = useCallback((objType) => {
|
|
1410
|
+
const run = useCallback((objType, settings = { returnPathLinkTypeId: false, returnLinkTypeId: false }) => {
|
|
1370
1411
|
if (typeof objType === "undefined") {
|
|
1371
1412
|
return {
|
|
1372
|
-
initiate: (objType) => execute(objType, { updateState: false }),
|
|
1413
|
+
initiate: (objType, initiateSettings = {}) => execute(objType, { ...settings, ...initiateSettings, updateState: false }),
|
|
1373
1414
|
clear: () => { setResult(null); setErrorsFound([]); }
|
|
1374
1415
|
};
|
|
1375
1416
|
}
|
|
1376
1417
|
// direct call: update state
|
|
1377
|
-
return execute(objType, { updateState: true });
|
|
1418
|
+
return execute(objType, { ...settings, updateState: true });
|
|
1378
1419
|
}, [execute]);
|
|
1379
1420
|
|
|
1380
1421
|
return [result, run, { errorsFound }];
|
|
@@ -1382,7 +1423,6 @@ export function collectObjectLinksWithRequestProperties() {
|
|
|
1382
1423
|
|
|
1383
1424
|
|
|
1384
1425
|
|
|
1385
|
-
|
|
1386
1426
|
/**
|
|
1387
1427
|
* TODO: need to use function inside reformatObjectSchema lib instead. create in this cause need to fix bug first
|
|
1388
1428
|
* create object schema that already combine fieldNames between main objectSchema and addOnDataStructure.type=versionedData
|