@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.
Files changed (172) hide show
  1. package/dist/ShapesGraphToAstTransformer.d.ts +1 -0
  2. package/dist/ShapesGraphToAstTransformer.js +56 -12
  3. package/dist/_ShapesGraphToAstTransformer/flattenAstObjectCompositeTypeMemberTypes.d.ts +13 -0
  4. package/dist/_ShapesGraphToAstTransformer/flattenAstObjectCompositeTypeMemberTypes.js +51 -0
  5. package/dist/_ShapesGraphToAstTransformer/shapeAstName.js +53 -12
  6. package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.d.ts +5 -0
  7. package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.js +130 -54
  8. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.d.ts +2 -3
  9. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +122 -129
  10. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.d.ts +2 -2
  11. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.d.ts +2 -2
  12. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +127 -5
  13. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.d.ts +3 -3
  14. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.d.ts +2 -3
  15. package/dist/ast/Ast.d.ts +0 -1
  16. package/dist/ast/Curie.d.ts +14 -0
  17. package/dist/ast/Curie.js +21 -0
  18. package/dist/ast/IdentifierType.d.ts +3 -2
  19. package/dist/ast/ListType.d.ts +2 -1
  20. package/dist/ast/LiteralType.d.ts +1 -1
  21. package/dist/ast/Name.d.ts +40 -5
  22. package/dist/ast/ObjectCompositeType.d.ts +11 -0
  23. package/dist/ast/ObjectType.d.ts +18 -13
  24. package/dist/ast/ObjectUnionType.d.ts +0 -11
  25. package/dist/ast/OptionType.d.ts +2 -2
  26. package/dist/ast/SetType.d.ts +2 -2
  27. package/dist/ast/TermType.d.ts +12 -4
  28. package/dist/ast/Type.d.ts +1 -1
  29. package/dist/enums/TsFeature.d.ts +1 -4
  30. package/dist/enums/TsFeature.js +1 -15
  31. package/dist/generators/json/AstJsonGenerator.js +19 -3
  32. package/dist/generators/ts/BooleanType.d.ts +3 -1
  33. package/dist/generators/ts/BooleanType.js +11 -2
  34. package/dist/generators/ts/DateTimeType.d.ts +8 -7
  35. package/dist/generators/ts/DateTimeType.js +31 -7
  36. package/dist/generators/ts/DateType.d.ts +5 -2
  37. package/dist/generators/ts/DateType.js +15 -1
  38. package/dist/generators/ts/DeclaredType.d.ts +2 -2
  39. package/dist/generators/ts/DeclaredType.js +2 -2
  40. package/dist/generators/ts/FloatType.d.ts +6 -0
  41. package/dist/generators/ts/FloatType.js +18 -0
  42. package/dist/generators/ts/IdentifierType.d.ts +12 -7
  43. package/dist/generators/ts/IdentifierType.js +94 -6
  44. package/dist/generators/ts/Import.d.ts +2 -0
  45. package/dist/generators/ts/Import.js +10 -0
  46. package/dist/generators/ts/IntType.d.ts +6 -0
  47. package/dist/generators/ts/IntType.js +18 -0
  48. package/dist/generators/ts/ListType.d.ts +15 -12
  49. package/dist/generators/ts/ListType.js +98 -57
  50. package/dist/generators/ts/LiteralType.d.ts +10 -9
  51. package/dist/generators/ts/LiteralType.js +13 -2
  52. package/dist/generators/ts/NumberType.d.ts +2 -1
  53. package/dist/generators/ts/NumberType.js +7 -2
  54. package/dist/generators/ts/ObjectType.d.ts +66 -43
  55. package/dist/generators/ts/ObjectType.js +144 -123
  56. package/dist/generators/ts/ObjectUnionType.d.ts +49 -8
  57. package/dist/generators/ts/ObjectUnionType.js +290 -97
  58. package/dist/generators/ts/OptionType.d.ts +14 -10
  59. package/dist/generators/ts/OptionType.js +60 -34
  60. package/dist/generators/ts/PrimitiveType.d.ts +4 -4
  61. package/dist/generators/ts/PrimitiveType.js +18 -3
  62. package/dist/generators/ts/SetType.d.ts +16 -12
  63. package/dist/generators/ts/SetType.js +69 -40
  64. package/dist/generators/ts/SnippetDeclarations.d.ts +13 -8
  65. package/dist/generators/ts/SnippetDeclarations.js +215 -101
  66. package/dist/generators/ts/StringType.d.ts +3 -1
  67. package/dist/generators/ts/StringType.js +14 -2
  68. package/dist/generators/ts/TermType.d.ts +22 -14
  69. package/dist/generators/ts/TermType.js +53 -25
  70. package/dist/generators/ts/TsGenerator.d.ts +2 -1
  71. package/dist/generators/ts/TsGenerator.js +23 -12
  72. package/dist/generators/ts/Type.d.ts +89 -31
  73. package/dist/generators/ts/Type.js +57 -54
  74. package/dist/generators/ts/TypeFactory.d.ts +4 -5
  75. package/dist/generators/ts/TypeFactory.js +290 -226
  76. package/dist/generators/ts/UnionType.d.ts +14 -10
  77. package/dist/generators/ts/UnionType.js +319 -142
  78. package/dist/generators/ts/_ObjectType/EagerShaclProperty.d.ts +12 -0
  79. package/dist/generators/ts/_ObjectType/EagerShaclProperty.js +30 -0
  80. package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.d.ts +13 -12
  81. package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.js +46 -47
  82. package/dist/generators/ts/_ObjectType/IdentifierProperty.d.ts +20 -13
  83. package/dist/generators/ts/_ObjectType/IdentifierProperty.js +152 -124
  84. package/dist/generators/ts/_ObjectType/LazyShaclProperty.d.ts +87 -0
  85. package/dist/generators/ts/_ObjectType/LazyShaclProperty.js +237 -0
  86. package/dist/generators/ts/_ObjectType/Property.d.ts +39 -44
  87. package/dist/generators/ts/_ObjectType/Property.js +1 -10
  88. package/dist/generators/ts/_ObjectType/ShaclProperty.d.ts +25 -30
  89. package/dist/generators/ts/_ObjectType/ShaclProperty.js +108 -85
  90. package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +21 -17
  91. package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +61 -53
  92. package/dist/generators/ts/_ObjectType/classDeclaration.js +6 -5
  93. package/dist/generators/ts/_ObjectType/createFunctionDeclaration.js +5 -4
  94. package/dist/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.js +5 -4
  95. package/dist/generators/ts/_ObjectType/fromRdfTypeVariableStatement.d.ts +1 -1
  96. package/dist/generators/ts/_ObjectType/fromRdfTypeVariableStatement.js +8 -5
  97. package/dist/generators/ts/_ObjectType/graphqlTypeVariableStatement.d.ts +5 -0
  98. package/dist/generators/ts/_ObjectType/graphqlTypeVariableStatement.js +37 -0
  99. package/dist/generators/ts/_ObjectType/hashFunctionOrMethodDeclarations.js +7 -8
  100. package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.d.ts +7 -0
  101. package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.js +54 -0
  102. package/dist/generators/ts/_ObjectType/index.d.ts +9 -7
  103. package/dist/generators/ts/_ObjectType/index.js +9 -7
  104. package/dist/generators/ts/_ObjectType/interfaceDeclaration.js +1 -1
  105. package/dist/generators/ts/_ObjectType/jsonFunctionDeclarations.d.ts +4 -0
  106. package/dist/generators/ts/_ObjectType/jsonFunctionDeclarations.js +189 -0
  107. package/dist/generators/ts/_ObjectType/jsonTypeAliasDeclaration.d.ts +5 -0
  108. package/dist/generators/ts/_ObjectType/jsonTypeAliasDeclaration.js +28 -0
  109. package/dist/generators/ts/_ObjectType/objectSetMethodNames.d.ts +9 -0
  110. package/dist/generators/ts/_ObjectType/objectSetMethodNames.js +18 -0
  111. package/dist/generators/ts/_ObjectType/propertiesVariableStatement.d.ts +5 -0
  112. package/dist/generators/ts/_ObjectType/propertiesVariableStatement.js +37 -0
  113. package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.d.ts +4 -0
  114. package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.js +152 -0
  115. package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.d.ts +1 -1
  116. package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.js +4 -3
  117. package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.d.ts +1 -1
  118. package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.js +3 -2
  119. package/dist/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +103 -35
  120. package/dist/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.js +6 -6
  121. package/dist/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.js +15 -13
  122. package/dist/generators/ts/graphqlSchemaVariableStatement.d.ts +9 -0
  123. package/dist/generators/ts/graphqlSchemaVariableStatement.js +86 -0
  124. package/dist/generators/ts/objectSetDeclarations.d.ts +8 -0
  125. package/dist/generators/ts/objectSetDeclarations.js +59 -0
  126. package/dist/generators/ts/objectSetInterfaceDeclaration.d.ts +8 -0
  127. package/dist/generators/ts/objectSetInterfaceDeclaration.js +46 -0
  128. package/dist/generators/ts/objectSetMethodSignatures.d.ts +11 -0
  129. package/dist/generators/ts/objectSetMethodSignatures.js +52 -0
  130. package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.d.ts +8 -0
  131. package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +393 -0
  132. package/dist/generators/ts/rdfjsTermExpression.d.ts +3 -0
  133. package/dist/generators/ts/rdfjsTermExpression.js +57 -0
  134. package/dist/generators/ts/sparqlObjectSetClassDeclaration.d.ts +8 -0
  135. package/dist/generators/ts/sparqlObjectSetClassDeclaration.js +415 -0
  136. package/dist/generators/ts/syntheticNamePrefix.d.ts +2 -0
  137. package/dist/generators/ts/syntheticNamePrefix.js +2 -0
  138. package/dist/generators/ts/tsName.js +27 -13
  139. package/dist/generators/ts/unsupportedObjectSetMethodDeclarations.d.ts +10 -0
  140. package/dist/generators/ts/unsupportedObjectSetMethodDeclarations.js +19 -0
  141. package/dist/input/NodeShape.d.ts +6 -8
  142. package/dist/input/NodeShape.js +20 -44
  143. package/dist/input/Ontology.d.ts +0 -3
  144. package/dist/input/Ontology.js +0 -9
  145. package/dist/input/PropertyPath.d.ts +6 -5
  146. package/dist/input/PropertyPath.js +14 -22
  147. package/dist/input/PropertyShape.d.ts +3 -1
  148. package/dist/input/PropertyShape.js +8 -2
  149. package/dist/input/ShapesGraph.js +4 -4
  150. package/dist/input/generated.d.ts +923 -105
  151. package/dist/input/generated.js +1865 -969
  152. package/dist/input/tsFeatures.d.ts +3 -2
  153. package/dist/input/tsFeatures.js +44 -27
  154. package/package.json +18 -16
  155. package/dist/generators/ts/_ObjectType/fromJsonFunctionDeclarations.d.ts +0 -4
  156. package/dist/generators/ts/_ObjectType/fromJsonFunctionDeclarations.js +0 -78
  157. package/dist/generators/ts/_ObjectType/fromRdfFunctionDeclarations.d.ts +0 -4
  158. package/dist/generators/ts/_ObjectType/fromRdfFunctionDeclarations.js +0 -91
  159. package/dist/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.d.ts +0 -5
  160. package/dist/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.js +0 -19
  161. package/dist/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.d.ts +0 -5
  162. package/dist/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.js +0 -31
  163. package/dist/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.d.ts +0 -5
  164. package/dist/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.js +0 -37
  165. package/dist/generators/ts/_ObjectType/rdfjsTermExpression.d.ts +0 -6
  166. package/dist/generators/ts/_ObjectType/rdfjsTermExpression.js +0 -17
  167. package/dist/generators/ts/_ObjectType/toJsonFunctionDeclaration.d.ts +0 -5
  168. package/dist/generators/ts/_ObjectType/toJsonFunctionDeclaration.js +0 -19
  169. package/dist/generators/ts/_ObjectType/toJsonReturnType.d.ts +0 -3
  170. package/dist/generators/ts/_ObjectType/toJsonReturnType.js +0 -17
  171. package/dist/generators/ts/_ObjectType/toRdfFunctionDeclaration.d.ts +0 -5
  172. package/dist/generators/ts/_ObjectType/toRdfFunctionDeclaration.js +0 -19
