@shaclmate/compiler 2.0.23 → 2.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) 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 +1 -1
  26. package/dist/generators/ts/BooleanType.js +1 -1
  27. package/dist/generators/ts/DateTimeType.d.ts +1 -1
  28. package/dist/generators/ts/DateTimeType.js +1 -1
  29. package/dist/generators/ts/IdentifierType.d.ts +6 -1
  30. package/dist/generators/ts/IdentifierType.js +20 -14
  31. package/dist/generators/ts/ListType.js +16 -5
  32. package/dist/generators/ts/LiteralType.d.ts +9 -2
  33. package/dist/generators/ts/LiteralType.js +79 -15
  34. package/dist/generators/ts/NumberType.d.ts +1 -1
  35. package/dist/generators/ts/NumberType.js +1 -1
  36. package/dist/generators/ts/ObjectType.d.ts +1 -2
  37. package/dist/generators/ts/ObjectType.js +4 -5
  38. package/dist/generators/ts/ObjectUnionType.d.ts +1 -0
  39. package/dist/generators/ts/ObjectUnionType.js +18 -9
  40. package/dist/generators/ts/OptionType.d.ts +1 -1
  41. package/dist/generators/ts/OptionType.js +6 -4
  42. package/dist/generators/ts/PrimitiveType.d.ts +19 -1
  43. package/dist/generators/ts/PrimitiveType.js +16 -3
  44. package/dist/generators/ts/SetType.d.ts +4 -4
  45. package/dist/generators/ts/SetType.js +15 -12
  46. package/dist/generators/ts/SnippetDeclarations.d.ts +1 -1
  47. package/dist/generators/ts/SnippetDeclarations.js +13 -2
  48. package/dist/generators/ts/StringType.d.ts +1 -1
  49. package/dist/generators/ts/StringType.js +8 -8
  50. package/dist/generators/ts/TermType.d.ts +7 -19
  51. package/dist/generators/ts/TermType.js +44 -51
  52. package/dist/generators/ts/TsGenerator.js +4 -1
  53. package/dist/generators/ts/Type.d.ts +12 -2
  54. package/dist/generators/ts/Type.js +1 -0
  55. package/dist/generators/ts/TypeFactory.d.ts +8 -0
  56. package/dist/generators/ts/TypeFactory.js +112 -22
  57. package/dist/generators/ts/UnionType.js +1 -1
  58. package/dist/generators/ts/_ObjectType/EagerShaclProperty.js +3 -2
  59. package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.d.ts +1 -1
  60. package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.js +15 -1
  61. package/dist/generators/ts/_ObjectType/IdentifierProperty.d.ts +6 -6
  62. package/dist/generators/ts/_ObjectType/IdentifierProperty.js +59 -29
  63. package/dist/generators/ts/_ObjectType/LazyShaclProperty.d.ts +14 -1
  64. package/dist/generators/ts/_ObjectType/LazyShaclProperty.js +89 -11
  65. package/dist/generators/ts/_ObjectType/Property.d.ts +9 -3
  66. package/dist/generators/ts/_ObjectType/ShaclProperty.d.ts +1 -1
  67. package/dist/generators/ts/_ObjectType/ShaclProperty.js +14 -2
  68. package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +1 -1
  69. package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +1 -1
  70. package/dist/generators/ts/_ObjectType/classDeclaration.js +16 -12
  71. package/dist/generators/ts/_ObjectType/createFunctionDeclaration.js +22 -10
  72. package/dist/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.js +3 -1
  73. package/dist/generators/ts/_ObjectType/graphqlTypeVariableStatement.js +14 -2
  74. package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.js +71 -79
  75. package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.js +3 -3
  76. package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.js +1 -1
  77. package/dist/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +6 -2
  78. package/dist/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.js +19 -12
  79. package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +5 -5
  80. package/dist/generators/ts/sparqlObjectSetClassDeclaration.js +6 -6
  81. package/dist/input/PropertyPath.d.ts +1 -2
  82. package/dist/input/PropertyPath.js +6 -8
  83. package/dist/input/ShapesGraph.js +4 -8
  84. package/dist/input/generated.d.ts +96 -54
  85. package/dist/input/generated.js +1350 -744
  86. package/package.json +5 -5
  87. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.d.ts +0 -12
  88. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +0 -193
  89. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.d.ts +0 -12
  90. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.js +0 -29
  91. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.d.ts +0 -12
  92. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.js +0 -43
  93. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.d.ts +0 -14
  94. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.js +0 -21
  95. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.d.ts +0 -15
  96. package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.js +0 -60
