@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,31 @@
1
+ import { Maybe } from "purify-ts";
2
+ import { StructureKind } from "ts-morph";
3
+ export function jsonUiSchemaFunctionDeclaration() {
4
+ if (!this.features.has("jsonUiSchema")) {
5
+ return Maybe.empty();
6
+ }
7
+ if (this.extern) {
8
+ return Maybe.empty();
9
+ }
10
+ const variables = { scopePrefix: "scopePrefix" };
11
+ const elements = this.parentObjectTypes
12
+ .map((parentObjectType) => `${parentObjectType.name}.${parentObjectType.jsonUiSchemaFunctionName}({ scopePrefix })`)
13
+ .concat(this.ownProperties.flatMap((property) => property.jsonUiSchemaElement({ variables }).toList()));
14
+ return Maybe.of({
15
+ isExported: true,
16
+ kind: StructureKind.Function,
17
+ name: this.jsonUiSchemaFunctionName,
18
+ parameters: [
19
+ {
20
+ hasQuestionToken: true,
21
+ name: "parameters",
22
+ type: "{ scopePrefix?: string }",
23
+ },
24
+ ],
25
+ statements: [
26
+ 'const scopePrefix = parameters?.scopePrefix ?? "#";',
27
+ `return { "elements": [ ${elements.join(", ")} ], label: "${this.label.orDefault(this.name)}", type: "Group" }`,
28
+ ],
29
+ });
30
+ }
31
+ //# sourceMappingURL=jsonUiSchemaFunctionDeclaration.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 jsonZodSchemaFunctionDeclaration(this: ObjectType): Maybe<FunctionDeclarationStructure>;
5
+ //# sourceMappingURL=jsonZodSchemaFunctionDeclaration.d.ts.map
@@ -0,0 +1,37 @@
1
+ import { Maybe } from "purify-ts";
2
+ import { StructureKind } from "ts-morph";
3
+ export function jsonZodSchemaFunctionDeclaration() {
4
+ if (!this.features.has("fromJson") && !this.features.has("jsonSchema")) {
5
+ return Maybe.empty();
6
+ }
7
+ if (this.extern) {
8
+ return Maybe.empty();
9
+ }
10
+ const variables = { zod: "zod" };
11
+ const mergeZodObjectSchemas = [];
12
+ for (const parentObjectType of this.parentObjectTypes) {
13
+ mergeZodObjectSchemas.push(`${parentObjectType.jsonZodSchema({ variables })}`);
14
+ }
15
+ if (this.properties.length > 0) {
16
+ mergeZodObjectSchemas.push(`${variables.zod}.object({ ${this.properties
17
+ .map((property) => property.jsonZodSchema({ variables }))
18
+ .map(({ key, schema }) => `"${key}": ${schema}`)
19
+ .join(",")} })`);
20
+ }
21
+ return Maybe.of({
22
+ isExported: true,
23
+ kind: StructureKind.Function,
24
+ name: this.jsonZodSchemaFunctionName,
25
+ statements: [
26
+ `return ${mergeZodObjectSchemas.length > 0
27
+ ? mergeZodObjectSchemas.reduce((merged, zodObjectSchema) => {
28
+ if (merged.length === 0) {
29
+ return zodObjectSchema;
30
+ }
31
+ return `${merged}.merge(${zodObjectSchema})`;
32
+ }, "")
33
+ : `${variables.zod}.object()`};`,
34
+ ],
35
+ });
36
+ }
37
+ //# sourceMappingURL=jsonZodSchemaFunctionDeclaration.js.map
@@ -0,0 +1,6 @@
1
+ import type { BlankNode, Literal, NamedNode, Variable } from "@rdfjs/types";
2
+ export declare function rdfjsTermExpression({ dataFactoryVariable, rdfjsTerm, }: {
3
+ dataFactoryVariable: string;
4
+ rdfjsTerm: Omit<BlankNode, "equals"> | Omit<Literal, "equals"> | Omit<NamedNode, "equals"> | Omit<Variable, "equals">;
5
+ }): string;
6
+ //# sourceMappingURL=rdfjsTermExpression.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { xsd } from "@tpluscode/rdf-ns-builders";
2
- export function rdfjsTermExpression(rdfjsTerm, { dataFactoryVariable }) {
2
+ export function rdfjsTermExpression({ dataFactoryVariable, rdfjsTerm, }) {
3
3
  switch (rdfjsTerm.termType) {
4
4
  case "BlankNode":
5
5
  return `${dataFactoryVariable}.blankNode("${rdfjsTerm.value}")`;
@@ -10,6 +10,8 @@ export function rdfjsTermExpression(rdfjsTerm, { dataFactoryVariable }) {
10
10
  return `${dataFactoryVariable}.literal("${rdfjsTerm.value}", ${dataFactoryVariable}.namedNode("${rdfjsTerm.datatype.value}"))`;
11
11
  case "NamedNode":
12
12
  return `${dataFactoryVariable}.namedNode("${rdfjsTerm.value}")`;
13
+ case "Variable":
14
+ return `${dataFactoryVariable}.variable!("${rdfjsTerm.value}")`;
13
15
  }
14
16
  }
15
17
  //# sourceMappingURL=rdfjsTermExpression.js.map
@@ -0,0 +1,5 @@
1
+ import { type FunctionDeclarationStructure } from "ts-morph";
2
+ export declare function sparqlConstructQueryFunctionDeclaration(this: {
3
+ readonly name: string;
4
+ }): FunctionDeclarationStructure;
5
+ //# sourceMappingURL=sparqlConstructQueryFunctionDeclaration.d.ts.map
@@ -0,0 +1,21 @@
1
+ import { StructureKind } from "ts-morph";
2
+ export function sparqlConstructQueryFunctionDeclaration() {
3
+ return {
4
+ isExported: true,
5
+ kind: StructureKind.Function,
6
+ name: "sparqlConstructQuery",
7
+ parameters: [
8
+ {
9
+ hasQuestionToken: true,
10
+ name: "parameters",
11
+ type: '{ ignoreRdfType?: boolean; prefixes?: { [prefix: string]: string }; subject?: sparqljs.Triple["subject"]; } & Omit<sparqljs.ConstructQuery, "prefixes" | "queryType" | "type">',
12
+ },
13
+ ],
14
+ returnType: "sparqljs.ConstructQuery",
15
+ statements: [
16
+ "const { ignoreRdfType, subject, ...queryParameters } = parameters ?? {}",
17
+ `return { ...queryParameters, prefixes: parameters?.prefixes ?? {}, queryType: "CONSTRUCT", template: (queryParameters.template ?? []).concat(${this.name}.sparqlConstructTemplateTriples({ ignoreRdfType, subject })), type: "query", where: (queryParameters.where ?? []).concat(${this.name}.sparqlWherePatterns({ ignoreRdfType, subject })) };`,
18
+ ],
19
+ };
20
+ }
21
+ //# sourceMappingURL=sparqlConstructQueryFunctionDeclaration.js.map
@@ -0,0 +1,5 @@
1
+ import { type FunctionDeclarationStructure } from "ts-morph";
2
+ export declare function sparqlConstructQueryStringFunctionDeclaration(this: {
3
+ readonly name: string;
4
+ }): FunctionDeclarationStructure;
5
+ //# sourceMappingURL=sparqlConstructQueryStringFunctionDeclaration.d.ts.map
@@ -0,0 +1,20 @@
1
+ import { StructureKind } from "ts-morph";
2
+ export function sparqlConstructQueryStringFunctionDeclaration() {
3
+ return {
4
+ isExported: true,
5
+ kind: StructureKind.Function,
6
+ name: "sparqlConstructQueryString",
7
+ parameters: [
8
+ {
9
+ hasQuestionToken: true,
10
+ name: "parameters",
11
+ type: '{ ignoreRdfType?: boolean; subject?: sparqljs.Triple["subject"]; variablePrefix?: string; } & Omit<sparqljs.ConstructQuery, "prefixes" | "queryType" | "type"> & sparqljs.GeneratorOptions',
12
+ },
13
+ ],
14
+ returnType: "string",
15
+ statements: [
16
+ `return new sparqljs.Generator(parameters).stringify(${this.name}.sparqlConstructQuery(parameters));`,
17
+ ],
18
+ };
19
+ }
20
+ //# sourceMappingURL=sparqlConstructQueryStringFunctionDeclaration.js.map
@@ -0,0 +1,4 @@
1
+ import { type FunctionDeclarationStructure } from "ts-morph";
2
+ import type { ObjectType } from "../ObjectType.js";
3
+ export declare function sparqlFunctionDeclarations(this: ObjectType): readonly FunctionDeclarationStructure[];
4
+ //# sourceMappingURL=sparqlFunctionDeclarations.d.ts.map
@@ -0,0 +1,78 @@
1
+ import { rdf } from "@tpluscode/rdf-ns-builders";
2
+ import { camelCase } from "change-case";
3
+ import { StructureKind } from "ts-morph";
4
+ import { sparqlConstructQueryFunctionDeclaration } from "./sparqlConstructQueryFunctionDeclaration.js";
5
+ import { sparqlConstructQueryStringFunctionDeclaration } from "./sparqlConstructQueryStringFunctionDeclaration.js";
6
+ export function sparqlFunctionDeclarations() {
7
+ if (!this.features.has("sparql")) {
8
+ return [];
9
+ }
10
+ if (this.extern) {
11
+ return [];
12
+ }
13
+ const variables = { subject: "subject", variablePrefix: "variablePrefix" };
14
+ const rdfTypeVariable = `${this.dataFactoryVariable}.variable!(\`\${${variables.variablePrefix}}RdfType\`)`;
15
+ const subjectDefault = camelCase(this.name);
16
+ const preambleStatements = [
17
+ `const subject = parameters?.subject ?? ${this.dataFactoryVariable}.variable!("${subjectDefault}");`,
18
+ `const variablePrefix = parameters?.variablePrefix ?? (subject.termType === "Variable" ? subject.value : "${subjectDefault}");`,
19
+ ];
20
+ const sparqlConstructTemplateTriples = [
21
+ ...this.parentObjectTypes.map((parentObjectType) => `...${parentObjectType.name}.sparqlConstructTemplateTriples({ ignoreRdfType: true, subject, variablePrefix })`),
22
+ ...(this.fromRdfType.isJust()
23
+ ? [
24
+ `...(parameters?.ignoreRdfType ? [] : [{ subject, predicate: ${this.rdfjsTermExpression(rdf.type)}, object: ${rdfTypeVariable} }])`,
25
+ ]
26
+ : []),
27
+ ...this.ownProperties.flatMap((property) => property.sparqlConstructTemplateTriples({ variables })),
28
+ ];
29
+ const sparqlWherePatterns = [
30
+ ...this.parentObjectTypes.map((parentObjectType) => `...${parentObjectType.name}.sparqlWherePatterns({ ignoreRdfType: true, subject, variablePrefix })`),
31
+ ...(this.fromRdfType.isJust()
32
+ ? [
33
+ `...(parameters?.ignoreRdfType ? [] : [{ triples: [{ subject, predicate: ${this.rdfjsTermExpression(rdf.type)}, object: ${this.rdfjsTermExpression(this.fromRdfType.unsafeCoerce())} }], type: "bgp" as const }, { triples: [{ subject, predicate: ${this.rdfjsTermExpression(rdf.type)}, object: ${rdfTypeVariable} }], type: "bgp" as const }])`,
34
+ ]
35
+ : []),
36
+ ...this.ownProperties.flatMap((property) => property.sparqlWherePatterns({ variables })),
37
+ ];
38
+ return [
39
+ sparqlConstructQueryFunctionDeclaration.bind(this)(),
40
+ sparqlConstructQueryStringFunctionDeclaration.bind(this)(),
41
+ {
42
+ isExported: true,
43
+ kind: StructureKind.Function,
44
+ name: "sparqlConstructTemplateTriples",
45
+ parameters: [
46
+ {
47
+ hasQuestionToken: true,
48
+ name: `${sparqlConstructTemplateTriples.length === 0 ? "_" : ""}parameters`,
49
+ type: '{ ignoreRdfType?: boolean; subject?: sparqljs.Triple["subject"], variablePrefix?: string }',
50
+ },
51
+ ],
52
+ returnType: "readonly sparqljs.Triple[]",
53
+ statements: [
54
+ ...(sparqlConstructTemplateTriples.length > 0
55
+ ? preambleStatements
56
+ : []),
57
+ `return [${sparqlConstructTemplateTriples.join(", ")}];`,
58
+ ],
59
+ },
60
+ {
61
+ isExported: true,
62
+ kind: StructureKind.Function,
63
+ name: "sparqlWherePatterns",
64
+ parameters: [
65
+ {
66
+ name: `${sparqlWherePatterns.length === 0 ? "_" : ""}parameters`,
67
+ type: '{ ignoreRdfType?: boolean; subject?: sparqljs.Triple["subject"], variablePrefix?: string }',
68
+ },
69
+ ],
70
+ returnType: "readonly sparqljs.Pattern[]",
71
+ statements: [
72
+ ...(sparqlWherePatterns.length > 0 ? preambleStatements : []),
73
+ `return [${sparqlWherePatterns.join(", ")}];`,
74
+ ],
75
+ },
76
+ ];
77
+ }
78
+ //# sourceMappingURL=sparqlFunctionDeclarations.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 toJsonFunctionDeclaration(this: ObjectType): Maybe<FunctionDeclarationStructure>;
5
+ //# sourceMappingURL=toJsonFunctionDeclaration.d.ts.map
@@ -0,0 +1,19 @@
1
+ import { Maybe } from "purify-ts";
2
+ import { StructureKind } from "ts-morph";
3
+ import { toJsonFunctionOrMethodDeclaration } from "./toJsonFunctionOrMethodDeclaration.js";
4
+ export function toJsonFunctionDeclaration() {
5
+ if (this.declarationType !== "interface") {
6
+ return Maybe.empty();
7
+ }
8
+ if (this.extern) {
9
+ return Maybe.empty();
10
+ }
11
+ return toJsonFunctionOrMethodDeclaration
12
+ .bind(this)()
13
+ .map((toJsonFunctionOrMethodDeclaration) => ({
14
+ ...toJsonFunctionOrMethodDeclaration,
15
+ isExported: true,
16
+ kind: StructureKind.Function,
17
+ }));
18
+ }
19
+ //# sourceMappingURL=toJsonFunctionDeclaration.js.map
@@ -0,0 +1,10 @@
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 toJsonFunctionOrMethodDeclaration(this: ObjectType): Maybe<{
5
+ name: string;
6
+ parameters: OptionalKind<ParameterDeclarationStructure>[];
7
+ returnType: string;
8
+ statements: string[];
9
+ }>;
10
+ //# sourceMappingURL=toJsonFunctionOrMethodDeclaration.d.ts.map
@@ -0,0 +1,59 @@
1
+ import { Maybe } from "purify-ts";
2
+ import { toJsonReturnType } from "./toJsonReturnType.js";
3
+ export function toJsonFunctionOrMethodDeclaration() {
4
+ if (!this.features.has("toJson")) {
5
+ return Maybe.empty();
6
+ }
7
+ if (this.declarationType === "class" &&
8
+ this.ownProperties.length === 0 &&
9
+ this.parentObjectTypes.length > 0) {
10
+ return Maybe.empty();
11
+ }
12
+ const jsonObjectMembers = [];
13
+ const parameters = [];
14
+ switch (this.declarationType) {
15
+ case "class":
16
+ if (this.parentObjectTypes.length > 0) {
17
+ jsonObjectMembers.push("...super.toJson()");
18
+ }
19
+ break;
20
+ case "interface":
21
+ for (const parentObjectType of this.parentObjectTypes) {
22
+ jsonObjectMembers.push(`...${parentObjectType.name}.toJson(${this.thisVariable})`);
23
+ }
24
+ parameters.push({
25
+ name: this.thisVariable,
26
+ type: this.name,
27
+ });
28
+ break;
29
+ }
30
+ if (this.ownProperties.length > 0) {
31
+ for (const property of this.ownProperties) {
32
+ jsonObjectMembers.push(property.toJsonObjectMember({
33
+ variables: { value: `${this.thisVariable}.${property.name}` },
34
+ }));
35
+ }
36
+ }
37
+ // 20241220: don't add @type until we're doing JSON-LD
38
+ // switch (this.toRdfTypes.length) {
39
+ // case 0:
40
+ // break;
41
+ // case 1:
42
+ // jsonObjectMembers.push(`"@type": "${this.toRdfTypes[0].value}"`);
43
+ // break;
44
+ // default:
45
+ // jsonObjectMembers.push(
46
+ // `"@type": ${JSON.stringify(this.toRdfTypes.map((rdfType) => rdfType.value))}`,
47
+ // );
48
+ // break;
49
+ // }
50
+ return Maybe.of({
51
+ name: "toJson",
52
+ parameters,
53
+ returnType: toJsonReturnType.bind(this)(),
54
+ statements: [
55
+ `return JSON.parse(JSON.stringify({ ${jsonObjectMembers.join(",")} } satisfies ${this.jsonName}));`,
56
+ ],
57
+ });
58
+ }
59
+ //# sourceMappingURL=toJsonFunctionOrMethodDeclaration.js.map
@@ -0,0 +1,3 @@
1
+ import type { ObjectType } from "../ObjectType.js";
2
+ export declare function toJsonReturnType(this: ObjectType): string;
3
+ //# sourceMappingURL=toJsonReturnType.d.ts.map
@@ -0,0 +1,19 @@
1
+ export function toJsonReturnType() {
2
+ const typeMembers = [];
3
+ if (this.ownProperties.length > 0) {
4
+ typeMembers.push(`{ ${this.ownProperties
5
+ .map((property) => {
6
+ const propertySignature = property.jsonPropertySignature;
7
+ return `readonly "${propertySignature.name}": ${propertySignature.type}`;
8
+ })
9
+ .join("; ")} }`);
10
+ }
11
+ for (const parentObjectType of this.parentObjectTypes) {
12
+ typeMembers.push(parentObjectType.jsonName);
13
+ }
14
+ if (typeMembers.length === 0) {
15
+ return "object";
16
+ }
17
+ return typeMembers.join(" & ");
18
+ }
19
+ //# sourceMappingURL=toJsonReturnType.js.map
@@ -1,4 +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 function toRdfFunctionDeclaration(this: ObjectType): FunctionDeclarationStructure;
3
+ import type { ObjectType } from "../ObjectType.js";
4
+ export declare function toRdfFunctionDeclaration(this: ObjectType): Maybe<FunctionDeclarationStructure>;
4
5
  //# sourceMappingURL=toRdfFunctionDeclaration.d.ts.map
@@ -1,53 +1,19 @@
1
- import { rdf } from "@tpluscode/rdf-ns-builders";
2
- import { camelCase } from "change-case";
1
+ import { Maybe } from "purify-ts";
3
2
  import { StructureKind } from "ts-morph";
4
- const variables = {
5
- ignoreRdfType: "ignoreRdfType",
6
- mutateGraph: "mutateGraph",
7
- resource: "resource",
8
- resourceSet: "resourceSet",
9
- };
3
+ import { toRdfFunctionOrMethodDeclaration } from "./toRdfFunctionOrMethodDeclaration.js";
10
4
  export function toRdfFunctionDeclaration() {
11
- this.ensureAtMostOneSuperObjectType();
12
- let usedIgnoreRdfTypeVariable = false;
13
- const thisVariable = camelCase(this.name);
14
- const statements = [];
15
- if (this.parentObjectTypes.length > 0) {
16
- statements.push(`const ${variables.resource} = ${this.parentObjectTypes[0].name}.toRdf(${thisVariable}, { ${variables.mutateGraph}, ${variables.ignoreRdfType}: true, ${variables.resourceSet} });`);
17
- usedIgnoreRdfTypeVariable = true;
5
+ if (this.declarationType !== "interface") {
6
+ return Maybe.empty();
18
7
  }
19
- else if (this.identifierType.isNamedNodeKind) {
20
- statements.push(`const ${variables.resource} = ${variables.resourceSet}.mutableNamedResource({ identifier: ${thisVariable}.${this.configuration.objectTypeIdentifierPropertyName}, ${variables.mutateGraph} });`);
8
+ if (this.extern) {
9
+ return Maybe.empty();
21
10
  }
22
- else {
23
- statements.push(`const ${variables.resource} = ${variables.resourceSet}.mutableResource({ identifier: ${thisVariable}.${this.configuration.objectTypeIdentifierPropertyName}, ${variables.mutateGraph} });`);
24
- }
25
- this.rdfType.ifJust((rdfType) => {
26
- statements.push(`if (!${variables.ignoreRdfType}) { ${variables.resource}.add(${variables.resource}.dataFactory.namedNode("${rdf.type.value}"), ${variables.resource}.dataFactory.namedNode("${rdfType.value}")); }`);
27
- usedIgnoreRdfTypeVariable = true;
28
- });
29
- for (const property of this.properties) {
30
- statements.push(...property.toRdfStatements({
31
- variables: { ...variables, value: `${thisVariable}.${property.name}` },
32
- }));
33
- }
34
- statements.push(`return ${variables.resource};`);
35
- return {
11
+ return toRdfFunctionOrMethodDeclaration
12
+ .bind(this)()
13
+ .map((toRdfFunctionOrMethodDeclaration) => ({
14
+ ...toRdfFunctionOrMethodDeclaration,
36
15
  isExported: true,
37
16
  kind: StructureKind.Function,
38
- name: "toRdf",
39
- parameters: [
40
- {
41
- name: thisVariable,
42
- type: this.name,
43
- },
44
- {
45
- name: `{ ${usedIgnoreRdfTypeVariable ? `${variables.ignoreRdfType},` : ""} ${variables.mutateGraph}, ${variables.resourceSet} }`,
46
- type: `{ ${variables.ignoreRdfType}?: boolean; ${variables.mutateGraph}: rdfjsResource.MutableResource.MutateGraph, ${variables.resourceSet}: rdfjsResource.MutableResourceSet }`,
47
- },
48
- ],
49
- returnType: this.rdfjsResourceType({ mutable: true }).name,
50
- statements,
51
- };
17
+ }));
52
18
  }
53
19
  //# sourceMappingURL=toRdfFunctionDeclaration.js.map
@@ -0,0 +1,10 @@
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 toRdfFunctionOrMethodDeclaration(this: ObjectType): Maybe<{
5
+ name: string;
6
+ parameters: OptionalKind<ParameterDeclarationStructure>[];
7
+ returnType: string;
8
+ statements: string[];
9
+ }>;
10
+ //# sourceMappingURL=toRdfFunctionOrMethodDeclaration.d.ts.map
@@ -0,0 +1,67 @@
1
+ import { rdf } from "@tpluscode/rdf-ns-builders";
2
+ import { Maybe } from "purify-ts";
3
+ const variables = {
4
+ ignoreRdfType: "ignoreRdfType",
5
+ mutateGraph: "mutateGraph",
6
+ resource: "_resource",
7
+ resourceSet: "resourceSet",
8
+ };
9
+ export function toRdfFunctionOrMethodDeclaration() {
10
+ if (!this.features.has("toRdf")) {
11
+ return Maybe.empty();
12
+ }
13
+ this.ensureAtMostOneSuperObjectType();
14
+ let usedIgnoreRdfTypeVariable = false;
15
+ const statements = [];
16
+ if (this.parentObjectTypes.length > 0) {
17
+ const superToRdfOptions = `{ ${variables.ignoreRdfType}: true, ${variables.mutateGraph}, ${variables.resourceSet} }`;
18
+ let superToRdfCall;
19
+ switch (this.declarationType) {
20
+ case "class":
21
+ superToRdfCall = `super.toRdf(${superToRdfOptions})`;
22
+ break;
23
+ case "interface":
24
+ superToRdfCall = `${this.parentObjectTypes[0].name}.toRdf(${this.thisVariable}, ${superToRdfOptions})`;
25
+ break;
26
+ }
27
+ statements.push(`const ${variables.resource} = ${superToRdfCall};`);
28
+ usedIgnoreRdfTypeVariable = !this.parentObjectTypes[0].abstract;
29
+ }
30
+ else if (this.identifierType.isNamedNodeKind) {
31
+ statements.push(`const ${variables.resource} = ${variables.resourceSet}.mutableNamedResource({ identifier: ${this.thisVariable}.${this.identifierProperty.name}, ${variables.mutateGraph} });`);
32
+ }
33
+ else {
34
+ statements.push(`const ${variables.resource} = ${variables.resourceSet}.mutableResource({ identifier: ${this.thisVariable}.${this.identifierProperty.name}, ${variables.mutateGraph} });`);
35
+ }
36
+ if (this.toRdfTypes.length > 0) {
37
+ statements.push(`if (!${variables.ignoreRdfType}) { ${this.toRdfTypes.map((toRdfType) => `${variables.resource}.add(${variables.resource}.dataFactory.namedNode("${rdf.type.value}"), ${variables.resource}.dataFactory.namedNode("${toRdfType.value}"));`).join(" ")} }`);
38
+ usedIgnoreRdfTypeVariable = true;
39
+ }
40
+ for (const property of this.properties) {
41
+ statements.push(...property.toRdfStatements({
42
+ variables: {
43
+ ...variables,
44
+ value: `${this.thisVariable}.${property.name}`,
45
+ },
46
+ }));
47
+ }
48
+ statements.push(`return ${variables.resource};`);
49
+ const parameters = [];
50
+ if (this.declarationType === "interface") {
51
+ parameters.push({
52
+ name: this.thisVariable,
53
+ type: this.name,
54
+ });
55
+ }
56
+ parameters.push({
57
+ name: `{ ${usedIgnoreRdfTypeVariable ? `${variables.ignoreRdfType}, ` : ""}${variables.mutateGraph}, ${variables.resourceSet} }`,
58
+ type: `{ ${variables.ignoreRdfType}?: boolean; ${variables.mutateGraph}: rdfjsResource.MutableResource.MutateGraph, ${variables.resourceSet}: rdfjsResource.MutableResourceSet }`,
59
+ });
60
+ return Maybe.of({
61
+ name: "toRdf",
62
+ parameters,
63
+ returnType: this.rdfjsResourceType({ mutable: true }).name,
64
+ statements,
65
+ });
66
+ }
67
+ //# sourceMappingURL=toRdfFunctionOrMethodDeclaration.js.map
@@ -0,0 +1,2 @@
1
+ export declare function objectInitializer(properties: Record<string, boolean | number | string | undefined>): string;
2
+ //# sourceMappingURL=objectInitializer.d.ts.map
@@ -0,0 +1,14 @@
1
+ export function objectInitializer(properties) {
2
+ return `{ ${Object.entries(properties)
3
+ .flatMap(([propertyName, propertyValue]) => {
4
+ if (typeof propertyValue === "undefined") {
5
+ return [];
6
+ }
7
+ if (typeof propertyValue === "string" && propertyName === propertyValue) {
8
+ return [propertyName];
9
+ }
10
+ return [`${propertyName}: ${propertyValue}`];
11
+ })
12
+ .join(", ")} }`;
13
+ }
14
+ //# sourceMappingURL=objectInitializer.js.map
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Prefix a comment with multiline comment delimiters.
3
+ */
4
+ export declare function tsComment(comment: string): string;
5
+ //# sourceMappingURL=tsComment.d.ts.map
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Prefix a comment with multiline comment delimiters.
3
+ */
4
+ export function tsComment(comment) {
5
+ return `/**\n${comment
6
+ .trim()
7
+ .split(/\r?\n|\r|\n/g)
8
+ .map((line) => ` * ${line}`)
9
+ .join("\n")}\n */\n`;
10
+ }
11
+ //# sourceMappingURL=tsComment.js.map
@@ -1,3 +1,3 @@
1
- import type * as ast from "../../ast";
1
+ import type * as ast from "../../ast/index.js";
2
2
  export declare function tsName(astName: ast.Name): string;
3
3
  //# sourceMappingURL=tsName.d.ts.map
@@ -4,6 +4,7 @@ export function tsName(astName) {
4
4
  for (const tsNameAlternative of [
5
5
  astName.shaclmateName.extract(),
6
6
  astName.shName.extract()?.replace(" ", "_"),
7
+ astName.label.extract()?.replace(" ", "_"),
7
8
  astName.curie.map((curie) => curie.replace(":", "_")).extract(),
8
9
  astName.propertyPath
9
10
  .chain((propertyPath) => propertyPath.curie.map((curie) => curie.replace(":", "_")))
package/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from "./ShapesGraphToAstTransformer.js";
1
+ export * from "./Compiler.js";
2
2
  //# sourceMappingURL=index.d.ts.map
package/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export * from "./ShapesGraphToAstTransformer.js";
1
+ export * from "./Compiler.js";
2
2
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,46 @@
1
+ import type { NamedNode } from "@rdfjs/types";
2
+ import { NodeShape as ShaclCoreNodeShape } from "@shaclmate/shacl-ast";
3
+ import { Maybe } from "purify-ts";
4
+ import type { MintingStrategy, TsFeature, TsObjectDeclarationType } from "../enums/index.js";
5
+ import type { Shape } from "./Shape.js";
6
+ import type * as generated from "./generated.js";
7
+ import type { Ontology, PropertyGroup, PropertyShape, ShapesGraph } from "./index.js";
8
+ export declare class NodeShape extends ShaclCoreNodeShape<any, Ontology, PropertyGroup, PropertyShape, Shape> {
9
+ readonly isClass: boolean;
10
+ readonly isList: boolean;
11
+ private readonly ancestorClassIris;
12
+ private readonly childClassIris;
13
+ private readonly descendantClassIris;
14
+ private readonly generatedShaclmateNodeShape;
15
+ private readonly parentClassIris;
16
+ constructor({ ancestorClassIris, childClassIris, descendantClassIris, generatedShaclmateNodeShape, isClass, isList, parentClassIris, shapesGraph, }: {
17
+ ancestorClassIris: readonly NamedNode[];
18
+ generatedShaclmateNodeShape: generated.ShaclmateNodeShape;
19
+ childClassIris: readonly NamedNode[];
20
+ descendantClassIris: readonly NamedNode[];
21
+ isClass: boolean;
22
+ isList: boolean;
23
+ parentClassIris: readonly NamedNode[];
24
+ shapesGraph: ShapesGraph;
25
+ });
26
+ get abstract(): Maybe<boolean>;
27
+ get ancestorNodeShapes(): readonly NodeShape[];
28
+ get childNodeShapes(): readonly NodeShape[];
29
+ get descendantNodeShapes(): readonly NodeShape[];
30
+ get export(): Maybe<boolean>;
31
+ get extern(): Maybe<boolean>;
32
+ get fromRdfType(): Maybe<NamedNode>;
33
+ get mintingStrategy(): Maybe<MintingStrategy>;
34
+ get mutable(): Maybe<boolean>;
35
+ get nodeKinds(): Set<"BlankNode" | "NamedNode">;
36
+ get parentNodeShapes(): readonly NodeShape[];
37
+ get shaclmateName(): Maybe<string>;
38
+ get toRdfTypes(): readonly NamedNode[];
39
+ get tsFeatures(): Maybe<Set<TsFeature>>;
40
+ get tsImports(): readonly string[];
41
+ get tsObjectDeclarationType(): Maybe<TsObjectDeclarationType>;
42
+ get tsObjectIdentifierPropertyName(): Maybe<string>;
43
+ get tsObjectTypeDiscriminatorPropertyName(): Maybe<string>;
44
+ private get _mintingStrategy();
45
+ }
46
+ //# sourceMappingURL=NodeShape.d.ts.map