@shaclmate/compiler 2.0.12 → 2.0.14

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 (204) 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 +165 -0
  17. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.d.ts +13 -0
  18. package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +198 -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 +92 -20
  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 +17 -0
  74. package/generators/ts/DateTimeType.js +58 -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 +18 -0
  80. package/generators/ts/Import.js +59 -0
  81. package/generators/ts/ListType.d.ts +18 -8
  82. package/generators/ts/ListType.js +197 -43
  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 +47 -25
  88. package/generators/ts/ObjectType.js +222 -49
  89. package/generators/ts/ObjectUnionType.d.ts +58 -0
  90. package/generators/ts/ObjectUnionType.js +481 -0
  91. package/generators/ts/OptionType.d.ts +12 -4
  92. package/generators/ts/OptionType.js +65 -16
  93. package/generators/ts/PrimitiveType.d.ts +15 -5
  94. package/generators/ts/PrimitiveType.js +20 -29
  95. package/generators/ts/SetType.d.ts +12 -4
  96. package/generators/ts/SetType.js +103 -29
  97. package/generators/ts/StringType.d.ts +8 -3
  98. package/generators/ts/StringType.js +57 -3
  99. package/generators/ts/TermType.d.ts +52 -0
  100. package/generators/ts/TermType.js +234 -0
  101. package/generators/ts/TsGenerator.d.ts +4 -12
  102. package/generators/ts/TsGenerator.js +44 -100
  103. package/generators/ts/Type.d.ts +107 -46
  104. package/generators/ts/Type.js +78 -61
  105. package/generators/ts/TypeFactory.d.ts +4 -5
  106. package/generators/ts/TypeFactory.js +212 -89
  107. package/generators/ts/UnionType.d.ts +19 -6
  108. package/generators/ts/UnionType.js +230 -120
  109. package/generators/ts/_ObjectType/IdentifierProperty.d.ts +27 -7
  110. package/generators/ts/_ObjectType/IdentifierProperty.js +143 -31
  111. package/generators/ts/_ObjectType/Property.d.ts +125 -9
  112. package/generators/ts/_ObjectType/Property.js +25 -3
  113. package/generators/ts/_ObjectType/ShaclProperty.d.ts +23 -5
  114. package/generators/ts/_ObjectType/ShaclProperty.js +100 -26
  115. package/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +24 -6
  116. package/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +75 -13
  117. package/generators/ts/_ObjectType/classDeclaration.d.ts +2 -1
  118. package/generators/ts/_ObjectType/classDeclaration.js +79 -111
  119. package/generators/ts/_ObjectType/createFunctionDeclaration.d.ts +5 -0
  120. package/generators/ts/_ObjectType/createFunctionDeclaration.js +60 -0
  121. package/generators/ts/_ObjectType/equalsFunctionDeclaration.d.ts +2 -1
  122. package/generators/ts/_ObjectType/equalsFunctionDeclaration.js +12 -20
  123. package/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.d.ts +11 -0
  124. package/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.js +70 -0
  125. package/generators/ts/_ObjectType/fromJsonFunctionDeclarations.d.ts +4 -0
  126. package/generators/ts/_ObjectType/fromJsonFunctionDeclarations.js +78 -0
  127. package/generators/ts/_ObjectType/fromRdfFunctionDeclarations.d.ts +4 -0
  128. package/generators/ts/_ObjectType/fromRdfFunctionDeclarations.js +91 -0
  129. package/generators/ts/_ObjectType/hashFunctionDeclaration.d.ts +3 -3
  130. package/generators/ts/_ObjectType/hashFunctionDeclaration.js +11 -55
  131. package/generators/ts/_ObjectType/hashFunctionOrMethodDeclaration.d.ts +11 -0
  132. package/generators/ts/_ObjectType/hashFunctionOrMethodDeclaration.js +64 -0
  133. package/generators/ts/_ObjectType/index.d.ts +8 -2
  134. package/generators/ts/_ObjectType/index.js +8 -2
  135. package/generators/ts/_ObjectType/interfaceDeclaration.d.ts +3 -2
  136. package/generators/ts/_ObjectType/interfaceDeclaration.js +11 -2
  137. package/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.d.ts +5 -0
  138. package/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.js +19 -0
  139. package/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.d.ts +5 -0
  140. package/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.js +31 -0
  141. package/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.d.ts +5 -0
  142. package/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.js +37 -0
  143. package/generators/ts/_ObjectType/rdfjsTermExpression.d.ts +6 -0
  144. package/generators/ts/{rdfjsTermExpression.js → _ObjectType/rdfjsTermExpression.js} +3 -1
  145. package/generators/ts/_ObjectType/sparqlFunctionDeclarations.d.ts +4 -0
  146. package/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +101 -0
  147. package/generators/ts/_ObjectType/toJsonFunctionDeclaration.d.ts +5 -0
  148. package/generators/ts/_ObjectType/toJsonFunctionDeclaration.js +19 -0
  149. package/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.d.ts +10 -0
  150. package/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.js +59 -0
  151. package/generators/ts/_ObjectType/toJsonReturnType.d.ts +3 -0
  152. package/generators/ts/_ObjectType/toJsonReturnType.js +19 -0
  153. package/generators/ts/_ObjectType/toRdfFunctionDeclaration.d.ts +3 -2
  154. package/generators/ts/_ObjectType/toRdfFunctionDeclaration.js +11 -45
  155. package/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.d.ts +10 -0
  156. package/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.js +67 -0
  157. package/generators/ts/objectInitializer.d.ts +2 -0
  158. package/generators/ts/objectInitializer.js +14 -0
  159. package/generators/ts/tsComment.d.ts +5 -0
  160. package/generators/ts/tsComment.js +11 -0
  161. package/generators/ts/tsName.d.ts +1 -1
  162. package/generators/ts/tsName.js +1 -0
  163. package/index.d.ts +1 -1
  164. package/index.js +1 -1
  165. package/input/NodeShape.d.ts +46 -0
  166. package/input/NodeShape.js +165 -0
  167. package/input/Ontology.d.ts +13 -0
  168. package/input/Ontology.js +30 -0
  169. package/input/PropertyShape.d.ts +15 -0
  170. package/input/PropertyShape.js +34 -0
  171. package/input/Shape.d.ts +4 -0
  172. package/input/Shape.js +2 -0
  173. package/input/ShapesGraph.d.ts +9 -0
  174. package/input/ShapesGraph.js +50 -0
  175. package/input/ancestorClassIris.d.ts +4 -0
  176. package/input/ancestorClassIris.js +21 -0
  177. package/input/descendantClassIris.d.ts +4 -0
  178. package/input/descendantClassIris.js +21 -0
  179. package/input/generated.d.ts +274 -0
  180. package/input/generated.js +1420 -0
  181. package/input/index.d.ts +7 -0
  182. package/input/index.js +7 -0
  183. package/input/tsFeatures.d.ts +10 -0
  184. package/input/tsFeatures.js +42 -0
  185. package/package.json +14 -8
  186. package/ast/MintingStrategy.d.ts +0 -8
  187. package/ast/MintingStrategy.js +0 -9
  188. package/generators/ts/Configuration.d.ts +0 -29
  189. package/generators/ts/Configuration.js +0 -40
  190. package/generators/ts/IntersectionType.d.ts +0 -14
  191. package/generators/ts/IntersectionType.js +0 -26
  192. package/generators/ts/RdfjsTermType.d.ts +0 -25
  193. package/generators/ts/RdfjsTermType.js +0 -46
  194. package/generators/ts/_ObjectType/fromRdfFunctionDeclaration.d.ts +0 -4
  195. package/generators/ts/_ObjectType/fromRdfFunctionDeclaration.js +0 -72
  196. package/generators/ts/_ObjectType/sparqlGraphPatternsClassDeclaration.d.ts +0 -4
  197. package/generators/ts/_ObjectType/sparqlGraphPatternsClassDeclaration.js +0 -46
  198. package/generators/ts/rdfjsTermExpression.d.ts +0 -5
  199. package/vocabularies/dashDataset.d.ts +0 -3
  200. package/vocabularies/dashDataset.js +0 -2370
  201. package/vocabularies/index.d.ts +0 -2
  202. package/vocabularies/index.js +0 -2
  203. package/vocabularies/shaclmate.d.ts +0 -15
  204. package/vocabularies/shaclmate.js +0 -6
