@shaclmate/compiler 4.0.33 → 4.0.34

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 (220) hide show
  1. package/dist/Compiler.d.ts +0 -3
  2. package/dist/Compiler.js +0 -2
  3. package/dist/ShapesGraphToAstTransformer.d.ts +1 -4
  4. package/dist/ShapesGraphToAstTransformer.js +1 -5
  5. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +1 -3
  6. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompoundType.js +4 -7
  7. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstListType.js +0 -1
  8. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstObjectType.js +1 -3
  9. package/dist/ast/AbstractCompoundType.d.ts +6 -4
  10. package/dist/ast/AbstractCompoundType.js +4 -37
  11. package/dist/ast/ObjectType.d.ts +1 -7
  12. package/dist/ast/ObjectType.js +1 -6
  13. package/dist/generators/ts/AbstractCollectionType.d.ts +8 -8
  14. package/dist/generators/ts/AbstractCollectionType.js +28 -111
  15. package/dist/generators/ts/AbstractContainerType.d.ts +1 -1
  16. package/dist/generators/ts/AbstractDateType.d.ts +4 -9
  17. package/dist/generators/ts/AbstractDateType.js +2 -29
  18. package/dist/generators/ts/AbstractIdentifierType.d.ts +4 -1
  19. package/dist/generators/ts/AbstractIdentifierType.js +0 -17
  20. package/dist/generators/ts/AbstractLazyObjectType.d.ts +8 -5
  21. package/dist/generators/ts/AbstractLazyObjectType.js +21 -21
  22. package/dist/generators/ts/AbstractLiteralType.d.ts +11 -3
  23. package/dist/generators/ts/AbstractLiteralType.js +1 -1
  24. package/dist/generators/ts/AbstractNamedUnionType.d.ts +2 -5
  25. package/dist/generators/ts/AbstractNamedUnionType.js +27 -58
  26. package/dist/generators/ts/AbstractNumericType.d.ts +9 -8
  27. package/dist/generators/ts/AbstractNumericType.js +18 -11
  28. package/dist/generators/ts/AbstractPrimitiveType.d.ts +8 -4
  29. package/dist/generators/ts/AbstractPrimitiveType.js +9 -17
  30. package/dist/generators/ts/AbstractTermType.d.ts +8 -4
  31. package/dist/generators/ts/AbstractTermType.js +11 -51
  32. package/dist/generators/ts/AbstractType.d.ts +26 -22
  33. package/dist/generators/ts/AbstractType.js +4 -2
  34. package/dist/generators/ts/AbstractUnionType.d.ts +2 -2
  35. package/dist/generators/ts/AbstractUnionType.js +25 -36
  36. package/dist/generators/ts/AnonymousUnionType.d.ts +1 -1
  37. package/dist/generators/ts/AnonymousUnionType.js +3 -3
  38. package/dist/generators/ts/BigDecimalType.d.ts +5 -3
  39. package/dist/generators/ts/BigDecimalType.js +15 -42
  40. package/dist/generators/ts/BigIntType.d.ts +3 -4
  41. package/dist/generators/ts/BigIntType.js +5 -16
  42. package/dist/generators/ts/BlankNodeType.d.ts +7 -7
  43. package/dist/generators/ts/BlankNodeType.js +14 -2
  44. package/dist/generators/ts/BooleanType.d.ts +6 -8
  45. package/dist/generators/ts/BooleanType.js +18 -11
  46. package/dist/generators/ts/DateTimeType.d.ts +5 -1
  47. package/dist/generators/ts/DateTimeType.js +15 -13
  48. package/dist/generators/ts/DateType.d.ts +5 -1
  49. package/dist/generators/ts/DateType.js +16 -14
  50. package/dist/generators/ts/DefaultValueType.d.ts +5 -6
  51. package/dist/generators/ts/DefaultValueType.js +30 -64
  52. package/dist/generators/ts/FloatType.d.ts +3 -3
  53. package/dist/generators/ts/FloatType.js +5 -5
  54. package/dist/generators/ts/IdentifierType.d.ts +6 -6
  55. package/dist/generators/ts/IdentifierType.js +22 -2
  56. package/dist/generators/ts/IntType.d.ts +3 -3
  57. package/dist/generators/ts/IntType.js +5 -5
  58. package/dist/generators/ts/IriType.d.ts +17 -12
  59. package/dist/generators/ts/IriType.js +39 -29
  60. package/dist/generators/ts/LazyObjectOptionType.d.ts +2 -1
  61. package/dist/generators/ts/LazyObjectOptionType.js +23 -44
  62. package/dist/generators/ts/LazyObjectSetType.d.ts +1 -1
  63. package/dist/generators/ts/LazyObjectSetType.js +19 -29
  64. package/dist/generators/ts/LazyObjectType.d.ts +1 -1
  65. package/dist/generators/ts/LazyObjectType.js +17 -25
  66. package/dist/generators/ts/LiteralType.d.ts +5 -3
  67. package/dist/generators/ts/LiteralType.js +25 -12
  68. package/dist/generators/ts/NamedObjectType.d.ts +6 -9
  69. package/dist/generators/ts/NamedObjectType.js +33 -29
  70. package/dist/generators/ts/NamedObjectUnionType.d.ts +3 -1
  71. package/dist/generators/ts/NamedObjectUnionType.js +21 -14
  72. package/dist/generators/ts/OptionType.d.ts +4 -4
  73. package/dist/generators/ts/OptionType.js +22 -45
  74. package/dist/generators/ts/Reusables.d.ts +3 -1
  75. package/dist/generators/ts/Reusables.js +2 -1
  76. package/dist/generators/ts/SetType.d.ts +0 -1
  77. package/dist/generators/ts/SetType.js +4 -22
  78. package/dist/generators/ts/SnippetFactory.d.ts +2 -0
  79. package/dist/generators/ts/Snippets.d.ts +40 -8
  80. package/dist/generators/ts/Snippets.js +235 -30
  81. package/dist/generators/ts/StringType.d.ts +6 -9
  82. package/dist/generators/ts/StringType.js +17 -16
  83. package/dist/generators/ts/TermType.d.ts +1 -4
  84. package/dist/generators/ts/TermType.js +14 -8
  85. package/dist/generators/ts/TsGenerator.d.ts +14 -1
  86. package/dist/generators/ts/TsGenerator.js +41 -12
  87. package/dist/generators/ts/TypeFactory.d.ts +8 -4
  88. package/dist/generators/ts/TypeFactory.js +73 -49
  89. package/dist/generators/ts/ZodGenerator.js +6 -3
  90. package/dist/generators/ts/_NamedObjectType/AbstractProperty.d.ts +27 -20
  91. package/dist/generators/ts/_NamedObjectType/AbstractProperty.js +4 -2
  92. package/dist/generators/ts/_NamedObjectType/DiscriminantProperty.d.ts +7 -7
  93. package/dist/generators/ts/_NamedObjectType/DiscriminantProperty.js +9 -9
  94. package/dist/generators/ts/_NamedObjectType/IdentifierProperty.d.ts +6 -6
  95. package/dist/generators/ts/_NamedObjectType/IdentifierProperty.js +35 -39
  96. package/dist/generators/ts/_NamedObjectType/NamedObjectType_createFunctionDeclaration.js +34 -31
  97. package/dist/generators/ts/_NamedObjectType/NamedObjectType_equalsFunctionDeclaration.js +1 -1
  98. package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlConstructTriplesFunctionDeclaration.js +1 -1
  99. package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlWherePatternsFunctionDeclaration.js +1 -1
  100. package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromJsonFunctionDeclaration.js +7 -16
  101. package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceFunctionDeclaration.js +26 -32
  102. package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceValuesFunctionDeclaration.js +1 -1
  103. package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfTypeVariableStatement.js +1 -1
  104. package/dist/generators/ts/_NamedObjectType/NamedObjectType_graphqlTypeVariableStatement.js +2 -3
  105. package/dist/generators/ts/_NamedObjectType/NamedObjectType_hashFunctionDeclarations.js +6 -8
  106. package/dist/generators/ts/_NamedObjectType/NamedObjectType_isTypeFunctionDeclaration.js +1 -2
  107. package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonParseFunctionDeclaration.js +1 -1
  108. package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonSchemaFunctionDeclaration.js +1 -1
  109. package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonTypeAliasDeclaration.js +1 -1
  110. package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonUiSchemaFunctionDeclaration.js +1 -1
  111. package/dist/generators/ts/_NamedObjectType/NamedObjectType_objectSetMethodNames.d.ts +2 -0
  112. package/dist/generators/ts/_NamedObjectType/NamedObjectType_objectSetMethodNames.js +1 -1
  113. package/dist/generators/ts/_NamedObjectType/NamedObjectType_sparqlConstructQueryFunctionDeclaration.d.ts +2 -2
  114. package/dist/generators/ts/_NamedObjectType/NamedObjectType_sparqlConstructQueryFunctionDeclaration.js +1 -1
  115. package/dist/generators/ts/_NamedObjectType/NamedObjectType_sparqlConstructQueryStringFunctionDeclaration.d.ts +2 -2
  116. package/dist/generators/ts/_NamedObjectType/NamedObjectType_sparqlConstructQueryStringFunctionDeclaration.js +1 -1
  117. package/dist/generators/ts/_NamedObjectType/NamedObjectType_toJsonFunctionDeclaration.js +2 -2
  118. package/dist/generators/ts/_NamedObjectType/NamedObjectType_toRdfResourceFunctionDeclaration.js +1 -1
  119. package/dist/generators/ts/_NamedObjectType/NamedObjectType_toStringFunctionDeclarations.js +14 -18
  120. package/dist/generators/ts/_NamedObjectType/NamedObjectType_valueSparqlConstructTriplesFunctionDeclaration.js +1 -1
  121. package/dist/generators/ts/_NamedObjectType/NamedObjectType_valueSparqlWherePatternsFunctionDeclaration.js +1 -1
  122. package/dist/generators/ts/_NamedObjectType/ShaclProperty.d.ts +7 -7
  123. package/dist/generators/ts/_NamedObjectType/ShaclProperty.js +22 -30
  124. package/dist/generators/ts/_snippets/snippets_DefaultValueSchema.js +3 -3
  125. package/dist/generators/ts/_snippets/snippets_HashFunction.d.ts +3 -0
  126. package/dist/generators/ts/_snippets/snippets_HashFunction.js +4 -0
  127. package/dist/generators/ts/_snippets/snippets_PropertyPath.js +34 -24
  128. package/dist/generators/ts/_snippets/snippets_convertToBigDecimal.d.ts +3 -0
  129. package/dist/generators/ts/_snippets/snippets_convertToBigDecimal.js +6 -0
  130. package/dist/generators/ts/_snippets/snippets_convertToBlankNode.d.ts +3 -0
  131. package/dist/generators/ts/_snippets/snippets_convertToBlankNode.js +11 -0
  132. package/dist/generators/ts/_snippets/snippets_convertToBlankNodeIdentifierProperty.d.ts +3 -0
  133. package/dist/generators/ts/_snippets/snippets_convertToBlankNodeIdentifierProperty.js +17 -0
  134. package/dist/generators/ts/_snippets/snippets_convertToBoolean.d.ts +3 -0
  135. package/dist/generators/ts/_snippets/snippets_convertToBoolean.js +6 -0
  136. package/dist/generators/ts/_snippets/snippets_convertToDate.d.ts +3 -0
  137. package/dist/generators/ts/_snippets/snippets_convertToDate.js +6 -0
  138. package/dist/generators/ts/_snippets/snippets_convertToDateTime.d.ts +3 -0
  139. package/dist/generators/ts/_snippets/snippets_convertToDateTime.js +6 -0
  140. package/dist/generators/ts/_snippets/snippets_convertToIdentifier.d.ts +3 -0
  141. package/dist/generators/ts/_snippets/snippets_convertToIdentifier.js +13 -0
  142. package/dist/generators/ts/_snippets/snippets_convertToIdentifierProperty.d.ts +3 -0
  143. package/dist/generators/ts/_snippets/snippets_convertToIdentifierProperty.js +21 -0
  144. package/dist/generators/ts/_snippets/snippets_convertToIri.d.ts +3 -0
  145. package/dist/generators/ts/_snippets/snippets_convertToIri.js +11 -0
  146. package/dist/generators/ts/_snippets/snippets_convertToIriIdentifierProperty.d.ts +3 -0
  147. package/dist/generators/ts/_snippets/snippets_convertToIriIdentifierProperty.js +17 -0
  148. package/dist/generators/ts/_snippets/snippets_convertToLazyObject.d.ts +3 -0
  149. package/dist/generators/ts/_snippets/snippets_convertToLazyObject.js +15 -0
  150. package/dist/generators/ts/_snippets/snippets_convertToLazyObjectOption.d.ts +3 -0
  151. package/dist/generators/ts/_snippets/snippets_convertToLazyObjectOption.js +31 -0
  152. package/dist/generators/ts/_snippets/snippets_convertToLazyObjectSet.d.ts +3 -0
  153. package/dist/generators/ts/_snippets/snippets_convertToLazyObjectSet.js +25 -0
  154. package/dist/generators/ts/_snippets/snippets_convertToLiteral.d.ts +3 -0
  155. package/dist/generators/ts/_snippets/snippets_convertToLiteral.js +13 -0
  156. package/dist/generators/ts/_snippets/snippets_convertToMaybe.d.ts +3 -0
  157. package/dist/generators/ts/_snippets/snippets_convertToMaybe.js +19 -0
  158. package/dist/generators/ts/_snippets/snippets_convertToMutableArray.d.ts +3 -0
  159. package/dist/generators/ts/_snippets/snippets_convertToMutableArray.js +14 -0
  160. package/dist/generators/ts/_snippets/snippets_convertToNumeric.d.ts +3 -0
  161. package/dist/generators/ts/_snippets/snippets_convertToNumeric.js +6 -0
  162. package/dist/generators/ts/_snippets/snippets_convertToObject.d.ts +3 -0
  163. package/dist/generators/ts/_snippets/snippets_convertToObject.js +6 -0
  164. package/dist/generators/ts/_snippets/snippets_convertToReadonlyArray.d.ts +3 -0
  165. package/dist/generators/ts/_snippets/snippets_convertToReadonlyArray.js +14 -0
  166. package/dist/generators/ts/_snippets/snippets_convertToString.d.ts +3 -0
  167. package/dist/generators/ts/_snippets/snippets_convertToString.js +6 -0
  168. package/dist/generators/ts/_snippets/snippets_convertToTerm.d.ts +3 -0
  169. package/dist/generators/ts/_snippets/snippets_convertToTerm.js +6 -0
  170. package/dist/generators/ts/_snippets/snippets_convertToUnion.d.ts +3 -0
  171. package/dist/generators/ts/_snippets/snippets_convertToUnion.js +6 -0
  172. package/dist/generators/ts/_snippets/snippets_convertWithDefaultValue.d.ts +3 -0
  173. package/dist/generators/ts/_snippets/snippets_convertWithDefaultValue.js +11 -0
  174. package/dist/generators/ts/_snippets/snippets_defaultValueSparqlWherePatterns.js +1 -1
  175. package/dist/generators/ts/_snippets/snippets_hashArray.d.ts +3 -0
  176. package/dist/generators/ts/_snippets/snippets_hashArray.js +11 -0
  177. package/dist/generators/ts/_snippets/snippets_hashBigDecimal.d.ts +3 -0
  178. package/dist/generators/ts/_snippets/snippets_hashBigDecimal.js +7 -0
  179. package/dist/generators/ts/_snippets/snippets_hashBoolean.d.ts +3 -0
  180. package/dist/generators/ts/_snippets/snippets_hashBoolean.js +7 -0
  181. package/dist/generators/ts/_snippets/snippets_hashDate.d.ts +3 -0
  182. package/dist/generators/ts/_snippets/snippets_hashDate.js +7 -0
  183. package/dist/generators/ts/_snippets/snippets_hashDateTime.d.ts +3 -0
  184. package/dist/generators/ts/_snippets/snippets_hashDateTime.js +7 -0
  185. package/dist/generators/ts/_snippets/snippets_hashMaybe.d.ts +3 -0
  186. package/dist/generators/ts/_snippets/snippets_hashMaybe.js +11 -0
  187. package/dist/generators/ts/_snippets/snippets_hashNumeric.d.ts +3 -0
  188. package/dist/generators/ts/_snippets/snippets_hashNumeric.js +7 -0
  189. package/dist/generators/ts/_snippets/snippets_hashString.d.ts +3 -0
  190. package/dist/generators/ts/_snippets/snippets_hashString.js +7 -0
  191. package/dist/generators/ts/_snippets/snippets_hashTerm.d.ts +3 -0
  192. package/dist/generators/ts/_snippets/snippets_hashTerm.js +12 -0
  193. package/dist/generators/ts/_snippets/snippets_toIsoDateString.d.ts +3 -0
  194. package/dist/generators/ts/_snippets/snippets_toIsoDateString.js +6 -0
  195. package/dist/generators/ts/graphqlSchemaVariableStatement.d.ts +1 -1
  196. package/dist/generators/ts/graphqlSchemaVariableStatement.js +7 -4
  197. package/dist/generators/ts/objectSetDeclarations.js +4 -34
  198. package/dist/generators/ts/objectSetInterfaceDeclaration.js +1 -1
  199. package/dist/generators/ts/objectSetMethodSignatures.js +2 -2
  200. package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +2 -2
  201. package/dist/generators/ts/sparqlObjectSetClassDeclaration.js +2 -2
  202. package/dist/input/ShapesGraph.d.ts +5 -8
  203. package/dist/input/ShapesGraph.js +5 -6
  204. package/dist/input/generated.d.ts +171 -226
  205. package/dist/input/generated.js +563 -2082
  206. package/package.json +2 -2
  207. package/dist/_ShapesGraphToAstTransformer/nodeShapeTsFeatures.d.ts +0 -6
  208. package/dist/_ShapesGraphToAstTransformer/nodeShapeTsFeatures.js +0 -67
  209. package/dist/generators/ts/_snippets/snippets_isReadonlyBigIntArray.d.ts +0 -3
  210. package/dist/generators/ts/_snippets/snippets_isReadonlyBigIntArray.js +0 -6
  211. package/dist/generators/ts/_snippets/snippets_isReadonlyBooleanArray.d.ts +0 -3
  212. package/dist/generators/ts/_snippets/snippets_isReadonlyBooleanArray.js +0 -6
  213. package/dist/generators/ts/_snippets/snippets_isReadonlyNumberArray.d.ts +0 -3
  214. package/dist/generators/ts/_snippets/snippets_isReadonlyNumberArray.js +0 -6
  215. package/dist/generators/ts/_snippets/snippets_isReadonlyObjectArray.d.ts +0 -3
  216. package/dist/generators/ts/_snippets/snippets_isReadonlyObjectArray.js +0 -6
  217. package/dist/generators/ts/_snippets/snippets_isReadonlyStringArray.d.ts +0 -3
  218. package/dist/generators/ts/_snippets/snippets_isReadonlyStringArray.js +0 -6
  219. package/dist/generators/ts/syntheticNamePrefix.d.ts +0 -2
  220. package/dist/generators/ts/syntheticNamePrefix.js +0 -2
