@shaclmate/compiler 2.0.22 → 2.0.23
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 +1 -0
- package/dist/ShapesGraphToAstTransformer.js +56 -12
- package/dist/_ShapesGraphToAstTransformer/flattenAstObjectCompositeTypeMemberTypes.d.ts +13 -0
- package/dist/_ShapesGraphToAstTransformer/flattenAstObjectCompositeTypeMemberTypes.js +51 -0
- package/dist/_ShapesGraphToAstTransformer/shapeAstName.js +53 -12
- package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.d.ts +5 -0
- package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.js +130 -54
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.d.ts +2 -3
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +122 -129
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.d.ts +2 -2
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.d.ts +2 -2
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +127 -5
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.d.ts +3 -3
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.d.ts +2 -3
- package/dist/ast/Ast.d.ts +0 -1
- package/dist/ast/Curie.d.ts +14 -0
- package/dist/ast/Curie.js +21 -0
- package/dist/ast/IdentifierType.d.ts +3 -2
- package/dist/ast/ListType.d.ts +2 -1
- package/dist/ast/LiteralType.d.ts +1 -1
- package/dist/ast/Name.d.ts +40 -5
- package/dist/ast/ObjectCompositeType.d.ts +11 -0
- package/dist/ast/ObjectType.d.ts +18 -13
- package/dist/ast/ObjectUnionType.d.ts +0 -11
- package/dist/ast/OptionType.d.ts +2 -2
- package/dist/ast/SetType.d.ts +2 -2
- package/dist/ast/TermType.d.ts +12 -4
- package/dist/ast/Type.d.ts +1 -1
- package/dist/enums/TsFeature.d.ts +1 -4
- package/dist/enums/TsFeature.js +1 -15
- package/dist/generators/json/AstJsonGenerator.js +19 -3
- package/dist/generators/ts/BooleanType.d.ts +3 -1
- package/dist/generators/ts/BooleanType.js +11 -2
- package/dist/generators/ts/DateTimeType.d.ts +8 -7
- package/dist/generators/ts/DateTimeType.js +31 -7
- package/dist/generators/ts/DateType.d.ts +5 -2
- package/dist/generators/ts/DateType.js +15 -1
- package/dist/generators/ts/DeclaredType.d.ts +2 -2
- package/dist/generators/ts/DeclaredType.js +2 -2
- package/dist/generators/ts/FloatType.d.ts +6 -0
- package/dist/generators/ts/FloatType.js +18 -0
- package/dist/generators/ts/IdentifierType.d.ts +12 -7
- package/dist/generators/ts/IdentifierType.js +94 -6
- package/dist/generators/ts/Import.d.ts +2 -0
- package/dist/generators/ts/Import.js +10 -0
- package/dist/generators/ts/IntType.d.ts +6 -0
- package/dist/generators/ts/IntType.js +18 -0
- package/dist/generators/ts/ListType.d.ts +15 -12
- package/dist/generators/ts/ListType.js +98 -57
- package/dist/generators/ts/LiteralType.d.ts +10 -9
- package/dist/generators/ts/LiteralType.js +13 -2
- package/dist/generators/ts/NumberType.d.ts +2 -1
- package/dist/generators/ts/NumberType.js +7 -2
- package/dist/generators/ts/ObjectType.d.ts +66 -43
- package/dist/generators/ts/ObjectType.js +144 -123
- package/dist/generators/ts/ObjectUnionType.d.ts +49 -8
- package/dist/generators/ts/ObjectUnionType.js +290 -97
- package/dist/generators/ts/OptionType.d.ts +14 -10
- package/dist/generators/ts/OptionType.js +60 -34
- package/dist/generators/ts/PrimitiveType.d.ts +4 -4
- package/dist/generators/ts/PrimitiveType.js +18 -3
- package/dist/generators/ts/SetType.d.ts +16 -12
- package/dist/generators/ts/SetType.js +69 -40
- package/dist/generators/ts/SnippetDeclarations.d.ts +13 -8
- package/dist/generators/ts/SnippetDeclarations.js +215 -101
- package/dist/generators/ts/StringType.d.ts +3 -1
- package/dist/generators/ts/StringType.js +14 -2
- package/dist/generators/ts/TermType.d.ts +22 -14
- package/dist/generators/ts/TermType.js +53 -25
- package/dist/generators/ts/TsGenerator.d.ts +2 -1
- package/dist/generators/ts/TsGenerator.js +23 -12
- package/dist/generators/ts/Type.d.ts +89 -31
- package/dist/generators/ts/Type.js +57 -54
- package/dist/generators/ts/TypeFactory.d.ts +4 -5
- package/dist/generators/ts/TypeFactory.js +290 -226
- package/dist/generators/ts/UnionType.d.ts +14 -10
- package/dist/generators/ts/UnionType.js +319 -142
- package/dist/generators/ts/_ObjectType/EagerShaclProperty.d.ts +12 -0
- package/dist/generators/ts/_ObjectType/EagerShaclProperty.js +30 -0
- package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.d.ts +13 -12
- package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.js +46 -47
- package/dist/generators/ts/_ObjectType/IdentifierProperty.d.ts +20 -13
- package/dist/generators/ts/_ObjectType/IdentifierProperty.js +152 -124
- package/dist/generators/ts/_ObjectType/LazyShaclProperty.d.ts +87 -0
- package/dist/generators/ts/_ObjectType/LazyShaclProperty.js +237 -0
- package/dist/generators/ts/_ObjectType/Property.d.ts +39 -44
- package/dist/generators/ts/_ObjectType/Property.js +1 -10
- package/dist/generators/ts/_ObjectType/ShaclProperty.d.ts +25 -30
- package/dist/generators/ts/_ObjectType/ShaclProperty.js +108 -85
- package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +21 -17
- package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +61 -53
- package/dist/generators/ts/_ObjectType/classDeclaration.js +6 -5
- package/dist/generators/ts/_ObjectType/createFunctionDeclaration.js +5 -4
- package/dist/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.js +5 -4
- package/dist/generators/ts/_ObjectType/fromRdfTypeVariableStatement.d.ts +1 -1
- package/dist/generators/ts/_ObjectType/fromRdfTypeVariableStatement.js +8 -5
- package/dist/generators/ts/_ObjectType/graphqlTypeVariableStatement.d.ts +5 -0
- package/dist/generators/ts/_ObjectType/graphqlTypeVariableStatement.js +37 -0
- package/dist/generators/ts/_ObjectType/hashFunctionOrMethodDeclarations.js +7 -8
- package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.d.ts +7 -0
- package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.js +54 -0
- package/dist/generators/ts/_ObjectType/index.d.ts +9 -7
- package/dist/generators/ts/_ObjectType/index.js +9 -7
- package/dist/generators/ts/_ObjectType/interfaceDeclaration.js +1 -1
- package/dist/generators/ts/_ObjectType/jsonFunctionDeclarations.d.ts +4 -0
- package/dist/generators/ts/_ObjectType/jsonFunctionDeclarations.js +189 -0
- package/dist/generators/ts/_ObjectType/jsonTypeAliasDeclaration.d.ts +5 -0
- package/dist/generators/ts/_ObjectType/jsonTypeAliasDeclaration.js +28 -0
- package/dist/generators/ts/_ObjectType/objectSetMethodNames.d.ts +9 -0
- package/dist/generators/ts/_ObjectType/objectSetMethodNames.js +18 -0
- package/dist/generators/ts/_ObjectType/propertiesVariableStatement.d.ts +5 -0
- package/dist/generators/ts/_ObjectType/propertiesVariableStatement.js +37 -0
- package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.d.ts +4 -0
- package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.js +152 -0
- package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.d.ts +1 -1
- package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.js +4 -3
- package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.d.ts +1 -1
- package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.js +3 -2
- package/dist/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +103 -35
- package/dist/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.js +6 -6
- package/dist/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.js +15 -13
- package/dist/generators/ts/graphqlSchemaVariableStatement.d.ts +9 -0
- package/dist/generators/ts/graphqlSchemaVariableStatement.js +86 -0
- package/dist/generators/ts/objectSetDeclarations.d.ts +8 -0
- package/dist/generators/ts/objectSetDeclarations.js +59 -0
- package/dist/generators/ts/objectSetInterfaceDeclaration.d.ts +8 -0
- package/dist/generators/ts/objectSetInterfaceDeclaration.js +46 -0
- package/dist/generators/ts/objectSetMethodSignatures.d.ts +11 -0
- package/dist/generators/ts/objectSetMethodSignatures.js +52 -0
- package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.d.ts +8 -0
- package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +393 -0
- package/dist/generators/ts/rdfjsTermExpression.d.ts +3 -0
- package/dist/generators/ts/rdfjsTermExpression.js +57 -0
- package/dist/generators/ts/sparqlObjectSetClassDeclaration.d.ts +8 -0
- package/dist/generators/ts/sparqlObjectSetClassDeclaration.js +415 -0
- package/dist/generators/ts/syntheticNamePrefix.d.ts +2 -0
- package/dist/generators/ts/syntheticNamePrefix.js +2 -0
- package/dist/generators/ts/tsName.js +27 -13
- package/dist/generators/ts/unsupportedObjectSetMethodDeclarations.d.ts +10 -0
- package/dist/generators/ts/unsupportedObjectSetMethodDeclarations.js +19 -0
- package/dist/input/NodeShape.d.ts +6 -8
- package/dist/input/NodeShape.js +20 -44
- package/dist/input/Ontology.d.ts +0 -3
- package/dist/input/Ontology.js +0 -9
- package/dist/input/PropertyPath.d.ts +6 -5
- package/dist/input/PropertyPath.js +14 -22
- package/dist/input/PropertyShape.d.ts +3 -1
- package/dist/input/PropertyShape.js +8 -2
- package/dist/input/ShapesGraph.js +4 -4
- package/dist/input/generated.d.ts +923 -105
- package/dist/input/generated.js +1865 -969
- package/dist/input/tsFeatures.d.ts +3 -2
- package/dist/input/tsFeatures.js +44 -27
- package/package.json +18 -16
- package/dist/generators/ts/_ObjectType/fromJsonFunctionDeclarations.d.ts +0 -4
- package/dist/generators/ts/_ObjectType/fromJsonFunctionDeclarations.js +0 -78
- package/dist/generators/ts/_ObjectType/fromRdfFunctionDeclarations.d.ts +0 -4
- package/dist/generators/ts/_ObjectType/fromRdfFunctionDeclarations.js +0 -91
- package/dist/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.js +0 -19
- package/dist/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.js +0 -31
- package/dist/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.js +0 -37
- package/dist/generators/ts/_ObjectType/rdfjsTermExpression.d.ts +0 -6
- package/dist/generators/ts/_ObjectType/rdfjsTermExpression.js +0 -17
- package/dist/generators/ts/_ObjectType/toJsonFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/toJsonFunctionDeclaration.js +0 -19
- package/dist/generators/ts/_ObjectType/toJsonReturnType.d.ts +0 -3
- package/dist/generators/ts/_ObjectType/toJsonReturnType.js +0 -17
- package/dist/generators/ts/_ObjectType/toRdfFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/toRdfFunctionDeclaration.js +0 -19
|
@@ -9,196 +9,327 @@ import { invariant } from "ts-invariant";
|
|
|
9
9
|
import { Memoize } from "typescript-memoize";
|
|
10
10
|
import { Type } from "./Type.js";
|
|
11
11
|
import { objectInitializer } from "./objectInitializer.js";
|
|
12
|
+
class MemberType {
|
|
13
|
+
delegate;
|
|
14
|
+
delegateIndex;
|
|
15
|
+
discriminatorKind;
|
|
16
|
+
universe;
|
|
17
|
+
constructor({ delegate, delegateIndex, discriminatorKind, universe, }) {
|
|
18
|
+
this.delegate = delegate;
|
|
19
|
+
this.delegateIndex = delegateIndex;
|
|
20
|
+
this.discriminatorKind = discriminatorKind;
|
|
21
|
+
this.universe = universe;
|
|
22
|
+
}
|
|
23
|
+
get discriminatorValues() {
|
|
24
|
+
switch (this.discriminatorKind) {
|
|
25
|
+
case "sharedProperty": {
|
|
26
|
+
// A member type's combined discriminator property values are its "own" values plus any descendant values that are
|
|
27
|
+
// not the "own" values of some other member type.
|
|
28
|
+
// So if you have type A, type B, and B inherits A, then
|
|
29
|
+
// A has
|
|
30
|
+
// own discriminator property values: ["A"]
|
|
31
|
+
// descendant discriminator property values: ["B"]
|
|
32
|
+
// and B has
|
|
33
|
+
// own discriminator property values: ["B"]
|
|
34
|
+
// descendant discriminator property values ["B"]
|
|
35
|
+
// In this case A shouldn't have "B" as a combined discriminator property value since it's "claimed" by B.
|
|
36
|
+
const memberOwnDiscriminatorPropertyValues = new Set();
|
|
37
|
+
for (const memberType of this.universe) {
|
|
38
|
+
for (const ownDiscriminatorPropertyValue of memberType.discriminatorProperty.unsafeCoerce()
|
|
39
|
+
.ownValues) {
|
|
40
|
+
memberOwnDiscriminatorPropertyValues.add(ownDiscriminatorPropertyValue);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return this.delegate.discriminatorProperty
|
|
44
|
+
.unsafeCoerce()
|
|
45
|
+
.ownValues.concat(this.delegate.discriminatorProperty
|
|
46
|
+
.unsafeCoerce()
|
|
47
|
+
.descendantValues.filter((value) => !memberOwnDiscriminatorPropertyValues.has(value)));
|
|
48
|
+
}
|
|
49
|
+
case "syntheticProperty":
|
|
50
|
+
return [`${this.delegateIndex}-${this.delegate.name}`];
|
|
51
|
+
case "typeof":
|
|
52
|
+
return [this.delegate.typeof];
|
|
53
|
+
default:
|
|
54
|
+
throw this.discriminatorKind;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
get equalsFunction() {
|
|
58
|
+
return this.delegate.equalsFunction;
|
|
59
|
+
}
|
|
60
|
+
get jsonName() {
|
|
61
|
+
return this.delegate.jsonName;
|
|
62
|
+
}
|
|
63
|
+
get mutable() {
|
|
64
|
+
return this.delegate.mutable;
|
|
65
|
+
}
|
|
66
|
+
get name() {
|
|
67
|
+
return this.delegate.name;
|
|
68
|
+
}
|
|
69
|
+
fromJsonExpression(parameters) {
|
|
70
|
+
return this.delegate.fromJsonExpression(parameters);
|
|
71
|
+
}
|
|
72
|
+
fromRdfExpression(parameters) {
|
|
73
|
+
return this.delegate.fromRdfExpression(parameters);
|
|
74
|
+
}
|
|
75
|
+
hashStatements(parameters) {
|
|
76
|
+
return this.delegate.hashStatements(parameters);
|
|
77
|
+
}
|
|
78
|
+
jsonZodSchema(parameters) {
|
|
79
|
+
return this.delegate.jsonZodSchema(parameters);
|
|
80
|
+
}
|
|
81
|
+
payload(instance) {
|
|
82
|
+
switch (this.discriminatorKind) {
|
|
83
|
+
case "sharedProperty":
|
|
84
|
+
case "typeof":
|
|
85
|
+
return instance;
|
|
86
|
+
case "syntheticProperty":
|
|
87
|
+
return `${instance}.value`;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
snippetDeclarations(parameters) {
|
|
91
|
+
return this.delegate.snippetDeclarations(parameters);
|
|
92
|
+
}
|
|
93
|
+
sparqlConstructTemplateTriples(parameters) {
|
|
94
|
+
return this.delegate.sparqlConstructTemplateTriples(parameters);
|
|
95
|
+
}
|
|
96
|
+
sparqlWherePatterns(parameters) {
|
|
97
|
+
return this.delegate.sparqlWherePatterns(parameters);
|
|
98
|
+
}
|
|
99
|
+
toJsonExpression(parameters) {
|
|
100
|
+
return this.delegate.toJsonExpression(parameters);
|
|
101
|
+
}
|
|
102
|
+
toRdfExpression(parameters) {
|
|
103
|
+
return this.delegate.toRdfExpression(parameters);
|
|
104
|
+
}
|
|
105
|
+
useImports(parameters) {
|
|
106
|
+
return this.delegate.useImports(parameters);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
__decorate([
|
|
110
|
+
Memoize()
|
|
111
|
+
], MemberType.prototype, "discriminatorValues", null);
|
|
12
112
|
export class UnionType extends Type {
|
|
13
|
-
|
|
113
|
+
_discriminator;
|
|
14
114
|
memberTypes;
|
|
15
|
-
|
|
16
|
-
|
|
115
|
+
_name;
|
|
116
|
+
kind = "UnionType";
|
|
117
|
+
typeof = "object";
|
|
118
|
+
constructor({ memberTypes, name, }) {
|
|
119
|
+
super();
|
|
17
120
|
invariant(memberTypes.length >= 2);
|
|
18
|
-
this.memberTypes = memberTypes;
|
|
19
121
|
this._name = name;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
122
|
+
const sharedDiscriminatorProperty_ = sharedDiscriminatorProperty(memberTypes);
|
|
123
|
+
if (sharedDiscriminatorProperty_) {
|
|
124
|
+
this._discriminator = {
|
|
125
|
+
...sharedDiscriminatorProperty_,
|
|
126
|
+
kind: "sharedProperty",
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
const memberTypeofs = new Set();
|
|
131
|
+
for (const memberType of memberTypes) {
|
|
132
|
+
memberTypeofs.add(memberType.typeof);
|
|
133
|
+
}
|
|
134
|
+
if (memberTypeofs.size === memberTypes.length) {
|
|
135
|
+
this._discriminator = {
|
|
136
|
+
kind: "typeof",
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
this._discriminator = {
|
|
141
|
+
descendantValues: [],
|
|
142
|
+
kind: "syntheticProperty",
|
|
143
|
+
name: "type",
|
|
144
|
+
ownValues: memberTypes.map((memberType, memberTypeIndex) => `${memberTypeIndex}-${memberType.name}`),
|
|
145
|
+
};
|
|
33
146
|
}
|
|
34
147
|
}
|
|
35
|
-
|
|
148
|
+
this.memberTypes = memberTypes.map((memberType, memberTypeIndex) => new MemberType({
|
|
149
|
+
delegate: memberType,
|
|
150
|
+
delegateIndex: memberTypeIndex,
|
|
151
|
+
discriminatorKind: this._discriminator.kind,
|
|
152
|
+
universe: memberTypes,
|
|
153
|
+
}));
|
|
36
154
|
}
|
|
37
155
|
get conversions() {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
156
|
+
switch (this._discriminator.kind) {
|
|
157
|
+
case "sharedProperty":
|
|
158
|
+
case "syntheticProperty":
|
|
159
|
+
return [
|
|
160
|
+
{
|
|
161
|
+
conversionExpression: (value) => value,
|
|
162
|
+
sourceTypeCheckExpression: (value) => `typeof ${value} === "object"`,
|
|
163
|
+
sourceTypeName: this.name,
|
|
164
|
+
},
|
|
165
|
+
];
|
|
166
|
+
case "typeof":
|
|
167
|
+
return this.memberTypes.map((memberType) => ({
|
|
168
|
+
conversionExpression: (value) => value,
|
|
169
|
+
sourceTypeCheckExpression: (value) => `typeof ${value} === "${memberType.discriminatorValues[0]}"`,
|
|
170
|
+
sourceTypeName: memberType.name,
|
|
171
|
+
}));
|
|
172
|
+
default:
|
|
173
|
+
throw this._discriminator;
|
|
174
|
+
}
|
|
45
175
|
}
|
|
46
176
|
get discriminatorProperty() {
|
|
47
|
-
|
|
177
|
+
switch (this._discriminator.kind) {
|
|
178
|
+
case "sharedProperty":
|
|
179
|
+
case "syntheticProperty":
|
|
180
|
+
return Maybe.of(this._discriminator);
|
|
181
|
+
case "typeof":
|
|
182
|
+
return Maybe.empty();
|
|
183
|
+
default:
|
|
184
|
+
throw this._discriminator;
|
|
185
|
+
}
|
|
48
186
|
}
|
|
49
187
|
get equalsFunction() {
|
|
50
188
|
return `
|
|
51
189
|
(left: ${this.name}, right: ${this.name}) => {
|
|
52
|
-
${this.
|
|
53
|
-
.flatMap((
|
|
54
|
-
return ${
|
|
190
|
+
${this.memberTypes
|
|
191
|
+
.flatMap((memberType) => memberType.discriminatorValues.map((value) => `if (${this.discriminatorVariable("left")} === "${value}" && ${this.discriminatorVariable("right")} === "${value}") {
|
|
192
|
+
return ${memberType.equalsFunction}(${memberType.payload("left")}, ${memberType.payload("right")});
|
|
55
193
|
}`))
|
|
56
194
|
.join("\n")}
|
|
57
195
|
|
|
58
196
|
return purify.Left({ left, right, propertyName: "type", propertyValuesUnequal: { left: typeof left, right: typeof right, type: "BooleanEquals" as const }, type: "Property" as const });
|
|
59
197
|
}`;
|
|
60
198
|
}
|
|
199
|
+
get graphqlName() {
|
|
200
|
+
throw new Error("not implemented");
|
|
201
|
+
}
|
|
61
202
|
get jsonName() {
|
|
62
|
-
switch (this.
|
|
63
|
-
case "
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return `(${this.memberTypeTraits.map((memberTypeTraits) => `{ ${this._discriminatorProperty.name}: "${memberTypeTraits.discriminatorPropertyValues[0]}", value: ${memberTypeTraits.memberType.jsonName} }`).join(" | ")})`;
|
|
203
|
+
switch (this._discriminator.kind) {
|
|
204
|
+
case "sharedProperty":
|
|
205
|
+
case "typeof":
|
|
206
|
+
return new Type.JsonName(this.memberTypes.map((memberType) => memberType.jsonName).join(" | "));
|
|
207
|
+
case "syntheticProperty":
|
|
208
|
+
return new Type.JsonName(`(${this.memberTypes.map((memberType) => `{ ${this._discriminator.name}: "${memberType.discriminatorValues[0]}", value: ${memberType.jsonName} }`).join(" | ")})`);
|
|
69
209
|
default:
|
|
70
|
-
throw
|
|
210
|
+
throw this._discriminator;
|
|
71
211
|
}
|
|
72
212
|
}
|
|
73
213
|
get mutable() {
|
|
74
214
|
return this.memberTypes.some((memberType) => memberType.mutable);
|
|
75
215
|
}
|
|
76
|
-
get
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
sharedDiscriminatorProperty.values =
|
|
93
|
-
sharedDiscriminatorProperty.values.concat(memberTypeDiscriminatorProperty.values);
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
sharedDiscriminatorProperty = undefined;
|
|
97
|
-
break;
|
|
216
|
+
get name() {
|
|
217
|
+
if (typeof this._name === "undefined") {
|
|
218
|
+
switch (this._discriminator.kind) {
|
|
219
|
+
case "sharedProperty":
|
|
220
|
+
// If every type shares a discriminator (e.g., RDF/JS "termType" or generated ObjectType "type"),
|
|
221
|
+
// just join their names with "|"
|
|
222
|
+
this._name = `(${this.memberTypes.map((memberType) => memberType.name).join(" | ")})`;
|
|
223
|
+
break;
|
|
224
|
+
case "syntheticProperty":
|
|
225
|
+
this._name = `(${this.memberTypes.map((memberType) => `{ ${this._discriminator.name}: "${memberType.discriminatorValues[0]}", value: ${memberType.name} }`).join(" | ")})`;
|
|
226
|
+
break;
|
|
227
|
+
case "typeof":
|
|
228
|
+
// The memberType.name may include literal values, but they should still be unambiguous with other member types since the typeofs
|
|
229
|
+
// of the different member types are known to be different.
|
|
230
|
+
this._name = `(${this.memberTypes.map((memberType) => memberType.name).join(" | ")})`;
|
|
231
|
+
break;
|
|
98
232
|
}
|
|
99
233
|
}
|
|
100
|
-
|
|
101
|
-
return {
|
|
102
|
-
...sharedDiscriminatorProperty,
|
|
103
|
-
kind: "shared",
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
return {
|
|
107
|
-
kind: "synthetic",
|
|
108
|
-
name: "type",
|
|
109
|
-
values: this.memberTypes.map((memberType, memberTypeIndex) => `${memberTypeIndex}-${memberType.name}`),
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
get memberTypeTraits() {
|
|
113
|
-
switch (this._discriminatorProperty.kind) {
|
|
114
|
-
case "shared":
|
|
115
|
-
return this.memberTypes.map((memberType) => ({
|
|
116
|
-
discriminatorPropertyValues: memberType.discriminatorProperty.unsafeCoerce().values,
|
|
117
|
-
memberType,
|
|
118
|
-
payload: (instance) => instance,
|
|
119
|
-
}));
|
|
120
|
-
case "synthetic":
|
|
121
|
-
return this.memberTypes.map((memberType, memberTypeIndex) => ({
|
|
122
|
-
discriminatorPropertyValues: [
|
|
123
|
-
`${memberTypeIndex}-${memberType.name}`,
|
|
124
|
-
],
|
|
125
|
-
memberType,
|
|
126
|
-
payload: (instance) => `${instance}.value`,
|
|
127
|
-
}));
|
|
128
|
-
default:
|
|
129
|
-
throw new RangeError(this._discriminatorProperty.kind);
|
|
130
|
-
}
|
|
234
|
+
return this._name;
|
|
131
235
|
}
|
|
132
236
|
fromJsonExpression({ variables, }) {
|
|
133
237
|
return this.ternaryExpression({
|
|
134
|
-
memberTypeExpression: (
|
|
135
|
-
let typeExpression =
|
|
238
|
+
memberTypeExpression: (memberType) => {
|
|
239
|
+
let typeExpression = memberType.fromJsonExpression({
|
|
136
240
|
variables: {
|
|
137
|
-
value:
|
|
241
|
+
value: memberType.payload(variables.value),
|
|
138
242
|
},
|
|
139
243
|
});
|
|
140
|
-
if (this.
|
|
141
|
-
typeExpression = `{ ${this.
|
|
244
|
+
if (this._discriminator.kind === "syntheticProperty") {
|
|
245
|
+
typeExpression = `{ ${this._discriminator.name}: "${memberType.discriminatorValues[0]}" as const, value: ${typeExpression} }`;
|
|
142
246
|
}
|
|
143
247
|
return typeExpression;
|
|
144
248
|
},
|
|
145
249
|
variables,
|
|
146
250
|
});
|
|
147
251
|
}
|
|
148
|
-
fromRdfExpression(
|
|
149
|
-
return this.
|
|
150
|
-
let typeExpression =
|
|
151
|
-
|
|
152
|
-
|
|
252
|
+
fromRdfExpression({ variables, }) {
|
|
253
|
+
return this.memberTypes.reduce((expression, memberType) => {
|
|
254
|
+
let typeExpression = memberType.fromRdfExpression({
|
|
255
|
+
variables: { ...variables, ignoreRdfType: false },
|
|
256
|
+
});
|
|
257
|
+
if (this._discriminator.kind === "syntheticProperty") {
|
|
258
|
+
typeExpression = `${typeExpression}.map(value => ({ ${this._discriminator.name}: "${memberType.discriminatorValues[0]}" as const, value }) as (${this.name}))`;
|
|
153
259
|
}
|
|
154
|
-
typeExpression = `(${typeExpression} as purify.Either<
|
|
260
|
+
typeExpression = `(${typeExpression} as purify.Either<Error, ${this.name}>)`;
|
|
155
261
|
return expression.length > 0
|
|
156
262
|
? `${expression}.altLazy(() => ${typeExpression})`
|
|
157
263
|
: typeExpression;
|
|
158
264
|
}, "");
|
|
159
265
|
}
|
|
266
|
+
graphqlResolveExpression(_parameters) {
|
|
267
|
+
throw new Error("not implemented");
|
|
268
|
+
}
|
|
160
269
|
hashStatements({ depth, variables, }) {
|
|
161
270
|
const caseBlocks = [];
|
|
162
|
-
for (const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
})
|
|
172
|
-
.join("\n")}; break; }`);
|
|
173
|
-
}
|
|
271
|
+
for (const memberType of this.memberTypes) {
|
|
272
|
+
caseBlocks.push(`${memberType.discriminatorValues.map((discriminatorPropertyValue) => `case "${discriminatorPropertyValue}":`).join("\n")} { ${memberType
|
|
273
|
+
.hashStatements({
|
|
274
|
+
depth: depth + 1,
|
|
275
|
+
variables: {
|
|
276
|
+
hasher: variables.hasher,
|
|
277
|
+
value: `${memberType.payload(variables.value)}`,
|
|
278
|
+
},
|
|
279
|
+
})
|
|
280
|
+
.join("\n")}; break; }`);
|
|
174
281
|
}
|
|
282
|
+
caseBlocks.push(`default: ${variables.value} satisfies never; throw new Error("unrecognized type");`);
|
|
175
283
|
return [
|
|
176
|
-
`switch (${variables.value}
|
|
284
|
+
`switch (${this.discriminatorVariable(variables.value)}) { ${caseBlocks.join("\n")} }`,
|
|
177
285
|
];
|
|
178
286
|
}
|
|
287
|
+
jsonUiSchemaElement() {
|
|
288
|
+
return Maybe.empty();
|
|
289
|
+
}
|
|
179
290
|
jsonZodSchema({ variables, }) {
|
|
180
|
-
switch (this.
|
|
181
|
-
case "
|
|
182
|
-
return `${variables.zod}.discriminatedUnion("${this.
|
|
183
|
-
.map((memberType) => memberType.jsonZodSchema({ variables }))
|
|
291
|
+
switch (this._discriminator.kind) {
|
|
292
|
+
case "sharedProperty":
|
|
293
|
+
return `${variables.zod}.discriminatedUnion("${this._discriminator.name}", [${this.memberTypes
|
|
294
|
+
.map((memberType) => memberType.jsonZodSchema({ context: "type", variables }))
|
|
184
295
|
.join(", ")}])`;
|
|
185
|
-
case "
|
|
186
|
-
return `${variables.zod}.discriminatedUnion("${this.
|
|
187
|
-
.map((
|
|
296
|
+
case "syntheticProperty":
|
|
297
|
+
return `${variables.zod}.discriminatedUnion("${this._discriminator.name}", [${this.memberTypes
|
|
298
|
+
.map((memberType) => `${variables.zod}.object({ ${this._discriminator.name}: ${variables.zod}.literal("${memberType.discriminatorValues[0]}"), value: ${memberType.jsonZodSchema({ context: "type", variables })} })`)
|
|
299
|
+
.join(", ")}])`;
|
|
300
|
+
case "typeof":
|
|
301
|
+
return `${variables.zod}.union([${this.memberTypes
|
|
302
|
+
.map((memberType) => memberType.jsonZodSchema({ context: "type", variables }))
|
|
188
303
|
.join(", ")}])`;
|
|
189
304
|
default:
|
|
190
|
-
throw
|
|
305
|
+
throw this._discriminator;
|
|
191
306
|
}
|
|
192
307
|
}
|
|
308
|
+
snippetDeclarations(parameters) {
|
|
309
|
+
const { recursionStack } = parameters;
|
|
310
|
+
if (recursionStack.some((type) => Object.is(type, this))) {
|
|
311
|
+
return [];
|
|
312
|
+
}
|
|
313
|
+
recursionStack.push(this);
|
|
314
|
+
const result = this.memberTypes.flatMap((memberType) => memberType.snippetDeclarations(parameters));
|
|
315
|
+
invariant(Object.is(recursionStack.pop(), this));
|
|
316
|
+
return result;
|
|
317
|
+
}
|
|
193
318
|
sparqlConstructTemplateTriples(parameters) {
|
|
194
|
-
return this.memberTypes.reduce((array, memberType) => array.concat(memberType.sparqlConstructTemplateTriples(
|
|
319
|
+
return this.memberTypes.reduce((array, memberType) => array.concat(memberType.sparqlConstructTemplateTriples({
|
|
320
|
+
...parameters,
|
|
321
|
+
allowIgnoreRdfType: false,
|
|
322
|
+
})), []);
|
|
195
323
|
}
|
|
196
324
|
sparqlWherePatterns(parameters) {
|
|
197
325
|
let haveEmptyGroup = false; // Only need one empty group
|
|
198
326
|
return [
|
|
199
327
|
`{ patterns: [${this.memberTypes
|
|
200
328
|
.flatMap((memberType) => {
|
|
201
|
-
const groupPatterns = memberType.sparqlWherePatterns(
|
|
329
|
+
const groupPatterns = memberType.sparqlWherePatterns({
|
|
330
|
+
...parameters,
|
|
331
|
+
allowIgnoreRdfType: false,
|
|
332
|
+
});
|
|
202
333
|
if (groupPatterns.length === 0) {
|
|
203
334
|
if (haveEmptyGroup) {
|
|
204
335
|
return [];
|
|
@@ -217,23 +348,24 @@ ${this.memberTypeTraits
|
|
|
217
348
|
];
|
|
218
349
|
}
|
|
219
350
|
toJsonExpression({ variables, }) {
|
|
220
|
-
switch (this.
|
|
221
|
-
case "
|
|
351
|
+
switch (this._discriminator.kind) {
|
|
352
|
+
case "sharedProperty":
|
|
353
|
+
case "typeof":
|
|
222
354
|
return this.ternaryExpression({
|
|
223
|
-
memberTypeExpression: (
|
|
355
|
+
memberTypeExpression: (memberType) => memberType.toJsonExpression({
|
|
224
356
|
variables: {
|
|
225
357
|
...variables,
|
|
226
|
-
value:
|
|
358
|
+
value: memberType.payload(variables.value),
|
|
227
359
|
},
|
|
228
360
|
}),
|
|
229
361
|
variables,
|
|
230
362
|
});
|
|
231
|
-
case "
|
|
363
|
+
case "syntheticProperty":
|
|
232
364
|
return this.ternaryExpression({
|
|
233
|
-
memberTypeExpression: (
|
|
365
|
+
memberTypeExpression: (memberType) => `{ ${this._discriminator.name}: "${memberType.discriminatorValues[0]}" as const, value: ${memberType.toJsonExpression({
|
|
234
366
|
variables: {
|
|
235
367
|
...variables,
|
|
236
|
-
value:
|
|
368
|
+
value: memberType.payload(variables.value),
|
|
237
369
|
},
|
|
238
370
|
})} }`,
|
|
239
371
|
variables,
|
|
@@ -242,36 +374,81 @@ ${this.memberTypeTraits
|
|
|
242
374
|
}
|
|
243
375
|
toRdfExpression({ variables, }) {
|
|
244
376
|
return this.ternaryExpression({
|
|
245
|
-
memberTypeExpression: (
|
|
377
|
+
memberTypeExpression: (memberType) => memberType.toRdfExpression({
|
|
246
378
|
variables: {
|
|
247
379
|
...variables,
|
|
248
|
-
value:
|
|
380
|
+
value: memberType.payload(variables.value),
|
|
249
381
|
},
|
|
250
382
|
}),
|
|
251
383
|
variables,
|
|
252
384
|
});
|
|
253
385
|
}
|
|
254
|
-
useImports(
|
|
255
|
-
return this.memberTypes.flatMap((memberType) => memberType.useImports(
|
|
386
|
+
useImports(parameters) {
|
|
387
|
+
return this.memberTypes.flatMap((memberType) => memberType.useImports(parameters));
|
|
388
|
+
}
|
|
389
|
+
discriminatorVariable(variableValue) {
|
|
390
|
+
switch (this._discriminator.kind) {
|
|
391
|
+
case "sharedProperty":
|
|
392
|
+
case "syntheticProperty":
|
|
393
|
+
return `${variableValue}.${this._discriminator.name}`;
|
|
394
|
+
case "typeof":
|
|
395
|
+
return `(typeof ${variableValue})`;
|
|
396
|
+
}
|
|
256
397
|
}
|
|
257
398
|
ternaryExpression({ memberTypeExpression, variables, }) {
|
|
258
|
-
return this.
|
|
399
|
+
return this.memberTypes.reduce((expression, memberType) => {
|
|
259
400
|
if (expression.length === 0) {
|
|
260
|
-
return memberTypeExpression(
|
|
401
|
+
return memberTypeExpression(memberType);
|
|
261
402
|
}
|
|
262
|
-
return `(${
|
|
263
|
-
.map((value) => `${variables.value}
|
|
264
|
-
.join(" || ")}) ? ${memberTypeExpression(
|
|
403
|
+
return `(${memberType.discriminatorValues
|
|
404
|
+
.map((value) => `${this.discriminatorVariable(variables.value)} === "${value}"`)
|
|
405
|
+
.join(" || ")}) ? ${memberTypeExpression(memberType)} : ${expression}`;
|
|
265
406
|
}, "");
|
|
266
407
|
}
|
|
267
408
|
}
|
|
409
|
+
__decorate([
|
|
410
|
+
Memoize()
|
|
411
|
+
], UnionType.prototype, "conversions", null);
|
|
268
412
|
__decorate([
|
|
269
413
|
Memoize()
|
|
270
414
|
], UnionType.prototype, "discriminatorProperty", null);
|
|
271
415
|
__decorate([
|
|
272
416
|
Memoize()
|
|
273
|
-
], UnionType.prototype, "
|
|
417
|
+
], UnionType.prototype, "equalsFunction", null);
|
|
418
|
+
__decorate([
|
|
419
|
+
Memoize()
|
|
420
|
+
], UnionType.prototype, "jsonName", null);
|
|
421
|
+
__decorate([
|
|
422
|
+
Memoize()
|
|
423
|
+
], UnionType.prototype, "mutable", null);
|
|
274
424
|
__decorate([
|
|
275
425
|
Memoize()
|
|
276
|
-
], UnionType.prototype, "
|
|
426
|
+
], UnionType.prototype, "name", null);
|
|
427
|
+
function sharedDiscriminatorProperty(memberTypes) {
|
|
428
|
+
let sharedDiscriminatorProperty;
|
|
429
|
+
for (const memberType of memberTypes) {
|
|
430
|
+
const memberTypeDiscriminatorProperty = memberType.discriminatorProperty.extract();
|
|
431
|
+
if (!memberTypeDiscriminatorProperty) {
|
|
432
|
+
sharedDiscriminatorProperty = undefined;
|
|
433
|
+
break;
|
|
434
|
+
}
|
|
435
|
+
if (!sharedDiscriminatorProperty) {
|
|
436
|
+
sharedDiscriminatorProperty = {
|
|
437
|
+
name: memberTypeDiscriminatorProperty.name,
|
|
438
|
+
ownValues: memberTypeDiscriminatorProperty.ownValues.concat(),
|
|
439
|
+
descendantValues: memberTypeDiscriminatorProperty.descendantValues.concat(),
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
else if (memberTypeDiscriminatorProperty.name === sharedDiscriminatorProperty.name) {
|
|
443
|
+
sharedDiscriminatorProperty.descendantValues =
|
|
444
|
+
sharedDiscriminatorProperty.descendantValues.concat(memberTypeDiscriminatorProperty.descendantValues);
|
|
445
|
+
sharedDiscriminatorProperty.ownValues =
|
|
446
|
+
sharedDiscriminatorProperty.ownValues.concat(memberTypeDiscriminatorProperty.ownValues);
|
|
447
|
+
}
|
|
448
|
+
else {
|
|
449
|
+
return undefined;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
return sharedDiscriminatorProperty;
|
|
453
|
+
}
|
|
277
454
|
//# sourceMappingURL=UnionType.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Type } from "../Type.js";
|
|
2
|
+
import { ShaclProperty } from "./ShaclProperty.js";
|
|
3
|
+
export declare class EagerShaclProperty<TypeT extends Type> extends ShaclProperty<TypeT> {
|
|
4
|
+
readonly mutable: boolean;
|
|
5
|
+
readonly recursive: boolean;
|
|
6
|
+
constructor({ mutable, recursive, ...superParameters }: {
|
|
7
|
+
mutable: boolean;
|
|
8
|
+
recursive: boolean;
|
|
9
|
+
} & ConstructorParameters<typeof ShaclProperty<TypeT>>[0]);
|
|
10
|
+
get graphqlField(): ShaclProperty<TypeT>["graphqlField"];
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=EagerShaclProperty.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { Maybe } from "purify-ts";
|
|
8
|
+
import { Memoize } from "typescript-memoize";
|
|
9
|
+
import { ShaclProperty } from "./ShaclProperty.js";
|
|
10
|
+
export class EagerShaclProperty extends ShaclProperty {
|
|
11
|
+
mutable;
|
|
12
|
+
recursive;
|
|
13
|
+
constructor({ mutable, recursive, ...superParameters }) {
|
|
14
|
+
super(superParameters);
|
|
15
|
+
this.mutable = mutable;
|
|
16
|
+
this.recursive = recursive;
|
|
17
|
+
}
|
|
18
|
+
get graphqlField() {
|
|
19
|
+
return Maybe.of({
|
|
20
|
+
description: this.comment.map(JSON.stringify).extract(),
|
|
21
|
+
name: this.name,
|
|
22
|
+
resolve: `(source) => ${this.type.graphqlResolveExpression({ variables: { value: `source.${this.name}` } })}`,
|
|
23
|
+
type: this.type.graphqlName.toString(),
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
__decorate([
|
|
28
|
+
Memoize()
|
|
29
|
+
], EagerShaclProperty.prototype, "graphqlField", null);
|
|
30
|
+
//# sourceMappingURL=EagerShaclProperty.js.map
|