@shaclmate/compiler 2.0.23 → 3.0.0

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 (103) hide show
  1. package/dist/ShapesGraphToAstTransformer.d.ts +5 -5
  2. package/dist/ShapesGraphToAstTransformer.js +5 -5
  3. package/dist/_ShapesGraphToAstTransformer/InheritableShapeConstraints.d.ts +2 -0
  4. package/dist/_ShapesGraphToAstTransformer/InheritableShapeConstraints.js +2 -0
  5. package/dist/_ShapesGraphToAstTransformer/ShapeStack.d.ts +15 -0
  6. package/dist/_ShapesGraphToAstTransformer/ShapeStack.js +51 -0
  7. package/dist/_ShapesGraphToAstTransformer/index.d.ts +5 -5
  8. package/dist/_ShapesGraphToAstTransformer/index.js +5 -5
  9. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +77 -29
  10. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompositeType.d.ts +10 -0
  11. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompositeType.js +185 -0
  12. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstIdentifierType.d.ts +10 -0
  13. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstIdentifierType.js +32 -0
  14. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstLiteralType.d.ts +10 -0
  15. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstLiteralType.js +46 -0
  16. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstTermType.d.ts +12 -0
  17. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstTermType.js +24 -0
  18. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstType.d.ts +13 -0
  19. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstType.js +14 -0
  20. package/dist/ast/OptionType.d.ts +0 -2
  21. package/dist/ast/SetType.d.ts +1 -6
  22. package/dist/ast/index.d.ts +1 -0
  23. package/dist/ast/index.js +1 -0
  24. package/dist/generators/json/AstJsonGenerator.js +7 -1
  25. package/dist/generators/ts/BooleanType.d.ts +2 -1
  26. package/dist/generators/ts/BooleanType.js +9 -4
  27. package/dist/generators/ts/DateTimeType.d.ts +2 -1
  28. package/dist/generators/ts/DateTimeType.js +9 -4
  29. package/dist/generators/ts/IdentifierType.d.ts +1 -1
  30. package/dist/generators/ts/IdentifierType.js +20 -14
  31. package/dist/generators/ts/Import.d.ts +2 -1
  32. package/dist/generators/ts/Import.js +29 -24
  33. package/dist/generators/ts/ListType.js +16 -5
  34. package/dist/generators/ts/LiteralType.d.ts +5 -2
  35. package/dist/generators/ts/LiteralType.js +81 -15
  36. package/dist/generators/ts/NumberType.d.ts +2 -1
  37. package/dist/generators/ts/NumberType.js +9 -4
  38. package/dist/generators/ts/ObjectType.d.ts +3 -2
  39. package/dist/generators/ts/ObjectType.js +16 -6
  40. package/dist/generators/ts/ObjectUnionType.d.ts +2 -0
  41. package/dist/generators/ts/ObjectUnionType.js +21 -9
  42. package/dist/generators/ts/OptionType.d.ts +1 -1
  43. package/dist/generators/ts/OptionType.js +6 -4
  44. package/dist/generators/ts/PrimitiveType.d.ts +1 -1
  45. package/dist/generators/ts/PrimitiveType.js +6 -3
  46. package/dist/generators/ts/SetType.d.ts +4 -4
  47. package/dist/generators/ts/SetType.js +15 -12
  48. package/dist/generators/ts/SnippetDeclarations.d.ts +3 -2
  49. package/dist/generators/ts/SnippetDeclarations.js +41 -3
  50. package/dist/generators/ts/StringType.d.ts +2 -1
  51. package/dist/generators/ts/StringType.js +14 -7
  52. package/dist/generators/ts/TermType.d.ts +18 -19
  53. package/dist/generators/ts/TermType.js +55 -51
  54. package/dist/generators/ts/TsGenerator.js +24 -12
  55. package/dist/generators/ts/Type.d.ts +12 -3
  56. package/dist/generators/ts/Type.js +1 -0
  57. package/dist/generators/ts/TypeFactory.d.ts +8 -0
  58. package/dist/generators/ts/TypeFactory.js +114 -23
  59. package/dist/generators/ts/UnionType.js +1 -1
  60. package/dist/generators/ts/_ObjectType/EagerShaclProperty.js +3 -2
  61. package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.d.ts +1 -1
  62. package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.js +15 -1
  63. package/dist/generators/ts/_ObjectType/IdentifierProperty.d.ts +6 -6
  64. package/dist/generators/ts/_ObjectType/IdentifierProperty.js +59 -29
  65. package/dist/generators/ts/_ObjectType/LazyShaclProperty.d.ts +14 -1
  66. package/dist/generators/ts/_ObjectType/LazyShaclProperty.js +89 -11
  67. package/dist/generators/ts/_ObjectType/Property.d.ts +10 -4
  68. package/dist/generators/ts/_ObjectType/ShaclProperty.d.ts +1 -1
  69. package/dist/generators/ts/_ObjectType/ShaclProperty.js +14 -2
  70. package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +1 -1
  71. package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +1 -1
  72. package/dist/generators/ts/_ObjectType/classDeclaration.js +16 -12
  73. package/dist/generators/ts/_ObjectType/createFunctionDeclaration.js +22 -10
  74. package/dist/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.js +3 -1
  75. package/dist/generators/ts/_ObjectType/graphqlTypeVariableStatement.js +14 -2
  76. package/dist/generators/ts/_ObjectType/jsonFunctionDeclarations.js +1 -1
  77. package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.js +95 -84
  78. package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.js +3 -3
  79. package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.js +1 -1
  80. package/dist/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +35 -15
  81. package/dist/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.js +19 -12
  82. package/dist/generators/ts/forwardingObjectSetClassDeclaration.d.ts +8 -0
  83. package/dist/generators/ts/forwardingObjectSetClassDeclaration.js +29 -0
  84. package/dist/generators/ts/objectSetDeclarations.js +2 -0
  85. package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +26 -19
  86. package/dist/generators/ts/rdfjsTermExpression.js +3 -3
  87. package/dist/generators/ts/sparqlObjectSetClassDeclaration.js +6 -6
  88. package/dist/input/PropertyPath.d.ts +2 -3
  89. package/dist/input/PropertyPath.js +6 -8
  90. package/dist/input/ShapesGraph.js +4 -8
  91. package/dist/input/generated.d.ts +96 -54
  92. package/dist/input/generated.js +1350 -744
  93. package/package.json +5 -8
  94. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.d.ts +0 -12
  95. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +0 -193
  96. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.d.ts +0 -12
  97. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.js +0 -29
  98. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.d.ts +0 -12
  99. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.js +0 -43
  100. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.d.ts +0 -14
  101. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.js +0 -21
  102. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.d.ts +0 -15
  103. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.js +0 -60
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "dependencies": {
3
- "@shaclmate/shacl-ast": "2.0.23",
3
+ "@shaclmate/shacl-ast": "3.0.0",
4
4
  "@rdfjs/prefix-map": "^0.1.2",
5
5
  "@rdfjs/term-map": "^2.0.2",
6
6
  "@rdfjs/term-set": "^2.0.3",
@@ -22,13 +22,10 @@
22
22
  "typescript-memoize": "^1.1.1"
23
23
  },
