componentsjs 5.0.0-beta.2 → 5.0.0-beta.6
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/CHANGELOG.md +53 -0
- package/README.md +51 -0
- package/components/context.jsonld +29 -2
- package/lib/ComponentsManager.js +3 -5
- package/lib/construction/ConfigConstructorPool.js +1 -1
- package/lib/construction/strategy/ConstructionStrategyCommonJs.d.ts +3 -1
- package/lib/construction/strategy/ConstructionStrategyCommonJs.js +8 -10
- package/lib/construction/strategy/ConstructionStrategyCommonJsString.js +6 -8
- package/lib/loading/ComponentRegistryFinalizer.js +7 -1
- package/lib/loading/ComponentsManagerBuilder.d.ts +6 -0
- package/lib/loading/ComponentsManagerBuilder.js +4 -1
- package/lib/preprocess/ConfigPreprocessorComponent.js +12 -13
- package/lib/preprocess/GenericsContext.d.ts +49 -5
- package/lib/preprocess/GenericsContext.js +280 -15
- package/lib/preprocess/ParameterHandler.d.ts +3 -0
- package/lib/preprocess/ParameterHandler.js +2 -2
- package/lib/preprocess/parameterproperty/ParameterPropertyHandlerRange.d.ts +32 -11
- package/lib/preprocess/parameterproperty/ParameterPropertyHandlerRange.js +376 -119
- package/lib/rdf/Iris.d.ts +1 -1
- package/lib/rdf/Iris.js +1 -1
- package/lib/rdf/RdfStreamIncluder.js +2 -2
- package/lib/util/ErrorResourcesContext.d.ts +11 -14
- package/lib/util/ErrorResourcesContext.js +44 -22
- package/package.json +2 -2
|
@@ -3,12 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ParameterPropertyHandlerRange = void 0;
|
|
4
4
|
const Iris_1 = require("../../rdf/Iris");
|
|
5
5
|
const ErrorResourcesContext_1 = require("../../util/ErrorResourcesContext");
|
|
6
|
+
const GenericsContext_1 = require("../GenericsContext");
|
|
6
7
|
/**
|
|
7
8
|
* If a param range is defined, apply the type and validate the range.
|
|
8
9
|
*/
|
|
9
10
|
class ParameterPropertyHandlerRange {
|
|
10
|
-
constructor(objectLoader) {
|
|
11
|
+
constructor(objectLoader, typeChecking) {
|
|
11
12
|
this.objectLoader = objectLoader;
|
|
13
|
+
this.typeChecking = typeChecking;
|
|
12
14
|
}
|
|
13
15
|
canHandle(value, configRoot, parameter) {
|
|
14
16
|
return Boolean(parameter.property.range);
|
|
@@ -27,33 +29,45 @@ class ParameterPropertyHandlerRange {
|
|
|
27
29
|
* @param genericsContext Context for generic types.
|
|
28
30
|
*/
|
|
29
31
|
captureType(value, param, genericsContext) {
|
|
30
|
-
|
|
32
|
+
const errorContext = { param };
|
|
33
|
+
const conflict = this.hasValueType(value, param.property.range, errorContext, genericsContext);
|
|
34
|
+
if (!conflict || !this.typeChecking) {
|
|
31
35
|
return value;
|
|
32
36
|
}
|
|
33
|
-
|
|
37
|
+
ParameterPropertyHandlerRange.throwIncorrectTypeError(value, param, genericsContext, conflict);
|
|
34
38
|
}
|
|
35
39
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
+
* Check if the given value is of the given type.
|
|
41
|
+
*
|
|
42
|
+
* For valid literals, the `valueRaw` field will be set.
|
|
43
|
+
*
|
|
40
44
|
* @param value The value.
|
|
41
|
-
* @param
|
|
42
|
-
* @param paramRange The parameter's range.
|
|
45
|
+
* @param type The parameter's range.
|
|
43
46
|
* @param genericsContext Context for generic types.
|
|
47
|
+
* @param errorContext The context for error reporting.
|
|
48
|
+
* @return IParamValueConflict A conflict value if there was an error, or undefined if there was no error
|
|
44
49
|
*/
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
50
|
+
hasValueType(value, type, errorContext, genericsContext) {
|
|
51
|
+
errorContext = Object.assign(Object.assign({}, errorContext), { value, type });
|
|
52
|
+
if (!type) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (type.isA('ParameterRangeWildcard')) {
|
|
56
|
+
return;
|
|
48
57
|
}
|
|
49
|
-
if (!value &&
|
|
50
|
-
return
|
|
58
|
+
if (!value && type.isA('ParameterRangeUndefined')) {
|
|
59
|
+
return;
|
|
51
60
|
}
|
|
61
|
+
// Always match variable values
|
|
62
|
+
if (value && value.isA('Variable')) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
// Handle literal values
|
|
52
66
|
if (value && value.type === 'Literal') {
|
|
53
67
|
let parsed;
|
|
54
|
-
switch (
|
|
68
|
+
switch (type.value) {
|
|
55
69
|
case Iris_1.IRIS_XSD.string:
|
|
56
|
-
return
|
|
70
|
+
return;
|
|
57
71
|
case Iris_1.IRIS_XSD.boolean:
|
|
58
72
|
if (value.value === 'true') {
|
|
59
73
|
value.term.valueRaw = true;
|
|
@@ -62,9 +76,12 @@ class ParameterPropertyHandlerRange {
|
|
|
62
76
|
value.term.valueRaw = false;
|
|
63
77
|
}
|
|
64
78
|
else {
|
|
65
|
-
return
|
|
79
|
+
return {
|
|
80
|
+
description: 'value must either be "true" or "false"',
|
|
81
|
+
context: errorContext,
|
|
82
|
+
};
|
|
66
83
|
}
|
|
67
|
-
return
|
|
84
|
+
return;
|
|
68
85
|
case Iris_1.IRIS_XSD.integer:
|
|
69
86
|
case Iris_1.IRIS_XSD.number:
|
|
70
87
|
case Iris_1.IRIS_XSD.int:
|
|
@@ -72,172 +89,405 @@ class ParameterPropertyHandlerRange {
|
|
|
72
89
|
case Iris_1.IRIS_XSD.long:
|
|
73
90
|
parsed = Number.parseInt(value.value, 10);
|
|
74
91
|
if (Number.isNaN(parsed)) {
|
|
75
|
-
return
|
|
92
|
+
return {
|
|
93
|
+
description: `value is not a number`,
|
|
94
|
+
context: errorContext,
|
|
95
|
+
};
|
|
76
96
|
}
|
|
77
97
|
// ParseInt also parses floats to ints!
|
|
78
98
|
if (String(parsed) !== value.value) {
|
|
79
|
-
return
|
|
99
|
+
return {
|
|
100
|
+
description: `value can not be a float`,
|
|
101
|
+
context: errorContext,
|
|
102
|
+
};
|
|
80
103
|
}
|
|
81
104
|
value.term.valueRaw = parsed;
|
|
82
|
-
return
|
|
105
|
+
return;
|
|
83
106
|
case Iris_1.IRIS_XSD.float:
|
|
84
107
|
case Iris_1.IRIS_XSD.decimal:
|
|
85
108
|
case Iris_1.IRIS_XSD.double:
|
|
86
109
|
parsed = Number.parseFloat(value.value);
|
|
87
110
|
if (Number.isNaN(parsed)) {
|
|
88
|
-
return
|
|
111
|
+
return {
|
|
112
|
+
description: `value is not a number`,
|
|
113
|
+
context: errorContext,
|
|
114
|
+
};
|
|
89
115
|
}
|
|
90
116
|
value.term.valueRaw = parsed;
|
|
91
|
-
return
|
|
117
|
+
return;
|
|
92
118
|
case Iris_1.IRIS_RDF.JSON:
|
|
93
119
|
try {
|
|
94
120
|
parsed = JSON.parse(value.value);
|
|
95
121
|
value.term.valueRaw = parsed;
|
|
96
122
|
}
|
|
97
|
-
catch (
|
|
98
|
-
return
|
|
123
|
+
catch (error) {
|
|
124
|
+
return {
|
|
125
|
+
description: `JSON parse exception: ${error.message}`,
|
|
126
|
+
context: errorContext,
|
|
127
|
+
};
|
|
99
128
|
}
|
|
100
|
-
return
|
|
129
|
+
return;
|
|
101
130
|
}
|
|
102
131
|
}
|
|
103
132
|
// Allow IRIs to be casted to strings
|
|
104
|
-
if (value &&
|
|
105
|
-
return
|
|
133
|
+
if (value && type.value === Iris_1.IRIS_XSD.string && value.type === 'NamedNode') {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
// Try to match the value with the parameter's range (which will always be defined at this stage)
|
|
137
|
+
// Check if the value has a super-type that equals the parameter's range
|
|
138
|
+
let hasTypeConflict;
|
|
139
|
+
if (value) {
|
|
140
|
+
const hasTypeConflictInner = this.hasType(value, type, genericsContext, value.property.genericTypeInstancesComponentScope, value.properties.genericTypeInstances, errorContext);
|
|
141
|
+
if (!hasTypeConflictInner) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
hasTypeConflict = hasTypeConflictInner;
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
hasTypeConflict = undefined;
|
|
148
|
+
}
|
|
149
|
+
// Check if the param type is an array
|
|
150
|
+
if (value && type.isA('ParameterRangeArray')) {
|
|
151
|
+
if (!value.list) {
|
|
152
|
+
return {
|
|
153
|
+
description: `value is not an RDF list`,
|
|
154
|
+
context: errorContext,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
const subConflicts = value.list.map(listElement => this
|
|
158
|
+
.hasValueType(listElement, type.property.parameterRangeValue, errorContext, genericsContext))
|
|
159
|
+
.filter(subConflict => subConflict !== undefined);
|
|
160
|
+
return subConflicts.length === 0 ?
|
|
161
|
+
undefined :
|
|
162
|
+
{
|
|
163
|
+
description: `one or more array values are invalid`,
|
|
164
|
+
context: errorContext,
|
|
165
|
+
causes: subConflicts,
|
|
166
|
+
};
|
|
106
167
|
}
|
|
107
|
-
if
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
168
|
+
// Check if the param type is a composed type
|
|
169
|
+
if (type.isA('ParameterRangeUnion')) {
|
|
170
|
+
const subConflicts = [];
|
|
171
|
+
for (const parameterRangeElement of type.properties.parameterRangeElements) {
|
|
172
|
+
const subConflict = this.hasValueType(value, parameterRangeElement, errorContext, genericsContext);
|
|
173
|
+
if (!subConflict) {
|
|
174
|
+
return;
|
|
111
175
|
}
|
|
112
|
-
|
|
113
|
-
.hasParamValueValidType(listElement, param, paramRange.property.parameterRangeValue, genericsContext));
|
|
176
|
+
subConflicts.push(subConflict);
|
|
114
177
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
178
|
+
return {
|
|
179
|
+
description: `no union values are valid`,
|
|
180
|
+
context: errorContext,
|
|
181
|
+
causes: subConflicts,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
if (type.isA('ParameterRangeIntersection')) {
|
|
185
|
+
const subConflicts = type.properties.parameterRangeElements
|
|
186
|
+
.map(child => this.hasValueType(value, child, errorContext, genericsContext));
|
|
187
|
+
if (subConflicts.every(subConflict => subConflict === undefined)) {
|
|
188
|
+
return;
|
|
119
189
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
190
|
+
return {
|
|
191
|
+
description: `not all intersection values are valid`,
|
|
192
|
+
context: errorContext,
|
|
193
|
+
causes: subConflicts.filter(subConflict => subConflict !== undefined),
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
if (type.isA('ParameterRangeTuple')) {
|
|
197
|
+
if (!value) {
|
|
198
|
+
return {
|
|
199
|
+
description: `undefined value is not an RDF list`,
|
|
200
|
+
context: errorContext,
|
|
201
|
+
};
|
|
123
202
|
}
|
|
124
|
-
if (
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
203
|
+
if (!value.list) {
|
|
204
|
+
return {
|
|
205
|
+
description: `value is not an RDF list`,
|
|
206
|
+
context: errorContext,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
// Iterate over list elements and try to match with tuple types
|
|
210
|
+
const listElements = value.list;
|
|
211
|
+
const tupleTypes = type.properties.parameterRangeElements;
|
|
212
|
+
let listIndex = 0;
|
|
213
|
+
let tupleIndex = 0;
|
|
214
|
+
while (listIndex < listElements.length && tupleIndex < tupleTypes.length) {
|
|
215
|
+
if (tupleTypes[tupleIndex].isA('ParameterRangeRest')) {
|
|
216
|
+
// Rest types can match multiple list elements, so only increment index if no match is found.
|
|
217
|
+
const subConflict = this.hasValueType(listElements[listIndex], tupleTypes[tupleIndex].property.parameterRangeValue, errorContext, genericsContext);
|
|
218
|
+
if (subConflict) {
|
|
219
|
+
tupleIndex++;
|
|
142
220
|
}
|
|
143
221
|
else {
|
|
144
|
-
if (!this.hasParamValueValidType(listElements[listIndex], param, tupleTypes[tupleIndex], genericsContext)) {
|
|
145
|
-
return false;
|
|
146
|
-
}
|
|
147
|
-
tupleIndex++;
|
|
148
222
|
listIndex++;
|
|
149
223
|
}
|
|
150
224
|
}
|
|
151
|
-
|
|
152
|
-
(tupleIndex
|
|
153
|
-
|
|
225
|
+
else {
|
|
226
|
+
const subConflict = this.hasValueType(listElements[listIndex], tupleTypes[tupleIndex], errorContext, genericsContext);
|
|
227
|
+
if (subConflict) {
|
|
228
|
+
return {
|
|
229
|
+
description: `tuple element is invalid`,
|
|
230
|
+
context: errorContext,
|
|
231
|
+
causes: [subConflict],
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
tupleIndex++;
|
|
235
|
+
listIndex++;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if (!(listIndex === listElements.length &&
|
|
239
|
+
(tupleIndex === tupleTypes.length ||
|
|
240
|
+
(tupleIndex === tupleTypes.length - 1 && tupleTypes[tupleIndex].isA('ParameterRangeRest'))))) {
|
|
241
|
+
return {
|
|
242
|
+
description: `tuple does not contain the expected number of elements`,
|
|
243
|
+
context: errorContext,
|
|
244
|
+
};
|
|
154
245
|
}
|
|
155
|
-
|
|
156
|
-
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
if (type.isA('ParameterRangeLiteral')) {
|
|
249
|
+
if (value && value.term.equals(type.property.parameterRangeValue.term)) {
|
|
250
|
+
return;
|
|
157
251
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
252
|
+
return {
|
|
253
|
+
description: `literal value is unequal`,
|
|
254
|
+
context: errorContext,
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
// Check if the range refers to `keyof ...`
|
|
258
|
+
if (type.isA('ParameterRangeKeyof')) {
|
|
259
|
+
const component = type.property.parameterRangeValue;
|
|
260
|
+
// Simulate a union of the member keys as literal parameter ranges
|
|
261
|
+
const simulatedUnionRange = this.objectLoader.createCompactedResource({
|
|
262
|
+
'@type': 'ParameterRangeUnion',
|
|
263
|
+
parameterRangeElements: component.properties.memberFields.map(memberField => ({
|
|
264
|
+
'@type': 'ParameterRangeLiteral',
|
|
265
|
+
parameterRangeValue: memberField.property.memberFieldName,
|
|
266
|
+
})),
|
|
267
|
+
});
|
|
268
|
+
const subConflict = this.hasValueType(value, simulatedUnionRange, errorContext, genericsContext);
|
|
269
|
+
if (!subConflict) {
|
|
270
|
+
return;
|
|
170
271
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
272
|
+
return {
|
|
273
|
+
description: `keyof value is invalid`,
|
|
274
|
+
context: errorContext,
|
|
275
|
+
causes: [subConflict],
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
// Check if the range refers to an indexed type such as `MyClass[myField]`
|
|
279
|
+
if (type.isA('ParameterRangeIndexed')) {
|
|
280
|
+
const object = type.property.parameterRangeIndexedObject;
|
|
281
|
+
const index = type.property.parameterRangeIndexedIndex;
|
|
282
|
+
// Collect field ranges
|
|
283
|
+
const fieldRanges = Object.fromEntries(object.properties.memberFields
|
|
284
|
+
.map(memberField => [memberField.property.memberFieldName.value, memberField.property.range ||
|
|
285
|
+
this.objectLoader.createCompactedResource({ '@type': 'ParameterRangeWildcard' })]));
|
|
286
|
+
// Handle literal indexes
|
|
287
|
+
if (index.isA('ParameterRangeLiteral')) {
|
|
288
|
+
const field = index.property.parameterRangeValue.value;
|
|
289
|
+
const range = fieldRanges[field];
|
|
290
|
+
if (!range) {
|
|
291
|
+
return {
|
|
292
|
+
description: `indexed index does not refer to a known field`,
|
|
293
|
+
context: errorContext,
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
const subConflict = this.hasValueType(value, range, errorContext, genericsContext);
|
|
297
|
+
if (!subConflict) {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
return {
|
|
301
|
+
description: `indexed value is invalid`,
|
|
302
|
+
context: errorContext,
|
|
303
|
+
causes: [subConflict],
|
|
304
|
+
};
|
|
174
305
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
306
|
+
return {
|
|
307
|
+
description: `indexed index type can not be understood`,
|
|
308
|
+
context: errorContext,
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
// Check if the range refers to a generic type
|
|
312
|
+
if (type.isA('ParameterRangeGenericTypeReference')) {
|
|
313
|
+
return genericsContext.bindGenericTypeToValue(type.property.parameterRangeGenericType.value, value, (subValue, subType) => this.hasValueType(subValue, subType, errorContext, genericsContext), (subType, superType) => this.hasType(subType, superType, genericsContext, undefined, [], errorContext));
|
|
314
|
+
}
|
|
315
|
+
// Check if the range refers to a component with a generic type
|
|
316
|
+
if (type.isA('ParameterRangeGenericComponent')) {
|
|
317
|
+
if (value) {
|
|
318
|
+
if (!value.property.genericTypeInstances) {
|
|
319
|
+
// For the defined generic type instances, apply them into the instance so they can be checked later during a
|
|
320
|
+
// call to GenericsContext#bindComponentGenericTypes.
|
|
321
|
+
value.property.genericTypeInstancesComponentScope = type.property.component;
|
|
322
|
+
value.properties.genericTypeInstances = type.properties.genericTypeInstances
|
|
323
|
+
.map(genericTypeInstance => {
|
|
324
|
+
// If we have a generic param type reference, instantiate them based on the current generics context
|
|
325
|
+
if (genericTypeInstance.isA('ParameterRangeGenericTypeReference')) {
|
|
326
|
+
if (!genericTypeInstance.property.parameterRangeGenericType) {
|
|
327
|
+
throw new ErrorResourcesContext_1.ErrorResourcesContext(`Invalid generic type instance in a ParameterRangeGenericComponent was detected: missing parameterRangeGenericType property.`, Object.assign(Object.assign({}, errorContext), { genericTypeInstance }));
|
|
328
|
+
}
|
|
329
|
+
return this.objectLoader.createCompactedResource({
|
|
330
|
+
'@type': 'ParameterRangeGenericTypeReference',
|
|
331
|
+
parameterRangeGenericType: genericTypeInstance.property.parameterRangeGenericType.value,
|
|
332
|
+
parameterRangeGenericBindings: genericsContext
|
|
333
|
+
.bindings[genericTypeInstance.property.parameterRangeGenericType.value],
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
// For all other param types, return the as-is
|
|
337
|
+
return genericTypeInstance;
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
// TODO: Once we support manual generics setting, we'll need to check here if we can merge with it.
|
|
342
|
+
// (sometimes, it can also be identical)
|
|
190
343
|
}
|
|
191
|
-
return this.hasParamValueValidType(value, param, paramRange.property.component, genericsContext);
|
|
192
344
|
}
|
|
193
|
-
|
|
194
|
-
if (
|
|
195
|
-
|
|
196
|
-
return true;
|
|
345
|
+
const subConflict = this.hasValueType(value, type.property.component, errorContext, genericsContext);
|
|
346
|
+
if (!subConflict) {
|
|
347
|
+
return;
|
|
197
348
|
}
|
|
198
|
-
return
|
|
349
|
+
return {
|
|
350
|
+
description: `generic component is invalid`,
|
|
351
|
+
context: errorContext,
|
|
352
|
+
causes: [subConflict],
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
// Check if this param defines a field with sub-params
|
|
356
|
+
if (type.isA('ParameterRangeCollectEntries')) {
|
|
357
|
+
// TODO: Add support for type-checking nested fields with collectEntries
|
|
358
|
+
return;
|
|
199
359
|
}
|
|
200
|
-
return
|
|
360
|
+
return hasTypeConflict || { description: 'unknown parameter type', context: errorContext };
|
|
201
361
|
}
|
|
202
|
-
throwIncorrectTypeError(value, parameter, genericsContext) {
|
|
362
|
+
static throwIncorrectTypeError(value, parameter, genericsContext, conflict) {
|
|
203
363
|
const withTypes = value && value.properties.types.length > 0 ? ` with types "${value.properties.types.map(resource => resource.value)}"` : '';
|
|
204
364
|
// eslint-disable-next-line @typescript-eslint/no-extra-parens
|
|
205
365
|
const valueString = value ? (value.list ? `[${value.list.map(subValue => subValue.value).join(', ')}]` : value.value) : 'undefined';
|
|
206
|
-
throw new ErrorResourcesContext_1.ErrorResourcesContext(`The value "${valueString}"${withTypes} for parameter "${parameter.value}" is not of required range type "${
|
|
366
|
+
throw new ErrorResourcesContext_1.ErrorResourcesContext(`The value "${valueString}"${withTypes} for parameter "${parameter.value}" is not of required range type "${ParameterPropertyHandlerRange.rangeToDisplayString(parameter.property.range, genericsContext)}"`, Object.assign(Object.assign({ cause: conflict, value: value || 'undefined' }, Object.keys(genericsContext.bindings).length > 0 ?
|
|
207
367
|
{ generics: `[\n ${Object.entries(genericsContext.bindings)
|
|
208
|
-
.map(([id,
|
|
368
|
+
.map(([id, subValue]) => `<${id}> => ${ParameterPropertyHandlerRange.rangeToDisplayString(subValue, genericsContext)}`)
|
|
209
369
|
.join(',\n ')}\n]` } :
|
|
210
370
|
{}), { parameter }));
|
|
211
371
|
}
|
|
212
|
-
|
|
213
|
-
|
|
372
|
+
/**
|
|
373
|
+
* Check if the given value is of the given type.
|
|
374
|
+
* @param value A value.
|
|
375
|
+
* @param type A type.
|
|
376
|
+
* @param genericsContext The current generics context.
|
|
377
|
+
* @param genericTypeInstancesComponentScope
|
|
378
|
+
* @param genericTypeInstances
|
|
379
|
+
* @param errorContext
|
|
380
|
+
*/
|
|
381
|
+
hasType(value, type, genericsContext, genericTypeInstancesComponentScope, genericTypeInstances, errorContext) {
|
|
382
|
+
var _a;
|
|
383
|
+
// Immediately return if the terms are equal
|
|
384
|
+
if (value.term.equals(type.term)) {
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
// Otherwise, iterate over the value's super types are recursively call this method again.
|
|
388
|
+
const subConflictTypes = [];
|
|
389
|
+
for (const valueSuperType of [...value.properties.extends, ...value.properties.type]) {
|
|
390
|
+
// Special case: if the super component is wrapped in a generic component instantiation, unwrap it.
|
|
391
|
+
if (((_a = valueSuperType.property.type) === null || _a === void 0 ? void 0 : _a.value) === this.objectLoader.contextResolved
|
|
392
|
+
.expandTerm('oo:GenericComponentExtension')) {
|
|
393
|
+
// First recursively continue calling hasType for the unwrapped component
|
|
394
|
+
const hasTypeConflict = this.hasType(valueSuperType.property.component, type, genericsContext, genericTypeInstancesComponentScope, genericTypeInstances, errorContext);
|
|
395
|
+
if (!hasTypeConflict) {
|
|
396
|
+
// If hasType has passed, validate the generic instantiations
|
|
397
|
+
// AND (possibly) the parameter's generic type instances against the component's generic params.
|
|
398
|
+
const superComponent = valueSuperType.property.component;
|
|
399
|
+
const genericsContextInner = new GenericsContext_1.GenericsContext(this.objectLoader, superComponent.properties.genericTypeParameters);
|
|
400
|
+
const typeTypeValidator = (subType, superType) => this
|
|
401
|
+
.hasType(subType, superType, genericsContextInner, undefined, [], errorContext);
|
|
402
|
+
// Try to bind the generic instances from the wrapped generic component instantiation
|
|
403
|
+
const subConflictWrapped = genericsContextInner.bindComponentGenericTypes(superComponent, valueSuperType.properties.genericTypeInstances
|
|
404
|
+
.map(instance => this.objectLoader.createCompactedResource({
|
|
405
|
+
parameterRangeGenericBindings: instance,
|
|
406
|
+
})), { value }, typeTypeValidator);
|
|
407
|
+
if (subConflictWrapped) {
|
|
408
|
+
return {
|
|
409
|
+
description: `invalid wrapped bindings for generic type instances for generic component extension of "${superComponent.value}"`,
|
|
410
|
+
context: { value, type },
|
|
411
|
+
causes: [subConflictWrapped],
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
// If the given generic type component scope applies to this component,
|
|
415
|
+
// Try to bind the generic instances from the parameter type-checking.
|
|
416
|
+
if (genericTypeInstancesComponentScope && genericTypeInstancesComponentScope.value === superComponent.value) {
|
|
417
|
+
const subConflictParam = genericsContextInner.bindComponentGenericTypes(superComponent, genericTypeInstances, { value }, typeTypeValidator);
|
|
418
|
+
if (subConflictParam) {
|
|
419
|
+
return {
|
|
420
|
+
description: `invalid parameter bindings for generic type instances for generic component extension of "${superComponent.value}"`,
|
|
421
|
+
context: { value, type },
|
|
422
|
+
causes: [subConflictParam],
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
// Extract the bound generic instances from the inner context into the actual context.
|
|
426
|
+
// This is needed for cases where param generics are bound via a wrapped generic component instantiation.
|
|
427
|
+
for (const [i, genericTypeInstance] of genericTypeInstances.entries()) {
|
|
428
|
+
const innerGenericType = genericTypeInstancesComponentScope.properties.genericTypeParameters[i].value;
|
|
429
|
+
if (genericTypeInstance.isA('ParameterRangeGenericTypeReference')) {
|
|
430
|
+
// If the generic type instance refers to another generic,
|
|
431
|
+
// bind it to the corresponding value of the inner context
|
|
432
|
+
const outerGenericType = genericTypeInstance.property.parameterRangeGenericType.value;
|
|
433
|
+
genericsContext.bindings[outerGenericType] = genericsContextInner.bindings[innerGenericType];
|
|
434
|
+
}
|
|
435
|
+
else if (!genericsContextInner.mergeRanges(genericsContextInner.bindings[innerGenericType], genericTypeInstance, typeTypeValidator)) {
|
|
436
|
+
// If the generic type instance is just a type, check it against the value in the inner context.
|
|
437
|
+
// If it does not match, return an error.
|
|
438
|
+
return {
|
|
439
|
+
description: `invalid binding for generic type <${innerGenericType}> in generic component extension of "${superComponent.value}": existing range "${ParameterPropertyHandlerRange.rangeToDisplayString(genericsContextInner.bindings[innerGenericType], genericsContextInner)}" can not be bound to range "${ParameterPropertyHandlerRange.rangeToDisplayString(genericTypeInstance, genericsContextInner)}"`,
|
|
440
|
+
context: { value, type },
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
return {
|
|
448
|
+
description: `value is not a subtype of the referenced component in the generic component extension of "${valueSuperType.property.component.value}"`,
|
|
449
|
+
context: { value, type },
|
|
450
|
+
causes: [hasTypeConflict],
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
// The default case just checks the super type recursively.
|
|
454
|
+
const subConflictType = this.hasType(valueSuperType, type, genericsContext, genericTypeInstancesComponentScope, genericTypeInstances, errorContext);
|
|
455
|
+
if (!subConflictType) {
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
subConflictTypes.push(subConflictType);
|
|
459
|
+
}
|
|
460
|
+
return Object.assign({ description: `value is not a subtype of "${type.value}"`, context: { value, type } }, subConflictTypes.length > 0 ? { causes: subConflictTypes } : {});
|
|
461
|
+
}
|
|
462
|
+
static rangeToDisplayString(paramRange, genericsContext) {
|
|
463
|
+
if (!paramRange || paramRange.isA('ParameterRangeWildcard')) {
|
|
214
464
|
return `any`;
|
|
215
465
|
}
|
|
216
466
|
if (paramRange.isA('ParameterRangeUndefined')) {
|
|
217
467
|
return `undefined`;
|
|
218
468
|
}
|
|
219
469
|
if (paramRange.isA('ParameterRangeArray')) {
|
|
220
|
-
return `${
|
|
470
|
+
return `${ParameterPropertyHandlerRange.rangeToDisplayString(paramRange.property.parameterRangeValue, genericsContext)}[]`;
|
|
221
471
|
}
|
|
222
472
|
if (paramRange.isA('ParameterRangeRest')) {
|
|
223
|
-
return `...${
|
|
473
|
+
return `...${ParameterPropertyHandlerRange.rangeToDisplayString(paramRange.property.parameterRangeValue, genericsContext)}`;
|
|
224
474
|
}
|
|
225
475
|
if (paramRange.isA('ParameterRangeKeyof')) {
|
|
226
|
-
return `keyof ${
|
|
476
|
+
return `keyof ${ParameterPropertyHandlerRange.rangeToDisplayString(paramRange.property.parameterRangeValue, genericsContext)}`;
|
|
227
477
|
}
|
|
228
478
|
if (paramRange.isA('ParameterRangeUnion')) {
|
|
229
479
|
return paramRange.properties.parameterRangeElements
|
|
230
|
-
.map(child =>
|
|
480
|
+
.map(child => ParameterPropertyHandlerRange.rangeToDisplayString(child, genericsContext))
|
|
231
481
|
.join(' | ');
|
|
232
482
|
}
|
|
233
483
|
if (paramRange.isA('ParameterRangeIntersection')) {
|
|
234
484
|
return paramRange.properties.parameterRangeElements
|
|
235
|
-
.map(child =>
|
|
485
|
+
.map(child => ParameterPropertyHandlerRange.rangeToDisplayString(child, genericsContext))
|
|
236
486
|
.join(' & ');
|
|
237
487
|
}
|
|
238
488
|
if (paramRange.isA('ParameterRangeTuple')) {
|
|
239
489
|
return `[${paramRange.properties.parameterRangeElements
|
|
240
|
-
.map(child =>
|
|
490
|
+
.map(child => ParameterPropertyHandlerRange.rangeToDisplayString(child, genericsContext))
|
|
241
491
|
.join(', ')}]`;
|
|
242
492
|
}
|
|
243
493
|
if (paramRange.isA('ParameterRangeLiteral')) {
|
|
@@ -245,11 +495,18 @@ class ParameterPropertyHandlerRange {
|
|
|
245
495
|
}
|
|
246
496
|
if (paramRange.isA('ParameterRangeGenericTypeReference')) {
|
|
247
497
|
const valid = paramRange.property.parameterRangeGenericType.value in genericsContext.genericTypeIds;
|
|
248
|
-
return
|
|
498
|
+
return `${valid ? 'GENERIC: ' : 'UNKNOWN GENERIC: '}${paramRange.property.parameterRangeGenericType.value}`;
|
|
249
499
|
}
|
|
250
500
|
if (paramRange.isA('ParameterRangeGenericComponent')) {
|
|
251
|
-
return `(${
|
|
252
|
-
.map(genericTypeInstance =>
|
|
501
|
+
return `(${ParameterPropertyHandlerRange.rangeToDisplayString(paramRange.property.component, genericsContext)})<${paramRange.properties.genericTypeInstances
|
|
502
|
+
.map(genericTypeInstance => ParameterPropertyHandlerRange.rangeToDisplayString(genericTypeInstance, genericsContext)).join(', ')}>`;
|
|
503
|
+
}
|
|
504
|
+
if (paramRange.isA('ParameterRangeIndexed')) {
|
|
505
|
+
const object = ParameterPropertyHandlerRange
|
|
506
|
+
.rangeToDisplayString(paramRange.property.parameterRangeIndexedObject, genericsContext);
|
|
507
|
+
const index = ParameterPropertyHandlerRange
|
|
508
|
+
.rangeToDisplayString(paramRange.property.parameterRangeIndexedIndex, genericsContext);
|
|
509
|
+
return `${object}[${index}]`;
|
|
253
510
|
}
|
|
254
511
|
return paramRange.value;
|
|
255
512
|
}
|
package/lib/rdf/Iris.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export declare const IRIS_RDF: {
|
|
|
18
18
|
};
|
|
19
19
|
export declare const PREFIX_RDFS: (suffix: string) => string;
|
|
20
20
|
export declare const IRIS_RDFS: {
|
|
21
|
-
|
|
21
|
+
seeAlso: string;
|
|
22
22
|
};
|
|
23
23
|
export declare const PREFIX_XSD: (suffix: string) => string;
|
|
24
24
|
export declare const IRIS_XSD: {
|
package/lib/rdf/Iris.js
CHANGED
|
@@ -22,7 +22,7 @@ exports.IRIS_RDF = {
|
|
|
22
22
|
};
|
|
23
23
|
exports.PREFIX_RDFS = definePrefix('http://www.w3.org/2000/01/rdf-schema#');
|
|
24
24
|
exports.IRIS_RDFS = {
|
|
25
|
-
|
|
25
|
+
seeAlso: (0, exports.PREFIX_RDFS)('seeAlso'),
|
|
26
26
|
};
|
|
27
27
|
exports.PREFIX_XSD = definePrefix('http://www.w3.org/2001/XMLSchema#');
|
|
28
28
|
exports.IRIS_XSD = {
|