@unito/integration-api 4.1.1 → 4.1.3

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.
@@ -0,0 +1,61 @@
1
+ import * as Api from './types.js';
2
+ /**
3
+ * Checks if the input is an Api.ItemSummary object.
4
+ * @param potentialItemSummary - The value to check.
5
+ * @returns True if the value is an ItemSummary, false otherwise.
6
+ */
7
+ export declare function isItemSummary(potentialItemSummary: unknown): potentialItemSummary is Api.ItemSummary;
8
+ /**
9
+ * Checks if the input is an Api.Item object.
10
+ * @param potentialItem - The value to check.
11
+ * @returns True if the value is an Item, false otherwise.
12
+ */
13
+ export declare function isItem(potentialItem: unknown): potentialItem is Api.Item;
14
+ /**
15
+ * Checks if the input is an Api.ReferenceRelation object.
16
+ * @param potentialReferenceRelation - The value to check.
17
+ * @returns True if the value is a ReferenceRelation, false otherwise.
18
+ */
19
+ export declare function isReferenceRelation(potentialReferenceRelation: unknown): potentialReferenceRelation is Api.ReferenceRelation;
20
+ /**
21
+ * Checks if the input is an Api.RelationSummary object.
22
+ * @param potentialRelationSummary - The value to check.
23
+ * @returns True if the value is a RelationSummary, false otherwise.
24
+ */
25
+ export declare function isRelationSummary(potentialRelationSummary: unknown): potentialRelationSummary is Api.RelationSummary;
26
+ /**
27
+ * Checks if the input is an Api.Relation object.
28
+ * @param potentialRelation - The value to check.
29
+ * @returns True if the value is a Relation, false otherwise.
30
+ */
31
+ export declare function isRelation(potentialRelation: unknown): potentialRelation is Api.Relation;
32
+ /**
33
+ * Checks if the input is an Api.RelationSchema object.
34
+ * @param potentialRelationSchema - The value to check.
35
+ * @returns True if the value is a RelationSchema, false otherwise.
36
+ */
37
+ export declare function isRelationSchema(potentialRelationSchema: unknown): potentialRelationSchema is Api.RelationSchema;
38
+ /**
39
+ * Checks if the input is an Api.RelationSchema object or the string '__self'.
40
+ * @param potentialRelationSchema - The value to check.
41
+ * @returns True if the value is a RelationSchema or '__self', false otherwise.
42
+ */
43
+ export declare function isRelationSchemaOrSelf(potentialRelationSchemaOrSelf: unknown): potentialRelationSchemaOrSelf is Api.RelationSchema | '__self';
44
+ /**
45
+ * Checks if the input is an Api.FieldValueType.
46
+ * @param potentialFieldValueType - The value to check.
47
+ * @returns True if the value is a FieldValueType, false otherwise.
48
+ */
49
+ export declare function isFieldValueType(potentialFieldValueType: unknown): potentialFieldValueType is Api.FieldValueType;
50
+ /**
51
+ * Checks if the input is an Api.Semantic value.
52
+ * @param potentialSemantic - The value to check.
53
+ * @returns True if the value is a Semantic, false otherwise.
54
+ */
55
+ export declare function isSemantic(potentialSemantic: unknown): potentialSemantic is Api.Semantic;
56
+ /**
57
+ * Checks if the input is an Api.FieldSchema object.
58
+ * @param potentialFieldSchema - The value to check.
59
+ * @returns True if the value is a FieldSchema, false otherwise.
60
+ */
61
+ export declare function isFieldSchema(potentialFieldSchema: unknown): potentialFieldSchema is Api.FieldSchema;
@@ -0,0 +1,133 @@
1
+ import * as Api from './types.js';
2
+ /**
3
+ * Checks if the input is a record<unknown, unknown>
4
+ * @param potentialObject - The value to check.
5
+ * @returns True if the value is a record, false otherwise.
6
+ */
7
+ function isObject(potentialObject) {
8
+ return typeof potentialObject === 'object' && potentialObject !== null && !Array.isArray(potentialObject);
9
+ }
10
+ /**
11
+ * Checks if the input is a string.
12
+ * @param potentialString - The value to check.
13
+ * @returns True if the value is a string, false otherwise.
14
+ */
15
+ function isString(potentialString) {
16
+ return typeof potentialString === 'string';
17
+ }
18
+ /**
19
+ * Checks if the input is undefined.
20
+ * @param potentialUndefined - The value to check.
21
+ * @returns True if the value is undefined, false otherwise.
22
+ */
23
+ function isUndefined(potentialUndefined) {
24
+ return potentialUndefined === undefined;
25
+ }
26
+ /**
27
+ * Checks if the input is an Api.ItemSummary object.
28
+ * @param potentialItemSummary - The value to check.
29
+ * @returns True if the value is an ItemSummary, false otherwise.
30
+ */
31
+ export function isItemSummary(potentialItemSummary) {
32
+ return (isObject(potentialItemSummary) &&
33
+ isString(potentialItemSummary['path']) &&
34
+ (isUndefined(potentialItemSummary['fields']) || isObject(potentialItemSummary['fields'])) &&
35
+ (isUndefined(potentialItemSummary['relations']) ||
36
+ (Array.isArray(potentialItemSummary['relations']) && potentialItemSummary['relations'].every(isString))));
37
+ }
38
+ /**
39
+ * Checks if the input is an Api.Item object.
40
+ * @param potentialItem - The value to check.
41
+ * @returns True if the value is an Item, false otherwise.
42
+ */
43
+ export function isItem(potentialItem) {
44
+ return (isObject(potentialItem) &&
45
+ isObject(potentialItem['fields']) &&
46
+ Array.isArray(potentialItem['relations']) &&
47
+ potentialItem['relations'].every(isRelation));
48
+ }
49
+ /**
50
+ * Checks if the input is an Api.ReferenceRelation object.
51
+ * @param potentialReferenceRelation - The value to check.
52
+ * @returns True if the value is a ReferenceRelation, false otherwise.
53
+ */
54
+ export function isReferenceRelation(potentialReferenceRelation) {
55
+ return (isObject(potentialReferenceRelation) &&
56
+ isString(potentialReferenceRelation['path']) &&
57
+ isString(potentialReferenceRelation['label']) &&
58
+ isRelationSchemaOrSelf(potentialReferenceRelation['schema']));
59
+ }
60
+ /**
61
+ * Checks if the input is an Api.RelationSummary object.
62
+ * @param potentialRelationSummary - The value to check.
63
+ * @returns True if the value is a RelationSummary, false otherwise.
64
+ */
65
+ export function isRelationSummary(potentialRelationSummary) {
66
+ return (isObject(potentialRelationSummary) &&
67
+ isString(potentialRelationSummary['name']) &&
68
+ isString(potentialRelationSummary['label']) &&
69
+ isRelationSchemaOrSelf(potentialRelationSummary['schema']));
70
+ }
71
+ /**
72
+ * Checks if the input is an Api.Relation object.
73
+ * @param potentialRelation - The value to check.
74
+ * @returns True if the value is a Relation, false otherwise.
75
+ */
76
+ export function isRelation(potentialRelation) {
77
+ return (isObject(potentialRelation) &&
78
+ isString(potentialRelation['name']) &&
79
+ isString(potentialRelation['path']) &&
80
+ isString(potentialRelation['label']) &&
81
+ isRelationSchema(potentialRelation['schema']));
82
+ }
83
+ /**
84
+ * Checks if the input is an Api.RelationSchema object.
85
+ * @param potentialRelationSchema - The value to check.
86
+ * @returns True if the value is a RelationSchema, false otherwise.
87
+ */
88
+ export function isRelationSchema(potentialRelationSchema) {
89
+ return (isObject(potentialRelationSchema) &&
90
+ isString(potentialRelationSchema['label']) &&
91
+ Array.isArray(potentialRelationSchema['fields']) &&
92
+ potentialRelationSchema['fields'].every(isFieldSchema) &&
93
+ (isUndefined(potentialRelationSchema['relations']) ||
94
+ (Array.isArray(potentialRelationSchema['relations']) &&
95
+ potentialRelationSchema['relations'].every(isRelationSummary))));
96
+ }
97
+ /**
98
+ * Checks if the input is an Api.RelationSchema object or the string '__self'.
99
+ * @param potentialRelationSchema - The value to check.
100
+ * @returns True if the value is a RelationSchema or '__self', false otherwise.
101
+ */
102
+ export function isRelationSchemaOrSelf(potentialRelationSchemaOrSelf) {
103
+ return isRelationSchema(potentialRelationSchemaOrSelf) || potentialRelationSchemaOrSelf === '__self';
104
+ }
105
+ /**
106
+ * Checks if the input is an Api.FieldValueType.
107
+ * @param potentialFieldValueType - The value to check.
108
+ * @returns True if the value is a FieldValueType, false otherwise.
109
+ */
110
+ export function isFieldValueType(potentialFieldValueType) {
111
+ return Object.values(Api.FieldValueTypes).includes(potentialFieldValueType);
112
+ }
113
+ /**
114
+ * Checks if the input is an Api.Semantic value.
115
+ * @param potentialSemantic - The value to check.
116
+ * @returns True if the value is a Semantic, false otherwise.
117
+ */
118
+ export function isSemantic(potentialSemantic) {
119
+ return Object.values(Api.Semantics).includes(potentialSemantic);
120
+ }
121
+ /**
122
+ * Checks if the input is an Api.FieldSchema object.
123
+ * @param potentialFieldSchema - The value to check.
124
+ * @returns True if the value is a FieldSchema, false otherwise.
125
+ */
126
+ export function isFieldSchema(potentialFieldSchema) {
127
+ return (isObject(potentialFieldSchema) &&
128
+ isString(potentialFieldSchema['name']) &&
129
+ isString(potentialFieldSchema['label']) &&
130
+ isString(potentialFieldSchema['type']) &&
131
+ isFieldValueType(potentialFieldSchema['type']) &&
132
+ (isUndefined(potentialFieldSchema['semantic']) || isSemantic(potentialFieldSchema['semantic'])));
133
+ }
@@ -85,8 +85,151 @@ const StatusCodes = {
85
85
  INTERNAL_SERVER_ERROR: 500,
86
86
  };
