componentsjs 5.0.0-beta.0 → 5.0.0-beta.4

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 (34) hide show
  1. package/CHANGELOG.md +272 -0
  2. package/README.md +16 -0
  3. package/components/context.jsonld +62 -1
  4. package/lib/ComponentsManager.js +3 -5
  5. package/lib/construction/strategy/ConstructionStrategyCommonJs.d.ts +3 -1
  6. package/lib/construction/strategy/ConstructionStrategyCommonJs.js +8 -10
  7. package/lib/construction/strategy/ConstructionStrategyCommonJsString.js +6 -8
  8. package/lib/loading/ComponentRegistryFinalizer.js +7 -1
  9. package/lib/preprocess/ConfigPreprocessorComponent.d.ts +2 -0
  10. package/lib/preprocess/ConfigPreprocessorComponent.js +18 -1
  11. package/lib/preprocess/ConfigPreprocessorComponentMapped.d.ts +3 -2
  12. package/lib/preprocess/ConfigPreprocessorComponentMapped.js +9 -7
  13. package/lib/preprocess/GenericsContext.d.ts +74 -0
  14. package/lib/preprocess/GenericsContext.js +326 -0
  15. package/lib/preprocess/ParameterHandler.d.ts +6 -2
  16. package/lib/preprocess/ParameterHandler.js +7 -6
  17. package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerCollectEntries.d.ts +3 -2
  18. package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerCollectEntries.js +8 -6
  19. package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerElements.d.ts +2 -1
  20. package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerElements.js +2 -2
  21. package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerFields.d.ts +2 -1
  22. package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerFields.js +3 -2
  23. package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerKeyValue.d.ts +4 -3
  24. package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerKeyValue.js +7 -7
  25. package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerList.d.ts +2 -1
  26. package/lib/preprocess/constructorargumentsmapping/ConstructorArgumentsElementMappingHandlerList.js +5 -3
  27. package/lib/preprocess/constructorargumentsmapping/IConstructorArgumentsElementMappingHandler.d.ts +5 -2
  28. package/lib/preprocess/constructorargumentsmapping/IConstructorArgumentsMapper.d.ts +5 -2
  29. package/lib/preprocess/parameterproperty/IParameterPropertyHandler.d.ts +5 -2
  30. package/lib/preprocess/parameterproperty/ParameterPropertyHandlerRange.d.ts +34 -11
  31. package/lib/preprocess/parameterproperty/ParameterPropertyHandlerRange.js +393 -88
  32. package/lib/util/ErrorResourcesContext.d.ts +11 -14
  33. package/lib/util/ErrorResourcesContext.js +44 -22
  34. package/package.json +2 -2
@@ -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
  }