@@ -28,6 +28,19 @@ export class PrimitiveType extends LiteralType {
28
28
  fromJsonExpression({ variables, }) {
29
29
  return variables.value;
30
30
  }
31
+ fromRdfExpressionChain({ variables, }) {
32
+ return {
33
+ ...super.fromRdfExpressionChain({ variables }),
34
+ languageIn: undefined,
35
+ valueTo: `chain(values => values.chainMap(value => ${this.fromRdfResourceValueExpression({
36
+ variables: {
37
+ predicate: variables.predicate,
38
+ resource: variables.resource,
39
+ resourceValue: "value",
40
+ },
41
+ })}))`,
42
+ };
43
+ }
31
44
  graphqlResolveExpression({ variables, }) {
32
45
  return variables.value;
33
46
  }
@@ -41,12 +54,12 @@ export class PrimitiveType extends LiteralType {
41
54
  }
42
55
  return snippetDeclarations;
43
56
  }
57
+ sparqlWherePatterns(parameters) {
58
+ return super.sparqlWherePatterns({ ...parameters, ignoreLanguageIn: true });
59
+ }
44
60
  toJsonExpression({ variables, }) {
45
61
  return variables.value;
46
62
  }
47
- propertyFilterRdfResourceValuesExpression({ variables, }) {
48
- return variables.resourceValues;
49
- }
50
63
  }
51
64
  __decorate([
52
65
  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
  }
@@ -4,7 +4,7 @@ export declare namespace SnippetDeclarations {
4
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
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
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}";
7
+ const LazyObjectSet = "/**\n * Type of lazy properties that return a set of objects. This is a class instead of an interface so it can be instanceof'd elsewhere.\n */\nexport class $LazyObjectSet<ObjectIdentifierT extends rdfjs.BlankNode | rdfjs.NamedNode, ResolvedObjectT extends { $identifier: ObjectIdentifierT }, StubObjectT extends { $identifier: ObjectIdentifierT }> {\n private readonly resolver: (identifiers: readonly ObjectIdentifierT[]) => Promise<purify.Either<Error, readonly ResolvedObjectT[]>>;\n readonly stubs: readonly StubObjectT[];\n\n constructor({ resolver, stubs }: {\n resolver: (identifiers: readonly ObjectIdentifierT[]) => Promise<purify.Either<Error, readonly ResolvedObjectT[]>>,\n stubs: readonly StubObjectT[]\n }) {\n this.resolver = resolver;\n this.stubs = stubs;\n }\n\n async resolve(options?: { limit?: number; offset?: number }): Promise<purify.Either<Error, readonly ResolvedObjectT[]>> {\n if (this.stubs.length === 0) {\n return purify.Either.of([]);\n }\n\n const limit = options?.limit ?? Number.MAX_SAFE_INTEGER;\n if (limit <= 0) {\n return purify.Either.of([]);\n }\n\n let offset = options?.offset ?? 0;\n if (offset < 0) {\n offset = 0;\n }\n\n return await this.resolver(this.stubs.slice(offset, offset + limit).map(stub => stub.$identifier));\n }\n}";
8
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
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
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}";
@@ -215,11 +215,22 @@ export class ${syntheticNamePrefix}LazyObjectSet<ObjectIdentifierT extends rdfjs
215
215
  this.stubs = stubs;
216
216
  }
217
217
 
218
- async resolve(): Promise<purify.Either<Error, readonly ResolvedObjectT[]>> {
218
+ async resolve(options?: { limit?: number; offset?: number }): Promise<purify.Either<Error, readonly ResolvedObjectT[]>> {
219
219
  if (this.stubs.length === 0) {
220
220
  return purify.Either.of([]);
221
221
  }
222
- return await this.resolver(this.stubs.map(stub => stub.${syntheticNamePrefix}identifier));
222
+
223
+ const limit = options?.limit ?? Number.MAX_SAFE_INTEGER;
224
+ if (limit <= 0) {
225
+ return purify.Either.of([]);
226
+ }
227
+
228
+ let offset = options?.offset ?? 0;
229
+ if (offset < 0) {
230
+ offset = 0;
231
+ }
232
+
233
+ return await this.resolver(this.stubs.slice(offset, offset + limit).map(stub => stub.${syntheticNamePrefix}identifier));
223
234
  }
224
235
  }`;
225
236
  SnippetDeclarations.LazyOptionalObject = `\
