componentsjs 5.3.2 → 5.4.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/README.md +7 -0
- package/lib/construction/ConfigConstructor.js +1 -1
- package/lib/construction/argument/ArgumentConstructorHandlerHash.js +4 -3
- package/lib/preprocess/ConfigPreprocessorOverride.d.ts +6 -10
- package/lib/preprocess/ConfigPreprocessorOverride.js +37 -25
- package/lib/preprocess/GenericsContext.js +1 -1
- package/lib/rdf/PrefetchedDocumentLoader.js +1 -1
- package/lib/rdf/RdfParser.d.ts +2 -1
- package/lib/util/LogLevel.d.ts +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -48,6 +48,8 @@ $ npm install -D componentsjs-generator
|
|
|
48
48
|
"name": "my-package",
|
|
49
49
|
"version": "2.3.4",
|
|
50
50
|
"lsd:module": true,
|
|
51
|
+
"main": "index.js",
|
|
52
|
+
"types": "index.d.ts",
|
|
51
53
|
...
|
|
52
54
|
"scripts": {
|
|
53
55
|
...
|
|
@@ -64,6 +66,9 @@ $ npm install -D componentsjs-generator
|
|
|
64
66
|
|
|
65
67
|
The `"scripts"` entry will make sure that all required component files will be generated when building your package.
|
|
66
68
|
|
|
69
|
+
The `componentsjs-generator` will look for your compiled TypeScript files (`.d.ts`) in the `lib/` directory.
|
|
70
|
+
If you use a different output directory for TypeScript (e.g. `dist/`), you must pass this to the generator using `-s` flag (e.g. `componentsjs-generator -s dist`).
|
|
71
|
+
|
|
67
72
|
#### 3. Create a configuration file to instantiate our class
|
|
68
73
|
|
|
69
74
|
Assuming a TypeScript class that is exported from the package:
|
|
@@ -107,6 +112,8 @@ const myInstance = await manager.instantiate('urn:my-package:myInstance');
|
|
|
107
112
|
|
|
108
113
|
`myInstance` is an instance of type `MyClass`, as defined in the config file.
|
|
109
114
|
|
|
115
|
+
After running `npm run build`, you can now execute your program.
|
|
116
|
+
|
|
110
117
|
## Quick Start (JavaScript)
|
|
111
118
|
|
|
112
119
|
#### 1. Install dependencies
|
|
@@ -88,7 +88,6 @@ class ConfigConstructor {
|
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
|
-
exports.ConfigConstructor = ConfigConstructor;
|
|
92
91
|
ConfigConstructor.ARGS_HANDLERS = [
|
|
93
92
|
new ArgumentConstructorHandlerUndefined_1.ArgumentConstructorHandlerUndefined(),
|
|
94
93
|
new ArgumentConstructorHandlerHash_1.ArgumentConstructorHandlerHash(),
|
|
@@ -98,4 +97,5 @@ ConfigConstructor.ARGS_HANDLERS = [
|
|
|
98
97
|
new ArgumentConstructorHandlerReference_1.ArgumentConstructorHandlerReference(),
|
|
99
98
|
new ArgumentConstructorHandlerPrimitive_1.ArgumentConstructorHandlerPrimitive(),
|
|
100
99
|
];
|
|
100
|
+
exports.ConfigConstructor = ConfigConstructor;
|
|
101
101
|
//# sourceMappingURL=ConfigConstructor.js.map
|
|
@@ -17,13 +17,14 @@ class ArgumentConstructorHandlerHash {
|
|
|
17
17
|
if (!entry.property.key) {
|
|
18
18
|
throw new ErrorResourcesContext_1.ErrorResourcesContext(`Missing key in fields entry`, { entry, argument });
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const key = await argsCreator.getArgumentValues(entry.properties.key, settings);
|
|
21
|
+
if (typeof key !== 'string') {
|
|
22
|
+
throw new ErrorResourcesContext_1.ErrorResourcesContext(`Illegal non-string key (${entry.property.key.value} as ${entry.property.key.type}) in fields entry`, { entry, argument });
|
|
22
23
|
}
|
|
23
24
|
// Recursively get value arg value
|
|
24
25
|
if (entry.property.value) {
|
|
25
26
|
const subValue = await argsCreator.getArgumentValues(entry.properties.value, settings);
|
|
26
|
-
return { key
|
|
27
|
+
return { key, value: subValue };
|
|
27
28
|
}
|
|
28
29
|
// Ignore cases where value may not be set, because params may be optional
|
|
29
30
|
}));
|
|
@@ -27,7 +27,7 @@ export declare class ConfigPreprocessorOverride implements IConfigPreprocessor<R
|
|
|
27
27
|
*/
|
|
28
28
|
transform(config: Resource, handleResponse: Record<string, Resource>): IConfigPreprocessorTransform;
|
|
29
29
|
/**
|
|
30
|
-
* Clear all cached overrides so they will be calculated again on the next call.
|
|
30
|
+
* Clear all cached overrides, so they will be calculated again on the next call.
|
|
31
31
|
*/
|
|
32
32
|
reset(): void;
|
|
33
33
|
/**
|
|
@@ -70,20 +70,16 @@ export declare class ConfigPreprocessorOverride implements IConfigPreprocessor<R
|
|
|
70
70
|
values: Record<string, Resource>;
|
|
71
71
|
};
|
|
72
72
|
/**
|
|
73
|
-
* Finds the final target and its type
|
|
73
|
+
* Finds the final target and validates its type value.
|
|
74
74
|
* @param chain - The chain to find the target of.
|
|
75
75
|
*/
|
|
76
|
-
protected getChainTarget(chain: Resource[]):
|
|
77
|
-
target: Resource;
|
|
78
|
-
type: Resource;
|
|
79
|
-
};
|
|
76
|
+
protected getChainTarget(chain: Resource[]): Resource;
|
|
80
77
|
/**
|
|
81
|
-
* Extracts all
|
|
78
|
+
* Extracts all parameters of an Override with their corresponding value.
|
|
82
79
|
* @param override - The Override to apply.
|
|
83
|
-
* @param target - The target resource to apply the Override to.
|
|
84
|
-
* @param parameters - The parameters that are relevant for the target.
|
|
80
|
+
* @param target - The target resource to apply the Override to. Only used for error messages.
|
|
85
81
|
*/
|
|
86
|
-
protected
|
|
82
|
+
protected extractOverrideParameters(override: Resource, target: Resource): Record<string, Resource>;
|
|
87
83
|
}
|
|
88
84
|
export interface IComponentConfigPreprocessorOverrideOptions {
|
|
89
85
|
objectLoader: RdfObjectLoader;
|
|
@@ -33,16 +33,23 @@ class ConfigPreprocessorOverride {
|
|
|
33
33
|
* @param handleResponse - Override values that were found for this resource.
|
|
34
34
|
*/
|
|
35
35
|
transform(config, handleResponse) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
var _a;
|
|
37
|
+
// We know this has exactly 1 result due to the canHandle call
|
|
38
|
+
const configType = (0, ResourceUtil_1.uniqueTypes)(config, this.componentResources)[0];
|
|
39
|
+
const overrideType = (_a = handleResponse[Iris_1.IRIS_RDF.type]) === null || _a === void 0 ? void 0 : _a.value;
|
|
40
|
+
// In case the type changes we have to delete all the original properties as those correspond to the old type
|
|
41
|
+
if (overrideType && configType.value !== overrideType) {
|
|
42
|
+
for (const id of Object.keys(config.properties)) {
|
|
43
|
+
delete config.properties[id];
|
|
40
44
|
}
|
|
41
45
|
}
|
|
46
|
+
for (const property of Object.keys(handleResponse)) {
|
|
47
|
+
config.properties[property] = [handleResponse[property]];
|
|
48
|
+
}
|
|
42
49
|
return { rawConfig: config, finishTransformation: false };
|
|
43
50
|
}
|
|
44
51
|
/**
|
|
45
|
-
* Clear all cached overrides so they will be calculated again on the next call.
|
|
52
|
+
* Clear all cached overrides, so they will be calculated again on the next call.
|
|
46
53
|
*/
|
|
47
54
|
reset() {
|
|
48
55
|
this.overrides = undefined;
|
|
@@ -147,19 +154,28 @@ class ConfigPreprocessorOverride {
|
|
|
147
154
|
* @param chain - The chain of Overrides, with a normal resource as the last entry in the array.
|
|
148
155
|
*/
|
|
149
156
|
chainToOverrideObject(chain) {
|
|
150
|
-
|
|
157
|
+
var _a, _b;
|
|
158
|
+
const target = this.getChainTarget(chain);
|
|
151
159
|
// Apply all overrides sequentially, starting from the one closest to the target.
|
|
152
160
|
// This ensures the most recent override has priority.
|
|
153
|
-
|
|
154
|
-
const mergedOverride = {};
|
|
161
|
+
let mergedOverride = {};
|
|
155
162
|
for (let i = chain.length - 2; i >= 0; --i) {
|
|
156
|
-
const
|
|
157
|
-
|
|
163
|
+
const validatedObject = this.extractOverrideParameters(chain[i], target);
|
|
164
|
+
// In case an Override has a different type, the properties of the target don't matter any more,
|
|
165
|
+
// as the object is being replaced completely.
|
|
166
|
+
const mergedType = (_a = mergedOverride[Iris_1.IRIS_RDF.type]) === null || _a === void 0 ? void 0 : _a.value;
|
|
167
|
+
const overrideType = (_b = validatedObject[Iris_1.IRIS_RDF.type]) === null || _b === void 0 ? void 0 : _b.value;
|
|
168
|
+
if (overrideType && overrideType !== mergedType) {
|
|
169
|
+
mergedOverride = validatedObject;
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
Object.assign(mergedOverride, validatedObject);
|
|
173
|
+
}
|
|
158
174
|
}
|
|
159
175
|
return { target: target.value, values: mergedOverride };
|
|
160
176
|
}
|
|
161
177
|
/**
|
|
162
|
-
* Finds the final target and its type
|
|
178
|
+
* Finds the final target and validates its type value.
|
|
163
179
|
* @param chain - The chain to find the target of.
|
|
164
180
|
*/
|
|
165
181
|
getChainTarget(chain) {
|
|
@@ -177,15 +193,14 @@ class ConfigPreprocessorOverride {
|
|
|
177
193
|
override: chain[chain.length - 2],
|
|
178
194
|
});
|
|
179
195
|
}
|
|
180
|
-
return
|
|
196
|
+
return target;
|
|
181
197
|
}
|
|
182
198
|
/**
|
|
183
|
-
* Extracts all
|
|
199
|
+
* Extracts all parameters of an Override with their corresponding value.
|
|
184
200
|
* @param override - The Override to apply.
|
|
185
|
-
* @param target - The target resource to apply the Override to.
|
|
186
|
-
* @param parameters - The parameters that are relevant for the target.
|
|
201
|
+
* @param target - The target resource to apply the Override to. Only used for error messages.
|
|
187
202
|
*/
|
|
188
|
-
|
|
203
|
+
extractOverrideParameters(override, target) {
|
|
189
204
|
const overrideObjects = override.properties[Iris_1.IRIS_OO.overrideParameters];
|
|
190
205
|
if (!overrideObjects || overrideObjects.length === 0) {
|
|
191
206
|
this.logger.warn(`No overrideParameters found for ${override.value}.`);
|
|
@@ -198,22 +213,19 @@ class ConfigPreprocessorOverride {
|
|
|
198
213
|
}
|
|
199
214
|
const overrideObject = overrideObjects[0];
|
|
200
215
|
// Only keep the parameters that are known to the type of the target object
|
|
201
|
-
const
|
|
202
|
-
for (const parameter of
|
|
203
|
-
const overrideValues = overrideObject.properties[parameter
|
|
204
|
-
if (!overrideValues || overrideValues.length === 0) {
|
|
205
|
-
continue;
|
|
206
|
-
}
|
|
216
|
+
const validatedObject = {};
|
|
217
|
+
for (const parameter of Object.keys(overrideObject.properties)) {
|
|
218
|
+
const overrideValues = overrideObject.properties[parameter];
|
|
207
219
|
if (overrideValues.length > 1) {
|
|
208
|
-
throw new ErrorResourcesContext_1.ErrorResourcesContext(`Detected multiple values for override parameter ${parameter
|
|
220
|
+
throw new ErrorResourcesContext_1.ErrorResourcesContext(`Detected multiple values for override parameter ${parameter} in Override ${override.value}. RDF lists should be used for defining multiple values.`, {
|
|
209
221
|
arguments: overrideValues,
|
|
210
222
|
target,
|
|
211
223
|
override,
|
|
212
224
|
});
|
|
213
225
|
}
|
|
214
|
-
|
|
226
|
+
validatedObject[parameter] = overrideValues[0];
|
|
215
227
|
}
|
|
216
|
-
return
|
|
228
|
+
return validatedObject;
|
|
217
229
|
}
|
|
218
230
|
}
|
|
219
231
|
exports.ConfigPreprocessorOverride = ConfigPreprocessorOverride;
|
|
@@ -292,7 +292,6 @@ class GenericsContext {
|
|
|
292
292
|
}
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
|
-
exports.GenericsContext = GenericsContext;
|
|
296
295
|
GenericsContext.XSD_INHERITANCE_TABLE = {
|
|
297
296
|
'http://www.w3.org/2001/XMLSchema#number': new Set([
|
|
298
297
|
'http://www.w3.org/2001/XMLSchema#integer',
|
|
@@ -325,4 +324,5 @@ GenericsContext.XSD_INHERITANCE_TABLE = {
|
|
|
325
324
|
'http://www.w3.org/2001/XMLSchema#langString',
|
|
326
325
|
]),
|
|
327
326
|
};
|
|
327
|
+
exports.GenericsContext = GenericsContext;
|
|
328
328
|
//# sourceMappingURL=GenericsContext.js.map
|
|
@@ -31,7 +31,6 @@ class PrefetchedDocumentLoader extends jsonld_context_parser_1.FetchDocumentLoad
|
|
|
31
31
|
return super.load(url);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
exports.PrefetchedDocumentLoader = PrefetchedDocumentLoader;
|
|
35
34
|
PrefetchedDocumentLoader.CONTEXT_URL = 'https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^5.0.0/components/context.jsonld';
|
|
36
35
|
PrefetchedDocumentLoader.DEFAULT_CONTEXT = require('../../components/context.json');
|
|
37
36
|
PrefetchedDocumentLoader.DEFAULT_CONTEXTS = {
|
|
@@ -40,4 +39,5 @@ PrefetchedDocumentLoader.DEFAULT_CONTEXTS = {
|
|
|
40
39
|
'https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^4.0.0/components/context.jsonld': PrefetchedDocumentLoader.DEFAULT_CONTEXT,
|
|
41
40
|
'https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^3.0.0/components/context.jsonld': PrefetchedDocumentLoader.DEFAULT_CONTEXT,
|
|
42
41
|
};
|
|
42
|
+
exports.PrefetchedDocumentLoader = PrefetchedDocumentLoader;
|
|
43
43
|
//# sourceMappingURL=PrefetchedDocumentLoader.js.map
|
package/lib/rdf/RdfParser.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import type { Readable } from 'stream';
|
|
3
4
|
import type * as RDF from '@rdfjs/types';
|
|
4
5
|
import type { ParseOptions } from 'rdf-parse';
|
|
@@ -27,7 +28,7 @@ export declare class RdfParser {
|
|
|
27
28
|
*/
|
|
28
29
|
static addPathToError(error: Error, path: string): Error;
|
|
29
30
|
}
|
|
30
|
-
export
|
|
31
|
+
export type RdfParserOptions = ParseOptions & {
|
|
31
32
|
/**
|
|
32
33
|
* If imports in the RDF document should be ignored.
|
|
33
34
|
*/
|
package/lib/util/LogLevel.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "componentsjs",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.4.0",
|
|
4
4
|
"description": "A semantic dependency injection framework",
|
|
5
5
|
"lsd:contexts": {
|
|
6
6
|
"https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^5.0.0/components/context.jsonld": "components/context.jsonld"
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@rdfjs/types": "*",
|
|
41
41
|
"@types/minimist": "^1.2.0",
|
|
42
|
-
"@types/node": "^
|
|
42
|
+
"@types/node": "^18.0.0",
|
|
43
43
|
"@types/semver": "^7.3.4",
|
|
44
44
|
"jsonld-context-parser": "^2.1.1",
|
|
45
45
|
"minimist": "^1.2.0",
|
|
@@ -78,9 +78,9 @@
|
|
|
78
78
|
"streamify-string": "^1.0.1",
|
|
79
79
|
"ts-jest": "^27.0.1",
|
|
80
80
|
"ts-loader": "^9.4.1",
|
|
81
|
-
"typescript": "^
|
|
81
|
+
"typescript": "^5.0.0",
|
|
82
82
|
"webpack": "^5.75.0",
|
|
83
|
-
"webpack-cli": "^
|
|
83
|
+
"webpack-cli": "^5.0.0"
|
|
84
84
|
},
|
|
85
85
|
"files": [
|
|
86
86
|
"components",
|