@shaclmate/compiler 4.0.39 → 4.0.41
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.d.ts +0 -8
- package/dist/ShapesGraphToAstTransformer.js +5 -85
- package/dist/_ShapesGraphToAstTransformer/shapeNodeKinds.js +128 -160
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstObjectType.d.ts +1 -1
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstObjectType.js +0 -16
- package/dist/ast/AbstractCompoundType.d.ts +2 -1
- package/dist/ast/AbstractCompoundType.js +1 -1
- package/dist/ast/AbstractLazyObjectType.d.ts +0 -2
- package/dist/ast/Ast.d.ts +1 -3
- package/dist/ast/ListType.d.ts +1 -1
- package/dist/ast/ListType.js +1 -1
- package/dist/ast/ObjectType.d.ts +0 -12
- package/dist/ast/ObjectType.js +0 -78
- package/dist/generators/AstJsonGenerator.js +7 -3
- package/dist/generators/transformAstToLabeledPropertyGraph.js +59 -56
- package/dist/generators/ts/AbstractCollectionType.d.ts +5 -12
- package/dist/generators/ts/AbstractCollectionType.js +9 -68
- package/dist/generators/ts/AbstractContainerType.d.ts +4 -6
- package/dist/generators/ts/AbstractContainerType.js +5 -9
- package/dist/generators/ts/AbstractDateType.d.ts +6 -3
- package/dist/generators/ts/AbstractDateType.js +7 -2
- package/dist/generators/ts/AbstractIdentifierType.d.ts +4 -0
- package/dist/generators/ts/AbstractIdentifierType.js +3 -0
- package/dist/generators/ts/AbstractLazyObjectType.d.ts +9 -9
- package/dist/generators/ts/AbstractLazyObjectType.js +30 -19
- package/dist/generators/ts/AbstractLiteralType.d.ts +1 -0
- package/dist/generators/ts/AbstractNumericType.d.ts +1 -1
- package/dist/generators/ts/AbstractNumericType.js +9 -9
- package/dist/generators/ts/AbstractObjectSetType.d.ts +10 -9
- package/dist/generators/ts/AbstractObjectSetType.js +2 -2
- package/dist/generators/ts/AbstractPrimitiveType.d.ts +1 -0
- package/dist/generators/ts/AbstractPrimitiveType.js +2 -2
- package/dist/generators/ts/AbstractTermType.d.ts +1 -2
- package/dist/generators/ts/AbstractTermType.js +3 -5
- package/dist/generators/ts/AbstractType.d.ts +61 -26
- package/dist/generators/ts/AbstractType.js +37 -17
- package/dist/generators/ts/BigDecimalType.d.ts +5 -1
- package/dist/generators/ts/BigDecimalType.js +6 -3
- package/dist/generators/ts/BigIntType.d.ts +3 -1
- package/dist/generators/ts/BigIntType.js +3 -3
- package/dist/generators/ts/BlankNodeType.d.ts +3 -3
- package/dist/generators/ts/BlankNodeType.js +13 -13
- package/dist/generators/ts/BooleanType.d.ts +5 -3
- package/dist/generators/ts/BooleanType.js +11 -6
- package/dist/generators/ts/DefaultValueType.d.ts +40 -2
- package/dist/generators/ts/DefaultValueType.js +14 -12
- package/dist/generators/ts/FloatType.d.ts +3 -1
- package/dist/generators/ts/FloatType.js +1 -1
- package/dist/generators/ts/GraphqlSchema.d.ts +4 -4
- package/dist/generators/ts/GraphqlSchema.js +6 -6
- package/dist/generators/ts/IdentifierType.d.ts +3 -3
- package/dist/generators/ts/IdentifierType.js +19 -17
- package/dist/generators/ts/IntType.d.ts +3 -1
- package/dist/generators/ts/IntType.js +1 -1
- package/dist/generators/ts/IriType.d.ts +2 -2
- package/dist/generators/ts/IriType.js +21 -19
- package/dist/generators/ts/LazyObjectOptionType.d.ts +2 -0
- package/dist/generators/ts/LazyObjectOptionType.js +14 -10
- package/dist/generators/ts/LazyObjectSetType.js +14 -8
- package/dist/generators/ts/LazyObjectType.js +9 -6
- package/dist/generators/ts/ListType.d.ts +13 -5
- package/dist/generators/ts/ListType.js +48 -12
- package/dist/generators/ts/LiteralType.d.ts +5 -1
- package/dist/generators/ts/LiteralType.js +11 -8
- package/dist/generators/ts/{NamedObjectType.d.ts → ObjectType.d.ts} +19 -34
- package/dist/generators/ts/ObjectType.js +282 -0
- package/dist/generators/ts/ObjectUnionType.d.ts +20 -0
- package/dist/generators/ts/{NamedObjectUnionType.js → ObjectUnionType.js} +52 -60
- package/dist/generators/ts/OptionType.d.ts +6 -2
- package/dist/generators/ts/OptionType.js +20 -15
- package/dist/generators/ts/RdfjsDatasetObjectSetType.js +8 -11
- package/dist/generators/ts/SetType.d.ts +16 -1
- package/dist/generators/ts/SetType.js +80 -2
- package/dist/generators/ts/Snippets.d.ts +3 -1
- package/dist/generators/ts/Snippets.js +18 -4
- package/dist/generators/ts/SparqlObjectSetType.js +2 -2
- package/dist/generators/ts/StringType.d.ts +5 -3
- package/dist/generators/ts/StringType.js +15 -6
- package/dist/generators/ts/TermType.d.ts +6 -2
- package/dist/generators/ts/TermType.js +15 -12
- package/dist/generators/ts/TsGenerator.d.ts +1 -1
- package/dist/generators/ts/TsGenerator.js +60 -32
- package/dist/generators/ts/Type.d.ts +4 -5
- package/dist/generators/ts/TypeFactory.d.ts +7 -8
- package/dist/generators/ts/TypeFactory.js +62 -76
- package/dist/generators/ts/{AbstractUnionType.d.ts → UnionType.d.ts} +36 -11
- package/dist/generators/ts/{AbstractUnionType.js → UnionType.js} +296 -105
- package/dist/generators/ts/ZodGenerator.d.ts +1 -1
- package/dist/generators/ts/ZodGenerator.js +21 -16
- package/dist/generators/ts/{_NamedObjectType → _ObjectType}/AbstractProperty.d.ts +9 -6
- package/dist/generators/ts/{_NamedObjectType → _ObjectType}/AbstractProperty.js +3 -3
- package/dist/generators/ts/{_NamedObjectType → _ObjectType}/DiscriminantProperty.d.ts +9 -13
- package/dist/generators/ts/{_NamedObjectType → _ObjectType}/DiscriminantProperty.js +22 -39
- package/dist/generators/ts/{_NamedObjectType → _ObjectType}/IdentifierProperty.d.ts +1 -5
- package/dist/generators/ts/{_NamedObjectType → _ObjectType}/IdentifierProperty.js +18 -13
- package/dist/generators/ts/_ObjectType/ObjectType_createFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/_ObjectType/ObjectType_createFunctionDeclaration.js +44 -0
- package/dist/generators/ts/_ObjectType/ObjectType_equalsFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_equalsFunctionDeclaration.js → _ObjectType/ObjectType_equalsFunctionDeclaration.js} +3 -7
- package/dist/generators/ts/_ObjectType/ObjectType_filterFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_filterFunctionDeclaration.js → _ObjectType/ObjectType_filterFunctionDeclaration.js} +3 -6
- package/dist/generators/ts/_ObjectType/ObjectType_filterTypeDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_filterTypeDeclaration.js → _ObjectType/ObjectType_filterTypeDeclaration.js} +2 -5
- package/dist/generators/ts/_ObjectType/ObjectType_focusSparqlConstructTriplesFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_focusSparqlConstructTriplesFunctionDeclaration.js → _ObjectType/ObjectType_focusSparqlConstructTriplesFunctionDeclaration.js} +2 -6
- package/dist/generators/ts/_ObjectType/ObjectType_focusSparqlWherePatternsFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_focusSparqlWherePatternsFunctionDeclaration.js → _ObjectType/ObjectType_focusSparqlWherePatternsFunctionDeclaration.js} +5 -24
- package/dist/generators/ts/_ObjectType/ObjectType_fromJsonFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/_ObjectType/ObjectType_fromJsonFunctionDeclaration.js +18 -0
- package/dist/generators/ts/_ObjectType/ObjectType_fromRdfResourceFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/_ObjectType/ObjectType_fromRdfResourceFunctionDeclaration.js +51 -0
- 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/_ObjectType/ObjectType_hashFunctionDeclarations.js +41 -0
- package/dist/generators/ts/_ObjectType/ObjectType_interfaceDeclaration.d.ts +4 -0
- package/dist/generators/ts/_ObjectType/ObjectType_interfaceDeclaration.js +12 -0
- package/dist/generators/ts/_ObjectType/ObjectType_isTypeFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/_ObjectType/ObjectType_isTypeFunctionDeclaration.js +20 -0
- 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} +5 -11
- package/dist/generators/ts/_ObjectType/ObjectType_jsonTypeAliasDeclaration.d.ts +5 -0
- package/dist/generators/ts/_ObjectType/ObjectType_jsonTypeAliasDeclaration.js +9 -0
- package/dist/generators/ts/_ObjectType/ObjectType_jsonUiSchemaFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_jsonUiSchemaFunctionDeclaration.js → _ObjectType/ObjectType_jsonUiSchemaFunctionDeclaration.js} +4 -6
- 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 +12 -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/_ObjectType/ObjectType_toJsonFunctionDeclaration.js +20 -0
- 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} +7 -14
- 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.js +12 -12
- package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.d.ts +4 -0
- package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.js +16 -0
- package/dist/generators/ts/_snippets/snippets_convertToArraySet.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToArraySet.js +8 -0
- package/dist/generators/ts/_snippets/snippets_convertToList.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToList.js +7 -0
- package/dist/generators/ts/_snippets/snippets_convertToScalarSet.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToScalarSet.js +15 -0
- package/dist/input/generated.d.ts +758 -117
- package/dist/input/generated.js +636 -128
- package/package.json +4 -6
- 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 -342
- 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_createFunctionDeclaration.js +0 -65
- 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_fromJsonFunctionDeclaration.js +0 -43
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceFunctionDeclaration.js +0 -80
- 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_hashFunctionDeclarations.js +0 -45
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_interfaceDeclaration.d.ts +0 -4
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_interfaceDeclaration.js +0 -16
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_isTypeFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_isTypeFunctionDeclaration.js +0 -17
- 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_jsonTypeAliasDeclaration.js +0 -16
- 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_toJsonFunctionDeclaration.js +0 -41
- 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/_NamedObjectType/identifierTypeDeclarations.js +0 -25
- package/dist/generators/ts/_snippets/snippets_convertToArray.d.ts +0 -3
- package/dist/generators/ts/_snippets/snippets_convertToArray.js +0 -8
- /package/dist/generators/ts/{_NamedObjectType → _ObjectType}/Property.d.ts +0 -0
- /package/dist/generators/ts/{_NamedObjectType → _ObjectType}/Property.js +0 -0
- /package/dist/generators/ts/{_NamedObjectType → _ObjectType}/ShaclProperty.d.ts +0 -0
|
@@ -8,18 +8,22 @@ 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 { code, joinCode, literalOf } from "./ts-poet-wrapper.js";
|
|
12
|
-
export class
|
|
11
|
+
import { code, def, joinCode, literalOf, } from "./ts-poet-wrapper.js";
|
|
12
|
+
export class UnionType extends AbstractType {
|
|
13
13
|
discriminant;
|
|
14
|
+
graphqlArgs = Maybe.empty();
|
|
14
15
|
identifierType;
|
|
16
|
+
kind = "Union";
|
|
15
17
|
recursive;
|
|
18
|
+
synthetic;
|
|
16
19
|
validationFunction = Maybe.empty();
|
|
17
|
-
constructor({ identifierType, members, recursive, ...superParameters }) {
|
|
20
|
+
constructor({ identifierType, members, recursive, synthetic, ...superParameters }) {
|
|
18
21
|
super(superParameters);
|
|
19
22
|
this.identifierType = identifierType;
|
|
20
23
|
invariant(members.length >= 2);
|
|
21
24
|
this.recursive = recursive;
|
|
22
25
|
this.discriminant = Discriminant.infer(members);
|
|
26
|
+
this.synthetic = synthetic;
|
|
23
27
|
this.lazyMembers = () => members.map((member, memberI) => {
|
|
24
28
|
let discriminantValues;
|
|
25
29
|
invariant(this.discriminant.memberValues.length === members.length);
|
|
@@ -28,32 +32,11 @@ export class AbstractUnionType extends AbstractType {
|
|
|
28
32
|
discriminantValues = [this.discriminant.memberValues[memberI]];
|
|
29
33
|
break;
|
|
30
34
|
case "Hybrid":
|
|
31
|
-
discriminantValues =
|
|
32
|
-
this.discriminant.memberValues[memberI].ownValues;
|
|
35
|
+
discriminantValues = this.discriminant.memberValues[memberI].values;
|
|
33
36
|
break;
|
|
34
37
|
case "Intrinsic": {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// So if you have type A, type B, and B inherits A, then
|
|
38
|
-
// A has
|
|
39
|
-
// own discriminant property values: ["A"]
|
|
40
|
-
// descendant discriminant property values: ["B"]
|
|
41
|
-
// and B has
|
|
42
|
-
// own discriminant property values: ["B"]
|
|
43
|
-
// descendant discriminant property values ["B"]
|
|
44
|
-
// In this case A shouldn't have "B" as a combined discriminant property value since it's "claimed" by B.
|
|
45
|
-
const memberOwnDiscriminantPropertyValues = new Set();
|
|
46
|
-
for (const member of members) {
|
|
47
|
-
for (const ownDiscriminantPropertyValue of member.type.discriminantProperty.unsafeCoerce()
|
|
48
|
-
.ownValues) {
|
|
49
|
-
memberOwnDiscriminantPropertyValues.add(ownDiscriminantPropertyValue);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
discriminantValues = member.type.discriminantProperty
|
|
53
|
-
.unsafeCoerce()
|
|
54
|
-
.ownValues.concat(member.type.discriminantProperty
|
|
55
|
-
.unsafeCoerce()
|
|
56
|
-
.descendantValues.filter((value) => !memberOwnDiscriminantPropertyValues.has(value)));
|
|
38
|
+
discriminantValues =
|
|
39
|
+
member.type.discriminantProperty.unsafeCoerce().values;
|
|
57
40
|
break;
|
|
58
41
|
}
|
|
59
42
|
case "Typeof":
|
|
@@ -70,10 +53,9 @@ export class AbstractUnionType extends AbstractType {
|
|
|
70
53
|
}
|
|
71
54
|
if (discriminant.kind === "Intrinsic" && !json) {
|
|
72
55
|
switch (member.type.kind) {
|
|
73
|
-
case "
|
|
74
|
-
case "
|
|
75
|
-
|
|
76
|
-
return code `${member.type.name}.is${member.type.name}(${instance})`;
|
|
56
|
+
case "Object":
|
|
57
|
+
case "ObjectUnion":
|
|
58
|
+
return code `${member.type.alias.unsafeCoerce()}.is${member.type.alias.unsafeCoerce()}(${instance})`;
|
|
77
59
|
}
|
|
78
60
|
}
|
|
79
61
|
const discriminantName = json
|
|
@@ -87,7 +69,7 @@ export class AbstractUnionType extends AbstractType {
|
|
|
87
69
|
includeDiscriminantProperty: this.discriminant.kind === "Intrinsic" ||
|
|
88
70
|
(this.discriminant.kind === "Hybrid" &&
|
|
89
71
|
this.discriminant.memberValues[memberI].kind === "Intrinsic"),
|
|
90
|
-
}).
|
|
72
|
+
}).expression,
|
|
91
73
|
jsonTypeCheck: typeCheck(true),
|
|
92
74
|
primaryDiscriminantValue: discriminantValues[0],
|
|
93
75
|
type: member.type,
|
|
@@ -133,40 +115,61 @@ export class AbstractUnionType extends AbstractType {
|
|
|
133
115
|
return Maybe.of({
|
|
134
116
|
code: code `${this.reusables.snippets.identityConversionFunction}`,
|
|
135
117
|
sourceTypes: this.discriminant.kind === "Typeof"
|
|
136
|
-
? this.members.
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}))
|
|
118
|
+
? this.members.flatMap(({ type }) => type.jsTypes.map((jsType) => ({
|
|
119
|
+
expression: type.expression,
|
|
120
|
+
jsType,
|
|
121
|
+
})))
|
|
140
122
|
: [
|
|
141
123
|
{
|
|
142
|
-
|
|
143
|
-
|
|
124
|
+
expression: this.expression,
|
|
125
|
+
jsType: {
|
|
126
|
+
instanceof: "Object",
|
|
127
|
+
typeof: "object",
|
|
128
|
+
},
|
|
144
129
|
},
|
|
145
130
|
],
|
|
146
131
|
});
|
|
147
132
|
}
|
|
133
|
+
get declaration() {
|
|
134
|
+
const alias = this.alias.extract();
|
|
135
|
+
if (!alias) {
|
|
136
|
+
return Maybe.empty();
|
|
137
|
+
}
|
|
138
|
+
const declarations = [];
|
|
139
|
+
if (this.configuration.features.has("Object.type")) {
|
|
140
|
+
declarations.push(code `export type ${def(alias)} = ${this.inlineExpression};`);
|
|
141
|
+
}
|
|
142
|
+
const staticModuleDeclarations = Object.entries(this.staticModuleDeclarations);
|
|
143
|
+
if (staticModuleDeclarations.length > 0) {
|
|
144
|
+
declarations.push(code `\
|
|
145
|
+
export namespace ${def(alias)} {
|
|
146
|
+
${joinCode(staticModuleDeclarations
|
|
147
|
+
.sort((left, right) => left[0].localeCompare(right[0]))
|
|
148
|
+
.map((_) => _[1]), { on: "\n\n" })}
|
|
149
|
+
}`);
|
|
150
|
+
}
|
|
151
|
+
return Maybe.of(joinCode(declarations, { on: "\n\n" }));
|
|
152
|
+
}
|
|
148
153
|
get discriminantProperty() {
|
|
149
154
|
switch (this.discriminant.kind) {
|
|
150
155
|
case "Extrinsic":
|
|
151
156
|
return Maybe.of({
|
|
152
157
|
descendantValues: [],
|
|
153
158
|
jsonName: this.discriminant.jsonName,
|
|
154
|
-
ownValues: this.discriminant.memberValues,
|
|
155
159
|
name: this.discriminant.name,
|
|
160
|
+
values: this.discriminant.memberValues,
|
|
156
161
|
});
|
|
157
162
|
case "Hybrid":
|
|
158
163
|
return Maybe.of({
|
|
159
|
-
descendantValues: [],
|
|
160
164
|
jsonName: this.discriminant.jsonName,
|
|
161
|
-
ownValues: this.discriminant.memberValues.flatMap((_) => _.ownValues),
|
|
162
165
|
name: "termType",
|
|
166
|
+
values: this.discriminant.memberValues.flatMap((_) => _.values),
|
|
163
167
|
});
|
|
164
168
|
case "Intrinsic":
|
|
165
169
|
return Maybe.of({
|
|
166
|
-
descendantValues: this.discriminant.memberValues.flatMap((_) => _.descendantValues),
|
|
167
170
|
jsonName: this.discriminant.jsonName,
|
|
168
171
|
name: this.discriminant.name,
|
|
169
|
-
|
|
172
|
+
values: this.discriminant.memberValues,
|
|
170
173
|
});
|
|
171
174
|
case "Typeof":
|
|
172
175
|
return Maybe.empty();
|
|
@@ -174,12 +177,60 @@ export class AbstractUnionType extends AbstractType {
|
|
|
174
177
|
throw this.discriminant;
|
|
175
178
|
}
|
|
176
179
|
}
|
|
180
|
+
get equalsFunction() {
|
|
181
|
+
return this.alias
|
|
182
|
+
.map((alias) => code `${alias}.equals`)
|
|
183
|
+
.orDefault(this.inlineEqualsFunction);
|
|
184
|
+
}
|
|
185
|
+
get filterFunction() {
|
|
186
|
+
return this.alias
|
|
187
|
+
.map((alias) => code `${alias}.filter`)
|
|
188
|
+
.orDefault(this.inlineFilterFunction);
|
|
189
|
+
}
|
|
190
|
+
get filterType() {
|
|
191
|
+
return this.alias
|
|
192
|
+
.map((alias) => code `${alias}.Filter`)
|
|
193
|
+
.orDefault(this.inlineFilterType);
|
|
194
|
+
}
|
|
195
|
+
get graphqlType() {
|
|
196
|
+
const alias = this.alias.extract();
|
|
197
|
+
if (!alias ||
|
|
198
|
+
!this.members.every((member) => member.type.kind === "Object")) {
|
|
199
|
+
throw new Error("not implemented");
|
|
200
|
+
}
|
|
201
|
+
return new AbstractType.GraphqlType(code `${alias}.GraphQL`, this.reusables);
|
|
202
|
+
}
|
|
203
|
+
get hashFunction() {
|
|
204
|
+
return this.alias
|
|
205
|
+
.map((alias) => code `${alias}.hash`)
|
|
206
|
+
.orDefault(this.inlineHashFunction);
|
|
207
|
+
}
|
|
208
|
+
get jsonSchemaFunctionDeclaration() {
|
|
209
|
+
const meta = {
|
|
210
|
+
// id: this.name,
|
|
211
|
+
};
|
|
212
|
+
this.comment.ifJust((description) => {
|
|
213
|
+
meta["description"] = description;
|
|
214
|
+
});
|
|
215
|
+
this.label.ifJust((label) => {
|
|
216
|
+
meta["title"] = label;
|
|
217
|
+
});
|
|
218
|
+
return code `export const schema = () => ${this.inlineJsonSchema}.meta(${meta});`;
|
|
219
|
+
}
|
|
220
|
+
get jsonTypeAliasDeclaration() {
|
|
221
|
+
return code `export type Json = ${this.inlineJsonType.expression}`;
|
|
222
|
+
}
|
|
177
223
|
get members() {
|
|
178
224
|
return this.lazyMembers();
|
|
179
225
|
}
|
|
180
226
|
get mutable() {
|
|
181
227
|
return this.members.some((member) => member.type.mutable);
|
|
182
228
|
}
|
|
229
|
+
get expression() {
|
|
230
|
+
return this.alias
|
|
231
|
+
.map((alias) => code `${alias}`)
|
|
232
|
+
.orDefault(this.inlineExpression);
|
|
233
|
+
}
|
|
183
234
|
get referencesObjectType() {
|
|
184
235
|
return this.members.some((member) => member.type.referencesObjectType);
|
|
185
236
|
}
|
|
@@ -201,14 +252,32 @@ export class AbstractUnionType extends AbstractType {
|
|
|
201
252
|
}
|
|
202
253
|
return set;
|
|
203
254
|
}
|
|
204
|
-
get
|
|
205
|
-
|
|
255
|
+
get jsTypes() {
|
|
256
|
+
const jsTypes = [];
|
|
257
|
+
for (const member of this.members) {
|
|
258
|
+
for (const memberJsType of member.type.jsTypes) {
|
|
259
|
+
if (!jsTypes.some((jsType) => AbstractType.JsType.equals(jsType, memberJsType))) {
|
|
260
|
+
jsTypes.push(memberJsType);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return jsTypes;
|
|
265
|
+
}
|
|
266
|
+
get valueSparqlConstructTriplesFunction() {
|
|
267
|
+
return this.alias
|
|
268
|
+
.map((alias) => code `${alias}.valueSparqlConstructTriples`)
|
|
269
|
+
.orDefault(this.inlineValueSparqlConstructTriplesFunction);
|
|
270
|
+
}
|
|
271
|
+
get valueSparqlWherePatternsFunction() {
|
|
272
|
+
return this.alias
|
|
273
|
+
.map((alias) => code `${alias}.valueSparqlWherePatterns`)
|
|
274
|
+
.orDefault(this.inlineValueSparqlWherePatternsFunction);
|
|
206
275
|
}
|
|
207
276
|
get inlineEqualsFunction() {
|
|
208
277
|
return code `\
|
|
209
|
-
((left: ${this.
|
|
278
|
+
((left: ${this.expression}, right: ${this.expression}) => {
|
|
210
279
|
${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeCheck(code `left`)} && ${typeCheck(code `right`)}) {
|
|
211
|
-
return ${type.equalsFunction}(${unwrap(code `left`)} as ${type.
|
|
280
|
+
return ${type.equalsFunction}(${unwrap(code `left`)} as ${type.expression}, ${unwrap(code `right`)} as ${type.expression});
|
|
212
281
|
}`))}
|
|
213
282
|
|
|
214
283
|
return ${this.reusables.imports.Left}({ left, right, propertyName: "type", propertyValuesUnequal: { left: typeof left, right: typeof right, type: "boolean" as const }, type: "property" as const });
|
|
@@ -217,7 +286,7 @@ ${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeChe
|
|
|
217
286
|
get inlineFilterFunction() {
|
|
218
287
|
const syntheticNamePrefix = this.configuration.syntheticNamePrefix;
|
|
219
288
|
return code `\
|
|
220
|
-
((filter: ${this.filterType}, value: ${this.
|
|
289
|
+
((filter: ${this.filterType}, value: ${this.expression}) => {
|
|
221
290
|
${joinCode([
|
|
222
291
|
...this.identifierType
|
|
223
292
|
.map((identifierType) => code `\
|
|
@@ -246,7 +315,7 @@ if (filter.on?.[${literalOf(primaryDiscriminantValue)}] !== undefined && ${typeC
|
|
|
246
315
|
}
|
|
247
316
|
get inlineFromJsonFunction() {
|
|
248
317
|
return code `\
|
|
249
|
-
((value: ${this.jsonType().
|
|
318
|
+
((value: ${this.jsonType().expression}): ${this.reusables.imports.Either}<Error, ${this.expression}> => {
|
|
250
319
|
${joinCode(this.members.map(({ jsonType, jsonTypeCheck, type, unwrap, wrap }) => code `if (${jsonTypeCheck(code `value`)}) { return ${type.fromJsonExpression({
|
|
251
320
|
variables: {
|
|
252
321
|
value: code `(${unwrap(code `value`)} as ${jsonType})`,
|
|
@@ -286,19 +355,19 @@ ${joinCode(this.members.map(({ jsonType, jsonTypeCheck, type, unwrap, wrap }) =>
|
|
|
286
355
|
if (this.discriminant.kind === "Extrinsic" ||
|
|
287
356
|
(this.discriminant.kind === "Hybrid" &&
|
|
288
357
|
this.discriminant.memberValues[memberI].kind === "Extrinsic")) {
|
|
289
|
-
typeExpression = code `${typeExpression}.map(values => values.map(value => ({ ${this.discriminant.name}: ${literalOf(primaryDiscriminantValue)} as const, value }) as (${this.
|
|
358
|
+
typeExpression = code `${typeExpression}.map(values => values.map(value => ({ ${this.discriminant.name}: ${literalOf(primaryDiscriminantValue)} as const, value }) as (${this.expression})))`;
|
|
290
359
|
}
|
|
291
|
-
typeExpression = code `(${typeExpression} as ${this.reusables.imports.Either}<Error, ${this.reusables.imports.Resource}.Values<${this.
|
|
360
|
+
typeExpression = code `(${typeExpression} as ${this.reusables.imports.Either}<Error, ${this.reusables.imports.Resource}.Values<${this.expression}>>)`;
|
|
292
361
|
return expression !== null
|
|
293
362
|
? code `${expression}.altLazy(() => ${typeExpression})`
|
|
294
363
|
: typeExpression;
|
|
295
364
|
}, null)}.chain(values => values.head());
|
|
296
365
|
}))
|
|
297
|
-
) satisfies ${this.reusables.snippets.FromRdfResourceValuesFunction}<${this.
|
|
366
|
+
) satisfies ${this.reusables.snippets.FromRdfResourceValuesFunction}<${this.expression}>)`;
|
|
298
367
|
}
|
|
299
368
|
get inlineHashFunction() {
|
|
300
369
|
return code `\
|
|
301
|
-
(<HasherT extends ${this.reusables.snippets.Hasher}>(hasher: HasherT, value: ${this.
|
|
370
|
+
(<HasherT extends ${this.reusables.snippets.Hasher}>(hasher: HasherT, value: ${this.expression}): HasherT => {
|
|
302
371
|
${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeCheck(code `value`)}) { return ${type.hashFunction}(hasher, ${unwrap(code `value`)}); }`))}
|
|
303
372
|
return hasher;
|
|
304
373
|
})`;
|
|
@@ -356,30 +425,30 @@ ${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeChe
|
|
|
356
425
|
throw discriminant;
|
|
357
426
|
}
|
|
358
427
|
}
|
|
359
|
-
get
|
|
428
|
+
get inlineExpression() {
|
|
360
429
|
const discriminant = this.discriminant; // To get type narrowing to work
|
|
361
430
|
switch (discriminant.kind) {
|
|
362
431
|
case "Extrinsic":
|
|
363
|
-
return code `(${joinCode(this.members.map(({ type, primaryDiscriminantValue }) => code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${type.
|
|
432
|
+
return code `(${joinCode(this.members.map(({ type, primaryDiscriminantValue }) => code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${type.expression} }`), { on: "|" })})`;
|
|
364
433
|
case "Hybrid":
|
|
365
434
|
return code `(${joinCode(this.members.map(({ primaryDiscriminantValue, type }, memberI) => {
|
|
366
435
|
switch (discriminant.memberValues[memberI].kind) {
|
|
367
436
|
case "Extrinsic":
|
|
368
|
-
return code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${type.
|
|
437
|
+
return code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${type.expression} }`;
|
|
369
438
|
case "Intrinsic":
|
|
370
|
-
return code `${type.
|
|
439
|
+
return code `${type.expression}`;
|
|
371
440
|
default:
|
|
372
441
|
throw new Error();
|
|
373
442
|
}
|
|
374
443
|
}), { on: "|" })})`;
|
|
375
444
|
case "Intrinsic":
|
|
376
|
-
// If every type shares a discriminant (e.g., RDF/JS "termType" or generated
|
|
445
|
+
// If every type shares a discriminant (e.g., RDF/JS "termType" or generated ObjectType "type"),
|
|
377
446
|
// just join their names with "|"
|
|
378
|
-
return code `(${joinCode(this.members.map(({ type }) => code `${type.
|
|
447
|
+
return code `(${joinCode(this.members.map(({ type }) => code `${type.expression}`), { on: "|" })})`;
|
|
379
448
|
case "Typeof":
|
|
380
449
|
// The type.name may include literal values, but they should still be unambiguous with other member types since the typeofs
|
|
381
450
|
// of the different member types are known to be different.
|
|
382
|
-
return code `(${joinCode(this.members.map(({ type }) => code `${type.
|
|
451
|
+
return code `(${joinCode(this.members.map(({ type }) => code `${type.expression}`), { on: "|" })})`;
|
|
383
452
|
default:
|
|
384
453
|
discriminant;
|
|
385
454
|
throw new Error("should never reach this point");
|
|
@@ -387,7 +456,7 @@ ${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeChe
|
|
|
387
456
|
}
|
|
388
457
|
get inlineToJsonFunction() {
|
|
389
458
|
return code `\
|
|
390
|
-
((value: ${this.
|
|
459
|
+
((value: ${this.expression}): ${this.jsonType().expression} => {
|
|
391
460
|
${joinCode(this.members.map(({ typeCheck, typeToJsonExpression, unwrap, wrap }) => code `if (${typeCheck(code `value`)}) { return ${wrap(typeToJsonExpression(unwrap(code `value`)))}; }`))}
|
|
392
461
|
|
|
393
462
|
throw new Error("unable to serialize to JSON");
|
|
@@ -419,11 +488,11 @@ ${joinCode(this.members.map(({ type, unwrap, typeCheck }) => code `if (${typeChe
|
|
|
419
488
|
})}; }`))}
|
|
420
489
|
|
|
421
490
|
throw new Error("unable to serialize to RDF");
|
|
422
|
-
}) satisfies ${this.reusables.snippets.ToRdfResourceValuesFunction}<${this.
|
|
491
|
+
}) satisfies ${this.reusables.snippets.ToRdfResourceValuesFunction}<${this.expression}>)`;
|
|
423
492
|
}
|
|
424
493
|
get inlineToStringFunction() {
|
|
425
494
|
return code `\
|
|
426
|
-
((value: ${this.
|
|
495
|
+
((value: ${this.expression}): string => {
|
|
427
496
|
${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeCheck(code `value`)}) { return ${type.toStringExpression({
|
|
428
497
|
variables: { value: unwrap(code `value`) },
|
|
429
498
|
})}; }`))}
|
|
@@ -459,50 +528,180 @@ unionPatterns.push({ patterns: ${type.valueSparqlWherePatternsFunction}({ ...oth
|
|
|
459
528
|
type: type.schema,
|
|
460
529
|
}}`), { on: "," })} }`);
|
|
461
530
|
}
|
|
531
|
+
get staticModuleDeclarations() {
|
|
532
|
+
const alias = this.alias.unsafeCoerce();
|
|
533
|
+
const staticModuleDeclarations = {};
|
|
534
|
+
if (this.configuration.features.has("Object.equals")) {
|
|
535
|
+
staticModuleDeclarations[`equals`] =
|
|
536
|
+
code `export const equals = ${this.inlineEqualsFunction};`;
|
|
537
|
+
}
|
|
538
|
+
if (this.configuration.features.has("Object.filter")) {
|
|
539
|
+
staticModuleDeclarations[`Filter`] =
|
|
540
|
+
code `export type Filter = ${this.inlineFilterType};`;
|
|
541
|
+
staticModuleDeclarations[`filter`] =
|
|
542
|
+
code `export const filter = ${this.inlineFilterFunction};`;
|
|
543
|
+
}
|
|
544
|
+
if (this.configuration.features.has("Object.hash")) {
|
|
545
|
+
staticModuleDeclarations[`hash`] =
|
|
546
|
+
code `export const hash = ${this.inlineHashFunction};`;
|
|
547
|
+
}
|
|
548
|
+
if (this.configuration.features.has("Object.JSON.type")) {
|
|
549
|
+
staticModuleDeclarations[`Json.type`] =
|
|
550
|
+
code `${this.jsonTypeAliasDeclaration}`;
|
|
551
|
+
}
|
|
552
|
+
if (this.configuration.features.has("Object.JSON.schema")) {
|
|
553
|
+
staticModuleDeclarations[`Json.namespace`] = code `\
|
|
554
|
+
export namespace Json {
|
|
555
|
+
${this.jsonSchemaFunctionDeclaration}
|
|
556
|
+
|
|
557
|
+
export function parse(json: unknown): ${this.reusables.imports.Either}<Error, Json> {
|
|
558
|
+
const jsonSafeParseResult = schema().safeParse(json);
|
|
559
|
+
if (!jsonSafeParseResult.success) { return ${this.reusables.imports.Left}(jsonSafeParseResult.error); }
|
|
560
|
+
return ${this.reusables.imports.Right}(jsonSafeParseResult.data);
|
|
561
|
+
}
|
|
562
|
+
}`;
|
|
563
|
+
}
|
|
564
|
+
if (this.configuration.features.has("Object.fromJson")) {
|
|
565
|
+
staticModuleDeclarations[`fromJson`] =
|
|
566
|
+
code `export const fromJson = ${this.inlineFromJsonFunction};`;
|
|
567
|
+
}
|
|
568
|
+
if (this.configuration.features.has("Object.fromRdf")) {
|
|
569
|
+
staticModuleDeclarations[`fromRdfResourceValues`] =
|
|
570
|
+
code `export const fromRdfResourceValues: ${this.reusables.snippets.FromRdfResourceValuesFunction}<${alias}> = ${this.inlineFromRdfResourceValuesFunction};`;
|
|
571
|
+
}
|
|
572
|
+
if (this.configuration.features.has("Object.toJson")) {
|
|
573
|
+
staticModuleDeclarations[`toJson`] =
|
|
574
|
+
code `export const toJson = ${this.inlineToJsonFunction};`;
|
|
575
|
+
}
|
|
576
|
+
if (this.configuration.features.has("Object.toRdf")) {
|
|
577
|
+
staticModuleDeclarations[`toRdfResourceValues`] =
|
|
578
|
+
code `export const toRdfResourceValues = ${this.inlineToRdfResourceValuesFunction};`;
|
|
579
|
+
}
|
|
580
|
+
if (this.configuration.features.has("Object.SPARQL")) {
|
|
581
|
+
staticModuleDeclarations[`valueSparqlConstructTriples`] =
|
|
582
|
+
code `export const valueSparqlConstructTriples: ${this.reusables.snippets.ValueSparqlConstructTriplesFunction}<${this.filterType}, ${this.schemaType}> = ${this.inlineValueSparqlConstructTriplesFunction};`;
|
|
583
|
+
staticModuleDeclarations[`valueSparqlWherePatterns`] =
|
|
584
|
+
code `export const valueSparqlWherePatterns: ${this.reusables.snippets.ValueSparqlWherePatternsFunction}<${this.filterType}, ${this.schemaType}> = ${this.inlineValueSparqlWherePatternsFunction};`;
|
|
585
|
+
}
|
|
586
|
+
if (this.configuration.features.has("Object.toString")) {
|
|
587
|
+
const syntheticNamePrefix = this.configuration.syntheticNamePrefix;
|
|
588
|
+
staticModuleDeclarations[`${syntheticNamePrefix}toString`] =
|
|
589
|
+
code `export const ${syntheticNamePrefix}toString = ${this.inlineToStringFunction};`;
|
|
590
|
+
}
|
|
591
|
+
return staticModuleDeclarations;
|
|
592
|
+
}
|
|
593
|
+
fromJsonExpression({ variables, }) {
|
|
594
|
+
return code `${this.alias.map((alias) => code `${alias}.fromJson`).orDefault(this.inlineFromJsonFunction)}(${variables.value})`;
|
|
595
|
+
}
|
|
596
|
+
fromRdfResourceValuesExpression({ variables, }) {
|
|
597
|
+
const { resourceValues: resourceValuesVariable, ...fromRdfResourceValuesOptionsTemp } = variables;
|
|
598
|
+
const fromRdfResourceValuesOptions = fromRdfResourceValuesOptionsTemp;
|
|
599
|
+
if (!this.configuration.features.has("ObjectSet")) {
|
|
600
|
+
delete fromRdfResourceValuesOptions["objectSet"];
|
|
601
|
+
}
|
|
602
|
+
return code `${this.alias.map((alias) => code `${alias}.fromRdfResourceValues`).orDefault(this.inlineFromRdfResourceValuesFunction)}(${resourceValuesVariable}, ${fromRdfResourceValuesOptions})`;
|
|
603
|
+
}
|
|
604
|
+
graphqlResolveExpression({ variables, }) {
|
|
605
|
+
return variables.value;
|
|
606
|
+
}
|
|
607
|
+
jsonSchema({ context, }) {
|
|
608
|
+
const expression = this.alias
|
|
609
|
+
.map((alias) => code `${alias}.Json.schema()`)
|
|
610
|
+
.orDefault(this.inlineJsonSchema);
|
|
611
|
+
if (context === "property" && this.recursive) {
|
|
612
|
+
return code `${this.reusables.imports.z}.lazy((): ${this.reusables.imports.z}.ZodType<${this.jsonType().expression}> => ${expression})`;
|
|
613
|
+
}
|
|
614
|
+
return expression;
|
|
615
|
+
}
|
|
616
|
+
jsonType() {
|
|
617
|
+
return this.alias
|
|
618
|
+
.map((alias) => new AbstractType.JsonType(code `${alias}.Json`))
|
|
619
|
+
.orDefault(this.inlineJsonType);
|
|
620
|
+
}
|
|
462
621
|
jsonUiSchemaElement() {
|
|
463
622
|
return Maybe.empty();
|
|
464
623
|
}
|
|
624
|
+
toJsonExpression({ variables, }) {
|
|
625
|
+
return code `${this.alias.map((alias) => code `${alias}.toJson`).orDefault(this.inlineToJsonFunction)}(${variables.value})`;
|
|
626
|
+
}
|
|
627
|
+
toRdfResourceValuesExpression({ variables, }) {
|
|
628
|
+
const { value: valueVariable, ...otherVariables } = variables;
|
|
629
|
+
return code `${this.alias.map((alias) => code `${alias}.toRdfResourceValues`).orDefault(this.inlineToRdfResourceValuesFunction)}(${valueVariable}, ${otherVariables})`;
|
|
630
|
+
}
|
|
631
|
+
toStringExpression({ variables, }) {
|
|
632
|
+
return code `${this.alias.map((alias) => code `${alias}.${this.configuration.syntheticNamePrefix}toString`).orDefault(this.inlineToStringFunction)}(${variables.value})`;
|
|
633
|
+
}
|
|
465
634
|
lazyMembers;
|
|
466
635
|
}
|
|
467
636
|
__decorate([
|
|
468
637
|
Memoize()
|
|
469
|
-
],
|
|
638
|
+
], UnionType.prototype, "conversionFunction", null);
|
|
639
|
+
__decorate([
|
|
640
|
+
Memoize()
|
|
641
|
+
], UnionType.prototype, "declaration", null);
|
|
642
|
+
__decorate([
|
|
643
|
+
Memoize()
|
|
644
|
+
], UnionType.prototype, "discriminantProperty", null);
|
|
645
|
+
__decorate([
|
|
646
|
+
Memoize()
|
|
647
|
+
], UnionType.prototype, "equalsFunction", null);
|
|
648
|
+
__decorate([
|
|
649
|
+
Memoize()
|
|
650
|
+
], UnionType.prototype, "filterFunction", null);
|
|
651
|
+
__decorate([
|
|
652
|
+
Memoize()
|
|
653
|
+
], UnionType.prototype, "filterType", null);
|
|
654
|
+
__decorate([
|
|
655
|
+
Memoize()
|
|
656
|
+
], UnionType.prototype, "graphqlType", null);
|
|
657
|
+
__decorate([
|
|
658
|
+
Memoize()
|
|
659
|
+
], UnionType.prototype, "hashFunction", null);
|
|
470
660
|
__decorate([
|
|
471
661
|
Memoize()
|
|
472
|
-
],
|
|
662
|
+
], UnionType.prototype, "members", null);
|
|
473
663
|
__decorate([
|
|
474
664
|
Memoize()
|
|
475
|
-
],
|
|
665
|
+
], UnionType.prototype, "mutable", null);
|
|
476
666
|
__decorate([
|
|
477
667
|
Memoize()
|
|
478
|
-
],
|
|
668
|
+
], UnionType.prototype, "expression", null);
|
|
479
669
|
__decorate([
|
|
480
670
|
Memoize()
|
|
481
|
-
],
|
|
671
|
+
], UnionType.prototype, "toRdfResourceValueTypes", null);
|
|
482
672
|
__decorate([
|
|
483
673
|
Memoize()
|
|
484
|
-
],
|
|
674
|
+
], UnionType.prototype, "jsTypes", null);
|
|
485
675
|
__decorate([
|
|
486
676
|
Memoize()
|
|
487
|
-
],
|
|
677
|
+
], UnionType.prototype, "valueSparqlConstructTriplesFunction", null);
|
|
488
678
|
__decorate([
|
|
489
679
|
Memoize()
|
|
490
|
-
],
|
|
680
|
+
], UnionType.prototype, "valueSparqlWherePatternsFunction", null);
|
|
491
681
|
__decorate([
|
|
492
682
|
Memoize()
|
|
493
|
-
],
|
|
683
|
+
], UnionType.prototype, "inlineEqualsFunction", null);
|
|
494
684
|
__decorate([
|
|
495
685
|
Memoize()
|
|
496
|
-
],
|
|
686
|
+
], UnionType.prototype, "inlineFilterFunction", null);
|
|
497
687
|
__decorate([
|
|
498
688
|
Memoize()
|
|
499
|
-
],
|
|
689
|
+
], UnionType.prototype, "inlineFilterType", null);
|
|
500
690
|
__decorate([
|
|
501
691
|
Memoize()
|
|
502
|
-
],
|
|
692
|
+
], UnionType.prototype, "inlineJsonType", null);
|
|
503
693
|
__decorate([
|
|
504
694
|
Memoize()
|
|
505
|
-
],
|
|
695
|
+
], UnionType.prototype, "inlineExpression", null);
|
|
696
|
+
__decorate([
|
|
697
|
+
Memoize()
|
|
698
|
+
], UnionType.prototype, "inlineValueSparqlConstructTriplesFunction", null);
|
|
699
|
+
__decorate([
|
|
700
|
+
Memoize()
|
|
701
|
+
], UnionType.prototype, "inlineValueSparqlWherePatternsFunction", null);
|
|
702
|
+
__decorate([
|
|
703
|
+
Memoize()
|
|
704
|
+
], UnionType.prototype, "jsonType", null);
|
|
506
705
|
function termTypes(type) {
|
|
507
706
|
switch (type.kind) {
|
|
508
707
|
case "BlankNode":
|
|
@@ -532,7 +731,7 @@ export var Discriminant;
|
|
|
532
731
|
// intrinsic
|
|
533
732
|
{
|
|
534
733
|
let inlineDiscriminantProperty;
|
|
535
|
-
|
|
734
|
+
let memberValues = [];
|
|
536
735
|
for (const memberType of memberTypes) {
|
|
537
736
|
const memberTypeDiscriminantProperty = memberType.discriminantProperty.extract();
|
|
538
737
|
if (!memberTypeDiscriminantProperty) {
|
|
@@ -547,10 +746,7 @@ export var Discriminant;
|
|
|
547
746
|
inlineDiscriminantProperty = undefined;
|
|
548
747
|
break;
|
|
549
748
|
}
|
|
550
|
-
memberValues.
|
|
551
|
-
descendantValues: memberTypeDiscriminantProperty.descendantValues,
|
|
552
|
-
ownValues: memberTypeDiscriminantProperty.ownValues,
|
|
553
|
-
});
|
|
749
|
+
memberValues = memberValues.concat(memberTypeDiscriminantProperty.values);
|
|
554
750
|
}
|
|
555
751
|
if (inlineDiscriminantProperty) {
|
|
556
752
|
return {
|
|
@@ -563,15 +759,17 @@ export var Discriminant;
|
|
|
563
759
|
}
|
|
564
760
|
// typeof
|
|
565
761
|
{
|
|
762
|
+
const memberTypeofs = [];
|
|
566
763
|
const memberTypeofsSet = new Set();
|
|
567
764
|
for (const memberType of memberTypes) {
|
|
568
|
-
for (const
|
|
569
|
-
|
|
765
|
+
for (const memberJsType of memberType.jsTypes) {
|
|
766
|
+
memberTypeofs.push(memberJsType.typeof);
|
|
767
|
+
memberTypeofsSet.add(memberJsType.typeof);
|
|
570
768
|
}
|
|
571
769
|
}
|
|
572
770
|
if (memberTypeofsSet.size === memberTypes.length) {
|
|
573
771
|
return {
|
|
574
|
-
memberValues:
|
|
772
|
+
memberValues: memberTypeofs,
|
|
575
773
|
kind: "Typeof",
|
|
576
774
|
};
|
|
577
775
|
}
|
|
@@ -579,15 +777,15 @@ export var Discriminant;
|
|
|
579
777
|
// hybrid
|
|
580
778
|
// If some member type is an RDF/JS term then reuse "termType" as the discriminant.
|
|
581
779
|
if (memberTypes.some((memberType) => termTypes(memberType).size > 0)) {
|
|
582
|
-
const
|
|
780
|
+
const extrinsicMemberTypeAliasesSet = new Set();
|
|
583
781
|
let extrinsicMemberTypeCount = 0;
|
|
584
782
|
for (const memberType of memberTypes) {
|
|
585
783
|
if (termTypes(memberType).size > 0) {
|
|
586
784
|
continue;
|
|
587
785
|
}
|
|
588
786
|
extrinsicMemberTypeCount++;
|
|
589
|
-
if (
|
|
590
|
-
|
|
787
|
+
if (memberType.alias.isJust()) {
|
|
788
|
+
extrinsicMemberTypeAliasesSet.add(memberType.alias.extract());
|
|
591
789
|
}
|
|
592
790
|
else {
|
|
593
791
|
break;
|
|
@@ -601,13 +799,13 @@ export var Discriminant;
|
|
|
601
799
|
if (memberTermTypes.size > 0) {
|
|
602
800
|
return {
|
|
603
801
|
kind: "Intrinsic",
|
|
604
|
-
|
|
802
|
+
values: [...memberTermTypes],
|
|
605
803
|
};
|
|
606
804
|
}
|
|
607
805
|
return {
|
|
608
806
|
kind: "Extrinsic",
|
|
609
|
-
|
|
610
|
-
? [memberType.
|
|
807
|
+
values: extrinsicMemberTypeAliasesSet.size === extrinsicMemberTypeCount
|
|
808
|
+
? [memberType.alias.unsafeCoerce()]
|
|
611
809
|
: [memberTypeI.toString()],
|
|
612
810
|
};
|
|
613
811
|
}),
|
|
@@ -618,21 +816,14 @@ export var Discriminant;
|
|
|
618
816
|
{
|
|
619
817
|
let memberValues;
|
|
620
818
|
{
|
|
621
|
-
const memberTypeNames = memberTypes.map((memberType) => memberType.
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
memberValues = memberTypeNames;
|
|
626
|
-
}
|
|
627
|
-
else {
|
|
628
|
-
// Otherwise prefix the non-unique strings with an index and use those as the discriminant values.
|
|
629
|
-
memberValues = memberTypeNames.map((memberTypeName, memberTypeI) => `${memberTypeI}-${memberTypeName}`);
|
|
630
|
-
}
|
|
819
|
+
const memberTypeNames = memberTypes.map((memberType) => memberType.alias.orDefault(memberType.jsTypes[0].typeof));
|
|
820
|
+
const memberTypeNamesSet = new Set(memberTypeNames);
|
|
821
|
+
if (memberTypeNamesSet.size === memberTypeNames.length) {
|
|
822
|
+
memberValues = memberTypeNames;
|
|
631
823
|
}
|
|
632
824
|
else {
|
|
633
|
-
//
|
|
634
|
-
|
|
635
|
-
memberValues = memberTypes.map((_, memberTypeI) => memberTypeI);
|
|
825
|
+
// Otherwise prefix the non-unique strings with an index and use those as the discriminant values.
|
|
826
|
+
memberValues = memberTypeNames.map((memberTypeName, memberTypeI) => `${memberTypeI}-${memberTypeName}`);
|
|
636
827
|
}
|
|
637
828
|
}
|
|
638
829
|
invariant(memberValues.length === memberTypes.length);
|
|
@@ -640,10 +831,10 @@ export var Discriminant;
|
|
|
640
831
|
jsonName: "type",
|
|
641
832
|
kind: "Extrinsic",
|
|
642
833
|
name: "type",
|
|
643
|
-
memberValues
|
|
834
|
+
memberValues,
|
|
644
835
|
};
|
|
645
836
|
}
|
|
646
837
|
}
|
|
647
838
|
Discriminant.infer = infer;
|
|
648
839
|
})(Discriminant || (Discriminant = {}));
|
|
649
|
-
//# sourceMappingURL=
|
|
840
|
+
//# sourceMappingURL=UnionType.js.map
|