@unito/integration-api 8.0.9 → 8.1.0
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/dist/src/index.cjs
CHANGED
|
@@ -1016,7 +1016,7 @@ function findFieldBySemantic(fields, semantic) {
|
|
|
1016
1016
|
/**
|
|
1017
1017
|
* JSONPath parser that returns a relation that is guaranteed to have its schema populated.
|
|
1018
1018
|
*/
|
|
1019
|
-
function findRelationByJSONPath(item, query) {
|
|
1019
|
+
async function findRelationByJSONPath(item, query, options = {}) {
|
|
1020
1020
|
const tokens = parseJSONPath(query);
|
|
1021
1021
|
const schemas = [];
|
|
1022
1022
|
let current = item;
|
|
@@ -1033,6 +1033,16 @@ function findRelationByJSONPath(item, query) {
|
|
|
1033
1033
|
schemas.push(result['schema']);
|
|
1034
1034
|
}
|
|
1035
1035
|
current = result;
|
|
1036
|
+
if (isRelationPointer(current) && options.resolveItem) {
|
|
1037
|
+
const { itemPath, relationName } = current;
|
|
1038
|
+
const item = await options.resolveItem(itemPath);
|
|
1039
|
+
if (item) {
|
|
1040
|
+
current = item.relations.find(relation => relation.name === relationName);
|
|
1041
|
+
}
|
|
1042
|
+
else {
|
|
1043
|
+
return undefined;
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1036
1046
|
}
|
|
1037
1047
|
if (isRelation(current, { strict: false })) {
|
|
1038
1048
|
return current;
|
|
@@ -2,4 +2,6 @@ import * as Api from './types.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* JSONPath parser that returns a relation that is guaranteed to have its schema populated.
|
|
4
4
|
*/
|
|
5
|
-
export declare function findRelationByJSONPath(item: Api.Item, query: string
|
|
5
|
+
export declare function findRelationByJSONPath(item: Api.Item, query: string, options?: {
|
|
6
|
+
resolveItem?: (itemPath: string) => Promise<Api.Item | undefined>;
|
|
7
|
+
}): Promise<Api.Relation | Api.RelationWithPopulatedSchema<Api.RelationSummary> | Api.RelationWithPopulatedSchema<Api.ReferenceRelation> | undefined>;
|
|
@@ -2,7 +2,7 @@ import * as Guards from './guards.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* JSONPath parser that returns a relation that is guaranteed to have its schema populated.
|
|
4
4
|
*/
|
|
5
|
-
export function findRelationByJSONPath(item, query) {
|
|
5
|
+
export async function findRelationByJSONPath(item, query, options = {}) {
|
|
6
6
|
const tokens = parseJSONPath(query);
|
|
7
7
|
const schemas = [];
|
|
8
8
|
let current = item;
|
|
@@ -19,6 +19,16 @@ export function findRelationByJSONPath(item, query) {
|
|
|
19
19
|
schemas.push(result['schema']);
|
|
20
20
|
}
|
|
21
21
|
current = result;
|
|
22
|
+
if (Guards.isRelationPointer(current) && options.resolveItem) {
|
|
23
|
+
const { itemPath, relationName } = current;
|
|
24
|
+
const item = await options.resolveItem(itemPath);
|
|
25
|
+
if (item) {
|
|
26
|
+
current = item.relations.find(relation => relation.name === relationName);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
22
32
|
}
|
|
23
33
|
if (Guards.isRelation(current, { strict: false })) {
|
|
24
34
|
return current;
|