@shaclmate/compiler 4.0.19 → 4.0.21
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 +4 -1
- package/dist/Compiler.js +4 -1
- package/dist/ShapesGraphToAstTransformer.d.ts +4 -1
- package/dist/ShapesGraphToAstTransformer.js +9 -6
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +1 -1
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstListType.js +1 -1
- package/dist/ast/AbstractCollectionType.d.ts +1 -1
- package/dist/ast/AbstractContainerType.d.ts +1 -1
- package/dist/ast/AbstractLazyObjectType.d.ts +19 -79
- package/dist/ast/AbstractTermType.d.ts +3 -33
- package/dist/ast/AbstractTermType.js +2 -3
- package/dist/ast/AbstractType.d.ts +1 -1
- package/dist/ast/AbstractType.js +1 -2
- package/dist/ast/BlankNodeType.d.ts +1 -1
- package/dist/ast/DefaultValueType.d.ts +2 -17
- package/dist/ast/DefaultValueType.js +1 -2
- package/dist/ast/IdentifierType.d.ts +1 -1
- package/dist/ast/LiteralType.d.ts +8 -98
- package/dist/ast/LiteralType.js +5 -7
- package/dist/ast/ObjectCompoundType.js +1 -2
- package/dist/ast/ObjectType.d.ts +9 -39
- package/dist/ast/ObjectType.js +9 -13
- package/dist/ast/SetType.d.ts +1 -1
- package/dist/ast/UnionType.d.ts +1 -1
- package/dist/generators/transformAstToLabeledPropertyGraph.js +3 -4
- package/dist/generators/ts/AbstractContainerType.d.ts +1 -0
- package/dist/generators/ts/AbstractContainerType.js +3 -0
- package/dist/generators/ts/AbstractDateType.js +1 -1
- package/dist/generators/ts/AbstractIdentifierType.d.ts +2 -2
- package/dist/generators/ts/AbstractIdentifierType.js +2 -5
- package/dist/generators/ts/AbstractLazyObjectType.d.ts +2 -1
- package/dist/generators/ts/AbstractLazyObjectType.js +6 -3
- package/dist/generators/ts/AbstractNamedUnionType.js +2 -2
- package/dist/generators/ts/AbstractNumericType.js +1 -1
- package/dist/generators/ts/AbstractTermType.d.ts +1 -0
- package/dist/generators/ts/AbstractTermType.js +8 -2
- package/dist/generators/ts/AbstractType.d.ts +21 -14
- package/dist/generators/ts/AbstractType.js +3 -1
- package/dist/generators/ts/AbstractUnionType.d.ts +5 -4
- package/dist/generators/ts/AbstractUnionType.js +83 -59
- package/dist/generators/ts/BlankNodeType.d.ts +2 -2
- package/dist/generators/ts/BlankNodeType.js +1 -1
- package/dist/generators/ts/BooleanType.js +1 -1
- package/dist/generators/ts/DefaultValueType.js +1 -1
- package/dist/generators/ts/IdentifierType.d.ts +2 -2
- package/dist/generators/ts/IdentifierType.js +1 -1
- package/dist/generators/ts/IriType.d.ts +1 -1
- package/dist/generators/ts/IriType.js +8 -13
- package/dist/generators/ts/LazyObjectOptionType.d.ts +1 -0
- package/dist/generators/ts/LazyObjectOptionType.js +1 -1
- package/dist/generators/ts/LazyObjectType.js +1 -1
- package/dist/generators/ts/ListType.js +5 -5
- package/dist/generators/ts/NamedObjectType.d.ts +1 -0
- package/dist/generators/ts/NamedObjectType.js +7 -0
- package/dist/generators/ts/NamedObjectUnionType.js +4 -1
- package/dist/generators/ts/SetType.js +1 -1
- package/dist/generators/ts/StringType.js +1 -1
- package/dist/generators/ts/TermType.js +3 -1
- package/dist/generators/ts/TsGenerator.d.ts +5 -0
- package/dist/generators/ts/TsGenerator.js +7 -1
- package/dist/generators/ts/TypeFactory.d.ts +5 -0
- package/dist/generators/ts/TypeFactory.js +35 -5
- package/dist/generators/ts/ZodGenerator.d.ts +4 -0
- package/dist/generators/ts/ZodGenerator.js +4 -1
- package/dist/generators/ts/_NamedObjectType/AbstractProperty.d.ts +4 -1
- package/dist/generators/ts/_NamedObjectType/AbstractProperty.js +3 -1
- package/dist/generators/ts/_NamedObjectType/IdentifierProperty.js +6 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlConstructTriplesFunctionDeclaration.js +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlWherePatternsFunctionDeclaration.js +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfTypeVariableStatement.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_propertiesFromRdfResourceFunctionDeclaration.js +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toRdfResourceFunctionOrMethodDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/ShaclProperty.d.ts +1 -0
- package/dist/generators/ts/_NamedObjectType/ShaclProperty.js +16 -16
- package/dist/generators/ts/_NamedObjectType/identifierTypeDeclarations.js +6 -2
- package/dist/generators/ts/_snippets/parseIri.d.ts +2 -0
- package/dist/generators/ts/_snippets/parseIri.js +12 -0
- package/dist/generators/ts/_snippets/snippets_ToRdfResourceValuesFunction.js +4 -3
- package/dist/generators/ts/_snippets/snippets_listSparqlWherePatterns.js +7 -5
- package/dist/generators/ts/_snippets/snippets_parseBlankNode.d.ts +2 -0
- package/dist/generators/ts/_snippets/snippets_parseBlankNode.js +12 -0
- package/dist/generators/ts/_snippets/snippets_parseIdentifier.d.ts +2 -0
- package/dist/generators/ts/_snippets/snippets_parseIdentifier.js +6 -0
- package/dist/generators/ts/graphqlSchemaVariableStatement.js +3 -3
- package/dist/generators/ts/imports.d.ts +2 -0
- package/dist/generators/ts/imports.js +3 -1
- package/dist/generators/ts/rdfjsTermExpression.d.ts +4 -1
- package/dist/generators/ts/rdfjsTermExpression.js +2 -3
- package/dist/generators/ts/snippets.d.ts +3 -2
- package/dist/generators/ts/snippets.js +6 -4
- package/dist/generators/ts/synthesizeUberObjectUnionType.d.ts +2 -0
- package/dist/generators/ts/synthesizeUberObjectUnionType.js +4 -0
- package/dist/input/ShapesGraph.d.ts +4 -1
- package/dist/input/ShapesGraph.js +3 -2
- package/dist/input/generated.d.ts +323 -323
- package/dist/input/generated.js +19 -20
- package/package.json +6 -7
- package/dist/ast/termToJson.d.ts +0 -18
- package/dist/ast/termToJson.js +0 -18
- package/dist/generators/ts/_snippets/snippets_blankNodeFromString.d.ts +0 -2
- package/dist/generators/ts/_snippets/snippets_blankNodeFromString.js +0 -11
- package/dist/generators/ts/_snippets/snippets_identifierFromString.d.ts +0 -2
- package/dist/generators/ts/_snippets/snippets_identifierFromString.js +0 -8
- package/dist/logger.d.ts +0 -2
- package/dist/logger.js +0 -8
|
@@ -13,24 +13,10 @@ import { removeUndefined } from "./removeUndefined.js";
|
|
|
13
13
|
import { snippets } from "./snippets.js";
|
|
14
14
|
import { syntheticNamePrefix } from "./syntheticNamePrefix.js";
|
|
15
15
|
import { code, joinCode, literalOf } from "./ts-poet-wrapper.js";
|
|
16
|
-
const emptyTermTypesSet = new Set();
|
|
17
|
-
function termTypes(type) {
|
|
18
|
-
switch (type.kind) {
|
|
19
|
-
case "BlankNodeType":
|
|
20
|
-
case "IriType":
|
|
21
|
-
case "IdentifierType":
|
|
22
|
-
case "LiteralType":
|
|
23
|
-
case "TermType":
|
|
24
|
-
return type.termTypes;
|
|
25
|
-
default:
|
|
26
|
-
return emptyTermTypesSet;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
16
|
export class AbstractUnionType extends AbstractType {
|
|
30
17
|
discriminant;
|
|
31
18
|
identifierType;
|
|
32
19
|
abstract = false;
|
|
33
|
-
lazyMembers;
|
|
34
20
|
recursive;
|
|
35
21
|
constructor({ identifierType, members, recursive, ...superParameters }) {
|
|
36
22
|
super(superParameters);
|
|
@@ -222,6 +208,15 @@ export class AbstractUnionType extends AbstractType {
|
|
|
222
208
|
}}`), { on: ";" })} }`,
|
|
223
209
|
}}`;
|
|
224
210
|
}
|
|
211
|
+
get toRdfResourceValueTypes() {
|
|
212
|
+
const set = new Set();
|
|
213
|
+
for (const member of this.members) {
|
|
214
|
+
for (const value of member.type.toRdfResourceValueTypes) {
|
|
215
|
+
set.add(value);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return set;
|
|
219
|
+
}
|
|
225
220
|
get typeofs() {
|
|
226
221
|
return NonEmptyList.fromArray(this.concreteMembers.flatMap((member) => member.type.typeofs)).unsafeCoerce();
|
|
227
222
|
}
|
|
@@ -318,55 +313,55 @@ ${joinCode(this.concreteMembers.map(({ jsonType, jsonTypeCheck, type, unwrap, wr
|
|
|
318
313
|
}))
|
|
319
314
|
) satisfies ${snippets.FromRdfResourceValuesFunction}<${this.name}>)`;
|
|
320
315
|
}
|
|
321
|
-
get
|
|
316
|
+
get inlineJsonSchema() {
|
|
322
317
|
const discriminant = this.discriminant; // To get type narrowing to work
|
|
323
318
|
switch (discriminant.kind) {
|
|
324
319
|
case "extrinsic":
|
|
325
|
-
return
|
|
320
|
+
return code `${imports.z}.discriminatedUnion("${discriminant.name}", [${joinCode(this.concreteMembers.map(({ type, primaryDiscriminantValue }) => code `${imports.z}.object({ ${discriminant.name}: ${imports.z}.literal(${literalOf(primaryDiscriminantValue)}), value: ${type.jsonSchema({ context: "type" })} })`), { on: "," })}]).readonly()`;
|
|
326
321
|
case "hybrid":
|
|
327
|
-
return
|
|
322
|
+
return code `${imports.z}.discriminatedUnion("${discriminant.name}", [${joinCode(this.concreteMembers.map(({ primaryDiscriminantValue, type }, memberI) => {
|
|
328
323
|
switch (discriminant.memberValues[memberI].kind) {
|
|
329
324
|
case "extrinsic":
|
|
330
|
-
return code
|
|
325
|
+
return code `${imports.z}.object({ ${discriminant.name}: ${imports.z}.literal(${literalOf(primaryDiscriminantValue)}), value: ${type.jsonSchema({ context: "type" })} })`;
|
|
331
326
|
case "intrinsic":
|
|
332
|
-
return
|
|
327
|
+
return type.jsonSchema({
|
|
328
|
+
includeDiscriminantProperty: true,
|
|
329
|
+
context: "type",
|
|
330
|
+
});
|
|
333
331
|
default:
|
|
334
332
|
throw new Error();
|
|
335
333
|
}
|
|
336
|
-
}), { on: "
|
|
334
|
+
}), { on: "," })}]).readonly()`;
|
|
337
335
|
case "intrinsic":
|
|
336
|
+
return code `${imports.z}.discriminatedUnion("${discriminant.name}", [${joinCode(this.concreteMembers.map(({ type }) => type.jsonSchema({
|
|
337
|
+
includeDiscriminantProperty: true,
|
|
338
|
+
context: "type",
|
|
339
|
+
})), { on: "," })}]).readonly()`;
|
|
338
340
|
case "typeof":
|
|
339
|
-
return
|
|
341
|
+
return code `${imports.z}.union([${joinCode(this.concreteMembers.map(({ type }) => type.jsonSchema({ context: "type" })), { on: "," })}]).readonly()`;
|
|
340
342
|
default:
|
|
341
343
|
throw discriminant;
|
|
342
344
|
}
|
|
343
345
|
}
|
|
344
|
-
get
|
|
346
|
+
get inlineJsonType() {
|
|
345
347
|
const discriminant = this.discriminant; // To get type narrowing to work
|
|
346
348
|
switch (discriminant.kind) {
|
|
347
349
|
case "extrinsic":
|
|
348
|
-
return
|
|
350
|
+
return new AbstractType.JsonType(code `(${joinCode(this.concreteMembers.map(({ jsonType, primaryDiscriminantValue }) => code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${jsonType} }`), { on: "|" })})`);
|
|
349
351
|
case "hybrid":
|
|
350
|
-
return
|
|
352
|
+
return new AbstractType.JsonType(code `(${joinCode(this.concreteMembers.map(({ jsonType, primaryDiscriminantValue }, memberI) => {
|
|
351
353
|
switch (discriminant.memberValues[memberI].kind) {
|
|
352
354
|
case "extrinsic":
|
|
353
|
-
return code
|
|
355
|
+
return code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${jsonType} }`;
|
|
354
356
|
case "intrinsic":
|
|
355
|
-
return
|
|
356
|
-
includeDiscriminantProperty: true,
|
|
357
|
-
context: "type",
|
|
358
|
-
});
|
|
357
|
+
return code `${jsonType}`;
|
|
359
358
|
default:
|
|
360
359
|
throw new Error();
|
|
361
360
|
}
|
|
362
|
-
}), { on: "
|
|
361
|
+
}), { on: "|" })})`);
|
|
363
362
|
case "intrinsic":
|
|
364
|
-
return code `${imports.z}.discriminatedUnion("${discriminant.name}", [${joinCode(this.concreteMembers.map(({ type }) => type.jsonSchema({
|
|
365
|
-
includeDiscriminantProperty: true,
|
|
366
|
-
context: "type",
|
|
367
|
-
})), { on: "," })}]).readonly()`;
|
|
368
363
|
case "typeof":
|
|
369
|
-
return
|
|
364
|
+
return new AbstractType.JsonType(joinCode(this.concreteMembers.map(({ jsonType }) => code `${jsonType}`), { on: "|" }));
|
|
370
365
|
default:
|
|
371
366
|
throw discriminant;
|
|
372
367
|
}
|
|
@@ -400,28 +395,6 @@ ${joinCode(this.concreteMembers.map(({ jsonType, jsonTypeCheck, type, unwrap, wr
|
|
|
400
395
|
throw new Error("should never reach this point");
|
|
401
396
|
}
|
|
402
397
|
}
|
|
403
|
-
get inlineValueSparqlConstructTriplesFunction() {
|
|
404
|
-
return code `\
|
|
405
|
-
((({ ignoreRdfType, filter, schema, ...otherParameters }) => {
|
|
406
|
-
let triples: ${imports.sparqljs}.Triple[] = [];
|
|
407
|
-
|
|
408
|
-
${joinCode(this.concreteMembers.map(({ type, primaryDiscriminantValue }) => code `\
|
|
409
|
-
triples = triples.concat(${type.valueSparqlConstructTriplesFunction}({ ...otherParameters, filter: filter?.on?.[${literalOf(primaryDiscriminantValue)}], ignoreRdfType: false, schema: schema.members[${literalOf(primaryDiscriminantValue)}].type }));`))}
|
|
410
|
-
|
|
411
|
-
return triples;
|
|
412
|
-
}) satisfies ${snippets.ValueSparqlConstructTriplesFunction}<${this.filterType}, ${this.schemaType}>)`;
|
|
413
|
-
}
|
|
414
|
-
get inlineValueSparqlWherePatternsFunction() {
|
|
415
|
-
return code `\
|
|
416
|
-
((({ filter, schema, ...otherParameters }) => {
|
|
417
|
-
const unionPatterns: ${imports.sparqljs}.GroupPattern[] = [];
|
|
418
|
-
|
|
419
|
-
${joinCode(this.concreteMembers.map(({ type, primaryDiscriminantValue }) => code `\
|
|
420
|
-
unionPatterns.push({ patterns: ${type.valueSparqlWherePatternsFunction}({ ...otherParameters, filter: filter?.on?.[${literalOf(primaryDiscriminantValue)}], ignoreRdfType: false, schema: schema.members[${literalOf(primaryDiscriminantValue)}].type }).concat(), type: "group" });`))}
|
|
421
|
-
|
|
422
|
-
return [{ patterns: unionPatterns, type: "union" }];
|
|
423
|
-
}) satisfies ${snippets.ValueSparqlWherePatternsFunction}<${this.filterType}, ${this.schemaType}>)`;
|
|
424
|
-
}
|
|
425
398
|
get inlineToJsonFunction() {
|
|
426
399
|
return code `\
|
|
427
400
|
((value: ${this.name}): ${this.jsonType().name} => {
|
|
@@ -432,7 +405,19 @@ ${joinCode(this.concreteMembers.map(({ typeCheck, typeToJsonExpression, unwrap,
|
|
|
432
405
|
}
|
|
433
406
|
get inlineToRdfResourceValuesFunction() {
|
|
434
407
|
return code `\
|
|
435
|
-
(((value, _options) => {
|
|
408
|
+
(((value, _options): (${joinCode([...this.toRdfResourceValueTypes].map((toRdfResourceValueType) => {
|
|
409
|
+
switch (toRdfResourceValueType) {
|
|
410
|
+
case "BlankNode":
|
|
411
|
+
return code `${imports.BlankNode}`;
|
|
412
|
+
case "Literal":
|
|
413
|
+
return code `${imports.Literal}`;
|
|
414
|
+
case "NamedNode":
|
|
415
|
+
return code `${imports.NamedNode}`;
|
|
416
|
+
default:
|
|
417
|
+
toRdfResourceValueType;
|
|
418
|
+
throw new Error();
|
|
419
|
+
}
|
|
420
|
+
}), { on: " | " })})[] => {
|
|
436
421
|
${joinCode(this.concreteMembers.map(({ type, unwrap, typeCheck }) => code `if (${typeCheck(code `value`)}) { return ${type.toRdfResourceValuesExpression({
|
|
437
422
|
variables: {
|
|
438
423
|
graph: code `_options.graph`,
|
|
@@ -444,7 +429,29 @@ ${joinCode(this.concreteMembers.map(({ type, unwrap, typeCheck }) => code `if ($
|
|
|
444
429
|
})}; }`))}
|
|
445
430
|
|
|
446
431
|
throw new Error("unable to serialize to RDF");
|
|
447
|
-
})
|
|
432
|
+
}) satisfies ${snippets.ToRdfResourceValuesFunction}<${this.name}>)`;
|
|
433
|
+
}
|
|
434
|
+
get inlineValueSparqlConstructTriplesFunction() {
|
|
435
|
+
return code `\
|
|
436
|
+
((({ ignoreRdfType, filter, schema, ...otherParameters }) => {
|
|
437
|
+
let triples: ${imports.sparqljs}.Triple[] = [];
|
|
438
|
+
|
|
439
|
+
${joinCode(this.concreteMembers.map(({ type, primaryDiscriminantValue }) => code `\
|
|
440
|
+
triples = triples.concat(${type.valueSparqlConstructTriplesFunction}({ ...otherParameters, filter: filter?.on?.[${literalOf(primaryDiscriminantValue)}], ignoreRdfType: false, schema: schema.members[${literalOf(primaryDiscriminantValue)}].type }));`))}
|
|
441
|
+
|
|
442
|
+
return triples;
|
|
443
|
+
}) satisfies ${snippets.ValueSparqlConstructTriplesFunction}<${this.filterType}, ${this.schemaType}>)`;
|
|
444
|
+
}
|
|
445
|
+
get inlineValueSparqlWherePatternsFunction() {
|
|
446
|
+
return code `\
|
|
447
|
+
((({ filter, schema, ...otherParameters }) => {
|
|
448
|
+
const unionPatterns: ${imports.sparqljs}.GroupPattern[] = [];
|
|
449
|
+
|
|
450
|
+
${joinCode(this.concreteMembers.map(({ type, primaryDiscriminantValue }) => code `\
|
|
451
|
+
unionPatterns.push({ patterns: ${type.valueSparqlWherePatternsFunction}({ ...otherParameters, filter: filter?.on?.[${literalOf(primaryDiscriminantValue)}], ignoreRdfType: false, schema: schema.members[${literalOf(primaryDiscriminantValue)}].type }).concat(), type: "group" });`))}
|
|
452
|
+
|
|
453
|
+
return [{ patterns: unionPatterns, type: "union" }];
|
|
454
|
+
}) satisfies ${snippets.ValueSparqlWherePatternsFunction}<${this.filterType}, ${this.schemaType}>)`;
|
|
448
455
|
}
|
|
449
456
|
get schemaObject() {
|
|
450
457
|
return {
|
|
@@ -469,6 +476,7 @@ ${joinCode(this.concreteMembers.map(({ type, unwrap, typeCheck }) => code `if ($
|
|
|
469
476
|
})
|
|
470
477
|
.concat())} }`);
|
|
471
478
|
}
|
|
479
|
+
lazyMembers;
|
|
472
480
|
}
|
|
473
481
|
__decorate([
|
|
474
482
|
Memoize()
|
|
@@ -485,6 +493,9 @@ __decorate([
|
|
|
485
493
|
__decorate([
|
|
486
494
|
Memoize()
|
|
487
495
|
], AbstractUnionType.prototype, "schema", null);
|
|
496
|
+
__decorate([
|
|
497
|
+
Memoize()
|
|
498
|
+
], AbstractUnionType.prototype, "toRdfResourceValueTypes", null);
|
|
488
499
|
__decorate([
|
|
489
500
|
Memoize()
|
|
490
501
|
], AbstractUnionType.prototype, "typeofs", null);
|
|
@@ -512,6 +523,19 @@ __decorate([
|
|
|
512
523
|
__decorate([
|
|
513
524
|
Memoize()
|
|
514
525
|
], AbstractUnionType.prototype, "inlineValueSparqlWherePatternsFunction", null);
|
|
526
|
+
function termTypes(type) {
|
|
527
|
+
switch (type.kind) {
|
|
528
|
+
case "BlankNodeType":
|
|
529
|
+
case "IriType":
|
|
530
|
+
case "IdentifierType":
|
|
531
|
+
case "LiteralType":
|
|
532
|
+
case "TermType":
|
|
533
|
+
return type.termTypes;
|
|
534
|
+
default:
|
|
535
|
+
return emptyTermTypesSet;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
const emptyTermTypesSet = new Set();
|
|
515
539
|
export var Discriminant;
|
|
516
540
|
(function (Discriminant) {
|
|
517
541
|
function infer(members) {
|
|
@@ -5,13 +5,13 @@ import { type Code } from "./ts-poet-wrapper.js";
|
|
|
5
5
|
export declare class BlankNodeType extends AbstractIdentifierType<BlankNode> {
|
|
6
6
|
readonly filterFunction: Code;
|
|
7
7
|
readonly filterType: Code;
|
|
8
|
-
readonly
|
|
8
|
+
readonly parseFunction: Code;
|
|
9
9
|
readonly kind = "BlankNodeType";
|
|
10
10
|
readonly name: Code;
|
|
11
11
|
readonly nodeKinds: ReadonlySet<"BlankNode">;
|
|
12
12
|
readonly schemaType: Code;
|
|
13
13
|
readonly valueSparqlWherePatternsFunction: Code;
|
|
14
|
-
constructor(superParameters:
|
|
14
|
+
constructor(superParameters: Omit<ConstructorParameters<typeof AbstractIdentifierType<BlankNode>>[0], "hasValues" | "in_">);
|
|
15
15
|
fromJsonExpression({ variables, }: Parameters<AbstractTermType<NamedNode, BlankNode | NamedNode>["fromJsonExpression"]>[0]): Code;
|
|
16
16
|
jsonType(parameters?: Parameters<AbstractTermType["jsonType"]>[0]): AbstractTermType.JsonType;
|
|
17
17
|
jsonSchema({ includeDiscriminantProperty, }: Parameters<AbstractTermType<NamedNode, BlankNode | NamedNode>["jsonSchema"]>[0]): Code;
|
|
@@ -13,7 +13,7 @@ import { code } from "./ts-poet-wrapper.js";
|
|
|
13
13
|
export class BlankNodeType extends AbstractIdentifierType {
|
|
14
14
|
filterFunction = code `${snippets.filterBlankNode}`;
|
|
15
15
|
filterType = code `${snippets.BlankNodeFilter}`;
|
|
16
|
-
|
|
16
|
+
parseFunction = code `${snippets.parseBlankNode};`;
|
|
17
17
|
kind = "BlankNodeType";
|
|
18
18
|
name = code `${imports.BlankNode}`;
|
|
19
19
|
nodeKinds = nodeKinds;
|
|
@@ -38,7 +38,7 @@ export class BooleanType extends AbstractPrimitiveType {
|
|
|
38
38
|
return code `${imports.z}.boolean()`;
|
|
39
39
|
}
|
|
40
40
|
toRdfResourceValuesExpression({ variables, }) {
|
|
41
|
-
return code `[${snippets.literalFactory}.boolean(${variables.value}, ${rdfjsTermExpression(this.datatype)})]`;
|
|
41
|
+
return code `[${snippets.literalFactory}.boolean(${variables.value}, ${rdfjsTermExpression(this.datatype, { logger: this.logger })})]`;
|
|
42
42
|
}
|
|
43
43
|
fromRdfExpressionChain({ variables, }) {
|
|
44
44
|
return {
|
|
@@ -114,7 +114,7 @@ export class DefaultValueType extends AbstractContainerType {
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
get defaultValueTermExpression() {
|
|
117
|
-
return rdfjsTermExpression(this.defaultValue);
|
|
117
|
+
return rdfjsTermExpression(this.defaultValue, { logger: this.logger });
|
|
118
118
|
}
|
|
119
119
|
fromJsonExpression(parameters) {
|
|
120
120
|
return this.itemType.fromJsonExpression(parameters);
|
|
@@ -6,13 +6,13 @@ import { type Code } from "./ts-poet-wrapper.js";
|
|
|
6
6
|
export declare class IdentifierType extends AbstractIdentifierType<BlankNode | NamedNode> {
|
|
7
7
|
readonly filterFunction: Code;
|
|
8
8
|
readonly filterType: Code;
|
|
9
|
-
readonly
|
|
9
|
+
readonly parseFunction: Code;
|
|
10
10
|
readonly kind = "IdentifierType";
|
|
11
11
|
readonly name: Code;
|
|
12
12
|
readonly nodeKinds: ReadonlySet<IdentifierNodeKind>;
|
|
13
13
|
readonly schemaType: Code;
|
|
14
14
|
readonly valueSparqlWherePatternsFunction: Code;
|
|
15
|
-
constructor(parameters:
|
|
15
|
+
constructor(parameters: Omit<ConstructorParameters<typeof AbstractIdentifierType<BlankNode | NamedNode>>[0], "hasValues" | "in_">);
|
|
16
16
|
fromJsonExpression({ variables, }: Parameters<AbstractTermType<NamedNode, BlankNode | NamedNode>["fromJsonExpression"]>[0]): Code;
|
|
17
17
|
jsonType(parameters?: Parameters<AbstractTermType["jsonType"]>[0]): AbstractTermType.JsonType;
|
|
18
18
|
jsonSchema({ includeDiscriminantProperty, }: Parameters<AbstractTermType<NamedNode, BlankNode | NamedNode>["jsonSchema"]>[0]): Code;
|
|
@@ -14,7 +14,7 @@ import { arrayOf, code } from "./ts-poet-wrapper.js";
|
|
|
14
14
|
export class IdentifierType extends AbstractIdentifierType {
|
|
15
15
|
filterFunction = code `${snippets.filterIdentifier}`;
|
|
16
16
|
filterType = code `${snippets.IdentifierFilter}`;
|
|
17
|
-
|
|
17
|
+
parseFunction = code `${snippets.parseIdentifier};`;
|
|
18
18
|
kind = "IdentifierType";
|
|
19
19
|
name = code `(${imports.BlankNode} | ${imports.NamedNode})`;
|
|
20
20
|
nodeKinds = nodeKinds;
|
|
@@ -9,7 +9,7 @@ export declare class IriType extends AbstractIdentifierType<NamedNode> {
|
|
|
9
9
|
readonly nodeKinds: ReadonlySet<"IRI">;
|
|
10
10
|
readonly schemaType: Code;
|
|
11
11
|
readonly valueSparqlWherePatternsFunction: Code;
|
|
12
|
-
get
|
|
12
|
+
get parseFunction(): Code;
|
|
13
13
|
get name(): Code;
|
|
14
14
|
protected get schemaObject(): {
|
|
15
15
|
in: Code[] | undefined;
|
|
@@ -18,18 +18,11 @@ export class IriType extends AbstractIdentifierType {
|
|
|
18
18
|
nodeKinds = nodeKinds;
|
|
19
19
|
schemaType = code `${snippets.IriSchema}`;
|
|
20
20
|
valueSparqlWherePatternsFunction = code `${snippets.iriSparqlWherePatterns}`;
|
|
21
|
-
get
|
|
22
|
-
const expressions = [
|
|
23
|
-
code `${imports.Either}.encase(() => ${imports.Resource}.Identifier.fromString({ ${imports.dataFactory}, identifier }))`,
|
|
24
|
-
code `chain((identifier) => (identifier.termType === "NamedNode") ? ${imports.Right}(identifier) : ${imports.Left}(new Error("expected identifier to be NamedNode")))`,
|
|
25
|
-
];
|
|
21
|
+
get parseFunction() {
|
|
26
22
|
if (this.in_.length > 0) {
|
|
27
|
-
|
|
23
|
+
return code `(identifier: string) => ${snippets.parseIri}(identifier).chain((identifier) => { switch (identifier.value) { ${joinCode(this.in_.map((iri) => code `case "${iri.value}": return ${imports.Right}(identifier as ${this.name});`))} default: return ${imports.Left}(new Error("expected NamedNode identifier to be one of ${this.in_.map((iri) => iri.value).join(" ")}")); } })`;
|
|
28
24
|
}
|
|
29
|
-
return code
|
|
30
|
-
export function fromString(identifier: string): ${imports.Either}<Error, ${this.name}> {
|
|
31
|
-
return ${joinCode(expressions, { on: "." })} as ${imports.Either}<Error, ${this.name}>;
|
|
32
|
-
}`;
|
|
25
|
+
return code `${snippets.parseIri}`;
|
|
33
26
|
}
|
|
34
27
|
get name() {
|
|
35
28
|
if (this.in_.length > 0) {
|
|
@@ -45,7 +38,9 @@ export function fromString(identifier: string): ${imports.Either}<Error, ${this.
|
|
|
45
38
|
return {
|
|
46
39
|
...super.schemaObject,
|
|
47
40
|
in: this.in_.length > 0
|
|
48
|
-
? this.in_
|
|
41
|
+
? this.in_
|
|
42
|
+
.map((in_) => rdfjsTermExpression(in_, { logger: this.logger }))
|
|
43
|
+
.concat()
|
|
49
44
|
: undefined,
|
|
50
45
|
};
|
|
51
46
|
}
|
|
@@ -88,14 +83,14 @@ export function fromString(identifier: string): ${imports.Either}<Error, ${this.
|
|
|
88
83
|
return {
|
|
89
84
|
...super.fromRdfExpressionChain({ variables }),
|
|
90
85
|
valueTo: code `chain(values => values.chainMap(value => value.toIri(${this.in_.length > 0
|
|
91
|
-
? code `[${joinCode(this.in_.map((in_) => rdfjsTermExpression(in_)), { on: ", " })}]`
|
|
86
|
+
? code `[${joinCode(this.in_.map((in_) => rdfjsTermExpression(in_, { logger: this.logger })), { on: ", " })}]`
|
|
92
87
|
: ""})))`,
|
|
93
88
|
};
|
|
94
89
|
}
|
|
95
90
|
}
|
|
96
91
|
__decorate([
|
|
97
92
|
Memoize()
|
|
98
|
-
], IriType.prototype, "
|
|
93
|
+
], IriType.prototype, "parseFunction", null);
|
|
99
94
|
__decorate([
|
|
100
95
|
Memoize()
|
|
101
96
|
], IriType.prototype, "name", null);
|
|
@@ -14,6 +14,7 @@ declare const Super: (abstract new ({ partialType, resolveType, runtimeClass, ..
|
|
|
14
14
|
} & {
|
|
15
15
|
comment: Maybe<string>;
|
|
16
16
|
label: Maybe<string>;
|
|
17
|
+
logger: import("ts-log").Logger;
|
|
17
18
|
}) => AbstractLazyObjectType<OptionType<AbstractLazyObjectType.ObjectTypeConstraint>, OptionType<AbstractLazyObjectType.ObjectTypeConstraint>>) & {
|
|
18
19
|
readonly GraphqlType: typeof import("./AbstractType.js").AbstractType.GraphqlType;
|
|
19
20
|
readonly JsonType: typeof import("./AbstractType.js").AbstractType.JsonType;
|
|
@@ -71,7 +71,7 @@ export class LazyObjectOptionType extends Super {
|
|
|
71
71
|
return conversions;
|
|
72
72
|
}
|
|
73
73
|
fromJsonExpression(parameters) {
|
|
74
|
-
return code `new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}: ${this.partialType.fromJsonExpression(parameters)}, resolver: (identifier) => Promise.resolve(${imports.Left}(new Error(\`unable to resolve identifier \${
|
|
74
|
+
return code `new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}: ${this.partialType.fromJsonExpression(parameters)}, resolver: (identifier) => Promise.resolve(${imports.Left}(new Error(\`unable to resolve identifier \${identifier} deserialized from JSON\`))) })`;
|
|
75
75
|
}
|
|
76
76
|
fromRdfResourceValuesExpression(parameters) {
|
|
77
77
|
const { variables } = parameters;
|
|
@@ -45,7 +45,7 @@ export class LazyObjectType extends AbstractLazyObjectType {
|
|
|
45
45
|
return conversions;
|
|
46
46
|
}
|
|
47
47
|
fromJsonExpression(parameters) {
|
|
48
|
-
return code `new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}: ${this.partialType.fromJsonExpression(parameters)}, resolver: (identifier) => Promise.resolve(${imports.Left}(new Error(\`unable to resolve identifier \${
|
|
48
|
+
return code `new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}: ${this.partialType.fromJsonExpression(parameters)}, resolver: (identifier) => Promise.resolve(${imports.Left}(new Error(\`unable to resolve identifier \${identifier} deserialized from JSON\`))) })`;
|
|
49
49
|
}
|
|
50
50
|
fromRdfResourceValuesExpression(parameters) {
|
|
51
51
|
const { variables } = parameters;
|
|
@@ -85,16 +85,16 @@ export class ListType extends AbstractCollectionType {
|
|
|
85
85
|
currentSubListResource = listResource;
|
|
86
86
|
} else {
|
|
87
87
|
const newSubListResource = ${variables.resourceSet}.resource(${subListIdentifier});
|
|
88
|
-
currentSubListResource!.add(${rdfjsTermExpression(rdf.rest)}, newSubListResource.identifier, ${variables.graph});
|
|
88
|
+
currentSubListResource!.add(${rdfjsTermExpression(rdf.rest, { logger: this.logger })}, newSubListResource.identifier, ${variables.graph});
|
|
89
89
|
currentSubListResource = newSubListResource;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
${joinCode(this.toRdfTypes.map((rdfType) => code `currentSubListResource.add(${rdfjsTermExpression(rdf.type)}, ${imports.dataFactory}.namedNode("${rdfType.value}"), ${variables.graph})`))}
|
|
92
|
+
${joinCode(this.toRdfTypes.map((rdfType) => code `currentSubListResource.add(${rdfjsTermExpression(rdf.type, { logger: this.logger })}, ${imports.dataFactory}.namedNode("${rdfType.value}"), ${variables.graph})`))}
|
|
93
93
|
|
|
94
|
-
currentSubListResource.add(${rdfjsTermExpression(rdf.first)}, ${this.itemType.toRdfResourceValuesExpression({ variables: { graph: variables.graph, propertyPath: rdfjsTermExpression(rdf.first), resource: code `currentSubListResource`, resourceSet: variables.resourceSet, value: code `item` } })}, ${variables.graph});
|
|
94
|
+
currentSubListResource.add(${rdfjsTermExpression(rdf.first, { logger: this.logger })}, ${this.itemType.toRdfResourceValuesExpression({ variables: { graph: variables.graph, propertyPath: rdfjsTermExpression(rdf.first, { logger: this.logger }), resource: code `currentSubListResource`, resourceSet: variables.resourceSet, value: code `item` } })}, ${variables.graph});
|
|
95
95
|
|
|
96
96
|
if (itemIndex + 1 === list.length) {
|
|
97
|
-
currentSubListResource.add(${rdfjsTermExpression(rdf.rest)}, ${rdfjsTermExpression(rdf.nil)}, ${variables.graph});
|
|
97
|
+
currentSubListResource.add(${rdfjsTermExpression(rdf.rest, { logger: this.logger })}, ${rdfjsTermExpression(rdf.nil, { logger: this.logger })}, ${variables.graph});
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
return { currentSubListResource, listResource };
|
|
@@ -106,7 +106,7 @@ export class ListType extends AbstractCollectionType {
|
|
|
106
106
|
currentSubListResource: ${resourceTypeName} | null;
|
|
107
107
|
listResource: ${resourceTypeName};
|
|
108
108
|
},
|
|
109
|
-
).listResource.identifier : ${rdfjsTermExpression(rdf.nil)}]`;
|
|
109
|
+
).listResource.identifier : ${rdfjsTermExpression(rdf.nil, { logger: this.logger })}]`;
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
__decorate([
|
|
@@ -77,6 +77,7 @@ export declare class NamedObjectType extends AbstractType {
|
|
|
77
77
|
get properties(): readonly NamedObjectType.Property[];
|
|
78
78
|
get schema(): Code;
|
|
79
79
|
get schemaType(): Code;
|
|
80
|
+
get toRdfResourceValueTypes(): AbstractType["toRdfResourceValueTypes"];
|
|
80
81
|
get toRdfjsResourceType(): Code;
|
|
81
82
|
get valueSparqlConstructTriplesFunction(): Code;
|
|
82
83
|
get valueSparqlWherePatternsFunction(): Code;
|
|
@@ -4,6 +4,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
+
import { NodeKind } from "@shaclmate/shacl-ast";
|
|
7
8
|
import { camelCase } from "change-case";
|
|
8
9
|
import { Maybe, NonEmptyList } from "purify-ts";
|
|
9
10
|
import { Memoize } from "typescript-memoize";
|
|
@@ -228,6 +229,9 @@ ${joinCode(staticModuleDeclarations, { on: "\n\n" })}
|
|
|
228
229
|
get schemaType() {
|
|
229
230
|
return code `typeof ${this.schema}`;
|
|
230
231
|
}
|
|
232
|
+
get toRdfResourceValueTypes() {
|
|
233
|
+
return new Set([...this.identifierType.nodeKinds].map(NodeKind.toTermType));
|
|
234
|
+
}
|
|
231
235
|
get toRdfjsResourceType() {
|
|
232
236
|
if (this.parentObjectTypes.length > 0) {
|
|
233
237
|
return this.parentObjectTypes[0].toRdfjsResourceType;
|
|
@@ -396,6 +400,9 @@ __decorate([
|
|
|
396
400
|
__decorate([
|
|
397
401
|
Memoize()
|
|
398
402
|
], NamedObjectType.prototype, "schemaType", null);
|
|
403
|
+
__decorate([
|
|
404
|
+
Memoize()
|
|
405
|
+
], NamedObjectType.prototype, "toRdfResourceValueTypes", null);
|
|
399
406
|
__decorate([
|
|
400
407
|
Memoize()
|
|
401
408
|
], NamedObjectType.prototype, "toRdfjsResourceType", null);
|
|
@@ -125,7 +125,10 @@ export const ${syntheticNamePrefix}GraphQL = new ${imports.GraphQLUnionType}(${{
|
|
|
125
125
|
get identifierTypeDeclarations() {
|
|
126
126
|
return singleEntryRecord(`${syntheticNamePrefix}Identifier`, code `\
|
|
127
127
|
export type ${syntheticNamePrefix}Identifier = ${this.#identifierType.name};
|
|
128
|
-
export namespace ${syntheticNamePrefix}Identifier {
|
|
128
|
+
export namespace ${syntheticNamePrefix}Identifier {
|
|
129
|
+
export const parse = ${this.#identifierType.parseFunction};
|
|
130
|
+
export const stringify = ${this.#identifierType.stringifyFunction};
|
|
131
|
+
}`);
|
|
129
132
|
}
|
|
130
133
|
get isTypeFunctionDeclaration() {
|
|
131
134
|
if (this._name === `${syntheticNamePrefix}Object`) {
|
|
@@ -40,7 +40,7 @@ export class SetType extends AbstractCollectionType {
|
|
|
40
40
|
chain.push(code `map(values => values.toArray()${this._mutable ? ".concat()" : ""})`);
|
|
41
41
|
}
|
|
42
42
|
else {
|
|
43
|
-
chain.push(code `chain(values => ${imports.NonEmptyList}.fromArray(values.toArray()).toEither(new Error(\`\${${
|
|
43
|
+
chain.push(code `chain(values => ${imports.NonEmptyList}.fromArray(values.toArray()).toEither(new Error(\`\${${variables.resource}.identifier} is an empty set\`)))`);
|
|
44
44
|
}
|
|
45
45
|
chain.push(code `map(valuesArray => ${imports.Resource}.Values.fromValue({ focusResource: ${variables.resource}, propertyPath: ${variables.propertyPath}, value: valuesArray }))`);
|
|
46
46
|
return joinCode(chain, { on: "." });
|
|
@@ -48,7 +48,7 @@ export class StringType extends AbstractPrimitiveType {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
toRdfResourceValuesExpression({ variables, }) {
|
|
51
|
-
return code `[${snippets.literalFactory}.string(${variables.value}${!this.datatype.equals(xsd.string) ? `, ${rdfjsTermExpression(this.datatype)}` : ""})]`;
|
|
51
|
+
return code `[${snippets.literalFactory}.string(${variables.value}${!this.datatype.equals(xsd.string) ? `, ${rdfjsTermExpression(this.datatype, { logger: this.logger })}` : ""})]`;
|
|
52
52
|
}
|
|
53
53
|
fromRdfExpressionChain({ variables, }) {
|
|
54
54
|
return {
|
|
@@ -49,7 +49,9 @@ export class TermType extends AbstractTermType {
|
|
|
49
49
|
get schemaObject() {
|
|
50
50
|
return {
|
|
51
51
|
...super.schemaObject,
|
|
52
|
-
in: this.in_.length > 0
|
|
52
|
+
in: this.in_.length > 0
|
|
53
|
+
? this.in_.map((in_) => rdfjsTermExpression(in_, { logger: this.logger }))
|
|
54
|
+
: undefined,
|
|
53
55
|
};
|
|
54
56
|
}
|
|
55
57
|
fromJsonExpression({ variables, }) {
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
import type { Logger } from "ts-log";
|
|
1
2
|
import * as ast from "../../ast/index.js";
|
|
2
3
|
import type { Generator } from "../Generator.js";
|
|
3
4
|
export declare class TsGenerator implements Generator {
|
|
5
|
+
private readonly logger;
|
|
4
6
|
private readonly typeFactory;
|
|
7
|
+
constructor({ logger }: {
|
|
8
|
+
logger: Logger;
|
|
9
|
+
});
|
|
5
10
|
generate(ast_: ast.Ast): string;
|
|
6
11
|
}
|
|
7
12
|
//# sourceMappingURL=TsGenerator.d.ts.map
|
|
@@ -6,7 +6,12 @@ import { synthesizeUberObjectUnionType } from "./synthesizeUberObjectUnionType.j
|
|
|
6
6
|
import { TypeFactory } from "./TypeFactory.js";
|
|
7
7
|
import { code, joinCode } from "./ts-poet-wrapper.js";
|
|
8
8
|
export class TsGenerator {
|
|
9
|
-
|
|
9
|
+
logger;
|
|
10
|
+
typeFactory;
|
|
11
|
+
constructor({ logger }) {
|
|
12
|
+
this.logger = logger;
|
|
13
|
+
this.typeFactory = new TypeFactory({ logger });
|
|
14
|
+
}
|
|
10
15
|
generate(ast_) {
|
|
11
16
|
let declarations = [];
|
|
12
17
|
for (const astNamedUnionType of ast_.namedUnionTypes) {
|
|
@@ -29,6 +34,7 @@ export class TsGenerator {
|
|
|
29
34
|
const namedObjectUnionTypesNameSorted = namedObjectUnionTypesToposorted.toSorted((left, right) => left.name.localeCompare(right.name));
|
|
30
35
|
if (namedObjectTypesToposorted.length > 0) {
|
|
31
36
|
const uberObjectUnionType = synthesizeUberObjectUnionType({
|
|
37
|
+
logger: this.logger,
|
|
32
38
|
namedObjectTypes: namedObjectTypesToposorted.toReversed(), // Reverse topological order so children ane before parents
|
|
33
39
|
});
|
|
34
40
|
declarations = declarations.concat(uberObjectUnionType.declaration.toList());
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Literal, NamedNode } from "@rdfjs/types";
|
|
2
|
+
import type { Logger } from "ts-log";
|
|
2
3
|
import * as ast from "../../ast/index.js";
|
|
3
4
|
import { AnonymousUnionType } from "./AnonymousUnionType.js";
|
|
4
5
|
import { NamedObjectType } from "./NamedObjectType.js";
|
|
@@ -9,6 +10,10 @@ export declare class TypeFactory {
|
|
|
9
10
|
private cachedNamedObjectUnionTypesByShapeIdentifier;
|
|
10
11
|
private cachedObjectTypePropertiesByShapeIdentifier;
|
|
11
12
|
private cachedObjectTypesByShapeIdentifier;
|
|
13
|
+
private readonly logger;
|
|
14
|
+
constructor({ logger }: {
|
|
15
|
+
logger: Logger;
|
|
16
|
+
});
|
|
12
17
|
createNamedObjectUnionType(astType: ast.ObjectUnionType): NamedObjectUnionType;
|
|
13
18
|
createNamedObjectType(astType: ast.ObjectType): NamedObjectType;
|
|
14
19
|
createType(astType: ast.Type, parameters?: {
|