componentsjs 5.0.0-beta.3 → 5.0.0-beta.7
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 +40 -0
- package/README.md +35 -0
- package/components/context.jsonld +21 -4
- 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/ComponentRegistry.js +1 -1
- package/lib/loading/ComponentsManagerBuilder.d.ts +6 -0
- package/lib/loading/ComponentsManagerBuilder.js +4 -1
- package/lib/preprocess/ConfigPreprocessorComponent.js +4 -1
- package/lib/preprocess/GenericsContext.js +4 -2
- package/lib/preprocess/ParameterHandler.d.ts +1 -0
- package/lib/preprocess/ParameterHandler.js +2 -2
- package/lib/preprocess/parameterproperty/ParameterPropertyHandlerRange.d.ts +2 -1
- package/lib/preprocess/parameterproperty/ParameterPropertyHandlerRange.js +45 -4
- package/lib/rdf/Iris.d.ts +1 -1
- package/lib/rdf/Iris.js +1 -1
- package/lib/rdf/RdfStreamIncluder.js +2 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
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.7"></a>
|
|
5
|
+
## [v5.0.0-beta.7](https://github.com/LinkedSoftwareDependencies/Components.js/compare/v5.0.0-beta.6...v5.0.0-beta.7) - 2022-02-21
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
* [Lower log level of empty modules to debug](https://github.com/LinkedSoftwareDependencies/Components.js/commit/df119861bc12992e05af05b42f0a734069de6915)
|
|
9
|
+
* [Bump to rdf-object 1.13.1](https://github.com/LinkedSoftwareDependencies/Components.js/commit/264be522079f86bd47bea9fe5730eaed29bbe450)
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
* [Fix incorrect error logging when generics error occurs in extends clause](https://github.com/LinkedSoftwareDependencies/Components.js/commit/1ce62d39896ca498ecba7443c9c7c298c9db0301)
|
|
13
|
+
* [Fix minor context issues](https://github.com/LinkedSoftwareDependencies/Components.js/commit/7adcd5fe0de73a42c8225069752be40214f843f3)
|
|
14
|
+
|
|
15
|
+
<a name="v5.0.0-beta.6"></a>
|
|
16
|
+
## [v5.0.0-beta.6](https://github.com/LinkedSoftwareDependencies/Components.js/compare/v5.0.0-beta.5...v5.0.0-beta.6) - 2022-02-09
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
* [Fix generic errors still throwing during ignored type checking](https://github.com/LinkedSoftwareDependencies/Components.js/commit/c14adcf4757e5194db22c0f0285407bd03bf5635)
|
|
20
|
+
|
|
21
|
+
<a name="v5.0.0-beta.5"></a>
|
|
22
|
+
## [v5.0.0-beta.5](https://github.com/LinkedSoftwareDependencies/Components.js/compare/v5.0.0-beta.4...v5.0.0-beta.5) - 2022-02-08
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
* [Allow type-checking to be disabled via typeChecking](https://github.com/LinkedSoftwareDependencies/Components.js/commit/a55331085e4c5621832e6b23bc52b00068e8256a)
|
|
26
|
+
|
|
27
|
+
### Changed
|
|
28
|
+
* [Throw error on circular dependencies, Closes #53](https://github.com/LinkedSoftwareDependencies/Components.js/commit/e7a28d1cf87d96d5b58bb6d1f19ce41d6e55aab6)
|
|
29
|
+
|
|
30
|
+
### Fixed
|
|
31
|
+
* [Fix seeAlso links not handling encoded URI components, Closes #43](https://github.com/LinkedSoftwareDependencies/Components.js/commit/2b72914d2720b2982d4570af55f9b5d7dc196c27)
|
|
32
|
+
|
|
33
|
+
<a name="v5.0.0-beta.4"></a>
|
|
34
|
+
## [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
|
|
35
|
+
|
|
36
|
+
### Added
|
|
37
|
+
* [Support ParameterRangeIndexed for fixed literals](https://github.com/LinkedSoftwareDependencies/Components.js/commit/0d97782a4a8dcca9fc5bbb3389a4213eca5a5205)
|
|
38
|
+
|
|
39
|
+
### Changed
|
|
40
|
+
* [Propagate original error messages to require calls, Closes #65](https://github.com/LinkedSoftwareDependencies/Components.js/commit/8934ec9b784def601730b3d3f2e60c4ff0b8776e)
|
|
41
|
+
* [Include config id in invalid param error message](https://github.com/LinkedSoftwareDependencies/Components.js/commit/e724f44e2222eb9917da3b227e2ce0dc9cde15f9)
|
|
42
|
+
* [Update memberKeys to memberFields](https://github.com/LinkedSoftwareDependencies/Components.js/commit/2c7437e1519c1813fb1a29f50d7c20bdbdf7f06e)
|
|
43
|
+
|
|
4
44
|
<a name="v5.0.0-beta.3"></a>
|
|
5
45
|
## [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
46
|
|
package/README.md
CHANGED
|
@@ -202,6 +202,41 @@ const myInstance = await manager.instantiate('http://example.org/myInstance');
|
|
|
202
202
|
[RDF]: https://www.w3.org/RDF/
|
|
203
203
|
[JSON-LD]: https://json-ld.org/
|
|
204
204
|
|
|
205
|
+
## Advanced usage
|
|
206
|
+
|
|
207
|
+
The `ComponentsManager` can be customized with the following options:
|
|
208
|
+
|
|
209
|
+
```javascript
|
|
210
|
+
const manager = await ComponentsManager.build({
|
|
211
|
+
// Absolute path to the package root from which module resolution should start.
|
|
212
|
+
mainModulePath: __dirname,
|
|
213
|
+
// Callback for registering components and modules
|
|
214
|
+
// Defaults to an invocation of {@link ComponentRegistry.registerAvailableModules}.
|
|
215
|
+
moduleLoader: (registry) => {},
|
|
216
|
+
// Callback for registering configurations.
|
|
217
|
+
// Defaults to no config registrations.
|
|
218
|
+
configLoader: (registry) => {},
|
|
219
|
+
// A strategy for constructing instances.
|
|
220
|
+
// Defaults to {@link ConstructionStrategyCommonJs}.
|
|
221
|
+
constructionStrategy: new ConstructionStrategyCommonJs(),
|
|
222
|
+
// If the error state should be dumped into `componentsjs-error-state.json` after failed instantiations.
|
|
223
|
+
// Defaults to `true`.
|
|
224
|
+
dumpErrorState: true,
|
|
225
|
+
// The logging level.
|
|
226
|
+
// Defaults to `'warn'`.
|
|
227
|
+
logLevel: 'warn',
|
|
228
|
+
// The module state.
|
|
229
|
+
// Defaults to a newly created instance on the {@link mainModulePath}.
|
|
230
|
+
moduleState: {},
|
|
231
|
+
// If JSON-LD context validation should be skipped.
|
|
232
|
+
// Defaults to `true`.
|
|
233
|
+
skipContextValidation: true,
|
|
234
|
+
// If values for parameters should be type-checked.
|
|
235
|
+
// Defaults to `true`.
|
|
236
|
+
typeChecking: true,
|
|
237
|
+
});
|
|
238
|
+
```
|
|
239
|
+
|
|
205
240
|
## Cite
|
|
206
241
|
|
|
207
242
|
If you are using or extending Components.js as part of a scientific publication,
|
|
@@ -32,8 +32,11 @@
|
|
|
32
32
|
"parameters": {
|
|
33
33
|
"@id": "oo:parameter"
|
|
34
34
|
},
|
|
35
|
-
"
|
|
36
|
-
"@id": "oo:
|
|
35
|
+
"memberFields": {
|
|
36
|
+
"@id": "oo:memberField"
|
|
37
|
+
},
|
|
38
|
+
"memberFieldName": {
|
|
39
|
+
"@id": "oo:memberFieldName"
|
|
37
40
|
},
|
|
38
41
|
"genericTypeParameters": {
|
|
39
42
|
"@id": "oo:genericTypeParameter"
|
|
@@ -108,8 +111,11 @@
|
|
|
108
111
|
"ParameterRangeIntersection": {
|
|
109
112
|
"@id": "oo:ParameterRangeIntersection"
|
|
110
113
|
},
|
|
114
|
+
"ParameterRangeTuple": {
|
|
115
|
+
"@id": "oo:ParameterRangeTuple"
|
|
116
|
+
},
|
|
111
117
|
"parameterRangeElements": {
|
|
112
|
-
"@id": "oo:
|
|
118
|
+
"@id": "oo:parameterRangeElement",
|
|
113
119
|
"@type": "@id"
|
|
114
120
|
},
|
|
115
121
|
"ParameterRangeCollectEntries": {
|
|
@@ -138,7 +144,18 @@
|
|
|
138
144
|
"@type": "@id"
|
|
139
145
|
},
|
|
140
146
|
"parameterRangeGenericBindings": {
|
|
141
|
-
"@id": "oo:
|
|
147
|
+
"@id": "oo:parameterRangeGenericBinding",
|
|
148
|
+
"@type": "@id"
|
|
149
|
+
},
|
|
150
|
+
"ParameterRangeIndexed": {
|
|
151
|
+
"@id": "oo:ParameterRangeIndexed"
|
|
152
|
+
},
|
|
153
|
+
"parameterRangeIndexedObject": {
|
|
154
|
+
"@id": "oo:parameterRangeIndexedObject",
|
|
155
|
+
"@type": "@id"
|
|
156
|
+
},
|
|
157
|
+
"parameterRangeIndexedIndex": {
|
|
158
|
+
"@id": "oo:parameterRangeIndexedIndex",
|
|
142
159
|
"@type": "@id"
|
|
143
160
|
},
|
|
144
161
|
"GenericComponentExtension": {
|
|
@@ -28,7 +28,7 @@ class ConfigConstructorPool {
|
|
|
28
28
|
// if so, return a dummy value, to avoid infinite recursion.
|
|
29
29
|
const resourceBlacklist = settings.resourceBlacklist || {};
|
|
30
30
|
if (resourceBlacklist[configResource.value]) {
|
|
31
|
-
return Promise.
|
|
31
|
+
return Promise.reject(new ErrorResourcesContext_1.ErrorResourcesContext(`Circular dependency was detected on ${configResource.value}`, { config: configResource }));
|
|
32
32
|
}
|
|
33
33
|
// Before instantiating, first check if the resource is a variable
|
|
34
34
|
if (configResource.isA('Variable')) {
|
|
@@ -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) {
|
|
@@ -18,6 +18,7 @@ export declare class ComponentsManagerBuilder<Instance = any> {
|
|
|
18
18
|
private readonly logger;
|
|
19
19
|
private readonly moduleState?;
|
|
20
20
|
private readonly skipContextValidation;
|
|
21
|
+
private readonly typeChecking;
|
|
21
22
|
constructor(options: IComponentsManagerBuilderOptions<Instance>);
|
|
22
23
|
static createLogger(logLevel?: LogLevel): Logger;
|
|
23
24
|
static createObjectLoader(): RdfObjectLoader;
|
|
@@ -69,4 +70,9 @@ export interface IComponentsManagerBuilderOptions<Instance> {
|
|
|
69
70
|
* Defaults to `true`.
|
|
70
71
|
*/
|
|
71
72
|
skipContextValidation?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* If values for parameters should be type-checked.
|
|
75
|
+
* Defaults to `true`.
|
|
76
|
+
*/
|
|
77
|
+
typeChecking?: boolean;
|
|
72
78
|
}
|
|
@@ -31,6 +31,9 @@ class ComponentsManagerBuilder {
|
|
|
31
31
|
this.skipContextValidation = options.skipContextValidation === undefined ?
|
|
32
32
|
true :
|
|
33
33
|
Boolean(options.skipContextValidation);
|
|
34
|
+
this.typeChecking = options.typeChecking === undefined ?
|
|
35
|
+
true :
|
|
36
|
+
Boolean(options.typeChecking);
|
|
34
37
|
}
|
|
35
38
|
static createLogger(logLevel = 'warn') {
|
|
36
39
|
return (0, winston_1.createLogger)({
|
|
@@ -92,7 +95,7 @@ class ComponentsManagerBuilder {
|
|
|
92
95
|
this.logger.info(`Loaded configs`);
|
|
93
96
|
// Build constructor pool
|
|
94
97
|
const runTypeConfigs = {};
|
|
95
|
-
const parameterHandler = new ParameterHandler_1.ParameterHandler({ objectLoader });
|
|
98
|
+
const parameterHandler = new ParameterHandler_1.ParameterHandler({ objectLoader, typeChecking: this.typeChecking });
|
|
96
99
|
const configConstructorPool = new ConfigConstructorPool_1.ConfigConstructorPool({
|
|
97
100
|
objectLoader,
|
|
98
101
|
configPreprocessors: [
|
|
@@ -97,8 +97,11 @@ class ConfigPreprocessorComponent {
|
|
|
97
97
|
// ParameterPropertyHandlerRange#hasParamValueValidType)
|
|
98
98
|
if (config.property.genericTypeInstancesComponentScope &&
|
|
99
99
|
handleResponse.component.value === config.property.genericTypeInstancesComponentScope.value) {
|
|
100
|
-
genericsContext.bindComponentGenericTypes(handleResponse.component, config.properties.genericTypeInstances, { config }, (subType, superType) => this.parameterHandler.parameterPropertyHandlerRange
|
|
100
|
+
const conflict = genericsContext.bindComponentGenericTypes(handleResponse.component, config.properties.genericTypeInstances, { config }, (subType, superType) => this.parameterHandler.parameterPropertyHandlerRange
|
|
101
101
|
.hasType(subType, superType, genericsContext, config.property.genericTypeInstancesComponentScope, config.properties.genericTypeInstances, { config }));
|
|
102
|
+
if (conflict) {
|
|
103
|
+
throw new ErrorResourcesContext_1.ErrorResourcesContext(conflict.description, { cause: conflict });
|
|
104
|
+
}
|
|
102
105
|
}
|
|
103
106
|
return genericsContext;
|
|
104
107
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GenericsContext = void 0;
|
|
4
|
-
const ErrorResourcesContext_1 = require("../util/ErrorResourcesContext");
|
|
5
4
|
const ParameterPropertyHandlerRange_1 = require("./parameterproperty/ParameterPropertyHandlerRange");
|
|
6
5
|
/**
|
|
7
6
|
* Context for binding generic types to a concrete range value.
|
|
@@ -270,7 +269,10 @@ class GenericsContext {
|
|
|
270
269
|
}
|
|
271
270
|
// Throw if an unexpected number of generic type instances are passed.
|
|
272
271
|
if (genericTypeParameters.length !== genericTypeInstances.length) {
|
|
273
|
-
|
|
272
|
+
return {
|
|
273
|
+
description: `Invalid generic type instantiation: a different amount of generic types are passed (${genericTypeInstances.length}) than are defined on the component (${genericTypeParameters.length}).`,
|
|
274
|
+
context: Object.assign({ passedGenerics: genericTypeInstances, definedGenerics: genericTypeParameters, component }, errorContext),
|
|
275
|
+
};
|
|
274
276
|
}
|
|
275
277
|
// Populate with manually defined generic type bindings
|
|
276
278
|
for (const [i, genericTypeInstance] of genericTypeInstances.entries()) {
|
|
@@ -17,7 +17,7 @@ class ParameterHandler {
|
|
|
17
17
|
new ParameterPropertyHandlerDefaultScoped_1.ParameterPropertyHandlerDefaultScoped(this.objectLoader),
|
|
18
18
|
new ParameterPropertyHandlerDefault_1.ParameterPropertyHandlerDefault(this.objectLoader),
|
|
19
19
|
new ParameterPropertyHandlerFixed_1.ParameterPropertyHandlerFixed(this.objectLoader),
|
|
20
|
-
this.parameterPropertyHandlerRange = new ParameterPropertyHandlerRange_1.ParameterPropertyHandlerRange(this.objectLoader),
|
|
20
|
+
this.parameterPropertyHandlerRange = new ParameterPropertyHandlerRange_1.ParameterPropertyHandlerRange(this.objectLoader, options.typeChecking),
|
|
21
21
|
new ParameterPropertyHandlerLazy_1.ParameterPropertyHandlerLazy(),
|
|
22
22
|
];
|
|
23
23
|
}
|
|
@@ -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
|
}
|
|
@@ -7,7 +7,8 @@ import type { IParameterPropertyHandler } from './IParameterPropertyHandler';
|
|
|
7
7
|
*/
|
|
8
8
|
export declare class ParameterPropertyHandlerRange implements IParameterPropertyHandler {
|
|
9
9
|
private readonly objectLoader;
|
|
10
|
-
|
|
10
|
+
private readonly typeChecking;
|
|
11
|
+
constructor(objectLoader: RdfObjectLoader, typeChecking: boolean);
|
|
11
12
|
canHandle(value: Resource | undefined, configRoot: Resource, parameter: Resource): boolean;
|
|
12
13
|
handle(value: Resource | undefined, configRoot: Resource, parameter: Resource, configElement: Resource, genericsContext: GenericsContext): Resource | undefined;
|
|
13
14
|
/**
|
|
@@ -8,8 +8,9 @@ const GenericsContext_1 = require("../GenericsContext");
|
|
|
8
8
|
* If a param range is defined, apply the type and validate the range.
|
|
9
9
|
*/
|
|
10
10
|
class ParameterPropertyHandlerRange {
|
|
11
|
-
constructor(objectLoader) {
|
|
11
|
+
constructor(objectLoader, typeChecking) {
|
|
12
12
|
this.objectLoader = objectLoader;
|
|
13
|
+
this.typeChecking = typeChecking;
|
|
13
14
|
}
|
|
14
15
|
canHandle(value, configRoot, parameter) {
|
|
15
16
|
return Boolean(parameter.property.range);
|
|
@@ -30,7 +31,7 @@ class ParameterPropertyHandlerRange {
|
|
|
30
31
|
captureType(value, param, genericsContext) {
|
|
31
32
|
const errorContext = { param };
|
|
32
33
|
const conflict = this.hasValueType(value, param.property.range, errorContext, genericsContext);
|
|
33
|
-
if (!conflict) {
|
|
34
|
+
if (!conflict || !this.typeChecking) {
|
|
34
35
|
return value;
|
|
35
36
|
}
|
|
36
37
|
ParameterPropertyHandlerRange.throwIncorrectTypeError(value, param, genericsContext, conflict);
|
|
@@ -259,9 +260,9 @@ class ParameterPropertyHandlerRange {
|
|
|
259
260
|
// Simulate a union of the member keys as literal parameter ranges
|
|
260
261
|
const simulatedUnionRange = this.objectLoader.createCompactedResource({
|
|
261
262
|
'@type': 'ParameterRangeUnion',
|
|
262
|
-
parameterRangeElements: component.properties.
|
|
263
|
+
parameterRangeElements: component.properties.memberFields.map(memberField => ({
|
|
263
264
|
'@type': 'ParameterRangeLiteral',
|
|
264
|
-
parameterRangeValue:
|
|
265
|
+
parameterRangeValue: memberField.property.memberFieldName,
|
|
265
266
|
})),
|
|
266
267
|
});
|
|
267
268
|
const subConflict = this.hasValueType(value, simulatedUnionRange, errorContext, genericsContext);
|
|
@@ -274,6 +275,39 @@ class ParameterPropertyHandlerRange {
|
|
|
274
275
|
causes: [subConflict],
|
|
275
276
|
};
|
|
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
|
+
};
|
|
305
|
+
}
|
|
306
|
+
return {
|
|
307
|
+
description: `indexed index type can not be understood`,
|
|
308
|
+
context: errorContext,
|
|
309
|
+
};
|
|
310
|
+
}
|
|
277
311
|
// Check if the range refers to a generic type
|
|
278
312
|
if (type.isA('ParameterRangeGenericTypeReference')) {
|
|
279
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));
|
|
@@ -467,6 +501,13 @@ class ParameterPropertyHandlerRange {
|
|
|
467
501
|
return `(${ParameterPropertyHandlerRange.rangeToDisplayString(paramRange.property.component, genericsContext)})<${paramRange.properties.genericTypeInstances
|
|
468
502
|
.map(genericTypeInstance => ParameterPropertyHandlerRange.rangeToDisplayString(genericTypeInstance, genericsContext)).join(', ')}>`;
|
|
469
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}]`;
|
|
510
|
+
}
|
|
470
511
|
return paramRange.value;
|
|
471
512
|
}
|
|
472
513
|
}
|
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 = {
|
|
@@ -36,9 +36,9 @@ class RdfStreamIncluder extends stream_1.Transform {
|
|
|
36
36
|
* @param quad A quad.
|
|
37
37
|
*/
|
|
38
38
|
handleImports(quad) {
|
|
39
|
-
if (!this.parserOptions.ignoreImports && quad.predicate.value === Iris_1.IRIS_RDFS.
|
|
39
|
+
if (!this.parserOptions.ignoreImports && quad.predicate.value === Iris_1.IRIS_RDFS.seeAlso) {
|
|
40
40
|
this.runningImporters++;
|
|
41
|
-
let relativeFilePath = quad.object.value;
|
|
41
|
+
let relativeFilePath = decodeURI(quad.object.value);
|
|
42
42
|
// Try overriding path using defined import paths
|
|
43
43
|
if (this.parserOptions.importPaths) {
|
|
44
44
|
for (const prefix of Object.keys(this.parserOptions.importPaths)) {
|
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.7",
|
|
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"
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"jsonld-context-parser": "^2.1.1",
|
|
41
41
|
"minimist": "^1.2.0",
|
|
42
42
|
"rdf-data-factory": "^1.1.0",
|
|
43
|
-
"rdf-object": "^1.13.
|
|
43
|
+
"rdf-object": "^1.13.1",
|
|
44
44
|
"rdf-parse": "^1.9.1",
|
|
45
45
|
"rdf-quad": "^1.5.0",
|
|
46
46
|
"rdf-terms": "^1.7.0",
|