@shaclmate/compiler 2.0.22 → 2.0.23
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/ShapesGraphToAstTransformer.d.ts +1 -0
- package/dist/ShapesGraphToAstTransformer.js +56 -12
- package/dist/_ShapesGraphToAstTransformer/flattenAstObjectCompositeTypeMemberTypes.d.ts +13 -0
- package/dist/_ShapesGraphToAstTransformer/flattenAstObjectCompositeTypeMemberTypes.js +51 -0
- package/dist/_ShapesGraphToAstTransformer/shapeAstName.js +53 -12
- package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.d.ts +5 -0
- package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.js +130 -54
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.d.ts +2 -3
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +122 -129
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.d.ts +2 -2
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.d.ts +2 -2
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +127 -5
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.d.ts +3 -3
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.d.ts +2 -3
- package/dist/ast/Ast.d.ts +0 -1
- package/dist/ast/Curie.d.ts +14 -0
- package/dist/ast/Curie.js +21 -0
- package/dist/ast/IdentifierType.d.ts +3 -2
- package/dist/ast/ListType.d.ts +2 -1
- package/dist/ast/LiteralType.d.ts +1 -1
- package/dist/ast/Name.d.ts +40 -5
- package/dist/ast/ObjectCompositeType.d.ts +11 -0
- package/dist/ast/ObjectType.d.ts +18 -13
- package/dist/ast/ObjectUnionType.d.ts +0 -11
- package/dist/ast/OptionType.d.ts +2 -2
- package/dist/ast/SetType.d.ts +2 -2
- package/dist/ast/TermType.d.ts +12 -4
- package/dist/ast/Type.d.ts +1 -1
- package/dist/enums/TsFeature.d.ts +1 -4
- package/dist/enums/TsFeature.js +1 -15
- package/dist/generators/json/AstJsonGenerator.js +19 -3
- package/dist/generators/ts/BooleanType.d.ts +3 -1
- package/dist/generators/ts/BooleanType.js +11 -2
- package/dist/generators/ts/DateTimeType.d.ts +8 -7
- package/dist/generators/ts/DateTimeType.js +31 -7
- package/dist/generators/ts/DateType.d.ts +5 -2
- package/dist/generators/ts/DateType.js +15 -1
- package/dist/generators/ts/DeclaredType.d.ts +2 -2
- package/dist/generators/ts/DeclaredType.js +2 -2
- package/dist/generators/ts/FloatType.d.ts +6 -0
- package/dist/generators/ts/FloatType.js +18 -0
- package/dist/generators/ts/IdentifierType.d.ts +12 -7
- package/dist/generators/ts/IdentifierType.js +94 -6
- package/dist/generators/ts/Import.d.ts +2 -0
- package/dist/generators/ts/Import.js +10 -0
- package/dist/generators/ts/IntType.d.ts +6 -0
- package/dist/generators/ts/IntType.js +18 -0
- package/dist/generators/ts/ListType.d.ts +15 -12
- package/dist/generators/ts/ListType.js +98 -57
- package/dist/generators/ts/LiteralType.d.ts +10 -9
- package/dist/generators/ts/LiteralType.js +13 -2
- package/dist/generators/ts/NumberType.d.ts +2 -1
- package/dist/generators/ts/NumberType.js +7 -2
- package/dist/generators/ts/ObjectType.d.ts +66 -43
- package/dist/generators/ts/ObjectType.js +144 -123
- package/dist/generators/ts/ObjectUnionType.d.ts +49 -8
- package/dist/generators/ts/ObjectUnionType.js +290 -97
- package/dist/generators/ts/OptionType.d.ts +14 -10
- package/dist/generators/ts/OptionType.js +60 -34
- package/dist/generators/ts/PrimitiveType.d.ts +4 -4
- package/dist/generators/ts/PrimitiveType.js +18 -3
- package/dist/generators/ts/SetType.d.ts +16 -12
- package/dist/generators/ts/SetType.js +69 -40
- package/dist/generators/ts/SnippetDeclarations.d.ts +13 -8
- package/dist/generators/ts/SnippetDeclarations.js +215 -101
- package/dist/generators/ts/StringType.d.ts +3 -1
- package/dist/generators/ts/StringType.js +14 -2
- package/dist/generators/ts/TermType.d.ts +22 -14
- package/dist/generators/ts/TermType.js +53 -25
- package/dist/generators/ts/TsGenerator.d.ts +2 -1
- package/dist/generators/ts/TsGenerator.js +23 -12
- package/dist/generators/ts/Type.d.ts +89 -31
- package/dist/generators/ts/Type.js +57 -54
- package/dist/generators/ts/TypeFactory.d.ts +4 -5
- package/dist/generators/ts/TypeFactory.js +290 -226
- package/dist/generators/ts/UnionType.d.ts +14 -10
- package/dist/generators/ts/UnionType.js +319 -142
- package/dist/generators/ts/_ObjectType/EagerShaclProperty.d.ts +12 -0
- package/dist/generators/ts/_ObjectType/EagerShaclProperty.js +30 -0
- package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.d.ts +13 -12
- package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.js +46 -47
- package/dist/generators/ts/_ObjectType/IdentifierProperty.d.ts +20 -13
- package/dist/generators/ts/_ObjectType/IdentifierProperty.js +152 -124
- package/dist/generators/ts/_ObjectType/LazyShaclProperty.d.ts +87 -0
- package/dist/generators/ts/_ObjectType/LazyShaclProperty.js +237 -0
- package/dist/generators/ts/_ObjectType/Property.d.ts +39 -44
- package/dist/generators/ts/_ObjectType/Property.js +1 -10
- package/dist/generators/ts/_ObjectType/ShaclProperty.d.ts +25 -30
- package/dist/generators/ts/_ObjectType/ShaclProperty.js +108 -85
- package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +21 -17
- package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +61 -53
- package/dist/generators/ts/_ObjectType/classDeclaration.js +6 -5
- package/dist/generators/ts/_ObjectType/createFunctionDeclaration.js +5 -4
- package/dist/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.js +5 -4
- package/dist/generators/ts/_ObjectType/fromRdfTypeVariableStatement.d.ts +1 -1
- package/dist/generators/ts/_ObjectType/fromRdfTypeVariableStatement.js +8 -5
- package/dist/generators/ts/_ObjectType/graphqlTypeVariableStatement.d.ts +5 -0
- package/dist/generators/ts/_ObjectType/graphqlTypeVariableStatement.js +37 -0
- package/dist/generators/ts/_ObjectType/hashFunctionOrMethodDeclarations.js +7 -8
- package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.d.ts +7 -0
- package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.js +54 -0
- package/dist/generators/ts/_ObjectType/index.d.ts +9 -7
- package/dist/generators/ts/_ObjectType/index.js +9 -7
- package/dist/generators/ts/_ObjectType/interfaceDeclaration.js +1 -1
- package/dist/generators/ts/_ObjectType/jsonFunctionDeclarations.d.ts +4 -0
- package/dist/generators/ts/_ObjectType/jsonFunctionDeclarations.js +189 -0
- package/dist/generators/ts/_ObjectType/jsonTypeAliasDeclaration.d.ts +5 -0
- package/dist/generators/ts/_ObjectType/jsonTypeAliasDeclaration.js +28 -0
- package/dist/generators/ts/_ObjectType/objectSetMethodNames.d.ts +9 -0
- package/dist/generators/ts/_ObjectType/objectSetMethodNames.js +18 -0
- package/dist/generators/ts/_ObjectType/propertiesVariableStatement.d.ts +5 -0
- package/dist/generators/ts/_ObjectType/propertiesVariableStatement.js +37 -0
- package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.d.ts +4 -0
- package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.js +152 -0
- package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.d.ts +1 -1
- package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.js +4 -3
- package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.d.ts +1 -1
- package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.js +3 -2
- package/dist/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +103 -35
- package/dist/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.js +6 -6
- package/dist/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.js +15 -13
- package/dist/generators/ts/graphqlSchemaVariableStatement.d.ts +9 -0
- package/dist/generators/ts/graphqlSchemaVariableStatement.js +86 -0
- package/dist/generators/ts/objectSetDeclarations.d.ts +8 -0
- package/dist/generators/ts/objectSetDeclarations.js +59 -0
- package/dist/generators/ts/objectSetInterfaceDeclaration.d.ts +8 -0
- package/dist/generators/ts/objectSetInterfaceDeclaration.js +46 -0
- package/dist/generators/ts/objectSetMethodSignatures.d.ts +11 -0
- package/dist/generators/ts/objectSetMethodSignatures.js +52 -0
- package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.d.ts +8 -0
- package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +393 -0
- package/dist/generators/ts/rdfjsTermExpression.d.ts +3 -0
- package/dist/generators/ts/rdfjsTermExpression.js +57 -0
- package/dist/generators/ts/sparqlObjectSetClassDeclaration.d.ts +8 -0
- package/dist/generators/ts/sparqlObjectSetClassDeclaration.js +415 -0
- package/dist/generators/ts/syntheticNamePrefix.d.ts +2 -0
- package/dist/generators/ts/syntheticNamePrefix.js +2 -0
- package/dist/generators/ts/tsName.js +27 -13
- package/dist/generators/ts/unsupportedObjectSetMethodDeclarations.d.ts +10 -0
- package/dist/generators/ts/unsupportedObjectSetMethodDeclarations.js +19 -0
- package/dist/input/NodeShape.d.ts +6 -8
- package/dist/input/NodeShape.js +20 -44
- package/dist/input/Ontology.d.ts +0 -3
- package/dist/input/Ontology.js +0 -9
- package/dist/input/PropertyPath.d.ts +6 -5
- package/dist/input/PropertyPath.js +14 -22
- package/dist/input/PropertyShape.d.ts +3 -1
- package/dist/input/PropertyShape.js +8 -2
- package/dist/input/ShapesGraph.js +4 -4
- package/dist/input/generated.d.ts +923 -105
- package/dist/input/generated.js +1865 -969
- package/dist/input/tsFeatures.d.ts +3 -2
- package/dist/input/tsFeatures.js +44 -27
- package/package.json +18 -16
- package/dist/generators/ts/_ObjectType/fromJsonFunctionDeclarations.d.ts +0 -4
- package/dist/generators/ts/_ObjectType/fromJsonFunctionDeclarations.js +0 -78
- package/dist/generators/ts/_ObjectType/fromRdfFunctionDeclarations.d.ts +0 -4
- package/dist/generators/ts/_ObjectType/fromRdfFunctionDeclarations.js +0 -91
- package/dist/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.js +0 -19
- package/dist/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.js +0 -31
- package/dist/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.js +0 -37
- package/dist/generators/ts/_ObjectType/rdfjsTermExpression.d.ts +0 -6
- package/dist/generators/ts/_ObjectType/rdfjsTermExpression.js +0 -17
- package/dist/generators/ts/_ObjectType/toJsonFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/toJsonFunctionDeclaration.js +0 -19
- package/dist/generators/ts/_ObjectType/toJsonReturnType.d.ts +0 -3
- package/dist/generators/ts/_ObjectType/toJsonReturnType.js +0 -17
- package/dist/generators/ts/_ObjectType/toRdfFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/toRdfFunctionDeclaration.js +0 -19
|
@@ -7,6 +7,7 @@ import type * as ast from "./ast/index.js";
|
|
|
7
7
|
import type * as input from "./input/index.js";
|
|
8
8
|
export declare class ShapesGraphToAstTransformer {
|
|
9
9
|
protected readonly astObjectTypePropertiesByIdentifier: TermMap<rdfjs.BlankNode | rdfjs.NamedNode, ast.ObjectType.Property>;
|
|
10
|
+
protected readonly iriLocalParts: Record<string, Record<string, number>>;
|
|
10
11
|
protected readonly iriPrefixMap: PrefixMap;
|
|
11
12
|
protected readonly nodeShapeAstTypesByIdentifier: TermMap<rdfjs.BlankNode | rdfjs.NamedNode, _ShapesGraphToAstTransformer.NodeShapeAstType>;
|
|
12
13
|
protected shapeAstName: typeof _ShapesGraphToAstTransformer.shapeAstName;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import TermMap from "@rdfjs/term-map";
|
|
2
2
|
import { dash } from "@tpluscode/rdf-ns-builders";
|
|
3
|
-
import { Either
|
|
3
|
+
import { Either } from "purify-ts";
|
|
4
4
|
import * as _ShapesGraphToAstTransformer from "./_ShapesGraphToAstTransformer/index.js";
|
|
5
5
|
export class ShapesGraphToAstTransformer {
|
|
6
6
|
// Members are protected so they're accessible to the bound functions
|
|
7
7
|
astObjectTypePropertiesByIdentifier = new TermMap();
|
|
8
|
+
iriLocalParts = {};
|
|
8
9
|
iriPrefixMap;
|
|
9
10
|
nodeShapeAstTypesByIdentifier = new TermMap();
|
|
10
11
|
shapeAstName = _ShapesGraphToAstTransformer.shapeAstName;
|
|
@@ -21,17 +22,60 @@ export class ShapesGraphToAstTransformer {
|
|
|
21
22
|
this.shapesGraph = shapesGraph;
|
|
22
23
|
}
|
|
23
24
|
transform() {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
25
|
+
const nodeShapeAstObjectIntersectionTypes = [];
|
|
26
|
+
const nodeShapeAstObjectTypes = [];
|
|
27
|
+
const syntheticAstObjectTypesByName = {};
|
|
28
|
+
const nodeShapeAstObjectUnionTypes = [];
|
|
29
|
+
for (const nodeShape of this.shapesGraph.nodeShapes) {
|
|
30
|
+
if (nodeShape.identifier.termType !== "NamedNode") {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (nodeShape.identifier.value.startsWith(dash[""].value)) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const nodeShapeAstTypeEither = this.transformNodeShapeToAstType(nodeShape);
|
|
37
|
+
if (nodeShapeAstTypeEither.isLeft()) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const nodeShapeAstType = nodeShapeAstTypeEither.unsafeCoerce();
|
|
41
|
+
switch (nodeShapeAstType.kind) {
|
|
42
|
+
case "ListType":
|
|
43
|
+
break; // Ignore
|
|
44
|
+
case "ObjectIntersectionType":
|
|
45
|
+
nodeShapeAstObjectIntersectionTypes.push(nodeShapeAstType);
|
|
46
|
+
break;
|
|
47
|
+
case "ObjectType": {
|
|
48
|
+
nodeShapeAstObjectTypes.push(nodeShapeAstType);
|
|
49
|
+
for (const property of nodeShapeAstType.properties) {
|
|
50
|
+
property.stubType
|
|
51
|
+
.map((stubType) => stubType.kind === "ObjectType" ||
|
|
52
|
+
stubType.kind === "ObjectUnionType"
|
|
53
|
+
? stubType
|
|
54
|
+
: stubType.itemType)
|
|
55
|
+
.filter((stubItemType) => stubItemType.kind === "ObjectType")
|
|
56
|
+
.filter((stubItemType) => stubItemType.synthetic)
|
|
57
|
+
.ifJust((stubItemType) => {
|
|
58
|
+
const stubItemTypeName = stubItemType.name.syntheticName.unsafeCoerce();
|
|
59
|
+
if (!syntheticAstObjectTypesByName[stubItemTypeName]) {
|
|
60
|
+
syntheticAstObjectTypesByName[stubItemTypeName] =
|
|
61
|
+
stubItemType;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
case "ObjectUnionType":
|
|
68
|
+
nodeShapeAstObjectUnionTypes.push(nodeShapeAstType);
|
|
69
|
+
break;
|
|
70
|
+
default:
|
|
71
|
+
nodeShapeAstType;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return Either.of({
|
|
75
|
+
objectIntersectionTypes: nodeShapeAstObjectIntersectionTypes,
|
|
76
|
+
objectTypes: nodeShapeAstObjectTypes.concat(Object.values(syntheticAstObjectTypesByName)),
|
|
77
|
+
objectUnionTypes: nodeShapeAstObjectUnionTypes,
|
|
78
|
+
});
|
|
35
79
|
}
|
|
36
80
|
}
|
|
37
81
|
//# sourceMappingURL=ShapesGraphToAstTransformer.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { TsFeature } from "enums/TsFeature.js";
|
|
2
|
+
import { Either } from "purify-ts";
|
|
3
|
+
import type * as ast from "../ast/index.js";
|
|
4
|
+
import type * as input from "../input/index.js";
|
|
5
|
+
export declare function flattenAstObjectCompositeTypeMemberTypes({ objectCompositeTypeKind, memberTypes, shape, }: {
|
|
6
|
+
objectCompositeTypeKind: "ObjectIntersectionType" | "ObjectUnionType";
|
|
7
|
+
memberTypes: readonly (ast.ObjectType | ast.ObjectIntersectionType | ast.ObjectUnionType)[];
|
|
8
|
+
shape: input.Shape;
|
|
9
|
+
}): Either<Error, {
|
|
10
|
+
memberTypes: readonly ast.ObjectType[];
|
|
11
|
+
tsFeatures: Set<TsFeature>;
|
|
12
|
+
}>;
|
|
13
|
+
//# sourceMappingURL=flattenAstObjectCompositeTypeMemberTypes.d.ts.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import TermSet from "@rdfjs/term-set";
|
|
2
|
+
import { Either, Left } from "purify-ts";
|
|
3
|
+
import { Resource } from "rdfjs-resource";
|
|
4
|
+
export function flattenAstObjectCompositeTypeMemberTypes({ objectCompositeTypeKind, memberTypes, shape, }) {
|
|
5
|
+
const flattenedMemberTypes = [];
|
|
6
|
+
for (const memberType of memberTypes) {
|
|
7
|
+
switch (memberType.kind) {
|
|
8
|
+
case "ObjectType":
|
|
9
|
+
flattenedMemberTypes.push(memberType);
|
|
10
|
+
break;
|
|
11
|
+
case "ObjectIntersectionType":
|
|
12
|
+
case "ObjectUnionType":
|
|
13
|
+
if (memberType.kind === objectCompositeTypeKind) {
|
|
14
|
+
flattenedMemberTypes.push(...memberType.memberTypes);
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
return Left(new Error(`${objectCompositeTypeKind} with a nested ${memberType.kind}`));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
// Members of the composite type must have the same tsFeatures.
|
|
21
|
+
// They must also have distinct RDF types or no RDF types at all.
|
|
22
|
+
const nonExternMemberTypes = flattenedMemberTypes.filter((memberType) => !memberType.extern);
|
|
23
|
+
const fromRdfTypes = new TermSet();
|
|
24
|
+
const tsFeatures = new Set();
|
|
25
|
+
for (let memberTypeI = 0; memberTypeI < nonExternMemberTypes.length; memberTypeI++) {
|
|
26
|
+
const memberType = nonExternMemberTypes[memberTypeI];
|
|
27
|
+
if (memberTypeI === 0) {
|
|
28
|
+
for (const tsFeature of memberType.tsFeatures) {
|
|
29
|
+
tsFeatures.add(tsFeature);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
memberType.fromRdfType.ifJust((fromRdfType) => fromRdfTypes.add(fromRdfType));
|
|
33
|
+
if (memberType.tsFeatures.size !== tsFeatures.size) {
|
|
34
|
+
return Left(new Error(`${shape} has a member ObjectType (${Resource.Identifier.toString(memberType.name.identifier)}) with different tsFeatures than the other member ObjectType's`));
|
|
35
|
+
}
|
|
36
|
+
for (const tsFeature of memberType.tsFeatures) {
|
|
37
|
+
if (!tsFeatures.has(tsFeature)) {
|
|
38
|
+
return Left(new Error(`${shape} has a member ObjectType (${Resource.Identifier.toString(memberType.name.identifier)}) with different tsFeatures than the other member ObjectType's`));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (fromRdfTypes.size > 0 &&
|
|
43
|
+
fromRdfTypes.size !== nonExternMemberTypes.length) {
|
|
44
|
+
return Left(new Error(`one or more ${shape} members ([${nonExternMemberTypes.map((memberType) => Resource.Identifier.toString(memberType.name.identifier)).join(", ")}]) lack distinguishing fromRdfType's ({${[...fromRdfTypes].map((fromRdfType) => Resource.Identifier.toString(fromRdfType)).join(", ")}})`));
|
|
45
|
+
}
|
|
46
|
+
return Either.of({
|
|
47
|
+
memberTypes: flattenedMemberTypes,
|
|
48
|
+
tsFeatures,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=flattenAstObjectCompositeTypeMemberTypes.js.map
|
|
@@ -1,28 +1,69 @@
|
|
|
1
1
|
import { Maybe } from "purify-ts";
|
|
2
|
+
import { Curie } from "../ast/Curie.js";
|
|
2
3
|
import * as input from "../input/index.js";
|
|
4
|
+
import { logger } from "../logger.js";
|
|
3
5
|
import { pickLiteral } from "./pickLiteral.js";
|
|
4
6
|
export function shapeAstName(shape) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
const namedIdentifier = (namedNode) => {
|
|
8
|
+
const curie = Maybe.fromNullable(this.iriPrefixMap.shrink(namedNode)?.value).map(Curie.parse);
|
|
9
|
+
curie.ifJust((curie) => {
|
|
10
|
+
if (typeof this.iriLocalParts[curie.reference] === "undefined") {
|
|
11
|
+
this.iriLocalParts[curie.reference] = {};
|
|
12
|
+
}
|
|
13
|
+
if (typeof this.iriLocalParts[curie.reference][curie.prefix] === "undefined") {
|
|
14
|
+
this.iriLocalParts[curie.reference][curie.prefix] = 1;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
this.iriLocalParts[curie.reference][curie.prefix] += 1;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
return {
|
|
21
|
+
equals: (other) => {
|
|
22
|
+
return namedNode.equals(other);
|
|
23
|
+
},
|
|
24
|
+
curie,
|
|
25
|
+
termType: "NamedNode",
|
|
26
|
+
uniqueLocalPart: () => curie
|
|
27
|
+
.filter((curie) => {
|
|
28
|
+
const curieReferenceInPrefixes = this.iriLocalParts[curie.reference];
|
|
29
|
+
if (Object.entries(curieReferenceInPrefixes).length === 1) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
logger.debug(`duplicate local part ${curie.reference} in ${JSON.stringify(curieReferenceInPrefixes)}`);
|
|
33
|
+
return false;
|
|
34
|
+
})
|
|
35
|
+
.map((curie) => curie.reference),
|
|
36
|
+
value: namedNode.value,
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
let propertyPath;
|
|
40
|
+
let shName;
|
|
7
41
|
if (shape instanceof input.PropertyShape) {
|
|
8
42
|
if (shape.path.kind === "PredicatePath") {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
43
|
+
propertyPath = Maybe.of(namedIdentifier(shape.path.iri));
|
|
44
|
+
// logger.debug(
|
|
45
|
+
// `shape ${shape} property path: ${JSON.stringify(propertyPath.unsafeCoerce())}`,
|
|
46
|
+
// );
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
propertyPath = Maybe.empty();
|
|
50
|
+
logger.warn(`property shape ${shape} has ${shape.path.kind} path`);
|
|
14
51
|
}
|
|
15
52
|
shName = pickLiteral(shape.names).map((literal) => literal.value);
|
|
16
53
|
}
|
|
54
|
+
else {
|
|
55
|
+
propertyPath = Maybe.empty();
|
|
56
|
+
shName = Maybe.empty();
|
|
57
|
+
}
|
|
17
58
|
return {
|
|
18
|
-
|
|
19
|
-
?
|
|
20
|
-
:
|
|
21
|
-
identifier: shape.identifier,
|
|
59
|
+
identifier: shape.identifier.termType === "NamedNode"
|
|
60
|
+
? namedIdentifier(shape.identifier)
|
|
61
|
+
: shape.identifier,
|
|
22
62
|
label: pickLiteral(shape.labels).map((literal) => literal.value),
|
|
23
63
|
propertyPath,
|
|
24
|
-
shName
|
|
64
|
+
shName,
|
|
25
65
|
shaclmateName: shape.shaclmateName,
|
|
66
|
+
syntheticName: Maybe.empty(),
|
|
26
67
|
};
|
|
27
68
|
}
|
|
28
69
|
//# sourceMappingURL=shapeAstName.js.map
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { Either } from "purify-ts";
|
|
2
2
|
import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
|
|
3
|
+
import type * as ast from "../ast/index.js";
|
|
3
4
|
import * as input from "../input/index.js";
|
|
4
5
|
import type { NodeShapeAstType } from "./NodeShapeAstType.js";
|
|
6
|
+
export declare function transformNodeShapeToAstObjectCompositeType(this: ShapesGraphToAstTransformer, { export_, nodeShape, }: {
|
|
7
|
+
export_: boolean;
|
|
8
|
+
nodeShape: input.NodeShape;
|
|
9
|
+
}): Either<Error, ast.ObjectIntersectionType | ast.ObjectUnionType>;
|
|
5
10
|
export declare function transformNodeShapeToAstType(this: ShapesGraphToAstTransformer, nodeShape: input.NodeShape): Either<Error, NodeShapeAstType>;
|
|
6
11
|
//# sourceMappingURL=transformNodeShapeToAstType.d.ts.map
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { rdf } from "@tpluscode/rdf-ns-builders";
|
|
2
2
|
import { Either, Left, Maybe } from "purify-ts";
|
|
3
3
|
import { invariant } from "ts-invariant";
|
|
4
|
-
import { TsFeature } from "../enums/index.js";
|
|
5
4
|
import * as input from "../input/index.js";
|
|
5
|
+
import { tsFeaturesDefault } from "../input/tsFeatures.js";
|
|
6
6
|
import { logger } from "../logger.js";
|
|
7
|
+
import { flattenAstObjectCompositeTypeMemberTypes } from "./flattenAstObjectCompositeTypeMemberTypes.js";
|
|
7
8
|
import { pickLiteral } from "./pickLiteral.js";
|
|
8
9
|
/**
|
|
9
10
|
* Is an ast.ObjectType actually the shape of an RDF list?
|
|
10
11
|
* If so, return the type of its rdf:first.
|
|
11
12
|
*/
|
|
12
|
-
function
|
|
13
|
+
function transformNodeShapeToAstListType(nodeShape) {
|
|
13
14
|
invariant(nodeShape.isList);
|
|
14
15
|
// Put a placeholder in the cache to deal with cyclic references
|
|
15
16
|
const listType = {
|
|
@@ -68,6 +69,73 @@ function transformNodeShapeToListType(nodeShape) {
|
|
|
68
69
|
listType.itemType = firstProperty.type;
|
|
69
70
|
return Either.of(listType);
|
|
70
71
|
}
|
|
72
|
+
export function transformNodeShapeToAstObjectCompositeType({ export_, nodeShape, }) {
|
|
73
|
+
let compositeTypeShapes;
|
|
74
|
+
let compositeTypeKind;
|
|
75
|
+
if (nodeShape.constraints.and.length > 0) {
|
|
76
|
+
compositeTypeShapes = nodeShape.constraints.and;
|
|
77
|
+
compositeTypeKind = "ObjectIntersectionType";
|
|
78
|
+
}
|
|
79
|
+
else if (nodeShape.constraints.xone.length > 0) {
|
|
80
|
+
compositeTypeShapes = nodeShape.constraints.xone;
|
|
81
|
+
compositeTypeKind = "ObjectUnionType";
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
throw new Error("should never be reached");
|
|
85
|
+
}
|
|
86
|
+
const compositeTypeNodeShapes = [];
|
|
87
|
+
for (const compositeTypeShape of compositeTypeShapes) {
|
|
88
|
+
if (!(compositeTypeShape instanceof input.NodeShape)) {
|
|
89
|
+
return Left(new Error(`${nodeShape} has non-NodeShape in its logical constraint`));
|
|
90
|
+
}
|
|
91
|
+
compositeTypeNodeShapes.push(compositeTypeShape);
|
|
92
|
+
}
|
|
93
|
+
if (compositeTypeNodeShapes.length === 0) {
|
|
94
|
+
return Left(new Error(`${nodeShape} has no NodeShapes in its logical constraint`));
|
|
95
|
+
}
|
|
96
|
+
// Put a placeholder in the cache to deal with cyclic references
|
|
97
|
+
const compositeType = {
|
|
98
|
+
comment: pickLiteral(nodeShape.comments).map((literal) => literal.value),
|
|
99
|
+
export: export_,
|
|
100
|
+
kind: compositeTypeKind,
|
|
101
|
+
label: pickLiteral(nodeShape.labels).map((literal) => literal.value),
|
|
102
|
+
memberTypes: [],
|
|
103
|
+
name: this.shapeAstName(nodeShape),
|
|
104
|
+
tsFeatures: new Set(),
|
|
105
|
+
};
|
|
106
|
+
this.nodeShapeAstTypesByIdentifier.set(nodeShape.identifier, compositeType);
|
|
107
|
+
const memberTypes = [];
|
|
108
|
+
for (const memberNodeShape of compositeTypeNodeShapes) {
|
|
109
|
+
const memberTypeEither = this.transformNodeShapeToAstType(memberNodeShape);
|
|
110
|
+
if (memberTypeEither.isLeft()) {
|
|
111
|
+
return memberTypeEither;
|
|
112
|
+
}
|
|
113
|
+
const memberType = memberTypeEither.unsafeCoerce();
|
|
114
|
+
switch (memberType.kind) {
|
|
115
|
+
case "ObjectType":
|
|
116
|
+
case "ObjectIntersectionType":
|
|
117
|
+
case "ObjectUnionType":
|
|
118
|
+
memberTypes.push(memberType);
|
|
119
|
+
break;
|
|
120
|
+
default:
|
|
121
|
+
return Left(new Error(`${nodeShape} has one or more non-ObjectType node shapes in its logical constraint`));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return flattenAstObjectCompositeTypeMemberTypes({
|
|
125
|
+
objectCompositeTypeKind: compositeTypeKind,
|
|
126
|
+
memberTypes,
|
|
127
|
+
shape: nodeShape,
|
|
128
|
+
}).map(({ memberTypes, tsFeatures }) => {
|
|
129
|
+
// Add to the placeholder composite type and return it.
|
|
130
|
+
for (const memberType of memberTypes) {
|
|
131
|
+
compositeType.memberTypes.push(memberType);
|
|
132
|
+
}
|
|
133
|
+
for (const tsFeature of tsFeatures) {
|
|
134
|
+
compositeType.tsFeatures.add(tsFeature);
|
|
135
|
+
}
|
|
136
|
+
return compositeType;
|
|
137
|
+
});
|
|
138
|
+
}
|
|
71
139
|
export function transformNodeShapeToAstType(nodeShape) {
|
|
72
140
|
{
|
|
73
141
|
const type = this.nodeShapeAstTypesByIdentifier.get(nodeShape.identifier);
|
|
@@ -76,55 +144,27 @@ export function transformNodeShapeToAstType(nodeShape) {
|
|
|
76
144
|
}
|
|
77
145
|
}
|
|
78
146
|
if (nodeShape.isList) {
|
|
79
|
-
return
|
|
147
|
+
return transformNodeShapeToAstListType.bind(this)(nodeShape);
|
|
80
148
|
}
|
|
81
149
|
const export_ = nodeShape.export.orDefault(true);
|
|
82
150
|
if (nodeShape.constraints.and.length > 0 ||
|
|
83
151
|
nodeShape.constraints.xone.length > 0) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
const compositeTypeNodeShapes = compositeTypeShapes.filter((shape) => shape instanceof input.NodeShape);
|
|
95
|
-
if (compositeTypeNodeShapes.length === 0) {
|
|
96
|
-
return Left(new Error(`${nodeShape} has no node shapes in its logical constraint`));
|
|
97
|
-
}
|
|
98
|
-
// Put a placeholder in the cache to deal with cyclic references
|
|
99
|
-
const compositeType = {
|
|
100
|
-
comment: pickLiteral(nodeShape.comments).map((literal) => literal.value),
|
|
101
|
-
export: export_,
|
|
102
|
-
kind: compositeTypeKind,
|
|
103
|
-
label: pickLiteral(nodeShape.labels).map((literal) => literal.value),
|
|
104
|
-
memberTypes: [],
|
|
105
|
-
name: this.shapeAstName(nodeShape),
|
|
106
|
-
tsFeatures: nodeShape.tsFeatures.orDefault(new Set(TsFeature.MEMBERS)),
|
|
107
|
-
};
|
|
108
|
-
this.nodeShapeAstTypesByIdentifier.set(nodeShape.identifier, compositeType);
|
|
109
|
-
for (const memberNodeShape of compositeTypeNodeShapes) {
|
|
110
|
-
const memberAstTypeEither = this.transformNodeShapeToAstType(memberNodeShape);
|
|
111
|
-
if (memberAstTypeEither.isLeft()) {
|
|
112
|
-
return memberAstTypeEither;
|
|
113
|
-
}
|
|
114
|
-
const memberAstType = memberAstTypeEither.unsafeCoerce();
|
|
115
|
-
switch (memberAstType.kind) {
|
|
116
|
-
case "ObjectType":
|
|
117
|
-
compositeType.memberTypes.push(memberAstType);
|
|
118
|
-
break;
|
|
119
|
-
case "ObjectUnionType":
|
|
120
|
-
compositeType.memberTypes.push(...memberAstType.memberTypes);
|
|
121
|
-
break;
|
|
122
|
-
default:
|
|
123
|
-
return Left(new Error(`${nodeShape} has one or more non-ObjectType node shapes in its logical constraint`));
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return Either.of(compositeType);
|
|
152
|
+
return transformNodeShapeToAstObjectCompositeType.bind(this)({
|
|
153
|
+
export_,
|
|
154
|
+
nodeShape,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
const fromRdfType = nodeShape.fromRdfType.alt(nodeShape.rdfType);
|
|
158
|
+
const toRdfTypes = nodeShape.toRdfTypes.concat();
|
|
159
|
+
if (toRdfTypes.length === 0) {
|
|
160
|
+
toRdfTypes.push(...nodeShape.rdfType.toList());
|
|
127
161
|
}
|
|
162
|
+
// Ensure toRdfTypes has fromRdfType
|
|
163
|
+
fromRdfType.ifJust((fromRdfType) => {
|
|
164
|
+
if (!toRdfTypes.some((toRdfType) => toRdfType.equals(fromRdfType))) {
|
|
165
|
+
toRdfTypes.push(fromRdfType);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
128
168
|
const identifierIn = nodeShape.constraints.in_.filter((term) => term.termType === "NamedNode");
|
|
129
169
|
// Put a placeholder in the cache to deal with cyclic references
|
|
130
170
|
// If this node shape's properties (directly or indirectly) refer to the node shape itself,
|
|
@@ -137,24 +177,22 @@ export function transformNodeShapeToAstType(nodeShape) {
|
|
|
137
177
|
descendantObjectTypes: [],
|
|
138
178
|
export: export_,
|
|
139
179
|
extern: nodeShape.extern.orDefault(false),
|
|
140
|
-
fromRdfType
|
|
180
|
+
fromRdfType,
|
|
141
181
|
label: pickLiteral(nodeShape.labels).map((literal) => literal.value),
|
|
142
182
|
kind: "ObjectType",
|
|
143
183
|
identifierIn,
|
|
144
184
|
identifierMintingStrategy: identifierIn.length === 0
|
|
145
185
|
? nodeShape.identifierMintingStrategy
|
|
146
186
|
: Maybe.empty(),
|
|
147
|
-
|
|
187
|
+
identifierNodeKinds: identifierIn.length === 0 ? nodeShape.nodeKinds : new Set(["NamedNode"]),
|
|
148
188
|
name: this.shapeAstName(nodeShape),
|
|
149
189
|
properties: [], // This is mutable, we'll populate it below.
|
|
150
190
|
parentObjectTypes: [], // This is mutable, we'll populate it below
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
tsIdentifierPropertyName: nodeShape.tsObjectIdentifierPropertyName.orDefault("identifier"),
|
|
191
|
+
synthetic: false,
|
|
192
|
+
toRdfTypes,
|
|
193
|
+
tsFeatures: nodeShape.tsFeatures.orDefault(new Set(tsFeaturesDefault)),
|
|
155
194
|
tsImports: nodeShape.tsImports,
|
|
156
195
|
tsObjectDeclarationType: nodeShape.tsObjectDeclarationType.orDefault("class"),
|
|
157
|
-
tsTypeDiscriminatorPropertyName: nodeShape.tsObjectTypeDiscriminatorPropertyName.orDefault("type"),
|
|
158
196
|
};
|
|
159
197
|
this.nodeShapeAstTypesByIdentifier.set(nodeShape.identifier, objectType);
|
|
160
198
|
// Populate ancestor and descendant object types
|
|
@@ -169,6 +207,40 @@ export function transformNodeShapeToAstType(nodeShape) {
|
|
|
169
207
|
objectType.descendantObjectTypes.push(...relatedObjectTypes(nodeShape.descendantNodeShapes));
|
|
170
208
|
objectType.parentObjectTypes.push(...relatedObjectTypes(nodeShape.parentNodeShapes));
|
|
171
209
|
// Populate properties
|
|
210
|
+
// Check whether a type refers to this ObjectType
|
|
211
|
+
const isPropertyRecursive = (astType) => {
|
|
212
|
+
switch (astType.kind) {
|
|
213
|
+
case "IdentifierType":
|
|
214
|
+
case "LiteralType":
|
|
215
|
+
case "PlaceholderType":
|
|
216
|
+
case "TermType":
|
|
217
|
+
return false;
|
|
218
|
+
case "ObjectType":
|
|
219
|
+
if (astType.name === objectType.name) {
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
for (const property of astType.properties) {
|
|
223
|
+
if (isPropertyRecursive(property.type)) {
|
|
224
|
+
return true;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return false;
|
|
228
|
+
case "IntersectionType":
|
|
229
|
+
case "ObjectIntersectionType":
|
|
230
|
+
case "ObjectUnionType":
|
|
231
|
+
case "UnionType":
|
|
232
|
+
for (const memberType of astType.memberTypes) {
|
|
233
|
+
if (isPropertyRecursive(memberType)) {
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return false;
|
|
238
|
+
case "ListType":
|
|
239
|
+
case "OptionType":
|
|
240
|
+
case "SetType":
|
|
241
|
+
return isPropertyRecursive(astType.itemType);
|
|
242
|
+
}
|
|
243
|
+
};
|
|
172
244
|
for (const propertyShape of nodeShape.constraints.properties) {
|
|
173
245
|
const propertyEither = this.transformPropertyShapeToAstObjectTypeProperty(propertyShape);
|
|
174
246
|
if (propertyEither.isLeft()) {
|
|
@@ -176,7 +248,11 @@ export function transformNodeShapeToAstType(nodeShape) {
|
|
|
176
248
|
continue;
|
|
177
249
|
// return property;
|
|
178
250
|
}
|
|
179
|
-
|
|
251
|
+
const property = propertyEither.unsafeCoerce();
|
|
252
|
+
objectType.properties.push({
|
|
253
|
+
...property,
|
|
254
|
+
recursive: isPropertyRecursive(property.type),
|
|
255
|
+
});
|
|
180
256
|
}
|
|
181
257
|
objectType.properties.sort((left, right) => {
|
|
182
258
|
if (left.order < right.order) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Literal, NamedNode } from "@rdfjs/types";
|
|
2
2
|
import { Either, Maybe } from "purify-ts";
|
|
3
3
|
import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
|
|
4
4
|
import type * as ast from "../ast/index.js";
|
|
@@ -7,7 +7,6 @@ import * as input from "../input/index.js";
|
|
|
7
7
|
* Try to convert a property shape to a composite type (intersection or union) using some heuristics.
|
|
8
8
|
*/
|
|
9
9
|
export declare function transformPropertyShapeToAstCompositeType(this: ShapesGraphToAstTransformer, shape: input.Shape, inherited: {
|
|
10
|
-
defaultValue: Maybe<
|
|
11
|
-
extern: Maybe<boolean>;
|
|
10
|
+
defaultValue: Maybe<Literal | NamedNode>;
|
|
12
11
|
} | null): Either<Error, ast.Type>;
|
|
13
12
|
//# sourceMappingURL=transformPropertyShapeToAstCompositeType.d.ts.map
|