@shaclmate/compiler 2.0.22 → 2.0.24

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 (194) hide show
  1. package/dist/ShapesGraphToAstTransformer.d.ts +6 -5
  2. package/dist/ShapesGraphToAstTransformer.js +61 -17
  3. package/dist/_ShapesGraphToAstTransformer/InheritableShapeConstraints.d.ts +2 -0
  4. package/dist/_ShapesGraphToAstTransformer/InheritableShapeConstraints.js +2 -0
  5. package/dist/_ShapesGraphToAstTransformer/ShapeStack.d.ts +15 -0
  6. package/dist/_ShapesGraphToAstTransformer/ShapeStack.js +51 -0
  7. package/dist/_ShapesGraphToAstTransformer/flattenAstObjectCompositeTypeMemberTypes.d.ts +13 -0
  8. package/dist/_ShapesGraphToAstTransformer/flattenAstObjectCompositeTypeMemberTypes.js +51 -0
  9. package/dist/_ShapesGraphToAstTransformer/index.d.ts +5 -5
  10. package/dist/_ShapesGraphToAstTransformer/index.js +5 -5
  11. package/dist/_ShapesGraphToAstTransformer/shapeAstName.js +53 -12
  12. package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.d.ts +5 -0
  13. package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.js +130 -54
  14. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +175 -5
  15. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompositeType.d.ts +10 -0
  16. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompositeType.js +185 -0
  17. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstIdentifierType.d.ts +10 -0
  18. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstIdentifierType.js +32 -0
  19. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstLiteralType.d.ts +10 -0
  20. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstLiteralType.js +46 -0
  21. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstTermType.d.ts +12 -0
  22. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstTermType.js +24 -0
  23. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstType.d.ts +13 -0
  24. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstType.js +14 -0
  25. package/dist/ast/Ast.d.ts +0 -1
  26. package/dist/ast/Curie.d.ts +14 -0
  27. package/dist/ast/Curie.js +21 -0
  28. package/dist/ast/IdentifierType.d.ts +3 -2
  29. package/dist/ast/ListType.d.ts +2 -1
  30. package/dist/ast/LiteralType.d.ts +1 -1
  31. package/dist/ast/Name.d.ts +40 -5
  32. package/dist/ast/ObjectCompositeType.d.ts +11 -0
  33. package/dist/ast/ObjectType.d.ts +18 -13
  34. package/dist/ast/ObjectUnionType.d.ts +0 -11
  35. package/dist/ast/OptionType.d.ts +2 -4
  36. package/dist/ast/SetType.d.ts +2 -7
  37. package/dist/ast/TermType.d.ts +12 -4
  38. package/dist/ast/Type.d.ts +1 -1
  39. package/dist/ast/index.d.ts +1 -0
  40. package/dist/ast/index.js +1 -0
  41. package/dist/enums/TsFeature.d.ts +1 -4
  42. package/dist/enums/TsFeature.js +1 -15
  43. package/dist/generators/json/AstJsonGenerator.js +26 -4
  44. package/dist/generators/ts/BooleanType.d.ts +4 -2
  45. package/dist/generators/ts/BooleanType.js +12 -3
  46. package/dist/generators/ts/DateTimeType.d.ts +9 -8
  47. package/dist/generators/ts/DateTimeType.js +32 -8
  48. package/dist/generators/ts/DateType.d.ts +5 -2
  49. package/dist/generators/ts/DateType.js +15 -1
  50. package/dist/generators/ts/DeclaredType.d.ts +2 -2
  51. package/dist/generators/ts/DeclaredType.js +2 -2
  52. package/dist/generators/ts/FloatType.d.ts +6 -0
  53. package/dist/generators/ts/FloatType.js +18 -0
  54. package/dist/generators/ts/IdentifierType.d.ts +17 -7
  55. package/dist/generators/ts/IdentifierType.js +112 -18
  56. package/dist/generators/ts/Import.d.ts +2 -0
  57. package/dist/generators/ts/Import.js +10 -0
  58. package/dist/generators/ts/IntType.d.ts +6 -0
  59. package/dist/generators/ts/IntType.js +18 -0
  60. package/dist/generators/ts/ListType.d.ts +15 -12
  61. package/dist/generators/ts/ListType.js +113 -61
  62. package/dist/generators/ts/LiteralType.d.ts +17 -9
  63. package/dist/generators/ts/LiteralType.js +92 -17
  64. package/dist/generators/ts/NumberType.d.ts +3 -2
  65. package/dist/generators/ts/NumberType.js +8 -3
  66. package/dist/generators/ts/ObjectType.d.ts +65 -43
  67. package/dist/generators/ts/ObjectType.js +143 -123
  68. package/dist/generators/ts/ObjectUnionType.d.ts +50 -8
  69. package/dist/generators/ts/ObjectUnionType.js +303 -101
  70. package/dist/generators/ts/OptionType.d.ts +14 -10
  71. package/dist/generators/ts/OptionType.js +62 -34
  72. package/dist/generators/ts/PrimitiveType.d.ts +23 -5
  73. package/dist/generators/ts/PrimitiveType.js +34 -6
  74. package/dist/generators/ts/SetType.d.ts +17 -13
  75. package/dist/generators/ts/SetType.js +76 -44
  76. package/dist/generators/ts/SnippetDeclarations.d.ts +13 -8
  77. package/dist/generators/ts/SnippetDeclarations.js +226 -101
  78. package/dist/generators/ts/StringType.d.ts +4 -2
  79. package/dist/generators/ts/StringType.js +20 -8
  80. package/dist/generators/ts/TermType.d.ts +29 -33
  81. package/dist/generators/ts/TermType.js +89 -68
  82. package/dist/generators/ts/TsGenerator.d.ts +2 -1
  83. package/dist/generators/ts/TsGenerator.js +26 -12
  84. package/dist/generators/ts/Type.d.ts +100 -32
  85. package/dist/generators/ts/Type.js +58 -54
  86. package/dist/generators/ts/TypeFactory.d.ts +12 -5
  87. package/dist/generators/ts/TypeFactory.js +380 -226
  88. package/dist/generators/ts/UnionType.d.ts +14 -10
  89. package/dist/generators/ts/UnionType.js +319 -142
  90. package/dist/generators/ts/_ObjectType/EagerShaclProperty.d.ts +12 -0
  91. package/dist/generators/ts/_ObjectType/EagerShaclProperty.js +31 -0
  92. package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.d.ts +13 -12
  93. package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.js +59 -46
  94. package/dist/generators/ts/_ObjectType/IdentifierProperty.d.ts +20 -13
  95. package/dist/generators/ts/_ObjectType/IdentifierProperty.js +198 -140
  96. package/dist/generators/ts/_ObjectType/LazyShaclProperty.d.ts +100 -0
  97. package/dist/generators/ts/_ObjectType/LazyShaclProperty.js +315 -0
  98. package/dist/generators/ts/_ObjectType/Property.d.ts +47 -46
  99. package/dist/generators/ts/_ObjectType/Property.js +1 -10
  100. package/dist/generators/ts/_ObjectType/ShaclProperty.d.ts +25 -30
  101. package/dist/generators/ts/_ObjectType/ShaclProperty.js +120 -85
  102. package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +21 -17
  103. package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +61 -53
  104. package/dist/generators/ts/_ObjectType/classDeclaration.js +22 -17
  105. package/dist/generators/ts/_ObjectType/createFunctionDeclaration.js +26 -13
  106. package/dist/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.js +8 -5
  107. package/dist/generators/ts/_ObjectType/fromRdfTypeVariableStatement.d.ts +1 -1
  108. package/dist/generators/ts/_ObjectType/fromRdfTypeVariableStatement.js +8 -5
  109. package/dist/generators/ts/_ObjectType/graphqlTypeVariableStatement.d.ts +5 -0
  110. package/dist/generators/ts/_ObjectType/graphqlTypeVariableStatement.js +49 -0
  111. package/dist/generators/ts/_ObjectType/hashFunctionOrMethodDeclarations.js +7 -8
  112. package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.d.ts +7 -0
  113. package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.js +54 -0
  114. package/dist/generators/ts/_ObjectType/index.d.ts +9 -7
  115. package/dist/generators/ts/_ObjectType/index.js +9 -7
  116. package/dist/generators/ts/_ObjectType/interfaceDeclaration.js +1 -1
  117. package/dist/generators/ts/_ObjectType/jsonFunctionDeclarations.d.ts +4 -0
  118. package/dist/generators/ts/_ObjectType/jsonFunctionDeclarations.js +189 -0
  119. package/dist/generators/ts/_ObjectType/jsonTypeAliasDeclaration.d.ts +5 -0
  120. package/dist/generators/ts/_ObjectType/jsonTypeAliasDeclaration.js +28 -0
  121. package/dist/generators/ts/_ObjectType/objectSetMethodNames.d.ts +9 -0
  122. package/dist/generators/ts/_ObjectType/objectSetMethodNames.js +18 -0
  123. package/dist/generators/ts/_ObjectType/propertiesVariableStatement.d.ts +5 -0
  124. package/dist/generators/ts/_ObjectType/propertiesVariableStatement.js +37 -0
  125. package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.d.ts +4 -0
  126. package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.js +144 -0
  127. package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.d.ts +1 -1
  128. package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.js +6 -5
  129. package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.d.ts +1 -1
  130. package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.js +4 -3
  131. package/dist/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +109 -37
  132. package/dist/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.js +6 -6
  133. package/dist/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.js +33 -24
  134. package/dist/generators/ts/graphqlSchemaVariableStatement.d.ts +9 -0
  135. package/dist/generators/ts/graphqlSchemaVariableStatement.js +86 -0
  136. package/dist/generators/ts/objectSetDeclarations.d.ts +8 -0
  137. package/dist/generators/ts/objectSetDeclarations.js +59 -0
  138. package/dist/generators/ts/objectSetInterfaceDeclaration.d.ts +8 -0
  139. package/dist/generators/ts/objectSetInterfaceDeclaration.js +46 -0
  140. package/dist/generators/ts/objectSetMethodSignatures.d.ts +11 -0
  141. package/dist/generators/ts/objectSetMethodSignatures.js +52 -0
  142. package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.d.ts +8 -0
  143. package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +393 -0
  144. package/dist/generators/ts/rdfjsTermExpression.d.ts +3 -0
  145. package/dist/generators/ts/rdfjsTermExpression.js +57 -0
  146. package/dist/generators/ts/sparqlObjectSetClassDeclaration.d.ts +8 -0
  147. package/dist/generators/ts/sparqlObjectSetClassDeclaration.js +415 -0
  148. package/dist/generators/ts/syntheticNamePrefix.d.ts +2 -0
  149. package/dist/generators/ts/syntheticNamePrefix.js +2 -0
  150. package/dist/generators/ts/tsName.js +27 -13
  151. package/dist/generators/ts/unsupportedObjectSetMethodDeclarations.d.ts +10 -0
  152. package/dist/generators/ts/unsupportedObjectSetMethodDeclarations.js +19 -0
  153. package/dist/input/NodeShape.d.ts +6 -8
  154. package/dist/input/NodeShape.js +20 -44
  155. package/dist/input/Ontology.d.ts +0 -3
  156. package/dist/input/Ontology.js +0 -9
  157. package/dist/input/PropertyPath.d.ts +5 -5
  158. package/dist/input/PropertyPath.js +14 -24
  159. package/dist/input/PropertyShape.d.ts +3 -1
  160. package/dist/input/PropertyShape.js +8 -2
  161. package/dist/input/ShapesGraph.js +4 -8
  162. package/dist/input/generated.d.ts +967 -107
  163. package/dist/input/generated.js +2548 -1046
  164. package/dist/input/tsFeatures.d.ts +3 -2
  165. package/dist/input/tsFeatures.js +44 -27
  166. package/package.json +18 -16
  167. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.d.ts +0 -13
  168. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +0 -200
  169. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.d.ts +0 -12
  170. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.js +0 -29
  171. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.d.ts +0 -12
  172. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.js +0 -43
  173. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.d.ts +0 -14
  174. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.js +0 -21
  175. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.d.ts +0 -16
  176. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.js +0 -60
  177. package/dist/generators/ts/_ObjectType/fromJsonFunctionDeclarations.d.ts +0 -4
  178. package/dist/generators/ts/_ObjectType/fromJsonFunctionDeclarations.js +0 -78
  179. package/dist/generators/ts/_ObjectType/fromRdfFunctionDeclarations.d.ts +0 -4
  180. package/dist/generators/ts/_ObjectType/fromRdfFunctionDeclarations.js +0 -91
  181. package/dist/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.d.ts +0 -5
  182. package/dist/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.js +0 -19
  183. package/dist/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.d.ts +0 -5
  184. package/dist/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.js +0 -31
  185. package/dist/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.d.ts +0 -5
  186. package/dist/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.js +0 -37
  187. package/dist/generators/ts/_ObjectType/rdfjsTermExpression.d.ts +0 -6
  188. package/dist/generators/ts/_ObjectType/rdfjsTermExpression.js +0 -17
  189. package/dist/generators/ts/_ObjectType/toJsonFunctionDeclaration.d.ts +0 -5
  190. package/dist/generators/ts/_ObjectType/toJsonFunctionDeclaration.js +0 -19
  191. package/dist/generators/ts/_ObjectType/toJsonReturnType.d.ts +0 -3
  192. package/dist/generators/ts/_ObjectType/toJsonReturnType.js +0 -17
  193. package/dist/generators/ts/_ObjectType/toRdfFunctionDeclaration.d.ts +0 -5
  194. package/dist/generators/ts/_ObjectType/toRdfFunctionDeclaration.js +0 -19
