componentsjs 5.0.0-beta.3 → 5.0.0-beta.4
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 +11 -0
- package/components/context.jsonld +16 -2
- 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/preprocess/ParameterHandler.js +1 -1
- package/lib/preprocess/parameterproperty/ParameterPropertyHandlerRange.js +42 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
|
3
3
|
|
|
4
|
+
<a name="v5.0.0-beta.4"></a>
|
|
5
|
+
## [v5.0.0-beta.4](https://github.com/LinkedSoftwareDependencies/Components.js/compare/v5.0.0-beta.3...v5.0.0-beta.4) - 2022-01-29
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
* [Support ParameterRangeIndexed for fixed literals](https://github.com/LinkedSoftwareDependencies/Components.js/commit/0d97782a4a8dcca9fc5bbb3389a4213eca5a5205)
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
* [Propagate original error messages to require calls, Closes #65](https://github.com/LinkedSoftwareDependencies/Components.js/commit/8934ec9b784def601730b3d3f2e60c4ff0b8776e)
|
|
12
|
+
* [Include config id in invalid param error message](https://github.com/LinkedSoftwareDependencies/Components.js/commit/e724f44e2222eb9917da3b227e2ce0dc9cde15f9)
|
|
13
|
+
* [Update memberKeys to memberFields](https://github.com/LinkedSoftwareDependencies/Components.js/commit/2c7437e1519c1813fb1a29f50d7c20bdbdf7f06e)
|
|
14
|
+
|
|
4
15
|
<a name="v5.0.0-beta.3"></a>
|
|
5
16
|
## [v5.0.0-beta.3](https://github.com/LinkedSoftwareDependencies/Components.js/compare/v5.0.0-beta.2...v5.0.0-beta.3) - 2022-01-17
|
|
6
17
|
|
|
@@ -32,8 +32,11 @@
|
|
|
32
32
|
"parameters": {
|
|
33
33
|
"@id": "oo:parameter"
|
|
34
34
|
},
|
|
35
|
-
"
|
|
36
|
-
"@id": "oo:
|
|
35
|
+
"memberFields": {
|
|
36
|
+
"@id": "oo:memberFields"
|
|
37
|
+
},
|
|
38
|
+
"memberFieldName": {
|
|
39
|
+
"@id": "oo:memberFieldName"
|
|
37
40
|
},
|
|
38
41
|
"genericTypeParameters": {
|
|
39
42
|
"@id": "oo:genericTypeParameter"
|
|
@@ -144,6 +147,17 @@
|
|
|
144
147
|
"GenericComponentExtension": {
|
|
145
148
|
"@id": "oo:GenericComponentExtension"
|
|
146
149
|
},
|
|
150
|
+
"ParameterRangeIndexed": {
|
|
151
|
+
"@id": "oo:ParameterRangeIndexed"
|
|
152
|
+
},
|
|
153
|
+
"parameterRangeIndexedObject": {
|
|
154
|
+
"@id": "oo:parameterRangeIndexedObject",
|
|
155
|
+
"@type": "@id"
|
|
156
|
+
},
|
|
157
|
+
"parameterRangeIndexedIndex": {
|
|
158
|
+
"@id": "oo:parameterRangeIndexedIndex",
|
|
159
|
+
"@type": "@id"
|
|
160
|
+
},
|
|
147
161
|
|
|
148
162
|
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
|
|
149
163
|
"comment": {
|
|
@@ -16,7 +16,9 @@ export declare class ConstructionStrategyCommonJs implements IConstructionStrate
|
|
|
16
16
|
* @param requireName The module name that should be required.
|
|
17
17
|
* @returns {any} The require() result
|
|
18
18
|
*/
|
|
19
|
-
requireCurrentRunningModuleIfCurrent(moduleState: IModuleState, requireName: string):
|
|
19
|
+
requireCurrentRunningModuleIfCurrent(moduleState: IModuleState, requireName: string): {
|
|
20
|
+
value: any;
|
|
21
|
+
} | false;
|
|
20
22
|
createHash(options: ICreationStrategyHashOptions<any>): any;
|
|
21
23
|
createArray(options: ICreationStrategyArrayOptions<any>): any;
|
|
22
24
|
createLazySupplier(options: ICreationStrategySupplierOptions<any>): Promise<any>;
|
|
@@ -14,16 +14,14 @@ class ConstructionStrategyCommonJs {
|
|
|
14
14
|
createInstance(options) {
|
|
15
15
|
// Call require()
|
|
16
16
|
options.requireName = this.overrideRequireNames[options.requireName] || options.requireName;
|
|
17
|
+
// First try requiring current module, and fallback to a plain require
|
|
17
18
|
let object;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// Always require relative from main module, because Components.js will in most cases just be dependency.
|
|
23
|
-
object = this.req(options.requireName.startsWith('.') ?
|
|
19
|
+
const currentResult = this.requireCurrentRunningModuleIfCurrent(options.moduleState, options.requireName);
|
|
20
|
+
object = currentResult !== false ?
|
|
21
|
+
currentResult.value :
|
|
22
|
+
this.req(options.requireName.startsWith('.') ?
|
|
24
23
|
Path.join(process.cwd(), options.requireName) :
|
|
25
24
|
this.req.resolve(options.requireName, { paths: [options.moduleState.mainModulePath] }));
|
|
26
|
-
}
|
|
27
25
|
// Determine the child of the require'd element
|
|
28
26
|
let subObject;
|
|
29
27
|
if (options.requireElement) {
|
|
@@ -31,7 +29,7 @@ class ConstructionStrategyCommonJs {
|
|
|
31
29
|
try {
|
|
32
30
|
subObject = requireElementPath.reduce((acc, subRequireElement) => acc[subRequireElement], object);
|
|
33
31
|
}
|
|
34
|
-
catch (
|
|
32
|
+
catch (_a) {
|
|
35
33
|
throw new Error(`Failed to get module element ${options.requireElement} from module ${options.requireName}`);
|
|
36
34
|
}
|
|
37
35
|
}
|
|
@@ -65,11 +63,11 @@ class ConstructionStrategyCommonJs {
|
|
|
65
63
|
const mainPath = Path.posix.join(moduleState.mainModulePath, pckg.main);
|
|
66
64
|
const required = this.req(mainPath);
|
|
67
65
|
if (required) {
|
|
68
|
-
return required;
|
|
66
|
+
return { value: required };
|
|
69
67
|
}
|
|
70
68
|
}
|
|
71
69
|
}
|
|
72
|
-
|
|
70
|
+
return false;
|
|
73
71
|
}
|
|
74
72
|
createHash(options) {
|
|
75
73
|
return options.entries.reduce((data, entry) => {
|
|
@@ -30,14 +30,12 @@ class ConstructionStrategyCommonJsString {
|
|
|
30
30
|
createInstance(options) {
|
|
31
31
|
// Call require()
|
|
32
32
|
options.requireName = this.overrideRequireNames[options.requireName] || options.requireName;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
resultingRequirePath = options.requireName;
|
|
40
|
-
}
|
|
33
|
+
// First try requiring current module, and fallback to a plain require
|
|
34
|
+
const currentResult = this.strategyCommonJs
|
|
35
|
+
.requireCurrentRunningModuleIfCurrent(options.moduleState, options.requireName);
|
|
36
|
+
const resultingRequirePath = currentResult !== false ?
|
|
37
|
+
`.${Path.sep}${Path.relative(options.moduleState.mainModulePath, this.getCurrentRunningModuleMain(options.moduleState))}` :
|
|
38
|
+
options.requireName;
|
|
41
39
|
let serialization = `require('${resultingRequirePath.replace(/\\/gu, '/')}')`;
|
|
42
40
|
// Determine the child of the require'd element
|
|
43
41
|
if (options.requireElement) {
|
|
@@ -38,7 +38,7 @@ class ParameterHandler {
|
|
|
38
38
|
}
|
|
39
39
|
else if (values.length > 0) {
|
|
40
40
|
if (values.some(subValue => !subValue.list)) {
|
|
41
|
-
throw new ErrorResourcesContext_1.ErrorResourcesContext(`Detected multiple values for parameter ${parameter.value}. RDF lists should be used for defining multiple values.`, {
|
|
41
|
+
throw new ErrorResourcesContext_1.ErrorResourcesContext(`Detected multiple values for parameter ${parameter.value} in ${configElement.value}. RDF lists should be used for defining multiple values.`, {
|
|
42
42
|
arguments: values,
|
|
43
43
|
});
|
|
44
44
|
}
|
|
@@ -259,9 +259,9 @@ class ParameterPropertyHandlerRange {
|
|
|
259
259
|
// Simulate a union of the member keys as literal parameter ranges
|
|
260
260
|
const simulatedUnionRange = this.objectLoader.createCompactedResource({
|
|
261
261
|
'@type': 'ParameterRangeUnion',
|
|
262
|
-
parameterRangeElements: component.properties.
|
|
262
|
+
parameterRangeElements: component.properties.memberFields.map(memberField => ({
|
|
263
263
|
'@type': 'ParameterRangeLiteral',
|
|
264
|
-
parameterRangeValue:
|
|
264
|
+
parameterRangeValue: memberField.property.memberFieldName,
|
|
265
265
|
})),
|
|
266
266
|
});
|
|
267
267
|
const subConflict = this.hasValueType(value, simulatedUnionRange, errorContext, genericsContext);
|
|
@@ -274,6 +274,39 @@ class ParameterPropertyHandlerRange {
|
|
|
274
274
|
causes: [subConflict],
|
|
275
275
|
};
|
|
276
276
|
}
|
|
277
|
+
// Check if the range refers to an indexed type such as `MyClass[myField]`
|
|
278
|
+
if (type.isA('ParameterRangeIndexed')) {
|
|
279
|
+
const object = type.property.parameterRangeIndexedObject;
|
|
280
|
+
const index = type.property.parameterRangeIndexedIndex;
|
|
281
|
+
// Collect field ranges
|
|
282
|
+
const fieldRanges = Object.fromEntries(object.properties.memberFields
|
|
283
|
+
.map(memberField => [memberField.property.memberFieldName.value, memberField.property.range ||
|
|
284
|
+
this.objectLoader.createCompactedResource({ '@type': 'ParameterRangeWildcard' })]));
|
|
285
|
+
// Handle literal indexes
|
|
286
|
+
if (index.isA('ParameterRangeLiteral')) {
|
|
287
|
+
const field = index.property.parameterRangeValue.value;
|
|
288
|
+
const range = fieldRanges[field];
|
|
289
|
+
if (!range) {
|
|
290
|
+
return {
|
|
291
|
+
description: `indexed index does not refer to a known field`,
|
|
292
|
+
context: errorContext,
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
const subConflict = this.hasValueType(value, range, errorContext, genericsContext);
|
|
296
|
+
if (!subConflict) {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
return {
|
|
300
|
+
description: `indexed value is invalid`,
|
|
301
|
+
context: errorContext,
|
|
302
|
+
causes: [subConflict],
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
return {
|
|
306
|
+
description: `indexed index type can not be understood`,
|
|
307
|
+
context: errorContext,
|
|
308
|
+
};
|
|
309
|
+
}
|
|
277
310
|
// Check if the range refers to a generic type
|
|
278
311
|
if (type.isA('ParameterRangeGenericTypeReference')) {
|
|
279
312
|
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));
|
|
@@ -467,6 +500,13 @@ class ParameterPropertyHandlerRange {
|
|
|
467
500
|
return `(${ParameterPropertyHandlerRange.rangeToDisplayString(paramRange.property.component, genericsContext)})<${paramRange.properties.genericTypeInstances
|
|
468
501
|
.map(genericTypeInstance => ParameterPropertyHandlerRange.rangeToDisplayString(genericTypeInstance, genericsContext)).join(', ')}>`;
|
|
469
502
|
}
|
|
503
|
+
if (paramRange.isA('ParameterRangeIndexed')) {
|
|
504
|
+
const object = ParameterPropertyHandlerRange
|
|
505
|
+
.rangeToDisplayString(paramRange.property.parameterRangeIndexedObject, genericsContext);
|
|
506
|
+
const index = ParameterPropertyHandlerRange
|
|
507
|
+
.rangeToDisplayString(paramRange.property.parameterRangeIndexedIndex, genericsContext);
|
|
508
|
+
return `${object}[${index}]`;
|
|
509
|
+
}
|
|
470
510
|
return paramRange.value;
|
|
471
511
|
}
|
|
472
512
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "componentsjs",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.4",
|
|
4
4
|
"description": "A semantic dependency injection framework",
|
|
5
5
|
"lsd:contexts": {
|
|
6
6
|
"https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^3.0.0/components/context.jsonld": "components/context.jsonld"
|