componentsjs 4.5.0 → 5.0.0-beta.3

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.
Files changed (51) hide show
  1. package/CHANGELOG.md +261 -0
  2. package/README.md +16 -0
  3. package/components/context.jsonld +87 -2
  4. package/lib/ComponentsManager.js +3 -5
  5. package/lib/construction/ConfigConstructor.js +7 -14
  6. package/lib/construction/argument/ArgumentConstructorHandlerHash.js +3 -2
  7. package/lib/construction/strategy/ConstructionStrategyCommonJsString.js +3 -0
  8. package/lib/construction/strategy/IConstructionStrategy.d.ts +2 -2
  9. package/lib/loading/ComponentRegistry.js +1 -1
  10. package/lib/loading/ComponentRegistryFinalizer.js +25 -4
  11. package/lib/preprocess/ConfigPreprocessorComponent.d.ts +3 -1
  12. package/lib/preprocess/ConfigPreprocessorComponent.js +34 -12
  13. package/lib/preprocess/ConfigPreprocessorComponentMapped.d.ts +4 -3
  14. package/lib/preprocess/ConfigPreprocessorComponentMapped.js +17 -18
  15. package/lib/preprocess/GenericsContext.d.ts +74 -0
  16. package/lib/preprocess/GenericsContext.js +326 -0
  17. package/lib/preprocess/ParameterHandler.d.ts +6 -2
  18. package/lib/preprocess/ParameterHandler.js +23 -21
  19. package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerCollectEntries.d.ts +3 -2
  20. package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerCollectEntries.js +24 -10
  21. package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerElements.d.ts +2 -1
  22. package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerElements.js +8 -5
  23. package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerFields.d.ts +2 -1
  24. package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerFields.js +16 -9
  25. package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerKeyValue.d.ts +4 -3
  26. package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerKeyValue.js +12 -12
  27. package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerList.d.ts +2 -1
  28. package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerList.js +9 -22
  29. package/lib/preprocess/constructorargumentsmapping/IConstructorArgumentsElementMappingHandler.d.ts +5 -2
  30. package/lib/preprocess/constructorargumentsmapping/IConstructorArgumentsMapper.d.ts +5 -2
  31. package/lib/preprocess/parameterproperty/IParameterPropertyHandler.d.ts +5 -2
  32. package/lib/preprocess/parameterproperty/ParameterPropertyHandlerDefault.d.ts +6 -3
  33. package/lib/preprocess/parameterproperty/ParameterPropertyHandlerDefault.js +20 -3
  34. package/lib/preprocess/parameterproperty/ParameterPropertyHandlerDefaultScoped.d.ts +2 -2
  35. package/lib/preprocess/parameterproperty/ParameterPropertyHandlerDefaultScoped.js +16 -5
  36. package/lib/preprocess/parameterproperty/ParameterPropertyHandlerFixed.d.ts +5 -3
  37. package/lib/preprocess/parameterproperty/ParameterPropertyHandlerFixed.js +25 -2
  38. package/lib/preprocess/parameterproperty/ParameterPropertyHandlerLazy.d.ts +2 -2
  39. package/lib/preprocess/parameterproperty/ParameterPropertyHandlerLazy.js +10 -3
  40. package/lib/preprocess/parameterproperty/ParameterPropertyHandlerRange.d.ts +38 -4
  41. package/lib/preprocess/parameterproperty/ParameterPropertyHandlerRange.js +412 -31
  42. package/lib/rdf/RdfParser.d.ts +1 -1
  43. package/lib/rdf/RdfParser.js +16 -4
  44. package/lib/rdf/RdfStreamIncluder.js +1 -1
  45. package/lib/util/ErrorResourcesContext.d.ts +11 -14
  46. package/lib/util/ErrorResourcesContext.js +44 -22
  47. package/package.json +2 -2
  48. package/lib/preprocess/parameterproperty/ParameterPropertyHandlerRequired.d.ts +0 -11
  49. package/lib/preprocess/parameterproperty/ParameterPropertyHandlerRequired.js +0 -23
  50. package/lib/preprocess/parameterproperty/ParameterPropertyHandlerUnique.d.ts +0 -12
  51. package/lib/preprocess/parameterproperty/ParameterPropertyHandlerUnique.js +0 -34
