@shaclmate/compiler 4.0.17 → 4.0.19

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 (43) hide show
  1. package/dist/ast/AbstractCollectionType.d.ts +10 -0
  2. package/dist/ast/AbstractCollectionType.js +6 -0
  3. package/dist/ast/AbstractCompoundType.d.ts +0 -1
  4. package/dist/ast/AbstractCompoundType.js +0 -3
  5. package/dist/ast/AbstractContainerType.d.ts +9 -1
  6. package/dist/ast/AbstractContainerType.js +5 -2
  7. package/dist/ast/AbstractLazyObjectType.d.ts +154 -1
  8. package/dist/ast/AbstractLazyObjectType.js +6 -2
  9. package/dist/ast/AbstractTermType.d.ts +41 -1
  10. package/dist/ast/AbstractTermType.js +8 -2
  11. package/dist/ast/AbstractType.d.ts +13 -1
  12. package/dist/ast/AbstractType.js +14 -0
  13. package/dist/ast/DefaultValueType.d.ts +25 -0
  14. package/dist/ast/DefaultValueType.js +7 -0
  15. package/dist/ast/LiteralType.d.ts +107 -1
  16. package/dist/ast/LiteralType.js +12 -2
  17. package/dist/ast/ObjectType.d.ts +74 -1
  18. package/dist/ast/ObjectType.js +30 -3
  19. package/dist/ast/SetType.d.ts +11 -0
  20. package/dist/ast/SetType.js +6 -0
  21. package/dist/ast/UnionType.d.ts +12 -0
  22. package/dist/ast/UnionType.js +11 -0
  23. package/dist/ast/termToJson.d.ts +18 -0
  24. package/dist/ast/termToJson.js +18 -0
  25. package/dist/generators/AstJsonGenerator.d.ts +6 -0
  26. package/dist/generators/AstJsonGenerator.js +11 -0
  27. package/dist/generators/Cx2Generator.d.ts +10 -0
  28. package/dist/generators/Cx2Generator.js +140 -0
  29. package/dist/generators/LabeledPropertyGraph.d.ts +42 -0
  30. package/dist/generators/LabeledPropertyGraph.js +2 -0
  31. package/dist/generators/index.d.ts +4 -2
  32. package/dist/generators/index.js +4 -2
  33. package/dist/generators/transformAstToLabeledPropertyGraph.d.ts +4 -0
  34. package/dist/generators/transformAstToLabeledPropertyGraph.js +76 -0
  35. package/dist/index.d.ts +1 -4
  36. package/dist/index.js +1 -3
  37. package/package.json +2 -4
  38. package/dist/generators/json/AstJsonGenerator.d.ts +0 -6
  39. package/dist/generators/json/AstJsonGenerator.js +0 -144
  40. package/dist/generators/json/index.d.ts +0 -2
  41. package/dist/generators/json/index.js +0 -2
  42. package/dist/generators/ts/index.d.ts +0 -2
  43. package/dist/generators/ts/index.js +0 -2
@@ -166,8 +166,20 @@ export class ObjectType extends AbstractType {
166
166
  return 0;
167
167
  });
168
168
  }
169
- toString() {
170
- return `${this.kind}(shapeIdentifier=${Resource.Identifier.toString(this.shapeIdentifier)})`;
169
+ toJSON() {
170
+ return {
171
+ ...super.toJSON(),
172
+ fromRdfType: this.fromRdfType.map(Resource.Identifier.toString).extract(),
173
+ identifierMintingStrategy: this.identifierMintingStrategy.extract(),
174
+ identifierType: this.identifierType.toJSON(),
175
+ parentObjectTypes: this.parentObjectTypes.length > 0
176
+ ? this.parentObjectTypes.map((parentObjectType) => parentObjectType.name.orDefault(Resource.Identifier.toString(parentObjectType.shapeIdentifier)))
177
+ : undefined,
178
+ synthetic: this.synthetic ? true : undefined,
179
+ toRdfTypes: this.toRdfTypes.length > 0
180
+ ? this.toRdfTypes.map(Resource.Identifier.toString)
181
+ : undefined,
182
+ };
171
183
  }
172
184
  }
