@shaclmate/compiler 2.0.23 → 3.0.0

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 (103) hide show
  1. package/dist/ShapesGraphToAstTransformer.d.ts +5 -5
  2. package/dist/ShapesGraphToAstTransformer.js +5 -5
  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/index.d.ts +5 -5
  8. package/dist/_ShapesGraphToAstTransformer/index.js +5 -5
  9. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +77 -29
  10. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompositeType.d.ts +10 -0
  11. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompositeType.js +185 -0
  12. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstIdentifierType.d.ts +10 -0
  13. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstIdentifierType.js +32 -0
  14. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstLiteralType.d.ts +10 -0
  15. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstLiteralType.js +46 -0
  16. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstTermType.d.ts +12 -0
  17. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstTermType.js +24 -0
  18. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstType.d.ts +13 -0
  19. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstType.js +14 -0
  20. package/dist/ast/OptionType.d.ts +0 -2
  21. package/dist/ast/SetType.d.ts +1 -6
  22. package/dist/ast/index.d.ts +1 -0
  23. package/dist/ast/index.js +1 -0
  24. package/dist/generators/json/AstJsonGenerator.js +7 -1
  25. package/dist/generators/ts/BooleanType.d.ts +2 -1
  26. package/dist/generators/ts/BooleanType.js +9 -4
  27. package/dist/generators/ts/DateTimeType.d.ts +2 -1
  28. package/dist/generators/ts/DateTimeType.js +9 -4
  29. package/dist/generators/ts/IdentifierType.d.ts +1 -1
  30. package/dist/generators/ts/IdentifierType.js +20 -14
  31. package/dist/generators/ts/Import.d.ts +2 -1
  32. package/dist/generators/ts/Import.js +29 -24
  33. package/dist/generators/ts/ListType.js +16 -5
  34. package/dist/generators/ts/LiteralType.d.ts +5 -2
  35. package/dist/generators/ts/LiteralType.js +81 -15
  36. package/dist/generators/ts/NumberType.d.ts +2 -1
  37. package/dist/generators/ts/NumberType.js +9 -4
  38. package/dist/generators/ts/ObjectType.d.ts +3 -2
  39. package/dist/generators/ts/ObjectType.js +16 -6
  40. package/dist/generators/ts/ObjectUnionType.d.ts +2 -0
  41. package/dist/generators/ts/ObjectUnionType.js +21 -9
  42. package/dist/generators/ts/OptionType.d.ts +1 -1
  43. package/dist/generators/ts/OptionType.js +6 -4
  44. package/dist/generators/ts/PrimitiveType.d.ts +1 -1
  45. package/dist/generators/ts/PrimitiveType.js +6 -3
  46. package/dist/generators/ts/SetType.d.ts +4 -4
  47. package/dist/generators/ts/SetType.js +15 -12
  48. package/dist/generators/ts/SnippetDeclarations.d.ts +3 -2
  49. package/dist/generators/ts/SnippetDeclarations.js +41 -3
  50. package/dist/generators/ts/StringType.d.ts +2 -1
  51. package/dist/generators/ts/StringType.js +14 -7
  52. package/dist/generators/ts/TermType.d.ts +18 -19
  53. package/dist/generators/ts/TermType.js +55 -51
  54. package/dist/generators/ts/TsGenerator.js +24 -12
  55. package/dist/generators/ts/Type.d.ts +12 -3
  56. package/dist/generators/ts/Type.js +1 -0
  57. package/dist/generators/ts/TypeFactory.d.ts +8 -0
  58. package/dist/generators/ts/TypeFactory.js +114 -23
  59. package/dist/generators/ts/UnionType.js +1 -1
  60. package/dist/generators/ts/_ObjectType/EagerShaclProperty.js +3 -2
  61. package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.d.ts +1 -1
  62. package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.js +15 -1
  63. package/dist/generators/ts/_ObjectType/IdentifierProperty.d.ts +6 -6
  64. package/dist/generators/ts/_ObjectType/IdentifierProperty.js +59 -29
  65. package/dist/generators/ts/_ObjectType/LazyShaclProperty.d.ts +14 -1
  66. package/dist/generators/ts/_ObjectType/LazyShaclProperty.js +89 -11
  67. package/dist/generators/ts/_ObjectType/Property.d.ts +10 -4
  68. package/dist/generators/ts/_ObjectType/ShaclProperty.d.ts +1 -1
  69. package/dist/generators/ts/_ObjectType/ShaclProperty.js +14 -2
  70. package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +1 -1
  71. package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +1 -1
  72. package/dist/generators/ts/_ObjectType/classDeclaration.js +16 -12
  73. package/dist/generators/ts/_ObjectType/createFunctionDeclaration.js +22 -10
  74. package/dist/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.js +3 -1
  75. package/dist/generators/ts/_ObjectType/graphqlTypeVariableStatement.js +14 -2
  76. package/dist/generators/ts/_ObjectType/jsonFunctionDeclarations.js +1 -1
  77. package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.js +95 -84
  78. package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.js +3 -3
  79. package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.js +1 -1
  80. package/dist/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +35 -15
  81. package/dist/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.js +19 -12
  82. package/dist/generators/ts/forwardingObjectSetClassDeclaration.d.ts +8 -0
  83. package/dist/generators/ts/forwardingObjectSetClassDeclaration.js +29 -0
  84. package/dist/generators/ts/objectSetDeclarations.js +2 -0
  85. package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +26 -19
  86. package/dist/generators/ts/rdfjsTermExpression.js +3 -3
  87. package/dist/generators/ts/sparqlObjectSetClassDeclaration.js +6 -6
  88. package/dist/input/PropertyPath.d.ts +2 -3
  89. package/dist/input/PropertyPath.js +6 -8
  90. package/dist/input/ShapesGraph.js +4 -8
  91. package/dist/input/generated.d.ts +96 -54
  92. package/dist/input/generated.js +1350 -744
  93. package/package.json +5 -8
  94. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.d.ts +0 -12
  95. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +0 -193
  96. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.d.ts +0 -12
  97. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.js +0 -29
  98. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.d.ts +0 -12
  99. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.js +0 -43
  100. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.d.ts +0 -14
  101. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.js +0 -21
  102. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.d.ts +0 -15
  103. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.js +0 -60