@@ -1,37 +1,59 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ErrorResourcesContext = void 0;
4
- const NodeUtil = require("util");
4
+ const rdf_object_1 = require("rdf-object");
5
5
  /**
6
6
  * An error that can include a context containing resources for display.
7
7
  */
8
8
  class ErrorResourcesContext extends Error {
9
9
  constructor(message, context) {
10
- super(`${message}\n${ErrorResourcesContext.contextToString(context)}`);
10
+ super(message);
11
11
  this.name = 'ErrorResourcesContext';
12
12
  this.context = context;
13
13
  }
14
- static contextToString(context) {
15
- return Object.entries(context)
16
- .map(([key, value]) => `${key}: ${typeof value === 'string' ?
17
- value :
18
- // eslint-disable-next-line @typescript-eslint/no-extra-parens
19
- (Array.isArray(value) ?
20
- value.map(valueSub => ErrorResourcesContext.resourceToString(valueSub)) :
21
- ErrorResourcesContext.resourceToString(value))}`)
22
- .join('\n');
14
+ exportContext() {
15
+ return ErrorResourcesContext.contextToJson(this.context);
23
16
  }
24
- /**
25
- * Convert the given resource to a compact string.
26
- * Mainly used for error reporting.
27
- *
28
- * Note that this will remove certain fields from the resource,
29
- * so only use this when throwing an error that will stop the process.
30
- *
31
- * @param resource A resource.
32
- */
33
- static resourceToString(resource) {
34
- return NodeUtil.inspect(Object.assign({ term: resource.term, properties: resource.properties }, resource.list ? { list: resource.list } : {}), { colors: true, depth: 2 });
17
+ static contextToJson(context) {
18
+ return Object.fromEntries(Object.entries(context)
19
+ .map(([key, value]) => {
20
+ let mapped;
21
+ if (typeof value === 'string') {
22
+ mapped = value;
23
+ }
24
+ else if (Array.isArray(value)) {
25
+ mapped = value.map(valueSub => ErrorResourcesContext.resourceToJson(valueSub));
26
+ }
27
+ else if (value instanceof rdf_object_1.Resource || value === undefined) {
28
+ mapped = ErrorResourcesContext.resourceToJson(value);
29
+ }
30
+ else if ('description' in value) {
31
+ mapped = ErrorResourcesContext.conflictToJson(value);
32
+ }
33
+ else {
34
+ mapped = ErrorResourcesContext.contextToJson(value);
35
+ }
36
+ return [key, mapped];
37
+ }));
38
+ }
39
+ static resourceToJson(resource) {
40
+ if (resource) {
41
+ return resource.toJSON(1);
42
+ }
43
+ }
44
+ static conflictToJson(conflict) {
45
+ const data = { description: conflict.description };
46
+ if (conflict.causes) {
47
+ data.causes = [];
48
+ // Only pick the first 2 conflicts for visualization
49
+ for (const subConflict of conflict.causes.slice(0, 1)) {
50
+ data.causes.push(ErrorResourcesContext.conflictToJson(subConflict));
51
+ }
52
+ }
53
+ else {
54
+ data.context = ErrorResourcesContext.contextToJson(conflict.context);
55
+ }
56
+ return data;
35
57
  }
36
58
  }
37
59
  exports.ErrorResourcesContext = ErrorResourcesContext;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "componentsjs",
3
- "version": "4.5.0",
3
+ "version": "5.0.0-beta.3",
4
4
  "description": "A semantic dependency injection framework",
5
5
  "lsd:contexts": {
6
6
  "https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^3.0.0/components/context.jsonld": "components/context.jsonld"
@@ -40,7 +40,7 @@
40
40
  "jsonld-context-parser": "^2.1.1",
41
41
  "minimist": "^1.2.0",
42
42
  "rdf-data-factory": "^1.1.0",
43
- "rdf-object": "^1.11.1",
43
+ "rdf-object": "^1.13.0",
44
44
  "rdf-parse": "^1.9.1",
45
45
  "rdf-quad": "^1.5.0",
46
46
  "rdf-terms": "^1.7.0",
@@ -1,11 +0,0 @@
1
- import type { RdfObjectLoader, Resource } from 'rdf-object';
2
- import type { IParameterPropertyHandler } from './IParameterPropertyHandler';
3
- /**
4
- * If no value has been set, but a value is required, throw.
5
- */
6
- export declare class ParameterPropertyHandlerRequired implements IParameterPropertyHandler {
7
- private readonly objectLoader;
8
- constructor(objectLoader: RdfObjectLoader);
9
- canHandle(value: Resource[], configRoot: Resource, parameter: Resource, configElement: Resource): boolean;
10
- handle(value: Resource[], configRoot: Resource, parameter: Resource, configElement: Resource): Resource[];
11
- }
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ParameterPropertyHandlerRequired = void 0;
4
- const ErrorResourcesContext_1 = require("../../util/ErrorResourcesContext");
5
- /**
6
- * If no value has been set, but a value is required, throw.
7
- */
8
- class ParameterPropertyHandlerRequired {
9
- constructor(objectLoader) {
10
- this.objectLoader = objectLoader;
11
- }
12
- canHandle(value, configRoot, parameter, configElement) {
13
- return Boolean(value.length === 0 && parameter.property.required);
14
- }
15
- handle(value, configRoot, parameter, configElement) {
16
- throw new ErrorResourcesContext_1.ErrorResourcesContext(`No value was set for required parameter "${parameter.value}"`, {
17
- config: configElement,
18
- parameter,
19
- });
20
- }
21
- }
22
- exports.ParameterPropertyHandlerRequired = ParameterPropertyHandlerRequired;
23
- //# sourceMappingURL=ParameterPropertyHandlerRequired.js.map
@@ -1,12 +0,0 @@
1
- import type { RdfObjectLoader } from 'rdf-object';
2
- import { Resource } from 'rdf-object';
3
- import type { IParameterPropertyHandler } from './IParameterPropertyHandler';
4
- /**
5
- * If the value is singular, and the value should be unique, transform to a single element.
6
- */
7
- export declare class ParameterPropertyHandlerUnique implements IParameterPropertyHandler {
8
- private readonly objectLoader;
9
- constructor(objectLoader: RdfObjectLoader);
10
- canHandle(value: Resource[], configRoot: Resource, parameter: Resource, configElement: Resource): boolean;
11
- handle(value: Resource[], configRoot: Resource, parameter: Resource, configElement: Resource): Resource[];
12
- }
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ParameterPropertyHandlerUnique = void 0;
4
- const rdf_object_1 = require("rdf-object");
5
- /**
6
- * If the value is singular, and the value should be unique, transform to a single element.
7
- */
8
- class ParameterPropertyHandlerUnique {
9
- constructor(objectLoader) {
10
- this.objectLoader = objectLoader;
11
- }
12
- canHandle(value, configRoot, parameter, configElement) {
13
- return Boolean(parameter.property.unique && parameter.property.unique.value === 'true' && value.length > 0);
14
- }
15
- handle(value, configRoot, parameter, configElement) {
16
- value = [value[0]];
17
- // !!!Hack incoming!!!
18
- // We make a manual resource to ensure uniqueness from other resources.
19
- // This is needed because literals may occur different times in param values.
20
- // This ensures that the unique label is only applied to the current occurrence, instead of all occurrences.
21
- // TODO: improve this
22
- const newValue = new rdf_object_1.Resource({ term: value[0].term, context: this.objectLoader.contextResolved });
23
- for (const key of Object.keys(value[0].properties)) {
24
- for (const subValue of value[0].properties[key]) {
25
- newValue.properties[key].push(subValue);
26
- }
27
- }
28
- value = [newValue];
29
- value[0].property.unique = parameter.property.unique;
30
- return value;
31
- }
32
- }
33
- exports.ParameterPropertyHandlerUnique = ParameterPropertyHandlerUnique;
34
- //# sourceMappingURL=ParameterPropertyHandlerUnique.js.map