87
87
 
88
+ /**
89
+ * Checks if the input is a record<unknown, unknown>
90
+ * @param potentialObject - The value to check.
91
+ * @returns True if the value is a record, false otherwise.
92
+ */
93
+ function isObject(potentialObject) {
94
+ return typeof potentialObject === 'object' && potentialObject !== null && !Array.isArray(potentialObject);
95
+ }
96
+ /**
97
+ * Checks if the input is a string.
98
+ * @param potentialString - The value to check.
99
+ * @returns True if the value is a string, false otherwise.
100
+ */
101
+ function isString(potentialString) {
102
+ return typeof potentialString === 'string';
103
+ }
104
+ /**
105
+ * Checks if the input is undefined.
106
+ * @param potentialUndefined - The value to check.
107
+ * @returns True if the value is undefined, false otherwise.
108
+ */
109
+ function isUndefined(potentialUndefined) {
110
+ return potentialUndefined === undefined;
111
+ }
112
+ /**
113
+ * Checks if the input is an Api.ItemSummary object.
114
+ * @param potentialItemSummary - The value to check.
115
+ * @returns True if the value is an ItemSummary, false otherwise.
116
+ */
117
+ function isItemSummary(potentialItemSummary) {
118
+ return (isObject(potentialItemSummary) &&
119
+ isString(potentialItemSummary['path']) &&
120
+ (isUndefined(potentialItemSummary['fields']) || isObject(potentialItemSummary['fields'])) &&
121
+ (isUndefined(potentialItemSummary['relations']) ||
122
+ (Array.isArray(potentialItemSummary['relations']) && potentialItemSummary['relations'].every(isString))));
123
+ }
124
+ /**
125
+ * Checks if the input is an Api.Item object.
126
+ * @param potentialItem - The value to check.
127
+ * @returns True if the value is an Item, false otherwise.
128
+ */
129
+ function isItem(potentialItem) {
130
+ return (isObject(potentialItem) &&
131
+ isObject(potentialItem['fields']) &&
132
+ Array.isArray(potentialItem['relations']) &&
133
+ potentialItem['relations'].every(isRelation));
134
+ }
135
+ /**
136
+ * Checks if the input is an Api.ReferenceRelation object.
137
+ * @param potentialReferenceRelation - The value to check.
138
+ * @returns True if the value is a ReferenceRelation, false otherwise.
139
+ */
140
+ function isReferenceRelation(potentialReferenceRelation) {
141
+ return (isObject(potentialReferenceRelation) &&
142
+ isString(potentialReferenceRelation['path']) &&
143
+ isString(potentialReferenceRelation['label']) &&
144
+ isRelationSchemaOrSelf(potentialReferenceRelation['schema']));
145
+ }
146
+ /**
147
+ * Checks if the input is an Api.RelationSummary object.
148
+ * @param potentialRelationSummary - The value to check.
149
+ * @returns True if the value is a RelationSummary, false otherwise.
150
+ */
151
+ function isRelationSummary(potentialRelationSummary) {
152
+ return (isObject(potentialRelationSummary) &&
153
+ isString(potentialRelationSummary['name']) &&
154
+ isString(potentialRelationSummary['label']) &&
155
+ isRelationSchemaOrSelf(potentialRelationSummary['schema']));
156
+ }
157
+ /**
158
+ * Checks if the input is an Api.Relation object.
159
+ * @param potentialRelation - The value to check.
160
+ * @returns True if the value is a Relation, false otherwise.
161
+ */
162
+ function isRelation(potentialRelation) {
163
+ return (isObject(potentialRelation) &&
164
+ isString(potentialRelation['name']) &&
165
+ isString(potentialRelation['path']) &&
166
+ isString(potentialRelation['label']) &&
167
+ isRelationSchema(potentialRelation['schema']));
168
+ }
169
+ /**
170
+ * Checks if the input is an Api.RelationSchema object.
171
+ * @param potentialRelationSchema - The value to check.
172
+ * @returns True if the value is a RelationSchema, false otherwise.
173
+ */
174
+ function isRelationSchema(potentialRelationSchema) {
175
+ return (isObject(potentialRelationSchema) &&
176
+ isString(potentialRelationSchema['label']) &&
177
+ Array.isArray(potentialRelationSchema['fields']) &&
178
+ potentialRelationSchema['fields'].every(isFieldSchema) &&
179
+ (isUndefined(potentialRelationSchema['relations']) ||
180
+ (Array.isArray(potentialRelationSchema['relations']) &&
181
+ potentialRelationSchema['relations'].every(isRelationSummary))));
182
+ }
183
+ /**
184
+ * Checks if the input is an Api.RelationSchema object or the string '__self'.
185
+ * @param potentialRelationSchema - The value to check.
186
+ * @returns True if the value is a RelationSchema or '__self', false otherwise.
187
+ */
188
+ function isRelationSchemaOrSelf(potentialRelationSchemaOrSelf) {
189
+ return isRelationSchema(potentialRelationSchemaOrSelf) || potentialRelationSchemaOrSelf === '__self';
190
+ }
191
+ /**
192
+ * Checks if the input is an Api.FieldValueType.
193
+ * @param potentialFieldValueType - The value to check.
194
+ * @returns True if the value is a FieldValueType, false otherwise.
195
+ */
196
+ function isFieldValueType(potentialFieldValueType) {
197
+ return Object.values(FieldValueTypes).includes(potentialFieldValueType);
198
+ }
199
+ /**
200
+ * Checks if the input is an Api.Semantic value.
201
+ * @param potentialSemantic - The value to check.
202
+ * @returns True if the value is a Semantic, false otherwise.
203
+ */
204
+ function isSemantic(potentialSemantic) {
205
+ return Object.values(Semantics).includes(potentialSemantic);
206
+ }
207
+ /**
208
+ * Checks if the input is an Api.FieldSchema object.
209
+ * @param potentialFieldSchema - The value to check.
210
+ * @returns True if the value is a FieldSchema, false otherwise.
211
+ */
212
+ function isFieldSchema(potentialFieldSchema) {
213
+ return (isObject(potentialFieldSchema) &&
214
+ isString(potentialFieldSchema['name']) &&
215
+ isString(potentialFieldSchema['label']) &&
216
+ isString(potentialFieldSchema['type']) &&
217
+ isFieldValueType(potentialFieldSchema['type']) &&
218
+ (isUndefined(potentialFieldSchema['semantic']) || isSemantic(potentialFieldSchema['semantic'])));
219
+ }
220
+
88
221
  exports.FieldValueTypes = FieldValueTypes;
