@unito/integration-api 4.2.1 → 4.2.2

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.
@@ -568,27 +568,31 @@ const fieldTypeCompatibilityMatrix = {
568
568
  */
569
569
  function findRelationByJSONPath(item, query) {
570
570
  const tokens = parseJSONPath(query);
571
- const relations = [];
571
+ const schemas = [];
572
572
  let current = item;
573
573
  for (const token of tokens) {
574
574
  if (current === '__self') {
575
- const previousRelation = relations[relations.length - 1];
576
- if (!previousRelation) {
575
+ const previousSchema = schemas[schemas.length - 1];
576
+ if (!previousSchema) {
577
577
  throw new Error(`Invalid use of __self`);
578
578
  }
579
- current = previousRelation.schema;
579
+ current = previousSchema;
580
580
  }
581
581
  const result = applyToken(current, token);
582
- if (isReferenceRelation(result) && isRelationSchema(result.schema)) {
583
- relations.push(result);
584
- }
585
- else if (isRelationSummary(result) && isRelationSchema(result.schema)) {
586
- relations.push(result);
582
+ if (isObject(result) && isRelationSchema(result['schema'])) {
583
+ schemas.push(result['schema']);
587
584
  }
588
585
  current = result;
589
586
  }
587
+ if (isRelation(current)) {
588
+ return current;
589
+ }
590
590
  if (isReferenceRelation(current) || isRelationSummary(current)) {
591
- return relations[relations.length - 1];
591
+ const latestSchema = schemas[schemas.length - 1];
592
+ if (latestSchema === undefined) {
593
+ throw new Error(`No schema found for relation ${current.label}`);
594
+ }
595
+ return { ...current, schema: latestSchema };
592
596
  }
593
597
  return undefined;
594
598
  }
@@ -4,27 +4,31 @@ import * as Api from './index.js';
4
4
  */
5
5
  export function findRelationByJSONPath(item, query) {
6
6
  const tokens = parseJSONPath(query);
7
- const relations = [];
7
+ const schemas = [];
8
8
  let current = item;
9
9
  for (const token of tokens) {
10
10
  if (current === '__self') {
11
- const previousRelation = relations[relations.length - 1];
12
- if (!previousRelation) {
11
+ const previousSchema = schemas[schemas.length - 1];
12
+ if (!previousSchema) {
13
13
  throw new Error(`Invalid use of __self`);
14
14
  }
15
- current = previousRelation.schema;
15
+ current = previousSchema;
16
16
  }
17
17
  const result = applyToken(current, token);
18
- if (Api.isReferenceRelation(result) && Api.isRelationSchema(result.schema)) {
19
- relations.push(result);
20
- }
21
- else if (Api.isRelationSummary(result) && Api.isRelationSchema(result.schema)) {
22
- relations.push(result);
18
+ if (Api.isObject(result) && Api.isRelationSchema(result['schema'])) {
19
+ schemas.push(result['schema']);
23
20
  }
24
21
  current = result;
25
22
  }
23
+ if (Api.isRelation(current)) {
24
+ return current;
25
+ }
26
26
  if (Api.isReferenceRelation(current) || Api.isRelationSummary(current)) {
27
- return relations[relations.length - 1];
27
+ const latestSchema = schemas[schemas.length - 1];
28
+ if (latestSchema === undefined) {
29
+ throw new Error(`No schema found for relation ${current.label}`);
30
+ }
31
+ return { ...current, schema: latestSchema };
28
32
  }
29
33
  return undefined;
30
34
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unito/integration-api",
3
- "version": "4.2.1",
3
+ "version": "4.2.2",
4
4
  "description": "The Unito Integration API",
5
5
  "type": "module",
6
6
  "types": "./dist/src/index.d.ts",