componentsjs 5.0.0-beta.1 → 5.0.0-beta.5

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.
@@ -1,19 +1,16 @@
1
- import type { Resource } from 'rdf-object';
1
+ import { Resource } from 'rdf-object';
2
+ import type { IParamValueConflict } from '../preprocess/parameterproperty/ParameterPropertyHandlerRange';
2
3
  /**
3
4
  * An error that can include a context containing resources for display.
4
5
  */
5
6
  export declare class ErrorResourcesContext extends Error {
6
- readonly context: Record<string, Resource | Resource[] | string>;
7
- constructor(message: string, context: Record<string, Resource | Resource[] | string>);
8
- static contextToString(context: Record<string, Resource | Resource[] | string>): string;
9
- /**
10
- * Convert the given resource to a compact string.
11
- * Mainly used for error reporting.
12
- *
13
- * Note that this will remove certain fields from the resource,
14
- * so only use this when throwing an error that will stop the process.
15
- *
16
- * @param resource A resource.
17
- */
18
- static resourceToString(resource: Resource): string;
7
+ readonly context: IErrorContext;
8
+ constructor(message: string, context: IErrorContext);
9
+ exportContext(): any;
10
+ static contextToJson(context: IErrorContext): any;
11
+ static resourceToJson(resource: Resource | undefined): any;
12
+ static conflictToJson(conflict: IParamValueConflict): any;
13
+ }
14
+ export interface IErrorContext {
15
+ [key: string]: Resource | Resource[] | string | undefined | IErrorContext | IParamValueConflict;
19
16
  }
@@ -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": "5.0.0-beta.1",
3
+ "version": "5.0.0-beta.5",
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.12.0",
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",