@shaclmate/compiler 2.0.13 → 2.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Compiler.d.ts +15 -0
- package/Compiler.js +20 -0
- package/ShapesGraphToAstTransformer.d.ts +18 -23
- package/ShapesGraphToAstTransformer.js +21 -447
- package/_ShapesGraphToAstTransformer/NodeShapeAstType.d.ts +3 -0
- package/_ShapesGraphToAstTransformer/NodeShapeAstType.js +2 -0
- package/_ShapesGraphToAstTransformer/index.d.ts +10 -0
- package/_ShapesGraphToAstTransformer/index.js +10 -0
- package/_ShapesGraphToAstTransformer/pickLiteral.d.ts +4 -0
- package/_ShapesGraphToAstTransformer/pickLiteral.js +18 -0
- package/_ShapesGraphToAstTransformer/propertyShapeNodeKinds.d.ts +4 -0
- package/_ShapesGraphToAstTransformer/propertyShapeNodeKinds.js +26 -0
- package/_ShapesGraphToAstTransformer/shapeAstName.d.ts +5 -0
- package/_ShapesGraphToAstTransformer/shapeAstName.js +28 -0
- package/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.d.ts +6 -0
- package/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.js +165 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.d.ts +13 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +198 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.d.ts +12 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.js +29 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.d.ts +12 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.js +43 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.d.ts +6 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +31 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.d.ts +14 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.js +21 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.d.ts +16 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.js +58 -0
- package/ast/Ast.d.ts +5 -0
- package/ast/CompositeType.d.ts +13 -0
- package/ast/CompositeType.js +2 -0
- package/ast/IdentifierType.d.ts +3 -6
- package/ast/IntersectionType.d.ts +2 -2
- package/ast/ListType.d.ts +53 -0
- package/ast/ListType.js +2 -0
- package/ast/LiteralType.d.ts +4 -3
- package/ast/Name.d.ts +1 -0
- package/ast/ObjectCompositeType.d.ts +22 -0
- package/ast/ObjectCompositeType.js +2 -0
- package/ast/ObjectIntersectionType.d.ts +8 -0
- package/ast/ObjectIntersectionType.js +2 -0
- package/ast/ObjectType.d.ts +91 -19
- package/ast/ObjectType.js +26 -1
- package/ast/ObjectUnionType.d.ts +19 -0
- package/ast/ObjectUnionType.js +2 -0
- package/ast/PlaceholderType.d.ts +7 -0
- package/ast/PlaceholderType.js +2 -0
- package/ast/SetType.d.ts +1 -1
- package/ast/TermType.d.ts +11 -0
- package/ast/TermType.js +2 -0
- package/ast/Type.d.ts +11 -3
- package/ast/UnionType.d.ts +3 -3
- package/ast/index.d.ts +6 -3
- package/ast/index.js +6 -3
- package/enums/MintingStrategy.d.ts +5 -0
- package/enums/MintingStrategy.js +2 -0
- package/enums/PropertyVisibility.d.ts +2 -0
- package/enums/PropertyVisibility.js +2 -0
- package/enums/TsFeature.d.ts +5 -0
- package/enums/TsFeature.js +16 -0
- package/enums/TsObjectDeclarationType.d.ts +5 -0
- package/enums/TsObjectDeclarationType.js +2 -0
- package/enums/index.d.ts +5 -0
- package/enums/index.js +5 -0
- package/generators/Generator.d.ts +5 -0
- package/generators/Generator.js +2 -0
- package/generators/index.d.ts +2 -2
- package/generators/index.js +2 -2
- package/generators/json/AstJsonGenerator.d.ts +4 -5
- package/generators/json/AstJsonGenerator.js +31 -22
- package/generators/ts/BooleanType.d.ts +7 -3
- package/generators/ts/BooleanType.js +58 -4
- package/generators/ts/DateTimeType.d.ts +17 -0
- package/generators/ts/DateTimeType.js +58 -0
- package/generators/ts/DeclaredType.d.ts +17 -0
- package/generators/ts/DeclaredType.js +10 -0
- package/generators/ts/IdentifierType.d.ts +7 -17
- package/generators/ts/IdentifierType.js +69 -60
- package/generators/ts/Import.d.ts +18 -0
- package/generators/ts/Import.js +59 -0
- package/generators/ts/ListType.d.ts +18 -8
- package/generators/ts/ListType.js +197 -43
- package/generators/ts/LiteralType.d.ts +13 -11
- package/generators/ts/LiteralType.js +36 -51
- package/generators/ts/NumberType.d.ts +7 -3
- package/generators/ts/NumberType.js +55 -4
- package/generators/ts/ObjectType.d.ts +47 -25
- package/generators/ts/ObjectType.js +222 -49
- package/generators/ts/ObjectUnionType.d.ts +58 -0
- package/generators/ts/ObjectUnionType.js +481 -0
- package/generators/ts/OptionType.d.ts +12 -4
- package/generators/ts/OptionType.js +65 -16
- package/generators/ts/PrimitiveType.d.ts +15 -5
- package/generators/ts/PrimitiveType.js +20 -29
- package/generators/ts/SetType.d.ts +12 -4
- package/generators/ts/SetType.js +103 -29
- package/generators/ts/StringType.d.ts +8 -3
- package/generators/ts/StringType.js +57 -3
- package/generators/ts/TermType.d.ts +52 -0
- package/generators/ts/TermType.js +234 -0
- package/generators/ts/TsGenerator.d.ts +4 -12
- package/generators/ts/TsGenerator.js +44 -100
- package/generators/ts/Type.d.ts +107 -46
- package/generators/ts/Type.js +78 -61
- package/generators/ts/TypeFactory.d.ts +4 -5
- package/generators/ts/TypeFactory.js +212 -89
- package/generators/ts/UnionType.d.ts +19 -6
- package/generators/ts/UnionType.js +230 -120
- package/generators/ts/_ObjectType/IdentifierProperty.d.ts +27 -7
- package/generators/ts/_ObjectType/IdentifierProperty.js +143 -31
- package/generators/ts/_ObjectType/Property.d.ts +125 -9
- package/generators/ts/_ObjectType/Property.js +25 -3
- package/generators/ts/_ObjectType/ShaclProperty.d.ts +23 -5
- package/generators/ts/_ObjectType/ShaclProperty.js +100 -26
- package/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +24 -6
- package/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +75 -13
- package/generators/ts/_ObjectType/classDeclaration.d.ts +2 -1
- package/generators/ts/_ObjectType/classDeclaration.js +79 -111
- package/generators/ts/_ObjectType/createFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/createFunctionDeclaration.js +60 -0
- package/generators/ts/_ObjectType/equalsFunctionDeclaration.d.ts +2 -1
- package/generators/ts/_ObjectType/equalsFunctionDeclaration.js +12 -20
- package/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.d.ts +11 -0
- package/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.js +70 -0
- package/generators/ts/_ObjectType/fromJsonFunctionDeclarations.d.ts +4 -0
- package/generators/ts/_ObjectType/fromJsonFunctionDeclarations.js +78 -0
- package/generators/ts/_ObjectType/fromRdfFunctionDeclarations.d.ts +4 -0
- package/generators/ts/_ObjectType/fromRdfFunctionDeclarations.js +91 -0
- package/generators/ts/_ObjectType/hashFunctionDeclaration.d.ts +3 -3
- package/generators/ts/_ObjectType/hashFunctionDeclaration.js +11 -55
- package/generators/ts/_ObjectType/hashFunctionOrMethodDeclaration.d.ts +11 -0
- package/generators/ts/_ObjectType/hashFunctionOrMethodDeclaration.js +64 -0
- package/generators/ts/_ObjectType/index.d.ts +8 -2
- package/generators/ts/_ObjectType/index.js +8 -2
- package/generators/ts/_ObjectType/interfaceDeclaration.d.ts +3 -2
- package/generators/ts/_ObjectType/interfaceDeclaration.js +11 -2
- package/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.js +19 -0
- package/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.js +31 -0
- package/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.js +37 -0
- package/generators/ts/_ObjectType/rdfjsTermExpression.d.ts +6 -0
- package/generators/ts/{rdfjsTermExpression.js → _ObjectType/rdfjsTermExpression.js} +3 -1
- package/generators/ts/_ObjectType/sparqlFunctionDeclarations.d.ts +4 -0
- package/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +101 -0
- package/generators/ts/_ObjectType/toJsonFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/toJsonFunctionDeclaration.js +19 -0
- package/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.d.ts +10 -0
- package/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.js +59 -0
- package/generators/ts/_ObjectType/toJsonReturnType.d.ts +3 -0
- package/generators/ts/_ObjectType/toJsonReturnType.js +19 -0
- package/generators/ts/_ObjectType/toRdfFunctionDeclaration.d.ts +3 -2
- package/generators/ts/_ObjectType/toRdfFunctionDeclaration.js +11 -45
- package/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.d.ts +10 -0
- package/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.js +67 -0
- package/generators/ts/objectInitializer.d.ts +2 -0
- package/generators/ts/objectInitializer.js +14 -0
- package/generators/ts/tsComment.d.ts +5 -0
- package/generators/ts/tsComment.js +11 -0
- package/generators/ts/tsName.d.ts +1 -1
- package/generators/ts/tsName.js +1 -0
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/input/NodeShape.d.ts +46 -0
- package/input/NodeShape.js +165 -0
- package/input/Ontology.d.ts +13 -0
- package/input/Ontology.js +30 -0
- package/input/PropertyShape.d.ts +15 -0
- package/input/PropertyShape.js +34 -0
- package/input/Shape.d.ts +4 -0
- package/input/Shape.js +2 -0
- package/input/ShapesGraph.d.ts +9 -0
- package/input/ShapesGraph.js +50 -0
- package/input/ancestorClassIris.d.ts +4 -0
- package/input/ancestorClassIris.js +21 -0
- package/input/descendantClassIris.d.ts +4 -0
- package/input/descendantClassIris.js +21 -0
- package/input/generated.d.ts +274 -0
- package/input/generated.js +1420 -0
- package/input/index.d.ts +7 -0
- package/input/index.js +7 -0
- package/input/tsFeatures.d.ts +10 -0
- package/input/tsFeatures.js +42 -0
- package/package.json +14 -8
- package/ast/MintingStrategy.d.ts +0 -8
- package/ast/MintingStrategy.js +0 -9
- package/generators/ts/Configuration.d.ts +0 -29
- package/generators/ts/Configuration.js +0 -40
- package/generators/ts/IntersectionType.d.ts +0 -14
- package/generators/ts/IntersectionType.js +0 -26
- package/generators/ts/RdfjsTermType.d.ts +0 -25
- package/generators/ts/RdfjsTermType.js +0 -46
- package/generators/ts/_ObjectType/fromRdfFunctionDeclaration.d.ts +0 -4
- package/generators/ts/_ObjectType/fromRdfFunctionDeclaration.js +0 -72
- package/generators/ts/_ObjectType/sparqlGraphPatternsClassDeclaration.d.ts +0 -4
- package/generators/ts/_ObjectType/sparqlGraphPatternsClassDeclaration.js +0 -46
- package/generators/ts/rdfjsTermExpression.d.ts +0 -5
- package/vocabularies/dashDataset.d.ts +0 -3
- package/vocabularies/dashDataset.js +0 -2370
- package/vocabularies/index.d.ts +0 -2
- package/vocabularies/index.js +0 -2
- package/vocabularies/shaclmate.d.ts +0 -15
- package/vocabularies/shaclmate.js +0 -6
|
@@ -8,152 +8,259 @@ import { Maybe } from "purify-ts";
|
|
|
8
8
|
import { invariant } from "ts-invariant";
|
|
9
9
|
import { Memoize } from "typescript-memoize";
|
|
10
10
|
import { Type } from "./Type.js";
|
|
11
|
-
|
|
12
|
-
function syntheticTypeDiscriminatorValue({ type, typeIndex, }) {
|
|
13
|
-
return `${typeIndex}-${type.name}`;
|
|
14
|
-
}
|
|
11
|
+
import { objectInitializer } from "./objectInitializer.js";
|
|
15
12
|
export class UnionType extends Type {
|
|
16
|
-
constructor({ memberTypes, ...superParameters }) {
|
|
13
|
+
constructor({ memberTypes, name, ...superParameters }) {
|
|
17
14
|
super(superParameters);
|
|
18
15
|
this.kind = "UnionType";
|
|
19
16
|
invariant(memberTypes.length >= 2);
|
|
20
17
|
this.memberTypes = memberTypes;
|
|
18
|
+
this._name = name;
|
|
19
|
+
}
|
|
20
|
+
get name() {
|
|
21
|
+
if (typeof this._name === "undefined") {
|
|
22
|
+
switch (this._discriminatorProperty.kind) {
|
|
23
|
+
case "shared":
|
|
24
|
+
// If every type shares a discriminator (e.g., RDF/JS "termType" or generated ObjectType "type"),
|
|
25
|
+
// just join their names with "|"
|
|
26
|
+
this._name = `(${this.memberTypes.map((memberType) => memberType.name).join(" | ")})`;
|
|
27
|
+
break;
|
|
28
|
+
case "synthetic":
|
|
29
|
+
this._name = `(${this.memberTypeTraits.map((memberTypeTraits) => `{ ${this._discriminatorProperty.name}: "${memberTypeTraits.discriminatorPropertyValues[0]}", value: ${memberTypeTraits.memberType.name} }`).join(" | ")})`;
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return this._name;
|
|
34
|
+
}
|
|
35
|
+
get conversions() {
|
|
36
|
+
return [
|
|
37
|
+
{
|
|
38
|
+
conversionExpression: (value) => value,
|
|
39
|
+
sourceTypeCheckExpression: (value) => `typeof ${value} === "object"`,
|
|
40
|
+
sourceTypeName: this.name,
|
|
41
|
+
},
|
|
42
|
+
];
|
|
21
43
|
}
|
|
22
44
|
get discriminatorProperty() {
|
|
23
|
-
return
|
|
24
|
-
name: syntheticTypeDiscriminatorPropertyName,
|
|
25
|
-
values: this.memberTypes.map((_, typeIndex) => typeIndex.toString()),
|
|
26
|
-
}));
|
|
45
|
+
return Maybe.of(this._discriminatorProperty);
|
|
27
46
|
}
|
|
28
|
-
get
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
47
|
+
get equalsFunction() {
|
|
48
|
+
return `
|
|
49
|
+
(left: ${this.name}, right: ${this.name}) => {
|
|
50
|
+
${this.memberTypeTraits
|
|
51
|
+
.flatMap((memberTypeTraits) => memberTypeTraits.discriminatorPropertyValues.map((value) => `if (left.${this._discriminatorProperty.name} === "${value}" && right.${this._discriminatorProperty.name} === "${value}") {
|
|
52
|
+
return ${memberTypeTraits.memberType.equalsFunction}(${memberTypeTraits.payload("left")}, ${memberTypeTraits.payload("right")});
|
|
53
|
+
}`))
|
|
54
|
+
.join("\n")}
|
|
55
|
+
|
|
56
|
+
return purify.Left({ left, right, propertyName: "type", propertyValuesUnequal: { left: typeof left, right: typeof right, type: "BooleanEquals" as const }, type: "Property" as const });
|
|
57
|
+
}`;
|
|
58
|
+
}
|
|
59
|
+
get jsonName() {
|
|
60
|
+
switch (this._discriminatorProperty.kind) {
|
|
61
|
+
case "shared":
|
|
62
|
+
return this.memberTypes
|
|
63
|
+
.map((memberType) => memberType.jsonName)
|
|
64
|
+
.join(" | ");
|
|
65
|
+
case "synthetic":
|
|
66
|
+
return `(${this.memberTypeTraits.map((memberTypeTraits) => `{ ${this._discriminatorProperty.name}: "${memberTypeTraits.discriminatorPropertyValues[0]}", value: ${memberTypeTraits.memberType.jsonName} }`).join(" | ")})`;
|
|
67
|
+
default:
|
|
68
|
+
throw new RangeError(this._discriminatorProperty.kind);
|
|
33
69
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
70
|
+
}
|
|
71
|
+
get mutable() {
|
|
72
|
+
return this.memberTypes.some((memberType) => memberType.mutable);
|
|
73
|
+
}
|
|
74
|
+
get useImports() {
|
|
75
|
+
return this.memberTypes.flatMap((memberType) => memberType.useImports);
|
|
76
|
+
}
|
|
77
|
+
get _discriminatorProperty() {
|
|
78
|
+
let sharedDiscriminatorProperty;
|
|
79
|
+
for (const memberType of this.memberTypes) {
|
|
80
|
+
const memberTypeDiscriminatorProperty = memberType.discriminatorProperty.extract();
|
|
81
|
+
if (!memberTypeDiscriminatorProperty) {
|
|
82
|
+
sharedDiscriminatorProperty = undefined;
|
|
83
|
+
break;
|
|
43
84
|
}
|
|
44
|
-
if (!
|
|
45
|
-
|
|
46
|
-
name:
|
|
47
|
-
values:
|
|
85
|
+
if (!sharedDiscriminatorProperty) {
|
|
86
|
+
sharedDiscriminatorProperty = {
|
|
87
|
+
name: memberTypeDiscriminatorProperty.name,
|
|
88
|
+
values: memberTypeDiscriminatorProperty.values.concat(),
|
|
48
89
|
};
|
|
49
90
|
}
|
|
50
|
-
else if (
|
|
51
|
-
|
|
52
|
-
|
|
91
|
+
else if (memberTypeDiscriminatorProperty.name ===
|
|
92
|
+
sharedDiscriminatorProperty.name) {
|
|
93
|
+
sharedDiscriminatorProperty.values =
|
|
94
|
+
sharedDiscriminatorProperty.values.concat(memberTypeDiscriminatorProperty.values);
|
|
53
95
|
}
|
|
54
96
|
else {
|
|
55
|
-
|
|
97
|
+
sharedDiscriminatorProperty = undefined;
|
|
98
|
+
break;
|
|
56
99
|
}
|
|
57
100
|
}
|
|
58
|
-
|
|
101
|
+
if (sharedDiscriminatorProperty) {
|
|
102
|
+
return {
|
|
103
|
+
...sharedDiscriminatorProperty,
|
|
104
|
+
kind: "shared",
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
kind: "synthetic",
|
|
109
|
+
name: "type",
|
|
110
|
+
values: this.memberTypes.map((memberType, memberTypeIndex) => `${memberTypeIndex}-${memberType.name}`),
|
|
111
|
+
};
|
|
59
112
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
113
|
+
get memberTypeTraits() {
|
|
114
|
+
switch (this._discriminatorProperty.kind) {
|
|
115
|
+
case "shared":
|
|
116
|
+
return this.memberTypes.map((memberType) => ({
|
|
117
|
+
discriminatorPropertyValues: memberType.discriminatorProperty.unsafeCoerce().values,
|
|
118
|
+
memberType,
|
|
119
|
+
payload: (instance) => instance,
|
|
120
|
+
}));
|
|
121
|
+
case "synthetic":
|
|
122
|
+
return this.memberTypes.map((memberType, memberTypeIndex) => ({
|
|
123
|
+
discriminatorPropertyValues: [
|
|
124
|
+
`${memberTypeIndex}-${memberType.name}`,
|
|
125
|
+
],
|
|
126
|
+
memberType,
|
|
127
|
+
payload: (instance) => `${instance}.value`,
|
|
128
|
+
}));
|
|
129
|
+
default:
|
|
130
|
+
throw new RangeError(this._discriminatorProperty.kind);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
fromJsonExpression({ variables, }) {
|
|
134
|
+
return this.ternaryExpression({
|
|
135
|
+
memberTypeExpression: (memberTypeTraits) => {
|
|
136
|
+
let typeExpression = memberTypeTraits.memberType.fromJsonExpression({
|
|
137
|
+
variables: {
|
|
138
|
+
value: memberTypeTraits.payload(variables.value),
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
if (this._discriminatorProperty.kind === "synthetic") {
|
|
142
|
+
typeExpression = `{ ${this._discriminatorProperty.name}: "${memberTypeTraits.discriminatorPropertyValues[0]}" as const, value: ${typeExpression} }`;
|
|
143
|
+
}
|
|
144
|
+
return typeExpression;
|
|
145
|
+
},
|
|
146
|
+
variables,
|
|
147
|
+
});
|
|
81
148
|
}
|
|
82
149
|
fromRdfExpression(parameters) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
typeExpression = `${typeExpression}.map(value => ({ type: "${typeIndex}-${type.name}" as const, value }) as (${this.name}))`;
|
|
150
|
+
return this.memberTypeTraits.reduce((expression, memberTypeTraits) => {
|
|
151
|
+
let typeExpression = memberTypeTraits.memberType.fromRdfExpression(parameters);
|
|
152
|
+
if (this._discriminatorProperty.kind === "synthetic") {
|
|
153
|
+
typeExpression = `${typeExpression}.map(value => ({ ${this._discriminatorProperty.name}: "${memberTypeTraits.discriminatorPropertyValues[0]}" as const, value }) as (${this.name}))`;
|
|
88
154
|
}
|
|
89
155
|
typeExpression = `(${typeExpression} as purify.Either<rdfjsResource.Resource.ValueError, ${this.name}>)`;
|
|
90
|
-
expression
|
|
91
|
-
expression.
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
});
|
|
95
|
-
return expression;
|
|
156
|
+
return expression.length > 0
|
|
157
|
+
? `${expression}.altLazy(() => ${typeExpression})`
|
|
158
|
+
: typeExpression;
|
|
159
|
+
}, "");
|
|
96
160
|
}
|
|
97
|
-
hashStatements({ variables, }) {
|
|
161
|
+
hashStatements({ depth, variables, }) {
|
|
98
162
|
const caseBlocks = [];
|
|
99
|
-
this.
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
.
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
163
|
+
for (const memberTypeTraits of this.memberTypeTraits) {
|
|
164
|
+
for (const discriminatorPropertyValue of memberTypeTraits.discriminatorPropertyValues) {
|
|
165
|
+
caseBlocks.push(`case "${discriminatorPropertyValue}": { ${memberTypeTraits.memberType
|
|
166
|
+
.hashStatements({
|
|
167
|
+
depth: depth + 1,
|
|
168
|
+
variables: {
|
|
169
|
+
hasher: variables.hasher,
|
|
170
|
+
value: `${memberTypeTraits.payload(variables.value)}`,
|
|
171
|
+
},
|
|
172
|
+
})
|
|
173
|
+
.join("\n")}; break; }`);
|
|
107
174
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
})}": { ${type.hashStatements({ variables: { hasher: variables.hasher, value: `${variables}.value` } })}; break; }`);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
const switchValue = this.typesSharedDiscriminatorProperty
|
|
116
|
-
.map((typeSharedDiscriminatorProperty) => `${variables.value}.${typeSharedDiscriminatorProperty.name}`)
|
|
117
|
-
.orDefaultLazy(() => `${variables.value}.${syntheticTypeDiscriminatorPropertyName}`);
|
|
118
|
-
return [`switch (${switchValue}) { ${caseBlocks.join("\n")} }`];
|
|
119
|
-
}
|
|
120
|
-
propertySparqlGraphPatternExpression(parameters) {
|
|
121
|
-
return new Type.SparqlGraphPatternExpression(`sparqlBuilder.GraphPattern.union(${this.memberTypes
|
|
122
|
-
.map((type) => type
|
|
123
|
-
.propertySparqlGraphPatternExpression(parameters)
|
|
124
|
-
.toSparqlGraphPatternExpression()
|
|
125
|
-
.toString())
|
|
126
|
-
.join(", ")})`);
|
|
175
|
+
}
|
|
176
|
+
return [
|
|
177
|
+
`switch (${variables.value}.${this._discriminatorProperty.name}) { ${caseBlocks.join("\n")} }`,
|
|
178
|
+
];
|
|
127
179
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
180
|
+
jsonZodSchema({ variables, }) {
|
|
181
|
+
switch (this._discriminatorProperty.kind) {
|
|
182
|
+
case "shared":
|
|
183
|
+
return `${variables.zod}.discriminatedUnion("${this._discriminatorProperty.name}", [${this.memberTypes
|
|
184
|
+
.map((memberType) => memberType.jsonZodSchema({ variables }))
|
|
185
|
+
.join(", ")}])`;
|
|
186
|
+
case "synthetic":
|
|
187
|
+
return `${variables.zod}.discriminatedUnion("${this._discriminatorProperty.name}", [${this.memberTypeTraits
|
|
188
|
+
.map((memberTypeTraits) => `${variables.zod}.object({ ${this._discriminatorProperty.name}: ${variables.zod}.literal("${memberTypeTraits.discriminatorPropertyValues[0]}"), value: ${memberTypeTraits.memberType.jsonZodSchema({ variables })} })`)
|
|
189
|
+
.join(", ")}])`;
|
|
190
|
+
default:
|
|
191
|
+
throw new RangeError(this._discriminatorProperty.kind);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
sparqlConstructTemplateTriples(parameters) {
|
|
195
|
+
return this.memberTypes.reduce((array, memberType) => array.concat(memberType.sparqlConstructTemplateTriples(parameters)), []);
|
|
196
|
+
}
|
|
197
|
+
sparqlWherePatterns(parameters) {
|
|
198
|
+
let haveEmptyGroup = false; // Only need one empty group
|
|
199
|
+
return [
|
|
200
|
+
`{ patterns: [${this.memberTypes
|
|
201
|
+
.flatMap((memberType) => {
|
|
202
|
+
const groupPatterns = memberType.sparqlWherePatterns(parameters);
|
|
203
|
+
if (groupPatterns.length === 0) {
|
|
204
|
+
if (haveEmptyGroup) {
|
|
205
|
+
return [];
|
|
206
|
+
}
|
|
207
|
+
haveEmptyGroup = true;
|
|
208
|
+
return [objectInitializer({ patterns: "[]", type: '"group"' })];
|
|
153
209
|
}
|
|
154
|
-
|
|
210
|
+
return [
|
|
211
|
+
objectInitializer({
|
|
212
|
+
patterns: `[${groupPatterns.join(", ")}]`,
|
|
213
|
+
type: '"group"',
|
|
214
|
+
}),
|
|
215
|
+
];
|
|
216
|
+
})
|
|
217
|
+
.join(", ")}], type: "union" }`,
|
|
218
|
+
];
|
|
219
|
+
}
|
|
220
|
+
toJsonExpression({ variables, }) {
|
|
221
|
+
switch (this._discriminatorProperty.kind) {
|
|
222
|
+
case "shared":
|
|
223
|
+
return this.ternaryExpression({
|
|
224
|
+
memberTypeExpression: (memberTypeTraits) => memberTypeTraits.memberType.toJsonExpression({
|
|
225
|
+
variables: {
|
|
226
|
+
...variables,
|
|
227
|
+
value: memberTypeTraits.payload(variables.value),
|
|
228
|
+
},
|
|
229
|
+
}),
|
|
230
|
+
variables,
|
|
231
|
+
});
|
|
232
|
+
case "synthetic":
|
|
233
|
+
return this.ternaryExpression({
|
|
234
|
+
memberTypeExpression: (memberTypeTraits) => `{ ${this._discriminatorProperty.name}: "${memberTypeTraits.discriminatorPropertyValues[0]}" as const, value: ${memberTypeTraits.memberType.toJsonExpression({
|
|
235
|
+
variables: {
|
|
236
|
+
...variables,
|
|
237
|
+
value: memberTypeTraits.payload(variables.value),
|
|
238
|
+
},
|
|
239
|
+
})} }`,
|
|
240
|
+
variables,
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
toRdfExpression({ variables, }) {
|
|
245
|
+
return this.ternaryExpression({
|
|
246
|
+
memberTypeExpression: (memberTypeTraits) => memberTypeTraits.memberType.toRdfExpression({
|
|
247
|
+
variables: {
|
|
248
|
+
...variables,
|
|
249
|
+
value: memberTypeTraits.payload(variables.value),
|
|
250
|
+
},
|
|
251
|
+
}),
|
|
252
|
+
variables,
|
|
155
253
|
});
|
|
156
|
-
|
|
254
|
+
}
|
|
255
|
+
ternaryExpression({ memberTypeExpression, variables, }) {
|
|
256
|
+
return this.memberTypeTraits.reduce((expression, memberTypeTraits) => {
|
|
257
|
+
if (expression.length === 0) {
|
|
258
|
+
return memberTypeExpression(memberTypeTraits);
|
|
259
|
+
}
|
|
260
|
+
return `(${memberTypeTraits.discriminatorPropertyValues
|
|
261
|
+
.map((value) => `${variables.value}.${this._discriminatorProperty.name} === "${value}"`)
|
|
262
|
+
.join(" || ")}) ? ${memberTypeExpression(memberTypeTraits)} : ${expression}`;
|
|
263
|
+
}, "");
|
|
157
264
|
}
|
|
158
265
|
}
|
|
159
266
|
__decorate([
|
|
@@ -161,5 +268,8 @@ __decorate([
|
|
|
161
268
|
], UnionType.prototype, "discriminatorProperty", null);
|
|
162
269
|
__decorate([
|
|
163
270
|
Memoize()
|
|
164
|
-
], UnionType.prototype, "
|
|
271
|
+
], UnionType.prototype, "_discriminatorProperty", null);
|
|
272
|
+
__decorate([
|
|
273
|
+
Memoize()
|
|
274
|
+
], UnionType.prototype, "memberTypeTraits", null);
|
|
165
275
|
//# sourceMappingURL=UnionType.js.map
|
|
@@ -1,23 +1,43 @@
|
|
|
1
1
|
import { Maybe } from "purify-ts";
|
|
2
|
-
import {
|
|
3
|
-
import { MintingStrategy } from "../../../
|
|
2
|
+
import type { GetAccessorDeclarationStructure, OptionalKind, PropertyDeclarationStructure, PropertySignatureStructure } from "ts-morph";
|
|
3
|
+
import type { MintingStrategy, PropertyVisibility, TsObjectDeclarationType } from "../../../enums/index.js";
|
|
4
4
|
import type { IdentifierType } from "../IdentifierType.js";
|
|
5
|
+
import { Import } from "../Import.js";
|
|
5
6
|
import { Property } from "./Property.js";
|
|
6
7
|
export declare class IdentifierProperty extends Property<IdentifierType> {
|
|
8
|
+
readonly abstract: boolean;
|
|
7
9
|
readonly equalsFunction = "purifyHelpers.Equatable.booleanEquals";
|
|
10
|
+
readonly mutable = false;
|
|
11
|
+
private readonly classDeclarationVisibility;
|
|
12
|
+
private readonly lazyObjectTypeMutable;
|
|
8
13
|
private readonly mintingStrategy;
|
|
9
|
-
|
|
14
|
+
private readonly objectTypeDeclarationType;
|
|
15
|
+
private readonly override;
|
|
16
|
+
constructor({ abstract, classDeclarationVisibility, lazyObjectTypeMutable, mintingStrategy, objectTypeDeclarationType, override, ...superParameters }: {
|
|
17
|
+
abstract: boolean;
|
|
18
|
+
classDeclarationVisibility: Maybe<PropertyVisibility>;
|
|
19
|
+
lazyObjectTypeMutable: () => boolean;
|
|
10
20
|
mintingStrategy: Maybe<MintingStrategy>;
|
|
21
|
+
objectTypeDeclarationType: TsObjectDeclarationType;
|
|
22
|
+
override: boolean;
|
|
11
23
|
type: IdentifierType;
|
|
12
24
|
} & ConstructorParameters<typeof Property>[0]);
|
|
13
|
-
get classConstructorParametersPropertySignature(): Maybe<OptionalKind<PropertySignatureStructure>>;
|
|
14
25
|
get classGetAccessorDeclaration(): Maybe<OptionalKind<GetAccessorDeclarationStructure>>;
|
|
15
|
-
get classPropertyDeclaration(): OptionalKind<PropertyDeclarationStructure
|
|
26
|
+
get classPropertyDeclaration(): Maybe<OptionalKind<PropertyDeclarationStructure>>;
|
|
27
|
+
get constructorParametersPropertySignature(): Maybe<OptionalKind<PropertySignatureStructure>>;
|
|
28
|
+
get declarationImports(): readonly Import[];
|
|
16
29
|
get interfacePropertySignature(): OptionalKind<PropertySignatureStructure>;
|
|
30
|
+
get jsonPropertySignature(): OptionalKind<PropertySignatureStructure>;
|
|
17
31
|
classConstructorStatements({ variables, }: Parameters<Property<IdentifierType>["classConstructorStatements"]>[0]): readonly string[];
|
|
32
|
+
fromJsonStatements({ variables, }: Parameters<Property<IdentifierType>["fromJsonStatements"]>[0]): readonly string[];
|
|
18
33
|
fromRdfStatements({ variables, }: Parameters<Property<IdentifierType>["fromRdfStatements"]>[0]): readonly string[];
|
|
19
|
-
hashStatements(
|
|
20
|
-
|
|
34
|
+
hashStatements(): readonly string[];
|
|
35
|
+
interfaceConstructorStatements({ variables, }: Parameters<Property<IdentifierType>["interfaceConstructorStatements"]>[0]): readonly string[];
|
|
36
|
+
jsonUiSchemaElement({ variables, }: Parameters<Property<IdentifierType>["jsonUiSchemaElement"]>[0]): Maybe<string>;
|
|
37
|
+
jsonZodSchema({ variables, }: Parameters<Property<IdentifierType>["jsonZodSchema"]>[0]): ReturnType<Property<IdentifierType>["jsonZodSchema"]>;
|
|
38
|
+
sparqlConstructTemplateTriples(): readonly string[];
|
|
39
|
+
sparqlWherePatterns(): readonly string[];
|
|
40
|
+
toJsonObjectMember({ variables, }: Parameters<Property<IdentifierType>["toJsonObjectMember"]>[0]): string;
|
|
21
41
|
toRdfStatements(): readonly string[];
|
|
22
42
|
}
|
|
23
43
|
//# sourceMappingURL=IdentifierProperty.d.ts.map
|