@@ -1,26 +1,36 @@
1
1
  import type { NamedNode } from "@rdfjs/types";
2
2
  import { Maybe } from "purify-ts";
3
- import { MintingStrategy } from "../../ast";
3
+ import type { MintingStrategy } 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
+ get useImports(): readonly Import[];
26
+ fromJsonExpression({ variables, }: Parameters<Type["fromJsonExpression"]>[0]): string;
22
27
  fromRdfExpression({ variables, }: Parameters<Type["fromRdfExpression"]>[0]): string;
23
- hashStatements({ variables, }: Parameters<Type["hashStatements"]>[0]): readonly string[];
28
+ hashStatements({ depth, variables, }: Parameters<Type["hashStatements"]>[0]): readonly string[];
29
+ jsonUiSchemaElement(parameters: Parameters<Type["jsonUiSchemaElement"]>[0]): ReturnType<Type["jsonUiSchemaElement"]>;
30
+ jsonZodSchema(parameters: Parameters<Type["jsonZodSchema"]>[0]): ReturnType<Type["jsonZodSchema"]>;
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;
25
35
  }
26
36
  //# sourceMappingURL=ListType.d.ts.map
@@ -1,74 +1,228 @@
1
1
  import { rdf } from "@tpluscode/rdf-ns-builders";
