@shaclmate/compiler 2.0.13 → 2.0.15
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 +178 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.d.ts +13 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +200 -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 +91 -19
- 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 +19 -0
- package/generators/ts/DateTimeType.js +66 -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 +17 -0
- package/generators/ts/Import.js +54 -0
- package/generators/ts/ListType.d.ts +19 -8
- package/generators/ts/ListType.js +206 -44
- 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 +48 -25
- package/generators/ts/ObjectType.js +234 -50
- package/generators/ts/ObjectUnionType.d.ts +58 -0
- package/generators/ts/ObjectUnionType.js +450 -0
- package/generators/ts/OptionType.d.ts +14 -4
- package/generators/ts/OptionType.js +70 -20
- package/generators/ts/PrimitiveType.d.ts +15 -5
- package/generators/ts/PrimitiveType.js +27 -31
- package/generators/ts/SetType.d.ts +14 -4
- package/generators/ts/SetType.js +108 -30
- package/generators/ts/SnippetDeclarations.d.ts +11 -0
- package/generators/ts/SnippetDeclarations.js +215 -0
- package/generators/ts/StringType.d.ts +8 -3
- package/generators/ts/StringType.js +57 -3
- package/generators/ts/TermType.d.ts +54 -0
- package/generators/ts/TermType.js +242 -0
- package/generators/ts/TsGenerator.d.ts +4 -12
- package/generators/ts/TsGenerator.js +57 -99
- package/generators/ts/Type.d.ts +117 -46
- package/generators/ts/Type.js +93 -59
- package/generators/ts/TypeFactory.d.ts +4 -5
- package/generators/ts/TypeFactory.js +224 -91
- package/generators/ts/UnionType.d.ts +20 -6
- package/generators/ts/UnionType.js +230 -120
- package/generators/ts/_ObjectType/IdentifierProperty.d.ts +27 -8
- package/generators/ts/_ObjectType/IdentifierProperty.js +153 -32
- package/generators/ts/_ObjectType/Property.d.ts +139 -9
- package/generators/ts/_ObjectType/Property.js +26 -3
- package/generators/ts/_ObjectType/ShaclProperty.d.ts +24 -5
- package/generators/ts/_ObjectType/ShaclProperty.js +103 -26
- package/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +23 -7
- package/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +83 -14
- 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/sparqlConstructQueryFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.js +21 -0
- package/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.js +20 -0
- package/generators/ts/_ObjectType/sparqlFunctionDeclarations.d.ts +4 -0
- package/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +78 -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 +275 -0
- package/input/generated.js +1436 -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 +46 -0
- package/package.json +15 -9
- 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,37 @@
|
|
|
1
1
|
import { Maybe } from "purify-ts";
|
|
2
|
-
import { fromRdf } from "rdf-literal";
|
|
3
2
|
import { LiteralType } from "./LiteralType.js";
|
|
3
|
+
import { SnippetDeclarations } from "./SnippetDeclarations.js";
|
|
4
4
|
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;
|
|
5
|
+
constructor({ primitiveDefaultValue, primitiveIn, ...superParameters }) {
|
|
6
|
+
super(superParameters);
|
|
7
|
+
this.equalsFunction = "strictEquals";
|
|
8
|
+
this.primitiveDefaultValue = primitiveDefaultValue;
|
|
9
|
+
this.primitiveIn = primitiveIn;
|
|
19
10
|
}
|
|
20
11
|
get discriminatorProperty() {
|
|
21
12
|
return Maybe.empty();
|
|
22
13
|
}
|
|
23
|
-
get
|
|
24
|
-
return
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
14
|
+
get jsonName() {
|
|
15
|
+
return this.name;
|
|
16
|
+
}
|
|
17
|
+
fromJsonExpression({ variables, }) {
|
|
18
|
+
return variables.value;
|
|
19
|
+
}
|
|
20
|
+
hashStatements({ variables, }) {
|
|
21
|
+
return [`${variables.hasher}.update(${variables.value}.toString());`];
|
|
22
|
+
}
|
|
23
|
+
snippetDeclarations(features) {
|
|
24
|
+
const snippetDeclarations = [];
|
|
25
|
+
if (features.has("equals")) {
|
|
26
|
+
snippetDeclarations.push(SnippetDeclarations.strictEquals);
|
|
27
|
+
}
|
|
28
|
+
return snippetDeclarations;
|
|
29
|
+
}
|
|
30
|
+
toJsonExpression({ variables, }) {
|
|
31
|
+
return variables.value;
|
|
32
|
+
}
|
|
33
|
+
propertyFilterRdfResourceValuesExpression({ variables, }) {
|
|
34
|
+
return variables.resourceValues;
|
|
39
35
|
}
|
|
40
36
|
}
|
|
41
37
|
//# sourceMappingURL=PrimitiveType.js.map
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { TsFeature } from "../../enums/index.js";
|
|
2
|
+
import type { Import } from "./Import.js";
|
|
1
3
|
import { Type } from "./Type.js";
|
|
2
4
|
export declare class SetType extends Type {
|
|
3
5
|
readonly itemType: Type;
|
|
@@ -8,12 +10,20 @@ export declare class SetType extends Type {
|
|
|
8
10
|
minCount: number;
|
|
9
11
|
});
|
|
10
12
|
get conversions(): readonly Type.Conversion[];
|
|
13
|
+
get equalsFunction(): string;
|
|
14
|
+
get jsonName(): string;
|
|
15
|
+
get mutable(): boolean;
|
|
11
16
|
get name(): string;
|
|
12
|
-
|
|
13
|
-
equalsFunction(): string;
|
|
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
|
+
snippetDeclarations(features: Set<TsFeature>): readonly string[];
|
|
23
|
+
sparqlConstructTemplateTriples({ context, variables, }: Parameters<Type["sparqlConstructTemplateTriples"]>[0]): readonly string[];
|
|
24
|
+
sparqlWherePatterns({ context, variables, }: Parameters<Type["sparqlWherePatterns"]>[0]): readonly string[];
|
|
25
|
+
toJsonExpression({ variables, }: Parameters<Type["toJsonExpression"]>[0]): string;
|
|
17
26
|
toRdfExpression({ variables, }: Parameters<Type["toRdfExpression"]>[0]): string;
|
|
27
|
+
useImports(features: Set<TsFeature>): readonly Import[];
|
|
18
28
|
}
|
|
19
29
|
//# sourceMappingURL=SetType.d.ts.map
|
package/generators/ts/SetType.js
CHANGED
|
@@ -4,70 +4,148 @@ 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";
|
|
9
|
+
import { SnippetDeclarations } from "./SnippetDeclarations.js";
|
|
8
10
|
import { Type } from "./Type.js";
|
|
11
|
+
import { objectInitializer } from "./objectInitializer.js";
|
|
9
12
|
export class SetType extends Type {
|
|
10
13
|
constructor({ itemType, minCount, ...superParameters }) {
|
|
11
14
|
super(superParameters);
|
|
12
15
|
this.kind = "SetType";
|
|
13
16
|
this.itemType = itemType;
|
|
14
17
|
this.minCount = minCount;
|
|
18
|
+
invariant(this.minCount >= 0);
|
|
15
19
|
}
|
|
16
20
|
get conversions() {
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
const conversions = [];
|
|
22
|
+
if (this.minCount === 0) {
|
|
23
|
+
conversions.push({
|
|
19
24
|
conversionExpression: () => "[]",
|
|
25
|
+
sourceTypeCheckExpression: (value) => `typeof ${value} === "undefined"`,
|
|
20
26
|
sourceTypeName: "undefined",
|
|
21
|
-
}
|
|
22
|
-
{
|
|
27
|
+
});
|
|
28
|
+
conversions.push({
|
|
23
29
|
conversionExpression: (value) => value,
|
|
24
30
|
sourceTypeCheckExpression: (value) => `Array.isArray(${value})`,
|
|
31
|
+
sourceTypeName: `readonly (${this.itemType.name})[]`,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
conversions.push({
|
|
36
|
+
conversionExpression: (value) => value,
|
|
37
|
+
sourceTypeCheckExpression: (value) => `purify.NonEmptyList.isNonEmpty(${value})`,
|
|
25
38
|
sourceTypeName: this.name,
|
|
26
|
-
}
|
|
27
|
-
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return conversions;
|
|
28
42
|
}
|
|
29
|
-
get
|
|
30
|
-
return `
|
|
43
|
+
get equalsFunction() {
|
|
44
|
+
return `((left, right) => arrayEquals(left, right, ${this.itemType.equalsFunction}))`;
|
|
31
45
|
}
|
|
32
|
-
|
|
33
|
-
|
|
46
|
+
get jsonName() {
|
|
47
|
+
if (this.minCount === 0) {
|
|
48
|
+
return `readonly (${this.itemType.jsonName})[]`;
|
|
49
|
+
}
|
|
50
|
+
return `purify.NonEmptyList<${this.itemType.jsonName}>`;
|
|
51
|
+
}
|
|
52
|
+
get mutable() {
|
|
53
|
+
return this.itemType.mutable;
|
|
34
54
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return "purifyHelpers.Equatable.arrayEquals";
|
|
55
|
+
get name() {
|
|
56
|
+
if (this.minCount === 0) {
|
|
57
|
+
return `readonly (${this.itemType.name})[]`;
|
|
39
58
|
}
|
|
40
|
-
return `
|
|
59
|
+
return `purify.NonEmptyList<${this.itemType.name}>`;
|
|
60
|
+
}
|
|
61
|
+
fromJsonExpression({ variables, }) {
|
|
62
|
+
let expression = variables.value;
|
|
63
|
+
if (this.minCount > 0) {
|
|
64
|
+
expression = `purify.NonEmptyList.fromArray(${expression}).unsafeCoerce()`;
|
|
65
|
+
}
|
|
66
|
+
const itemFromJsonExpression = this.itemType.fromJsonExpression({
|
|
67
|
+
variables: { value: "_item" },
|
|
68
|
+
});
|
|
69
|
+
return itemFromJsonExpression === "_item"
|
|
70
|
+
? expression
|
|
71
|
+
: `${expression}.map(_item => (${itemFromJsonExpression}))`;
|
|
41
72
|
}
|
|
42
73
|
fromRdfExpression({ variables, }) {
|
|
43
|
-
|
|
74
|
+
const itemFromRdfExpression = this.itemType.fromRdfExpression({
|
|
75
|
+
variables: { ...variables, resourceValues: "_item.toValues()" },
|
|
76
|
+
});
|
|
77
|
+
if (this.minCount === 0) {
|
|
78
|
+
return `purify.Either.of([...${variables.resourceValues}.flatMap(_item => ${itemFromRdfExpression}.toMaybe().toList())])`;
|
|
79
|
+
}
|
|
80
|
+
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
81
|
}
|
|
45
|
-
hashStatements({ variables, }) {
|
|
82
|
+
hashStatements({ depth, variables, }) {
|
|
46
83
|
return [
|
|
47
|
-
`for (const
|
|
84
|
+
`for (const _item${depth} of ${variables.value}) { ${this.itemType
|
|
48
85
|
.hashStatements({
|
|
86
|
+
depth: depth + 1,
|
|
49
87
|
variables: {
|
|
50
88
|
hasher: variables.hasher,
|
|
51
|
-
value:
|
|
89
|
+
value: `_item${depth}`,
|
|
52
90
|
},
|
|
53
91
|
})
|
|
54
92
|
.join("\n")} }`,
|
|
55
93
|
];
|
|
56
94
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
95
|
+
jsonUiSchemaElement(parameters) {
|
|
96
|
+
return this.itemType.jsonUiSchemaElement(parameters);
|
|
97
|
+
}
|
|
98
|
+
jsonZodSchema(parameters) {
|
|
99
|
+
let schema = `${this.itemType.jsonZodSchema(parameters)}.array()`;
|
|
100
|
+
if (this.minCount > 0) {
|
|
101
|
+
schema = `${schema}.nonempty().min(${this.minCount})`;
|
|
60
102
|
}
|
|
61
|
-
return
|
|
103
|
+
return schema;
|
|
62
104
|
}
|
|
63
|
-
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (itemTypeToRdfExpression === "value") {
|
|
68
|
-
return variables.value;
|
|
105
|
+
snippetDeclarations(features) {
|
|
106
|
+
const snippetDeclarations = [];
|
|
107
|
+
if (features.has("equals")) {
|
|
108
|
+
snippetDeclarations.push(SnippetDeclarations.arrayEquals);
|
|
69
109
|
}
|
|
70
|
-
return
|
|
110
|
+
return snippetDeclarations;
|
|
111
|
+
}
|
|
112
|
+
sparqlConstructTemplateTriples({ context, variables, }) {
|
|
113
|
+
switch (context) {
|
|
114
|
+
case "property":
|
|
115
|
+
return super.sparqlConstructTemplateTriples({ context, variables });
|
|
116
|
+
case "type":
|
|
117
|
+
return this.itemType.sparqlConstructTemplateTriples({
|
|
118
|
+
context,
|
|
119
|
+
variables,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
sparqlWherePatterns({ context, variables, }) {
|
|
124
|
+
switch (context) {
|
|
125
|
+
case "property": {
|
|
126
|
+
const patterns = super.sparqlWherePatterns({ context, variables });
|
|
127
|
+
if (patterns.length === 0) {
|
|
128
|
+
return [];
|
|
129
|
+
}
|
|
130
|
+
return this.minCount > 0
|
|
131
|
+
? patterns
|
|
132
|
+
: [`{ patterns: [${patterns.join(", ")}], type: "optional" }`];
|
|
133
|
+
}
|
|
134
|
+
case "type": {
|
|
135
|
+
return this.itemType.sparqlWherePatterns({ context, variables });
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
toJsonExpression({ variables, }) {
|
|
140
|
+
return `${variables.value}.map(_item => (${this.itemType.toJsonExpression({ variables: { value: "_item" } })}))`;
|
|
141
|
+
}
|
|
142
|
+
toRdfExpression({ variables, }) {
|
|
143
|
+
return `${variables.value}.map((_item) => ${this.itemType.toRdfExpression({
|
|
144
|
+
variables: { ...variables, value: "_item" },
|
|
145
|
+
})})`;
|
|
146
|
+
}
|
|
147
|
+
useImports(features) {
|
|
148
|
+
return this.itemType.useImports(features);
|
|
71
149
|
}
|
|
72
150
|
}
|
|
73
151
|
__decorate([
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare namespace SnippetDeclarations {
|
|
2
|
+
const arrayEquals = "export function arrayEquals<T>(\n leftArray: readonly T[],\n rightArray: readonly T[],\n elementEquals: (left: T, right: T) => boolean | EqualsResult,\n): EqualsResult {\n if (leftArray.length !== rightArray.length) {\n return purify.Left({\n left: leftArray,\n right: rightArray,\n type: \"ArrayLength\",\n });\n }\n\n for (\n let leftElementIndex = 0;\n leftElementIndex < leftArray.length;\n leftElementIndex++\n ) {\n const leftElement = leftArray[leftElementIndex];\n\n const rightUnequals: EqualsResult.Unequal[] = [];\n for (\n let rightElementIndex = 0;\n rightElementIndex < rightArray.length;\n rightElementIndex++\n ) {\n const rightElement = rightArray[rightElementIndex];\n\n const leftElementEqualsRightElement =\n EqualsResult.fromBooleanEqualsResult(\n leftElement,\n rightElement,\n elementEquals(leftElement, rightElement),\n );\n if (leftElementEqualsRightElement.isRight()) {\n break; // left element === right element, break out of the right iteration\n }\n rightUnequals.push(\n leftElementEqualsRightElement.extract() as EqualsResult.Unequal,\n );\n }\n\n if (rightUnequals.length === rightArray.length) {\n // All right elements were unequal to the left element\n return purify.Left({\n left: {\n array: leftArray,\n element: leftElement,\n elementIndex: leftElementIndex,\n },\n right: {\n array: rightArray,\n unequals: rightUnequals,\n },\n type: \"ArrayElement\",\n });\n }\n // Else there was a right element equal to the left element, continue to the next left element\n }\n\n return EqualsResult.Equal;\n}\n";
|
|
3
|
+
const booleanEquals = "/**\n * Compare two objects with equals(other: T): boolean methods and return an EqualsResult.\n */\nexport function booleanEquals<T extends { equals: (other: T) => boolean }>(\n left: T,\n right: T,\n): EqualsResult {\n return EqualsResult.fromBooleanEqualsResult(\n left,\n right,\n left.equals(right),\n );\n}";
|
|
4
|
+
const dateEquals = "/**\n * Compare two Dates and return an EqualsResult.\n */\nexport function dateEquals(left: Date, right: Date): EqualsResult {\n return EqualsResult.fromBooleanEqualsResult(\n left,\n right,\n left.getTime() === right.getTime(),\n );\n}";
|
|
5
|
+
const EqualsResult = "export type EqualsResult = purify.Either<EqualsResult.Unequal, true>;\n\nexport namespace EqualsResult {\n export const Equal: EqualsResult = purify.Either.of<Unequal, true>(true);\n\n export function fromBooleanEqualsResult(\n left: any,\n right: any,\n equalsResult: boolean | EqualsResult,\n ): EqualsResult {\n if (typeof equalsResult !== \"boolean\") {\n return equalsResult;\n }\n\n if (equalsResult) {\n return Equal;\n }\n return purify.Left({\n left,\n right,\n type: \"BooleanEquals\",\n });\n }\n\n export type Unequal =\n | {\n readonly left: {\n readonly array: readonly any[];\n readonly element: any;\n readonly elementIndex: number;\n };\n readonly right: {\n readonly array: readonly any[];\n readonly unequals: readonly Unequal[];\n };\n readonly type: \"ArrayElement\";\n }\n | {\n readonly left: readonly any[];\n readonly right: readonly any[];\n readonly type: \"ArrayLength\";\n }\n | {\n readonly left: any;\n readonly right: any;\n readonly type: \"BooleanEquals\";\n }\n | {\n readonly left: any;\n readonly right: any;\n readonly type: \"LeftError\";\n }\n | {\n readonly right: any;\n readonly type: \"LeftNull\";\n }\n | {\n readonly left: bigint | boolean | number | string;\n readonly right: bigint | boolean | number | string;\n readonly type: \"Primitive\";\n }\n | {\n readonly left: object;\n readonly right: object;\n readonly propertyName: string;\n readonly propertyValuesUnequal: Unequal;\n readonly type: \"Property\";\n }\n | {\n readonly left: any;\n readonly right: any;\n readonly type: \"RightError\";\n }\n | {\n readonly left: any;\n readonly type: \"RightNull\";\n };\n} \n";
|
|
6
|
+
const maybeEquals = "export function maybeEquals<T>(\n leftMaybe: purify.Maybe<T>,\n rightMaybe: purify.Maybe<T>,\n valueEquals: (left: T, right: T) => boolean | EqualsResult,\n): EqualsResult {\n if (leftMaybe.isJust()) {\n if (rightMaybe.isJust()) {\n return EqualsResult.fromBooleanEqualsResult(\n leftMaybe,\n rightMaybe,\n valueEquals(leftMaybe.unsafeCoerce(), rightMaybe.unsafeCoerce()),\n );\n }\n return purify.Left({\n left: leftMaybe.unsafeCoerce(),\n type: \"RightNull\",\n });\n }\n\n if (rightMaybe.isJust()) {\n return purify.Left({\n right: rightMaybe.unsafeCoerce(),\n type: \"LeftNull\",\n });\n }\n\n return EqualsResult.Equal;\n}\n";
|
|
7
|
+
const strictEquals = "/**\n * Compare two values for strict equality (===), returning an EqualsResult rather than a boolean.\n */\nexport function strictEquals<T extends bigint | boolean | number | string>(\n left: T,\n right: T,\n): EqualsResult {\n return EqualsResult.fromBooleanEqualsResult(left, right, left === right);\n}";
|
|
8
|
+
const UnwrapL = "type UnwrapL<T> = T extends purify.Either<infer L, any> ? L : never";
|
|
9
|
+
const UnwrapR = "type UnwrapR<T> = T extends purify.Either<any, infer R> ? R : never";
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=SnippetDeclarations.d.ts.map
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
export var SnippetDeclarations;
|
|
2
|
+
(function (SnippetDeclarations) {
|
|
3
|
+
SnippetDeclarations.arrayEquals = `\
|
|
4
|
+
export function arrayEquals<T>(
|
|
5
|
+
leftArray: readonly T[],
|
|
6
|
+
rightArray: readonly T[],
|
|
7
|
+
elementEquals: (left: T, right: T) => boolean | EqualsResult,
|
|
8
|
+
): EqualsResult {
|
|
9
|
+
if (leftArray.length !== rightArray.length) {
|
|
10
|
+
return purify.Left({
|
|
11
|
+
left: leftArray,
|
|
12
|
+
right: rightArray,
|
|
13
|
+
type: "ArrayLength",
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
for (
|
|
18
|
+
let leftElementIndex = 0;
|
|
19
|
+
leftElementIndex < leftArray.length;
|
|
20
|
+
leftElementIndex++
|
|
21
|
+
) {
|
|
22
|
+
const leftElement = leftArray[leftElementIndex];
|
|
23
|
+
|
|
24
|
+
const rightUnequals: EqualsResult.Unequal[] = [];
|
|
25
|
+
for (
|
|
26
|
+
let rightElementIndex = 0;
|
|
27
|
+
rightElementIndex < rightArray.length;
|
|
28
|
+
rightElementIndex++
|
|
29
|
+
) {
|
|
30
|
+
const rightElement = rightArray[rightElementIndex];
|
|
31
|
+
|
|
32
|
+
const leftElementEqualsRightElement =
|
|
33
|
+
EqualsResult.fromBooleanEqualsResult(
|
|
34
|
+
leftElement,
|
|
35
|
+
rightElement,
|
|
36
|
+
elementEquals(leftElement, rightElement),
|
|
37
|
+
);
|
|
38
|
+
if (leftElementEqualsRightElement.isRight()) {
|
|
39
|
+
break; // left element === right element, break out of the right iteration
|
|
40
|
+
}
|
|
41
|
+
rightUnequals.push(
|
|
42
|
+
leftElementEqualsRightElement.extract() as EqualsResult.Unequal,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (rightUnequals.length === rightArray.length) {
|
|
47
|
+
// All right elements were unequal to the left element
|
|
48
|
+
return purify.Left({
|
|
49
|
+
left: {
|
|
50
|
+
array: leftArray,
|
|
51
|
+
element: leftElement,
|
|
52
|
+
elementIndex: leftElementIndex,
|
|
53
|
+
},
|
|
54
|
+
right: {
|
|
55
|
+
array: rightArray,
|
|
56
|
+
unequals: rightUnequals,
|
|
57
|
+
},
|
|
58
|
+
type: "ArrayElement",
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
// Else there was a right element equal to the left element, continue to the next left element
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return EqualsResult.Equal;
|
|
65
|
+
}
|
|
66
|
+
`;
|
|
67
|
+
SnippetDeclarations.booleanEquals = `\
|
|
68
|
+
/**
|
|
69
|
+
* Compare two objects with equals(other: T): boolean methods and return an EqualsResult.
|
|
70
|
+
*/
|
|
71
|
+
export function booleanEquals<T extends { equals: (other: T) => boolean }>(
|
|
72
|
+
left: T,
|
|
73
|
+
right: T,
|
|
74
|
+
): EqualsResult {
|
|
75
|
+
return EqualsResult.fromBooleanEqualsResult(
|
|
76
|
+
left,
|
|
77
|
+
right,
|
|
78
|
+
left.equals(right),
|
|
79
|
+
);
|
|
80
|
+
}`;
|
|
81
|
+
SnippetDeclarations.dateEquals = `\
|
|
82
|
+
/**
|
|
83
|
+
* Compare two Dates and return an EqualsResult.
|
|
84
|
+
*/
|
|
85
|
+
export function dateEquals(left: Date, right: Date): EqualsResult {
|
|
86
|
+
return EqualsResult.fromBooleanEqualsResult(
|
|
87
|
+
left,
|
|
88
|
+
right,
|
|
89
|
+
left.getTime() === right.getTime(),
|
|
90
|
+
);
|
|
91
|
+
}`;
|
|
92
|
+
SnippetDeclarations.EqualsResult = `\
|
|
93
|
+
export type EqualsResult = purify.Either<EqualsResult.Unequal, true>;
|
|
94
|
+
|
|
95
|
+
export namespace EqualsResult {
|
|
96
|
+
export const Equal: EqualsResult = purify.Either.of<Unequal, true>(true);
|
|
97
|
+
|
|
98
|
+
export function fromBooleanEqualsResult(
|
|
99
|
+
left: any,
|
|
100
|
+
right: any,
|
|
101
|
+
equalsResult: boolean | EqualsResult,
|
|
102
|
+
): EqualsResult {
|
|
103
|
+
if (typeof equalsResult !== "boolean") {
|
|
104
|
+
return equalsResult;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (equalsResult) {
|
|
108
|
+
return Equal;
|
|
109
|
+
}
|
|
110
|
+
return purify.Left({
|
|
111
|
+
left,
|
|
112
|
+
right,
|
|
113
|
+
type: "BooleanEquals",
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export type Unequal =
|
|
118
|
+
| {
|
|
119
|
+
readonly left: {
|
|
120
|
+
readonly array: readonly any[];
|
|
121
|
+
readonly element: any;
|
|
122
|
+
readonly elementIndex: number;
|
|
123
|
+
};
|
|
124
|
+
readonly right: {
|
|
125
|
+
readonly array: readonly any[];
|
|
126
|
+
readonly unequals: readonly Unequal[];
|
|
127
|
+
};
|
|
128
|
+
readonly type: "ArrayElement";
|
|
129
|
+
}
|
|
130
|
+
| {
|
|
131
|
+
readonly left: readonly any[];
|
|
132
|
+
readonly right: readonly any[];
|
|
133
|
+
readonly type: "ArrayLength";
|
|
134
|
+
}
|
|
135
|
+
| {
|
|
136
|
+
readonly left: any;
|
|
137
|
+
readonly right: any;
|
|
138
|
+
readonly type: "BooleanEquals";
|
|
139
|
+
}
|
|
140
|
+
| {
|
|
141
|
+
readonly left: any;
|
|
142
|
+
readonly right: any;
|
|
143
|
+
readonly type: "LeftError";
|
|
144
|
+
}
|
|
145
|
+
| {
|
|
146
|
+
readonly right: any;
|
|
147
|
+
readonly type: "LeftNull";
|
|
148
|
+
}
|
|
149
|
+
| {
|
|
150
|
+
readonly left: bigint | boolean | number | string;
|
|
151
|
+
readonly right: bigint | boolean | number | string;
|
|
152
|
+
readonly type: "Primitive";
|
|
153
|
+
}
|
|
154
|
+
| {
|
|
155
|
+
readonly left: object;
|
|
156
|
+
readonly right: object;
|
|
157
|
+
readonly propertyName: string;
|
|
158
|
+
readonly propertyValuesUnequal: Unequal;
|
|
159
|
+
readonly type: "Property";
|
|
160
|
+
}
|
|
161
|
+
| {
|
|
162
|
+
readonly left: any;
|
|
163
|
+
readonly right: any;
|
|
164
|
+
readonly type: "RightError";
|
|
165
|
+
}
|
|
166
|
+
| {
|
|
167
|
+
readonly left: any;
|
|
168
|
+
readonly type: "RightNull";
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
`;
|
|
172
|
+
SnippetDeclarations.maybeEquals = `\
|
|
173
|
+
export function maybeEquals<T>(
|
|
174
|
+
leftMaybe: purify.Maybe<T>,
|
|
175
|
+
rightMaybe: purify.Maybe<T>,
|
|
176
|
+
valueEquals: (left: T, right: T) => boolean | EqualsResult,
|
|
177
|
+
): EqualsResult {
|
|
178
|
+
if (leftMaybe.isJust()) {
|
|
179
|
+
if (rightMaybe.isJust()) {
|
|
180
|
+
return EqualsResult.fromBooleanEqualsResult(
|
|
181
|
+
leftMaybe,
|
|
182
|
+
rightMaybe,
|
|
183
|
+
valueEquals(leftMaybe.unsafeCoerce(), rightMaybe.unsafeCoerce()),
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
return purify.Left({
|
|
187
|
+
left: leftMaybe.unsafeCoerce(),
|
|
188
|
+
type: "RightNull",
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (rightMaybe.isJust()) {
|
|
193
|
+
return purify.Left({
|
|
194
|
+
right: rightMaybe.unsafeCoerce(),
|
|
195
|
+
type: "LeftNull",
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return EqualsResult.Equal;
|
|
200
|
+
}
|
|
201
|
+
`;
|
|
202
|
+
SnippetDeclarations.strictEquals = `\
|
|
203
|
+
/**
|
|
204
|
+
* Compare two values for strict equality (===), returning an EqualsResult rather than a boolean.
|
|
205
|
+
*/
|
|
206
|
+
export function strictEquals<T extends bigint | boolean | number | string>(
|
|
207
|
+
left: T,
|
|
208
|
+
right: T,
|
|
209
|
+
): EqualsResult {
|
|
210
|
+
return EqualsResult.fromBooleanEqualsResult(left, right, left === right);
|
|
211
|
+
}`;
|
|
212
|
+
SnippetDeclarations.UnwrapL = "type UnwrapL<T> = T extends purify.Either<infer L, any> ? L : never";
|
|
213
|
+
SnippetDeclarations.UnwrapR = "type UnwrapR<T> = T extends purify.Either<any, infer R> ? R : never";
|
|
214
|
+
})(SnippetDeclarations || (SnippetDeclarations = {}));
|
|
215
|
+
//# sourceMappingURL=SnippetDeclarations.js.map
|
|
@@ -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,54 @@
|
|
|
1
|
+
import type { BlankNode, Literal, NamedNode } from "@rdfjs/types";
|
|
2
|
+
import { Maybe } from "purify-ts";
|
|
3
|
+
import type { TsFeature } from "../../enums/index.js";
|
|
4
|
+
import { Import } from "./Import.js";
|
|
5
|
+
import { Type } from "./Type.js";
|
|
6
|
+
/**
|
|
7
|
+
* Abstract base class for IdentifierType and LiteralType.
|
|
8
|
+
*/
|
|
9
|
+
export declare class TermType<TermT extends BlankNode | Literal | NamedNode> extends Type {
|
|
10
|
+
readonly defaultValue: Maybe<TermT>;
|
|
11
|
+
readonly equalsFunction: string;
|
|
12
|
+
readonly hasValues: readonly TermT[];
|
|
13
|
+
readonly in_: readonly TermT[];
|
|
14
|
+
readonly mutable: boolean;
|
|
15
|
+
readonly nodeKinds: Set<TermT["termType"]>;
|
|
16
|
+
constructor({ defaultValue, hasValues, in_, nodeKinds, ...superParameters }: {
|
|
17
|
+
defaultValue: Maybe<TermT>;
|
|
18
|
+
hasValues: readonly TermT[];
|
|
19
|
+
in_: readonly TermT[];
|
|
20
|
+
nodeKinds: Set<TermT["termType"]>;
|
|
21
|
+
} & ConstructorParameters<typeof Type>[0]);
|
|
22
|
+
get conversions(): readonly Type.Conversion[];
|
|
23
|
+
get discriminatorProperty(): Maybe<Type.DiscriminatorProperty>;
|
|
24
|
+
get jsonName(): string;
|
|
25
|
+
get name(): string;
|
|
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
|
+
snippetDeclarations(features: Set<TsFeature>): readonly string[];
|
|
31
|
+
sparqlWherePatterns(parameters: Parameters<Type["sparqlWherePatterns"]>[0]): readonly string[];
|
|
32
|
+
toJsonExpression({ variables, }: Parameters<Type["toJsonExpression"]>[0]): string;
|
|
33
|
+
toRdfExpression({ variables, }: Parameters<Type["toRdfExpression"]>[0]): string;
|
|
34
|
+
useImports(): readonly Import[];
|
|
35
|
+
/**
|
|
36
|
+
* Filter the rdfjsResource.Resource.Values to those that are relevant to the type.
|
|
37
|
+
*
|
|
38
|
+
* This is done before
|
|
39
|
+
*/
|
|
40
|
+
protected propertyFilterRdfResourceValuesExpression({ variables, }: Parameters<Type["fromRdfExpression"]>[0]): string;
|
|
41
|
+
/**
|
|
42
|
+
* Convert an rdfjsResource.Resource.Value to a value of this type.
|
|
43
|
+
* @param variables
|
|
44
|
+
* @protected
|
|
45
|
+
*/
|
|
46
|
+
protected propertyFromRdfResourceValueExpression({ variables, }: {
|
|
47
|
+
variables: {
|
|
48
|
+
predicate: string;
|
|
49
|
+
resource: string;
|
|
50
|
+
resourceValue: string;
|
|
51
|
+
};
|
|
52
|
+
}): string;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=TermType.d.ts.map
|