@shaclmate/compiler 4.0.33 → 4.0.35
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/dist/Compiler.d.ts +0 -3
- package/dist/Compiler.js +0 -2
- package/dist/ShapesGraphToAstTransformer.d.ts +1 -4
- package/dist/ShapesGraphToAstTransformer.js +1 -5
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +1 -3
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompoundType.js +4 -7
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstListType.js +0 -1
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstObjectType.js +1 -3
- package/dist/ast/AbstractCompoundType.d.ts +6 -4
- package/dist/ast/AbstractCompoundType.js +4 -37
- package/dist/ast/ObjectType.d.ts +1 -7
- package/dist/ast/ObjectType.js +1 -6
- package/dist/generators/ts/AbstractCollectionType.d.ts +9 -8
- package/dist/generators/ts/AbstractCollectionType.js +38 -120
- package/dist/generators/ts/AbstractContainerType.d.ts +3 -1
- package/dist/generators/ts/AbstractContainerType.js +20 -0
- package/dist/generators/ts/AbstractDateType.d.ts +5 -10
- package/dist/generators/ts/AbstractDateType.js +5 -32
- package/dist/generators/ts/AbstractIdentifierType.d.ts +4 -1
- package/dist/generators/ts/AbstractIdentifierType.js +0 -17
- package/dist/generators/ts/AbstractLazyObjectType.d.ts +9 -5
- package/dist/generators/ts/AbstractLazyObjectType.js +22 -21
- package/dist/generators/ts/AbstractLiteralType.d.ts +12 -4
- package/dist/generators/ts/AbstractLiteralType.js +3 -3
- package/dist/generators/ts/AbstractNamedUnionType.d.ts +2 -5
- package/dist/generators/ts/AbstractNamedUnionType.js +27 -58
- package/dist/generators/ts/AbstractNumericType.d.ts +3 -9
- package/dist/generators/ts/AbstractNumericType.js +6 -13
- package/dist/generators/ts/AbstractPrimitiveType.d.ts +9 -4
- package/dist/generators/ts/AbstractPrimitiveType.js +11 -18
- package/dist/generators/ts/AbstractTermType.d.ts +10 -5
- package/dist/generators/ts/AbstractTermType.js +14 -53
- package/dist/generators/ts/AbstractType.d.ts +39 -24
- package/dist/generators/ts/AbstractType.js +4 -2
- package/dist/generators/ts/AbstractUnionType.d.ts +3 -2
- package/dist/generators/ts/AbstractUnionType.js +29 -39
- package/dist/generators/ts/AnonymousUnionType.d.ts +1 -1
- package/dist/generators/ts/AnonymousUnionType.js +3 -3
- package/dist/generators/ts/BigDecimalType.d.ts +7 -4
- package/dist/generators/ts/BigDecimalType.js +11 -45
- package/dist/generators/ts/BigIntType.d.ts +3 -4
- package/dist/generators/ts/BigIntType.js +6 -17
- package/dist/generators/ts/BlankNodeType.d.ts +8 -7
- package/dist/generators/ts/BlankNodeType.js +18 -5
- package/dist/generators/ts/BooleanType.d.ts +6 -9
- package/dist/generators/ts/BooleanType.js +9 -16
- package/dist/generators/ts/DateTimeType.d.ts +4 -1
- package/dist/generators/ts/DateTimeType.js +6 -13
- package/dist/generators/ts/DateType.d.ts +4 -1
- package/dist/generators/ts/DateType.js +7 -14
- package/dist/generators/ts/DefaultValueType.d.ts +6 -6
- package/dist/generators/ts/DefaultValueType.js +30 -63
- package/dist/generators/ts/FloatType.d.ts +3 -3
- package/dist/generators/ts/FloatType.js +5 -5
- package/dist/generators/ts/IdentifierType.d.ts +7 -6
- package/dist/generators/ts/IdentifierType.js +26 -5
- package/dist/generators/ts/IntType.d.ts +3 -3
- package/dist/generators/ts/IntType.js +5 -5
- package/dist/generators/ts/IriType.d.ts +9 -12
- package/dist/generators/ts/IriType.js +43 -32
- package/dist/generators/ts/LazyObjectOptionType.d.ts +2 -1
- package/dist/generators/ts/LazyObjectOptionType.js +23 -44
- package/dist/generators/ts/LazyObjectSetType.d.ts +2 -1
- package/dist/generators/ts/LazyObjectSetType.js +19 -29
- package/dist/generators/ts/LazyObjectType.d.ts +2 -1
- package/dist/generators/ts/LazyObjectType.js +18 -26
- package/dist/generators/ts/LiteralType.d.ts +6 -3
- package/dist/generators/ts/LiteralType.js +27 -13
- package/dist/generators/ts/NamedObjectType.d.ts +7 -9
- package/dist/generators/ts/NamedObjectType.js +24 -32
- package/dist/generators/ts/NamedObjectUnionType.d.ts +3 -1
- package/dist/generators/ts/NamedObjectUnionType.js +21 -14
- package/dist/generators/ts/OptionType.d.ts +6 -5
- package/dist/generators/ts/OptionType.js +31 -51
- package/dist/generators/ts/Reusables.d.ts +3 -1
- package/dist/generators/ts/Reusables.js +2 -1
- package/dist/generators/ts/SetType.d.ts +0 -1
- package/dist/generators/ts/SetType.js +4 -22
- package/dist/generators/ts/SnippetFactory.d.ts +2 -0
- package/dist/generators/ts/Snippets.d.ts +36 -8
- package/dist/generators/ts/Snippets.js +207 -30
- package/dist/generators/ts/StringType.d.ts +6 -10
- package/dist/generators/ts/StringType.js +8 -21
- package/dist/generators/ts/TermType.d.ts +2 -4
- package/dist/generators/ts/TermType.js +6 -10
- package/dist/generators/ts/TsGenerator.d.ts +14 -1
- package/dist/generators/ts/TsGenerator.js +41 -12
- package/dist/generators/ts/TypeFactory.d.ts +8 -4
- package/dist/generators/ts/TypeFactory.js +73 -49
- package/dist/generators/ts/ZodGenerator.js +6 -3
- package/dist/generators/ts/_NamedObjectType/AbstractProperty.d.ts +27 -20
- package/dist/generators/ts/_NamedObjectType/AbstractProperty.js +4 -2
- package/dist/generators/ts/_NamedObjectType/DiscriminantProperty.d.ts +7 -7
- package/dist/generators/ts/_NamedObjectType/DiscriminantProperty.js +9 -9
- package/dist/generators/ts/_NamedObjectType/IdentifierProperty.d.ts +6 -6
- package/dist/generators/ts/_NamedObjectType/IdentifierProperty.js +36 -39
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_createFunctionDeclaration.js +34 -31
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_equalsFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlConstructTriplesFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlWherePatternsFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromJsonFunctionDeclaration.js +31 -19
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceFunctionDeclaration.js +30 -36
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceValuesFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfTypeVariableStatement.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_graphqlTypeVariableStatement.js +2 -3
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_hashFunctionDeclarations.js +6 -8
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_isTypeFunctionDeclaration.js +1 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonParseFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonSchemaFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonTypeAliasDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonUiSchemaFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_objectSetMethodNames.d.ts +2 -0
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_objectSetMethodNames.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_sparqlConstructQueryFunctionDeclaration.d.ts +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_sparqlConstructQueryFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_sparqlConstructQueryStringFunctionDeclaration.d.ts +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_sparqlConstructQueryStringFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toJsonFunctionDeclaration.js +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toRdfResourceFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toStringFunctionDeclarations.js +14 -18
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_valueSparqlConstructTriplesFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_valueSparqlWherePatternsFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/ShaclProperty.d.ts +7 -7
- package/dist/generators/ts/_NamedObjectType/ShaclProperty.js +41 -29
- package/dist/generators/ts/_snippets/snippets_ConversionFunction.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_ConversionFunction.js +4 -0
- package/dist/generators/ts/_snippets/snippets_DefaultValueSchema.js +3 -3
- package/dist/generators/ts/_snippets/snippets_HashFunction.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_HashFunction.js +4 -0
- package/dist/generators/ts/_snippets/snippets_PropertyPath.js +34 -24
- package/dist/generators/ts/_snippets/snippets_ValidationFunction.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_ValidationFunction.js +4 -0
- package/dist/generators/ts/_snippets/snippets_convertToArray.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToArray.js +8 -0
- package/dist/generators/ts/_snippets/snippets_convertToBlankNode.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToBlankNode.js +11 -0
- package/dist/generators/ts/_snippets/snippets_convertToBlankNodeIdentifierProperty.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToBlankNodeIdentifierProperty.js +17 -0
- package/dist/generators/ts/_snippets/snippets_convertToIdentifier.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToIdentifier.js +13 -0
- package/dist/generators/ts/_snippets/snippets_convertToIdentifierProperty.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToIdentifierProperty.js +21 -0
- package/dist/generators/ts/_snippets/snippets_convertToIri.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToIri.js +11 -0
- package/dist/generators/ts/_snippets/snippets_convertToIriIdentifierProperty.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToIriIdentifierProperty.js +17 -0
- package/dist/generators/ts/_snippets/snippets_convertToLazyObject.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToLazyObject.js +15 -0
- package/dist/generators/ts/_snippets/snippets_convertToLazyObjectOption.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToLazyObjectOption.js +31 -0
- package/dist/generators/ts/_snippets/snippets_convertToLazyObjectSet.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToLazyObjectSet.js +25 -0
- package/dist/generators/ts/_snippets/snippets_convertToLiteral.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToLiteral.js +13 -0
- package/dist/generators/ts/_snippets/snippets_convertToMaybe.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToMaybe.js +19 -0
- package/dist/generators/ts/_snippets/snippets_convertWithDefaultValue.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertWithDefaultValue.js +11 -0
- package/dist/generators/ts/_snippets/snippets_defaultValueSparqlWherePatterns.js +1 -1
- package/dist/generators/ts/_snippets/snippets_hashArray.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_hashArray.js +11 -0
- package/dist/generators/ts/_snippets/snippets_hashBigDecimal.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_hashBigDecimal.js +7 -0
- package/dist/generators/ts/_snippets/snippets_hashBoolean.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_hashBoolean.js +7 -0
- package/dist/generators/ts/_snippets/snippets_hashDate.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_hashDate.js +7 -0
- package/dist/generators/ts/_snippets/snippets_hashDateTime.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_hashDateTime.js +7 -0
- package/dist/generators/ts/_snippets/snippets_hashMaybe.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_hashMaybe.js +11 -0
- package/dist/generators/ts/_snippets/snippets_hashNumeric.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_hashNumeric.js +7 -0
- package/dist/generators/ts/_snippets/snippets_hashString.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_hashString.js +7 -0
- package/dist/generators/ts/_snippets/snippets_hashTerm.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_hashTerm.js +12 -0
- package/dist/generators/ts/_snippets/snippets_identityConversionFunction.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_identityConversionFunction.js +6 -0
- package/dist/generators/ts/_snippets/snippets_identityValidationFunction.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_identityValidationFunction.js +6 -0
- package/dist/generators/ts/_snippets/snippets_toIsoDateString.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_toIsoDateString.js +6 -0
- package/dist/generators/ts/_snippets/snippets_validateArray.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_validateArray.js +13 -0
- package/dist/generators/ts/_snippets/snippets_validateMaybe.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_validateMaybe.js +7 -0
- package/dist/generators/ts/graphqlSchemaVariableStatement.d.ts +1 -1
- package/dist/generators/ts/graphqlSchemaVariableStatement.js +7 -4
- package/dist/generators/ts/objectSetDeclarations.js +4 -34
- package/dist/generators/ts/objectSetInterfaceDeclaration.js +1 -1
- package/dist/generators/ts/objectSetMethodSignatures.js +2 -2
- package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +2 -2
- package/dist/generators/ts/sparqlObjectSetClassDeclaration.js +2 -2
- package/dist/input/ShapesGraph.d.ts +5 -8
- package/dist/input/ShapesGraph.js +5 -6
- package/dist/input/generated.d.ts +175 -230
- package/dist/input/generated.js +226 -1748
- package/package.json +2 -2
- package/dist/_ShapesGraphToAstTransformer/nodeShapeTsFeatures.d.ts +0 -6
- package/dist/_ShapesGraphToAstTransformer/nodeShapeTsFeatures.js +0 -67
- package/dist/generators/ts/_snippets/snippets_isReadonlyBigIntArray.d.ts +0 -3
- package/dist/generators/ts/_snippets/snippets_isReadonlyBigIntArray.js +0 -6
- package/dist/generators/ts/_snippets/snippets_isReadonlyBooleanArray.d.ts +0 -3
- package/dist/generators/ts/_snippets/snippets_isReadonlyBooleanArray.js +0 -6
- package/dist/generators/ts/_snippets/snippets_isReadonlyNumberArray.d.ts +0 -3
- package/dist/generators/ts/_snippets/snippets_isReadonlyNumberArray.js +0 -6
- package/dist/generators/ts/_snippets/snippets_isReadonlyObjectArray.d.ts +0 -3
- package/dist/generators/ts/_snippets/snippets_isReadonlyObjectArray.js +0 -6
- package/dist/generators/ts/_snippets/snippets_isReadonlyStringArray.d.ts +0 -3
- package/dist/generators/ts/_snippets/snippets_isReadonlyStringArray.js +0 -6
- package/dist/generators/ts/syntheticNamePrefix.d.ts +0 -2
- package/dist/generators/ts/syntheticNamePrefix.js +0 -2
|
@@ -4,33 +4,33 @@ 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 {
|
|
8
|
-
import { Maybe, NonEmptyList } from "purify-ts";
|
|
7
|
+
import { Maybe } from "purify-ts";
|
|
9
8
|
import { invariant } from "ts-invariant";
|
|
10
9
|
import { Memoize } from "typescript-memoize";
|
|
11
10
|
import { AbstractContainerType } from "./AbstractContainerType.js";
|
|
12
|
-
import { code
|
|
11
|
+
import { code } from "./ts-poet-wrapper.js";
|
|
13
12
|
export class DefaultValueType extends AbstractContainerType {
|
|
14
13
|
defaultValue;
|
|
15
14
|
discriminantProperty = Maybe.empty();
|
|
16
15
|
graphqlArgs = Maybe.empty();
|
|
17
16
|
kind = "DefaultValueType";
|
|
18
|
-
typeofs =
|
|
17
|
+
typeofs = ["object"];
|
|
18
|
+
validationFunction = this.itemType.validationFunction;
|
|
19
19
|
constructor({ defaultValue, ...superParameters }) {
|
|
20
20
|
super(superParameters);
|
|
21
21
|
this.defaultValue = defaultValue;
|
|
22
22
|
}
|
|
23
|
-
get
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
get conversionFunction() {
|
|
24
|
+
const itemConversionFunction = this.itemType.conversionFunction.orDefault(this.itemConversionFunctionDefault);
|
|
25
|
+
return Maybe.of({
|
|
26
|
+
code: code `${this.reusables.snippets.convertWithDefaultValue}(${itemConversionFunction.code}, ${this.defaultValueExpression})`,
|
|
27
|
+
sourceTypes: itemConversionFunction.sourceTypes
|
|
28
|
+
.filter((sourceType) => sourceType.typeof !== "undefined")
|
|
29
|
+
.concat({
|
|
30
|
+
name: "undefined",
|
|
31
|
+
typeof: "undefined",
|
|
32
|
+
}),
|
|
32
33
|
});
|
|
33
|
-
return conversions;
|
|
34
34
|
}
|
|
35
35
|
get equalsFunction() {
|
|
36
36
|
return this.itemType.equalsFunction;
|
|
@@ -44,6 +44,9 @@ export class DefaultValueType extends AbstractContainerType {
|
|
|
44
44
|
get graphqlType() {
|
|
45
45
|
return this.itemType.graphqlType;
|
|
46
46
|
}
|
|
47
|
+
get hashFunction() {
|
|
48
|
+
return this.itemType.hashFunction;
|
|
49
|
+
}
|
|
47
50
|
get mutable() {
|
|
48
51
|
return this.itemType.mutable;
|
|
49
52
|
}
|
|
@@ -51,7 +54,7 @@ export class DefaultValueType extends AbstractContainerType {
|
|
|
51
54
|
return this.itemType.name;
|
|
52
55
|
}
|
|
53
56
|
get schemaType() {
|
|
54
|
-
return code `${this.reusables.snippets.DefaultValueSchema}
|
|
57
|
+
return code `${this.reusables.snippets.DefaultValueSchema}<${this.itemType.name}, ${this.itemType.schemaType}>`;
|
|
55
58
|
}
|
|
56
59
|
get valueSparqlConstructTriplesFunction() {
|
|
57
60
|
return this.itemType.valueSparqlConstructTriplesFunction;
|
|
@@ -62,56 +65,25 @@ export class DefaultValueType extends AbstractContainerType {
|
|
|
62
65
|
get schemaObject() {
|
|
63
66
|
return {
|
|
64
67
|
...super.schemaObject,
|
|
65
|
-
defaultValue: this.
|
|
68
|
+
defaultValue: this.defaultValueExpression,
|
|
66
69
|
};
|
|
67
70
|
}
|
|
68
|
-
get
|
|
71
|
+
get defaultValueExpression() {
|
|
69
72
|
switch (this.itemType.kind) {
|
|
70
|
-
case "BigDecimalType":
|
|
71
|
-
invariant(this.defaultValue.termType === "Literal");
|
|
72
|
-
return Maybe.of(code `new ${this.reusables.imports.BigDecimal}(${literalOf(this.defaultValue.value)})`);
|
|
73
|
-
case "BigIntType":
|
|
74
|
-
invariant(this.defaultValue.termType === "Literal");
|
|
75
|
-
return Maybe.of(code `${LiteralDecoder.decodeBigIntLiteral(this.defaultValue).unsafeCoerce()}n`);
|
|
76
|
-
case "BooleanType":
|
|
77
|
-
invariant(this.defaultValue.termType === "Literal");
|
|
78
|
-
return Maybe.of(code `${LiteralDecoder.decodeBooleanLiteral(this.defaultValue).unsafeCoerce()}`);
|
|
79
|
-
case "DateType":
|
|
80
|
-
invariant(this.defaultValue.termType === "Literal");
|
|
81
|
-
return Maybe.of(code `new Date("${LiteralDecoder.decodeDateLiteral(this.defaultValue).unsafeCoerce().toISOString()}")`);
|
|
82
|
-
case "DateTimeType":
|
|
83
|
-
invariant(this.defaultValue.termType === "Literal");
|
|
84
|
-
return Maybe.of(code `new Date("${LiteralDecoder.decodeDateTimeLiteral(this.defaultValue).unsafeCoerce().toISOString()}")`);
|
|
85
|
-
case "FloatType":
|
|
86
|
-
invariant(this.defaultValue.termType === "Literal");
|
|
87
|
-
return Maybe.of(code `${LiteralDecoder.decodeFloatLiteral(this.defaultValue).unsafeCoerce()}`);
|
|
88
|
-
case "IntType":
|
|
89
|
-
invariant(this.defaultValue.termType === "Literal");
|
|
90
|
-
return Maybe.of(code `${LiteralDecoder.decodeIntLiteral(this.defaultValue).unsafeCoerce()}`);
|
|
91
|
-
case "StringType":
|
|
92
|
-
invariant(this.defaultValue.termType === "Literal");
|
|
93
|
-
return Maybe.of(code `${literalOf(this.defaultValue.value)}`);
|
|
94
73
|
case "IdentifierType":
|
|
95
74
|
case "IriType":
|
|
96
|
-
invariant(this.defaultValue.termType === "NamedNode");
|
|
97
|
-
return Maybe.of(this.defaultValueTermExpression);
|
|
98
75
|
case "LiteralType":
|
|
99
76
|
case "TermType":
|
|
100
|
-
|
|
101
|
-
return Maybe.of(this.defaultValueTermExpression);
|
|
77
|
+
return this.rdfjsTermExpression(this.defaultValue);
|
|
102
78
|
case "AnonymousUnionType":
|
|
103
79
|
case "ListType":
|
|
104
80
|
case "NamedObjectType":
|
|
105
81
|
case "NamedObjectUnionType":
|
|
106
82
|
case "NamedUnionType":
|
|
107
|
-
|
|
108
|
-
default:
|
|
109
|
-
this.itemType;
|
|
110
|
-
throw new Error("should never reach this point");
|
|
83
|
+
throw new RangeError(`not implemented ${this.itemType.kind}`);
|
|
111
84
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
return this.rdfjsTermExpression(this.defaultValue);
|
|
85
|
+
invariant(this.defaultValue.termType === "Literal");
|
|
86
|
+
return this.itemType.literalExpression(this.defaultValue);
|
|
115
87
|
}
|
|
116
88
|
fromJsonExpression(parameters) {
|
|
117
89
|
return this.itemType.fromJsonExpression(parameters);
|
|
@@ -120,16 +92,13 @@ export class DefaultValueType extends AbstractContainerType {
|
|
|
120
92
|
return this.itemType.fromRdfResourceValuesExpression({
|
|
121
93
|
variables: {
|
|
122
94
|
...variables,
|
|
123
|
-
resourceValues: code `${variables.resourceValues}.map(values => values.length > 0 ? values : new ${this.reusables.imports.Resource}.Value(${{ dataFactory: this.reusables.imports.dataFactory, focusResource: variables.resource, propertyPath: variables.propertyPath, term: this.
|
|
95
|
+
resourceValues: code `${variables.resourceValues}.map(values => values.length > 0 ? values : new ${this.reusables.imports.Resource}.Value(${{ dataFactory: this.reusables.imports.dataFactory, focusResource: variables.resource, propertyPath: variables.propertyPath, term: this.rdfjsTermExpression(this.defaultValue) }}).toValues())`,
|
|
124
96
|
},
|
|
125
97
|
});
|
|
126
98
|
}
|
|
127
99
|
graphqlResolveExpression(parameters) {
|
|
128
100
|
return this.itemType.graphqlResolveExpression(parameters);
|
|
129
101
|
}
|
|
130
|
-
hashStatements(parameters) {
|
|
131
|
-
return this.itemType.hashStatements(parameters);
|
|
132
|
-
}
|
|
133
102
|
jsonSchema(parameters) {
|
|
134
103
|
return this.itemType.jsonSchema(parameters);
|
|
135
104
|
}
|
|
@@ -144,14 +113,15 @@ export class DefaultValueType extends AbstractContainerType {
|
|
|
144
113
|
}
|
|
145
114
|
toRdfResourceValuesExpression(parameters) {
|
|
146
115
|
const { variables } = parameters;
|
|
147
|
-
return this.
|
|
148
|
-
.map((defaultValuePrimitiveExpression) => code `${this.itemType.equalsFunction}(${variables.value}, ${defaultValuePrimitiveExpression}).isLeft() ? ${this.itemType.toRdfResourceValuesExpression(parameters)} : []`)
|
|
149
|
-
.orDefault(code `${this.itemType.toRdfResourceValuesExpression(parameters)}.filter(value => !value.equals(${this.defaultValueTermExpression}))`);
|
|
116
|
+
return code `${this.itemType.equalsFunction}(${variables.value}, ${this.defaultValueExpression}).isLeft() ? ${this.itemType.toRdfResourceValuesExpression(parameters)} : []`;
|
|
150
117
|
}
|
|
151
118
|
toStringExpression(parameters) {
|
|
152
119
|
return this.itemType.toStringExpression(parameters);
|
|
153
120
|
}
|
|
154
121
|
}
|
|
122
|
+
__decorate([
|
|
123
|
+
Memoize()
|
|
124
|
+
], DefaultValueType.prototype, "conversionFunction", null);
|
|
155
125
|
__decorate([
|
|
156
126
|
Memoize()
|
|
157
127
|
], DefaultValueType.prototype, "schemaType", null);
|
|
@@ -163,10 +133,7 @@ __decorate([
|
|
|
163
133
|
], DefaultValueType.prototype, "valueSparqlWherePatternsFunction", null);
|
|
164
134
|
__decorate([
|
|
165
135
|
Memoize()
|
|
166
|
-
], DefaultValueType.prototype, "
|
|
167
|
-
__decorate([
|
|
168
|
-
Memoize()
|
|
169
|
-
], DefaultValueType.prototype, "defaultValueTermExpression", null);
|
|
136
|
+
], DefaultValueType.prototype, "defaultValueExpression", null);
|
|
170
137
|
(function (DefaultValueType) {
|
|
171
138
|
function isItemType(type) {
|
|
172
139
|
if (type.kind === "BlankNodeType") {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Literal } from "@rdfjs/types";
|
|
2
2
|
import { AbstractNumericType } from "./AbstractNumericType.js";
|
|
3
3
|
import { type Code } from "./ts-poet-wrapper.js";
|
|
4
4
|
export declare class FloatType extends AbstractNumericType<number> {
|
|
5
5
|
readonly kind = "FloatType";
|
|
6
|
-
readonly typeofs:
|
|
6
|
+
readonly typeofs: "number"[];
|
|
7
7
|
get graphqlType(): import("./AbstractType.js").AbstractType.GraphqlType;
|
|
8
|
+
literalExpression(literal: Literal | number): Code;
|
|
8
9
|
protected fromRdfResourceValueExpression({ variables, }: Parameters<AbstractNumericType<number>["fromRdfResourceValueExpression"]>[0]): Code;
|
|
9
|
-
protected literalOf(value: number): string;
|
|
10
10
|
}
|
|
11
11
|
//# sourceMappingURL=FloatType.d.ts.map
|
|
@@ -4,22 +4,22 @@ 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 {
|
|
7
|
+
import { LiteralDecoder } from "@rdfx/literal";
|
|
8
8
|
import { Memoize } from "typescript-memoize";
|
|
9
9
|
import { AbstractNumericType } from "./AbstractNumericType.js";
|
|
10
10
|
import { code } from "./ts-poet-wrapper.js";
|
|
11
11
|
export class FloatType extends AbstractNumericType {
|
|
12
12
|
kind = "FloatType";
|
|
13
|
-
typeofs =
|
|
13
|
+
typeofs = ["number"];
|
|
14
14
|
get graphqlType() {
|
|
15
15
|
return new AbstractNumericType.GraphqlType(code `${this.reusables.imports.GraphQLFloat}`, this.reusables);
|
|
16
16
|
}
|
|
17
|
+
literalExpression(literal) {
|
|
18
|
+
return code `${typeof literal === "number" ? literal : LiteralDecoder.decodeFloatLiteral(literal).unsafeCoerce()}`;
|
|
19
|
+
}
|
|
17
20
|
fromRdfResourceValueExpression({ variables, }) {
|
|
18
21
|
return code `${variables.value}.toFloat(${this.primitiveIn.length > 0 ? `${JSON.stringify(this.primitiveIn)} as const` : ""})`;
|
|
19
22
|
}
|
|
20
|
-
literalOf(value) {
|
|
21
|
-
return value.toString();
|
|
22
|
-
}
|
|
23
23
|
}
|
|
24
24
|
__decorate([
|
|
25
25
|
Memoize()
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { BlankNode, NamedNode } from "@rdfjs/types";
|
|
2
2
|
import { type IdentifierNodeKind } from "@shaclmate/shacl-ast";
|
|
3
|
+
import { Maybe } from "purify-ts";
|
|
3
4
|
import { AbstractIdentifierType } from "./AbstractIdentifierType.js";
|
|
4
|
-
import { AbstractTermType } from "./AbstractTermType.js";
|
|
5
5
|
import { type Code } from "./ts-poet-wrapper.js";
|
|
6
6
|
export declare class IdentifierType extends AbstractIdentifierType<BlankNode | NamedNode> {
|
|
7
|
+
readonly conversionFunction: Maybe<AbstractIdentifierType.ConversionFunction>;
|
|
7
8
|
readonly filterFunction: Code;
|
|
8
9
|
readonly filterType: Code;
|
|
9
10
|
readonly parseFunction: Code;
|
|
@@ -13,10 +14,10 @@ export declare class IdentifierType extends AbstractIdentifierType<BlankNode | N
|
|
|
13
14
|
readonly schemaType: Code;
|
|
14
15
|
readonly valueSparqlWherePatternsFunction: Code;
|
|
15
16
|
constructor(parameters: Omit<ConstructorParameters<typeof AbstractIdentifierType<BlankNode | NamedNode>>[0], "hasValues" | "in_">);
|
|
16
|
-
fromJsonExpression({ variables, }: Parameters<
|
|
17
|
-
jsonType(parameters?: Parameters<
|
|
18
|
-
jsonSchema({ includeDiscriminantProperty, }: Parameters<
|
|
19
|
-
toJsonExpression({ includeDiscriminantProperty, variables, }: Parameters<
|
|
20
|
-
protected
|
|
17
|
+
fromJsonExpression({ variables, }: Parameters<AbstractIdentifierType<BlankNode | NamedNode>["fromJsonExpression"]>[0]): Code;
|
|
18
|
+
jsonType(parameters?: Parameters<AbstractIdentifierType<BlankNode | NamedNode>["jsonType"]>[0]): AbstractIdentifierType.JsonType;
|
|
19
|
+
jsonSchema({ includeDiscriminantProperty, }: Parameters<AbstractIdentifierType<BlankNode | NamedNode>["jsonSchema"]>[0]): Code;
|
|
20
|
+
toJsonExpression({ includeDiscriminantProperty, variables, }: Parameters<AbstractIdentifierType<BlankNode | NamedNode>["toJsonExpression"]>[0]): Code;
|
|
21
|
+
protected fromRdfResourceValuesExpressionChain({ variables, }: Parameters<AbstractIdentifierType<BlankNode | NamedNode>["fromRdfResourceValuesExpressionChain"]>[0]): ReturnType<AbstractIdentifierType<BlankNode | NamedNode>["fromRdfResourceValuesExpressionChain"]>;
|
|
21
22
|
}
|
|
22
23
|
//# sourceMappingURL=IdentifierType.d.ts.map
|
|
@@ -5,11 +5,32 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
import { NodeKind } from "@shaclmate/shacl-ast";
|
|
8
|
+
import { Maybe } from "purify-ts";
|
|
8
9
|
import { Memoize } from "typescript-memoize";
|
|
9
10
|
import { AbstractIdentifierType } from "./AbstractIdentifierType.js";
|
|
10
|
-
import { AbstractTermType } from "./AbstractTermType.js";
|
|
11
11
|
import { arrayOf, code } from "./ts-poet-wrapper.js";
|
|
12
12
|
export class IdentifierType extends AbstractIdentifierType {
|
|
13
|
+
conversionFunction = Maybe.of({
|
|
14
|
+
code: code `${this.reusables.snippets.convertToIdentifier}`,
|
|
15
|
+
sourceTypes: [
|
|
16
|
+
{
|
|
17
|
+
name: code `${this.reusables.imports.BlankNode}`,
|
|
18
|
+
typeof: "object",
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: code `${this.reusables.imports.NamedNode}`,
|
|
22
|
+
typeof: "object",
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: "string",
|
|
26
|
+
typeof: "string",
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: "undefined",
|
|
30
|
+
typeof: "undefined",
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
});
|
|
13
34
|
filterFunction = code `${this.reusables.snippets.filterIdentifier}`;
|
|
14
35
|
filterType = code `${this.reusables.snippets.IdentifierFilter}`;
|
|
15
36
|
parseFunction = code `${this.reusables.snippets.parseIdentifier};`;
|
|
@@ -26,13 +47,13 @@ export class IdentifierType extends AbstractIdentifierType {
|
|
|
26
47
|
});
|
|
27
48
|
}
|
|
28
49
|
fromJsonExpression({ variables, }) {
|
|
29
|
-
return code
|
|
50
|
+
return code `${this.reusables.imports.Either}.of<Error, ${this.name}>((${variables.value}["@id"].startsWith("_:") ? ${this.reusables.imports.dataFactory}.blankNode(${variables.value}["@id"].substring(2)) : ${this.reusables.imports.dataFactory}.namedNode(${variables.value}["@id"])))`;
|
|
30
51
|
}
|
|
31
52
|
jsonType(parameters) {
|
|
32
53
|
const discriminantProperty = parameters?.includeDiscriminantProperty
|
|
33
54
|
? `, readonly termType: "BlankNode" | "NamedNode"`
|
|
34
55
|
: "";
|
|
35
|
-
return new
|
|
56
|
+
return new AbstractIdentifierType.JsonType(code `{ readonly "@id": string${discriminantProperty} }`);
|
|
36
57
|
}
|
|
37
58
|
jsonSchema({ includeDiscriminantProperty, }) {
|
|
38
59
|
const discriminantProperty = includeDiscriminantProperty
|
|
@@ -48,9 +69,9 @@ export class IdentifierType extends AbstractIdentifierType {
|
|
|
48
69
|
const valueToNamedNode = code `{ "@id": ${variables.value}.value${discriminantProperty} }`;
|
|
49
70
|
return code `(${variables.value}.termType === "BlankNode" ? ${valueToBlankNode} : ${valueToNamedNode})`;
|
|
50
71
|
}
|
|
51
|
-
|
|
72
|
+
fromRdfResourceValuesExpressionChain({ variables, }) {
|
|
52
73
|
return {
|
|
53
|
-
...super.
|
|
74
|
+
...super.fromRdfResourceValuesExpressionChain({ variables }),
|
|
54
75
|
valueTo: code `chain(values => values.chainMap(value => value.toIdentifier()))`,
|
|
55
76
|
};
|
|
56
77
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Literal } from "@rdfjs/types";
|
|
2
2
|
import { AbstractNumericType } from "./AbstractNumericType.js";
|
|
3
3
|
import { type Code } from "./ts-poet-wrapper.js";
|
|
4
4
|
export declare class IntType extends AbstractNumericType<number> {
|
|
5
5
|
readonly kind = "IntType";
|
|
6
|
-
readonly typeofs:
|
|
6
|
+
readonly typeofs: "number"[];
|
|
7
7
|
get graphqlType(): import("./AbstractType.js").AbstractType.GraphqlType;
|
|
8
|
+
literalExpression(literal: Literal | number): Code;
|
|
8
9
|
protected fromRdfResourceValueExpression({ variables, }: Parameters<AbstractNumericType<number>["fromRdfResourceValueExpression"]>[0]): Code;
|
|
9
|
-
protected literalOf(value: number): string;
|
|
10
10
|
}
|
|
11
11
|
//# sourceMappingURL=IntType.d.ts.map
|
|
@@ -4,22 +4,22 @@ 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 {
|
|
7
|
+
import { LiteralDecoder } from "@rdfx/literal";
|
|
8
8
|
import { Memoize } from "typescript-memoize";
|
|
9
9
|
import { AbstractNumericType } from "./AbstractNumericType.js";
|
|
10
10
|
import { code } from "./ts-poet-wrapper.js";
|
|
11
11
|
export class IntType extends AbstractNumericType {
|
|
12
12
|
kind = "IntType";
|
|
13
|
-
typeofs =
|
|
13
|
+
typeofs = ["number"];
|
|
14
14
|
get graphqlType() {
|
|
15
15
|
return new AbstractNumericType.GraphqlType(code `${this.reusables.imports.GraphQLInt}`, this.reusables);
|
|
16
16
|
}
|
|
17
|
+
literalExpression(literal) {
|
|
18
|
+
return code `${typeof literal === "number" ? literal : LiteralDecoder.decodeIntLiteral(literal).unsafeCoerce()}`;
|
|
19
|
+
}
|
|
17
20
|
fromRdfResourceValueExpression({ variables, }) {
|
|
18
21
|
return code `${variables.value}.toInt(${this.primitiveIn.length > 0 ? `${JSON.stringify(this.primitiveIn)} as const` : ""})`;
|
|
19
22
|
}
|
|
20
|
-
literalOf(value) {
|
|
21
|
-
return value.toString();
|
|
22
|
-
}
|
|
23
23
|
}
|
|
24
24
|
__decorate([
|
|
25
25
|
Memoize()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { NamedNode } from "@rdfjs/types";
|
|
2
|
+
import { Maybe } from "purify-ts";
|
|
2
3
|
import { AbstractIdentifierType } from "./AbstractIdentifierType.js";
|
|
3
|
-
import { AbstractTermType } from "./AbstractTermType.js";
|
|
4
4
|
import { type Code } from "./ts-poet-wrapper.js";
|
|
5
5
|
export declare class IriType extends AbstractIdentifierType<NamedNode> {
|
|
6
6
|
readonly filterFunction: Code;
|
|
@@ -9,16 +9,13 @@ export declare class IriType extends AbstractIdentifierType<NamedNode> {
|
|
|
9
9
|
readonly nodeKinds: ReadonlySet<"IRI">;
|
|
10
10
|
readonly schemaType: Code;
|
|
11
11
|
readonly valueSparqlWherePatternsFunction: Code;
|
|
12
|
-
get
|
|
12
|
+
get conversionFunction(): Maybe<AbstractIdentifierType.ConversionFunction>;
|
|
13
13
|
get name(): Code;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
jsonSchema({ includeDiscriminantProperty, }: Parameters<AbstractTermType<NamedNode, BlankNode | NamedNode>["jsonSchema"]>[0]): Code;
|
|
21
|
-
toJsonExpression({ includeDiscriminantProperty, variables, }: Parameters<AbstractTermType<NamedNode, BlankNode | NamedNode>["toJsonExpression"]>[0]): Code;
|
|
22
|
-
protected fromRdfExpressionChain({ variables, }: Parameters<AbstractTermType["fromRdfExpressionChain"]>[0]): ReturnType<AbstractTermType["fromRdfExpressionChain"]>;
|
|
14
|
+
get parseFunction(): Code;
|
|
15
|
+
fromJsonExpression({ variables, }: Parameters<AbstractIdentifierType<NamedNode>["fromJsonExpression"]>[0]): Code;
|
|
16
|
+
jsonSchema({ includeDiscriminantProperty, }: Parameters<AbstractIdentifierType<NamedNode>["jsonSchema"]>[0]): Code;
|
|
17
|
+
jsonType(parameters?: Parameters<AbstractIdentifierType<NamedNode>["jsonType"]>[0]): AbstractIdentifierType.JsonType;
|
|
18
|
+
toJsonExpression({ includeDiscriminantProperty, variables, }: Parameters<AbstractIdentifierType<NamedNode>["toJsonExpression"]>[0]): Code;
|
|
19
|
+
protected fromRdfResourceValuesExpressionChain({ variables, }: Parameters<AbstractIdentifierType<NamedNode>["fromRdfResourceValuesExpressionChain"]>[0]): ReturnType<AbstractIdentifierType<NamedNode>["fromRdfResourceValuesExpressionChain"]>;
|
|
23
20
|
}
|
|
24
21
|
//# sourceMappingURL=IriType.d.ts.map
|
|
@@ -4,10 +4,10 @@ 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 { Maybe } from "purify-ts";
|
|
7
8
|
import { Memoize } from "typescript-memoize";
|
|
8
9
|
import { AbstractIdentifierType } from "./AbstractIdentifierType.js";
|
|
9
|
-
import {
|
|
10
|
-
import { arrayOf, code, joinCode } from "./ts-poet-wrapper.js";
|
|
10
|
+
import { arrayOf, code, joinCode, literalOf, } from "./ts-poet-wrapper.js";
|
|
11
11
|
export class IriType extends AbstractIdentifierType {
|
|
12
12
|
filterFunction = code `${this.reusables.snippets.filterIri}`;
|
|
13
13
|
filterType = code `${this.reusables.snippets.IriFilter}`;
|
|
@@ -15,43 +15,40 @@ export class IriType extends AbstractIdentifierType {
|
|
|
15
15
|
nodeKinds = nodeKinds;
|
|
16
16
|
schemaType = code `${this.reusables.snippets.IriSchema}`;
|
|
17
17
|
valueSparqlWherePatternsFunction = code `${this.reusables.snippets.iriSparqlWherePatterns}`;
|
|
18
|
-
get
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return
|
|
18
|
+
get conversionFunction() {
|
|
19
|
+
const IriT = this.in_.length > 0
|
|
20
|
+
? code `${joinCode(this.in_.map((iri) => code `${literalOf(iri.value)}`), { on: "| " })}`
|
|
21
|
+
: code `string`;
|
|
22
|
+
return Maybe.of({
|
|
23
|
+
code: code `${this.reusables.snippets.convertToIri}<${IriT}>`,
|
|
24
|
+
sourceTypes: [
|
|
25
|
+
{
|
|
26
|
+
name: IriT,
|
|
27
|
+
typeof: "string",
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: this.name,
|
|
31
|
+
typeof: "object",
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
});
|
|
23
35
|
}
|
|
24
36
|
get name() {
|
|
25
37
|
if (this.in_.length > 0) {
|
|
26
38
|
// Treat sh:in as a union of the IRIs
|
|
27
39
|
// rdfjs.NamedNode<"http://example.com/1" | "http://example.com/2">
|
|
28
|
-
return code `${this.reusables.imports.NamedNode}<${this.in_
|
|
29
|
-
.map((iri) => `"${iri.value}"`)
|
|
30
|
-
.join(" | ")}>`;
|
|
40
|
+
return code `${this.reusables.imports.NamedNode}<${joinCode(this.in_.map((iri) => code `${literalOf(iri.value)}`), { on: "| " })}>`;
|
|
31
41
|
}
|
|
32
42
|
return code `${this.reusables.imports.NamedNode}`;
|
|
33
43
|
}
|
|
34
|
-
get
|
|
35
|
-
return {
|
|
36
|
-
...super.schemaObject,
|
|
37
|
-
in: this.in_.length > 0
|
|
38
|
-
? this.in_.map((in_) => this.rdfjsTermExpression(in_)).concat()
|
|
39
|
-
: undefined,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
fromJsonExpression({ variables, }) {
|
|
43
|
-
return code `${this.reusables.imports.dataFactory}.namedNode(${variables.value}["@id"])`;
|
|
44
|
-
}
|
|
45
|
-
jsonType(parameters) {
|
|
46
|
-
const discriminantProperty = parameters?.includeDiscriminantProperty
|
|
47
|
-
? `, readonly termType: "NamedNode"`
|
|
48
|
-
: "";
|
|
44
|
+
get parseFunction() {
|
|
49
45
|
if (this.in_.length > 0) {
|
|
50
|
-
|
|
51
|
-
// rdfjs.NamedNode<"http://example.com/1" | "http://example.com/2">
|
|
52
|
-
return new AbstractTermType.JsonType(code `{ readonly "@id": ${this.in_.map((iri) => `"${iri.value}"`).join(" | ")}${discriminantProperty} }`);
|
|
46
|
+
return code `(identifier: string) => ${this.reusables.snippets.parseIri}(identifier).chain((identifier) => { switch (identifier.value) { ${joinCode(this.in_.map((iri) => code `case "${iri.value}": return ${this.reusables.imports.Right}(identifier as ${this.name});`))} default: return ${this.reusables.imports.Left}(new Error("expected NamedNode identifier to be one of ${this.in_.map((iri) => iri.value).join(" ")}")); } })`;
|
|
53
47
|
}
|
|
54
|
-
return
|
|
48
|
+
return code `${this.reusables.snippets.parseIri}`;
|
|
49
|
+
}
|
|
50
|
+
fromJsonExpression({ variables, }) {
|
|
51
|
+
return code `${this.reusables.imports.Either}.of<Error, ${this.name}>(${this.reusables.imports.dataFactory}.namedNode(${variables.value}["@id"]))`;
|
|
55
52
|
}
|
|
56
53
|
jsonSchema({ includeDiscriminantProperty, }) {
|
|
57
54
|
let idSchema;
|
|
@@ -68,15 +65,26 @@ export class IriType extends AbstractIdentifierType {
|
|
|
68
65
|
: "";
|
|
69
66
|
return code `${this.reusables.imports.z}.object({ "@id": ${idSchema}${discriminantProperty} })`;
|
|
70
67
|
}
|
|
68
|
+
jsonType(parameters) {
|
|
69
|
+
const discriminantProperty = parameters?.includeDiscriminantProperty
|
|
70
|
+
? `, readonly termType: "NamedNode"`
|
|
71
|
+
: "";
|
|
72
|
+
if (this.in_.length > 0) {
|
|
73
|
+
// Treat sh:in as a union of the IRIs
|
|
74
|
+
// rdfjs.NamedNode<"http://example.com/1" | "http://example.com/2">
|
|
75
|
+
return new AbstractIdentifierType.JsonType(code `{ readonly "@id": ${this.in_.map((iri) => `"${iri.value}"`).join(" | ")}${discriminantProperty} }`);
|
|
76
|
+
}
|
|
77
|
+
return new AbstractIdentifierType.JsonType(code `{ readonly "@id": string${discriminantProperty} }`);
|
|
78
|
+
}
|
|
71
79
|
toJsonExpression({ includeDiscriminantProperty, variables, }) {
|
|
72
80
|
const discriminantProperty = includeDiscriminantProperty
|
|
73
81
|
? code `, termType: ${variables.value}.termType`
|
|
74
82
|
: "";
|
|
75
83
|
return code `{ "@id": ${variables.value}.value${discriminantProperty} }`;
|
|
76
84
|
}
|
|
77
|
-
|
|
85
|
+
fromRdfResourceValuesExpressionChain({ variables, }) {
|
|
78
86
|
return {
|
|
79
|
-
...super.
|
|
87
|
+
...super.fromRdfResourceValuesExpressionChain({ variables }),
|
|
80
88
|
valueTo: code `chain(values => values.chainMap(value => value.toIri(${this.in_.length > 0
|
|
81
89
|
? code `[${joinCode(this.in_.map((in_) => this.rdfjsTermExpression(in_)), { on: ", " })}]`
|
|
82
90
|
: ""})))`,
|
|
@@ -85,10 +93,13 @@ export class IriType extends AbstractIdentifierType {
|
|
|
85
93
|
}
|
|
86
94
|
__decorate([
|
|
87
95
|
Memoize()
|
|
88
|
-
], IriType.prototype, "
|
|
96
|
+
], IriType.prototype, "conversionFunction", null);
|
|
89
97
|
__decorate([
|
|
90
98
|
Memoize()
|
|
91
99
|
], IriType.prototype, "name", null);
|
|
100
|
+
__decorate([
|
|
101
|
+
Memoize()
|
|
102
|
+
], IriType.prototype, "parseFunction", null);
|
|
92
103
|
__decorate([
|
|
93
104
|
Memoize()
|
|
94
105
|
], IriType.prototype, "jsonType", null);
|
|
@@ -8,6 +8,7 @@ declare const Super: (abstract new ({ partialType, resolveType, ...superParamete
|
|
|
8
8
|
resolveType: OptionType<AbstractLazyObjectType.ObjectTypeConstraint>;
|
|
9
9
|
} & {
|
|
10
10
|
comment: Maybe<string>;
|
|
11
|
+
configuration: import("./TsGenerator.js").TsGenerator.Configuration;
|
|
11
12
|
label: Maybe<string>;
|
|
12
13
|
logger: import("ts-log").Logger;
|
|
13
14
|
reusables: import("./Reusables.js").Reusables;
|
|
@@ -18,7 +19,7 @@ declare const Super: (abstract new ({ partialType, resolveType, ...superParamete
|
|
|
18
19
|
export declare class LazyObjectOptionType extends Super {
|
|
19
20
|
readonly graphqlArgs: Super["graphqlArgs"];
|
|
20
21
|
readonly kind = "LazyObjectOptionType";
|
|
21
|
-
get
|
|
22
|
+
get conversionFunction(): Maybe<AbstractLazyObjectType.ConversionFunction>;
|
|
22
23
|
protected get runtimeClass(): {
|
|
23
24
|
name: Code;
|
|
24
25
|
partialPropertyName: string;
|
|
@@ -12,49 +12,28 @@ const Super = (AbstractLazyObjectType);
|
|
|
12
12
|
export class LazyObjectOptionType extends Super {
|
|
13
13
|
graphqlArgs = Maybe.empty();
|
|
14
14
|
kind = "LazyObjectOptionType";
|
|
15
|
-
get
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const maybeMap = code `.map(object => { ${this.resolvedNamedObjectUnionTypeToPartialNamedObjectUnionTypeConversion({ resolvedNamedObjectUnionType: this.resolveType.itemType, partialNamedObjectUnionType: this.partialType.itemType, variables: { resolvedObjectUnion: code `object` } })} })`;
|
|
37
|
-
conversions.push({
|
|
38
|
-
conversionExpression: (value) => code `new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}: ${value}${maybeMap}, resolver: async () => ${this.reusables.imports.Right}((${value} as ${this.reusables.imports.Maybe}<${this.resolveType.itemType.name}>).unsafeCoerce()) })`,
|
|
39
|
-
sourceTypeCheckExpression: (value) => code `${this.reusables.imports.Maybe}.isMaybe(${value})`,
|
|
40
|
-
sourceTypeName: code `${this.reusables.imports.Maybe}<${this.resolveType.itemType.name}>`,
|
|
41
|
-
sourceTypeof: "object",
|
|
42
|
-
}, {
|
|
43
|
-
conversionExpression: (value) => code `new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}: ${this.reusables.imports.Maybe}.of(${value})${maybeMap}, resolver: async () => ${this.reusables.imports.Right}(${value} as ${this.resolveType.itemType.name}) })`,
|
|
44
|
-
// Don't check instanceof value since the NamedObjectUnionType may be an interface
|
|
45
|
-
// Rely on the fact that this will be the last type check on an object
|
|
46
|
-
sourceTypeCheckExpression: (value) => code `typeof ${value} === "object"`,
|
|
47
|
-
sourceTypeName: this.resolveType.itemType.name,
|
|
48
|
-
sourceTypeof: "object",
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
conversions.push({
|
|
52
|
-
conversionExpression: () => code `new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}: ${this.reusables.imports.Maybe}.empty(), resolver: async () => { throw new Error("should never be called"); } })`,
|
|
53
|
-
sourceTypeCheckExpression: (value) => code `${value} === undefined`,
|
|
54
|
-
sourceTypeName: code `undefined`,
|
|
55
|
-
sourceTypeof: "undefined",
|
|
15
|
+
get conversionFunction() {
|
|
16
|
+
return Maybe.of({
|
|
17
|
+
code: code `${this.reusables.snippets.convertToLazyObjectOption}<${this.resolveType.itemType.identifierTypeAlias}, ${this.partialType.itemType.name}, ${this.resolveType.itemType.name}>(${this.resolveToPartialFunction({ partialType: this.partialType.itemType, resolveType: this.resolveType.itemType })})`,
|
|
18
|
+
sourceTypes: [
|
|
19
|
+
{
|
|
20
|
+
name: this.name,
|
|
21
|
+
typeof: "object",
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: this.resolveType.name,
|
|
25
|
+
typeof: "object",
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: this.resolveType.itemType.name,
|
|
29
|
+
typeof: "object",
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: "undefined",
|
|
33
|
+
typeof: "undefined",
|
|
34
|
+
},
|
|
35
|
+
],
|
|
56
36
|
});
|
|
57
|
-
return conversions;
|
|
58
37
|
}
|
|
59
38
|
get runtimeClass() {
|
|
60
39
|
return {
|
|
@@ -64,7 +43,7 @@ export class LazyObjectOptionType extends Super {
|
|
|
64
43
|
};
|
|
65
44
|
}
|
|
66
45
|
fromJsonExpression(parameters) {
|
|
67
|
-
return code
|
|
46
|
+
return code `${this.partialType.fromJsonExpression(parameters)}.map(partial => new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}: partial, resolver: (identifier) => Promise.resolve(${this.reusables.imports.Left}(new Error(\`unable to resolve identifier \${identifier} deserialized from JSON\`))) }))`;
|
|
68
47
|
}
|
|
69
48
|
fromRdfResourceValuesExpression(parameters) {
|
|
70
49
|
const { variables } = parameters;
|
|
@@ -76,7 +55,7 @@ export class LazyObjectOptionType extends Super {
|
|
|
76
55
|
}
|
|
77
56
|
__decorate([
|
|
78
57
|
Memoize()
|
|
79
|
-
], LazyObjectOptionType.prototype, "
|
|
58
|
+
], LazyObjectOptionType.prototype, "conversionFunction", null);
|
|
80
59
|
__decorate([
|
|
81
60
|
Memoize()
|
|
82
61
|
], LazyObjectOptionType.prototype, "runtimeClass", null);
|