@shaclmate/compiler 2.0.12 → 2.0.14
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.
- package/Compiler.d.ts +15 -0
- package/Compiler.js +20 -0
- package/ShapesGraphToAstTransformer.d.ts +18 -23
- package/ShapesGraphToAstTransformer.js +21 -447
- package/_ShapesGraphToAstTransformer/NodeShapeAstType.d.ts +3 -0
- package/_ShapesGraphToAstTransformer/NodeShapeAstType.js +2 -0
- package/_ShapesGraphToAstTransformer/index.d.ts +10 -0
- package/_ShapesGraphToAstTransformer/index.js +10 -0
- package/_ShapesGraphToAstTransformer/pickLiteral.d.ts +4 -0
- package/_ShapesGraphToAstTransformer/pickLiteral.js +18 -0
- package/_ShapesGraphToAstTransformer/propertyShapeNodeKinds.d.ts +4 -0
- package/_ShapesGraphToAstTransformer/propertyShapeNodeKinds.js +26 -0
- package/_ShapesGraphToAstTransformer/shapeAstName.d.ts +5 -0
- package/_ShapesGraphToAstTransformer/shapeAstName.js +28 -0
- package/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.d.ts +6 -0
- package/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.js +165 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.d.ts +13 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +198 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.d.ts +12 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.js +29 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.d.ts +12 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.js +43 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.d.ts +6 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +31 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.d.ts +14 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.js +21 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.d.ts +16 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.js +58 -0
- package/ast/Ast.d.ts +5 -0
- package/ast/CompositeType.d.ts +13 -0
- package/ast/CompositeType.js +2 -0
- package/ast/IdentifierType.d.ts +3 -6
- package/ast/IntersectionType.d.ts +2 -2
- package/ast/ListType.d.ts +53 -0
- package/ast/ListType.js +2 -0
- package/ast/LiteralType.d.ts +4 -3
- package/ast/Name.d.ts +1 -0
- package/ast/ObjectCompositeType.d.ts +22 -0
- package/ast/ObjectCompositeType.js +2 -0
- package/ast/ObjectIntersectionType.d.ts +8 -0
- package/ast/ObjectIntersectionType.js +2 -0
- package/ast/ObjectType.d.ts +92 -20
- package/ast/ObjectType.js +26 -1
- package/ast/ObjectUnionType.d.ts +19 -0
- package/ast/ObjectUnionType.js +2 -0
- package/ast/PlaceholderType.d.ts +7 -0
- package/ast/PlaceholderType.js +2 -0
- package/ast/SetType.d.ts +1 -1
- package/ast/TermType.d.ts +11 -0
- package/ast/TermType.js +2 -0
- package/ast/Type.d.ts +11 -3
- package/ast/UnionType.d.ts +3 -3
- package/ast/index.d.ts +6 -3
- package/ast/index.js +6 -3
- package/enums/MintingStrategy.d.ts +5 -0
- package/enums/MintingStrategy.js +2 -0
- package/enums/PropertyVisibility.d.ts +2 -0
- package/enums/PropertyVisibility.js +2 -0
- package/enums/TsFeature.d.ts +5 -0
- package/enums/TsFeature.js +16 -0
- package/enums/TsObjectDeclarationType.d.ts +5 -0
- package/enums/TsObjectDeclarationType.js +2 -0
- package/enums/index.d.ts +5 -0
- package/enums/index.js +5 -0
- package/generators/Generator.d.ts +5 -0
- package/generators/Generator.js +2 -0
- package/generators/index.d.ts +2 -2
- package/generators/index.js +2 -2
- package/generators/json/AstJsonGenerator.d.ts +4 -5
- package/generators/json/AstJsonGenerator.js +31 -22
- package/generators/ts/BooleanType.d.ts +7 -3
- package/generators/ts/BooleanType.js +58 -4
- package/generators/ts/DateTimeType.d.ts +17 -0
- package/generators/ts/DateTimeType.js +58 -0
- package/generators/ts/DeclaredType.d.ts +17 -0
- package/generators/ts/DeclaredType.js +10 -0
- package/generators/ts/IdentifierType.d.ts +7 -17
- package/generators/ts/IdentifierType.js +69 -60
- package/generators/ts/Import.d.ts +18 -0
- package/generators/ts/Import.js +59 -0
- package/generators/ts/ListType.d.ts +18 -8
- package/generators/ts/ListType.js +197 -43
- package/generators/ts/LiteralType.d.ts +13 -11
- package/generators/ts/LiteralType.js +36 -51
- package/generators/ts/NumberType.d.ts +7 -3
- package/generators/ts/NumberType.js +55 -4
- package/generators/ts/ObjectType.d.ts +47 -25
- package/generators/ts/ObjectType.js +222 -49
- package/generators/ts/ObjectUnionType.d.ts +58 -0
- package/generators/ts/ObjectUnionType.js +481 -0
- package/generators/ts/OptionType.d.ts +12 -4
- package/generators/ts/OptionType.js +65 -16
- package/generators/ts/PrimitiveType.d.ts +15 -5
- package/generators/ts/PrimitiveType.js +20 -29
- package/generators/ts/SetType.d.ts +12 -4
- package/generators/ts/SetType.js +103 -29
- package/generators/ts/StringType.d.ts +8 -3
- package/generators/ts/StringType.js +57 -3
- package/generators/ts/TermType.d.ts +52 -0
- package/generators/ts/TermType.js +234 -0
- package/generators/ts/TsGenerator.d.ts +4 -12
- package/generators/ts/TsGenerator.js +44 -100
- package/generators/ts/Type.d.ts +107 -46
- package/generators/ts/Type.js +78 -61
- package/generators/ts/TypeFactory.d.ts +4 -5
- package/generators/ts/TypeFactory.js +212 -89
- package/generators/ts/UnionType.d.ts +19 -6
- package/generators/ts/UnionType.js +230 -120
- package/generators/ts/_ObjectType/IdentifierProperty.d.ts +27 -7
- package/generators/ts/_ObjectType/IdentifierProperty.js +143 -31
- package/generators/ts/_ObjectType/Property.d.ts +125 -9
- package/generators/ts/_ObjectType/Property.js +25 -3
- package/generators/ts/_ObjectType/ShaclProperty.d.ts +23 -5
- package/generators/ts/_ObjectType/ShaclProperty.js +100 -26
- package/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +24 -6
- package/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +75 -13
- package/generators/ts/_ObjectType/classDeclaration.d.ts +2 -1
- package/generators/ts/_ObjectType/classDeclaration.js +79 -111
- package/generators/ts/_ObjectType/createFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/createFunctionDeclaration.js +60 -0
- package/generators/ts/_ObjectType/equalsFunctionDeclaration.d.ts +2 -1
- package/generators/ts/_ObjectType/equalsFunctionDeclaration.js +12 -20
- package/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.d.ts +11 -0
- package/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.js +70 -0
- package/generators/ts/_ObjectType/fromJsonFunctionDeclarations.d.ts +4 -0
- package/generators/ts/_ObjectType/fromJsonFunctionDeclarations.js +78 -0
- package/generators/ts/_ObjectType/fromRdfFunctionDeclarations.d.ts +4 -0
- package/generators/ts/_ObjectType/fromRdfFunctionDeclarations.js +91 -0
- package/generators/ts/_ObjectType/hashFunctionDeclaration.d.ts +3 -3
- package/generators/ts/_ObjectType/hashFunctionDeclaration.js +11 -55
- package/generators/ts/_ObjectType/hashFunctionOrMethodDeclaration.d.ts +11 -0
- package/generators/ts/_ObjectType/hashFunctionOrMethodDeclaration.js +64 -0
- package/generators/ts/_ObjectType/index.d.ts +8 -2
- package/generators/ts/_ObjectType/index.js +8 -2
- package/generators/ts/_ObjectType/interfaceDeclaration.d.ts +3 -2
- package/generators/ts/_ObjectType/interfaceDeclaration.js +11 -2
- package/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.js +19 -0
- package/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.js +31 -0
- package/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.js +37 -0
- package/generators/ts/_ObjectType/rdfjsTermExpression.d.ts +6 -0
- package/generators/ts/{rdfjsTermExpression.js → _ObjectType/rdfjsTermExpression.js} +3 -1
- package/generators/ts/_ObjectType/sparqlFunctionDeclarations.d.ts +4 -0
- package/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +101 -0
- package/generators/ts/_ObjectType/toJsonFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/toJsonFunctionDeclaration.js +19 -0
- package/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.d.ts +10 -0
- package/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.js +59 -0
- package/generators/ts/_ObjectType/toJsonReturnType.d.ts +3 -0
- package/generators/ts/_ObjectType/toJsonReturnType.js +19 -0
- package/generators/ts/_ObjectType/toRdfFunctionDeclaration.d.ts +3 -2
- package/generators/ts/_ObjectType/toRdfFunctionDeclaration.js +11 -45
- package/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.d.ts +10 -0
- package/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.js +67 -0
- package/generators/ts/objectInitializer.d.ts +2 -0
- package/generators/ts/objectInitializer.js +14 -0
- package/generators/ts/tsComment.d.ts +5 -0
- package/generators/ts/tsComment.js +11 -0
- package/generators/ts/tsName.d.ts +1 -1
- package/generators/ts/tsName.js +1 -0
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/input/NodeShape.d.ts +46 -0
- package/input/NodeShape.js +165 -0
- package/input/Ontology.d.ts +13 -0
- package/input/Ontology.js +30 -0
- package/input/PropertyShape.d.ts +15 -0
- package/input/PropertyShape.js +34 -0
- package/input/Shape.d.ts +4 -0
- package/input/Shape.js +2 -0
- package/input/ShapesGraph.d.ts +9 -0
- package/input/ShapesGraph.js +50 -0
- package/input/ancestorClassIris.d.ts +4 -0
- package/input/ancestorClassIris.js +21 -0
- package/input/descendantClassIris.d.ts +4 -0
- package/input/descendantClassIris.js +21 -0
- package/input/generated.d.ts +274 -0
- package/input/generated.js +1420 -0
- package/input/index.d.ts +7 -0
- package/input/index.js +7 -0
- package/input/tsFeatures.d.ts +10 -0
- package/input/tsFeatures.js +42 -0
- package/package.json +14 -8
- package/ast/MintingStrategy.d.ts +0 -8
- package/ast/MintingStrategy.js +0 -9
- package/generators/ts/Configuration.d.ts +0 -29
- package/generators/ts/Configuration.js +0 -40
- package/generators/ts/IntersectionType.d.ts +0 -14
- package/generators/ts/IntersectionType.js +0 -26
- package/generators/ts/RdfjsTermType.d.ts +0 -25
- package/generators/ts/RdfjsTermType.js +0 -46
- package/generators/ts/_ObjectType/fromRdfFunctionDeclaration.d.ts +0 -4
- package/generators/ts/_ObjectType/fromRdfFunctionDeclaration.js +0 -72
- package/generators/ts/_ObjectType/sparqlGraphPatternsClassDeclaration.d.ts +0 -4
- package/generators/ts/_ObjectType/sparqlGraphPatternsClassDeclaration.js +0 -46
- package/generators/ts/rdfjsTermExpression.d.ts +0 -5
- package/vocabularies/dashDataset.d.ts +0 -3
- package/vocabularies/dashDataset.js +0 -2370
- package/vocabularies/index.d.ts +0 -2
- package/vocabularies/index.js +0 -2
- package/vocabularies/shaclmate.d.ts +0 -15
- package/vocabularies/shaclmate.js +0 -6
|
@@ -1,41 +1,32 @@
|
|
|
1
1
|
import { Maybe } from "purify-ts";
|
|
2
|
-
import { fromRdf } from "rdf-literal";
|
|
3
2
|
import { LiteralType } from "./LiteralType.js";
|
|
4
3
|
export class PrimitiveType extends LiteralType {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
},
|
|
11
|
-
];
|
|
12
|
-
this.defaultValue.ifJust((defaultValue) => {
|
|
13
|
-
conversions.push({
|
|
14
|
-
conversionExpression: () => fromRdf(defaultValue, true),
|
|
15
|
-
sourceTypeName: "undefined",
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
return conversions;
|
|
4
|
+
constructor({ primitiveDefaultValue, primitiveIn, ...superParameters }) {
|
|
5
|
+
super(superParameters);
|
|
6
|
+
this.equalsFunction = "purifyHelpers.Equatable.strictEquals";
|
|
7
|
+
this.primitiveDefaultValue = primitiveDefaultValue;
|
|
8
|
+
this.primitiveIn = primitiveIn;
|
|
19
9
|
}
|
|
20
10
|
get discriminatorProperty() {
|
|
21
11
|
return Maybe.empty();
|
|
22
12
|
}
|
|
23
|
-
get
|
|
13
|
+
get jsonName() {
|
|
14
|
+
return this.name;
|
|
15
|
+
}
|
|
16
|
+
get useImports() {
|
|
24
17
|
return [];
|
|
25
18
|
}
|
|
26
|
-
|
|
27
|
-
return
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
})
|
|
38
|
-
.orDefault(variables.value);
|
|
19
|
+
fromJsonExpression({ variables, }) {
|
|
20
|
+
return variables.value;
|
|
21
|
+
}
|
|
22
|
+
hashStatements({ variables, }) {
|
|
23
|
+
return [`${variables.hasher}.update(${variables.value}.toString());`];
|
|
24
|
+
}
|
|
25
|
+
toJsonExpression({ variables, }) {
|
|
26
|
+
return variables.value;
|
|
27
|
+
}
|
|
28
|
+
propertyFilterRdfResourceValuesExpression({ variables, }) {
|
|
29
|
+
return variables.resourceValues;
|
|
39
30
|
}
|
|
40
31
|
}
|
|
41
32
|
//# sourceMappingURL=PrimitiveType.js.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Import } from "./Import.js";
|
|
1
2
|
import { Type } from "./Type.js";
|
|
2
3
|
export declare class SetType extends Type {
|
|
3
4
|
readonly itemType: Type;
|
|
@@ -8,12 +9,19 @@ export declare class SetType extends Type {
|
|
|
8
9
|
minCount: number;
|
|
9
10
|
});
|
|
10
11
|
get conversions(): readonly Type.Conversion[];
|
|
12
|
+
get equalsFunction(): string;
|
|
13
|
+
get jsonName(): string;
|
|
14
|
+
get mutable(): boolean;
|
|
11
15
|
get name(): string;
|
|
12
|
-
|
|
13
|
-
|
|
16
|
+
get useImports(): readonly Import[];
|
|
17
|
+
fromJsonExpression({ variables, }: Parameters<Type["fromJsonExpression"]>[0]): string;
|
|
14
18
|
fromRdfExpression({ variables, }: Parameters<Type["fromRdfExpression"]>[0]): string;
|
|
15
|
-
hashStatements({ variables, }: Parameters<Type["hashStatements"]>[0]): readonly string[];
|
|
16
|
-
|
|
19
|
+
hashStatements({ depth, variables, }: Parameters<Type["hashStatements"]>[0]): readonly string[];
|
|
20
|
+
jsonUiSchemaElement(parameters: Parameters<Type["jsonUiSchemaElement"]>[0]): ReturnType<Type["jsonUiSchemaElement"]>;
|
|
21
|
+
jsonZodSchema(parameters: Parameters<Type["jsonZodSchema"]>[0]): ReturnType<Type["jsonZodSchema"]>;
|
|
22
|
+
sparqlConstructTemplateTriples({ context, variables, }: Parameters<Type["sparqlConstructTemplateTriples"]>[0]): readonly string[];
|
|
23
|
+
sparqlWherePatterns({ context, variables, }: Parameters<Type["sparqlWherePatterns"]>[0]): readonly string[];
|
|
24
|
+
toJsonExpression({ variables, }: Parameters<Type["toJsonExpression"]>[0]): string;
|
|
17
25
|
toRdfExpression({ variables, }: Parameters<Type["toRdfExpression"]>[0]): string;
|
|
18
26
|
}
|
|
19
27
|
//# sourceMappingURL=SetType.d.ts.map
|
package/generators/ts/SetType.js
CHANGED
|
@@ -4,70 +4,144 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
+
import { invariant } from "ts-invariant";
|
|
7
8
|
import { Memoize } from "typescript-memoize";
|
|
8
9
|
import { Type } from "./Type.js";
|
|
10
|
+
import { objectInitializer } from "./objectInitializer.js";
|
|
9
11
|
export class SetType extends Type {
|
|
10
12
|
constructor({ itemType, minCount, ...superParameters }) {
|
|
11
13
|
super(superParameters);
|
|
12
14
|
this.kind = "SetType";
|
|
13
15
|
this.itemType = itemType;
|
|
14
16
|
this.minCount = minCount;
|
|
17
|
+
invariant(this.minCount >= 0);
|
|
15
18
|
}
|
|
16
19
|
get conversions() {
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
const conversions = [];
|
|
21
|
+
if (this.minCount === 0) {
|
|
22
|
+
conversions.push({
|
|
19
23
|
conversionExpression: () => "[]",
|
|
24
|
+
sourceTypeCheckExpression: (value) => `typeof ${value} === "undefined"`,
|
|
20
25
|
sourceTypeName: "undefined",
|
|
21
|
-
}
|
|
22
|
-
{
|
|
26
|
+
});
|
|
27
|
+
conversions.push({
|
|
23
28
|
conversionExpression: (value) => value,
|
|
24
29
|
sourceTypeCheckExpression: (value) => `Array.isArray(${value})`,
|
|
30
|
+
sourceTypeName: `readonly (${this.itemType.name})[]`,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
conversions.push({
|
|
35
|
+
conversionExpression: (value) => value,
|
|
36
|
+
sourceTypeCheckExpression: (value) => `purify.NonEmptyList.isNonEmpty(${value})`,
|
|
25
37
|
sourceTypeName: this.name,
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
get name() {
|
|
30
|
-
return `readonly (${this.itemType.name})[]`;
|
|
31
|
-
}
|
|
32
|
-
chainSparqlGraphPatternExpression(parameters) {
|
|
33
|
-
return this.itemType.chainSparqlGraphPatternExpression(parameters);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return conversions;
|
|
34
41
|
}
|
|
35
|
-
equalsFunction() {
|
|
36
|
-
const itemTypeEqualsFunction = this.itemType.equalsFunction
|
|
42
|
+
get equalsFunction() {
|
|
43
|
+
const itemTypeEqualsFunction = this.itemType.equalsFunction;
|
|
37
44
|
if (itemTypeEqualsFunction === "purifyHelpers.Equatable.equals") {
|
|
38
45
|
return "purifyHelpers.Equatable.arrayEquals";
|
|
39
46
|
}
|
|
40
47
|
return `(left, right) => purifyHelpers.Arrays.equals(left, right, ${itemTypeEqualsFunction})`;
|
|
41
48
|
}
|
|
49
|
+
get jsonName() {
|
|
50
|
+
if (this.minCount === 0) {
|
|
51
|
+
return `readonly (${this.itemType.jsonName})[]`;
|
|
52
|
+
}
|
|
53
|
+
return `purify.NonEmptyList<${this.itemType.jsonName}>`;
|
|
54
|
+
}
|
|
55
|
+
get mutable() {
|
|
56
|
+
return this.itemType.mutable;
|
|
57
|
+
}
|
|
58
|
+
get name() {
|
|
59
|
+
if (this.minCount === 0) {
|
|
60
|
+
return `readonly (${this.itemType.name})[]`;
|
|
61
|
+
}
|
|
62
|
+
return `purify.NonEmptyList<${this.itemType.name}>`;
|
|
63
|
+
}
|
|
64
|
+
get useImports() {
|
|
65
|
+
return this.itemType.useImports;
|
|
66
|
+
}
|
|
67
|
+
fromJsonExpression({ variables, }) {
|
|
68
|
+
let expression = variables.value;
|
|
69
|
+
if (this.minCount > 0) {
|
|
70
|
+
expression = `purify.NonEmptyList.fromArray(${expression}).unsafeCoerce()`;
|
|
71
|
+
}
|
|
72
|
+
const itemFromJsonExpression = this.itemType.fromJsonExpression({
|
|
73
|
+
variables: { value: "_item" },
|
|
74
|
+
});
|
|
75
|
+
return itemFromJsonExpression === "_item"
|
|
76
|
+
? expression
|
|
77
|
+
: `${expression}.map(_item => (${itemFromJsonExpression}))`;
|
|
78
|
+
}
|
|
42
79
|
fromRdfExpression({ variables, }) {
|
|
43
|
-
|
|
80
|
+
const itemFromRdfExpression = this.itemType.fromRdfExpression({
|
|
81
|
+
variables: { ...variables, resourceValues: "_item.toValues()" },
|
|
82
|
+
});
|
|
83
|
+
if (this.minCount === 0) {
|
|
84
|
+
return `purify.Either.of([...${variables.resourceValues}.flatMap(_item => ${itemFromRdfExpression}.toMaybe().toList())])`;
|
|
85
|
+
}
|
|
86
|
+
return `purify.NonEmptyList.fromArray([...${variables.resourceValues}.flatMap(_item => ${itemFromRdfExpression}.toMaybe().toList())]).toEither(new rdfjsResource.Resource.ValueError(${objectInitializer({ focusResource: variables.resource, message: `\`\${rdfjsResource.Resource.Identifier.toString(${variables.resource}.identifier)} is empty\``, predicate: variables.predicate })}))`;
|
|
44
87
|
}
|
|
45
|
-
hashStatements({ variables, }) {
|
|
88
|
+
hashStatements({ depth, variables, }) {
|
|
46
89
|
return [
|
|
47
|
-
`for (const
|
|
90
|
+
`for (const _item${depth} of ${variables.value}) { ${this.itemType
|
|
48
91
|
.hashStatements({
|
|
92
|
+
depth: depth + 1,
|
|
49
93
|
variables: {
|
|
50
94
|
hasher: variables.hasher,
|
|
51
|
-
value:
|
|
95
|
+
value: `_item${depth}`,
|
|
52
96
|
},
|
|
53
97
|
})
|
|
54
98
|
.join("\n")} }`,
|
|
55
99
|
];
|
|
56
100
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
101
|
+
jsonUiSchemaElement(parameters) {
|
|
102
|
+
return this.itemType.jsonUiSchemaElement(parameters);
|
|
103
|
+
}
|
|
104
|
+
jsonZodSchema(parameters) {
|
|
105
|
+
let schema = `${this.itemType.jsonZodSchema(parameters)}.array()`;
|
|
106
|
+
if (this.minCount > 0) {
|
|
107
|
+
schema = `${schema}.nonempty().min(${this.minCount})`;
|
|
60
108
|
}
|
|
61
|
-
return
|
|
109
|
+
return schema;
|
|
62
110
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
111
|
+
sparqlConstructTemplateTriples({ context, variables, }) {
|
|
112
|
+
switch (context) {
|
|
113
|
+
case "property":
|
|
114
|
+
return super.sparqlConstructTemplateTriples({ context, variables });
|
|
115
|
+
case "type":
|
|
116
|
+
return this.itemType.sparqlConstructTemplateTriples({
|
|
117
|
+
context,
|
|
118
|
+
variables,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
sparqlWherePatterns({ context, variables, }) {
|
|
123
|
+
switch (context) {
|
|
124
|
+
case "property": {
|
|
125
|
+
const patterns = super.sparqlWherePatterns({ context, variables });
|
|
126
|
+
if (patterns.length === 0) {
|
|
127
|
+
return [];
|
|
128
|
+
}
|
|
129
|
+
return this.minCount > 0
|
|
130
|
+
? patterns
|
|
131
|
+
: [`{ patterns: [${patterns.join(", ")}], type: "optional" }`];
|
|
132
|
+
}
|
|
133
|
+
case "type": {
|
|
134
|
+
return this.itemType.sparqlWherePatterns({ context, variables });
|
|
135
|
+
}
|
|
69
136
|
}
|
|
70
|
-
|
|
137
|
+
}
|
|
138
|
+
toJsonExpression({ variables, }) {
|
|
139
|
+
return `${variables.value}.map(_item => (${this.itemType.toJsonExpression({ variables: { value: "_item" } })}))`;
|
|
140
|
+
}
|
|
141
|
+
toRdfExpression({ variables, }) {
|
|
142
|
+
return `${variables.value}.map((_item) => ${this.itemType.toRdfExpression({
|
|
143
|
+
variables: { ...variables, value: "_item" },
|
|
144
|
+
})})`;
|
|
71
145
|
}
|
|
72
146
|
}
|
|
73
147
|
__decorate([
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { PrimitiveType } from "./PrimitiveType.js";
|
|
2
|
-
|
|
2
|
+
import type { Type } from "./Type.js";
|
|
3
|
+
export declare class StringType extends PrimitiveType<string> {
|
|
4
|
+
readonly kind = "StringType";
|
|
5
|
+
get conversions(): readonly Type.Conversion[];
|
|
3
6
|
get name(): string;
|
|
4
|
-
|
|
5
|
-
|
|
7
|
+
hashStatements({ variables, }: Parameters<Type["hashStatements"]>[0]): readonly string[];
|
|
8
|
+
jsonZodSchema({ variables, }: Parameters<Type["jsonZodSchema"]>[0]): ReturnType<Type["jsonZodSchema"]>;
|
|
9
|
+
propertyFromRdfResourceValueExpression({ variables, }: Parameters<PrimitiveType<string>["propertyFromRdfResourceValueExpression"]>[0]): string;
|
|
10
|
+
toRdfExpression({ variables, }: Parameters<PrimitiveType<string>["toRdfExpression"]>[0]): string;
|
|
6
11
|
}
|
|
7
12
|
//# sourceMappingURL=StringType.d.ts.map
|
|
@@ -1,13 +1,67 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { Memoize } from "typescript-memoize";
|
|
1
8
|
import { PrimitiveType } from "./PrimitiveType.js";
|
|
9
|
+
import { objectInitializer } from "./objectInitializer.js";
|
|
2
10
|
export class StringType extends PrimitiveType {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(...arguments);
|
|
13
|
+
this.kind = "StringType";
|
|
14
|
+
}
|
|
15
|
+
get conversions() {
|
|
16
|
+
const conversions = [
|
|
17
|
+
{
|
|
18
|
+
conversionExpression: (value) => value,
|
|
19
|
+
sourceTypeCheckExpression: (value) => `typeof ${value} === "string"`,
|
|
20
|
+
sourceTypeName: this.name,
|
|
21
|
+
},
|
|
22
|
+
];
|
|
23
|
+
this.primitiveDefaultValue.ifJust((defaultValue) => {
|
|
24
|
+
conversions.push({
|
|
25
|
+
conversionExpression: () => `"${defaultValue}"`,
|
|
26
|
+
sourceTypeCheckExpression: (value) => `typeof ${value} === "undefined"`,
|
|
27
|
+
sourceTypeName: "undefined",
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
return conversions;
|
|
31
|
+
}
|
|
3
32
|
get name() {
|
|
33
|
+
if (this.primitiveIn.length > 0) {
|
|
34
|
+
return this.primitiveIn.map((value) => `"${value}"`).join(" | ");
|
|
35
|
+
}
|
|
4
36
|
return "string";
|
|
5
37
|
}
|
|
6
|
-
fromRdfResourceValueExpression({ variables, }) {
|
|
7
|
-
return `${variables.resourceValue}.toString()`;
|
|
8
|
-
}
|
|
9
38
|
hashStatements({ variables, }) {
|
|
10
39
|
return [`${variables.hasher}.update(${variables.value});`];
|
|
11
40
|
}
|
|
41
|
+
jsonZodSchema({ variables, }) {
|
|
42
|
+
switch (this.primitiveIn.length) {
|
|
43
|
+
case 0:
|
|
44
|
+
return `${variables.zod}.string()`;
|
|
45
|
+
case 1:
|
|
46
|
+
return `${variables.zod}.literal(${this.primitiveIn[0]})`;
|
|
47
|
+
default:
|
|
48
|
+
return `${variables.zod}.enum(${JSON.stringify(this.primitiveIn)})`;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
propertyFromRdfResourceValueExpression({ variables, }) {
|
|
52
|
+
let expression = `${variables.resourceValue}.toString()`;
|
|
53
|
+
if (this.primitiveIn.length > 0) {
|
|
54
|
+
expression = `${expression}.chain(value => { switch (value) { ${this.primitiveIn.map((value) => `case "${value}":`).join(" ")} return purify.Either.of(value); default: return purify.Left(new rdfjsResource.Resource.MistypedValueError(${objectInitializer({ actualValue: "rdfLiteral.toRdf(value)", expectedValueType: JSON.stringify(this.name), focusResource: variables.resource, predicate: variables.predicate })})); } })`;
|
|
55
|
+
}
|
|
56
|
+
return expression;
|
|
57
|
+
}
|
|
58
|
+
toRdfExpression({ variables, }) {
|
|
59
|
+
return this.primitiveDefaultValue
|
|
60
|
+
.map((defaultValue) => `${variables.value} !== "${defaultValue}" ? ${variables.value} : undefined`)
|
|
61
|
+
.orDefault(variables.value);
|
|
62
|
+
}
|
|
12
63
|
}
|
|
64
|
+
__decorate([
|
|
65
|
+
Memoize()
|
|
66
|
+
], StringType.prototype, "name", null);
|
|
13
67
|
//# sourceMappingURL=StringType.js.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { BlankNode, Literal, NamedNode } from "@rdfjs/types";
|
|
2
|
+
import { Maybe } from "purify-ts";
|
|
3
|
+
import { Import } from "./Import.js";
|
|
4
|
+
import { Type } from "./Type.js";
|
|
5
|
+
/**
|
|
6
|
+
* Abstract base class for IdentifierType and LiteralType.
|
|
7
|
+
*/
|
|
8
|
+
export declare class TermType<TermT extends BlankNode | Literal | NamedNode> extends Type {
|
|
9
|
+
readonly defaultValue: Maybe<TermT>;
|
|
10
|
+
readonly equalsFunction: string;
|
|
11
|
+
readonly hasValues: readonly TermT[];
|
|
12
|
+
readonly in_: readonly TermT[];
|
|
13
|
+
readonly mutable: boolean;
|
|
14
|
+
readonly nodeKinds: Set<TermT["termType"]>;
|
|
15
|
+
constructor({ defaultValue, hasValues, in_, nodeKinds, ...superParameters }: {
|
|
16
|
+
defaultValue: Maybe<TermT>;
|
|
17
|
+
hasValues: readonly TermT[];
|
|
18
|
+
in_: readonly TermT[];
|
|
19
|
+
nodeKinds: Set<TermT["termType"]>;
|
|
20
|
+
} & ConstructorParameters<typeof Type>[0]);
|
|
21
|
+
get conversions(): readonly Type.Conversion[];
|
|
22
|
+
get discriminatorProperty(): Maybe<Type.DiscriminatorProperty>;
|
|
23
|
+
get jsonName(): string;
|
|
24
|
+
get name(): string;
|
|
25
|
+
get useImports(): readonly Import[];
|
|
26
|
+
fromJsonExpression({ variables, }: Parameters<Type["fromJsonExpression"]>[0]): string;
|
|
27
|
+
fromRdfExpression({ variables, }: Parameters<Type["fromRdfExpression"]>[0]): string;
|
|
28
|
+
hashStatements({ variables, }: Parameters<Type["hashStatements"]>[0]): readonly string[];
|
|
29
|
+
jsonZodSchema({ variables, }: Parameters<Type["jsonZodSchema"]>[0]): ReturnType<Type["jsonZodSchema"]>;
|
|
30
|
+
sparqlWherePatterns(parameters: Parameters<Type["sparqlWherePatterns"]>[0]): readonly string[];
|
|
31
|
+
toJsonExpression({ variables, }: Parameters<Type["toJsonExpression"]>[0]): string;
|
|
32
|
+
toRdfExpression({ variables, }: Parameters<Type["toRdfExpression"]>[0]): string;
|
|
33
|
+
/**
|
|
34
|
+
* Filter the rdfjsResource.Resource.Values to those that are relevant to the type.
|
|
35
|
+
*
|
|
36
|
+
* This is done before
|
|
37
|
+
*/
|
|
38
|
+
protected propertyFilterRdfResourceValuesExpression({ variables, }: Parameters<Type["fromRdfExpression"]>[0]): string;
|
|
39
|
+
/**
|
|
40
|
+
* Convert an rdfjsResource.Resource.Value to a value of this type.
|
|
41
|
+
* @param variables
|
|
42
|
+
* @protected
|
|
43
|
+
*/
|
|
44
|
+
protected propertyFromRdfResourceValueExpression({ variables, }: {
|
|
45
|
+
variables: {
|
|
46
|
+
predicate: string;
|
|
47
|
+
resource: string;
|
|
48
|
+
resourceValue: string;
|
|
49
|
+
};
|
|
50
|
+
}): string;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=TermType.d.ts.map
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { xsd } from "@tpluscode/rdf-ns-builders";
|
|
8
|
+
import { Maybe } from "purify-ts";
|
|
9
|
+
import { invariant } from "ts-invariant";
|
|
10
|
+
import { Memoize } from "typescript-memoize";
|
|
11
|
+
import { Import } from "./Import.js";
|
|
12
|
+
import { Type } from "./Type.js";
|
|
13
|
+
import { objectInitializer } from "./objectInitializer.js";
|
|
14
|
+
/**
|
|
15
|
+
* Abstract base class for IdentifierType and LiteralType.
|
|
16
|
+
*/
|
|
17
|
+
export class TermType extends Type {
|
|
18
|
+
constructor({ defaultValue, hasValues, in_, nodeKinds, ...superParameters }) {
|
|
19
|
+
super(superParameters);
|
|
20
|
+
this.equalsFunction = "purifyHelpers.Equatable.booleanEquals";
|
|
21
|
+
this.mutable = false;
|
|
22
|
+
this.defaultValue = defaultValue;
|
|
23
|
+
this.hasValues = hasValues;
|
|
24
|
+
this.in_ = in_;
|
|
25
|
+
this.nodeKinds = new Set([...nodeKinds]);
|
|
26
|
+
invariant(this.nodeKinds.size > 0);
|
|
27
|
+
}
|
|
28
|
+
get conversions() {
|
|
29
|
+
const conversions = [];
|
|
30
|
+
if (this.nodeKinds.has("Literal")) {
|
|
31
|
+
conversions.push({
|
|
32
|
+
conversionExpression: (value) => `rdfLiteral.toRdf(${value})`,
|
|
33
|
+
sourceTypeCheckExpression: (value) => `typeof ${value} === "boolean"`,
|
|
34
|
+
sourceTypeName: "boolean",
|
|
35
|
+
}, {
|
|
36
|
+
conversionExpression: (value) => `rdfLiteral.toRdf(${value})`,
|
|
37
|
+
sourceTypeCheckExpression: (value) => `typeof ${value} === "object" && ${value} instanceof Date`,
|
|
38
|
+
sourceTypeName: "Date",
|
|
39
|
+
}, {
|
|
40
|
+
conversionExpression: (value) => `rdfLiteral.toRdf(${value})`,
|
|
41
|
+
sourceTypeCheckExpression: (value) => `typeof ${value} === "number"`,
|
|
42
|
+
sourceTypeName: "number",
|
|
43
|
+
}, {
|
|
44
|
+
conversionExpression: (value) => `${this.dataFactoryVariable}.literal(${value})`,
|
|
45
|
+
sourceTypeCheckExpression: (value) => `typeof ${value} === "string"`,
|
|
46
|
+
sourceTypeName: "string",
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
this.defaultValue.ifJust((defaultValue) => {
|
|
50
|
+
conversions.push({
|
|
51
|
+
conversionExpression: () => this.rdfjsTermExpression(defaultValue),
|
|
52
|
+
sourceTypeCheckExpression: (value) => `typeof ${value} === "undefined"`,
|
|
53
|
+
sourceTypeName: "undefined",
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
conversions.push({
|
|
57
|
+
conversionExpression: (value) => value,
|
|
58
|
+
sourceTypeCheckExpression: (value) => `typeof ${value} === "object"`,
|
|
59
|
+
sourceTypeName: this.name,
|
|
60
|
+
});
|
|
61
|
+
return conversions;
|
|
62
|
+
}
|
|
63
|
+
get discriminatorProperty() {
|
|
64
|
+
return Maybe.of({
|
|
65
|
+
name: "termType",
|
|
66
|
+
type: "string",
|
|
67
|
+
values: [...this.nodeKinds],
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
get jsonName() {
|
|
71
|
+
invariant(this.nodeKinds.has("Literal") &&
|
|
72
|
+
(this.nodeKinds.has("BlankNode") || this.nodeKinds.has("NamedNode")), "IdentifierType and LiteralType should override");
|
|
73
|
+
return `{ readonly "@id": string, readonly termType: ${[...this.nodeKinds]
|
|
74
|
+
.filter((nodeKind) => nodeKind !== "Literal")
|
|
75
|
+
.map((nodeKind) => `"${nodeKind}"`)
|
|
76
|
+
.join(" | ")} } | { readonly "@language": string | undefined, readonly "@type": string | undefined, readonly "@value": string, readonly termType: "Literal" }`;
|
|
77
|
+
}
|
|
78
|
+
get name() {
|
|
79
|
+
return `(${[...this.nodeKinds]
|
|
80
|
+
.map((nodeKind) => `rdfjs.${nodeKind}`)
|
|
81
|
+
.join(" | ")})`;
|
|
82
|
+
}
|
|
83
|
+
get useImports() {
|
|
84
|
+
const imports = [Import.RDFJS_TYPES];
|
|
85
|
+
if (this.nodeKinds.has("Literal")) {
|
|
86
|
+
imports.push(Import.RDF_LITERAL);
|
|
87
|
+
}
|
|
88
|
+
return imports;
|
|
89
|
+
}
|
|
90
|
+
fromJsonExpression({ variables, }) {
|
|
91
|
+
invariant(this.nodeKinds.has("Literal") &&
|
|
92
|
+
(this.nodeKinds.has("BlankNode") || this.nodeKinds.has("NamedNode")), "IdentifierType and LiteralType should override");
|
|
93
|
+
return [...this.nodeKinds].reduce((expression, nodeKind) => {
|
|
94
|
+
let valueToNodeKind;
|
|
95
|
+
switch (nodeKind) {
|
|
96
|
+
case "BlankNode":
|
|
97
|
+
valueToNodeKind = `${this.dataFactoryVariable}.blankNode(${variables.value}["@id"].substring(2))`;
|
|
98
|
+
break;
|
|
99
|
+
case "Literal":
|
|
100
|
+
valueToNodeKind = `${this.dataFactoryVariable}.literal(${variables.value}["@value"], typeof ${variables.value}["@language"] !== "undefined" ? ${variables.value}["@language"] : (typeof ${variables.value}["@type"] !== "undefined" ? dataFactory.namedNode(${variables.value}["@type"]) : undefined))`;
|
|
101
|
+
break;
|
|
102
|
+
case "NamedNode":
|
|
103
|
+
valueToNodeKind = `${this.dataFactoryVariable}.namedNode(${variables.value}["@id"])`;
|
|
104
|
+
break;
|
|
105
|
+
default:
|
|
106
|
+
throw new RangeError(nodeKind);
|
|
107
|
+
}
|
|
108
|
+
return expression.length === 0
|
|
109
|
+
? valueToNodeKind
|
|
110
|
+
: `((${variables.value}.termType === "${nodeKind}") ? (${valueToNodeKind}) : (${expression}))`;
|
|
111
|
+
}, "");
|
|
112
|
+
}
|
|
113
|
+
fromRdfExpression({ variables, }) {
|
|
114
|
+
const chain = [
|
|
115
|
+
this.propertyFilterRdfResourceValuesExpression({ variables }),
|
|
116
|
+
];
|
|
117
|
+
// Have an rdfjsResource.Resource.Values here
|
|
118
|
+
if (this.hasValues.length === 1) {
|
|
119
|
+
chain.push(`find(_value => _value.toTerm().equals(${this.rdfjsTermExpression(this.hasValues[0])}))`);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
chain.push("head()");
|
|
123
|
+
}
|
|
124
|
+
// Have an rdfjsResource.Resource.Value here
|
|
125
|
+
this.defaultValue.ifJust((defaultValue) => {
|
|
126
|
+
// alt the default value before trying to convert the rdfjsResource.Resource.Value to the type
|
|
127
|
+
chain.push(`alt(purify.Either.of(new rdfjsResource.Resource.Value(${objectInitializer({ subject: variables.resource, predicate: variables.predicate, object: this.rdfjsTermExpression(defaultValue) })})))`);
|
|
128
|
+
});
|
|
129
|
+
// Last step: convert the rdfjsResource.Resource.Value to the type
|
|
130
|
+
chain.push(`chain(_value => ${this.propertyFromRdfResourceValueExpression({
|
|
131
|
+
variables: {
|
|
132
|
+
predicate: variables.predicate,
|
|
133
|
+
resource: variables.resource,
|
|
134
|
+
resourceValue: "_value",
|
|
135
|
+
},
|
|
136
|
+
})})`);
|
|
137
|
+
return chain.join(".");
|
|
138
|
+
}
|
|
139
|
+
hashStatements({ variables, }) {
|
|
140
|
+
return [
|
|
141
|
+
`${variables.hasher}.update(${variables.value}.termType);`,
|
|
142
|
+
`${variables.hasher}.update(${variables.value}.value);`,
|
|
143
|
+
];
|
|
144
|
+
}
|
|
145
|
+
jsonZodSchema({ variables, }) {
|
|
146
|
+
invariant(this.nodeKinds.has("Literal") &&
|
|
147
|
+
(this.nodeKinds.has("BlankNode") || this.nodeKinds.has("NamedNode")), "IdentifierType and LiteralType should override");
|
|
148
|
+
return `${variables.zod}.discriminatedUnion("termType", [${[
|
|
149
|
+
...this.nodeKinds,
|
|
150
|
+
]
|
|
151
|
+
.map((nodeKind) => {
|
|
152
|
+
switch (nodeKind) {
|
|
153
|
+
case "BlankNode":
|
|
154
|
+
case "NamedNode":
|
|
155
|
+
return `${variables.zod}.object({ "@id": ${variables.zod}.string().min(1), termType: ${variables.zod}.literal("${nodeKind}") })`;
|
|
156
|
+
case "Literal":
|
|
157
|
+
return `${variables.zod}.object({ "@language": ${variables.zod}.string().optional(), "@type": ${variables.zod}.string().optional(), "@value": ${variables.zod}.string(), termType: ${variables.zod}.literal("Literal") })`;
|
|
158
|
+
default:
|
|
159
|
+
throw new RangeError(nodeKind);
|
|
160
|
+
}
|
|
161
|
+
})
|
|
162
|
+
.join(", ")}])`;
|
|
163
|
+
}
|
|
164
|
+
sparqlWherePatterns(parameters) {
|
|
165
|
+
switch (parameters.context) {
|
|
166
|
+
case "property":
|
|
167
|
+
return this.defaultValue
|
|
168
|
+
.map(() => [
|
|
169
|
+
`{ patterns: [${super.sparqlWherePatterns(parameters).join(", ")}], type: "optional" }`,
|
|
170
|
+
])
|
|
171
|
+
.orDefault(super.sparqlWherePatterns(parameters));
|
|
172
|
+
case "type":
|
|
173
|
+
return super.sparqlWherePatterns(parameters);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
toJsonExpression({ variables, }) {
|
|
177
|
+
invariant(this.nodeKinds.has("Literal") &&
|
|
178
|
+
(this.nodeKinds.has("BlankNode") || this.nodeKinds.has("NamedNode")), "IdentifierType and LiteralType should override");
|
|
179
|
+
return [...this.nodeKinds].reduce((expression, nodeKind) => {
|
|
180
|
+
let valueToNodeKind;
|
|
181
|
+
switch (nodeKind) {
|
|
182
|
+
case "BlankNode":
|
|
183
|
+
valueToNodeKind = `{ "@id": \`_:\${${variables.value}.value}\`, termType: "${nodeKind}" as const }`;
|
|
184
|
+
break;
|
|
185
|
+
case "Literal":
|
|
186
|
+
valueToNodeKind = `{ "@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, termType: "${nodeKind}" as const }`;
|
|
187
|
+
break;
|
|
188
|
+
case "NamedNode":
|
|
189
|
+
valueToNodeKind = `{ "@id": ${variables.value}.value, termType: "${nodeKind}" as const }`;
|
|
190
|
+
break;
|
|
191
|
+
default:
|
|
192
|
+
throw new RangeError(nodeKind);
|
|
193
|
+
}
|
|
194
|
+
return expression.length === 0
|
|
195
|
+
? valueToNodeKind
|
|
196
|
+
: `(${variables.value}.termType === "${nodeKind}") ? ${valueToNodeKind} : ${expression}`;
|
|
197
|
+
}, "");
|
|
198
|
+
}
|
|
199
|
+
toRdfExpression({ variables, }) {
|
|
200
|
+
return this.defaultValue
|
|
201
|
+
.map((defaultValue) => `!${variables.value}.equals(${this.rdfjsTermExpression(defaultValue)}) ? ${variables.value} : undefined`)
|
|
202
|
+
.orDefault(variables.value);
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Filter the rdfjsResource.Resource.Values to those that are relevant to the type.
|
|
206
|
+
*
|
|
207
|
+
* This is done before
|
|
208
|
+
*/
|
|
209
|
+
propertyFilterRdfResourceValuesExpression({ variables, }) {
|
|
210
|
+
return variables.resourceValues;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Convert an rdfjsResource.Resource.Value to a value of this type.
|
|
214
|
+
* @param variables
|
|
215
|
+
* @protected
|
|
216
|
+
*/
|
|
217
|
+
propertyFromRdfResourceValueExpression({ variables, }) {
|
|
218
|
+
invariant(this.nodeKinds.has("Literal") &&
|
|
219
|
+
(this.nodeKinds.has("BlankNode") || this.nodeKinds.has("NamedNode")), "IdentifierType and LiteralType should override");
|
|
220
|
+
let expression = `purify.Either.of(${variables.resourceValue}.toTerm())`;
|
|
221
|
+
if (this.nodeKinds.size < 3) {
|
|
222
|
+
expression = `${expression}.chain(term => {
|
|
223
|
+
switch (term.termType) {
|
|
224
|
+
${[...this.nodeKinds].map((nodeKind) => `case "${nodeKind}":`).join("\n")} return purify.Either.of(term);
|
|
225
|
+
default: return purify.Left(new rdfjsResource.Resource.MistypedValueError(${objectInitializer({ actualValue: "term", expectedValueType: JSON.stringify(this.name), focusResource: variables.resource, predicate: variables.predicate })}));
|
|
226
|
+
}})`;
|
|
227
|
+
}
|
|
228
|
+
return expression;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
__decorate([
|
|
232
|
+
Memoize()
|
|
233
|
+
], TermType.prototype, "name", null);
|
|
234
|
+
//# sourceMappingURL=TermType.js.map
|
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
export declare class TsGenerator {
|
|
4
|
-
|
|
5
|
-
protected readonly configuration: TsGenerator.Configuration;
|
|
6
|
-
constructor(ast: ast.Ast, configuration?: TsGenerator.Configuration);
|
|
7
|
-
generate(): string;
|
|
1
|
+
import * as ast from "../../ast/index.js";
|
|
2
|
+
import type { Generator } from "../Generator.js";
|
|
3
|
+
export declare class TsGenerator implements Generator {
|
|
4
|
+
generate(ast_: ast.Ast): string;
|
|
8
5
|
private addDeclarations;
|
|
9
|
-
private addImportDeclarations;
|
|
10
|
-
}
|
|
11
|
-
export declare namespace TsGenerator {
|
|
12
|
-
const Configuration: typeof GlobalConfiguration;
|
|
13
|
-
type Configuration = GlobalConfiguration;
|
|
14
6
|
}
|
|
15
7
|
//# sourceMappingURL=TsGenerator.d.ts.map
|