@shaclmate/compiler 4.0.96 → 4.0.98

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 (114) hide show
  1. package/dist/_ShapesGraphToAstTransformer/synthesizePartialAstStructType.d.ts +6 -0
  2. package/dist/_ShapesGraphToAstTransformer/synthesizePartialAstStructType.js +38 -0
  3. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstStructTypeField.js +114 -145
  4. package/dist/_ShapesGraphToAstTransformer/transformShapeNodeConstraintToAstType.d.ts +7 -0
  5. package/dist/_ShapesGraphToAstTransformer/transformShapeNodeConstraintToAstType.js +13 -0
  6. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstStructType.d.ts +1 -1
  7. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstStructType.js +0 -52
  8. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstType.js +2 -0
  9. package/dist/ast/StructCompoundType.d.ts +3 -2
  10. package/dist/ast/StructCompoundType.js +29 -46
  11. package/dist/ast/StructDiscriminatedUnionType.d.ts +5 -1
  12. package/dist/ast/StructIntersectionType.d.ts +4 -1
  13. package/dist/generators/ts/AbstractLazyType.js +4 -4
  14. package/dist/generators/ts/AbstractStructuredType.js +2 -2
  15. package/dist/generators/ts/Imports.d.ts +1 -0
  16. package/dist/generators/ts/Imports.js +1 -0
  17. package/dist/generators/ts/IriType.js +13 -3
  18. package/dist/generators/ts/ObjectDiscriminatedUnionType.d.ts +7 -4
  19. package/dist/generators/ts/ObjectDiscriminatedUnionType.js +18 -2
  20. package/dist/generators/ts/ObjectIntersectionType.d.ts +7 -4
  21. package/dist/generators/ts/RdfjsDatasetObjectSetType.js +21 -10
  22. package/dist/generators/ts/Snippets.d.ts +7 -6
  23. package/dist/generators/ts/Snippets.js +41 -34
  24. package/dist/generators/ts/TypeFactory.js +19 -33
  25. package/dist/generators/ts/_ObjectIntersectionType/ObjectIntersectionType_fromJsonObjectFunction.js +1 -1
  26. package/dist/generators/ts/_ObjectType/ObjectType_IdentifierProperty.js +1 -1
  27. package/dist/generators/ts/_ObjectType/ObjectType_fromJsonObjectFunction.js +7 -2
  28. package/dist/generators/ts/_ObjectType/ObjectType_toJsonObjectFunction.js +1 -1
  29. package/dist/generators/ts/_snippets/snippets_FromJsonFunction.d.ts +3 -0
  30. package/dist/generators/ts/_snippets/snippets_FromJsonFunction.js +28 -0
  31. package/dist/generators/ts/_snippets/snippets_ToJsonFunction.d.ts +3 -0
  32. package/dist/generators/ts/_snippets/snippets_ToJsonFunction.js +3 -0
  33. package/dist/generators/ts/_snippets/snippets_arrayFromJsonArray.js +1 -1
  34. package/dist/generators/ts/_snippets/snippets_arrayToJsonArray.js +1 -1
  35. package/dist/generators/ts/_snippets/snippets_bigDecimalFromJsonObject.js +1 -1
  36. package/dist/generators/ts/_snippets/snippets_bigDecimalFromJsonString.js +1 -1
  37. package/dist/generators/ts/_snippets/snippets_bigDecimalToJsonObject.js +1 -1
  38. package/dist/generators/ts/_snippets/snippets_bigDecimalToJsonString.js +1 -1
  39. package/dist/generators/ts/_snippets/snippets_bigIntFromJsonObject.js +1 -1
  40. package/dist/generators/ts/_snippets/snippets_bigIntFromJsonString.js +1 -1
  41. package/dist/generators/ts/_snippets/snippets_bigIntToJsonObject.js +1 -1
  42. package/dist/generators/ts/_snippets/snippets_bigIntToJsonString.js +1 -1
  43. package/dist/generators/ts/_snippets/snippets_blankNodeFromJsonObject.js +1 -1
  44. package/dist/generators/ts/_snippets/snippets_blankNodeFromJsonString.js +1 -1
  45. package/dist/generators/ts/_snippets/snippets_blankNodeToJsonObject.js +1 -1
  46. package/dist/generators/ts/_snippets/snippets_blankNodeToJsonString.js +1 -1
  47. package/dist/generators/ts/_snippets/snippets_booleanFromJsonBoolean.js +1 -1
  48. package/dist/generators/ts/_snippets/snippets_booleanFromJsonObject.js +1 -1
  49. package/dist/generators/ts/_snippets/snippets_convertToIdentifier.js +1 -1
  50. package/dist/generators/ts/_snippets/snippets_convertToIdentifierProperty.js +2 -4
  51. package/dist/generators/ts/_snippets/snippets_convertToIri.js +1 -1
  52. package/dist/generators/ts/_snippets/snippets_convertToIriIdentifierProperty.js +1 -2
  53. package/dist/generators/ts/_snippets/snippets_convertToIriLiteral.d.ts +3 -0
  54. package/dist/generators/ts/_snippets/snippets_convertToIriLiteral.js +11 -0
  55. package/dist/generators/ts/_snippets/snippets_convertToIriLiteralIdentifierProperty.d.ts +3 -0
  56. package/dist/generators/ts/_snippets/snippets_convertToIriLiteralIdentifierProperty.js +17 -0
  57. package/dist/generators/ts/_snippets/snippets_dateFromJsonObject.js +1 -1
  58. package/dist/generators/ts/_snippets/snippets_dateFromJsonString.js +1 -1
  59. package/dist/generators/ts/_snippets/snippets_dateTimeFromJsonObject.js +1 -1
  60. package/dist/generators/ts/_snippets/snippets_dateTimeToJsonString.js +1 -1
  61. package/dist/generators/ts/_snippets/snippets_dateToJsonObject.js +1 -1
  62. package/dist/generators/ts/_snippets/snippets_dateToJsonString.js +1 -1
  63. package/dist/generators/ts/_snippets/snippets_defaultValueFromJsonObject.js +1 -1
  64. package/dist/generators/ts/_snippets/snippets_defaultValueFromJsonValue.js +1 -1
  65. package/dist/generators/ts/_snippets/snippets_floatFromJsonNumber.js +1 -1
  66. package/dist/generators/ts/_snippets/snippets_floatFromJsonObject.js +1 -1
  67. package/dist/generators/ts/_snippets/snippets_identifierFromJsonObject.js +1 -1
  68. package/dist/generators/ts/_snippets/snippets_identifierFromJsonString.js +1 -1
  69. package/dist/generators/ts/_snippets/snippets_identifierToJsonObject.js +1 -1
  70. package/dist/generators/ts/_snippets/snippets_identifierToJsonString.js +1 -1
  71. package/dist/generators/ts/_snippets/snippets_intFromJsonNumber.js +1 -1
  72. package/dist/generators/ts/_snippets/snippets_intFromJsonObject.js +1 -1
  73. package/dist/generators/ts/_snippets/snippets_iriFromJsonObject.js +1 -1
  74. package/dist/generators/ts/_snippets/snippets_iriFromJsonString.js +2 -2
  75. package/dist/generators/ts/_snippets/snippets_iriFromString.d.ts +3 -0
  76. package/dist/generators/ts/_snippets/snippets_iriFromString.js +76 -0
  77. package/dist/generators/ts/_snippets/snippets_iriLiteralFromJsonObject.d.ts +3 -0
  78. package/dist/generators/ts/_snippets/snippets_iriLiteralFromJsonObject.js +6 -0
  79. package/dist/generators/ts/_snippets/snippets_iriLiteralFromJsonString.d.ts +3 -0
  80. package/dist/generators/ts/_snippets/snippets_iriLiteralFromJsonString.js +6 -0
  81. package/dist/generators/ts/_snippets/snippets_langStringFromJsonObject.js +1 -1
  82. package/dist/generators/ts/_snippets/snippets_langStringToJsonObject.js +1 -1
  83. package/dist/generators/ts/_snippets/snippets_listFromJsonObject.js +1 -1
  84. package/dist/generators/ts/_snippets/snippets_listToJsonObject.js +1 -1
  85. package/dist/generators/ts/_snippets/snippets_literalFromJsonObject.js +1 -1
  86. package/dist/generators/ts/_snippets/snippets_literalToJsonObject.js +1 -1
  87. package/dist/generators/ts/_snippets/snippets_maybeFromJsonObject.js +1 -1
  88. package/dist/generators/ts/_snippets/snippets_maybeFromJsonValue.js +1 -1
  89. package/dist/generators/ts/_snippets/snippets_maybeToJsonObject.js +1 -1
  90. package/dist/generators/ts/_snippets/snippets_maybeToJsonValue.js +1 -1
  91. package/dist/generators/ts/_snippets/snippets_primitiveToJsonObject.js +1 -1
  92. package/dist/generators/ts/_snippets/snippets_stringFromJsonObject.js +1 -1
  93. package/dist/generators/ts/_snippets/snippets_stringFromJsonString.js +1 -1
  94. package/dist/generators/ts/_snippets/snippets_termFromJsonObject.js +1 -1
  95. package/dist/generators/ts/_snippets/snippets_termToJsonObject.js +1 -1
  96. package/dist/generators/ts/_snippets/snippets_typedLiteralToJsonObject.js +1 -1
  97. package/dist/input/input.shaclmate.d.ts +2474 -2124
  98. package/dist/input/input.shaclmate.js +558 -1292
  99. package/dist/input/input.shaclmate.ttl +9 -5
  100. package/package.json +20 -16
  101. package/dist/generators/ts/_ObjectDiscriminatedUnionType/ObjectDiscriminatedUnionType_schemaExpression.d.ts +0 -4
  102. package/dist/generators/ts/_ObjectDiscriminatedUnionType/ObjectDiscriminatedUnionType_schemaExpression.js +0 -37
  103. package/dist/generators/ts/_snippets/snippets_FromJsonObjectFunction.d.ts +0 -3
  104. package/dist/generators/ts/_snippets/snippets_FromJsonObjectFunction.js +0 -21
  105. package/dist/generators/ts/_snippets/snippets_FromJsonValueFunction.d.ts +0 -3
  106. package/dist/generators/ts/_snippets/snippets_FromJsonValueFunction.js +0 -21
  107. package/dist/generators/ts/_snippets/snippets_ToJsonObjectFunction.d.ts +0 -3
  108. package/dist/generators/ts/_snippets/snippets_ToJsonObjectFunction.js +0 -3
  109. package/dist/generators/ts/_snippets/snippets_ToJsonValueFunction.d.ts +0 -3
  110. package/dist/generators/ts/_snippets/snippets_ToJsonValueFunction.js +0 -3
  111. package/dist/generators/ts/_snippets/snippets_convertToInIri.d.ts +0 -3
  112. package/dist/generators/ts/_snippets/snippets_convertToInIri.js +0 -11
  113. package/dist/generators/ts/_snippets/snippets_convertToInIriIdentifierProperty.d.ts +0 -3
  114. package/dist/generators/ts/_snippets/snippets_convertToInIriIdentifierProperty.js +0 -17
