@shaclmate/compiler 2.0.13 → 2.0.15

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 (210) hide show
  1. package/Compiler.d.ts +15 -0
  2. package/Compiler.js +20 -0
  3. package/ShapesGraphToAstTransformer.d.ts +18 -23
  4. package/ShapesGraphToAstTransformer.js +21 -447
  5. package/_ShapesGraphToAstTransformer/NodeShapeAstType.d.ts +3 -0
  6. package/_ShapesGraphToAstTransformer/NodeShapeAstType.js +2 -0
  7. package/_ShapesGraphToAstTransformer/index.d.ts +10 -0
  8. package/_ShapesGraphToAstTransformer/index.js +10 -0
  9. package/_ShapesGraphToAstTransformer/pickLiteral.d.ts +4 -0
  10. package/_ShapesGraphToAstTransformer/pickLiteral.js +18 -0
  11. package/_ShapesGraphToAstTransformer/propertyShapeNodeKinds.d.ts +4 -0
  12. package/_ShapesGraphToAstTransformer/propertyShapeNodeKinds.js +26 -0
  13. package/_ShapesGraphToAstTransformer/shapeAstName.d.ts +5 -0
  14. package/_ShapesGraphToAstTransformer/shapeAstName.js +28 -0
  15. package/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.d.ts +6 -0
  16. package/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.js +178 -0
  17. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.d.ts +13 -0
  18. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +200 -0
  19. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.d.ts +12 -0
  20. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.js +29 -0
  21. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.d.ts +12 -0
  22. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.js +43 -0
  23. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.d.ts +6 -0
  24. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +31 -0
  25. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.d.ts +14 -0
  26. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.js +21 -0
  27. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.d.ts +16 -0
  28. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.js +58 -0
  29. package/ast/Ast.d.ts +5 -0
  30. package/ast/CompositeType.d.ts +13 -0
  31. package/ast/CompositeType.js +2 -0
  32. package/ast/IdentifierType.d.ts +3 -6
  33. package/ast/IntersectionType.d.ts +2 -2
  34. package/ast/ListType.d.ts +53 -0
  35. package/ast/ListType.js +2 -0
  36. package/ast/LiteralType.d.ts +4 -3
  37. package/ast/Name.d.ts +1 -0
  38. package/ast/ObjectCompositeType.d.ts +22 -0
  39. package/ast/ObjectCompositeType.js +2 -0
  40. package/ast/ObjectIntersectionType.d.ts +8 -0
  41. package/ast/ObjectIntersectionType.js +2 -0
  42. package/ast/ObjectType.d.ts +91 -19
  43. package/ast/ObjectType.js +26 -1
  44. package/ast/ObjectUnionType.d.ts +19 -0
  45. package/ast/ObjectUnionType.js +2 -0
  46. package/ast/PlaceholderType.d.ts +7 -0
  47. package/ast/PlaceholderType.js +2 -0
  48. package/ast/SetType.d.ts +1 -1
  49. package/ast/TermType.d.ts +11 -0
  50. package/ast/TermType.js +2 -0
  51. package/ast/Type.d.ts +11 -3
  52. package/ast/UnionType.d.ts +3 -3
  53. package/ast/index.d.ts +6 -3
  54. package/ast/index.js +6 -3
  55. package/enums/MintingStrategy.d.ts +5 -0
  56. package/enums/MintingStrategy.js +2 -0
  57. package/enums/PropertyVisibility.d.ts +2 -0
  58. package/enums/PropertyVisibility.js +2 -0
  59. package/enums/TsFeature.d.ts +5 -0
  60. package/enums/TsFeature.js +16 -0
  61. package/enums/TsObjectDeclarationType.d.ts +5 -0
  62. package/enums/TsObjectDeclarationType.js +2 -0
  63. package/enums/index.d.ts +5 -0
  64. package/enums/index.js +5 -0
  65. package/generators/Generator.d.ts +5 -0
  66. package/generators/Generator.js +2 -0
  67. package/generators/index.d.ts +2 -2
  68. package/generators/index.js +2 -2
  69. package/generators/json/AstJsonGenerator.d.ts +4 -5
  70. package/generators/json/AstJsonGenerator.js +31 -22
  71. package/generators/ts/BooleanType.d.ts +7 -3
  72. package/generators/ts/BooleanType.js +58 -4
  73. package/generators/ts/DateTimeType.d.ts +19 -0
  74. package/generators/ts/DateTimeType.js +66 -0
  75. package/generators/ts/DeclaredType.d.ts +17 -0
  76. package/generators/ts/DeclaredType.js +10 -0
  77. package/generators/ts/IdentifierType.d.ts +7 -17
  78. package/generators/ts/IdentifierType.js +69 -60
  79. package/generators/ts/Import.d.ts +17 -0
  80. package/generators/ts/Import.js +54 -0
  81. package/generators/ts/ListType.d.ts +19 -8
  82. package/generators/ts/ListType.js +206 -44
  83. package/generators/ts/LiteralType.d.ts +13 -11
  84. package/generators/ts/LiteralType.js +36 -51
  85. package/generators/ts/NumberType.d.ts +7 -3
  86. package/generators/ts/NumberType.js +55 -4
  87. package/generators/ts/ObjectType.d.ts +48 -25
  88. package/generators/ts/ObjectType.js +234 -50
  89. package/generators/ts/ObjectUnionType.d.ts +58 -0
  90. package/generators/ts/ObjectUnionType.js +450 -0
  91. package/generators/ts/OptionType.d.ts +14 -4
  92. package/generators/ts/OptionType.js +70 -20
  93. package/generators/ts/PrimitiveType.d.ts +15 -5
  94. package/generators/ts/PrimitiveType.js +27 -31
  95. package/generators/ts/SetType.d.ts +14 -4
  96. package/generators/ts/SetType.js +108 -30
  97. package/generators/ts/SnippetDeclarations.d.ts +11 -0
  98. package/generators/ts/SnippetDeclarations.js +215 -0
  99. package/generators/ts/StringType.d.ts +8 -3
  100. package/generators/ts/StringType.js +57 -3
  101. package/generators/ts/TermType.d.ts +54 -0
  102. package/generators/ts/TermType.js +242 -0
  103. package/generators/ts/TsGenerator.d.ts +4 -12
  104. package/generators/ts/TsGenerator.js +57 -99
  105. package/generators/ts/Type.d.ts +117 -46
  106. package/generators/ts/Type.js +93 -59
  107. package/generators/ts/TypeFactory.d.ts +4 -5
  108. package/generators/ts/TypeFactory.js +224 -91
  109. package/generators/ts/UnionType.d.ts +20 -6
  110. package/generators/ts/UnionType.js +230 -120
  111. package/generators/ts/_ObjectType/IdentifierProperty.d.ts +27 -8
  112. package/generators/ts/_ObjectType/IdentifierProperty.js +153 -32
  113. package/generators/ts/_ObjectType/Property.d.ts +139 -9
  114. package/generators/ts/_ObjectType/Property.js +26 -3
  115. package/generators/ts/_ObjectType/ShaclProperty.d.ts +24 -5
  116. package/generators/ts/_ObjectType/ShaclProperty.js +103 -26
  117. package/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +23 -7
  118. package/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +83 -14
  119. package/generators/ts/_ObjectType/classDeclaration.d.ts +2 -1
  120. package/generators/ts/_ObjectType/classDeclaration.js +79 -111
  121. package/generators/ts/_ObjectType/createFunctionDeclaration.d.ts +5 -0
  122. package/generators/ts/_ObjectType/createFunctionDeclaration.js +60 -0
  123. package/generators/ts/_ObjectType/equalsFunctionDeclaration.d.ts +2 -1
  124. package/generators/ts/_ObjectType/equalsFunctionDeclaration.js +12 -20
  125. package/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.d.ts +11 -0
  126. package/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.js +70 -0
  127. package/generators/ts/_ObjectType/fromJsonFunctionDeclarations.d.ts +4 -0
  128. package/generators/ts/_ObjectType/fromJsonFunctionDeclarations.js +78 -0
  129. package/generators/ts/_ObjectType/fromRdfFunctionDeclarations.d.ts +4 -0
  130. package/generators/ts/_ObjectType/fromRdfFunctionDeclarations.js +91 -0
  131. package/generators/ts/_ObjectType/hashFunctionDeclaration.d.ts +3 -3
  132. package/generators/ts/_ObjectType/hashFunctionDeclaration.js +11 -55
  133. package/generators/ts/_ObjectType/hashFunctionOrMethodDeclaration.d.ts +11 -0
  134. package/generators/ts/_ObjectType/hashFunctionOrMethodDeclaration.js +64 -0
  135. package/generators/ts/_ObjectType/index.d.ts +8 -2
  136. package/generators/ts/_ObjectType/index.js +8 -2
  137. package/generators/ts/_ObjectType/interfaceDeclaration.d.ts +3 -2
  138. package/generators/ts/_ObjectType/interfaceDeclaration.js +11 -2
  139. package/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.d.ts +5 -0
  140. package/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.js +19 -0
  141. package/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.d.ts +5 -0
  142. package/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.js +31 -0
  143. package/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.d.ts +5 -0
  144. package/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.js +37 -0
  145. package/generators/ts/_ObjectType/rdfjsTermExpression.d.ts +6 -0
  146. package/generators/ts/{rdfjsTermExpression.js → _ObjectType/rdfjsTermExpression.js} +3 -1
  147. package/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.d.ts +5 -0
  148. package/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.js +21 -0
  149. package/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.d.ts +5 -0
  150. package/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.js +20 -0
  151. package/generators/ts/_ObjectType/sparqlFunctionDeclarations.d.ts +4 -0
  152. package/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +78 -0
  153. package/generators/ts/_ObjectType/toJsonFunctionDeclaration.d.ts +5 -0
  154. package/generators/ts/_ObjectType/toJsonFunctionDeclaration.js +19 -0
  155. package/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.d.ts +10 -0
  156. package/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.js +59 -0
  157. package/generators/ts/_ObjectType/toJsonReturnType.d.ts +3 -0
  158. package/generators/ts/_ObjectType/toJsonReturnType.js +19 -0
  159. package/generators/ts/_ObjectType/toRdfFunctionDeclaration.d.ts +3 -2
  160. package/generators/ts/_ObjectType/toRdfFunctionDeclaration.js +11 -45
  161. package/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.d.ts +10 -0
  162. package/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.js +67 -0
  163. package/generators/ts/objectInitializer.d.ts +2 -0
  164. package/generators/ts/objectInitializer.js +14 -0
  165. package/generators/ts/tsComment.d.ts +5 -0
  166. package/generators/ts/tsComment.js +11 -0
  167. package/generators/ts/tsName.d.ts +1 -1
  168. package/generators/ts/tsName.js +1 -0
  169. package/index.d.ts +1 -1
  170. package/index.js +1 -1
  171. package/input/NodeShape.d.ts +46 -0
  172. package/input/NodeShape.js +165 -0
  173. package/input/Ontology.d.ts +13 -0
  174. package/input/Ontology.js +30 -0
  175. package/input/PropertyShape.d.ts +15 -0
  176. package/input/PropertyShape.js +34 -0
  177. package/input/Shape.d.ts +4 -0
  178. package/input/Shape.js +2 -0
  179. package/input/ShapesGraph.d.ts +9 -0
  180. package/input/ShapesGraph.js +50 -0
  181. package/input/ancestorClassIris.d.ts +4 -0
  182. package/input/ancestorClassIris.js +21 -0
  183. package/input/descendantClassIris.d.ts +4 -0
  184. package/input/descendantClassIris.js +21 -0
  185. package/input/generated.d.ts +275 -0
  186. package/input/generated.js +1436 -0
  187. package/input/index.d.ts +7 -0
  188. package/input/index.js +7 -0
  189. package/input/tsFeatures.d.ts +10 -0
  190. package/input/tsFeatures.js +46 -0
  191. package/package.json +15 -9
  192. package/ast/MintingStrategy.d.ts +0 -8
  193. package/ast/MintingStrategy.js +0 -9
  194. package/generators/ts/Configuration.d.ts +0 -29
  195. package/generators/ts/Configuration.js +0 -40
  196. package/generators/ts/IntersectionType.d.ts +0 -14
  197. package/generators/ts/IntersectionType.js +0 -26
  198. package/generators/ts/RdfjsTermType.d.ts +0 -25
  199. package/generators/ts/RdfjsTermType.js +0 -46
  200. package/generators/ts/_ObjectType/fromRdfFunctionDeclaration.d.ts +0 -4
  201. package/generators/ts/_ObjectType/fromRdfFunctionDeclaration.js +0 -72
  202. package/generators/ts/_ObjectType/sparqlGraphPatternsClassDeclaration.d.ts +0 -4
  203. package/generators/ts/_ObjectType/sparqlGraphPatternsClassDeclaration.js +0 -46
  204. package/generators/ts/rdfjsTermExpression.d.ts +0 -5
  205. package/vocabularies/dashDataset.d.ts +0 -3
  206. package/vocabularies/dashDataset.js +0 -2370
  207. package/vocabularies/index.d.ts +0 -2
  208. package/vocabularies/index.js +0 -2
  209. package/vocabularies/shaclmate.d.ts +0 -15
  210. package/vocabularies/shaclmate.js +0 -6