24
24
  "devDependencies": {
25
- "@shaclmate/kitchen-sink-example": "2.0.23",
26
- "@shaclmate/runtime": "2.0.23",
25
+ "@shaclmate/kitchen-sink-example": "3.0.0",
26
+ "@shaclmate/runtime": "3.0.0",
27
27
  "@kos-kit/sparql-client": "2.0.115",
28
- "@types/n3": "^1.21.1",
29
- "oxigraph": "0.4.11",
30
- "n3": "^1.21.3",
31
- "rdfjs-resource": "1.0.20"
28
+ "oxigraph": "0.4.11"
32
29
  },
33
30
  "exports": {
34
31
  ".": {
@@ -79,5 +76,5 @@
79
76
  "unlink": "npm unlink -g @shaclmate/compiler"
80
77
  },
81
78
  "type": "module",
82
- "version": "2.0.23"
79
+ "version": "3.0.0"
83
80
  }
@@ -1,12 +0,0 @@
1
- import type { Literal, NamedNode } from "@rdfjs/types";
2
- import { Either, Maybe } from "purify-ts";
3
- import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
4
- import type * as ast from "../ast/index.js";
5
- import * as input from "../input/index.js";
6
- /**
7
- * Try to convert a property shape to a composite type (intersection or union) using some heuristics.
8
- */
9
- export declare function transformPropertyShapeToAstCompositeType(this: ShapesGraphToAstTransformer, shape: input.Shape, inherited: {
10
- defaultValue: Maybe<Literal | NamedNode>;
11
- } | null): Either<Error, ast.Type>;
12
- //# sourceMappingURL=transformPropertyShapeToAstCompositeType.d.ts.map
@@ -1,193 +0,0 @@
1
- import { owl, rdfs } from "@tpluscode/rdf-ns-builders";
2
- import { Either, Left, Maybe } from "purify-ts";
3
- import { invariant } from "ts-invariant";
4
- import * as input from "../input/index.js";
5
- import { logger } from "../logger.js";
6
- import { flattenAstObjectCompositeTypeMemberTypes } from "./flattenAstObjectCompositeTypeMemberTypes.js";
7
- /**
8
- * Try to convert a property shape to a composite type (intersection or union) using some heuristics.
9
- */
10
- export function transformPropertyShapeToAstCompositeType(shape, inherited) {
11
- const defaultValue = (shape instanceof input.PropertyShape ? shape.defaultValue : Maybe.empty()).alt(inherited !== null ? inherited.defaultValue : Maybe.empty());
12
- let memberTypeEithers;
13
- let compositeTypeKind;
14
- if (shape.constraints.and.length > 0) {
15
- memberTypeEithers = shape.constraints.and.map((memberShape) => this.transformPropertyShapeToAstType(memberShape, {
16
- defaultValue,
17
- }));
18
- compositeTypeKind = "IntersectionType";
19
- }
20
- else if (shape.constraints.classes.length > 0) {
21
- memberTypeEithers = shape.constraints.classes.map((classIri) => {
22
- if (classIri.equals(owl.Class) ||
23
- classIri.equals(owl.Thing) ||
24
- classIri.equals(rdfs.Class)) {
25
- return Left(new Error(`class ${classIri.value} is not transformable`));
26
- }
27
- const classNodeShape = this.shapesGraph
28
- .nodeShapeByIdentifier(classIri)
29
- .extractNullable();
30
- if (classNodeShape === null) {
31
- return Left(new Error(`class ${classIri.value} did not resolve to a node shape`));
32
- }
33
- return this.transformNodeShapeToAstType(classNodeShape);
34
- });
35
- compositeTypeKind = "IntersectionType";
36
- if (Either.rights(memberTypeEithers).length === 0) {
37
- // This frequently happens with e.g., sh:class skos:Concept
38
- logger.debug("shape %s sh:class(es) did not map to any node shapes", shape);
39
- return memberTypeEithers[0];
40
- }
41
- }
42
- else if (shape.constraints.nodes.length > 0) {
43
- memberTypeEithers = shape.constraints.nodes.map((nodeShape) => this.transformNodeShapeToAstType(nodeShape));
44
- compositeTypeKind = "IntersectionType";
45
- }
46
- else if (shape.constraints.xone.length > 0) {
47
- memberTypeEithers = shape.constraints.xone.map((memberShape) => this.transformPropertyShapeToAstType(memberShape, {
48
- defaultValue,
49
- }));
50
- compositeTypeKind = "UnionType";
51
- }
52
- else {
53
- return Left(new Error(`unable to transform ${shape} into an AST type`));
54
- }
55
- invariant(memberTypeEithers.length > 0);
56
- let memberObjectTypes = [];
57
- let memberTypes = [];
58
- for (const memberTypeEither of memberTypeEithers) {
59
- if (memberTypeEither.isLeft()) {
60
- return memberTypeEither;
61
- }
62
- const memberType = memberTypeEither.unsafeCoerce();
63
- memberTypes.push(memberType);
64
- switch (memberType.kind) {
65
- case "ObjectType":
66
- case "ObjectIntersectionType":
67
- case "ObjectUnionType":
68
- memberObjectTypes.push(memberType);
69
- break;
70
- }
71
- }
72
- if (memberTypes.length === 1) {
73
- return Either.of(memberTypes[0]);
74
- }
75
- if (memberTypes.length === memberObjectTypes.length) {
76
- // If all the member types are ast.ObjectType, flatten them.
77
- const flattenedMemberTypesEither = flattenAstObjectCompositeTypeMemberTypes({
78
- objectCompositeTypeKind: compositeTypeKind === "IntersectionType"
79
- ? "ObjectIntersectionType"
80
- : "ObjectUnionType",
81
- memberTypes: memberObjectTypes,
82
- shape,
83
- });
84
- if (flattenedMemberTypesEither.isLeft()) {
85
- return flattenedMemberTypesEither;
86
- }
87
- const { memberTypes: flattenedMemberTypes } = flattenedMemberTypesEither.unsafeCoerce();
88
- memberTypes = memberObjectTypes = flattenedMemberTypes.concat();
89
- }
90
- return widenAstCompositeTypeToSingleType({
91
- defaultValue,
92
- memberTypes,
93
- shape,
94
- }).altLazy(() =>
95
- // True composite type
96
- Either.of({
97
- kind: compositeTypeKind,
98
- memberTypes,
99
- }));
100
- }
101
- function widenAstCompositeTypeToSingleType({ defaultValue, memberTypes, shape, }) {
102
- if (shape.constraints.hasValues.length > 0) {
103
- return Left(new Error(`shape ${shape} hasValues, not attempting to widen composite type into a single type`));
104
- }
105
- if (shape instanceof input.PropertyShape && !shape.widen.orDefault(true)) {
106
- return Left(new Error(`shape ${shape} has widening disabled`));
107
- }
108
- // Get the type underlying a set or option
109
- const memberItemTypes = memberTypes.map((memberType) => {
110
- switch (memberType.kind) {
111
- case "OptionType":
112
- return memberType.itemType;
113
- case "SetType":
114
- return memberType.itemType;
115
- default:
116
- return memberType;
117
- }
118
- });
119
- const canWiden = (memberItemType) => {
120
- if (memberItemType.in_.length > 0) {
121
- return false;
122
- }
123
- switch (memberItemType.kind) {
124
- case "LiteralType": {
125
- if (memberItemType.maxExclusive.isJust()) {
126
- return false;
127
- }
128
- if (memberItemType.maxInclusive.isJust()) {
129
- return false;
130
- }
131
- if (memberItemType.minExclusive.isJust()) {
132
- return false;
133
- }
134
- if (memberItemType.minInclusive.isJust()) {
135
- return false;
136
- }
137
- }
138
- }
139
- return true;
140
- };
141
- if (memberItemTypes.every((memberItemType) => memberItemType.kind === "IdentifierType" && canWiden(memberItemType))) {
142
- // Special case: all member types are identifiers without further constraints
143
- return Either.of({
144
- defaultValue: defaultValue.filter((term) => term.termType === "NamedNode"),
145
- hasValues: [],
146
- in_: [],
147
- kind: "IdentifierType",
148
- nodeKinds: new Set(memberItemTypes
149
- .filter((memberItemType) => memberItemType.kind === "IdentifierType")
150
- .flatMap((memberItemType) => [
151
- ...memberItemType.nodeKinds,
152
- ])),
153
- });
154
- }
155
- if (memberItemTypes.every((memberItemType) => memberItemType.kind === "LiteralType" && canWiden(memberItemType))) {
156
- // Special case: all the member types are Literals without further constraints,
157
- // like dash:StringOrLangString
158
- // Don't try to widen range constraints.
159
- return Either.of({
160
- datatype: Maybe.empty(),
161
- defaultValue: defaultValue.filter((term) => term.termType === "Literal"),
162
- hasValues: [],
163
- in_: [],
164
- kind: "LiteralType",
165
- languageIn: [],
166
- maxExclusive: Maybe.empty(),
167
- maxInclusive: Maybe.empty(),
168
- minExclusive: Maybe.empty(),
169
- minInclusive: Maybe.empty(),
170
- nodeKinds: new Set(["Literal"]),
171
- });
172
- }
173
- if (memberItemTypes.every((memberItemType) => (memberItemType.kind === "IdentifierType" ||
174
- memberItemType.kind === "LiteralType" ||
175
- memberItemType.kind === "TermType") &&
176
- canWiden(memberItemType))) {
177
- // Special case: all member types are terms without further constraints
178
- const nodeKinds = new Set(memberItemTypes.flatMap((memberItemType) => [
179
- ...memberItemType.nodeKinds,
180
- ]));
181
- invariant(nodeKinds.has("Literal") &&
182
- (nodeKinds.has("BlankNode") || nodeKinds.has("NamedNode"))); // The identifier-identifier and literal-literal cases should have been caught above
183
- return Either.of({
184
- defaultValue,
185
- hasValues: [],
186
- in_: [],
187
- kind: "TermType",
188
- nodeKinds,
189
- });
190
- }
191
- return Left(new Error(`shape ${shape} member types could not be widened into a single type`));
192
- }
193
- //# sourceMappingURL=transformPropertyShapeToAstCompositeType.js.map
@@ -1,12 +0,0 @@
1
- import type { Literal, NamedNode } from "@rdfjs/types";
2
- import { Either, Maybe } from "purify-ts";
3
- import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
4
- import type * as ast from "../ast/index.js";
5
- import * as input from "../input/index.js";
6
- /**
7
- * Try to convert a property shape to an AST IdentifierType using some heuristics.
8
- */
9
- export declare function transformPropertyShapeToAstIdentifierType(this: ShapesGraphToAstTransformer, shape: input.Shape, inherited: {
10
- defaultValue: Maybe<Literal | NamedNode>;
11
- } | null): Either<Error, ast.IdentifierType>;
12
- //# sourceMappingURL=transformPropertyShapeToAstIdentifierType.d.ts.map
@@ -1,29 +0,0 @@
1
- import { Either, Left, Maybe } from "purify-ts";
2
- import * as input from "../input/index.js";
3
- import { propertyShapeNodeKinds } from "./propertyShapeNodeKinds.js";
4
- /**
5
- * Try to convert a property shape to an AST IdentifierType using some heuristics.
6
- */
7
- export function transformPropertyShapeToAstIdentifierType(shape, inherited) {
8
- // defaultValue / hasValue / in only makes sense with IRIs
9
- const identifierDefaultValue = (shape instanceof input.PropertyShape ? shape.defaultValue : Maybe.empty())
10
- .alt(inherited !== null ? inherited.defaultValue : Maybe.empty())
11
- .filter((value) => value.termType === "NamedNode");
12
- const identifierHasValues = shape.constraints.hasValues.filter((term) => term.termType === "NamedNode");
13
- const identifierIn = shape.constraints.in_.filter((term) => term.termType === "NamedNode");
14
- const nodeKinds = propertyShapeNodeKinds(shape);
15
- if (identifierHasValues.length > 0 ||
16
- identifierDefaultValue.isJust() ||
17
- identifierIn.length > 0 ||
18
- (nodeKinds.size > 0 && nodeKinds.size <= 2 && !nodeKinds.has("Literal"))) {
19
- return Either.of({
20
- defaultValue: identifierDefaultValue,
21
- hasValues: identifierHasValues,
22
- in_: identifierIn,
23
- kind: "IdentifierType",
24
- nodeKinds: nodeKinds,
25
- });
26
- }
27
- return Left(new Error(`unable to transform ${shape} into an AST type`));
28
- }
29
- //# sourceMappingURL=transformPropertyShapeToAstIdentifierType.js.map
@@ -1,12 +0,0 @@
1
- import type { Literal, NamedNode } from "@rdfjs/types";
2
- import { Either, Maybe } from "purify-ts";
3
- import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
4
- import type * as ast from "../ast/index.js";
5
- import * as input from "../input/index.js";
6
- /**
7
- * Try to convert a property shape to an AST LiteralType using some heuristics.
8
- */
9
- export declare function transformPropertyShapeToAstLiteralType(this: ShapesGraphToAstTransformer, shape: input.Shape, inherited: {
10
- defaultValue: Maybe<Literal | NamedNode>;
11
- } | null): Either<Error, ast.LiteralType>;
12
- //# sourceMappingURL=transformPropertyShapeToAstLiteralType.d.ts.map
@@ -1,43 +0,0 @@
1
- import { Either, Left, Maybe } from "purify-ts";
2
- import * as input from "../input/index.js";
3
- import { propertyShapeNodeKinds } from "./propertyShapeNodeKinds.js";
4
- /**
5
- * Try to convert a property shape to an AST LiteralType using some heuristics.
6
- */
7
- export function transformPropertyShapeToAstLiteralType(shape, inherited) {
8
- const literalDefaultValue = (shape instanceof input.PropertyShape ? shape.defaultValue : Maybe.empty())
9
- .alt(inherited !== null ? inherited.defaultValue : Maybe.empty())
10
- .filter((term) => term.termType === "Literal");
11
- const literalHasValues = shape.constraints.hasValues.filter((term) => term.termType === "Literal");
12
- const literalIn = shape.constraints.in_.filter((term) => term.termType === "Literal");
13
- const nodeKinds = propertyShapeNodeKinds(shape);
14
- if ([
15
- // Treat any shape with the constraints in the list as a literal type
16
- shape.constraints.datatype,
17
- shape.constraints.maxExclusive,
18
- shape.constraints.maxInclusive,
19
- shape.constraints.minExclusive,
20
- shape.constraints.minInclusive,
21
- ].some((constraint) => constraint.isJust()) ||
22
- shape.constraints.languageIn.length > 0 ||
23
- literalDefaultValue.isJust() ||
24
- literalHasValues.length > 0 ||
25
- literalIn.length > 0 ||
26
- // Treat any shape with a single sh:nodeKind of sh:Literal as a literal type
27
- (nodeKinds.size === 1 && nodeKinds.has("Literal")))
28
- return Either.of({
29
- datatype: shape.constraints.datatype,
30
- defaultValue: literalDefaultValue,
31
- hasValues: literalHasValues,
32
- in_: literalIn,
33
- kind: "LiteralType",
34
- languageIn: shape.constraints.languageIn,
35
- maxExclusive: shape.constraints.maxExclusive,
36
- maxInclusive: shape.constraints.maxInclusive,
37
- minExclusive: shape.constraints.minExclusive,
38
- minInclusive: shape.constraints.minInclusive,
39
- nodeKinds: new Set(["Literal"]),
40
- });
41
- return Left(new Error(`unable to transform ${shape} into an AST type`));
42
- }
43
- //# sourceMappingURL=transformPropertyShapeToAstLiteralType.js.map
@@ -1,14 +0,0 @@
1
- import type { Literal, NamedNode } from "@rdfjs/types";
2
- import { Either, Maybe } from "purify-ts";
3
- import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
4
- import type * as ast from "../ast/index.js";
5
- import * as input from "../input/index.js";
6
- /**
7
- * Try to convert a property shape to an AST TermType using some heuristics.
8
- */
9
- export declare function transformPropertyShapeToAstTermType(this: ShapesGraphToAstTransformer, shape: input.Shape, inherited: {
10
- defaultValue: Maybe<Literal | NamedNode>;
11
- } | null): Either<Error, Omit<ast.TermType, "kind"> & {
12
- readonly kind: "TermType";
13
- }>;
14
- //# sourceMappingURL=transformPropertyShapeToAstTermType.d.ts.map
@@ -1,21 +0,0 @@
1
- import { Either, Maybe } from "purify-ts";
2
- import * as input from "../input/index.js";
3
- import { propertyShapeNodeKinds } from "./propertyShapeNodeKinds.js";
4
- /**
5
- * Try to convert a property shape to an AST TermType using some heuristics.
6
- */
7
- export function transformPropertyShapeToAstTermType(shape, inherited) {
8
- const nodeKinds = propertyShapeNodeKinds(shape);
9
- return Either.of({
10
- defaultValue: (shape instanceof input.PropertyShape
11
- ? shape.defaultValue
12
- : Maybe.empty()).alt(inherited !== null ? inherited.defaultValue : Maybe.empty()),
13
- hasValues: shape.constraints.hasValues,
14
- in_: shape.constraints.in_,
15
- kind: "TermType",
16
- nodeKinds: nodeKinds.size > 0
17
- ? nodeKinds
18
- : new Set(["BlankNode", "NamedNode", "Literal"]),
19
- });
20
- }
21
- //# sourceMappingURL=transformPropertyShapeToAstTermType.js.map
@@ -1,15 +0,0 @@
1
- import type { Literal, NamedNode } from "@rdfjs/types";
2
- import type { Either, Maybe } from "purify-ts";
3
- import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
4
- import type * as ast from "../ast/index.js";
5
- import * as input from "../input/index.js";
6
- /**
7
- * Try to convert a property shape to a type using some heuristics.
8
- *
9
- * We don't try to handle exotic cases allowed by the SHACL spec, such as combinations of sh:in and sh:node. Instead we assume
10
- * a shape has one type.
11
- */
12
- export declare function transformPropertyShapeToAstType(this: ShapesGraphToAstTransformer, shape: input.Shape, inherited: {
13
- defaultValue: Maybe<Literal | NamedNode>;
14
- } | null): Either<Error, ast.Type>;
15
- //# sourceMappingURL=transformPropertyShapeToAstType.d.ts.map
@@ -1,60 +0,0 @@
1
- import { invariant } from "ts-invariant";
2
- import * as input from "../input/index.js";
3
- /**
4
- * Try to convert a property shape to a type using some heuristics.
5
- *
6
- * We don't try to handle exotic cases allowed by the SHACL spec, such as combinations of sh:in and sh:node. Instead we assume
7
- * a shape has one type.
8
- */
9
- export function transformPropertyShapeToAstType(shape, inherited) {
10
- // Try to transform the property shape into an AST type without cardinality constraints
11
- return this.transformPropertyShapeToAstCompositeType(shape, inherited)
12
- .altLazy(() => this.transformPropertyShapeToAstIdentifierType(shape, inherited))
13
- .altLazy(() => this.transformPropertyShapeToAstLiteralType(shape, inherited))
14
- .altLazy(() => this.transformPropertyShapeToAstTermType(shape, inherited))
15
- .map((itemType) => {
16
- // Handle cardinality constraints
17
- if ((shape instanceof input.PropertyShape && shape.defaultValue.isJust()) ||
18
- inherited?.defaultValue.isJust()) {
19
- // Ignore other cardinality constraints if there's a default value and treat the type as minCount=maxCount=1
20
- return itemType;
21
- }
22
- const maxCount = shape.constraints.maxCount;
23
- const minCount = shape.constraints.minCount;
24
- if (maxCount.isNothing() && minCount.isNothing()) {
25
- // The shape has no cardinality constraints
26
- if (inherited === null) {
27
- // The shape is top-level (not an sh:xone/sh:and of a top-level shape)
28
- // Treat it as a Set, the default in RDF.
29
- // We want Set to be the outermost type unless it's explicitly requested with sh:minCount 0.
30
- return {
31
- itemType,
32
- kind: "SetType",
33
- mutable: shape.mutable,
34
- minCount: 0,
35
- };
36
- }
37
- // else the shape is not top-level
38
- // We want Set to be the outermost type, so just return the itemType here
39
- return itemType;
40
- }
41
- if (minCount.orDefault(0) === 0 && maxCount.extractNullable() === 1) {
42
- return {
43
- itemType,
44
- kind: "OptionType",
45
- };
46
- }
47
- if (minCount.orDefault(0) === 1 && maxCount.extractNullable() === 1) {
48
- return itemType;
49
- }
50
- invariant(minCount.isJust() || maxCount.isJust());
51
- // There are cardinality constraints for a Set. It may be an inner type.
52
- return {
53
- itemType,
54
- kind: "SetType",
55
- minCount: minCount.orDefault(0),
56
- mutable: shape.mutable,
57
- };
58
- });
59
- }
60
- //# sourceMappingURL=transformPropertyShapeToAstType.js.map