@unito/integration-api 7.1.0 → 7.1.1
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/guards.d.ts +18 -6
- package/dist/src/guards.js +17 -15
- package/dist/src/index.cjs +20 -18
- package/dist/src/jsonPathHelpers.js +3 -3
- package/package.json +1 -1
package/dist/src/guards.d.ts
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import * as Api from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Options for type guard functions.
|
|
4
|
+
*/
|
|
5
|
+
export interface GuardOptions {
|
|
6
|
+
/**
|
|
7
|
+
* When false, validate structure only (values are strings) without checking enum membership.
|
|
8
|
+
* This allows forward compatibility when a newer integration-api adds Semantics or FieldValueTypes
|
|
9
|
+
* that the consumer doesn't know about yet.
|
|
10
|
+
* Defaults to true.
|
|
11
|
+
*/
|
|
12
|
+
strict?: boolean;
|
|
13
|
+
}
|
|
2
14
|
/**
|
|
3
15
|
* Checks if the input is a record<unknown, unknown>
|
|
4
16
|
* @param potentialObject - The value to check.
|
|
@@ -40,31 +52,31 @@ export declare function isRelationPointer(potentialRelationPointer: unknown): po
|
|
|
40
52
|
* @param potentialReferenceRelation - The value to check.
|
|
41
53
|
* @returns True if the value is a ReferenceRelation, false otherwise.
|
|
42
54
|
*/
|
|
43
|
-
export declare function isReferenceRelation(potentialReferenceRelation: unknown): potentialReferenceRelation is Api.ReferenceRelation;
|
|
55
|
+
export declare function isReferenceRelation(potentialReferenceRelation: unknown, options?: GuardOptions): potentialReferenceRelation is Api.ReferenceRelation;
|
|
44
56
|
/**
|
|
45
57
|
* Checks if the input is an Api.RelationSummary object.
|
|
46
58
|
* @param potentialRelationSummary - The value to check.
|
|
47
59
|
* @returns True if the value is a RelationSummary, false otherwise.
|
|
48
60
|
*/
|
|
49
|
-
export declare function isRelationSummary(potentialRelationSummary: unknown): potentialRelationSummary is Api.RelationSummary;
|
|
61
|
+
export declare function isRelationSummary(potentialRelationSummary: unknown, options?: GuardOptions): potentialRelationSummary is Api.RelationSummary;
|
|
50
62
|
/**
|
|
51
63
|
* Checks if the input is an Api.Relation object.
|
|
52
64
|
* @param potentialRelation - The value to check.
|
|
53
65
|
* @returns True if the value is a Relation, false otherwise.
|
|
54
66
|
*/
|
|
55
|
-
export declare function isRelation(potentialRelation: unknown): potentialRelation is Api.Relation;
|
|
67
|
+
export declare function isRelation(potentialRelation: unknown, options?: GuardOptions): potentialRelation is Api.Relation;
|
|
56
68
|
/**
|
|
57
69
|
* Checks if the input is an Api.RelationSchema object.
|
|
58
70
|
* @param potentialRelationSchema - The value to check.
|
|
59
71
|
* @returns True if the value is a RelationSchema, false otherwise.
|
|
60
72
|
*/
|
|
61
|
-
export declare function isRelationSchema(potentialRelationSchema: unknown): potentialRelationSchema is Api.RelationSchema;
|
|
73
|
+
export declare function isRelationSchema(potentialRelationSchema: unknown, options?: GuardOptions): potentialRelationSchema is Api.RelationSchema;
|
|
62
74
|
/**
|
|
63
75
|
* Checks if the input is an Api.RelationSchema object or the string '__self'.
|
|
64
76
|
* @param potentialRelationSchema - The value to check.
|
|
65
77
|
* @returns True if the value is a RelationSchema or '__self', false otherwise.
|
|
66
78
|
*/
|
|
67
|
-
export declare function isRelationSchemaOrSelf(potentialRelationSchemaOrSelf: unknown): potentialRelationSchemaOrSelf is Api.RelationSchema | '__self';
|
|
79
|
+
export declare function isRelationSchemaOrSelf(potentialRelationSchemaOrSelf: unknown, options?: GuardOptions): potentialRelationSchemaOrSelf is Api.RelationSchema | '__self';
|
|
68
80
|
/**
|
|
69
81
|
* Checks if the input is an Api.FieldValueType.
|
|
70
82
|
* @param potentialFieldValueType - The value to check.
|
|
@@ -82,4 +94,4 @@ export declare function isSemantic(potentialSemantic: unknown): potentialSemanti
|
|
|
82
94
|
* @param potentialFieldSchema - The value to check.
|
|
83
95
|
* @returns True if the value is a FieldSchema, false otherwise.
|
|
84
96
|
*/
|
|
85
|
-
export declare function isFieldSchema(potentialFieldSchema: unknown): potentialFieldSchema is Api.FieldSchema;
|
|
97
|
+
export declare function isFieldSchema(potentialFieldSchema: unknown, options?: GuardOptions): potentialFieldSchema is Api.FieldSchema;
|
package/dist/src/guards.js
CHANGED
|
@@ -44,7 +44,7 @@ export function isItem(potentialItem) {
|
|
|
44
44
|
return (isObject(potentialItem) &&
|
|
45
45
|
isObject(potentialItem['fields']) &&
|
|
46
46
|
Array.isArray(potentialItem['relations']) &&
|
|
47
|
-
potentialItem['relations'].every(isRelation));
|
|
47
|
+
potentialItem['relations'].every((r) => isRelation(r)));
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
50
|
* Checks if the input is an Api.RelationPointer object.
|
|
@@ -61,57 +61,57 @@ export function isRelationPointer(potentialRelationPointer) {
|
|
|
61
61
|
* @param potentialReferenceRelation - The value to check.
|
|
62
62
|
* @returns True if the value is a ReferenceRelation, false otherwise.
|
|
63
63
|
*/
|
|
64
|
-
export function isReferenceRelation(potentialReferenceRelation) {
|
|
64
|
+
export function isReferenceRelation(potentialReferenceRelation, options) {
|
|
65
65
|
return (isObject(potentialReferenceRelation) &&
|
|
66
66
|
isString(potentialReferenceRelation['name']) &&
|
|
67
67
|
isString(potentialReferenceRelation['path']) &&
|
|
68
68
|
isString(potentialReferenceRelation['label']) &&
|
|
69
|
-
isRelationSchemaOrSelf(potentialReferenceRelation['schema']));
|
|
69
|
+
isRelationSchemaOrSelf(potentialReferenceRelation['schema'], options));
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
72
|
* Checks if the input is an Api.RelationSummary object.
|
|
73
73
|
* @param potentialRelationSummary - The value to check.
|
|
74
74
|
* @returns True if the value is a RelationSummary, false otherwise.
|
|
75
75
|
*/
|
|
76
|
-
export function isRelationSummary(potentialRelationSummary) {
|
|
76
|
+
export function isRelationSummary(potentialRelationSummary, options) {
|
|
77
77
|
return (isObject(potentialRelationSummary) &&
|
|
78
78
|
isString(potentialRelationSummary['name']) &&
|
|
79
79
|
isString(potentialRelationSummary['label']) &&
|
|
80
|
-
isRelationSchemaOrSelf(potentialRelationSummary['schema']));
|
|
80
|
+
isRelationSchemaOrSelf(potentialRelationSummary['schema'], options));
|
|
81
81
|
}
|
|
82
82
|
/**
|
|
83
83
|
* Checks if the input is an Api.Relation object.
|
|
84
84
|
* @param potentialRelation - The value to check.
|
|
85
85
|
* @returns True if the value is a Relation, false otherwise.
|
|
86
86
|
*/
|
|
87
|
-
export function isRelation(potentialRelation) {
|
|
87
|
+
export function isRelation(potentialRelation, options) {
|
|
88
88
|
return (isObject(potentialRelation) &&
|
|
89
89
|
isString(potentialRelation['name']) &&
|
|
90
90
|
isString(potentialRelation['path']) &&
|
|
91
91
|
isString(potentialRelation['label']) &&
|
|
92
|
-
isRelationSchema(potentialRelation['schema']));
|
|
92
|
+
isRelationSchema(potentialRelation['schema'], options));
|
|
93
93
|
}
|
|
94
94
|
/**
|
|
95
95
|
* Checks if the input is an Api.RelationSchema object.
|
|
96
96
|
* @param potentialRelationSchema - The value to check.
|
|
97
97
|
* @returns True if the value is a RelationSchema, false otherwise.
|
|
98
98
|
*/
|
|
99
|
-
export function isRelationSchema(potentialRelationSchema) {
|
|
99
|
+
export function isRelationSchema(potentialRelationSchema, options) {
|
|
100
100
|
return (isObject(potentialRelationSchema) &&
|
|
101
101
|
isString(potentialRelationSchema['label']) &&
|
|
102
102
|
Array.isArray(potentialRelationSchema['fields']) &&
|
|
103
|
-
potentialRelationSchema['fields'].every(isFieldSchema) &&
|
|
103
|
+
potentialRelationSchema['fields'].every((f) => isFieldSchema(f, options)) &&
|
|
104
104
|
(isUndefined(potentialRelationSchema['relations']) ||
|
|
105
105
|
(Array.isArray(potentialRelationSchema['relations']) &&
|
|
106
|
-
potentialRelationSchema['relations'].every(isRelationSummary))));
|
|
106
|
+
potentialRelationSchema['relations'].every((r) => isRelationSummary(r, options)))));
|
|
107
107
|
}
|
|
108
108
|
/**
|
|
109
109
|
* Checks if the input is an Api.RelationSchema object or the string '__self'.
|
|
110
110
|
* @param potentialRelationSchema - The value to check.
|
|
111
111
|
* @returns True if the value is a RelationSchema or '__self', false otherwise.
|
|
112
112
|
*/
|
|
113
|
-
export function isRelationSchemaOrSelf(potentialRelationSchemaOrSelf) {
|
|
114
|
-
return isRelationSchema(potentialRelationSchemaOrSelf) || potentialRelationSchemaOrSelf === '__self';
|
|
113
|
+
export function isRelationSchemaOrSelf(potentialRelationSchemaOrSelf, options) {
|
|
114
|
+
return isRelationSchema(potentialRelationSchemaOrSelf, options) || potentialRelationSchemaOrSelf === '__self';
|
|
115
115
|
}
|
|
116
116
|
/**
|
|
117
117
|
* Checks if the input is an Api.FieldValueType.
|
|
@@ -134,11 +134,13 @@ export function isSemantic(potentialSemantic) {
|
|
|
134
134
|
* @param potentialFieldSchema - The value to check.
|
|
135
135
|
* @returns True if the value is a FieldSchema, false otherwise.
|
|
136
136
|
*/
|
|
137
|
-
export function isFieldSchema(potentialFieldSchema) {
|
|
137
|
+
export function isFieldSchema(potentialFieldSchema, options) {
|
|
138
|
+
const strict = options?.strict ?? true;
|
|
138
139
|
return (isObject(potentialFieldSchema) &&
|
|
139
140
|
isString(potentialFieldSchema['name']) &&
|
|
140
141
|
isString(potentialFieldSchema['label']) &&
|
|
141
142
|
isString(potentialFieldSchema['type']) &&
|
|
142
|
-
isFieldValueType(potentialFieldSchema['type']) &&
|
|
143
|
-
(isUndefined(potentialFieldSchema['semantic']) ||
|
|
143
|
+
(strict ? isFieldValueType(potentialFieldSchema['type']) : true) &&
|
|
144
|
+
(isUndefined(potentialFieldSchema['semantic']) ||
|
|
145
|
+
(strict ? isSemantic(potentialFieldSchema['semantic']) : isString(potentialFieldSchema['semantic']))));
|
|
144
146
|
}
|
package/dist/src/index.cjs
CHANGED
|
@@ -161,7 +161,7 @@ function isItem(potentialItem) {
|
|
|
161
161
|
return (isObject(potentialItem) &&
|
|
162
162
|
isObject(potentialItem['fields']) &&
|
|
163
163
|
Array.isArray(potentialItem['relations']) &&
|
|
164
|
-
potentialItem['relations'].every(isRelation));
|
|
164
|
+
potentialItem['relations'].every((r) => isRelation(r)));
|
|
165
165
|
}
|
|
166
166
|
/**
|
|
167
167
|
* Checks if the input is an Api.RelationPointer object.
|
|
@@ -178,57 +178,57 @@ function isRelationPointer(potentialRelationPointer) {
|
|
|
178
178
|
* @param potentialReferenceRelation - The value to check.
|
|
179
179
|
* @returns True if the value is a ReferenceRelation, false otherwise.
|
|
180
180
|
*/
|
|
181
|
-
function isReferenceRelation(potentialReferenceRelation) {
|
|
181
|
+
function isReferenceRelation(potentialReferenceRelation, options) {
|
|
182
182
|
return (isObject(potentialReferenceRelation) &&
|
|
183
183
|
isString(potentialReferenceRelation['name']) &&
|
|
184
184
|
isString(potentialReferenceRelation['path']) &&
|
|
185
185
|
isString(potentialReferenceRelation['label']) &&
|
|
186
|
-
isRelationSchemaOrSelf(potentialReferenceRelation['schema']));
|
|
186
|
+
isRelationSchemaOrSelf(potentialReferenceRelation['schema'], options));
|
|
187
187
|
}
|
|
188
188
|
/**
|
|
189
189
|
* Checks if the input is an Api.RelationSummary object.
|
|
190
190
|
* @param potentialRelationSummary - The value to check.
|
|
191
191
|
* @returns True if the value is a RelationSummary, false otherwise.
|
|
192
192
|
*/
|
|
193
|
-
function isRelationSummary(potentialRelationSummary) {
|
|
193
|
+
function isRelationSummary(potentialRelationSummary, options) {
|
|
194
194
|
return (isObject(potentialRelationSummary) &&
|
|
195
195
|
isString(potentialRelationSummary['name']) &&
|
|
196
196
|
isString(potentialRelationSummary['label']) &&
|
|
197
|
-
isRelationSchemaOrSelf(potentialRelationSummary['schema']));
|
|
197
|
+
isRelationSchemaOrSelf(potentialRelationSummary['schema'], options));
|
|
198
198
|
}
|
|
199
199
|
/**
|
|
200
200
|
* Checks if the input is an Api.Relation object.
|
|
201
201
|
* @param potentialRelation - The value to check.
|
|
202
202
|
* @returns True if the value is a Relation, false otherwise.
|
|
203
203
|
*/
|
|
204
|
-
function isRelation(potentialRelation) {
|
|
204
|
+
function isRelation(potentialRelation, options) {
|
|
205
205
|
return (isObject(potentialRelation) &&
|
|
206
206
|
isString(potentialRelation['name']) &&
|
|
207
207
|
isString(potentialRelation['path']) &&
|
|
208
208
|
isString(potentialRelation['label']) &&
|
|
209
|
-
isRelationSchema(potentialRelation['schema']));
|
|
209
|
+
isRelationSchema(potentialRelation['schema'], options));
|
|
210
210
|
}
|
|
211
211
|
/**
|
|
212
212
|
* Checks if the input is an Api.RelationSchema object.
|
|
213
213
|
* @param potentialRelationSchema - The value to check.
|
|
214
214
|
* @returns True if the value is a RelationSchema, false otherwise.
|
|
215
215
|
*/
|
|
216
|
-
function isRelationSchema(potentialRelationSchema) {
|
|
216
|
+
function isRelationSchema(potentialRelationSchema, options) {
|
|
217
217
|
return (isObject(potentialRelationSchema) &&
|
|
218
218
|
isString(potentialRelationSchema['label']) &&
|
|
219
219
|
Array.isArray(potentialRelationSchema['fields']) &&
|
|
220
|
-
potentialRelationSchema['fields'].every(isFieldSchema) &&
|
|
220
|
+
potentialRelationSchema['fields'].every((f) => isFieldSchema(f, options)) &&
|
|
221
221
|
(isUndefined(potentialRelationSchema['relations']) ||
|
|
222
222
|
(Array.isArray(potentialRelationSchema['relations']) &&
|
|
223
|
-
potentialRelationSchema['relations'].every(isRelationSummary))));
|
|
223
|
+
potentialRelationSchema['relations'].every((r) => isRelationSummary(r, options)))));
|
|
224
224
|
}
|
|
225
225
|
/**
|
|
226
226
|
* Checks if the input is an Api.RelationSchema object or the string '__self'.
|
|
227
227
|
* @param potentialRelationSchema - The value to check.
|
|
228
228
|
* @returns True if the value is a RelationSchema or '__self', false otherwise.
|
|
229
229
|
*/
|
|
230
|
-
function isRelationSchemaOrSelf(potentialRelationSchemaOrSelf) {
|
|
231
|
-
return isRelationSchema(potentialRelationSchemaOrSelf) || potentialRelationSchemaOrSelf === '__self';
|
|
230
|
+
function isRelationSchemaOrSelf(potentialRelationSchemaOrSelf, options) {
|
|
231
|
+
return isRelationSchema(potentialRelationSchemaOrSelf, options) || potentialRelationSchemaOrSelf === '__self';
|
|
232
232
|
}
|
|
233
233
|
/**
|
|
234
234
|
* Checks if the input is an Api.FieldValueType.
|
|
@@ -251,13 +251,15 @@ function isSemantic(potentialSemantic) {
|
|
|
251
251
|
* @param potentialFieldSchema - The value to check.
|
|
252
252
|
* @returns True if the value is a FieldSchema, false otherwise.
|
|
253
253
|
*/
|
|
254
|
-
function isFieldSchema(potentialFieldSchema) {
|
|
254
|
+
function isFieldSchema(potentialFieldSchema, options) {
|
|
255
|
+
const strict = options?.strict ?? true;
|
|
255
256
|
return (isObject(potentialFieldSchema) &&
|
|
256
257
|
isString(potentialFieldSchema['name']) &&
|
|
257
258
|
isString(potentialFieldSchema['label']) &&
|
|
258
259
|
isString(potentialFieldSchema['type']) &&
|
|
259
|
-
isFieldValueType(potentialFieldSchema['type']) &&
|
|
260
|
-
(isUndefined(potentialFieldSchema['semantic']) ||
|
|
260
|
+
(strict ? isFieldValueType(potentialFieldSchema['type']) : true) &&
|
|
261
|
+
(isUndefined(potentialFieldSchema['semantic']) ||
|
|
262
|
+
(strict ? isSemantic(potentialFieldSchema['semantic']) : isString(potentialFieldSchema['semantic']))));
|
|
261
263
|
}
|
|
262
264
|
|
|
263
265
|
const referenceToStringLikeConfiguration = {
|
|
@@ -672,15 +674,15 @@ function findRelationByJSONPath(item, query) {
|
|
|
672
674
|
current = previousSchema;
|
|
673
675
|
}
|
|
674
676
|
const result = applyToken(current, token);
|
|
675
|
-
if (isObject(result) && isRelationSchema(result['schema'])) {
|
|
677
|
+
if (isObject(result) && isRelationSchema(result['schema'], { strict: false })) {
|
|
676
678
|
schemas.push(result['schema']);
|
|
677
679
|
}
|
|
678
680
|
current = result;
|
|
679
681
|
}
|
|
680
|
-
if (isRelation(current)) {
|
|
682
|
+
if (isRelation(current, { strict: false })) {
|
|
681
683
|
return current;
|
|
682
684
|
}
|
|
683
|
-
if (isReferenceRelation(current) || isRelationSummary(current)) {
|
|
685
|
+
if (isReferenceRelation(current, { strict: false }) || isRelationSummary(current, { strict: false })) {
|
|
684
686
|
const latestSchema = schemas[schemas.length - 1];
|
|
685
687
|
if (latestSchema === undefined) {
|
|
686
688
|
throw new Error(`No schema found for relation ${current.label}`);
|
|
@@ -15,15 +15,15 @@ export function findRelationByJSONPath(item, query) {
|
|
|
15
15
|
current = previousSchema;
|
|
16
16
|
}
|
|
17
17
|
const result = applyToken(current, token);
|
|
18
|
-
if (Guards.isObject(result) && Guards.isRelationSchema(result['schema'])) {
|
|
18
|
+
if (Guards.isObject(result) && Guards.isRelationSchema(result['schema'], { strict: false })) {
|
|
19
19
|
schemas.push(result['schema']);
|
|
20
20
|
}
|
|
21
21
|
current = result;
|
|
22
22
|
}
|
|
23
|
-
if (Guards.isRelation(current)) {
|
|
23
|
+
if (Guards.isRelation(current, { strict: false })) {
|
|
24
24
|
return current;
|
|
25
25
|
}
|
|
26
|
-
if (Guards.isReferenceRelation(current) || Guards.isRelationSummary(current)) {
|
|
26
|
+
if (Guards.isReferenceRelation(current, { strict: false }) || Guards.isRelationSummary(current, { strict: false })) {
|
|
27
27
|
const latestSchema = schemas[schemas.length - 1];
|
|
28
28
|
if (latestSchema === undefined) {
|
|
29
29
|
throw new Error(`No schema found for relation ${current.label}`);
|