@@ -0,0 +1,60 @@
1
+ import { Maybe } from "purify-ts";
2
+ import { invariant } from "ts-invariant";
3
+ import { StructureKind } from "ts-morph";
4
+ export function createFunctionDeclaration() {
5
+ if (!this.features.has("create")) {
6
+ return Maybe.empty();
7
+ }
8
+ if (this.declarationType !== "interface") {
9
+ return Maybe.empty();
10
+ }
11
+ if (this.extern) {
12
+ return Maybe.empty();
13
+ }
14
+ const parametersPropertySignatures = this.properties.flatMap((property) => property.constructorParametersPropertySignature
15
+ .map((propertySignature) => `readonly ${propertySignature.name}${propertySignature.hasQuestionToken ? "?" : ""}: ${propertySignature.type}`)
16
+ .toList());
17
+ // Should always have at least an identifier
18
+ invariant(parametersPropertySignatures.length > 0);
19
+ const parametersType = [`{ ${parametersPropertySignatures.join(", ")} }`]
20
+ .concat(this.parentObjectTypes.map((parentObjectType) => `Parameters<typeof ${parentObjectType.name}.create>[0]`))
21
+ .join(" & ");
22
+ const propertyInitializers = [];
23
+ const omitPropertyNames = [];
24
+ const propertyStatements = [];
25
+ for (const parentObjectType of this.parentObjectTypes) {
26
+ propertyInitializers.push(`...${parentObjectType.name}.create(parameters)`);
27
+ }
28
+ for (const property of this.properties) {
29
+ const thisPropertyStatements = property.interfaceConstructorStatements({
30
+ variables: { parameter: `parameters.${property.name}` },
31
+ });
32
+ if (thisPropertyStatements.length > 0) {
33
+ propertyInitializers.push(property.name);
34
+ propertyStatements.push(...thisPropertyStatements);
35
+ }
36
+ else {
37
+ omitPropertyNames.push(property.name);
38
+ }
39
+ }
40
+ invariant(propertyInitializers.length > 0);
41
+ invariant(propertyStatements.length > 0);
42
+ return Maybe.of({
43
+ isExported: true,
44
+ kind: StructureKind.Function,
45
+ name: "create",
46
+ parameters: [
47
+ {
48
+ name: "parameters",
49
+ type: parametersType,
50
+ },
51
+ ],
52
+ returnType: omitPropertyNames.length === 0
53
+ ? this.name
54
+ : `Omit<${this.name}, ${omitPropertyNames.map((omitPropertyName) => `"${omitPropertyName}"`).join(" | ")}>`,
55
+ statements: propertyStatements.concat([
56
+ `return { ${propertyInitializers.join(", ")} }`,
57
+ ]),
58
+ });
59
+ }
60
+ //# sourceMappingURL=createFunctionDeclaration.js.map
@@ -1,4 +1,5 @@
1
+ import { Maybe } from "purify-ts";
1
2
  import { type FunctionDeclarationStructure } from "ts-morph";
