componentsjs 4.3.0 → 5.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/compile-config.js +1 -1
- package/components/context.jsonld +40 -2
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/lib/construction/ConfigConstructor.js +10 -6
- package/lib/construction/argument/ArgumentConstructorHandlerHash.js +3 -2
- package/lib/construction/argument/ArgumentConstructorHandlerList.d.ts +11 -0
- package/lib/construction/argument/ArgumentConstructorHandlerList.js +19 -0
- 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 +1 -1
- package/lib/preprocess/ConfigPreprocessorComponent.js +17 -12
- package/lib/preprocess/ConfigPreprocessorComponentMapped.d.ts +3 -3
- package/lib/preprocess/ConfigPreprocessorComponentMapped.js +8 -11
- package/lib/preprocess/ParameterHandler.d.ts +2 -2
- package/lib/preprocess/ParameterHandler.js +20 -9
- package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerCollectEntries.d.ts +1 -1
- package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerCollectEntries.js +20 -8
- package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerElements.d.ts +1 -1
- package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerElements.js +7 -4
- package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerFields.d.ts +1 -1
- package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerFields.js +14 -8
- package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerKeyValue.d.ts +3 -3
- package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerKeyValue.js +7 -7
- package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerList.d.ts +1 -1
- package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerList.js +6 -21
- package/lib/preprocess/constructorargumentsmapping/IConstructorArgumentsElementMappingHandler.d.ts +1 -1
- package/lib/preprocess/constructorargumentsmapping/IConstructorArgumentsMapper.d.ts +2 -2
- package/lib/preprocess/parameterproperty/IParameterPropertyHandler.d.ts +2 -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 +15 -4
- package/lib/preprocess/parameterproperty/ParameterPropertyHandlerRange.js +141 -25
- 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/lib/util/ErrorResourcesContext.d.ts +3 -3
- package/lib/util/ErrorResourcesContext.js +6 -1
- package/package.json +10 -10
- package/CHANGELOG.md +0 -176
- 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
package/bin/compile-config.js
CHANGED
|
@@ -30,7 +30,7 @@ if (args.e) {
|
|
|
30
30
|
exportVariableName = args.e;
|
|
31
31
|
}
|
|
32
32
|
const asFunction = !!args.f;
|
|
33
|
-
__1.compileConfig(mainModulePath, configPath, configResourceUri, exportVariableName, asFunction)
|
|
33
|
+
(0, __1.compileConfig)(mainModulePath, configPath, configResourceUri, exportVariableName, asFunction)
|
|
34
34
|
.then((output) => process.stdout.write(`${output}\n`))
|
|
35
35
|
.catch(error => {
|
|
36
36
|
process.stderr.write(`${error.stack}\n`);
|
|
@@ -61,6 +61,42 @@
|
|
|
61
61
|
"undefined": {
|
|
62
62
|
"@id": "oo:isUndefined"
|
|
63
63
|
},
|
|
64
|
+
"ParameterRange": {
|
|
65
|
+
"@id": "oo:ParameterRange"
|
|
66
|
+
},
|
|
67
|
+
"ParameterRangeUndefined": {
|
|
68
|
+
"@id": "oo:ParameterRangeUndefined"
|
|
69
|
+
},
|
|
70
|
+
"ParameterRangeArray": {
|
|
71
|
+
"@id": "oo:ParameterRangeArray"
|
|
72
|
+
},
|
|
73
|
+
"ParameterRangeLiteral": {
|
|
74
|
+
"@id": "oo:ParameterRangeLiteral"
|
|
75
|
+
},
|
|
76
|
+
"parameterRangeValue": {
|
|
77
|
+
"@id": "oo:parameterRangeValue",
|
|
78
|
+
"@type": "@id"
|
|
79
|
+
},
|
|
80
|
+
"parameterRangeValueLiteral": {
|
|
81
|
+
"@id": "oo:parameterRangeValue"
|
|
82
|
+
},
|
|
83
|
+
"ParameterRangeUnion": {
|
|
84
|
+
"@id": "oo:ParameterRangeUnion"
|
|
85
|
+
},
|
|
86
|
+
"ParameterRangeIntersection": {
|
|
87
|
+
"@id": "oo:ParameterRangeIntersection"
|
|
88
|
+
},
|
|
89
|
+
"parameterRangeElements": {
|
|
90
|
+
"@id": "oo:parameterRangeElements",
|
|
91
|
+
"@type": "@id"
|
|
92
|
+
},
|
|
93
|
+
"ParameterRangeCollectEntries": {
|
|
94
|
+
"@id": "oo:ParameterRangeCollectEntries"
|
|
95
|
+
},
|
|
96
|
+
"parameterRangeCollectEntriesParameters": {
|
|
97
|
+
"@id": "oo:parameterRangeCollectEntriesParameters",
|
|
98
|
+
"@type": "@id"
|
|
99
|
+
},
|
|
64
100
|
|
|
65
101
|
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
|
|
66
102
|
"comment": {
|
|
@@ -116,7 +152,8 @@
|
|
|
116
152
|
},
|
|
117
153
|
"fields": {
|
|
118
154
|
"@id": "om:field",
|
|
119
|
-
"@type": "om:ObjectMapEntry"
|
|
155
|
+
"@type": "om:ObjectMapEntry",
|
|
156
|
+
"@container": "@list"
|
|
120
157
|
},
|
|
121
158
|
"elements": {
|
|
122
159
|
"@id": "om:elements",
|
|
@@ -125,7 +162,8 @@
|
|
|
125
162
|
},
|
|
126
163
|
"collectEntries": {
|
|
127
164
|
"@id": "om:collectsEntriesFrom",
|
|
128
|
-
"@type": "@id"
|
|
165
|
+
"@type": "@id",
|
|
166
|
+
"@container": "@list"
|
|
129
167
|
},
|
|
130
168
|
"keyRaw": {
|
|
131
169
|
"@id": "om:fieldName"
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './lib/construction/argument/ArgumentConstructorHandlerArray';
|
|
2
2
|
export * from './lib/construction/argument/ArgumentConstructorHandlerHash';
|
|
3
|
+
export * from './lib/construction/argument/ArgumentConstructorHandlerList';
|
|
3
4
|
export * from './lib/construction/argument/ArgumentConstructorHandlerPrimitive';
|
|
4
5
|
export * from './lib/construction/argument/ArgumentConstructorHandlerReference';
|
|
5
6
|
export * from './lib/construction/argument/ArgumentConstructorHandlerUndefined';
|
package/index.js
CHANGED
|
@@ -12,6 +12,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
__exportStar(require("./lib/construction/argument/ArgumentConstructorHandlerArray"), exports);
|
|
14
14
|
__exportStar(require("./lib/construction/argument/ArgumentConstructorHandlerHash"), exports);
|
|
15
|
+
__exportStar(require("./lib/construction/argument/ArgumentConstructorHandlerList"), exports);
|
|
15
16
|
__exportStar(require("./lib/construction/argument/ArgumentConstructorHandlerPrimitive"), exports);
|
|
16
17
|
__exportStar(require("./lib/construction/argument/ArgumentConstructorHandlerReference"), exports);
|
|
17
18
|
__exportStar(require("./lib/construction/argument/ArgumentConstructorHandlerUndefined"), exports);
|
|
@@ -4,6 +4,7 @@ exports.ConfigConstructor = void 0;
|
|
|
4
4
|
const ErrorResourcesContext_1 = require("../util/ErrorResourcesContext");
|
|
5
5
|
const ArgumentConstructorHandlerArray_1 = require("./argument/ArgumentConstructorHandlerArray");
|
|
6
6
|
const ArgumentConstructorHandlerHash_1 = require("./argument/ArgumentConstructorHandlerHash");
|
|
7
|
+
const ArgumentConstructorHandlerList_1 = require("./argument/ArgumentConstructorHandlerList");
|
|
7
8
|
const ArgumentConstructorHandlerPrimitive_1 = require("./argument/ArgumentConstructorHandlerPrimitive");
|
|
8
9
|
const ArgumentConstructorHandlerReference_1 = require("./argument/ArgumentConstructorHandlerReference");
|
|
9
10
|
const ArgumentConstructorHandlerUndefined_1 = require("./argument/ArgumentConstructorHandlerUndefined");
|
|
@@ -30,13 +31,15 @@ class ConfigConstructor {
|
|
|
30
31
|
this.moduleState = options.moduleState;
|
|
31
32
|
}
|
|
32
33
|
async getArgumentValues(values, settings) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return this.getArgumentValue(values[0], settings);
|
|
34
|
+
if (values.length === 0) {
|
|
35
|
+
return this.constructionStrategy.createUndefined();
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
if (values.length > 1) {
|
|
38
|
+
throw new ErrorResourcesContext_1.ErrorResourcesContext(`Detected multiple values for an argument. RDF lists should be used for defining multiple values.`, {
|
|
39
|
+
arguments: values,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return this.getArgumentValue(values[0], settings);
|
|
40
43
|
}
|
|
41
44
|
async getArgumentValue(value, settings) {
|
|
42
45
|
// Check if this args resource can be handled by one of the built-in handlers.
|
|
@@ -90,6 +93,7 @@ ConfigConstructor.ARGS_HANDLERS = [
|
|
|
90
93
|
new ArgumentConstructorHandlerUndefined_1.ArgumentConstructorHandlerUndefined(),
|
|
91
94
|
new ArgumentConstructorHandlerHash_1.ArgumentConstructorHandlerHash(),
|
|
92
95
|
new ArgumentConstructorHandlerArray_1.ArgumentConstructorHandlerArray(),
|
|
96
|
+
new ArgumentConstructorHandlerList_1.ArgumentConstructorHandlerList(),
|
|
93
97
|
new ArgumentConstructorHandlerValue_1.ArgumentConstructorHandlerValue(),
|
|
94
98
|
new ArgumentConstructorHandlerReference_1.ArgumentConstructorHandlerReference(),
|
|
95
99
|
new ArgumentConstructorHandlerPrimitive_1.ArgumentConstructorHandlerPrimitive(),
|
|
@@ -7,11 +7,12 @@ const ErrorResourcesContext_1 = require("../../util/ErrorResourcesContext");
|
|
|
7
7
|
*/
|
|
8
8
|
class ArgumentConstructorHandlerHash {
|
|
9
9
|
canHandle(value, settings, argsCreator) {
|
|
10
|
-
return Boolean(value.property.fields
|
|
10
|
+
return Boolean(value.property.fields);
|
|
11
11
|
}
|
|
12
12
|
async handle(argument, settings, argsCreator) {
|
|
13
|
+
const fields = argument.property.fields.list || [];
|
|
13
14
|
// Determine all key-value pairs
|
|
14
|
-
const entries = await Promise.all(
|
|
15
|
+
const entries = await Promise.all(fields.map(async (entry) => {
|
|
15
16
|
// Validate entry
|
|
16
17
|
if (!entry.property.key) {
|
|
17
18
|
throw new ErrorResourcesContext_1.ErrorResourcesContext(`Missing key in fields entry`, { entry, argument });
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Resource } from 'rdf-object';
|
|
2
|
+
import type { IConstructionSettings } from '../IConstructionSettings';
|
|
3
|
+
import type { IArgumentConstructorHandler } from './IArgumentConstructorHandler';
|
|
4
|
+
import type { IArgumentsConstructor } from './IArgumentsConstructor';
|
|
5
|
+
/**
|
|
6
|
+
* Handles arguments with RDF list values.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ArgumentConstructorHandlerList implements IArgumentConstructorHandler {
|
|
9
|
+
canHandle<Instance>(value: Resource, settings: IConstructionSettings, argsCreator: IArgumentsConstructor<Instance>): boolean;
|
|
10
|
+
handle<Instance>(argument: Resource, settings: IConstructionSettings, argsCreator: IArgumentsConstructor<Instance>): Promise<Instance>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArgumentConstructorHandlerList = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Handles arguments with RDF list values.
|
|
6
|
+
*/
|
|
7
|
+
class ArgumentConstructorHandlerList {
|
|
8
|
+
canHandle(value, settings, argsCreator) {
|
|
9
|
+
return Boolean(value.list);
|
|
10
|
+
}
|
|
11
|
+
async handle(argument, settings, argsCreator) {
|
|
12
|
+
// Recursively handle all sub-args in the list
|
|
13
|
+
const elements = await Promise.all(argument.list
|
|
14
|
+
.map((entry) => argsCreator.getArgumentValue(entry, settings)));
|
|
15
|
+
return argsCreator.constructionStrategy.createArray({ settings, elements });
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.ArgumentConstructorHandlerList = ArgumentConstructorHandlerList;
|
|
19
|
+
//# sourceMappingURL=ArgumentConstructorHandlerList.js.map
|
|
@@ -103,6 +103,9 @@ class ConstructionStrategyCommonJsString {
|
|
|
103
103
|
return `new function() { return Promise.resolve(${await options.supplier()}); }`;
|
|
104
104
|
}
|
|
105
105
|
createPrimitive(options) {
|
|
106
|
+
if (typeof options.value === 'object') {
|
|
107
|
+
return JSON.stringify(options.value);
|
|
108
|
+
}
|
|
106
109
|
return typeof options.value === 'string' ? `'${options.value}'` : `${options.value}`;
|
|
107
110
|
}
|
|
108
111
|
getVariableValue(options) {
|
|
@@ -111,9 +111,9 @@ export interface ICreationStrategyPrimitiveOptions<Instance> {
|
|
|
111
111
|
*/
|
|
112
112
|
settings: IConstructionSettings;
|
|
113
113
|
/**
|
|
114
|
-
* A string or
|
|
114
|
+
* A string, number or object value.
|
|
115
115
|
*/
|
|
116
|
-
value: string | number;
|
|
116
|
+
value: string | number | any;
|
|
117
117
|
}
|
|
118
118
|
export interface ICreationStrategyVariableOptions<Instance> {
|
|
119
119
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { Readable } from 'stream';
|
|
3
|
-
import type * as RDF from '
|
|
3
|
+
import type * as RDF from '@rdfjs/types';
|
|
4
4
|
import type { Resource, RdfObjectLoader } from 'rdf-object';
|
|
5
5
|
import type { Logger } from 'winston';
|
|
6
6
|
import type { IModuleState } from './ModuleStateBuilder';
|
|
@@ -55,7 +55,7 @@ class ComponentRegistry {
|
|
|
55
55
|
registerModuleResource(moduleResource) {
|
|
56
56
|
if (moduleResource.property.components) {
|
|
57
57
|
for (const component of moduleResource.properties.components) {
|
|
58
|
-
component.
|
|
58
|
+
component.properties.module.push(moduleResource);
|
|
59
59
|
this.registerComponent(component);
|
|
60
60
|
}
|
|
61
61
|
}
|
|
@@ -75,11 +75,26 @@ class ComponentRegistryFinalizer {
|
|
|
75
75
|
* @param extendingConstructorArgs The constructor argument resources to inherit from.
|
|
76
76
|
*/
|
|
77
77
|
inheritConstructorArgumentsEntry(constructorArg, extendingConstructorArgs) {
|
|
78
|
+
// Make sure that we have fields in list-form
|
|
79
|
+
if (constructorArg.property.fields && !constructorArg.property.fields.list) {
|
|
80
|
+
if (constructorArg.properties.fields.length > 1) {
|
|
81
|
+
throw new ErrorResourcesContext_1.ErrorResourcesContext(`Invalid fields: Only one value can be defined, or an RDF list must be provided`, {
|
|
82
|
+
constructorArg,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
constructorArg.property.fields = this.objectLoader.createCompactedResource({
|
|
86
|
+
list: constructorArg.properties.fields,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
78
89
|
for (const extendingConstructorArg of extendingConstructorArgs) {
|
|
79
90
|
if (extendingConstructorArg.property.fields) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
91
|
+
// Inherit fields
|
|
92
|
+
for (const field of extendingConstructorArg.property.fields.list || extendingConstructorArg.properties.fields) {
|
|
93
|
+
if (!constructorArg.property.fields) {
|
|
94
|
+
constructorArg.property.fields = this.objectLoader.createCompactedResource({ list: [] });
|
|
95
|
+
}
|
|
96
|
+
if (!constructorArg.property.fields.list.includes(field)) {
|
|
97
|
+
constructorArg.property.fields.list.push(field);
|
|
83
98
|
}
|
|
84
99
|
}
|
|
85
100
|
}
|
|
@@ -33,7 +33,7 @@ class ComponentsManagerBuilder {
|
|
|
33
33
|
Boolean(options.skipContextValidation);
|
|
34
34
|
}
|
|
35
35
|
static createLogger(logLevel = 'warn') {
|
|
36
|
-
return winston_1.createLogger({
|
|
36
|
+
return (0, winston_1.createLogger)({
|
|
37
37
|
level: logLevel,
|
|
38
38
|
format: winston_1.format.combine(winston_1.format.label({ label: 'Components.js' }), winston_1.format.colorize(), winston_1.format.timestamp(), winston_1.format.printf(({ level: levelInner, message, label: labelInner, timestamp }) => `${timestamp} [${labelInner}] ${levelInner}: ${message}`)),
|
|
39
39
|
transports: [new winston_1.transports.Console({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { Readable } from 'stream';
|
|
3
|
-
import type * as RDF from '
|
|
3
|
+
import type * as RDF from '@rdfjs/types';
|
|
4
4
|
import type { RdfObjectLoader } from 'rdf-object';
|
|
5
5
|
import type { Logger } from 'winston';
|
|
6
6
|
import type { IModuleState } from './ModuleStateBuilder';
|
|
@@ -20,7 +20,7 @@ export declare class ConfigPreprocessorComponent implements IConfigPreprocessor<
|
|
|
20
20
|
* @param config A config.
|
|
21
21
|
* @param handleResponse Return value of the {#canHandle}.
|
|
22
22
|
*/
|
|
23
|
-
transformConstructorArguments(config: Resource, handleResponse: IComponentConfigPreprocessorHandleResponse): Resource
|
|
23
|
+
transformConstructorArguments(config: Resource, handleResponse: IComponentConfigPreprocessorHandleResponse): Resource;
|
|
24
24
|
/**
|
|
25
25
|
* Let this config inherit parameter values from previously instantiated configs.
|
|
26
26
|
* This will check for inheritanceValues that are defined on the component,
|
|
@@ -82,7 +82,7 @@ class ConfigPreprocessorComponent {
|
|
|
82
82
|
if (requireElement) {
|
|
83
83
|
configRaw.property.requireElement = requireElement;
|
|
84
84
|
}
|
|
85
|
-
configRaw.
|
|
85
|
+
configRaw.property.arguments = this.transformConstructorArguments(config, handleResponse);
|
|
86
86
|
// Validate the input config
|
|
87
87
|
this.validateConfig(config, handleResponse);
|
|
88
88
|
return configRaw;
|
|
@@ -93,23 +93,28 @@ class ConfigPreprocessorComponent {
|
|
|
93
93
|
* @param handleResponse Return value of the {#canHandle}.
|
|
94
94
|
*/
|
|
95
95
|
transformConstructorArguments(config, handleResponse) {
|
|
96
|
-
|
|
97
|
-
const param0 = this.objectLoader.createCompactedResource({
|
|
98
|
-
// Hack to enforce ArgumentConstructorHandlerHash
|
|
99
|
-
hasFields: '"true"',
|
|
100
|
-
});
|
|
96
|
+
const entries = [];
|
|
101
97
|
for (const fieldData of handleResponse.component.properties.parameters) {
|
|
102
98
|
const field = this.objectLoader.createCompactedResource({});
|
|
103
99
|
field.property.key = this.objectLoader.createCompactedResource(`"${fieldData.term.value}"`);
|
|
104
|
-
|
|
105
|
-
|
|
100
|
+
const value = this.parameterHandler.applyParameterValues(handleResponse.component, fieldData, config);
|
|
101
|
+
if (value) {
|
|
102
|
+
field.property.value = value;
|
|
106
103
|
}
|
|
107
|
-
|
|
104
|
+
entries.push(field);
|
|
108
105
|
}
|
|
106
|
+
// Create a single-arg hash constructor, and add all params as key-value pairs
|
|
107
|
+
const param0 = this.objectLoader.createCompactedResource({
|
|
108
|
+
fields: {
|
|
109
|
+
list: entries,
|
|
110
|
+
},
|
|
111
|
+
});
|
|
109
112
|
// Create constructor arguments list
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
+
return this.objectLoader.createCompactedResource({
|
|
114
|
+
list: [
|
|
115
|
+
param0,
|
|
116
|
+
],
|
|
117
|
+
});
|
|
113
118
|
}
|
|
114
119
|
/**
|
|
115
120
|
* Let this config inherit parameter values from previously instantiated configs.
|
|
@@ -10,7 +10,7 @@ import type { IConstructorArgumentsMapper } from './constructorargumentsmapping/
|
|
|
10
10
|
export declare class ConfigPreprocessorComponentMapped extends ConfigPreprocessorComponent implements IConstructorArgumentsMapper {
|
|
11
11
|
private readonly mappingHandlers;
|
|
12
12
|
canHandle(config: Resource): IComponentConfigPreprocessorHandleResponse | undefined;
|
|
13
|
-
transformConstructorArguments(config: Resource, handleResponse: IComponentConfigPreprocessorHandleResponse): Resource
|
|
14
|
-
applyConstructorArgumentsParameters(configRoot: Resource, constructorArgs: Resource, configElement: Resource): Resource
|
|
15
|
-
getParameterValue(configRoot: Resource, parameter: Resource, configElement: Resource, rawValue: boolean): Resource
|
|
13
|
+
transformConstructorArguments(config: Resource, handleResponse: IComponentConfigPreprocessorHandleResponse): Resource;
|
|
14
|
+
applyConstructorArgumentsParameters(configRoot: Resource, constructorArgs: Resource, configElement: Resource): Resource;
|
|
15
|
+
getParameterValue(configRoot: Resource, parameter: Resource, configElement: Resource, rawValue: boolean): Resource | undefined;
|
|
16
16
|
}
|
|
@@ -43,16 +43,14 @@ class ConfigPreprocessorComponentMapped extends ConfigPreprocessorComponent_1.Co
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
// Fallback to original constructor args
|
|
46
|
-
return
|
|
46
|
+
return constructorArgs;
|
|
47
47
|
}
|
|
48
48
|
getParameterValue(configRoot, parameter, configElement, rawValue) {
|
|
49
|
-
var _a;
|
|
50
49
|
let valueOut;
|
|
51
50
|
if (parameter.type === 'NamedNode' && parameter.value === Iris_1.IRIS_RDF.subject) {
|
|
52
|
-
valueOut =
|
|
53
|
-
valueOut[0].property.unique = this.objectLoader.createCompactedResource('"true"');
|
|
51
|
+
valueOut = this.objectLoader.createCompactedResource(`"${configElement.value}"`);
|
|
54
52
|
}
|
|
55
|
-
else if (parameter.type === 'NamedNode') {
|
|
53
|
+
else if (parameter.type === 'NamedNode' && !parameter.property.fields) {
|
|
56
54
|
valueOut = this.parameterHandler.applyParameterValues(configRoot, parameter, configElement);
|
|
57
55
|
}
|
|
58
56
|
else {
|
|
@@ -60,12 +58,11 @@ class ConfigPreprocessorComponentMapped extends ConfigPreprocessorComponent_1.Co
|
|
|
60
58
|
}
|
|
61
59
|
// If the referenced IRI should become a plain string
|
|
62
60
|
if (rawValue) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
61
|
+
valueOut = (valueOut === null || valueOut === void 0 ? void 0 : valueOut.list) ?
|
|
62
|
+
this.objectLoader.createCompactedResource({
|
|
63
|
+
list: valueOut.list.map(valueOutSub => `"${valueOutSub.value}"`),
|
|
64
|
+
}) :
|
|
65
|
+
this.objectLoader.createCompactedResource(`"${valueOut ? valueOut.value : 'undefined'}"`);
|
|
69
66
|
}
|
|
70
67
|
return valueOut;
|
|
71
68
|
}
|
|
@@ -11,9 +11,9 @@ export declare class ParameterHandler {
|
|
|
11
11
|
* @param configRoot The root config resource that we are working in.
|
|
12
12
|
* @param parameter The parameter resource to get the value for.
|
|
13
13
|
* @param configElement Part of the config resource to look for parameter instantiations as predicates.
|
|
14
|
-
* @return The parameter value
|
|
14
|
+
* @return The parameter value
|
|
15
15
|
*/
|
|
16
|
-
applyParameterValues(configRoot: Resource, parameter: Resource, configElement: Resource): Resource
|
|
16
|
+
applyParameterValues(configRoot: Resource, parameter: Resource, configElement: Resource): Resource | undefined;
|
|
17
17
|
}
|
|
18
18
|
export interface IParameterHandlerOptions {
|
|
19
19
|
objectLoader: RdfObjectLoader;
|
|
@@ -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,11 +26,25 @@ 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
|
-
* @return The parameter value
|
|
29
|
+
* @return The parameter value
|
|
33
30
|
*/
|
|
34
31
|
applyParameterValues(configRoot, parameter, configElement) {
|
|
35
|
-
//
|
|
36
|
-
|
|
32
|
+
// Make sure that we always have a single value with list elements in it.
|
|
33
|
+
const values = configElement.properties[parameter.value];
|
|
34
|
+
let value;
|
|
35
|
+
if (values.length === 1) {
|
|
36
|
+
value = values[0];
|
|
37
|
+
}
|
|
38
|
+
else if (values.length > 0) {
|
|
39
|
+
if (values.some(subValue => !subValue.list)) {
|
|
40
|
+
throw new ErrorResourcesContext_1.ErrorResourcesContext(`Detected multiple values for parameter ${parameter.value}. RDF lists should be used for defining multiple values.`, {
|
|
41
|
+
arguments: values,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
value = this.objectLoader.createCompactedResource({
|
|
45
|
+
list: values.flatMap(subValue => subValue.list),
|
|
46
|
+
});
|
|
47
|
+
}
|
|
37
48
|
// Run the value through all applicable parameters property handlers.
|
|
38
49
|
for (const handler of this.parameterPropertyHandlers) {
|
|
39
50
|
if (handler.canHandle(value, configRoot, parameter, configElement)) {
|
|
@@ -9,6 +9,6 @@ export declare class ConstructorArgumentsElementMappingHandlerCollectEntries imp
|
|
|
9
9
|
private readonly parameterHandler;
|
|
10
10
|
constructor(parameterHandler: ParameterHandler);
|
|
11
11
|
canHandle(configRoot: Resource, constructorArgs: Resource, configElement: Resource, mapper: IConstructorArgumentsMapper): boolean;
|
|
12
|
-
handle(configRoot: Resource, constructorArgs: Resource, configElement: Resource, mapper: IConstructorArgumentsMapper): Resource
|
|
12
|
+
handle(configRoot: Resource, constructorArgs: Resource, configElement: Resource, mapper: IConstructorArgumentsMapper): Resource;
|
|
13
13
|
handleCollectEntry(entryResource: Resource, configRoot: Resource, constructorArgs: Resource, configElement: Resource, mapper: IConstructorArgumentsMapper): Resource;
|
|
14
14
|
}
|
|
@@ -15,22 +15,34 @@ class ConstructorArgumentsElementMappingHandlerCollectEntries {
|
|
|
15
15
|
constructorArgs.property.collectEntries);
|
|
16
16
|
}
|
|
17
17
|
handle(configRoot, constructorArgs, configElement, mapper) {
|
|
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);
|
|
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)),
|
|
45
|
+
});
|
|
34
46
|
}
|
|
35
47
|
handleCollectEntry(entryResource, configRoot, constructorArgs, configElement, mapper) {
|
|
36
48
|
// Determine the (optional) entry key
|
|
@@ -82,12 +94,13 @@ 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.applyConstructorArgumentsParameters(configRoot, entryResource, configElement)
|
|
97
|
+
value = mapper.applyConstructorArgumentsParameters(configRoot, entryResource, configElement);
|
|
86
98
|
}
|
|
87
99
|
else if (constructorArgs.property.value &&
|
|
88
100
|
(constructorArgs.property.value.property.fields || constructorArgs.property.value.property.elements)) {
|
|
89
101
|
// Nested mapping should reduce the parameter scope
|
|
90
|
-
|
|
102
|
+
// ! at the end of the line, because will always be truthy
|
|
103
|
+
value = mapper.getParameterValue(configRoot, constructorArgs.property.value, entryResource, false);
|
|
91
104
|
}
|
|
92
105
|
else if (entryResource.properties[constructorArgs.property.value.value].length !== 1) {
|
|
93
106
|
throw new ErrorResourcesContext_1.ErrorResourcesContext(`Detected more than one value value in collectEntries`, {
|
|
@@ -106,7 +119,6 @@ class ConstructorArgumentsElementMappingHandlerCollectEntries {
|
|
|
106
119
|
if (key) {
|
|
107
120
|
const ret = mapper.objectLoader.createCompactedResource({});
|
|
108
121
|
ret.property.key = key;
|
|
109
|
-
value.property.unique = mapper.objectLoader.createCompactedResource('"true"');
|
|
110
122
|
ret.property.value = value;
|
|
111
123
|
return ret;
|
|
112
124
|
}
|
|
@@ -6,5 +6,5 @@ import type { IConstructorArgumentsMapper } from './IConstructorArgumentsMapper'
|
|
|
6
6
|
*/
|
|
7
7
|
export declare class ConstructorArgumentsElementMappingHandlerElements implements IConstructorArgumentsElementMappingHandler {
|
|
8
8
|
canHandle(configRoot: Resource, constructorArgs: Resource, configElement: Resource, mapper: IConstructorArgumentsMapper): boolean;
|
|
9
|
-
handle(configRoot: Resource, constructorArgs: Resource, configElement: Resource, mapper: IConstructorArgumentsMapper): Resource
|
|
9
|
+
handle(configRoot: Resource, constructorArgs: Resource, configElement: Resource, mapper: IConstructorArgumentsMapper): Resource;
|
|
10
10
|
}
|
|
@@ -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));
|
|
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;
|
|
@@ -6,5 +6,5 @@ import type { IConstructorArgumentsMapper } from './IConstructorArgumentsMapper'
|
|
|
6
6
|
*/
|
|
7
7
|
export declare class ConstructorArgumentsElementMappingHandlerFields implements IConstructorArgumentsElementMappingHandler {
|
|
8
8
|
canHandle(configRoot: Resource, constructorArgs: Resource, configElement: Resource, mapper: IConstructorArgumentsMapper): boolean;
|
|
9
|
-
handle(configRoot: Resource, constructorArgs: Resource, configElement: Resource, mapper: IConstructorArgumentsMapper): Resource
|
|
9
|
+
handle(configRoot: Resource, constructorArgs: Resource, configElement: Resource, mapper: IConstructorArgumentsMapper): Resource;
|
|
10
10
|
}
|
|
@@ -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
|
*/
|
|
@@ -9,17 +10,22 @@ class ConstructorArgumentsElementMappingHandlerFields {
|
|
|
9
10
|
return Boolean(constructorArgs.property.fields);
|
|
10
11
|
}
|
|
11
12
|
handle(configRoot, constructorArgs, configElement, mapper) {
|
|
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.applyConstructorArgumentsParameters(configRoot, field, configElement);
|
|
24
|
+
for (const entry of mapped.list || [mapped]) {
|
|
25
|
+
entries.push(entry);
|
|
17
26
|
}
|
|
18
27
|
}
|
|
19
|
-
|
|
20
|
-
// Hack to enforce ArgumentConstructorHandlerHash
|
|
21
|
-
ret.property.hasFields = mapper.objectLoader.createCompactedResource('"true"');
|
|
22
|
-
return [ret];
|
|
28
|
+
return mapper.objectLoader.createCompactedResource({ fields: { list: entries } });
|
|
23
29
|
}
|
|
24
30
|
}
|
|
25
31
|
exports.ConstructorArgumentsElementMappingHandlerFields = ConstructorArgumentsElementMappingHandlerFields;
|
|
@@ -6,7 +6,7 @@ import type { IConstructorArgumentsMapper } from './IConstructorArgumentsMapper'
|
|
|
6
6
|
*/
|
|
7
7
|
export declare class ConstructorArgumentsElementMappingHandlerKeyValue implements IConstructorArgumentsElementMappingHandler {
|
|
8
8
|
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
|
|
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;
|
|
12
12
|
}
|