@@ -19,7 +19,6 @@ import { syntheticNamePrefix } from "./syntheticNamePrefix.js";
19
19
  export class ObjectType extends DeclaredType {
20
20
  imports;
21
21
  comment;
22
- identifierMintingStrategy;
23
22
  label;
24
23
  toRdfTypes;
25
24
  abstract;
@@ -30,14 +29,13 @@ export class ObjectType extends DeclaredType {
30
29
  staticModuleName;
31
30
  synthetic;
32
31
  typeof = "object";
33
- constructor({ abstract, comment, declarationType, extern, fromRdfType, imports, identifierMintingStrategy, label, lazyAncestorObjectTypes, lazyChildObjectTypes, lazyDescendantObjectTypes, lazyParentObjectTypes, lazyProperties, staticModuleName, synthetic, toRdfTypes, ...superParameters }) {
32
+ constructor({ abstract, comment, declarationType, extern, fromRdfType, imports, label, lazyAncestorObjectTypes, lazyChildObjectTypes, lazyDescendantObjectTypes, lazyParentObjectTypes, lazyProperties, staticModuleName, synthetic, toRdfTypes, ...superParameters }) {
34
33
  super(superParameters);
35
34
  this.abstract = abstract;
36
35
  this.comment = comment;
37
36
  this.declarationType = declarationType;
38
37
  this.extern = extern;
39
38
  this.fromRdfType = fromRdfType;
40
- this.identifierMintingStrategy = identifierMintingStrategy;
41
39
  this.imports = imports;
42
40
  this.label = label;
43
41
  // Lazily initialize some members in getters to avoid recursive construction
@@ -85,7 +83,6 @@ export class ObjectType extends DeclaredType {
85
83
  }
86
84
  if (this.features.has("json")) {
87
85
  imports.push(Import.ZOD);
88
- imports.push(Import.ZOD_TO_JSON_SCHEMA);
89
86
  }
90
87
  if (this.features.has("rdf")) {
91
88
  imports.push(Import.PURIFY);
@@ -124,6 +121,12 @@ export class ObjectType extends DeclaredType {
124
121
  }
125
122
  return declarations;
126
123
  }
124
+ get descendantFromRdfTypes() {
125
+ return this.descendantObjectTypes.flatMap((descendantObjectType) => descendantObjectType.fromRdfType.toList());
126
+ }
127
+ get descendantFromRdfTypeVariables() {
128
+ return this.descendantObjectTypes.flatMap((descendantObjectType) => descendantObjectType.fromRdfTypeVariable.toList());
129
+ }
127
130
  get descendantObjectTypes() {
128
131
  return this.lazyDescendantObjectTypes();
129
132
  }
@@ -171,7 +174,7 @@ export class ObjectType extends DeclaredType {
171
174
  case "class":
172
175
  return `new ${this.name}(${parameters})`;
173
176
  case "interface":
174
- return `${this.staticModuleName}.create(${parameters})`;
177
+ return `${this.staticModuleName}.${syntheticNamePrefix}create(${parameters})`;
175
178
  }
176
179
  }
177
180
  get objectSetMethodNames() {
@@ -223,7 +226,7 @@ export class ObjectType extends DeclaredType {
223
226
  return `${this.staticModuleName}.${syntheticNamePrefix}fromJson(${variables.value}).unsafeCoerce()`;
224
227
  }
225
228
  fromRdfExpression({ variables, }) {
226
- return `${variables.resourceValues}.head().chain(value => value.toResource()).chain(_resource => ${this.staticModuleName}.${syntheticNamePrefix}fromRdf({ ...${variables.context}, ${variables.ignoreRdfType ? "ignoreRdfType: true, " : ""}languageIn: ${variables.languageIn}, objectSet: ${variables.objectSet}, resource: _resource }))`;
229
+ return `${variables.resourceValues}.chain(values => values.chainMap(value => value.toResource().chain(resource => ${this.staticModuleName}.${syntheticNamePrefix}fromRdf(resource, { ...${variables.context}, ${variables.ignoreRdfType ? "ignoreRdfType: true, " : ""}objectSet: ${variables.objectSet}, preferredLanguages: ${variables.preferredLanguages} }))))`;
227
230
  }
228
231
  graphqlResolveExpression({ variables, }) {
229
232
  return variables.value;
@@ -301,6 +304,7 @@ export class ObjectType extends DeclaredType {
301
304
  return [
302
305
  `...${this.staticModuleName}.${syntheticNamePrefix}sparqlWherePatterns(${objectInitializer({
303
306
  ignoreRdfType: parameters.allowIgnoreRdfType ? true : undefined, // Can ignore the rdf:type when the object is nested
307
+ preferredLanguages: parameters.variables.preferredLanguages,
304
308
  subject: parameters.variables.subject,
305
309
  variablePrefix: parameters.variables.variablePrefix,
306
310
  })})`,
@@ -349,6 +353,12 @@ __decorate([
349
353
  __decorate([
350
354
  Memoize()
351
355
  ], ObjectType.prototype, "conversions", null);
356
+ __decorate([
357
+ Memoize()
358
+ ], ObjectType.prototype, "descendantFromRdfTypes", null);
359
+ __decorate([
360
+ Memoize()
361
+ ], ObjectType.prototype, "descendantFromRdfTypeVariables", null);
352
362
  __decorate([
353
363
  Memoize()
354
364
  ], ObjectType.prototype, "descendantObjectTypes", null);
@@ -13,6 +13,7 @@ declare class MemberType {
13
13
  universe: readonly ObjectType[];
14
14
  });
15
15
  get declarationType(): import("../../enums/TsObjectDeclarationType.js").TsObjectDeclarationType;
16
+ get descendantFromRdfTypeVariables(): readonly string[];
16
17
  get discriminatorPropertyValues(): readonly string[];
17
18
  get features(): Set<import("../../enums/TsFeature.js").TsFeature>;
18
19
  get fromRdfType(): Maybe<import("@rdfjs/types").NamedNode<string>>;
@@ -25,6 +26,7 @@ declare class MemberType {
25
26
  get staticModuleName(): string;
26
27
  get toRdfjsResourceType(): string;
27
28
  jsonZodSchema(parameters: Parameters<DeclaredType["jsonZodSchema"]>[0]): string;
29
+ newExpression(parameters: Parameters<ObjectType["newExpression"]>[0]): string;
28
30
  snippetDeclarations(parameters: Parameters<DeclaredType["snippetDeclarations"]>[0]): readonly string[];
29
31
  useImports(): readonly Import[];
30
32
  }
@@ -28,6 +28,9 @@ class MemberType {
28
28
  get declarationType() {
29
29
  return this.delegate.declarationType;
30
30
  }
31
+ get descendantFromRdfTypeVariables() {
32
+ return this.delegate.descendantFromRdfTypeVariables;
33
+ }
31
34
  get discriminatorPropertyValues() {
32
35
  // A member type's combined discriminator property values are its "own" values plus any descendant values that are
33
36
  // not the "own" values of some other member type.
@@ -81,6 +84,9 @@ class MemberType {
81
84
  jsonZodSchema(parameters) {
82
85
  return this.delegate.jsonZodSchema(parameters);
83
86
  }
87
+ newExpression(parameters) {
88
+ return this.delegate.newExpression(parameters);
89
+ }
84
90
  snippetDeclarations(parameters) {
85
91
  return this.delegate.snippetDeclarations(parameters);
86
92
  }
@@ -270,14 +276,19 @@ return ${syntheticNamePrefix}strictEquals(left.${syntheticNamePrefix}type, right
270
276
  name: `${syntheticNamePrefix}fromRdf`,
271
277
  parameters: [
272
278
  {
273
- name: "{ ignoreRdfType, objectSet, resource, ...context }",
274
- type: `{ [_index: string]: any; ignoreRdfType?: boolean; objectSet?: ${syntheticNamePrefix}ObjectSet, resource: rdfjsResource.Resource; }`,
279
+ name: "resource",
280
+ type: "rdfjsResource.Resource",
281
+ },
282
+ {
283
+ hasQuestionToken: true,
284
+ name: "options",
285
+ type: `{ [_index: string]: any; ignoreRdfType?: boolean; objectSet?: ${syntheticNamePrefix}ObjectSet; preferredLanguages?: readonly string[] }`,
275
286
  },
276
287
  ],
277
288
  returnType: `purify.Either<Error, ${this.name}>`,
278
289
  statements: [
279
290
  `return ${this.memberTypes.reduce((expression, memberType) => {
280
- const memberTypeExpression = `(${memberType.staticModuleName}.${syntheticNamePrefix}fromRdf({ ...context, objectSet, resource }) as purify.Either<Error, ${this.name}>)`;
291
+ const memberTypeExpression = `(${memberType.staticModuleName}.${syntheticNamePrefix}fromRdf(resource, { ...options, ignoreRdfType: false }) as purify.Either<Error, ${this.name}>)`;
281
292
  return expression.length > 0
282
293
  ? `${expression}.altLazy(() => ${memberTypeExpression})`
283
294
  : memberTypeExpression;
@@ -298,7 +309,7 @@ return ${syntheticNamePrefix}strictEquals(left.${syntheticNamePrefix}type, right
298
309
  initializer: `new graphql.GraphQLUnionType(${objectInitializer({
299
310
  description: this.comment.map(JSON.stringify).extract(),
300
311
  name: `"${this.name}"`,
301
- resolveType: `function (value: ${this.name}) { return value.${syntheticNamePrefix}type; }`,
312
+ resolveType: `(value: ${this.name}) => value.${syntheticNamePrefix}type`,
302
313
  types: `[${this.memberTypes.map((memberType) => memberType.graphqlName.nullableName).join(", ")}]`,
303
314
  })})`,
304
315
  },
@@ -427,7 +438,7 @@ return ${syntheticNamePrefix}strictEquals(left.${syntheticNamePrefix}type, right
427
438
  {
428
439
  hasQuestionToken: true,
429
440
  name: "parameters",
430
- type: '{ ignoreRdfType?: boolean; subject?: sparqljs.Triple["subject"], variablePrefix?: string }',
441
+ type: '{ ignoreRdfType?: boolean; preferredLanguages?: readonly string[]; subject?: sparqljs.Triple["subject"], variablePrefix?: string }',
431
442
  },
432
443
  ],
433
444
  returnType: "readonly sparqljs.Pattern[]",
@@ -501,8 +512,9 @@ return ${syntheticNamePrefix}strictEquals(left.${syntheticNamePrefix}type, right
501
512
  type: this.name,
502
513
  },
503
514
  {
515
+ hasQuestionToken: true,
504
516
  name: parametersVariable,
505
- type: "{ mutateGraph: rdfjsResource.MutableResource.MutateGraph, resourceSet: rdfjsResource.MutableResourceSet }",
517
+ type: "{ mutateGraph?: rdfjsResource.MutableResource.MutateGraph, resourceSet?: rdfjsResource.MutableResourceSet }",
506
518
  },
507
519
  ],
508
520
  returnType: (() => {
@@ -537,7 +549,7 @@ return ${syntheticNamePrefix}strictEquals(left.${syntheticNamePrefix}type, right
537
549
  }
538
550
  fromRdfExpression({ variables, }) {
539
551
  // Don't ignoreRdfType, we may need it to distinguish the union members
540
- return `${variables.resourceValues}.head().chain(value => value.toResource()).chain(_resource => ${this.staticModuleName}.${syntheticNamePrefix}fromRdf({ ...${variables.context}, languageIn: ${variables.languageIn}, objectSet: ${variables.objectSet}, resource: _resource }))`;
552
+ return `${variables.resourceValues}.chain(values => values.chainMap(value => value.toResource().chain(resource => ${this.staticModuleName}.${syntheticNamePrefix}fromRdf(resource, { ...${variables.context}, ignoreRdfType: false, objectSet: ${variables.objectSet}, preferredLanguages: ${variables.preferredLanguages} }))))`;
541
553
  }
542
554
  graphqlResolveExpression({ variables, }) {
543
555
  return variables.value;
@@ -590,6 +602,7 @@ return ${syntheticNamePrefix}strictEquals(left.${syntheticNamePrefix}type, right
590
602
  case "subject":
591
603
  return [
592
604
  `...${this.staticModuleName}.${syntheticNamePrefix}sparqlWherePatterns(${objectInitializer({
605
+ preferredLanguages: parameters.variables.preferredLanguages,
593
606
  subject: parameters.variables.subject,
594
607
  variablePrefix: parameters.variables.variablePrefix,
595
608
  })})`,
@@ -601,8 +614,7 @@ return ${syntheticNamePrefix}strictEquals(left.${syntheticNamePrefix}type, right
601
614
  case "class":
602
615
  return `${variables.value}.${syntheticNamePrefix}toJson()`;
603
616
  case "interface":
604
- throw new Error("not implemented: need a freestanding toJson function like the toRdf function");
605
- // return `${this.name}.toJson(${variables.value})`;
617
+ return `${this.staticModuleName}.${syntheticNamePrefix}toJson(${variables.value})`;
606
618
  }
607
619
  }
608
620
  toRdfExpression({ variables, }) {
@@ -1,7 +1,7 @@
1
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<ItemTypeT extends Type = Type> extends Type {
4
+ export declare class OptionType<ItemTypeT extends Type> extends Type {
5
5
  readonly discriminatorProperty: Maybe<Type.DiscriminatorProperty>;
6
6
  readonly itemType: ItemTypeT;
7
7
  readonly kind = "OptionType";
@@ -4,8 +4,8 @@ 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";
8
7
  import { Memoize } from "typescript-memoize";
8
+ import { Maybe } from "purify-ts";
9
9
  import { invariant } from "ts-invariant";
10
10
  import { Import } from "./Import.js";
11
11
  import { SnippetDeclarations } from "./SnippetDeclarations.js";
@@ -73,7 +73,8 @@ export class OptionType extends Type {
73
73
  : `${expression}.map(item => (${itemFromJsonExpression}))`;
74
74
  }
75
75
  fromRdfExpression(parameters) {
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))`;
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} }))`;
77
78
  }
78
79
  graphqlResolveExpression(parameters) {
79
80
  return `${this.itemType.graphqlResolveExpression(parameters)}.extractNullable()`;
@@ -117,14 +118,15 @@ export class OptionType extends Type {
117
118
  sparqlWherePatterns(parameters) {
118
119
  switch (parameters.context) {
119
120
  case "object": {
120
- const patterns = super.sparqlWherePatterns(parameters);
121
+ const patterns = this.itemType.sparqlWherePatterns(parameters);
121
122
  if (patterns.length === 0) {
122
123
  return [];
123
124
  }
124
125
  return [`{ patterns: [${patterns.join(", ")}], type: "optional" }`];
125
126
  }
126
127
  case "subject": {
127
- return this.itemType.sparqlWherePatterns(parameters);
128
+ throw new Error("should never be called");
129
+ // return this.itemType.sparqlWherePatterns(parameters);
128
130
  }
129
131
  }
130
132
  }
@@ -15,7 +15,7 @@ export declare abstract class PrimitiveType<ValueT extends boolean | Date | stri
15
15
  graphqlResolveExpression({ variables, }: Parameters<Type["graphqlResolveExpression"]>[0]): string;
16
16
  hashStatements({ variables, }: Parameters<Type["hashStatements"]>[0]): readonly string[];
17
17
  snippetDeclarations({ features, }: Parameters<Type["snippetDeclarations"]>[0]): readonly string[];
18
+ sparqlWherePatterns(parameters: Parameters<LiteralType["sparqlWherePatterns"]>[0]): readonly string[];
18
19
  toJsonExpression({ variables, }: Parameters<Type["toJsonExpression"]>[0]): string;
19
- protected propertyFilterRdfResourceValuesExpression({ variables, }: Parameters<LiteralType["propertyFilterRdfResourceValuesExpression"]>[0]): string;
20
20
  }
21
21
  //# sourceMappingURL=PrimitiveType.d.ts.map
@@ -41,12 +41,15 @@ export class PrimitiveType extends LiteralType {
41
41
  }
42
42
  return snippetDeclarations;
43
43
  }
44
+ sparqlWherePatterns(parameters) {
45
+ return super.sparqlWherePatterns({
46
+ ...parameters,
47
+ ignoreLiteralLanguage: parameters.ignoreLiteralLanguage ?? true,
48
+ });
49
+ }
44
50
  toJsonExpression({ variables, }) {
45
51
  return variables.value;
46
52
  }
47
- propertyFilterRdfResourceValuesExpression({ variables, }) {
48
- return variables.resourceValues;
49
- }
50
53
  }
51
54
  __decorate([
52
55
  Memoize()
@@ -1,11 +1,11 @@
1
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<ItemTypeT extends Type = Type> extends Type {
5
- private readonly _mutable;
6
- private readonly minCount;
4
+ export declare class SetType<ItemTypeT extends Type> extends Type {
7
5
  readonly discriminatorProperty: Maybe<Type.DiscriminatorProperty>;
8
6
  readonly itemType: ItemTypeT;
7
+ private readonly _mutable;
8
+ private readonly minCount;
9
9
  readonly kind = "SetType";
10
10
  readonly typeof = "object";
11
11
  constructor({ itemType, minCount, mutable, }: {
@@ -20,7 +20,7 @@ export declare class SetType<ItemTypeT extends Type = Type> extends Type {
20
20
  get mutable(): boolean;
21
21
  get name(): string;
22
22
  fromJsonExpression({ variables, }: Parameters<Type["fromJsonExpression"]>[0]): string;
23
- fromRdfExpression({ variables, }: Parameters<Type["fromRdfExpression"]>[0]): string;
23
+ fromRdfExpression(parameters: Parameters<Type["fromRdfExpression"]>[0]): string;
24
24
  graphqlResolveExpression({ variables, }: Parameters<Type["graphqlResolveExpression"]>[0]): string;
25
25
  hashStatements({ depth, variables, }: Parameters<Type["hashStatements"]>[0]): readonly string[];
26
26
  jsonUiSchemaElement(parameters: Parameters<Type["jsonUiSchemaElement"]>[0]): ReturnType<Type["jsonUiSchemaElement"]>;
@@ -11,10 +11,10 @@ import { SnippetDeclarations } from "./SnippetDeclarations.js";
11
11
  import { Type } from "./Type.js";
12
12
  import { syntheticNamePrefix } from "./syntheticNamePrefix.js";
13
13
  export class SetType extends Type {
14
- _mutable;
15
- minCount;
16
14
  discriminatorProperty = Maybe.empty();
17
15
  itemType;
16
+ _mutable;
17
+ minCount;
18
18
  kind = "SetType";
19
19
  typeof = "object";
20
20
  constructor({ itemType, minCount, mutable, }) {
@@ -87,15 +87,17 @@ export class SetType extends Type {
87
87
  ? expression
88
88
  : `${expression}.map(item => (${itemFromJsonExpression}))`;
89
89
  }
90
- fromRdfExpression({ variables, }) {
91
- const itemFromRdfExpression = this.itemType.fromRdfExpression({
92
- variables: { ...variables, resourceValues: "item.toValues()" },
93
- });
94
- const arrayFromRdfExpression = `purify.Either.sequence(${variables.resourceValues}.map(item => ${itemFromRdfExpression}))`;
95
- if (this._mutable || this.minCount === 0) {
96
- return arrayFromRdfExpression;
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\`)))`);
97
98
  }
98
- return `${arrayFromRdfExpression}.chain(array => purify.NonEmptyList.fromArray(array).toEither(new Error(\`\${rdfjsResource.Resource.Identifier.toString(${variables.resource}.identifier)} is an empty set\`)))`;
99
+ chain.push(`map(valuesArray => rdfjsResource.Resource.Values.fromValue({ object: valuesArray , predicate: ${variables.predicate}, subject: ${variables.resource} }))`);
100
+ return chain.join(".");
99
101
  }
100
102
  graphqlResolveExpression({ variables, }) {
101
103
  return variables.value;
@@ -146,7 +148,7 @@ export class SetType extends Type {
146
148
  sparqlWherePatterns(parameters) {
147
149
  switch (parameters.context) {
148
150
  case "object": {
149
- const patterns = super.sparqlWherePatterns(parameters);
151
+ const patterns = this.itemType.sparqlWherePatterns(parameters);
150
152
  if (patterns.length === 0) {
151
153
  return [];
152
154
  }
@@ -155,7 +157,8 @@ export class SetType extends Type {
155
157
  : [`{ patterns: [${patterns.join(", ")}], type: "optional" }`];
156
158
  }
157
159
  case "subject": {
158
- return this.itemType.sparqlWherePatterns(parameters);
160
+ throw new Error("should never be called");
161
+ // return this.itemType.sparqlWherePatterns(parameters);
159
162
  }
160
163
  }
161
164
  }
@@ -1,14 +1,15 @@
1
1
  export declare namespace SnippetDeclarations {
2
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 arrayIntersection = "export function $arrayIntersection<T>(left: readonly T[], right: readonly T[]): readonly T[] {\n if (left.length === 0) {\n return right;\n }\n if (right.length === 0) {\n return left;\n }\n\n const intersection = new Set<T>();\n if (left.length <= right.length) {\n const rightSet = new Set(right);\n for (const leftElement of left) {\n if (rightSet.has(leftElement)) {\n intersection.add(leftElement);\n }\n }\n } else {\n const leftSet = new Set(left);\n for (const rightElement of right) {\n if (leftSet.has(rightElement)) {\n intersection.add(rightElement);\n } \n }\n }\n return [...intersection];\n}";
3
4
  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
5
  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
6
  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
7
  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 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
9
  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
10
  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
11
  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 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 | rdfjs.Variable, 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
13
  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
14
  const UnwrapL = "type $UnwrapL<T> = T extends purify.Either<infer L, any> ? L : never";
14
15
  const UnwrapR = "type $UnwrapR<T> = T extends purify.Either<any, infer R> ? R : never";
@@ -68,6 +68,33 @@ export function ${syntheticNamePrefix}arrayEquals<T>(
68
68
  return ${syntheticNamePrefix}EqualsResult.Equal;
69
69
  }
70
70
  `;
71
+ SnippetDeclarations.arrayIntersection = `\
72
+ export function ${syntheticNamePrefix}arrayIntersection<T>(left: readonly T[], right: readonly T[]): readonly T[] {
73
+ if (left.length === 0) {
74
+ return right;
75
+ }
76
+ if (right.length === 0) {
77
+ return left;
78
+ }
79
+
80
+ const intersection = new Set<T>();
81
+ if (left.length <= right.length) {
82
+ const rightSet = new Set(right);
83
+ for (const leftElement of left) {
84
+ if (rightSet.has(leftElement)) {
85
+ intersection.add(leftElement);
86
+ }
87
+ }
88
+ } else {
89
+ const leftSet = new Set(left);
90
+ for (const rightElement of right) {
91
+ if (leftSet.has(rightElement)) {
92
+ intersection.add(rightElement);
93
+ }
94
+ }
95
+ }
96
+ return [...intersection];
97
+ }`;
71
98
  SnippetDeclarations.booleanEquals = `\
72
99
  /**
73
100
  * Compare two objects with equals(other: T): boolean methods and return an ${syntheticNamePrefix}EqualsResult.
@@ -215,11 +242,22 @@ export class ${syntheticNamePrefix}LazyObjectSet<ObjectIdentifierT extends rdfjs
215
242
  this.stubs = stubs;
216
243
  }
217
244
 
218
- async resolve(): Promise<purify.Either<Error, readonly ResolvedObjectT[]>> {
245
+ async resolve(options?: { limit?: number; offset?: number }): Promise<purify.Either<Error, readonly ResolvedObjectT[]>> {
219
246
  if (this.stubs.length === 0) {
220
247
  return purify.Either.of([]);
221
248
  }
222
- return await this.resolver(this.stubs.map(stub => stub.${syntheticNamePrefix}identifier));
249
+
250
+ const limit = options?.limit ?? Number.MAX_SAFE_INTEGER;
251
+ if (limit <= 0) {
252
+ return purify.Either.of([]);
253
+ }
254
+
255
+ let offset = options?.offset ?? 0;
256
+ if (offset < 0) {
257
+ offset = 0;
258
+ }
259
+
260
+ return await this.resolver(this.stubs.slice(offset, offset + limit).map(stub => stub.${syntheticNamePrefix}identifier));
223
261
  }
224
262
  }`;
225
263
  SnippetDeclarations.LazyOptionalObject = `\
@@ -290,7 +328,7 @@ export namespace ${syntheticNamePrefix}RdfVocabularies {
290
328
  /**
291
329
  * A sparqljs.Pattern that's the equivalent of ?subject rdf:type/rdfs:subClassOf* ?rdfType .
292
330
  */
293
- export function ${syntheticNamePrefix}sparqlInstancesOfPattern({ rdfType, subject }: { rdfType: rdfjs.NamedNode, subject: sparqljs.Triple["subject"] }): sparqljs.Pattern {
331
+ export function ${syntheticNamePrefix}sparqlInstancesOfPattern({ rdfType, subject }: { rdfType: rdfjs.NamedNode | rdfjs.Variable, subject: sparqljs.Triple["subject"] }): sparqljs.Pattern {
294
332
  return {
295
333
  triples: [
296
334
  {
@@ -6,9 +6,10 @@ export declare class StringType extends PrimitiveType<string> {
6
6
  get conversions(): readonly Type.Conversion[];
7
7
  get graphqlName(): Type.GraphqlName;
8
8
  get name(): string;
9
+ protected fromRdfExpressionChain({ variables, }: Parameters<PrimitiveType<string>["fromRdfExpressionChain"]>[0]): ReturnType<PrimitiveType<string>["fromRdfExpressionChain"]>;
9
10
  hashStatements({ variables, }: Parameters<Type["hashStatements"]>[0]): readonly string[];
10
11
  jsonZodSchema({ variables, }: Parameters<Type["jsonZodSchema"]>[0]): ReturnType<Type["jsonZodSchema"]>;
11
- propertyFromRdfResourceValueExpression({ variables, }: Parameters<PrimitiveType<string>["propertyFromRdfResourceValueExpression"]>[0]): string;
12
+ sparqlWherePatterns(parameters: Parameters<PrimitiveType<string>["sparqlWherePatterns"]>[0]): readonly string[];
12
13
  toRdfExpression({ variables, }: Parameters<PrimitiveType<string>["toRdfExpression"]>[0]): string;
13
14
  }
14
15
  //# sourceMappingURL=StringType.d.ts.map
@@ -37,6 +37,15 @@ export class StringType extends PrimitiveType {
37
37
  }
38
38
  return this.typeof;
39
39
  }
40
+ fromRdfExpressionChain({ variables, }) {
41
+ const inChain = this.primitiveIn.length > 0
42
+ ? `.chain(string_ => { switch (string_) { ${this.primitiveIn.map((value) => `case "${value}":`).join(" ")} return purify.Either.of<Error, ${this.name}>(string_); default: return purify.Left<Error, ${this.name}>(new rdfjsResource.Resource.MistypedValueError(${objectInitializer({ actualValue: "value.toTerm()", expectedValueType: JSON.stringify(this.name), focusResource: variables.resource, predicate: variables.predicate })})); } })`
43
+ : "";
44
+ return {
45
+ ...super.fromRdfExpressionChain({ variables }),
46
+ valueTo: `chain(values => values.chainMap(value => value.toString()${inChain}))`,
47
+ };
48
+ }
40
49
  hashStatements({ variables, }) {
41
50
  return [`${variables.hasher}.update(${variables.value});`];
42
51
  }
@@ -50,13 +59,11 @@ export class StringType extends PrimitiveType {
50
59
  return `${variables.zod}.enum(${JSON.stringify(this.primitiveIn)})`;
51
60
  }
52
61
  }
53
- propertyFromRdfResourceValueExpression({ variables, }) {
54
- let expression = `${variables.resourceValue}.toString()`;
55
- if (this.primitiveIn.length > 0) {
56
- const eitherTypeParameters = `<Error, ${this.name}>`;
57
- expression = `${expression}.chain(value => { switch (value) { ${this.primitiveIn.map((value) => `case "${value}":`).join(" ")} return purify.Either.of${eitherTypeParameters}(value); default: return purify.Left${eitherTypeParameters}(new rdfjsResource.Resource.MistypedValueError(${objectInitializer({ actualValue: "rdfLiteral.toRdf(value)", expectedValueType: JSON.stringify(this.name), focusResource: variables.resource, predicate: variables.predicate })})); } })`;
58
- }
59
- return expression;
62
+ sparqlWherePatterns(parameters) {
63
+ return super.sparqlWherePatterns({
64
+ ...parameters,
65
+ ignoreLiteralLanguage: false,
66
+ });
60
67
  }
61
68
  toRdfExpression({ variables, }) {
62
69
  return this.primitiveDefaultValue
@@ -30,7 +30,24 @@ export declare class TermType<ConstantTermT extends Literal | NamedNode = Litera
30
30
  get jsonName(): Type.JsonName;
31
31
  get name(): string;
32
32
  fromJsonExpression({ variables, }: Parameters<Type["fromJsonExpression"]>[0]): string;
33
- fromRdfExpression({ variables, }: Parameters<Type["fromRdfExpression"]>[0]): string;
33
+ fromRdfExpression(parameters: Parameters<Type["fromRdfExpression"]>[0]): string;
34
+ /**
35
+ * The fromRdfExpression for a term type can be decomposed into multiple sub-expressions with different purposes:
36
+ *
37
+ * defaultValues: add the default value to the values sequence if the latter doesn't contain values already
38
+ * hasValues: test whether the values sequence has sh:hasValue values
39
+ * languageIn: filter the values sequence to literals with the right sh:languageIn (or runtime languageIn)
40
+ * valueTo: convert values in the values sequence to the appropriate term type/sub-type (literal, string, etc.)
41
+ *
42
+ * Considering the sub-expressions as a record instead of an array allows them to be selectively overridden by subclasses.
43
+ */
44
+ protected fromRdfExpressionChain({ variables, }: Parameters<Type["fromRdfExpression"]>[0]): {
45
+ defaultValue?: string;
46
+ hasValues?: string;
47
+ languageIn?: string;
48
+ preferredLanguages?: string;
49
+ valueTo: string;
50
+ };
34
51
  graphqlResolveExpression(_parameters: Parameters<Type["graphqlResolveExpression"]>[0]): string;
35
52
  hashStatements({ variables, }: Parameters<Type["hashStatements"]>[0]): readonly string[];
36
53
  jsonUiSchemaElement(): Maybe<string>;
@@ -40,23 +57,5 @@ export declare class TermType<ConstantTermT extends Literal | NamedNode = Litera
40
57
  toJsonExpression({ variables, }: Parameters<Type["toJsonExpression"]>[0]): string;
41
58
  toRdfExpression({ variables, }: Parameters<Type["toRdfExpression"]>[0]): string;
42
59
  useImports(): readonly Import[];
43
- /**
44
- * Filter the rdfjsResource.Resource.Values to those that are relevant to the type.
45
- *
46
- * This is done before
47
- */
48
- protected propertyFilterRdfResourceValuesExpression({ variables, }: Parameters<Type["fromRdfExpression"]>[0]): string;
49
- /**
50
- * Convert an rdfjsResource.Resource.Value to a value of this type.
51
- * @param variables
52
- * @protected
53
- */
54
- protected propertyFromRdfResourceValueExpression({ variables, }: {
55
- variables: {
56
- predicate: string;
57
- resource: string;
58
- resourceValue: string;
59
- };
60
- }): string;
61
60
  }
62
61
  //# sourceMappingURL=TermType.d.ts.map