@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
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Try to convert a shape to a type using some heuristics.
3
+ *
4
+ * We don't try to handle exotic cases allowed by the SHACL spec, such as combinations of sh:in and sh:node. Instead we assume
5
+ * a shape has one type.
6
+ */
7
+ export function transformShapeToAstType(shape, shapeStack) {
8
+ // Try to transform the property shape into an AST type without cardinality constraints
9
+ return this.transformShapeToAstCompositeType(shape, shapeStack)
10
+ .altLazy(() => this.transformShapeToAstIdentifierType(shape, shapeStack))
11
+ .altLazy(() => this.transformShapeToAstLiteralType(shape, shapeStack))
12
+ .altLazy(() => this.transformShapeToAstTermType(shape, shapeStack));
13
+ }
14
+ //# sourceMappingURL=transformShapeToAstType.js.map
@@ -1,8 +1,6 @@
1
1
  import type { Type } from "./Type.js";
2
2
  /**
3
3
  * A type with zero or one values of an item type.
4
- *
5
- * This is a property with sh:minCount 0 and sh:maxCount 1.
6
4
  */
7
5
  export interface OptionType<ItemTypeT extends Type = Type> {
8
6
  readonly itemType: ItemTypeT;
@@ -2,15 +2,10 @@ import type { Maybe } from "purify-ts";
2
2
  import type { Type } from "./Type.js";
3
3
  /**
4
4
  * An unordered set of items of a specific type.
5
- *
6
- * This is a property with sh:maxCount != 1.
7
5
  */
8
6
  export interface SetType<ItemTypeT extends Type = Type> {
9
- /**
10
- * Set item type.
11
- */
12
- readonly itemType: ItemTypeT;
13
7
  readonly kind: "SetType";
8
+ readonly itemType: ItemTypeT;
14
9
  /**
15
10
  * Minimum number of items in the set.
16
11
  */
@@ -7,6 +7,7 @@ export * from "./Name.js";
7
7
  export * from "./ObjectIntersectionType.js";
8
8
  export * from "./ObjectType.js";
9
9
  export * from "./ObjectUnionType.js";
10
+ export * from "./SetType.js";
10
11
  export * from "./UnionType.js";
11
12
  export * from "./TermType.js";
12
13
  export * from "./Type.js";
package/dist/ast/index.js CHANGED
@@ -7,6 +7,7 @@ export * from "./Name.js";
7
7
  export * from "./ObjectIntersectionType.js";
8
8
  export * from "./ObjectType.js";
9
9
  export * from "./ObjectUnionType.js";
10
+ export * from "./SetType.js";
10
11
  export * from "./UnionType.js";
11
12
  export * from "./TermType.js";
12
13
  export * from "./Type.js";
@@ -119,11 +119,17 @@ export class AstJsonGenerator {
119
119
  kind: objectType.kind,
120
120
  name: nameToJson(objectType.name),
121
121
  properties: objectType.properties.map((property) => ({
122
- name: nameToJson(property.name),
122
+ comment: property.comment.extract(),
123
+ description: property.description.extract(),
124
+ label: property.label.extract(),
123
125
  mutable: property.mutable.extract(),
126
+ name: nameToJson(property.name),
127
+ order: property.order,
124
128
  path: property.path.iri.value,
125
129
  recursive: property.recursive ? true : undefined,
130
+ stubType: property.stubType.map(typeToJson).extract(),
126
131
  type: typeToJson(property.type),
132
+ visibility: property.visibility,
127
133
  })),
128
134
  })),
129
135
  }, undefined, 2);