@@ -8,16 +8,18 @@ class ConstructorArgumentsElementMappingHandlerList {
8
8
  canHandle(configRoot, constructorArgs, configElement, mapper) {
9
9
  return Boolean(constructorArgs.list);
10
10
  }
11
- handle(configRoot, constructorArgs, configElement, mapper) {
11
+ handle(configRoot, constructorArgs, configElement, mapper, genericsContext) {
12
12
  // Recursively handle all field values.
13
13
  const ret = mapper.objectLoader.createCompactedResource({});
14
14
  ret.list = [];
15
15
  for (const argument of constructorArgs.list) {
16
16
  if (argument.property.fields || argument.property.elements) {
17
- ret.list.push(mapper.applyConstructorArgumentsParameters(configRoot, argument, configElement));
17
+ ret.list.push(mapper
18
+ .applyConstructorArgumentsParameters(configRoot, argument, configElement, genericsContext));
18
19
  }
19
20
  else {
20
- const value = mapper.getParameterValue(configRoot, argument, configElement, false);
21
+ const value = mapper
22
+ .getParameterValue(configRoot, argument, configElement, false, genericsContext);
21
23
  if (value) {
22
24
  ret.list.push(value);
23
25
  }
@@ -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 | undefined;
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 | undefined, configRoot: Resource, parameter: Resource, configElement: Resource) => boolean;
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 | undefined, configRoot: Resource, parameter: Resource, configElement: Resource) => Resource | undefined;
26
+ handle: (value: Resource | undefined, configRoot: Resource, parameter: Resource, configElement: Resource, genericsContext: GenericsContext) => Resource | undefined;
24
27
  }
@@ -1,4 +1,6 @@
1
1
  import type { RdfObjectLoader, Resource } from 'rdf-object';
2
+ import type { IErrorContext } from '../../util/ErrorResourcesContext';
3
+ import { GenericsContext } from '../GenericsContext';
2
4
  import type { IParameterPropertyHandler } from './IParameterPropertyHandler';
3
5
  /**
4
6
  * If a param range is defined, apply the type and validate the range.
@@ -7,7 +9,7 @@ export declare class ParameterPropertyHandlerRange implements IParameterProperty
7
9
  private readonly objectLoader;
8
10
  constructor(objectLoader: RdfObjectLoader);
9
11
  canHandle(value: Resource | undefined, configRoot: Resource, parameter: Resource): boolean;
10
- handle(value: Resource | undefined, configRoot: Resource, parameter: Resource, configElement: Resource): Resource | undefined;
12
+ handle(value: Resource | undefined, configRoot: Resource, parameter: Resource, configElement: Resource, genericsContext: GenericsContext): Resource | undefined;
11
13
  /**
12
14
  * Apply the given datatype to the given literal.
13
15
  * Checks if the datatype is correct and casts to the correct js type.
@@ -15,18 +17,39 @@ export declare class ParameterPropertyHandlerRange implements IParameterProperty
15
17
  * Will be ignored if the value is not a literal or the type is not recognized.
16
18
  * @param value The value.
17
19
  * @param param The parameter.
20
+ * @param genericsContext Context for generic types.
18
21
  */
19
- captureType(value: Resource | undefined, param: Resource): Resource | undefined;
22
+ captureType(value: Resource | undefined, param: Resource, genericsContext: GenericsContext): Resource | undefined;
20
23
  /**
21
- * Apply the given datatype to the given literal.
22
- * Checks if the datatype is correct and casts to the correct js type.
23
- * Will throw an error if the type has an invalid value.
24
- * Will be ignored if the value is not a literal or the type is not recognized.
24
+ * Check if the given value is of the given type.
25
+ *
26
+ * For valid literals, the `valueRaw` field will be set.
27
+ *
25
28
  * @param value The value.
26
- * @param param The parameter.
27
- * @param paramRange The parameter's range.
29
+ * @param type The parameter's range.
30
+ * @param genericsContext Context for generic types.
31
+ * @param errorContext The context for error reporting.
32
+ * @return IParamValueConflict A conflict value if there was an error, or undefined if there was no error
28
33
  */
29
- hasParamValueValidType(value: Resource | undefined, param: Resource, paramRange: Resource): boolean;
30
- protected throwIncorrectTypeError(value: Resource | undefined, parameter: Resource): never;
31
- rangeToDisplayString(paramRange: Resource | undefined): string;
34
+ hasValueType(value: Resource | undefined, type: Resource | undefined, errorContext: IErrorContext, genericsContext: GenericsContext): IParamValueConflict | undefined;
35
+ static throwIncorrectTypeError(value: Resource | undefined, parameter: Resource, genericsContext: GenericsContext, conflict: IParamValueConflict): never;
36
+ /**
37
+ * Check if the given value is of the given type.
38
+ * @param value A value.
39
+ * @param type A type.
40
+ * @param genericsContext The current generics context.
41
+ * @param genericTypeInstancesComponentScope
42
+ * @param genericTypeInstances
43
+ * @param errorContext
44
+ */
45
+ hasType(value: Resource, type: Resource, genericsContext: GenericsContext, genericTypeInstancesComponentScope: Resource | undefined, genericTypeInstances: Resource[], errorContext: IErrorContext): IParamValueConflict | undefined;
46
+ static rangeToDisplayString(paramRange: Resource | undefined, genericsContext: GenericsContext): string;
47
+ }
48
+ /**
49
+ * Represents a conflict between a value and a type.
50
+ */
51
+ export interface IParamValueConflict {
52
+ description: string;
53
+ context: IErrorContext;
54
+ causes?: IParamValueConflict[];
32
55
  }