@shaclmate/compiler 4.0.18 → 4.0.20
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/dist/Compiler.d.ts +4 -1
- package/dist/Compiler.js +4 -1
- package/dist/ShapesGraphToAstTransformer.d.ts +4 -1
- package/dist/ShapesGraphToAstTransformer.js +9 -6
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +1 -1
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstListType.js +1 -1
- package/dist/ast/AbstractCollectionType.d.ts +10 -0
- package/dist/ast/AbstractCollectionType.js +6 -0
- package/dist/ast/AbstractCompoundType.d.ts +0 -1
- package/dist/ast/AbstractCompoundType.js +0 -3
- package/dist/ast/AbstractContainerType.d.ts +9 -1
- package/dist/ast/AbstractContainerType.js +5 -2
- package/dist/ast/AbstractLazyObjectType.d.ts +94 -1
- package/dist/ast/AbstractLazyObjectType.js +6 -2
- package/dist/ast/AbstractTermType.d.ts +11 -1
- package/dist/ast/AbstractTermType.js +7 -2
- package/dist/ast/AbstractType.d.ts +13 -1
- package/dist/ast/AbstractType.js +13 -0
- package/dist/ast/BlankNodeType.d.ts +1 -1
- package/dist/ast/DefaultValueType.d.ts +10 -0
- package/dist/ast/DefaultValueType.js +6 -0
- package/dist/ast/IdentifierType.d.ts +1 -1
- package/dist/ast/LiteralType.d.ts +17 -1
- package/dist/ast/LiteralType.js +10 -2
- package/dist/ast/ObjectCompoundType.js +1 -2
- package/dist/ast/ObjectType.d.ts +44 -1
- package/dist/ast/ObjectType.js +33 -10
- package/dist/ast/SetType.d.ts +11 -0
- package/dist/ast/SetType.js +6 -0
- package/dist/ast/UnionType.d.ts +12 -0
- package/dist/ast/UnionType.js +11 -0
- package/dist/generators/AstJsonGenerator.d.ts +6 -0
- package/dist/generators/AstJsonGenerator.js +11 -0
- package/dist/generators/Cx2Generator.d.ts +10 -0
- package/dist/generators/Cx2Generator.js +140 -0
- package/dist/generators/LabeledPropertyGraph.d.ts +42 -0
- package/dist/generators/LabeledPropertyGraph.js +2 -0
- package/dist/generators/index.d.ts +4 -2
- package/dist/generators/index.js +4 -2
- package/dist/generators/transformAstToLabeledPropertyGraph.d.ts +4 -0
- package/dist/generators/transformAstToLabeledPropertyGraph.js +75 -0
- package/dist/generators/ts/AbstractDateType.js +1 -1
- package/dist/generators/ts/AbstractIdentifierType.d.ts +2 -2
- package/dist/generators/ts/AbstractIdentifierType.js +2 -5
- package/dist/generators/ts/AbstractNamedUnionType.js +1 -1
- package/dist/generators/ts/AbstractNumericType.js +1 -1
- package/dist/generators/ts/AbstractTermType.js +2 -2
- package/dist/generators/ts/AbstractType.d.ts +17 -14
- package/dist/generators/ts/AbstractType.js +3 -1
- package/dist/generators/ts/BlankNodeType.d.ts +2 -2
- package/dist/generators/ts/BlankNodeType.js +1 -1
- package/dist/generators/ts/BooleanType.js +1 -1
- package/dist/generators/ts/DefaultValueType.js +1 -1
- package/dist/generators/ts/IdentifierType.d.ts +2 -2
- package/dist/generators/ts/IdentifierType.js +1 -1
- package/dist/generators/ts/IriType.d.ts +1 -1
- package/dist/generators/ts/IriType.js +8 -13
- package/dist/generators/ts/LazyObjectOptionType.d.ts +1 -0
- package/dist/generators/ts/LazyObjectOptionType.js +1 -1
- package/dist/generators/ts/LazyObjectType.js +1 -1
- package/dist/generators/ts/ListType.js +5 -5
- package/dist/generators/ts/NamedObjectUnionType.js +4 -1
- package/dist/generators/ts/SetType.js +1 -1
- package/dist/generators/ts/StringType.js +1 -1
- package/dist/generators/ts/TermType.js +3 -1
- package/dist/generators/ts/TsGenerator.d.ts +5 -0
- package/dist/generators/ts/TsGenerator.js +7 -1
- package/dist/generators/ts/TypeFactory.d.ts +5 -0
- package/dist/generators/ts/TypeFactory.js +35 -5
- package/dist/generators/ts/ZodGenerator.d.ts +4 -0
- package/dist/generators/ts/ZodGenerator.js +4 -1
- package/dist/generators/ts/_NamedObjectType/AbstractProperty.d.ts +4 -1
- package/dist/generators/ts/_NamedObjectType/AbstractProperty.js +3 -1
- package/dist/generators/ts/_NamedObjectType/IdentifierProperty.js +6 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlConstructTriplesFunctionDeclaration.js +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlWherePatternsFunctionDeclaration.js +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfTypeVariableStatement.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_propertiesFromRdfResourceFunctionDeclaration.js +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toRdfResourceFunctionOrMethodDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/ShaclProperty.d.ts +1 -0
- package/dist/generators/ts/_NamedObjectType/ShaclProperty.js +16 -16
- package/dist/generators/ts/_NamedObjectType/identifierTypeDeclarations.js +6 -2
- package/dist/generators/ts/_snippets/parseIri.d.ts +2 -0
- package/dist/generators/ts/_snippets/parseIri.js +12 -0
- package/dist/generators/ts/_snippets/snippets_listSparqlWherePatterns.js +7 -5
- package/dist/generators/ts/_snippets/snippets_parseBlankNode.d.ts +2 -0
- package/dist/generators/ts/_snippets/snippets_parseBlankNode.js +12 -0
- package/dist/generators/ts/_snippets/snippets_parseIdentifier.d.ts +2 -0
- package/dist/generators/ts/_snippets/snippets_parseIdentifier.js +6 -0
- package/dist/generators/ts/graphqlSchemaVariableStatement.js +3 -3
- package/dist/generators/ts/imports.d.ts +2 -0
- package/dist/generators/ts/imports.js +3 -1
- package/dist/generators/ts/rdfjsTermExpression.d.ts +4 -1
- package/dist/generators/ts/rdfjsTermExpression.js +2 -3
- package/dist/generators/ts/snippets.d.ts +3 -2
- package/dist/generators/ts/snippets.js +6 -4
- package/dist/generators/ts/synthesizeUberObjectUnionType.d.ts +2 -0
- package/dist/generators/ts/synthesizeUberObjectUnionType.js +4 -0
- package/dist/index.d.ts +1 -4
- package/dist/index.js +1 -3
- package/dist/input/ShapesGraph.d.ts +4 -1
- package/dist/input/ShapesGraph.js +3 -2
- package/dist/input/generated.d.ts +323 -323
- package/dist/input/generated.js +19 -20
- package/package.json +6 -9
- package/dist/generators/json/AstJsonGenerator.d.ts +0 -6
- package/dist/generators/json/AstJsonGenerator.js +0 -144
- package/dist/generators/json/index.d.ts +0 -2
- package/dist/generators/json/index.js +0 -2
- package/dist/generators/ts/_snippets/snippets_blankNodeFromString.d.ts +0 -2
- package/dist/generators/ts/_snippets/snippets_blankNodeFromString.js +0 -11
- package/dist/generators/ts/_snippets/snippets_identifierFromString.d.ts +0 -2
- package/dist/generators/ts/_snippets/snippets_identifierFromString.js +0 -8
- package/dist/generators/ts/index.d.ts +0 -2
- package/dist/generators/ts/index.js +0 -2
- package/dist/logger.d.ts +0 -2
- package/dist/logger.js +0 -8
package/dist/ast/SetType.d.ts
CHANGED
|
@@ -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: import("@rdfjs/types").BlankNode | import("@rdfjs/types").NamedNode<string>;
|
|
25
|
+
};
|
|
15
26
|
}
|
|
16
27
|
export declare namespace SetType {
|
|
17
28
|
type ItemType = AbstractCollectionType.ItemType;
|
package/dist/ast/SetType.js
CHANGED
|
@@ -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;
|
package/dist/ast/UnionType.d.ts
CHANGED
|
@@ -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: import("@rdfjs/types").BlankNode | import("@rdfjs/types").NamedNode<string>;
|
|
21
|
+
};
|
|
10
22
|
}
|
|
11
23
|
export declare namespace UnionType {
|
|
12
24
|
interface Member<TypeT extends UnionType.MemberType> extends AbstractCompoundType.Member<TypeT> {
|
package/dist/ast/UnionType.js
CHANGED
|
@@ -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,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
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
export * from "./AstJsonGenerator.js";
|
|
2
|
+
export * from "./Cx2Generator.js";
|
|
1
3
|
export * from "./Generator.js";
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
+
export { TsGenerator } from "./ts/TsGenerator.js";
|
|
5
|
+
export { ZodGenerator } from "./ts/ZodGenerator.js";
|
|
4
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/generators/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
export * from "./AstJsonGenerator.js";
|
|
2
|
+
export * from "./Cx2Generator.js";
|
|
1
3
|
export * from "./Generator.js";
|
|
2
|
-
export
|
|
3
|
-
export
|
|
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,75 @@
|
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
2
|
+
export function transformAstToLabeledPropertyGraph(ast) {
|
|
3
|
+
const nodes = [];
|
|
4
|
+
const relationships = [];
|
|
5
|
+
for (const namedObjectType of ast.namedObjectTypes) {
|
|
6
|
+
const id = typeId(namedObjectType);
|
|
7
|
+
const properties = {
|
|
8
|
+
name: { type: "string", value: typeName(namedObjectType) },
|
|
9
|
+
};
|
|
10
|
+
for (const namedObjectTypeProperty of namedObjectType.properties) {
|
|
11
|
+
let itemType;
|
|
12
|
+
switch (namedObjectTypeProperty.type.kind) {
|
|
13
|
+
case "DefaultValueType":
|
|
14
|
+
case "ListType":
|
|
15
|
+
case "OptionType":
|
|
16
|
+
case "SetType":
|
|
17
|
+
itemType = namedObjectTypeProperty.type.itemType;
|
|
18
|
+
break;
|
|
19
|
+
case "LazyObjectType":
|
|
20
|
+
itemType = namedObjectTypeProperty.type.resolveType;
|
|
21
|
+
break;
|
|
22
|
+
case "LazyObjectOptionType":
|
|
23
|
+
case "LazyObjectSetType":
|
|
24
|
+
itemType = namedObjectTypeProperty.type.resolveType.itemType;
|
|
25
|
+
break;
|
|
26
|
+
default:
|
|
27
|
+
itemType = namedObjectTypeProperty.type;
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
switch (itemType.kind) {
|
|
31
|
+
case "IntersectionType":
|
|
32
|
+
case "ObjectType":
|
|
33
|
+
case "UnionType":
|
|
34
|
+
if (itemType.name.isJust()) {
|
|
35
|
+
relationships.push({
|
|
36
|
+
id: namedObjectTypeProperty.shapeIdentifier.toString(),
|
|
37
|
+
label: Maybe.of(namedObjectTypeProperty.name),
|
|
38
|
+
properties: {},
|
|
39
|
+
sourceNodeId: id,
|
|
40
|
+
targetNodeId: typeId(itemType),
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
break;
|
|
44
|
+
default:
|
|
45
|
+
properties[namedObjectTypeProperty.name] = {
|
|
46
|
+
type: "string",
|
|
47
|
+
value: namedObjectTypeProperty.toString(),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
nodes.push({
|
|
52
|
+
id,
|
|
53
|
+
label: typeName(namedObjectType),
|
|
54
|
+
properties: properties,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
for (const namedUnionType of ast.namedUnionTypes) {
|
|
58
|
+
nodes.push({
|
|
59
|
+
id: typeId(namedUnionType),
|
|
60
|
+
label: typeName(namedUnionType),
|
|
61
|
+
properties: {},
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
nodes,
|
|
66
|
+
relationships,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function typeId(type) {
|
|
70
|
+
return type.name.orDefault(type.shapeIdentifier.toString());
|
|
71
|
+
}
|
|
72
|
+
function typeName(type) {
|
|
73
|
+
return type.name.orDefault(type.shapeIdentifier.toString());
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=transformAstToLabeledPropertyGraph.js.map
|
|
@@ -49,7 +49,7 @@ export class AbstractDateType extends AbstractPrimitiveType {
|
|
|
49
49
|
return new AbstractPrimitiveType.JsonType(code `string`);
|
|
50
50
|
}
|
|
51
51
|
toRdfResourceValuesExpression({ variables, }) {
|
|
52
|
-
return code `[${snippets.literalFactory}.date(${variables.value}, ${rdfjsTermExpression(this.datatype)})]`;
|
|
52
|
+
return code `[${snippets.literalFactory}.date(${variables.value}, ${rdfjsTermExpression(this.datatype, { logger: this.logger })})]`;
|
|
53
53
|
}
|
|
54
54
|
fromRdfExpressionChain({ variables, }) {
|
|
55
55
|
return {
|
|
@@ -3,11 +3,11 @@ import type { IdentifierNodeKind } from "@shaclmate/shacl-ast";
|
|
|
3
3
|
import { AbstractTermType } from "./AbstractTermType.js";
|
|
4
4
|
import { type Code } from "./ts-poet-wrapper.js";
|
|
5
5
|
export declare abstract class AbstractIdentifierType<IdentifierT extends BlankNode | NamedNode> extends AbstractTermType<NamedNode, IdentifierT> {
|
|
6
|
-
abstract readonly fromStringFunction: Code;
|
|
7
6
|
readonly graphqlType: import("./AbstractType.js").AbstractType.GraphqlType;
|
|
8
7
|
abstract readonly kind: "BlankNodeType" | "IdentifierType" | "IriType";
|
|
9
8
|
abstract readonly nodeKinds: ReadonlySet<IdentifierNodeKind>;
|
|
10
|
-
readonly
|
|
9
|
+
abstract readonly parseFunction: Code;
|
|
10
|
+
readonly stringifyFunction: Code;
|
|
11
11
|
get conversions(): readonly AbstractTermType.Conversion[];
|
|
12
12
|
graphqlResolveExpression({ variables: { value }, }: Parameters<AbstractTermType["graphqlResolveExpression"]>[0]): Code;
|
|
13
13
|
}
|
|
@@ -10,10 +10,7 @@ import { imports } from "./imports.js";
|
|
|
10
10
|
import { code } from "./ts-poet-wrapper.js";
|
|
11
11
|
export class AbstractIdentifierType extends AbstractTermType {
|
|
12
12
|
graphqlType = new AbstractTermType.GraphqlType(code `${imports.GraphQLString}`);
|
|
13
|
-
|
|
14
|
-
code `\
|
|
15
|
-
// biome-ignore lint/suspicious/noShadowRestrictedNames: allow toString
|
|
16
|
-
export const toString = ${imports.Resource}.Identifier.toString`;
|
|
13
|
+
stringifyFunction = code `${imports.NTriplesTerm}.stringify`;
|
|
17
14
|
get conversions() {
|
|
18
15
|
const conversions = super.conversions.concat();
|
|
19
16
|
if (this.nodeKinds.has("IRI")) {
|
|
@@ -29,7 +26,7 @@ export const toString = ${imports.Resource}.Identifier.toString`;
|
|
|
29
26
|
return conversions;
|
|
30
27
|
}
|
|
31
28
|
graphqlResolveExpression({ variables: { value }, }) {
|
|
32
|
-
return code `${imports.
|
|
29
|
+
return code `${imports.NTriplesTerm}.stringify(${value})`;
|
|
33
30
|
}
|
|
34
31
|
}
|
|
35
32
|
__decorate([
|
|
@@ -92,7 +92,7 @@ ${this.jsonTypeAliasDeclaration}
|
|
|
92
92
|
export namespace ${syntheticNamePrefix}Json {
|
|
93
93
|
${this.jsonSchemaFunctionDeclaration}
|
|
94
94
|
|
|
95
|
-
export function
|
|
95
|
+
export function parse(json: unknown): ${imports.Either}<Error, ${syntheticNamePrefix}Json> {
|
|
96
96
|
const jsonSafeParseResult = schema().safeParse(json);
|
|
97
97
|
if (!jsonSafeParseResult.success) { return ${imports.Left}(jsonSafeParseResult.error); }
|
|
98
98
|
return ${imports.Right}(jsonSafeParseResult.data);
|
|
@@ -51,7 +51,7 @@ export class AbstractNumericType extends AbstractPrimitiveType {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
toRdfResourceValuesExpression({ variables, }) {
|
|
54
|
-
return code `[${snippets.literalFactory}.${this.typeofs[0]}(${variables.value}, ${rdfjsTermExpression(this.datatype)})]`;
|
|
54
|
+
return code `[${snippets.literalFactory}.${this.typeofs[0]}(${variables.value}, ${rdfjsTermExpression(this.datatype, { logger: this.logger })})]`;
|
|
55
55
|
}
|
|
56
56
|
fromRdfExpressionChain({ variables, }) {
|
|
57
57
|
return {
|
|
@@ -136,7 +136,7 @@ export class AbstractTermType extends AbstractType {
|
|
|
136
136
|
fromRdfExpressionChain({ variables, }) {
|
|
137
137
|
let valueToExpression;
|
|
138
138
|
if (this.in_.length > 0) {
|
|
139
|
-
valueToExpression = code `value.toTerm([${joinCode(this.in_.map((in_) => rdfjsTermExpression(in_)), { on: ", " })}])`;
|
|
139
|
+
valueToExpression = code `value.toTerm([${joinCode(this.in_.map((in_) => rdfjsTermExpression(in_, { logger: this.logger })), { on: ", " })}])`;
|
|
140
140
|
}
|
|
141
141
|
else if (this.nodeKinds.size < 3) {
|
|
142
142
|
const eitherTypeParameters = code `<Error, ${this.name}>`;
|
|
@@ -152,7 +152,7 @@ export class AbstractTermType extends AbstractType {
|
|
|
152
152
|
return {
|
|
153
153
|
hasValues: this.hasValues.length > 0
|
|
154
154
|
? code `\
|
|
155
|
-
chain(values => ${imports.Either}.sequence([${joinCode(this.hasValues.map(rdfjsTermExpression), { on: ", " })}].map(hasValue => values.find(value => value.term.equals(hasValue)))).map(() => values))`
|
|
155
|
+
chain(values => ${imports.Either}.sequence([${joinCode(this.hasValues.map((hasValue) => rdfjsTermExpression(hasValue, { logger: this.logger })), { on: ", " })}].map(hasValue => values.find(value => value.term.equals(hasValue)))).map(() => values))`
|
|
156
156
|
: undefined,
|
|
157
157
|
valueTo: code `chain(values => values.chainMap(value => ${valueToExpression}))`,
|
|
158
158
|
};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { Maybe, NonEmptyList } from "purify-ts";
|
|
2
|
+
import type { Logger } from "ts-log";
|
|
2
3
|
import type { Typeof } from "./Typeof.js";
|
|
3
4
|
import { type Code } from "./ts-poet-wrapper.js";
|
|
4
5
|
/**
|
|
5
6
|
* Abstract base class all types.
|
|
6
7
|
*/
|
|
7
8
|
export declare abstract class AbstractType {
|
|
9
|
+
protected readonly logger: Logger;
|
|
8
10
|
/**
|
|
9
11
|
* Is the type abstract?
|
|
10
12
|
*/
|
|
@@ -104,9 +106,10 @@ export declare abstract class AbstractType {
|
|
|
104
106
|
* - variablePrefix: string prefix to use for new variables
|
|
105
107
|
*/
|
|
106
108
|
abstract readonly valueSparqlWherePatternsFunction: Code;
|
|
107
|
-
constructor({ comment, label, }: {
|
|
109
|
+
constructor({ comment, label, logger, }: {
|
|
108
110
|
comment: Maybe<string>;
|
|
109
111
|
label: Maybe<string>;
|
|
112
|
+
logger: Logger;
|
|
110
113
|
});
|
|
111
114
|
/**
|
|
112
115
|
* Helper to compose the result of schema along the type hierarchy.
|
|
@@ -177,6 +180,19 @@ export declare abstract class AbstractType {
|
|
|
177
180
|
value: Code;
|
|
178
181
|
};
|
|
179
182
|
}): readonly Code[];
|
|
183
|
+
/**
|
|
184
|
+
* Zod schema for the JSON type of this type.
|
|
185
|
+
*
|
|
186
|
+
* This method is called in two contexts:
|
|
187
|
+
* "property": from a ShaclProperty, while generating the z.object properties of an NamedObjectType
|
|
188
|
+
* "type": from another Type e.g., an OptionType or UnionType
|
|
189
|
+
*
|
|
190
|
+
* z.lazy() should only be returned for "property".
|
|
191
|
+
*/
|
|
192
|
+
abstract jsonSchema(parameters: {
|
|
193
|
+
includeDiscriminantProperty?: boolean;
|
|
194
|
+
context: "property" | "type";
|
|
195
|
+
}): Code;
|
|
180
196
|
/**
|
|
181
197
|
* JSON-compatible version of the type.
|
|
182
198
|
*/
|
|
@@ -191,19 +207,6 @@ export declare abstract class AbstractType {
|
|
|
191
207
|
scopePrefix: Code;
|
|
192
208
|
};
|
|
193
209
|
}): Maybe<Code>;
|
|
194
|
-
/**
|
|
195
|
-
* Zod schema for the JSON type of this type.
|
|
196
|
-
*
|
|
197
|
-
* This method is called in two contexts:
|
|
198
|
-
* "property": from a ShaclProperty, while generating the z.object properties of an NamedObjectType
|
|
199
|
-
* "type": from another Type e.g., an OptionType or UnionType
|
|
200
|
-
*
|
|
201
|
-
* z.lazy() should only be returned for "property".
|
|
202
|
-
*/
|
|
203
|
-
abstract jsonSchema(parameters: {
|
|
204
|
-
includeDiscriminantProperty?: boolean;
|
|
205
|
-
context: "property" | "type";
|
|
206
|
-
}): Code;
|
|
207
210
|
/**
|
|
208
211
|
* An expression that converts a value of this type to a JSON-LD compatible value. It can assume the presence
|
|
209
212
|
* of the correct JSON-LD context.
|
|
@@ -12,6 +12,7 @@ import { code, literalOf } from "./ts-poet-wrapper.js";
|
|
|
12
12
|
* Abstract base class all types.
|
|
13
13
|
*/
|
|
14
14
|
export class AbstractType {
|
|
15
|
+
logger;
|
|
15
16
|
/**
|
|
16
17
|
* Comment from rdfs:comment.
|
|
17
18
|
*/
|
|
@@ -20,9 +21,10 @@ export class AbstractType {
|
|
|
20
21
|
* Label from rdfs:label.
|
|
21
22
|
*/
|
|
22
23
|
label;
|
|
23
|
-
constructor({ comment, label, }) {
|
|
24
|
+
constructor({ comment, label, logger, }) {
|
|
24
25
|
this.comment = comment;
|
|
25
26
|
this.label = label;
|
|
27
|
+
this.logger = logger;
|
|
26
28
|
}
|
|
27
29
|
/**
|
|
28
30
|
* Helper to compose the result of schema along the type hierarchy.
|
|
@@ -5,13 +5,13 @@ import { type Code } from "./ts-poet-wrapper.js";
|
|
|
5
5
|
export declare class BlankNodeType extends AbstractIdentifierType<BlankNode> {
|
|
6
6
|
readonly filterFunction: Code;
|
|
7
7
|
readonly filterType: Code;
|
|
8
|
-
readonly
|
|
8
|
+
readonly parseFunction: Code;
|
|
9
9
|
readonly kind = "BlankNodeType";
|
|
10
10
|
readonly name: Code;
|
|
11
11
|
readonly nodeKinds: ReadonlySet<"BlankNode">;
|
|
12
12
|
readonly schemaType: Code;
|
|
13
13
|
readonly valueSparqlWherePatternsFunction: Code;
|
|
14
|
-
constructor(superParameters:
|
|
14
|
+
constructor(superParameters: Omit<ConstructorParameters<typeof AbstractIdentifierType<BlankNode>>[0], "hasValues" | "in_">);
|
|
15
15
|
fromJsonExpression({ variables, }: Parameters<AbstractTermType<NamedNode, BlankNode | NamedNode>["fromJsonExpression"]>[0]): Code;
|
|
16
16
|
jsonType(parameters?: Parameters<AbstractTermType["jsonType"]>[0]): AbstractTermType.JsonType;
|
|
17
17
|
jsonSchema({ includeDiscriminantProperty, }: Parameters<AbstractTermType<NamedNode, BlankNode | NamedNode>["jsonSchema"]>[0]): Code;
|
|
@@ -13,7 +13,7 @@ import { code } from "./ts-poet-wrapper.js";
|
|
|
13
13
|
export class BlankNodeType extends AbstractIdentifierType {
|
|
14
14
|
filterFunction = code `${snippets.filterBlankNode}`;
|
|
15
15
|
filterType = code `${snippets.BlankNodeFilter}`;
|
|
16
|
-
|
|
16
|
+
parseFunction = code `${snippets.parseBlankNode};`;
|
|
17
17
|
kind = "BlankNodeType";
|
|
18
18
|
name = code `${imports.BlankNode}`;
|
|
19
19
|
nodeKinds = nodeKinds;
|
|
@@ -38,7 +38,7 @@ export class BooleanType extends AbstractPrimitiveType {
|
|
|
38
38
|
return code `${imports.z}.boolean()`;
|
|
39
39
|
}
|
|
40
40
|
toRdfResourceValuesExpression({ variables, }) {
|
|
41
|
-
return code `[${snippets.literalFactory}.boolean(${variables.value}, ${rdfjsTermExpression(this.datatype)})]`;
|
|
41
|
+
return code `[${snippets.literalFactory}.boolean(${variables.value}, ${rdfjsTermExpression(this.datatype, { logger: this.logger })})]`;
|
|
42
42
|
}
|
|
43
43
|
fromRdfExpressionChain({ variables, }) {
|
|
44
44
|
return {
|
|
@@ -114,7 +114,7 @@ export class DefaultValueType extends AbstractContainerType {
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
get defaultValueTermExpression() {
|
|
117
|
-
return rdfjsTermExpression(this.defaultValue);
|
|
117
|
+
return rdfjsTermExpression(this.defaultValue, { logger: this.logger });
|
|
118
118
|
}
|
|
119
119
|
fromJsonExpression(parameters) {
|
|
120
120
|
return this.itemType.fromJsonExpression(parameters);
|
|
@@ -6,13 +6,13 @@ import { type Code } from "./ts-poet-wrapper.js";
|
|
|
6
6
|
export declare class IdentifierType extends AbstractIdentifierType<BlankNode | NamedNode> {
|
|
7
7
|
readonly filterFunction: Code;
|
|
8
8
|
readonly filterType: Code;
|
|
9
|
-
readonly
|
|
9
|
+
readonly parseFunction: Code;
|
|
10
10
|
readonly kind = "IdentifierType";
|
|
11
11
|
readonly name: Code;
|
|
12
12
|
readonly nodeKinds: ReadonlySet<IdentifierNodeKind>;
|
|
13
13
|
readonly schemaType: Code;
|
|
14
14
|
readonly valueSparqlWherePatternsFunction: Code;
|
|
15
|
-
constructor(parameters:
|
|
15
|
+
constructor(parameters: Omit<ConstructorParameters<typeof AbstractIdentifierType<BlankNode | NamedNode>>[0], "hasValues" | "in_">);
|
|
16
16
|
fromJsonExpression({ variables, }: Parameters<AbstractTermType<NamedNode, BlankNode | NamedNode>["fromJsonExpression"]>[0]): Code;
|
|
17
17
|
jsonType(parameters?: Parameters<AbstractTermType["jsonType"]>[0]): AbstractTermType.JsonType;
|
|
18
18
|
jsonSchema({ includeDiscriminantProperty, }: Parameters<AbstractTermType<NamedNode, BlankNode | NamedNode>["jsonSchema"]>[0]): Code;
|
|
@@ -14,7 +14,7 @@ import { arrayOf, code } from "./ts-poet-wrapper.js";
|
|
|
14
14
|
export class IdentifierType extends AbstractIdentifierType {
|
|
15
15
|
filterFunction = code `${snippets.filterIdentifier}`;
|
|
16
16
|
filterType = code `${snippets.IdentifierFilter}`;
|
|
17
|
-
|
|
17
|
+
parseFunction = code `${snippets.parseIdentifier};`;
|
|
18
18
|
kind = "IdentifierType";
|
|
19
19
|
name = code `(${imports.BlankNode} | ${imports.NamedNode})`;
|
|
20
20
|
nodeKinds = nodeKinds;
|
|
@@ -9,7 +9,7 @@ export declare class IriType extends AbstractIdentifierType<NamedNode> {
|
|
|
9
9
|
readonly nodeKinds: ReadonlySet<"IRI">;
|
|
10
10
|
readonly schemaType: Code;
|
|
11
11
|
readonly valueSparqlWherePatternsFunction: Code;
|
|
12
|
-
get
|
|
12
|
+
get parseFunction(): Code;
|
|
13
13
|
get name(): Code;
|
|
14
14
|
protected get schemaObject(): {
|
|
15
15
|
in: Code[] | undefined;
|