@@ -0,0 +1,6 @@
1
+ import * as ast from "../ast/index.js";
2
+ import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
3
+ export declare function synthesizePartialAstStructType(this: ShapesGraphToAstTransformer, { identifierType, }: {
4
+ identifierType: ast.IdentifierType | ast.IriType;
5
+ }): ast.StructType;
6
+ //# sourceMappingURL=synthesizePartialAstStructType.d.ts.map
@@ -0,0 +1,38 @@
1
+ import dataFactory from "@rdfx/data-factory";
2
+ import { Maybe } from "purify-ts";
3
+ import * as ast from "../ast/index.js";
4
+ export function synthesizePartialAstStructType({ identifierType, }) {
5
+ let syntheticName;
6
+ switch (identifierType.kind) {
7
+ case "Identifier":
8
+ syntheticName = "DefaultPartial";
9
+ break;
10
+ case "Iri":
11
+ syntheticName = "NamedDefaultPartial";
12
+ break;
13
+ }
14
+ let partialAstStructType = this.syntheticAstStructTypes.find((syntheticAstStructType) => syntheticAstStructType.name.extract() === syntheticName &&
15
+ ast.Type.equals(syntheticAstStructType.identifierType, identifierType));
16
+ if (partialAstStructType) {
17
+ return partialAstStructType;
18
+ }
19
+ partialAstStructType = new ast.StructType({
20
+ comment: Maybe.empty(),
21
+ extern: false,
22
+ fromRdfType: Maybe.empty(),
23
+ identifierType,
24
+ label: Maybe.empty(),
25
+ name: Maybe.of(syntheticName),
26
+ shapeIdentifier: dataFactory.namedNode(`urn:shaclmate:synthetic:${syntheticName}`),
27
+ synthetic: true,
28
+ toRdfTypes: [],
29
+ tsImports: [],
30
+ });
31
+ partialAstStructType.addField(new ast.StructType.IdentifierField({
32
+ structType: partialAstStructType,
33
+ type: identifierType,
34
+ }));
35
+ this.syntheticAstStructTypes.push(partialAstStructType);
36
+ return partialAstStructType;
37
+ }
38
+ //# sourceMappingURL=synthesizePartialAstStructType.js.map
@@ -1,11 +1,11 @@
1
1
  import { Curie } from "@rdfx/curie";
