@shaclmate/compiler 2.0.24 → 3.0.1

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 (44) hide show
  1. package/dist/_ShapesGraphToAstTransformer/transformShapeToAstLiteralType.js +1 -1
  2. package/dist/generators/ts/BooleanType.d.ts +2 -1
  3. package/dist/generators/ts/BooleanType.js +9 -4
  4. package/dist/generators/ts/DateTimeType.d.ts +2 -1
  5. package/dist/generators/ts/DateTimeType.js +9 -4
  6. package/dist/generators/ts/IdentifierType.d.ts +1 -6
  7. package/dist/generators/ts/IdentifierType.js +1 -1
  8. package/dist/generators/ts/Import.d.ts +2 -1
  9. package/dist/generators/ts/Import.js +29 -24
  10. package/dist/generators/ts/ListType.js +2 -2
  11. package/dist/generators/ts/LiteralType.d.ts +3 -7
  12. package/dist/generators/ts/LiteralType.js +53 -51
  13. package/dist/generators/ts/NumberType.d.ts +2 -1
  14. package/dist/generators/ts/NumberType.js +9 -4
  15. package/dist/generators/ts/ObjectType.d.ts +2 -0
  16. package/dist/generators/ts/ObjectType.js +14 -3
  17. package/dist/generators/ts/ObjectUnionType.d.ts +1 -0
  18. package/dist/generators/ts/ObjectUnionType.js +7 -4
  19. package/dist/generators/ts/PrimitiveType.d.ts +1 -19
  20. package/dist/generators/ts/PrimitiveType.js +4 -14
  21. package/dist/generators/ts/SnippetDeclarations.d.ts +2 -1
  22. package/dist/generators/ts/SnippetDeclarations.js +28 -1
  23. package/dist/generators/ts/StringType.d.ts +2 -1
  24. package/dist/generators/ts/StringType.js +14 -7
  25. package/dist/generators/ts/TermType.d.ts +12 -1
  26. package/dist/generators/ts/TermType.js +11 -0
  27. package/dist/generators/ts/TsGenerator.js +24 -15
  28. package/dist/generators/ts/Type.d.ts +7 -8
  29. package/dist/generators/ts/Type.js +1 -1
  30. package/dist/generators/ts/TypeFactory.js +3 -2
  31. package/dist/generators/ts/_ObjectType/Property.d.ts +2 -2
  32. package/dist/generators/ts/_ObjectType/ShaclProperty.js +1 -1
  33. package/dist/generators/ts/_ObjectType/jsonFunctionDeclarations.js +1 -1
  34. package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.js +30 -11
  35. package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.js +3 -3
  36. package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.js +1 -1
  37. package/dist/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +31 -15
  38. package/dist/generators/ts/forwardingObjectSetClassDeclaration.d.ts +8 -0
  39. package/dist/generators/ts/forwardingObjectSetClassDeclaration.js +29 -0
  40. package/dist/generators/ts/objectSetDeclarations.js +2 -0
  41. package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +21 -14
  42. package/dist/generators/ts/rdfjsTermExpression.js +3 -3
  43. package/dist/input/PropertyPath.d.ts +1 -1
  44. package/package.json +7 -14