@@ -1,18 +1,28 @@
1
- import { rdf } from "@tpluscode/rdf-ns-builders";
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
+ };
2
7
  import { Maybe } from "purify-ts";
8
+ import { rdf } from "@tpluscode/rdf-ns-builders";
9
+ import { Memoize } from "typescript-memoize";
3
10
  import { Import } from "./Import.js";
4
11
  import { SnippetDeclarations } from "./SnippetDeclarations.js";
5
12
  import { Type } from "./Type.js";
6
13
  import { objectInitializer } from "./objectInitializer.js";
14
+ import { rdfjsTermExpression } from "./rdfjsTermExpression.js";
15
+ import { syntheticNamePrefix } from "./syntheticNamePrefix.js";
7
16
  export class ListType extends Type {
8
- itemType;
9
- kind = "ListType";
10
- identifierNodeKind;
11
- identifierMintingStrategy;
12
17
  _mutable;
18
+ identifierMintingStrategy;
19
+ identifierNodeKind;
13
20
  toRdfTypes;
14
- constructor({ identifierNodeKind, itemType, identifierMintingStrategy, mutable, toRdfTypes, ...superParameters }) {
15
- super(superParameters);
21
+ itemType;
22
+ kind = "ListType";
23
+ typeof = "object";
24
+ constructor({ identifierNodeKind, itemType, identifierMintingStrategy, mutable, toRdfTypes, }) {
25
+ super();
16
26
  this.identifierNodeKind = identifierNodeKind;
17
27
  this.itemType = itemType;
18
28
  this.identifierMintingStrategy = identifierMintingStrategy.orDefault(identifierNodeKind === "BlankNode" ? "blankNode" : "sha256");
@@ -22,8 +32,11 @@ export class ListType extends Type {
22
32
  get conversions() {
23
33
  return [
24
34
  {
25
- conversionExpression: (value) => value,
26
- sourceTypeCheckExpression: (value) => `Array.isArray(${value})`,
35
+ // Defensive copy
36
+ conversionExpression: (value) => `${value}${this.mutable ? ".concat()" : ""}`,
37
+ // Array.isArray doesn't narrow correctly
38
+ // sourceTypeCheckExpression: (value) => `Array.isArray(${value})`,
39
+ sourceTypeCheckExpression: (value) => `typeof ${value} === "object"`,
27
40
  sourceTypeName: this.name,
28
41
  },
29
42
  ];
@@ -32,10 +45,13 @@ export class ListType extends Type {
32
45
  return Maybe.empty();
33
46
  }
34
47
  get equalsFunction() {
35
- return `((left, right) => arrayEquals(left, right, ${this.itemType.equalsFunction}))`;
48
+ return `((left, right) => ${syntheticNamePrefix}arrayEquals(left, right, ${this.itemType.equalsFunction}))`;
49
+ }
50
+ get graphqlName() {
51
+ return new Type.GraphqlName(`new graphql.GraphQLList(${this.itemType.graphqlName})`);
36
52
  }
37
53
  get jsonName() {
38
- return `readonly (${this.itemType.jsonName})[]`;
54
+ return new Type.JsonName(`readonly (${this.itemType.jsonName})[]`);
39
55
  }
40
56
  get mutable() {
41
57
  return this._mutable || this.itemType.mutable;
@@ -44,18 +60,30 @@ export class ListType extends Type {
44
60
  return `${this._mutable ? "" : "readonly "}${this.itemType.name}[]`;
45
61
  }
46
62
  fromJsonExpression({ variables, }) {
47
- return `${variables.value}.map(_item => (${this.itemType.fromJsonExpression({ variables: { value: "_item" } })}))`;
63
+ return `${variables.value}.map(item => (${this.itemType.fromJsonExpression({ variables: { value: "item" } })}))`;
48
64
  }
49
65
  fromRdfExpression({ variables, }) {
50
- const chain = [variables.resourceValues];
51
- chain.push("head()");
52
- chain.push("chain(value => value.toList())");
53
- chain.push(`map(values => values.flatMap(_value => ${this.itemType.fromRdfExpression({ variables: { ...variables, resourceValues: "_value.toValues()" } })}.toMaybe().toList()))`);
54
- return chain.join(".");
66
+ return [
67
+ variables.resourceValues,
68
+ "chain(values => values.chainMap(value => value.toList()))", // Resource.Values<Resource.Value> to Resource.Values<Resource.Value[]>
69
+ `chain(valueLists =>
70
+ valueLists.chainMap(
71
+ valueList => ${this.itemType.fromRdfExpression({
72
+ variables: {
73
+ ...variables,
74
+ resourceValues: `purify.Either.of<Error, rdfjsResource.Resource.Values<rdfjsResource.Resource.Value>>(rdfjsResource.Resource.Values.fromArray({ objects: valueList, predicate: ${variables.predicate}, subject: ${variables.resource} }))`,
75
+ },
76
+ })}
77
+ ))`, // Resource.Values<Resource.Value[]> to Resource.Values<item type arrays>
78
+ `map(valueLists => valueLists.map(valueList => valueList.toArray()${this.mutable ? ".concat()" : ""}))`, // Convert inner Resource.Values to arrays
79
+ ].join(".");
80
+ }
81
+ graphqlResolveExpression({ variables, }) {
82
+ return variables.value;
55
83
  }
56
84
  hashStatements({ depth, variables, }) {
57
85
  return [
58
- `for (const _element${depth} of ${variables.value}) { ${this.itemType.hashStatements({ depth: depth + 1, variables: { ...variables, value: `_element${depth}` } }).join("\n")} }`,
86
+ `for (const item${depth} of ${variables.value}) { ${this.itemType.hashStatements({ depth: depth + 1, variables: { ...variables, value: `item${depth}` } }).join("\n")} }`,
59
87
  ];
60
88
  }
61
89
  jsonUiSchemaElement(parameters) {
@@ -64,33 +92,35 @@ export class ListType extends Type {
64
92
  jsonZodSchema(parameters) {
65
93
  return `${this.itemType.jsonZodSchema(parameters)}.array()`;
66
94
  }
67
- snippetDeclarations(features) {
95
+ snippetDeclarations(parameters) {
68
96
  const snippetDeclarations = this.itemType
69
- .snippetDeclarations(features)
97
+ .snippetDeclarations(parameters)
70
98
  .concat();
71
- if (features.has("equals")) {
99
+ if (parameters.features.has("equals")) {
72
100
  snippetDeclarations.push(SnippetDeclarations.arrayEquals);
73
101
  }
74
102
  return snippetDeclarations;
75
103
  }
76
- sparqlConstructTemplateTriples({ variables, context, }) {
77
- switch (context) {
78
- case "property":
79
- return super.sparqlConstructTemplateTriples({ context, variables });
80
- case "type": {
104
+ sparqlConstructTemplateTriples(parameters) {
105
+ switch (parameters.context) {
106
+ case "object":
107
+ return super.sparqlConstructTemplateTriples(parameters);
108
+ case "subject": {
109
+ const { variables } = parameters;
81
110
  const triples = [];
82
111
  const listVariable = variables.subject;
83
- const variable = (suffix) => `${this.dataFactoryVariable}.variable!(\`\${${variables.variablePrefix}}${suffix}\`)`;
112
+ const variable = (suffix) => `dataFactory.variable!(\`\${${variables.variablePrefix}}${suffix}\`)`;
84
113
  const variablePrefix = (suffix) => `\`\${${variables.variablePrefix}}${suffix}\``;
85
114
  {
86
115
  // ?list rdf:first ?item0
87
116
  const item0Variable = variable("Item0");
88
117
  triples.push(objectInitializer({
89
118
  subject: listVariable,
90
- predicate: this.rdfjsTermExpression(rdf.first),
119
+ predicate: rdfjsTermExpression(rdf.first),
91
120
  object: item0Variable,
92
121
  }), ...this.itemType.sparqlConstructTemplateTriples({
93
- context: "type",
122
+ allowIgnoreRdfType: true,
123
+ context: "subject",
94
124
  variables: {
95
125
  subject: item0Variable,
96
126
  variablePrefix: variablePrefix("Item0"),
@@ -102,7 +132,7 @@ export class ListType extends Type {
102
132
  const rest0Variable = variable("Rest0");
103
133
  triples.push(objectInitializer({
104
134
  subject: listVariable,
105
- predicate: this.rdfjsTermExpression(rdf.rest),
135
+ predicate: rdfjsTermExpression(rdf.rest),
106
136
  object: rest0Variable,
107
137
  }));
108
138
  }
@@ -113,10 +143,11 @@ export class ListType extends Type {
113
143
  const itemNVariable = variable("ItemN");
114
144
  triples.push(objectInitializer({
115
145
  subject: restNVariable,
116
- predicate: this.rdfjsTermExpression(rdf.first),
146
+ predicate: rdfjsTermExpression(rdf.first),
117
147
  object: itemNVariable,
118
148
  }), ...this.itemType.sparqlConstructTemplateTriples({
119
- context: "type",
149
+ allowIgnoreRdfType: true,
150
+ context: "subject",
120
151
  variables: {
121
152
  subject: itemNVariable,
122
153
  variablePrefix: variablePrefix("ItemN"),
@@ -126,36 +157,39 @@ export class ListType extends Type {
126
157
  // ?restN rdf:rest ?restNBasic to get the rdf:rest statement in the CONSTRUCT
127
158
  triples.push(objectInitializer({
128
159
  subject: restNVariable,
129
- predicate: this.rdfjsTermExpression(rdf.rest),
160
+ predicate: rdfjsTermExpression(rdf.rest),
130
161
  object: variable("RestNBasic"),
131
162
  }));
132
163
  return triples;
133
164
  }
134
165
  }
135
166
  }
136
- sparqlWherePatterns({ variables, context, }) {
167
+ sparqlWherePatterns(parameters) {
137
168
  // Need to handle two cases:
138
169
  // (1) (?s, ?p, ?list) where ?list binds to rdf:nil
139
170
  // (2) (?s, ?p, ?list) (?list, rdf:first, "element") (?list, rdf:rest, rdf:nil) etc. where list binds to the head of a list
140
171
  // Case (2) is case (1) with OPTIONAL graph patterns to handle actual list elements.
141
- switch (context) {
142
- case "property":
143
- return super.sparqlWherePatterns({ context, variables });
144
- case "type": {
172
+ switch (parameters.context) {
173
+ case "object":
174
+ return super.sparqlWherePatterns(parameters);
175
+ case "subject": {
176
+ const { variables } = parameters;
145
177
  const patterns = [];
146
178
  const listVariable = variables.subject;
147
- const variable = (suffix) => `${this.dataFactoryVariable}.variable!(\`\${${variables.variablePrefix}}${suffix}\`)`;
179
+ const variable = (suffix) => `dataFactory.variable!(\`\${${variables.variablePrefix}}${suffix}\`)`;
148
180
  const variablePrefix = (suffix) => `\`\${${variables.variablePrefix}}${suffix}\``;
149
181
  {
150
182
  // ?list rdf:first ?item0
151
183
  const item0Variable = variable("Item0");
152
184
  patterns.push(`{ type: "bgp", triples: [${objectInitializer({
153
185
  subject: listVariable,
154
- predicate: this.rdfjsTermExpression(rdf.first),
186
+ predicate: rdfjsTermExpression(rdf.first),
155
187
  object: item0Variable,
156
188
  })}] }`, ...this.itemType.sparqlWherePatterns({
157
- context: "type",
189
+ allowIgnoreRdfType: true,
190
+ context: "subject",
158
191
  variables: {
192
+ languageIn: parameters.variables.languageIn,
159
193
  subject: item0Variable,
160
194
  variablePrefix: variablePrefix("Item0"),
161
195
  },
@@ -166,7 +200,7 @@ export class ListType extends Type {
166
200
  const rest0Variable = variable("Rest0");
167
201
  patterns.push(`{ type: "bgp", triples: [${objectInitializer({
168
202
  subject: listVariable,
169
- predicate: this.rdfjsTermExpression(rdf.rest),
203
+ predicate: rdfjsTermExpression(rdf.rest),
170
204
  object: rest0Variable,
171
205
  })}] }`);
172
206
  }
@@ -175,7 +209,7 @@ export class ListType extends Type {
175
209
  // ?list rdf:rest+ ?restN
176
210
  optionalPatterns.push(`{ type: "bgp", triples: [${objectInitializer({
177
211
  subject: listVariable,
178
- predicate: `{ type: "path", pathType: "*", items: [${this.rdfjsTermExpression(rdf.rest)}] }`,
212
+ predicate: `{ type: "path", pathType: "*", items: [${rdfjsTermExpression(rdf.rest)}] }`,
179
213
  object: restNVariable,
180
214
  })}] }`);
181
215
  {
@@ -183,11 +217,13 @@ export class ListType extends Type {
183
217
  const itemNVariable = variable("ItemN");
184
218
  optionalPatterns.push(`{ type: "bgp", triples: [${objectInitializer({
185
219
  subject: restNVariable,
186
- predicate: this.rdfjsTermExpression(rdf.first),
220
+ predicate: rdfjsTermExpression(rdf.first),
187
221
  object: itemNVariable,
188
222
  })}] }`, ...this.itemType.sparqlWherePatterns({
189
- context: "type",
223
+ allowIgnoreRdfType: true,
224
+ context: "subject",
190
225
  variables: {
226
+ languageIn: parameters.variables.languageIn,
191
227
  subject: itemNVariable,
192
228
  variablePrefix: variablePrefix("ItemN"),
193
229
  },
@@ -196,7 +232,7 @@ export class ListType extends Type {
196
232
  // ?restN rdf:rest ?restNBasic to get the rdf:rest statement in the CONSTRUCT
197
233
  optionalPatterns.push(`{ type: "bgp", triples: [${objectInitializer({
198
234
  subject: restNVariable,
199
- predicate: this.rdfjsTermExpression(rdf.rest),
235
+ predicate: rdfjsTermExpression(rdf.rest),
200
236
  object: variable("RestNBasic"),
201
237
  })}] }`);
202
238
  patterns.push(`{ type: "optional", patterns: [${optionalPatterns.join(", ")}] }`);
@@ -208,12 +244,12 @@ export class ListType extends Type {
208
244
  toJsonExpression({ variables, }) {
209
245
  let expression = variables.value;
210
246
  const itemFromJsonExpression = this.itemType.fromJsonExpression({
211
- variables: { value: "_item" },
247
+ variables: { value: "item" },
212
248
  });
213
- if (itemFromJsonExpression !== "_item") {
214
- expression = `${expression}.map(_item => (${itemFromJsonExpression}))`;
249
+ if (itemFromJsonExpression !== "item") {
250
+ expression = `${expression}.map(item => (${itemFromJsonExpression}))`;
215
251
  }
216
- return `${variables.value}.map(_item => (${this.itemType.toJsonExpression({ variables: { value: "_item" } })}))`;
252
+ return `${variables.value}.map(item => (${this.itemType.toJsonExpression({ variables: { value: "item" } })}))`;
217
253
  }
218
254
  toRdfExpression({ variables, }) {
219
255
  let listIdentifier;
@@ -233,9 +269,9 @@ export class ListType extends Type {
233
269
  throw new RangeError(this.identifierMintingStrategy);
234
270
  case "sha256":
235
271
  listIdentifier = `dataFactory.namedNode(\`urn:shaclmate:list:\${${variables.value}.reduce(
236
- (_hasher, _item) => {
237
- ${this.itemType.hashStatements({ depth: 0, variables: { hasher: "_hasher", value: "_item" } }).join("\n")}
238
- return _hasher;
272
+ (hasher, item) => {
273
+ ${this.itemType.hashStatements({ depth: 0, variables: { hasher: "hasher", value: "item" } }).join("\n")}
274
+ return hasher;
239
275
  },
240
276
  sha256.create(),
241
277
  )}\`)`;
@@ -260,16 +296,16 @@ export class ListType extends Type {
260
296
  const newSubListResource = ${variables.resourceSet}.${resourceSetMethodName}(${subListIdentifier}, ${objectInitializer({
261
297
  mutateGraph: variables.mutateGraph,
262
298
  })});
263
- currentSubListResource!.add(dataFactory.namedNode("${rdf.rest.value}"), newSubListResource.identifier);
299
+ currentSubListResource!.add(${rdfjsTermExpression(rdf.rest)}, newSubListResource.identifier);
264
300
  currentSubListResource = newSubListResource;
265
301
  }
266
302
 
267
- ${this.toRdfTypes.map((rdfType) => `currentSubListResource.add(dataFactory.namedNode("${rdf.type.value}"), dataFactory.namedNode("${rdfType.value}"))`).join("\n")}
303
+ ${this.toRdfTypes.map((rdfType) => `currentSubListResource.add(${rdfjsTermExpression(rdf.type)}, dataFactory.namedNode("${rdfType.value}"))`).join("\n")}
268
304
 
269
- 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" } })});
305
+ currentSubListResource.add(${rdfjsTermExpression(rdf.first)}, ${this.itemType.toRdfExpression({ variables: { mutateGraph: variables.mutateGraph, predicate: rdfjsTermExpression(rdf.first), resource: "currentSubListResource", resourceSet: variables.resourceSet, value: "item" } })});
270
306
 
271
307
  if (itemIndex + 1 === list.length) {
272
- currentSubListResource.add(dataFactory.namedNode("${rdf.rest.value}"), dataFactory.namedNode("${rdf.nil.value}"));
308
+ currentSubListResource.add(${rdfjsTermExpression(rdf.rest)}, ${rdfjsTermExpression(rdf.nil)});
273
309
  }
274
310
 
275
311
  return { currentSubListResource, listResource };
@@ -283,14 +319,30 @@ export class ListType extends Type {
283
319
  currentSubListResource: ${mutableResourceTypeName} | null;
284
320
  listResource: ${mutableResourceTypeName};
285
321
  },
286
- ).listResource.identifier : dataFactory.namedNode("${rdf.nil.value}")`;
322
+ ).listResource.identifier : ${rdfjsTermExpression(rdf.nil)}`;
287
323
  }
288
- useImports(features) {
289
- const imports = this.itemType.useImports(features).concat();
290
- if (features.has("hash") && this.identifierNodeKind === "NamedNode") {
324
+ useImports(parameters) {
325
+ const imports = this.itemType.useImports(parameters).concat();
326
+ if (parameters.features.has("hash") &&
327
+ this.identifierNodeKind === "NamedNode") {
291
328
  imports.push(Import.SHA256);
292
329
  }
293
330
  return imports;
294
331
  }
295
332
  }
333
+ __decorate([
334
+ Memoize()
335
+ ], ListType.prototype, "conversions", null);
336
+ __decorate([
337
+ Memoize()
338
+ ], ListType.prototype, "equalsFunction", null);
339
+ __decorate([
340
+ Memoize()
341
+ ], ListType.prototype, "graphqlName", null);
342
+ __decorate([
343
+ Memoize()
344
+ ], ListType.prototype, "jsonName", null);
345
+ __decorate([
346
+ Memoize()
347
+ ], ListType.prototype, "name", null);
296
348
  //# sourceMappingURL=ListType.js.map
@@ -1,16 +1,24 @@
1
1
  import type { Literal } from "@rdfjs/types";
2
2
  import { TermType } from "./TermType.js";
3
- export declare class LiteralType extends TermType<Literal> {
3
+ import { Type } from "./Type.js";
4
+ export declare class LiteralType extends TermType<Literal, Literal> {
4
5
  private readonly languageIn;
5
6
  constructor({ languageIn, ...superParameters }: {
6
7
  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;
8
+ } & Omit<ConstructorParameters<typeof TermType<Literal, Literal>>[0], "nodeKinds">);
9
+ get jsonName(): Type.JsonName;
10
+ fromJsonExpression({ variables, }: Parameters<TermType<Literal, Literal>["fromJsonExpression"]>[0]): string;
11
+ protected fromRdfExpressionChain({ variables, }: Parameters<Type["fromRdfExpression"]>[0]): {
12
+ defaultValue?: string;
13
+ hasValues?: string;
14
+ languageIn?: string;
15
+ valueTo?: string;
16
+ };
17
+ hashStatements({ depth, variables, }: Parameters<TermType<Literal, Literal>["hashStatements"]>[0]): readonly string[];
18
+ jsonZodSchema({ variables, }: Parameters<TermType<Literal, Literal>["jsonZodSchema"]>[0]): ReturnType<TermType<Literal, Literal>["jsonZodSchema"]>;
19
+ sparqlWherePatterns(parameters: Parameters<Type["sparqlWherePatterns"]>[0] & {
20
+ ignoreLanguageIn?: boolean;
21
+ }): readonly string[];
22
+ toJsonExpression({ variables, }: Parameters<TermType<Literal, Literal>["toJsonExpression"]>[0]): string;
15
23
  }
16
24
  //# sourceMappingURL=LiteralType.d.ts.map
@@ -1,5 +1,14 @@
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
+ };
1
7
  import { xsd } from "@tpluscode/rdf-ns-builders";
8
+ import { invariant } from "ts-invariant";
9
+ import { Memoize } from "typescript-memoize";
2
10
  import { TermType } from "./TermType.js";
11
+ import { Type } from "./Type.js";
3
12
  export class LiteralType extends TermType {
4
13
  languageIn;
5
14
  constructor({ languageIn, ...superParameters }) {
@@ -10,10 +19,53 @@ export class LiteralType extends TermType {
10
19
  this.languageIn = languageIn;
11
20
  }
12
21
  get jsonName() {
13
- return '{ readonly "@language": string | undefined, readonly "@type": string | undefined, readonly "@value": string }';
22
+ return new Type.JsonName('{ readonly "@language"?: string, readonly "@type"?: string, readonly "@value": string }');
14
23
  }
15
24
  fromJsonExpression({ variables, }) {
16
- 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))`;
25
+ return `dataFactory.literal(${variables.value}["@value"], typeof ${variables.value}["@language"] !== "undefined" ? ${variables.value}["@language"] : (typeof ${variables.value}["@type"] !== "undefined" ? dataFactory.namedNode(${variables.value}["@type"]) : undefined))`;
26
+ }
27
+ fromRdfExpressionChain({ variables, }) {
28
+ return {
29
+ ...super.fromRdfExpressionChain({ variables }),
30
+ languageIn: `chain(values => {
31
+ const literalValuesEither = values.chainMap(value => value.toLiteral());
32
+ if (literalValuesEither.isLeft()) {
33
+ return literalValuesEither;
34
+ }
35
+ const literalValues = literalValuesEither.unsafeCoerce();
36
+
37
+ const nonUniqueLanguageIn = ${variables.languageIn} ?? ${JSON.stringify(this.languageIn)};
38
+ if (nonUniqueLanguageIn.length === 0) {
39
+ return purify.Either.of<Error, rdfjsResource.Resource.Values<rdfjs.Literal>>(literalValues);
40
+ }
41
+
42
+ let uniqueLanguageIn: string[];
43
+ if (nonUniqueLanguageIn.length === 1) {
44
+ uniqueLanguageIn = [nonUniqueLanguageIn[0]];
45
+ } else {
46
+ uniqueLanguageIn = [];
47
+ for (const languageIn of nonUniqueLanguageIn) {
48
+ if (uniqueLanguageIn.indexOf(languageIn) === -1) {
49
+ uniqueLanguageIn.push(languageIn);
50
+ }
51
+ }
52
+ }
53
+
54
+ // Return all literals for the first languageIn, then all literals for the second languageIn, etc.
55
+ // Within a languageIn the literals may be in any order.
56
+ let filteredLiteralValues: rdfjsResource.Resource.Values<rdfjs.Literal> | undefined;
57
+ for (const languageIn of uniqueLanguageIn) {
58
+ if (!filteredLiteralValues) {
59
+ filteredLiteralValues = literalValues.filter(value => value.language === languageIn);
60
+ } else {
61
+ filteredLiteralValues = filteredLiteralValues.concat(...literalValues.filter(value => value.language === languageIn).toArray());
62
+ }
63
+ }
64
+
65
+ return purify.Either.of<Error, rdfjsResource.Resource.Values<rdfjs.Literal>>(filteredLiteralValues!);
66
+ })`,
67
+ valueTo: undefined,
68
+ };
17
69
  }
18
70
  hashStatements({ depth, variables, }) {
19
71
  return [
@@ -24,24 +76,47 @@ export class LiteralType extends TermType {
24
76
  jsonZodSchema({ variables, }) {
25
77
  return `${variables.zod}.object({ "@language": ${variables.zod}.string().optional(), "@type": ${variables.zod}.string().optional(), "@value": ${variables.zod}.string() })`;
26
78
  }
27
- propertyFromRdfResourceValueExpression({ variables, }) {
28
- return `${variables.resourceValue}.toLiteral()`;
79
+ sparqlWherePatterns(parameters) {
80
+ const { context, ignoreLanguageIn, variables } = parameters;
81
+ const superPatterns = super.sparqlWherePatterns(parameters);
82
+ if (ignoreLanguageIn || context === "subject") {
83
+ return superPatterns;
84
+ }
85
+ invariant(this.name.indexOf("rdfjs.Literal") !== -1, this.name);
86
+ return superPatterns.concat(`...[(${variables.languageIn} && ${variables.languageIn}.length > 0) ? ${variables.languageIn} : ${JSON.stringify(this.languageIn)}]
87
+ .filter(languagesIn => languagesIn.length > 0)
88
+ .map(languagesIn =>
89
+ languagesIn.map(languageIn =>
90
+ ({
91
+ type: "operation" as const,
92
+ operator: "=",
93
+ args: [
94
+ { type: "operation" as const, operator: "lang", args: [${variables.object}] },
95
+ dataFactory.literal(languageIn)
96
+ ]
97
+ })
98
+ )
99
+ )
100
+ .map(langEqualsExpressions =>
101
+ ({
102
+ type: "filter" as const,
103
+ expression:
104
+ langEqualsExpressions.length === 1
105
+ ? langEqualsExpressions[0]
106
+ :
107
+ {
108
+ type: "operation" as const,
109
+ operator: "||",
110
+ args: langEqualsExpressions
111
+ },
112
+ })
113
+ )`);
29
114
  }
30
115
  toJsonExpression({ variables, }) {
31
116
  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 }`;
32
117
  }
33
- propertyFilterRdfResourceValuesExpression({ variables, }) {
34
- return `${variables.resourceValues}.filter(_value => {
35
- const _languageInOrDefault = ${variables.languageIn} ?? ${JSON.stringify(this.languageIn)};
36
- if (_languageInOrDefault.length === 0) {
37
- return true;
38
- }
39
- const _valueLiteral = _value.toLiteral().toMaybe().extract();
40
- if (typeof _valueLiteral === "undefined") {
41
- return false;
42
- }
43
- return _languageInOrDefault.some(_languageIn => _languageIn === _valueLiteral.language);
44
- })`;
45
- }
46
118
  }
119
+ __decorate([
120
+ Memoize()
121
+ ], LiteralType.prototype, "jsonName", null);
47
122
  //# sourceMappingURL=LiteralType.js.map
@@ -1,11 +1,12 @@
1
1
  import { PrimitiveType } from "./PrimitiveType.js";
2
2
  import type { Type } from "./Type.js";
3
- export declare class NumberType extends PrimitiveType<number> {
3
+ export declare abstract class NumberType extends PrimitiveType<number> {
4
4
  readonly kind = "NumberType";
5
+ readonly typeof = "number";
5
6
  get conversions(): readonly Type.Conversion[];
6
7
  get name(): string;
7
8
  jsonZodSchema({ variables, }: Parameters<Type["jsonZodSchema"]>[0]): ReturnType<Type["jsonZodSchema"]>;
8
- propertyFromRdfResourceValueExpression({ variables, }: Parameters<PrimitiveType<number>["propertyFromRdfResourceValueExpression"]>[0]): string;
9
+ protected fromRdfResourceValueExpression({ variables, }: Parameters<PrimitiveType<number>["fromRdfResourceValueExpression"]>[0]): string;
9
10
  toRdfExpression({ variables, }: Parameters<PrimitiveType<string>["toRdfExpression"]>[0]): string;
10
11
  }
11
12
  //# sourceMappingURL=NumberType.d.ts.map
@@ -9,6 +9,7 @@ import { PrimitiveType } from "./PrimitiveType.js";
9
9
  import { objectInitializer } from "./objectInitializer.js";
10
10
  export class NumberType extends PrimitiveType {
11
11
  kind = "NumberType";
12
+ typeof = "number";
12
13
  get conversions() {
13
14
  const conversions = [
14
15
  {
@@ -30,7 +31,7 @@ export class NumberType extends PrimitiveType {
30
31
  if (this.primitiveIn.length > 0) {
31
32
  return this.primitiveIn.map((value) => value.toString()).join(" | ");
32
33
  }
33
- return "number";
34
+ return this.typeof;
34
35
  }
35
36
  jsonZodSchema({ variables, }) {
36
37
  switch (this.primitiveIn.length) {
@@ -42,10 +43,11 @@ export class NumberType extends PrimitiveType {
42
43
  return `${variables.zod}.union([${this.primitiveIn.map((value) => `${variables.zod}.literal(${value})`).join(", ")}])`;
43
44
  }
44
45
  }
45
- propertyFromRdfResourceValueExpression({ variables, }) {
46
+ fromRdfResourceValueExpression({ variables, }) {
46
47
  let expression = `${variables.resourceValue}.toNumber()`;
47
48
  if (this.primitiveIn.length > 0) {
48
- 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 })})); } })`;
49
+ const eitherTypeParameters = `<Error, ${this.name}>`;
50
+ expression = `${expression}.chain(value => { switch (value) { ${this.primitiveIn.map((value) => `case ${value}:`).join(" ")} return purify.Either.of${eitherTypeParameters}(value); default: return purify.Left${eitherTypeParameters}(new rdfjsResource.Resource.MistypedValueError(${objectInitializer({ actualValue: "rdfLiteral.toRdf(value)", expectedValueType: JSON.stringify(this.name), focusResource: variables.resource, predicate: variables.predicate })})); } })`;
49
51
  }
50
52
  return expression;
51
53
  }
@@ -55,6 +57,9 @@ export class NumberType extends PrimitiveType {
55
57
  .orDefault(variables.value);
56
58
  }
57
59
  }
60
+ __decorate([
61
+ Memoize()
62
+ ], NumberType.prototype, "conversions", null);
58
63
  __decorate([
59
64
  Memoize()
60
65
  ], NumberType.prototype, "name", null);