@shaclmate/compiler 4.0.38 → 4.0.40
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/ShapesGraphToAstTransformer.js +12 -12
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +24 -24
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompoundType.js +4 -4
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstListType.js +1 -1
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstObjectType.js +16 -16
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstTermType.js +1 -1
- package/dist/ast/AbstractCollectionType.d.ts +1 -1
- package/dist/ast/AbstractCompoundType.d.ts +1 -1
- package/dist/ast/AbstractCompoundType.js +15 -15
- package/dist/ast/AbstractContainerType.d.ts +1 -1
- package/dist/ast/AbstractContainerType.js +15 -15
- package/dist/ast/AbstractLazyObjectType.d.ts +1 -1
- package/dist/ast/AbstractTermType.d.ts +1 -1
- package/dist/ast/BlankNodeType.d.ts +1 -1
- package/dist/ast/BlankNodeType.js +1 -1
- package/dist/ast/DefaultValueType.d.ts +1 -1
- package/dist/ast/DefaultValueType.js +2 -2
- package/dist/ast/IdentifierType.d.ts +1 -1
- package/dist/ast/IdentifierType.js +1 -1
- package/dist/ast/IntersectionType.d.ts +1 -1
- package/dist/ast/IntersectionType.js +3 -3
- package/dist/ast/IriType.d.ts +1 -1
- package/dist/ast/IriType.js +1 -1
- package/dist/ast/LazyObjectOptionType.d.ts +1 -1
- package/dist/ast/LazyObjectOptionType.js +1 -1
- package/dist/ast/LazyObjectSetType.d.ts +1 -1
- package/dist/ast/LazyObjectSetType.js +1 -1
- package/dist/ast/LazyObjectType.d.ts +1 -1
- package/dist/ast/LazyObjectType.js +1 -1
- package/dist/ast/ListType.d.ts +1 -1
- package/dist/ast/ListType.js +16 -16
- package/dist/ast/LiteralType.d.ts +1 -1
- package/dist/ast/LiteralType.js +1 -1
- package/dist/ast/ObjectCompoundType.js +3 -3
- package/dist/ast/ObjectType.d.ts +1 -1
- package/dist/ast/ObjectType.js +16 -16
- package/dist/ast/OptionType.d.ts +1 -1
- package/dist/ast/OptionType.js +1 -1
- package/dist/ast/SetType.d.ts +1 -1
- package/dist/ast/SetType.js +1 -1
- package/dist/ast/TermType.d.ts +1 -1
- package/dist/ast/TermType.js +1 -1
- package/dist/ast/Type.js +15 -15
- package/dist/ast/UnionType.d.ts +1 -1
- package/dist/ast/UnionType.js +3 -3
- package/dist/generators/transformAstToLabeledPropertyGraph.js +10 -10
- package/dist/generators/ts/AbstractCollectionType.d.ts +2 -6
- package/dist/generators/ts/AbstractCollectionType.js +16 -15
- package/dist/generators/ts/AbstractContainerType.d.ts +7 -11
- package/dist/generators/ts/AbstractContainerType.js +35 -36
- package/dist/generators/ts/AbstractDateType.d.ts +4 -4
- package/dist/generators/ts/AbstractDateType.js +2 -2
- package/dist/generators/ts/AbstractIdentifierType.d.ts +1 -1
- package/dist/generators/ts/AbstractLazyObjectType.d.ts +14 -17
- package/dist/generators/ts/AbstractLazyObjectType.js +26 -38
- package/dist/generators/ts/AbstractLiteralType.d.ts +1 -5
- package/dist/generators/ts/AbstractLiteralType.js +7 -6
- package/dist/generators/ts/AbstractNumericType.d.ts +2 -2
- package/dist/generators/ts/AbstractNumericType.js +3 -3
- package/dist/generators/ts/AbstractObjectSetType.d.ts +10 -9
- package/dist/generators/ts/AbstractObjectSetType.js +2 -2
- package/dist/generators/ts/AbstractPrimitiveType.d.ts +2 -6
- package/dist/generators/ts/AbstractPrimitiveType.js +9 -10
- package/dist/generators/ts/AbstractTermType.d.ts +1 -5
- package/dist/generators/ts/AbstractTermType.js +3 -17
- package/dist/generators/ts/AbstractType.d.ts +22 -15
- package/dist/generators/ts/AbstractType.js +18 -8
- package/dist/generators/ts/BigDecimalType.d.ts +2 -2
- package/dist/generators/ts/BigDecimalType.js +3 -3
- package/dist/generators/ts/BigIntType.d.ts +1 -1
- package/dist/generators/ts/BigIntType.js +3 -3
- package/dist/generators/ts/BlankNodeType.d.ts +4 -4
- package/dist/generators/ts/BlankNodeType.js +12 -12
- package/dist/generators/ts/BooleanType.d.ts +3 -3
- package/dist/generators/ts/BooleanType.js +11 -6
- package/dist/generators/ts/DateTimeType.d.ts +1 -1
- package/dist/generators/ts/DateTimeType.js +1 -1
- package/dist/generators/ts/DateType.d.ts +1 -1
- package/dist/generators/ts/DateType.js +1 -1
- package/dist/generators/ts/DefaultValueType.d.ts +3 -7
- package/dist/generators/ts/DefaultValueType.js +17 -21
- package/dist/generators/ts/FloatType.d.ts +1 -1
- package/dist/generators/ts/FloatType.js +1 -1
- package/dist/generators/ts/GraphqlSchema.d.ts +4 -4
- package/dist/generators/ts/GraphqlSchema.js +4 -4
- package/dist/generators/ts/IdentifierType.d.ts +4 -4
- package/dist/generators/ts/IdentifierType.js +14 -14
- package/dist/generators/ts/IntType.d.ts +1 -1
- package/dist/generators/ts/IntType.js +1 -1
- package/dist/generators/ts/IriType.d.ts +4 -2
- package/dist/generators/ts/IriType.js +27 -22
- package/dist/generators/ts/LazyObjectOptionType.d.ts +2 -1
- package/dist/generators/ts/LazyObjectOptionType.js +7 -7
- package/dist/generators/ts/LazyObjectSetType.d.ts +1 -1
- package/dist/generators/ts/LazyObjectSetType.js +6 -6
- package/dist/generators/ts/LazyObjectType.d.ts +1 -1
- package/dist/generators/ts/LazyObjectType.js +5 -5
- package/dist/generators/ts/ListType.d.ts +5 -6
- package/dist/generators/ts/ListType.js +24 -25
- package/dist/generators/ts/LiteralType.d.ts +3 -2
- package/dist/generators/ts/LiteralType.js +14 -7
- package/dist/generators/ts/{NamedObjectType.d.ts → ObjectType.d.ts} +24 -24
- package/dist/generators/ts/ObjectType.js +350 -0
- package/dist/generators/ts/ObjectUnionType.d.ts +20 -0
- package/dist/generators/ts/{NamedObjectUnionType.js → ObjectUnionType.js} +54 -64
- package/dist/generators/ts/OptionType.d.ts +2 -6
- package/dist/generators/ts/OptionType.js +12 -18
- package/dist/generators/ts/RdfjsDatasetObjectSetType.js +8 -8
- package/dist/generators/ts/SetType.d.ts +1 -1
- package/dist/generators/ts/SetType.js +1 -1
- package/dist/generators/ts/Snippets.d.ts +1 -0
- package/dist/generators/ts/Snippets.js +7 -0
- package/dist/generators/ts/SparqlObjectSetType.js +2 -2
- package/dist/generators/ts/StringType.d.ts +3 -3
- package/dist/generators/ts/StringType.js +11 -6
- package/dist/generators/ts/TermType.d.ts +3 -3
- package/dist/generators/ts/TermType.js +13 -13
- package/dist/generators/ts/TsGenerator.js +12 -9
- package/dist/generators/ts/Type.d.ts +4 -5
- package/dist/generators/ts/TypeFactory.d.ts +7 -8
- package/dist/generators/ts/TypeFactory.js +79 -80
- package/dist/generators/ts/{AbstractUnionType.d.ts → UnionType.d.ts} +40 -15
- package/dist/generators/ts/{AbstractUnionType.js → UnionType.js} +328 -135
- package/dist/generators/ts/ZodGenerator.js +7 -9
- package/dist/generators/ts/{_NamedObjectType → _ObjectType}/AbstractProperty.d.ts +13 -13
- package/dist/generators/ts/{_NamedObjectType → _ObjectType}/AbstractProperty.js +11 -14
- package/dist/generators/ts/{_NamedObjectType → _ObjectType}/DiscriminantProperty.d.ts +3 -2
- package/dist/generators/ts/{_NamedObjectType → _ObjectType}/DiscriminantProperty.js +24 -15
- package/dist/generators/ts/{_NamedObjectType → _ObjectType}/IdentifierProperty.d.ts +3 -6
- package/dist/generators/ts/{_NamedObjectType → _ObjectType}/IdentifierProperty.js +20 -12
- package/dist/generators/ts/_ObjectType/ObjectType_createFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_createFunctionDeclaration.js → _ObjectType/ObjectType_createFunctionDeclaration.js} +6 -6
- package/dist/generators/ts/_ObjectType/ObjectType_equalsFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_equalsFunctionDeclaration.js → _ObjectType/ObjectType_equalsFunctionDeclaration.js} +5 -5
- package/dist/generators/ts/_ObjectType/ObjectType_filterFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_filterFunctionDeclaration.js → _ObjectType/ObjectType_filterFunctionDeclaration.js} +3 -3
- package/dist/generators/ts/_ObjectType/ObjectType_filterTypeDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_filterTypeDeclaration.js → _ObjectType/ObjectType_filterTypeDeclaration.js} +3 -3
- package/dist/generators/ts/_ObjectType/ObjectType_focusSparqlConstructTriplesFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_focusSparqlConstructTriplesFunctionDeclaration.js → _ObjectType/ObjectType_focusSparqlConstructTriplesFunctionDeclaration.js} +3 -3
- package/dist/generators/ts/_ObjectType/ObjectType_focusSparqlWherePatternsFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_focusSparqlWherePatternsFunctionDeclaration.js → _ObjectType/ObjectType_focusSparqlWherePatternsFunctionDeclaration.js} +3 -3
- package/dist/generators/ts/_ObjectType/ObjectType_fromJsonFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_fromJsonFunctionDeclaration.js → _ObjectType/ObjectType_fromJsonFunctionDeclaration.js} +4 -4
- package/dist/generators/ts/_ObjectType/ObjectType_fromRdfResourceFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_fromRdfResourceFunctionDeclaration.js → _ObjectType/ObjectType_fromRdfResourceFunctionDeclaration.js} +7 -31
- package/dist/generators/ts/_ObjectType/ObjectType_fromRdfResourceValuesFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/_ObjectType/ObjectType_fromRdfResourceValuesFunctionDeclaration.js +15 -0
- package/dist/generators/ts/_ObjectType/ObjectType_fromRdfTypeVariableStatement.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_fromRdfTypeVariableStatement.js → _ObjectType/ObjectType_fromRdfTypeVariableStatement.js} +2 -2
- package/dist/generators/ts/_ObjectType/ObjectType_graphqlTypeVariableStatement.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_graphqlTypeVariableStatement.js → _ObjectType/ObjectType_graphqlTypeVariableStatement.js} +4 -4
- package/dist/generators/ts/_ObjectType/ObjectType_hashFunctionDeclarations.d.ts +4 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_hashFunctionDeclarations.js → _ObjectType/ObjectType_hashFunctionDeclarations.js} +8 -8
- package/dist/generators/ts/_ObjectType/ObjectType_interfaceDeclaration.d.ts +4 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_interfaceDeclaration.js → _ObjectType/ObjectType_interfaceDeclaration.js} +5 -5
- package/dist/generators/ts/_ObjectType/ObjectType_isTypeFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_isTypeFunctionDeclaration.js → _ObjectType/ObjectType_isTypeFunctionDeclaration.js} +3 -3
- package/dist/generators/ts/_ObjectType/ObjectType_jsonParseFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_jsonParseFunctionDeclaration.js → _ObjectType/ObjectType_jsonParseFunctionDeclaration.js} +2 -2
- package/dist/generators/ts/_ObjectType/ObjectType_jsonSchemaFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_jsonSchemaFunctionDeclaration.js → _ObjectType/ObjectType_jsonSchemaFunctionDeclaration.js} +2 -2
- package/dist/generators/ts/_ObjectType/ObjectType_jsonTypeAliasDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_jsonTypeAliasDeclaration.js → _ObjectType/ObjectType_jsonTypeAliasDeclaration.js} +2 -2
- package/dist/generators/ts/_ObjectType/ObjectType_jsonUiSchemaFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_jsonUiSchemaFunctionDeclaration.js → _ObjectType/ObjectType_jsonUiSchemaFunctionDeclaration.js} +4 -4
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_objectSetMethodNames.d.ts → _ObjectType/ObjectType_objectSetMethodNames.d.ts} +3 -3
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_objectSetMethodNames.js → _ObjectType/ObjectType_objectSetMethodNames.js} +4 -4
- package/dist/generators/ts/_ObjectType/ObjectType_schemaVariableStatement.d.ts +5 -0
- package/dist/generators/ts/_ObjectType/ObjectType_schemaVariableStatement.js +14 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_sparqlConstructQueryFunctionDeclaration.d.ts → _ObjectType/ObjectType_sparqlConstructQueryFunctionDeclaration.d.ts} +3 -3
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_sparqlConstructQueryFunctionDeclaration.js → _ObjectType/ObjectType_sparqlConstructQueryFunctionDeclaration.js} +5 -5
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_sparqlConstructQueryStringFunctionDeclaration.d.ts → _ObjectType/ObjectType_sparqlConstructQueryStringFunctionDeclaration.d.ts} +3 -3
- package/dist/generators/ts/_ObjectType/ObjectType_sparqlConstructQueryStringFunctionDeclaration.js +12 -0
- package/dist/generators/ts/_ObjectType/ObjectType_toJsonFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_toJsonFunctionDeclaration.js → _ObjectType/ObjectType_toJsonFunctionDeclaration.js} +4 -4
- package/dist/generators/ts/_ObjectType/ObjectType_toRdfResourceFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_toRdfResourceFunctionDeclaration.js → _ObjectType/ObjectType_toRdfResourceFunctionDeclaration.js} +4 -4
- package/dist/generators/ts/_ObjectType/ObjectType_toStringFunctionDeclarations.d.ts +4 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_toStringFunctionDeclarations.js → _ObjectType/ObjectType_toStringFunctionDeclarations.js} +6 -6
- package/dist/generators/ts/_ObjectType/ObjectType_valueSparqlConstructTriplesFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_valueSparqlConstructTriplesFunctionDeclaration.js → _ObjectType/ObjectType_valueSparqlConstructTriplesFunctionDeclaration.js} +3 -3
- package/dist/generators/ts/_ObjectType/ObjectType_valueSparqlWherePatternsFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_valueSparqlWherePatternsFunctionDeclaration.js → _ObjectType/ObjectType_valueSparqlWherePatternsFunctionDeclaration.js} +3 -3
- package/dist/generators/ts/{_NamedObjectType → _ObjectType}/ShaclProperty.d.ts +2 -6
- package/dist/generators/ts/{_NamedObjectType → _ObjectType}/ShaclProperty.js +24 -28
- package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.d.ts +4 -0
- package/dist/generators/ts/{_NamedObjectType → _ObjectType}/identifierTypeDeclarations.js +4 -2
- package/dist/generators/ts/_snippets/snippets_BooleanSchema.js +2 -2
- package/dist/generators/ts/_snippets/snippets_CollectionSchema.js +1 -1
- package/dist/generators/ts/_snippets/snippets_DefaultValueSchema.js +1 -1
- package/dist/generators/ts/_snippets/snippets_IriSchema.js +2 -2
- package/dist/generators/ts/_snippets/snippets_MaybeSchema.js +2 -2
- package/dist/generators/ts/_snippets/snippets_ShaclPropertySchema.js +1 -1
- package/dist/generators/ts/_snippets/snippets_StringSchema.js +2 -2
- package/dist/generators/ts/_snippets/snippets_booleanSparqlWherePatterns.js +1 -1
- package/dist/generators/ts/_snippets/snippets_convertToIri.js +1 -1
- package/dist/generators/ts/_snippets/snippets_defaultValueSparqlWherePatterns.js +1 -1
- package/dist/generators/ts/_snippets/snippets_ensureRdfResourceType.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_ensureRdfResourceType.js +16 -0
- package/dist/generators/ts/_snippets/snippets_iriSparqlWherePatterns.js +1 -1
- package/dist/generators/ts/_snippets/snippets_listSparqlConstructTriples.js +2 -2
- package/dist/generators/ts/_snippets/snippets_listSparqlWherePatterns.js +2 -2
- package/dist/generators/ts/_snippets/snippets_maybeSparqlConstructTriples.js +1 -1
- package/dist/generators/ts/_snippets/snippets_maybeSparqlWherePatterns.js +3 -3
- package/dist/generators/ts/_snippets/snippets_setSparqlConstructTriples.js +1 -1
- package/dist/generators/ts/_snippets/snippets_setSparqlWherePatterns.js +1 -1
- package/dist/generators/ts/_snippets/snippets_shaclPropertySparqlConstructTriples.js +1 -1
- package/dist/generators/ts/_snippets/snippets_shaclPropertySparqlWherePatterns.js +1 -1
- package/dist/generators/ts/_snippets/snippets_stringSparqlWherePatterns.js +1 -1
- package/dist/generators/ts/_snippets/snippets_validateArray.js +1 -1
- package/dist/generators/ts/_snippets/snippets_validateMaybe.js +1 -1
- package/dist/generators/ts/tsComment.js +1 -1
- package/dist/input/generated.d.ts +1399 -1468
- package/dist/input/generated.js +518 -655
- package/package.json +4 -4
- package/dist/generators/ts/AbstractNamedUnionType.d.ts +0 -30
- package/dist/generators/ts/AbstractNamedUnionType.js +0 -190
- package/dist/generators/ts/AnonymousUnionType.d.ts +0 -27
- package/dist/generators/ts/AnonymousUnionType.js +0 -59
- package/dist/generators/ts/NamedObjectType.js +0 -341
- package/dist/generators/ts/NamedObjectUnionType.d.ts +0 -37
- package/dist/generators/ts/NamedUnionType.d.ts +0 -11
- package/dist/generators/ts/NamedUnionType.js +0 -13
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_createFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_equalsFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_filterFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_filterTypeDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlConstructTriplesFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlWherePatternsFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromJsonFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceValuesFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceValuesFunctionDeclaration.js +0 -15
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfTypeVariableStatement.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_graphqlTypeVariableStatement.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_hashFunctionDeclarations.d.ts +0 -4
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_interfaceDeclaration.d.ts +0 -4
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_isTypeFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonParseFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonSchemaFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonTypeAliasDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonUiSchemaFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_schemaVariableStatement.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_schemaVariableStatement.js +0 -12
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_sparqlConstructQueryStringFunctionDeclaration.js +0 -12
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toJsonFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toRdfResourceFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toStringFunctionDeclarations.d.ts +0 -4
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_valueSparqlConstructTriplesFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_valueSparqlWherePatternsFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/identifierTypeDeclarations.d.ts +0 -4
- package/dist/generators/ts/removeUndefined.d.ts +0 -2
- package/dist/generators/ts/removeUndefined.js +0 -17
- /package/dist/generators/ts/{_NamedObjectType → _ObjectType}/Property.d.ts +0 -0
- /package/dist/generators/ts/{_NamedObjectType → _ObjectType}/Property.js +0 -0
|
@@ -8,31 +8,34 @@ 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
|
-
import {
|
|
12
|
-
|
|
13
|
-
export class AbstractUnionType extends AbstractType {
|
|
11
|
+
import { code, def, joinCode, literalOf, } from "./ts-poet-wrapper.js";
|
|
12
|
+
export class UnionType extends AbstractType {
|
|
14
13
|
discriminant;
|
|
14
|
+
graphqlArgs = Maybe.empty();
|
|
15
15
|
identifierType;
|
|
16
|
+
kind = "Union";
|
|
16
17
|
recursive;
|
|
18
|
+
synthetic;
|
|
17
19
|
validationFunction = Maybe.empty();
|
|
18
|
-
constructor({ identifierType, members, recursive, ...superParameters }) {
|
|
20
|
+
constructor({ identifierType, members, recursive, synthetic, ...superParameters }) {
|
|
19
21
|
super(superParameters);
|
|
20
22
|
this.identifierType = identifierType;
|
|
21
23
|
invariant(members.length >= 2);
|
|
22
24
|
this.recursive = recursive;
|
|
23
25
|
this.discriminant = Discriminant.infer(members);
|
|
26
|
+
this.synthetic = synthetic;
|
|
24
27
|
this.lazyMembers = () => members.map((member, memberI) => {
|
|
25
28
|
let discriminantValues;
|
|
26
29
|
invariant(this.discriminant.memberValues.length === members.length);
|
|
27
30
|
switch (this.discriminant.kind) {
|
|
28
|
-
case "
|
|
31
|
+
case "Extrinsic":
|
|
29
32
|
discriminantValues = [this.discriminant.memberValues[memberI]];
|
|
30
33
|
break;
|
|
31
|
-
case "
|
|
34
|
+
case "Hybrid":
|
|
32
35
|
discriminantValues =
|
|
33
36
|
this.discriminant.memberValues[memberI].ownValues;
|
|
34
37
|
break;
|
|
35
|
-
case "
|
|
38
|
+
case "Intrinsic": {
|
|
36
39
|
// A member type's combined discriminant property values are its "own" values plus any descendant values that are
|
|
37
40
|
// not the "own" values of some other member type.
|
|
38
41
|
// So if you have type A, type B, and B inherits A, then
|
|
@@ -57,7 +60,7 @@ export class AbstractUnionType extends AbstractType {
|
|
|
57
60
|
.descendantValues.filter((value) => !memberOwnDiscriminantPropertyValues.has(value)));
|
|
58
61
|
break;
|
|
59
62
|
}
|
|
60
|
-
case "
|
|
63
|
+
case "Typeof":
|
|
61
64
|
discriminantValues = [this.discriminant.memberValues[memberI]];
|
|
62
65
|
break;
|
|
63
66
|
default:
|
|
@@ -66,15 +69,14 @@ export class AbstractUnionType extends AbstractType {
|
|
|
66
69
|
invariant(discriminantValues.length > 0);
|
|
67
70
|
const typeCheck = (json) => (instance) => {
|
|
68
71
|
const discriminant = this.discriminant; // To get type narrowing to work
|
|
69
|
-
if (discriminant.kind === "
|
|
72
|
+
if (discriminant.kind === "Typeof") {
|
|
70
73
|
return code `(${joinCode(discriminantValues.map((discriminantValue) => code `typeof ${instance} === ${literalOf(discriminantValue)}`), { on: " || " })})`;
|
|
71
74
|
}
|
|
72
|
-
if (discriminant.kind === "
|
|
75
|
+
if (discriminant.kind === "Intrinsic" && !json) {
|
|
73
76
|
switch (member.type.kind) {
|
|
74
|
-
case "
|
|
75
|
-
case "
|
|
76
|
-
|
|
77
|
-
return code `${member.type.name}.is${member.type.name}(${instance})`;
|
|
77
|
+
case "Object":
|
|
78
|
+
case "ObjectUnion":
|
|
79
|
+
return code `${member.type.alias.unsafeCoerce()}.is${member.type.alias.unsafeCoerce()}(${instance})`;
|
|
78
80
|
}
|
|
79
81
|
}
|
|
80
82
|
const discriminantName = json
|
|
@@ -85,45 +87,45 @@ export class AbstractUnionType extends AbstractType {
|
|
|
85
87
|
return {
|
|
86
88
|
discriminantValues,
|
|
87
89
|
jsonType: member.type.jsonType({
|
|
88
|
-
includeDiscriminantProperty: this.discriminant.kind === "
|
|
89
|
-
(this.discriminant.kind === "
|
|
90
|
-
this.discriminant.memberValues[memberI].kind === "
|
|
90
|
+
includeDiscriminantProperty: this.discriminant.kind === "Intrinsic" ||
|
|
91
|
+
(this.discriminant.kind === "Hybrid" &&
|
|
92
|
+
this.discriminant.memberValues[memberI].kind === "Intrinsic"),
|
|
91
93
|
}).name,
|
|
92
94
|
jsonTypeCheck: typeCheck(true),
|
|
93
95
|
primaryDiscriminantValue: discriminantValues[0],
|
|
94
96
|
type: member.type,
|
|
95
97
|
typeCheck: typeCheck(false),
|
|
96
98
|
typeToJsonExpression: (valueVariable) => member.type.toJsonExpression({
|
|
97
|
-
includeDiscriminantProperty: this.discriminant.kind === "
|
|
98
|
-
(this.discriminant.kind === "
|
|
99
|
-
this.discriminant.memberValues[memberI].kind === "
|
|
99
|
+
includeDiscriminantProperty: this.discriminant.kind === "Intrinsic" ||
|
|
100
|
+
(this.discriminant.kind === "Hybrid" &&
|
|
101
|
+
this.discriminant.memberValues[memberI].kind === "Intrinsic"),
|
|
100
102
|
variables: { value: valueVariable },
|
|
101
103
|
}),
|
|
102
104
|
unwrap: (instance) => {
|
|
103
105
|
switch (this.discriminant.kind) {
|
|
104
|
-
case "
|
|
106
|
+
case "Extrinsic":
|
|
105
107
|
return code `${instance}.value`;
|
|
106
|
-
case "
|
|
108
|
+
case "Hybrid":
|
|
107
109
|
return this.discriminant.memberValues[memberI].kind ===
|
|
108
|
-
"
|
|
110
|
+
"Intrinsic"
|
|
109
111
|
? instance
|
|
110
112
|
: code `${instance}.value`;
|
|
111
|
-
case "
|
|
112
|
-
case "
|
|
113
|
+
case "Intrinsic":
|
|
114
|
+
case "Typeof":
|
|
113
115
|
return instance;
|
|
114
116
|
}
|
|
115
117
|
},
|
|
116
118
|
wrap: (instance) => {
|
|
117
119
|
switch (this.discriminant.kind) {
|
|
118
|
-
case "
|
|
120
|
+
case "Extrinsic":
|
|
119
121
|
return code `{ ${this.discriminant.name}: ${literalOf(discriminantValues[0])} as const, value: ${instance} }`;
|
|
120
|
-
case "
|
|
122
|
+
case "Hybrid":
|
|
121
123
|
return this.discriminant.memberValues[memberI].kind ===
|
|
122
|
-
"
|
|
124
|
+
"Intrinsic"
|
|
123
125
|
? instance
|
|
124
126
|
: code `{ ${this.discriminant.name}: ${literalOf(discriminantValues[0])} as const, value: ${instance} }`;
|
|
125
|
-
case "
|
|
126
|
-
case "
|
|
127
|
+
case "Intrinsic":
|
|
128
|
+
case "Typeof":
|
|
127
129
|
return instance;
|
|
128
130
|
}
|
|
129
131
|
},
|
|
@@ -133,64 +135,128 @@ export class AbstractUnionType extends AbstractType {
|
|
|
133
135
|
get conversionFunction() {
|
|
134
136
|
return Maybe.of({
|
|
135
137
|
code: code `${this.reusables.snippets.identityConversionFunction}`,
|
|
136
|
-
sourceTypes: this.discriminant.kind === "
|
|
138
|
+
sourceTypes: this.discriminant.kind === "Typeof"
|
|
137
139
|
? this.members.map(({ primaryDiscriminantValue, type }) => ({
|
|
138
|
-
|
|
140
|
+
expression: type.expression,
|
|
139
141
|
typeof: primaryDiscriminantValue,
|
|
140
142
|
}))
|
|
141
143
|
: [
|
|
142
144
|
{
|
|
143
|
-
|
|
145
|
+
expression: this.expression,
|
|
144
146
|
typeof: "object",
|
|
145
147
|
},
|
|
146
148
|
],
|
|
147
149
|
});
|
|
148
150
|
}
|
|
151
|
+
get declaration() {
|
|
152
|
+
const alias = this.alias.extract();
|
|
153
|
+
if (!alias) {
|
|
154
|
+
return Maybe.empty();
|
|
155
|
+
}
|
|
156
|
+
const declarations = [];
|
|
157
|
+
if (this.configuration.features.has("Object.type")) {
|
|
158
|
+
declarations.push(code `export type ${def(alias)} = ${this.inlineExpression};`);
|
|
159
|
+
}
|
|
160
|
+
const staticModuleDeclarations = Object.entries(this.staticModuleDeclarations);
|
|
161
|
+
if (staticModuleDeclarations.length > 0) {
|
|
162
|
+
declarations.push(code `\
|
|
163
|
+
export namespace ${def(alias)} {
|
|
164
|
+
${joinCode(staticModuleDeclarations
|
|
165
|
+
.sort((left, right) => left[0].localeCompare(right[0]))
|
|
166
|
+
.map((_) => _[1]), { on: "\n\n" })}
|
|
167
|
+
}`);
|
|
168
|
+
}
|
|
169
|
+
return Maybe.of(joinCode(declarations, { on: "\n\n" }));
|
|
170
|
+
}
|
|
149
171
|
get discriminantProperty() {
|
|
150
172
|
switch (this.discriminant.kind) {
|
|
151
|
-
case "
|
|
173
|
+
case "Extrinsic":
|
|
152
174
|
return Maybe.of({
|
|
153
175
|
descendantValues: [],
|
|
154
176
|
jsonName: this.discriminant.jsonName,
|
|
155
177
|
ownValues: this.discriminant.memberValues,
|
|
156
178
|
name: this.discriminant.name,
|
|
157
179
|
});
|
|
158
|
-
case "
|
|
180
|
+
case "Hybrid":
|
|
159
181
|
return Maybe.of({
|
|
160
182
|
descendantValues: [],
|
|
161
183
|
jsonName: this.discriminant.jsonName,
|
|
162
184
|
ownValues: this.discriminant.memberValues.flatMap((_) => _.ownValues),
|
|
163
185
|
name: "termType",
|
|
164
186
|
});
|
|
165
|
-
case "
|
|
187
|
+
case "Intrinsic":
|
|
166
188
|
return Maybe.of({
|
|
167
189
|
descendantValues: this.discriminant.memberValues.flatMap((_) => _.descendantValues),
|
|
168
190
|
jsonName: this.discriminant.jsonName,
|
|
169
191
|
name: this.discriminant.name,
|
|
170
192
|
ownValues: this.discriminant.memberValues.flatMap((_) => _.ownValues),
|
|
171
193
|
});
|
|
172
|
-
case "
|
|
194
|
+
case "Typeof":
|
|
173
195
|
return Maybe.empty();
|
|
174
196
|
default:
|
|
175
197
|
throw this.discriminant;
|
|
176
198
|
}
|
|
177
199
|
}
|
|
200
|
+
get equalsFunction() {
|
|
201
|
+
return this.alias
|
|
202
|
+
.map((alias) => code `${alias}.equals`)
|
|
203
|
+
.orDefault(this.inlineEqualsFunction);
|
|
204
|
+
}
|
|
205
|
+
get filterFunction() {
|
|
206
|
+
return this.alias
|
|
207
|
+
.map((alias) => code `${alias}.filter`)
|
|
208
|
+
.orDefault(this.inlineFilterFunction);
|
|
209
|
+
}
|
|
210
|
+
get filterType() {
|
|
211
|
+
return this.alias
|
|
212
|
+
.map((alias) => code `${alias}.Filter`)
|
|
213
|
+
.orDefault(this.inlineFilterType);
|
|
214
|
+
}
|
|
215
|
+
get graphqlType() {
|
|
216
|
+
const alias = this.alias.extract();
|
|
217
|
+
if (!alias ||
|
|
218
|
+
!this.members.every((member) => member.type.kind === "Object")) {
|
|
219
|
+
throw new Error("not implemented");
|
|
220
|
+
}
|
|
221
|
+
return new AbstractType.GraphqlType(code `${alias}.GraphQL`, this.reusables);
|
|
222
|
+
}
|
|
223
|
+
get hashFunction() {
|
|
224
|
+
return this.alias
|
|
225
|
+
.map((alias) => code `${alias}.hash`)
|
|
226
|
+
.orDefault(this.inlineHashFunction);
|
|
227
|
+
}
|
|
228
|
+
get jsonSchemaFunctionDeclaration() {
|
|
229
|
+
const meta = {
|
|
230
|
+
// id: this.name,
|
|
231
|
+
};
|
|
232
|
+
this.comment.ifJust((description) => {
|
|
233
|
+
meta["description"] = description;
|
|
234
|
+
});
|
|
235
|
+
this.label.ifJust((label) => {
|
|
236
|
+
meta["title"] = label;
|
|
237
|
+
});
|
|
238
|
+
return code `export const schema = () => ${this.inlineJsonSchema}.meta(${meta});`;
|
|
239
|
+
}
|
|
240
|
+
get jsonTypeAliasDeclaration() {
|
|
241
|
+
return code `export type Json = ${this.inlineJsonType.name}`;
|
|
242
|
+
}
|
|
178
243
|
get members() {
|
|
179
244
|
return this.lazyMembers();
|
|
180
245
|
}
|
|
181
246
|
get mutable() {
|
|
182
247
|
return this.members.some((member) => member.type.mutable);
|
|
183
248
|
}
|
|
184
|
-
get
|
|
185
|
-
return
|
|
249
|
+
get expression() {
|
|
250
|
+
return this.alias
|
|
251
|
+
.map((alias) => code `${alias}`)
|
|
252
|
+
.orDefault(this.inlineExpression);
|
|
253
|
+
}
|
|
254
|
+
get referencesObjectType() {
|
|
255
|
+
return this.members.some((member) => member.type.referencesObjectType);
|
|
186
256
|
}
|
|
187
257
|
get schemaType() {
|
|
188
|
-
invariant(this.kind.endsWith("Type"));
|
|
189
258
|
return code `${{
|
|
190
|
-
|
|
191
|
-
// kind: '"extrinsic" | "intrinsic" | "typeof"',
|
|
192
|
-
// },
|
|
193
|
-
kind: code `${literalOf(this.kind.substring(0, this.kind.length - "Type".length))}`,
|
|
259
|
+
kind: this.kind,
|
|
194
260
|
members: code `{ ${joinCode(this.members.map(({ type, primaryDiscriminantValue }) => code `readonly ${literalOf(primaryDiscriminantValue)}: ${{
|
|
195
261
|
discriminantValues: code `readonly (number | string)[]`,
|
|
196
262
|
type: type.schemaType,
|
|
@@ -209,11 +275,21 @@ export class AbstractUnionType extends AbstractType {
|
|
|
209
275
|
get typeofs() {
|
|
210
276
|
return [...new Set(this.members.flatMap((member) => member.type.typeofs))];
|
|
211
277
|
}
|
|
278
|
+
get valueSparqlConstructTriplesFunction() {
|
|
279
|
+
return this.alias
|
|
280
|
+
.map((alias) => code `${alias}.valueSparqlConstructTriples`)
|
|
281
|
+
.orDefault(this.inlineValueSparqlConstructTriplesFunction);
|
|
282
|
+
}
|
|
283
|
+
get valueSparqlWherePatternsFunction() {
|
|
284
|
+
return this.alias
|
|
285
|
+
.map((alias) => code `${alias}.valueSparqlWherePatterns`)
|
|
286
|
+
.orDefault(this.inlineValueSparqlWherePatternsFunction);
|
|
287
|
+
}
|
|
212
288
|
get inlineEqualsFunction() {
|
|
213
289
|
return code `\
|
|
214
|
-
((left: ${this.
|
|
290
|
+
((left: ${this.expression}, right: ${this.expression}) => {
|
|
215
291
|
${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeCheck(code `left`)} && ${typeCheck(code `right`)}) {
|
|
216
|
-
return ${type.equalsFunction}(${unwrap(code `left`)} as ${type.
|
|
292
|
+
return ${type.equalsFunction}(${unwrap(code `left`)} as ${type.expression}, ${unwrap(code `right`)} as ${type.expression});
|
|
217
293
|
}`))}
|
|
218
294
|
|
|
219
295
|
return ${this.reusables.imports.Left}({ left, right, propertyName: "type", propertyValuesUnequal: { left: typeof left, right: typeof right, type: "boolean" as const }, type: "property" as const });
|
|
@@ -222,7 +298,7 @@ ${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeChe
|
|
|
222
298
|
get inlineFilterFunction() {
|
|
223
299
|
const syntheticNamePrefix = this.configuration.syntheticNamePrefix;
|
|
224
300
|
return code `\
|
|
225
|
-
((filter: ${this.filterType}, value: ${this.
|
|
301
|
+
((filter: ${this.filterType}, value: ${this.expression}) => {
|
|
226
302
|
${joinCode([
|
|
227
303
|
...this.identifierType
|
|
228
304
|
.map((identifierType) => code `\
|
|
@@ -251,7 +327,7 @@ if (filter.on?.[${literalOf(primaryDiscriminantValue)}] !== undefined && ${typeC
|
|
|
251
327
|
}
|
|
252
328
|
get inlineFromJsonFunction() {
|
|
253
329
|
return code `\
|
|
254
|
-
((value: ${this.jsonType().name}): ${this.reusables.imports.Either}<Error, ${this.
|
|
330
|
+
((value: ${this.jsonType().name}): ${this.reusables.imports.Either}<Error, ${this.expression}> => {
|
|
255
331
|
${joinCode(this.members.map(({ jsonType, jsonTypeCheck, type, unwrap, wrap }) => code `if (${jsonTypeCheck(code `value`)}) { return ${type.fromJsonExpression({
|
|
256
332
|
variables: {
|
|
257
333
|
value: code `(${unwrap(code `value`)} as ${jsonType})`,
|
|
@@ -288,22 +364,22 @@ ${joinCode(this.members.map(({ jsonType, jsonTypeCheck, type, unwrap, wrap }) =>
|
|
|
288
364
|
resourceValues: code `valueAsValues`,
|
|
289
365
|
},
|
|
290
366
|
});
|
|
291
|
-
if (this.discriminant.kind === "
|
|
292
|
-
(this.discriminant.kind === "
|
|
293
|
-
this.discriminant.memberValues[memberI].kind === "
|
|
294
|
-
typeExpression = code `${typeExpression}.map(values => values.map(value => ({ ${this.discriminant.name}: ${literalOf(primaryDiscriminantValue)} as const, value }) as (${this.
|
|
367
|
+
if (this.discriminant.kind === "Extrinsic" ||
|
|
368
|
+
(this.discriminant.kind === "Hybrid" &&
|
|
369
|
+
this.discriminant.memberValues[memberI].kind === "Extrinsic")) {
|
|
370
|
+
typeExpression = code `${typeExpression}.map(values => values.map(value => ({ ${this.discriminant.name}: ${literalOf(primaryDiscriminantValue)} as const, value }) as (${this.expression})))`;
|
|
295
371
|
}
|
|
296
|
-
typeExpression = code `(${typeExpression} as ${this.reusables.imports.Either}<Error, ${this.reusables.imports.Resource}.Values<${this.
|
|
372
|
+
typeExpression = code `(${typeExpression} as ${this.reusables.imports.Either}<Error, ${this.reusables.imports.Resource}.Values<${this.expression}>>)`;
|
|
297
373
|
return expression !== null
|
|
298
374
|
? code `${expression}.altLazy(() => ${typeExpression})`
|
|
299
375
|
: typeExpression;
|
|
300
376
|
}, null)}.chain(values => values.head());
|
|
301
377
|
}))
|
|
302
|
-
) satisfies ${this.reusables.snippets.FromRdfResourceValuesFunction}<${this.
|
|
378
|
+
) satisfies ${this.reusables.snippets.FromRdfResourceValuesFunction}<${this.expression}>)`;
|
|
303
379
|
}
|
|
304
380
|
get inlineHashFunction() {
|
|
305
381
|
return code `\
|
|
306
|
-
(<HasherT extends ${this.reusables.snippets.Hasher}>(hasher: HasherT, value: ${this.
|
|
382
|
+
(<HasherT extends ${this.reusables.snippets.Hasher}>(hasher: HasherT, value: ${this.expression}): HasherT => {
|
|
307
383
|
${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeCheck(code `value`)}) { return ${type.hashFunction}(hasher, ${unwrap(code `value`)}); }`))}
|
|
308
384
|
return hasher;
|
|
309
385
|
})`;
|
|
@@ -311,14 +387,14 @@ ${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeChe
|
|
|
311
387
|
get inlineJsonSchema() {
|
|
312
388
|
const discriminant = this.discriminant; // To get type narrowing to work
|
|
313
389
|
switch (discriminant.kind) {
|
|
314
|
-
case "
|
|
390
|
+
case "Extrinsic":
|
|
315
391
|
return code `${this.reusables.imports.z}.discriminatedUnion("${discriminant.name}", [${joinCode(this.members.map(({ type, primaryDiscriminantValue }) => code `${this.reusables.imports.z}.object({ ${discriminant.name}: ${this.reusables.imports.z}.literal(${literalOf(primaryDiscriminantValue)}), value: ${type.jsonSchema({ context: "type" })} })`), { on: "," })}]).readonly()`;
|
|
316
|
-
case "
|
|
392
|
+
case "Hybrid":
|
|
317
393
|
return code `${this.reusables.imports.z}.discriminatedUnion("${discriminant.name}", [${joinCode(this.members.map(({ primaryDiscriminantValue, type }, memberI) => {
|
|
318
394
|
switch (discriminant.memberValues[memberI].kind) {
|
|
319
|
-
case "
|
|
395
|
+
case "Extrinsic":
|
|
320
396
|
return code `${this.reusables.imports.z}.object({ ${discriminant.name}: ${this.reusables.imports.z}.literal(${literalOf(primaryDiscriminantValue)}), value: ${type.jsonSchema({ context: "type" })} })`;
|
|
321
|
-
case "
|
|
397
|
+
case "Intrinsic":
|
|
322
398
|
return type.jsonSchema({
|
|
323
399
|
includeDiscriminantProperty: true,
|
|
324
400
|
context: "type",
|
|
@@ -327,12 +403,12 @@ ${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeChe
|
|
|
327
403
|
throw new Error();
|
|
328
404
|
}
|
|
329
405
|
}), { on: "," })}]).readonly()`;
|
|
330
|
-
case "
|
|
406
|
+
case "Intrinsic":
|
|
331
407
|
return code `${this.reusables.imports.z}.discriminatedUnion("${discriminant.name}", [${joinCode(this.members.map(({ type }) => type.jsonSchema({
|
|
332
408
|
includeDiscriminantProperty: true,
|
|
333
409
|
context: "type",
|
|
334
410
|
})), { on: "," })}]).readonly()`;
|
|
335
|
-
case "
|
|
411
|
+
case "Typeof":
|
|
336
412
|
return code `${this.reusables.imports.z}.union([${joinCode(this.members.map(({ type }) => type.jsonSchema({ context: "type" })), { on: "," })}]).readonly()`;
|
|
337
413
|
default:
|
|
338
414
|
throw discriminant;
|
|
@@ -341,50 +417,50 @@ ${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeChe
|
|
|
341
417
|
get inlineJsonType() {
|
|
342
418
|
const discriminant = this.discriminant; // To get type narrowing to work
|
|
343
419
|
switch (discriminant.kind) {
|
|
344
|
-
case "
|
|
420
|
+
case "Extrinsic":
|
|
345
421
|
return new AbstractType.JsonType(code `(${joinCode(this.members.map(({ jsonType, primaryDiscriminantValue }) => code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${jsonType} }`), { on: "|" })})`);
|
|
346
|
-
case "
|
|
422
|
+
case "Hybrid":
|
|
347
423
|
return new AbstractType.JsonType(code `(${joinCode(this.members.map(({ jsonType, primaryDiscriminantValue }, memberI) => {
|
|
348
424
|
switch (discriminant.memberValues[memberI].kind) {
|
|
349
|
-
case "
|
|
425
|
+
case "Extrinsic":
|
|
350
426
|
return code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${jsonType} }`;
|
|
351
|
-
case "
|
|
427
|
+
case "Intrinsic":
|
|
352
428
|
return code `${jsonType}`;
|
|
353
429
|
default:
|
|
354
430
|
throw new Error();
|
|
355
431
|
}
|
|
356
432
|
}), { on: "|" })})`);
|
|
357
|
-
case "
|
|
358
|
-
case "
|
|
433
|
+
case "Intrinsic":
|
|
434
|
+
case "Typeof":
|
|
359
435
|
return new AbstractType.JsonType(joinCode(this.members.map(({ jsonType }) => code `${jsonType}`), { on: "|" }));
|
|
360
436
|
default:
|
|
361
437
|
throw discriminant;
|
|
362
438
|
}
|
|
363
439
|
}
|
|
364
|
-
get
|
|
440
|
+
get inlineExpression() {
|
|
365
441
|
const discriminant = this.discriminant; // To get type narrowing to work
|
|
366
442
|
switch (discriminant.kind) {
|
|
367
|
-
case "
|
|
368
|
-
return code `(${joinCode(this.members.map(({ type, primaryDiscriminantValue }) => code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${type.
|
|
369
|
-
case "
|
|
443
|
+
case "Extrinsic":
|
|
444
|
+
return code `(${joinCode(this.members.map(({ type, primaryDiscriminantValue }) => code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${type.expression} }`), { on: "|" })})`;
|
|
445
|
+
case "Hybrid":
|
|
370
446
|
return code `(${joinCode(this.members.map(({ primaryDiscriminantValue, type }, memberI) => {
|
|
371
447
|
switch (discriminant.memberValues[memberI].kind) {
|
|
372
|
-
case "
|
|
373
|
-
return code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${type.
|
|
374
|
-
case "
|
|
375
|
-
return code `${type.
|
|
448
|
+
case "Extrinsic":
|
|
449
|
+
return code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${type.expression} }`;
|
|
450
|
+
case "Intrinsic":
|
|
451
|
+
return code `${type.expression}`;
|
|
376
452
|
default:
|
|
377
453
|
throw new Error();
|
|
378
454
|
}
|
|
379
455
|
}), { on: "|" })})`;
|
|
380
|
-
case "
|
|
381
|
-
// If every type shares a discriminant (e.g., RDF/JS "termType" or generated
|
|
456
|
+
case "Intrinsic":
|
|
457
|
+
// If every type shares a discriminant (e.g., RDF/JS "termType" or generated ObjectType "type"),
|
|
382
458
|
// just join their names with "|"
|
|
383
|
-
return code `(${joinCode(this.members.map(({ type }) => code `${type.
|
|
384
|
-
case "
|
|
459
|
+
return code `(${joinCode(this.members.map(({ type }) => code `${type.expression}`), { on: "|" })})`;
|
|
460
|
+
case "Typeof":
|
|
385
461
|
// The type.name may include literal values, but they should still be unambiguous with other member types since the typeofs
|
|
386
462
|
// of the different member types are known to be different.
|
|
387
|
-
return code `(${joinCode(this.members.map(({ type }) => code `${type.
|
|
463
|
+
return code `(${joinCode(this.members.map(({ type }) => code `${type.expression}`), { on: "|" })})`;
|
|
388
464
|
default:
|
|
389
465
|
discriminant;
|
|
390
466
|
throw new Error("should never reach this point");
|
|
@@ -392,7 +468,7 @@ ${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeChe
|
|
|
392
468
|
}
|
|
393
469
|
get inlineToJsonFunction() {
|
|
394
470
|
return code `\
|
|
395
|
-
((value: ${this.
|
|
471
|
+
((value: ${this.expression}): ${this.jsonType().name} => {
|
|
396
472
|
${joinCode(this.members.map(({ typeCheck, typeToJsonExpression, unwrap, wrap }) => code `if (${typeCheck(code `value`)}) { return ${wrap(typeToJsonExpression(unwrap(code `value`)))}; }`))}
|
|
397
473
|
|
|
398
474
|
throw new Error("unable to serialize to JSON");
|
|
@@ -424,11 +500,11 @@ ${joinCode(this.members.map(({ type, unwrap, typeCheck }) => code `if (${typeChe
|
|
|
424
500
|
})}; }`))}
|
|
425
501
|
|
|
426
502
|
throw new Error("unable to serialize to RDF");
|
|
427
|
-
}) satisfies ${this.reusables.snippets.ToRdfResourceValuesFunction}<${this.
|
|
503
|
+
}) satisfies ${this.reusables.snippets.ToRdfResourceValuesFunction}<${this.expression}>)`;
|
|
428
504
|
}
|
|
429
505
|
get inlineToStringFunction() {
|
|
430
506
|
return code `\
|
|
431
|
-
((value: ${this.
|
|
507
|
+
((value: ${this.expression}): string => {
|
|
432
508
|
${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeCheck(code `value`)}) { return ${type.toStringExpression({
|
|
433
509
|
variables: { value: unwrap(code `value`) },
|
|
434
510
|
})}; }`))}
|
|
@@ -458,69 +534,193 @@ unionPatterns.push({ patterns: ${type.valueSparqlWherePatternsFunction}({ ...oth
|
|
|
458
534
|
return [{ patterns: unionPatterns, type: "union" }];
|
|
459
535
|
}) satisfies ${this.reusables.snippets.ValueSparqlWherePatternsFunction}<${this.filterType}, ${this.schemaType}>)`;
|
|
460
536
|
}
|
|
461
|
-
get
|
|
462
|
-
return {
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
537
|
+
get schemaInitializers() {
|
|
538
|
+
return super.schemaInitializers.concat(code `members: { ${joinCode(this.members.map(({ discriminantValues, type, primaryDiscriminantValue }) => code `${literalOf(primaryDiscriminantValue)}: ${{
|
|
539
|
+
discriminantValues: discriminantValues,
|
|
540
|
+
type: type.schema,
|
|
541
|
+
}}`), { on: "," })} }`);
|
|
542
|
+
}
|
|
543
|
+
get staticModuleDeclarations() {
|
|
544
|
+
const alias = this.alias.unsafeCoerce();
|
|
545
|
+
const staticModuleDeclarations = {};
|
|
546
|
+
if (this.configuration.features.has("Object.equals")) {
|
|
547
|
+
staticModuleDeclarations[`equals`] =
|
|
548
|
+
code `export const equals = ${this.inlineEqualsFunction};`;
|
|
549
|
+
}
|
|
550
|
+
if (this.configuration.features.has("Object.filter")) {
|
|
551
|
+
staticModuleDeclarations[`Filter`] =
|
|
552
|
+
code `export type Filter = ${this.inlineFilterType};`;
|
|
553
|
+
staticModuleDeclarations[`filter`] =
|
|
554
|
+
code `export const filter = ${this.inlineFilterFunction};`;
|
|
555
|
+
}
|
|
556
|
+
if (this.configuration.features.has("Object.hash")) {
|
|
557
|
+
staticModuleDeclarations[`hash`] =
|
|
558
|
+
code `export const hash = ${this.inlineHashFunction};`;
|
|
559
|
+
}
|
|
560
|
+
if (this.configuration.features.has("Object.JSON.type")) {
|
|
561
|
+
staticModuleDeclarations[`Json.type`] =
|
|
562
|
+
code `${this.jsonTypeAliasDeclaration}`;
|
|
563
|
+
}
|
|
564
|
+
if (this.configuration.features.has("Object.JSON.schema")) {
|
|
565
|
+
staticModuleDeclarations[`Json.namespace`] = code `\
|
|
566
|
+
export namespace Json {
|
|
567
|
+
${this.jsonSchemaFunctionDeclaration}
|
|
568
|
+
|
|
569
|
+
export function parse(json: unknown): ${this.reusables.imports.Either}<Error, Json> {
|
|
570
|
+
const jsonSafeParseResult = schema().safeParse(json);
|
|
571
|
+
if (!jsonSafeParseResult.success) { return ${this.reusables.imports.Left}(jsonSafeParseResult.error); }
|
|
572
|
+
return ${this.reusables.imports.Right}(jsonSafeParseResult.data);
|
|
573
|
+
}
|
|
574
|
+
}`;
|
|
575
|
+
}
|
|
576
|
+
if (this.configuration.features.has("Object.fromJson")) {
|
|
577
|
+
staticModuleDeclarations[`fromJson`] =
|
|
578
|
+
code `export const fromJson = ${this.inlineFromJsonFunction};`;
|
|
579
|
+
}
|
|
580
|
+
if (this.configuration.features.has("Object.fromRdf")) {
|
|
581
|
+
staticModuleDeclarations[`fromRdfResourceValues`] =
|
|
582
|
+
code `export const fromRdfResourceValues: ${this.reusables.snippets.FromRdfResourceValuesFunction}<${alias}> = ${this.inlineFromRdfResourceValuesFunction};`;
|
|
583
|
+
}
|
|
584
|
+
if (this.configuration.features.has("Object.toJson")) {
|
|
585
|
+
staticModuleDeclarations[`toJson`] =
|
|
586
|
+
code `export const toJson = ${this.inlineToJsonFunction};`;
|
|
587
|
+
}
|
|
588
|
+
if (this.configuration.features.has("Object.toRdf")) {
|
|
589
|
+
staticModuleDeclarations[`toRdfResourceValues`] =
|
|
590
|
+
code `export const toRdfResourceValues = ${this.inlineToRdfResourceValuesFunction};`;
|
|
591
|
+
}
|
|
592
|
+
if (this.configuration.features.has("Object.SPARQL")) {
|
|
593
|
+
staticModuleDeclarations[`valueSparqlConstructTriples`] =
|
|
594
|
+
code `export const valueSparqlConstructTriples: ${this.reusables.snippets.ValueSparqlConstructTriplesFunction}<${this.filterType}, ${this.schemaType}> = ${this.inlineValueSparqlConstructTriplesFunction};`;
|
|
595
|
+
staticModuleDeclarations[`valueSparqlWherePatterns`] =
|
|
596
|
+
code `export const valueSparqlWherePatterns: ${this.reusables.snippets.ValueSparqlWherePatternsFunction}<${this.filterType}, ${this.schemaType}> = ${this.inlineValueSparqlWherePatternsFunction};`;
|
|
597
|
+
}
|
|
598
|
+
if (this.configuration.features.has("Object.toString")) {
|
|
599
|
+
const syntheticNamePrefix = this.configuration.syntheticNamePrefix;
|
|
600
|
+
staticModuleDeclarations[`${syntheticNamePrefix}toString`] =
|
|
601
|
+
code `export const ${syntheticNamePrefix}toString = ${this.inlineToStringFunction};`;
|
|
602
|
+
}
|
|
603
|
+
return staticModuleDeclarations;
|
|
604
|
+
}
|
|
605
|
+
fromJsonExpression({ variables, }) {
|
|
606
|
+
return code `${this.alias.map((alias) => code `${alias}.fromJson`).orDefault(this.inlineFromJsonFunction)}(${variables.value})`;
|
|
607
|
+
}
|
|
608
|
+
fromRdfResourceValuesExpression({ variables, }) {
|
|
609
|
+
const { resourceValues: resourceValuesVariable, ...fromRdfResourceValuesOptionsTemp } = variables;
|
|
610
|
+
const fromRdfResourceValuesOptions = fromRdfResourceValuesOptionsTemp;
|
|
611
|
+
if (!this.configuration.features.has("ObjectSet")) {
|
|
612
|
+
delete fromRdfResourceValuesOptions["objectSet"];
|
|
613
|
+
}
|
|
614
|
+
return code `${this.alias.map((alias) => code `${alias}.fromRdfResourceValues`).orDefault(this.inlineFromRdfResourceValuesFunction)}(${resourceValuesVariable}, ${fromRdfResourceValuesOptions})`;
|
|
615
|
+
}
|
|
616
|
+
graphqlResolveExpression({ variables, }) {
|
|
617
|
+
return variables.value;
|
|
618
|
+
}
|
|
619
|
+
jsonSchema({ context, }) {
|
|
620
|
+
const expression = this.alias
|
|
621
|
+
.map((alias) => code `${alias}.Json.schema()`)
|
|
622
|
+
.orDefault(this.inlineJsonSchema);
|
|
623
|
+
if (context === "property" && this.recursive) {
|
|
624
|
+
return code `${this.reusables.imports.z}.lazy((): ${this.reusables.imports.z}.ZodType<${this.jsonType().name}> => ${expression})`;
|
|
625
|
+
}
|
|
626
|
+
return expression;
|
|
627
|
+
}
|
|
628
|
+
jsonType() {
|
|
629
|
+
return this.alias
|
|
630
|
+
.map((alias) => new AbstractType.JsonType(`${alias}.Json`))
|
|
631
|
+
.orDefault(this.inlineJsonType);
|
|
469
632
|
}
|
|
470
633
|
jsonUiSchemaElement() {
|
|
471
634
|
return Maybe.empty();
|
|
472
635
|
}
|
|
636
|
+
toJsonExpression({ variables, }) {
|
|
637
|
+
return code `${this.alias.map((alias) => code `${alias}.toJson`).orDefault(this.inlineToJsonFunction)}(${variables.value})`;
|
|
638
|
+
}
|
|
639
|
+
toRdfResourceValuesExpression({ variables, }) {
|
|
640
|
+
const { value: valueVariable, ...otherVariables } = variables;
|
|
641
|
+
return code `${this.alias.map((alias) => code `${alias}.toRdfResourceValues`).orDefault(this.inlineToRdfResourceValuesFunction)}(${valueVariable}, ${otherVariables})`;
|
|
642
|
+
}
|
|
643
|
+
toStringExpression({ variables, }) {
|
|
644
|
+
return code `${this.alias.map((alias) => code `${alias}.${this.configuration.syntheticNamePrefix}toString`).orDefault(this.inlineToStringFunction)}(${variables.value})`;
|
|
645
|
+
}
|
|
473
646
|
lazyMembers;
|
|
474
647
|
}
|
|
475
648
|
__decorate([
|
|
476
649
|
Memoize()
|
|
477
|
-
],
|
|
650
|
+
], UnionType.prototype, "conversionFunction", null);
|
|
651
|
+
__decorate([
|
|
652
|
+
Memoize()
|
|
653
|
+
], UnionType.prototype, "declaration", null);
|
|
654
|
+
__decorate([
|
|
655
|
+
Memoize()
|
|
656
|
+
], UnionType.prototype, "discriminantProperty", null);
|
|
478
657
|
__decorate([
|
|
479
658
|
Memoize()
|
|
480
|
-
],
|
|
659
|
+
], UnionType.prototype, "equalsFunction", null);
|
|
481
660
|
__decorate([
|
|
482
661
|
Memoize()
|
|
483
|
-
],
|
|
662
|
+
], UnionType.prototype, "filterFunction", null);
|
|
484
663
|
__decorate([
|
|
485
664
|
Memoize()
|
|
486
|
-
],
|
|
665
|
+
], UnionType.prototype, "filterType", null);
|
|
487
666
|
__decorate([
|
|
488
667
|
Memoize()
|
|
489
|
-
],
|
|
668
|
+
], UnionType.prototype, "graphqlType", null);
|
|
490
669
|
__decorate([
|
|
491
670
|
Memoize()
|
|
492
|
-
],
|
|
671
|
+
], UnionType.prototype, "hashFunction", null);
|
|
493
672
|
__decorate([
|
|
494
673
|
Memoize()
|
|
495
|
-
],
|
|
674
|
+
], UnionType.prototype, "members", null);
|
|
496
675
|
__decorate([
|
|
497
676
|
Memoize()
|
|
498
|
-
],
|
|
677
|
+
], UnionType.prototype, "mutable", null);
|
|
499
678
|
__decorate([
|
|
500
679
|
Memoize()
|
|
501
|
-
],
|
|
680
|
+
], UnionType.prototype, "expression", null);
|
|
502
681
|
__decorate([
|
|
503
682
|
Memoize()
|
|
504
|
-
],
|
|
683
|
+
], UnionType.prototype, "toRdfResourceValueTypes", null);
|
|
505
684
|
__decorate([
|
|
506
685
|
Memoize()
|
|
507
|
-
],
|
|
686
|
+
], UnionType.prototype, "typeofs", null);
|
|
508
687
|
__decorate([
|
|
509
688
|
Memoize()
|
|
510
|
-
],
|
|
689
|
+
], UnionType.prototype, "valueSparqlConstructTriplesFunction", null);
|
|
511
690
|
__decorate([
|
|
512
691
|
Memoize()
|
|
513
|
-
],
|
|
692
|
+
], UnionType.prototype, "valueSparqlWherePatternsFunction", null);
|
|
514
693
|
__decorate([
|
|
515
694
|
Memoize()
|
|
516
|
-
],
|
|
695
|
+
], UnionType.prototype, "inlineEqualsFunction", null);
|
|
696
|
+
__decorate([
|
|
697
|
+
Memoize()
|
|
698
|
+
], UnionType.prototype, "inlineFilterFunction", null);
|
|
699
|
+
__decorate([
|
|
700
|
+
Memoize()
|
|
701
|
+
], UnionType.prototype, "inlineFilterType", null);
|
|
702
|
+
__decorate([
|
|
703
|
+
Memoize()
|
|
704
|
+
], UnionType.prototype, "inlineJsonType", null);
|
|
705
|
+
__decorate([
|
|
706
|
+
Memoize()
|
|
707
|
+
], UnionType.prototype, "inlineExpression", null);
|
|
708
|
+
__decorate([
|
|
709
|
+
Memoize()
|
|
710
|
+
], UnionType.prototype, "inlineValueSparqlConstructTriplesFunction", null);
|
|
711
|
+
__decorate([
|
|
712
|
+
Memoize()
|
|
713
|
+
], UnionType.prototype, "inlineValueSparqlWherePatternsFunction", null);
|
|
714
|
+
__decorate([
|
|
715
|
+
Memoize()
|
|
716
|
+
], UnionType.prototype, "jsonType", null);
|
|
517
717
|
function termTypes(type) {
|
|
518
718
|
switch (type.kind) {
|
|
519
|
-
case "
|
|
520
|
-
case "
|
|
521
|
-
case "
|
|
522
|
-
case "
|
|
523
|
-
case "
|
|
719
|
+
case "BlankNode":
|
|
720
|
+
case "Iri":
|
|
721
|
+
case "Identifier":
|
|
722
|
+
case "Literal":
|
|
723
|
+
case "Term":
|
|
524
724
|
return type.termTypes;
|
|
525
725
|
default:
|
|
526
726
|
return emptyTermTypesSet;
|
|
@@ -534,7 +734,7 @@ export var Discriminant;
|
|
|
534
734
|
if (members.some((member) => member.discriminantValue.isJust())) {
|
|
535
735
|
return {
|
|
536
736
|
jsonName: "type",
|
|
537
|
-
kind: "
|
|
737
|
+
kind: "Extrinsic",
|
|
538
738
|
memberValues: members.map((member, memberI) => member.discriminantValue.orDefault(memberI)),
|
|
539
739
|
name: "type",
|
|
540
740
|
};
|
|
@@ -566,7 +766,7 @@ export var Discriminant;
|
|
|
566
766
|
if (inlineDiscriminantProperty) {
|
|
567
767
|
return {
|
|
568
768
|
jsonName: inlineDiscriminantProperty.jsonName,
|
|
569
|
-
kind: "
|
|
769
|
+
kind: "Intrinsic",
|
|
570
770
|
memberValues,
|
|
571
771
|
name: inlineDiscriminantProperty.name,
|
|
572
772
|
};
|
|
@@ -583,7 +783,7 @@ export var Discriminant;
|
|
|
583
783
|
if (memberTypeofsSet.size === memberTypes.length) {
|
|
584
784
|
return {
|
|
585
785
|
memberValues: memberTypes.flatMap((memberType) => memberType.typeofs),
|
|
586
|
-
kind: "
|
|
786
|
+
kind: "Typeof",
|
|
587
787
|
};
|
|
588
788
|
}
|
|
589
789
|
}
|
|
@@ -597,8 +797,8 @@ export var Discriminant;
|
|
|
597
797
|
continue;
|
|
598
798
|
}
|
|
599
799
|
extrinsicMemberTypeCount++;
|
|
600
|
-
if (
|
|
601
|
-
extrinsicMemberTypeNamesSet.add(memberType.
|
|
800
|
+
if (memberType.alias.isJust()) {
|
|
801
|
+
extrinsicMemberTypeNamesSet.add(memberType.alias.extract());
|
|
602
802
|
}
|
|
603
803
|
else {
|
|
604
804
|
break;
|
|
@@ -606,19 +806,19 @@ export var Discriminant;
|
|
|
606
806
|
}
|
|
607
807
|
return {
|
|
608
808
|
jsonName: "termType",
|
|
609
|
-
kind: "
|
|
809
|
+
kind: "Hybrid",
|
|
610
810
|
memberValues: memberTypes.map((memberType, memberTypeI) => {
|
|
611
811
|
const memberTermTypes = termTypes(memberType);
|
|
612
812
|
if (memberTermTypes.size > 0) {
|
|
613
813
|
return {
|
|
614
|
-
kind: "
|
|
814
|
+
kind: "Intrinsic",
|
|
615
815
|
ownValues: [...memberTermTypes],
|
|
616
816
|
};
|
|
617
817
|
}
|
|
618
818
|
return {
|
|
619
|
-
kind: "
|
|
819
|
+
kind: "Extrinsic",
|
|
620
820
|
ownValues: extrinsicMemberTypeNamesSet.size === extrinsicMemberTypeCount
|
|
621
|
-
? [memberType.
|
|
821
|
+
? [memberType.alias.unsafeCoerce()]
|
|
622
822
|
: [memberTypeI.toString()],
|
|
623
823
|
};
|
|
624
824
|
}),
|
|
@@ -629,32 +829,25 @@ export var Discriminant;
|
|
|
629
829
|
{
|
|
630
830
|
let memberValues;
|
|
631
831
|
{
|
|
632
|
-
const memberTypeNames = memberTypes.map((memberType) => memberType.
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
memberValues = memberTypeNames;
|
|
637
|
-
}
|
|
638
|
-
else {
|
|
639
|
-
// Otherwise prefix the non-unique strings with an index and use those as the discriminant values.
|
|
640
|
-
memberValues = memberTypeNames.map((memberTypeName, memberTypeI) => `${memberTypeI}-${memberTypeName}`);
|
|
641
|
-
}
|
|
832
|
+
const memberTypeNames = memberTypes.map((memberType) => memberType.alias.orDefault(memberType.typeofs[0]));
|
|
833
|
+
const memberTypeNamesSet = new Set(memberTypeNames);
|
|
834
|
+
if (memberTypeNamesSet.size === memberTypeNames.length) {
|
|
835
|
+
memberValues = memberTypeNames;
|
|
642
836
|
}
|
|
643
837
|
else {
|
|
644
|
-
//
|
|
645
|
-
|
|
646
|
-
memberValues = memberTypes.map((_, memberTypeI) => memberTypeI);
|
|
838
|
+
// Otherwise prefix the non-unique strings with an index and use those as the discriminant values.
|
|
839
|
+
memberValues = memberTypeNames.map((memberTypeName, memberTypeI) => `${memberTypeI}-${memberTypeName}`);
|
|
647
840
|
}
|
|
648
841
|
}
|
|
649
842
|
invariant(memberValues.length === memberTypes.length);
|
|
650
843
|
return {
|
|
651
844
|
jsonName: "type",
|
|
652
|
-
kind: "
|
|
845
|
+
kind: "Extrinsic",
|
|
653
846
|
name: "type",
|
|
654
|
-
memberValues
|
|
847
|
+
memberValues,
|
|
655
848
|
};
|
|
656
849
|
}
|
|
657
850
|
}
|
|
658
851
|
Discriminant.infer = infer;
|
|
659
852
|
})(Discriminant || (Discriminant = {}));
|
|
660
|
-
//# sourceMappingURL=
|
|
853
|
+
//# sourceMappingURL=UnionType.js.map
|