componentsjs 5.3.2 → 5.4.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/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
@@ -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 in an override chain.
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 relevant parameters of an Override with their corresponding new value.
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 filterOverrideObject(override: Resource, target: Resource, parameters: Resource[]): Record<string, Resource>;
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
- for (const id of Object.keys(config.properties)) {
37
- const overrideValue = handleResponse[id];
38
- if (overrideValue) {
39
- config.properties[id] = [overrideValue];
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
- const { target, type } = this.getChainTarget(chain);
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
- const parameters = this.componentResources[type.value].properties.parameters;
154
- const mergedOverride = {};
161
+ let mergedOverride = {};
155
162
  for (let i = chain.length - 2; i >= 0; --i) {
156
- const filteredObject = this.filterOverrideObject(chain[i], target, parameters);
157
- Object.assign(mergedOverride, filteredObject);
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 in an override chain.
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 { target, type: types[0] };
196
+ return target;
181
197
  }
182
198
  /**
183
- * Extracts all relevant parameters of an Override with their corresponding new value.
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
- filterOverrideObject(override, target, parameters) {
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 filteredObject = {};
202
- for (const parameter of parameters) {
203
- const overrideValues = overrideObject.properties[parameter.value];
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.value} in Override ${override.value}. RDF lists should be used for defining multiple values.`, {
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
- filteredObject[parameter.value] = overrideValues[0];
226
+ validatedObject[parameter] = overrideValues[0];
215
227
  }
216
- return filteredObject;
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
@@ -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 declare type RdfParserOptions = ParseOptions & {
31
+ export type RdfParserOptions = ParseOptions & {
31
32
  /**
32
33
  * If imports in the RDF document should be ignored.
33
34
  */
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * Different log levels, from most important to least important.
3
3
  */
4
- export declare type LogLevel = 'error' | 'warn' | 'info' | 'verbose' | 'debug' | 'silly';
4
+ export type LogLevel = 'error' | 'warn' | 'info' | 'verbose' | 'debug' | 'silly';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "componentsjs",
3
- "version": "5.3.2",
3
+ "version": "5.4.1",
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": "^14.14.7",
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": "^4.3.5",
81
+ "typescript": "^5.0.0",
82
82
  "webpack": "^5.75.0",
83
- "webpack-cli": "^4.10.0"
83
+ "webpack-cli": "^5.0.0"
84
84
  },
85
85
  "files": [
86
86
  "components",