2
3
  import type { ObjectType } from "../ObjectType.js";
3
- export declare function equalsFunctionDeclaration(this: ObjectType): FunctionDeclarationStructure;
4
+ export declare function equalsFunctionDeclaration(this: ObjectType): Maybe<FunctionDeclarationStructure>;
4
5
  //# sourceMappingURL=equalsFunctionDeclaration.d.ts.map
@@ -1,27 +1,19 @@
1
+ import { Maybe } from "purify-ts";
1
2
  import { StructureKind } from "ts-morph";
3
+ import { equalsFunctionOrMethodDeclaration } from "./equalsFunctionOrMethodDeclaration.js";
2
4
  export function equalsFunctionDeclaration() {
3
- let expression = `purifyHelpers.Equatable.objectEquals(left, right, { ${this.properties
4
- .map((property) => `${property.name}: ${property.equalsFunction}`)
5
- .join()} })`;
6
- for (const parentObjectType of this.parentObjectTypes) {
7
- expression = `${parentObjectType.name}.equals(left, right).chain(() => ${expression})`;
5
+ if (this.declarationType !== "interface") {
6
+ return Maybe.empty();
8
7
  }
9
- return {
8
+ if (this.extern) {
9
+ return Maybe.empty();
10
+ }
11
+ return equalsFunctionOrMethodDeclaration
12
+ .bind(this)()
13
+ .map((equalsFunctionOrMethodDeclaration) => ({
14
+ ...equalsFunctionOrMethodDeclaration,
10
15
  isExported: true,
11
16
  kind: StructureKind.Function,
12
- name: "equals",
13
- parameters: [
14
- {
15
- name: "left",
16
- type: this.name,
17
- },
18
- {
19
- name: "right",
20
- type: this.name,
21
- },
22
- ],
23
- statements: [`return ${expression};`],
24
- returnType: "purifyHelpers.Equatable.EqualsResult",
25
- };
17
+ }));
26
18
  }
27
19
  //# sourceMappingURL=equalsFunctionDeclaration.js.map
@@ -0,0 +1,11 @@
1
+ import { Maybe } from "purify-ts";
2
+ import type { OptionalKind, ParameterDeclarationStructure } from "ts-morph";
3
+ import type { ObjectType } from "../ObjectType.js";
4
+ export declare function equalsFunctionOrMethodDeclaration(this: ObjectType): Maybe<{
5
+ hasOverrideKeyword: boolean;
6
+ name: string;
7
+ parameters: OptionalKind<ParameterDeclarationStructure>[];
8
+ returnType: string;
9
+ statements: string[];
10
+ }>;
11
+ //# sourceMappingURL=equalsFunctionOrMethodDeclaration.d.ts.map
@@ -0,0 +1,70 @@
1
+ import { Maybe } from "purify-ts";
2
+ export function equalsFunctionOrMethodDeclaration() {
3
+ if (!this.features.has("equals")) {
4
+ return Maybe.empty();
5
+ }
6
+ if (this.declarationType === "class" && this.ownProperties.length === 0) {
7
+ // If there's a parent class and no properties in this class, can skip overriding equals
8
+ return Maybe.empty();
9
+ }
10
+ let leftVariable;
11
+ let rightVariable;
12
+ switch (this.declarationType) {
13
+ case "class":
14
+ leftVariable = "this";
15
+ rightVariable = "other";
16
+ break;
17
+ case "interface":
18
+ leftVariable = "left";
19
+ rightVariable = "right";
20
+ }
21
+ const chain = [];
22
+ let hasOverrideKeyword = false;
23
+ if (this.parentObjectTypes.length > 0) {
24
+ switch (this.declarationType) {
25
+ case "class": {
26
+ chain.push("super.equals(other)");
27
+ hasOverrideKeyword = true;
28
+ break;
29
+ }
30
+ case "interface": {
31
+ // For every parent, find the nearest equals implementation
32
+ for (const parentObjectType of this.parentObjectTypes) {
33
+ chain.push(`${parentObjectType.name}.equals(left, right)`);
34
+ }
35
+ break;
36
+ }
37
+ }
38
+ }
39
+ for (const property of this.ownProperties) {
40
+ chain.push(`(${property.equalsFunction})(${leftVariable}.${property.name}, ${rightVariable}.${property.name}).mapLeft(propertyValuesUnequal => ({ left: ${leftVariable}, right: ${rightVariable}, propertyName: "${property.name}", propertyValuesUnequal, type: "Property" as const }))`);
41
+ }
42
+ return Maybe.of({
43
+ hasOverrideKeyword,
44
+ name: "equals",
45
+ parameters: this.declarationType === "interface"
46
+ ? [
47
+ {
48
+ name: "left",
49
+ type: this.name,
50
+ },
51
+ {
52
+ name: "right",
53
+ type: this.name,
54
+ },
55
+ ]
56
+ : [
57
+ {
58
+ name: "other",
59
+ type: this.name,
60
+ },
61
+ ],
62
+ returnType: "EqualsResult",
63
+ statements: [
64
+ `return ${chain
65
+ .map((chainPart, chainPartI) => chainPartI === 0 ? chainPart : `chain(() => ${chainPart})`)
66
+ .join(".")};`,
67
+ ],
68
+ });
69
+ }
70
+ //# sourceMappingURL=equalsFunctionOrMethodDeclaration.js.map
@@ -0,0 +1,4 @@
1
+ import { type FunctionDeclarationStructure } from "ts-morph";
2
+ import type { ObjectType } from "../ObjectType.js";
3
+ export declare function fromJsonFunctionDeclarations(this: ObjectType): readonly FunctionDeclarationStructure[];
4
+ //# sourceMappingURL=fromJsonFunctionDeclarations.d.ts.map
@@ -0,0 +1,78 @@
1
+ import { StructureKind } from "ts-morph";
2
+ const variables = {
3
+ jsonObject: "_jsonObject",
4
+ };
5
+ export function fromJsonFunctionDeclarations() {
6
+ if (!this.features.has("fromJson")) {
7
+ return [];
8
+ }
9
+ if (this.extern) {
10
+ return [];
11
+ }
12
+ const initializers = [];
13
+ const propertyReturnTypeSignatures = [];
14
+ const propertiesFromJsonFunctionReturnType = [];
15
+ const propertiesFromJsonFunctionStatements = [];
16
+ propertiesFromJsonFunctionStatements.push(`const _jsonSafeParseResult = ${this.jsonZodSchemaFunctionName}().safeParse(_json);`, "if (!_jsonSafeParseResult.success) { return purify.Left(_jsonSafeParseResult.error); }", `const ${variables.jsonObject} = _jsonSafeParseResult.data;`);
17
+ this.parentObjectTypes.forEach((parentObjectType, parentObjectTypeI) => {
18
+ propertiesFromJsonFunctionStatements.push(`const _super${parentObjectTypeI}Either = ${parentObjectType.name}.propertiesFromJson(${variables.jsonObject});`, `if (_super${parentObjectTypeI}Either.isLeft()) { return _super${parentObjectTypeI}Either; }`, `const _super${parentObjectTypeI} = _super${parentObjectTypeI}Either.unsafeCoerce()`);
19
+ initializers.push(`..._super${parentObjectTypeI}`);
20
+ propertiesFromJsonFunctionReturnType.push(`UnwrapR<ReturnType<typeof ${parentObjectType.name}.propertiesFromJson>>`);
21
+ });
22
+ for (const property of this.properties) {
23
+ const propertyFromJsonStatements = property.fromJsonStatements({
24
+ variables,
25
+ });
26
+ if (propertyFromJsonStatements.length > 0) {
27
+ propertiesFromJsonFunctionStatements.push(...propertyFromJsonStatements);
28
+ initializers.push(property.name);
29
+ propertyReturnTypeSignatures.push(`${property.name}: ${property.type.name};`);
30
+ }
31
+ }
32
+ propertiesFromJsonFunctionStatements.push(`return purify.Either.of({ ${initializers.join(", ")} })`);
33
+ if (propertyReturnTypeSignatures.length > 0) {
34
+ propertiesFromJsonFunctionReturnType.splice(0, 0, `{ ${propertyReturnTypeSignatures.join(" ")} }`);
35
+ }
36
+ const fromJsonFunctionDeclarations = [];
37
+ fromJsonFunctionDeclarations.push({
38
+ isExported: true,
39
+ kind: StructureKind.Function,
40
+ name: "propertiesFromJson",
41
+ parameters: [
42
+ {
43
+ name: "_json",
44
+ type: "unknown",
45
+ },
46
+ ],
47
+ returnType: `purify.Either<zod.ZodError, ${propertiesFromJsonFunctionReturnType.join(" & ")}>`,
48
+ statements: propertiesFromJsonFunctionStatements,
49
+ });
50
+ if (!this.abstract) {
51
+ let fromJsonStatements;
52
+ switch (this.declarationType) {
53
+ case "class":
54
+ fromJsonStatements = [
55
+ `return ${this.name}.propertiesFromJson(json).map(properties => new ${this.name}(properties));`,
56
+ ];
57
+ break;
58
+ case "interface":
59
+ fromJsonStatements = [`return ${this.name}.propertiesFromJson(json);`];
60
+ break;
61
+ }
62
+ fromJsonFunctionDeclarations.push({
63
+ isExported: true,
64
+ kind: StructureKind.Function,
65
+ name: "fromJson",
66
+ parameters: [
67
+ {
68
+ name: "json",
69
+ type: "unknown",
70
+ },
71
+ ],
72
+ returnType: `purify.Either<zod.ZodError, ${this.name}>`,
73
+ statements: fromJsonStatements,
74
+ });
75
+ }
76
+ return fromJsonFunctionDeclarations;
77
+ }
78
+ //# sourceMappingURL=fromJsonFunctionDeclarations.js.map
@@ -0,0 +1,4 @@
1
+ import { type FunctionDeclarationStructure } from "ts-morph";
2
+ import type { ObjectType } from "../ObjectType.js";
3
+ export declare function fromRdfFunctionDeclarations(this: ObjectType): readonly FunctionDeclarationStructure[];
4
+ //# sourceMappingURL=fromRdfFunctionDeclarations.d.ts.map
@@ -0,0 +1,91 @@
1
+ import { StructureKind } from "ts-morph";
2
+ import { objectInitializer } from "../objectInitializer.js";
3
+ const variables = {
4
+ context: "_context",
5
+ ignoreRdfType: "_ignoreRdfType",
6
+ languageIn: "_languageIn",
7
+ resource: "_resource",
8
+ };
9
+ export function fromRdfFunctionDeclarations() {
10
+ if (!this.features.has("fromRdf")) {
11
+ return [];
12
+ }
13
+ if (this.extern) {
14
+ return [];
15
+ }
16
+ const initializers = [];
17
+ const propertySignatures = [];
18
+ const propertiesFromRdfFunctionReturnType = [];
19
+ const propertiesFromRdfFunctionStatements = [];
20
+ this.parentObjectTypes.forEach((parentObjectType, parentObjectTypeI) => {
21
+ propertiesFromRdfFunctionStatements.push(`const _super${parentObjectTypeI}Either = ${parentObjectType.name}.propertiesFromRdf({ ...${variables.context}, ignoreRdfType: true, languageIn: ${variables.languageIn}, resource: ${variables.resource} });`, `if (_super${parentObjectTypeI}Either.isLeft()) { return _super${parentObjectTypeI}Either; }`, `const _super${parentObjectTypeI} = _super${parentObjectTypeI}Either.unsafeCoerce()`);
22
+ initializers.push(`..._super${parentObjectTypeI}`);
23
+ propertiesFromRdfFunctionReturnType.push(`UnwrapR<ReturnType<typeof ${parentObjectType.name}.propertiesFromRdf>>`);
24
+ });
25
+ this.fromRdfType.ifJust((rdfType) => {
26
+ propertiesFromRdfFunctionStatements.push(`if (!${variables.ignoreRdfType} && !${variables.resource}.isInstanceOf(${this.rdfjsTermExpression(rdfType)})) { return purify.Left(new rdfjsResource.Resource.ValueError(${objectInitializer({ focusResource: variables.resource, message: `\`\${rdfjsResource.Resource.Identifier.toString(${variables.resource}.identifier)} has unexpected RDF type\``, predicate: this.rdfjsTermExpression(rdfType) })})); }`);
27
+ });
28
+ const propertyFromRdfVariables = {
29
+ context: variables.context,
30
+ languageIn: variables.languageIn,
31
+ resource: variables.resource,
32
+ };
33
+ for (const property of this.properties) {
34
+ const propertyFromRdfStatements = property.fromRdfStatements({
35
+ variables: propertyFromRdfVariables,
36
+ });
37
+ if (propertyFromRdfStatements.length > 0) {
38
+ propertiesFromRdfFunctionStatements.push(...propertyFromRdfStatements);
39
+ initializers.push(property.name);
40
+ propertySignatures.push(`${property.name}: ${property.type.name};`);
41
+ }
42
+ }
43
+ propertiesFromRdfFunctionStatements.push(`return purify.Either.of({ ${initializers.join(", ")} })`);
44
+ if (propertySignatures.length > 0) {
45
+ propertiesFromRdfFunctionReturnType.splice(0, 0, `{ ${propertySignatures.join(" ")} }`);
46
+ }
47
+ const fromRdfFunctionDeclarations = [];
48
+ fromRdfFunctionDeclarations.push({
49
+ isExported: true,
50
+ kind: StructureKind.Function,
51
+ name: "propertiesFromRdf",
52
+ parameters: [
53
+ {
54
+ name: `{ ignoreRdfType: ${variables.ignoreRdfType}, languageIn: ${variables.languageIn}, resource: ${variables.resource},\n// @ts-ignore\n...${variables.context} }`,
55
+ type: `{ [_index: string]: any; ignoreRdfType?: boolean; languageIn?: readonly string[]; resource: ${this.rdfjsResourceType().name}; }`,
56
+ },
57
+ ],
58
+ returnType: `purify.Either<rdfjsResource.Resource.ValueError, ${propertiesFromRdfFunctionReturnType.join(" & ")}>`,
59
+ statements: propertiesFromRdfFunctionStatements,
60
+ });
61
+ if (!this.abstract) {
62
+ let fromRdfStatements;
63
+ switch (this.declarationType) {
64
+ case "class":
65
+ fromRdfStatements = [
66
+ `return ${this.name}.propertiesFromRdf(parameters).map(properties => new ${this.name}(properties));`,
67
+ ];
68
+ break;
69
+ case "interface":
70
+ fromRdfStatements = [
71
+ `return ${this.name}.propertiesFromRdf(parameters);`,
72
+ ];
73
+ break;
74
+ }
75
+ fromRdfFunctionDeclarations.push({
76
+ isExported: true,
77
+ kind: StructureKind.Function,
78
+ name: "fromRdf",
79
+ parameters: [
80
+ {
81
+ name: "parameters",
82
+ type: `Parameters<typeof ${this.name}.propertiesFromRdf>[0]`,
83
+ },
84
+ ],
85
+ returnType: `purify.Either<rdfjsResource.Resource.ValueError, ${this.name}>`,
86
+ statements: fromRdfStatements,
87
+ });
88
+ }
89
+ return fromRdfFunctionDeclarations;
90
+ }
91
+ //# sourceMappingURL=fromRdfFunctionDeclarations.js.map
@@ -1,5 +1,5 @@
1
+ import { Maybe } from "purify-ts";
1
2
  import { type FunctionDeclarationStructure } from "ts-morph";
