@shaclmate/compiler 4.0.39 → 4.0.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/generators/ts/AbstractCollectionType.d.ts +1 -1
- package/dist/generators/ts/AbstractCollectionType.js +10 -10
- package/dist/generators/ts/AbstractContainerType.d.ts +4 -5
- package/dist/generators/ts/AbstractContainerType.js +4 -5
- package/dist/generators/ts/AbstractDateType.d.ts +3 -3
- package/dist/generators/ts/AbstractDateType.js +2 -2
- package/dist/generators/ts/AbstractLazyObjectType.d.ts +8 -8
- package/dist/generators/ts/AbstractLazyObjectType.js +19 -19
- package/dist/generators/ts/AbstractNumericType.d.ts +1 -1
- package/dist/generators/ts/AbstractNumericType.js +3 -3
- package/dist/generators/ts/AbstractObjectSetType.d.ts +10 -9
- package/dist/generators/ts/AbstractObjectSetType.js +2 -2
- package/dist/generators/ts/AbstractPrimitiveType.js +2 -2
- package/dist/generators/ts/AbstractTermType.js +2 -2
- package/dist/generators/ts/AbstractType.d.ts +15 -10
- package/dist/generators/ts/AbstractType.js +6 -1
- package/dist/generators/ts/BigDecimalType.d.ts +1 -1
- package/dist/generators/ts/BigDecimalType.js +2 -2
- package/dist/generators/ts/BigIntType.js +2 -2
- package/dist/generators/ts/BlankNodeType.d.ts +3 -3
- package/dist/generators/ts/BlankNodeType.js +11 -11
- package/dist/generators/ts/BooleanType.d.ts +2 -2
- package/dist/generators/ts/BooleanType.js +10 -5
- package/dist/generators/ts/DefaultValueType.d.ts +1 -1
- package/dist/generators/ts/DefaultValueType.js +8 -9
- package/dist/generators/ts/GraphqlSchema.d.ts +4 -4
- package/dist/generators/ts/GraphqlSchema.js +4 -4
- package/dist/generators/ts/IdentifierType.d.ts +3 -3
- package/dist/generators/ts/IdentifierType.js +13 -13
- package/dist/generators/ts/IriType.d.ts +2 -2
- package/dist/generators/ts/IriType.js +17 -17
- package/dist/generators/ts/LazyObjectOptionType.d.ts +1 -0
- package/dist/generators/ts/LazyObjectOptionType.js +6 -6
- package/dist/generators/ts/LazyObjectSetType.js +5 -5
- package/dist/generators/ts/LazyObjectType.js +4 -4
- package/dist/generators/ts/ListType.d.ts +4 -5
- package/dist/generators/ts/ListType.js +3 -4
- package/dist/generators/ts/LiteralType.d.ts +1 -1
- package/dist/generators/ts/LiteralType.js +5 -5
- package/dist/generators/ts/{NamedObjectType.d.ts → ObjectType.d.ts} +23 -24
- package/dist/generators/ts/ObjectType.js +350 -0
- package/dist/generators/ts/ObjectUnionType.d.ts +20 -0
- package/dist/generators/ts/{NamedObjectUnionType.js → ObjectUnionType.js} +50 -58
- package/dist/generators/ts/OptionType.d.ts +1 -1
- package/dist/generators/ts/OptionType.js +10 -10
- package/dist/generators/ts/RdfjsDatasetObjectSetType.js +8 -8
- package/dist/generators/ts/SparqlObjectSetType.js +2 -2
- package/dist/generators/ts/StringType.d.ts +2 -2
- package/dist/generators/ts/StringType.js +10 -5
- package/dist/generators/ts/TermType.d.ts +2 -2
- package/dist/generators/ts/TermType.js +12 -12
- package/dist/generators/ts/TsGenerator.js +12 -9
- package/dist/generators/ts/Type.d.ts +4 -5
- package/dist/generators/ts/TypeFactory.d.ts +7 -8
- package/dist/generators/ts/TypeFactory.js +61 -62
- package/dist/generators/ts/{AbstractUnionType.d.ts → UnionType.d.ts} +33 -5
- package/dist/generators/ts/{AbstractUnionType.js → UnionType.js} +262 -58
- package/dist/generators/ts/ZodGenerator.js +7 -9
- package/dist/generators/ts/{_NamedObjectType → _ObjectType}/AbstractProperty.d.ts +6 -6
- package/dist/generators/ts/{_NamedObjectType → _ObjectType}/AbstractProperty.js +3 -3
- package/dist/generators/ts/{_NamedObjectType → _ObjectType}/DiscriminantProperty.d.ts +1 -1
- package/dist/generators/ts/{_NamedObjectType → _ObjectType}/DiscriminantProperty.js +8 -8
- package/dist/generators/ts/{_NamedObjectType → _ObjectType}/IdentifierProperty.d.ts +1 -5
- package/dist/generators/ts/{_NamedObjectType → _ObjectType}/IdentifierProperty.js +15 -10
- package/dist/generators/ts/_ObjectType/ObjectType_createFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_createFunctionDeclaration.js → _ObjectType/ObjectType_createFunctionDeclaration.js} +6 -6
- package/dist/generators/ts/_ObjectType/ObjectType_equalsFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_equalsFunctionDeclaration.js → _ObjectType/ObjectType_equalsFunctionDeclaration.js} +4 -4
- package/dist/generators/ts/_ObjectType/ObjectType_filterFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_filterFunctionDeclaration.js → _ObjectType/ObjectType_filterFunctionDeclaration.js} +3 -3
- package/dist/generators/ts/_ObjectType/ObjectType_filterTypeDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_filterTypeDeclaration.js → _ObjectType/ObjectType_filterTypeDeclaration.js} +3 -3
- package/dist/generators/ts/_ObjectType/ObjectType_focusSparqlConstructTriplesFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_focusSparqlConstructTriplesFunctionDeclaration.js → _ObjectType/ObjectType_focusSparqlConstructTriplesFunctionDeclaration.js} +3 -3
- package/dist/generators/ts/_ObjectType/ObjectType_focusSparqlWherePatternsFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_focusSparqlWherePatternsFunctionDeclaration.js → _ObjectType/ObjectType_focusSparqlWherePatternsFunctionDeclaration.js} +3 -3
- package/dist/generators/ts/_ObjectType/ObjectType_fromJsonFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_fromJsonFunctionDeclaration.js → _ObjectType/ObjectType_fromJsonFunctionDeclaration.js} +4 -4
- package/dist/generators/ts/_ObjectType/ObjectType_fromRdfResourceFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_fromRdfResourceFunctionDeclaration.js → _ObjectType/ObjectType_fromRdfResourceFunctionDeclaration.js} +4 -4
- package/dist/generators/ts/_ObjectType/ObjectType_fromRdfResourceValuesFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/_ObjectType/ObjectType_fromRdfResourceValuesFunctionDeclaration.js +15 -0
- package/dist/generators/ts/_ObjectType/ObjectType_fromRdfTypeVariableStatement.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_fromRdfTypeVariableStatement.js → _ObjectType/ObjectType_fromRdfTypeVariableStatement.js} +2 -2
- package/dist/generators/ts/_ObjectType/ObjectType_graphqlTypeVariableStatement.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_graphqlTypeVariableStatement.js → _ObjectType/ObjectType_graphqlTypeVariableStatement.js} +4 -4
- package/dist/generators/ts/_ObjectType/ObjectType_hashFunctionDeclarations.d.ts +4 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_hashFunctionDeclarations.js → _ObjectType/ObjectType_hashFunctionDeclarations.js} +6 -6
- package/dist/generators/ts/_ObjectType/ObjectType_interfaceDeclaration.d.ts +4 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_interfaceDeclaration.js → _ObjectType/ObjectType_interfaceDeclaration.js} +4 -4
- package/dist/generators/ts/_ObjectType/ObjectType_isTypeFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_isTypeFunctionDeclaration.js → _ObjectType/ObjectType_isTypeFunctionDeclaration.js} +3 -3
- package/dist/generators/ts/_ObjectType/ObjectType_jsonParseFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_jsonParseFunctionDeclaration.js → _ObjectType/ObjectType_jsonParseFunctionDeclaration.js} +2 -2
- package/dist/generators/ts/_ObjectType/ObjectType_jsonSchemaFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_jsonSchemaFunctionDeclaration.js → _ObjectType/ObjectType_jsonSchemaFunctionDeclaration.js} +2 -2
- package/dist/generators/ts/_ObjectType/ObjectType_jsonTypeAliasDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_jsonTypeAliasDeclaration.js → _ObjectType/ObjectType_jsonTypeAliasDeclaration.js} +2 -2
- package/dist/generators/ts/_ObjectType/ObjectType_jsonUiSchemaFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_jsonUiSchemaFunctionDeclaration.js → _ObjectType/ObjectType_jsonUiSchemaFunctionDeclaration.js} +4 -4
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_objectSetMethodNames.d.ts → _ObjectType/ObjectType_objectSetMethodNames.d.ts} +3 -3
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_objectSetMethodNames.js → _ObjectType/ObjectType_objectSetMethodNames.js} +4 -4
- package/dist/generators/ts/_ObjectType/ObjectType_schemaVariableStatement.d.ts +5 -0
- package/dist/generators/ts/_ObjectType/ObjectType_schemaVariableStatement.js +14 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_sparqlConstructQueryFunctionDeclaration.d.ts → _ObjectType/ObjectType_sparqlConstructQueryFunctionDeclaration.d.ts} +3 -3
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_sparqlConstructQueryFunctionDeclaration.js → _ObjectType/ObjectType_sparqlConstructQueryFunctionDeclaration.js} +5 -5
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_sparqlConstructQueryStringFunctionDeclaration.d.ts → _ObjectType/ObjectType_sparqlConstructQueryStringFunctionDeclaration.d.ts} +3 -3
- package/dist/generators/ts/_ObjectType/ObjectType_sparqlConstructQueryStringFunctionDeclaration.js +12 -0
- package/dist/generators/ts/_ObjectType/ObjectType_toJsonFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_toJsonFunctionDeclaration.js → _ObjectType/ObjectType_toJsonFunctionDeclaration.js} +4 -4
- package/dist/generators/ts/_ObjectType/ObjectType_toRdfResourceFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_toRdfResourceFunctionDeclaration.js → _ObjectType/ObjectType_toRdfResourceFunctionDeclaration.js} +4 -4
- package/dist/generators/ts/_ObjectType/ObjectType_toStringFunctionDeclarations.d.ts +4 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_toStringFunctionDeclarations.js → _ObjectType/ObjectType_toStringFunctionDeclarations.js} +6 -6
- package/dist/generators/ts/_ObjectType/ObjectType_valueSparqlConstructTriplesFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_valueSparqlConstructTriplesFunctionDeclaration.js → _ObjectType/ObjectType_valueSparqlConstructTriplesFunctionDeclaration.js} +3 -3
- package/dist/generators/ts/_ObjectType/ObjectType_valueSparqlWherePatternsFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_NamedObjectType/NamedObjectType_valueSparqlWherePatternsFunctionDeclaration.js → _ObjectType/ObjectType_valueSparqlWherePatternsFunctionDeclaration.js} +3 -3
- package/dist/generators/ts/{_NamedObjectType → _ObjectType}/ShaclProperty.js +7 -7
- package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.d.ts +4 -0
- package/dist/generators/ts/{_NamedObjectType → _ObjectType}/identifierTypeDeclarations.js +4 -2
- package/dist/input/generated.d.ts +2 -2
- package/dist/input/generated.js +2 -2
- package/package.json +4 -4
- package/dist/generators/ts/AbstractNamedUnionType.d.ts +0 -30
- package/dist/generators/ts/AbstractNamedUnionType.js +0 -190
- package/dist/generators/ts/AnonymousUnionType.d.ts +0 -27
- package/dist/generators/ts/AnonymousUnionType.js +0 -59
- package/dist/generators/ts/NamedObjectType.js +0 -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_equalsFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_filterFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_filterTypeDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlConstructTriplesFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlWherePatternsFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromJsonFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceValuesFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceValuesFunctionDeclaration.js +0 -15
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfTypeVariableStatement.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_graphqlTypeVariableStatement.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_hashFunctionDeclarations.d.ts +0 -4
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_interfaceDeclaration.d.ts +0 -4
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_isTypeFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonParseFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonSchemaFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonTypeAliasDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonUiSchemaFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_schemaVariableStatement.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_schemaVariableStatement.js +0 -12
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_sparqlConstructQueryStringFunctionDeclaration.js +0 -12
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toJsonFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toRdfResourceFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toStringFunctionDeclarations.d.ts +0 -4
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_valueSparqlConstructTriplesFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_valueSparqlWherePatternsFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/identifierTypeDeclarations.d.ts +0 -4
- /package/dist/generators/ts/{_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);
|
|
@@ -70,10 +74,9 @@ export class AbstractUnionType extends AbstractType {
|
|
|
70
74
|
}
|
|
71
75
|
if (discriminant.kind === "Intrinsic" && !json) {
|
|
72
76
|
switch (member.type.kind) {
|
|
73
|
-
case "
|
|
74
|
-
case "
|
|
75
|
-
|
|
76
|
-
return code `${member.type.name}.is${member.type.name}(${instance})`;
|
|
77
|
+
case "Object":
|
|
78
|
+
case "ObjectUnion":
|
|
79
|
+
return code `${member.type.alias.unsafeCoerce()}.is${member.type.alias.unsafeCoerce()}(${instance})`;
|
|
77
80
|
}
|
|
78
81
|
}
|
|
79
82
|
const discriminantName = json
|
|
@@ -134,17 +137,37 @@ export class AbstractUnionType extends AbstractType {
|
|
|
134
137
|
code: code `${this.reusables.snippets.identityConversionFunction}`,
|
|
135
138
|
sourceTypes: this.discriminant.kind === "Typeof"
|
|
136
139
|
? this.members.map(({ primaryDiscriminantValue, type }) => ({
|
|
137
|
-
|
|
140
|
+
expression: type.expression,
|
|
138
141
|
typeof: primaryDiscriminantValue,
|
|
139
142
|
}))
|
|
140
143
|
: [
|
|
141
144
|
{
|
|
142
|
-
|
|
145
|
+
expression: this.expression,
|
|
143
146
|
typeof: "object",
|
|
144
147
|
},
|
|
145
148
|
],
|
|
146
149
|
});
|
|
147
150
|
}
|
|
151
|
+
get declaration() {
|
|
152
|
+
const alias = this.alias.extract();
|
|
153
|
+
if (!alias) {
|
|
154
|
+
return Maybe.empty();
|
|
155
|
+
}
|
|
156
|
+
const declarations = [];
|
|
157
|
+
if (this.configuration.features.has("Object.type")) {
|
|
158
|
+
declarations.push(code `export type ${def(alias)} = ${this.inlineExpression};`);
|
|
159
|
+
}
|
|
160
|
+
const staticModuleDeclarations = Object.entries(this.staticModuleDeclarations);
|
|
161
|
+
if (staticModuleDeclarations.length > 0) {
|
|
162
|
+
declarations.push(code `\
|
|
163
|
+
export namespace ${def(alias)} {
|
|
164
|
+
${joinCode(staticModuleDeclarations
|
|
165
|
+
.sort((left, right) => left[0].localeCompare(right[0]))
|
|
166
|
+
.map((_) => _[1]), { on: "\n\n" })}
|
|
167
|
+
}`);
|
|
168
|
+
}
|
|
169
|
+
return Maybe.of(joinCode(declarations, { on: "\n\n" }));
|
|
170
|
+
}
|
|
148
171
|
get discriminantProperty() {
|
|
149
172
|
switch (this.discriminant.kind) {
|
|
150
173
|
case "Extrinsic":
|
|
@@ -174,12 +197,60 @@ export class AbstractUnionType extends AbstractType {
|
|
|
174
197
|
throw this.discriminant;
|
|
175
198
|
}
|
|
176
199
|
}
|
|
200
|
+
get equalsFunction() {
|
|
201
|
+
return this.alias
|
|
202
|
+
.map((alias) => code `${alias}.equals`)
|
|
203
|
+
.orDefault(this.inlineEqualsFunction);
|
|
204
|
+
}
|
|
205
|
+
get filterFunction() {
|
|
206
|
+
return this.alias
|
|
207
|
+
.map((alias) => code `${alias}.filter`)
|
|
208
|
+
.orDefault(this.inlineFilterFunction);
|
|
209
|
+
}
|
|
210
|
+
get filterType() {
|
|
211
|
+
return this.alias
|
|
212
|
+
.map((alias) => code `${alias}.Filter`)
|
|
213
|
+
.orDefault(this.inlineFilterType);
|
|
214
|
+
}
|
|
215
|
+
get graphqlType() {
|
|
216
|
+
const alias = this.alias.extract();
|
|
217
|
+
if (!alias ||
|
|
218
|
+
!this.members.every((member) => member.type.kind === "Object")) {
|
|
219
|
+
throw new Error("not implemented");
|
|
220
|
+
}
|
|
221
|
+
return new AbstractType.GraphqlType(code `${alias}.GraphQL`, this.reusables);
|
|
222
|
+
}
|
|
223
|
+
get hashFunction() {
|
|
224
|
+
return this.alias
|
|
225
|
+
.map((alias) => code `${alias}.hash`)
|
|
226
|
+
.orDefault(this.inlineHashFunction);
|
|
227
|
+
}
|
|
228
|
+
get jsonSchemaFunctionDeclaration() {
|
|
229
|
+
const meta = {
|
|
230
|
+
// id: this.name,
|
|
231
|
+
};
|
|
232
|
+
this.comment.ifJust((description) => {
|
|
233
|
+
meta["description"] = description;
|
|
234
|
+
});
|
|
235
|
+
this.label.ifJust((label) => {
|
|
236
|
+
meta["title"] = label;
|
|
237
|
+
});
|
|
238
|
+
return code `export const schema = () => ${this.inlineJsonSchema}.meta(${meta});`;
|
|
239
|
+
}
|
|
240
|
+
get jsonTypeAliasDeclaration() {
|
|
241
|
+
return code `export type Json = ${this.inlineJsonType.name}`;
|
|
242
|
+
}
|
|
177
243
|
get members() {
|
|
178
244
|
return this.lazyMembers();
|
|
179
245
|
}
|
|
180
246
|
get mutable() {
|
|
181
247
|
return this.members.some((member) => member.type.mutable);
|
|
182
248
|
}
|
|
249
|
+
get expression() {
|
|
250
|
+
return this.alias
|
|
251
|
+
.map((alias) => code `${alias}`)
|
|
252
|
+
.orDefault(this.inlineExpression);
|
|
253
|
+
}
|
|
183
254
|
get referencesObjectType() {
|
|
184
255
|
return this.members.some((member) => member.type.referencesObjectType);
|
|
185
256
|
}
|
|
@@ -204,11 +275,21 @@ export class AbstractUnionType extends AbstractType {
|
|
|
204
275
|
get typeofs() {
|
|
205
276
|
return [...new Set(this.members.flatMap((member) => member.type.typeofs))];
|
|
206
277
|
}
|
|
278
|
+
get valueSparqlConstructTriplesFunction() {
|
|
279
|
+
return this.alias
|
|
280
|
+
.map((alias) => code `${alias}.valueSparqlConstructTriples`)
|
|
281
|
+
.orDefault(this.inlineValueSparqlConstructTriplesFunction);
|
|
282
|
+
}
|
|
283
|
+
get valueSparqlWherePatternsFunction() {
|
|
284
|
+
return this.alias
|
|
285
|
+
.map((alias) => code `${alias}.valueSparqlWherePatterns`)
|
|
286
|
+
.orDefault(this.inlineValueSparqlWherePatternsFunction);
|
|
287
|
+
}
|
|
207
288
|
get inlineEqualsFunction() {
|
|
208
289
|
return code `\
|
|
209
|
-
((left: ${this.
|
|
290
|
+
((left: ${this.expression}, right: ${this.expression}) => {
|
|
210
291
|
${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeCheck(code `left`)} && ${typeCheck(code `right`)}) {
|
|
211
|
-
return ${type.equalsFunction}(${unwrap(code `left`)} as ${type.
|
|
292
|
+
return ${type.equalsFunction}(${unwrap(code `left`)} as ${type.expression}, ${unwrap(code `right`)} as ${type.expression});
|
|
212
293
|
}`))}
|
|
213
294
|
|
|
214
295
|
return ${this.reusables.imports.Left}({ left, right, propertyName: "type", propertyValuesUnequal: { left: typeof left, right: typeof right, type: "boolean" as const }, type: "property" as const });
|
|
@@ -217,7 +298,7 @@ ${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeChe
|
|
|
217
298
|
get inlineFilterFunction() {
|
|
218
299
|
const syntheticNamePrefix = this.configuration.syntheticNamePrefix;
|
|
219
300
|
return code `\
|
|
220
|
-
((filter: ${this.filterType}, value: ${this.
|
|
301
|
+
((filter: ${this.filterType}, value: ${this.expression}) => {
|
|
221
302
|
${joinCode([
|
|
222
303
|
...this.identifierType
|
|
223
304
|
.map((identifierType) => code `\
|
|
@@ -246,7 +327,7 @@ if (filter.on?.[${literalOf(primaryDiscriminantValue)}] !== undefined && ${typeC
|
|
|
246
327
|
}
|
|
247
328
|
get inlineFromJsonFunction() {
|
|
248
329
|
return code `\
|
|
249
|
-
((value: ${this.jsonType().name}): ${this.reusables.imports.Either}<Error, ${this.
|
|
330
|
+
((value: ${this.jsonType().name}): ${this.reusables.imports.Either}<Error, ${this.expression}> => {
|
|
250
331
|
${joinCode(this.members.map(({ jsonType, jsonTypeCheck, type, unwrap, wrap }) => code `if (${jsonTypeCheck(code `value`)}) { return ${type.fromJsonExpression({
|
|
251
332
|
variables: {
|
|
252
333
|
value: code `(${unwrap(code `value`)} as ${jsonType})`,
|
|
@@ -286,19 +367,19 @@ ${joinCode(this.members.map(({ jsonType, jsonTypeCheck, type, unwrap, wrap }) =>
|
|
|
286
367
|
if (this.discriminant.kind === "Extrinsic" ||
|
|
287
368
|
(this.discriminant.kind === "Hybrid" &&
|
|
288
369
|
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.
|
|
370
|
+
typeExpression = code `${typeExpression}.map(values => values.map(value => ({ ${this.discriminant.name}: ${literalOf(primaryDiscriminantValue)} as const, value }) as (${this.expression})))`;
|
|
290
371
|
}
|
|
291
|
-
typeExpression = code `(${typeExpression} as ${this.reusables.imports.Either}<Error, ${this.reusables.imports.Resource}.Values<${this.
|
|
372
|
+
typeExpression = code `(${typeExpression} as ${this.reusables.imports.Either}<Error, ${this.reusables.imports.Resource}.Values<${this.expression}>>)`;
|
|
292
373
|
return expression !== null
|
|
293
374
|
? code `${expression}.altLazy(() => ${typeExpression})`
|
|
294
375
|
: typeExpression;
|
|
295
376
|
}, null)}.chain(values => values.head());
|
|
296
377
|
}))
|
|
297
|
-
) satisfies ${this.reusables.snippets.FromRdfResourceValuesFunction}<${this.
|
|
378
|
+
) satisfies ${this.reusables.snippets.FromRdfResourceValuesFunction}<${this.expression}>)`;
|
|
298
379
|
}
|
|
299
380
|
get inlineHashFunction() {
|
|
300
381
|
return code `\
|
|
301
|
-
(<HasherT extends ${this.reusables.snippets.Hasher}>(hasher: HasherT, value: ${this.
|
|
382
|
+
(<HasherT extends ${this.reusables.snippets.Hasher}>(hasher: HasherT, value: ${this.expression}): HasherT => {
|
|
302
383
|
${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeCheck(code `value`)}) { return ${type.hashFunction}(hasher, ${unwrap(code `value`)}); }`))}
|
|
303
384
|
return hasher;
|
|
304
385
|
})`;
|
|
@@ -356,30 +437,30 @@ ${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeChe
|
|
|
356
437
|
throw discriminant;
|
|
357
438
|
}
|
|
358
439
|
}
|
|
359
|
-
get
|
|
440
|
+
get inlineExpression() {
|
|
360
441
|
const discriminant = this.discriminant; // To get type narrowing to work
|
|
361
442
|
switch (discriminant.kind) {
|
|
362
443
|
case "Extrinsic":
|
|
363
|
-
return code `(${joinCode(this.members.map(({ type, primaryDiscriminantValue }) => code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${type.
|
|
444
|
+
return code `(${joinCode(this.members.map(({ type, primaryDiscriminantValue }) => code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${type.expression} }`), { on: "|" })})`;
|
|
364
445
|
case "Hybrid":
|
|
365
446
|
return code `(${joinCode(this.members.map(({ primaryDiscriminantValue, type }, memberI) => {
|
|
366
447
|
switch (discriminant.memberValues[memberI].kind) {
|
|
367
448
|
case "Extrinsic":
|
|
368
|
-
return code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${type.
|
|
449
|
+
return code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${type.expression} }`;
|
|
369
450
|
case "Intrinsic":
|
|
370
|
-
return code `${type.
|
|
451
|
+
return code `${type.expression}`;
|
|
371
452
|
default:
|
|
372
453
|
throw new Error();
|
|
373
454
|
}
|
|
374
455
|
}), { on: "|" })})`;
|
|
375
456
|
case "Intrinsic":
|
|
376
|
-
// If every type shares a discriminant (e.g., RDF/JS "termType" or generated
|
|
457
|
+
// If every type shares a discriminant (e.g., RDF/JS "termType" or generated ObjectType "type"),
|
|
377
458
|
// just join their names with "|"
|
|
378
|
-
return code `(${joinCode(this.members.map(({ type }) => code `${type.
|
|
459
|
+
return code `(${joinCode(this.members.map(({ type }) => code `${type.expression}`), { on: "|" })})`;
|
|
379
460
|
case "Typeof":
|
|
380
461
|
// The type.name may include literal values, but they should still be unambiguous with other member types since the typeofs
|
|
381
462
|
// of the different member types are known to be different.
|
|
382
|
-
return code `(${joinCode(this.members.map(({ type }) => code `${type.
|
|
463
|
+
return code `(${joinCode(this.members.map(({ type }) => code `${type.expression}`), { on: "|" })})`;
|
|
383
464
|
default:
|
|
384
465
|
discriminant;
|
|
385
466
|
throw new Error("should never reach this point");
|
|
@@ -387,7 +468,7 @@ ${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeChe
|
|
|
387
468
|
}
|
|
388
469
|
get inlineToJsonFunction() {
|
|
389
470
|
return code `\
|
|
390
|
-
((value: ${this.
|
|
471
|
+
((value: ${this.expression}): ${this.jsonType().name} => {
|
|
391
472
|
${joinCode(this.members.map(({ typeCheck, typeToJsonExpression, unwrap, wrap }) => code `if (${typeCheck(code `value`)}) { return ${wrap(typeToJsonExpression(unwrap(code `value`)))}; }`))}
|
|
392
473
|
|
|
393
474
|
throw new Error("unable to serialize to JSON");
|
|
@@ -419,11 +500,11 @@ ${joinCode(this.members.map(({ type, unwrap, typeCheck }) => code `if (${typeChe
|
|
|
419
500
|
})}; }`))}
|
|
420
501
|
|
|
421
502
|
throw new Error("unable to serialize to RDF");
|
|
422
|
-
}) satisfies ${this.reusables.snippets.ToRdfResourceValuesFunction}<${this.
|
|
503
|
+
}) satisfies ${this.reusables.snippets.ToRdfResourceValuesFunction}<${this.expression}>)`;
|
|
423
504
|
}
|
|
424
505
|
get inlineToStringFunction() {
|
|
425
506
|
return code `\
|
|
426
|
-
((value: ${this.
|
|
507
|
+
((value: ${this.expression}): string => {
|
|
427
508
|
${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeCheck(code `value`)}) { return ${type.toStringExpression({
|
|
428
509
|
variables: { value: unwrap(code `value`) },
|
|
429
510
|
})}; }`))}
|
|
@@ -459,50 +540,180 @@ unionPatterns.push({ patterns: ${type.valueSparqlWherePatternsFunction}({ ...oth
|
|
|
459
540
|
type: type.schema,
|
|
460
541
|
}}`), { on: "," })} }`);
|
|
461
542
|
}
|
|
543
|
+
get staticModuleDeclarations() {
|
|
544
|
+
const alias = this.alias.unsafeCoerce();
|
|
545
|
+
const staticModuleDeclarations = {};
|
|
546
|
+
if (this.configuration.features.has("Object.equals")) {
|
|
547
|
+
staticModuleDeclarations[`equals`] =
|
|
548
|
+
code `export const equals = ${this.inlineEqualsFunction};`;
|
|
549
|
+
}
|
|
550
|
+
if (this.configuration.features.has("Object.filter")) {
|
|
551
|
+
staticModuleDeclarations[`Filter`] =
|
|
552
|
+
code `export type Filter = ${this.inlineFilterType};`;
|
|
553
|
+
staticModuleDeclarations[`filter`] =
|
|
554
|
+
code `export const filter = ${this.inlineFilterFunction};`;
|
|
555
|
+
}
|
|
556
|
+
if (this.configuration.features.has("Object.hash")) {
|
|
557
|
+
staticModuleDeclarations[`hash`] =
|
|
558
|
+
code `export const hash = ${this.inlineHashFunction};`;
|
|
559
|
+
}
|
|
560
|
+
if (this.configuration.features.has("Object.JSON.type")) {
|
|
561
|
+
staticModuleDeclarations[`Json.type`] =
|
|
562
|
+
code `${this.jsonTypeAliasDeclaration}`;
|
|
563
|
+
}
|
|
564
|
+
if (this.configuration.features.has("Object.JSON.schema")) {
|
|
565
|
+
staticModuleDeclarations[`Json.namespace`] = code `\
|
|
566
|
+
export namespace Json {
|
|
567
|
+
${this.jsonSchemaFunctionDeclaration}
|
|
568
|
+
|
|
569
|
+
export function parse(json: unknown): ${this.reusables.imports.Either}<Error, Json> {
|
|
570
|
+
const jsonSafeParseResult = schema().safeParse(json);
|
|
571
|
+
if (!jsonSafeParseResult.success) { return ${this.reusables.imports.Left}(jsonSafeParseResult.error); }
|
|
572
|
+
return ${this.reusables.imports.Right}(jsonSafeParseResult.data);
|
|
573
|
+
}
|
|
574
|
+
}`;
|
|
575
|
+
}
|
|
576
|
+
if (this.configuration.features.has("Object.fromJson")) {
|
|
577
|
+
staticModuleDeclarations[`fromJson`] =
|
|
578
|
+
code `export const fromJson = ${this.inlineFromJsonFunction};`;
|
|
579
|
+
}
|
|
580
|
+
if (this.configuration.features.has("Object.fromRdf")) {
|
|
581
|
+
staticModuleDeclarations[`fromRdfResourceValues`] =
|
|
582
|
+
code `export const fromRdfResourceValues: ${this.reusables.snippets.FromRdfResourceValuesFunction}<${alias}> = ${this.inlineFromRdfResourceValuesFunction};`;
|
|
583
|
+
}
|
|
584
|
+
if (this.configuration.features.has("Object.toJson")) {
|
|
585
|
+
staticModuleDeclarations[`toJson`] =
|
|
586
|
+
code `export const toJson = ${this.inlineToJsonFunction};`;
|
|
587
|
+
}
|
|
588
|
+
if (this.configuration.features.has("Object.toRdf")) {
|
|
589
|
+
staticModuleDeclarations[`toRdfResourceValues`] =
|
|
590
|
+
code `export const toRdfResourceValues = ${this.inlineToRdfResourceValuesFunction};`;
|
|
591
|
+
}
|
|
592
|
+
if (this.configuration.features.has("Object.SPARQL")) {
|
|
593
|
+
staticModuleDeclarations[`valueSparqlConstructTriples`] =
|
|
594
|
+
code `export const valueSparqlConstructTriples: ${this.reusables.snippets.ValueSparqlConstructTriplesFunction}<${this.filterType}, ${this.schemaType}> = ${this.inlineValueSparqlConstructTriplesFunction};`;
|
|
595
|
+
staticModuleDeclarations[`valueSparqlWherePatterns`] =
|
|
596
|
+
code `export const valueSparqlWherePatterns: ${this.reusables.snippets.ValueSparqlWherePatternsFunction}<${this.filterType}, ${this.schemaType}> = ${this.inlineValueSparqlWherePatternsFunction};`;
|
|
597
|
+
}
|
|
598
|
+
if (this.configuration.features.has("Object.toString")) {
|
|
599
|
+
const syntheticNamePrefix = this.configuration.syntheticNamePrefix;
|
|
600
|
+
staticModuleDeclarations[`${syntheticNamePrefix}toString`] =
|
|
601
|
+
code `export const ${syntheticNamePrefix}toString = ${this.inlineToStringFunction};`;
|
|
602
|
+
}
|
|
603
|
+
return staticModuleDeclarations;
|
|
604
|
+
}
|
|
605
|
+
fromJsonExpression({ variables, }) {
|
|
606
|
+
return code `${this.alias.map((alias) => code `${alias}.fromJson`).orDefault(this.inlineFromJsonFunction)}(${variables.value})`;
|
|
607
|
+
}
|
|
608
|
+
fromRdfResourceValuesExpression({ variables, }) {
|
|
609
|
+
const { resourceValues: resourceValuesVariable, ...fromRdfResourceValuesOptionsTemp } = variables;
|
|
610
|
+
const fromRdfResourceValuesOptions = fromRdfResourceValuesOptionsTemp;
|
|
611
|
+
if (!this.configuration.features.has("ObjectSet")) {
|
|
612
|
+
delete fromRdfResourceValuesOptions["objectSet"];
|
|
613
|
+
}
|
|
614
|
+
return code `${this.alias.map((alias) => code `${alias}.fromRdfResourceValues`).orDefault(this.inlineFromRdfResourceValuesFunction)}(${resourceValuesVariable}, ${fromRdfResourceValuesOptions})`;
|
|
615
|
+
}
|
|
616
|
+
graphqlResolveExpression({ variables, }) {
|
|
617
|
+
return variables.value;
|
|
618
|
+
}
|
|
619
|
+
jsonSchema({ context, }) {
|
|
620
|
+
const expression = this.alias
|
|
621
|
+
.map((alias) => code `${alias}.Json.schema()`)
|
|
622
|
+
.orDefault(this.inlineJsonSchema);
|
|
623
|
+
if (context === "property" && this.recursive) {
|
|
624
|
+
return code `${this.reusables.imports.z}.lazy((): ${this.reusables.imports.z}.ZodType<${this.jsonType().name}> => ${expression})`;
|
|
625
|
+
}
|
|
626
|
+
return expression;
|
|
627
|
+
}
|
|
628
|
+
jsonType() {
|
|
629
|
+
return this.alias
|
|
630
|
+
.map((alias) => new AbstractType.JsonType(`${alias}.Json`))
|
|
631
|
+
.orDefault(this.inlineJsonType);
|
|
632
|
+
}
|
|
462
633
|
jsonUiSchemaElement() {
|
|
463
634
|
return Maybe.empty();
|
|
464
635
|
}
|
|
636
|
+
toJsonExpression({ variables, }) {
|
|
637
|
+
return code `${this.alias.map((alias) => code `${alias}.toJson`).orDefault(this.inlineToJsonFunction)}(${variables.value})`;
|
|
638
|
+
}
|
|
639
|
+
toRdfResourceValuesExpression({ variables, }) {
|
|
640
|
+
const { value: valueVariable, ...otherVariables } = variables;
|
|
641
|
+
return code `${this.alias.map((alias) => code `${alias}.toRdfResourceValues`).orDefault(this.inlineToRdfResourceValuesFunction)}(${valueVariable}, ${otherVariables})`;
|
|
642
|
+
}
|
|
643
|
+
toStringExpression({ variables, }) {
|
|
644
|
+
return code `${this.alias.map((alias) => code `${alias}.${this.configuration.syntheticNamePrefix}toString`).orDefault(this.inlineToStringFunction)}(${variables.value})`;
|
|
645
|
+
}
|
|
465
646
|
lazyMembers;
|
|
466
647
|
}
|
|
467
648
|
__decorate([
|
|
468
649
|
Memoize()
|
|
469
|
-
],
|
|
650
|
+
], UnionType.prototype, "conversionFunction", null);
|
|
651
|
+
__decorate([
|
|
652
|
+
Memoize()
|
|
653
|
+
], UnionType.prototype, "declaration", null);
|
|
654
|
+
__decorate([
|
|
655
|
+
Memoize()
|
|
656
|
+
], UnionType.prototype, "discriminantProperty", null);
|
|
657
|
+
__decorate([
|
|
658
|
+
Memoize()
|
|
659
|
+
], UnionType.prototype, "equalsFunction", null);
|
|
470
660
|
__decorate([
|
|
471
661
|
Memoize()
|
|
472
|
-
],
|
|
662
|
+
], UnionType.prototype, "filterFunction", null);
|
|
473
663
|
__decorate([
|
|
474
664
|
Memoize()
|
|
475
|
-
],
|
|
665
|
+
], UnionType.prototype, "filterType", null);
|
|
476
666
|
__decorate([
|
|
477
667
|
Memoize()
|
|
478
|
-
],
|
|
668
|
+
], UnionType.prototype, "graphqlType", null);
|
|
479
669
|
__decorate([
|
|
480
670
|
Memoize()
|
|
481
|
-
],
|
|
671
|
+
], UnionType.prototype, "hashFunction", null);
|
|
482
672
|
__decorate([
|
|
483
673
|
Memoize()
|
|
484
|
-
],
|
|
674
|
+
], UnionType.prototype, "members", null);
|
|
485
675
|
__decorate([
|
|
486
676
|
Memoize()
|
|
487
|
-
],
|
|
677
|
+
], UnionType.prototype, "mutable", null);
|
|
488
678
|
__decorate([
|
|
489
679
|
Memoize()
|
|
490
|
-
],
|
|
680
|
+
], UnionType.prototype, "expression", null);
|
|
491
681
|
__decorate([
|
|
492
682
|
Memoize()
|
|
493
|
-
],
|
|
683
|
+
], UnionType.prototype, "toRdfResourceValueTypes", null);
|
|
494
684
|
__decorate([
|
|
495
685
|
Memoize()
|
|
496
|
-
],
|
|
686
|
+
], UnionType.prototype, "typeofs", null);
|
|
497
687
|
__decorate([
|
|
498
688
|
Memoize()
|
|
499
|
-
],
|
|
689
|
+
], UnionType.prototype, "valueSparqlConstructTriplesFunction", null);
|
|
500
690
|
__decorate([
|
|
501
691
|
Memoize()
|
|
502
|
-
],
|
|
692
|
+
], UnionType.prototype, "valueSparqlWherePatternsFunction", null);
|
|
503
693
|
__decorate([
|
|
504
694
|
Memoize()
|
|
505
|
-
],
|
|
695
|
+
], UnionType.prototype, "inlineEqualsFunction", null);
|
|
696
|
+
__decorate([
|
|
697
|
+
Memoize()
|
|
698
|
+
], UnionType.prototype, "inlineFilterFunction", null);
|
|
699
|
+
__decorate([
|
|
700
|
+
Memoize()
|
|
701
|
+
], UnionType.prototype, "inlineFilterType", null);
|
|
702
|
+
__decorate([
|
|
703
|
+
Memoize()
|
|
704
|
+
], UnionType.prototype, "inlineJsonType", null);
|
|
705
|
+
__decorate([
|
|
706
|
+
Memoize()
|
|
707
|
+
], UnionType.prototype, "inlineExpression", null);
|
|
708
|
+
__decorate([
|
|
709
|
+
Memoize()
|
|
710
|
+
], UnionType.prototype, "inlineValueSparqlConstructTriplesFunction", null);
|
|
711
|
+
__decorate([
|
|
712
|
+
Memoize()
|
|
713
|
+
], UnionType.prototype, "inlineValueSparqlWherePatternsFunction", null);
|
|
714
|
+
__decorate([
|
|
715
|
+
Memoize()
|
|
716
|
+
], UnionType.prototype, "jsonType", null);
|
|
506
717
|
function termTypes(type) {
|
|
507
718
|
switch (type.kind) {
|
|
508
719
|
case "BlankNode":
|
|
@@ -586,8 +797,8 @@ export var Discriminant;
|
|
|
586
797
|
continue;
|
|
587
798
|
}
|
|
588
799
|
extrinsicMemberTypeCount++;
|
|
589
|
-
if (
|
|
590
|
-
extrinsicMemberTypeNamesSet.add(memberType.
|
|
800
|
+
if (memberType.alias.isJust()) {
|
|
801
|
+
extrinsicMemberTypeNamesSet.add(memberType.alias.extract());
|
|
591
802
|
}
|
|
592
803
|
else {
|
|
593
804
|
break;
|
|
@@ -607,7 +818,7 @@ export var Discriminant;
|
|
|
607
818
|
return {
|
|
608
819
|
kind: "Extrinsic",
|
|
609
820
|
ownValues: extrinsicMemberTypeNamesSet.size === extrinsicMemberTypeCount
|
|
610
|
-
? [memberType.
|
|
821
|
+
? [memberType.alias.unsafeCoerce()]
|
|
611
822
|
: [memberTypeI.toString()],
|
|
612
823
|
};
|
|
613
824
|
}),
|
|
@@ -618,21 +829,14 @@ export var Discriminant;
|
|
|
618
829
|
{
|
|
619
830
|
let memberValues;
|
|
620
831
|
{
|
|
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
|
-
}
|
|
832
|
+
const memberTypeNames = memberTypes.map((memberType) => memberType.alias.orDefault(memberType.typeofs[0]));
|
|
833
|
+
const memberTypeNamesSet = new Set(memberTypeNames);
|
|
834
|
+
if (memberTypeNamesSet.size === memberTypeNames.length) {
|
|
835
|
+
memberValues = memberTypeNames;
|
|
631
836
|
}
|
|
632
837
|
else {
|
|
633
|
-
//
|
|
634
|
-
|
|
635
|
-
memberValues = memberTypes.map((_, memberTypeI) => memberTypeI);
|
|
838
|
+
// Otherwise prefix the non-unique strings with an index and use those as the discriminant values.
|
|
839
|
+
memberValues = memberTypeNames.map((memberTypeName, memberTypeI) => `${memberTypeI}-${memberTypeName}`);
|
|
636
840
|
}
|
|
637
841
|
}
|
|
638
842
|
invariant(memberValues.length === memberTypes.length);
|
|
@@ -640,10 +844,10 @@ export var Discriminant;
|
|
|
640
844
|
jsonName: "type",
|
|
641
845
|
kind: "Extrinsic",
|
|
642
846
|
name: "type",
|
|
643
|
-
memberValues
|
|
847
|
+
memberValues,
|
|
644
848
|
};
|
|
645
849
|
}
|
|
646
850
|
}
|
|
647
851
|
Discriminant.infer = infer;
|
|
648
852
|
})(Discriminant || (Discriminant = {}));
|
|
649
|
-
//# sourceMappingURL=
|
|
853
|
+
//# sourceMappingURL=UnionType.js.map
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { invariant } from "ts-invariant";
|
|
2
1
|
import * as ast from "../../ast/index.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { ObjectType_jsonSchemaFunctionDeclaration } from "./_ObjectType/ObjectType_jsonSchemaFunctionDeclaration.js";
|
|
3
|
+
import { ObjectType_jsonTypeAliasDeclaration } from "./_ObjectType/ObjectType_jsonTypeAliasDeclaration.js";
|
|
5
4
|
import { Reusables } from "./Reusables.js";
|
|
6
5
|
import { TsGenerator } from "./TsGenerator.js";
|
|
7
6
|
import { TypeFactory } from "./TypeFactory.js";
|
|
@@ -20,20 +19,19 @@ export class ZodGenerator {
|
|
|
20
19
|
reusables,
|
|
21
20
|
});
|
|
22
21
|
const declarations = [];
|
|
23
|
-
for (const namedObjectType of ast.ObjectType.toposort(ast_.namedObjectTypes).map((astObjectType) => typeFactory.
|
|
22
|
+
for (const namedObjectType of ast.ObjectType.toposort(ast_.namedObjectTypes).map((astObjectType) => typeFactory.createObjectType(astObjectType))) {
|
|
24
23
|
declarations.push(code `\
|
|
25
|
-
export namespace ${namedObjectType.
|
|
26
|
-
${joinCode(
|
|
24
|
+
export namespace ${namedObjectType.alias.unsafeCoerce()} {
|
|
25
|
+
${joinCode(ObjectType_jsonTypeAliasDeclaration.call(namedObjectType).toList())}
|
|
27
26
|
|
|
28
27
|
export namespace Json {
|
|
29
|
-
${joinCode(
|
|
28
|
+
${joinCode(ObjectType_jsonSchemaFunctionDeclaration.call(namedObjectType).toList())}
|
|
30
29
|
}
|
|
31
30
|
}`);
|
|
32
31
|
}
|
|
33
32
|
for (const astNamedUnionType of ast_.namedUnionTypes.map((astNamedUnionType) => typeFactory.createUnionType(astNamedUnionType))) {
|
|
34
|
-
invariant(astNamedUnionType.kind !== "AnonymousUnion");
|
|
35
33
|
declarations.push(code `\
|
|
36
|
-
export namespace ${astNamedUnionType.
|
|
34
|
+
export namespace ${astNamedUnionType.alias.unsafeCoerce()} {
|
|
37
35
|
${astNamedUnionType.jsonTypeAliasDeclaration}
|
|
38
36
|
export namespace Json {
|
|
39
37
|
${astNamedUnionType.jsonSchemaFunctionDeclaration}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { Maybe } from "purify-ts";
|
|
2
2
|
import type { Logger } from "ts-log";
|
|
3
|
-
import type {
|
|
3
|
+
import type { ObjectType } from "../ObjectType.js";
|
|
4
4
|
import type { Reusables } from "../Reusables.js";
|
|
5
5
|
import { rdfjsTermExpression } from "../rdfjsTermExpression.js";
|
|
6
6
|
import type { TsGenerator } from "../TsGenerator.js";
|
|
7
7
|
import type { Type } from "../Type.js";
|
|
8
8
|
import { type Code } from "../ts-poet-wrapper.js";
|
|
9
|
-
export declare abstract class AbstractProperty<TypeT extends Pick<Type, "
|
|
9
|
+
export declare abstract class AbstractProperty<TypeT extends Pick<Type, "expression" | "filterFunction" | "mutable" | "schema">> {
|
|
10
10
|
protected readonly configuration: TsGenerator.Configuration;
|
|
11
11
|
protected readonly logger: Logger;
|
|
12
|
-
protected readonly
|
|
12
|
+
protected readonly objectType: ObjectType;
|
|
13
13
|
protected readonly reusables: Reusables;
|
|
14
14
|
/**
|
|
15
15
|
* Optional parameter to include in the parameters object of constructor function.
|
|
@@ -62,18 +62,18 @@ export declare abstract class AbstractProperty<TypeT extends Pick<Type, "filterF
|
|
|
62
62
|
*/
|
|
63
63
|
readonly name: string;
|
|
64
64
|
/**
|
|
65
|
-
* Is the property's type the
|
|
65
|
+
* Is the property's type the ObjectType or does its type indirectly reference the ObjectType?
|
|
66
66
|
*/
|
|
67
67
|
abstract readonly recursive: boolean;
|
|
68
68
|
/**
|
|
69
69
|
* Property type
|
|
70
70
|
. */
|
|
71
71
|
readonly type: TypeT;
|
|
72
|
-
constructor({ configuration, logger, name,
|
|
72
|
+
constructor({ configuration, logger, name, objectType, reusables, type, }: {
|
|
73
73
|
configuration: TsGenerator.Configuration;
|
|
74
74
|
logger: Logger;
|
|
75
75
|
name: string;
|
|
76
|
-
|
|
76
|
+
objectType: ObjectType;
|
|
77
77
|
reusables: Reusables;
|
|
78
78
|
type: TypeT;
|
|
79
79
|
});
|
|
@@ -11,7 +11,7 @@ import { code, joinCode, literalOf } from "../ts-poet-wrapper.js";
|
|
|
11
11
|
export class AbstractProperty {
|
|
12
12
|
configuration;
|
|
13
13
|
logger;
|
|
14
|
-
|
|
14
|
+
objectType;
|
|
15
15
|
reusables;
|
|
16
16
|
/**
|
|
17
17
|
* TypeScript identifier-safe name of the property.
|
|
@@ -21,11 +21,11 @@ export class AbstractProperty {
|
|
|
21
21
|
* Property type
|
|
22
22
|
. */
|
|
23
23
|
type;
|
|
24
|
-
constructor({ configuration, logger, name,
|
|
24
|
+
constructor({ configuration, logger, name, objectType, reusables, type, }) {
|
|
25
25
|
this.configuration = configuration;
|
|
26
26
|
this.logger = logger;
|
|
27
27
|
this.name = name;
|
|
28
|
-
this.
|
|
28
|
+
this.objectType = objectType;
|
|
29
29
|
this.reusables = reusables;
|
|
30
30
|
this.type = type;
|
|
31
31
|
this.rdfjsTermExpression = rdfjsTermExpression.bind({
|