2
- import dataFactory from "@rdfx/data-factory";
3
2
  import { sh } from "@tpluscode/rdf-ns-builders";
4
3
  import { Either, Left, Maybe } from "purify-ts";
5
4
  import { invariant } from "ts-invariant";
6
5
  import * as ast from "../ast/index.js";
7
6
  import { Eithers } from "../Eithers.js";
8
7
  import { ShapeStack } from "./ShapeStack.js";
8
+ import { synthesizePartialAstStructType } from "./synthesizePartialAstStructType.js";
9
9
  import { transformShapeToAstType } from "./transformShapeToAstType.js";
10
10
  function fieldName(propertyShape, structType) {
11
11
  // Explicit shaclmate:name or sh:name
@@ -62,41 +62,7 @@ function propertyCardinality(propertyShape) {
62
62
  }
63
63
  return { maxCount, minCount };
64
64
  }
65
- function synthesizePartialAstStructType({ identifierType, }) {
66
- let syntheticName;
67
- switch (identifierType.kind) {
68
- case "Identifier":
69
- syntheticName = "DefaultPartial";
70
- break;
71
- case "Iri":
72
- syntheticName = "NamedDefaultPartial";
73
- break;
74
- }
75
- let partialAstStructType = this.syntheticAstStructTypes.find((syntheticAstStructType) => syntheticAstStructType.name.extract() === syntheticName &&
76
- ast.Type.equals(syntheticAstStructType.identifierType, identifierType));
77
- if (partialAstStructType) {
78
- return partialAstStructType;
79
- }
80
- partialAstStructType = new ast.StructType({
81
- comment: Maybe.empty(),
82
- extern: false,
83
- fromRdfType: Maybe.empty(),
84
- identifierType,
85
- label: Maybe.empty(),
86
- name: Maybe.of(syntheticName),
87
- shapeIdentifier: dataFactory.namedNode(`urn:shaclmate:synthetic:${syntheticName}`),
88
- synthetic: true,
89
- toRdfTypes: [],
90
- tsImports: [],
91
- });
92
- partialAstStructType.addField(new ast.StructType.IdentifierField({
93
- structType: partialAstStructType,
94
- type: identifierType,
95
- }));
96
- this.syntheticAstStructTypes.push(partialAstStructType);
97
- return partialAstStructType;
98
- }
99
- function transformPropertyShapeToAstType(propertyShape, shapeStack) {
65
+ function transformPropertyShapeToAstCardinalityType(propertyShape, shapeStack) {
100
66
  // if (
101
67
  // propertyShape.path.kind === "PredicatePath" &&
102
68
  // propertyShape.path.iri.value.endsWith("termProperty")
@@ -136,102 +102,78 @@ function transformPropertyShapeToAstType(propertyShape, shapeStack) {
136
102
  }));
137
103
  });
138
104
  }
