@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
|
@@ -11,6 +11,7 @@ import { code, joinCode } from "./ts-poet-wrapper.js";
|
|
|
11
11
|
* Abstract base class for TypeScript numeric types (bigint | number).
|
|
12
12
|
*/
|
|
13
13
|
export class AbstractNumericType extends AbstractPrimitiveType {
|
|
14
|
+
hashFunction = code `${this.reusables.snippets.hashNumeric}`;
|
|
14
15
|
get filterFunction() {
|
|
15
16
|
return code `${this.reusables.snippets.filterNumeric}<${this.typeofs[0]}>`;
|
|
16
17
|
}
|
|
@@ -19,7 +20,7 @@ export class AbstractNumericType extends AbstractPrimitiveType {
|
|
|
19
20
|
}
|
|
20
21
|
get name() {
|
|
21
22
|
if (this.primitiveIn.length > 0) {
|
|
22
|
-
return `${this.primitiveIn.map((value) => this.
|
|
23
|
+
return code `${joinCode(this.primitiveIn.map((value) => this.literalExpression(value)), { on: " | " })}`;
|
|
23
24
|
}
|
|
24
25
|
return this.typeofs[0];
|
|
25
26
|
}
|
|
@@ -29,30 +30,22 @@ export class AbstractNumericType extends AbstractPrimitiveType {
|
|
|
29
30
|
get valueSparqlWherePatternsFunction() {
|
|
30
31
|
return code `${this.reusables.snippets.numericSparqlWherePatterns}<${this.typeofs[0]}>`;
|
|
31
32
|
}
|
|
32
|
-
get schemaObject() {
|
|
33
|
-
return {
|
|
34
|
-
...super.schemaObject,
|
|
35
|
-
in: this.primitiveIn.length > 0
|
|
36
|
-
? this.primitiveIn.map((_) => code `${this.literalOf(_)}`)
|
|
37
|
-
: undefined,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
33
|
jsonSchema(_parameters) {
|
|
41
34
|
switch (this.primitiveIn.length) {
|
|
42
35
|
case 0:
|
|
43
36
|
return code `${this.reusables.imports.z}.${this.typeofs[0]}()`;
|
|
44
37
|
case 1:
|
|
45
|
-
return code `${this.reusables.imports.z}.literal(${this.
|
|
38
|
+
return code `${this.reusables.imports.z}.literal(${this.literalExpression(this.primitiveIn[0])})`;
|
|
46
39
|
default:
|
|
47
|
-
return code `${this.reusables.imports.z}.union([${joinCode(this.primitiveIn.map((value) => code `${this.reusables.imports.z}.literal(${this.
|
|
40
|
+
return code `${this.reusables.imports.z}.union([${joinCode(this.primitiveIn.map((value) => code `${this.reusables.imports.z}.literal(${this.literalExpression(value)})`), { on: "," })}])`;
|
|
48
41
|
}
|
|
49
42
|
}
|
|
50
43
|
toRdfResourceValuesExpression({ variables, }) {
|
|
51
44
|
return code `[${this.reusables.snippets.literalFactory}.${this.typeofs[0]}(${variables.value}, ${this.rdfjsTermExpression(this.datatype)})]`;
|
|
52
45
|
}
|
|
53
|
-
|
|
46
|
+
fromRdfResourceValuesExpressionChain({ variables, }) {
|
|
54
47
|
return {
|
|
55
|
-
...super.
|
|
48
|
+
...super.fromRdfResourceValuesExpressionChain({ variables }),
|
|
56
49
|
languageIn: undefined,
|
|
57
50
|
preferredLanguages: undefined,
|
|
58
51
|
valueTo: code `chain(values => values.chainMap(value => ${this.fromRdfResourceValueExpression({
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { NamedNode } from "@rdfjs/types";
|
|
1
|
+
import type { Literal, NamedNode } from "@rdfjs/types";
|
|
2
2
|
import { Maybe } from "purify-ts";
|
|
3
3
|
import { AbstractLiteralType } from "./AbstractLiteralType.js";
|
|
4
4
|
import { type Code } from "./ts-poet-wrapper.js";
|
|
5
5
|
export declare abstract class AbstractPrimitiveType<ValueT extends bigint | boolean | Date | string | number> extends AbstractLiteralType {
|
|
6
6
|
protected readonly datatype: NamedNode;
|
|
7
|
+
readonly conversionFunction: Maybe<AbstractLiteralType.ConversionFunction>;
|
|
7
8
|
readonly equalsFunction: Code;
|
|
8
9
|
abstract readonly kind: "BigIntType" | "BooleanType" | "DateTimeType" | "DateType" | "FloatType" | "IntType" | "NumberType" | "StringType";
|
|
9
10
|
readonly primitiveIn: readonly ValueT[];
|
|
@@ -11,16 +12,20 @@ export declare abstract class AbstractPrimitiveType<ValueT extends bigint | bool
|
|
|
11
12
|
datatype: NamedNode;
|
|
12
13
|
primitiveIn: readonly ValueT[];
|
|
13
14
|
} & ConstructorParameters<typeof AbstractLiteralType>[0]);
|
|
14
|
-
get conversions(): readonly AbstractPrimitiveType.Conversion[];
|
|
15
15
|
get discriminantProperty(): Maybe<AbstractLiteralType.DiscriminantProperty>;
|
|
16
|
+
protected get schemaObject(): {
|
|
17
|
+
in: Code | undefined;
|
|
18
|
+
languageIn: import("ts-poet/build/Node.js").Node[] | undefined;
|
|
19
|
+
kind: Code;
|
|
20
|
+
};
|
|
16
21
|
fromJsonExpression({ variables, }: Parameters<AbstractLiteralType["fromJsonExpression"]>[0]): Code;
|
|
17
22
|
graphqlResolveExpression({ variables, }: Parameters<AbstractLiteralType["graphqlResolveExpression"]>[0]): Code;
|
|
18
|
-
hashStatements({ variables, }: Parameters<AbstractLiteralType["hashStatements"]>[0]): readonly Code[];
|
|
19
23
|
jsonType(): AbstractLiteralType.JsonType;
|
|
24
|
+
abstract literalExpression(literal: Literal | ValueT): Code;
|
|
20
25
|
toJsonExpression({ variables, }: Parameters<AbstractLiteralType["toJsonExpression"]>[0]): Code;
|
|
21
26
|
}
|
|
22
27
|
export declare namespace AbstractPrimitiveType {
|
|
23
|
-
type
|
|
28
|
+
type ConversionFunction = AbstractLiteralType.ConversionFunction;
|
|
24
29
|
type DiscriminantProperty = AbstractLiteralType.DiscriminantProperty;
|
|
25
30
|
const GraphqlType: typeof import("./AbstractType.js").AbstractType.GraphqlType;
|
|
26
31
|
type GraphqlType = AbstractLiteralType.GraphqlType;
|
|
@@ -7,9 +7,10 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
import { Maybe } from "purify-ts";
|
|
8
8
|
import { Memoize } from "typescript-memoize";
|
|
9
9
|
import { AbstractLiteralType } from "./AbstractLiteralType.js";
|
|
10
|
-
import { code } from "./ts-poet-wrapper.js";
|
|
10
|
+
import { code, joinCode } from "./ts-poet-wrapper.js";
|
|
11
11
|
export class AbstractPrimitiveType extends AbstractLiteralType {
|
|
12
12
|
datatype;
|
|
13
|
+
conversionFunction = Maybe.empty();
|
|
13
14
|
equalsFunction = code `${this.reusables.snippets.strictEquals}`;
|
|
14
15
|
primitiveIn;
|
|
15
16
|
constructor({ datatype, primitiveIn, ...superParameters }) {
|
|
@@ -17,28 +18,23 @@ export class AbstractPrimitiveType extends AbstractLiteralType {
|
|
|
17
18
|
this.datatype = datatype;
|
|
18
19
|
this.primitiveIn = primitiveIn;
|
|
19
20
|
}
|
|
20
|
-
get conversions() {
|
|
21
|
-
return [
|
|
22
|
-
{
|
|
23
|
-
conversionExpression: (value) => value,
|
|
24
|
-
sourceTypeCheckExpression: (value) => code `typeof ${value} === "${this.typeofs[0]}"`,
|
|
25
|
-
sourceTypeName: this.name,
|
|
26
|
-
sourceTypeof: this.typeofs[0],
|
|
27
|
-
},
|
|
28
|
-
];
|
|
29
|
-
}
|
|
30
21
|
get discriminantProperty() {
|
|
31
22
|
return Maybe.empty();
|
|
32
23
|
}
|
|
24
|
+
get schemaObject() {
|
|
25
|
+
return {
|
|
26
|
+
...super.schemaObject,
|
|
27
|
+
in: this.primitiveIn.length > 0
|
|
28
|
+
? code `[${joinCode(this.primitiveIn.map((in_) => this.literalExpression(in_)), { on: ", " })}] as const`
|
|
29
|
+
: undefined,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
33
32
|
fromJsonExpression({ variables, }) {
|
|
34
|
-
return variables.value
|
|
33
|
+
return code `${this.reusables.imports.Either}.of<Error, ${this.name}>(${variables.value})`;
|
|
35
34
|
}
|
|
36
35
|
graphqlResolveExpression({ variables, }) {
|
|
37
36
|
return variables.value;
|
|
38
37
|
}
|
|
39
|
-
hashStatements({ variables, }) {
|
|
40
|
-
return [code `${variables.hasher}.update(${variables.value}.toString());`];
|
|
41
|
-
}
|
|
42
38
|
jsonType() {
|
|
43
39
|
return new AbstractLiteralType.JsonType(this.name);
|
|
44
40
|
}
|
|
@@ -46,9 +42,6 @@ export class AbstractPrimitiveType extends AbstractLiteralType {
|
|
|
46
42
|
return variables.value;
|
|
47
43
|
}
|
|
48
44
|
}
|
|
49
|
-
__decorate([
|
|
50
|
-
Memoize()
|
|
51
|
-
], AbstractPrimitiveType.prototype, "conversions", null);
|
|
52
45
|
__decorate([
|
|
53
46
|
Memoize()
|
|
54
47
|
], AbstractPrimitiveType.prototype, "jsonType", null);
|
|
@@ -3,6 +3,7 @@ import { NodeKind } from "@shaclmate/shacl-ast";
|
|
|
3
3
|
import { Maybe } from "purify-ts";
|
|
4
4
|
import { AbstractType } from "./AbstractType.js";
|
|
5
5
|
import type { Type } from "./Type.js";
|
|
6
|
+
import type { Typeof } from "./Typeof.js";
|
|
6
7
|
import { type Code } from "./ts-poet-wrapper.js";
|
|
7
8
|
/**
|
|
8
9
|
* Abstract base class for IdentifierType and LiteralType.
|
|
@@ -17,24 +18,28 @@ export declare abstract class AbstractTermType<ConstantTermT extends Literal | N
|
|
|
17
18
|
readonly equalsFunction: Code;
|
|
18
19
|
readonly graphqlArgs: AbstractType["graphqlArgs"];
|
|
19
20
|
readonly hasValues: readonly ConstantTermT[];
|
|
21
|
+
readonly hashFunction: Code;
|
|
20
22
|
readonly in_: readonly ConstantTermT[];
|
|
21
23
|
readonly mutable: boolean;
|
|
22
24
|
abstract readonly nodeKinds: ReadonlySet<NodeKind>;
|
|
23
25
|
readonly recursive = false;
|
|
24
|
-
readonly typeofs:
|
|
26
|
+
readonly typeofs: readonly Typeof[];
|
|
27
|
+
readonly validationFunction: Maybe<Code>;
|
|
25
28
|
constructor({ hasValues, in_, ...superParameters }: {
|
|
26
29
|
hasValues: readonly ConstantTermT[];
|
|
27
30
|
in_: readonly ConstantTermT[];
|
|
28
31
|
} & ConstructorParameters<typeof AbstractType>[0]);
|
|
29
32
|
get constrained(): boolean;
|
|
30
|
-
get conversions(): readonly AbstractType.Conversion[];
|
|
31
33
|
get discriminantProperty(): Maybe<AbstractType.DiscriminantProperty>;
|
|
32
34
|
get schema(): Code;
|
|
35
|
+
protected get schemaObject(): {
|
|
36
|
+
in: Code | undefined;
|
|
37
|
+
kind: Code;
|
|
38
|
+
};
|
|
33
39
|
get termTypes(): ReadonlySet<"BlankNode" | "Literal" | "NamedNode">;
|
|
34
40
|
get toRdfResourceValueTypes(): Set<"BlankNode" | "Literal" | "NamedNode">;
|
|
35
41
|
get valueSparqlConstructTriplesFunction(): Code;
|
|
36
42
|
fromRdfResourceValuesExpression(parameters: Parameters<AbstractType["fromRdfResourceValuesExpression"]>[0]): Code;
|
|
37
|
-
hashStatements({ variables, }: Parameters<AbstractType["hashStatements"]>[0]): readonly Code[];
|
|
38
43
|
jsonUiSchemaElement(): Maybe<Code>;
|
|
39
44
|
toRdfResourceValuesExpression({ variables, }: Parameters<AbstractType["toRdfResourceValuesExpression"]>[0]): Code;
|
|
40
45
|
toStringExpression({ variables, }: Parameters<AbstractType["toStringExpression"]>[0]): Code;
|
|
@@ -47,7 +52,7 @@ export declare abstract class AbstractTermType<ConstantTermT extends Literal | N
|
|
|
47
52
|
*
|
|
48
53
|
* Considering the sub-expressions as a record instead of an array allows them to be selectively overridden by subclasses.
|
|
49
54
|
*/
|
|
50
|
-
protected
|
|
55
|
+
protected fromRdfResourceValuesExpressionChain({ variables, }: Parameters<Type["fromRdfResourceValuesExpression"]>[0]): {
|
|
51
56
|
hasValues?: Code;
|
|
52
57
|
languageIn?: Code;
|
|
53
58
|
preferredLanguages?: Code;
|
|
@@ -55,7 +60,7 @@ export declare abstract class AbstractTermType<ConstantTermT extends Literal | N
|
|
|
55
60
|
};
|
|
56
61
|
}
|
|
57
62
|
export declare namespace AbstractTermType {
|
|
58
|
-
type
|
|
63
|
+
type ConversionFunction = AbstractType.ConversionFunction;
|
|
59
64
|
type DiscriminantProperty = AbstractType.DiscriminantProperty;
|
|
60
65
|
const GraphqlType: typeof AbstractType.GraphqlType;
|
|
61
66
|
type GraphqlType = AbstractType.GraphqlType;
|
|
@@ -5,7 +5,7 @@ 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
|
|
8
|
+
import { Maybe } from "purify-ts";
|
|
9
9
|
import { Memoize } from "typescript-memoize";
|
|
10
10
|
import { AbstractType } from "./AbstractType.js";
|
|
11
11
|
import { removeUndefined } from "./removeUndefined.js";
|
|
@@ -23,12 +23,12 @@ export class AbstractTermType extends AbstractType {
|
|
|
23
23
|
equalsFunction = code `${this.reusables.snippets.booleanEquals}`;
|
|
24
24
|
graphqlArgs = Maybe.empty();
|
|
25
25
|
hasValues;
|
|
26
|
+
hashFunction = code `${this.reusables.snippets.hashTerm}`;
|
|
26
27
|
in_;
|
|
27
28
|
mutable = false;
|
|
28
29
|
recursive = false;
|
|
29
|
-
typeofs =
|
|
30
|
-
|
|
31
|
-
]);
|
|
30
|
+
typeofs = ["object"];
|
|
31
|
+
validationFunction = Maybe.empty();
|
|
32
32
|
constructor({ hasValues, in_, ...superParameters }) {
|
|
33
33
|
super(superParameters);
|
|
34
34
|
this.hasValues = hasValues;
|
|
@@ -37,44 +37,6 @@ export class AbstractTermType extends AbstractType {
|
|
|
37
37
|
get constrained() {
|
|
38
38
|
return this.hasValues.length > 0 || this.in_.length > 0;
|
|
39
39
|
}
|
|
40
|
-
get conversions() {
|
|
41
|
-
const conversions = [];
|
|
42
|
-
if (this.nodeKinds.has("Literal")) {
|
|
43
|
-
conversions.push({
|
|
44
|
-
conversionExpression: (value) => code `${this.reusables.snippets.literalFactory}.bigint(${value})`,
|
|
45
|
-
sourceTypeCheckExpression: (value) => code `typeof ${value} === "bigint"`,
|
|
46
|
-
sourceTypeName: code `bigint`,
|
|
47
|
-
sourceTypeof: "bigint",
|
|
48
|
-
}, {
|
|
49
|
-
conversionExpression: (value) => code `${this.reusables.snippets.literalFactory}.boolean(${value})`,
|
|
50
|
-
sourceTypeCheckExpression: (value) => code `typeof ${value} === "boolean"`,
|
|
51
|
-
sourceTypeName: code `boolean`,
|
|
52
|
-
sourceTypeof: "boolean",
|
|
53
|
-
}, {
|
|
54
|
-
conversionExpression: (value) => code `${this.reusables.snippets.literalFactory}.date(${value})`,
|
|
55
|
-
sourceTypeCheckExpression: (value) => code `typeof ${value} === "object" && ${value} instanceof Date`,
|
|
56
|
-
sourceTypeName: code `Date`,
|
|
57
|
-
sourceTypeof: "object",
|
|
58
|
-
}, {
|
|
59
|
-
conversionExpression: (value) => code `${this.reusables.snippets.literalFactory}.number(${value})`,
|
|
60
|
-
sourceTypeCheckExpression: (value) => code `typeof ${value} === "number"`,
|
|
61
|
-
sourceTypeName: code `number`,
|
|
62
|
-
sourceTypeof: "number",
|
|
63
|
-
}, {
|
|
64
|
-
conversionExpression: (value) => code `${this.reusables.snippets.literalFactory}.string(${value})`,
|
|
65
|
-
sourceTypeCheckExpression: (value) => code `typeof ${value} === "string"`,
|
|
66
|
-
sourceTypeName: code `string`,
|
|
67
|
-
sourceTypeof: "string",
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
conversions.push({
|
|
71
|
-
conversionExpression: (value) => value,
|
|
72
|
-
sourceTypeCheckExpression: (value) => code `typeof ${value} === "object"`,
|
|
73
|
-
sourceTypeName: this.name,
|
|
74
|
-
sourceTypeof: "object",
|
|
75
|
-
});
|
|
76
|
-
return conversions;
|
|
77
|
-
}
|
|
78
40
|
get discriminantProperty() {
|
|
79
41
|
return Maybe.of({
|
|
80
42
|
descendantValues: [],
|
|
@@ -87,6 +49,14 @@ export class AbstractTermType extends AbstractType {
|
|
|
87
49
|
get schema() {
|
|
88
50
|
return code `${removeUndefined(this.schemaObject)}`;
|
|
89
51
|
}
|
|
52
|
+
get schemaObject() {
|
|
53
|
+
return {
|
|
54
|
+
...super.schemaObject,
|
|
55
|
+
in: this.in_.length > 0
|
|
56
|
+
? code `[${joinCode(this.in_.map((in_) => this.rdfjsTermExpression(in_)), { on: ", " })}] as const`
|
|
57
|
+
: undefined,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
90
60
|
get termTypes() {
|
|
91
61
|
return new Set([...this.nodeKinds].map(NodeKind.toTermType));
|
|
92
62
|
}
|
|
@@ -102,7 +72,7 @@ export class AbstractTermType extends AbstractType {
|
|
|
102
72
|
// (this.nodeKinds.has("BlankNode") || this.nodeKinds.has("NamedNode")),
|
|
103
73
|
// "IdentifierType and LiteralType should override",
|
|
104
74
|
// );
|
|
105
|
-
const chain = this.
|
|
75
|
+
const chain = this.fromRdfResourceValuesExpressionChain(parameters);
|
|
106
76
|
const { variables } = parameters;
|
|
107
77
|
return joinCode([
|
|
108
78
|
variables.resourceValues,
|
|
@@ -112,12 +82,6 @@ export class AbstractTermType extends AbstractType {
|
|
|
112
82
|
chain.valueTo,
|
|
113
83
|
].filter((_) => _ !== undefined), { on: "." });
|
|
114
84
|
}
|
|
115
|
-
hashStatements({ variables, }) {
|
|
116
|
-
return [
|
|
117
|
-
code `${variables.hasher}.update(${variables.value}.termType);`,
|
|
118
|
-
code `${variables.hasher}.update(${variables.value}.value);`,
|
|
119
|
-
];
|
|
120
|
-
}
|
|
121
85
|
jsonUiSchemaElement() {
|
|
122
86
|
return Maybe.empty();
|
|
123
87
|
}
|
|
@@ -136,7 +100,7 @@ export class AbstractTermType extends AbstractType {
|
|
|
136
100
|
*
|
|
137
101
|
* Considering the sub-expressions as a record instead of an array allows them to be selectively overridden by subclasses.
|
|
138
102
|
*/
|
|
139
|
-
|
|
103
|
+
fromRdfResourceValuesExpressionChain({ variables, }) {
|
|
140
104
|
let valueToExpression;
|
|
141
105
|
if (this.in_.length > 0) {
|
|
142
106
|
valueToExpression = code `value.toTerm([${joinCode(this.in_.map((in_) => this.rdfjsTermExpression(in_)), { on: ", " })}])`;
|
|
@@ -161,9 +125,6 @@ chain(values => ${this.reusables.imports.Either}.sequence([${joinCode(this.hasVa
|
|
|
161
125
|
};
|
|
162
126
|
}
|
|
163
127
|
}
|
|
164
|
-
__decorate([
|
|
165
|
-
Memoize()
|
|
166
|
-
], AbstractTermType.prototype, "conversions", null);
|
|
167
128
|
__decorate([
|
|
168
129
|
Memoize()
|
|
169
130
|
], AbstractTermType.prototype, "discriminantProperty", null);
|
|
@@ -1,24 +1,31 @@
|
|
|
1
|
-
import type { Maybe
|
|
1
|
+
import type { Maybe } from "purify-ts";
|
|
2
2
|
import type { Logger } from "ts-log";
|
|
3
3
|
import type { Reusables } from "./Reusables.js";
|
|
4
4
|
import { rdfjsTermExpression } from "./rdfjsTermExpression.js";
|
|
5
|
+
import type { TsGenerator } from "./TsGenerator.js";
|
|
5
6
|
import type { Typeof } from "./Typeof.js";
|
|
6
7
|
import { type Code } from "./ts-poet-wrapper.js";
|
|
7
8
|
/**
|
|
8
9
|
* Abstract base class all types.
|
|
9
10
|
*/
|
|
10
11
|
export declare abstract class AbstractType {
|
|
12
|
+
protected readonly configuration: TsGenerator.Configuration;
|
|
11
13
|
protected readonly logger: Logger;
|
|
12
14
|
protected readonly reusables: Reusables;
|
|
13
|
-
protected readonly rdfjsTermExpression: (parameters: Parameters<typeof rdfjsTermExpression>[0]) => Code;
|
|
14
15
|
/**
|
|
15
16
|
* Comment from rdfs:comment.
|
|
16
17
|
*/
|
|
17
18
|
readonly comment: Maybe<string>;
|
|
18
19
|
/**
|
|
19
|
-
*
|
|
20
|
+
* Function that takes a value of one or more source types to this type and returns Either<Error, ThisType>.
|
|
21
|
+
*
|
|
22
|
+
* The source types should include this type.
|
|
23
|
+
*
|
|
24
|
+
* The function should not perform validation (e.g., checking array lengths). That will be done by validationFunction in conjunction with this function.
|
|
25
|
+
*
|
|
26
|
+
* If unspecified, uses an identity function (i.e., function identity(value: ThisType): Either<Error, ThisType>).
|
|
20
27
|
*/
|
|
21
|
-
abstract readonly
|
|
28
|
+
abstract readonly conversionFunction: Maybe<AbstractType.ConversionFunction>;
|
|
22
29
|
/**
|
|
23
30
|
* The declaration of named types.
|
|
24
31
|
*/
|
|
@@ -52,7 +59,11 @@ export declare abstract class AbstractType {
|
|
|
52
59
|
*/
|
|
53
60
|
abstract readonly graphqlType: AbstractType.GraphqlType;
|
|
54
61
|
/**
|
|
55
|
-
*
|
|
62
|
+
* A function (reference or declaration) that takes a Hasher and a value of this type, calls hasher.update on the value, and returns the Hasher.
|
|
63
|
+
*/
|
|
64
|
+
abstract readonly hashFunction: Code;
|
|
65
|
+
/**
|
|
66
|
+
* Type discriminant.
|
|
56
67
|
*/
|
|
57
68
|
abstract readonly kind: string;
|
|
58
69
|
/**
|
|
@@ -86,7 +97,19 @@ export declare abstract class AbstractType {
|
|
|
86
97
|
/**
|
|
87
98
|
* JavaScript typeof(s) the type.
|
|
88
99
|
*/
|
|
89
|
-
abstract readonly typeofs:
|
|
100
|
+
abstract readonly typeofs: readonly Typeof[];
|
|
101
|
+
/**
|
|
102
|
+
* Function that takes
|
|
103
|
+
* - a schema of this.schemaType
|
|
104
|
+
* - a value of this.type
|
|
105
|
+
*
|
|
106
|
+
* and validates the value against the schema, returning
|
|
107
|
+
* - Left(Error) if validation fails or
|
|
108
|
+
* - Right(the value) if validatios succeeds
|
|
109
|
+
*
|
|
110
|
+
* If unspecified, uses an identity function (i.e., function identity(schema: unknown, value: ThisType): Either<Error, ThisType>).
|
|
111
|
+
*/
|
|
112
|
+
abstract readonly validationFunction: Maybe<Code>;
|
|
90
113
|
/**
|
|
91
114
|
* A ValueSparqlConstructTriplesFunction (reference or declaration) that returns an array of sparqljs.Triple's for a property value of this type.
|
|
92
115
|
*
|
|
@@ -110,8 +133,9 @@ export declare abstract class AbstractType {
|
|
|
110
133
|
* - variablePrefix: string prefix to use for new variables
|
|
111
134
|
*/
|
|
112
135
|
abstract readonly valueSparqlWherePatternsFunction: Code;
|
|
113
|
-
constructor({ comment, label, logger, reusables, }: {
|
|
136
|
+
constructor({ comment, configuration, label, logger, reusables, }: {
|
|
114
137
|
comment: Maybe<string>;
|
|
138
|
+
configuration: TsGenerator.Configuration;
|
|
115
139
|
label: Maybe<string>;
|
|
116
140
|
logger: Logger;
|
|
117
141
|
reusables: Reusables;
|
|
@@ -123,8 +147,7 @@ export declare abstract class AbstractType {
|
|
|
123
147
|
kind: Code;
|
|
124
148
|
};
|
|
125
149
|
/**
|
|
126
|
-
* An expression that converts this type's JSON type to
|
|
127
|
-
* already been validated and converted to the expected JSON type with Zod.
|
|
150
|
+
* An expression that converts this type's JSON type to an Either<Error, ThisType>.
|
|
128
151
|
*/
|
|
129
152
|
abstract fromJsonExpression(parameters: {
|
|
130
153
|
variables: {
|
|
@@ -175,16 +198,6 @@ export declare abstract class AbstractType {
|
|
|
175
198
|
value: Code;
|
|
176
199
|
};
|
|
177
200
|
}): Code;
|
|
178
|
-
/**
|
|
179
|
-
* Statements that use hasher.update to hash a property value of this type.
|
|
180
|
-
*/
|
|
181
|
-
abstract hashStatements(parameters: {
|
|
182
|
-
depth: number;
|
|
183
|
-
variables: {
|
|
184
|
-
hasher: Code;
|
|
185
|
-
value: Code;
|
|
186
|
-
};
|
|
187
|
-
}): readonly Code[];
|
|
188
201
|
/**
|
|
189
202
|
* Zod schema for the JSON type of this type.
|
|
190
203
|
*
|
|
@@ -250,13 +263,15 @@ export declare abstract class AbstractType {
|
|
|
250
263
|
value: Code;
|
|
251
264
|
};
|
|
252
265
|
}): Code;
|
|
266
|
+
protected readonly rdfjsTermExpression: (parameters: Parameters<typeof rdfjsTermExpression>[0]) => Code;
|
|
253
267
|
}
|
|
254
268
|
export declare namespace AbstractType {
|
|
255
|
-
interface
|
|
256
|
-
readonly
|
|
257
|
-
readonly
|
|
258
|
-
|
|
259
|
-
|
|
269
|
+
interface ConversionFunction {
|
|
270
|
+
readonly code: Code;
|
|
271
|
+
readonly sourceTypes: {
|
|
272
|
+
readonly name: Code | string;
|
|
273
|
+
readonly typeof: Typeof;
|
|
274
|
+
}[];
|
|
260
275
|
}
|
|
261
276
|
interface DiscriminantProperty {
|
|
262
277
|
readonly descendantValues: readonly DiscriminantProperty.Value[];
|
|
@@ -12,9 +12,9 @@ import { code, literalOf } from "./ts-poet-wrapper.js";
|
|
|
12
12
|
* Abstract base class all types.
|
|
13
13
|
*/
|
|
14
14
|
export class AbstractType {
|
|
15
|
+
configuration;
|
|
15
16
|
logger;
|
|
16
17
|
reusables;
|
|
17
|
-
rdfjsTermExpression;
|
|
18
18
|
/**
|
|
19
19
|
* Comment from rdfs:comment.
|
|
20
20
|
*/
|
|
@@ -23,8 +23,9 @@ export class AbstractType {
|
|
|
23
23
|
* Label from rdfs:label.
|
|
24
24
|
*/
|
|
25
25
|
label;
|
|
26
|
-
constructor({ comment, label, logger, reusables, }) {
|
|
26
|
+
constructor({ comment, configuration, label, logger, reusables, }) {
|
|
27
27
|
this.comment = comment;
|
|
28
|
+
this.configuration = configuration;
|
|
28
29
|
this.label = label;
|
|
29
30
|
this.logger = logger;
|
|
30
31
|
this.reusables = reusables;
|
|
@@ -43,6 +44,7 @@ export class AbstractType {
|
|
|
43
44
|
kind: code `${literalOf(this.kind.substring(0, this.kind.length - "Type".length))} as const`,
|
|
44
45
|
};
|
|
45
46
|
}
|
|
47
|
+
rdfjsTermExpression;
|
|
46
48
|
}
|
|
47
49
|
(function (AbstractType) {
|
|
48
50
|
class GraphqlType {
|
|
@@ -10,6 +10,7 @@ export declare abstract class AbstractUnionType<MemberTypeT extends Type> extend
|
|
|
10
10
|
private readonly discriminant;
|
|
11
11
|
private readonly identifierType;
|
|
12
12
|
readonly recursive: boolean;
|
|
13
|
+
readonly validationFunction: Maybe<Code>;
|
|
13
14
|
constructor({ identifierType, members, recursive, ...superParameters }: {
|
|
14
15
|
identifierType: Maybe<BlankNodeType | IdentifierType | IriType>;
|
|
15
16
|
members: readonly (Pick<AbstractUnionType.Member<MemberTypeT>, "type"> & {
|
|
@@ -17,7 +18,7 @@ export declare abstract class AbstractUnionType<MemberTypeT extends Type> extend
|
|
|
17
18
|
})[];
|
|
18
19
|
recursive: boolean;
|
|
19
20
|
} & ConstructorParameters<typeof AbstractType>[0]);
|
|
20
|
-
get
|
|
21
|
+
get conversionFunction(): Maybe<AbstractType.ConversionFunction>;
|
|
21
22
|
get discriminantProperty(): Maybe<AbstractType.DiscriminantProperty>;
|
|
22
23
|
get members(): readonly AbstractUnionType.Member<MemberTypeT>[];
|
|
23
24
|
get mutable(): boolean;
|
|
@@ -30,6 +31,7 @@ export declare abstract class AbstractUnionType<MemberTypeT extends Type> extend
|
|
|
30
31
|
protected get inlineFilterType(): Code;
|
|
31
32
|
protected get inlineFromJsonFunction(): Code;
|
|
32
33
|
protected get inlineFromRdfResourceValuesFunction(): Code;
|
|
34
|
+
protected get inlineHashFunction(): Code;
|
|
33
35
|
protected get inlineJsonSchema(): Code;
|
|
34
36
|
protected get inlineJsonType(): AbstractType.JsonType;
|
|
35
37
|
protected get inlineName(): Code;
|
|
@@ -43,7 +45,6 @@ export declare abstract class AbstractUnionType<MemberTypeT extends Type> extend
|
|
|
43
45
|
members: Code;
|
|
44
46
|
};
|
|
45
47
|
jsonUiSchemaElement(): Maybe<Code>;
|
|
46
|
-
protected inlineHashStatements({ depth, variables, }: Parameters<AbstractType["hashStatements"]>[0]): readonly Code[];
|
|
47
48
|
private readonly lazyMembers;
|
|
48
49
|
}
|
|
49
50
|
type Discriminant = ExtrinsicDiscriminant | HybridDiscriminant | IntrinsicDiscriminant | TypeofDiscriminant;
|
|
@@ -4,17 +4,17 @@ 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
|
|
7
|
+
import { Maybe } from "purify-ts";
|
|
8
8
|
import { invariant } from "ts-invariant";
|
|
9
9
|
import { Memoize } from "typescript-memoize";
|
|
10
10
|
import { AbstractType } from "./AbstractType.js";
|
|
11
11
|
import { removeUndefined } from "./removeUndefined.js";
|
|
12
|
-
import { syntheticNamePrefix } from "./syntheticNamePrefix.js";
|
|
13
12
|
import { code, joinCode, literalOf } from "./ts-poet-wrapper.js";
|
|
14
13
|
export class AbstractUnionType extends AbstractType {
|
|
15
14
|
discriminant;
|
|
16
15
|
identifierType;
|
|
17
16
|
recursive;
|
|
17
|
+
validationFunction = Maybe.empty();
|
|
18
18
|
constructor({ identifierType, members, recursive, ...superParameters }) {
|
|
19
19
|
super(superParameters);
|
|
20
20
|
this.identifierType = identifierType;
|
|
@@ -130,29 +130,21 @@ export class AbstractUnionType extends AbstractType {
|
|
|
130
130
|
};
|
|
131
131
|
});
|
|
132
132
|
}
|
|
133
|
-
get
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
133
|
+
get conversionFunction() {
|
|
134
|
+
return Maybe.of({
|
|
135
|
+
code: code `${this.reusables.snippets.identityConversionFunction}`,
|
|
136
|
+
sourceTypes: this.discriminant.kind === "typeof"
|
|
137
|
+
? this.members.map(({ primaryDiscriminantValue, type }) => ({
|
|
138
|
+
name: type.name,
|
|
139
|
+
typeof: primaryDiscriminantValue,
|
|
140
|
+
}))
|
|
141
|
+
: [
|
|
139
142
|
{
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
sourceTypeName: this.name,
|
|
143
|
-
sourceTypeof: "object",
|
|
143
|
+
name: this.name,
|
|
144
|
+
typeof: "object",
|
|
144
145
|
},
|
|
145
|
-
]
|
|
146
|
-
|
|
147
|
-
return this.members.map(({ primaryDiscriminantValue, type, typeCheck }) => ({
|
|
148
|
-
conversionExpression: (value) => value,
|
|
149
|
-
sourceTypeCheckExpression: (value) => typeCheck(value),
|
|
150
|
-
sourceTypeName: type.name,
|
|
151
|
-
sourceTypeof: primaryDiscriminantValue,
|
|
152
|
-
}));
|
|
153
|
-
default:
|
|
154
|
-
throw this.discriminant;
|
|
155
|
-
}
|
|
146
|
+
],
|
|
147
|
+
});
|
|
156
148
|
}
|
|
157
149
|
get discriminantProperty() {
|
|
158
150
|
switch (this.discriminant.kind) {
|
|
@@ -215,7 +207,7 @@ export class AbstractUnionType extends AbstractType {
|
|
|
215
207
|
return set;
|
|
216
208
|
}
|
|
217
209
|
get typeofs() {
|
|
218
|
-
return
|
|
210
|
+
return [...new Set(this.members.flatMap((member) => member.type.typeofs))];
|
|
219
211
|
}
|
|
220
212
|
get inlineEqualsFunction() {
|
|
221
213
|
return code `\
|
|
@@ -228,6 +220,7 @@ ${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeChe
|
|
|
228
220
|
})`;
|
|
229
221
|
}
|
|
230
222
|
get inlineFilterFunction() {
|
|
223
|
+
const syntheticNamePrefix = this.configuration.syntheticNamePrefix;
|
|
231
224
|
return code `\
|
|
232
225
|
((filter: ${this.filterType}, value: ${this.name}) => {
|
|
233
226
|
${joinCode([
|
|
@@ -249,6 +242,7 @@ if (filter.on?.[${literalOf(primaryDiscriminantValue)}] !== undefined && ${typeC
|
|
|
249
242
|
})`;
|
|
250
243
|
}
|
|
251
244
|
get inlineFilterType() {
|
|
245
|
+
const syntheticNamePrefix = this.configuration.syntheticNamePrefix;
|
|
252
246
|
return code `\
|
|
253
247
|
{
|
|
254
248
|
${this.identifierType.map((identifierType) => code `readonly ${syntheticNamePrefix}identifier?: ${identifierType.filterType};`).orDefault(code ``)}
|
|
@@ -257,12 +251,12 @@ if (filter.on?.[${literalOf(primaryDiscriminantValue)}] !== undefined && ${typeC
|
|
|
257
251
|
}
|
|
258
252
|
get inlineFromJsonFunction() {
|
|
259
253
|
return code `\
|
|
260
|
-
((value: ${this.jsonType().name}): ${this.name} => {
|
|
261
|
-
${joinCode(this.members.map(({ jsonType, jsonTypeCheck, type, unwrap, wrap }) => code `if (${jsonTypeCheck(code `value`)}) { return ${
|
|
254
|
+
((value: ${this.jsonType().name}): ${this.reusables.imports.Either}<Error, ${this.name}> => {
|
|
255
|
+
${joinCode(this.members.map(({ jsonType, jsonTypeCheck, type, unwrap, wrap }) => code `if (${jsonTypeCheck(code `value`)}) { return ${type.fromJsonExpression({
|
|
262
256
|
variables: {
|
|
263
257
|
value: code `(${unwrap(code `value`)} as ${jsonType})`,
|
|
264
258
|
},
|
|
265
|
-
}))}; }`))}
|
|
259
|
+
})}.map(value => (${wrap(code `value`)})); }`))}
|
|
266
260
|
|
|
267
261
|
throw new Error("unable to deserialize JSON");
|
|
268
262
|
})`;
|
|
@@ -306,6 +300,13 @@ ${joinCode(this.members.map(({ jsonType, jsonTypeCheck, type, unwrap, wrap }) =>
|
|
|
306
300
|
}, null)}.chain(values => values.head());
|
|
307
301
|
}))
|
|
308
302
|
) satisfies ${this.reusables.snippets.FromRdfResourceValuesFunction}<${this.name}>)`;
|
|
303
|
+
}
|
|
304
|
+
get inlineHashFunction() {
|
|
305
|
+
return code `\
|
|
306
|
+
(<HasherT extends ${this.reusables.snippets.Hasher}>(hasher: HasherT, value: ${this.name}): HasherT => {
|
|
307
|
+
${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeCheck(code `value`)}) { return ${type.hashFunction}(hasher, ${unwrap(code `value`)}); }`))}
|
|
308
|
+
return hasher;
|
|
309
|
+
})`;
|
|
309
310
|
}
|
|
310
311
|
get inlineJsonSchema() {
|
|
311
312
|
const discriminant = this.discriminant; // To get type narrowing to work
|
|
@@ -469,22 +470,11 @@ unionPatterns.push({ patterns: ${type.valueSparqlWherePatternsFunction}({ ...oth
|
|
|
469
470
|
jsonUiSchemaElement() {
|
|
470
471
|
return Maybe.empty();
|
|
471
472
|
}
|
|
472
|
-
inlineHashStatements({ depth, variables, }) {
|
|
473
|
-
return this.members.map(({ type, unwrap, typeCheck }) => code `if (${typeCheck(variables.value)}) { ${joinCode(type
|
|
474
|
-
.hashStatements({
|
|
475
|
-
depth: depth + 1,
|
|
476
|
-
variables: {
|
|
477
|
-
hasher: variables.hasher,
|
|
478
|
-
value: unwrap(variables.value),
|
|
479
|
-
},
|
|
480
|
-
})
|
|
481
|
-
.concat())} }`);
|
|
482
|
-
}
|
|
483
473
|
lazyMembers;
|
|
484
474
|
}
|
|
485
475
|
__decorate([
|
|
486
476
|
Memoize()
|
|
487
|
-
], AbstractUnionType.prototype, "
|
|
477
|
+
], AbstractUnionType.prototype, "conversionFunction", null);
|
|
488
478
|
__decorate([
|
|
489
479
|
Memoize()
|
|
490
480
|
], AbstractUnionType.prototype, "discriminantProperty", null);
|