@@ -30,7 +30,7 @@ export function transformShapeToAstLiteralType(shape, shapeStack) {
30
30
  hasValues: literalHasValues,
31
31
  in_: literalIn,
32
32
  kind: "LiteralType",
33
- languageIn: shape.constraints.languageIn,
33
+ languageIn: [...new Set(shape.constraints.languageIn)],
34
34
  maxExclusive: shape.constraints.maxExclusive,
35
35
  maxInclusive: shape.constraints.maxInclusive,
36
36
  minExclusive: shape.constraints.minExclusive,
@@ -1,4 +1,5 @@
1
1
  import { PrimitiveType } from "./PrimitiveType.js";
2
+ import type { TermType } from "./TermType.js";
2
3
  import { Type } from "./Type.js";
3
4
  export declare class BooleanType extends PrimitiveType<boolean> {
4
5
  readonly kind = "BooleanType";
@@ -7,7 +8,7 @@ export declare class BooleanType extends PrimitiveType<boolean> {
7
8
  get graphqlName(): Type.GraphqlName;
8
9
  get name(): string;
9
10
  jsonZodSchema({ variables, }: Parameters<Type["jsonZodSchema"]>[0]): ReturnType<Type["jsonZodSchema"]>;
10
- fromRdfResourceValueExpression({ variables, }: Parameters<PrimitiveType<boolean>["fromRdfResourceValueExpression"]>[0]): string;
11
+ protected fromRdfExpressionChain({ variables, }: Parameters<TermType["fromRdfExpressionChain"]>[0]): ReturnType<TermType["fromRdfExpressionChain"]>;
11
12
  toRdfExpression({ variables, }: Parameters<PrimitiveType<string>["toRdfExpression"]>[0]): string;
12
13
  }
13
14
  //# sourceMappingURL=BooleanType.d.ts.map
@@ -43,13 +43,18 @@ export class BooleanType extends PrimitiveType {
43
43
  }
44
44
  return `${variables.zod}.boolean()`;
45
45
  }
46
- fromRdfResourceValueExpression({ variables, }) {
47
- let expression = `${variables.resourceValue}.toBoolean()`;
46
+ fromRdfExpressionChain({ variables, }) {
47
+ let fromRdfResourceValueExpression = "value.toBoolean()";
48
48
  if (this.primitiveIn.length === 1) {
49
49
  const eitherTypeParameters = `<Error, ${this.name}>`;
50
- expression = `${expression}.chain(value => value === ${this.primitiveIn[0]} ? purify.Either.of${eitherTypeParameters}(value) : purify.Left${eitherTypeParameters}(new rdfjsResource.Resource.MistypedValueError(${objectInitializer({ actualValue: "rdfLiteral.toRdf(value)", expectedValueType: JSON.stringify(this.name), focusResource: variables.resource, predicate: variables.predicate })})))`;
50
+ fromRdfResourceValueExpression = `${fromRdfResourceValueExpression}.chain(value => value === ${this.primitiveIn[0]} ? purify.Either.of${eitherTypeParameters}(value) : purify.Left${eitherTypeParameters}(new rdfjsResource.Resource.MistypedValueError(${objectInitializer({ actualValue: "rdfLiteral.toRdf(value)", expectedValueType: JSON.stringify(this.name), focusResource: variables.resource, predicate: variables.predicate })})))`;
51
51
  }
52
- return expression;
52
+ return {
53
+ ...super.fromRdfExpressionChain({ variables }),
54
+ languageIn: undefined,
55
+ preferredLanguages: undefined,
56
+ valueTo: `chain(values => values.chainMap(value => ${fromRdfResourceValueExpression}))`,
57
+ };
53
58
  }
54
59
  toRdfExpression({ variables, }) {
55
60
  return this.primitiveDefaultValue
@@ -1,5 +1,6 @@
1
1
  import type { NamedNode } from "@rdfjs/types";
2
2
  import { PrimitiveType } from "./PrimitiveType.js";
3
+ import type { TermType } from "./TermType.js";
3
4
  import { Type } from "./Type.js";
4
5
  export declare class DateTimeType extends PrimitiveType<Date> {
5
6
  protected readonly xsdDatatype: NamedNode;
@@ -15,7 +16,7 @@ export declare class DateTimeType extends PrimitiveType<Date> {
15
16
  fromJsonExpression({ variables, }: Parameters<Type["fromJsonExpression"]>[0]): string;
16
17
  hashStatements({ variables, }: Parameters<Type["hashStatements"]>[0]): readonly string[];
17
18
  jsonZodSchema({ variables, }: Parameters<Type["jsonZodSchema"]>[0]): ReturnType<Type["jsonZodSchema"]>;
18
- fromRdfResourceValueExpression({ variables, }: Parameters<PrimitiveType<number>["fromRdfResourceValueExpression"]>[0]): string;
19
+ protected fromRdfExpressionChain({ variables, }: Parameters<TermType["fromRdfExpressionChain"]>[0]): ReturnType<TermType["fromRdfExpressionChain"]>;
19
20
  snippetDeclarations({ features, }: Parameters<PrimitiveType<Date>["snippetDeclarations"]>[0]): readonly string[];
20
21
  toJsonExpression({ variables, }: Parameters<PrimitiveType<Date>["toJsonExpression"]>[0]): string;
21
22
  toRdfExpression({ variables, }: Parameters<PrimitiveType<Date>["toRdfExpression"]>[0]): string;
@@ -54,13 +54,18 @@ export class DateTimeType extends PrimitiveType {
54
54
  jsonZodSchema({ variables, }) {
55
55
  return `${variables.zod}.string().${this.zodDatatype}()`;
56
56
  }
57
- fromRdfResourceValueExpression({ variables, }) {
58
- let expression = `${variables.resourceValue}.toDate()`;
57
+ fromRdfExpressionChain({ variables, }) {
58
+ let fromRdfResourceValueExpression = "value.toDate()";
59
59
  if (this.primitiveIn.length > 0) {
60
60
  const eitherTypeParameters = `<Error, ${this.name}>`;
61
- expression = `${expression}.chain(value => { ${this.primitiveIn.map((value) => `if (value.getTime() === ${value.getTime()}) { return purify.Either.of${eitherTypeParameters}(value); }`).join(" ")} return purify.Left${eitherTypeParameters}(new rdfjsResource.Resource.MistypedValueError(${objectInitializer({ actualValue: `rdfLiteral.toRdf(value, ${objectInitializer({ dataFactory: "dataFactory", datatype: rdfjsTermExpression(this.xsdDatatype) })})`, expectedValueType: JSON.stringify(this.name), focusResource: variables.resource, predicate: variables.predicate })})); })`;
61
+ fromRdfResourceValueExpression = `${fromRdfResourceValueExpression}.chain(value => { ${this.primitiveIn.map((value) => `if (value.getTime() === ${value.getTime()}) { return purify.Either.of${eitherTypeParameters}(value); }`).join(" ")} return purify.Left${eitherTypeParameters}(new rdfjsResource.Resource.MistypedValueError(${objectInitializer({ actualValue: `rdfLiteral.toRdf(value, ${objectInitializer({ dataFactory: "dataFactory", datatype: rdfjsTermExpression(this.xsdDatatype) })})`, expectedValueType: JSON.stringify(this.name), focusResource: variables.resource, predicate: variables.predicate })})); })`;
62
62
  }
63
- return expression;
63
+ return {
64
+ ...super.fromRdfExpressionChain({ variables }),
65
+ languageIn: undefined,
66
+ preferredLanguages: undefined,
67
+ valueTo: `chain(values => values.chainMap(value => ${fromRdfResourceValueExpression}))`,
68
+ };
64
69
  }
65
70
  snippetDeclarations({ features, }) {
66
71
  const snippetDeclarations = [];
@@ -12,12 +12,7 @@ export declare class IdentifierType extends TermType<NamedNode, BlankNode | Name
12
12
  get name(): string;
13
13
  get toStringFunctionDeclaration(): VariableStatementStructure;
14
14
  fromJsonExpression({ variables, }: Parameters<TermType<NamedNode, BlankNode | NamedNode>["fromJsonExpression"]>[0]): string;
15
- protected fromRdfExpressionChain({ variables, }: Parameters<Type["fromRdfExpression"]>[0]): {
16
- defaultValue?: string;
17
- hasValues?: string;
18
- languageIn?: string;
19
- valueTo?: string;
20
- };
15
+ protected fromRdfExpressionChain({ variables, }: Parameters<TermType["fromRdfExpressionChain"]>[0]): ReturnType<TermType["fromRdfExpressionChain"]>;
21
16
  graphqlResolveExpression({ variables: { value }, }: Parameters<Type["graphqlResolveExpression"]>[0]): string;
22
17
  jsonZodSchema({ variables, }: Parameters<TermType<NamedNode, BlankNode | NamedNode>["jsonZodSchema"]>[0]): ReturnType<TermType<NamedNode, BlankNode | NamedNode>["jsonZodSchema"]>;
23
18
  toJsonExpression({ variables, }: Parameters<TermType<NamedNode, BlankNode | NamedNode>["toJsonExpression"]>[0]): string;
@@ -137,7 +137,7 @@ export class IdentifierType extends TermType {
137
137
  throw new Error("not implemented");
138
138
  }
139
139
  return {
140
- ...super.fromRdfExpressionChain,
140
+ ...super.fromRdfExpressionChain({ variables }),
141
141
  valueTo: `chain(values => values.chainMap(value => ${valueToExpression}))`,
142
142
  };
143
143
  }
@@ -4,6 +4,8 @@ export type Import = ImportDeclarationStructure | string;
4
4
  * Singleton values for common imports.
5
5
  */
6
6
  export declare namespace Import {
7
+ const DATA_FACTORY: Import;
8
+ const DATASET_FACTORY: Import;
7
9
  const GRAPHQL: Import;
8
10
  const GRAPHQL_SCALARS: Import;
9
11
  const PURIFY: Import;
@@ -14,6 +16,5 @@ export declare namespace Import {
14
16
  const SPARQLJS: Import;
15
17
  const UUID: Import;
16
18
  const ZOD: Import;
17
- const ZOD_TO_JSON_SCHEMA: Import;
18
19
  }
19
20
  //# sourceMappingURL=Import.d.ts.map
@@ -4,61 +4,66 @@ import { StructureKind } from "ts-morph";
4
4
  */
5
5
  export var Import;
6
6
  (function (Import) {
7
+ Import.DATA_FACTORY = {
8
+ kind: StructureKind.ImportDeclaration,
9
+ moduleSpecifier: "@shaclmate/runtime",
10
+ namedImports: ["dataFactory"],
11
+ };
12
+ Import.DATASET_FACTORY = {
13
+ kind: StructureKind.ImportDeclaration,
14
+ moduleSpecifier: "@shaclmate/runtime",
15
+ namedImports: ["datasetFactory"],
16
+ };
7
17
  Import.GRAPHQL = {
8
18
  kind: StructureKind.ImportDeclaration,
9
- moduleSpecifier: "graphql",
10
- namespaceImport: "graphql",
19
+ moduleSpecifier: "@shaclmate/runtime",
20
+ namedImports: ["graphql"],
11
21
  };
12
22
  Import.GRAPHQL_SCALARS = {
13
23
  kind: StructureKind.ImportDeclaration,
14
- moduleSpecifier: "graphql-scalars",
15
- namespaceImport: "graphqlScalars",
24
+ moduleSpecifier: "@shaclmate/runtime",
25
+ namedImports: ["graphqlScalars"],
16
26
  };
17
27
  Import.PURIFY = {
18
28
  kind: StructureKind.ImportDeclaration,
19
- moduleSpecifier: "purify-ts",
20
- namespaceImport: "purify",
29
+ moduleSpecifier: "@shaclmate/runtime",
30
+ namedImports: ["purify"],
21
31
  };
22
32
  Import.RDF_LITERAL = {
23
33
  kind: StructureKind.ImportDeclaration,
24
- moduleSpecifier: "rdf-literal",
25
- namespaceImport: "rdfLiteral",
34
+ moduleSpecifier: "@shaclmate/runtime",
35
+ namedImports: ["rdfLiteral"],
26
36
  };
27
37
  Import.RDFJS_RESOURCE = {
28
38
  kind: StructureKind.ImportDeclaration,
29
- moduleSpecifier: "rdfjs-resource",
30
- namespaceImport: "rdfjsResource",
39
+ moduleSpecifier: "@shaclmate/runtime",
40
+ namedImports: ["rdfjsResource"],
31
41
  };
32
42
  Import.RDFJS_TYPES = {
33
43
  isTypeOnly: true,
34
44
  kind: StructureKind.ImportDeclaration,
35
- moduleSpecifier: "@rdfjs/types",
36
- namespaceImport: "rdfjs",
45
+ moduleSpecifier: "@shaclmate/runtime",
46
+ namedImports: ["rdfjs"],
37
47
  };
38
48
  Import.SHA256 = {
39
49
  kind: StructureKind.ImportDeclaration,
40
- moduleSpecifier: "js-sha256",
50
+ moduleSpecifier: "@shaclmate/runtime",
41
51
  namedImports: ["sha256"],
42
52
  };
43
53
  Import.SPARQLJS = {
44
54
  kind: StructureKind.ImportDeclaration,
45
- moduleSpecifier: "sparqljs",
46
- namespaceImport: "sparqljs",
55
+ moduleSpecifier: "@shaclmate/runtime",
56
+ namedImports: ["sparqljs"],
47
57
  };
48
58
  Import.UUID = {
49
59
  kind: StructureKind.ImportDeclaration,
50
- moduleSpecifier: "uuid",
51
- namespaceImport: "uuid",
60
+ moduleSpecifier: "@shaclmate/runtime",
61
+ namedImports: ["uuid"],
52
62
  };
53
63
  Import.ZOD = {
54
64
  kind: StructureKind.ImportDeclaration,
55
- moduleSpecifier: "zod",
56
- namedImports: [{ alias: "zod", name: "z" }],
57
- };
58
- Import.ZOD_TO_JSON_SCHEMA = {
59
- kind: StructureKind.ImportDeclaration,
60
- moduleSpecifier: "zod-to-json-schema",
61
- namedImports: [{ name: "zodToJsonSchema" }],
65
+ moduleSpecifier: "@shaclmate/runtime",
66
+ namedImports: ["zod"],
62
67
  };
63
68
  })(Import || (Import = {}));
64
69
  //# sourceMappingURL=Import.js.map
@@ -189,7 +189,7 @@ export class ListType extends Type {
189
189
  allowIgnoreRdfType: true,
190
190
  context: "subject",
191
191
  variables: {
192
- languageIn: parameters.variables.languageIn,
192
+ preferredLanguages: parameters.variables.preferredLanguages,
193
193
  subject: item0Variable,
194
194
  variablePrefix: variablePrefix("Item0"),
195
195
  },
@@ -223,7 +223,7 @@ export class ListType extends Type {
223
223
  allowIgnoreRdfType: true,
224
224
  context: "subject",
225
225
  variables: {
226
- languageIn: parameters.variables.languageIn,
226
+ preferredLanguages: parameters.variables.preferredLanguages,
227
227
  subject: itemNVariable,
228
228
  variablePrefix: variablePrefix("ItemN"),
229
229
  },
@@ -8,16 +8,12 @@ export declare class LiteralType extends TermType<Literal, Literal> {
8
8
  } & Omit<ConstructorParameters<typeof TermType<Literal, Literal>>[0], "nodeKinds">);
9
9
  get jsonName(): Type.JsonName;
10
10
  fromJsonExpression({ variables, }: Parameters<TermType<Literal, Literal>["fromJsonExpression"]>[0]): string;
11
- protected fromRdfExpressionChain({ variables, }: Parameters<Type["fromRdfExpression"]>[0]): {
12
- defaultValue?: string;
13
- hasValues?: string;
14
- languageIn?: string;
15
- valueTo?: string;
16
- };
11
+ protected fromRdfExpressionChain({ variables, }: Parameters<TermType<Literal>["fromRdfExpressionChain"]>[0]): ReturnType<TermType<Literal>["fromRdfExpressionChain"]>;
17
12
  hashStatements({ depth, variables, }: Parameters<TermType<Literal, Literal>["hashStatements"]>[0]): readonly string[];
18
13
  jsonZodSchema({ variables, }: Parameters<TermType<Literal, Literal>["jsonZodSchema"]>[0]): ReturnType<TermType<Literal, Literal>["jsonZodSchema"]>;
14
+ snippetDeclarations(parameters: Parameters<Type["snippetDeclarations"]>[0]): readonly string[];
19
15
  sparqlWherePatterns(parameters: Parameters<Type["sparqlWherePatterns"]>[0] & {
20
- ignoreLanguageIn?: boolean;
16
+ ignoreLiteralLanguage?: boolean;
21
17
  }): readonly string[];
22
18
  toJsonExpression({ variables, }: Parameters<TermType<Literal, Literal>["toJsonExpression"]>[0]): string;
23
19
  }
@@ -5,10 +5,12 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
7
  import { xsd } from "@tpluscode/rdf-ns-builders";
8
- import { invariant } from "ts-invariant";
9
8
  import { Memoize } from "typescript-memoize";
9
+ import { SnippetDeclarations } from "./SnippetDeclarations.js";
10
10
  import { TermType } from "./TermType.js";
11
11
  import { Type } from "./Type.js";
12
+ import { objectInitializer } from "./objectInitializer.js";
13
+ import { syntheticNamePrefix } from "./syntheticNamePrefix.js";
12
14
  export class LiteralType extends TermType {
13
15
  languageIn;
14
16
  constructor({ languageIn, ...superParameters }) {
@@ -27,44 +29,34 @@ export class LiteralType extends TermType {
27
29
  fromRdfExpressionChain({ variables, }) {
28
30
  return {
29
31
  ...super.fromRdfExpressionChain({ variables }),
30
- languageIn: `chain(values => {
31
- const literalValuesEither = values.chainMap(value => value.toLiteral());
32
- if (literalValuesEither.isLeft()) {
33
- return literalValuesEither;
34
- }
35
- const literalValues = literalValuesEither.unsafeCoerce();
36
-
37
- const nonUniqueLanguageIn = ${variables.languageIn} ?? ${JSON.stringify(this.languageIn)};
38
- if (nonUniqueLanguageIn.length === 0) {
39
- return purify.Either.of<Error, rdfjsResource.Resource.Values<rdfjs.Literal>>(literalValues);
40
- }
32
+ languageIn: this.languageIn.length > 0
33
+ ? `chain(values => values.chainMap(value => value.toLiteral().chain(literalValue => { switch (literalValue.language) { ${this.languageIn.map((languageIn) => `case "${languageIn}":`).join(" ")} return purify.Either.of(value); default: return purify.Left(new rdfjsResource.Resource.MistypedValueError(${objectInitializer({ actualValue: "literalValue", expectedValueType: JSON.stringify(this.name), focusResource: variables.resource, predicate: variables.predicate })})); } })))`
34
+ : undefined,
35
+ preferredLanguages: `chain(values => {
36
+ if (!${variables.preferredLanguages} || ${variables.preferredLanguages}.length === 0) {
37
+ return purify.Either.of<Error, rdfjsResource.Resource.Values<rdfjsResource.Resource.Value>>(values);
38
+ }
41
39
 
42
- let uniqueLanguageIn: string[];
43
- if (nonUniqueLanguageIn.length === 1) {
44
- uniqueLanguageIn = [nonUniqueLanguageIn[0]];
45
- } else {
46
- uniqueLanguageIn = [];
47
- for (const languageIn of nonUniqueLanguageIn) {
48
- if (uniqueLanguageIn.indexOf(languageIn) === -1) {
49
- uniqueLanguageIn.push(languageIn);
50
- }
40
+ const literalValuesEither = values.chainMap(value => value.toLiteral());
41
+ if (literalValuesEither.isLeft()) {
42
+ return literalValuesEither;
51
43
  }
52
- }
44
+ const literalValues = literalValuesEither.unsafeCoerce();
53
45
 
54
- // Return all literals for the first languageIn, then all literals for the second languageIn, etc.
55
- // Within a languageIn the literals may be in any order.
56
- let filteredLiteralValues: rdfjsResource.Resource.Values<rdfjs.Literal> | undefined;
57
- for (const languageIn of uniqueLanguageIn) {
58
- if (!filteredLiteralValues) {
59
- filteredLiteralValues = literalValues.filter(value => value.language === languageIn);
60
- } else {
61
- filteredLiteralValues = filteredLiteralValues.concat(...literalValues.filter(value => value.language === languageIn).toArray());
46
+ // Return all literals for the first preferredLanguage, then all literals for the second preferredLanguage, etc.
47
+ // Within a preferredLanguage the literals may be in any order.
48
+ let filteredLiteralValues: rdfjsResource.Resource.Values<rdfjs.Literal> | undefined;
49
+ for (const preferredLanguage of ${variables.preferredLanguages}) {
50
+ if (!filteredLiteralValues) {
51
+ filteredLiteralValues = literalValues.filter(value => value.language === preferredLanguage);
52
+ } else {
53
+ filteredLiteralValues = filteredLiteralValues.concat(...literalValues.filter(value => value.language === preferredLanguage).toArray());
54
+ }
62
55
  }
63
- }
64
56
 
65
- return purify.Either.of<Error, rdfjsResource.Resource.Values<rdfjs.Literal>>(filteredLiteralValues!);
66
- })`,
67
- valueTo: undefined,
57
+ return purify.Either.of<Error, rdfjsResource.Resource.Values<rdfjsResource.Resource.Value>>(filteredLiteralValues!.map(literalValue => new rdfjsResource.Resource.Value({ object: literalValue, predicate: ${variables.predicate}, subject: ${variables.resource} })));
58
+ })`,
59
+ valueTo: "chain(values => values.chainMap(value => value.toLiteral()))",
68
60
  };
69
61
  }
70
62
  hashStatements({ depth, variables, }) {
@@ -76,23 +68,32 @@ export class LiteralType extends TermType {
76
68
  jsonZodSchema({ variables, }) {
77
69
  return `${variables.zod}.object({ "@language": ${variables.zod}.string().optional(), "@type": ${variables.zod}.string().optional(), "@value": ${variables.zod}.string() })`;
78
70
  }
71
+ snippetDeclarations(parameters) {
72
+ let snippetDeclarations = super.snippetDeclarations(parameters);
73
+ const { features } = parameters;
74
+ if (features.has("sparql") && this.languageIn.length > 0) {
75
+ snippetDeclarations = snippetDeclarations.concat(SnippetDeclarations.arrayIntersection);
76
+ }
77
+ return snippetDeclarations;
78
+ }
79
79
  sparqlWherePatterns(parameters) {
80
- const { context, ignoreLanguageIn, variables } = parameters;
80
+ const { context, ignoreLiteralLanguage, variables } = parameters;
81
81
  const superPatterns = super.sparqlWherePatterns(parameters);
82
- if (ignoreLanguageIn || context === "subject") {
82
+ if (ignoreLiteralLanguage || context === "subject") {
83
83
  return superPatterns;
84
84
  }
85
- invariant(this.name.indexOf("rdfjs.Literal") !== -1, this.name);
86
- return superPatterns.concat(`...[(${variables.languageIn} && ${variables.languageIn}.length > 0) ? ${variables.languageIn} : ${JSON.stringify(this.languageIn)}]
87
- .filter(languagesIn => languagesIn.length > 0)
88
- .map(languagesIn =>
89
- languagesIn.map(languageIn =>
85
+ return superPatterns.concat(`...[${this.languageIn.length > 0
86
+ ? `[...${syntheticNamePrefix}arrayIntersection(${JSON.stringify(this.languageIn)}, ${variables.preferredLanguages} ?? [])]`
87
+ : `(${variables.preferredLanguages} ?? [])`}]
88
+ .filter(languages => languages.length > 0)
89
+ .map(languages =>
90
+ languages.map(language =>
90
91
  ({
91
92
  type: "operation" as const,
92
93
  operator: "=",
93
94
  args: [
94
95
  { type: "operation" as const, operator: "lang", args: [${variables.object}] },
95
- dataFactory.literal(languageIn)
96
+ dataFactory.literal(language)
96
97
  ]
97
98
  })
98
99
  )
@@ -100,15 +101,16 @@ export class LiteralType extends TermType {
100
101
  .map(langEqualsExpressions =>
101
102
  ({
102
103
  type: "filter" as const,
103
- expression:
104
- langEqualsExpressions.length === 1
105
- ? langEqualsExpressions[0]
106
- :
107
- {
108
- type: "operation" as const,
109
- operator: "||",
110
- args: langEqualsExpressions
111
- },
104
+ expression: langEqualsExpressions.reduce((reducedExpression, langEqualsExpression) => {
105
+ if (reducedExpression === null) {
106
+ return langEqualsExpression;
107
+ }
108
+ return {
109
+ type: "operation" as const,
110
+ operator: "||",
111
+ args: [reducedExpression, langEqualsExpression]
112
+ };
113
+ }, null as sparqljs.Expression | null) as sparqljs.Expression
112
114
  })
113
115
  )`);
114
116
  }
@@ -1,4 +1,5 @@
1
1
  import { PrimitiveType } from "./PrimitiveType.js";
2
+ import type { TermType } from "./TermType.js";
2
3
  import type { Type } from "./Type.js";
3
4
  export declare abstract class NumberType extends PrimitiveType<number> {
4
5
  readonly kind = "NumberType";
@@ -6,7 +7,7 @@ export declare abstract class NumberType extends PrimitiveType<number> {
6
7
  get conversions(): readonly Type.Conversion[];
7
8
  get name(): string;
8
9
  jsonZodSchema({ variables, }: Parameters<Type["jsonZodSchema"]>[0]): ReturnType<Type["jsonZodSchema"]>;
9
- protected fromRdfResourceValueExpression({ variables, }: Parameters<PrimitiveType<number>["fromRdfResourceValueExpression"]>[0]): string;
10
+ protected fromRdfExpressionChain({ variables, }: Parameters<TermType["fromRdfExpressionChain"]>[0]): ReturnType<TermType["fromRdfExpressionChain"]>;
10
11
  toRdfExpression({ variables, }: Parameters<PrimitiveType<string>["toRdfExpression"]>[0]): string;
11
12
  }
12
13
  //# sourceMappingURL=NumberType.d.ts.map
@@ -43,13 +43,18 @@ export class NumberType extends PrimitiveType {
43
43
  return `${variables.zod}.union([${this.primitiveIn.map((value) => `${variables.zod}.literal(${value})`).join(", ")}])`;
44
44
  }
45
45
  }
46
- fromRdfResourceValueExpression({ variables, }) {
47
- let expression = `${variables.resourceValue}.toNumber()`;
46
+ fromRdfExpressionChain({ variables, }) {
47
+ let fromRdfResourceValueExpression = "value.toNumber()";
48
48
  if (this.primitiveIn.length > 0) {
49
49
  const eitherTypeParameters = `<Error, ${this.name}>`;
50
- 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 })})); } })`;
50
+ fromRdfResourceValueExpression = `${fromRdfResourceValueExpression}.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 })})); } })`;
51
51
  }
52
- return expression;
52
+ return {
53
+ ...super.fromRdfExpressionChain({ variables }),
54
+ languageIn: undefined,
55
+ preferredLanguages: undefined,
56
+ valueTo: `chain(values => values.chainMap(value => ${fromRdfResourceValueExpression}))`,
57
+ };
53
58
  }
54
59
  toRdfExpression({ variables, }) {
55
60
  return this.primitiveDefaultValue
@@ -44,6 +44,8 @@ export declare class ObjectType extends DeclaredType {
44
44
  get conversions(): readonly Type.Conversion[];
45
45
  get declarationImports(): readonly Import[];
46
46
  get declarations(): (ClassDeclarationStructure | InterfaceDeclarationStructure | ModuleDeclarationStructure)[];
47
+ get descendantFromRdfTypes(): readonly NamedNode[];
48
+ get descendantFromRdfTypeVariables(): readonly string[];
47
49
  get descendantObjectTypes(): readonly ObjectType[];
48
50
  get discriminatorProperty(): Maybe<Type.DiscriminatorProperty>;
49
51
  get discriminatorValue(): string;
@@ -83,7 +83,6 @@ export class ObjectType extends DeclaredType {
83
83
  }
84
84
  if (this.features.has("json")) {
85
85
  imports.push(Import.ZOD);
86
- imports.push(Import.ZOD_TO_JSON_SCHEMA);
87
86
  }
88
87
  if (this.features.has("rdf")) {
89
88
  imports.push(Import.PURIFY);
@@ -122,6 +121,12 @@ export class ObjectType extends DeclaredType {
122
121
  }
123
122
  return declarations;
124
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
+ }
125
130
  get descendantObjectTypes() {
126
131
  return this.lazyDescendantObjectTypes();
127
132
  }
@@ -221,7 +226,7 @@ export class ObjectType extends DeclaredType {
221
226
  return `${this.staticModuleName}.${syntheticNamePrefix}fromJson(${variables.value}).unsafeCoerce()`;
222
227
  }
223
228
  fromRdfExpression({ variables, }) {
224
- return `${variables.resourceValues}.chain(values => values.chainMap(value => value.toResource().chain(resource => ${this.staticModuleName}.${syntheticNamePrefix}fromRdf(resource, { ...${variables.context}, ${variables.ignoreRdfType ? "ignoreRdfType: true, " : ""}languageIn: ${variables.languageIn}, objectSet: ${variables.objectSet} }))))`;
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} }))))`;
225
230
  }
226
231
  graphqlResolveExpression({ variables, }) {
227
232
  return variables.value;
@@ -299,7 +304,7 @@ export class ObjectType extends DeclaredType {
299
304
  return [
300
305
  `...${this.staticModuleName}.${syntheticNamePrefix}sparqlWherePatterns(${objectInitializer({
301
306
  ignoreRdfType: parameters.allowIgnoreRdfType ? true : undefined, // Can ignore the rdf:type when the object is nested
302
- languageIn: parameters.variables.languageIn,
307
+ preferredLanguages: parameters.variables.preferredLanguages,
303
308
  subject: parameters.variables.subject,
304
309
  variablePrefix: parameters.variables.variablePrefix,
305
310
  })})`,
@@ -348,6 +353,12 @@ __decorate([
348
353
  __decorate([
349
354
  Memoize()
350
355
  ], ObjectType.prototype, "conversions", null);
356
+ __decorate([
357
+ Memoize()
358
+ ], ObjectType.prototype, "descendantFromRdfTypes", null);
359
+ __decorate([
360
+ Memoize()
361
+ ], ObjectType.prototype, "descendantFromRdfTypeVariables", null);
351
362
  __decorate([
352
363
  Memoize()
353
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>>;
@@ -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.
@@ -279,7 +282,7 @@ return ${syntheticNamePrefix}strictEquals(left.${syntheticNamePrefix}type, right
279
282
  {
280
283
  hasQuestionToken: true,
281
284
  name: "options",
282
- type: `{ [_index: string]: any; ignoreRdfType?: boolean; languageIn?: readonly string[]; objectSet?: ${syntheticNamePrefix}ObjectSet }`,
285
+ type: `{ [_index: string]: any; ignoreRdfType?: boolean; objectSet?: ${syntheticNamePrefix}ObjectSet; preferredLanguages?: readonly string[] }`,
283
286
  },
284
287
  ],
285
288
  returnType: `purify.Either<Error, ${this.name}>`,
@@ -435,7 +438,7 @@ return ${syntheticNamePrefix}strictEquals(left.${syntheticNamePrefix}type, right
435
438
  {
436
439
  hasQuestionToken: true,
437
440
  name: "parameters",
438
- type: '{ ignoreRdfType?: boolean; languageIn?: readonly string[]; subject?: sparqljs.Triple["subject"], variablePrefix?: string }',
441
+ type: '{ ignoreRdfType?: boolean; preferredLanguages?: readonly string[]; subject?: sparqljs.Triple["subject"], variablePrefix?: string }',
439
442
  },
440
443
  ],
441
444
  returnType: "readonly sparqljs.Pattern[]",
@@ -546,7 +549,7 @@ return ${syntheticNamePrefix}strictEquals(left.${syntheticNamePrefix}type, right
546
549
  }
547
550
  fromRdfExpression({ variables, }) {
548
551
  // Don't ignoreRdfType, we may need it to distinguish the union members
549
- return `${variables.resourceValues}.chain(values => values.chainMap(value => value.toResource().chain(resource => ${this.staticModuleName}.${syntheticNamePrefix}fromRdf(resource, { ...${variables.context}, ignoreRdfType: false, languageIn: ${variables.languageIn}, objectSet: ${variables.objectSet} }))))`;
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} }))))`;
550
553
  }
551
554
  graphqlResolveExpression({ variables, }) {
552
555
  return variables.value;
@@ -599,7 +602,7 @@ return ${syntheticNamePrefix}strictEquals(left.${syntheticNamePrefix}type, right
599
602
  case "subject":
600
603
  return [
601
604
  `...${this.staticModuleName}.${syntheticNamePrefix}sparqlWherePatterns(${objectInitializer({
602
- languageIn: parameters.variables.languageIn,
605
+ preferredLanguages: parameters.variables.preferredLanguages,
603
606
  subject: parameters.variables.subject,
604
607
  variablePrefix: parameters.variables.variablePrefix,
605
608
  })})`,
@@ -12,28 +12,10 @@ export declare abstract class PrimitiveType<ValueT extends boolean | Date | stri
12
12
  get discriminatorProperty(): Maybe<Type.DiscriminatorProperty>;
13
13
  get jsonName(): Type.JsonName;
14
14
  fromJsonExpression({ variables, }: Parameters<Type["fromJsonExpression"]>[0]): string;
15
- protected fromRdfExpressionChain({ variables, }: Parameters<Type["fromRdfExpression"]>[0]): {
16
- defaultValue?: string;
17
- hasValues?: string;
18
- languageIn?: string;
19
- valueTo?: string;
20
- };
21
15
  graphqlResolveExpression({ variables, }: Parameters<Type["graphqlResolveExpression"]>[0]): string;
22
16
  hashStatements({ variables, }: Parameters<Type["hashStatements"]>[0]): readonly string[];
23
17
  snippetDeclarations({ features, }: Parameters<Type["snippetDeclarations"]>[0]): readonly string[];
24
- sparqlWherePatterns(parameters: Parameters<Type["sparqlWherePatterns"]>[0]): readonly string[];
18
+ sparqlWherePatterns(parameters: Parameters<LiteralType["sparqlWherePatterns"]>[0]): readonly string[];
25
19
  toJsonExpression({ variables, }: Parameters<Type["toJsonExpression"]>[0]): string;
26
- /**
27
- * Convert an rdfjsResource.Resource.Value to a value of this type.
28
- * @param variables
29
- * @protected
30
- */
31
- protected abstract fromRdfResourceValueExpression({ variables, }: {
32
- variables: {
33
- predicate: string;
34
- resource: string;
35
- resourceValue: string;
36
- };
37
- }): string;
38
20
  }
39
21
  //# sourceMappingURL=PrimitiveType.d.ts.map