89
222
  exports.OperatorTypes = OperatorTypes;
90
223
  exports.RelationSemantics = RelationSemantics;
91
224
  exports.Semantics = Semantics;
92
225
  exports.StatusCodes = StatusCodes;
226
+ exports.isFieldSchema = isFieldSchema;
227
+ exports.isFieldValueType = isFieldValueType;
228
+ exports.isItem = isItem;
229
+ exports.isItemSummary = isItemSummary;
230
+ exports.isReferenceRelation = isReferenceRelation;
231
+ exports.isRelation = isRelation;
232
+ exports.isRelationSchema = isRelationSchema;
233
+ exports.isRelationSchemaOrSelf = isRelationSchemaOrSelf;
234
+ exports.isRelationSummary = isRelationSummary;
235
+ exports.isSemantic = isSemantic;
@@ -1 +1,2 @@
1
1
  export * from './types.js';
2
+ export * from './guards.js';
package/dist/src/index.js CHANGED
@@ -1 +1,2 @@
1
1
  export * from './types.js';
2
+ export * from './guards.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unito/integration-api",
3
- "version": "4.1.1",
3
+ "version": "4.1.3",
4
4
  "description": "The Unito Integration API",
5
5
  "type": "module",
6
6
  "types": "./dist/src/index.d.ts",