173
185
  const nodeKinds = new Set(["BlankNode", "IRI"]);
@@ -350,8 +362,23 @@ const nodeKinds = new Set(["BlankNode", "IRI"]);
350
362
  }
351
363
  return helper([{ objectType: rootObjectType, property: rootProperty }]);
352
364
  }
365
+ toJSON() {
366
+ return {
367
+ comment: this.comment.extract(),
368
+ description: this.description.extract(),
369
+ label: this.label.extract(),
370
+ mutable: this.mutable ? true : undefined,
371
+ name: this.name,
372
+ order: this.order,
373
+ path: PropertyPath.toString(this.path),
374
+ recursive: this.recursive ? true : undefined,
375
+ shapeIdentifier: Resource.Identifier.toString(this.shapeIdentifier),
376
+ type: this.type.toJSON(),
377
+ visibility: this.visibility,
378
+ };
379
+ }
353
380
  toString() {
354
- return `${this.name}(path=${PropertyPath.toString(this.path)})`;
381
+ return JSON.stringify(this.toJSON());
355
382
  }
356
383
  }
357
384
  __decorate([
@@ -12,6 +12,17 @@ export declare class SetType<ItemTypeT extends SetType.ItemType = SetType.ItemTy
12
12
  minCount: number;
13
13
  } & Pick<ConstructorParameters<typeof AbstractCollectionType<ItemTypeT>>[0], "itemType" | "mutable">);
14
14
  equals(other: SetType<ItemTypeT>): boolean;
15
+ toJSON(): {
16
+ minCount: number;
17
+ mutable: boolean | undefined;
18
+ itemType: any;
19
+ comment: string | undefined;
20
+ kind: string;
21
+ label: string | undefined;
22
+ name: string | undefined;
23
+ recursive: boolean | undefined;
24
+ shapeIdentifier: string;
25
+ };
15
26
  }
16
27
  export declare namespace SetType {
17
28
  type ItemType = AbstractCollectionType.ItemType;
@@ -28,6 +28,12 @@ export class SetType extends AbstractCollectionType {
28
28
  }
29
29
  return true;
30
30
  }
31
+ toJSON() {
32
+ return {
33
+ ...super.toJSON(),
34
+ minCount: this.minCount,
35
+ };
36
+ }
31
37
  }