2
- import type { ObjectType } from "../ObjectType";
3
- export declare const hasherTypeConstraint = "{ update: (message: string | number[] | ArrayBuffer | Uint8Array) => void; }";
4
- export declare function hashFunctionDeclaration(this: ObjectType): FunctionDeclarationStructure;
3
+ import type { ObjectType } from "../ObjectType.js";
4
+ export declare function hashFunctionDeclaration(this: ObjectType): Maybe<FunctionDeclarationStructure>;
5
5
  //# sourceMappingURL=hashFunctionDeclaration.d.ts.map
@@ -1,64 +1,20 @@
1
- import { camelCase } from "change-case";
1
+ import { Maybe } from "purify-ts";
2
2
  import { StructureKind } from "ts-morph";
3
- const hasherVariable = "hasher";
4
- export const hasherTypeConstraint = "{ update: (message: string | number[] | ArrayBuffer | Uint8Array) => void; }";
3
+ import { hashFunctionOrMethodDeclaration } from "./hashFunctionOrMethodDeclaration.js";
5
4
  export function hashFunctionDeclaration() {
6
- const thisVariable = camelCase(this.name);
7
- const omitPropertyNamesSet = new Set();
8
- omitPropertyNamesSet.add(this.configuration.objectTypeIdentifierPropertyName);
9
- omitPropertyNamesSet.add(this.configuration.objectTypeDiscriminatorPropertyName);
10
- if (this.configuration.objectTypeDeclarationType === "class") {
11
- omitPropertyNamesSet.add("equals");
12
- omitPropertyNamesSet.add("hash");
13
- omitPropertyNamesSet.add("toRdf");
5
+ if (this.declarationType !== "interface") {
6
+ return Maybe.empty();
14
7
  }
15
- const statements = [];
16
- for (const parentObjectType of this.parentObjectTypes) {
17
- statements.push(`${parentObjectType.name}.${parentObjectType.hashFunctionName}(${thisVariable}, ${hasherVariable})`);
8
+ if (this.extern) {
9
+ return Maybe.empty();
18
10
  }
19
- for (const property of this.properties) {
20
- const propertyValueVariable = `${thisVariable}.${property.name}`;
21
- const propertyHashStatements = property.hashStatements({
22
- variables: {
23
- hasher: hasherVariable,
24
- value: propertyValueVariable,
25
- },
26
- });
27
- if (propertyHashStatements.length === 0) {
28
- omitPropertyNamesSet.add(property.name);
29
- continue;
30
- }
31
- if (property.name === this.configuration.objectTypeIdentifierPropertyName) {
32
- // Don't hash the identifier since we may be using hash to calculate the identifier, leading to infinite recursion
33
- continue;
34
- }
35
- statements.push(...propertyHashStatements);
36
- }
37
- const omitPropertyNames = [...omitPropertyNamesSet];
38
- omitPropertyNames.sort();
39
- statements.push(`return ${hasherVariable};`);
40
- return {
11
+ return hashFunctionOrMethodDeclaration
12
+ .bind(this)()
13
+ .map((hashFunctionOrMethodDeclaration) => ({
14
+ ...hashFunctionOrMethodDeclaration,
41
15
  isExported: true,
42
16
  kind: StructureKind.Function,
43
17
  name: this.hashFunctionName,
44
- parameters: [
45
- {
46
- name: thisVariable,
47
- type: `Omit<${this.name}, ${omitPropertyNames.map((propertyName) => `"${propertyName}"`).join(" | ")}>`,
48
- },
49
- {
50
- name: hasherVariable,
51
- type: "HasherT",
52
- },
53
- ],
54
- returnType: "HasherT",
55
- statements,
56
- typeParameters: [
57
- {
58
- name: "HasherT",
59
- constraint: hasherTypeConstraint,
60
- },
61
- ],
62
- };
18
+ }));
63
19
  }
64
20
  //# sourceMappingURL=hashFunctionDeclaration.js.map
@@ -0,0 +1,11 @@
1
+ import { Maybe } from "purify-ts";
2
+ import type { OptionalKind, ParameterDeclarationStructure, TypeParameterDeclarationStructure } from "ts-morph";
3
+ import type { ObjectType } from "../ObjectType.js";
4
+ export declare const hasherTypeConstraint = "{ update: (message: string | number[] | ArrayBuffer | Uint8Array) => void; }";
5
+ export declare function hashFunctionOrMethodDeclaration(this: ObjectType): Maybe<{
6
+ parameters: OptionalKind<ParameterDeclarationStructure>[];
7
+ returnType: string;
8
+ statements: string[];
9
+ typeParameters: OptionalKind<TypeParameterDeclarationStructure>[];
10
+ }>;
11
+ //# sourceMappingURL=hashFunctionOrMethodDeclaration.d.ts.map
@@ -0,0 +1,64 @@
1
+ import { Maybe } from "purify-ts";
2
+ const hasherVariable = "_hasher";
3
+ export const hasherTypeConstraint = "{ update: (message: string | number[] | ArrayBuffer | Uint8Array) => void; }";
4
+ export function hashFunctionOrMethodDeclaration() {
5
+ if (!this.features.has("hash")) {
6
+ return Maybe.empty();
7
+ }
8
+ const propertyHashStatements = this.properties.flatMap((property) => property.hashStatements({
9
+ depth: 0,
10
+ variables: {
11
+ hasher: hasherVariable,
12
+ value: `${this.thisVariable}.${property.name}`,
13
+ },
14
+ }));
15
+ if (this.declarationType === "class" &&
16
+ this.parentObjectTypes.length > 0 &&
17
+ propertyHashStatements.length === 0) {
18
+ // If there's a parent class and no hash statements in this class, can skip overriding hash
19
+ return Maybe.empty();
20
+ }
21
+ const parameters = [];
22
+ if (this.declarationType === "interface") {
23
+ parameters.push({
24
+ name: this.thisVariable,
25
+ type: this.name,
26
+ });
27
+ }
28
+ parameters.push({
29
+ name: hasherVariable,
30
+ type: "HasherT",
31
+ });
32
+ const statements = [];
33
+ let hasOverrideKeyword = false;
34
+ if (this.parentObjectTypes.length > 0) {
35
+ switch (this.declarationType) {
36
+ case "class": {
37
+ statements.push(`super.hash(${hasherVariable});`);
38
+ hasOverrideKeyword = true;
39
+ break;
40
+ }
41
+ case "interface": {
42
+ for (const parentObjectType of this.parentObjectTypes) {
43
+ statements.push(`${parentObjectType.name}.${parentObjectType.hashFunctionName}(${this.thisVariable}, ${hasherVariable});`);
44
+ }
45
+ break;
46
+ }
47
+ }
48
+ }
49
+ statements.push(...propertyHashStatements);
50
+ statements.push(`return ${hasherVariable};`);
51
+ return Maybe.of({
52
+ hasOverrideKeyword,
53
+ parameters,
54
+ returnType: "HasherT",
55
+ statements,
56
+ typeParameters: [
57
+ {
58
+ name: "HasherT",
59
+ constraint: hasherTypeConstraint,
60
+ },
61
+ ],
62
+ });
63
+ }
64
+ //# sourceMappingURL=hashFunctionOrMethodDeclaration.js.map
@@ -1,12 +1,18 @@
1
1
  export * from "./classDeclaration.js";
2
+ export * from "./createFunctionDeclaration.js";
2
3
  export * from "./equalsFunctionDeclaration.js";
3
- export * from "./fromRdfFunctionDeclaration.js";
4
+ export * from "./fromJsonFunctionDeclarations.js";
5
+ export * from "./fromRdfFunctionDeclarations.js";
4
6
  export * from "./hashFunctionDeclaration.js";
5
7
  export * from "./IdentifierProperty.js";
6
8
  export * from "./interfaceDeclaration.js";
9
+ export * from "./jsonSchemaFunctionDeclaration.js";
10
+ export * from "./jsonUiSchemaFunctionDeclaration.js";
11
+ export * from "./jsonZodSchemaFunctionDeclaration.js";
7
12
  export * from "./Property.js";
8
13
  export * from "./ShaclProperty.js";
9
- export * from "./sparqlGraphPatternsClassDeclaration.js";
14
+ export * from "./sparqlFunctionDeclarations.js";
15
+ export * from "./toJsonFunctionDeclaration.js";
10
16
  export * from "./toRdfFunctionDeclaration.js";
11
17
  export * from "./TypeDiscriminatorProperty.js";
12
18
  //# sourceMappingURL=index.d.ts.map
@@ -1,12 +1,18 @@
1
1
  export * from "./classDeclaration.js";
2
+ export * from "./createFunctionDeclaration.js";
2
3
  export * from "./equalsFunctionDeclaration.js";
3
- export * from "./fromRdfFunctionDeclaration.js";
4
+ export * from "./fromJsonFunctionDeclarations.js";
5
+ export * from "./fromRdfFunctionDeclarations.js";
4
6
  export * from "./hashFunctionDeclaration.js";
5
7
  export * from "./IdentifierProperty.js";
6
8
  export * from "./interfaceDeclaration.js";
9
+ export * from "./jsonSchemaFunctionDeclaration.js";
10
+ export * from "./jsonUiSchemaFunctionDeclaration.js";
11
+ export * from "./jsonZodSchemaFunctionDeclaration.js";
7
12
  export * from "./Property.js";
8
13
  export * from "./ShaclProperty.js";
9
- export * from "./sparqlGraphPatternsClassDeclaration.js";
14
+ export * from "./sparqlFunctionDeclarations.js";
15
+ export * from "./toJsonFunctionDeclaration.js";
10
16
  export * from "./toRdfFunctionDeclaration.js";
11
17
  export * from "./TypeDiscriminatorProperty.js";
12
18
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,5 @@
1
+ import { Maybe } from "purify-ts";
1
2
  import { type InterfaceDeclarationStructure } from "ts-morph";
2
- import type { ObjectType } from "../ObjectType";
3
- export declare function interfaceDeclaration(this: ObjectType): InterfaceDeclarationStructure;
3
+ import type { ObjectType } from "../ObjectType.js";
4
+ export declare function interfaceDeclaration(this: ObjectType): Maybe<InterfaceDeclarationStructure>;
4
5
  //# sourceMappingURL=interfaceDeclaration.d.ts.map
@@ -1,12 +1,21 @@
1
+ import { Maybe } from "purify-ts";
1
2
  import { StructureKind, } from "ts-morph";
3
+ import { tsComment } from "../tsComment.js";
2
4
  export function interfaceDeclaration() {
5
+ if (this.declarationType !== "interface") {
6
+ return Maybe.empty();
7
+ }
8
+ if (this.extern) {
9
+ return Maybe.empty();
10
+ }
3
11
  const properties = this.properties.map((property) => property.interfacePropertySignature);
4
- return {
12
+ return Maybe.of({
5
13
  extends: this.parentObjectTypes.map((parentObjectType) => parentObjectType.name),
6
14
  isExported: true,
7
15
  kind: StructureKind.Interface,
16
+ leadingTrivia: this.comment.alt(this.label).map(tsComment).extract(),
8
17
  name: this.name,
9
18
  properties,
10
- };
19
+ });
11
20
  }
12
21
  //# sourceMappingURL=interfaceDeclaration.js.map
@@ -0,0 +1,5 @@
1
+ import { Maybe } from "purify-ts";
2
+ import { type FunctionDeclarationStructure } from "ts-morph";
3
+ import type { ObjectType } from "../ObjectType.js";
4
+ export declare function jsonSchemaFunctionDeclaration(this: ObjectType): Maybe<FunctionDeclarationStructure>;
5
+ //# sourceMappingURL=jsonSchemaFunctionDeclaration.d.ts.map
@@ -0,0 +1,19 @@
1
+ import { Maybe } from "purify-ts";
2
+ import { StructureKind } from "ts-morph";
3
+ export function jsonSchemaFunctionDeclaration() {
4
+ if (!this.features.has("jsonSchema")) {
5
+ return Maybe.empty();
6
+ }
7
+ if (this.extern) {
8
+ return Maybe.empty();
9
+ }
10
+ return Maybe.of({
11
+ isExported: true,
12
+ kind: StructureKind.Function,
13
+ name: "jsonSchema",
14
+ statements: [
15
+ `return zodToJsonSchema(${this.jsonZodSchemaFunctionName}());`,
16
+ ],
17
+ });
18
+ }
19
+ //# sourceMappingURL=jsonSchemaFunctionDeclaration.js.map
@@ -0,0 +1,5 @@
1
+ import { Maybe } from "purify-ts";
2
+ import { type FunctionDeclarationStructure } from "ts-morph";
3
+ import type { ObjectType } from "../ObjectType.js";
4
+ export declare function jsonUiSchemaFunctionDeclaration(this: ObjectType): Maybe<FunctionDeclarationStructure>;
5
+ //# sourceMappingURL=jsonUiSchemaFunctionDeclaration.d.ts.map