2
2
  import { Maybe } from "purify-ts";
3
- import { NodeKind } from "shacl-ast";
4
- import { MintingStrategy } from "../../ast";
3
+ import { Import } from "./Import.js";
5
4
  import { Type } from "./Type.js";
5
+ import { objectInitializer } from "./objectInitializer.js";
6
6
  export class ListType extends Type {
7
- constructor({ identifierNodeKind, itemType, mintingStrategy, rdfType, ...superParameters }) {
7
+ constructor({ identifierNodeKind, itemType, mintingStrategy, mutable, toRdfTypes, ...superParameters }) {
8
8
  super(superParameters);
9
9
  this.kind = "ListType";
10
10
  this.identifierNodeKind = identifierNodeKind;
11
11
  this.itemType = itemType;
12
- this.mintingStrategy = mintingStrategy.orDefault(MintingStrategy.SHA256);
13
- this.rdfType = rdfType;
12
+ this.mintingStrategy = mintingStrategy.orDefault("sha256");
13
+ this.mutable = mutable;
14
+ this.toRdfTypes = toRdfTypes;
15
+ }
16
+ get conversions() {
17
+ return [
18
+ {
19
+ conversionExpression: (value) => value,
20
+ sourceTypeCheckExpression: (value) => `Array.isArray(${value})`,
21
+ sourceTypeName: this.name,
22
+ },
23
+ ];
14
24
  }
15
25
  get discriminatorProperty() {
16
26
  return Maybe.empty();
17
27
  }
18
- get importStatements() {
19
- if (this.identifierNodeKind === NodeKind.IRI) {
20
- return ['import { sha256 } from "js-sha256";'];
21
- }
22
- return [];
28
+ get equalsFunction() {
29
+ return `((left, right) => purifyHelpers.Arrays.equals(left, right, ${this.itemType.equalsFunction}))`;
30
+ }
31
+ get jsonName() {
32
+ return `readonly (${this.itemType.jsonName})[]`;
23
33
  }
24
34
  get name() {
25
- return `readonly ${this.itemType.name}[]`;
35
+ return `${this.mutable ? "" : "readonly "}${this.itemType.name}[]`;
26
36
  }
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} })`));
37
+ get useImports() {
38
+ const imports = this.itemType.useImports.concat();
39
+ if (this.identifierNodeKind === "NamedNode") {
40
+ imports.push(Import.SHA256);
41
+ }
42
+ return imports;
36
43
  }
37
- equalsFunction() {
38
- return `(left, right) => purifyHelpers.Arrays.equals(left, right, ${this.itemType.equalsFunction()})`;
44
+ fromJsonExpression({ variables, }) {
45
+ return `${variables.value}.map(_item => (${this.itemType.fromJsonExpression({ variables: { value: "_item" } })}))`;
39
46
  }
40
47
  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()))`;