@@ -7,9 +7,29 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  import { NodeKind } from "@shaclmate/shacl-ast";
8
8
  import { Memoize } from "typescript-memoize";
9
9
  import { AbstractIdentifierType } from "./AbstractIdentifierType.js";
10
- import { AbstractTermType } from "./AbstractTermType.js";
11
10
  import { arrayOf, code } from "./ts-poet-wrapper.js";
12
11
  export class IdentifierType extends AbstractIdentifierType {
12
+ conversionFunction = {
13
+ code: code `${this.reusables.snippets.convertToIdentifier}`,
14
+ sourceTypes: [
15
+ {
16
+ name: code `${this.reusables.imports.BlankNode}`,
17
+ typeof: "object",
18
+ },
19
+ {
20
+ name: code `${this.reusables.imports.NamedNode}`,
21
+ typeof: "object",
22
+ },
23
+ {
24
+ name: "string",
25
+ typeof: "string",
26
+ },
27
+ {
28
+ name: "undefined",
29
+ typeof: "undefined",
30
+ },
31
+ ],
32
+ };
13
33
  filterFunction = code `${this.reusables.snippets.filterIdentifier}`;
14
34
  filterType = code `${this.reusables.snippets.IdentifierFilter}`;
15
35
  parseFunction = code `${this.reusables.snippets.parseIdentifier};`;
@@ -32,7 +52,7 @@ export class IdentifierType extends AbstractIdentifierType {
32
52
  const discriminantProperty = parameters?.includeDiscriminantProperty
33
53
  ? `, readonly termType: "BlankNode" | "NamedNode"`
34
54
  : "";
35
- return new AbstractTermType.JsonType(code `{ readonly "@id": string${discriminantProperty} }`);
55
+ return new AbstractIdentifierType.JsonType(code `{ readonly "@id": string${discriminantProperty} }`);
36
56
  }
37
57
  jsonSchema({ includeDiscriminantProperty, }) {
38
58
  const discriminantProperty = includeDiscriminantProperty
@@ -1,11 +1,11 @@
1
- import { NonEmptyList } from "purify-ts";
1
+ import type { Literal } from "@rdfjs/types";
2
2
  import { AbstractNumericType } from "./AbstractNumericType.js";
3
3
  import { type Code } from "./ts-poet-wrapper.js";
4
4
  export declare class IntType extends AbstractNumericType<number> {
5
5
  readonly kind = "IntType";
6
- readonly typeofs: NonEmptyList<"number">;
6
+ readonly typeofs: "number"[];
7
7
  get graphqlType(): import("./AbstractType.js").AbstractType.GraphqlType;
8
+ literalExpression(literal: Literal | number): Code;
8
9
  protected fromRdfResourceValueExpression({ variables, }: Parameters<AbstractNumericType<number>["fromRdfResourceValueExpression"]>[0]): Code;
9
- protected literalOf(value: number): string;
10
10
  }
11
11
  //# sourceMappingURL=IntType.d.ts.map
@@ -4,22 +4,22 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
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
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
- import { NonEmptyList } from "purify-ts";
7
+ import { LiteralDecoder } from "@rdfx/literal";
8
8
  import { Memoize } from "typescript-memoize";
9
9
  import { AbstractNumericType } from "./AbstractNumericType.js";
10
10
  import { code } from "./ts-poet-wrapper.js";
11
11
  export class IntType extends AbstractNumericType {
12
12
  kind = "IntType";
13
- typeofs = NonEmptyList(["number"]);
13
+ typeofs = ["number"];
14
14
  get graphqlType() {
15
15
  return new AbstractNumericType.GraphqlType(code `${this.reusables.imports.GraphQLInt}`, this.reusables);
16
16
  }
17
+ literalExpression(literal) {
18
+ return code `${typeof literal === "number" ? literal : LiteralDecoder.decodeIntLiteral(literal).unsafeCoerce()}`;
19
+ }
17
20
  fromRdfResourceValueExpression({ variables, }) {
18
21
  return code `${variables.value}.toInt(${this.primitiveIn.length > 0 ? `${JSON.stringify(this.primitiveIn)} as const` : ""})`;
19
22
  }
20
- literalOf(value) {
21
- return value.toString();
22
- }
23
23
  }
24
24
  __decorate([
25
25
  Memoize()
@@ -1,6 +1,5 @@
1
- import type { BlankNode, NamedNode } from "@rdfjs/types";
1
+ import type { NamedNode } from "@rdfjs/types";
2
2
  import { AbstractIdentifierType } from "./AbstractIdentifierType.js";
3
- import { AbstractTermType } from "./AbstractTermType.js";
4
3
  import { type Code } from "./ts-poet-wrapper.js";
5
4
  export declare class IriType extends AbstractIdentifierType<NamedNode> {
6
5
  readonly filterFunction: Code;
@@ -9,16 +8,22 @@ export declare class IriType extends AbstractIdentifierType<NamedNode> {
9
8
  readonly nodeKinds: ReadonlySet<"IRI">;
10
9
  readonly schemaType: Code;
11
10
  readonly valueSparqlWherePatternsFunction: Code;
12
- get parseFunction(): Code;
13
- get name(): Code;
14
- protected get schemaObject(): {
15
- in: Code[] | undefined;
16
- kind: Code;
11
+ get conversionFunction(): {
12
+ code: Code;
13
+ sourceTypes: ({
14
+ name: Code;
15
+ typeof: "string";
16
+ } | {
17
+ name: Code;
18
+ typeof: "object";
19
+ })[];
17
20
  };
18
- fromJsonExpression({ variables, }: Parameters<AbstractTermType<NamedNode, BlankNode | NamedNode>["fromJsonExpression"]>[0]): Code;
19
- jsonType(parameters?: Parameters<AbstractTermType["jsonType"]>[0]): AbstractTermType.JsonType;
20
- jsonSchema({ includeDiscriminantProperty, }: Parameters<AbstractTermType<NamedNode, BlankNode | NamedNode>["jsonSchema"]>[0]): Code;
21
- toJsonExpression({ includeDiscriminantProperty, variables, }: Parameters<AbstractTermType<NamedNode, BlankNode | NamedNode>["toJsonExpression"]>[0]): Code;
22
- protected fromRdfExpressionChain({ variables, }: Parameters<AbstractTermType["fromRdfExpressionChain"]>[0]): ReturnType<AbstractTermType["fromRdfExpressionChain"]>;
21
+ get name(): Code;
22
+ get parseFunction(): Code;
23
+ fromJsonExpression({ variables, }: Parameters<AbstractIdentifierType<NamedNode>["fromJsonExpression"]>[0]): Code;
24
+ jsonSchema({ includeDiscriminantProperty, }: Parameters<AbstractIdentifierType<NamedNode>["jsonSchema"]>[0]): Code;
25
+ jsonType(parameters?: Parameters<AbstractIdentifierType<NamedNode>["jsonType"]>[0]): AbstractIdentifierType.JsonType;
26
+ toJsonExpression({ includeDiscriminantProperty, variables, }: Parameters<AbstractIdentifierType<NamedNode>["toJsonExpression"]>[0]): Code;
27
+ protected fromRdfExpressionChain({ variables, }: Parameters<AbstractIdentifierType<NamedNode>["fromRdfExpressionChain"]>[0]): ReturnType<AbstractIdentifierType<NamedNode>["fromRdfExpressionChain"]>;
23
28
  }
24
29
  //# sourceMappingURL=IriType.d.ts.map
@@ -6,8 +6,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
6
6
  };
7
7
  import { Memoize } from "typescript-memoize";
8
8
  import { AbstractIdentifierType } from "./AbstractIdentifierType.js";
9
- import { AbstractTermType } from "./AbstractTermType.js";
10
- import { arrayOf, code, joinCode } from "./ts-poet-wrapper.js";
9
+ import { arrayOf, code, joinCode, literalOf, } from "./ts-poet-wrapper.js";
11
10
  export class IriType extends AbstractIdentifierType {
12
11
  filterFunction = code `${this.reusables.snippets.filterIri}`;
13
12
  filterType = code `${this.reusables.snippets.IriFilter}`;
@@ -15,44 +14,41 @@ export class IriType extends AbstractIdentifierType {
15
14
  nodeKinds = nodeKinds;
16
15
  schemaType = code `${this.reusables.snippets.IriSchema}`;
17
16
  valueSparqlWherePatternsFunction = code `${this.reusables.snippets.iriSparqlWherePatterns}`;
18
- get parseFunction() {
19
- if (this.in_.length > 0) {
20
- return code `(identifier: string) => ${this.reusables.snippets.parseIri}(identifier).chain((identifier) => { switch (identifier.value) { ${joinCode(this.in_.map((iri) => code `case "${iri.value}": return ${this.reusables.imports.Right}(identifier as ${this.name});`))} default: return ${this.reusables.imports.Left}(new Error("expected NamedNode identifier to be one of ${this.in_.map((iri) => iri.value).join(" ")}")); } })`;
21
- }
22
- return code `${this.reusables.snippets.parseIri}`;
17
+ get conversionFunction() {
18
+ const IriT = this.in_.length > 0
19
+ ? code `${joinCode(this.in_.map((iri) => code `${literalOf(iri.value)}`), { on: "| " })}`
20
+ : code `string`;
21
+ return {
22
+ code: code `${this.reusables.snippets.convertToIri}<${IriT}>`,
23
+ sourceTypes: [
24
+ {
25
+ name: IriT,
26
+ typeof: "string",
27
+ },
28
+ {
29
+ name: this.name,
30
+ typeof: "object",
31
+ },
32
+ ],
33
+ };
23
34
  }
24
35
  get name() {
25
36
  if (this.in_.length > 0) {
26
37
  // Treat sh:in as a union of the IRIs
27
38
  // rdfjs.NamedNode<"http://example.com/1" | "http://example.com/2">
28
- return code `${this.reusables.imports.NamedNode}<${this.in_
29
- .map((iri) => `"${iri.value}"`)
30
- .join(" | ")}>`;
39
+ return code `${this.reusables.imports.NamedNode}<${joinCode(this.in_.map((iri) => code `${literalOf(iri.value)}`), { on: "| " })}>`;
31
40
  }
32
41
  return code `${this.reusables.imports.NamedNode}`;
33
42
  }
34
- get schemaObject() {
35
- return {
36
- ...super.schemaObject,
37
- in: this.in_.length > 0
38
- ? this.in_.map((in_) => this.rdfjsTermExpression(in_)).concat()
39
- : undefined,
40
- };
43
+ get parseFunction() {
44
+ if (this.in_.length > 0) {
45
+ return code `(identifier: string) => ${this.reusables.snippets.parseIri}(identifier).chain((identifier) => { switch (identifier.value) { ${joinCode(this.in_.map((iri) => code `case "${iri.value}": return ${this.reusables.imports.Right}(identifier as ${this.name});`))} default: return ${this.reusables.imports.Left}(new Error("expected NamedNode identifier to be one of ${this.in_.map((iri) => iri.value).join(" ")}")); } })`;
46
+ }
47
+ return code `${this.reusables.snippets.parseIri}`;
41
48
  }
42
49
  fromJsonExpression({ variables, }) {
43
50
  return code `${this.reusables.imports.dataFactory}.namedNode(${variables.value}["@id"])`;
44
51
  }
45
- jsonType(parameters) {
46
- const discriminantProperty = parameters?.includeDiscriminantProperty
47
- ? `, readonly termType: "NamedNode"`
48
- : "";
49
- if (this.in_.length > 0) {
50
- // Treat sh:in as a union of the IRIs
51
- // rdfjs.NamedNode<"http://example.com/1" | "http://example.com/2">
52
- return new AbstractTermType.JsonType(code `{ readonly "@id": ${this.in_.map((iri) => `"${iri.value}"`).join(" | ")}${discriminantProperty} }`);
53
- }
54
- return new AbstractTermType.JsonType(code `{ readonly "@id": string${discriminantProperty} }`);
55
- }
56
52
  jsonSchema({ includeDiscriminantProperty, }) {
57
53
  let idSchema;
58
54
  if (this.in_.length > 0) {
@@ -68,6 +64,17 @@ export class IriType extends AbstractIdentifierType {
68
64
  : "";
69
65
  return code `${this.reusables.imports.z}.object({ "@id": ${idSchema}${discriminantProperty} })`;
70
66
  }
67
+ jsonType(parameters) {
68
+ const discriminantProperty = parameters?.includeDiscriminantProperty
69
+ ? `, readonly termType: "NamedNode"`
70
+ : "";
71
+ if (this.in_.length > 0) {
72
+ // Treat sh:in as a union of the IRIs
73
+ // rdfjs.NamedNode<"http://example.com/1" | "http://example.com/2">
74
+ return new AbstractIdentifierType.JsonType(code `{ readonly "@id": ${this.in_.map((iri) => `"${iri.value}"`).join(" | ")}${discriminantProperty} }`);
75
+ }
76
+ return new AbstractIdentifierType.JsonType(code `{ readonly "@id": string${discriminantProperty} }`);
77
+ }
71
78
  toJsonExpression({ includeDiscriminantProperty, variables, }) {
72
79
  const discriminantProperty = includeDiscriminantProperty
73
80
  ? code `, termType: ${variables.value}.termType`
@@ -85,10 +92,13 @@ export class IriType extends AbstractIdentifierType {
85
92
  }
86
93
  __decorate([
87
94
  Memoize()
88
- ], IriType.prototype, "parseFunction", null);
95
+ ], IriType.prototype, "conversionFunction", null);
89
96
  __decorate([
90
97
  Memoize()
91
98
  ], IriType.prototype, "name", null);
99
+ __decorate([
100
+ Memoize()
101
+ ], IriType.prototype, "parseFunction", null);
92
102
  __decorate([
93
103
  Memoize()
94
104
  ], IriType.prototype, "jsonType", null);
@@ -8,6 +8,7 @@ declare const Super: (abstract new ({ partialType, resolveType, ...superParamete
8
8
  resolveType: OptionType<AbstractLazyObjectType.ObjectTypeConstraint>;
9
9
  } & {
10
10
  comment: Maybe<string>;
11
+ configuration: import("./TsGenerator.js").TsGenerator.Configuration;
11
12
  label: Maybe<string>;
12
13
  logger: import("ts-log").Logger;
13
14
  reusables: import("./Reusables.js").Reusables;
@@ -18,7 +19,7 @@ declare const Super: (abstract new ({ partialType, resolveType, ...superParamete
18
19
  export declare class LazyObjectOptionType extends Super {
19
20
  readonly graphqlArgs: Super["graphqlArgs"];
20
21
  readonly kind = "LazyObjectOptionType";
21
- get conversions(): readonly AbstractLazyObjectType.Conversion[];
22
+ get conversionFunction(): AbstractLazyObjectType.ConversionFunction;
22
23
  protected get runtimeClass(): {
23
24
  name: Code;
24
25
  partialPropertyName: string;
@@ -12,49 +12,28 @@ const Super = (AbstractLazyObjectType);
12
12
  export class LazyObjectOptionType extends Super {
13
13
  graphqlArgs = Maybe.empty();
14
14
  kind = "LazyObjectOptionType";
15
- get conversions() {
16
- const conversions = super.conversions.concat();
17
- if (this.partialType.itemType.kind === "NamedObjectType") {
18
- conversions.push({
19
- conversionExpression: (value) => code `new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}: ${value}.map(${this.partialType.itemType.name}.create), resolver: async () => ${this.reusables.imports.Right}((${value} as ${this.reusables.imports.Maybe}<${this.resolveType.itemType.name}>).unsafeCoerce()) })`,
20
- sourceTypeCheckExpression: (value) => code `${this.reusables.imports.Maybe}.isMaybe(${value})`,
21
- sourceTypeName: code `${this.reusables.imports.Maybe}<${this.resolveType.itemType.name}>`,
22
- sourceTypeof: "object",
23
- }, {
24
- conversionExpression: (value) => code `new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}: ${this.reusables.imports.Maybe}.of(${this.partialType.itemType.name}.create(${value})), resolver: async () => ${this.reusables.imports.Right}(${value} as ${this.resolveType.itemType.name}) })`,
25
- // Don't check instanceof value since the NamedObjectUnionType may be an interface
26
- // Rely on the fact that this will be the last type check on an object
27
- sourceTypeCheckExpression: (value) => code `typeof ${value} === "object"`,
28
- sourceTypeName: this.resolveType.itemType.name,
29
- sourceTypeof: "object",
30
- });
31
- }
32
- else if (this.resolveType.itemType.kind === "NamedObjectUnionType" &&
33
- this.partialType.itemType.kind === "NamedObjectUnionType" &&
34
- this.resolveType.itemType.members.length ===
35
- this.partialType.itemType.members.length) {
36
- const maybeMap = code `.map(object => { ${this.resolvedNamedObjectUnionTypeToPartialNamedObjectUnionTypeConversion({ resolvedNamedObjectUnionType: this.resolveType.itemType, partialNamedObjectUnionType: this.partialType.itemType, variables: { resolvedObjectUnion: code `object` } })} })`;
37
- conversions.push({
38
- conversionExpression: (value) => code `new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}: ${value}${maybeMap}, resolver: async () => ${this.reusables.imports.Right}((${value} as ${this.reusables.imports.Maybe}<${this.resolveType.itemType.name}>).unsafeCoerce()) })`,
39
- sourceTypeCheckExpression: (value) => code `${this.reusables.imports.Maybe}.isMaybe(${value})`,
40
- sourceTypeName: code `${this.reusables.imports.Maybe}<${this.resolveType.itemType.name}>`,
41
- sourceTypeof: "object",
42
- }, {
43
- conversionExpression: (value) => code `new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}: ${this.reusables.imports.Maybe}.of(${value})${maybeMap}, resolver: async () => ${this.reusables.imports.Right}(${value} as ${this.resolveType.itemType.name}) })`,
44
- // Don't check instanceof value since the NamedObjectUnionType may be an interface
45
- // Rely on the fact that this will be the last type check on an object
46
- sourceTypeCheckExpression: (value) => code `typeof ${value} === "object"`,
47
- sourceTypeName: this.resolveType.itemType.name,
48
- sourceTypeof: "object",
49
- });
50
- }
51
- conversions.push({
52
- conversionExpression: () => code `new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}: ${this.reusables.imports.Maybe}.empty(), resolver: async () => { throw new Error("should never be called"); } })`,
53
- sourceTypeCheckExpression: (value) => code `${value} === undefined`,
54
- sourceTypeName: code `undefined`,
55
- sourceTypeof: "undefined",
56
- });
57
- return conversions;
15
+ get conversionFunction() {
16
+ return {
17
+ code: code `${this.reusables.snippets.convertToLazyObjectOption}<${this.resolveType.itemType.identifierTypeAlias}, ${this.partialType.itemType.name}, ${this.resolveType.itemType.name}>(${this.resolveToPartialFunction({ partialType: this.partialType.itemType, resolveType: this.resolveType.itemType })})`,
18
+ sourceTypes: [
19
+ {
20
+ name: this.name,
21
+ typeof: "object",
22
+ },
23
+ {
24
+ name: this.resolveType.name,
25
+ typeof: "object",
26
+ },
27
+ {
28
+ name: this.resolveType.itemType.name,
29
+ typeof: "object",
30
+ },
31
+ {
32
+ name: "undefined",
33
+ typeof: "undefined",
34
+ },
35
+ ],
36
+ };
58
37
  }
59
38
  get runtimeClass() {
60
39
  return {
@@ -76,7 +55,7 @@ export class LazyObjectOptionType extends Super {
76
55
  }
77
56
  __decorate([
78
57
  Memoize()
79
- ], LazyObjectOptionType.prototype, "conversions", null);
58
+ ], LazyObjectOptionType.prototype, "conversionFunction", null);
80
59
  __decorate([
81
60
  Memoize()
82
61
  ], LazyObjectOptionType.prototype, "runtimeClass", null);
@@ -4,7 +4,7 @@ import { type Code } from "./ts-poet-wrapper.js";
4
4
  export declare class LazyObjectSetType extends AbstractLazyObjectType<SetType<AbstractLazyObjectType.ObjectTypeConstraint>, SetType<AbstractLazyObjectType.ObjectTypeConstraint>> {
5
5
  readonly graphqlArgs: Super["graphqlArgs"];
6
6
  readonly kind = "LazyObjectSetType";
7
- get conversions(): readonly AbstractLazyObjectType.Conversion[];
7
+ get conversionFunction(): AbstractLazyObjectType.ConversionFunction;
8
8
  protected get runtimeClass(): {
9
9
  name: Code;
10
10
  partialPropertyName: string;
@@ -18,34 +18,24 @@ export class LazyObjectSetType extends AbstractLazyObjectType {
18
18
  },
19
19
  });
20
20
  kind = "LazyObjectSetType";
21
- get conversions() {
22
- const conversions = super.conversions.concat();
23
- if (this.partialType.itemType.kind === "NamedObjectType") {
24
- conversions.push({
25
- conversionExpression: (value) => code `new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}: ${value}.map(${this.partialType.itemType.name}.create), resolver: async () => ${this.reusables.imports.Right}(${value} as readonly ${this.resolveType.itemType.name}[]) })`,
26
- sourceTypeCheckExpression: (value) => code `typeof ${value} === "object"`,
27
- sourceTypeName: code `readonly ${this.resolveType.itemType.name}[]`,
28
- sourceTypeof: "object",
29
- });
30
- }
31
- else if (this.resolveType.itemType.kind === "NamedObjectUnionType" &&
32
- this.partialType.itemType.kind === "NamedObjectUnionType" &&
33
- this.resolveType.itemType.members.length ===
34
- this.partialType.itemType.members.length) {
35
- conversions.push({
36
- conversionExpression: (value) => code `new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}: ${value}.map(object => { ${this.resolvedNamedObjectUnionTypeToPartialNamedObjectUnionTypeConversion({ resolvedNamedObjectUnionType: this.resolveType.itemType, partialNamedObjectUnionType: this.partialType.itemType, variables: { resolvedObjectUnion: code `object` } })} }), resolver: async () => ${this.reusables.imports.Right}(${value} as readonly ${this.resolveType.itemType.name}[]) })`,
37
- sourceTypeCheckExpression: (value) => code `typeof ${value} === "object"`,
38
- sourceTypeName: code `readonly ${this.resolveType.itemType.name}[]`,
39
- sourceTypeof: "object",
40
- });
41
- }
42
- conversions.push({
43
- conversionExpression: () => code `new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}: [], resolver: async () => { throw new Error("should never be called"); } })`,
44
- sourceTypeCheckExpression: (value) => code `${value} === undefined`,
45
- sourceTypeName: code `undefined`,
46
- sourceTypeof: "undefined",
47
- });
48
- return conversions;
21
+ get conversionFunction() {
22
+ return {
23
+ code: code `${this.reusables.snippets.convertToLazyObjectSet}<${this.resolveType.itemType.identifierTypeAlias}, ${this.partialType.itemType.name}, ${this.resolveType.itemType.name}>(${this.resolveToPartialFunction({ partialType: this.partialType.itemType, resolveType: this.resolveType.itemType })})`,
24
+ sourceTypes: [
25
+ {
26
+ name: this.name,
27
+ typeof: "object",
28
+ },
29
+ {
30
+ name: this.resolveType.name,
31
+ typeof: "object",
32
+ },
33
+ {
34
+ name: "undefined",
35
+ typeof: "undefined",
36
+ },
37
+ ],
38
+ };
49
39
  }
50
40
  get runtimeClass() {
51
41
  return {
@@ -67,5 +57,5 @@ export class LazyObjectSetType extends AbstractLazyObjectType {
67
57
  }
68
58
  __decorate([
69
59
  Memoize()
70
- ], LazyObjectSetType.prototype, "conversions", null);
60
+ ], LazyObjectSetType.prototype, "conversionFunction", null);
71
61
  //# sourceMappingURL=LazyObjectSetType.js.map
@@ -3,7 +3,7 @@ import { type Code } from "./ts-poet-wrapper.js";
3
3
  export declare class LazyObjectType extends AbstractLazyObjectType<AbstractLazyObjectType.ObjectTypeConstraint, AbstractLazyObjectType.ObjectTypeConstraint> {
4
4
  readonly graphqlArgs: Super["graphqlArgs"];
5
5
  readonly kind = "LazyObjectType";
6
- get conversions(): readonly AbstractLazyObjectType.Conversion[];
6
+ get conversionFunction(): AbstractLazyObjectType.ConversionFunction;
7
7
  protected get runtimeClass(): {
8
8
  name: Code;
9
9
  partialPropertyName: string;
@@ -11,31 +11,20 @@ import { code } from "./ts-poet-wrapper.js";
11
11
  export class LazyObjectType extends AbstractLazyObjectType {
12
12
  graphqlArgs = Maybe.empty();
13
13
  kind = "LazyObjectType";
14
- get conversions() {
15
- const conversions = super.conversions.concat();
16
- if (this.partialType.kind === "NamedObjectType") {
17
- conversions.push({
18
- conversionExpression: (value) => code `new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}: ${this.partialType.name}.create(${value}), resolver: async () => ${this.reusables.imports.Right}(${value} as ${this.resolveType.name}) })`,
19
- // Don't check instanceof value since the NamedObjectType may be an interface
20
- // Rely on the fact that this will be the last type check on an object
21
- sourceTypeCheckExpression: (value) => code `typeof ${value} === "object"`,
22
- sourceTypeName: this.resolveType.name,
23
- sourceTypeof: "object",
24
- });
25
- }
26
- else if (this.resolveType.kind === "NamedObjectUnionType" &&
27
- this.partialType.kind === "NamedObjectUnionType" &&
28
- this.resolveType.members.length === this.partialType.members.length) {
29
- conversions.push({
30
- conversionExpression: (value) => code `new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}: ((object: ${this.resolveType.name}) => { ${this.resolvedNamedObjectUnionTypeToPartialNamedObjectUnionTypeConversion({ resolvedNamedObjectUnionType: this.resolveType, partialNamedObjectUnionType: this.partialType, variables: { resolvedObjectUnion: code `object` } })} })(${value}), resolver: async () => ${this.reusables.imports.Right}(${value} as ${this.resolveType.name}) })`,
31
- // Don't check instanceof value since the NamedObjectUnionType may be an interface
32
- // Rely on the fact that this will be the last type check on an object
33
- sourceTypeCheckExpression: (value) => code `typeof ${value} === "object"`,
34
- sourceTypeName: this.resolveType.name,
35
- sourceTypeof: "object",
36
- });
37
- }
38
- return conversions;
14
+ get conversionFunction() {
15
+ return {
16
+ code: code `${this.reusables.snippets.convertToLazyObject}<${this.resolveType.identifierTypeAlias}, ${this.partialType.name}, ${this.resolveType.name}>(${this.resolveToPartialFunction({ partialType: this.partialType, resolveType: this.resolveType })})`,
17
+ sourceTypes: [
18
+ {
19
+ name: this.name,
20
+ typeof: "object",
21
+ },
22
+ {
23
+ name: this.resolveType.name,
24
+ typeof: "object",
25
+ },
26
+ ],
27
+ };
39
28
  }
40
29
  get runtimeClass() {
41
30
  return {
@@ -55,6 +44,9 @@ export class LazyObjectType extends AbstractLazyObjectType {
55
44
  return code `${variables.value}.resolve().then(either => either.unsafeCoerce())`;
56
45
  }
57
46
  }
47
+ __decorate([
48
+ Memoize()
49
+ ], LazyObjectType.prototype, "conversionFunction", null);
58
50
  __decorate([
59
51
  Memoize()
60
52
  ], LazyObjectType.prototype, "runtimeClass", null);
@@ -1,18 +1,20 @@
1
+ import type { Literal } from "@rdfjs/types";
1
2
  import { AbstractLiteralType } from "./AbstractLiteralType.js";
2
3
  import { type Code } from "./ts-poet-wrapper.js";
3
4
  export declare class LiteralType extends AbstractLiteralType {
5
+ readonly name: Code;
6
+ readonly conversionFunction: AbstractLiteralType.ConversionFunction;
4
7
  readonly filterFunction: Code;
5
8
  readonly filterType: Code;
6
9
  readonly kind = "LiteralType";
7
- readonly name: Code;
8
10
  readonly schemaType: Code;
9
11
  readonly valueSparqlWherePatternsFunction: Code;
10
12
  get graphqlType(): AbstractLiteralType.GraphqlType;
11
13
  fromJsonExpression({ variables, }: Parameters<AbstractLiteralType["fromJsonExpression"]>[0]): Code;
12
14
  graphqlResolveExpression(_parameters: Parameters<AbstractLiteralType["graphqlResolveExpression"]>[0]): Code;
13
- hashStatements({ depth, variables, }: Parameters<AbstractLiteralType["hashStatements"]>[0]): readonly Code[];
14
- jsonType(parameters?: Parameters<AbstractLiteralType["jsonType"]>[0]): AbstractLiteralType.JsonType;
15
15
  jsonSchema({ includeDiscriminantProperty, }: Parameters<AbstractLiteralType["jsonSchema"]>[0]): Code;
16
+ jsonType(parameters?: Parameters<AbstractLiteralType["jsonType"]>[0]): AbstractLiteralType.JsonType;
17
+ literalExpression(literal: Literal): Code;
16
18
  toJsonExpression({ includeDiscriminantProperty, variables, }: Parameters<AbstractLiteralType["toJsonExpression"]>[0]): Code;
17
19
  }
18
20
  //# sourceMappingURL=LiteralType.d.ts.map
@@ -2,10 +2,27 @@ import { xsd } from "@tpluscode/rdf-ns-builders";
2
2
  import { AbstractLiteralType } from "./AbstractLiteralType.js";
3
3
  import { code } from "./ts-poet-wrapper.js";
4
4
  export class LiteralType extends AbstractLiteralType {
5
+ name = code `${this.reusables.imports.Literal}`;
6
+ conversionFunction = {
7
+ code: code `${this.reusables.snippets.convertToLiteral}`,
8
+ sourceTypes: [
9
+ ...["bigint", "boolean", "number", "string"].map((typeof_) => ({
10
+ name: typeof_,
11
+ typeof: typeof_,
12
+ })),
13
+ {
14
+ name: "Date",
15
+ typeof: "object",
16
+ },
17
+ {
18
+ name: code `${this.reusables.imports.Literal}`,
19
+ typeof: "object",
20
+ },
21
+ ],
22
+ };
5
23
  filterFunction = code `${this.reusables.snippets.filterLiteral}`;
6
24
  filterType = code `${this.reusables.snippets.LiteralFilter}`;
7
25
  kind = "LiteralType";
8
- name = code `${this.reusables.imports.Literal}`;
9
26
  schemaType = code `${this.reusables.snippets.LiteralSchema}`;
10
27
  valueSparqlWherePatternsFunction = code `${this.reusables.snippets.literalSparqlWherePatterns}`;
11
28
  get graphqlType() {
@@ -17,12 +34,11 @@ export class LiteralType extends AbstractLiteralType {
17
34
  graphqlResolveExpression(_parameters) {
18
35
  throw new Error("not implemented");
19
36
  }
20
- hashStatements({ depth, variables, }) {
21
- return [
22
- ...super.hashStatements({ depth, variables }),
23
- code `${variables.hasher}.update(${variables.value}.datatype.value);`,
24
- code `${variables.hasher}.update(${variables.value}.language);`,
25
- ];
37
+ jsonSchema({ includeDiscriminantProperty, }) {
38
+ const discriminantProperty = includeDiscriminantProperty
39
+ ? code `, termType: ${this.reusables.imports.z}.literal("Literal")`
40
+ : "";
41
+ return code `${this.reusables.imports.z}.object({ "@language": ${this.reusables.imports.z}.string().optional()${discriminantProperty}, "@type": ${this.reusables.imports.z}.string().optional(), "@value": ${this.reusables.imports.z}.string() })`;
26
42
  }
27
43
  jsonType(parameters) {
28
44
  const discriminantProperty = parameters?.includeDiscriminantProperty
@@ -30,11 +46,8 @@ export class LiteralType extends AbstractLiteralType {
30
46
  : "";
31
47
  return new AbstractLiteralType.JsonType(code `{ readonly "@language"?: string${discriminantProperty}, readonly "@type"?: string, readonly "@value": string }`);
32
48
  }
33
- jsonSchema({ includeDiscriminantProperty, }) {
34
- const discriminantProperty = includeDiscriminantProperty
35
- ? code `, termType: ${this.reusables.imports.z}.literal("Literal")`
36
- : "";
37
- return code `${this.reusables.imports.z}.object({ "@language": ${this.reusables.imports.z}.string().optional()${discriminantProperty}, "@type": ${this.reusables.imports.z}.string().optional(), "@value": ${this.reusables.imports.z}.string() })`;
49
+ literalExpression(literal) {
50
+ return this.rdfjsTermExpression(literal);
38
51
  }
39
52
  toJsonExpression({ includeDiscriminantProperty, variables, }) {
40
53
  return code `{ "@language": ${variables.value}.language.length > 0 ? ${variables.value}.language : undefined${includeDiscriminantProperty ? `, "termType": "Literal" as const` : ""}, "@type": ${variables.value}.datatype.value !== "${xsd.string.value}" ? ${variables.value}.datatype.value : undefined, "@value": ${variables.value}.value }`;
@@ -1,5 +1,5 @@
1
1
  import type { NamedNode } from "@rdfjs/types";
2
- import { Maybe, NonEmptyList } from "purify-ts";
2
+ import { Maybe } from "purify-ts";
3
3
  import { DiscriminantProperty as _DiscriminantProperty } from "./_NamedObjectType/DiscriminantProperty.js";
4
4
  import { IdentifierProperty as _IdentifierProperty } from "./_NamedObjectType/IdentifierProperty.js";
5
5
  import type { Property as _Property } from "./_NamedObjectType/Property.js";
@@ -8,13 +8,11 @@ import { AbstractType } from "./AbstractType.js";
8
8
  import type { BlankNodeType } from "./BlankNodeType.js";
9
9
  import type { IdentifierType } from "./IdentifierType.js";
10
10
  import type { IriType } from "./IriType.js";
11
- import type { TsFeature } from "./TsFeature.js";
12
11
  import type { Type } from "./Type.js";
13
12
  import { type Code } from "./ts-poet-wrapper.js";
14
13
  export declare class NamedObjectType extends AbstractType {
15
14
  protected readonly toRdfTypes: readonly NamedNode[];
16
15
  readonly extern: boolean;
17
- readonly features: ReadonlySet<TsFeature>;
18
16
  readonly fromRdfType: Maybe<NamedNode>;
19
17
  readonly graphqlArgs: AbstractType["graphqlArgs"];
20
18
  readonly identifierType: BlankNodeType | IdentifierType | IriType;
@@ -22,11 +20,10 @@ export declare class NamedObjectType extends AbstractType {
22
20
  readonly name: string;
23
21
  readonly recursive: boolean;
24
22
  readonly synthetic: boolean;
25
- readonly typeofs: NonEmptyList<"object">;
26
- constructor({ extern, features, fromRdfType, identifierType, lazyAncestorObjectTypes, lazyChildObjectTypes, lazyDescendantObjectTypes, lazyDiscriminantProperty, lazyParentObjectTypes, lazyProperties, name, recursive, synthetic, toRdfTypes, ...superParameters }: {
23
+ readonly typeofs: "object"[];
24
+ constructor({ extern, fromRdfType, identifierType, lazyAncestorObjectTypes, lazyChildObjectTypes, lazyDescendantObjectTypes, lazyDiscriminantProperty, lazyParentObjectTypes, lazyProperties, name, recursive, synthetic, toRdfTypes, ...superParameters }: {
27
25
  comment: Maybe<string>;
28
26
  extern: boolean;
29
- features: ReadonlySet<TsFeature>;
30
27
  fromRdfType: Maybe<NamedNode>;
31
28
  identifierType: BlankNodeType | IdentifierType | IriType;
32
29
  label: Maybe<string>;
@@ -44,7 +41,7 @@ export declare class NamedObjectType extends AbstractType {
44
41
  get _discriminantProperty(): NamedObjectType.DiscriminantProperty;
45
42
  get ancestorObjectTypes(): readonly NamedObjectType[];
46
43
  get childObjectTypes(): readonly NamedObjectType[];
47
- get conversions(): readonly AbstractType.Conversion[];
44
+ get conversionFunction(): AbstractType.ConversionFunction;
48
45
  get declaration(): Maybe<Code>;
49
46
  get descendantFromRdfTypeVariables(): readonly Code[];
50
47
  get descendantFromRdfTypes(): readonly NamedNode[];
@@ -56,6 +53,7 @@ export declare class NamedObjectType extends AbstractType {
56
53
  get filterType(): Code;
57
54
  get fromRdfTypeVariable(): Maybe<Code>;
58
55
  get graphqlType(): AbstractType.GraphqlType;
56
+ get hashFunction(): Code;
59
57
  get identifierTypeAlias(): Code;
60
58
  get mutable(): boolean;
61
59
  get objectSetMethodNames(): NamedObjectType.ObjectSetMethodNames;
@@ -75,13 +73,12 @@ export declare class NamedObjectType extends AbstractType {
75
73
  value: Code;
76
74
  };
77
75
  }): Code;
78
- hashStatements({ variables, }: Parameters<AbstractType["hashStatements"]>[0]): readonly Code[];
79
76
  jsonSchema({ context, }: Parameters<AbstractType["jsonSchema"]>[0]): Code;
80
77
  jsonType(): AbstractType.JsonType;
81
78
  jsonUiSchemaElement({ variables, }: Parameters<AbstractType["jsonUiSchemaElement"]>[0]): Maybe<Code>;
82
79
  toJsonExpression({ variables, }: Parameters<AbstractType["toJsonExpression"]>[0]): Code;
83
- toStringExpression({ variables, }: Parameters<AbstractType["toStringExpression"]>[0]): Code;
84
80
  toRdfResourceValuesExpression({ variables, }: Parameters<AbstractType["toRdfResourceValuesExpression"]>[0]): Code;
81
+ toStringExpression({ variables, }: Parameters<AbstractType["toStringExpression"]>[0]): Code;
85
82
  private readonly lazyAncestorObjectTypes;
86
83
  private readonly lazyChildObjectTypes;
87
84
  private readonly lazyDescendantObjectTypes;