@shaclmate/compiler 4.0.59 → 4.0.61
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 -430
- 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 +59 -8
|
@@ -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,7 +38,7 @@ 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;
|
|
@@ -137,7 +153,7 @@ export class DiscriminatedUnionType extends AbstractType {
|
|
|
137
153
|
}
|
|
138
154
|
const declarations = [];
|
|
139
155
|
if (this.configuration.features.has("Object.type")) {
|
|
140
|
-
declarations.push(code `export type ${def(name)} = ${this
|
|
156
|
+
declarations.push(code `export type ${def(name)} = ${DiscriminatedUnionType_inlineExpression.call(this)};`);
|
|
141
157
|
}
|
|
142
158
|
const staticModuleDeclarations = Object.entries(this.staticModuleDeclarations);
|
|
143
159
|
if (staticModuleDeclarations.length > 0) {
|
|
@@ -179,27 +195,27 @@ ${joinCode(staticModuleDeclarations
|
|
|
179
195
|
get equalsFunction() {
|
|
180
196
|
return this.name
|
|
181
197
|
.map((name) => code `${name}.equals`)
|
|
182
|
-
.orDefault(this
|
|
198
|
+
.orDefault(DiscriminatedUnionType_equalsFunctionExpression.call(this));
|
|
183
199
|
}
|
|
184
200
|
get expression() {
|
|
185
201
|
return this.name
|
|
186
202
|
.map((name) => code `${name}`)
|
|
187
|
-
.orDefault(this
|
|
203
|
+
.orDefault(DiscriminatedUnionType_inlineExpression.call(this));
|
|
188
204
|
}
|
|
189
205
|
get filterFunction() {
|
|
190
206
|
return this.name
|
|
191
207
|
.map((name) => code `${name}.filter`)
|
|
192
|
-
.orDefault(this
|
|
208
|
+
.orDefault(DiscriminatedUnionType_filterFunctionExpression.call(this));
|
|
193
209
|
}
|
|
194
210
|
get filterType() {
|
|
195
211
|
return this.name
|
|
196
212
|
.map((name) => code `${name}.Filter`)
|
|
197
|
-
.orDefault(this
|
|
213
|
+
.orDefault(DiscriminatedUnionType_filterTypeExpression.call(this));
|
|
198
214
|
}
|
|
199
215
|
get fromRdfResourceValuesFunction() {
|
|
200
216
|
return this.name
|
|
201
217
|
.map((name) => code `${name}.fromRdfResourceValues`)
|
|
202
|
-
.orDefault(this
|
|
218
|
+
.orDefault(DiscriminatedUnionType_fromRdfResourceValuesFunctionExpression.call(this));
|
|
203
219
|
}
|
|
204
220
|
get graphqlType() {
|
|
205
221
|
const name = this.name.extract();
|
|
@@ -212,7 +228,7 @@ ${joinCode(staticModuleDeclarations
|
|
|
212
228
|
get hashFunction() {
|
|
213
229
|
return this.name
|
|
214
230
|
.map((name) => code `${name}.hash`)
|
|
215
|
-
.orDefault(this
|
|
231
|
+
.orDefault(DiscriminatedUnionType_hashFunctionExpression.call(this));
|
|
216
232
|
}
|
|
217
233
|
get jsTypes() {
|
|
218
234
|
const jsTypes = [];
|
|
@@ -226,7 +242,7 @@ ${joinCode(staticModuleDeclarations
|
|
|
226
242
|
return jsTypes;
|
|
227
243
|
}
|
|
228
244
|
get jsonSchemaFunctionDeclaration() {
|
|
229
|
-
let expression = this
|
|
245
|
+
let expression = DiscriminatedUnionType_jsonSchemaExpression.call(this);
|
|
230
246
|
const meta = {
|
|
231
247
|
// id: this.name,
|
|
232
248
|
};
|
|
@@ -242,7 +258,7 @@ ${joinCode(staticModuleDeclarations
|
|
|
242
258
|
return code `export const schema = () => ${expression};`;
|
|
243
259
|
}
|
|
244
260
|
get jsonTypeAliasDeclaration() {
|
|
245
|
-
return code `export type Json = ${this.
|
|
261
|
+
return code `export type Json = ${DiscriminatedUnionType_jsonTypeLiteral.call(this).expression}`;
|
|
246
262
|
}
|
|
247
263
|
get members() {
|
|
248
264
|
return this.lazyMembers();
|
|
@@ -262,7 +278,7 @@ ${joinCode(staticModuleDeclarations
|
|
|
262
278
|
get schemaType() {
|
|
263
279
|
return this.name
|
|
264
280
|
.map(() => code `typeof ${this.schema}`)
|
|
265
|
-
.orDefault(this
|
|
281
|
+
.orDefault(DiscriminatedUnionType_schemaTypeExpression.call(this));
|
|
266
282
|
}
|
|
267
283
|
get toRdfResourceValueTypes() {
|
|
268
284
|
const set = new Set();
|
|
@@ -276,12 +292,12 @@ ${joinCode(staticModuleDeclarations
|
|
|
276
292
|
get valueSparqlConstructTriplesFunction() {
|
|
277
293
|
return this.name
|
|
278
294
|
.map((name) => code `${name}.valueSparqlConstructTriples`)
|
|
279
|
-
.orDefault(this
|
|
295
|
+
.orDefault(DiscriminatedUnionType_valueSparqlConstructTriplesFunctionExpression.call(this));
|
|
280
296
|
}
|
|
281
297
|
get valueSparqlWherePatternsFunction() {
|
|
282
298
|
return this.name
|
|
283
299
|
.map((name) => code `${name}.valueSparqlWherePatterns`)
|
|
284
|
-
.orDefault(this
|
|
300
|
+
.orDefault(DiscriminatedUnionType_valueSparqlWherePatternsFunctionExpression.call(this));
|
|
285
301
|
}
|
|
286
302
|
get schemaInitializers() {
|
|
287
303
|
return super.schemaInitializers.concat(code `members: { ${joinCode(this.members.map(({ discriminantValues, type, primaryDiscriminantValue }) => code `${literalOf(primaryDiscriminantValue)}: ${{
|
|
@@ -289,31 +305,22 @@ ${joinCode(staticModuleDeclarations
|
|
|
289
305
|
type: type.schema,
|
|
290
306
|
}}`), { on: "," })} }`);
|
|
291
307
|
}
|
|
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
308
|
get staticModuleDeclarations() {
|
|
302
309
|
const name = this.name.unsafeCoerce();
|
|
303
310
|
const staticModuleDeclarations = {};
|
|
304
311
|
if (this.configuration.features.has("Object.equals")) {
|
|
305
312
|
staticModuleDeclarations[`equals`] =
|
|
306
|
-
code `export const equals = ${this
|
|
313
|
+
code `export const equals = ${DiscriminatedUnionType_equalsFunctionExpression.call(this)};`;
|
|
307
314
|
}
|
|
308
315
|
if (this.configuration.features.has("Object.filter")) {
|
|
309
316
|
staticModuleDeclarations[`Filter`] =
|
|
310
|
-
code `export type Filter = ${this
|
|
317
|
+
code `export type Filter = ${DiscriminatedUnionType_filterTypeExpression.call(this)};`;
|
|
311
318
|
staticModuleDeclarations[`filter`] =
|
|
312
|
-
code `export const filter = ${this
|
|
319
|
+
code `export const filter = ${DiscriminatedUnionType_filterFunctionExpression.call(this)};`;
|
|
313
320
|
}
|
|
314
321
|
if (this.configuration.features.has("Object.hash")) {
|
|
315
322
|
staticModuleDeclarations[`hash`] =
|
|
316
|
-
code `export const hash = ${this
|
|
323
|
+
code `export const hash = ${DiscriminatedUnionType_hashFunctionExpression.call(this)};`;
|
|
317
324
|
}
|
|
318
325
|
if (this.configuration.features.has("Object.JSON.type")) {
|
|
319
326
|
staticModuleDeclarations[`Json.type`] =
|
|
@@ -333,11 +340,11 @@ export namespace Json {
|
|
|
333
340
|
}
|
|
334
341
|
if (this.configuration.features.has("Object.fromJson")) {
|
|
335
342
|
staticModuleDeclarations[`fromJson`] =
|
|
336
|
-
code `export const fromJson = ${this
|
|
343
|
+
code `export const fromJson = ${DiscriminatedUnionType_fromJsonFunctionExpression.call(this)};`;
|
|
337
344
|
}
|
|
338
345
|
if (this.configuration.features.has("Object.fromRdf")) {
|
|
339
346
|
staticModuleDeclarations[`fromRdfResourceValues`] =
|
|
340
|
-
code `export const fromRdfResourceValues: ${this.reusables.snippets.FromRdfResourceValuesFunction}<${name}, ${this.schemaType}> = ${this
|
|
347
|
+
code `export const fromRdfResourceValues: ${this.reusables.snippets.FromRdfResourceValuesFunction}<${name}, ${this.schemaType}> = ${DiscriminatedUnionType_fromRdfResourceValuesFunctionExpression.call(this)};`;
|
|
341
348
|
}
|
|
342
349
|
if (this.configuration.features.has("Object.schema")) {
|
|
343
350
|
staticModuleDeclarations["schema"] =
|
|
@@ -345,259 +352,27 @@ export namespace Json {
|
|
|
345
352
|
}
|
|
346
353
|
if (this.configuration.features.has("Object.toJson")) {
|
|
347
354
|
staticModuleDeclarations[`toJson`] =
|
|
348
|
-
code `export const toJson = ${this
|
|
355
|
+
code `export const toJson = ${DiscriminatedUnionType_toJsonFunctionExpression.call(this)};`;
|
|
349
356
|
}
|
|
350
357
|
if (this.configuration.features.has("Object.toRdf")) {
|
|
351
358
|
staticModuleDeclarations[`toRdfResourceValues`] =
|
|
352
|
-
code `export const toRdfResourceValues = ${this
|
|
359
|
+
code `export const toRdfResourceValues = ${DiscriminatedUnionType_toRdfResourceValuesFunctionExpression.call(this)};`;
|
|
353
360
|
}
|
|
354
361
|
if (this.configuration.features.has("Object.SPARQL")) {
|
|
355
362
|
staticModuleDeclarations[`valueSparqlConstructTriples`] =
|
|
356
|
-
code `export const valueSparqlConstructTriples: ${this.reusables.snippets.ValueSparqlConstructTriplesFunction}<${this.filterType}, ${this.schemaType}> = ${this
|
|
363
|
+
code `export const valueSparqlConstructTriples: ${this.reusables.snippets.ValueSparqlConstructTriplesFunction}<${this.filterType}, ${this.schemaType}> = ${DiscriminatedUnionType_valueSparqlConstructTriplesFunctionExpression.call(this)};`;
|
|
357
364
|
staticModuleDeclarations[`valueSparqlWherePatterns`] =
|
|
358
|
-
code `export const valueSparqlWherePatterns: ${this.reusables.snippets.ValueSparqlWherePatternsFunction}<${this.filterType}, ${this.schemaType}> = ${this
|
|
365
|
+
code `export const valueSparqlWherePatterns: ${this.reusables.snippets.ValueSparqlWherePatternsFunction}<${this.filterType}, ${this.schemaType}> = ${DiscriminatedUnionType_valueSparqlWherePatternsFunctionExpression.call(this)};`;
|
|
359
366
|
}
|
|
360
367
|
if (this.configuration.features.has("Object.toString")) {
|
|
361
368
|
const syntheticNamePrefix = this.configuration.syntheticNamePrefix;
|
|
362
369
|
staticModuleDeclarations[`${syntheticNamePrefix}toString`] =
|
|
363
|
-
code `export const ${syntheticNamePrefix}toString = ${this
|
|
370
|
+
code `export const ${syntheticNamePrefix}toString = ${DiscriminatedUnionType_toStringFunctionExpression.call(this)};`;
|
|
364
371
|
}
|
|
365
372
|
return staticModuleDeclarations;
|
|
366
373
|
}
|
|
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
374
|
fromJsonExpression({ variables, }) {
|
|
600
|
-
return code `${this.name.map((name) => code `${name}.fromJson`).orDefault(this
|
|
375
|
+
return code `${this.name.map((name) => code `${name}.fromJson`).orDefault(DiscriminatedUnionType_fromJsonFunctionExpression.call(this))}(${variables.value})`;
|
|
601
376
|
}
|
|
602
377
|
graphqlResolveExpression({ variables, }) {
|
|
603
378
|
return variables.value;
|
|
@@ -605,7 +380,7 @@ unionPatterns.push({ patterns: ${type.valueSparqlWherePatternsFunction}({ ...oth
|
|
|
605
380
|
jsonSchema({ context, }) {
|
|
606
381
|
const expression = this.name
|
|
607
382
|
.map((name) => code `${name}.Json.schema()`)
|
|
608
|
-
.orDefault(this
|
|
383
|
+
.orDefault(DiscriminatedUnionType_jsonSchemaExpression.call(this));
|
|
609
384
|
if (context === "property" && this.recursive) {
|
|
610
385
|
return code `${this.reusables.imports.z}.lazy((): ${this.reusables.imports.z}.ZodType<${this.jsonType().expression}> => ${expression})`;
|
|
611
386
|
}
|
|
@@ -614,20 +389,20 @@ unionPatterns.push({ patterns: ${type.valueSparqlWherePatternsFunction}({ ...oth
|
|
|
614
389
|
jsonType() {
|
|
615
390
|
return this.name
|
|
616
391
|
.map((name) => new AbstractType.JsonType(code `${name}.Json`))
|
|
617
|
-
.orDefault(this
|
|
392
|
+
.orDefault(DiscriminatedUnionType_jsonTypeLiteral.call(this));
|
|
618
393
|
}
|
|
619
394
|
jsonUiSchemaElement() {
|
|
620
395
|
return Maybe.empty();
|
|
621
396
|
}
|
|
622
397
|
toJsonExpression({ variables, }) {
|
|
623
|
-
return code `${this.name.map((name) => code `${name}.toJson`).orDefault(this
|
|
398
|
+
return code `${this.name.map((name) => code `${name}.toJson`).orDefault(DiscriminatedUnionType_toJsonFunctionExpression.call(this))}(${variables.value})`;
|
|
624
399
|
}
|
|
625
400
|
toRdfResourceValuesExpression({ variables, }) {
|
|
626
401
|
const { value: valueVariable, ...otherVariables } = variables;
|
|
627
|
-
return code `${this.name.map((name) => code `${name}.toRdfResourceValues`).orDefault(this
|
|
402
|
+
return code `${this.name.map((name) => code `${name}.toRdfResourceValues`).orDefault(DiscriminatedUnionType_toRdfResourceValuesFunctionExpression.call(this))}(${valueVariable}, ${otherVariables})`;
|
|
628
403
|
}
|
|
629
404
|
toStringExpression({ variables, }) {
|
|
630
|
-
return code `${this.name.map((name) => code `${name}.${this.configuration.syntheticNamePrefix}toString`).orDefault(this
|
|
405
|
+
return code `${this.name.map((name) => code `${name}.${this.configuration.syntheticNamePrefix}toString`).orDefault(DiscriminatedUnionType_toStringFunctionExpression.call(this))}(${variables.value})`;
|
|
631
406
|
}
|
|
632
407
|
lazyMembers;
|
|
633
408
|
}
|
|
@@ -685,166 +460,7 @@ __decorate([
|
|
|
685
460
|
__decorate([
|
|
686
461
|
Memoize()
|
|
687
462
|
], 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
463
|
__decorate([
|
|
713
464
|
Memoize()
|
|
714
465
|
], 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
466
|
//# sourceMappingURL=DiscriminatedUnionType.js.map
|
|
@@ -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
|