@@ -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
- propertyFromRdfResourceValueExpression({ variables, }: Parameters<PrimitiveType<boolean>["propertyFromRdfResourceValueExpression"]>[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
- propertyFromRdfResourceValueExpression({ 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
- propertyFromRdfResourceValueExpression({ variables, }: Parameters<PrimitiveType<number>["propertyFromRdfResourceValueExpression"]>[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
- propertyFromRdfResourceValueExpression({ 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,9 +12,9 @@ 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<TermType["fromRdfExpressionChain"]>[0]): ReturnType<TermType["fromRdfExpressionChain"]>;
15
16
  graphqlResolveExpression({ variables: { value }, }: Parameters<Type["graphqlResolveExpression"]>[0]): string;
16
17
  jsonZodSchema({ variables, }: Parameters<TermType<NamedNode, BlankNode | NamedNode>["jsonZodSchema"]>[0]): ReturnType<TermType<NamedNode, BlankNode | NamedNode>["jsonZodSchema"]>;
17
18
  toJsonExpression({ variables, }: Parameters<TermType<NamedNode, BlankNode | NamedNode>["toJsonExpression"]>[0]): string;
18
- protected propertyFromRdfResourceValueExpression({ variables, }: Parameters<TermType<NamedNode, BlankNode | NamedNode>["propertyFromRdfResourceValueExpression"]>[0]): string;
19
19
  }
20
20
  //# sourceMappingURL=IdentifierType.d.ts.map
@@ -121,6 +121,26 @@ export class IdentifierType extends TermType {
121
121
  return valueToNamedNode;
122
122
  }
123
123
  }
124
+ fromRdfExpressionChain({ variables, }) {
125
+ let valueToExpression;
126
+ if (this.nodeKinds.size === 2) {
127
+ valueToExpression = "value.toIdentifier()";
128
+ }
129
+ else if (this.isNamedNodeKind) {
130
+ valueToExpression = "value.toIri()";
131
+ if (this.in_.length > 0) {
132
+ const eitherTypeParameters = `<Error, ${this.name}>`;
133
+ valueToExpression = `${valueToExpression}.chain(iri => { switch (iri.value) { ${this.in_.map((iri) => `case "${iri.value}": return purify.Either.of${eitherTypeParameters}(iri as rdfjs.NamedNode<"${iri.value}">);`).join(" ")} default: return purify.Left${eitherTypeParameters}(new rdfjsResource.Resource.MistypedValueError({ actualValue: iri, expectedValueType: ${JSON.stringify(this.name)}, focusResource: ${variables.resource}, predicate: ${variables.predicate} })); } } )`;
134
+ }
135
+ }
136
+ else {
137
+ throw new Error("not implemented");
138
+ }
139
+ return {
140
+ ...super.fromRdfExpressionChain({ variables }),
141
+ valueTo: `chain(values => values.chainMap(value => ${valueToExpression}))`,
142
+ };
143
+ }
124
144
  graphqlResolveExpression({ variables: { value }, }) {
125
145
  return `rdfjsResource.Resource.Identifier.toString(${value})`;
126
146
  }
@@ -149,20 +169,6 @@ export class IdentifierType extends TermType {
149
169
  return valueToNamedNode;
150
170
  }
151
171
  }
152
- propertyFromRdfResourceValueExpression({ variables, }) {
153
- if (this.nodeKinds.size === 2) {
154
- return `${variables.resourceValue}.toIdentifier()`;
155
- }
156
- if (this.isNamedNodeKind) {
157
- let expression = `${variables.resourceValue}.toIri()`;
158
- if (this.in_.length > 0) {
159
- const eitherTypeParameters = `<Error, ${this.name}>`;
160
- expression = `${expression}.chain(iri => { switch (iri.value) { ${this.in_.map((iri) => `case "${iri.value}": return purify.Either.of${eitherTypeParameters}(iri as rdfjs.NamedNode<"${iri.value}">);`).join(" ")} default: return purify.Left${eitherTypeParameters}(new rdfjsResource.Resource.MistypedValueError({ actualValue: iri, expectedValueType: ${JSON.stringify(this.name)}, focusResource: ${variables.resource}, predicate: ${variables.predicate} })); } } )`;
161
- }
162
- return expression;
163
- }
164
- throw new Error(`not implemented: ${this.name}`);
165
- }
166
172
  }
167
173
  __decorate([
168
174
  Memoize()
@@ -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
@@ -63,11 +63,20 @@ export class ListType extends Type {
63
63
  return `${variables.value}.map(item => (${this.itemType.fromJsonExpression({ variables: { value: "item" } })}))`;
64
64
  }
65
65
  fromRdfExpression({ variables, }) {
66
- const chain = [variables.resourceValues];
67
- chain.push("head()");
68
- chain.push("chain(value => value.toList())");
69
- chain.push(`chain(values => purify.Either.sequence(values.map(value => ${this.itemType.fromRdfExpression({ variables: { ...variables, resourceValues: "value.toValues()" } })})))`);
70
- return chain.join(".");
66
+ return [
67
+ variables.resourceValues,
68
+ "chain(values => values.chainMap(value => value.toList()))", // Resource.Values<Resource.Value> to Resource.Values<Resource.Value[]>
69
+ `chain(valueLists =>
70
+ valueLists.chainMap(
71
+ valueList => ${this.itemType.fromRdfExpression({
72
+ variables: {
73
+ ...variables,
74
+ resourceValues: `purify.Either.of<Error, rdfjsResource.Resource.Values<rdfjsResource.Resource.Value>>(rdfjsResource.Resource.Values.fromArray({ objects: valueList, predicate: ${variables.predicate}, subject: ${variables.resource} }))`,
75
+ },
76
+ })}
77
+ ))`, // Resource.Values<Resource.Value[]> to Resource.Values<item type arrays>
78
+ `map(valueLists => valueLists.map(valueList => valueList.toArray()${this.mutable ? ".concat()" : ""}))`, // Convert inner Resource.Values to arrays
79
+ ].join(".");
71
80
  }
72
81
  graphqlResolveExpression({ variables, }) {
73
82
  return variables.value;
@@ -180,6 +189,7 @@ export class ListType extends Type {
180
189
  allowIgnoreRdfType: true,
181
190
  context: "subject",
182
191
  variables: {
192
+ preferredLanguages: parameters.variables.preferredLanguages,
183
193
  subject: item0Variable,
184
194
  variablePrefix: variablePrefix("Item0"),
185
195
  },
@@ -213,6 +223,7 @@ export class ListType extends Type {
213
223
  allowIgnoreRdfType: true,
214
224
  context: "subject",
215
225
  variables: {
226
+ preferredLanguages: parameters.variables.preferredLanguages,
216
227
  subject: itemNVariable,
217
228
  variablePrefix: variablePrefix("ItemN"),
218
229
  },
@@ -8,10 +8,13 @@ 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<TermType<Literal>["fromRdfExpressionChain"]>[0]): ReturnType<TermType<Literal>["fromRdfExpressionChain"]>;
11
12
  hashStatements({ depth, variables, }: Parameters<TermType<Literal, Literal>["hashStatements"]>[0]): readonly string[];
12
13
  jsonZodSchema({ variables, }: Parameters<TermType<Literal, Literal>["jsonZodSchema"]>[0]): ReturnType<TermType<Literal, Literal>["jsonZodSchema"]>;
13
- propertyFromRdfResourceValueExpression({ variables, }: Parameters<TermType<Literal, Literal>["propertyFromRdfResourceValueExpression"]>[0]): string;
14
+ snippetDeclarations(parameters: Parameters<Type["snippetDeclarations"]>[0]): readonly string[];
15
+ sparqlWherePatterns(parameters: Parameters<Type["sparqlWherePatterns"]>[0] & {
16
+ ignoreLiteralLanguage?: boolean;
17
+ }): readonly string[];
14
18
  toJsonExpression({ variables, }: Parameters<TermType<Literal, Literal>["toJsonExpression"]>[0]): string;
15
- protected propertyFilterRdfResourceValuesExpression({ variables, }: Parameters<TermType<Literal, Literal>["propertyFilterRdfResourceValuesExpression"]>[0]): string;
16
19
  }
17
20
  //# sourceMappingURL=LiteralType.d.ts.map
@@ -6,8 +6,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
6
6
  };
7
7
  import { xsd } from "@tpluscode/rdf-ns-builders";
8
8
  import { Memoize } from "typescript-memoize";
9
+ import { SnippetDeclarations } from "./SnippetDeclarations.js";
9
10
  import { TermType } from "./TermType.js";
10
11
  import { Type } from "./Type.js";
12
+ import { objectInitializer } from "./objectInitializer.js";
13
+ import { syntheticNamePrefix } from "./syntheticNamePrefix.js";
11
14
  export class LiteralType extends TermType {
12
15
  languageIn;
13
16
  constructor({ languageIn, ...superParameters }) {
@@ -23,6 +26,39 @@ export class LiteralType extends TermType {
23
26
  fromJsonExpression({ variables, }) {
24
27
  return `dataFactory.literal(${variables.value}["@value"], typeof ${variables.value}["@language"] !== "undefined" ? ${variables.value}["@language"] : (typeof ${variables.value}["@type"] !== "undefined" ? dataFactory.namedNode(${variables.value}["@type"]) : undefined))`;
25
28
  }
29
+ fromRdfExpressionChain({ variables, }) {
30
+ return {
31
+ ...super.fromRdfExpressionChain({ variables }),
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
+ }
39
+
40
+ const literalValuesEither = values.chainMap(value => value.toLiteral());
41
+ if (literalValuesEither.isLeft()) {
42
+ return literalValuesEither;
43
+ }
44
+ const literalValues = literalValuesEither.unsafeCoerce();
45
+
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
+ }
55
+ }
56
+
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()))",
60
+ };
61
+ }
26
62
  hashStatements({ depth, variables, }) {
27
63
  return [
28
64
  `${variables.hasher}.update(${variables.value}.datatype.value);`,
@@ -32,25 +68,55 @@ export class LiteralType extends TermType {
32
68
  jsonZodSchema({ variables, }) {
33
69
  return `${variables.zod}.object({ "@language": ${variables.zod}.string().optional(), "@type": ${variables.zod}.string().optional(), "@value": ${variables.zod}.string() })`;
34
70
  }
35
- propertyFromRdfResourceValueExpression({ variables, }) {
36
- return `${variables.resourceValue}.toLiteral()`;
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
+ sparqlWherePatterns(parameters) {
80
+ const { context, ignoreLiteralLanguage, variables } = parameters;
81
+ const superPatterns = super.sparqlWherePatterns(parameters);
82
+ if (ignoreLiteralLanguage || context === "subject") {
83
+ return superPatterns;
84
+ }
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 =>
91
+ ({
92
+ type: "operation" as const,
93
+ operator: "=",
94
+ args: [
95
+ { type: "operation" as const, operator: "lang", args: [${variables.object}] },
96
+ dataFactory.literal(language)
97
+ ]
98
+ })
99
+ )
100
+ )
101
+ .map(langEqualsExpressions =>
102
+ ({
103
+ type: "filter" as const,
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
114
+ })
115
+ )`);
37
116
  }
38
117
  toJsonExpression({ variables, }) {
39
118
  return `{ "@language": ${variables.value}.language.length > 0 ? ${variables.value}.language : undefined, "@type": ${variables.value}.datatype.value !== "${xsd.string.value}" ? ${variables.value}.datatype.value : undefined, "@value": ${variables.value}.value }`;
40
119
  }
41
- propertyFilterRdfResourceValuesExpression({ variables, }) {
42
- return `${variables.resourceValues}.filter(_value => {
43
- const _languageInOrDefault = ${variables.languageIn} ?? ${JSON.stringify(this.languageIn)};
44
- if (_languageInOrDefault.length === 0) {
45
- return true;
46
- }
47
- const _valueLiteral = _value.toLiteral().toMaybe().extract();
48
- if (typeof _valueLiteral === "undefined") {
49
- return false;
50
- }
51
- return _languageInOrDefault.some(_languageIn => _languageIn === _valueLiteral.language);
52
- })`;
53
- }
54
120
  }
55
121
  __decorate([
56
122
  Memoize()
@@ -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
- propertyFromRdfResourceValueExpression({ variables, }: Parameters<PrimitiveType<number>["propertyFromRdfResourceValueExpression"]>[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
- propertyFromRdfResourceValueExpression({ 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
@@ -10,7 +10,6 @@ import { Type } from "./Type.js";
10
10
  export declare class ObjectType extends DeclaredType {
11
11
  private readonly imports;
12
12
  protected readonly comment: Maybe<string>;
13
- protected readonly identifierMintingStrategy: Maybe<IdentifierMintingStrategy>;
14
13
  protected readonly label: Maybe<string>;
15
14
  protected readonly toRdfTypes: readonly NamedNode[];
16
15
  readonly abstract: boolean;
@@ -21,7 +20,7 @@ export declare class ObjectType extends DeclaredType {
21
20
  readonly staticModuleName: string;
22
21
  readonly synthetic: boolean;
23
22
  readonly typeof = "object";
24
- constructor({ abstract, comment, declarationType, extern, fromRdfType, imports, identifierMintingStrategy, label, lazyAncestorObjectTypes, lazyChildObjectTypes, lazyDescendantObjectTypes, lazyParentObjectTypes, lazyProperties, staticModuleName, synthetic, toRdfTypes, ...superParameters }: {
23
+ constructor({ abstract, comment, declarationType, extern, fromRdfType, imports, label, lazyAncestorObjectTypes, lazyChildObjectTypes, lazyDescendantObjectTypes, lazyParentObjectTypes, lazyProperties, staticModuleName, synthetic, toRdfTypes, ...superParameters }: {
25
24
  abstract: boolean;
26
25
  comment: Maybe<string>;
27
26
  declarationType: TsObjectDeclarationType;
@@ -45,6 +44,8 @@ export declare class ObjectType extends DeclaredType {
45
44
  get conversions(): readonly Type.Conversion[];
46
45
  get declarationImports(): readonly Import[];
47
46
  get declarations(): (ClassDeclarationStructure | InterfaceDeclarationStructure | ModuleDeclarationStructure)[];
47
+ get descendantFromRdfTypes(): readonly NamedNode[];
48
+ get descendantFromRdfTypeVariables(): readonly string[];
48
49
  get descendantObjectTypes(): readonly ObjectType[];
49
50
  get discriminatorProperty(): Maybe<Type.DiscriminatorProperty>;
50
51
  get discriminatorValue(): string;