componentsjs 4.4.0 → 5.0.0-beta.1
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 +46 -0
- package/bin/compile-config.js +1 -1
- package/components/context.jsonld +65 -2
- package/lib/construction/ConfigConstructor.js +7 -14
- package/lib/construction/argument/ArgumentConstructorHandlerHash.js +3 -2
- package/lib/construction/strategy/ConstructionStrategyCommonJsString.js +3 -0
- package/lib/construction/strategy/IConstructionStrategy.d.ts +2 -2
- package/lib/loading/ComponentRegistry.d.ts +1 -1
- package/lib/loading/ComponentRegistry.js +1 -1
- package/lib/loading/ComponentRegistryFinalizer.js +18 -3
- package/lib/loading/ComponentsManagerBuilder.js +1 -1
- package/lib/loading/ConfigRegistry.d.ts +1 -1
- package/lib/preprocess/ConfigPreprocessorComponent.d.ts +3 -1
- package/lib/preprocess/ConfigPreprocessorComponent.js +38 -12
- package/lib/preprocess/ConfigPreprocessorComponentMapped.d.ts +4 -3
- package/lib/preprocess/ConfigPreprocessorComponentMapped.js +17 -18
- package/lib/preprocess/GenericsContext.d.ts +30 -0
- package/lib/preprocess/GenericsContext.js +63 -0
- package/lib/preprocess/ParameterHandler.d.ts +4 -2
- package/lib/preprocess/ParameterHandler.js +24 -12
- package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerCollectEntries.d.ts +3 -2
- package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerCollectEntries.js +24 -10
- package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerElements.d.ts +2 -1
- package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerElements.js +8 -5
- package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerFields.d.ts +2 -1
- package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerFields.js +16 -9
- package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerKeyValue.d.ts +4 -3
- package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerKeyValue.js +12 -12
- package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerList.d.ts +2 -1
- package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerList.js +9 -22
- package/lib/preprocess/constructorargumentsmapping/IConstructorArgumentsElementMappingHandler.d.ts +5 -2
- package/lib/preprocess/constructorargumentsmapping/IConstructorArgumentsMapper.d.ts +5 -2
- package/lib/preprocess/parameterproperty/IParameterPropertyHandler.d.ts +5 -2
- package/lib/preprocess/parameterproperty/ParameterPropertyHandlerDefault.d.ts +6 -3
- package/lib/preprocess/parameterproperty/ParameterPropertyHandlerDefault.js +20 -3
- package/lib/preprocess/parameterproperty/ParameterPropertyHandlerDefaultScoped.d.ts +2 -2
- package/lib/preprocess/parameterproperty/ParameterPropertyHandlerDefaultScoped.js +16 -5
- package/lib/preprocess/parameterproperty/ParameterPropertyHandlerFixed.d.ts +5 -3
- package/lib/preprocess/parameterproperty/ParameterPropertyHandlerFixed.js +25 -2
- package/lib/preprocess/parameterproperty/ParameterPropertyHandlerLazy.d.ts +2 -2
- package/lib/preprocess/parameterproperty/ParameterPropertyHandlerLazy.js +10 -3
- package/lib/preprocess/parameterproperty/ParameterPropertyHandlerRange.d.ts +18 -4
- package/lib/preprocess/parameterproperty/ParameterPropertyHandlerRange.js +179 -30
- package/lib/rdf/Iris.js +24 -24
- package/lib/rdf/RdfParser.d.ts +2 -2
- package/lib/rdf/RdfParser.js +17 -5
- package/lib/rdf/RdfStreamIncluder.d.ts +1 -1
- package/lib/rdf/RdfStreamIncluder.js +2 -2
- package/package.json +10 -10
- package/lib/preprocess/parameterproperty/ParameterPropertyHandlerRequired.d.ts +0 -11
- package/lib/preprocess/parameterproperty/ParameterPropertyHandlerRequired.js +0 -23
- package/lib/preprocess/parameterproperty/ParameterPropertyHandlerUnique.d.ts +0 -12
- package/lib/preprocess/parameterproperty/ParameterPropertyHandlerUnique.js +0 -34
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ParameterHandler = void 0;
|
|
4
|
+
const ErrorResourcesContext_1 = require("../util/ErrorResourcesContext");
|
|
4
5
|
const ParameterPropertyHandlerDefault_1 = require("./parameterproperty/ParameterPropertyHandlerDefault");
|
|
5
6
|
const ParameterPropertyHandlerDefaultScoped_1 = require("./parameterproperty/ParameterPropertyHandlerDefaultScoped");
|
|
6
7
|
const ParameterPropertyHandlerFixed_1 = require("./parameterproperty/ParameterPropertyHandlerFixed");
|
|
7
8
|
const ParameterPropertyHandlerLazy_1 = require("./parameterproperty/ParameterPropertyHandlerLazy");
|
|
8
9
|
const ParameterPropertyHandlerRange_1 = require("./parameterproperty/ParameterPropertyHandlerRange");
|
|
9
|
-
const ParameterPropertyHandlerRequired_1 = require("./parameterproperty/ParameterPropertyHandlerRequired");
|
|
10
|
-
const ParameterPropertyHandlerUnique_1 = require("./parameterproperty/ParameterPropertyHandlerUnique");
|
|
11
10
|
/**
|
|
12
11
|
* Handles component parameters in the context of a config.
|
|
13
12
|
*/
|
|
@@ -16,10 +15,8 @@ class ParameterHandler {
|
|
|
16
15
|
this.objectLoader = options.objectLoader;
|
|
17
16
|
this.parameterPropertyHandlers = [
|
|
18
17
|
new ParameterPropertyHandlerDefaultScoped_1.ParameterPropertyHandlerDefaultScoped(this.objectLoader),
|
|
19
|
-
new ParameterPropertyHandlerDefault_1.ParameterPropertyHandlerDefault(),
|
|
20
|
-
new
|
|
21
|
-
new ParameterPropertyHandlerFixed_1.ParameterPropertyHandlerFixed(),
|
|
22
|
-
new ParameterPropertyHandlerUnique_1.ParameterPropertyHandlerUnique(this.objectLoader),
|
|
18
|
+
new ParameterPropertyHandlerDefault_1.ParameterPropertyHandlerDefault(this.objectLoader),
|
|
19
|
+
new ParameterPropertyHandlerFixed_1.ParameterPropertyHandlerFixed(this.objectLoader),
|
|
23
20
|
new ParameterPropertyHandlerRange_1.ParameterPropertyHandlerRange(this.objectLoader),
|
|
24
21
|
new ParameterPropertyHandlerLazy_1.ParameterPropertyHandlerLazy(),
|
|
25
22
|
];
|
|
@@ -29,15 +26,30 @@ class ParameterHandler {
|
|
|
29
26
|
* @param configRoot The root config resource that we are working in.
|
|
30
27
|
* @param parameter The parameter resource to get the value for.
|
|
31
28
|
* @param configElement Part of the config resource to look for parameter instantiations as predicates.
|
|
32
|
-
* @
|
|
29
|
+
* @param genericsContext Context for generic types.
|
|
30
|
+
* @return - The parameter value
|
|
33
31
|
*/
|
|
34
|
-
applyParameterValues(configRoot, parameter, configElement) {
|
|
35
|
-
//
|
|
36
|
-
|
|
32
|
+
applyParameterValues(configRoot, parameter, configElement, genericsContext) {
|
|
33
|
+
// Make sure that we always have a single value with list elements in it.
|
|
34
|
+
const values = configElement.properties[parameter.value];
|
|
35
|
+
let value;
|
|
36
|
+
if (values.length === 1) {
|
|
37
|
+
value = values[0];
|
|
38
|
+
}
|
|
39
|
+
else if (values.length > 0) {
|
|
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.`, {
|
|
42
|
+
arguments: values,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
value = this.objectLoader.createCompactedResource({
|
|
46
|
+
list: values.flatMap(subValue => subValue.list),
|
|
47
|
+
});
|
|
48
|
+
}
|
|
37
49
|
// Run the value through all applicable parameters property handlers.
|
|
38
50
|
for (const handler of this.parameterPropertyHandlers) {
|
|
39
|
-
if (handler.canHandle(value, configRoot, parameter, configElement)) {
|
|
40
|
-
value = handler.handle(value, configRoot, parameter, configElement);
|
|
51
|
+
if (handler.canHandle(value, configRoot, parameter, configElement, genericsContext)) {
|
|
52
|
+
value = handler.handle(value, configRoot, parameter, configElement, genericsContext);
|
|
41
53
|
}
|
|
42
54
|
}
|
|
43
55
|
return value;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Resource } from 'rdf-object';
|
|
2
|
+
import type { GenericsContext } from '../GenericsContext';
|
|
2
3
|
import type { ParameterHandler } from '../ParameterHandler';
|
|
3
4
|
import type { IConstructorArgumentsElementMappingHandler } from './IConstructorArgumentsElementMappingHandler';
|
|
4
5
|
import type { IConstructorArgumentsMapper } from './IConstructorArgumentsMapper';
|
|
@@ -9,6 +10,6 @@ export declare class ConstructorArgumentsElementMappingHandlerCollectEntries imp
|
|
|
9
10
|
private readonly parameterHandler;
|
|
10
11
|
constructor(parameterHandler: ParameterHandler);
|
|
11
12
|
canHandle(configRoot: Resource, constructorArgs: Resource, configElement: Resource, mapper: IConstructorArgumentsMapper): boolean;
|
|
12
|
-
handle(configRoot: Resource, constructorArgs: Resource, configElement: Resource, mapper: IConstructorArgumentsMapper): Resource
|
|
13
|
-
handleCollectEntry(entryResource: Resource, configRoot: Resource, constructorArgs: Resource, configElement: Resource, mapper: IConstructorArgumentsMapper): Resource;
|
|
13
|
+
handle(configRoot: Resource, constructorArgs: Resource, configElement: Resource, mapper: IConstructorArgumentsMapper, genericsContext: GenericsContext): Resource;
|
|
14
|
+
handleCollectEntry(entryResource: Resource, configRoot: Resource, constructorArgs: Resource, configElement: Resource, mapper: IConstructorArgumentsMapper, genericsContext: GenericsContext): Resource;
|
|
14
15
|
}
|
|
@@ -14,25 +14,37 @@ class ConstructorArgumentsElementMappingHandlerCollectEntries {
|
|
|
14
14
|
return Boolean((constructorArgs.property.value || constructorArgs.property.valueRawReference) &&
|
|
15
15
|
constructorArgs.property.collectEntries);
|
|
16
16
|
}
|
|
17
|
-
handle(configRoot, constructorArgs, configElement, mapper) {
|
|
17
|
+
handle(configRoot, constructorArgs, configElement, mapper, genericsContext) {
|
|
18
|
+
if (constructorArgs.properties.collectEntries.length > 1) {
|
|
19
|
+
throw new ErrorResourcesContext_1.ErrorResourcesContext(`Invalid collectEntries: Only one value can be defined, or an RDF list must be provided`, {
|
|
20
|
+
constructorArgs,
|
|
21
|
+
config: configRoot,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
const collectEntries = constructorArgs.properties.collectEntries[0];
|
|
18
25
|
// Obtain all entry values
|
|
19
26
|
const entryResources = [];
|
|
20
|
-
for (const entry of
|
|
27
|
+
for (const entry of collectEntries.list || [collectEntries]) {
|
|
21
28
|
if (entry.type !== 'NamedNode') {
|
|
22
29
|
throw new ErrorResourcesContext_1.ErrorResourcesContext(`Detected illegal collectEntries value "${entry.type}", must be an IRI`, {
|
|
23
30
|
constructorArgs,
|
|
24
31
|
config: configRoot,
|
|
25
32
|
});
|
|
26
33
|
}
|
|
27
|
-
|
|
28
|
-
|
|
34
|
+
const value = this.parameterHandler.applyParameterValues(configRoot, entry, configElement, genericsContext);
|
|
35
|
+
if (value) {
|
|
36
|
+
for (const subValue of value.list || [value]) {
|
|
37
|
+
entryResources.push(subValue);
|
|
38
|
+
}
|
|
29
39
|
}
|
|
30
40
|
}
|
|
31
41
|
// Map all entries to values
|
|
32
|
-
return
|
|
33
|
-
.
|
|
42
|
+
return mapper.objectLoader.createCompactedResource({
|
|
43
|
+
list: entryResources.map((entryResource) => this
|
|
44
|
+
.handleCollectEntry(entryResource, configRoot, constructorArgs, configElement, mapper, genericsContext)),
|
|
45
|
+
});
|
|
34
46
|
}
|
|
35
|
-
handleCollectEntry(entryResource, configRoot, constructorArgs, configElement, mapper) {
|
|
47
|
+
handleCollectEntry(entryResource, configRoot, constructorArgs, configElement, mapper, genericsContext) {
|
|
36
48
|
// Determine the (optional) entry key
|
|
37
49
|
let key;
|
|
38
50
|
if (constructorArgs.property.key) {
|
|
@@ -82,12 +94,15 @@ class ConstructorArgumentsElementMappingHandlerCollectEntries {
|
|
|
82
94
|
else if (constructorArgs.property.value.type === 'NamedNode' &&
|
|
83
95
|
constructorArgs.property.value.value === Iris_1.IRIS_RDF.object) {
|
|
84
96
|
// Value is the entry value
|
|
85
|
-
value = mapper
|
|
97
|
+
value = mapper
|
|
98
|
+
.applyConstructorArgumentsParameters(configRoot, entryResource, configElement, genericsContext);
|
|
86
99
|
}
|
|
87
100
|
else if (constructorArgs.property.value &&
|
|
88
101
|
(constructorArgs.property.value.property.fields || constructorArgs.property.value.property.elements)) {
|
|
89
102
|
// Nested mapping should reduce the parameter scope
|
|
90
|
-
|
|
103
|
+
// ! at the end of the line, because will always be truthy
|
|
104
|
+
value = mapper
|
|
105
|
+
.getParameterValue(configRoot, constructorArgs.property.value, entryResource, false, genericsContext);
|
|
91
106
|
}
|
|
92
107
|
else if (entryResource.properties[constructorArgs.property.value.value].length !== 1) {
|
|
93
108
|
throw new ErrorResourcesContext_1.ErrorResourcesContext(`Detected more than one value value in collectEntries`, {
|
|
@@ -106,7 +121,6 @@ class ConstructorArgumentsElementMappingHandlerCollectEntries {
|
|
|
106
121
|
if (key) {
|
|
107
122
|
const ret = mapper.objectLoader.createCompactedResource({});
|
|
108
123
|
ret.property.key = key;
|
|
109
|
-
value.property.unique = mapper.objectLoader.createCompactedResource('"true"');
|
|
110
124
|
ret.property.value = value;
|
|
111
125
|
return ret;
|
|
112
126
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Resource } from 'rdf-object';
|
|
2
|
+
import type { GenericsContext } from '../GenericsContext';
|
|
2
3
|
import type { IConstructorArgumentsElementMappingHandler } from './IConstructorArgumentsElementMappingHandler';
|
|
3
4
|
import type { IConstructorArgumentsMapper } from './IConstructorArgumentsMapper';
|
|
4
5
|
/**
|
|
@@ -6,5 +7,5 @@ import type { IConstructorArgumentsMapper } from './IConstructorArgumentsMapper'
|
|
|
6
7
|
*/
|
|
7
8
|
export declare class ConstructorArgumentsElementMappingHandlerElements implements IConstructorArgumentsElementMappingHandler {
|
|
8
9
|
canHandle(configRoot: Resource, constructorArgs: Resource, configElement: Resource, mapper: IConstructorArgumentsMapper): boolean;
|
|
9
|
-
handle(configRoot: Resource, constructorArgs: Resource, configElement: Resource, mapper: IConstructorArgumentsMapper): Resource
|
|
10
|
+
handle(configRoot: Resource, constructorArgs: Resource, configElement: Resource, mapper: IConstructorArgumentsMapper, genericsContext: GenericsContext): Resource;
|
|
10
11
|
}
|
|
@@ -9,7 +9,7 @@ class ConstructorArgumentsElementMappingHandlerElements {
|
|
|
9
9
|
canHandle(configRoot, constructorArgs, configElement, mapper) {
|
|
10
10
|
return Boolean(constructorArgs.property.elements);
|
|
11
11
|
}
|
|
12
|
-
handle(configRoot, constructorArgs, configElement, mapper) {
|
|
12
|
+
handle(configRoot, constructorArgs, configElement, mapper, genericsContext) {
|
|
13
13
|
// Elements must have RDF list values.
|
|
14
14
|
if (!constructorArgs.property.elements.list) {
|
|
15
15
|
throw new ErrorResourcesContext_1.ErrorResourcesContext(`Illegal non-RDF-list elements`, {
|
|
@@ -19,7 +19,7 @@ class ConstructorArgumentsElementMappingHandlerElements {
|
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
// Recursively handle all values in the array
|
|
22
|
-
const
|
|
22
|
+
const entries = [];
|
|
23
23
|
for (const element of constructorArgs.property.elements.list) {
|
|
24
24
|
if (element.type !== 'NamedNode' && !element.property.value && !element.property.valueRawReference) {
|
|
25
25
|
throw new ErrorResourcesContext_1.ErrorResourcesContext(`Illegal elements value, must be an IRI or resource with value/valueRawReference`, {
|
|
@@ -29,11 +29,14 @@ class ConstructorArgumentsElementMappingHandlerElements {
|
|
|
29
29
|
config: configRoot,
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
const value = mapper.getParameterValue(configRoot, element, configElement, Boolean(element.property.valueRawReference), genericsContext);
|
|
33
|
+
if (value) {
|
|
34
|
+
for (const entry of value.list || [value]) {
|
|
35
|
+
entries.push(entry);
|
|
36
|
+
}
|
|
34
37
|
}
|
|
35
38
|
}
|
|
36
|
-
return
|
|
39
|
+
return mapper.objectLoader.createCompactedResource({ value: { list: entries } });
|
|
37
40
|
}
|
|
38
41
|
}
|
|
39
42
|
exports.ConstructorArgumentsElementMappingHandlerElements = ConstructorArgumentsElementMappingHandlerElements;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Resource } from 'rdf-object';
|
|
2
|
+
import type { GenericsContext } from '../GenericsContext';
|
|
2
3
|
import type { IConstructorArgumentsElementMappingHandler } from './IConstructorArgumentsElementMappingHandler';
|
|
3
4
|
import type { IConstructorArgumentsMapper } from './IConstructorArgumentsMapper';
|
|
4
5
|
/**
|
|
@@ -6,5 +7,5 @@ import type { IConstructorArgumentsMapper } from './IConstructorArgumentsMapper'
|
|
|
6
7
|
*/
|
|
7
8
|
export declare class ConstructorArgumentsElementMappingHandlerFields implements IConstructorArgumentsElementMappingHandler {
|
|
8
9
|
canHandle(configRoot: Resource, constructorArgs: Resource, configElement: Resource, mapper: IConstructorArgumentsMapper): boolean;
|
|
9
|
-
handle(configRoot: Resource, constructorArgs: Resource, configElement: Resource, mapper: IConstructorArgumentsMapper): Resource
|
|
10
|
+
handle(configRoot: Resource, constructorArgs: Resource, configElement: Resource, mapper: IConstructorArgumentsMapper, genericsContext: GenericsContext): Resource;
|
|
10
11
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ConstructorArgumentsElementMappingHandlerFields = void 0;
|
|
4
|
+
const ErrorResourcesContext_1 = require("../../util/ErrorResourcesContext");
|
|
4
5
|
/**
|
|
5
6
|
* Handler for field definitions that contain key-value pairs to form a hash.
|
|
6
7
|
*/
|
|
@@ -8,18 +9,24 @@ class ConstructorArgumentsElementMappingHandlerFields {
|
|
|
8
9
|
canHandle(configRoot, constructorArgs, configElement, mapper) {
|
|
9
10
|
return Boolean(constructorArgs.property.fields);
|
|
10
11
|
}
|
|
11
|
-
handle(configRoot, constructorArgs, configElement, mapper) {
|
|
12
|
+
handle(configRoot, constructorArgs, configElement, mapper, genericsContext) {
|
|
13
|
+
if (constructorArgs.properties.fields.length > 1) {
|
|
14
|
+
throw new ErrorResourcesContext_1.ErrorResourcesContext(`Invalid fields: Only one value can be defined, or an RDF list must be provided`, {
|
|
15
|
+
constructorArgs,
|
|
16
|
+
config: configRoot,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
const fields = constructorArgs.properties.fields[0];
|
|
12
20
|
// Recursively handle all field values.
|
|
13
|
-
const
|
|
14
|
-
for (const field of
|
|
15
|
-
|
|
16
|
-
|
|
21
|
+
const entries = [];
|
|
22
|
+
for (const field of fields.list || [fields]) {
|
|
23
|
+
const mapped = mapper
|
|
24
|
+
.applyConstructorArgumentsParameters(configRoot, field, configElement, genericsContext);
|
|
25
|
+
for (const entry of mapped.list || [mapped]) {
|
|
26
|
+
entries.push(entry);
|
|
17
27
|
}
|
|
18
28
|
}
|
|
19
|
-
|
|
20
|
-
// Hack to enforce ArgumentConstructorHandlerHash
|
|
21
|
-
ret.property.hasFields = mapper.objectLoader.createCompactedResource('"true"');
|
|
22
|
-
return [ret];
|
|
29
|
+
return mapper.objectLoader.createCompactedResource({ fields: { list: entries } });
|
|
23
30
|
}
|
|
24
31
|
}
|
|
25
32
|
exports.ConstructorArgumentsElementMappingHandlerFields = ConstructorArgumentsElementMappingHandlerFields;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Resource } from 'rdf-object';
|
|
2
|
+
import type { GenericsContext } from '../GenericsContext';
|
|
2
3
|
import type { IConstructorArgumentsElementMappingHandler } from './IConstructorArgumentsElementMappingHandler';
|
|
3
4
|
import type { IConstructorArgumentsMapper } from './IConstructorArgumentsMapper';
|
|
4
5
|
/**
|
|
@@ -6,7 +7,7 @@ import type { IConstructorArgumentsMapper } from './IConstructorArgumentsMapper'
|
|
|
6
7
|
*/
|
|
7
8
|
export declare class ConstructorArgumentsElementMappingHandlerKeyValue implements IConstructorArgumentsElementMappingHandler {
|
|
8
9
|
canHandle(configRoot: Resource, constructorArgs: Resource, configElement: Resource, mapper: IConstructorArgumentsMapper): boolean;
|
|
9
|
-
handle(configRoot: Resource, constructorArgs: Resource, configElement: Resource, mapper: IConstructorArgumentsMapper): Resource
|
|
10
|
-
handleKeyValue(configRoot: Resource, constructorArgs: Resource, configElement: Resource, mapper: IConstructorArgumentsMapper): Resource
|
|
11
|
-
handleValue(configRoot: Resource, constructorArgs: Resource, configElement: Resource, mapper: IConstructorArgumentsMapper): Resource
|
|
10
|
+
handle(configRoot: Resource, constructorArgs: Resource, configElement: Resource, mapper: IConstructorArgumentsMapper, genericsContext: GenericsContext): Resource;
|
|
11
|
+
handleKeyValue(configRoot: Resource, constructorArgs: Resource, configElement: Resource, mapper: IConstructorArgumentsMapper, genericsContext: GenericsContext): Resource;
|
|
12
|
+
handleValue(configRoot: Resource, constructorArgs: Resource, configElement: Resource, mapper: IConstructorArgumentsMapper, genericsContext: GenericsContext): Resource;
|
|
12
13
|
}
|
|
@@ -10,7 +10,7 @@ class ConstructorArgumentsElementMappingHandlerKeyValue {
|
|
|
10
10
|
return Boolean((constructorArgs.property.value || constructorArgs.property.valueRawReference) &&
|
|
11
11
|
!constructorArgs.property.collectEntries);
|
|
12
12
|
}
|
|
13
|
-
handle(configRoot, constructorArgs, configElement, mapper) {
|
|
13
|
+
handle(configRoot, constructorArgs, configElement, mapper, genericsContext) {
|
|
14
14
|
if (constructorArgs.property.key) {
|
|
15
15
|
// Throw if our key is not a literal
|
|
16
16
|
if (constructorArgs.property.key.type !== 'Literal') {
|
|
@@ -21,21 +21,21 @@ class ConstructorArgumentsElementMappingHandlerKeyValue {
|
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
// Key-value
|
|
24
|
-
return this.handleKeyValue(configRoot, constructorArgs, configElement, mapper);
|
|
24
|
+
return this.handleKeyValue(configRoot, constructorArgs, configElement, mapper, genericsContext);
|
|
25
25
|
}
|
|
26
26
|
// Only value
|
|
27
|
-
return this.handleValue(configRoot, constructorArgs, configElement, mapper);
|
|
27
|
+
return this.handleValue(configRoot, constructorArgs, configElement, mapper, genericsContext);
|
|
28
28
|
}
|
|
29
|
-
handleKeyValue(configRoot, constructorArgs, configElement, mapper) {
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
for (const value of mapper.getParameterValue(configRoot, constructorArgs.property.value || constructorArgs.property.valueRawReference, configElement, Boolean(constructorArgs.property.valueRawReference))) {
|
|
33
|
-
ret.properties.value.push(value);
|
|
34
|
-
}
|
|
35
|
-
return [ret];
|
|
29
|
+
handleKeyValue(configRoot, constructorArgs, configElement, mapper, genericsContext) {
|
|
30
|
+
const value = mapper.getParameterValue(configRoot, constructorArgs.property.value || constructorArgs.property.valueRawReference, configElement, Boolean(constructorArgs.property.valueRawReference), genericsContext);
|
|
31
|
+
return mapper.objectLoader.createCompactedResource(Object.assign({ key: constructorArgs.property.key }, value ? { value } : {}));
|
|
36
32
|
}
|
|
37
|
-
handleValue(configRoot, constructorArgs, configElement, mapper) {
|
|
38
|
-
|
|
33
|
+
handleValue(configRoot, constructorArgs, configElement, mapper, genericsContext) {
|
|
34
|
+
const value = mapper.getParameterValue(configRoot, constructorArgs.property.value || constructorArgs.property.valueRawReference, configElement, Boolean(constructorArgs.property.valueRawReference), genericsContext);
|
|
35
|
+
if (!value) {
|
|
36
|
+
return mapper.objectLoader.createCompactedResource({ undefined: true });
|
|
37
|
+
}
|
|
38
|
+
return value;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
exports.ConstructorArgumentsElementMappingHandlerKeyValue = ConstructorArgumentsElementMappingHandlerKeyValue;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Resource } from 'rdf-object';
|
|
2
|
+
import type { GenericsContext } from '../GenericsContext';
|
|
2
3
|
import type { IConstructorArgumentsElementMappingHandler } from './IConstructorArgumentsElementMappingHandler';
|
|
3
4
|
import type { IConstructorArgumentsMapper } from './IConstructorArgumentsMapper';
|
|
4
5
|
/**
|
|
@@ -6,5 +7,5 @@ import type { IConstructorArgumentsMapper } from './IConstructorArgumentsMapper'
|
|
|
6
7
|
*/
|
|
7
8
|
export declare class ConstructorArgumentsElementMappingHandlerList implements IConstructorArgumentsElementMappingHandler {
|
|
8
9
|
canHandle(configRoot: Resource, constructorArgs: Resource, configElement: Resource, mapper: IConstructorArgumentsMapper): boolean;
|
|
9
|
-
handle(configRoot: Resource, constructorArgs: Resource, configElement: Resource, mapper: IConstructorArgumentsMapper): Resource
|
|
10
|
+
handle(configRoot: Resource, constructorArgs: Resource, configElement: Resource, mapper: IConstructorArgumentsMapper, genericsContext: GenericsContext): Resource;
|
|
10
11
|
}
|
package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerList.js
CHANGED
|
@@ -8,40 +8,27 @@ class ConstructorArgumentsElementMappingHandlerList {
|
|
|
8
8
|
canHandle(configRoot, constructorArgs, configElement, mapper) {
|
|
9
9
|
return Boolean(constructorArgs.list);
|
|
10
10
|
}
|
|
11
|
-
handle(configRoot, constructorArgs, configElement, mapper) {
|
|
12
|
-
var _a;
|
|
11
|
+
handle(configRoot, constructorArgs, configElement, mapper, genericsContext) {
|
|
13
12
|
// Recursively handle all field values.
|
|
14
13
|
const ret = mapper.objectLoader.createCompactedResource({});
|
|
15
14
|
ret.list = [];
|
|
16
15
|
for (const argument of constructorArgs.list) {
|
|
17
16
|
if (argument.property.fields || argument.property.elements) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
17
|
+
ret.list.push(mapper
|
|
18
|
+
.applyConstructorArgumentsParameters(configRoot, argument, configElement, genericsContext));
|
|
21
19
|
}
|
|
22
20
|
else {
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
ret.list.push(mappeds[0]);
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
// Add all values as an array if param was not unique
|
|
31
|
-
ret.list.push(mapper.objectLoader.createCompactedResource({
|
|
32
|
-
elements: mappeds.map(value => mapper.objectLoader.createCompactedResource({ value })),
|
|
33
|
-
}));
|
|
34
|
-
}
|
|
21
|
+
const value = mapper
|
|
22
|
+
.getParameterValue(configRoot, argument, configElement, false, genericsContext);
|
|
23
|
+
if (value) {
|
|
24
|
+
ret.list.push(value);
|
|
35
25
|
}
|
|
36
26
|
else {
|
|
37
|
-
|
|
38
|
-
ret.list.push(mapper.objectLoader.createCompactedResource({
|
|
39
|
-
undefined: true,
|
|
40
|
-
}));
|
|
27
|
+
ret.list.push(mapper.objectLoader.createCompactedResource({ undefined: true }));
|
|
41
28
|
}
|
|
42
29
|
}
|
|
43
30
|
}
|
|
44
|
-
return
|
|
31
|
+
return ret;
|
|
45
32
|
}
|
|
46
33
|
}
|
|
47
34
|
exports.ConstructorArgumentsElementMappingHandlerList = ConstructorArgumentsElementMappingHandlerList;
|
package/lib/preprocess/constructorargumentsmapping/IConstructorArgumentsElementMappingHandler.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Resource } from 'rdf-object';
|
|
2
|
+
import type { GenericsContext } from '../GenericsContext';
|
|
2
3
|
import type { IConstructorArgumentsMapper } from './IConstructorArgumentsMapper';
|
|
3
4
|
/**
|
|
4
5
|
* Handles a specific type of a constructor argument element.
|
|
@@ -10,8 +11,9 @@ export interface IConstructorArgumentsElementMappingHandler {
|
|
|
10
11
|
* @param constructorArgs Object mapping definition inside the constructor arguments.
|
|
11
12
|
* @param configElement Part of the config resource to look for parameter instantiations as predicates.
|
|
12
13
|
* @param mapper Instance of the constructor arguments mapper that can be used to handle recursive args.
|
|
14
|
+
* @param genericsContext Context for generic types.
|
|
13
15
|
*/
|
|
14
|
-
canHandle: (configRoot: Resource, constructorArgs: Resource, configElement: Resource, mapper: IConstructorArgumentsMapper) => boolean;
|
|
16
|
+
canHandle: (configRoot: Resource, constructorArgs: Resource, configElement: Resource, mapper: IConstructorArgumentsMapper, genericsContext: GenericsContext) => boolean;
|
|
15
17
|
/**
|
|
16
18
|
* Map the given config element with param instantiations
|
|
17
19
|
* to a raw config according to the given constructor arguments definition.
|
|
@@ -19,6 +21,7 @@ export interface IConstructorArgumentsElementMappingHandler {
|
|
|
19
21
|
* @param constructorArgs Object mapping definition inside the constructor arguments.
|
|
20
22
|
* @param configElement Part of the config resource to look for parameter instantiations as predicates.
|
|
21
23
|
* @param mapper Instance of the constructor arguments mapper that can be used to handle recursive args.
|
|
24
|
+
* @param genericsContext Context for generic types.
|
|
22
25
|
*/
|
|
23
|
-
handle: (configRoot: Resource, constructorArgs: Resource, configElement: Resource, mapper: IConstructorArgumentsMapper) => Resource
|
|
26
|
+
handle: (configRoot: Resource, constructorArgs: Resource, configElement: Resource, mapper: IConstructorArgumentsMapper, genericsContext: GenericsContext) => Resource;
|
|
24
27
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { RdfObjectLoader, Resource } from 'rdf-object';
|
|
2
|
+
import type { GenericsContext } from '../GenericsContext';
|
|
2
3
|
/**
|
|
3
4
|
* Instances of this interfaces can apply constructor arguments on configs.
|
|
4
5
|
* This is mainly used by {@link IConstructorArgumentsElementMappingHandler}.
|
|
@@ -15,14 +16,16 @@ export interface IConstructorArgumentsMapper {
|
|
|
15
16
|
* @param configRoot The root config resource that we are working in.
|
|
16
17
|
* @param constructorArgs Object mapping definition inside the constructor arguments.
|
|
17
18
|
* @param configElement Part of the config resource to look for parameter instantiations as predicates.
|
|
19
|
+
* @param genericsContext Context for generic types.
|
|
18
20
|
*/
|
|
19
|
-
applyConstructorArgumentsParameters: (configRoot: Resource, constructorArgs: Resource, configElement: Resource) => Resource
|
|
21
|
+
applyConstructorArgumentsParameters: (configRoot: Resource, constructorArgs: Resource, configElement: Resource, genericsContext: GenericsContext) => Resource;
|
|
20
22
|
/**
|
|
21
23
|
* Obtain the value(s) of the given parameter in the given config.
|
|
22
24
|
* @param configRoot The root config resource that we are working in.
|
|
23
25
|
* @param parameter The parameter resource to get the value for.
|
|
24
26
|
* @param configElement Part of the config resource to look for parameter instantiations as predicates.
|
|
25
27
|
* @param rawValue If the IRI represents a raw string value instead of a parameter reference.
|
|
28
|
+
* @param genericsContext Context for generic types.
|
|
26
29
|
*/
|
|
27
|
-
getParameterValue: (configRoot: Resource, parameter: Resource, configElement: Resource, rawValue: boolean) => Resource
|
|
30
|
+
getParameterValue: (configRoot: Resource, parameter: Resource, configElement: Resource, rawValue: boolean, genericsContext: GenericsContext) => Resource | undefined;
|
|
28
31
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Resource } from 'rdf-object';
|
|
2
|
+
import type { GenericsContext } from '../GenericsContext';
|
|
2
3
|
/**
|
|
3
4
|
* Transforms a parameter value based on some kind of parameter property.
|
|
4
5
|
*/
|
|
@@ -10,8 +11,9 @@ export interface IParameterPropertyHandler {
|
|
|
10
11
|
* @param configRoot The root config resource that we are working in.
|
|
11
12
|
* @param parameter The parameter resource to get the value for.
|
|
12
13
|
* @param configElement Part of the config resource to look for parameter instantiations as predicates.
|
|
14
|
+
* @param genericsContext Context for generic types.
|
|
13
15
|
*/
|
|
14
|
-
canHandle: (value: Resource
|
|
16
|
+
canHandle: (value: Resource | undefined, configRoot: Resource, parameter: Resource, configElement: Resource, genericsContext: GenericsContext) => boolean;
|
|
15
17
|
/**
|
|
16
18
|
* Transform the given parameter value.
|
|
17
19
|
* @param value The current parameter value obtained from the config.
|
|
@@ -19,6 +21,7 @@ export interface IParameterPropertyHandler {
|
|
|
19
21
|
* @param configRoot The root config resource that we are working in.
|
|
20
22
|
* @param parameter The parameter resource to get the value for.
|
|
21
23
|
* @param configElement Part of the config resource to look for parameter instantiations as predicates.
|
|
24
|
+
* @param genericsContext Context for generic types.
|
|
22
25
|
*/
|
|
23
|
-
handle: (value: Resource
|
|
26
|
+
handle: (value: Resource | undefined, configRoot: Resource, parameter: Resource, configElement: Resource, genericsContext: GenericsContext) => Resource | undefined;
|
|
24
27
|
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import type { Resource } from 'rdf-object';
|
|
1
|
+
import type { Resource, RdfObjectLoader } from 'rdf-object';
|
|
2
2
|
import type { IParameterPropertyHandler } from './IParameterPropertyHandler';
|
|
3
3
|
/**
|
|
4
4
|
* If no value has been set, its default value will be set.
|
|
5
5
|
*/
|
|
6
6
|
export declare class ParameterPropertyHandlerDefault implements IParameterPropertyHandler {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
private readonly objectLoader;
|
|
8
|
+
constructor(objectLoader: RdfObjectLoader);
|
|
9
|
+
canHandle(value: Resource | undefined, configRoot: Resource, parameter: Resource): boolean;
|
|
10
|
+
handle(value: Resource | undefined, configRoot: Resource, parameter: Resource, configElement: Resource): Resource | undefined;
|
|
11
|
+
protected handleValue(value: Resource, configElement: Resource): Resource;
|
|
9
12
|
}
|
|
@@ -1,15 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ParameterPropertyHandlerDefault = void 0;
|
|
4
|
+
const Iris_1 = require("../../rdf/Iris");
|
|
5
|
+
const ErrorResourcesContext_1 = require("../../util/ErrorResourcesContext");
|
|
4
6
|
/**
|
|
5
7
|
* If no value has been set, its default value will be set.
|
|
6
8
|
*/
|
|
7
9
|
class ParameterPropertyHandlerDefault {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
constructor(objectLoader) {
|
|
11
|
+
this.objectLoader = objectLoader;
|
|
12
|
+
}
|
|
13
|
+
canHandle(value, configRoot, parameter) {
|
|
14
|
+
return Boolean(!value && parameter.property.default);
|
|
10
15
|
}
|
|
11
16
|
handle(value, configRoot, parameter, configElement) {
|
|
12
|
-
|
|
17
|
+
if (parameter.properties.default.length > 1) {
|
|
18
|
+
throw new ErrorResourcesContext_1.ErrorResourcesContext(`Invalid default value for parameter "${parameter.value}": Only one value can be defined, or an RDF list must be provided`, { parameter });
|
|
19
|
+
}
|
|
20
|
+
return parameter.property.default.list ?
|
|
21
|
+
this.objectLoader.createCompactedResource({
|
|
22
|
+
list: parameter.property.default.list.map(subValue => this.handleValue(subValue, configElement)),
|
|
23
|
+
}) :
|
|
24
|
+
this.handleValue(parameter.property.default, configElement);
|
|
25
|
+
}
|
|
26
|
+
handleValue(value, configElement) {
|
|
27
|
+
if (value.type === 'NamedNode' && value.value === Iris_1.IRIS_RDF.subject) {
|
|
28
|
+
value = this.objectLoader.createCompactedResource(`"${configElement.value}"`);
|
|
29
|
+
}
|
|
13
30
|
return value;
|
|
14
31
|
}
|
|
15
32
|
}
|
|
@@ -6,6 +6,6 @@ import type { IParameterPropertyHandler } from './IParameterPropertyHandler';
|
|
|
6
6
|
export declare class ParameterPropertyHandlerDefaultScoped implements IParameterPropertyHandler {
|
|
7
7
|
private readonly objectLoader;
|
|
8
8
|
constructor(objectLoader: RdfObjectLoader);
|
|
9
|
-
canHandle(value: Resource
|
|
10
|
-
handle(value: Resource
|
|
9
|
+
canHandle(value: Resource | undefined, configRoot: Resource, parameter: Resource): boolean;
|
|
10
|
+
handle(value: Resource | undefined, configRoot: Resource, parameter: Resource, configElement: Resource): Resource | undefined;
|
|
11
11
|
}
|
|
@@ -9,11 +9,11 @@ class ParameterPropertyHandlerDefaultScoped {
|
|
|
9
9
|
constructor(objectLoader) {
|
|
10
10
|
this.objectLoader = objectLoader;
|
|
11
11
|
}
|
|
12
|
-
canHandle(value, configRoot, parameter
|
|
13
|
-
return Boolean(value
|
|
12
|
+
canHandle(value, configRoot, parameter) {
|
|
13
|
+
return Boolean(!value && parameter.property.defaultScoped);
|
|
14
14
|
}
|
|
15
15
|
handle(value, configRoot, parameter, configElement) {
|
|
16
|
-
|
|
16
|
+
let applyingValue;
|
|
17
17
|
for (const scoped of parameter.properties.defaultScoped) {
|
|
18
18
|
// Require defaultScope
|
|
19
19
|
if (!scoped.property.defaultScope) {
|
|
@@ -25,13 +25,24 @@ class ParameterPropertyHandlerDefaultScoped {
|
|
|
25
25
|
if (!scoped.property.defaultScopedValue) {
|
|
26
26
|
throw new ErrorResourcesContext_1.ErrorResourcesContext(`Invalid defaultScoped for parameter "${parameter.value}": Missing defaultScopedValue`, { parameter });
|
|
27
27
|
}
|
|
28
|
+
// Require RDF list or single value
|
|
29
|
+
if (scoped.properties.defaultScopedValue.length > 1) {
|
|
30
|
+
throw new ErrorResourcesContext_1.ErrorResourcesContext(`Invalid defaultScoped value for parameter "${parameter.value}": Only one defaultScopedValue can be defined, or an RDF list must be provided`, { parameter });
|
|
31
|
+
}
|
|
28
32
|
// Apply the scope if the config is of the required type (also considering sub-types)
|
|
29
33
|
if (configRoot.isA(scopeType.term)) {
|
|
30
|
-
|
|
34
|
+
applyingValue = !applyingValue ?
|
|
35
|
+
scoped.property.defaultScopedValue :
|
|
36
|
+
this.objectLoader.createCompactedResource({
|
|
37
|
+
list: [
|
|
38
|
+
...applyingValue.list || [applyingValue],
|
|
39
|
+
...scoped.property.defaultScopedValue.list || [scoped.property.defaultScopedValue],
|
|
40
|
+
],
|
|
41
|
+
});
|
|
31
42
|
}
|
|
32
43
|
}
|
|
33
44
|
}
|
|
34
|
-
return
|
|
45
|
+
return applyingValue;
|
|
35
46
|
}
|
|
36
47
|
}
|
|
37
48
|
exports.ParameterPropertyHandlerDefaultScoped = ParameterPropertyHandlerDefaultScoped;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import type { Resource } from 'rdf-object';
|
|
1
|
+
import type { Resource, RdfObjectLoader } from 'rdf-object';
|
|
2
2
|
import type { IParameterPropertyHandler } from './IParameterPropertyHandler';
|
|
3
3
|
/**
|
|
4
4
|
* Irrespective of any set values, prepend the parameter's fixed values.
|
|
5
5
|
*/
|
|
6
6
|
export declare class ParameterPropertyHandlerFixed implements IParameterPropertyHandler {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
private readonly objectLoader;
|
|
8
|
+
constructor(objectLoader: RdfObjectLoader);
|
|
9
|
+
canHandle(value: Resource | undefined, configRoot: Resource, parameter: Resource): boolean;
|
|
10
|
+
handle(value: Resource | undefined, configRoot: Resource, parameter: Resource, configElement: Resource): Resource | undefined;
|
|
9
11
|
}
|
|
@@ -1,15 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ParameterPropertyHandlerFixed = void 0;
|
|
4
|
+
const ErrorResourcesContext_1 = require("../../util/ErrorResourcesContext");
|
|
4
5
|
/**
|
|
5
6
|
* Irrespective of any set values, prepend the parameter's fixed values.
|
|
6
7
|
*/
|
|
7
8
|
class ParameterPropertyHandlerFixed {
|
|
8
|
-
|
|
9
|
+
constructor(objectLoader) {
|
|
10
|
+
this.objectLoader = objectLoader;
|
|
11
|
+
}
|
|
12
|
+
canHandle(value, configRoot, parameter) {
|
|
9
13
|
return Boolean(parameter.property.fixed);
|
|
10
14
|
}
|
|
11
15
|
handle(value, configRoot, parameter, configElement) {
|
|
12
|
-
|
|
16
|
+
if (parameter.properties.fixed.length > 1) {
|
|
17
|
+
throw new ErrorResourcesContext_1.ErrorResourcesContext(`Invalid fixed value for parameter "${parameter.value}": Only one value can be defined, or an RDF list must be provided`, { parameter });
|
|
18
|
+
}
|
|
19
|
+
if (value) {
|
|
20
|
+
const fixedValues = parameter.property.fixed.list || [parameter.property.fixed];
|
|
21
|
+
if (value.list) {
|
|
22
|
+
value.list.unshift(...fixedValues);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
value = this.objectLoader.createCompactedResource({
|
|
26
|
+
list: [
|
|
27
|
+
...fixedValues,
|
|
28
|
+
value,
|
|
29
|
+
],
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
value = parameter.property.fixed;
|
|
35
|
+
}
|
|
13
36
|
return value;
|
|
14
37
|
}
|
|
15
38
|
}
|