@shaclmate/compiler 2.0.20 → 2.0.23

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 (172) hide show
  1. package/dist/ShapesGraphToAstTransformer.d.ts +1 -0
  2. package/dist/ShapesGraphToAstTransformer.js +56 -12
  3. package/dist/_ShapesGraphToAstTransformer/flattenAstObjectCompositeTypeMemberTypes.d.ts +13 -0
  4. package/dist/_ShapesGraphToAstTransformer/flattenAstObjectCompositeTypeMemberTypes.js +51 -0
  5. package/dist/_ShapesGraphToAstTransformer/shapeAstName.js +53 -12
  6. package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.d.ts +5 -0
  7. package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.js +130 -54
  8. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.d.ts +2 -3
  9. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +122 -129
  10. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.d.ts +2 -2
  11. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.d.ts +2 -2
  12. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +127 -5
  13. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.d.ts +3 -3
  14. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.d.ts +2 -3
  15. package/dist/ast/Ast.d.ts +0 -1
  16. package/dist/ast/Curie.d.ts +14 -0
  17. package/dist/ast/Curie.js +21 -0
  18. package/dist/ast/IdentifierType.d.ts +3 -2
  19. package/dist/ast/ListType.d.ts +2 -1
  20. package/dist/ast/LiteralType.d.ts +1 -1
  21. package/dist/ast/Name.d.ts +40 -5
  22. package/dist/ast/ObjectCompositeType.d.ts +11 -0
  23. package/dist/ast/ObjectType.d.ts +18 -13
  24. package/dist/ast/ObjectUnionType.d.ts +0 -11
  25. package/dist/ast/OptionType.d.ts +2 -2
  26. package/dist/ast/SetType.d.ts +2 -2
  27. package/dist/ast/TermType.d.ts +12 -4
  28. package/dist/ast/Type.d.ts +1 -1
  29. package/dist/enums/TsFeature.d.ts +1 -4
  30. package/dist/enums/TsFeature.js +1 -15
  31. package/dist/generators/json/AstJsonGenerator.js +19 -3
  32. package/dist/generators/ts/BooleanType.d.ts +3 -1
  33. package/dist/generators/ts/BooleanType.js +11 -2
  34. package/dist/generators/ts/DateTimeType.d.ts +8 -7
  35. package/dist/generators/ts/DateTimeType.js +31 -7
  36. package/dist/generators/ts/DateType.d.ts +5 -2
  37. package/dist/generators/ts/DateType.js +15 -1
  38. package/dist/generators/ts/DeclaredType.d.ts +2 -2
  39. package/dist/generators/ts/DeclaredType.js +2 -2
  40. package/dist/generators/ts/FloatType.d.ts +6 -0
  41. package/dist/generators/ts/FloatType.js +18 -0
  42. package/dist/generators/ts/IdentifierType.d.ts +12 -7
  43. package/dist/generators/ts/IdentifierType.js +94 -6
  44. package/dist/generators/ts/Import.d.ts +2 -0
  45. package/dist/generators/ts/Import.js +10 -0
  46. package/dist/generators/ts/IntType.d.ts +6 -0
  47. package/dist/generators/ts/IntType.js +18 -0
  48. package/dist/generators/ts/ListType.d.ts +15 -12
  49. package/dist/generators/ts/ListType.js +98 -57
  50. package/dist/generators/ts/LiteralType.d.ts +10 -9
  51. package/dist/generators/ts/LiteralType.js +13 -2
  52. package/dist/generators/ts/NumberType.d.ts +2 -1
  53. package/dist/generators/ts/NumberType.js +7 -2
  54. package/dist/generators/ts/ObjectType.d.ts +66 -43
  55. package/dist/generators/ts/ObjectType.js +144 -123
  56. package/dist/generators/ts/ObjectUnionType.d.ts +49 -8
  57. package/dist/generators/ts/ObjectUnionType.js +290 -97
  58. package/dist/generators/ts/OptionType.d.ts +14 -10
  59. package/dist/generators/ts/OptionType.js +60 -34
  60. package/dist/generators/ts/PrimitiveType.d.ts +4 -4
  61. package/dist/generators/ts/PrimitiveType.js +18 -3
  62. package/dist/generators/ts/SetType.d.ts +16 -12
  63. package/dist/generators/ts/SetType.js +69 -40
  64. package/dist/generators/ts/SnippetDeclarations.d.ts +13 -8
  65. package/dist/generators/ts/SnippetDeclarations.js +215 -101
  66. package/dist/generators/ts/StringType.d.ts +3 -1
  67. package/dist/generators/ts/StringType.js +14 -2
  68. package/dist/generators/ts/TermType.d.ts +22 -14
  69. package/dist/generators/ts/TermType.js +53 -25
  70. package/dist/generators/ts/TsGenerator.d.ts +2 -1
  71. package/dist/generators/ts/TsGenerator.js +23 -12
  72. package/dist/generators/ts/Type.d.ts +89 -31
  73. package/dist/generators/ts/Type.js +57 -54
  74. package/dist/generators/ts/TypeFactory.d.ts +4 -5
  75. package/dist/generators/ts/TypeFactory.js +290 -226
  76. package/dist/generators/ts/UnionType.d.ts +14 -10
  77. package/dist/generators/ts/UnionType.js +319 -142
  78. package/dist/generators/ts/_ObjectType/EagerShaclProperty.d.ts +12 -0
  79. package/dist/generators/ts/_ObjectType/EagerShaclProperty.js +30 -0
  80. package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.d.ts +13 -12
  81. package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.js +46 -47
  82. package/dist/generators/ts/_ObjectType/IdentifierProperty.d.ts +20 -13
  83. package/dist/generators/ts/_ObjectType/IdentifierProperty.js +152 -124
  84. package/dist/generators/ts/_ObjectType/LazyShaclProperty.d.ts +87 -0
  85. package/dist/generators/ts/_ObjectType/LazyShaclProperty.js +237 -0
  86. package/dist/generators/ts/_ObjectType/Property.d.ts +39 -44
  87. package/dist/generators/ts/_ObjectType/Property.js +1 -10
  88. package/dist/generators/ts/_ObjectType/ShaclProperty.d.ts +25 -30
  89. package/dist/generators/ts/_ObjectType/ShaclProperty.js +108 -85
  90. package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +21 -17
  91. package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +61 -53
  92. package/dist/generators/ts/_ObjectType/classDeclaration.js +6 -5
  93. package/dist/generators/ts/_ObjectType/createFunctionDeclaration.js +5 -4
  94. package/dist/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.js +5 -4
  95. package/dist/generators/ts/_ObjectType/fromRdfTypeVariableStatement.d.ts +1 -1
  96. package/dist/generators/ts/_ObjectType/fromRdfTypeVariableStatement.js +8 -5
  97. package/dist/generators/ts/_ObjectType/graphqlTypeVariableStatement.d.ts +5 -0
  98. package/dist/generators/ts/_ObjectType/graphqlTypeVariableStatement.js +37 -0
  99. package/dist/generators/ts/_ObjectType/hashFunctionOrMethodDeclarations.js +7 -8
  100. package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.d.ts +7 -0
  101. package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.js +54 -0
  102. package/dist/generators/ts/_ObjectType/index.d.ts +9 -7
  103. package/dist/generators/ts/_ObjectType/index.js +9 -7
  104. package/dist/generators/ts/_ObjectType/interfaceDeclaration.js +1 -1
  105. package/dist/generators/ts/_ObjectType/jsonFunctionDeclarations.d.ts +4 -0
  106. package/dist/generators/ts/_ObjectType/jsonFunctionDeclarations.js +189 -0
  107. package/dist/generators/ts/_ObjectType/jsonTypeAliasDeclaration.d.ts +5 -0
  108. package/dist/generators/ts/_ObjectType/jsonTypeAliasDeclaration.js +28 -0
  109. package/dist/generators/ts/_ObjectType/objectSetMethodNames.d.ts +9 -0
  110. package/dist/generators/ts/_ObjectType/objectSetMethodNames.js +18 -0
  111. package/dist/generators/ts/_ObjectType/propertiesVariableStatement.d.ts +5 -0
  112. package/dist/generators/ts/_ObjectType/propertiesVariableStatement.js +37 -0
  113. package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.d.ts +4 -0
  114. package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.js +152 -0
  115. package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.d.ts +1 -1
  116. package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.js +4 -3
  117. package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.d.ts +1 -1
  118. package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.js +3 -2
  119. package/dist/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +103 -35
  120. package/dist/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.js +6 -6
  121. package/dist/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.js +15 -13
  122. package/dist/generators/ts/graphqlSchemaVariableStatement.d.ts +9 -0
  123. package/dist/generators/ts/graphqlSchemaVariableStatement.js +86 -0
  124. package/dist/generators/ts/objectSetDeclarations.d.ts +8 -0
  125. package/dist/generators/ts/objectSetDeclarations.js +59 -0
  126. package/dist/generators/ts/objectSetInterfaceDeclaration.d.ts +8 -0
  127. package/dist/generators/ts/objectSetInterfaceDeclaration.js +46 -0
  128. package/dist/generators/ts/objectSetMethodSignatures.d.ts +11 -0
  129. package/dist/generators/ts/objectSetMethodSignatures.js +52 -0
  130. package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.d.ts +8 -0
  131. package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +393 -0
  132. package/dist/generators/ts/rdfjsTermExpression.d.ts +3 -0
  133. package/dist/generators/ts/rdfjsTermExpression.js +57 -0
  134. package/dist/generators/ts/sparqlObjectSetClassDeclaration.d.ts +8 -0
  135. package/dist/generators/ts/sparqlObjectSetClassDeclaration.js +415 -0
  136. package/dist/generators/ts/syntheticNamePrefix.d.ts +2 -0
  137. package/dist/generators/ts/syntheticNamePrefix.js +2 -0
  138. package/dist/generators/ts/tsName.js +27 -13
  139. package/dist/generators/ts/unsupportedObjectSetMethodDeclarations.d.ts +10 -0
  140. package/dist/generators/ts/unsupportedObjectSetMethodDeclarations.js +19 -0
  141. package/dist/input/NodeShape.d.ts +6 -8
  142. package/dist/input/NodeShape.js +20 -44
  143. package/dist/input/Ontology.d.ts +0 -3
  144. package/dist/input/Ontology.js +0 -9
  145. package/dist/input/PropertyPath.d.ts +6 -5
  146. package/dist/input/PropertyPath.js +14 -22
  147. package/dist/input/PropertyShape.d.ts +3 -1
  148. package/dist/input/PropertyShape.js +8 -2
  149. package/dist/input/ShapesGraph.js +4 -4
  150. package/dist/input/generated.d.ts +923 -105
  151. package/dist/input/generated.js +1865 -969
  152. package/dist/input/tsFeatures.d.ts +3 -2
  153. package/dist/input/tsFeatures.js +44 -27
  154. package/package.json +18 -16
  155. package/dist/generators/ts/_ObjectType/fromJsonFunctionDeclarations.d.ts +0 -4
  156. package/dist/generators/ts/_ObjectType/fromJsonFunctionDeclarations.js +0 -78
  157. package/dist/generators/ts/_ObjectType/fromRdfFunctionDeclarations.d.ts +0 -4
  158. package/dist/generators/ts/_ObjectType/fromRdfFunctionDeclarations.js +0 -91
  159. package/dist/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.d.ts +0 -5
  160. package/dist/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.js +0 -19
  161. package/dist/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.d.ts +0 -5
  162. package/dist/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.js +0 -31
  163. package/dist/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.d.ts +0 -5
  164. package/dist/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.js +0 -37
  165. package/dist/generators/ts/_ObjectType/rdfjsTermExpression.d.ts +0 -6
  166. package/dist/generators/ts/_ObjectType/rdfjsTermExpression.js +0 -17
  167. package/dist/generators/ts/_ObjectType/toJsonFunctionDeclaration.d.ts +0 -5
  168. package/dist/generators/ts/_ObjectType/toJsonFunctionDeclaration.js +0 -19
  169. package/dist/generators/ts/_ObjectType/toJsonReturnType.d.ts +0 -3
  170. package/dist/generators/ts/_ObjectType/toJsonReturnType.js +0 -17
  171. package/dist/generators/ts/_ObjectType/toRdfFunctionDeclaration.d.ts +0 -5
  172. 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 = 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
