@shaclmate/compiler 4.0.24 → 4.0.25
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/Compiler.d.ts +1 -1
- package/dist/ShapesGraphToAstTransformer.d.ts +1 -1
- package/dist/_ShapesGraphToAstTransformer/nodeShapeTsFeatures.d.ts +1 -1
- package/dist/_ShapesGraphToAstTransformer/nodeShapeTsFeatures.js +5 -2
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +0 -6
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstListType.js +0 -2
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstObjectType.js +14 -32
- package/dist/ast/AbstractCompoundType.d.ts +1 -1
- package/dist/ast/ObjectType.d.ts +3 -23
- package/dist/ast/ObjectType.js +2 -20
- package/dist/generators/ts/AbstractContainerType.d.ts +0 -1
- package/dist/generators/ts/AbstractContainerType.js +0 -1
- package/dist/generators/ts/AbstractLazyObjectType.d.ts +0 -1
- package/dist/generators/ts/AbstractLazyObjectType.js +2 -2
- package/dist/generators/ts/AbstractNamedUnionType.d.ts +1 -2
- package/dist/generators/ts/AbstractNamedUnionType.js +16 -19
- package/dist/generators/ts/AbstractTermType.d.ts +0 -1
- package/dist/generators/ts/AbstractTermType.js +0 -1
- package/dist/generators/ts/AbstractType.d.ts +0 -4
- package/dist/generators/ts/AbstractUnionType.d.ts +1 -10
- package/dist/generators/ts/AbstractUnionType.js +26 -39
- package/dist/generators/ts/LazyObjectOptionType.js +3 -2
- package/dist/generators/ts/LazyObjectSetType.js +2 -1
- package/dist/generators/ts/LazyObjectType.js +2 -1
- package/dist/generators/ts/NamedObjectType.d.ts +2 -13
- package/dist/generators/ts/NamedObjectType.js +33 -104
- package/dist/generators/ts/NamedObjectUnionType.js +13 -24
- package/dist/generators/ts/TypeFactory.js +10 -28
- package/dist/generators/ts/ZodGenerator.js +2 -2
- package/dist/generators/ts/_NamedObjectType/AbstractProperty.d.ts +1 -7
- package/dist/generators/ts/_NamedObjectType/AbstractProperty.js +1 -6
- package/dist/generators/ts/_NamedObjectType/DiscriminantProperty.d.ts +0 -1
- package/dist/generators/ts/_NamedObjectType/DiscriminantProperty.js +4 -31
- package/dist/generators/ts/_NamedObjectType/IdentifierProperty.js +6 -17
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_createFunctionDeclaration.js +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_equalsFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_equalsFunctionDeclaration.js +25 -0
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_filterTypeDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlConstructTriplesFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlWherePatternsFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromJsonFunctionDeclaration.js +1 -4
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceFunctionDeclaration.js +1 -4
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceValuesFunctionDeclaration.js +1 -4
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_hashFunctionDeclarations.d.ts +4 -0
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_hashFunctionDeclarations.js +49 -0
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonParseFunctionDeclaration.js +0 -3
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonSchemaFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonUiSchemaFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_propertiesFromJsonFunctionDeclaration.js +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_propertiesFromRdfResourceFunctionDeclaration.js +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_schemaVariableStatement.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_sparqlConstructQueryFunctionDeclaration.d.ts +1 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_sparqlConstructQueryFunctionDeclaration.js +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_sparqlConstructQueryStringFunctionDeclaration.d.ts +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_sparqlConstructQueryStringFunctionDeclaration.js +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toJsonFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/_NamedObjectType/{NamedObjectType_toJsonFunctionOrMethodDeclaration.js → NamedObjectType_toJsonFunctionDeclaration.js} +5 -27
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toRdfResourceFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/_NamedObjectType/{NamedObjectType_toRdfResourceFunctionOrMethodDeclaration.js → NamedObjectType_toRdfResourceFunctionDeclaration.js} +4 -25
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toStringFunctionDeclarations.d.ts +4 -0
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toStringFunctionDeclarations.js +40 -0
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_valueSparqlConstructTriplesFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_valueSparqlWherePatternsFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/ShaclProperty.js +6 -28
- package/dist/generators/ts/objectSetDeclarations.js +1 -3
- package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +2 -4
- package/dist/generators/ts/sparqlObjectSetClassDeclaration.js +1 -1
- package/dist/input/ShapesGraph.d.ts +1 -1
- package/dist/input/generated.d.ts +0 -134
- package/dist/input/generated.js +12 -239
- package/package.json +2 -4
- package/dist/enums/TsObjectDeclarationType.d.ts +0 -9
- package/dist/enums/TsObjectDeclarationType.js +0 -16
- package/dist/enums/Visibility.d.ts +0 -6
- package/dist/enums/Visibility.js +0 -18
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_classDeclaration.d.ts +0 -4
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_classDeclaration.js +0 -61
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_equalsFunctionOrMethodDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_equalsFunctionOrMethodDeclaration.js +0 -52
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_hashFunctionOrMethodDeclarations.d.ts +0 -4
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_hashFunctionOrMethodDeclarations.js +0 -77
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toJsonFunctionOrMethodDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toRdfResourceFunctionOrMethodDeclaration.d.ts +0 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toStringFunctionOrMethodDeclaration.d.ts +0 -4
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toStringFunctionOrMethodDeclaration.js +0 -66
- /package/dist/{enums → generators/ts}/TsFeature.d.ts +0 -0
- /package/dist/{enums → generators/ts}/TsFeature.js +0 -0
|
@@ -16,7 +16,6 @@ import { code, joinCode, literalOf } from "./ts-poet-wrapper.js";
|
|
|
16
16
|
export class AbstractUnionType extends AbstractType {
|
|
17
17
|
discriminant;
|
|
18
18
|
identifierType;
|
|
19
|
-
abstract = false;
|
|
20
19
|
recursive;
|
|
21
20
|
constructor({ identifierType, members, recursive, ...superParameters }) {
|
|
22
21
|
super(superParameters);
|
|
@@ -25,9 +24,6 @@ export class AbstractUnionType extends AbstractType {
|
|
|
25
24
|
this.recursive = recursive;
|
|
26
25
|
this.discriminant = Discriminant.infer(members);
|
|
27
26
|
this.lazyMembers = () => members.map((member, memberI) => {
|
|
28
|
-
if (member.type.abstract) {
|
|
29
|
-
return { abstract: true, discriminantValues: [], type: member.type };
|
|
30
|
-
}
|
|
31
27
|
let discriminantValues;
|
|
32
28
|
invariant(this.discriminant.memberValues.length === members.length);
|
|
33
29
|
switch (this.discriminant.kind) {
|
|
@@ -69,9 +65,7 @@ export class AbstractUnionType extends AbstractType {
|
|
|
69
65
|
default:
|
|
70
66
|
throw this.discriminant;
|
|
71
67
|
}
|
|
72
|
-
|
|
73
|
-
return { abstract: true, discriminantValues: [], type: member.type };
|
|
74
|
-
}
|
|
68
|
+
invariant(discriminantValues.length > 0);
|
|
75
69
|
const typeCheck = (json) => (instance) => {
|
|
76
70
|
const discriminant = this.discriminant; // To get type narrowing to work
|
|
77
71
|
if (discriminant.kind === "typeof") {
|
|
@@ -82,13 +76,12 @@ export class AbstractUnionType extends AbstractType {
|
|
|
82
76
|
case "NamedObjectUnionType":
|
|
83
77
|
case "NamedUnionType":
|
|
84
78
|
case "NamedObjectType":
|
|
85
|
-
return code `${member.type.
|
|
79
|
+
return code `${member.type.name}.is${member.type.name}(${instance})`;
|
|
86
80
|
}
|
|
87
81
|
}
|
|
88
82
|
return code `(${joinCode(discriminantValues.map((discriminantValue) => code `${instance}.${discriminant.name} === ${literalOf(discriminantValue)}`), { on: " || " })})`;
|
|
89
83
|
};
|
|
90
84
|
return {
|
|
91
|
-
abstract: false,
|
|
92
85
|
discriminantValues,
|
|
93
86
|
jsonType: member.type.jsonType({
|
|
94
87
|
includeDiscriminantProperty: this.discriminant.kind === "intrinsic" ||
|
|
@@ -150,7 +143,7 @@ export class AbstractUnionType extends AbstractType {
|
|
|
150
143
|
},
|
|
151
144
|
];
|
|
152
145
|
case "typeof":
|
|
153
|
-
return this.
|
|
146
|
+
return this.members.map(({ primaryDiscriminantValue, type, typeCheck }) => ({
|
|
154
147
|
conversionExpression: (value) => value,
|
|
155
148
|
sourceTypeCheckExpression: (value) => typeCheck(value),
|
|
156
149
|
sourceTypeName: type.name,
|
|
@@ -202,7 +195,7 @@ export class AbstractUnionType extends AbstractType {
|
|
|
202
195
|
// kind: '"extrinsic" | "intrinsic" | "typeof"',
|
|
203
196
|
// },
|
|
204
197
|
kind: code `${literalOf(this.kind.substring(0, this.kind.length - "Type".length))}`,
|
|
205
|
-
members: code `{ ${joinCode(this.
|
|
198
|
+
members: code `{ ${joinCode(this.members.map(({ type, primaryDiscriminantValue }) => code `readonly ${literalOf(primaryDiscriminantValue)}: ${{
|
|
206
199
|
discriminantValues: code `readonly (number | string)[]`,
|
|
207
200
|
type: type.schemaType,
|
|
208
201
|
}}`), { on: ";" })} }`,
|
|
@@ -218,15 +211,12 @@ export class AbstractUnionType extends AbstractType {
|
|
|
218
211
|
return set;
|
|
219
212
|
}
|
|
220
213
|
get typeofs() {
|
|
221
|
-
return NonEmptyList.fromArray(this.
|
|
222
|
-
}
|
|
223
|
-
get concreteMembers() {
|
|
224
|
-
return this.members.filter((member) => !member.abstract);
|
|
214
|
+
return NonEmptyList.fromArray(this.members.flatMap((member) => member.type.typeofs)).unsafeCoerce();
|
|
225
215
|
}
|
|
226
216
|
get inlineEqualsFunction() {
|
|
227
217
|
return code `\
|
|
228
218
|
((left: ${this.name}, right: ${this.name}) => {
|
|
229
|
-
${joinCode(this.
|
|
219
|
+
${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeCheck(code `left`)} && ${typeCheck(code `right`)}) {
|
|
230
220
|
return ${type.equalsFunction}(${unwrap(code `left`)} as ${type.name}, ${unwrap(code `right`)} as ${type.name});
|
|
231
221
|
}`))}
|
|
232
222
|
|
|
@@ -243,7 +233,7 @@ if (filter.${syntheticNamePrefix}identifier !== undefined && !${identifierType.f
|
|
|
243
233
|
return false;
|
|
244
234
|
}`)
|
|
245
235
|
.toList(),
|
|
246
|
-
...this.
|
|
236
|
+
...this.members.map(({ primaryDiscriminantValue, type, typeCheck, unwrap }) => code `\
|
|
247
237
|
if (filter.on?.[${literalOf(primaryDiscriminantValue)}] !== undefined && ${typeCheck(code `value`)}) {
|
|
248
238
|
if (!${type.filterFunction}(filter.on[${literalOf(primaryDiscriminantValue)}], ${unwrap(code `value`)})) {
|
|
249
239
|
return false;
|
|
@@ -258,13 +248,13 @@ if (filter.on?.[${literalOf(primaryDiscriminantValue)}] !== undefined && ${typeC
|
|
|
258
248
|
return code `\
|
|
259
249
|
{
|
|
260
250
|
${this.identifierType.map((identifierType) => code `readonly ${syntheticNamePrefix}identifier?: ${identifierType.filterType};`).orDefault(code ``)}
|
|
261
|
-
readonly on?: { ${joinCode(this.
|
|
251
|
+
readonly on?: { ${joinCode(this.members.map(({ type, primaryDiscriminantValue }) => code `readonly ${literalOf(primaryDiscriminantValue)}?: ${type.filterType}`), { on: ";" })} }
|
|
262
252
|
}`;
|
|
263
253
|
}
|
|
264
254
|
get inlineFromJsonFunction() {
|
|
265
255
|
return code `\
|
|
266
256
|
((value: ${this.jsonType().name}): ${this.name} => {
|
|
267
|
-
${joinCode(this.
|
|
257
|
+
${joinCode(this.members.map(({ jsonType, jsonTypeCheck, type, unwrap, wrap }) => code `if (${jsonTypeCheck(code `value`)}) { return ${wrap(type.fromJsonExpression({
|
|
268
258
|
variables: {
|
|
269
259
|
value: code `(${unwrap(code `value`)} as ${jsonType})`,
|
|
270
260
|
},
|
|
@@ -287,7 +277,7 @@ ${joinCode(this.concreteMembers.map(({ jsonType, jsonTypeCheck, type, unwrap, wr
|
|
|
287
277
|
(((values, _options) =>
|
|
288
278
|
values.chain(values => values.chainMap(value => {
|
|
289
279
|
const valueAsValues = ${imports.Right}(value.toValues());
|
|
290
|
-
return ${this.
|
|
280
|
+
return ${this.members.reduce((expression, { type, primaryDiscriminantValue }, memberI) => {
|
|
291
281
|
let typeExpression = type.fromRdfResourceValuesExpression({
|
|
292
282
|
variables: {
|
|
293
283
|
context: variables.context,
|
|
@@ -317,9 +307,9 @@ ${joinCode(this.concreteMembers.map(({ jsonType, jsonTypeCheck, type, unwrap, wr
|
|
|
317
307
|
const discriminant = this.discriminant; // To get type narrowing to work
|
|
318
308
|
switch (discriminant.kind) {
|
|
319
309
|
case "extrinsic":
|
|
320
|
-
return code `${imports.z}.discriminatedUnion("${discriminant.name}", [${joinCode(this.
|
|
310
|
+
return code `${imports.z}.discriminatedUnion("${discriminant.name}", [${joinCode(this.members.map(({ type, primaryDiscriminantValue }) => code `${imports.z}.object({ ${discriminant.name}: ${imports.z}.literal(${literalOf(primaryDiscriminantValue)}), value: ${type.jsonSchema({ context: "type" })} })`), { on: "," })}]).readonly()`;
|
|
321
311
|
case "hybrid":
|
|
322
|
-
return code `${imports.z}.discriminatedUnion("${discriminant.name}", [${joinCode(this.
|
|
312
|
+
return code `${imports.z}.discriminatedUnion("${discriminant.name}", [${joinCode(this.members.map(({ primaryDiscriminantValue, type }, memberI) => {
|
|
323
313
|
switch (discriminant.memberValues[memberI].kind) {
|
|
324
314
|
case "extrinsic":
|
|
325
315
|
return code `${imports.z}.object({ ${discriminant.name}: ${imports.z}.literal(${literalOf(primaryDiscriminantValue)}), value: ${type.jsonSchema({ context: "type" })} })`;
|
|
@@ -333,12 +323,12 @@ ${joinCode(this.concreteMembers.map(({ jsonType, jsonTypeCheck, type, unwrap, wr
|
|
|
333
323
|
}
|
|
334
324
|
}), { on: "," })}]).readonly()`;
|
|
335
325
|
case "intrinsic":
|
|
336
|
-
return code `${imports.z}.discriminatedUnion("${discriminant.name}", [${joinCode(this.
|
|
326
|
+
return code `${imports.z}.discriminatedUnion("${discriminant.name}", [${joinCode(this.members.map(({ type }) => type.jsonSchema({
|
|
337
327
|
includeDiscriminantProperty: true,
|
|
338
328
|
context: "type",
|
|
339
329
|
})), { on: "," })}]).readonly()`;
|
|
340
330
|
case "typeof":
|
|
341
|
-
return code `${imports.z}.union([${joinCode(this.
|
|
331
|
+
return code `${imports.z}.union([${joinCode(this.members.map(({ type }) => type.jsonSchema({ context: "type" })), { on: "," })}]).readonly()`;
|
|
342
332
|
default:
|
|
343
333
|
throw discriminant;
|
|
344
334
|
}
|
|
@@ -347,9 +337,9 @@ ${joinCode(this.concreteMembers.map(({ jsonType, jsonTypeCheck, type, unwrap, wr
|
|
|
347
337
|
const discriminant = this.discriminant; // To get type narrowing to work
|
|
348
338
|
switch (discriminant.kind) {
|
|
349
339
|
case "extrinsic":
|
|
350
|
-
return new AbstractType.JsonType(code `(${joinCode(this.
|
|
340
|
+
return new AbstractType.JsonType(code `(${joinCode(this.members.map(({ jsonType, primaryDiscriminantValue }) => code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${jsonType} }`), { on: "|" })})`);
|
|
351
341
|
case "hybrid":
|
|
352
|
-
return new AbstractType.JsonType(code `(${joinCode(this.
|
|
342
|
+
return new AbstractType.JsonType(code `(${joinCode(this.members.map(({ jsonType, primaryDiscriminantValue }, memberI) => {
|
|
353
343
|
switch (discriminant.memberValues[memberI].kind) {
|
|
354
344
|
case "extrinsic":
|
|
355
345
|
return code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${jsonType} }`;
|
|
@@ -361,7 +351,7 @@ ${joinCode(this.concreteMembers.map(({ jsonType, jsonTypeCheck, type, unwrap, wr
|
|
|
361
351
|
}), { on: "|" })})`);
|
|
362
352
|
case "intrinsic":
|
|
363
353
|
case "typeof":
|
|
364
|
-
return new AbstractType.JsonType(joinCode(this.
|
|
354
|
+
return new AbstractType.JsonType(joinCode(this.members.map(({ jsonType }) => code `${jsonType}`), { on: "|" }));
|
|
365
355
|
default:
|
|
366
356
|
throw discriminant;
|
|
367
357
|
}
|
|
@@ -370,9 +360,9 @@ ${joinCode(this.concreteMembers.map(({ jsonType, jsonTypeCheck, type, unwrap, wr
|
|
|
370
360
|
const discriminant = this.discriminant; // To get type narrowing to work
|
|
371
361
|
switch (discriminant.kind) {
|
|
372
362
|
case "extrinsic":
|
|
373
|
-
return code `(${joinCode(this.
|
|
363
|
+
return code `(${joinCode(this.members.map(({ type, primaryDiscriminantValue }) => code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${type.name} }`), { on: "|" })})`;
|
|
374
364
|
case "hybrid":
|
|
375
|
-
return code `(${joinCode(this.
|
|
365
|
+
return code `(${joinCode(this.members.map(({ primaryDiscriminantValue, type }, memberI) => {
|
|
376
366
|
switch (discriminant.memberValues[memberI].kind) {
|
|
377
367
|
case "extrinsic":
|
|
378
368
|
return code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${type.name} }`;
|
|
@@ -398,7 +388,7 @@ ${joinCode(this.concreteMembers.map(({ jsonType, jsonTypeCheck, type, unwrap, wr
|
|
|
398
388
|
get inlineToJsonFunction() {
|
|
399
389
|
return code `\
|
|
400
390
|
((value: ${this.name}): ${this.jsonType().name} => {
|
|
401
|
-
${joinCode(this.
|
|
391
|
+
${joinCode(this.members.map(({ typeCheck, typeToJsonExpression, unwrap, wrap }) => code `if (${typeCheck(code `value`)}) { return ${wrap(typeToJsonExpression(unwrap(code `value`)))}; }`))}
|
|
402
392
|
|
|
403
393
|
throw new Error("unable to serialize to JSON");
|
|
404
394
|
})`;
|
|
@@ -418,7 +408,7 @@ ${joinCode(this.concreteMembers.map(({ typeCheck, typeToJsonExpression, unwrap,
|
|
|
418
408
|
throw new Error();
|
|
419
409
|
}
|
|
420
410
|
}), { on: " | " })})[] => {
|
|
421
|
-
${joinCode(this.
|
|
411
|
+
${joinCode(this.members.map(({ type, unwrap, typeCheck }) => code `if (${typeCheck(code `value`)}) { return ${type.toRdfResourceValuesExpression({
|
|
422
412
|
variables: {
|
|
423
413
|
graph: code `_options.graph`,
|
|
424
414
|
propertyPath: code `_options.propertyPath`,
|
|
@@ -434,7 +424,7 @@ ${joinCode(this.concreteMembers.map(({ type, unwrap, typeCheck }) => code `if ($
|
|
|
434
424
|
get inlineToStringFunction() {
|
|
435
425
|
return code `\
|
|
436
426
|
((value: ${this.name}): string => {
|
|
437
|
-
${joinCode(this.
|
|
427
|
+
${joinCode(this.members.map(({ type, typeCheck, unwrap }) => code `if (${typeCheck(code `value`)}) { return ${type.toStringExpression({
|
|
438
428
|
variables: { value: unwrap(code `value`) },
|
|
439
429
|
})}; }`))}
|
|
440
430
|
|
|
@@ -446,7 +436,7 @@ ${joinCode(this.concreteMembers.map(({ type, typeCheck, unwrap }) => code `if ($
|
|
|
446
436
|
((({ ignoreRdfType, filter, schema, ...otherParameters }) => {
|
|
447
437
|
let triples: ${imports.sparqljs}.Triple[] = [];
|
|
448
438
|
|
|
449
|
-
${joinCode(this.
|
|
439
|
+
${joinCode(this.members.map(({ type, primaryDiscriminantValue }) => code `\
|
|
450
440
|
triples = triples.concat(${type.valueSparqlConstructTriplesFunction}({ ...otherParameters, filter: filter?.on?.[${literalOf(primaryDiscriminantValue)}], ignoreRdfType: false, schema: schema.members[${literalOf(primaryDiscriminantValue)}].type }));`))}
|
|
451
441
|
|
|
452
442
|
return triples;
|
|
@@ -457,7 +447,7 @@ triples = triples.concat(${type.valueSparqlConstructTriplesFunction}({ ...otherP
|
|
|
457
447
|
((({ filter, schema, ...otherParameters }) => {
|
|
458
448
|
const unionPatterns: ${imports.sparqljs}.GroupPattern[] = [];
|
|
459
449
|
|
|
460
|
-
${joinCode(this.
|
|
450
|
+
${joinCode(this.members.map(({ type, primaryDiscriminantValue }) => code `\
|
|
461
451
|
unionPatterns.push({ patterns: ${type.valueSparqlWherePatternsFunction}({ ...otherParameters, filter: filter?.on?.[${literalOf(primaryDiscriminantValue)}], ignoreRdfType: false, schema: schema.members[${literalOf(primaryDiscriminantValue)}].type }).concat(), type: "group" });`))}
|
|
462
452
|
|
|
463
453
|
return [{ patterns: unionPatterns, type: "union" }];
|
|
@@ -466,7 +456,7 @@ unionPatterns.push({ patterns: ${type.valueSparqlWherePatternsFunction}({ ...oth
|
|
|
466
456
|
get schemaObject() {
|
|
467
457
|
return {
|
|
468
458
|
...super.schemaObject,
|
|
469
|
-
members: code `{ ${joinCode(this.
|
|
459
|
+
members: code `{ ${joinCode(this.members.map(({ discriminantValues, type, primaryDiscriminantValue }) => code `${literalOf(primaryDiscriminantValue)}: ${{
|
|
470
460
|
discriminantValues: discriminantValues,
|
|
471
461
|
type: type.schema,
|
|
472
462
|
}}`), { on: "," })} }`,
|
|
@@ -476,7 +466,7 @@ unionPatterns.push({ patterns: ${type.valueSparqlWherePatternsFunction}({ ...oth
|
|
|
476
466
|
return Maybe.empty();
|
|
477
467
|
}
|
|
478
468
|
inlineHashStatements({ depth, variables, }) {
|
|
479
|
-
return this.
|
|
469
|
+
return this.members.map(({ type, unwrap, typeCheck }) => code `if (${typeCheck(variables.value)}) { ${joinCode(type
|
|
480
470
|
.hashStatements({
|
|
481
471
|
depth: depth + 1,
|
|
482
472
|
variables: {
|
|
@@ -509,9 +499,6 @@ __decorate([
|
|
|
509
499
|
__decorate([
|
|
510
500
|
Memoize()
|
|
511
501
|
], AbstractUnionType.prototype, "typeofs", null);
|
|
512
|
-
__decorate([
|
|
513
|
-
Memoize()
|
|
514
|
-
], AbstractUnionType.prototype, "concreteMembers", null);
|
|
515
502
|
__decorate([
|
|
516
503
|
Memoize()
|
|
517
504
|
], AbstractUnionType.prototype, "inlineEqualsFunction", null);
|
|
@@ -9,6 +9,7 @@ import { Memoize } from "typescript-memoize";
|
|
|
9
9
|
import { AbstractLazyObjectType } from "./AbstractLazyObjectType.js";
|
|
10
10
|
import { imports } from "./imports.js";
|
|
11
11
|
import { snippets } from "./snippets.js";
|
|
12
|
+
import { syntheticNamePrefix } from "./syntheticNamePrefix.js";
|
|
12
13
|
import { code } from "./ts-poet-wrapper.js";
|
|
13
14
|
const Super = (AbstractLazyObjectType);
|
|
14
15
|
export class LazyObjectOptionType extends Super {
|
|
@@ -30,12 +31,12 @@ export class LazyObjectOptionType extends Super {
|
|
|
30
31
|
const conversions = super.conversions.concat();
|
|
31
32
|
if (this.partialType.itemType.kind === "NamedObjectType") {
|
|
32
33
|
conversions.push({
|
|
33
|
-
conversionExpression: (value) => code `new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}: ${value}.map(
|
|
34
|
+
conversionExpression: (value) => code `new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}: ${value}.map(${this.partialType.itemType.name}.${syntheticNamePrefix}create), resolver: async () => ${imports.Right}((${value} as ${imports.Maybe}<${this.resolveType.itemType.name}>).unsafeCoerce()) })`,
|
|
34
35
|
sourceTypeCheckExpression: (value) => code `${imports.Maybe}.isMaybe(${value})`,
|
|
35
36
|
sourceTypeName: code `${imports.Maybe}<${this.resolveType.itemType.name}>`,
|
|
36
37
|
sourceTypeof: "object",
|
|
37
38
|
}, {
|
|
38
|
-
conversionExpression: (value) => code `new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}: ${imports.Maybe}.of(${this.partialType.itemType.
|
|
39
|
+
conversionExpression: (value) => code `new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}: ${imports.Maybe}.of(${this.partialType.itemType.name}.${syntheticNamePrefix}create(${value})), resolver: async () => ${imports.Right}(${value} as ${this.resolveType.itemType.name}) })`,
|
|
39
40
|
// Don't check instanceof value since the NamedObjectUnionType may be an interface
|
|
40
41
|
// Rely on the fact that this will be the last type check on an object
|
|
41
42
|
sourceTypeCheckExpression: (value) => code `typeof ${value} === "object"`,
|
|
@@ -9,6 +9,7 @@ import { Memoize } from "typescript-memoize";
|
|
|
9
9
|
import { AbstractLazyObjectType } from "./AbstractLazyObjectType.js";
|
|
10
10
|
import { imports } from "./imports.js";
|
|
11
11
|
import { snippets } from "./snippets.js";
|
|
12
|
+
import { syntheticNamePrefix } from "./syntheticNamePrefix.js";
|
|
12
13
|
import { code } from "./ts-poet-wrapper.js";
|
|
13
14
|
export class LazyObjectSetType extends AbstractLazyObjectType {
|
|
14
15
|
graphqlArgs = Maybe.of({
|
|
@@ -36,7 +37,7 @@ export class LazyObjectSetType extends AbstractLazyObjectType {
|
|
|
36
37
|
const conversions = super.conversions.concat();
|
|
37
38
|
if (this.partialType.itemType.kind === "NamedObjectType") {
|
|
38
39
|
conversions.push({
|
|
39
|
-
conversionExpression: (value) => code `new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}: ${value}.map(
|
|
40
|
+
conversionExpression: (value) => code `new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}: ${value}.map(${this.partialType.itemType.name}.${syntheticNamePrefix}create), resolver: async () => ${imports.Right}(${value} as readonly ${this.resolveType.itemType.name}[]) })`,
|
|
40
41
|
sourceTypeCheckExpression: (value) => code `typeof ${value} === "object"`,
|
|
41
42
|
sourceTypeName: code `readonly ${this.resolveType.itemType.name}[]`,
|
|
42
43
|
sourceTypeof: "object",
|
|
@@ -2,6 +2,7 @@ import { Maybe } from "purify-ts";
|
|
|
2
2
|
import { AbstractLazyObjectType } from "./AbstractLazyObjectType.js";
|
|
3
3
|
import { imports } from "./imports.js";
|
|
4
4
|
import { snippets } from "./snippets.js";
|
|
5
|
+
import { syntheticNamePrefix } from "./syntheticNamePrefix.js";
|
|
5
6
|
import { code } from "./ts-poet-wrapper.js";
|
|
6
7
|
export class LazyObjectType extends AbstractLazyObjectType {
|
|
7
8
|
graphqlArgs = Maybe.empty();
|
|
@@ -22,7 +23,7 @@ export class LazyObjectType extends AbstractLazyObjectType {
|
|
|
22
23
|
const conversions = super.conversions.concat();
|
|
23
24
|
if (this.partialType.kind === "NamedObjectType") {
|
|
24
25
|
conversions.push({
|
|
25
|
-
conversionExpression: (value) => code `new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}: ${this.partialType.
|
|
26
|
+
conversionExpression: (value) => code `new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}: ${this.partialType.name}.${syntheticNamePrefix}create(${value}), resolver: async () => ${imports.Right}(${value} as ${this.resolveType.name}) })`,
|
|
26
27
|
// Don't check instanceof value since the NamedObjectType may be an interface
|
|
27
28
|
// Rely on the fact that this will be the last type check on an object
|
|
28
29
|
sourceTypeCheckExpression: (value) => code `typeof ${value} === "object"`,
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { NamedNode } from "@rdfjs/types";
|
|
2
2
|
import { Maybe, NonEmptyList } from "purify-ts";
|
|
3
|
-
import type { TsFeature } from "../../enums/TsFeature.js";
|
|
4
|
-
import type { TsObjectDeclarationType } from "../../enums/TsObjectDeclarationType.js";
|
|
5
3
|
import { DiscriminantProperty as _DiscriminantProperty } from "./_NamedObjectType/DiscriminantProperty.js";
|
|
6
4
|
import { IdentifierProperty as _IdentifierProperty } from "./_NamedObjectType/IdentifierProperty.js";
|
|
7
5
|
import type { Property as _Property } from "./_NamedObjectType/Property.js";
|
|
@@ -10,13 +8,12 @@ import { AbstractType } from "./AbstractType.js";
|
|
|
10
8
|
import type { BlankNodeType } from "./BlankNodeType.js";
|
|
11
9
|
import type { IdentifierType } from "./IdentifierType.js";
|
|
12
10
|
import type { IriType } from "./IriType.js";
|
|
11
|
+
import type { TsFeature } from "./TsFeature.js";
|
|
13
12
|
import type { Type } from "./Type.js";
|
|
14
13
|
import { type Code } from "./ts-poet-wrapper.js";
|
|
15
14
|
export declare class NamedObjectType extends AbstractType {
|
|
16
15
|
private readonly imports;
|
|
17
16
|
protected readonly toRdfTypes: readonly NamedNode[];
|
|
18
|
-
readonly abstract: boolean;
|
|
19
|
-
readonly declarationType: TsObjectDeclarationType;
|
|
20
17
|
readonly extern: boolean;
|
|
21
18
|
readonly features: ReadonlySet<TsFeature>;
|
|
22
19
|
readonly fromRdfType: Maybe<NamedNode>;
|
|
@@ -25,13 +22,10 @@ export declare class NamedObjectType extends AbstractType {
|
|
|
25
22
|
readonly kind = "NamedObjectType";
|
|
26
23
|
readonly name: string;
|
|
27
24
|
readonly recursive: boolean;
|
|
28
|
-
readonly staticModuleName: string;
|
|
29
25
|
readonly synthetic: boolean;
|
|
30
26
|
readonly typeofs: NonEmptyList<"object">;
|
|
31
|
-
constructor({
|
|
32
|
-
abstract: boolean;
|
|
27
|
+
constructor({ extern, features, fromRdfType, identifierType, imports, lazyAncestorObjectTypes, lazyChildObjectTypes, lazyDescendantObjectTypes, lazyDiscriminantProperty, lazyParentObjectTypes, lazyProperties, name, recursive, synthetic, toRdfTypes, ...superParameters }: {
|
|
33
28
|
comment: Maybe<string>;
|
|
34
|
-
declarationType: TsObjectDeclarationType;
|
|
35
29
|
extern: boolean;
|
|
36
30
|
features: ReadonlySet<TsFeature>;
|
|
37
31
|
fromRdfType: Maybe<NamedNode>;
|
|
@@ -46,7 +40,6 @@ export declare class NamedObjectType extends AbstractType {
|
|
|
46
40
|
lazyProperties: (namedObjectType: NamedObjectType) => readonly NamedObjectType.Property[];
|
|
47
41
|
name: string;
|
|
48
42
|
recursive: boolean;
|
|
49
|
-
staticModuleName: string;
|
|
50
43
|
synthetic: boolean;
|
|
51
44
|
toRdfTypes: readonly NamedNode[];
|
|
52
45
|
} & ConstructorParameters<typeof AbstractType>[0]);
|
|
@@ -88,13 +81,9 @@ export declare class NamedObjectType extends AbstractType {
|
|
|
88
81
|
jsonSchema({ context, }: Parameters<AbstractType["jsonSchema"]>[0]): Code;
|
|
89
82
|
jsonType(): AbstractType.JsonType;
|
|
90
83
|
jsonUiSchemaElement({ variables, }: Parameters<AbstractType["jsonUiSchemaElement"]>[0]): Maybe<Code>;
|
|
91
|
-
newExpression({ parameters }: {
|
|
92
|
-
parameters: Code;
|
|
93
|
-
}): Code;
|
|
94
84
|
toJsonExpression({ variables, }: Parameters<AbstractType["toJsonExpression"]>[0]): Code;
|
|
95
85
|
toStringExpression({ variables, }: Parameters<AbstractType["toStringExpression"]>[0]): Code;
|
|
96
86
|
toRdfResourceValuesExpression({ variables, }: Parameters<AbstractType["toRdfResourceValuesExpression"]>[0]): Code;
|
|
97
|
-
protected ensureAtMostOneSuperObjectType(): void;
|
|
98
87
|
private readonly lazyAncestorObjectTypes;
|
|
99
88
|
private readonly lazyChildObjectTypes;
|
|
100
89
|
private readonly lazyDescendantObjectTypes;
|
|
@@ -11,9 +11,8 @@ import { Memoize } from "typescript-memoize";
|
|
|
11
11
|
import { DiscriminantProperty as _DiscriminantProperty } from "./_NamedObjectType/DiscriminantProperty.js";
|
|
12
12
|
import { IdentifierProperty as _IdentifierProperty } from "./_NamedObjectType/IdentifierProperty.js";
|
|
13
13
|
import { identifierTypeDeclarations } from "./_NamedObjectType/identifierTypeDeclarations.js";
|
|
14
|
-
import { NamedObjectType_classDeclaration } from "./_NamedObjectType/NamedObjectType_classDeclaration.js";
|
|
15
14
|
import { NamedObjectType_createFunctionDeclaration } from "./_NamedObjectType/NamedObjectType_createFunctionDeclaration.js";
|
|
16
|
-
import {
|
|
15
|
+
import { NamedObjectType_equalsFunctionDeclaration } from "./_NamedObjectType/NamedObjectType_equalsFunctionDeclaration.js";
|
|
17
16
|
import { NamedObjectType_filterFunctionDeclaration } from "./_NamedObjectType/NamedObjectType_filterFunctionDeclaration.js";
|
|
18
17
|
import { NamedObjectType_filterTypeDeclaration } from "./_NamedObjectType/NamedObjectType_filterTypeDeclaration.js";
|
|
19
18
|
import { NamedObjectType_focusSparqlConstructTriplesFunctionDeclaration } from "./_NamedObjectType/NamedObjectType_focusSparqlConstructTriplesFunctionDeclaration.js";
|
|
@@ -23,7 +22,7 @@ import { NamedObjectType_fromRdfResourceFunctionDeclaration } from "./_NamedObje
|
|
|
23
22
|
import { NamedObjectType_fromRdfResourceValuesFunctionDeclaration } from "./_NamedObjectType/NamedObjectType_fromRdfResourceValuesFunctionDeclaration.js";
|
|
24
23
|
import { NamedObjectType_fromRdfTypeVariableStatement } from "./_NamedObjectType/NamedObjectType_fromRdfTypeVariableStatement.js";
|
|
25
24
|
import { NamedObjectType_graphqlTypeVariableStatement } from "./_NamedObjectType/NamedObjectType_graphqlTypeVariableStatement.js";
|
|
26
|
-
import {
|
|
25
|
+
import { NamedObjectType_hashFunctionDeclarations } from "./_NamedObjectType/NamedObjectType_hashFunctionDeclarations.js";
|
|
27
26
|
import { NamedObjectType_interfaceDeclaration } from "./_NamedObjectType/NamedObjectType_interfaceDeclaration.js";
|
|
28
27
|
import { NamedObjectType_isTypeFunctionDeclaration } from "./_NamedObjectType/NamedObjectType_isTypeFunctionDeclaration.js";
|
|
29
28
|
import { NamedObjectType_jsonParseFunctionDeclaration } from "./_NamedObjectType/NamedObjectType_jsonParseFunctionDeclaration.js";
|
|
@@ -36,9 +35,9 @@ import { NamedObjectType_propertiesFromRdfResourceFunctionDeclaration } from "./
|
|
|
36
35
|
import { NamedObjectType_schemaVariableStatement } from "./_NamedObjectType/NamedObjectType_schemaVariableStatement.js";
|
|
37
36
|
import { NamedObjectType_sparqlConstructQueryFunctionDeclaration } from "./_NamedObjectType/NamedObjectType_sparqlConstructQueryFunctionDeclaration.js";
|
|
38
37
|
import { NamedObjectType_sparqlConstructQueryStringFunctionDeclaration } from "./_NamedObjectType/NamedObjectType_sparqlConstructQueryStringFunctionDeclaration.js";
|
|
39
|
-
import {
|
|
40
|
-
import {
|
|
41
|
-
import {
|
|
38
|
+
import { NamedObjectType_toJsonFunctionDeclaration } from "./_NamedObjectType/NamedObjectType_toJsonFunctionDeclaration.js";
|
|
39
|
+
import { NamedObjectType_toRdfResourceFunctionDeclaration } from "./_NamedObjectType/NamedObjectType_toRdfResourceFunctionDeclaration.js";
|
|
40
|
+
import { NamedObjectType_toStringFunctionDeclarations } from "./_NamedObjectType/NamedObjectType_toStringFunctionDeclarations.js";
|
|
42
41
|
import { NamedObjectType_valueSparqlConstructTriplesFunctionDeclaration } from "./_NamedObjectType/NamedObjectType_valueSparqlConstructTriplesFunctionDeclaration.js";
|
|
43
42
|
import { NamedObjectType_valueSparqlWherePatternsFunctionDeclaration } from "./_NamedObjectType/NamedObjectType_valueSparqlWherePatternsFunctionDeclaration.js";
|
|
44
43
|
import { ShaclProperty as _ShaclProperty } from "./_NamedObjectType/ShaclProperty.js";
|
|
@@ -49,8 +48,6 @@ import { code, def, joinCode } from "./ts-poet-wrapper.js";
|
|
|
49
48
|
export class NamedObjectType extends AbstractType {
|
|
50
49
|
imports;
|
|
51
50
|
toRdfTypes;
|
|
52
|
-
abstract;
|
|
53
|
-
declarationType;
|
|
54
51
|
extern;
|
|
55
52
|
features;
|
|
56
53
|
fromRdfType;
|
|
@@ -59,13 +56,10 @@ export class NamedObjectType extends AbstractType {
|
|
|
59
56
|
kind = "NamedObjectType";
|
|
60
57
|
name;
|
|
61
58
|
recursive;
|
|
62
|
-
staticModuleName;
|
|
63
59
|
synthetic;
|
|
64
60
|
typeofs = NonEmptyList(["object"]);
|
|
65
|
-
constructor({
|
|
61
|
+
constructor({ extern, features, fromRdfType, identifierType, imports, lazyAncestorObjectTypes, lazyChildObjectTypes, lazyDescendantObjectTypes, lazyDiscriminantProperty, lazyParentObjectTypes, lazyProperties, name, recursive, synthetic, toRdfTypes, ...superParameters }) {
|
|
66
62
|
super(superParameters);
|
|
67
|
-
this.abstract = abstract;
|
|
68
|
-
this.declarationType = declarationType;
|
|
69
63
|
this.extern = extern;
|
|
70
64
|
this.features = features;
|
|
71
65
|
this.fromRdfType = fromRdfType;
|
|
@@ -80,7 +74,6 @@ export class NamedObjectType extends AbstractType {
|
|
|
80
74
|
this.lazyProperties = lazyProperties;
|
|
81
75
|
this.name = name;
|
|
82
76
|
this.recursive = recursive;
|
|
83
|
-
this.staticModuleName = staticModuleName;
|
|
84
77
|
this.synthetic = synthetic;
|
|
85
78
|
this.toRdfTypes = toRdfTypes;
|
|
86
79
|
}
|
|
@@ -97,7 +90,7 @@ export class NamedObjectType extends AbstractType {
|
|
|
97
90
|
return [
|
|
98
91
|
{
|
|
99
92
|
conversionExpression: (value) => value,
|
|
100
|
-
sourceTypeCheckExpression: (value) => code `typeof ${value} === "object"
|
|
93
|
+
sourceTypeCheckExpression: (value) => code `typeof ${value} === "object"`,
|
|
101
94
|
sourceTypeName: this.name,
|
|
102
95
|
sourceTypeof: "object",
|
|
103
96
|
},
|
|
@@ -110,17 +103,8 @@ export class NamedObjectType extends AbstractType {
|
|
|
110
103
|
}
|
|
111
104
|
if (!this.extern) {
|
|
112
105
|
const staticModuleDeclarations = [];
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
declarations.push(NamedObjectType_classDeclaration.call(this));
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
case "interface": {
|
|
119
|
-
declarations.push(NamedObjectType_interfaceDeclaration.call(this));
|
|
120
|
-
staticModuleDeclarations.push(...NamedObjectType_createFunctionDeclaration.call(this).toList(), ...NamedObjectType_equalsFunctionOrMethodDeclaration.bind(this)().toList(), ...NamedObjectType_hashFunctionOrMethodDeclarations.call(this));
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
106
|
+
declarations.push(NamedObjectType_interfaceDeclaration.call(this));
|
|
107
|
+
staticModuleDeclarations.push(...NamedObjectType_createFunctionDeclaration.call(this).toList(), ...NamedObjectType_equalsFunctionDeclaration.bind(this)().toList(), ...NamedObjectType_hashFunctionDeclarations.call(this));
|
|
124
108
|
const jsonModuleDeclarations = [
|
|
125
109
|
...NamedObjectType_jsonParseFunctionDeclaration.call(this).toList(),
|
|
126
110
|
...NamedObjectType_jsonSchemaFunctionDeclaration.call(this).toList(),
|
|
@@ -130,16 +114,10 @@ export class NamedObjectType extends AbstractType {
|
|
|
130
114
|
? [
|
|
131
115
|
code `export namespace ${syntheticNamePrefix}Json { ${joinCode(jsonModuleDeclarations, { on: "\n\n" })} }`,
|
|
132
116
|
]
|
|
133
|
-
: []), NamedObjectType_filterFunctionDeclaration.call(this), NamedObjectType_filterTypeDeclaration.call(this), ...NamedObjectType_focusSparqlConstructTriplesFunctionDeclaration.bind(this)().toList(), ...NamedObjectType_focusSparqlWherePatternsFunctionDeclaration.bind(this)().toList(), ...NamedObjectType_fromJsonFunctionDeclaration.call(this).toList(), ...NamedObjectType_fromRdfResourceFunctionDeclaration.call(this).toList(), ...NamedObjectType_fromRdfResourceValuesFunctionDeclaration.call(this).toList(), ...NamedObjectType_fromRdfTypeVariableStatement.call(this).toList(), NamedObjectType_isTypeFunctionDeclaration.call(this), ...NamedObjectType_propertiesFromJsonFunctionDeclaration.bind(this)().toList(), ...NamedObjectType_propertiesFromRdfResourceFunctionDeclaration.bind(this)().toList(), NamedObjectType_schemaVariableStatement.call(this), ...NamedObjectType_sparqlConstructQueryFunctionDeclaration.bind(this)().toList(), ...NamedObjectType_sparqlConstructQueryStringFunctionDeclaration.bind(this)().toList(), ...(this.
|
|
134
|
-
? NamedObjectType_toJsonFunctionOrMethodDeclaration.call(this).toList()
|
|
135
|
-
: []), ...(this.declarationType === "interface"
|
|
136
|
-
? NamedObjectType_toRdfResourceFunctionOrMethodDeclaration.call(this).toList()
|
|
137
|
-
: []), ...(this.declarationType === "interface"
|
|
138
|
-
? NamedObjectType_toStringFunctionOrMethodDeclarations.call(this)
|
|
139
|
-
: []), ...NamedObjectType_valueSparqlConstructTriplesFunctionDeclaration.bind(this)().toList(), ...NamedObjectType_valueSparqlWherePatternsFunctionDeclaration.bind(this)().toList());
|
|
117
|
+
: []), NamedObjectType_filterFunctionDeclaration.call(this), NamedObjectType_filterTypeDeclaration.call(this), ...NamedObjectType_focusSparqlConstructTriplesFunctionDeclaration.bind(this)().toList(), ...NamedObjectType_focusSparqlWherePatternsFunctionDeclaration.bind(this)().toList(), ...NamedObjectType_fromJsonFunctionDeclaration.call(this).toList(), ...NamedObjectType_fromRdfResourceFunctionDeclaration.call(this).toList(), ...NamedObjectType_fromRdfResourceValuesFunctionDeclaration.call(this).toList(), ...NamedObjectType_fromRdfTypeVariableStatement.call(this).toList(), NamedObjectType_isTypeFunctionDeclaration.call(this), ...NamedObjectType_propertiesFromJsonFunctionDeclaration.bind(this)().toList(), ...NamedObjectType_propertiesFromRdfResourceFunctionDeclaration.bind(this)().toList(), NamedObjectType_schemaVariableStatement.call(this), ...NamedObjectType_sparqlConstructQueryFunctionDeclaration.bind(this)().toList(), ...NamedObjectType_sparqlConstructQueryStringFunctionDeclaration.bind(this)().toList(), ...NamedObjectType_toJsonFunctionDeclaration.call(this).toList(), ...NamedObjectType_toRdfResourceFunctionDeclaration.call(this).toList(), ...NamedObjectType_toStringFunctionDeclarations.call(this), ...NamedObjectType_valueSparqlConstructTriplesFunctionDeclaration.bind(this)().toList(), ...NamedObjectType_valueSparqlWherePatternsFunctionDeclaration.bind(this)().toList());
|
|
140
118
|
if (staticModuleDeclarations.length > 0) {
|
|
141
119
|
declarations.push(code `\
|
|
142
|
-
export namespace ${def(this.
|
|
120
|
+
export namespace ${def(this.name)} {
|
|
143
121
|
${joinCode(staticModuleDeclarations, { on: "\n\n" })}
|
|
144
122
|
}`);
|
|
145
123
|
}
|
|
@@ -166,29 +144,22 @@ ${joinCode(staticModuleDeclarations, { on: "\n\n" })}
|
|
|
166
144
|
return this.name;
|
|
167
145
|
}
|
|
168
146
|
get equalsFunction() {
|
|
169
|
-
|
|
170
|
-
case "class":
|
|
171
|
-
return code `((left, right) => left.${syntheticNamePrefix}equals(right))`;
|
|
172
|
-
case "interface":
|
|
173
|
-
return code `${this.staticModuleName}.${syntheticNamePrefix}equals`;
|
|
174
|
-
default:
|
|
175
|
-
throw new RangeError(this.declarationType);
|
|
176
|
-
}
|
|
147
|
+
return code `${this.name}.${syntheticNamePrefix}equals`;
|
|
177
148
|
}
|
|
178
149
|
get filterFunction() {
|
|
179
|
-
return code `${this.
|
|
150
|
+
return code `${this.name}.${syntheticNamePrefix}filter`;
|
|
180
151
|
}
|
|
181
152
|
get filterType() {
|
|
182
|
-
return code `${this.
|
|
153
|
+
return code `${this.name}.${syntheticNamePrefix}Filter`;
|
|
183
154
|
}
|
|
184
155
|
get fromRdfTypeVariable() {
|
|
185
|
-
return this.fromRdfType.map(() => code `${this.
|
|
156
|
+
return this.fromRdfType.map(() => code `${this.name}.${syntheticNamePrefix}fromRdfType`);
|
|
186
157
|
}
|
|
187
158
|
get graphqlType() {
|
|
188
|
-
return new AbstractType.GraphqlType(code `${this.
|
|
159
|
+
return new AbstractType.GraphqlType(code `${this.name}.${syntheticNamePrefix}GraphQL`);
|
|
189
160
|
}
|
|
190
161
|
get identifierTypeAlias() {
|
|
191
|
-
return code `${this.
|
|
162
|
+
return code `${this.name}.${syntheticNamePrefix}Identifier`;
|
|
192
163
|
}
|
|
193
164
|
get mutable() {
|
|
194
165
|
return this.properties.some((property) => property.mutable);
|
|
@@ -210,7 +181,7 @@ ${joinCode(staticModuleDeclarations, { on: "\n\n" })}
|
|
|
210
181
|
return properties;
|
|
211
182
|
}
|
|
212
183
|
get schema() {
|
|
213
|
-
return code `${this.
|
|
184
|
+
return code `${this.name}.${syntheticNamePrefix}schema`;
|
|
214
185
|
}
|
|
215
186
|
get schemaType() {
|
|
216
187
|
return code `typeof ${this.schema}`;
|
|
@@ -225,94 +196,52 @@ ${joinCode(staticModuleDeclarations, { on: "\n\n" })}
|
|
|
225
196
|
return code `${imports.Resource}${this.identifierType.kind === "IriType" ? code `<${imports.NamedNode}>` : ""}`;
|
|
226
197
|
}
|
|
227
198
|
get valueSparqlConstructTriplesFunction() {
|
|
228
|
-
return code `${this.
|
|
199
|
+
return code `${this.name}.${syntheticNamePrefix}valueSparqlConstructTriples`;
|
|
229
200
|
}
|
|
230
201
|
get valueSparqlWherePatternsFunction() {
|
|
231
|
-
return code `${this.
|
|
202
|
+
return code `${this.name}.${syntheticNamePrefix}valueSparqlWherePatterns`;
|
|
232
203
|
}
|
|
233
204
|
get thisVariable() {
|
|
234
|
-
|
|
235
|
-
case "class":
|
|
236
|
-
return code `this`;
|
|
237
|
-
case "interface":
|
|
238
|
-
return code `_${camelCase(this.name)}`;
|
|
239
|
-
default:
|
|
240
|
-
throw new RangeError(this.declarationType);
|
|
241
|
-
}
|
|
205
|
+
return code `_${camelCase(this.name)}`;
|
|
242
206
|
}
|
|
243
207
|
fromJsonExpression({ variables, }) {
|
|
244
208
|
// Assumes the JSON object has been recursively validated already.
|
|
245
|
-
return code `${this.
|
|
209
|
+
return code `${this.name}.${syntheticNamePrefix}fromJson(${variables.value})`;
|
|
246
210
|
}
|
|
247
211
|
fromRdfResourceValuesExpression({ variables, }) {
|
|
248
212
|
const { resourceValues, ...options } = variables;
|
|
249
|
-
return code `${this.
|
|
213
|
+
return code `${this.name}.${syntheticNamePrefix}fromRdfResourceValues(${resourceValues}, ${options})`;
|
|
250
214
|
}
|
|
251
215
|
graphqlResolveExpression({ variables, }) {
|
|
252
216
|
return variables.value;
|
|
253
217
|
}
|
|
254
218
|
hashStatements({ variables, }) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
code `${variables.value}.${syntheticNamePrefix}hash(${variables.hasher});`,
|
|
259
|
-
];
|
|
260
|
-
case "interface":
|
|
261
|
-
return [
|
|
262
|
-
code `${this.staticModuleName}.${syntheticNamePrefix}hash(${variables.value}, ${variables.hasher});`,
|
|
263
|
-
];
|
|
264
|
-
}
|
|
219
|
+
return [
|
|
220
|
+
code `${this.name}.${syntheticNamePrefix}hash(${variables.value}, ${variables.hasher});`,
|
|
221
|
+
];
|
|
265
222
|
}
|
|
266
223
|
jsonSchema({ context, }) {
|
|
267
|
-
let expression = code `${this.
|
|
224
|
+
let expression = code `${this.name}.${syntheticNamePrefix}Json.schema()`;
|
|
268
225
|
if (context === "property" &&
|
|
269
226
|
this.properties.some((property) => property.recursive)) {
|
|
270
|
-
expression = code `${imports.z}.lazy((): ${imports.z}.ZodType<${this.
|
|
227
|
+
expression = code `${imports.z}.lazy((): ${imports.z}.ZodType<${this.name}.${syntheticNamePrefix}Json> => ${expression})`;
|
|
271
228
|
}
|
|
272
229
|
return expression;
|
|
273
230
|
}
|
|
274
231
|
jsonType() {
|
|
275
|
-
return new AbstractType.JsonType(code `${this.
|
|
232
|
+
return new AbstractType.JsonType(code `${this.name}.${syntheticNamePrefix}Json`);
|
|
276
233
|
}
|
|
277
234
|
jsonUiSchemaElement({ variables, }) {
|
|
278
|
-
return Maybe.of(code `${this.
|
|
279
|
-
}
|
|
280
|
-
newExpression({ parameters }) {
|
|
281
|
-
switch (this.declarationType) {
|
|
282
|
-
case "class":
|
|
283
|
-
return code `new ${this.name}(${parameters})`;
|
|
284
|
-
case "interface":
|
|
285
|
-
return code `${this.staticModuleName}.${syntheticNamePrefix}create(${parameters})`;
|
|
286
|
-
}
|
|
235
|
+
return Maybe.of(code `${this.name}.${syntheticNamePrefix}Json.uiSchema({ scopePrefix: ${variables.scopePrefix} })`);
|
|
287
236
|
}
|
|
288
237
|
toJsonExpression({ variables, }) {
|
|
289
|
-
|
|
290
|
-
case "class":
|
|
291
|
-
return code `${variables.value}.${syntheticNamePrefix}toJson()`;
|
|
292
|
-
case "interface":
|
|
293
|
-
return code `${this.staticModuleName}.${syntheticNamePrefix}toJson(${variables.value})`;
|
|
294
|
-
}
|
|
238
|
+
return code `${this.name}.${syntheticNamePrefix}toJson(${variables.value})`;
|
|
295
239
|
}
|
|
296
240
|
toStringExpression({ variables, }) {
|
|
297
|
-
|
|
298
|
-
case "class":
|
|
299
|
-
return code `${variables.value}.toString()`;
|
|
300
|
-
case "interface":
|
|
301
|
-
return code `${this.staticModuleName}.${syntheticNamePrefix}toString(${variables.value})`;
|
|
302
|
-
}
|
|
241
|
+
return code `${this.name}.${syntheticNamePrefix}toString(${variables.value})`;
|
|
303
242
|
}
|
|
304
243
|
toRdfResourceValuesExpression({ variables, }) {
|
|
305
|
-
|
|
306
|
-
case "class":
|
|
307
|
-
return code `[${variables.value}.${syntheticNamePrefix}toRdfResource({ graph: ${variables.graph}, resourceSet: ${variables.resourceSet} }).identifier]`;
|
|
308
|
-
case "interface":
|
|
309
|
-
return code `[${this.staticModuleName}.${syntheticNamePrefix}toRdfResource(${variables.value}, { graph: ${variables.graph}, resourceSet: ${variables.resourceSet} }).identifier]`;
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
ensureAtMostOneSuperObjectType() {
|
|
313
|
-
if (this.parentObjectTypes.length > 1) {
|
|
314
|
-
throw new RangeError(`object type '${this.name}' has multiple super object types`);
|
|
315
|
-
}
|
|
244
|
+
return code `[${this.name}.${syntheticNamePrefix}toRdfResource(${variables.value}, { graph: ${variables.graph}, resourceSet: ${variables.resourceSet} }).identifier]`;
|
|
316
245
|
}
|
|
317
246
|
lazyAncestorObjectTypes;
|
|
318
247
|
lazyChildObjectTypes;
|