@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,27 +1,31 @@
1
- import type { TsFeature } from "../../enums/index.js";
1
+ import { Maybe } from "purify-ts";
2
2
  import { Import } from "./Import.js";
3
3
  import { Type } from "./Type.js";
4
- export declare class OptionType extends Type {
5
- readonly itemType: Type;
4
+ export declare class OptionType<ItemTypeT extends Type> extends Type {
5
+ readonly discriminatorProperty: Maybe<Type.DiscriminatorProperty>;
6
+ readonly itemType: ItemTypeT;
6
7
  readonly kind = "OptionType";
7
- constructor({ itemType, ...superParameters }: ConstructorParameters<typeof Type>[0] & {
8
- itemType: Type;
8
+ readonly typeof = "object";
9
+ constructor({ itemType }: {
10
+ itemType: ItemTypeT;
9
11
  });
10
12
  get conversions(): readonly Type.Conversion[];
11
13
  get equalsFunction(): string;
12
- get jsonName(): string;
14
+ get graphqlName(): Type.GraphqlName;
15
+ get jsonName(): Type.JsonName;
13
16
  get mutable(): boolean;
14
17
  get name(): string;
15
18
  fromJsonExpression({ variables, }: Parameters<Type["fromJsonExpression"]>[0]): string;
16
19
  fromRdfExpression(parameters: Parameters<Type["fromRdfExpression"]>[0]): string;
20
+ graphqlResolveExpression(parameters: Parameters<Type["graphqlResolveExpression"]>[0]): string;
17
21
  hashStatements({ depth, variables, }: Parameters<Type["hashStatements"]>[0]): readonly string[];
18
22
  jsonUiSchemaElement(parameters: Parameters<Type["jsonUiSchemaElement"]>[0]): ReturnType<Type["jsonUiSchemaElement"]>;
19
23
  jsonZodSchema(parameters: Parameters<Type["jsonZodSchema"]>[0]): ReturnType<Type["jsonZodSchema"]>;
20
- snippetDeclarations(features: Set<TsFeature>): readonly string[];
21
- sparqlConstructTemplateTriples({ context, variables, }: Parameters<Type["sparqlConstructTemplateTriples"]>[0]): readonly string[];
22
- sparqlWherePatterns({ context, variables, }: Parameters<Type["sparqlWherePatterns"]>[0]): readonly string[];
24
+ snippetDeclarations(parameters: Parameters<Type["snippetDeclarations"]>[0]): readonly string[];
25
+ sparqlConstructTemplateTriples(parameters: Parameters<Type["sparqlConstructTemplateTriples"]>[0]): readonly string[];
26
+ sparqlWherePatterns(parameters: Parameters<Type["sparqlWherePatterns"]>[0]): readonly string[];
23
27
  toJsonExpression({ variables, }: Parameters<Type["toJsonExpression"]>[0]): string;
24
28
  toRdfExpression({ variables, }: Parameters<Type["toRdfExpression"]>[0]): string;
25
- useImports(features: Set<TsFeature>): readonly Import[];
29
+ useImports(parameters: Parameters<Type["useImports"]>[0]): readonly Import[];
26
30
  }
27
31
  //# sourceMappingURL=OptionType.d.ts.map
@@ -5,14 +5,19 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
7
  import { Memoize } from "typescript-memoize";
8
+ import { Maybe } from "purify-ts";
9
+ import { invariant } from "ts-invariant";
8
10
  import { Import } from "./Import.js";
9
11
  import { SnippetDeclarations } from "./SnippetDeclarations.js";
10
12
  import { Type } from "./Type.js";
13
+ import { syntheticNamePrefix } from "./syntheticNamePrefix.js";
11
14
  export class OptionType extends Type {
15
+ discriminatorProperty = Maybe.empty();
12
16
  itemType;
13
17
  kind = "OptionType";
14
- constructor({ itemType, ...superParameters }) {
15
- super(superParameters);
18
+ typeof = "object";
19
+ constructor({ itemType }) {
20
+ super();
16
21
  this.itemType = itemType;
17
22
  }
18
23
  get conversions() {
@@ -38,10 +43,19 @@ export class OptionType extends Type {
38
43
  return conversions;
39
44
  }
40
45
  get equalsFunction() {
41
- return `((left, right) => maybeEquals(left, right, ${this.itemType.equalsFunction}))`;
46
+ return `((left, right) => ${syntheticNamePrefix}maybeEquals(left, right, ${this.itemType.equalsFunction}))`;
47
+ }
48
+ get graphqlName() {
49
+ invariant(!this.itemType.graphqlName.nullable);
50
+ return new Type.GraphqlName(this.itemType.graphqlName.toString(), {
51
+ nullable: true,
52
+ });
42
53
  }
43
54
  get jsonName() {
44
- return `(${this.itemType.jsonName}) | undefined`;
55
+ invariant(!this.itemType.jsonName.optional);
56
+ return new Type.JsonName(this.itemType.jsonName.toString(), {
57
+ optional: true,
58
+ });
45
59
  }
46
60
  get mutable() {
47
61
  return this.itemType.mutable;
@@ -52,23 +66,27 @@ export class OptionType extends Type {
52
66
  fromJsonExpression({ variables, }) {
53
67
  const expression = `purify.Maybe.fromNullable(${variables.value})`;
54
68
  const itemFromJsonExpression = this.itemType.fromJsonExpression({
55
- variables: { value: "_item" },
69
+ variables: { value: "item" },
56
70
  });
57
- return itemFromJsonExpression === "_item"
71
+ return itemFromJsonExpression === "item"
58
72
  ? expression
59
- : `${expression}.map(_item => (${itemFromJsonExpression}))`;
73
+ : `${expression}.map(item => (${itemFromJsonExpression}))`;
60
74
  }
61
75
  fromRdfExpression(parameters) {
62
- return `purify.Either.of(${this.itemType.fromRdfExpression(parameters)}.toMaybe())`;
76
+ const { variables } = parameters;
77
+ return `${this.itemType.fromRdfExpression(parameters)}.map(values => values.length > 0 ? values.map(value => purify.Maybe.of(value)) : rdfjsResource.Resource.Values.fromValue<purify.Maybe<${this.itemType.name}>>({ object: purify.Maybe.empty(), predicate: ${variables.predicate}, subject: ${variables.resource} }))`;
78
+ }
79
+ graphqlResolveExpression(parameters) {
80
+ return `${this.itemType.graphqlResolveExpression(parameters)}.extractNullable()`;
63
81
  }
64
82
  hashStatements({ depth, variables, }) {
65
83
  return [
66
- `${variables.value}.ifJust((_value${depth}) => { ${this.itemType
84
+ `${variables.value}.ifJust((value${depth}) => { ${this.itemType
67
85
  .hashStatements({
68
86
  depth: depth + 1,
69
87
  variables: {
70
88
  hasher: variables.hasher,
71
- value: `_value${depth}`,
89
+ value: `value${depth}`,
72
90
  },
73
91
  })
74
92
  .join("\n")} })`,
@@ -80,56 +98,66 @@ export class OptionType extends Type {
80
98
  jsonZodSchema(parameters) {
81
99
  return `${this.itemType.jsonZodSchema(parameters)}.optional()`;
82
100
  }
83
- snippetDeclarations(features) {
101
+ snippetDeclarations(parameters) {
84
102
  const snippetDeclarations = this.itemType
85
- .snippetDeclarations(features)
103
+ .snippetDeclarations(parameters)
86
104
  .concat();
87
- if (features.has("equals")) {
105
+ if (parameters.features.has("equals")) {
88
106
  snippetDeclarations.push(SnippetDeclarations.maybeEquals);
89
107
  }
90
108
  return snippetDeclarations;
91
109
  }
92
- sparqlConstructTemplateTriples({ context, variables, }) {
93
- switch (context) {
94
- case "property":
95
- return super.sparqlConstructTemplateTriples({ context, variables });
96
- case "type":
97
- return this.itemType.sparqlConstructTemplateTriples({
98
- context,
99
- variables,
100
- });
110
+ sparqlConstructTemplateTriples(parameters) {
111
+ switch (parameters.context) {
112
+ case "object":
113
+ return super.sparqlConstructTemplateTriples(parameters);
114
+ case "subject":
115
+ return this.itemType.sparqlConstructTemplateTriples(parameters);
101
116
  }
102
117
  }
103
- sparqlWherePatterns({ context, variables, }) {
104
- switch (context) {
105
- case "property": {
106
- const patterns = super.sparqlWherePatterns({ context, variables });
118
+ sparqlWherePatterns(parameters) {
119
+ switch (parameters.context) {
120
+ case "object": {
121
+ const patterns = this.itemType.sparqlWherePatterns(parameters);
107
122
  if (patterns.length === 0) {
108
123
  return [];
109
124
  }
110
125
  return [`{ patterns: [${patterns.join(", ")}], type: "optional" }`];
111
126
  }
112
- case "type": {
113
- return this.itemType.sparqlWherePatterns({ context, variables });
127
+ case "subject": {
128
+ throw new Error("should never be called");
129
+ // return this.itemType.sparqlWherePatterns(parameters);
114
130
  }
115
131
  }
116
132
  }
117
133
  toJsonExpression({ variables, }) {
118
- return `${variables.value}.map(_item => (${this.itemType.toJsonExpression({ variables: { value: "_item" } })})).extract()`;
134
+ return `${variables.value}.map(item => (${this.itemType.toJsonExpression({ variables: { value: "item" } })})).extract()`;
119
135
  }
120
136
  toRdfExpression({ variables, }) {
121
137
  const itemTypeToRdfExpression = this.itemType.toRdfExpression({
122
- variables: { ...variables, value: "_value" },
138
+ variables: { ...variables, value: "value" },
123
139
  });
124
- if (itemTypeToRdfExpression === "_value") {
140
+ if (itemTypeToRdfExpression === "value") {
125
141
  return variables.value;
126
142
  }
127
- return `${variables.value}.map((_value) => ${itemTypeToRdfExpression})`;
143
+ return `${variables.value}.map((value) => ${itemTypeToRdfExpression})`;
128
144
  }
129
- useImports(features) {
130
- return [...this.itemType.useImports(features), Import.PURIFY];
145
+ useImports(parameters) {
146
+ return [...this.itemType.useImports(parameters), Import.PURIFY];
131
147
  }
132
148
  }
149
+ __decorate([
150
+ Memoize()
151
+ ], OptionType.prototype, "conversions", null);
152
+ __decorate([
153
+ Memoize()
154
+ ], OptionType.prototype, "equalsFunction", null);
155
+ __decorate([
156
+ Memoize()
157
+ ], OptionType.prototype, "graphqlName", null);
158
+ __decorate([
159
+ Memoize()
160
+ ], OptionType.prototype, "jsonName", null);
133
161
  __decorate([
134
162
  Memoize()
135
163
  ], OptionType.prototype, "name", null);
@@ -1,7 +1,6 @@
1
1
  import { Maybe } from "purify-ts";
2
- import type { TsFeature } from "../../enums/index.js";
3
2
  import { LiteralType } from "./LiteralType.js";
4
- import type { Type } from "./Type.js";
3
+ import { Type } from "./Type.js";
5
4
  export declare abstract class PrimitiveType<ValueT extends boolean | Date | string | number> extends LiteralType {
6
5
  readonly equalsFunction: string;
7
6
  readonly primitiveDefaultValue: Maybe<ValueT>;
@@ -11,11 +10,30 @@ export declare abstract class PrimitiveType<ValueT extends boolean | Date | stri
11
10
  primitiveIn: readonly ValueT[];
12
11
  } & ConstructorParameters<typeof LiteralType>[0]);
13
12
  get discriminatorProperty(): Maybe<Type.DiscriminatorProperty>;
14
- get jsonName(): string;
13
+ get jsonName(): Type.JsonName;
15
14
  fromJsonExpression({ variables, }: Parameters<Type["fromJsonExpression"]>[0]): string;
15
+ protected fromRdfExpressionChain({ variables, }: Parameters<Type["fromRdfExpression"]>[0]): {
16
+ defaultValue?: string;
17
+ hasValues?: string;
18
+ languageIn?: string;
19
+ valueTo?: string;
20
+ };
21
+ graphqlResolveExpression({ variables, }: Parameters<Type["graphqlResolveExpression"]>[0]): string;
16
22
  hashStatements({ variables, }: Parameters<Type["hashStatements"]>[0]): readonly string[];
17
- snippetDeclarations(features: Set<TsFeature>): readonly string[];
23
+ snippetDeclarations({ features, }: Parameters<Type["snippetDeclarations"]>[0]): readonly string[];
24
+ sparqlWherePatterns(parameters: Parameters<Type["sparqlWherePatterns"]>[0]): readonly string[];
18
25
  toJsonExpression({ variables, }: Parameters<Type["toJsonExpression"]>[0]): string;
19
- protected propertyFilterRdfResourceValuesExpression({ variables, }: Parameters<LiteralType["propertyFilterRdfResourceValuesExpression"]>[0]): string;
26
+ /**
27
+ * Convert an rdfjsResource.Resource.Value to a value of this type.
28
+ * @param variables
29
+ * @protected
30
+ */
31
+ protected abstract fromRdfResourceValueExpression({ variables, }: {
32
+ variables: {
33
+ predicate: string;
34
+ resource: string;
35
+ resourceValue: string;
36
+ };
37
+ }): string;
20
38
  }
21
39
  //# sourceMappingURL=PrimitiveType.d.ts.map
@@ -1,8 +1,17 @@
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 { Maybe } from "purify-ts";
8
+ import { Memoize } from "typescript-memoize";
2
9
  import { LiteralType } from "./LiteralType.js";
3
10
  import { SnippetDeclarations } from "./SnippetDeclarations.js";
11
+ import { Type } from "./Type.js";
12
+ import { syntheticNamePrefix } from "./syntheticNamePrefix.js";
4
13
  export class PrimitiveType extends LiteralType {
5
- equalsFunction = "strictEquals";
14
+ equalsFunction = `${syntheticNamePrefix}strictEquals`;
6
15
  primitiveDefaultValue;
7
16
  primitiveIn;
8
17
  constructor({ primitiveDefaultValue, primitiveIn, ...superParameters }) {
@@ -14,26 +23,45 @@ export class PrimitiveType extends LiteralType {
14
23
  return Maybe.empty();
15
24
  }
16
25
  get jsonName() {
17
- return this.name;
26
+ return new Type.JsonName(this.name);
18
27
  }
19
28
  fromJsonExpression({ variables, }) {
20
29
  return variables.value;
21
30
  }
31
+ fromRdfExpressionChain({ variables, }) {
32
+ return {
33
+ ...super.fromRdfExpressionChain({ variables }),
34
+ languageIn: undefined,
35
+ valueTo: `chain(values => values.chainMap(value => ${this.fromRdfResourceValueExpression({
36
+ variables: {
37
+ predicate: variables.predicate,
38
+ resource: variables.resource,
39
+ resourceValue: "value",
40
+ },
41
+ })}))`,
42
+ };
43
+ }
44
+ graphqlResolveExpression({ variables, }) {
45
+ return variables.value;
46
+ }
22
47
  hashStatements({ variables, }) {
23
48
  return [`${variables.hasher}.update(${variables.value}.toString());`];
24
49
  }
25
- snippetDeclarations(features) {
50
+ snippetDeclarations({ features, }) {
26
51
  const snippetDeclarations = [];
27
52
  if (features.has("equals")) {
28
53
  snippetDeclarations.push(SnippetDeclarations.strictEquals);
29
54
  }
30
55
  return snippetDeclarations;
31
56
  }
57
+ sparqlWherePatterns(parameters) {
58
+ return super.sparqlWherePatterns({ ...parameters, ignoreLanguageIn: true });
59
+ }
32
60
  toJsonExpression({ variables, }) {
33
61
  return variables.value;
34
62
  }
35
- propertyFilterRdfResourceValuesExpression({ variables, }) {
36
- return variables.resourceValues;
37
- }
38
63
  }
64
+ __decorate([
65
+ Memoize()
66
+ ], PrimitiveType.prototype, "jsonName", null);
39
67
  //# sourceMappingURL=PrimitiveType.js.map
@@ -1,31 +1,35 @@
1
- import type { TsFeature } from "../../enums/index.js";
1
+ import { Maybe } from "purify-ts";
2
2
  import type { Import } from "./Import.js";
3
3
  import { Type } from "./Type.js";
4
- export declare class SetType extends Type {
5
- readonly itemType: Type;
6
- readonly kind = "SetType";
7
- private readonly minCount;
4
+ export declare class SetType<ItemTypeT extends Type> extends Type {
5
+ readonly discriminatorProperty: Maybe<Type.DiscriminatorProperty>;
6
+ readonly itemType: ItemTypeT;
8
7
  private readonly _mutable;
9
- constructor({ itemType, minCount, mutable, ...superParameters }: ConstructorParameters<typeof Type>[0] & {
10
- itemType: Type;
8
+ private readonly minCount;
9
+ readonly kind = "SetType";
10
+ readonly typeof = "object";
11
+ constructor({ itemType, minCount, mutable, }: {
12
+ itemType: ItemTypeT;
11
13
  mutable: boolean;
12
14
  minCount: number;
13
15
  });
14
16
  get conversions(): readonly Type.Conversion[];
15
17
  get equalsFunction(): string;
16
- get jsonName(): string;
18
+ get graphqlName(): Type.GraphqlName;
19
+ get jsonName(): Type.JsonName;
17
20
  get mutable(): boolean;
18
21
  get name(): string;
19
22
  fromJsonExpression({ variables, }: Parameters<Type["fromJsonExpression"]>[0]): string;
20
- fromRdfExpression({ variables, }: Parameters<Type["fromRdfExpression"]>[0]): string;
23
+ fromRdfExpression(parameters: Parameters<Type["fromRdfExpression"]>[0]): string;
24
+ graphqlResolveExpression({ variables, }: Parameters<Type["graphqlResolveExpression"]>[0]): string;
21
25
  hashStatements({ depth, variables, }: Parameters<Type["hashStatements"]>[0]): readonly string[];
22
26
  jsonUiSchemaElement(parameters: Parameters<Type["jsonUiSchemaElement"]>[0]): ReturnType<Type["jsonUiSchemaElement"]>;
23
27
  jsonZodSchema(parameters: Parameters<Type["jsonZodSchema"]>[0]): ReturnType<Type["jsonZodSchema"]>;
24
- snippetDeclarations(features: Set<TsFeature>): readonly string[];
25
- sparqlConstructTemplateTriples({ context, variables, }: Parameters<Type["sparqlConstructTemplateTriples"]>[0]): readonly string[];
26
- sparqlWherePatterns({ context, variables, }: Parameters<Type["sparqlWherePatterns"]>[0]): readonly string[];
28
+ snippetDeclarations(parameters: Parameters<Type["snippetDeclarations"]>[0]): readonly string[];
29
+ sparqlConstructTemplateTriples(parameters: Parameters<Type["sparqlConstructTemplateTriples"]>[0]): readonly string[];
30
+ sparqlWherePatterns(parameters: Parameters<Type["sparqlWherePatterns"]>[0]): readonly string[];
27
31
  toJsonExpression({ variables, }: Parameters<Type["toJsonExpression"]>[0]): string;
28
32
  toRdfExpression({ variables, }: Parameters<Type["toRdfExpression"]>[0]): string;
29
- useImports(features: Set<TsFeature>): readonly Import[];
33
+ useImports(parameters: Parameters<Type["useImports"]>[0]): readonly Import[];
30
34
  }
31
35
  //# sourceMappingURL=SetType.d.ts.map
@@ -4,18 +4,21 @@ 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 { Maybe } from "purify-ts";
7
8
  import { invariant } from "ts-invariant";
8
9
  import { Memoize } from "typescript-memoize";
9
10
  import { SnippetDeclarations } from "./SnippetDeclarations.js";
10
11
  import { Type } from "./Type.js";
11
- import { objectInitializer } from "./objectInitializer.js";
12
+ import { syntheticNamePrefix } from "./syntheticNamePrefix.js";
12
13
  export class SetType extends Type {
14
+ discriminatorProperty = Maybe.empty();
13
15
  itemType;
14
- kind = "SetType";
15
- minCount;
16
16
  _mutable;
17
- constructor({ itemType, minCount, mutable, ...superParameters }) {
18
- super(superParameters);
17
+ minCount;
18
+ kind = "SetType";
19
+ typeof = "object";
20
+ constructor({ itemType, minCount, mutable, }) {
21
+ super();
19
22
  this.itemType = itemType;
20
23
  this.minCount = minCount;
21
24
  invariant(this.minCount >= 0);
@@ -30,8 +33,11 @@ export class SetType extends Type {
30
33
  sourceTypeName: "undefined",
31
34
  });
32
35
  conversions.push({
33
- conversionExpression: (value) => value,
34
- sourceTypeCheckExpression: (value) => `Array.isArray(${value})`,
36
+ // Defensive copy
37
+ conversionExpression: (value) => `${value}${this.mutable ? ".concat()" : ""}`,
38
+ // Array.isArray doesn't narrow correctly
39
+ // sourceTypeCheckExpression: (value) => `Array.isArray(${value})`,
40
+ sourceTypeCheckExpression: (value) => `typeof ${value} === "object"`,
35
41
  sourceTypeName: `readonly (${this.itemType.name})[]`,
36
42
  });
37
43
  }
@@ -45,10 +51,17 @@ export class SetType extends Type {
45
51
  return conversions;
46
52
  }
47
53
  get equalsFunction() {
48
- return `((left, right) => arrayEquals(left, right, ${this.itemType.equalsFunction}))`;
54
+ return `((left, right) => ${syntheticNamePrefix}arrayEquals(left, right, ${this.itemType.equalsFunction}))`;
55
+ }
56
+ get graphqlName() {
57
+ return new Type.GraphqlName(`new graphql.GraphQLList(${this.itemType.graphqlName})`);
49
58
  }
50
59
  get jsonName() {
51
- return `readonly (${this.itemType.jsonName})[]`;
60
+ const name = `readonly (${this.itemType.jsonName})[]`;
61
+ if (this.minCount === 0) {
62
+ return new Type.JsonName(name, { optional: true });
63
+ }
64
+ return new Type.JsonName(name);
52
65
  }
53
66
  get mutable() {
54
67
  return this._mutable || this.itemType.mutable;
@@ -68,29 +81,35 @@ export class SetType extends Type {
68
81
  expression = `purify.NonEmptyList.fromArray(${expression}).unsafeCoerce()`;
69
82
  }
70
83
  const itemFromJsonExpression = this.itemType.fromJsonExpression({
71
- variables: { value: "_item" },
84
+ variables: { value: "item" },
72
85
  });
73
- return itemFromJsonExpression === "_item"
86
+ return itemFromJsonExpression === "item"
74
87
  ? expression
75
- : `${expression}.map(_item => (${itemFromJsonExpression}))`;
88
+ : `${expression}.map(item => (${itemFromJsonExpression}))`;
76
89
  }
77
- fromRdfExpression({ variables, }) {
78
- const itemFromRdfExpression = this.itemType.fromRdfExpression({
79
- variables: { ...variables, resourceValues: "_item.toValues()" },
80
- });
81
- if (this._mutable || this.minCount === 0) {
82
- return `purify.Either.of([...${variables.resourceValues}.flatMap(_item => ${itemFromRdfExpression}.toMaybe().toList())])`;
90
+ fromRdfExpression(parameters) {
91
+ const { variables } = parameters;
92
+ const chain = [this.itemType.fromRdfExpression(parameters)];
93
+ if (this.minCount === 0 || this._mutable) {
94
+ chain.push(`map(values => values.toArray()${this._mutable ? ".concat()" : ""})`);
95
+ }
96
+ else {
97
+ chain.push(`chain(values => purify.NonEmptyList.fromArray(values.toArray()).toEither(new Error(\`\${rdfjsResource.Resource.Identifier.toString(${variables.resource}.identifier)} is an empty set\`)))`);
83
98
  }
84
- return `purify.NonEmptyList.fromArray([...${variables.resourceValues}.flatMap(_item => ${itemFromRdfExpression}.toMaybe().toList())]).toEither(new rdfjsResource.Resource.ValueError(${objectInitializer({ focusResource: variables.resource, message: `\`\${rdfjsResource.Resource.Identifier.toString(${variables.resource}.identifier)} is empty\``, predicate: variables.predicate })}))`;
99
+ chain.push(`map(valuesArray => rdfjsResource.Resource.Values.fromValue({ object: valuesArray , predicate: ${variables.predicate}, subject: ${variables.resource} }))`);
100
+ return chain.join(".");
101
+ }
102
+ graphqlResolveExpression({ variables, }) {
103
+ return variables.value;
85
104
  }
86
105
  hashStatements({ depth, variables, }) {
87
106
  return [
88
- `for (const _item${depth} of ${variables.value}) { ${this.itemType
107
+ `for (const item${depth} of ${variables.value}) { ${this.itemType
89
108
  .hashStatements({
90
109
  depth: depth + 1,
91
110
  variables: {
92
111
  hasher: variables.hasher,
93
- value: `_item${depth}`,
112
+ value: `item${depth}`,
94
113
  },
95
114
  })
96
115
  .join("\n")} }`,
@@ -104,32 +123,32 @@ export class SetType extends Type {
104
123
  if (this.minCount > 0) {
105
124
  schema = `${schema}.nonempty().min(${this.minCount})`;
106
125
  }
126
+ else {
127
+ schema = `${schema}.default(() => [])`;
128
+ }
107
129
  return schema;
108
130
  }
109
- snippetDeclarations(features) {
131
+ snippetDeclarations(parameters) {
110
132
  const snippetDeclarations = this.itemType
111
- .snippetDeclarations(features)
133
+ .snippetDeclarations(parameters)
112
134
  .concat();
113
- if (features.has("equals")) {
135
+ if (parameters.features.has("equals")) {
114
136
  snippetDeclarations.push(SnippetDeclarations.arrayEquals);
115
137
  }
116
138
  return snippetDeclarations;
117
139
  }
118
- sparqlConstructTemplateTriples({ context, variables, }) {
119
- switch (context) {
120
- case "property":
121
- return super.sparqlConstructTemplateTriples({ context, variables });
122
- case "type":
123
- return this.itemType.sparqlConstructTemplateTriples({
124
- context,
125
- variables,
126
- });
140
+ sparqlConstructTemplateTriples(parameters) {
141
+ switch (parameters.context) {
142
+ case "object":
143
+ return super.sparqlConstructTemplateTriples(parameters);
144
+ case "subject":
145
+ return this.itemType.sparqlConstructTemplateTriples(parameters);
127
146
  }
128
147
  }
129
- sparqlWherePatterns({ context, variables, }) {
130
- switch (context) {
131
- case "property": {
132
- const patterns = super.sparqlWherePatterns({ context, variables });
148
+ sparqlWherePatterns(parameters) {
149
+ switch (parameters.context) {
150
+ case "object": {
151
+ const patterns = this.itemType.sparqlWherePatterns(parameters);
133
152
  if (patterns.length === 0) {
134
153
  return [];
135
154
  }
@@ -137,23 +156,36 @@ export class SetType extends Type {
137
156
  ? patterns
138
157
  : [`{ patterns: [${patterns.join(", ")}], type: "optional" }`];
139
158
  }
140
- case "type": {
141
- return this.itemType.sparqlWherePatterns({ context, variables });
159
+ case "subject": {
160
+ throw new Error("should never be called");
161
+ // return this.itemType.sparqlWherePatterns(parameters);
142
162
  }
143
163
  }
144
164
  }
145
165
  toJsonExpression({ variables, }) {
146
- return `${variables.value}.map(_item => (${this.itemType.toJsonExpression({ variables: { value: "_item" } })}))`;
166
+ return `${variables.value}.map(item => (${this.itemType.toJsonExpression({ variables: { value: "item" } })}))`;
147
167
  }
148
168
  toRdfExpression({ variables, }) {
149
- return `${variables.value}.map((_item) => ${this.itemType.toRdfExpression({
150
- variables: { ...variables, value: "_item" },
169
+ return `${variables.value}.map((item) => ${this.itemType.toRdfExpression({
170
+ variables: { ...variables, value: "item" },
151
171
  })})`;
152
172
  }
153
- useImports(features) {
154
- return this.itemType.useImports(features);
173
+ useImports(parameters) {
174
+ return this.itemType.useImports(parameters);
155
175
  }
156
176
  }
177
+ __decorate([
178
+ Memoize()
179
+ ], SetType.prototype, "conversions", null);
180
+ __decorate([
181
+ Memoize()
182
+ ], SetType.prototype, "equalsFunction", null);
183
+ __decorate([
184
+ Memoize()
185
+ ], SetType.prototype, "graphqlName", null);
186
+ __decorate([
187
+ Memoize()
188
+ ], SetType.prototype, "jsonName", null);
157
189
  __decorate([
158
190
  Memoize()
159
191
  ], SetType.prototype, "name", null);
@@ -1,11 +1,16 @@
1
1
  export declare namespace SnippetDeclarations {
2
- const arrayEquals = "export function arrayEquals<T>(\n leftArray: readonly T[],\n rightArray: readonly T[],\n elementEquals: (left: T, right: T) => boolean | EqualsResult,\n): EqualsResult {\n if (leftArray.length !== rightArray.length) {\n return purify.Left({\n left: leftArray,\n right: rightArray,\n type: \"ArrayLength\",\n });\n }\n\n for (\n let leftElementIndex = 0;\n leftElementIndex < leftArray.length;\n leftElementIndex++\n ) {\n const leftElement = leftArray[leftElementIndex];\n\n const rightUnequals: EqualsResult.Unequal[] = [];\n for (\n let rightElementIndex = 0;\n rightElementIndex < rightArray.length;\n rightElementIndex++\n ) {\n const rightElement = rightArray[rightElementIndex];\n\n const leftElementEqualsRightElement =\n EqualsResult.fromBooleanEqualsResult(\n leftElement,\n rightElement,\n elementEquals(leftElement, rightElement),\n );\n if (leftElementEqualsRightElement.isRight()) {\n break; // left element === right element, break out of the right iteration\n }\n rightUnequals.push(\n leftElementEqualsRightElement.extract() as EqualsResult.Unequal,\n );\n }\n\n if (rightUnequals.length === rightArray.length) {\n // All right elements were unequal to the left element\n return purify.Left({\n left: {\n array: leftArray,\n element: leftElement,\n elementIndex: leftElementIndex,\n },\n right: {\n array: rightArray,\n unequals: rightUnequals,\n },\n type: \"ArrayElement\",\n });\n }\n // Else there was a right element equal to the left element, continue to the next left element\n }\n\n return EqualsResult.Equal;\n}\n";
3
- const booleanEquals = "/**\n * Compare two objects with equals(other: T): boolean methods and return an EqualsResult.\n */\nexport function booleanEquals<T extends { equals: (other: T) => boolean }>(\n left: T,\n right: T,\n): EqualsResult {\n return EqualsResult.fromBooleanEqualsResult(\n left,\n right,\n left.equals(right),\n );\n}";
4
- const dateEquals = "/**\n * Compare two Dates and return an EqualsResult.\n */\nexport function dateEquals(left: Date, right: Date): EqualsResult {\n return EqualsResult.fromBooleanEqualsResult(\n left,\n right,\n left.getTime() === right.getTime(),\n );\n}";
5
- const EqualsResult = "export type EqualsResult = purify.Either<EqualsResult.Unequal, true>;\n\nexport namespace EqualsResult {\n export const Equal: EqualsResult = purify.Either.of<Unequal, true>(true);\n\n export function fromBooleanEqualsResult(\n left: any,\n right: any,\n equalsResult: boolean | EqualsResult,\n ): EqualsResult {\n if (typeof equalsResult !== \"boolean\") {\n return equalsResult;\n }\n\n if (equalsResult) {\n return Equal;\n }\n return purify.Left({\n left,\n right,\n type: \"BooleanEquals\",\n });\n }\n\n export type Unequal =\n | {\n readonly left: {\n readonly array: readonly any[];\n readonly element: any;\n readonly elementIndex: number;\n };\n readonly right: {\n readonly array: readonly any[];\n readonly unequals: readonly Unequal[];\n };\n readonly type: \"ArrayElement\";\n }\n | {\n readonly left: readonly any[];\n readonly right: readonly any[];\n readonly type: \"ArrayLength\";\n }\n | {\n readonly left: any;\n readonly right: any;\n readonly type: \"BooleanEquals\";\n }\n | {\n readonly left: any;\n readonly right: any;\n readonly type: \"LeftError\";\n }\n | {\n readonly right: any;\n readonly type: \"LeftNull\";\n }\n | {\n readonly left: bigint | boolean | number | string;\n readonly right: bigint | boolean | number | string;\n readonly type: \"Primitive\";\n }\n | {\n readonly left: object;\n readonly right: object;\n readonly propertyName: string;\n readonly propertyValuesUnequal: Unequal;\n readonly type: \"Property\";\n }\n | {\n readonly left: any;\n readonly right: any;\n readonly type: \"RightError\";\n }\n | {\n readonly left: any;\n readonly type: \"RightNull\";\n };\n} \n";
6
- const maybeEquals = "export function maybeEquals<T>(\n leftMaybe: purify.Maybe<T>,\n rightMaybe: purify.Maybe<T>,\n valueEquals: (left: T, right: T) => boolean | EqualsResult,\n): EqualsResult {\n if (leftMaybe.isJust()) {\n if (rightMaybe.isJust()) {\n return EqualsResult.fromBooleanEqualsResult(\n leftMaybe,\n rightMaybe,\n valueEquals(leftMaybe.unsafeCoerce(), rightMaybe.unsafeCoerce()),\n );\n }\n return purify.Left({\n left: leftMaybe.unsafeCoerce(),\n type: \"RightNull\",\n });\n }\n\n if (rightMaybe.isJust()) {\n return purify.Left({\n right: rightMaybe.unsafeCoerce(),\n type: \"LeftNull\",\n });\n }\n\n return EqualsResult.Equal;\n}\n";
7
- const strictEquals = "/**\n * Compare two values for strict equality (===), returning an EqualsResult rather than a boolean.\n */\nexport function strictEquals<T extends bigint | boolean | number | string>(\n left: T,\n right: T,\n): EqualsResult {\n return EqualsResult.fromBooleanEqualsResult(left, right, left === right);\n}";
8
- const UnwrapL = "type UnwrapL<T> = T extends purify.Either<infer L, any> ? L : never";
9
- const UnwrapR = "type UnwrapR<T> = T extends purify.Either<any, infer R> ? R : never";
2
+ const arrayEquals = "/**\n * Compare two arrays element-wise with the provided elementEquals function.\n */ \nexport function $arrayEquals<T>(\n leftArray: readonly T[],\n rightArray: readonly T[],\n elementEquals: (left: T, right: T) => boolean | $EqualsResult,\n): $EqualsResult {\n if (leftArray.length !== rightArray.length) {\n return purify.Left({\n left: leftArray,\n right: rightArray,\n type: \"ArrayLength\",\n });\n }\n\n for (\n let leftElementIndex = 0;\n leftElementIndex < leftArray.length;\n leftElementIndex++\n ) {\n const leftElement = leftArray[leftElementIndex];\n\n const rightUnequals: $EqualsResult.Unequal[] = [];\n for (\n let rightElementIndex = 0;\n rightElementIndex < rightArray.length;\n rightElementIndex++\n ) {\n const rightElement = rightArray[rightElementIndex];\n\n const leftElementEqualsRightElement =\n $EqualsResult.fromBooleanEqualsResult(\n leftElement,\n rightElement,\n elementEquals(leftElement, rightElement),\n );\n if (leftElementEqualsRightElement.isRight()) {\n break; // left element === right element, break out of the right iteration\n }\n rightUnequals.push(\n leftElementEqualsRightElement.extract() as $EqualsResult.Unequal,\n );\n }\n\n if (rightUnequals.length === rightArray.length) {\n // All right elements were unequal to the left element\n return purify.Left({\n left: {\n array: leftArray,\n element: leftElement,\n elementIndex: leftElementIndex,\n },\n right: {\n array: rightArray,\n unequals: rightUnequals,\n },\n type: \"ArrayElement\",\n });\n }\n // Else there was a right element equal to the left element, continue to the next left element\n }\n\n return $EqualsResult.Equal;\n}\n";
3
+ const booleanEquals = "/**\n * Compare two objects with equals(other: T): boolean methods and return an $EqualsResult.\n */\nexport function $booleanEquals<T extends { equals: (other: T) => boolean }>(\n left: T,\n right: T,\n): $EqualsResult {\n return $EqualsResult.fromBooleanEqualsResult(\n left,\n right,\n left.equals(right),\n );\n}";
4
+ const dateEquals = "/**\n * Compare two Dates and return an $EqualsResult.\n */\nexport function $dateEquals(left: Date, right: Date): $EqualsResult {\n return $EqualsResult.fromBooleanEqualsResult(\n left,\n right,\n left.getTime() === right.getTime(),\n );\n}";
5
+ const EqualsResult = "export type $EqualsResult = purify.Either<$EqualsResult.Unequal, true>;\n\nexport namespace $EqualsResult {\n export const Equal: $EqualsResult = purify.Either.of<Unequal, true>(true);\n\n export function fromBooleanEqualsResult(\n left: any,\n right: any,\n equalsResult: boolean | $EqualsResult,\n ): $EqualsResult {\n if (typeof equalsResult !== \"boolean\") {\n return equalsResult;\n }\n\n if (equalsResult) {\n return Equal;\n }\n\n return purify.Left({ left, right, type: \"BooleanEquals\" });\n }\n\n export type Unequal =\n | {\n readonly left: {\n readonly array: readonly any[];\n readonly element: any;\n readonly elementIndex: number;\n };\n readonly right: {\n readonly array: readonly any[];\n readonly unequals: readonly Unequal[];\n };\n readonly type: \"ArrayElement\";\n }\n | {\n readonly left: readonly any[];\n readonly right: readonly any[];\n readonly type: \"ArrayLength\";\n }\n | {\n readonly left: any;\n readonly right: any;\n readonly type: \"BooleanEquals\";\n }\n | {\n readonly left: any;\n readonly right: any;\n readonly type: \"LeftError\";\n }\n | {\n readonly right: any;\n readonly type: \"LeftNull\";\n }\n | {\n readonly left: bigint | boolean | number | string;\n readonly right: bigint | boolean | number | string;\n readonly type: \"Primitive\";\n }\n | {\n readonly left: any;\n readonly right: any;\n readonly propertyName: string;\n readonly propertyValuesUnequal: Unequal;\n readonly type: \"Property\";\n }\n | {\n readonly left: any;\n readonly right: any;\n readonly type: \"RightError\";\n }\n | {\n readonly left: any;\n readonly type: \"RightNull\";\n };\n} \n";
6
+ const maybeEquals = "export function $maybeEquals<T>(\n leftMaybe: purify.Maybe<T>,\n rightMaybe: purify.Maybe<T>,\n valueEquals: (left: T, right: T) => boolean | $EqualsResult,\n): $EqualsResult {\n if (leftMaybe.isJust()) {\n if (rightMaybe.isJust()) {\n return $EqualsResult.fromBooleanEqualsResult(\n leftMaybe,\n rightMaybe,\n valueEquals(leftMaybe.unsafeCoerce(), rightMaybe.unsafeCoerce()),\n );\n }\n return purify.Left({\n left: leftMaybe.unsafeCoerce(),\n type: \"RightNull\",\n });\n }\n\n if (rightMaybe.isJust()) {\n return purify.Left({\n right: rightMaybe.unsafeCoerce(),\n type: \"LeftNull\",\n });\n }\n\n return $EqualsResult.Equal;\n}";
7
+ const LazyObjectSet = "/**\n * Type of lazy properties that return a set of objects. This is a class instead of an interface so it can be instanceof'd elsewhere.\n */\nexport class $LazyObjectSet<ObjectIdentifierT extends rdfjs.BlankNode | rdfjs.NamedNode, ResolvedObjectT extends { $identifier: ObjectIdentifierT }, StubObjectT extends { $identifier: ObjectIdentifierT }> {\n private readonly resolver: (identifiers: readonly ObjectIdentifierT[]) => Promise<purify.Either<Error, readonly ResolvedObjectT[]>>;\n readonly stubs: readonly StubObjectT[];\n\n constructor({ resolver, stubs }: {\n resolver: (identifiers: readonly ObjectIdentifierT[]) => Promise<purify.Either<Error, readonly ResolvedObjectT[]>>,\n stubs: readonly StubObjectT[]\n }) {\n this.resolver = resolver;\n this.stubs = stubs;\n }\n\n async resolve(options?: { limit?: number; offset?: number }): Promise<purify.Either<Error, readonly ResolvedObjectT[]>> {\n if (this.stubs.length === 0) {\n return purify.Either.of([]);\n }\n\n const limit = options?.limit ?? Number.MAX_SAFE_INTEGER;\n if (limit <= 0) {\n return purify.Either.of([]);\n }\n\n let offset = options?.offset ?? 0;\n if (offset < 0) {\n offset = 0;\n }\n\n return await this.resolver(this.stubs.slice(offset, offset + limit).map(stub => stub.$identifier));\n }\n}";
8
+ const LazyOptionalObject = "/**\n * Type of lazy properties that return a single optional object. This is a class instead of an interface so it can be instanceof'd elsewhere.\n */\nexport class $LazyOptionalObject<ObjectIdentifierT extends rdfjs.BlankNode | rdfjs.NamedNode, ResolvedObjectT extends { $identifier: ObjectIdentifierT }, StubObjectT extends { $identifier: ObjectIdentifierT }> {\n private readonly resolver: (identifier: ObjectIdentifierT) => Promise<purify.Either<Error, ResolvedObjectT>>;\n readonly stub: purify.Maybe<StubObjectT>;\n\n constructor({ resolver, stub }: {\n resolver: (identifier: ObjectIdentifierT) => Promise<purify.Either<Error, ResolvedObjectT>>,\n stub: purify.Maybe<StubObjectT>\n }) {\n this.resolver = resolver;\n this.stub = stub;\n }\n\n async resolve(): Promise<purify.Either<Error, purify.Maybe<ResolvedObjectT>>> {\n if (this.stub.isNothing()) {\n return purify.Either.of(purify.Maybe.empty());\n }\n return (await this.resolver(this.stub.unsafeCoerce().$identifier)).map(purify.Maybe.of);\n }\n}";
9
+ const LazyRequiredObject = "/**\n * Type of lazy properties that return a single required object. This is a class instead of an interface so it can be instanceof'd elsewhere.\n */\nexport class $LazyRequiredObject<ObjectIdentifierT extends rdfjs.BlankNode | rdfjs.NamedNode, ResolvedObjectT extends { $identifier: ObjectIdentifierT }, StubObjectT extends { $identifier: ObjectIdentifierT }> {\n private readonly resolver: (identifier: ObjectIdentifierT) => Promise<purify.Either<Error, ResolvedObjectT>>;\n readonly stub: StubObjectT;\n\n constructor({ resolver, stub }: {\n resolver: (identifier: ObjectIdentifierT) => Promise<purify.Either<Error, ResolvedObjectT>>,\n stub: StubObjectT\n }) {\n this.resolver = resolver;\n this.stub = stub;\n }\n\n resolve(): Promise<purify.Either<Error, ResolvedObjectT>> {\n return this.resolver(this.stub.$identifier);\n }\n}";
10
+ const RdfVocabularies = "export namespace $RdfVocabularies {\n export namespace rdf {\n export const first = dataFactory.namedNode(\"http://www.w3.org/1999/02/22-rdf-syntax-ns#first\");\n export const nil = dataFactory.namedNode(\"http://www.w3.org/1999/02/22-rdf-syntax-ns#nil\");\n export const rest = dataFactory.namedNode(\"http://www.w3.org/1999/02/22-rdf-syntax-ns#rest\");\n export const subject = dataFactory.namedNode(\"http://www.w3.org/1999/02/22-rdf-syntax-ns#subject\");\n export const type = dataFactory.namedNode(\"http://www.w3.org/1999/02/22-rdf-syntax-ns#type\");\n }\n\n export namespace rdfs {\n export const subClassOf = dataFactory.namedNode(\"http://www.w3.org/2000/01/rdf-schema#subClassOf\");\n }\n\n export namespace xsd {\n export const boolean = dataFactory.namedNode(\"http://www.w3.org/2001/XMLSchema#boolean\");\n export const date = dataFactory.namedNode(\"http://www.w3.org/2001/XMLSchema#date\");\n export const dateTime = dataFactory.namedNode(\"http://www.w3.org/2001/XMLSchema#dateTime\");\n export const integer = dataFactory.namedNode(\"http://www.w3.org/2001/XMLSchema#integer\");\n }\n}";
11
+ const sparqlInstancesOfPattern = "/**\n * A sparqljs.Pattern that's the equivalent of ?subject rdf:type/rdfs:subClassOf* ?rdfType .\n */\nexport function $sparqlInstancesOfPattern({ rdfType, subject }: { rdfType: rdfjs.NamedNode, subject: sparqljs.Triple[\"subject\"] }): sparqljs.Pattern {\n return {\n triples: [\n {\n subject,\n predicate: {\n items: [\n $RdfVocabularies.rdf.type,\n {\n items: [$RdfVocabularies.rdfs.subClassOf],\n pathType: \"*\",\n type: \"path\",\n },\n ],\n pathType: \"/\",\n type: \"path\",\n },\n object: rdfType,\n },\n ],\n type: \"bgp\",\n };\n}";
12
+ const strictEquals = "/**\n * Compare two values for strict equality (===), returning an $EqualsResult rather than a boolean.\n */\nexport function $strictEquals<T extends bigint | boolean | number | string>(\n left: T,\n right: T,\n): $EqualsResult {\n return $EqualsResult.fromBooleanEqualsResult(left, right, left === right);\n}";
13
+ const UnwrapL = "type $UnwrapL<T> = T extends purify.Either<infer L, any> ? L : never";
14
+ const UnwrapR = "type $UnwrapR<T> = T extends purify.Either<any, infer R> ? R : never";
10
15
  }
11
16
  //# sourceMappingURL=SnippetDeclarations.d.ts.map