139
- /**
140
- * Try to transform a property shape to an ast.StructType.Field.
141
- *
142
- * Returns:
143
- * - Right<Just<ast.StructType.Field>> if the transformation succeeds
144
- * - Right<Nothing> if the property shape should be ignored
145
- * - Left<Error> if the transformation fails
146
- */
147
- export function transformPropertyShapeToAstStructTypeField({ propertyShape, structType, }) {
148
- if (propertyShape.ignore) {
105
+ function transformPropertyShapeToAstLazyType({ propertyShape, propertyShapeAstCardinalityType, shapeStack, }) {
106
+ if (propertyShape.resolve.isNothing()) {
149
107
  return Either.of(Maybe.empty());
150
108
  }
151
- switch (propertyShape.severity.orDefault(sh.Violation).value) {
152
- case "http://www.w3.org/ns/shacl#Info":
153
- case "http://www.w3.org/ns/shacl#Warning":
154
- return Either.of(Maybe.empty());
155
- }
156
- const shapeStack = new ShapeStack(); // Start a new ShapeStack per property shape
157
- return Eithers.chain2(propertyShape.resolve.isJust()
158
- ? this.shapesGraph
159
- .nodeShape(propertyShape.resolve.extract())
160
- .map(Maybe.of)
161
- : Either.of(Maybe.empty()), transformPropertyShapeToAstType.call(this, propertyShape, shapeStack)).chain(([propertyShapeResolve, astType]) => {
162
- let astResolveItemType;
163
- if (propertyShapeResolve.isJust()) {
164
- const astResolveTypeEither = transformShapeToAstType
165
- .call(this, propertyShapeResolve.unsafeCoerce(), shapeStack)
166
- .chain((astResolveType) => {
167
- switch (astResolveType.kind) {
168
- case "Struct":
169
- return Either.of(astResolveType);
170
- case "DiscriminatedUnion":
171
- if (
172
- // This check relies on .members being populated, which may not happen in cycles
173
- astResolveType.members.length > 0 &&
174
- !astResolveType.isStructDiscriminatedUnionType()) {
175
- return Left(new Error(`${propertyShape} resolve cannot refer to a ${astResolveType.kind} with non-StructType members`));
176
- }
177
- return Either.of(astResolveType);
178
- default:
179
- return Left(new Error(`${propertyShape} resolve cannot refer to a ${astResolveType.kind}`));
180
- }
181
- });
182
- if (astResolveTypeEither.isLeft()) {
183
- return astResolveTypeEither;
184
- }
185
- astResolveItemType = astResolveTypeEither.unsafeCoerce();
186
- }
187
- if (astResolveItemType) {
188
- let astItemType;
189
- switch (astType.kind) {
190
- case "DefaultValue":
191
- case "Option":
192
- case "Set":
193
- astItemType = astType.itemType;
194
- break;
195
- case "LazyOption":
196
- case "LazySet":
197
- // biome-ignore lint/suspicious/noFallthroughSwitchClause: break is unreachable
198
- case "Lazy":
199
- invariant(false, `lazy types should not appear here: ${astType.kind}`);
200
- default:
201
- astItemType = astType;
202
- break;
203
- }
204
- let astPartialItemType;
205
- switch (astItemType.kind) {
206
- case "Identifier":
207
- case "Iri":
208
- astPartialItemType = synthesizePartialAstStructType.call(this, {
209
- identifierType: astItemType,
210
- });
211
- break;
109
+ return this.shapesGraph
110
+ .nodeShape(propertyShape.resolve.extract())
111
+ .chain((resolveNodeShape) => {
112
+ const resolveAstItemTypeEither = transformShapeToAstType
113
+ .call(this, resolveNodeShape, shapeStack)
114
+ .chain((resolveAstItemType) => {
115
+ switch (resolveAstItemType.kind) {
212
116
  case "Struct":
213
- astPartialItemType = astItemType;
214
- break;
117
+ return Either.of(resolveAstItemType);
215
118
  case "DiscriminatedUnion":
216
- if (!astItemType.isStructDiscriminatedUnionType()) {
217
- return Left(new Error(`${propertyShape} partial type cannot be a ${astItemType.kind} with non-StructType members`));
119
+ if (
120
+ // This check relies on .members being populated, which may not happen in cycles
121
+ resolveAstItemType.members.length > 0 &&
122
+ !resolveAstItemType.isStructDiscriminatedUnionType()) {
123
+ return Left(new Error(`${propertyShape} resolve cannot refer to a ${resolveAstItemType.kind} with non-StructType members`));
218
124
  }
219
- astPartialItemType = astItemType;
220
- break;
125
+ return Either.of(resolveAstItemType);
221
126
  default:
222
- return Left(new Error(`${propertyShape} has a resolve with an incompatible partial type ${astItemType.kind}`));
127
+ return Left(new Error(`${propertyShape} resolve cannot refer to a ${resolveAstItemType.kind}`));
223
128
  }
224
- const astPartialItemIdentifierType = astPartialItemType.kind === "Struct"
225
- ? astPartialItemType.identifierType
226
- : ast.StructCompoundType.identifierType(astPartialItemType);
227
- const astResolveItemIdentifierType = astResolveItemType.kind === "Struct"
228
- ? astResolveItemType.identifierType
229
- : ast.StructCompoundType.identifierType(astResolveItemType);
230
- if (astPartialItemIdentifierType.kind !== astResolveItemIdentifierType.kind) {
231
- return Left(new Error(`${propertyShape} has a resolve with a different identifier type (${astResolveItemIdentifierType.kind}) than the partial's identifier type (${astPartialItemIdentifierType.kind})`));
129
+ });
130
+ if (resolveAstItemTypeEither.isLeft()) {
131
+ return resolveAstItemTypeEither;
132
+ }
133
+ const resolveAstItemType = resolveAstItemTypeEither.unsafeCoerce();
134
+ let propertyShapeAstItemType;
135
+ switch (propertyShapeAstCardinalityType.kind) {
136
+ case "DefaultValue":
137
+ case "Option":
138
+ case "Set":
139
+ propertyShapeAstItemType = propertyShapeAstCardinalityType.itemType;
140
+ break;
141
+ case "LazyOption":
142
+ case "LazySet":
143
+ // biome-ignore lint/suspicious/noFallthroughSwitchClause: break is unreachable
144
+ case "Lazy":
145
+ invariant(false, `lazy types should not appear here: ${propertyShapeAstCardinalityType.kind}`);
146
+ default:
147
+ propertyShapeAstItemType = propertyShapeAstCardinalityType;
148
+ break;
149
+ }
150
+ let partialAstItemType;
151
+ switch (propertyShapeAstItemType.kind) {
152
+ case "Identifier":
153
+ case "Iri":
154
+ partialAstItemType = synthesizePartialAstStructType.call(this, {
155
+ identifierType: propertyShapeAstItemType,
156
+ });
157
+ break;
158
+ case "Struct":
159
+ partialAstItemType = propertyShapeAstItemType;
160
+ break;
161
+ case "DiscriminatedUnion":
162
+ if (!propertyShapeAstItemType.isStructDiscriminatedUnionType()) {
163
+ return Left(new Error(`${propertyShape} partial type cannot be a ${propertyShapeAstItemType.kind} with non-StructType members`));
164
+ }
165
+ partialAstItemType = propertyShapeAstItemType;
166
+ break;
167
+ default:
168
+ return Left(new Error(`${propertyShape} has a resolve with an incompatible partial type ${propertyShapeAstItemType.kind}`));
169
+ }
170
+ return Eithers.chain2(ast.StructCompoundType.identifierType(partialAstItemType), ast.StructCompoundType.identifierType(resolveAstItemType)).chain(([partialAstItemIdentifierType, resolveAstItemIdentifierType]) => {
171
+ if (partialAstItemIdentifierType.kind !==
172
+ resolveAstItemIdentifierType.kind) {
173
+ return Left(new Error(`${propertyShape} has a resolve with a different identifier type (${resolveAstItemIdentifierType.kind}) than the partial's identifier type (${partialAstItemIdentifierType.kind})`));
232
174
  }
233
- if (astPartialItemIdentifierType.kind === "BlankNode") {
234
- return Left(new Error(`${propertyShape} has a ${astPartialItemIdentifierType.kind} identifier type, which is incompatible with shaclmate:resolve`));
175
+ if (partialAstItemIdentifierType.kind === "BlankNode") {
176
+ return Left(new Error(`${propertyShape} has a ${partialAstItemIdentifierType.kind} identifier type, which is incompatible with shaclmate:resolve`));
235
177
  }
236
178
  const astAbstractTypeProperties = {
237
179
  comment: Maybe.empty(),
@@ -239,50 +181,77 @@ export function transformPropertyShapeToAstStructTypeField({ propertyShape, stru
239
181
  name: Maybe.empty(),
240
182
  shapeIdentifier: propertyShape.$identifier(),
241
183
  };
242
- switch (astType.kind) {
184
+ switch (propertyShapeAstCardinalityType.kind) {
243
185
  case "BlankNode":
244
186
  case "Identifier":
245
187
  case "Iri":
246
188
  case "Struct":
247
189
  case "DiscriminatedUnion":
248
- astType = new ast.LazyType({
190
+ return Either.of(Maybe.of(new ast.LazyType({
249
191
  ...astAbstractTypeProperties,
250
- partialType: astPartialItemType,
251
- resolveType: astResolveItemType,
252
- });
253
- break;
192
+ partialType: partialAstItemType,
193
+ resolveType: resolveAstItemType,
194
+ })));
254
195
  case "Option":
255
- astType = new ast.LazyOptionType({
196
+ return Either.of(Maybe.of(new ast.LazyOptionType({
256
197
  ...astAbstractTypeProperties,
257
198
  partialType: new ast.OptionType({
258
- itemType: astPartialItemType,
199
+ itemType: partialAstItemType,
259
200
  }),
260
201
  resolveType: new ast.OptionType({
261
- itemType: astResolveItemType,
202
+ itemType: resolveAstItemType,
262
203
  }),
263
- });
264
- break;
204
+ })));
265
205
  case "Set":
266
- astType = new ast.LazySetType({
206
+ return Either.of(Maybe.of(new ast.LazySetType({
267
207
  ...astAbstractTypeProperties,
268
208
  partialType: new ast.SetType({
269
- itemType: astPartialItemType,
209
+ itemType: partialAstItemType,
270
210
  minCount: 0n,
271
211
  mutable: false,
272
212
  }),
273
213
  resolveType: new ast.SetType({
274
- itemType: astResolveItemType,
214
+ itemType: resolveAstItemType,
275
215
  minCount: 0n,
276
216
  mutable: false,
277
217
  }),
278
- });
279
- break;
218
+ })));
280
219
  default:
281
- invariant(false, `unexpected lazy AST type ${astType.kind}`);
220
+ invariant(false, `unexpected lazy AST type ${propertyShapeAstCardinalityType.kind}`);
282
221
  }
283
- }
222
+ });
223
+ });
224
+ }
225
+ /**
226
+ * Try to transform a property shape to an ast.StructType.Field.
227
+ *
228
+ * Returns:
229
+ * - Right<Just<ast.StructType.Field>> if the transformation succeeds
230
+ * - Right<Nothing> if the property shape should be ignored
231
+ * - Left<Error> if the transformation fails
232
+ */
233
+ export function transformPropertyShapeToAstStructTypeField({ propertyShape, structType, }) {
234
+ if (propertyShape.ignore) {
235
+ return Either.of(Maybe.empty());
236
+ }
237
+ switch (propertyShape.severity.orDefault(sh.Violation).value) {
238
+ case "http://www.w3.org/ns/shacl#Info":
239
+ case "http://www.w3.org/ns/shacl#Warning":
240
+ return Either.of(Maybe.empty());
241
+ }
242
+ const shapeStack = new ShapeStack(); // Start a new ShapeStack per property shape
243
+ return transformPropertyShapeToAstCardinalityType
244
+ .call(this, propertyShape, shapeStack)
245
+ .chain((propertyShapeAstCardinalityType) => transformPropertyShapeToAstLazyType
246
+ .call(this, {
247
+ propertyShape,
248
+ propertyShapeAstCardinalityType,
249
+ shapeStack,
250
+ })
251
+ .chain((propertyShapeAstLazyType) => {
252
+ const propertyShapeAstType = propertyShapeAstLazyType.orDefault(propertyShapeAstCardinalityType);
284
253
  if (propertyShape.path.termType === "InversePath" &&
285
- astType.nodeKinds.has("Literal")) {
254
+ propertyShapeAstType.nodeKinds.has("Literal")) {
286
255
  return Left(new Error(`${propertyShape}: property shapes with inverse paths can only have blank node or IRI node kinds`));
287
256
  }
288
257
  return Either.of(Maybe.of(new ast.StructType.ShaclField({
@@ -297,8 +266,8 @@ export function transformPropertyShapeToAstStructTypeField({ propertyShape, stru
297
266
  path: propertyShape.path,
298
267
  shapeIdentifier: propertyShape.$identifier(),
299
268
  structType,
300
- type: astType,
269
+ type: propertyShapeAstType,
301
270
  })));
302
- });
271
+ }));
303
272
  }
304
273
  //# sourceMappingURL=transformPropertyShapeToAstStructTypeField.js.map
@@ -0,0 +1,7 @@
1
+ import { Either, Maybe } from "purify-ts";
2
+ import type * as ast from "../ast/index.js";
3
+ import type * as input from "../input/index.js";
4
+ import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
5
+ import type { ShapeStack } from "./ShapeStack.js";
6
+ export declare function transformShapeNodeConstraintToAstType(this: ShapesGraphToAstTransformer, shape: input.UndiscriminatedShape, shapeStack: ShapeStack): Either<Error, Maybe<ast.Type>>;
7
+ //# sourceMappingURL=transformShapeNodeConstraintToAstType.d.ts.map
@@ -0,0 +1,13 @@
1
+ import { Either, Maybe } from "purify-ts";
2
+ import { transformShapeToAstType } from "./transformShapeToAstType.js";
3
+ export function transformShapeNodeConstraintToAstType(shape, shapeStack) {
4
+ // If the shape has an sh:node itself then transform that instead
5
+ if (shape.node.isJust()) {
6
+ return this.shapesGraph
7
+ .nodeShape(shape.node.unsafeCoerce())
8
+ .chain((nodeShape) => transformShapeToAstType.call(this, nodeShape, shapeStack))
9
+ .map(Maybe.of);
10
+ }
11
+ return Either.of(Maybe.empty());
12
+ }
13
+ //# sourceMappingURL=transformShapeNodeConstraintToAstType.js.map
@@ -3,5 +3,5 @@ import * as ast from "../ast/index.js";
3
3
  import type * as input from "../input/index.js";
4
4
  import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
5
5
  import type { ShapeStack } from "./ShapeStack.js";
6
- export declare function transformShapeToAstStructType(this: ShapesGraphToAstTransformer, shape: input.UndiscriminatedShape, shapeStack: ShapeStack): Either<Error, Maybe<ast.Type>>;
6
+ export declare function transformShapeToAstStructType(this: ShapesGraphToAstTransformer, shape: input.UndiscriminatedShape, shapeStack: ShapeStack): Either<Error, Maybe<ast.StructType>>;
7
7
  //# sourceMappingURL=transformShapeToAstStructType.d.ts.map
@@ -8,46 +8,6 @@ import { isNodeShape } from "./isNodeShape.js";
8
8
  import { shapeAstTypeName } from "./shapeAstTypeName.js";
9
9
  import { shapeNodeKinds } from "./shapeNodeKinds.js";
10
10
  import { transformPropertyShapeToAstStructTypeField } from "./transformPropertyShapeToAstStructTypeField.js";
11
- import { transformShapeToAstType } from "./transformShapeToAstType.js";
12
- function isStructTypeFieldRequired(field) {
13
- switch (field.kind) {
14
- case "Identifier":
15
- return field.type.kind === "Iri";
16
- case "Shacl": {
17
- switch (field.type.kind) {
18
- case "DiscriminatedUnion":
19
- return field.type.members.every((member) => isStructTypeFieldRequired({ kind: "Shacl", type: member.type }));
20
- case "DefaultValue":
21
- return false;
22
- case "Intersection":
23
- return field.type.members.every((member) => isStructTypeFieldRequired({ kind: "Shacl", type: member.type }));
24
- case "LazyOption":
25
- return false;
26
- case "LazySet":
27
- return field.type.partialType.minCount > 0n;
28
- case "Option":
29
- return false;
30
- case "Set":
31
- return field.type.minCount > 0;
32
- case "BlankNode":
33
- case "Identifier":
34
- case "Iri":
35
- case "Lazy":
36
- case "List":
37
- case "Literal":
38
- case "Struct":
39
- case "Term":
40
- return true;
41
- default:
42
- field.type;
43
- throw new Error("should never reach this point");
44
- }
45
- }
46
- default:
47
- field.kind;
48
- throw new Error("should never reach this point");
49
- }
50
- }
51
11
  function transformNodeShapeNodeKindsToAstIdentifierType(nodeKinds, nodeShape) {
52
12
  const identifierTypeProperties = {
53
13
  comment: Maybe.empty(),
@@ -79,13 +39,6 @@ function transformNodeShapeNodeKindsToAstIdentifierType(nodeKinds, nodeShape) {
79
39
  export function transformShapeToAstStructType(shape, shapeStack) {
80
40
  shapeStack.push(shape);
81
41
  try {
82
- // If the shape has an sh:node itself then transform that instead
83
- if (shape.node.isJust()) {
84
- return this.shapesGraph
85
- .nodeShape(shape.node.unsafeCoerce())
86
- .chain((nodeShape) => transformShapeToAstType.call(this, nodeShape, shapeStack))
87
- .map(Maybe.of);
88
- }
89
42
  if (!isNodeShape(shape)) {
90
43
  return Either.of(Maybe.empty());
91
44
  }
@@ -173,11 +126,6 @@ export function transformShapeToAstStructType(shape, shapeStack) {
173
126
  return fieldEither;
174
127
  }
175
128
  }
176
- if (!structType.extern &&
177
- structType.fromRdfType.isNothing() &&
178
- !structType.fields.some(isStructTypeFieldRequired)) {
179
- return Left(new Error(`${nodeShape} has no required properties and no implicitly required rdf:type`));
180
- }
181
129
  structType.sortFields();
182
130
  return Either.of(Maybe.of(structType));
183
131
  })().ifLeft(() => {
@@ -1,4 +1,5 @@
1
1
  import { Either, Left } from "purify-ts";
2
+ import { transformShapeNodeConstraintToAstType } from "./transformShapeNodeConstraintToAstType.js";
2
3
  import { transformShapeToAstCompoundType } from "./transformShapeToAstCompoundType.js";
3
4
  import { transformShapeToAstListType } from "./transformShapeToAstListType.js";
4
5
  import { transformShapeToAstStructType } from "./transformShapeToAstStructType.js";
@@ -6,6 +7,7 @@ import { transformShapeToAstTermType } from "./transformShapeToAstTermType.js";
6
7
  const tryTransformShapeToAstTypeMethods = [
7
8
  transformShapeToAstListType, // List type must be before compound type since a list shape uses sh:xone
8
9
  transformShapeToAstCompoundType,
10
+ transformShapeNodeConstraintToAstType,
9
11
  transformShapeToAstStructType,
10
12
  ];
11
13
  /**
@@ -1,3 +1,4 @@
1
+ import { Either } from "purify-ts";
1
2
  import { BlankNodeType } from "./BlankNodeType.js";
2
3
  import { IdentifierType } from "./IdentifierType.js";
3
4
  import { IriType } from "./IriType.js";
@@ -6,7 +7,7 @@ import type { StructIntersectionType } from "./StructIntersectionType.js";
6
7
  import type { StructType } from "./StructType.js";
7
8
  export type StructCompoundType = StructIntersectionType | StructDiscriminatedUnionType;
8
9
  export declare namespace StructCompoundType {
9
- function identifierType(structCompoundType: StructCompoundType): BlankNodeType | IdentifierType | IriType;
10
- function memberStructTypes(objectCompoundType: StructCompoundType): readonly StructType[];
10
+ function hasIdentifierField(structCompoundType: StructCompoundType | StructType): boolean;
11
+ function identifierType(structCompoundType: StructCompoundType | StructType): Either<Error, BlankNodeType | IdentifierType | IriType>;
11
12
  }
12
13
  //# sourceMappingURL=StructCompoundType.d.ts.map
@@ -1,87 +1,70 @@
1
1
  import { TermSet } from "@rdfx/collection";
2
- import { Maybe } from "purify-ts";
2
+ import { Either, Maybe } from "purify-ts";
3
3
  import { invariant } from "ts-invariant";
4
4
  import { BlankNodeType } from "./BlankNodeType.js";
5
5
  import { IdentifierType } from "./IdentifierType.js";
6
6
  import { IriType } from "./IriType.js";
7
7
  export var StructCompoundType;
8
8
  (function (StructCompoundType) {
9
+ function hasIdentifierField(structCompoundType) {
10
+ if (structCompoundType.kind === "Struct") {
11
+ return structCompoundType.identifierField.isJust();
12
+ }
13
+ return structCompoundType.members.every((member) => hasIdentifierField(member.type));
14
+ }
15
+ StructCompoundType.hasIdentifierField = hasIdentifierField;
9
16
  function identifierType(structCompoundType) {
17
+ if (structCompoundType.kind === "Struct") {
18
+ return Either.of(structCompoundType.identifierType);
19
+ }
10
20
  const memberIdentifierTypeNodeKinds = new Set();
11
21
  const memberIdentifierTypesIn = new TermSet();
12
- for (const memberType of memberStructTypes(structCompoundType)) {
13
- for (const nodeKind of memberType.identifierType.nodeKinds) {
14
- memberIdentifierTypeNodeKinds.add(nodeKind);
15
- }
16
- for (const in_ of memberType.identifierType.in_) {
17
- memberIdentifierTypesIn.add(in_);
22
+ for (const member of structCompoundType.members) {
23
+ const memberIdentifierTypeEither = identifierType(member.type);
24
+ if (memberIdentifierTypeEither.isLeft()) {
25
+ return memberIdentifierTypeEither;
18
26
  }
27
+ memberIdentifierTypeEither.ifRight((memberIdentifierType) => {
28
+ for (const nodeKind of memberIdentifierType.nodeKinds) {
29
+ memberIdentifierTypeNodeKinds.add(nodeKind);
30
+ }
31
+ for (const in_ of memberIdentifierType.in_) {
32
+ memberIdentifierTypesIn.add(in_);
33
+ }
34
+ });
19
35
  }
20
36
  invariant(memberIdentifierTypeNodeKinds.size > 0);
21
37
  if (memberIdentifierTypeNodeKinds.size === 2) {
22
- return new IdentifierType({
38
+ return Either.of(new IdentifierType({
23
39
  comment: Maybe.empty(),
24
40
  label: Maybe.empty(),
25
41
  name: Maybe.empty(),
26
42
  shapeIdentifier: structCompoundType.shapeIdentifier,
27
- });
43
+ }));
28
44
  }
29
45
  const memberIdentifierTypeNodeKind = [...memberIdentifierTypeNodeKinds][0];
30
46
  switch (memberIdentifierTypeNodeKind) {
31
47
  case "BlankNode":
32
- return new BlankNodeType({
48
+ return Either.of(new BlankNodeType({
33
49
  comment: Maybe.empty(),
34
50
  label: Maybe.empty(),
35
51
  name: Maybe.empty(),
36
52
  shapeIdentifier: structCompoundType.shapeIdentifier,
37
- });
53
+ }));
38
54
  case "IRI":
39
- return new IriType({
55
+ return Either.of(new IriType({
40
56
  comment: Maybe.empty(),
41
57
  hasValues: [],
42
58
  in_: [...memberIdentifierTypesIn],
43
59
  label: Maybe.empty(),
44
60
  name: Maybe.empty(),
45
61
  shapeIdentifier: structCompoundType.shapeIdentifier,
46
- });
62
+ }));
47
63
  default:
48
64
  memberIdentifierTypeNodeKind;
49
65
  throw new Error("should never reach here");
50
66
  }
51
67
  }
52
68
  StructCompoundType.identifierType = identifierType;
53
- function memberStructTypes(objectCompoundType) {
54
- const memberStructTypes_ = [];
55
- for (const member of objectCompoundType.members) {
56
- switch (member.type.kind) {
57
- case "Struct":
58
- memberStructTypes_.push(member.type);
59
- break;
60
- case "Intersection":
61
- case "DiscriminatedUnion": {
62
- invariant(member.type.kind === objectCompoundType.kind);
63
- memberStructTypes_.push(...memberStructTypes(member.type));
64
- break;
65
- }
66
- }
67
- }
68
- invariant(memberStructTypes_.length >= objectCompoundType.members.length, "object compound type has no member StructType's");
69
- // Member object types must have distinct RDF types or no RDF types at all.
70
- const fromRdfTypes = new TermSet();
71
- let expectUniqueFromRdfTypesCount = 0;
72
- for (const memberStructType of memberStructTypes_) {
73
- if (memberStructType.extern) {
74
- continue;
75
- }
76
- expectUniqueFromRdfTypesCount++;
77
- memberStructType.fromRdfType.ifJust((fromRdfType) => fromRdfTypes.add(fromRdfType));
78
- }
79
- if (fromRdfTypes.size > 0 &&
80
- fromRdfTypes.size !== expectUniqueFromRdfTypesCount) {
81
- throw new Error(`one or more ${objectCompoundType} members ([${memberStructTypes_.map((memberType) => memberType.toString()).join(", ")}]) lack distinguishing fromRdfType's ({${[...fromRdfTypes].join(", ")}})`);
82
- }
83
- return memberStructTypes_;
84
- }
85
- StructCompoundType.memberStructTypes = memberStructTypes;
86
69
  })(StructCompoundType || (StructCompoundType = {}));
87
70
  //# sourceMappingURL=StructCompoundType.js.map
@@ -1,4 +1,8 @@
1
1
  import type { DiscriminatedUnionType } from "./DiscriminatedUnionType.js";
2
+ import type { StructIntersectionType } from "./StructIntersectionType.js";
2
3
  import type { StructType } from "./StructType.js";
3
- export type StructDiscriminatedUnionType = DiscriminatedUnionType<DiscriminatedUnionType<StructType> | StructType>;
4
+ export type StructDiscriminatedUnionType = DiscriminatedUnionType<StructDiscriminatedUnionType.MemberType>;
5
+ export declare namespace StructDiscriminatedUnionType {
6
+ type MemberType = DiscriminatedUnionType<MemberType> | StructIntersectionType | StructType;
7
+ }
4
8
  //# sourceMappingURL=StructDiscriminatedUnionType.d.ts.map
@@ -1,4 +1,7 @@
1
1
  import type { IntersectionType } from "./IntersectionType.js";
2
2
  import type { StructType } from "./StructType.js";
3
- export type StructIntersectionType = IntersectionType<IntersectionType<StructType> | StructType>;
3
+ export type StructIntersectionType = IntersectionType<StructIntersectionType.MemberType>;
4
+ export declare namespace StructIntersectionType {
5
+ type MemberType = IntersectionType<MemberType> | StructType;
6
+ }
4
7
  //# sourceMappingURL=StructIntersectionType.d.ts.map