@@ -4,15 +4,20 @@ 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 { Memoize } from "typescript-memoize";
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,26 @@ 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
+ return `${this.itemType.fromRdfExpression(parameters)}.map(value => purify.Maybe.of(value)).chainLeft(error => error instanceof rdfjsResource.Resource.MissingValueError ? purify.Right(purify.Maybe.empty()) : purify.Left(error))`;
77
+ }
78
+ graphqlResolveExpression(parameters) {
79
+ return `${this.itemType.graphqlResolveExpression(parameters)}.extractNullable()`;
63
80
  }
64
81
  hashStatements({ depth, variables, }) {
65
82
  return [
66
- `${variables.value}.ifJust((_value${depth}) => { ${this.itemType
83
+ `${variables.value}.ifJust((value${depth}) => { ${this.itemType
67
84
  .hashStatements({
68
85
  depth: depth + 1,
69
86
  variables: {
70
87
  hasher: variables.hasher,
71
- value: `_value${depth}`,
88
+ value: `value${depth}`,
72
89
  },
73
90
  })
74
91
  .join("\n")} })`,
@@ -80,56 +97,65 @@ export class OptionType extends Type {
80
97
  jsonZodSchema(parameters) {
81
98
  return `${this.itemType.jsonZodSchema(parameters)}.optional()`;
82
99
  }
83
- snippetDeclarations(features) {
100
+ snippetDeclarations(parameters) {
84
101
  const snippetDeclarations = this.itemType
85
- .snippetDeclarations(features)
102
+ .snippetDeclarations(parameters)
86
103
  .concat();
87
- if (features.has("equals")) {
104
+ if (parameters.features.has("equals")) {
88
105
  snippetDeclarations.push(SnippetDeclarations.maybeEquals);
89
106
  }
90
107
  return snippetDeclarations;
91
108
  }
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
- });
109
+ sparqlConstructTemplateTriples(parameters) {
110
+ switch (parameters.context) {
111
+ case "object":
112
+ return super.sparqlConstructTemplateTriples(parameters);
113
+ case "subject":
114
+ return this.itemType.sparqlConstructTemplateTriples(parameters);
101
115
  }
102
116
  }
103
- sparqlWherePatterns({ context, variables, }) {
104
- switch (context) {
105
- case "property": {
106
- const patterns = super.sparqlWherePatterns({ context, variables });
117
+ sparqlWherePatterns(parameters) {
118
+ switch (parameters.context) {
119
+ case "object": {
120
+ const patterns = super.sparqlWherePatterns(parameters);
107
121
  if (patterns.length === 0) {
108
122
  return [];
109
123
  }
110
124
  return [`{ patterns: [${patterns.join(", ")}], type: "optional" }`];
111
125
  }
112
- case "type": {
113
- return this.itemType.sparqlWherePatterns({ context, variables });
126
+ case "subject": {
127
+ return this.itemType.sparqlWherePatterns(parameters);
114
128
  }
115
129
  }
116
130
  }
117
131
  toJsonExpression({ variables, }) {
118
- return `${variables.value}.map(_item => (${this.itemType.toJsonExpression({ variables: { value: "_item" } })})).extract()`;
132
+ return `${variables.value}.map(item => (${this.itemType.toJsonExpression({ variables: { value: "item" } })})).extract()`;
119
133
  }
120
134
  toRdfExpression({ variables, }) {
121
135
  const itemTypeToRdfExpression = this.itemType.toRdfExpression({
122
- variables: { ...variables, value: "_value" },
136
+ variables: { ...variables, value: "value" },
123
137
  });
124
- if (itemTypeToRdfExpression === "_value") {
138
+ if (itemTypeToRdfExpression === "value") {
125
139
  return variables.value;
126
140
  }
127
- return `${variables.value}.map((_value) => ${itemTypeToRdfExpression})`;
141
+ return `${variables.value}.map((value) => ${itemTypeToRdfExpression})`;
128
142
  }
129
- useImports(features) {
130
- return [...this.itemType.useImports(features), Import.PURIFY];
143
+ useImports(parameters) {
144
+ return [...this.itemType.useImports(parameters), Import.PURIFY];
131
145
  }
132
146
  }
147
+ __decorate([
148
+ Memoize()
149
+ ], OptionType.prototype, "conversions", null);
150
+ __decorate([
151
+ Memoize()
152
+ ], OptionType.prototype, "equalsFunction", null);
153
+ __decorate([
154
+ Memoize()
155
+ ], OptionType.prototype, "graphqlName", null);
156
+ __decorate([
157
+ Memoize()
158
+ ], OptionType.prototype, "jsonName", null);
133
159
  __decorate([
134
160
  Memoize()
135
161
  ], 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,10 +10,11 @@ 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
+ graphqlResolveExpression({ variables, }: Parameters<Type["graphqlResolveExpression"]>[0]): string;
16
16
  hashStatements({ variables, }: Parameters<Type["hashStatements"]>[0]): readonly string[];
17
- snippetDeclarations(features: Set<TsFeature>): readonly string[];
17
+ snippetDeclarations({ features, }: Parameters<Type["snippetDeclarations"]>[0]): readonly string[];
18
18
  toJsonExpression({ variables, }: Parameters<Type["toJsonExpression"]>[0]): string;
19
19
  protected propertyFilterRdfResourceValuesExpression({ variables, }: Parameters<LiteralType["propertyFilterRdfResourceValuesExpression"]>[0]): string;
20
20
  }
@@ -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,15 +23,18 @@ 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
+ graphqlResolveExpression({ variables, }) {
32
+ return variables.value;
33
+ }
22
34
  hashStatements({ variables, }) {
23
35
  return [`${variables.hasher}.update(${variables.value}.toString());`];
24
36
  }
25
- snippetDeclarations(features) {
37
+ snippetDeclarations({ features, }) {
26
38
  const snippetDeclarations = [];
27
39
  if (features.has("equals")) {
28
40
  snippetDeclarations.push(SnippetDeclarations.strictEquals);
@@ -36,4 +48,7 @@ export class PrimitiveType extends LiteralType {
36
48
  return variables.resourceValues;
37
49
  }
38
50
  }
51
+ __decorate([
52
+ Memoize()
53
+ ], PrimitiveType.prototype, "jsonName", null);
39
54
  //# 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 = Type> extends Type {
8
5
  private readonly _mutable;
9
- constructor({ itemType, minCount, mutable, ...superParameters }: ConstructorParameters<typeof Type>[0] & {
10
- itemType: Type;
6
+ private readonly minCount;
7
+ readonly discriminatorProperty: Maybe<Type.DiscriminatorProperty>;
8
+ readonly itemType: ItemTypeT;
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
23
  fromRdfExpression({ variables, }: 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
+ _mutable;
15
+ minCount;
16
+ discriminatorProperty = Maybe.empty();
13
17
  itemType;
14
18
  kind = "SetType";
15
- minCount;
16
- _mutable;
17
- constructor({ itemType, minCount, mutable, ...superParameters }) {
18
- super(superParameters);
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,33 @@ 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
90
  fromRdfExpression({ variables, }) {
78
91
  const itemFromRdfExpression = this.itemType.fromRdfExpression({
79
- variables: { ...variables, resourceValues: "_item.toValues()" },
92
+ variables: { ...variables, resourceValues: "item.toValues()" },
80
93
  });
94
+ const arrayFromRdfExpression = `purify.Either.sequence(${variables.resourceValues}.map(item => ${itemFromRdfExpression}))`;
81
95
  if (this._mutable || this.minCount === 0) {
82
- return `purify.Either.of([...${variables.resourceValues}.flatMap(_item => ${itemFromRdfExpression}.toMaybe().toList())])`;
96
+ return arrayFromRdfExpression;
83
97
  }
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 })}))`;
98
+ return `${arrayFromRdfExpression}.chain(array => purify.NonEmptyList.fromArray(array).toEither(new Error(\`\${rdfjsResource.Resource.Identifier.toString(${variables.resource}.identifier)} is an empty set\`)))`;
99
+ }
100
+ graphqlResolveExpression({ variables, }) {
101
+ return variables.value;
85
102
  }
86
103
  hashStatements({ depth, variables, }) {
87
104
  return [
88
- `for (const _item${depth} of ${variables.value}) { ${this.itemType
105
+ `for (const item${depth} of ${variables.value}) { ${this.itemType
89
106
  .hashStatements({
90
107
  depth: depth + 1,
91
108
  variables: {
92
109
  hasher: variables.hasher,
93
- value: `_item${depth}`,
110
+ value: `item${depth}`,
94
111
  },
95
112
  })
96
113
  .join("\n")} }`,
@@ -104,32 +121,32 @@ export class SetType extends Type {
104
121
  if (this.minCount > 0) {
105
122
  schema = `${schema}.nonempty().min(${this.minCount})`;
106
123
  }
124
+ else {
125
+ schema = `${schema}.default(() => [])`;
126
+ }
107
127
  return schema;
108
128
  }
109
- snippetDeclarations(features) {
129
+ snippetDeclarations(parameters) {
110
130
  const snippetDeclarations = this.itemType
111
- .snippetDeclarations(features)
131
+ .snippetDeclarations(parameters)
112
132
  .concat();
113
- if (features.has("equals")) {
133
+ if (parameters.features.has("equals")) {
114
134
  snippetDeclarations.push(SnippetDeclarations.arrayEquals);
115
135
  }
116
136
  return snippetDeclarations;
117
137
  }
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
- });
138
+ sparqlConstructTemplateTriples(parameters) {
139
+ switch (parameters.context) {
140
+ case "object":
141
+ return super.sparqlConstructTemplateTriples(parameters);
142
+ case "subject":
143
+ return this.itemType.sparqlConstructTemplateTriples(parameters);
127
144
  }
128
145
  }
129
- sparqlWherePatterns({ context, variables, }) {
130
- switch (context) {
131
- case "property": {
132
- const patterns = super.sparqlWherePatterns({ context, variables });
146
+ sparqlWherePatterns(parameters) {
147
+ switch (parameters.context) {
148
+ case "object": {
149
+ const patterns = super.sparqlWherePatterns(parameters);
133
150
  if (patterns.length === 0) {
134
151
  return [];
135
152
  }
@@ -137,23 +154,35 @@ export class SetType extends Type {
137
154
  ? patterns
138
155
  : [`{ patterns: [${patterns.join(", ")}], type: "optional" }`];
139
156
  }
140
- case "type": {
141
- return this.itemType.sparqlWherePatterns({ context, variables });
157
+ case "subject": {
158
+ return this.itemType.sparqlWherePatterns(parameters);
142
159
  }
143
160
  }
144
161
  }
145
162
  toJsonExpression({ variables, }) {
146
- return `${variables.value}.map(_item => (${this.itemType.toJsonExpression({ variables: { value: "_item" } })}))`;
163
+ return `${variables.value}.map(item => (${this.itemType.toJsonExpression({ variables: { value: "item" } })}))`;
147
164
  }
148
165
  toRdfExpression({ variables, }) {
149
- return `${variables.value}.map((_item) => ${this.itemType.toRdfExpression({
150
- variables: { ...variables, value: "_item" },
166
+ return `${variables.value}.map((item) => ${this.itemType.toRdfExpression({
167
+ variables: { ...variables, value: "item" },
151
168
  })})`;
152
169
  }
153
- useImports(features) {
154
- return this.itemType.useImports(features);
170
+ useImports(parameters) {
171
+ return this.itemType.useImports(parameters);
155
172
  }
156
173
  }
174
+ __decorate([
175
+ Memoize()
176
+ ], SetType.prototype, "conversions", null);
177
+ __decorate([
178
+ Memoize()
179
+ ], SetType.prototype, "equalsFunction", null);
180
+ __decorate([
181
+ Memoize()
182
+ ], SetType.prototype, "graphqlName", null);
183
+ __decorate([
184
+ Memoize()
185
+ ], SetType.prototype, "jsonName", null);
157
186
  __decorate([
158
187
  Memoize()
159
188
  ], 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(): Promise<purify.Either<Error, readonly ResolvedObjectT[]>> {\n if (this.stubs.length === 0) {\n return purify.Either.of([]);\n }\n return await this.resolver(this.stubs.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