componentsjs 5.0.0-beta.1 → 5.0.0-beta.5
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 +36 -0
- 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 +9 -13
- package/lib/preprocess/GenericsContext.d.ts +49 -5
- package/lib/preprocess/GenericsContext.js +278 -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 +381 -108
- 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
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,59 @@
|
|
|
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.5"></a>
|
|
5
|
+
## [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
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
* [Allow type-checking to be disabled via typeChecking](https://github.com/LinkedSoftwareDependencies/Components.js/commit/a55331085e4c5621832e6b23bc52b00068e8256a)
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
* [Throw error on circular dependencies, Closes #53](https://github.com/LinkedSoftwareDependencies/Components.js/commit/e7a28d1cf87d96d5b58bb6d1f19ce41d6e55aab6)
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
* [Fix seeAlso links not handling encoded URI components, Closes #43](https://github.com/LinkedSoftwareDependencies/Components.js/commit/2b72914d2720b2982d4570af55f9b5d7dc196c27)
|
|
15
|
+
|
|
16
|
+
<a name="v5.0.0-beta.4"></a>
|
|
17
|
+
## [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
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
* [Support ParameterRangeIndexed for fixed literals](https://github.com/LinkedSoftwareDependencies/Components.js/commit/0d97782a4a8dcca9fc5bbb3389a4213eca5a5205)
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
* [Propagate original error messages to require calls, Closes #65](https://github.com/LinkedSoftwareDependencies/Components.js/commit/8934ec9b784def601730b3d3f2e60c4ff0b8776e)
|
|
24
|
+
* [Include config id in invalid param error message](https://github.com/LinkedSoftwareDependencies/Components.js/commit/e724f44e2222eb9917da3b227e2ce0dc9cde15f9)
|
|
25
|
+
* [Update memberKeys to memberFields](https://github.com/LinkedSoftwareDependencies/Components.js/commit/2c7437e1519c1813fb1a29f50d7c20bdbdf7f06e)
|
|
26
|
+
|
|
27
|
+
<a name="v5.0.0-beta.3"></a>
|
|
28
|
+
## [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
|
|
29
|
+
|
|
30
|
+
### Added
|
|
31
|
+
* [Add support for wildcard parameter ranges](https://github.com/LinkedSoftwareDependencies/Components.js/commit/83238a9fa08877f29326be562d7d3d5fff860c69)
|
|
32
|
+
* Improve error reporting:
|
|
33
|
+
* [Add causes for param check failures in error messages](https://github.com/LinkedSoftwareDependencies/Components.js/commit/9be1fd0899ffb8a77ea99e5fb86e661526ef6d1a)
|
|
34
|
+
* [Improve error message on invalid generic type instantiations](https://github.com/LinkedSoftwareDependencies/Components.js/commit/6ecb9798eeb84f09fece68b3a47454fa8c857ba4)
|
|
35
|
+
* [Move error context to error state file](https://github.com/LinkedSoftwareDependencies/Components.js/commit/dbf26e072bdc63168814ef4d503777efaf4745eb)
|
|
36
|
+
|
|
37
|
+
### Fixed
|
|
38
|
+
* Resolve several issues related to generics:
|
|
39
|
+
* [Throw error on invalid ParameterRangeGenericComponent](https://github.com/LinkedSoftwareDependencies/Components.js/commit/c692ab6175ce466fb32fbe38b973644e2601b2e6)
|
|
40
|
+
* [Fix generic components not accepting specific types](https://github.com/LinkedSoftwareDependencies/Components.js/commit/c7739182fddcb92d46a86fe3e33d6e29fd1134b6)
|
|
41
|
+
* [Support generic type instantiation during component extension](https://github.com/LinkedSoftwareDependencies/Components.js/commit/98f70e350cc3f9bf8a4ea632db546f74624ddda7)
|
|
42
|
+
* [Support generic components in params with fixed generics](https://github.com/LinkedSoftwareDependencies/Components.js/commit/d8b30972e1306e9fe9db391d4693aa6000917e60)
|
|
43
|
+
* [Use GenericComponentExtension to refer to wrapped generic comp extensions](https://github.com/LinkedSoftwareDependencies/Components.js/commit/239895accfdb7f09a7ac8454928bd3e0be5e5f15)
|
|
44
|
+
* [Fix invalid range display with multiple generics](https://github.com/LinkedSoftwareDependencies/Components.js/commit/b98baf0bcf4546b60299ae548f929693345292bc)
|
|
45
|
+
* [Handle range merging if left or right is union](https://github.com/LinkedSoftwareDependencies/Components.js/commit/637e140106691b95f0f546cf88eb39f3f80dc61d)
|
|
46
|
+
* [Handle sub-types when merging param ranges](https://github.com/LinkedSoftwareDependencies/Components.js/commit/43290525b2e244f5fbb6d5f344760b863329c31b)
|
|
47
|
+
* [Allow merging of generic component param types](https://github.com/LinkedSoftwareDependencies/Components.js/commit/ee8de7d9b8d18bf6968a17078e493946e5fca8cd)
|
|
48
|
+
* [Allow param range merging with generic components](https://github.com/LinkedSoftwareDependencies/Components.js/commit/bcea7dcff288ce7068ee244c49c12134208c89da)
|
|
49
|
+
* [Fix generics crash when doing repeated param type checking](https://github.com/LinkedSoftwareDependencies/Components.js/commit/237572cb8a9c546b098582041ccd7a457b41aecd)
|
|
50
|
+
|
|
51
|
+
<a name="v5.0.0-beta.2"></a>
|
|
52
|
+
## [v5.0.0-beta.2](https://github.com/LinkedSoftwareDependencies/Components.js/compare/v5.0.0-beta.1...v5.0.0-beta.2) - 2021-12-09
|
|
53
|
+
|
|
54
|
+
### Added
|
|
55
|
+
* [Handle keyof parameter ranges](https://github.com/LinkedSoftwareDependencies/Components.js/commit/0f55ba05bff5311d111ca97256aaa2e7be7ae83b)
|
|
56
|
+
|
|
4
57
|
<a name="v5.0.0-beta.1"></a>
|
|
5
58
|
## [v5.0.0-beta.1](https://github.com/LinkedSoftwareDependencies/Components.js/compare/v5.0.0-beta.0...v5.0.0-beta.1) - 2021-12-07
|
|
6
59
|
|
package/README.md
CHANGED
|
@@ -202,6 +202,57 @@ 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
|
+
|
|
240
|
+
## Cite
|
|
241
|
+
|
|
242
|
+
If you are using or extending Components.js as part of a scientific publication,
|
|
243
|
+
we would appreciate a citation of our [article](https://linkedsoftwaredependencies.github.io/Article-System-Components/).
|
|
244
|
+
|
|
245
|
+
```bibtex
|
|
246
|
+
@article{taelman_swj_componentsjs_2022,
|
|
247
|
+
author = {Taelman, Ruben and Van Herwegen, Joachim and Vander Sande, Miel and Verborgh, Ruben},
|
|
248
|
+
title = {Components.js: Semantic Dependency Injection},
|
|
249
|
+
journal = {Semantic Web Journal},
|
|
250
|
+
year = {2022},
|
|
251
|
+
month = jan,
|
|
252
|
+
url = {https://linkedsoftwaredependencies.github.io/Article-System-Components/}
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
205
256
|
## License
|
|
206
257
|
Components.js is written by [Ruben Taelman](http://www.rubensworks.net/).
|
|
207
258
|
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
"@context": {
|
|
3
3
|
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
|
|
4
4
|
"xsd": "http://www.w3.org/2001/XMLSchema#",
|
|
5
|
+
"type": {
|
|
6
|
+
"@id": "rdf:type"
|
|
7
|
+
},
|
|
5
8
|
"types": {
|
|
6
9
|
"@id": "rdf:type"
|
|
7
10
|
},
|
|
@@ -29,6 +32,12 @@
|
|
|
29
32
|
"parameters": {
|
|
30
33
|
"@id": "oo:parameter"
|
|
31
34
|
},
|
|
35
|
+
"memberFields": {
|
|
36
|
+
"@id": "oo:memberFields"
|
|
37
|
+
},
|
|
38
|
+
"memberFieldName": {
|
|
39
|
+
"@id": "oo:memberFieldName"
|
|
40
|
+
},
|
|
32
41
|
"genericTypeParameters": {
|
|
33
42
|
"@id": "oo:genericTypeParameter"
|
|
34
43
|
},
|
|
@@ -74,9 +83,18 @@
|
|
|
74
83
|
"ParameterRangeUndefined": {
|
|
75
84
|
"@id": "oo:ParameterRangeUndefined"
|
|
76
85
|
},
|
|
86
|
+
"ParameterRangeWildcard": {
|
|
87
|
+
"@id": "oo:ParameterRangeWildcard"
|
|
88
|
+
},
|
|
77
89
|
"ParameterRangeArray": {
|
|
78
90
|
"@id": "oo:ParameterRangeArray"
|
|
79
91
|
},
|
|
92
|
+
"ParameterRangeRest": {
|
|
93
|
+
"@id": "oo:ParameterRangeRest"
|
|
94
|
+
},
|
|
95
|
+
"ParameterRangeKeyof": {
|
|
96
|
+
"@id": "oo:ParameterRangeKeyof"
|
|
97
|
+
},
|
|
80
98
|
"ParameterRangeLiteral": {
|
|
81
99
|
"@id": "oo:ParameterRangeLiteral"
|
|
82
100
|
},
|
|
@@ -107,6 +125,10 @@
|
|
|
107
125
|
"ParameterRangeGenericComponent": {
|
|
108
126
|
"@id": "oo:ParameterRangeGenericComponent"
|
|
109
127
|
},
|
|
128
|
+
"genericTypeInstancesComponentScope": {
|
|
129
|
+
"@id": "oo:genericTypeInstancesComponentScope",
|
|
130
|
+
"@type": "@id"
|
|
131
|
+
},
|
|
110
132
|
"genericTypeInstances": {
|
|
111
133
|
"@id": "oo:genericTypeInstance",
|
|
112
134
|
"@type": "@id"
|
|
@@ -122,6 +144,20 @@
|
|
|
122
144
|
"@id": "oo:parameterRangeGenericBindings",
|
|
123
145
|
"@type": "@id"
|
|
124
146
|
},
|
|
147
|
+
"GenericComponentExtension": {
|
|
148
|
+
"@id": "oo:GenericComponentExtension"
|
|
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
|
+
},
|
|
125
161
|
|
|
126
162
|
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
|
|
127
163
|
"comment": {
|
package/lib/ComponentsManager.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ComponentsManager = void 0;
|
|
4
4
|
const fs = require("fs");
|
|
5
5
|
const ComponentsManagerBuilder_1 = require("./loading/ComponentsManagerBuilder");
|
|
6
|
+
const ErrorResourcesContext_1 = require("./util/ErrorResourcesContext");
|
|
6
7
|
/**
|
|
7
8
|
* A components manager can instantiate components.
|
|
8
9
|
* This manager should be created using {@link ComponentsManager.build}.
|
|
@@ -51,17 +52,14 @@ class ComponentsManager {
|
|
|
51
52
|
*/
|
|
52
53
|
generateErrorLog(error) {
|
|
53
54
|
if (this.dumpErrorState) {
|
|
54
|
-
const contents = JSON.stringify({
|
|
55
|
-
componentTypes: Object.keys(this.componentResources),
|
|
56
|
-
moduleState: {
|
|
55
|
+
const contents = JSON.stringify(Object.assign(Object.assign({}, error instanceof ErrorResourcesContext_1.ErrorResourcesContext ? error.exportContext() : {}), { componentTypes: Object.keys(this.componentResources), moduleState: {
|
|
57
56
|
mainModulePath: this.moduleState.mainModulePath,
|
|
58
57
|
componentModules: this.moduleState.componentModules,
|
|
59
58
|
importPaths: this.moduleState.importPaths,
|
|
60
59
|
contexts: this.moduleState.contexts,
|
|
61
60
|
nodeModuleImportPaths: this.moduleState.nodeModuleImportPaths,
|
|
62
61
|
nodeModulePaths: this.moduleState.nodeModulePaths,
|
|
63
|
-
},
|
|
64
|
-
}, null, ' ');
|
|
62
|
+
} }), null, ' ');
|
|
65
63
|
fs.writeFileSync('componentsjs-error-state.json', contents, 'utf8');
|
|
66
64
|
this.logger.error(`Detected fatal error. Generated 'componentsjs-error-state.json' with more information.`);
|
|
67
65
|
}
|
|
@@ -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) {
|
|
@@ -41,7 +41,13 @@ class ComponentRegistryFinalizer {
|
|
|
41
41
|
* @param superComponents The components to inherit from.
|
|
42
42
|
*/
|
|
43
43
|
inheritParameters(component, superComponents) {
|
|
44
|
-
|
|
44
|
+
var _a;
|
|
45
|
+
for (let superComponent of superComponents) {
|
|
46
|
+
// Check if the super component is wrapped in a generic component instantiation
|
|
47
|
+
if (((_a = superComponent.property.type) === null || _a === void 0 ? void 0 : _a.value) === this.objectLoader.contextResolved
|
|
48
|
+
.expandTerm('oo:GenericComponentExtension')) {
|
|
49
|
+
superComponent = superComponent.property.component;
|
|
50
|
+
}
|
|
45
51
|
this.componentRegistry.requireValidComponent(superComponent, component);
|
|
46
52
|
for (const parameter of superComponent.properties.parameters) {
|
|
47
53
|
if (!component.properties.parameters.includes(parameter)) {
|
|
@@ -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: [
|
|
@@ -89,20 +89,16 @@ class ConfigPreprocessorComponent {
|
|
|
89
89
|
return configRaw;
|
|
90
90
|
}
|
|
91
91
|
createGenericsContext(handleResponse, config) {
|
|
92
|
+
// Create a new generics context for the component's generic type parameters
|
|
92
93
|
const genericsContext = new GenericsContext_1.GenericsContext(this.objectLoader, handleResponse.component.properties.genericTypeParameters);
|
|
93
|
-
//
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
for (const [i, genericTypeInstance] of config.properties.genericTypeInstances.entries()) {
|
|
102
|
-
// Remap generic type IRI to inner generic type IRI
|
|
103
|
-
const genericTypeIdInner = genericTypesInner[i].value;
|
|
104
|
-
genericsContext.bindings[genericTypeIdInner] = genericTypeInstance.properties.parameterRangeGenericBindings;
|
|
105
|
-
genericsContext.genericTypeIds[genericTypeIdInner] = true;
|
|
94
|
+
// If the config has a genericTypeInstancesComponentScope, it will also have genericTypeInstances.
|
|
95
|
+
// In that case, we bind these instances to the component's generic type parameters within the context.
|
|
96
|
+
// (these values may have been set during generic param type-checking in
|
|
97
|
+
// ParameterPropertyHandlerRange#hasParamValueValidType)
|
|
98
|
+
if (config.property.genericTypeInstancesComponentScope &&
|
|
99
|
+
handleResponse.component.value === config.property.genericTypeInstancesComponentScope.value) {
|
|
100
|
+
genericsContext.bindComponentGenericTypes(handleResponse.component, config.properties.genericTypeInstances, { config }, (subType, superType) => this.parameterHandler.parameterPropertyHandlerRange
|
|
101
|
+
.hasType(subType, superType, genericsContext, config.property.genericTypeInstancesComponentScope, config.properties.genericTypeInstances, { config }));
|
|
106
102
|
}
|
|
107
103
|
return genericsContext;
|
|
108
104
|
}
|
|
@@ -1,30 +1,74 @@
|
|
|
1
|
+
import type * as RDF from '@rdfjs/types';
|
|
1
2
|
import type { Resource, RdfObjectLoader } from 'rdf-object';
|
|
3
|
+
import type { IParamValueConflict } from './parameterproperty/ParameterPropertyHandlerRange';
|
|
2
4
|
/**
|
|
3
5
|
* Context for binding generic types to a concrete range value.
|
|
4
6
|
*/
|
|
5
7
|
export declare class GenericsContext {
|
|
8
|
+
private static readonly XSD_INHERITANCE_TABLE;
|
|
6
9
|
private readonly objectLoader;
|
|
7
10
|
/**
|
|
8
11
|
* Set of generic type ids.
|
|
9
12
|
* @private
|
|
10
13
|
*/
|
|
11
|
-
|
|
14
|
+
genericTypeIds: Record<string, boolean>;
|
|
12
15
|
/**
|
|
13
16
|
* Mapping of generic type id to the resolved range.
|
|
14
17
|
* @private
|
|
15
18
|
*/
|
|
16
|
-
|
|
19
|
+
bindings: Record<string, Resource>;
|
|
17
20
|
constructor(objectLoader: RdfObjectLoader, genericTypeParameters: Resource[]);
|
|
18
21
|
/**
|
|
19
22
|
* Try to to bind the given value to the given generic.
|
|
20
23
|
* @param genericTypeId IRI of the generic to bind.
|
|
21
24
|
* @param value The value to bind to.
|
|
22
|
-
* @param
|
|
25
|
+
* @param valueTypeValidator Callback for validating values against types.
|
|
26
|
+
* @param typeTypeValidator Callback for validating sub-types against super-types.
|
|
27
|
+
* @return boolean True if the binding was valid and took place.
|
|
23
28
|
*/
|
|
24
|
-
bindGenericTypeToValue(genericTypeId: string, value: Resource | undefined,
|
|
29
|
+
bindGenericTypeToValue(genericTypeId: string, value: Resource | undefined, valueTypeValidator: (subValue: Resource | undefined, subType: Resource) => IParamValueConflict | undefined, typeTypeValidator: (subValue: Resource, subType: Resource) => IParamValueConflict | undefined): IParamValueConflict | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Try to bind the given range to the given generic.
|
|
32
|
+
* @param genericTypeId IRI of the generic to bind.
|
|
33
|
+
* @param range The range to bind to.
|
|
34
|
+
* @param typeTypeValidator Callback for validating sub-types against super-types.
|
|
35
|
+
* @return boolean True if the binding was valid and took place.
|
|
36
|
+
*/
|
|
37
|
+
bindGenericTypeToRange(genericTypeId: string, range: Resource, typeTypeValidator: (subType: Resource, superType: Resource) => IParamValueConflict | undefined): IParamValueConflict | undefined;
|
|
25
38
|
/**
|
|
26
39
|
* Infer the parameter range of the given value.
|
|
27
40
|
* @param value A value.
|
|
28
41
|
*/
|
|
29
|
-
inferValueRange(value: Resource | undefined): Resource
|
|
42
|
+
inferValueRange(value: Resource | undefined): Resource | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Merge the given ranges into a new range.
|
|
45
|
+
* This will return undefined in the ranges are incompatible.
|
|
46
|
+
*
|
|
47
|
+
* If one type is more specific than the other, it will return the narrowest type.
|
|
48
|
+
*
|
|
49
|
+
* @param rangeA A first range.
|
|
50
|
+
* @param rangeB A second range.
|
|
51
|
+
* @param typeTypeValidator Callback for validating sub-types against super-types.
|
|
52
|
+
*/
|
|
53
|
+
mergeRanges(rangeA: Resource, rangeB: Resource, typeTypeValidator: (subType: Resource, superType: Resource) => IParamValueConflict | undefined): Resource | undefined;
|
|
54
|
+
protected mergeUnion(rangeUnion: Resource, rangeOther: Resource, typeValidator: (subType: Resource, superType: Resource) => IParamValueConflict | undefined): Resource | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Check if the given type is a subtype of the given super type.
|
|
57
|
+
* @param type A type node.
|
|
58
|
+
* @param potentialSuperType A potential super type node.
|
|
59
|
+
*/
|
|
60
|
+
isXsdSubType(type: RDF.Term, potentialSuperType: RDF.Term): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Apply the give generic type instances for the given component's generic type parameters.
|
|
63
|
+
*
|
|
64
|
+
* This will throw if the number of passed instances does not match with
|
|
65
|
+
* the number of generic type parameters on the component.
|
|
66
|
+
*
|
|
67
|
+
* @param component The component
|
|
68
|
+
* @param genericTypeInstances The generic type instances to apply.
|
|
69
|
+
* @param errorContext The context for error reporting.
|
|
70
|
+
* @param typeTypeValidator Callback for validating sub-types against super-types.
|
|
71
|
+
* @return boolean False if the application failed due to a binding error. True otherwise
|
|
72
|
+
*/
|
|
73
|
+
bindComponentGenericTypes(component: Resource, genericTypeInstances: Resource[], errorContext: Record<string, Resource | Resource[] | string>, typeTypeValidator: (subValue: Resource, subType: Resource) => IParamValueConflict | undefined): IParamValueConflict | undefined;
|
|
30
74
|
}
|