componentsjs 5.1.0 → 5.2.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/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
|
3
3
|
|
|
4
|
+
<a name="v5.2.0"></a>
|
|
5
|
+
## [v5.2.0](https://github.com/LinkedSoftwareDependencies/Components.js/compare/v5.1.0...v5.2.0) - 2022-05-20
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
* [Preserve literal values for params with type unknown](https://github.com/LinkedSoftwareDependencies/Components.js/commit/ad52da8afc2340ddc63e8a45c4d560e11ecb3ceb)
|
|
9
|
+
|
|
4
10
|
<a name="v5.1.0"></a>
|
|
5
11
|
## [v5.1.0](https://github.com/LinkedSoftwareDependencies/Components.js/compare/v5.0.0...v5.1.0) - 2022-05-10
|
|
6
12
|
|
|
@@ -33,6 +33,11 @@ export declare class ParameterPropertyHandlerRange implements IParameterProperty
|
|
|
33
33
|
* @return IParamValueConflict A conflict value if there was an error, or undefined if there was no error
|
|
34
34
|
*/
|
|
35
35
|
hasValueType(value: Resource | undefined, type: Resource | undefined, errorContext: IErrorContext, genericsContext: GenericsContext): IParamValueConflict | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Utility function for handling Literals.
|
|
38
|
+
* If the provided value represents a valid Literal, the `valueRaw` field will be set.
|
|
39
|
+
*/
|
|
40
|
+
private interpretValueAsType;
|
|
36
41
|
static throwIncorrectTypeError(value: Resource | undefined, parameter: Resource, genericsContext: GenericsContext, conflict: IParamValueConflict): never;
|
|
37
42
|
/**
|
|
38
43
|
* Check if the given value is of the given type.
|
|
@@ -54,3 +59,13 @@ export interface IParamValueConflict {
|
|
|
54
59
|
context: IErrorContext;
|
|
55
60
|
causes?: IParamValueConflict[];
|
|
56
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Represents the result of an interpretValuesAsType operation.
|
|
64
|
+
*/
|
|
65
|
+
export interface ILiteralAsTypeInterpretationResult {
|
|
66
|
+
/**
|
|
67
|
+
* Value is true if a matching literal type was found.
|
|
68
|
+
*/
|
|
69
|
+
match: boolean;
|
|
70
|
+
value?: IParamValueConflict;
|
|
71
|
+
}
|
|
@@ -53,6 +53,11 @@ class ParameterPropertyHandlerRange {
|
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
55
55
|
if (type.isA('ParameterRangeWildcard')) {
|
|
56
|
+
if (value && value.term.termType === 'Literal') {
|
|
57
|
+
// Get datatype of the configured value
|
|
58
|
+
const configuredDataType = value.term.datatype;
|
|
59
|
+
return this.interpretValueAsType(value, configuredDataType, errorContext, genericsContext).value;
|
|
60
|
+
}
|
|
56
61
|
return;
|
|
57
62
|
}
|
|
58
63
|
if (!value && type.isA('ParameterRangeUndefined')) {
|
|
@@ -64,69 +69,10 @@ class ParameterPropertyHandlerRange {
|
|
|
64
69
|
}
|
|
65
70
|
// Handle literal values
|
|
66
71
|
if (value && value.type === 'Literal') {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
case Iris_1.IRIS_XSD.boolean:
|
|
72
|
-
if (value.value === 'true') {
|
|
73
|
-
value.term.valueRaw = true;
|
|
74
|
-
}
|
|
75
|
-
else if (value.value === 'false') {
|
|
76
|
-
value.term.valueRaw = false;
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
return {
|
|
80
|
-
description: 'value must either be "true" or "false"',
|
|
81
|
-
context: errorContext,
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
return;
|
|
85
|
-
case Iris_1.IRIS_XSD.integer:
|
|
86
|
-
case Iris_1.IRIS_XSD.number:
|
|
87
|
-
case Iris_1.IRIS_XSD.int:
|
|
88
|
-
case Iris_1.IRIS_XSD.byte:
|
|
89
|
-
case Iris_1.IRIS_XSD.long:
|
|
90
|
-
parsed = Number.parseInt(value.value, 10);
|
|
91
|
-
if (Number.isNaN(parsed)) {
|
|
92
|
-
return {
|
|
93
|
-
description: `value is not a number`,
|
|
94
|
-
context: errorContext,
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
// ParseInt also parses floats to ints!
|
|
98
|
-
if (String(parsed) !== value.value) {
|
|
99
|
-
return {
|
|
100
|
-
description: `value can not be a float`,
|
|
101
|
-
context: errorContext,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
value.term.valueRaw = parsed;
|
|
105
|
-
return;
|
|
106
|
-
case Iris_1.IRIS_XSD.float:
|
|
107
|
-
case Iris_1.IRIS_XSD.decimal:
|
|
108
|
-
case Iris_1.IRIS_XSD.double:
|
|
109
|
-
parsed = Number.parseFloat(value.value);
|
|
110
|
-
if (Number.isNaN(parsed)) {
|
|
111
|
-
return {
|
|
112
|
-
description: `value is not a number`,
|
|
113
|
-
context: errorContext,
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
value.term.valueRaw = parsed;
|
|
117
|
-
return;
|
|
118
|
-
case Iris_1.IRIS_RDF.JSON:
|
|
119
|
-
try {
|
|
120
|
-
parsed = JSON.parse(value.value);
|
|
121
|
-
value.term.valueRaw = parsed;
|
|
122
|
-
}
|
|
123
|
-
catch (error) {
|
|
124
|
-
return {
|
|
125
|
-
description: `JSON parse exception: ${error.message}`,
|
|
126
|
-
context: errorContext,
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
return;
|
|
72
|
+
const result = this.interpretValueAsType(value, type, errorContext, genericsContext);
|
|
73
|
+
if (result.match) {
|
|
74
|
+
// Stop processing and return (with a possible IParamValueConflict) if a match was found.
|
|
75
|
+
return result.value;
|
|
130
76
|
}
|
|
131
77
|
}
|
|
132
78
|
// Allow IRIs to be casted to strings
|
|
@@ -359,6 +305,93 @@ class ParameterPropertyHandlerRange {
|
|
|
359
305
|
}
|
|
360
306
|
return hasTypeConflict || { description: 'unknown parameter type', context: errorContext };
|
|
361
307
|
}
|
|
308
|
+
/**
|
|
309
|
+
* Utility function for handling Literals.
|
|
310
|
+
* If the provided value represents a valid Literal, the `valueRaw` field will be set.
|
|
311
|
+
*/
|
|
312
|
+
interpretValueAsType(value, type, errorContext, genericsContext) {
|
|
313
|
+
let parsed;
|
|
314
|
+
switch (type.value) {
|
|
315
|
+
case Iris_1.IRIS_XSD.string:
|
|
316
|
+
return { match: true };
|
|
317
|
+
case Iris_1.IRIS_XSD.boolean:
|
|
318
|
+
if (value.value === 'true') {
|
|
319
|
+
value.term.valueRaw = true;
|
|
320
|
+
}
|
|
321
|
+
else if (value.value === 'false') {
|
|
322
|
+
value.term.valueRaw = false;
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
return {
|
|
326
|
+
match: true,
|
|
327
|
+
value: {
|
|
328
|
+
description: 'value must either be "true" or "false"',
|
|
329
|
+
context: errorContext,
|
|
330
|
+
},
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
return { match: true };
|
|
334
|
+
case Iris_1.IRIS_XSD.integer:
|
|
335
|
+
case Iris_1.IRIS_XSD.number:
|
|
336
|
+
case Iris_1.IRIS_XSD.int:
|
|
337
|
+
case Iris_1.IRIS_XSD.byte:
|
|
338
|
+
case Iris_1.IRIS_XSD.long:
|
|
339
|
+
parsed = Number.parseInt(value.value, 10);
|
|
340
|
+
if (Number.isNaN(parsed)) {
|
|
341
|
+
return {
|
|
342
|
+
match: true,
|
|
343
|
+
value: {
|
|
344
|
+
description: `value is not a number`,
|
|
345
|
+
context: errorContext,
|
|
346
|
+
},
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
// ParseInt also parses floats to ints!
|
|
350
|
+
if (String(parsed) !== value.value) {
|
|
351
|
+
return {
|
|
352
|
+
match: true,
|
|
353
|
+
value: {
|
|
354
|
+
description: `value can not be a float`,
|
|
355
|
+
context: errorContext,
|
|
356
|
+
},
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
value.term.valueRaw = parsed;
|
|
360
|
+
return { match: true };
|
|
361
|
+
case Iris_1.IRIS_XSD.float:
|
|
362
|
+
case Iris_1.IRIS_XSD.decimal:
|
|
363
|
+
case Iris_1.IRIS_XSD.double:
|
|
364
|
+
parsed = Number.parseFloat(value.value);
|
|
365
|
+
if (Number.isNaN(parsed)) {
|
|
366
|
+
return {
|
|
367
|
+
match: true,
|
|
368
|
+
value: {
|
|
369
|
+
description: `value is not a number`,
|
|
370
|
+
context: errorContext,
|
|
371
|
+
},
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
value.term.valueRaw = parsed;
|
|
375
|
+
return { match: true };
|
|
376
|
+
case Iris_1.IRIS_RDF.JSON:
|
|
377
|
+
try {
|
|
378
|
+
parsed = JSON.parse(value.value);
|
|
379
|
+
value.term.valueRaw = parsed;
|
|
380
|
+
}
|
|
381
|
+
catch (error) {
|
|
382
|
+
return {
|
|
383
|
+
match: true,
|
|
384
|
+
value: {
|
|
385
|
+
description: `JSON parse exception: ${error.message}`,
|
|
386
|
+
context: errorContext,
|
|
387
|
+
},
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
return { match: true };
|
|
391
|
+
default:
|
|
392
|
+
return { match: false };
|
|
393
|
+
}
|
|
394
|
+
}
|
|
362
395
|
static throwIncorrectTypeError(value, parameter, genericsContext, conflict) {
|
|
363
396
|
const withTypes = value && value.properties.types.length > 0 ? ` with types "${value.properties.types.map(resource => resource.value)}"` : '';
|
|
364
397
|
// eslint-disable-next-line @typescript-eslint/no-extra-parens
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "componentsjs",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "A semantic dependency injection framework",
|
|
5
5
|
"lsd:contexts": {
|
|
6
6
|
"https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^5.0.0/components/context.jsonld": "components/context.jsonld"
|