32
38
  (function (SetType) {
33
39
  SetType.isItemType = AbstractCollectionType.isItemType;
@@ -7,6 +7,18 @@ import type { ObjectUnionType } from "./ObjectUnionType.js";
7
7
  export declare class UnionType<MemberTypeT extends UnionType.MemberType = UnionType.MemberType> extends AbstractCompoundType<UnionType.Member<MemberTypeT>, MemberTypeT> {
8
8
  readonly kind = "UnionType";
9
9
  isObjectUnionType(): this is ObjectUnionType;
10
+ toJSON(): {
11
+ members: {
12
+ discriminantValue: string | number | undefined;
13
+ type: any;
14
+ }[] | undefined;
15
+ comment: string | undefined;
16
+ kind: string;
17
+ label: string | undefined;
18
+ name: string | undefined;
19
+ recursive: boolean | undefined;
20
+ shapeIdentifier: string;
21
+ };
10
22
  }
11
23
  export declare namespace UnionType {
12
24
  interface Member<TypeT extends UnionType.MemberType> extends AbstractCompoundType.Member<TypeT> {
@@ -9,6 +9,17 @@ export class UnionType extends AbstractCompoundType {
9
9
  this.members.every((member) => member.type.kind === "ObjectType" ||
10
10
  (member.type.kind === "UnionType" && member.type.isObjectUnionType())));
11
11
  }
12
+ toJSON() {
13
+ return {
14
+ ...super.toJSON(),
15
+ members: !this.recursive
16
+ ? this.members.map((member) => ({
17
+ discriminantValue: member.discriminantValue.extract(),
18
+ type: member.type.toJSON(),
19
+ }))
20
+ : undefined,
21
+ };
22
+ }
12
23
  }
13
24
  (function (UnionType) {
14
25
  UnionType.isMemberType = AbstractCompoundType.isMemberType;
@@ -0,0 +1,18 @@
1
+ import type { Term } from "@rdfjs/types";
2
+ export declare function termToJson(term: Term): {
3
+ termType: "BlankNode";
4
+ value: string;
5
+ datatype?: undefined;
6
+ language?: undefined;
7
+ } | {
8
+ datatype: string;
9
+ language: string;
10
+ termType: "Literal";
11
+ value: string;
12
+ } | {
13
+ termType: "NamedNode";
14
+ value: string;
15
+ datatype?: undefined;
16
+ language?: undefined;
17
+ };
18
+ //# sourceMappingURL=termToJson.d.ts.map
@@ -0,0 +1,18 @@
1
+ export function termToJson(term) {
2
+ switch (term.termType) {
3
+ case "BlankNode":
4
+ return { termType: term.termType, value: term.value };
5
+ case "Literal":
6
+ return {
7
+ datatype: term.datatype.value,
8
+ language: term.language,
9
+ termType: term.termType,
10
+ value: term.value,
11
+ };
12
+ case "NamedNode":
13
+ return { termType: term.termType, value: term.value };
14
+ default:
15
+ throw new Error(`unsupported term type: ${term.termType}`);
16
+ }
17
+ }
18
+ //# sourceMappingURL=termToJson.js.map
@@ -0,0 +1,6 @@
1
+ import type * as ast from "../ast/index.js";
2
+ import type { Generator } from "./Generator.js";
3
+ export declare class AstJsonGenerator implements Generator {
4
+ generate(ast: ast.Ast): string;
5
+ }
6
+ //# sourceMappingURL=AstJsonGenerator.d.ts.map
@@ -0,0 +1,11 @@
1
+ export class AstJsonGenerator {
2
+ generate(ast) {
3
+ return JSON.stringify({
4
+ objectTypes: ast.namedObjectTypes.map((objectType) => ({
5
+ ...objectType.toJSON(),
6
+ properties: objectType.properties.map((property) => property.toJSON()),
7
+ })),
8
+ }, undefined, 2);
9
+ }
10
+ }
11
+ //# sourceMappingURL=AstJsonGenerator.js.map
@@ -0,0 +1,10 @@
1
+ import type { Ast } from "../ast/Ast.js";
2
+ import type { Generator } from "./Generator.js";
3
+ export declare class Cx2Generator implements Generator {
4
+ private readonly visualProperties;
5
+ constructor(options?: {
6
+ visualProperties?: Record<string, unknown>;
7
+ });
8
+ generate(ast: Ast): string;
9
+ }
10
+ //# sourceMappingURL=Cx2Generator.d.ts.map
@@ -0,0 +1,140 @@
1
+ import { transformAstToLabeledPropertyGraph } from "./transformAstToLabeledPropertyGraph.js";
2
+ export class Cx2Generator {
3
+ visualProperties;
4
+ constructor(options) {
5
+ this.visualProperties = options?.visualProperties;
6
+ }
7
+ generate(ast) {
8
+ const labeledPropertyGraph = transformAstToLabeledPropertyGraph(ast);
9
+ const edgeAttributeDeclarations = {
10
+ interaction: { d: "string" },
11
+ };
12
+ const edgeIdMap = {};
13
+ const edges = [];
14
+ const nodeAttributeDeclarations = {
15
+ name: { d: "string" },
16
+ };
17
+ const nodeIdMap = {};
18
+ const nodes = [];
19
+ function attributeDeclaration(lpgPropertyValue) {
20
+ switch (lpgPropertyValue.type) {
21
+ case "boolean":
22
+ case "double":
23
+ case "integer":
24
+ case "long":
25
+ case "string":
26
+ return { d: lpgPropertyValue.type };
27
+ case "boolean[]":
28
+ case "double[]":
29
+ case "integer[]":
30
+ case "long[]":
31
+ case "string[]":
32
+ return {
33
+ d: `list_of_${lpgPropertyValue.type.substring(0, lpgPropertyValue.type.length - 2)}`,
34
+ };
35
+ }
36
+ }
37
+ for (const lpgNode of labeledPropertyGraph.nodes) {
38
+ let id = nodeIdMap[lpgNode.id];
39
+ if (id === undefined) {
40
+ id = Object.keys(nodeIdMap).length + 1;
41
+ nodeIdMap[lpgNode.id] = id;
42
+ }
43
+ const v = {
44
+ name: lpgNode.label,
45
+ };
46
+ for (const [lpgNodePropertyName, lpgNodePropertyValue] of Object.entries(lpgNode.properties)) {
47
+ if (lpgNodePropertyName === "name") {
48
+ continue;
49
+ }
50
+ if (!nodeAttributeDeclarations[lpgNodePropertyName]) {
51
+ nodeAttributeDeclarations[lpgNodePropertyName] =
52
+ attributeDeclaration(lpgNodePropertyValue);
53
+ }
54
+ v[lpgNodePropertyName] = lpgNodePropertyValue.value;
55
+ }
56
+ nodes.push({
57
+ id,
58
+ v,
59
+ });
60
+ }
61
+ for (const lpgRelationship of labeledPropertyGraph.relationships) {
62
+ let id = edgeIdMap[lpgRelationship.id];
63
+ if (id === undefined) {
64
+ id = Object.keys(edgeIdMap).length + 1;
65
+ edgeIdMap[lpgRelationship.id] = id;
66
+ }
67
+ edges.push({
68
+ id,
69
+ s: nodeIdMap[lpgRelationship.sourceNodeId],
70
+ t: nodeIdMap[lpgRelationship.targetNodeId],
71
+ v: lpgRelationship.label
72
+ .map((label) => ({ interaction: label }))
73
+ .orDefault({}),
74
+ });
75
+ }
76
+ let visualProperties = this.visualProperties ?? {};
77
+ visualProperties = {
78
+ ...visualProperties,
79
+ default: {
80
+ edge: {
81
+ ...visualProperties?.default?.edge,
82
+ EDGE_LABEL: "interaction",
83
+ },
84
+ },
85
+ edgeMapping: {
86
+ ...visualProperties?.edgeMapping,
87
+ EDGE_LABEL: {
88
+ type: "PASSTHROUGH",
89
+ definition: {
90
+ attribute: "interaction",
91
+ type: "string",
92
+ },
93
+ },
94
+ },
95
+ };
96
+ return JSON.stringify([
97
+ {
98
+ CXVersion: "2.0",
99
+ hasFragments: false,
100
+ },
101
+ {
102
+ metaData: [
103
+ {
104
+ elementCount: edges.length,
105
+ name: "edges",
106
+ },
107
+ {
108
+ elementCount: nodes.length,
109
+ name: "nodes",
110
+ },
111
+ ],
112
+ },
113
+ {
114
+ attributeDeclarations: [
115
+ {
116
+ edges: edgeAttributeDeclarations,
117
+ nodes: nodeAttributeDeclarations,
118
+ },
119
+ ],
120
+ },
121
+ {
122
+ nodes,
123
+ },
124
+ {
125
+ edges,
126
+ },
127
+ {
128
+ visualProperties: [visualProperties],
129
+ },
130
+ {
131
+ status: [
132
+ {
133
+ success: true,
134
+ },
135
+ ],
136
+ },
137
+ ], undefined, 2);
138
+ }
139
+ }
140
+ //# sourceMappingURL=Cx2Generator.js.map
@@ -0,0 +1,42 @@
1
+ import type { Maybe } from "purify-ts";
2
+ export interface LabeledPropertyGraph {
3
+ readonly nodes: readonly LabeledPropertyGraph.Node[];
4
+ readonly relationships: readonly LabeledPropertyGraph.Relationship[];
5
+ }
6
+ export declare namespace LabeledPropertyGraph {
7
+ export type Id = string;
8
+ export interface Node {
9
+ readonly id: Id;
10
+ readonly label: string;
11
+ readonly properties: Record<PropertyName, PropertyValue>;
12
+ }
13
+ export type PropertyName = string;
14
+ type PropertyTypeValueMap = {
15
+ boolean: boolean;
16
+ "boolean[]": readonly boolean[];
17
+ double: number;
18
+ "double[]": readonly number[];
19
+ integer: bigint;
20
+ "integer[]": readonly bigint[];
21
+ long: bigint;
22
+ "long[]": readonly bigint[];
23
+ string: string;
24
+ "string[]": readonly string[];
25
+ };
26
+ export type PropertyType = keyof PropertyTypeValueMap;
27
+ export type PropertyValue = {
28
+ [K in PropertyType]: {
29
+ type: K;
30
+ value: PropertyTypeValueMap[K];
31
+ };
32
+ }[PropertyType];
33
+ export interface Relationship {
34
+ readonly id: Id;
35
+ readonly label: Maybe<string>;
36
+ readonly properties: Record<PropertyName, PropertyValue>;
37
+ readonly sourceNodeId: Id;
38
+ readonly targetNodeId: Id;
39
+ }
40
+ export {};
41
+ }
42
+ //# sourceMappingURL=LabeledPropertyGraph.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=LabeledPropertyGraph.js.map
@@ -1,4 +1,6 @@
1
+ export * from "./AstJsonGenerator.js";
2
+ export * from "./Cx2Generator.js";
1
3
  export * from "./Generator.js";
2
- export * as json from "./json/index.js";
3
- export * as ts from "./ts/index.js";
4
+ export { TsGenerator } from "./ts/TsGenerator.js";
5
+ export { ZodGenerator } from "./ts/ZodGenerator.js";
4
6
  //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,6 @@
1
+ export * from "./AstJsonGenerator.js";
2
+ export * from "./Cx2Generator.js";
1
3
  export * from "./Generator.js";
2
- export * as json from "./json/index.js";
3
- export * as ts from "./ts/index.js";
4
+ export { TsGenerator } from "./ts/TsGenerator.js";
5
+ export { ZodGenerator } from "./ts/ZodGenerator.js";
4
6
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,4 @@
1
+ import type * as ast from "../ast/index.js";
2
+ import type { LabeledPropertyGraph } from "./LabeledPropertyGraph.js";
3
+ export declare function transformAstToLabeledPropertyGraph(ast: ast.Ast): LabeledPropertyGraph;
4
+ //# sourceMappingURL=transformAstToLabeledPropertyGraph.d.ts.map
@@ -0,0 +1,76 @@
1
+ import { Resource } from "@rdfx/resource";
2
+ import { Maybe } from "purify-ts";
3
+ export function transformAstToLabeledPropertyGraph(ast) {
4
+ const nodes = [];
5
+ const relationships = [];
6
+ for (const namedObjectType of ast.namedObjectTypes) {
7
+ const id = typeId(namedObjectType);
8
+ const properties = {
9
+ name: { type: "string", value: typeName(namedObjectType) },
10
+ };
11
+ for (const namedObjectTypeProperty of namedObjectType.properties) {
12
+ let itemType;
13
+ switch (namedObjectTypeProperty.type.kind) {
14
+ case "DefaultValueType":
15
+ case "ListType":
16
+ case "OptionType":
17
+ case "SetType":
18
+ itemType = namedObjectTypeProperty.type.itemType;
19
+ break;
20
+ case "LazyObjectType":
21
+ itemType = namedObjectTypeProperty.type.resolveType;
22
+ break;
23
+ case "LazyObjectOptionType":
24
+ case "LazyObjectSetType":
25
+ itemType = namedObjectTypeProperty.type.resolveType.itemType;
26
+ break;
27
+ default:
28
+ itemType = namedObjectTypeProperty.type;
29
+ break;
30
+ }
31
+ switch (itemType.kind) {
32
+ case "IntersectionType":
33
+ case "ObjectType":
34
+ case "UnionType":
35
+ if (itemType.name.isJust()) {
36
+ relationships.push({
37
+ id: Resource.Identifier.toString(namedObjectTypeProperty.shapeIdentifier),
38
+ label: Maybe.of(namedObjectTypeProperty.name),
39
+ properties: {},
40
+ sourceNodeId: id,
41
+ targetNodeId: typeId(itemType),
42
+ });
43
+ }
44
+ break;
45
+ default:
46
+ properties[namedObjectTypeProperty.name] = {
47
+ type: "string",
48
+ value: namedObjectTypeProperty.toString(),
49
+ };
50
+ }
51
+ }
52
+ nodes.push({
53
+ id,
54
+ label: typeName(namedObjectType),
55
+ properties: properties,
56
+ });
57
+ }
58
+ for (const namedUnionType of ast.namedUnionTypes) {
59
+ nodes.push({
60
+ id: typeId(namedUnionType),
61
+ label: typeName(namedUnionType),
62
+ properties: {},
63
+ });
64
+ }
65
+ return {
66
+ nodes,
67
+ relationships,
68
+ };
69
+ }
70
+ function typeId(type) {
71
+ return type.name.orDefault(Resource.Identifier.toString(type.shapeIdentifier));
72
+ }
73
+ function typeName(type) {
74
+ return type.name.orDefault(Resource.Identifier.toString(type.shapeIdentifier));
75
+ }
76
+ //# sourceMappingURL=transformAstToLabeledPropertyGraph.js.map
package/dist/index.d.ts CHANGED
@@ -1,9 +1,6 @@
1
1
  export * as ast from "./ast/index.js";
2
2
  export * from "./Compiler.js";
3
- export type { Generator } from "./generators/Generator.js";
4
- export { AstJsonGenerator } from "./generators/json/AstJsonGenerator.js";
5
- export { TsGenerator } from "./generators/ts/TsGenerator.js";
6
- export { ZodGenerator } from "./generators/ts/ZodGenerator.js";
3
+ export * from "./generators/index.js";
7
4
  export * from "./input/ShapesGraph.js";
8
5
  export * from "./ShapesGraphToAstTransformer.js";
9
6
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,8 +1,6 @@
1
1
  export * as ast from "./ast/index.js";
2
2
  export * from "./Compiler.js";
3
- export { AstJsonGenerator } from "./generators/json/AstJsonGenerator.js";
4
- export { TsGenerator } from "./generators/ts/TsGenerator.js";
5
- export { ZodGenerator } from "./generators/ts/ZodGenerator.js";
3
+ export * from "./generators/index.js";
6
4
  export * from "./input/ShapesGraph.js";
7
5
  export * from "./ShapesGraphToAstTransformer.js";
8
6
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "dependencies": {
3
- "@shaclmate/shacl-ast": "4.0.17",
3
+ "@shaclmate/shacl-ast": "4.0.19",
4
4
  "@rdfjs/data-model": "~2.1.1",
5
5
  "@rdfjs/dataset": "~2.0.2",
6
6
  "@rdfjs/prefix-map": "~0.1.2",
@@ -42,8 +42,6 @@
42
42
  "dist/enums/*.js",
43
43
  "dist/generators/*.d.ts",
44
44
  "dist/generators/*.js",
45
- "dist/generators/json/*.d.ts",
46
- "dist/generators/json/*.js",
47
45
  "dist/generators/ts/*.d.ts",
48
46
  "dist/generators/ts/*.js",
49
47
  "dist/generators/ts/_NamedObjectType/*.d.ts",
@@ -73,5 +71,5 @@
73
71
  },
74
72
  "type": "module",
75
73
  "types": "./dist/index.d.ts",
76
- "version": "4.0.17"
74
+ "version": "4.0.19"
77
75
  }
@@ -1,6 +0,0 @@
1
- import type * as ast from "../../ast/index.js";
2
- import type { Generator } from "../Generator.js";
3
- export declare class AstJsonGenerator implements Generator {
4
- generate(ast: ast.Ast): string;
5
- }
6
- //# sourceMappingURL=AstJsonGenerator.d.ts.map