@@ -6,9 +6,9 @@ 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 fromRdfResourceValueExpression({ variables, }: Parameters<PrimitiveType<string>["fromRdfResourceValueExpression"]>[0]): string;
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
12
  toRdfExpression({ variables, }: Parameters<PrimitiveType<string>["toRdfExpression"]>[0]): string;
13
13
  }
14
14
  //# sourceMappingURL=StringType.d.ts.map
@@ -37,6 +37,14 @@ export class StringType extends PrimitiveType {
37
37
  }
38
38
  return this.typeof;
39
39
  }
40
+ fromRdfResourceValueExpression({ variables, }) {
41
+ let expression = `${variables.resourceValue}.toString()`;
42
+ if (this.primitiveIn.length > 0) {
43
+ const eitherTypeParameters = `<Error, ${this.name}>`;
44
+ 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 })})); } })`;
45
+ }
46
+ return expression;
47
+ }
40
48
  hashStatements({ variables, }) {
41
49
  return [`${variables.hasher}.update(${variables.value});`];
42
50
  }
@@ -50,14 +58,6 @@ export class StringType extends PrimitiveType {
50
58
  return `${variables.zod}.enum(${JSON.stringify(this.primitiveIn)})`;
51
59
  }
52
60
  }
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;
60
- }
61
61
  toRdfExpression({ variables, }) {
62
62
  return this.primitiveDefaultValue
63
63
  .map((defaultValue) => `${variables.value} !== "${defaultValue}" ? ${variables.value} : undefined`)
@@ -30,7 +30,13 @@ 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
+ protected fromRdfExpressionChain({ variables, }: Parameters<Type["fromRdfExpression"]>[0]): {
35
+ defaultValue?: string;
36
+ hasValues?: string;
37
+ languageIn?: string;
38
+ valueTo?: string;
39
+ };
34
40
  graphqlResolveExpression(_parameters: Parameters<Type["graphqlResolveExpression"]>[0]): string;
35
41
  hashStatements({ variables, }: Parameters<Type["hashStatements"]>[0]): readonly string[];
36
42
  jsonUiSchemaElement(): Maybe<string>;
@@ -40,23 +46,5 @@ export declare class TermType<ConstantTermT extends Literal | NamedNode = Litera
40
46
  toJsonExpression({ variables, }: Parameters<Type["toJsonExpression"]>[0]): string;
41
47
  toRdfExpression({ variables, }: Parameters<Type["toRdfExpression"]>[0]): string;
42
48
  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
49
  }
62
50
  //# sourceMappingURL=TermType.d.ts.map
@@ -120,31 +120,51 @@ export class TermType extends Type {
120
120
  : `((${variables.value}.termType === "${nodeKind}") ? (${valueToNodeKind}) : (${expression}))`;
121
121
  }, "");
122
122
  }
123
- fromRdfExpression({ variables, }) {
124
- const chain = [
125
- this.propertyFilterRdfResourceValuesExpression({ variables }),
126
- ];
127
- // Have an rdfjsResource.Resource.Values here
128
- if (this.hasValues.length === 1) {
129
- chain.push(`find(value => value.toTerm().equals(${rdfjsTermExpression(this.hasValues[0])}))`);
130
- }
131
- else {
132
- chain.push("head()");
123
+ fromRdfExpression(parameters) {
124
+ // invariant(
125
+ // this.nodeKinds.has("Literal") &&
126
+ // (this.nodeKinds.has("BlankNode") || this.nodeKinds.has("NamedNode")),
127
+ // "IdentifierType and LiteralType should override",
128
+ // );
129
+ const chain = this.fromRdfExpressionChain(parameters);
130
+ const { variables } = parameters;
131
+ return [
132
+ variables.resourceValues,
133
+ chain.defaultValue,
134
+ chain.hasValues,
135
+ chain.languageIn,
136
+ chain.valueTo,
137
+ ]
138
+ .filter((_) => typeof _ !== "undefined")
139
+ .join(".");
140
+ }
141
+ fromRdfExpressionChain({ variables, }) {
142
+ let valueToExpression = "purify.Either.of<Error, rdfjs.BlankNode | rdfjs.Literal | rdfjs.NamedNode>(value.toTerm())";
143
+ if (this.nodeKinds.size < 3) {
144
+ const eitherTypeParameters = `<Error, ${this.name}>`;
145
+ valueToExpression = `${valueToExpression}.chain(term => {
146
+ switch (term.termType) {
147
+ ${[...this.nodeKinds].map((nodeKind) => `case "${nodeKind}":`).join("\n")} return purify.Either.of${eitherTypeParameters}(term);
148
+ default: return purify.Left${eitherTypeParameters}(new rdfjsResource.Resource.MistypedValueError(${objectInitializer({ actualValue: "term", expectedValueType: JSON.stringify(this.name), focusResource: variables.resource, predicate: variables.predicate })}));
149
+ }})`;
133
150
  }
134
- // Have an rdfjsResource.Resource.Value here
135
- this.defaultValue.ifJust((defaultValue) => {
136
- // alt the default value before trying to convert the rdfjsResource.Resource.Value to the type
137
- chain.push(`alt(purify.Either.of(new rdfjsResource.Resource.Value(${objectInitializer({ subject: variables.resource, predicate: variables.predicate, object: rdfjsTermExpression(defaultValue) })})))`);
138
- });
139
- // Last step: convert the rdfjsResource.Resource.Value to the type
140
- chain.push(`chain(value => ${this.propertyFromRdfResourceValueExpression({
141
- variables: {
142
- predicate: variables.predicate,
143
- resource: variables.resource,
144
- resourceValue: "value",
145
- },
146
- })})`);
147
- return chain.join(".");
151
+ return {
152
+ defaultValue: this.defaultValue
153
+ .map((defaultValue) => `map(values => values.length > 0 ? values : new rdfjsResource.Resource.Value(${objectInitializer({ subject: variables.resource, predicate: variables.predicate, object: rdfjsTermExpression(defaultValue) })}).toValues())`)
154
+ .extract(),
155
+ hasValues: this.hasValues.length > 0
156
+ ? `chain(values => {
157
+ for (const hasValue of [${this.hasValues.map(rdfjsTermExpression).join(", ")}]) {
158
+ const findResult = values.find(value => value.toTerm().equals(hasValue));
159
+ if (findResult.isLeft()) {
160
+ return findResult;
161
+ }
162
+ }
163
+ return purify.Either.of<Error, rdfjsResource.Resource.Values<rdfjsResource.Resource.Value>>(values);
164
+ })`
165
+ : undefined,
166
+ valueTo: `chain(values => values.chainMap(value => ${valueToExpression}))`,
167
+ };
148
168
  }
149
169
  graphqlResolveExpression(_parameters) {
150
170
  throw new Error("not implemented");
@@ -231,33 +251,6 @@ export class TermType extends Type {
231
251
  }
232
252
  return imports;
233
253
  }
234
- /**
235
- * Filter the rdfjsResource.Resource.Values to those that are relevant to the type.
236
- *
237
- * This is done before
238
- */
239
- propertyFilterRdfResourceValuesExpression({ variables, }) {
240
- return variables.resourceValues;
241
- }
242
- /**
243
- * Convert an rdfjsResource.Resource.Value to a value of this type.
244
- * @param variables
245
- * @protected
246
- */
247
- propertyFromRdfResourceValueExpression({ variables, }) {
248
- invariant(this.nodeKinds.has("Literal") &&
249
- (this.nodeKinds.has("BlankNode") || this.nodeKinds.has("NamedNode")), "IdentifierType and LiteralType should override");
250
- let expression = `purify.Either.of<Error, rdfjs.BlankNode | rdfjs.Literal | rdfjs.NamedNode>(${variables.resourceValue}.toTerm())`;
251
- if (this.nodeKinds.size < 3) {
252
- const eitherTypeParameters = `<Error, ${this.name}>`;
253
- expression = `${expression}.chain(term => {
254
- switch (term.termType) {
255
- ${[...this.nodeKinds].map((nodeKind) => `case "${nodeKind}":`).join("\n")} return purify.Either.of${eitherTypeParameters}(term);
256
- default: return purify.Left${eitherTypeParameters}(new rdfjsResource.Resource.MistypedValueError(${objectInitializer({ actualValue: "term", expectedValueType: JSON.stringify(this.name), focusResource: variables.resource, predicate: variables.predicate })}));
257
- }})`;
258
- }
259
- return expression;
260
- }
261
254
  }
262
255
  __decorate([
263
256
  Memoize()
@@ -28,7 +28,10 @@ export class TsGenerator {
28
28
  }
29
29
  addStatements({ objectTypes, objectUnionTypes, sourceFile, }) {
30
30
  // sourceFile.addStatements(this.configuration.dataFactoryImport);
31
- sourceFile.addStatements('import N3, { DataFactory as dataFactory } from "n3"');
31
+ sourceFile.addStatements([
32
+ 'import { DataFactory as dataFactory, StoreFactory as _DatasetFactory } from "n3";',
33
+ "const datasetFactory: rdfjs.DatasetCoreFactory = new _DatasetFactory();",
34
+ ]);
32
35
  const declaredTypes = [
33
36
  ...objectTypes,
34
37
  ...objectUnionTypes,
@@ -50,8 +50,15 @@ export declare abstract class Type {
50
50
  };
51
51
  }): string;
52
52
  /**
53
- * An expression that converts a rdfjsResource.Resource.Values to a purify.Either of value/values
54
- * of this type for a property.
53
+ * An expression that converts a purify.Either<Error, rdfjsResource.Resource.Values<rdfjsResource.Resource.Value>> to
54
+ * (1) a purify.Either<Error, rdfjsResource.Resource.Values<this type>> if this is an item type (identifier, object, et al.) or
55
+ * (2) a purify.Either<Error, cardinality type> if this is a cardinality type
56
+ *
57
+ * Some types need to filter on the set of all objects/values of a (subject, predicate). For example, all sh:hasValue values must be present in the set for any values
58
+ * to be considered valid. Similar
59
+ *
60
+ * Values may also need to be sorted. For example, applying sh:languageIn should sort the values in the order of the specified languages so that the first value
61
+ * (if it exists) is always of the first specified language -- a common situation when sh:maxCount is 1.
55
62
  */
56
63
  abstract fromRdfExpression(parameters: {
57
64
  variables: {
@@ -69,6 +76,7 @@ export declare abstract class Type {
69
76
  */
70
77
  abstract graphqlResolveExpression(parameters: {
71
78
  variables: {
79
+ args: string;
72
80
  value: string;
73
81
  };
74
82
  }): string;
@@ -152,6 +160,7 @@ export declare abstract class Type {
152
160
  allowIgnoreRdfType: boolean;
153
161
  context: "object";
154
162
  variables: {
163
+ languageIn: string;
155
164
  object: string;
156
165
  predicate: string;
157
166
  subject: string;
@@ -161,6 +170,7 @@ export declare abstract class Type {
161
170
  allowIgnoreRdfType: boolean;
162
171
  context: "subject";
163
172
  variables: {
173
+ languageIn: string;
164
174
  subject: string;
165
175
  variablePrefix: string;
166
176
  };
@@ -66,6 +66,7 @@ export class Type {
66
66
  allowIgnoreRdfType,
67
67
  context: "subject",
68
68
  variables: {
69
+ languageIn: variables.languageIn,
69
70
  subject: variables.object,
70
71
  variablePrefix: variables.object.substring(objectPrefix.length, variables.object.length - objectSuffix.length),
71
72
  },
@@ -2,9 +2,17 @@ import type * as ast from "../../ast/index.js";
2
2
  import { ObjectType } from "./ObjectType.js";
3
3
  import type { Type } from "./Type.js";
4
4
  export declare class TypeFactory {
5
+ private cachedBooleanType;
6
+ private cachedDateType;
7
+ private cachedDateTimeType;
8
+ private cachedFloatType;
9
+ private cachedIdentifierType;
10
+ private cachedIntType;
11
+ private cachedNamedIdentifierType;
5
12
  private cachedObjectTypePropertiesByIdentifier;
6
13
  private cachedObjectTypesByIdentifier;
7
14
  private cachedObjectUnionTypesByIdentifier;
15
+ private cachedStringType;
8
16
  createObjectTypeFromAstType(astType: ast.ObjectType): ObjectType;
9
17
  createTypeFromAstType(astType: ast.Type): Type;
10
18
  private createObjectTypePropertyFromAstProperty;