48
+ const chain = [variables.resourceValues];
49
+ chain.push("head()");
50
+ chain.push("chain(value => value.toList())");
51
+ chain.push(`map(values => values.flatMap(_value => ${this.itemType.fromRdfExpression({ variables: { ...variables, resourceValues: "_value.toValues()" } })}.toMaybe().toList()))`);
52
+ return chain.join(".");
42
53
  }
43
- hashStatements({ variables, }) {
54
+ hashStatements({ depth, variables, }) {
44
55
  return [
45
- `for (const element of ${variables.value}) { ${this.itemType.hashStatements({ variables: { ...variables, value: "element" } }).join("\n")} }`,
56
+ `for (const _element${depth} of ${variables.value}) { ${this.itemType.hashStatements({ depth: depth + 1, variables: { ...variables, value: `_element${depth}` } }).join("\n")} }`,
46
57
  ];
47
58
  }
59
+ jsonUiSchemaElement(parameters) {
60
+ return this.itemType.jsonUiSchemaElement(parameters);
61
+ }
62
+ jsonZodSchema(parameters) {
63
+ return `${this.itemType.jsonZodSchema(parameters)}.array()`;
64
+ }
65
+ sparqlConstructTemplateTriples({ variables, context, }) {
66
+ switch (context) {
67
+ case "property":
68
+ return super.sparqlConstructTemplateTriples({ context, variables });
69
+ case "type": {
70
+ const triples = [];
71
+ const listVariable = variables.subject;
72
+ const variable = (suffix) => `${this.dataFactoryVariable}.variable!(\`\${${variables.variablePrefix}}${suffix}\`)`;
73
+ const variablePrefix = (suffix) => `\`\${${variables.variablePrefix}}${suffix}\``;
74
+ {
75
+ // ?list rdf:first ?item0
76
+ const item0Variable = variable("Item0");
77
+ triples.push(objectInitializer({
78
+ subject: listVariable,
79
+ predicate: this.rdfjsTermExpression(rdf.first),
80
+ object: item0Variable,
81
+ }), ...this.itemType.sparqlConstructTemplateTriples({
82
+ context: "type",
83
+ variables: {
84
+ subject: item0Variable,
85
+ variablePrefix: variablePrefix("Item0"),
86
+ },
87
+ }));
88
+ }
89
+ {
90
+ // ?list rdf:rest ?rest0
91
+ const rest0Variable = variable("Rest0");
92
+ triples.push(objectInitializer({
93
+ subject: listVariable,
94
+ predicate: this.rdfjsTermExpression(rdf.rest),
95
+ object: rest0Variable,
96
+ }));
97
+ }
98
+ // Don't do ?list rdf:rest+ ?restN in CONSTRUCT
99
+ const restNVariable = variable("RestN");
100
+ {
101
+ // ?rest rdf:first ?itemN
102
+ const itemNVariable = variable("ItemN");
103
+ triples.push(objectInitializer({
104
+ subject: restNVariable,
105
+ predicate: this.rdfjsTermExpression(rdf.first),
106
+ object: itemNVariable,
107
+ }), ...this.itemType.sparqlConstructTemplateTriples({
108
+ context: "type",
109
+ variables: {
110
+ subject: itemNVariable,
111
+ variablePrefix: variablePrefix("ItemN"),
112
+ },
113
+ }));
114
+ }
115
+ // ?restN rdf:rest ?restNBasic to get the rdf:rest statement in the CONSTRUCT
116
+ triples.push(objectInitializer({
117
+ subject: restNVariable,
118
+ predicate: this.rdfjsTermExpression(rdf.rest),
119
+ object: variable("RestNBasic"),
120
+ }));
121
+ return triples;
122
+ }
123
+ }
124
+ }
125
+ sparqlWherePatterns({ variables, context, }) {
126
+ switch (context) {
127
+ case "property":
128
+ return super.sparqlWherePatterns({ context, variables });
129
+ case "type": {
130
+ const patterns = [];
131
+ const listVariable = variables.subject;
132
+ const variable = (suffix) => `${this.dataFactoryVariable}.variable!(\`\${${variables.variablePrefix}}${suffix}\`)`;
133
+ const variablePrefix = (suffix) => `\`\${${variables.variablePrefix}}${suffix}\``;
134
+ {
135
+ // ?list rdf:first ?item0
136
+ const item0Variable = variable("Item0");
137
+ patterns.push(`{ type: "bgp", triples: [${objectInitializer({
138
+ subject: listVariable,
139
+ predicate: this.rdfjsTermExpression(rdf.first),
140
+ object: item0Variable,
141
+ })}] }`, ...this.itemType.sparqlWherePatterns({
142
+ context: "type",
143
+ variables: {
144
+ subject: item0Variable,
145
+ variablePrefix: variablePrefix("Item0"),
146
+ },
147
+ }));
148
+ }
149
+ {
150
+ // ?list rdf:rest ?rest0
151
+ const rest0Variable = variable("Rest0");
152
+ patterns.push(`{ type: "bgp", triples: [${objectInitializer({
153
+ subject: listVariable,
154
+ predicate: this.rdfjsTermExpression(rdf.rest),
155
+ object: rest0Variable,
156
+ })}] }`);
157
+ }
158
+ const optionalPatterns = [];
159
+ const restNVariable = variable("RestN");
160
+ // ?list rdf:rest+ ?restN
161
+ optionalPatterns.push(`{ type: "bgp", triples: [${objectInitializer({
162
+ subject: listVariable,
163
+ predicate: `{ type: "path", pathType: "*", items: [${this.rdfjsTermExpression(rdf.rest)}] }`,
164
+ object: restNVariable,
165
+ })}] }`);
166
+ {
167
+ // ?rest rdf:first ?itemN
168
+ const itemNVariable = variable("ItemN");
169
+ optionalPatterns.push(`{ type: "bgp", triples: [${objectInitializer({
170
+ subject: restNVariable,
171
+ predicate: this.rdfjsTermExpression(rdf.first),
172
+ object: itemNVariable,
173
+ })}] }`, ...this.itemType.sparqlConstructTemplateTriples({
174
+ context: "type",
175
+ variables: {
176
+ subject: itemNVariable,
177
+ variablePrefix: variablePrefix("ItemN"),
178
+ },
179
+ }));
180
+ }
181
+ // ?restN rdf:rest ?restNBasic to get the rdf:rest statement in the CONSTRUCT
182
+ optionalPatterns.push(`{ type: "bgp", triples: [${objectInitializer({
183
+ subject: restNVariable,
184
+ predicate: this.rdfjsTermExpression(rdf.rest),
185
+ object: variable("RestNBasic"),
186
+ })}] }`);
187
+ patterns.push(`{ type: "optional", patterns: [${optionalPatterns.join(", ")}] }`);
188
+ return patterns;
189
+ }
190
+ }
191
+ }
192
+ toJsonExpression({ variables, }) {
193
+ let expression = variables.value;
194
+ const itemFromJsonExpression = this.itemType.fromJsonExpression({
195
+ variables: { value: "_item" },
196
+ });
197
+ if (itemFromJsonExpression !== "_item") {
198
+ expression = `${expression}.map(_item => (${itemFromJsonExpression}))`;
199
+ }
200
+ return `${variables.value}.map(_item => (${this.itemType.toJsonExpression({ variables: { value: "_item" } })}))`;
201
+ }
48
202
  toRdfExpression({ variables, }) {
49
203
  let listIdentifier;
50
204
  let mutableResourceTypeName;
51
205
  let resourceSetMethodName;
52
206
  let subListIdentifier;
53
207
  switch (this.identifierNodeKind) {
54
- case NodeKind.BLANK_NODE: {
208
+ case "BlankNode": {
55
209
  listIdentifier = subListIdentifier = "dataFactory.blankNode()";
56
210
  mutableResourceTypeName = "rdfjsResource.MutableResource";
57
211
  resourceSetMethodName = "mutableResource";
58
212
  break;
59
213
  }
60
- case NodeKind.IRI: {
214
+ case "NamedNode": {
61
215
  switch (this.mintingStrategy) {
62
- case MintingStrategy.SHA256:
216
+ case "sha256":
63
217
  listIdentifier = `dataFactory.namedNode(\`urn:shaclmate:list:\${${variables.value}.reduce(
64
- (hasher, item) => {
65
- ${this.itemType.hashStatements({ variables: { hasher: "hasher", value: "item" } })}
66
- return hasher;
218
+ (_hasher, _item) => {
219
+ ${this.itemType.hashStatements({ depth: 0, variables: { hasher: "_hasher", value: "_item" } }).join("\n")}
220
+ return _hasher;
67
221
  },
68
222
  sha256.create(),
69
223
  )}\`)`;
70
224
  break;
71
- case MintingStrategy.UUIDv4:
225
+ case "uuidv4":
72
226
  listIdentifier =
73
227
  "dataFactory.namedNode(`urn:shaclmate:list:${uuid.v4()}`)";
74
228
  break;
@@ -81,23 +235,23 @@ export class ListType extends Type {
81
235
  break;
82
236
  }
83
237
  }
84
- return `${variables.value}.reduce(({ currentSubListResource, listResource }, item, itemIndex) => {
238
+ return `${variables.value}.reduce(({ currentSubListResource, listResource }, item, itemIndex, list) => {
85
239
  if (itemIndex === 0) {
86
240
  currentSubListResource = listResource;
87
241
  } else {
88
- const newSubListResource = ${variables.resourceSet}.${resourceSetMethodName}({
89
- identifier: ${subListIdentifier},
90
- mutateGraph: ${variables.mutateGraph},
91
- });
242
+ const newSubListResource = ${variables.resourceSet}.${resourceSetMethodName}(${objectInitializer({
243
+ identifier: subListIdentifier,
244
+ mutateGraph: variables.mutateGraph,
245
+ })});
92
246
  currentSubListResource!.add(dataFactory.namedNode("${rdf.rest.value}"), newSubListResource.identifier);
93
247
  currentSubListResource = newSubListResource;
94
248
  }
95
249
 
96
- ${this.rdfType.map((rdfType) => `currentSubListResource.add(dataFactory.namedNode("${rdf.type.value}"), dataFactory.namedNode("${rdfType.value}"))`).orDefault("")}
250
+ ${this.toRdfTypes.map((rdfType) => `currentSubListResource.add(dataFactory.namedNode("${rdf.type.value}"), dataFactory.namedNode("${rdfType.value}"))`).join("\n")}
97
251
 
98
252
  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
253
 
100
- if (itemIndex + 1 === ${variables.value}.length) {
254
+ if (itemIndex + 1 === list.length) {
101
255
  currentSubListResource.add(dataFactory.namedNode("${rdf.rest.value}"), dataFactory.namedNode("${rdf.nil.value}"));
102
256
  }
103
257
 
@@ -105,10 +259,10 @@ export class ListType extends Type {
105
259
  },
106
260
  {
107
261
  currentSubListResource: null,
108
- listResource: resourceSet.${resourceSetMethodName}({
109
- identifier: ${listIdentifier},
110
- mutateGraph: ${variables.mutateGraph}
111
- }),
262
+ listResource: resourceSet.${resourceSetMethodName}(${objectInitializer({
263
+ identifier: listIdentifier,
264
+ mutateGraph: variables.mutateGraph,
265
+ })}),
112
266
  } as {
113
267
  currentSubListResource: ${mutableResourceTypeName} | null;
114
268
  listResource: ${mutableResourceTypeName};
@@ -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