@shaclmate/compiler 4.0.60 → 4.0.62
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/DefaultValueType.d.ts +6 -6
- package/dist/generators/ts/DiscriminatedUnionType.d.ts +3 -53
- package/dist/generators/ts/DiscriminatedUnionType.js +46 -431
- package/dist/generators/ts/IdentifierType.js +1 -1
- package/dist/generators/ts/ObjectDiscriminatedUnionType.d.ts +0 -8
- package/dist/generators/ts/ObjectDiscriminatedUnionType.js +17 -152
- package/dist/generators/ts/TsGenerator.d.ts +4 -0
- package/dist/generators/ts/TsGenerator.js +6 -0
- package/dist/generators/ts/TypeFactory.js +0 -1
- package/dist/generators/ts/_DiscriminatedUnionType/DiscriminatedUnionType_Discriminant.d.ts +30 -0
- package/dist/generators/ts/_DiscriminatedUnionType/DiscriminatedUnionType_Discriminant.js +2 -0
- package/dist/generators/ts/_DiscriminatedUnionType/DiscriminatedUnionType_equalsFunctionExpression.d.ts +5 -0
- package/dist/generators/ts/_DiscriminatedUnionType/DiscriminatedUnionType_equalsFunctionExpression.js +12 -0
- package/dist/generators/ts/_DiscriminatedUnionType/DiscriminatedUnionType_filterFunctionExpression.d.ts +5 -0
- package/dist/generators/ts/_DiscriminatedUnionType/DiscriminatedUnionType_filterFunctionExpression.js +24 -0
- package/dist/generators/ts/_DiscriminatedUnionType/DiscriminatedUnionType_filterTypeExpression.d.ts +5 -0
- package/dist/generators/ts/_DiscriminatedUnionType/DiscriminatedUnionType_filterTypeExpression.js +10 -0
- package/dist/generators/ts/_DiscriminatedUnionType/DiscriminatedUnionType_fromJsonFunctionExpression.d.ts +5 -0
- package/dist/generators/ts/_DiscriminatedUnionType/DiscriminatedUnionType_fromJsonFunctionExpression.js +14 -0
- package/dist/generators/ts/_DiscriminatedUnionType/DiscriminatedUnionType_fromRdfResourceValuesFunctionExpression.d.ts +5 -0
- package/dist/generators/ts/_DiscriminatedUnionType/DiscriminatedUnionType_fromRdfResourceValuesFunctionExpression.js +22 -0
- package/dist/generators/ts/_DiscriminatedUnionType/DiscriminatedUnionType_hashFunctionExpression.d.ts +5 -0
- package/dist/generators/ts/_DiscriminatedUnionType/DiscriminatedUnionType_hashFunctionExpression.js +9 -0
- package/dist/generators/ts/_DiscriminatedUnionType/DiscriminatedUnionType_inferDiscriminant.d.ts +8 -0
- package/dist/generators/ts/_DiscriminatedUnionType/DiscriminatedUnionType_inferDiscriminant.js +133 -0
- package/dist/generators/ts/_DiscriminatedUnionType/DiscriminatedUnionType_inlineExpression.d.ts +5 -0
- package/dist/generators/ts/_DiscriminatedUnionType/DiscriminatedUnionType_inlineExpression.js +31 -0
- package/dist/generators/ts/_DiscriminatedUnionType/DiscriminatedUnionType_jsonSchemaExpression.d.ts +5 -0
- package/dist/generators/ts/_DiscriminatedUnionType/DiscriminatedUnionType_jsonSchemaExpression.js +32 -0
- package/dist/generators/ts/_DiscriminatedUnionType/DiscriminatedUnionType_jsonTypeLiteral.d.ts +5 -0
- package/dist/generators/ts/_DiscriminatedUnionType/DiscriminatedUnionType_jsonTypeLiteral.js +26 -0
- package/dist/generators/ts/_DiscriminatedUnionType/DiscriminatedUnionType_schemaTypeExpression.d.ts +5 -0
- package/dist/generators/ts/_DiscriminatedUnionType/DiscriminatedUnionType_schemaTypeExpression.js +11 -0
- package/dist/generators/ts/_DiscriminatedUnionType/DiscriminatedUnionType_toJsonFunctionExpression.d.ts +5 -0
- package/dist/generators/ts/_DiscriminatedUnionType/DiscriminatedUnionType_toJsonFunctionExpression.js +10 -0
- package/dist/generators/ts/_DiscriminatedUnionType/DiscriminatedUnionType_toRdfResourceValuesFunctionExpression.d.ts +5 -0
- package/dist/generators/ts/_DiscriminatedUnionType/DiscriminatedUnionType_toRdfResourceValuesFunctionExpression.js +30 -0
- package/dist/generators/ts/_DiscriminatedUnionType/DiscriminatedUnionType_toStringFunctionExpression.d.ts +5 -0
- package/dist/generators/ts/_DiscriminatedUnionType/DiscriminatedUnionType_toStringFunctionExpression.js +12 -0
- package/dist/generators/ts/_DiscriminatedUnionType/DiscriminatedUnionType_valueSparqlConstructTriplesFunctionExpression.d.ts +5 -0
- package/dist/generators/ts/_DiscriminatedUnionType/DiscriminatedUnionType_valueSparqlConstructTriplesFunctionExpression.js +13 -0
- package/dist/generators/ts/_DiscriminatedUnionType/DiscriminatedUnionType_valueSparqlWherePatternsFunctionExpression.d.ts +5 -0
- package/dist/generators/ts/_DiscriminatedUnionType/DiscriminatedUnionType_valueSparqlWherePatternsFunctionExpression.js +13 -0
- package/dist/generators/ts/_ObjectDiscriminatedUnionType/ObjectDiscriminatedUnionType_focusSparqlConstructTriplesFunctionDeclaration.d.ts +4 -0
- package/dist/generators/ts/_ObjectDiscriminatedUnionType/ObjectDiscriminatedUnionType_focusSparqlConstructTriplesFunctionDeclaration.js +13 -0
- package/dist/generators/ts/_ObjectDiscriminatedUnionType/ObjectDiscriminatedUnionType_focusSparqlWherePatternsFunctionDeclaration.d.ts +4 -0
- package/dist/generators/ts/_ObjectDiscriminatedUnionType/ObjectDiscriminatedUnionType_focusSparqlWherePatternsFunctionDeclaration.js +32 -0
- package/dist/generators/ts/_ObjectDiscriminatedUnionType/ObjectDiscriminatedUnionType_fromRdfResourceFunctionDeclaration.d.ts +4 -0
- package/dist/generators/ts/_ObjectDiscriminatedUnionType/ObjectDiscriminatedUnionType_fromRdfResourceFunctionDeclaration.js +17 -0
- package/dist/generators/ts/_ObjectDiscriminatedUnionType/ObjectDiscriminatedUnionType_graphqlTypeVariableStatement.d.ts +4 -0
- package/dist/generators/ts/_ObjectDiscriminatedUnionType/ObjectDiscriminatedUnionType_graphqlTypeVariableStatement.js +19 -0
- package/dist/generators/ts/_ObjectDiscriminatedUnionType/ObjectDiscriminatedUnionType_identifierTypeDeclarations.d.ts +4 -0
- package/dist/generators/ts/_ObjectDiscriminatedUnionType/ObjectDiscriminatedUnionType_identifierTypeDeclarations.js +14 -0
- package/dist/generators/ts/_ObjectDiscriminatedUnionType/ObjectDiscriminatedUnionType_isTypeFunctionDeclaration.d.ts +4 -0
- package/dist/generators/ts/_ObjectDiscriminatedUnionType/ObjectDiscriminatedUnionType_isTypeFunctionDeclaration.js +16 -0
- package/dist/generators/ts/_ObjectDiscriminatedUnionType/ObjectDiscriminatedUnionType_schemaVariableStatement.d.ts +4 -0
- package/dist/generators/ts/_ObjectDiscriminatedUnionType/ObjectDiscriminatedUnionType_schemaVariableStatement.js +42 -0
- package/dist/generators/ts/_ObjectDiscriminatedUnionType/ObjectDiscriminatedUnionType_toRdfResourceFunctionDeclaration.d.ts +4 -0
- package/dist/generators/ts/_ObjectDiscriminatedUnionType/ObjectDiscriminatedUnionType_toRdfResourceFunctionDeclaration.js +15 -0
- package/dist/generators/ts/_ObjectType/ObjectType_DiscriminantProperty.d.ts +4 -4
- package/dist/generators/ts/_ObjectType/ObjectType_DiscriminantProperty.js +15 -3
- package/package.json +55 -4
|
@@ -7,6 +7,22 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
import { Maybe } from "purify-ts";
|
|
8
8
|
import { invariant } from "ts-invariant";
|
|
9
9
|
import { Memoize } from "typescript-memoize";
|
|
10
|
+
import { DiscriminatedUnionType_equalsFunctionExpression } from "./_DiscriminatedUnionType/DiscriminatedUnionType_equalsFunctionExpression.js";
|
|
11
|
+
import { DiscriminatedUnionType_filterFunctionExpression } from "./_DiscriminatedUnionType/DiscriminatedUnionType_filterFunctionExpression.js";
|
|
12
|
+
import { DiscriminatedUnionType_filterTypeExpression } from "./_DiscriminatedUnionType/DiscriminatedUnionType_filterTypeExpression.js";
|
|
13
|
+
import { DiscriminatedUnionType_fromJsonFunctionExpression } from "./_DiscriminatedUnionType/DiscriminatedUnionType_fromJsonFunctionExpression.js";
|
|
14
|
+
import { DiscriminatedUnionType_fromRdfResourceValuesFunctionExpression } from "./_DiscriminatedUnionType/DiscriminatedUnionType_fromRdfResourceValuesFunctionExpression.js";
|
|
15
|
+
import { DiscriminatedUnionType_hashFunctionExpression } from "./_DiscriminatedUnionType/DiscriminatedUnionType_hashFunctionExpression.js";
|
|
16
|
+
import { DiscriminatedUnionType_inferDiscriminant } from "./_DiscriminatedUnionType/DiscriminatedUnionType_inferDiscriminant.js";
|
|
17
|
+
import { DiscriminatedUnionType_inlineExpression } from "./_DiscriminatedUnionType/DiscriminatedUnionType_inlineExpression.js";
|
|
18
|
+
import { DiscriminatedUnionType_jsonSchemaExpression } from "./_DiscriminatedUnionType/DiscriminatedUnionType_jsonSchemaExpression.js";
|
|
19
|
+
import { DiscriminatedUnionType_jsonTypeLiteral } from "./_DiscriminatedUnionType/DiscriminatedUnionType_jsonTypeLiteral.js";
|
|
20
|
+
import { DiscriminatedUnionType_schemaTypeExpression } from "./_DiscriminatedUnionType/DiscriminatedUnionType_schemaTypeExpression.js";
|
|
21
|
+
import { DiscriminatedUnionType_toJsonFunctionExpression } from "./_DiscriminatedUnionType/DiscriminatedUnionType_toJsonFunctionExpression.js";
|
|
22
|
+
import { DiscriminatedUnionType_toRdfResourceValuesFunctionExpression } from "./_DiscriminatedUnionType/DiscriminatedUnionType_toRdfResourceValuesFunctionExpression.js";
|
|
23
|
+
import { DiscriminatedUnionType_toStringFunctionExpression } from "./_DiscriminatedUnionType/DiscriminatedUnionType_toStringFunctionExpression.js";
|
|
24
|
+
import { DiscriminatedUnionType_valueSparqlConstructTriplesFunctionExpression } from "./_DiscriminatedUnionType/DiscriminatedUnionType_valueSparqlConstructTriplesFunctionExpression.js";
|
|
25
|
+
import { DiscriminatedUnionType_valueSparqlWherePatternsFunctionExpression } from "./_DiscriminatedUnionType/DiscriminatedUnionType_valueSparqlWherePatternsFunctionExpression.js";
|
|
10
26
|
import { AbstractType } from "./AbstractType.js";
|
|
11
27
|
import { code, def, joinCode, literalOf, } from "./ts-poet-wrapper.js";
|
|
12
28
|
export class DiscriminatedUnionType extends AbstractType {
|
|
@@ -22,11 +38,10 @@ export class DiscriminatedUnionType extends AbstractType {
|
|
|
22
38
|
this.identifierType = identifierType;
|
|
23
39
|
invariant(members.length >= 2);
|
|
24
40
|
this.recursive = recursive;
|
|
25
|
-
this.discriminant =
|
|
41
|
+
this.discriminant = DiscriminatedUnionType_inferDiscriminant.call(this, members);
|
|
26
42
|
this.synthetic = synthetic;
|
|
27
43
|
this.lazyMembers = () => members.map((member, memberI) => {
|
|
28
44
|
let discriminantValues;
|
|
29
|
-
invariant(this.discriminant.memberValues.length === members.length);
|
|
30
45
|
switch (this.discriminant.kind) {
|
|
31
46
|
case "Extrinsic":
|
|
32
47
|
discriminantValues = [this.discriminant.memberValues[memberI]];
|
|
@@ -137,7 +152,7 @@ export class DiscriminatedUnionType extends AbstractType {
|
|
|
137
152
|
}
|
|
138
153
|
const declarations = [];
|
|
139
154
|
if (this.configuration.features.has("Object.type")) {
|
|
140
|
-
declarations.push(code `export type ${def(name)} = ${this
|
|
155
|
+
declarations.push(code `export type ${def(name)} = ${DiscriminatedUnionType_inlineExpression.call(this)};`);
|
|
141
156
|
}
|
|
142
157
|
const staticModuleDeclarations = Object.entries(this.staticModuleDeclarations);
|
|
143
158
|
if (staticModuleDeclarations.length > 0) {
|
|
@@ -179,27 +194,27 @@ ${joinCode(staticModuleDeclarations
|
|
|
179
194
|
get equalsFunction() {
|
|
180
195
|
return this.name
|
|
181
196
|
.map((name) => code `${name}.equals`)
|
|
182
|
-
.orDefault(this
|
|
197
|
+
.orDefault(DiscriminatedUnionType_equalsFunctionExpression.call(this));
|
|
183
198
|
}
|
|
184
199
|
get expression() {
|
|
185
200
|
return this.name
|
|
186
201
|
.map((name) => code `${name}`)
|
|
187
|
-
.orDefault(this
|
|
202
|
+
.orDefault(DiscriminatedUnionType_inlineExpression.call(this));
|
|
188
203
|
}
|
|
189
204
|
get filterFunction() {
|
|
190
205
|
return this.name
|
|
191
206
|
.map((name) => code `${name}.filter`)
|
|
192
|
-
.orDefault(this
|
|
207
|
+
.orDefault(DiscriminatedUnionType_filterFunctionExpression.call(this));
|
|
193
208
|
}
|
|
194
209
|
get filterType() {
|
|
195
210
|
return this.name
|
|
196
211
|
.map((name) => code `${name}.Filter`)
|
|
197
|
-
.orDefault(this
|
|
212
|
+
.orDefault(DiscriminatedUnionType_filterTypeExpression.call(this));
|
|
198
213
|
}
|
|
199
214
|
get fromRdfResourceValuesFunction() {
|
|
200
215
|
return this.name
|
|
201
216
|
.map((name) => code `${name}.fromRdfResourceValues`)
|
|
202
|
-
.orDefault(this
|
|
217
|
+
.orDefault(DiscriminatedUnionType_fromRdfResourceValuesFunctionExpression.call(this));
|
|
203
218
|
}
|
|
204
219
|
get graphqlType() {
|
|
205
220
|
const name = this.name.extract();
|
|
@@ -212,7 +227,7 @@ ${joinCode(staticModuleDeclarations
|
|
|
212
227
|
get hashFunction() {
|
|
213
228
|
return this.name
|
|
214
229
|
.map((name) => code `${name}.hash`)
|
|
215
|
-
.orDefault(this
|
|
230
|
+
.orDefault(DiscriminatedUnionType_hashFunctionExpression.call(this));
|
|
216
231
|
}
|
|
217
232
|
get jsTypes() {
|
|
218
233
|
const jsTypes = [];
|
|
@@ -226,7 +241,7 @@ ${joinCode(staticModuleDeclarations
|
|
|
226
241
|
return jsTypes;
|
|
227
242
|
}
|
|
228
243
|
get jsonSchemaFunctionDeclaration() {
|
|
229
|
-
let expression = this
|
|
244
|
+
let expression = DiscriminatedUnionType_jsonSchemaExpression.call(this);
|
|
230
245
|
const meta = {
|
|
231
246
|
// id: this.name,
|
|
232
247
|
};
|
|
@@ -242,7 +257,7 @@ ${joinCode(staticModuleDeclarations
|
|
|
242
257
|
return code `export const schema = () => ${expression};`;
|
|
243
258
|
}
|
|
244
259
|
get jsonTypeAliasDeclaration() {
|
|
245
|
-
return code `export type Json = ${this.
|
|
260
|
+
return code `export type Json = ${DiscriminatedUnionType_jsonTypeLiteral.call(this).expression}`;
|
|
246
261
|
}
|
|
247
262
|
get members() {
|
|
248
263
|
return this.lazyMembers();
|
|
@@ -262,7 +277,7 @@ ${joinCode(staticModuleDeclarations
|
|
|
262
277
|
get schemaType() {
|
|
263
278
|
return this.name
|
|
264
279
|
.map(() => code `typeof ${this.schema}`)
|
|
265
|
-
.orDefault(this
|
|
280
|
+
.orDefault(DiscriminatedUnionType_schemaTypeExpression.call(this));
|
|
266
281
|
}
|
|
267
282
|
get toRdfResourceValueTypes() {
|
|
268
283
|
const set = new Set();
|
|
@@ -276,12 +291,12 @@ ${joinCode(staticModuleDeclarations
|
|
|
276
291
|
get valueSparqlConstructTriplesFunction() {
|
|
277
292
|
return this.name
|
|
278
293
|
.map((name) => code `${name}.valueSparqlConstructTriples`)
|
|
279
|
-
.orDefault(this
|
|
294
|
+
.orDefault(DiscriminatedUnionType_valueSparqlConstructTriplesFunctionExpression.call(this));
|
|
280
295
|
}
|
|
281
296
|
get valueSparqlWherePatternsFunction() {
|
|
282
297
|
return this.name
|
|
283
298
|
.map((name) => code `${name}.valueSparqlWherePatterns`)
|
|
284
|
-
.orDefault(this
|
|
299
|
+
.orDefault(DiscriminatedUnionType_valueSparqlWherePatternsFunctionExpression.call(this));
|
|
285
300
|
}
|
|
286
301
|
get schemaInitializers() {
|
|
287
302
|
return super.schemaInitializers.concat(code `members: { ${joinCode(this.members.map(({ discriminantValues, type, primaryDiscriminantValue }) => code `${literalOf(primaryDiscriminantValue)}: ${{
|
|
@@ -289,31 +304,22 @@ ${joinCode(staticModuleDeclarations
|
|
|
289
304
|
type: type.schema,
|
|
290
305
|
}}`), { on: "," })} }`);
|
|
291
306
|
}
|
|
292
|
-
get schemaTypeExpression() {
|
|
293
|
-
return code `${{
|
|
294
|
-
kind: this.kind,
|
|
295
|
-
members: code `{ ${joinCode(this.members.map(({ type, primaryDiscriminantValue }) => code `readonly ${literalOf(primaryDiscriminantValue)}: ${{
|
|
296
|
-
discriminantValues: code `readonly (number | string)[]`,
|
|
297
|
-
type: type.schemaType,
|
|
298
|
-
}}`), { on: ";" })} }`,
|
|
299
|
-
}}`;
|
|
300
|
-
}
|
|
301
307
|
get staticModuleDeclarations() {
|
|
302
308
|
const name = this.name.unsafeCoerce();
|
|
303
309
|
const staticModuleDeclarations = {};
|
|
304
310
|
if (this.configuration.features.has("Object.equals")) {
|
|
305
311
|
staticModuleDeclarations[`equals`] =
|
|
306
|
-
code `export const equals = ${this
|
|
312
|
+
code `export const equals = ${DiscriminatedUnionType_equalsFunctionExpression.call(this)};`;
|
|
307
313
|
}
|
|
308
314
|
if (this.configuration.features.has("Object.filter")) {
|
|
309
315
|
staticModuleDeclarations[`Filter`] =
|
|
310
|
-
code `export type Filter = ${this
|
|
316
|
+
code `export type Filter = ${DiscriminatedUnionType_filterTypeExpression.call(this)};`;
|
|
311
317
|
staticModuleDeclarations[`filter`] =
|
|
312
|
-
code `export const filter = ${this
|
|
318
|
+
code `export const filter = ${DiscriminatedUnionType_filterFunctionExpression.call(this)};`;
|
|
313
319
|
}
|
|
314
320
|
if (this.configuration.features.has("Object.hash")) {
|
|
315
321
|
staticModuleDeclarations[`hash`] =
|
|
316
|
-
code `export const hash = ${this
|
|
322
|
+
code `export const hash = ${DiscriminatedUnionType_hashFunctionExpression.call(this)};`;
|
|
317
323
|
}
|
|
318
324
|
if (this.configuration.features.has("Object.JSON.type")) {
|
|
319
325
|
staticModuleDeclarations[`Json.type`] =
|
|
@@ -333,11 +339,11 @@ export namespace Json {
|
|
|
333
339
|
}
|
|
334
340
|
if (this.configuration.features.has("Object.fromJson")) {
|
|
335
341
|
staticModuleDeclarations[`fromJson`] =
|
|
336
|
-
code `export const fromJson = ${this
|
|
342
|
+
code `export const fromJson = ${DiscriminatedUnionType_fromJsonFunctionExpression.call(this)};`;
|
|
337
343
|
}
|
|
338
344
|
if (this.configuration.features.has("Object.fromRdf")) {
|
|
339
345
|
staticModuleDeclarations[`fromRdfResourceValues`] =
|
|
340
|
-
code `export const fromRdfResourceValues: ${this.reusables.snippets.FromRdfResourceValuesFunction}<${name}, ${this.schemaType}> = ${this
|
|
346
|
+
code `export const fromRdfResourceValues: ${this.reusables.snippets.FromRdfResourceValuesFunction}<${name}, ${this.schemaType}> = ${DiscriminatedUnionType_fromRdfResourceValuesFunctionExpression.call(this)};`;
|
|
341
347
|
}
|
|
342
348
|
if (this.configuration.features.has("Object.schema")) {
|
|
343
349
|
staticModuleDeclarations["schema"] =
|
|
@@ -345,259 +351,27 @@ export namespace Json {
|
|
|
345
351
|
}
|
|
346
352
|
if (this.configuration.features.has("Object.toJson")) {
|
|
347
353
|
staticModuleDeclarations[`toJson`] =
|
|
348
|
-
code `export const toJson = ${this
|
|
354
|
+
code `export const toJson = ${DiscriminatedUnionType_toJsonFunctionExpression.call(this)};`;
|
|
349
355
|
}
|
|
350
356
|
if (this.configuration.features.has("Object.toRdf")) {
|
|
351
357
|
staticModuleDeclarations[`toRdfResourceValues`] =
|
|
352
|
-
code `export const toRdfResourceValues = ${this
|
|
358
|
+
code `export const toRdfResourceValues = ${DiscriminatedUnionType_toRdfResourceValuesFunctionExpression.call(this)};`;
|
|
353
359
|
}
|
|
354
360
|
if (this.configuration.features.has("Object.SPARQL")) {
|
|
355
361
|
staticModuleDeclarations[`valueSparqlConstructTriples`] =
|
|
356
|
-
code `export const valueSparqlConstructTriples: ${this.reusables.snippets.ValueSparqlConstructTriplesFunction}<${this.filterType}, ${this.schemaType}> = ${this
|
|
362
|
+
code `export const valueSparqlConstructTriples: ${this.reusables.snippets.ValueSparqlConstructTriplesFunction}<${this.filterType}, ${this.schemaType}> = ${DiscriminatedUnionType_valueSparqlConstructTriplesFunctionExpression.call(this)};`;
|
|
357
363
|
staticModuleDeclarations[`valueSparqlWherePatterns`] =
|
|
358
|
-
code `export const valueSparqlWherePatterns: ${this.reusables.snippets.ValueSparqlWherePatternsFunction}<${this.filterType}, ${this.schemaType}> = ${this
|
|
364
|
+
code `export const valueSparqlWherePatterns: ${this.reusables.snippets.ValueSparqlWherePatternsFunction}<${this.filterType}, ${this.schemaType}> = ${DiscriminatedUnionType_valueSparqlWherePatternsFunctionExpression.call(this)};`;
|
|
359
365
|
}
|
|
360
366
|
if (this.configuration.features.has("Object.toString")) {
|
|
361
367
|
const syntheticNamePrefix = this.configuration.syntheticNamePrefix;
|
|
362
368
|
staticModuleDeclarations[`${syntheticNamePrefix}toString`] =
|
|
363
|
-
code `export const ${syntheticNamePrefix}toString = ${this
|
|
369
|
+
code `export const ${syntheticNamePrefix}toString = ${DiscriminatedUnionType_toStringFunctionExpression.call(this)};`;
|
|
364
370
|
}
|
|
365
371
|
return staticModuleDeclarations;
|
|
366
372
|
}
|
|
367
|
-
get equalsFunctionExpression() {
|
|
368
|
-
return code `\
|
|
369
|
-
((left: ${this.expression}, right: ${this.expression}) => {
|
|
370
|
-
${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeCheck(code `left`)} && ${typeCheck(code `right`)}) {
|
|
371
|
-
return ${type.equalsFunction}(${unwrap(code `left`)} as ${type.expression}, ${unwrap(code `right`)} as ${type.expression});
|
|
372
|
-
}`))}
|
|
373
|
-
|
|
374
|
-
return ${this.reusables.imports.Left}({ left, right, propertyName: "type", propertyValuesUnequal: { left: typeof left, right: typeof right, type: "boolean" as const }, type: "property" as const });
|
|
375
|
-
})`;
|
|
376
|
-
}
|
|
377
|
-
get filterFunctionExpression() {
|
|
378
|
-
const syntheticNamePrefix = this.configuration.syntheticNamePrefix;
|
|
379
|
-
return code `\
|
|
380
|
-
((filter: ${this.filterType}, value: ${this.expression}) => {
|
|
381
|
-
${joinCode([
|
|
382
|
-
...this.identifierType
|
|
383
|
-
.map((identifierType) => code `\
|
|
384
|
-
if (filter.${syntheticNamePrefix}identifier !== undefined && !${identifierType.filterFunction}(filter.${syntheticNamePrefix}identifier, value.${syntheticNamePrefix}identifier())) {
|
|
385
|
-
return false;
|
|
386
|
-
}`)
|
|
387
|
-
.toList(),
|
|
388
|
-
...this.members.map(({ primaryDiscriminantValue, type, typeCheck, unwrap }) => code `\
|
|
389
|
-
if (filter.on?.[${literalOf(primaryDiscriminantValue)}] !== undefined && ${typeCheck(code `value`)}) {
|
|
390
|
-
if (!${type.filterFunction}(filter.on[${literalOf(primaryDiscriminantValue)}], ${unwrap(code `value`)})) {
|
|
391
|
-
return false;
|
|
392
|
-
}
|
|
393
|
-
}`),
|
|
394
|
-
])}
|
|
395
|
-
|
|
396
|
-
return true;
|
|
397
|
-
})`;
|
|
398
|
-
}
|
|
399
|
-
get filterTypeLiteral() {
|
|
400
|
-
const syntheticNamePrefix = this.configuration.syntheticNamePrefix;
|
|
401
|
-
return code `\
|
|
402
|
-
{
|
|
403
|
-
${this.identifierType.map((identifierType) => code `readonly ${syntheticNamePrefix}identifier?: ${identifierType.filterType};`).orDefault(code ``)}
|
|
404
|
-
readonly on?: { ${joinCode(this.members.map(({ type, primaryDiscriminantValue }) => code `readonly ${literalOf(primaryDiscriminantValue)}?: ${type.filterType}`), { on: ";" })} }
|
|
405
|
-
}`;
|
|
406
|
-
}
|
|
407
|
-
get fromJsonFunctionExpression() {
|
|
408
|
-
return code `\
|
|
409
|
-
((value: ${this.jsonType().expression}): ${this.reusables.imports.Either}<Error, ${this.expression}> => {
|
|
410
|
-
${joinCode(this.members.map(({ jsonType, jsonTypeCheck, type, unwrap, wrap }) => code `if (${jsonTypeCheck(code `value`)}) { return ${type.fromJsonExpression({
|
|
411
|
-
variables: {
|
|
412
|
-
value: code `(${unwrap(code `value`)} as ${jsonType})`,
|
|
413
|
-
},
|
|
414
|
-
})}.map(value => (${wrap(code `value`)})); }`))}
|
|
415
|
-
|
|
416
|
-
throw new Error("unable to deserialize JSON");
|
|
417
|
-
})`;
|
|
418
|
-
}
|
|
419
|
-
get fromRdfResourceValuesFunctionExpression() {
|
|
420
|
-
return code `\
|
|
421
|
-
(((values, options) =>
|
|
422
|
-
values.chainMap(value => {
|
|
423
|
-
const valueAsValues = value.toValues();
|
|
424
|
-
return ${this.members.reduce((expression, { type, primaryDiscriminantValue }, memberI) => {
|
|
425
|
-
let typeExpression = code `${type.fromRdfResourceValuesFunction}(valueAsValues, { ...options, schema: options.schema.members[${literalOf(primaryDiscriminantValue)}].type })`;
|
|
426
|
-
if (this.discriminant.kind === "Extrinsic" ||
|
|
427
|
-
(this.discriminant.kind === "Hybrid" &&
|
|
428
|
-
this.discriminant.memberValues[memberI].kind === "Extrinsic")) {
|
|
429
|
-
typeExpression = code `${typeExpression}.map(values => values.map(value => ({ ${this.discriminant.name}: ${literalOf(primaryDiscriminantValue)} as const, value }) as (${this.expression})))`;
|
|
430
|
-
}
|
|
431
|
-
typeExpression = code `(${typeExpression} as ${this.reusables.imports.Either}<Error, ${this.reusables.imports.Resource}.Values<${this.expression}>>)`;
|
|
432
|
-
return expression !== null
|
|
433
|
-
? code `${expression}.altLazy(() => ${typeExpression})`
|
|
434
|
-
: typeExpression;
|
|
435
|
-
}, null)}.chain(values => values.head());
|
|
436
|
-
})
|
|
437
|
-
) satisfies ${this.reusables.snippets.FromRdfResourceValuesFunction}<${this.expression}, ${this.schemaType}>)`;
|
|
438
|
-
}
|
|
439
|
-
get hashFunctionExpression() {
|
|
440
|
-
return code `\
|
|
441
|
-
(<HasherT extends ${this.reusables.snippets.Hasher}>(hasher: HasherT, value: ${this.expression}): HasherT => {
|
|
442
|
-
${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeCheck(code `value`)}) { return ${type.hashFunction}(hasher, ${unwrap(code `value`)}); }`))}
|
|
443
|
-
return hasher;
|
|
444
|
-
})`;
|
|
445
|
-
}
|
|
446
|
-
/**
|
|
447
|
-
* An inline expression of this type rather than a type reference/name.
|
|
448
|
-
*/
|
|
449
|
-
get inlineExpression() {
|
|
450
|
-
const discriminant = this.discriminant; // To get type narrowing to work
|
|
451
|
-
switch (discriminant.kind) {
|
|
452
|
-
case "Extrinsic":
|
|
453
|
-
return code `(${joinCode(this.members.map(({ type, primaryDiscriminantValue }) => code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${type.expression} }`), { on: "|" })})`;
|
|
454
|
-
case "Hybrid":
|
|
455
|
-
return code `(${joinCode(this.members.map(({ primaryDiscriminantValue, type }, memberI) => {
|
|
456
|
-
switch (discriminant.memberValues[memberI].kind) {
|
|
457
|
-
case "Extrinsic":
|
|
458
|
-
return code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${type.expression} }`;
|
|
459
|
-
case "Intrinsic":
|
|
460
|
-
return code `${type.expression}`;
|
|
461
|
-
default:
|
|
462
|
-
throw new Error();
|
|
463
|
-
}
|
|
464
|
-
}), { on: "|" })})`;
|
|
465
|
-
case "Intrinsic":
|
|
466
|
-
// If every type shares a discriminant (e.g., RDF/JS "termType" or generated ObjectType "type"),
|
|
467
|
-
// just join their names with "|"
|
|
468
|
-
return code `(${joinCode(this.members.map(({ type }) => code `${type.expression}`), { on: "|" })})`;
|
|
469
|
-
case "Typeof":
|
|
470
|
-
// The type.name may include literal values, but they should still be unambiguous with other member types since the typeofs
|
|
471
|
-
// of the different member types are known to be different.
|
|
472
|
-
return code `(${joinCode(this.members.map(({ type }) => code `${type.expression}`), { on: "|" })})`;
|
|
473
|
-
default:
|
|
474
|
-
discriminant;
|
|
475
|
-
throw new Error("should never reach this point");
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
get jsonSchemaExpression() {
|
|
479
|
-
const discriminant = this.discriminant; // To get type narrowing to work
|
|
480
|
-
switch (discriminant.kind) {
|
|
481
|
-
case "Extrinsic":
|
|
482
|
-
return code `${this.reusables.imports.z}.discriminatedUnion("${discriminant.name}", [${joinCode(this.members.map(({ type, primaryDiscriminantValue }) => code `${this.reusables.imports.z}.object({ ${discriminant.name}: ${this.reusables.imports.z}.literal(${literalOf(primaryDiscriminantValue)}), value: ${type.jsonSchema({ context: "type" })} })`), { on: "," })}]).readonly()`;
|
|
483
|
-
case "Hybrid":
|
|
484
|
-
return code `${this.reusables.imports.z}.discriminatedUnion("${discriminant.name}", [${joinCode(this.members.map(({ primaryDiscriminantValue, type }, memberI) => {
|
|
485
|
-
switch (discriminant.memberValues[memberI].kind) {
|
|
486
|
-
case "Extrinsic":
|
|
487
|
-
return code `${this.reusables.imports.z}.object({ ${discriminant.name}: ${this.reusables.imports.z}.literal(${literalOf(primaryDiscriminantValue)}), value: ${type.jsonSchema({ context: "type" })} })`;
|
|
488
|
-
case "Intrinsic":
|
|
489
|
-
return type.jsonSchema({
|
|
490
|
-
includeDiscriminantProperty: true,
|
|
491
|
-
context: "type",
|
|
492
|
-
});
|
|
493
|
-
default:
|
|
494
|
-
throw new Error();
|
|
495
|
-
}
|
|
496
|
-
}), { on: "," })}]).readonly()`;
|
|
497
|
-
case "Intrinsic":
|
|
498
|
-
return code `${this.reusables.imports.z}.discriminatedUnion("${discriminant.name}", [${joinCode(this.members.map(({ type }) => type.jsonSchema({
|
|
499
|
-
includeDiscriminantProperty: true,
|
|
500
|
-
context: "type",
|
|
501
|
-
})), { on: "," })}]).readonly()`;
|
|
502
|
-
case "Typeof":
|
|
503
|
-
return code `${this.reusables.imports.z}.union([${joinCode(this.members.map(({ type }) => type.jsonSchema({ context: "type" })), { on: "," })}]).readonly()`;
|
|
504
|
-
default:
|
|
505
|
-
throw discriminant;
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
get jsonTypeLiteral() {
|
|
509
|
-
const discriminant = this.discriminant; // To get type narrowing to work
|
|
510
|
-
switch (discriminant.kind) {
|
|
511
|
-
case "Extrinsic":
|
|
512
|
-
return new AbstractType.JsonType(code `(${joinCode(this.members.map(({ jsonType, primaryDiscriminantValue }) => code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${jsonType} }`), { on: "|" })})`);
|
|
513
|
-
case "Hybrid":
|
|
514
|
-
return new AbstractType.JsonType(code `(${joinCode(this.members.map(({ jsonType, primaryDiscriminantValue }, memberI) => {
|
|
515
|
-
switch (discriminant.memberValues[memberI].kind) {
|
|
516
|
-
case "Extrinsic":
|
|
517
|
-
return code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${jsonType} }`;
|
|
518
|
-
case "Intrinsic":
|
|
519
|
-
return code `${jsonType}`;
|
|
520
|
-
default:
|
|
521
|
-
throw new Error();
|
|
522
|
-
}
|
|
523
|
-
}), { on: "|" })})`);
|
|
524
|
-
case "Intrinsic":
|
|
525
|
-
case "Typeof":
|
|
526
|
-
return new AbstractType.JsonType(joinCode(this.members.map(({ jsonType }) => code `${jsonType}`), { on: "|" }));
|
|
527
|
-
default:
|
|
528
|
-
throw discriminant;
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
get toJsonFunctionExpression() {
|
|
532
|
-
return code `\
|
|
533
|
-
((value: ${this.expression}): ${this.jsonType().expression} => {
|
|
534
|
-
${joinCode(this.members.map(({ typeCheck, typeToJsonExpression, unwrap, wrap }) => code `if (${typeCheck(code `value`)}) { return ${wrap(typeToJsonExpression(unwrap(code `value`)))}; }`))}
|
|
535
|
-
|
|
536
|
-
throw new Error("unable to serialize to JSON");
|
|
537
|
-
})`;
|
|
538
|
-
}
|
|
539
|
-
get toRdfResourceValuesFunctionExpression() {
|
|
540
|
-
return code `\
|
|
541
|
-
(((value, _options): (${joinCode([...this.toRdfResourceValueTypes].map((toRdfResourceValueType) => {
|
|
542
|
-
switch (toRdfResourceValueType) {
|
|
543
|
-
case "BlankNode":
|
|
544
|
-
return code `${this.reusables.imports.BlankNode}`;
|
|
545
|
-
case "Literal":
|
|
546
|
-
return code `${this.reusables.imports.Literal}`;
|
|
547
|
-
case "NamedNode":
|
|
548
|
-
return code `${this.reusables.imports.NamedNode}`;
|
|
549
|
-
default:
|
|
550
|
-
toRdfResourceValueType;
|
|
551
|
-
throw new Error();
|
|
552
|
-
}
|
|
553
|
-
}), { on: " | " })})[] => {
|
|
554
|
-
${joinCode(this.members.map(({ type, unwrap, typeCheck }) => code `if (${typeCheck(code `value`)}) { return ${type.toRdfResourceValuesExpression({
|
|
555
|
-
variables: {
|
|
556
|
-
graph: code `_options.graph`,
|
|
557
|
-
propertyPath: code `_options.propertyPath`,
|
|
558
|
-
resource: code `_options.resource`,
|
|
559
|
-
resourceSet: code `_options.resourceSet`,
|
|
560
|
-
value: unwrap(code `value`),
|
|
561
|
-
},
|
|
562
|
-
})}; }`))}
|
|
563
|
-
|
|
564
|
-
throw new Error("unable to serialize to RDF");
|
|
565
|
-
}) satisfies ${this.reusables.snippets.ToRdfResourceValuesFunction}<${this.expression}>)`;
|
|
566
|
-
}
|
|
567
|
-
get toStringFunctionExpression() {
|
|
568
|
-
return code `\
|
|
569
|
-
((value: ${this.expression}): string => {
|
|
570
|
-
${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeCheck(code `value`)}) { return ${type.toStringExpression({
|
|
571
|
-
variables: { value: unwrap(code `value`) },
|
|
572
|
-
})}; }`))}
|
|
573
|
-
|
|
574
|
-
throw new Error("unable to serialize to string");
|
|
575
|
-
})`;
|
|
576
|
-
}
|
|
577
|
-
get valueSparqlConstructTriplesFunctionExpression() {
|
|
578
|
-
return code `\
|
|
579
|
-
((({ ignoreRdfType, filter, schema, ...otherParameters }) => {
|
|
580
|
-
let triples: ${this.reusables.imports.sparqljs}.Triple[] = [];
|
|
581
|
-
|
|
582
|
-
${joinCode(this.members.map(({ type, primaryDiscriminantValue }) => code `\
|
|
583
|
-
triples = triples.concat(${type.valueSparqlConstructTriplesFunction}({ ...otherParameters, filter: filter?.on?.[${literalOf(primaryDiscriminantValue)}], ignoreRdfType: false, schema: schema.members[${literalOf(primaryDiscriminantValue)}].type }));`))}
|
|
584
|
-
|
|
585
|
-
return triples;
|
|
586
|
-
}) satisfies ${this.reusables.snippets.ValueSparqlConstructTriplesFunction}<${this.filterType}, ${this.schemaType}>)`;
|
|
587
|
-
}
|
|
588
|
-
get valueSparqlWherePatternsFunctionExpression() {
|
|
589
|
-
return code `\
|
|
590
|
-
((({ filter, schema, ...otherParameters }) => {
|
|
591
|
-
const unionPatterns: ${this.reusables.imports.sparqljs}.GroupPattern[] = [];
|
|
592
|
-
|
|
593
|
-
${joinCode(this.members.map(({ type, primaryDiscriminantValue }) => code `\
|
|
594
|
-
unionPatterns.push({ patterns: ${type.valueSparqlWherePatternsFunction}({ ...otherParameters, filter: filter?.on?.[${literalOf(primaryDiscriminantValue)}], ignoreRdfType: false, schema: schema.members[${literalOf(primaryDiscriminantValue)}].type }).concat(), type: "group" });`))}
|
|
595
|
-
|
|
596
|
-
return [{ patterns: unionPatterns, type: "union" }];
|
|
597
|
-
}) satisfies ${this.reusables.snippets.ValueSparqlWherePatternsFunction}<${this.filterType}, ${this.schemaType}>)`;
|
|
598
|
-
}
|
|
599
373
|
fromJsonExpression({ variables, }) {
|
|
600
|
-
return code `${this.name.map((name) => code `${name}.fromJson`).orDefault(this
|
|
374
|
+
return code `${this.name.map((name) => code `${name}.fromJson`).orDefault(DiscriminatedUnionType_fromJsonFunctionExpression.call(this))}(${variables.value})`;
|
|
601
375
|
}
|
|
602
376
|
graphqlResolveExpression({ variables, }) {
|
|
603
377
|
return variables.value;
|
|
@@ -605,7 +379,7 @@ unionPatterns.push({ patterns: ${type.valueSparqlWherePatternsFunction}({ ...oth
|
|
|
605
379
|
jsonSchema({ context, }) {
|
|
606
380
|
const expression = this.name
|
|
607
381
|
.map((name) => code `${name}.Json.schema()`)
|
|
608
|
-
.orDefault(this
|
|
382
|
+
.orDefault(DiscriminatedUnionType_jsonSchemaExpression.call(this));
|
|
609
383
|
if (context === "property" && this.recursive) {
|
|
610
384
|
return code `${this.reusables.imports.z}.lazy((): ${this.reusables.imports.z}.ZodType<${this.jsonType().expression}> => ${expression})`;
|
|
611
385
|
}
|
|
@@ -614,20 +388,20 @@ unionPatterns.push({ patterns: ${type.valueSparqlWherePatternsFunction}({ ...oth
|
|
|
614
388
|
jsonType() {
|
|
615
389
|
return this.name
|
|
616
390
|
.map((name) => new AbstractType.JsonType(code `${name}.Json`))
|
|
617
|
-
.orDefault(this
|
|
391
|
+
.orDefault(DiscriminatedUnionType_jsonTypeLiteral.call(this));
|
|
618
392
|
}
|
|
619
393
|
jsonUiSchemaElement() {
|
|
620
394
|
return Maybe.empty();
|
|
621
395
|
}
|
|
622
396
|
toJsonExpression({ variables, }) {
|
|
623
|
-
return code `${this.name.map((name) => code `${name}.toJson`).orDefault(this
|
|
397
|
+
return code `${this.name.map((name) => code `${name}.toJson`).orDefault(DiscriminatedUnionType_toJsonFunctionExpression.call(this))}(${variables.value})`;
|
|
624
398
|
}
|
|
625
399
|
toRdfResourceValuesExpression({ variables, }) {
|
|
626
400
|
const { value: valueVariable, ...otherVariables } = variables;
|
|
627
|
-
return code `${this.name.map((name) => code `${name}.toRdfResourceValues`).orDefault(this
|
|
401
|
+
return code `${this.name.map((name) => code `${name}.toRdfResourceValues`).orDefault(DiscriminatedUnionType_toRdfResourceValuesFunctionExpression.call(this))}(${valueVariable}, ${otherVariables})`;
|
|
628
402
|
}
|
|
629
403
|
toStringExpression({ variables, }) {
|
|
630
|
-
return code `${this.name.map((name) => code `${name}.${this.configuration.syntheticNamePrefix}toString`).orDefault(this
|
|
404
|
+
return code `${this.name.map((name) => code `${name}.${this.configuration.syntheticNamePrefix}toString`).orDefault(DiscriminatedUnionType_toStringFunctionExpression.call(this))}(${variables.value})`;
|
|
631
405
|
}
|
|
632
406
|
lazyMembers;
|
|
633
407
|
}
|
|
@@ -685,166 +459,7 @@ __decorate([
|
|
|
685
459
|
__decorate([
|
|
686
460
|
Memoize()
|
|
687
461
|
], DiscriminatedUnionType.prototype, "valueSparqlWherePatternsFunction", null);
|
|
688
|
-
__decorate([
|
|
689
|
-
Memoize()
|
|
690
|
-
], DiscriminatedUnionType.prototype, "schemaTypeExpression", null);
|
|
691
|
-
__decorate([
|
|
692
|
-
Memoize()
|
|
693
|
-
], DiscriminatedUnionType.prototype, "equalsFunctionExpression", null);
|
|
694
|
-
__decorate([
|
|
695
|
-
Memoize()
|
|
696
|
-
], DiscriminatedUnionType.prototype, "filterFunctionExpression", null);
|
|
697
|
-
__decorate([
|
|
698
|
-
Memoize()
|
|
699
|
-
], DiscriminatedUnionType.prototype, "filterTypeLiteral", null);
|
|
700
|
-
__decorate([
|
|
701
|
-
Memoize()
|
|
702
|
-
], DiscriminatedUnionType.prototype, "inlineExpression", null);
|
|
703
|
-
__decorate([
|
|
704
|
-
Memoize()
|
|
705
|
-
], DiscriminatedUnionType.prototype, "jsonTypeLiteral", null);
|
|
706
|
-
__decorate([
|
|
707
|
-
Memoize()
|
|
708
|
-
], DiscriminatedUnionType.prototype, "valueSparqlConstructTriplesFunctionExpression", null);
|
|
709
|
-
__decorate([
|
|
710
|
-
Memoize()
|
|
711
|
-
], DiscriminatedUnionType.prototype, "valueSparqlWherePatternsFunctionExpression", null);
|
|
712
462
|
__decorate([
|
|
713
463
|
Memoize()
|
|
714
464
|
], DiscriminatedUnionType.prototype, "jsonType", null);
|
|
715
|
-
function termTypes(type) {
|
|
716
|
-
switch (type.kind) {
|
|
717
|
-
case "BlankNode":
|
|
718
|
-
case "Iri":
|
|
719
|
-
case "Identifier":
|
|
720
|
-
case "Literal":
|
|
721
|
-
case "Term":
|
|
722
|
-
return type.termTypes;
|
|
723
|
-
default:
|
|
724
|
-
return emptyTermTypesSet;
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
const emptyTermTypesSet = new Set();
|
|
728
|
-
export var Discriminant;
|
|
729
|
-
(function (Discriminant) {
|
|
730
|
-
function infer(members) {
|
|
731
|
-
// extrinsic with user-specified values
|
|
732
|
-
if (members.some((member) => member.discriminantValue.isJust())) {
|
|
733
|
-
return {
|
|
734
|
-
jsonName: "type",
|
|
735
|
-
kind: "Extrinsic",
|
|
736
|
-
memberValues: members.map((member, memberI) => member.discriminantValue.orDefault(memberI)),
|
|
737
|
-
name: "type",
|
|
738
|
-
};
|
|
739
|
-
}
|
|
740
|
-
const memberTypes = members.map((member) => member.type);
|
|
741
|
-
// intrinsic
|
|
742
|
-
{
|
|
743
|
-
let inlineDiscriminantProperty;
|
|
744
|
-
let memberValues = [];
|
|
745
|
-
for (const memberType of memberTypes) {
|
|
746
|
-
const memberTypeDiscriminantProperty = memberType.discriminantProperty.extract();
|
|
747
|
-
if (!memberTypeDiscriminantProperty) {
|
|
748
|
-
inlineDiscriminantProperty = undefined;
|
|
749
|
-
break;
|
|
750
|
-
}
|
|
751
|
-
if (!inlineDiscriminantProperty) {
|
|
752
|
-
inlineDiscriminantProperty = memberTypeDiscriminantProperty;
|
|
753
|
-
}
|
|
754
|
-
else if (memberTypeDiscriminantProperty.name !==
|
|
755
|
-
inlineDiscriminantProperty.name) {
|
|
756
|
-
inlineDiscriminantProperty = undefined;
|
|
757
|
-
break;
|
|
758
|
-
}
|
|
759
|
-
memberValues = memberValues.concat(memberTypeDiscriminantProperty.values);
|
|
760
|
-
}
|
|
761
|
-
if (inlineDiscriminantProperty) {
|
|
762
|
-
return {
|
|
763
|
-
jsonName: inlineDiscriminantProperty.jsonName,
|
|
764
|
-
kind: "Intrinsic",
|
|
765
|
-
memberValues,
|
|
766
|
-
name: inlineDiscriminantProperty.name,
|
|
767
|
-
};
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
|
-
// typeof
|
|
771
|
-
{
|
|
772
|
-
const memberTypeofs = [];
|
|
773
|
-
const memberTypeofsSet = new Set();
|
|
774
|
-
for (const memberType of memberTypes) {
|
|
775
|
-
for (const memberJsType of memberType.jsTypes) {
|
|
776
|
-
memberTypeofs.push(memberJsType.typeof);
|
|
777
|
-
memberTypeofsSet.add(memberJsType.typeof);
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
if (memberTypeofsSet.size === memberTypes.length) {
|
|
781
|
-
return {
|
|
782
|
-
memberValues: memberTypeofs,
|
|
783
|
-
kind: "Typeof",
|
|
784
|
-
};
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
// hybrid
|
|
788
|
-
// If some member type is an RDF/JS term then reuse "termType" as the discriminant.
|
|
789
|
-
if (memberTypes.some((memberType) => termTypes(memberType).size > 0)) {
|
|
790
|
-
const extrinsicMemberTypeAliasesSet = new Set();
|
|
791
|
-
let extrinsicMemberTypeCount = 0;
|
|
792
|
-
for (const memberType of memberTypes) {
|
|
793
|
-
if (termTypes(memberType).size > 0) {
|
|
794
|
-
continue;
|
|
795
|
-
}
|
|
796
|
-
extrinsicMemberTypeCount++;
|
|
797
|
-
if (memberType.name.isJust()) {
|
|
798
|
-
extrinsicMemberTypeAliasesSet.add(memberType.name.extract());
|
|
799
|
-
}
|
|
800
|
-
else {
|
|
801
|
-
break;
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
return {
|
|
805
|
-
jsonName: "termType",
|
|
806
|
-
kind: "Hybrid",
|
|
807
|
-
memberValues: memberTypes.map((memberType, memberTypeI) => {
|
|
808
|
-
const memberTermTypes = termTypes(memberType);
|
|
809
|
-
if (memberTermTypes.size > 0) {
|
|
810
|
-
return {
|
|
811
|
-
kind: "Intrinsic",
|
|
812
|
-
values: [...memberTermTypes],
|
|
813
|
-
};
|
|
814
|
-
}
|
|
815
|
-
return {
|
|
816
|
-
kind: "Extrinsic",
|
|
817
|
-
values: extrinsicMemberTypeAliasesSet.size === extrinsicMemberTypeCount
|
|
818
|
-
? [memberType.name.unsafeCoerce()]
|
|
819
|
-
: [memberTypeI.toString()],
|
|
820
|
-
};
|
|
821
|
-
}),
|
|
822
|
-
name: "termType",
|
|
823
|
-
};
|
|
824
|
-
}
|
|
825
|
-
// extrinsic with inferred values
|
|
826
|
-
{
|
|
827
|
-
let memberValues;
|
|
828
|
-
{
|
|
829
|
-
const memberTypeNames = memberTypes.map((memberType) => memberType.name.orDefault(memberType.jsTypes[0].typeof));
|
|
830
|
-
const memberTypeNamesSet = new Set(memberTypeNames);
|
|
831
|
-
if (memberTypeNamesSet.size === memberTypeNames.length) {
|
|
832
|
-
memberValues = memberTypeNames;
|
|
833
|
-
}
|
|
834
|
-
else {
|
|
835
|
-
// Otherwise prefix the non-unique strings with an index and use those as the discriminant values.
|
|
836
|
-
memberValues = memberTypeNames.map((memberTypeName, memberTypeI) => `${memberTypeI}-${memberTypeName}`);
|
|
837
|
-
}
|
|
838
|
-
}
|
|
839
|
-
invariant(memberValues.length === memberTypes.length);
|
|
840
|
-
return {
|
|
841
|
-
jsonName: "type",
|
|
842
|
-
kind: "Extrinsic",
|
|
843
|
-
name: "type",
|
|
844
|
-
memberValues,
|
|
845
|
-
};
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
Discriminant.infer = infer;
|
|
849
|
-
})(Discriminant || (Discriminant = {}));
|
|
850
465
|
//# sourceMappingURL=DiscriminatedUnionType.js.map
|
|
@@ -54,7 +54,7 @@ export class IdentifierType extends AbstractIdentifierType {
|
|
|
54
54
|
}
|
|
55
55
|
jsonSchema({ includeDiscriminantProperty, }) {
|
|
56
56
|
const discriminantProperty = includeDiscriminantProperty
|
|
57
|
-
? code `, termType: ${this.reusables.imports.z}.enum(${arrayOf(...this.nodeKinds)})`
|
|
57
|
+
? code `, termType: ${this.reusables.imports.z}.enum(${arrayOf(...[...this.nodeKinds].map(NodeKind.toTermType))})`
|
|
58
58
|
: "";
|
|
59
59
|
return code `${this.reusables.imports.z}.object({ "@id": ${this.reusables.imports.z}.string().min(1)${discriminantProperty} })`;
|
|
60
60
|
}
|
|
@@ -8,13 +8,5 @@ export declare class ObjectDiscriminatedUnionType extends DiscriminatedUnionType
|
|
|
8
8
|
get schema(): Code;
|
|
9
9
|
get schemaType(): Code;
|
|
10
10
|
protected get staticModuleDeclarations(): Record<string, Code>;
|
|
11
|
-
private get focusSparqlConstructTriplesFunctionDeclaration();
|
|
12
|
-
private get focusSparqlWherePatternsFunctionDeclaration();
|
|
13
|
-
private get fromRdfResourceFunctionDeclaration();
|
|
14
|
-
private get graphqlTypeVariableStatement();
|
|
15
|
-
private get identifierTypeDeclarations();
|
|
16
|
-
private get isTypeFunctionDeclaration();
|
|
17
|
-
private get schemaVariableStatement();
|
|
18
|
-
private get toRdfResourceFunctionDeclaration();
|
|
19
11
|
}
|
|
20
12
|
//# sourceMappingURL=ObjectDiscriminatedUnionType.d.ts.map
|