@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
@@ -1,26 +1,37 @@
1
1
  import type { NamedNode } from "@rdfjs/types";
2
2
  import { Maybe } from "purify-ts";
3
- import { MintingStrategy } from "../../ast";
3
+ import type { MintingStrategy, TsFeature } from "../../enums/index.js";
4
+ import { Import } from "./Import.js";
4
5
  import { Type } from "./Type.js";
5
6
  export declare class ListType extends Type {
6
7
  readonly itemType: Type;
7
8
  readonly kind = "ListType";
9
+ readonly mutable: boolean;
8
10
  private readonly identifierNodeKind;
9
11
  private readonly mintingStrategy;
10
- private readonly rdfType;
11
- constructor({ identifierNodeKind, itemType, mintingStrategy, rdfType, ...superParameters }: {
12
+ private readonly toRdfTypes;
13
+ constructor({ identifierNodeKind, itemType, mintingStrategy, mutable, toRdfTypes, ...superParameters }: {
12
14
  identifierNodeKind: ListType["identifierNodeKind"];
13
15
  itemType: Type;
14
16
  mintingStrategy: Maybe<MintingStrategy>;
15
- rdfType: Maybe<NamedNode>;
17
+ mutable: boolean;
18
+ toRdfTypes: readonly NamedNode[];
16
19
  } & ConstructorParameters<typeof Type>[0]);
20
+ get conversions(): readonly Type.Conversion[];
17
21
  get discriminatorProperty(): Maybe<Type.DiscriminatorProperty>;
18
- get importStatements(): readonly string[];
22
+ get equalsFunction(): string;
23
+ get jsonName(): string;
19
24
  get name(): string;
20
- chainSparqlGraphPatternExpression({ variables, }: Parameters<Type["chainSparqlGraphPatternExpression"]>[0]): Maybe<Type.SparqlGraphPatternsExpression>;
21
- equalsFunction(): string;
25
+ fromJsonExpression({ variables, }: Parameters<Type["fromJsonExpression"]>[0]): string;
22
26
  fromRdfExpression({ variables, }: Parameters<Type["fromRdfExpression"]>[0]): string;
23
- hashStatements({ variables, }: Parameters<Type["hashStatements"]>[0]): readonly string[];
27
+ hashStatements({ depth, variables, }: Parameters<Type["hashStatements"]>[0]): readonly string[];
28
+ jsonUiSchemaElement(parameters: Parameters<Type["jsonUiSchemaElement"]>[0]): ReturnType<Type["jsonUiSchemaElement"]>;
29
+ jsonZodSchema(parameters: Parameters<Type["jsonZodSchema"]>[0]): ReturnType<Type["jsonZodSchema"]>;
30
+ snippetDeclarations(features: Set<TsFeature>): readonly string[];
31
+ sparqlConstructTemplateTriples({ variables, context, }: Parameters<Type["sparqlConstructTemplateTriples"]>[0]): readonly string[];
32
+ sparqlWherePatterns({ variables, context, }: Parameters<Type["sparqlWherePatterns"]>[0]): readonly string[];
33
+ toJsonExpression({ variables, }: Parameters<Type["toJsonExpression"]>[0]): string;
24
34
  toRdfExpression({ variables, }: Parameters<Type["toRdfExpression"]>[0]): string;
35
+ useImports(features: Set<TsFeature>): readonly Import[];
25
36
  }
26
37
  //# sourceMappingURL=ListType.d.ts.map
@@ -1,74 +1,229 @@
1
- import { NodeKind } from "@shaclmate/shacl-ast";
2
1
  import { rdf } from "@tpluscode/rdf-ns-builders";
3
2
  import { Maybe } from "purify-ts";
4
- import { MintingStrategy } from "../../ast";
3
+ import { Import } from "./Import.js";
4
+ import { SnippetDeclarations } from "./SnippetDeclarations.js";
5
5
  import { Type } from "./Type.js";
6
+ import { objectInitializer } from "./objectInitializer.js";
6
7
  export class ListType extends Type {
7
- constructor({ identifierNodeKind, itemType, mintingStrategy, rdfType, ...superParameters }) {
8
+ constructor({ identifierNodeKind, itemType, mintingStrategy, mutable, toRdfTypes, ...superParameters }) {
8
9
  super(superParameters);
9
10
  this.kind = "ListType";
10
11
  this.identifierNodeKind = identifierNodeKind;
11
12
  this.itemType = itemType;
12
- this.mintingStrategy = mintingStrategy.orDefault(MintingStrategy.SHA256);
13
- this.rdfType = rdfType;
13
+ this.mintingStrategy = mintingStrategy.orDefault("sha256");
14
+ this.mutable = mutable;
15
+ this.toRdfTypes = toRdfTypes;
16
+ }
17
+ get conversions() {
18
+ return [
19
+ {
20
+ conversionExpression: (value) => value,
21
+ sourceTypeCheckExpression: (value) => `Array.isArray(${value})`,
22
+ sourceTypeName: this.name,
23
+ },
24
+ ];
14
25
  }
15
26
  get discriminatorProperty() {
16
27
  return Maybe.empty();
17
28
  }
18
- get importStatements() {
19
- if (this.identifierNodeKind === NodeKind.IRI) {
20
- return ['import { sha256 } from "js-sha256";'];
21
- }
22
- return [];
29
+ get equalsFunction() {
30
+ return `((left, right) => arrayEquals(left, right, ${this.itemType.equalsFunction}))`;
23
31
  }
24
- get name() {
25
- return `readonly ${this.itemType.name}[]`;
32
+ get jsonName() {
33
+ return `readonly (${this.itemType.jsonName})[]`;
26
34
  }
27
- chainSparqlGraphPatternExpression({ variables, }) {
28
- return Maybe.of(new Type.SparqlGraphPatternsExpression(`new sparqlBuilder.RdfListGraphPatterns({ ${this.itemType
29
- .chainSparqlGraphPatternExpression({
30
- variables: {
31
- subject: "itemVariable",
32
- },
33
- })
34
- .map((itemSparqlGraphPatternsExpression) => `itemGraphPatterns: (itemVariable) => ${itemSparqlGraphPatternsExpression.toSparqlGraphPatternsExpression()}, `)
35
- .orDefault("")} rdfList: ${variables.subject} })`));
35
+ get name() {
36
+ return `${this.mutable ? "" : "readonly "}${this.itemType.name}[]`;
36
37
  }
37
- equalsFunction() {
38
- return `(left, right) => purifyHelpers.Arrays.equals(left, right, ${this.itemType.equalsFunction()})`;
38
+ fromJsonExpression({ variables, }) {
39
+ return `${variables.value}.map(_item => (${this.itemType.fromJsonExpression({ variables: { value: "_item" } })}))`;
39
40
  }
40
41
  fromRdfExpression({ variables, }) {
41
- return `${variables.resourceValues}.head().chain(value => value.toList()).map(values => values.flatMap(value => ${this.itemType.fromRdfExpression({ variables: { ...variables, resourceValues: "value.toValues()" } })}.toMaybe().toList()))`;
42
+ const chain = [variables.resourceValues];
43
+ chain.push("head()");
44
+ chain.push("chain(value => value.toList())");
45
+ chain.push(`map(values => values.flatMap(_value => ${this.itemType.fromRdfExpression({ variables: { ...variables, resourceValues: "_value.toValues()" } })}.toMaybe().toList()))`);
46
+ return chain.join(".");
42
47
  }
43
- hashStatements({ variables, }) {
48
+ hashStatements({ depth, variables, }) {
44
49
  return [
45
- `for (const element of ${variables.value}) { ${this.itemType.hashStatements({ variables: { ...variables, value: "element" } }).join("\n")} }`,
50
+ `for (const _element${depth} of ${variables.value}) { ${this.itemType.hashStatements({ depth: depth + 1, variables: { ...variables, value: `_element${depth}` } }).join("\n")} }`,
46
51
  ];
47
52
  }
53
+ jsonUiSchemaElement(parameters) {
54
+ return this.itemType.jsonUiSchemaElement(parameters);
55
+ }
56
+ jsonZodSchema(parameters) {
57
+ return `${this.itemType.jsonZodSchema(parameters)}.array()`;
58
+ }
59
+ snippetDeclarations(features) {
60
+ const snippetDeclarations = [];
61
+ if (features.has("equals")) {
62
+ snippetDeclarations.push(SnippetDeclarations.arrayEquals);
63
+ }
64
+ return snippetDeclarations;
65
+ }
66
+ sparqlConstructTemplateTriples({ variables, context, }) {
67
+ switch (context) {
68
+ case "property":
69
+ return super.sparqlConstructTemplateTriples({ context, variables });
70
+ case "type": {
71
+ const triples = [];
72
+ const listVariable = variables.subject;
73
+ const variable = (suffix) => `${this.dataFactoryVariable}.variable!(\`\${${variables.variablePrefix}}${suffix}\`)`;
74
+ const variablePrefix = (suffix) => `\`\${${variables.variablePrefix}}${suffix}\``;
75
+ {
76
+ // ?list rdf:first ?item0
77
+ const item0Variable = variable("Item0");
78
+ triples.push(objectInitializer({
79
+ subject: listVariable,
80
+ predicate: this.rdfjsTermExpression(rdf.first),
81
+ object: item0Variable,
82
+ }), ...this.itemType.sparqlConstructTemplateTriples({
83
+ context: "type",
84
+ variables: {
85
+ subject: item0Variable,
86
+ variablePrefix: variablePrefix("Item0"),
87
+ },
88
+ }));
89
+ }
90
+ {
91
+ // ?list rdf:rest ?rest0
92
+ const rest0Variable = variable("Rest0");
93
+ triples.push(objectInitializer({
94
+ subject: listVariable,
95
+ predicate: this.rdfjsTermExpression(rdf.rest),
96
+ object: rest0Variable,
97
+ }));
98
+ }
99
+ // Don't do ?list rdf:rest+ ?restN in CONSTRUCT
100
+ const restNVariable = variable("RestN");
101
+ {
102
+ // ?rest rdf:first ?itemN
103
+ const itemNVariable = variable("ItemN");
104
+ triples.push(objectInitializer({
105
+ subject: restNVariable,
106
+ predicate: this.rdfjsTermExpression(rdf.first),
107
+ object: itemNVariable,
108
+ }), ...this.itemType.sparqlConstructTemplateTriples({
109
+ context: "type",
110
+ variables: {
111
+ subject: itemNVariable,
112
+ variablePrefix: variablePrefix("ItemN"),
113
+ },
114
+ }));
115
+ }
116
+ // ?restN rdf:rest ?restNBasic to get the rdf:rest statement in the CONSTRUCT
117
+ triples.push(objectInitializer({
118
+ subject: restNVariable,
119
+ predicate: this.rdfjsTermExpression(rdf.rest),
120
+ object: variable("RestNBasic"),
121
+ }));
122
+ return triples;
123
+ }
124
+ }
125
+ }
126
+ sparqlWherePatterns({ variables, context, }) {
127
+ switch (context) {
128
+ case "property":
129
+ return super.sparqlWherePatterns({ context, variables });
130
+ case "type": {
131
+ const patterns = [];
132
+ const listVariable = variables.subject;
133
+ const variable = (suffix) => `${this.dataFactoryVariable}.variable!(\`\${${variables.variablePrefix}}${suffix}\`)`;
134
+ const variablePrefix = (suffix) => `\`\${${variables.variablePrefix}}${suffix}\``;
135
+ {
136
+ // ?list rdf:first ?item0
137
+ const item0Variable = variable("Item0");
138
+ patterns.push(`{ type: "bgp", triples: [${objectInitializer({
139
+ subject: listVariable,
140
+ predicate: this.rdfjsTermExpression(rdf.first),
141
+ object: item0Variable,
142
+ })}] }`, ...this.itemType.sparqlWherePatterns({
143
+ context: "type",
144
+ variables: {
145
+ subject: item0Variable,
146
+ variablePrefix: variablePrefix("Item0"),
147
+ },
148
+ }));
149
+ }
150
+ {
151
+ // ?list rdf:rest ?rest0
152
+ const rest0Variable = variable("Rest0");
153
+ patterns.push(`{ type: "bgp", triples: [${objectInitializer({
154
+ subject: listVariable,
155
+ predicate: this.rdfjsTermExpression(rdf.rest),
156
+ object: rest0Variable,
157
+ })}] }`);
158
+ }
159
+ const optionalPatterns = [];
160
+ const restNVariable = variable("RestN");
161
+ // ?list rdf:rest+ ?restN
162
+ optionalPatterns.push(`{ type: "bgp", triples: [${objectInitializer({
163
+ subject: listVariable,
164
+ predicate: `{ type: "path", pathType: "*", items: [${this.rdfjsTermExpression(rdf.rest)}] }`,
165
+ object: restNVariable,
166
+ })}] }`);
167
+ {
168
+ // ?rest rdf:first ?itemN
169
+ const itemNVariable = variable("ItemN");
170
+ optionalPatterns.push(`{ type: "bgp", triples: [${objectInitializer({
171
+ subject: restNVariable,
172
+ predicate: this.rdfjsTermExpression(rdf.first),
173
+ object: itemNVariable,
174
+ })}] }`, ...this.itemType.sparqlWherePatterns({
175
+ context: "type",
176
+ variables: {
177
+ subject: itemNVariable,
178
+ variablePrefix: variablePrefix("ItemN"),
179
+ },
180
+ }));
181
+ }
182
+ // ?restN rdf:rest ?restNBasic to get the rdf:rest statement in the CONSTRUCT
183
+ optionalPatterns.push(`{ type: "bgp", triples: [${objectInitializer({
184
+ subject: restNVariable,
185
+ predicate: this.rdfjsTermExpression(rdf.rest),
186
+ object: variable("RestNBasic"),
187
+ })}] }`);
188
+ patterns.push(`{ type: "optional", patterns: [${optionalPatterns.join(", ")}] }`);
189
+ return patterns;
190
+ }
191
+ }
192
+ }
193
+ toJsonExpression({ variables, }) {
194
+ let expression = variables.value;
195
+ const itemFromJsonExpression = this.itemType.fromJsonExpression({
196
+ variables: { value: "_item" },
197
+ });
198
+ if (itemFromJsonExpression !== "_item") {
199
+ expression = `${expression}.map(_item => (${itemFromJsonExpression}))`;
200
+ }
201
+ return `${variables.value}.map(_item => (${this.itemType.toJsonExpression({ variables: { value: "_item" } })}))`;
202
+ }
48
203
  toRdfExpression({ variables, }) {
49
204
  let listIdentifier;
50
205
  let mutableResourceTypeName;
51
206
  let resourceSetMethodName;
52
207
  let subListIdentifier;
53
208
  switch (this.identifierNodeKind) {
54
- case NodeKind.BLANK_NODE: {
209
+ case "BlankNode": {
55
210
  listIdentifier = subListIdentifier = "dataFactory.blankNode()";
56
211
  mutableResourceTypeName = "rdfjsResource.MutableResource";
57
212
  resourceSetMethodName = "mutableResource";
58
213
  break;
59
214
  }
60
- case NodeKind.IRI: {
215
+ case "NamedNode": {
61
216
  switch (this.mintingStrategy) {
62
- case MintingStrategy.SHA256:
217
+ case "sha256":
63
218
  listIdentifier = `dataFactory.namedNode(\`urn:shaclmate:list:\${${variables.value}.reduce(
64
- (hasher, item) => {
65
- ${this.itemType.hashStatements({ variables: { hasher: "hasher", value: "item" } })}
66
- return hasher;
219
+ (_hasher, _item) => {
220
+ ${this.itemType.hashStatements({ depth: 0, variables: { hasher: "_hasher", value: "_item" } }).join("\n")}
221
+ return _hasher;
67
222
  },
68
223
  sha256.create(),
69
224
  )}\`)`;
70
225
  break;
71
- case MintingStrategy.UUIDv4:
226
+ case "uuidv4":
72
227
  listIdentifier =
73
228
  "dataFactory.namedNode(`urn:shaclmate:list:${uuid.v4()}`)";
74
229
  break;
@@ -81,23 +236,23 @@ export class ListType extends Type {
81
236
  break;
82
237
  }
83
238
  }
84
- return `${variables.value}.reduce(({ currentSubListResource, listResource }, item, itemIndex) => {
239
+ return `${variables.value}.reduce(({ currentSubListResource, listResource }, item, itemIndex, list) => {
85
240
  if (itemIndex === 0) {
86
241
  currentSubListResource = listResource;
87
242
  } else {
88
- const newSubListResource = ${variables.resourceSet}.${resourceSetMethodName}({
89
- identifier: ${subListIdentifier},
90
- mutateGraph: ${variables.mutateGraph},
91
- });
243
+ const newSubListResource = ${variables.resourceSet}.${resourceSetMethodName}(${objectInitializer({
244
+ identifier: subListIdentifier,
245
+ mutateGraph: variables.mutateGraph,
246
+ })});
92
247
  currentSubListResource!.add(dataFactory.namedNode("${rdf.rest.value}"), newSubListResource.identifier);
93
248
  currentSubListResource = newSubListResource;
94
249
  }
95
250
 
96
- ${this.rdfType.map((rdfType) => `currentSubListResource.add(dataFactory.namedNode("${rdf.type.value}"), dataFactory.namedNode("${rdfType.value}"))`).orDefault("")}
251
+ ${this.toRdfTypes.map((rdfType) => `currentSubListResource.add(dataFactory.namedNode("${rdf.type.value}"), dataFactory.namedNode("${rdfType.value}"))`).join("\n")}
97
252
 
98
253
  currentSubListResource.add(dataFactory.namedNode("${rdf.first.value}"), ${this.itemType.toRdfExpression({ variables: { mutateGraph: variables.mutateGraph, predicate: `dataFactory.namedNode("${rdf.first.value}")`, resource: "currentSubListResource", resourceSet: variables.resourceSet, value: "item" } })});
99
254
 
100
- if (itemIndex + 1 === ${variables.value}.length) {
255
+ if (itemIndex + 1 === list.length) {
101
256
  currentSubListResource.add(dataFactory.namedNode("${rdf.rest.value}"), dataFactory.namedNode("${rdf.nil.value}"));
102
257
  }
103
258
 
@@ -105,15 +260,22 @@ export class ListType extends Type {
105
260
  },
106
261
  {
107
262
  currentSubListResource: null,
108
- listResource: resourceSet.${resourceSetMethodName}({
109
- identifier: ${listIdentifier},
110
- mutateGraph: ${variables.mutateGraph}
111
- }),
263
+ listResource: resourceSet.${resourceSetMethodName}(${objectInitializer({
264
+ identifier: listIdentifier,
265
+ mutateGraph: variables.mutateGraph,
266
+ })}),
112
267
  } as {
113
268
  currentSubListResource: ${mutableResourceTypeName} | null;
114
269
  listResource: ${mutableResourceTypeName};
115
270
  },
116
271
  ).listResource.identifier`;
117
272
  }
273
+ useImports(features) {
274
+ const imports = this.itemType.useImports(features).concat();
275
+ if (features.has("hash") && this.identifierNodeKind === "NamedNode") {
276
+ imports.push(Import.SHA256);
277
+ }
278
+ return imports;
279
+ }
118
280
  }
119
281
  //# sourceMappingURL=ListType.js.map
@@ -1,14 +1,16 @@
1
1
  import type { Literal } from "@rdfjs/types";
2
- import { Maybe } from "purify-ts";
3
- import { RdfjsTermType } from "./RdfjsTermType.js";
4
- import type { Type } from "./Type";
5
- export declare class LiteralType extends RdfjsTermType<Literal> {
6
- readonly kind = "LiteralType";
7
- get conversions(): readonly Type.Conversion[];
8
- get discriminatorProperty(): Maybe<Type.DiscriminatorProperty>;
9
- get importStatements(): readonly string[];
10
- get name(): string;
11
- fromRdfResourceValueExpression({ variables, }: Parameters<RdfjsTermType<Literal>["fromRdfResourceValueExpression"]>[0]): string;
12
- hashStatements({ variables, }: Parameters<RdfjsTermType<Literal>["hashStatements"]>[0]): readonly string[];
2
+ import { TermType } from "./TermType.js";
3
+ export declare class LiteralType extends TermType<Literal> {
4
+ private readonly languageIn;
5
+ constructor({ languageIn, ...superParameters }: {
6
+ languageIn: readonly string[];
7
+ } & Omit<ConstructorParameters<typeof TermType<Literal>>[0], "nodeKinds">);
8
+ get jsonName(): string;
9
+ fromJsonExpression({ variables, }: Parameters<TermType<Literal>["fromJsonExpression"]>[0]): string;
10
+ hashStatements({ depth, variables, }: Parameters<TermType<Literal>["hashStatements"]>[0]): readonly string[];
11
+ jsonZodSchema({ variables, }: Parameters<TermType<Literal>["jsonZodSchema"]>[0]): ReturnType<TermType<Literal>["jsonZodSchema"]>;
12
+ propertyFromRdfResourceValueExpression({ variables, }: Parameters<TermType<Literal>["propertyFromRdfResourceValueExpression"]>[0]): string;
13
+ toJsonExpression({ variables, }: Parameters<TermType<Literal>["toJsonExpression"]>[0]): string;
14
+ protected propertyFilterRdfResourceValuesExpression({ variables, }: Parameters<TermType<Literal>["propertyFilterRdfResourceValuesExpression"]>[0]): string;
13
15
  }
14
16
  //# sourceMappingURL=LiteralType.d.ts.map
@@ -1,61 +1,46 @@
1
- import { Maybe } from "purify-ts";
2
- import { RdfjsTermType } from "./RdfjsTermType.js";
3
- import { rdfjsTermExpression } from "./rdfjsTermExpression";
4
- export class LiteralType extends RdfjsTermType {
5
- constructor() {
6
- super(...arguments);
7
- this.kind = "LiteralType";
8
- }
9
- get conversions() {
10
- const conversions = [];
11
- conversions.push({
12
- conversionExpression: (value) => `rdfLiteral.toRdf(${value})`,
13
- sourceTypeName: "boolean",
1
+ import { xsd } from "@tpluscode/rdf-ns-builders";
2
+ import { TermType } from "./TermType.js";
3
+ export class LiteralType extends TermType {
4
+ constructor({ languageIn, ...superParameters }) {
5
+ super({
6
+ ...superParameters,
7
+ nodeKinds: new Set(["Literal"]),
14
8
  });
15
- conversions.push({
16
- conversionExpression: (value) => `rdfLiteral.toRdf(${value})`,
17
- sourceTypeCheckExpression: (value) => `typeof ${value} === "object" && ${value} instanceof Date`,
18
- sourceTypeName: "Date",
19
- });
20
- conversions.push({
21
- conversionExpression: (value) => `rdfLiteral.toRdf(${value})`,
22
- sourceTypeName: "number",
23
- });
24
- conversions.push({
25
- conversionExpression: (value) => `${this.configuration.dataFactoryVariable}.literal(${value})`,
26
- sourceTypeName: "string",
27
- });
28
- this.defaultValue.ifJust((defaultValue) => {
29
- conversions.push({
30
- conversionExpression: () => rdfjsTermExpression(defaultValue, this.configuration),
31
- sourceTypeName: "undefined",
32
- });
33
- });
34
- conversions.push({
35
- conversionExpression: (value) => value,
36
- sourceTypeCheckExpression: (value) => `typeof ${value} === "object"`,
37
- sourceTypeName: this.name,
38
- });
39
- return conversions;
9
+ this.languageIn = languageIn;
40
10
  }
41
- get discriminatorProperty() {
42
- return Maybe.of({
43
- name: "termType",
44
- type: "string",
45
- values: ["Literal"],
46
- });
11
+ get jsonName() {
12
+ return '{ readonly "@language": string | undefined, readonly "@type": string | undefined, readonly "@value": string }';
47
13
  }
48
- get importStatements() {
49
- return ["// @ts-ignore", 'import * as rdfLiteral from "rdf-literal";'];
14
+ fromJsonExpression({ variables, }) {
15
+ return `${this.dataFactoryVariable}.literal(${variables.value}["@value"], typeof ${variables.value}["@language"] !== "undefined" ? ${variables.value}["@language"] : (typeof ${variables.value}["@type"] !== "undefined" ? dataFactory.namedNode(${variables.value}["@type"]) : undefined))`;
50
16
  }
51
- get name() {
52
- return "rdfjs.Literal";
17
+ hashStatements({ depth, variables, }) {
18
+ return [
19
+ `${variables.hasher}.update(${variables.value}.datatype.value);`,
20
+ `${variables.hasher}.update(${variables.value}.language);`,
21
+ ].concat(super.hashStatements({ depth, variables }));
53
22
  }
54
- fromRdfResourceValueExpression({ variables, }) {
23
+ jsonZodSchema({ variables, }) {
24
+ return `${variables.zod}.object({ "@language": ${variables.zod}.string().optional(), "@type": ${variables.zod}.string().optional(), "@value": ${variables.zod}.string() })`;
25
+ }
26
+ propertyFromRdfResourceValueExpression({ variables, }) {
55
27
  return `${variables.resourceValue}.toLiteral()`;
56
28
  }
57
- hashStatements({ variables, }) {
58
- return [`${variables.hasher}.update(${variables.value}.value);`];
29
+ toJsonExpression({ variables, }) {
30
+ return `{ "@language": ${variables.value}.language.length > 0 ? ${variables.value}.language : undefined, "@type": ${variables.value}.datatype.value !== "${xsd.string.value}" ? ${variables.value}.datatype.value : undefined, "@value": ${variables.value}.value }`;
31
+ }
32
+ propertyFilterRdfResourceValuesExpression({ variables, }) {
33
+ return `${variables.resourceValues}.filter(_value => {
34
+ const _languageInOrDefault = ${variables.languageIn} ?? ${JSON.stringify(this.languageIn)};
35
+ if (_languageInOrDefault.length === 0) {
36
+ return true;
37
+ }
38
+ const _valueLiteral = _value.toLiteral().toMaybe().extract();
39
+ if (typeof _valueLiteral === "undefined") {
40
+ return false;
41
+ }
42
+ return _languageInOrDefault.some(_languageIn => _languageIn === _valueLiteral.language);
43
+ })`;
59
44
  }
60
45
  }
61
46
  //# sourceMappingURL=LiteralType.js.map
@@ -1,7 +1,11 @@
1
1
  import { PrimitiveType } from "./PrimitiveType.js";
2
- export declare class NumberType extends PrimitiveType {
2
+ import type { Type } from "./Type.js";
3
+ export declare class NumberType extends PrimitiveType<number> {
4
+ readonly kind = "NumberType";
5
+ get conversions(): readonly Type.Conversion[];
3
6
  get name(): string;
4
- fromRdfResourceValueExpression({ variables, }: Parameters<PrimitiveType["fromRdfResourceValueExpression"]>[0]): string;
5
- hashStatements({ variables, }: Parameters<PrimitiveType["hashStatements"]>[0]): readonly string[];
7
+ jsonZodSchema({ variables, }: Parameters<Type["jsonZodSchema"]>[0]): ReturnType<Type["jsonZodSchema"]>;
8
+ propertyFromRdfResourceValueExpression({ variables, }: Parameters<PrimitiveType<number>["propertyFromRdfResourceValueExpression"]>[0]): string;
9
+ toRdfExpression({ variables, }: Parameters<PrimitiveType<string>["toRdfExpression"]>[0]): string;
6
10
  }
7
11
  //# sourceMappingURL=NumberType.d.ts.map
@@ -1,13 +1,64 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { Memoize } from "typescript-memoize";
1
8
  import { PrimitiveType } from "./PrimitiveType.js";
9
+ import { objectInitializer } from "./objectInitializer.js";
2
10
  export class NumberType extends PrimitiveType {
11
+ constructor() {
12
+ super(...arguments);
13
+ this.kind = "NumberType";
14
+ }
15
+ get conversions() {
16
+ const conversions = [
17
+ {
18
+ conversionExpression: (value) => value,
19
+ sourceTypeCheckExpression: (value) => `typeof ${value} === "number"`,
20
+ sourceTypeName: this.name,
21
+ },
22
+ ];
23
+ this.primitiveDefaultValue.ifJust((defaultValue) => {
24
+ conversions.push({
25
+ conversionExpression: () => defaultValue.toString(),
26
+ sourceTypeCheckExpression: (value) => `typeof ${value} === "undefined"`,
27
+ sourceTypeName: "undefined",
28
+ });
29
+ });
30
+ return conversions;
31
+ }
3
32
  get name() {
33
+ if (this.primitiveIn.length > 0) {
34
+ return this.primitiveIn.map((value) => value.toString()).join(" | ");
35
+ }
4
36
  return "number";
5
37
  }
6
- fromRdfResourceValueExpression({ variables, }) {
7
- return `${variables.resourceValue}.toNumber()`;
38
+ jsonZodSchema({ variables, }) {
39
+ switch (this.primitiveIn.length) {
40
+ case 0:
41
+ return `${variables.zod}.number()`;
42
+ case 1:
43
+ return `${variables.zod}.literal(${this.primitiveIn[0]})`;
44
+ default:
45
+ return `${variables.zod}.union([${this.primitiveIn.map((value) => `${variables.zod}.literal(${value})`).join(", ")}])`;
46
+ }
47
+ }
48
+ propertyFromRdfResourceValueExpression({ variables, }) {
49
+ let expression = `${variables.resourceValue}.toNumber()`;
50
+ 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 })})); } })`;
52
+ }
53
+ return expression;
8
54
  }
9
- hashStatements({ variables, }) {
10
- return [`${variables.hasher}.update(${variables.value}.toString());`];
55
+ toRdfExpression({ variables, }) {
56
+ return this.primitiveDefaultValue
57
+ .map((defaultValue) => `${variables.value} !== ${defaultValue} ? ${variables.value} : undefined`)
58
+ .orDefault(variables.value);
11
59
  }
12
60
  }
61
+ __decorate([
62
+ Memoize()
63
+ ], NumberType.prototype, "name", null);
13
64
  //# sourceMappingURL=NumberType.js.map