@@ -1,11 +1,15 @@
1
+ import { syntheticNamePrefix } from "./syntheticNamePrefix.js";
1
2
  export var SnippetDeclarations;
2
3
  (function (SnippetDeclarations) {
3
4
  SnippetDeclarations.arrayEquals = `\
4
- export function arrayEquals<T>(
5
+ /**
6
+ * Compare two arrays element-wise with the provided elementEquals function.
7
+ */
8
+ export function ${syntheticNamePrefix}arrayEquals<T>(
5
9
  leftArray: readonly T[],
6
10
  rightArray: readonly T[],
7
- elementEquals: (left: T, right: T) => boolean | EqualsResult,
8
- ): EqualsResult {
11
+ elementEquals: (left: T, right: T) => boolean | ${syntheticNamePrefix}EqualsResult,
12
+ ): ${syntheticNamePrefix}EqualsResult {
9
13
  if (leftArray.length !== rightArray.length) {
10
14
  return purify.Left({
11
15
  left: leftArray,
@@ -21,7 +25,7 @@ export function arrayEquals<T>(
21
25
  ) {
22
26
  const leftElement = leftArray[leftElementIndex];
23
27
 
24
- const rightUnequals: EqualsResult.Unequal[] = [];
28
+ const rightUnequals: ${syntheticNamePrefix}EqualsResult.Unequal[] = [];
25
29
  for (
26
30
  let rightElementIndex = 0;
27
31
  rightElementIndex < rightArray.length;
@@ -30,7 +34,7 @@ export function arrayEquals<T>(
30
34
  const rightElement = rightArray[rightElementIndex];
31
35
 
32
36
  const leftElementEqualsRightElement =
33
- EqualsResult.fromBooleanEqualsResult(
37
+ ${syntheticNamePrefix}EqualsResult.fromBooleanEqualsResult(
34
38
  leftElement,
35
39
  rightElement,
36
40
  elementEquals(leftElement, rightElement),
@@ -39,7 +43,7 @@ export function arrayEquals<T>(
39
43
  break; // left element === right element, break out of the right iteration
40
44
  }
41
45
  rightUnequals.push(
42
- leftElementEqualsRightElement.extract() as EqualsResult.Unequal,
46
+ leftElementEqualsRightElement.extract() as ${syntheticNamePrefix}EqualsResult.Unequal,
43
47
  );
44
48
  }
45
49
 
@@ -61,18 +65,18 @@ export function arrayEquals<T>(
61
65
  // Else there was a right element equal to the left element, continue to the next left element
62
66
  }
63
67
 
64
- return EqualsResult.Equal;
68
+ return ${syntheticNamePrefix}EqualsResult.Equal;
65
69
  }
66
70
  `;
67
71
  SnippetDeclarations.booleanEquals = `\
68
72
  /**
69
- * Compare two objects with equals(other: T): boolean methods and return an EqualsResult.
73
+ * Compare two objects with equals(other: T): boolean methods and return an ${syntheticNamePrefix}EqualsResult.
70
74
  */
71
- export function booleanEquals<T extends { equals: (other: T) => boolean }>(
75
+ export function ${syntheticNamePrefix}booleanEquals<T extends { equals: (other: T) => boolean }>(
72
76
  left: T,
73
77
  right: T,
74
- ): EqualsResult {
75
- return EqualsResult.fromBooleanEqualsResult(
78
+ ): ${syntheticNamePrefix}EqualsResult {
79
+ return ${syntheticNamePrefix}EqualsResult.fromBooleanEqualsResult(
76
80
  left,
77
81
  right,
78
82
  left.equals(right),
@@ -80,104 +84,101 @@ export function booleanEquals<T extends { equals: (other: T) => boolean }>(
80
84
  }`;
81
85
  SnippetDeclarations.dateEquals = `\
82
86
  /**
83
- * Compare two Dates and return an EqualsResult.
87
+ * Compare two Dates and return an ${syntheticNamePrefix}EqualsResult.
84
88
  */
85
- export function dateEquals(left: Date, right: Date): EqualsResult {
86
- return EqualsResult.fromBooleanEqualsResult(
89
+ export function ${syntheticNamePrefix}dateEquals(left: Date, right: Date): ${syntheticNamePrefix}EqualsResult {
90
+ return ${syntheticNamePrefix}EqualsResult.fromBooleanEqualsResult(
87
91
  left,
88
92
  right,
89
93
  left.getTime() === right.getTime(),
90
94
  );
91
95
  }`;
92
96
  SnippetDeclarations.EqualsResult = `\
93
- export type EqualsResult = purify.Either<EqualsResult.Unequal, true>;
94
-
95
- export namespace EqualsResult {
96
- export const Equal: EqualsResult = purify.Either.of<Unequal, true>(true);
97
-
98
- export function fromBooleanEqualsResult(
99
- left: any,
100
- right: any,
101
- equalsResult: boolean | EqualsResult,
102
- ): EqualsResult {
103
- if (typeof equalsResult !== "boolean") {
104
- return equalsResult;
105
- }
97
+ export type ${syntheticNamePrefix}EqualsResult = purify.Either<${syntheticNamePrefix}EqualsResult.Unequal, true>;
106
98
 
107
- if (equalsResult) {
108
- return Equal;
109
- }
110
- return purify.Left({
111
- left,
112
- right,
113
- type: "BooleanEquals",
114
- });
99
+ export namespace ${syntheticNamePrefix}EqualsResult {
100
+ export const Equal: ${syntheticNamePrefix}EqualsResult = purify.Either.of<Unequal, true>(true);
101
+
102
+ export function fromBooleanEqualsResult(
103
+ left: any,
104
+ right: any,
105
+ equalsResult: boolean | ${syntheticNamePrefix}EqualsResult,
106
+ ): ${syntheticNamePrefix}EqualsResult {
107
+ if (typeof equalsResult !== "boolean") {
108
+ return equalsResult;
109
+ }
110
+
111
+ if (equalsResult) {
112
+ return Equal;
115
113
  }
116
114
 
117
- export type Unequal =
118
- | {
119
- readonly left: {
120
- readonly array: readonly any[];
121
- readonly element: any;
122
- readonly elementIndex: number;
123
- };
124
- readonly right: {
125
- readonly array: readonly any[];
126
- readonly unequals: readonly Unequal[];
127
- };
128
- readonly type: "ArrayElement";
129
- }
130
- | {
131
- readonly left: readonly any[];
132
- readonly right: readonly any[];
133
- readonly type: "ArrayLength";
134
- }
135
- | {
136
- readonly left: any;
137
- readonly right: any;
138
- readonly type: "BooleanEquals";
139
- }
140
- | {
141
- readonly left: any;
142
- readonly right: any;
143
- readonly type: "LeftError";
144
- }
145
- | {
146
- readonly right: any;
147
- readonly type: "LeftNull";
148
- }
149
- | {
150
- readonly left: bigint | boolean | number | string;
151
- readonly right: bigint | boolean | number | string;
152
- readonly type: "Primitive";
153
- }
154
- | {
155
- readonly left: object;
156
- readonly right: object;
157
- readonly propertyName: string;
158
- readonly propertyValuesUnequal: Unequal;
159
- readonly type: "Property";
160
- }
161
- | {
162
- readonly left: any;
163
- readonly right: any;
164
- readonly type: "RightError";
165
- }
166
- | {
167
- readonly left: any;
168
- readonly type: "RightNull";
169
- };
115
+ return purify.Left({ left, right, type: "BooleanEquals" });
116
+ }
117
+
118
+ export type Unequal =
119
+ | {
120
+ readonly left: {
121
+ readonly array: readonly any[];
122
+ readonly element: any;
123
+ readonly elementIndex: number;
124
+ };
125
+ readonly right: {
126
+ readonly array: readonly any[];
127
+ readonly unequals: readonly Unequal[];
128
+ };
129
+ readonly type: "ArrayElement";
130
+ }
131
+ | {
132
+ readonly left: readonly any[];
133
+ readonly right: readonly any[];
134
+ readonly type: "ArrayLength";
135
+ }
136
+ | {
137
+ readonly left: any;
138
+ readonly right: any;
139
+ readonly type: "BooleanEquals";
140
+ }
141
+ | {
142
+ readonly left: any;
143
+ readonly right: any;
144
+ readonly type: "LeftError";
145
+ }
146
+ | {
147
+ readonly right: any;
148
+ readonly type: "LeftNull";
149
+ }
150
+ | {
151
+ readonly left: bigint | boolean | number | string;
152
+ readonly right: bigint | boolean | number | string;
153
+ readonly type: "Primitive";
154
+ }
155
+ | {
156
+ readonly left: any;
157
+ readonly right: any;
158
+ readonly propertyName: string;
159
+ readonly propertyValuesUnequal: Unequal;
160
+ readonly type: "Property";
161
+ }
162
+ | {
163
+ readonly left: any;
164
+ readonly right: any;
165
+ readonly type: "RightError";
166
+ }
167
+ | {
168
+ readonly left: any;
169
+ readonly type: "RightNull";
170
+ };
170
171
  }
171
172
  `;
172
173
  SnippetDeclarations.maybeEquals = `\
173
- export function maybeEquals<T>(
174
+ export function ${syntheticNamePrefix}maybeEquals<T>(
174
175
  leftMaybe: purify.Maybe<T>,
175
176
  rightMaybe: purify.Maybe<T>,
176
- valueEquals: (left: T, right: T) => boolean | EqualsResult,
177
- ): EqualsResult {
177
+ valueEquals: (left: T, right: T) => boolean | ${syntheticNamePrefix}EqualsResult,
178
+ ): ${syntheticNamePrefix}EqualsResult {
178
179
  if (leftMaybe.isJust()) {
179
180
  if (rightMaybe.isJust()) {
180
- return EqualsResult.fromBooleanEqualsResult(
181
+ return ${syntheticNamePrefix}EqualsResult.fromBooleanEqualsResult(
181
182
  leftMaybe,
182
183
  rightMaybe,
183
184
  valueEquals(leftMaybe.unsafeCoerce(), rightMaybe.unsafeCoerce()),
@@ -196,20 +197,133 @@ export function maybeEquals<T>(
196
197
  });
197
198
  }
198
199
 
199
- return EqualsResult.Equal;
200
- }
201
- `;
200
+ return ${syntheticNamePrefix}EqualsResult.Equal;
201
+ }`;
202
+ SnippetDeclarations.LazyObjectSet = `\
203
+ /**
204
+ * Type of lazy properties that return a set of objects. This is a class instead of an interface so it can be instanceof'd elsewhere.
205
+ */
206
+ export class ${syntheticNamePrefix}LazyObjectSet<ObjectIdentifierT extends rdfjs.BlankNode | rdfjs.NamedNode, ResolvedObjectT extends { ${syntheticNamePrefix}identifier: ObjectIdentifierT }, StubObjectT extends { ${syntheticNamePrefix}identifier: ObjectIdentifierT }> {
207
+ private readonly resolver: (identifiers: readonly ObjectIdentifierT[]) => Promise<purify.Either<Error, readonly ResolvedObjectT[]>>;
208
+ readonly stubs: readonly StubObjectT[];
209
+
210
+ constructor({ resolver, stubs }: {
211
+ resolver: (identifiers: readonly ObjectIdentifierT[]) => Promise<purify.Either<Error, readonly ResolvedObjectT[]>>,
212
+ stubs: readonly StubObjectT[]
213
+ }) {
214
+ this.resolver = resolver;
215
+ this.stubs = stubs;
216
+ }
217
+
218
+ async resolve(): Promise<purify.Either<Error, readonly ResolvedObjectT[]>> {
219
+ if (this.stubs.length === 0) {
220
+ return purify.Either.of([]);
221
+ }
222
+ return await this.resolver(this.stubs.map(stub => stub.${syntheticNamePrefix}identifier));
223
+ }
224
+ }`;
225
+ SnippetDeclarations.LazyOptionalObject = `\
226
+ /**
227
+ * Type of lazy properties that return a single optional object. This is a class instead of an interface so it can be instanceof'd elsewhere.
228
+ */
229
+ export class ${syntheticNamePrefix}LazyOptionalObject<ObjectIdentifierT extends rdfjs.BlankNode | rdfjs.NamedNode, ResolvedObjectT extends { ${syntheticNamePrefix}identifier: ObjectIdentifierT }, StubObjectT extends { ${syntheticNamePrefix}identifier: ObjectIdentifierT }> {
230
+ private readonly resolver: (identifier: ObjectIdentifierT) => Promise<purify.Either<Error, ResolvedObjectT>>;
231
+ readonly stub: purify.Maybe<StubObjectT>;
232
+
233
+ constructor({ resolver, stub }: {
234
+ resolver: (identifier: ObjectIdentifierT) => Promise<purify.Either<Error, ResolvedObjectT>>,
235
+ stub: purify.Maybe<StubObjectT>
236
+ }) {
237
+ this.resolver = resolver;
238
+ this.stub = stub;
239
+ }
240
+
241
+ async resolve(): Promise<purify.Either<Error, purify.Maybe<ResolvedObjectT>>> {
242
+ if (this.stub.isNothing()) {
243
+ return purify.Either.of(purify.Maybe.empty());
244
+ }
245
+ return (await this.resolver(this.stub.unsafeCoerce().${syntheticNamePrefix}identifier)).map(purify.Maybe.of);
246
+ }
247
+ }`;
248
+ SnippetDeclarations.LazyRequiredObject = `\
249
+ /**
250
+ * Type of lazy properties that return a single required object. This is a class instead of an interface so it can be instanceof'd elsewhere.
251
+ */
252
+ export class ${syntheticNamePrefix}LazyRequiredObject<ObjectIdentifierT extends rdfjs.BlankNode | rdfjs.NamedNode, ResolvedObjectT extends { ${syntheticNamePrefix}identifier: ObjectIdentifierT }, StubObjectT extends { ${syntheticNamePrefix}identifier: ObjectIdentifierT }> {
253
+ private readonly resolver: (identifier: ObjectIdentifierT) => Promise<purify.Either<Error, ResolvedObjectT>>;
254
+ readonly stub: StubObjectT;
255
+
256
+ constructor({ resolver, stub }: {
257
+ resolver: (identifier: ObjectIdentifierT) => Promise<purify.Either<Error, ResolvedObjectT>>,
258
+ stub: StubObjectT
259
+ }) {
260
+ this.resolver = resolver;
261
+ this.stub = stub;
262
+ }
263
+
264
+ resolve(): Promise<purify.Either<Error, ResolvedObjectT>> {
265
+ return this.resolver(this.stub.${syntheticNamePrefix}identifier);
266
+ }
267
+ }`;
268
+ SnippetDeclarations.RdfVocabularies = `\
269
+ export namespace ${syntheticNamePrefix}RdfVocabularies {
270
+ export namespace rdf {
271
+ export const first = dataFactory.namedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#first");
272
+ export const nil = dataFactory.namedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#nil");
273
+ export const rest = dataFactory.namedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest");
274
+ export const subject = dataFactory.namedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#subject");
275
+ export const type = dataFactory.namedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
276
+ }
277
+
278
+ export namespace rdfs {
279
+ export const subClassOf = dataFactory.namedNode("http://www.w3.org/2000/01/rdf-schema#subClassOf");
280
+ }
281
+
282
+ export namespace xsd {
283
+ export const boolean = dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#boolean");
284
+ export const date = dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#date");
285
+ export const dateTime = dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#dateTime");
286
+ export const integer = dataFactory.namedNode("http://www.w3.org/2001/XMLSchema#integer");
287
+ }
288
+ }`;
289
+ SnippetDeclarations.sparqlInstancesOfPattern = `\
290
+ /**
291
+ * A sparqljs.Pattern that's the equivalent of ?subject rdf:type/rdfs:subClassOf* ?rdfType .
292
+ */
293
+ export function ${syntheticNamePrefix}sparqlInstancesOfPattern({ rdfType, subject }: { rdfType: rdfjs.NamedNode, subject: sparqljs.Triple["subject"] }): sparqljs.Pattern {
294
+ return {
295
+ triples: [
296
+ {
297
+ subject,
298
+ predicate: {
299
+ items: [
300
+ $RdfVocabularies.rdf.type,
301
+ {
302
+ items: [$RdfVocabularies.rdfs.subClassOf],
303
+ pathType: "*",
304
+ type: "path",
305
+ },
306
+ ],
307
+ pathType: "/",
308
+ type: "path",
309
+ },
310
+ object: rdfType,
311
+ },
312
+ ],
313
+ type: "bgp",
314
+ };
315
+ }`;
202
316
  SnippetDeclarations.strictEquals = `\
203
317
  /**
204
- * Compare two values for strict equality (===), returning an EqualsResult rather than a boolean.
318
+ * Compare two values for strict equality (===), returning an ${syntheticNamePrefix}EqualsResult rather than a boolean.
205
319
  */
206
- export function strictEquals<T extends bigint | boolean | number | string>(
320
+ export function ${syntheticNamePrefix}strictEquals<T extends bigint | boolean | number | string>(
207
321
  left: T,
208
322
  right: T,
209
- ): EqualsResult {
210
- return EqualsResult.fromBooleanEqualsResult(left, right, left === right);
323
+ ): ${syntheticNamePrefix}EqualsResult {
324
+ return ${syntheticNamePrefix}EqualsResult.fromBooleanEqualsResult(left, right, left === right);
211
325
  }`;
212
- SnippetDeclarations.UnwrapL = "type UnwrapL<T> = T extends purify.Either<infer L, any> ? L : never";
213
- SnippetDeclarations.UnwrapR = "type UnwrapR<T> = T extends purify.Either<any, infer R> ? R : never";
326
+ SnippetDeclarations.UnwrapL = `type ${syntheticNamePrefix}UnwrapL<T> = T extends purify.Either<infer L, any> ? L : never`;
327
+ SnippetDeclarations.UnwrapR = `type ${syntheticNamePrefix}UnwrapR<T> = T extends purify.Either<any, infer R> ? R : never`;
214
328
  })(SnippetDeclarations || (SnippetDeclarations = {}));
215
329
  //# sourceMappingURL=SnippetDeclarations.js.map
@@ -1,8 +1,10 @@
1
1
  import { PrimitiveType } from "./PrimitiveType.js";
2
- import type { Type } from "./Type.js";
2
+ import { Type } from "./Type.js";
3
3
  export declare class StringType extends PrimitiveType<string> {
4
4
  readonly kind = "StringType";
5
+ readonly typeof = "string";
5
6
  get conversions(): readonly Type.Conversion[];
7
+ get graphqlName(): Type.GraphqlName;
6
8
  get name(): string;
7
9
  hashStatements({ variables, }: Parameters<Type["hashStatements"]>[0]): readonly string[];
8
10
  jsonZodSchema({ variables, }: Parameters<Type["jsonZodSchema"]>[0]): ReturnType<Type["jsonZodSchema"]>;
@@ -6,9 +6,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
6
6
  };
7
7
  import { Memoize } from "typescript-memoize";
8
8
  import { PrimitiveType } from "./PrimitiveType.js";
9
+ import { Type } from "./Type.js";
9
10
  import { objectInitializer } from "./objectInitializer.js";
10
11
  export class StringType extends PrimitiveType {
11
12
  kind = "StringType";
13
+ typeof = "string";
12
14
  get conversions() {
13
15
  const conversions = [
14
16
  {
@@ -26,11 +28,14 @@ export class StringType extends PrimitiveType {
26
28
  });
27
29
  return conversions;
28
30
  }
31
+ get graphqlName() {
32
+ return new Type.GraphqlName("graphql.GraphQLString");
33
+ }
29
34
  get name() {
30
35
  if (this.primitiveIn.length > 0) {
31
36
  return this.primitiveIn.map((value) => `"${value}"`).join(" | ");
32
37
  }
33
- return "string";
38
+ return this.typeof;
34
39
  }
35
40
  hashStatements({ variables, }) {
36
41
  return [`${variables.hasher}.update(${variables.value});`];
@@ -48,7 +53,8 @@ export class StringType extends PrimitiveType {
48
53
  propertyFromRdfResourceValueExpression({ variables, }) {
49
54
  let expression = `${variables.resourceValue}.toString()`;
50
55
  if (this.primitiveIn.length > 0) {
51
- expression = `${expression}.chain(value => { switch (value) { ${this.primitiveIn.map((value) => `case "${value}":`).join(" ")} return purify.Either.of(value); default: return purify.Left(new rdfjsResource.Resource.MistypedValueError(${objectInitializer({ actualValue: "rdfLiteral.toRdf(value)", expectedValueType: JSON.stringify(this.name), focusResource: variables.resource, predicate: variables.predicate })})); } })`;
56
+ const eitherTypeParameters = `<Error, ${this.name}>`;
57
+ expression = `${expression}.chain(value => { switch (value) { ${this.primitiveIn.map((value) => `case "${value}":`).join(" ")} return purify.Either.of${eitherTypeParameters}(value); default: return purify.Left${eitherTypeParameters}(new rdfjsResource.Resource.MistypedValueError(${objectInitializer({ actualValue: "rdfLiteral.toRdf(value)", expectedValueType: JSON.stringify(this.name), focusResource: variables.resource, predicate: variables.predicate })})); } })`;
52
58
  }
53
59
  return expression;
54
60
  }
@@ -58,6 +64,12 @@ export class StringType extends PrimitiveType {
58
64
  .orDefault(variables.value);
59
65
  }
60
66
  }
67
+ __decorate([
68
+ Memoize()
69
+ ], StringType.prototype, "conversions", null);
70
+ __decorate([
71
+ Memoize()
72
+ ], StringType.prototype, "graphqlName", null);
61
73
  __decorate([
62
74
  Memoize()
63
75
  ], StringType.prototype, "name", null);
@@ -1,33 +1,41 @@
1
1
  import type { BlankNode, Literal, NamedNode } from "@rdfjs/types";
2
2
  import { Maybe } from "purify-ts";
3
- import type { TsFeature } from "../../enums/index.js";
4
3
  import { Import } from "./Import.js";
5
4
  import { Type } from "./Type.js";
6
5
  /**
7
6
  * Abstract base class for IdentifierType and LiteralType.
7
+ *
8
+ * ConstantTermT is the type of sh:defaultValue, sh:hasValue, and sh:in.
9
+ * RuntimeTermT is the type of values at runtime.
10
+ *
11
+ * The two are differentiated because identifiers can have BlankNode or NamedNode values at runtime but only NamedNode values for sh:defaultValue et al.
8
12
  */
9
- export declare class TermType<TermT extends BlankNode | Literal | NamedNode> extends Type {
10
- readonly defaultValue: Maybe<TermT>;
13
+ export declare class TermType<ConstantTermT extends Literal | NamedNode = Literal | NamedNode, RuntimeTermT extends BlankNode | Literal | NamedNode = BlankNode | Literal | NamedNode> extends Type {
14
+ readonly defaultValue: Maybe<ConstantTermT>;
11
15
  readonly equalsFunction: string;
12
- readonly hasValues: readonly TermT[];
13
- readonly in_: readonly TermT[];
16
+ readonly hasValues: readonly ConstantTermT[];
17
+ readonly in_: readonly ConstantTermT[];
14
18
  readonly mutable: boolean;
15
- readonly nodeKinds: Set<TermT["termType"]>;
16
- constructor({ defaultValue, hasValues, in_, nodeKinds, ...superParameters }: {
17
- defaultValue: Maybe<TermT>;
18
- hasValues: readonly TermT[];
19
- in_: readonly TermT[];
20
- nodeKinds: Set<TermT["termType"]>;
21
- } & ConstructorParameters<typeof Type>[0]);
19
+ readonly nodeKinds: Set<RuntimeTermT["termType"]>;
20
+ readonly typeof: "boolean" | "number" | "object" | "string";
21
+ constructor({ defaultValue, hasValues, in_, nodeKinds, }: {
22
+ defaultValue: Maybe<ConstantTermT>;
23
+ hasValues: readonly ConstantTermT[];
24
+ in_: readonly ConstantTermT[];
25
+ nodeKinds: Set<RuntimeTermT["termType"]>;
26
+ });
22
27
  get conversions(): readonly Type.Conversion[];
23
28
  get discriminatorProperty(): Maybe<Type.DiscriminatorProperty>;
24
- get jsonName(): string;
29
+ get graphqlName(): Type.GraphqlName;
30
+ get jsonName(): Type.JsonName;
25
31
  get name(): string;
26
32
  fromJsonExpression({ variables, }: Parameters<Type["fromJsonExpression"]>[0]): string;
27
33
  fromRdfExpression({ variables, }: Parameters<Type["fromRdfExpression"]>[0]): string;
34
+ graphqlResolveExpression(_parameters: Parameters<Type["graphqlResolveExpression"]>[0]): string;
28
35
  hashStatements({ variables, }: Parameters<Type["hashStatements"]>[0]): readonly string[];
36
+ jsonUiSchemaElement(): Maybe<string>;
29
37
  jsonZodSchema({ variables, }: Parameters<Type["jsonZodSchema"]>[0]): ReturnType<Type["jsonZodSchema"]>;
30
- snippetDeclarations(features: Set<TsFeature>): readonly string[];
38
+ snippetDeclarations({ features, }: Parameters<Type["snippetDeclarations"]>[0]): readonly string[];
31
39
  sparqlWherePatterns(parameters: Parameters<Type["sparqlWherePatterns"]>[0]): readonly string[];
32
40
  toJsonExpression({ variables, }: Parameters<Type["toJsonExpression"]>[0]): string;
33
41
  toRdfExpression({ variables, }: Parameters<Type["toRdfExpression"]>[0]): string;