@shaclmate/compiler 4.0.40 → 4.0.41
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/ShapesGraphToAstTransformer.d.ts +0 -8
- package/dist/ShapesGraphToAstTransformer.js +5 -85
- package/dist/_ShapesGraphToAstTransformer/shapeNodeKinds.js +128 -160
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstObjectType.d.ts +1 -1
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstObjectType.js +0 -16
- package/dist/ast/AbstractCompoundType.d.ts +2 -1
- package/dist/ast/AbstractCompoundType.js +1 -1
- package/dist/ast/AbstractLazyObjectType.d.ts +0 -2
- package/dist/ast/Ast.d.ts +1 -3
- package/dist/ast/ListType.d.ts +1 -1
- package/dist/ast/ListType.js +1 -1
- package/dist/ast/ObjectType.d.ts +0 -12
- package/dist/ast/ObjectType.js +0 -78
- package/dist/generators/AstJsonGenerator.js +7 -3
- package/dist/generators/transformAstToLabeledPropertyGraph.js +59 -56
- package/dist/generators/ts/AbstractCollectionType.d.ts +4 -11
- package/dist/generators/ts/AbstractCollectionType.js +3 -62
- package/dist/generators/ts/AbstractContainerType.d.ts +0 -1
- package/dist/generators/ts/AbstractContainerType.js +1 -4
- package/dist/generators/ts/AbstractDateType.d.ts +4 -1
- package/dist/generators/ts/AbstractDateType.js +6 -1
- package/dist/generators/ts/AbstractIdentifierType.d.ts +4 -0
- package/dist/generators/ts/AbstractIdentifierType.js +3 -0
- package/dist/generators/ts/AbstractLazyObjectType.d.ts +1 -1
- package/dist/generators/ts/AbstractLazyObjectType.js +12 -1
- package/dist/generators/ts/AbstractLiteralType.d.ts +1 -0
- package/dist/generators/ts/AbstractNumericType.js +7 -7
- package/dist/generators/ts/AbstractPrimitiveType.d.ts +1 -0
- package/dist/generators/ts/AbstractTermType.d.ts +1 -2
- package/dist/generators/ts/AbstractTermType.js +1 -3
- package/dist/generators/ts/AbstractType.d.ts +46 -16
- package/dist/generators/ts/AbstractType.js +31 -16
- package/dist/generators/ts/BigDecimalType.d.ts +4 -0
- package/dist/generators/ts/BigDecimalType.js +4 -1
- package/dist/generators/ts/BigIntType.d.ts +3 -1
- package/dist/generators/ts/BigIntType.js +1 -1
- package/dist/generators/ts/BlankNodeType.d.ts +1 -1
- package/dist/generators/ts/BlankNodeType.js +3 -3
- package/dist/generators/ts/BooleanType.d.ts +3 -1
- package/dist/generators/ts/BooleanType.js +1 -1
- package/dist/generators/ts/DefaultValueType.d.ts +39 -1
- package/dist/generators/ts/DefaultValueType.js +6 -3
- package/dist/generators/ts/FloatType.d.ts +3 -1
- package/dist/generators/ts/FloatType.js +1 -1
- package/dist/generators/ts/GraphqlSchema.js +2 -2
- package/dist/generators/ts/IdentifierType.d.ts +1 -1
- package/dist/generators/ts/IdentifierType.js +7 -5
- package/dist/generators/ts/IntType.d.ts +3 -1
- package/dist/generators/ts/IntType.js +1 -1
- package/dist/generators/ts/IriType.js +4 -2
- package/dist/generators/ts/LazyObjectOptionType.d.ts +1 -0
- package/dist/generators/ts/LazyObjectOptionType.js +8 -4
- package/dist/generators/ts/LazyObjectSetType.js +9 -3
- package/dist/generators/ts/LazyObjectType.js +5 -2
- package/dist/generators/ts/ListType.d.ts +10 -1
- package/dist/generators/ts/ListType.js +45 -8
- package/dist/generators/ts/LiteralType.d.ts +4 -0
- package/dist/generators/ts/LiteralType.js +6 -3
- package/dist/generators/ts/ObjectType.d.ts +8 -22
- package/dist/generators/ts/ObjectType.js +6 -74
- package/dist/generators/ts/ObjectUnionType.js +2 -2
- package/dist/generators/ts/OptionType.d.ts +5 -1
- package/dist/generators/ts/OptionType.js +10 -5
- package/dist/generators/ts/RdfjsDatasetObjectSetType.js +1 -4
- package/dist/generators/ts/SetType.d.ts +16 -1
- package/dist/generators/ts/SetType.js +80 -2
- package/dist/generators/ts/Snippets.d.ts +3 -1
- package/dist/generators/ts/Snippets.js +18 -4
- package/dist/generators/ts/StringType.d.ts +3 -1
- package/dist/generators/ts/StringType.js +5 -1
- package/dist/generators/ts/TermType.d.ts +4 -0
- package/dist/generators/ts/TermType.js +3 -0
- package/dist/generators/ts/TsGenerator.d.ts +1 -1
- package/dist/generators/ts/TsGenerator.js +53 -28
- package/dist/generators/ts/TypeFactory.js +12 -25
- package/dist/generators/ts/UnionType.d.ts +3 -6
- package/dist/generators/ts/UnionType.js +42 -55
- package/dist/generators/ts/ZodGenerator.d.ts +1 -1
- package/dist/generators/ts/ZodGenerator.js +19 -12
- package/dist/generators/ts/_ObjectType/AbstractProperty.d.ts +6 -3
- package/dist/generators/ts/_ObjectType/DiscriminantProperty.d.ts +8 -12
- package/dist/generators/ts/_ObjectType/DiscriminantProperty.js +18 -35
- package/dist/generators/ts/_ObjectType/IdentifierProperty.js +5 -5
- package/dist/generators/ts/_ObjectType/ObjectType_createFunctionDeclaration.js +9 -30
- package/dist/generators/ts/_ObjectType/ObjectType_equalsFunctionDeclaration.js +0 -4
- package/dist/generators/ts/_ObjectType/ObjectType_filterFunctionDeclaration.js +0 -3
- package/dist/generators/ts/_ObjectType/ObjectType_filterTypeDeclaration.js +0 -3
- package/dist/generators/ts/_ObjectType/ObjectType_focusSparqlConstructTriplesFunctionDeclaration.js +0 -4
- package/dist/generators/ts/_ObjectType/ObjectType_focusSparqlWherePatternsFunctionDeclaration.js +3 -22
- package/dist/generators/ts/_ObjectType/ObjectType_fromJsonFunctionDeclaration.js +4 -29
- package/dist/generators/ts/_ObjectType/ObjectType_fromRdfResourceFunctionDeclaration.js +10 -39
- package/dist/generators/ts/_ObjectType/ObjectType_hashFunctionDeclarations.js +25 -29
- package/dist/generators/ts/_ObjectType/ObjectType_interfaceDeclaration.js +1 -5
- package/dist/generators/ts/_ObjectType/ObjectType_isTypeFunctionDeclaration.js +11 -8
- package/dist/generators/ts/_ObjectType/ObjectType_jsonSchemaFunctionDeclaration.js +3 -9
- package/dist/generators/ts/_ObjectType/ObjectType_jsonTypeAliasDeclaration.js +1 -8
- package/dist/generators/ts/_ObjectType/ObjectType_jsonUiSchemaFunctionDeclaration.js +1 -3
- package/dist/generators/ts/_ObjectType/ObjectType_schemaVariableStatement.js +2 -4
- package/dist/generators/ts/_ObjectType/ObjectType_toJsonFunctionDeclaration.js +10 -31
- package/dist/generators/ts/_ObjectType/ObjectType_toRdfResourceFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_ObjectType/ObjectType_toStringFunctionDeclarations.js +2 -9
- package/dist/generators/ts/_ObjectType/ShaclProperty.js +6 -6
- package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.js +0 -11
- package/dist/generators/ts/_snippets/snippets_convertToArraySet.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToArraySet.js +8 -0
- package/dist/generators/ts/_snippets/snippets_convertToList.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToList.js +7 -0
- package/dist/generators/ts/_snippets/snippets_convertToScalarSet.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToScalarSet.js +15 -0
- package/dist/input/generated.d.ts +756 -115
- package/dist/input/generated.js +634 -126
- package/package.json +2 -4
- package/dist/generators/ts/_snippets/snippets_convertToArray.d.ts +0 -3
- package/dist/generators/ts/_snippets/snippets_convertToArray.js +0 -8
|
@@ -5,18 +5,80 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
import { Maybe } from "purify-ts";
|
|
8
|
+
import { invariant } from "ts-invariant";
|
|
8
9
|
import { Memoize } from "typescript-memoize";
|
|
9
10
|
import { AbstractCollectionType } from "./AbstractCollectionType.js";
|
|
10
|
-
import { code, joinCode } from "./ts-poet-wrapper.js";
|
|
11
|
+
import { code, joinCode, literalOf } from "./ts-poet-wrapper.js";
|
|
11
12
|
export class SetType extends AbstractCollectionType {
|
|
12
13
|
graphqlArgs = Maybe.empty();
|
|
13
14
|
kind = "Set";
|
|
15
|
+
minCount;
|
|
16
|
+
jsTypes = [
|
|
17
|
+
{ instanceof: "Array", typeof: "object" },
|
|
18
|
+
];
|
|
19
|
+
constructor({ minCount, ...superParameters }) {
|
|
20
|
+
super(superParameters);
|
|
21
|
+
this.minCount = minCount;
|
|
22
|
+
invariant(this.minCount >= 0n);
|
|
23
|
+
if (this._mutable) {
|
|
24
|
+
invariant(this.minCount === 0n);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
get conversionFunction() {
|
|
28
|
+
const itemConversionFunction = this.itemType.conversionFunction.orDefault(this.itemConversionFunctionDefault);
|
|
29
|
+
let conversionFunction;
|
|
30
|
+
const sourceTypes = [];
|
|
31
|
+
if (itemConversionFunction.sourceTypes.some((sourceType) => sourceType.jsType.typeof === "object" &&
|
|
32
|
+
sourceType.jsType.instanceof === "Array")) {
|
|
33
|
+
conversionFunction = this.reusables.snippets.convertToArraySet;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
conversionFunction = this.reusables.snippets.convertToScalarSet;
|
|
37
|
+
// Convert from a single item
|
|
38
|
+
sourceTypes.push(...itemConversionFunction.sourceTypes);
|
|
39
|
+
}
|
|
40
|
+
// Convert from an array of items
|
|
41
|
+
sourceTypes.push({
|
|
42
|
+
expression: code `readonly (${joinCode(itemConversionFunction.sourceTypes.map((itemSourceType) => code `${itemSourceType.expression}`), { on: " | " })})[]`,
|
|
43
|
+
jsType: { instanceof: "Array", typeof: "object" },
|
|
44
|
+
});
|
|
45
|
+
// Convert from undefined to an empty array
|
|
46
|
+
if (this.minCount === 0n) {
|
|
47
|
+
sourceTypes.push({
|
|
48
|
+
expression: code `undefined`,
|
|
49
|
+
jsType: { typeof: "undefined" },
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return Maybe.of({
|
|
53
|
+
code: code `${conversionFunction}(${itemConversionFunction.code}, ${literalOf(!this._mutable)})`,
|
|
54
|
+
sourceTypes,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
get toRdfResourceValueTypes() {
|
|
58
|
+
return this.itemType.toRdfResourceValueTypes;
|
|
59
|
+
}
|
|
14
60
|
get valueSparqlConstructTriplesFunction() {
|
|
15
61
|
return code `${this.reusables.snippets.setSparqlConstructTriples}<${this.itemType.filterType}, ${this.itemType.schemaType}>(${this.itemType.valueSparqlConstructTriplesFunction})`;
|
|
16
62
|
}
|
|
17
63
|
get valueSparqlWherePatternsFunction() {
|
|
18
64
|
return code `${this.reusables.snippets.setSparqlWherePatterns}<${this.itemType.filterType}, ${this.itemType.schemaType}>(${this.itemType.valueSparqlWherePatternsFunction})`;
|
|
19
65
|
}
|
|
66
|
+
get schemaInitializers() {
|
|
67
|
+
let schemaInitializers = super.schemaInitializers;
|
|
68
|
+
if (this.minCount > 0n) {
|
|
69
|
+
schemaInitializers = schemaInitializers.concat(code `minCount: ${Number(this.minCount)}`);
|
|
70
|
+
}
|
|
71
|
+
return schemaInitializers;
|
|
72
|
+
}
|
|
73
|
+
fromJsonExpression({ variables, }) {
|
|
74
|
+
let expression = variables.value;
|
|
75
|
+
if (this.minCount === 0n) {
|
|
76
|
+
expression = code `(${expression} ?? [])`;
|
|
77
|
+
}
|
|
78
|
+
return code `${this.reusables.imports.Either}.sequence<Error, ${this.itemType.expression}>(${expression}.map(item => (${this.itemType.fromJsonExpression({
|
|
79
|
+
variables: { value: code `item` },
|
|
80
|
+
})})))`;
|
|
81
|
+
}
|
|
20
82
|
fromRdfResourceValuesExpression(parameters) {
|
|
21
83
|
const { variables } = parameters;
|
|
22
84
|
return joinCode([
|
|
@@ -25,8 +87,21 @@ export class SetType extends AbstractCollectionType {
|
|
|
25
87
|
code `map(valuesArray => ${this.reusables.imports.Resource}.Values.fromValue({ focusResource: ${variables.resource}, propertyPath: ${variables.propertyPath}, value: valuesArray }))`,
|
|
26
88
|
], { on: "." });
|
|
27
89
|
}
|
|
90
|
+
jsonSchema(parameters) {
|
|
91
|
+
let schema = code `${this.itemType.jsonSchema(parameters)}.array()`;
|
|
92
|
+
if (this.minCount > 0n) {
|
|
93
|
+
schema = code `${schema}.nonempty().min(${this.minCount})`;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
schema = code `${schema}.optional()`;
|
|
97
|
+
}
|
|
98
|
+
if (!this._mutable) {
|
|
99
|
+
schema = code `${schema}.readonly()`;
|
|
100
|
+
}
|
|
101
|
+
return schema;
|
|
102
|
+
}
|
|
28
103
|
jsonType() {
|
|
29
|
-
const name = code `${!this.mutable ? "readonly " : ""}(${this.itemType.jsonType().
|
|
104
|
+
const name = code `${!this.mutable ? "readonly " : ""}(${this.itemType.jsonType().expression})[]`;
|
|
30
105
|
if (this.minCount === 0n) {
|
|
31
106
|
return new AbstractCollectionType.JsonType(name, { optional: true });
|
|
32
107
|
}
|
|
@@ -41,6 +116,9 @@ export class SetType extends AbstractCollectionType {
|
|
|
41
116
|
return code `(${variables.value}.length > 0 ? \`[\${${variables.value}.map(item => (${this.itemType.toStringExpression({ variables: { value: code `item` } })}))}]\` : undefined)`;
|
|
42
117
|
}
|
|
43
118
|
}
|
|
119
|
+
__decorate([
|
|
120
|
+
Memoize()
|
|
121
|
+
], SetType.prototype, "conversionFunction", null);
|
|
44
122
|
__decorate([
|
|
45
123
|
Memoize()
|
|
46
124
|
], SetType.prototype, "valueSparqlConstructTriplesFunction", null);
|
|
@@ -69,7 +69,7 @@ export declare class Snippets {
|
|
|
69
69
|
get booleanEquals(): Snippet;
|
|
70
70
|
get booleanSparqlWherePatterns(): Snippet;
|
|
71
71
|
get compactRecord(): Snippet;
|
|
72
|
-
get
|
|
72
|
+
get convertToArraySet(): Snippet;
|
|
73
73
|
get convertToBlankNode(): Snippet;
|
|
74
74
|
get convertToBlankNodeIdentifierProperty(): Snippet;
|
|
75
75
|
get convertToIdentifier(): Snippet;
|
|
@@ -79,8 +79,10 @@ export declare class Snippets {
|
|
|
79
79
|
get convertToLazyObject(): Snippet;
|
|
80
80
|
get convertToLazyObjectOption(): Snippet;
|
|
81
81
|
get convertToLazyObjectSet(): Snippet;
|
|
82
|
+
get convertToList(): Snippet;
|
|
82
83
|
get convertToLiteral(): Snippet;
|
|
83
84
|
get convertToMaybe(): Snippet;
|
|
85
|
+
get convertToScalarSet(): Snippet;
|
|
84
86
|
get convertWithDefaultValue(): Snippet;
|
|
85
87
|
get dateEquals(): Snippet;
|
|
86
88
|
get dateSparqlWherePatterns(): Snippet;
|
|
@@ -23,7 +23,7 @@ import { snippets_CollectionFilter } from "./_snippets/snippets_CollectionFilter
|
|
|
23
23
|
import { snippets_CollectionSchema } from "./_snippets/snippets_CollectionSchema.js";
|
|
24
24
|
import { snippets_ConversionFunction } from "./_snippets/snippets_ConversionFunction.js";
|
|
25
25
|
import { snippets_compactRecord } from "./_snippets/snippets_compactRecord.js";
|
|
26
|
-
import {
|
|
26
|
+
import { snippets_convertToArraySet } from "./_snippets/snippets_convertToArraySet.js";
|
|
27
27
|
import { snippets_convertToBlankNode } from "./_snippets/snippets_convertToBlankNode.js";
|
|
28
28
|
import { snippets_convertToBlankNodeIdentifierProperty } from "./_snippets/snippets_convertToBlankNodeIdentifierProperty.js";
|
|
29
29
|
import { snippets_convertToIdentifier } from "./_snippets/snippets_convertToIdentifier.js";
|
|
@@ -33,8 +33,10 @@ import { snippets_convertToIriIdentifierProperty } from "./_snippets/snippets_co
|
|
|
33
33
|
import { snippets_convertToLazyObject } from "./_snippets/snippets_convertToLazyObject.js";
|
|
34
34
|
import { snippets_convertToLazyObjectOption } from "./_snippets/snippets_convertToLazyObjectOption.js";
|
|
35
35
|
import { snippets_convertToLazyObjectSet } from "./_snippets/snippets_convertToLazyObjectSet.js";
|
|
36
|
+
import { snippets_convertToList } from "./_snippets/snippets_convertToList.js";
|
|
36
37
|
import { snippets_convertToLiteral } from "./_snippets/snippets_convertToLiteral.js";
|
|
37
38
|
import { snippets_convertToMaybe } from "./_snippets/snippets_convertToMaybe.js";
|
|
39
|
+
import { snippets_convertToScalarSet } from "./_snippets/snippets_convertToScalarSet.js";
|
|
38
40
|
import { snippets_convertWithDefaultValue } from "./_snippets/snippets_convertWithDefaultValue.js";
|
|
39
41
|
import { snippets_DateFilter } from "./_snippets/snippets_DateFilter.js";
|
|
40
42
|
import { snippets_DateSchema } from "./_snippets/snippets_DateSchema.js";
|
|
@@ -326,8 +328,8 @@ export class Snippets {
|
|
|
326
328
|
get compactRecord() {
|
|
327
329
|
return this.snippet(snippets_compactRecord);
|
|
328
330
|
}
|
|
329
|
-
get
|
|
330
|
-
return this.snippet(
|
|
331
|
+
get convertToArraySet() {
|
|
332
|
+
return this.snippet(snippets_convertToArraySet);
|
|
331
333
|
}
|
|
332
334
|
get convertToBlankNode() {
|
|
333
335
|
return this.snippet(snippets_convertToBlankNode);
|
|
@@ -356,12 +358,18 @@ export class Snippets {
|
|
|
356
358
|
get convertToLazyObjectSet() {
|
|
357
359
|
return this.snippet(snippets_convertToLazyObjectSet);
|
|
358
360
|
}
|
|
361
|
+
get convertToList() {
|
|
362
|
+
return this.snippet(snippets_convertToList);
|
|
363
|
+
}
|
|
359
364
|
get convertToLiteral() {
|
|
360
365
|
return this.snippet(snippets_convertToLiteral);
|
|
361
366
|
}
|
|
362
367
|
get convertToMaybe() {
|
|
363
368
|
return this.snippet(snippets_convertToMaybe);
|
|
364
369
|
}
|
|
370
|
+
get convertToScalarSet() {
|
|
371
|
+
return this.snippet(snippets_convertToScalarSet);
|
|
372
|
+
}
|
|
365
373
|
get convertWithDefaultValue() {
|
|
366
374
|
return this.snippet(snippets_convertWithDefaultValue);
|
|
367
375
|
}
|
|
@@ -779,7 +787,7 @@ __decorate([
|
|
|
779
787
|
], Snippets.prototype, "compactRecord", null);
|
|
780
788
|
__decorate([
|
|
781
789
|
Memoize()
|
|
782
|
-
], Snippets.prototype, "
|
|
790
|
+
], Snippets.prototype, "convertToArraySet", null);
|
|
783
791
|
__decorate([
|
|
784
792
|
Memoize()
|
|
785
793
|
], Snippets.prototype, "convertToBlankNode", null);
|
|
@@ -807,12 +815,18 @@ __decorate([
|
|
|
807
815
|
__decorate([
|
|
808
816
|
Memoize()
|
|
809
817
|
], Snippets.prototype, "convertToLazyObjectSet", null);
|
|
818
|
+
__decorate([
|
|
819
|
+
Memoize()
|
|
820
|
+
], Snippets.prototype, "convertToList", null);
|
|
810
821
|
__decorate([
|
|
811
822
|
Memoize()
|
|
812
823
|
], Snippets.prototype, "convertToLiteral", null);
|
|
813
824
|
__decorate([
|
|
814
825
|
Memoize()
|
|
815
826
|
], Snippets.prototype, "convertToMaybe", null);
|
|
827
|
+
__decorate([
|
|
828
|
+
Memoize()
|
|
829
|
+
], Snippets.prototype, "convertToScalarSet", null);
|
|
816
830
|
__decorate([
|
|
817
831
|
Memoize()
|
|
818
832
|
], Snippets.prototype, "convertWithDefaultValue", null);
|
|
@@ -6,8 +6,10 @@ export declare class StringType extends AbstractPrimitiveType<string> {
|
|
|
6
6
|
readonly filterType: Code;
|
|
7
7
|
readonly graphqlType: import("./AbstractType.js").AbstractType.GraphqlType;
|
|
8
8
|
readonly hashFunction: Code;
|
|
9
|
+
readonly jsTypes: readonly [{
|
|
10
|
+
readonly typeof: "string";
|
|
11
|
+
}];
|
|
9
12
|
readonly kind = "String";
|
|
10
|
-
readonly typeofs: "string"[];
|
|
11
13
|
readonly valueSparqlWherePatternsFunction: Code;
|
|
12
14
|
get expression(): Code;
|
|
13
15
|
get schemaType(): Code;
|
|
@@ -13,8 +13,12 @@ export class StringType extends AbstractPrimitiveType {
|
|
|
13
13
|
filterType = code `${this.reusables.snippets.StringFilter}`;
|
|
14
14
|
graphqlType = new AbstractPrimitiveType.GraphqlType(code `${this.reusables.imports.GraphQLString}`, this.reusables);
|
|
15
15
|
hashFunction = code `${this.reusables.snippets.hashString}`;
|
|
16
|
+
jsTypes = [
|
|
17
|
+
{
|
|
18
|
+
typeof: "string",
|
|
19
|
+
},
|
|
20
|
+
];
|
|
16
21
|
kind = "String";
|
|
17
|
-
typeofs = ["string"];
|
|
18
22
|
valueSparqlWherePatternsFunction = code `${this.reusables.snippets.stringSparqlWherePatterns}`;
|
|
19
23
|
get expression() {
|
|
20
24
|
if (this.primitiveIn.length > 0) {
|
|
@@ -10,6 +10,10 @@ export declare class TermType<ConstantTermT extends Literal | NamedNode = Litera
|
|
|
10
10
|
readonly kind = "Term";
|
|
11
11
|
readonly nodeKinds: ReadonlySet<NodeKind>;
|
|
12
12
|
readonly schemaType: Code;
|
|
13
|
+
readonly jsTypes: readonly [{
|
|
14
|
+
readonly instanceof: "Object";
|
|
15
|
+
readonly typeof: "object";
|
|
16
|
+
}];
|
|
13
17
|
readonly valueSparqlWherePatternsFunction: Code;
|
|
14
18
|
constructor({ nodeKinds, ...superParameters }: ConstructorParameters<typeof AbstractTermType<ConstantTermT, RuntimeTermT>>[0] & {
|
|
15
19
|
nodeKinds: ReadonlySet<NodeKind>;
|
|
@@ -18,6 +18,9 @@ export class TermType extends AbstractTermType {
|
|
|
18
18
|
kind = "Term";
|
|
19
19
|
nodeKinds;
|
|
20
20
|
schemaType = code `${this.reusables.snippets.TermSchema}`;
|
|
21
|
+
jsTypes = [
|
|
22
|
+
{ instanceof: "Object", typeof: "object" },
|
|
23
|
+
];
|
|
21
24
|
valueSparqlWherePatternsFunction = code `${this.reusables.snippets.termSparqlWherePatterns}`;
|
|
22
25
|
constructor({ nodeKinds, ...superParameters }) {
|
|
23
26
|
super(superParameters);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Logger } from "ts-log";
|
|
2
|
-
import * as ast from "../../ast/index.js";
|
|
2
|
+
import type * as ast from "../../ast/index.js";
|
|
3
3
|
import type { Generator } from "../Generator.js";
|
|
4
4
|
import type { TsFeature } from "./TsFeature.js";
|
|
5
5
|
export declare class TsGenerator implements Generator {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Maybe } from "purify-ts";
|
|
2
2
|
import { invariant } from "ts-invariant";
|
|
3
|
-
import * as ast from "../../ast/index.js";
|
|
4
3
|
import { BlankNodeType } from "./BlankNodeType.js";
|
|
5
4
|
import { GraphqlSchema } from "./GraphqlSchema.js";
|
|
6
5
|
import { IdentifierType } from "./IdentifierType.js";
|
|
@@ -12,6 +11,9 @@ import { Reusables } from "./Reusables.js";
|
|
|
12
11
|
import { SparqlObjectSetType } from "./SparqlObjectSetType.js";
|
|
13
12
|
import { TypeFactory } from "./TypeFactory.js";
|
|
14
13
|
import { code, joinCode } from "./ts-poet-wrapper.js";
|
|
14
|
+
function compareTsNamedType(left, right) {
|
|
15
|
+
return left.alias.unsafeCoerce().localeCompare(right.alias.unsafeCoerce());
|
|
16
|
+
}
|
|
15
17
|
export class TsGenerator {
|
|
16
18
|
configuration;
|
|
17
19
|
logger;
|
|
@@ -31,54 +33,77 @@ export class TsGenerator {
|
|
|
31
33
|
reusables,
|
|
32
34
|
});
|
|
33
35
|
let declarations = [];
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
const tsNamedTypes = [];
|
|
37
|
+
const tsNamedObjectTypes = [];
|
|
38
|
+
const tsNamedObjectUnionTypes = [];
|
|
39
|
+
for (const astNamedType of ast_.namedTypes) {
|
|
40
|
+
const tsNamedType = typeFactory.createType(astNamedType);
|
|
41
|
+
tsNamedTypes.push(tsNamedType);
|
|
42
|
+
if (astNamedType.kind === "Object") {
|
|
43
|
+
for (const tsImport of astNamedType.tsImports) {
|
|
44
|
+
declarations.push(code `${tsImport}`);
|
|
45
|
+
}
|
|
37
46
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
47
|
+
switch (tsNamedType.kind) {
|
|
48
|
+
case "Object":
|
|
49
|
+
tsNamedObjectTypes.push(tsNamedType);
|
|
50
|
+
break;
|
|
51
|
+
case "ObjectUnion":
|
|
52
|
+
tsNamedObjectUnionTypes.push(tsNamedType);
|
|
53
|
+
break;
|
|
42
54
|
}
|
|
43
|
-
declarations = declarations.concat(typeFactory.createType(astNamedUnionType).declaration.toList());
|
|
44
55
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
56
|
+
tsNamedTypes.sort(compareTsNamedType);
|
|
57
|
+
tsNamedObjectTypes.sort(compareTsNamedType);
|
|
58
|
+
tsNamedObjectUnionTypes.sort(compareTsNamedType);
|
|
59
|
+
for (const tsNamedType of tsNamedTypes) {
|
|
60
|
+
switch (tsNamedType.kind) {
|
|
61
|
+
case "ObjectUnion":
|
|
62
|
+
case "Union":
|
|
63
|
+
continue; // Declare compound types last.
|
|
64
|
+
}
|
|
65
|
+
tsNamedType.declaration.ifJust((declaration) => {
|
|
66
|
+
declarations.push(declaration);
|
|
67
|
+
});
|
|
51
68
|
}
|
|
52
|
-
|
|
53
|
-
|
|
69
|
+
// Declare compound types last.
|
|
70
|
+
for (const tsNamedType of tsNamedTypes) {
|
|
71
|
+
switch (tsNamedType.kind) {
|
|
72
|
+
case "ObjectUnion":
|
|
73
|
+
case "Union":
|
|
74
|
+
break;
|
|
75
|
+
default:
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
tsNamedType.declaration.ifJust((declaration) => {
|
|
79
|
+
declarations.push(declaration);
|
|
80
|
+
});
|
|
54
81
|
}
|
|
55
|
-
|
|
56
|
-
const namedObjectUnionTypesNameSorted = namedObjectUnionTypesToposorted.toSorted((left, right) => left.alias.unsafeCoerce().localeCompare(right.alias.unsafeCoerce()));
|
|
57
|
-
switch (namedObjectTypesNameSorted.length) {
|
|
82
|
+
switch (tsNamedObjectTypes.length) {
|
|
58
83
|
case 0:
|
|
59
84
|
break;
|
|
60
85
|
case 1:
|
|
61
|
-
declarations.push(code `type ${configuration.syntheticNamePrefix}Object = ${
|
|
86
|
+
declarations.push(code `type ${configuration.syntheticNamePrefix}Object = ${tsNamedObjectTypes[0].expression};`);
|
|
62
87
|
break;
|
|
63
88
|
default: {
|
|
64
89
|
const uberObjectUnionType = this.synthesizeUberObjectUnionType({
|
|
65
90
|
configuration,
|
|
66
|
-
namedObjectTypes:
|
|
91
|
+
namedObjectTypes: tsNamedObjectTypes,
|
|
67
92
|
reusables,
|
|
68
93
|
});
|
|
69
94
|
declarations = declarations.concat(uberObjectUnionType.declaration.toList());
|
|
70
|
-
|
|
95
|
+
tsNamedObjectUnionTypes.push(uberObjectUnionType);
|
|
71
96
|
}
|
|
72
97
|
}
|
|
73
98
|
declarations.push(...this.objectSetTypeDeclarations({
|
|
74
99
|
configuration,
|
|
75
|
-
namedObjectTypes:
|
|
76
|
-
namedObjectUnionTypes:
|
|
100
|
+
namedObjectTypes: tsNamedObjectTypes,
|
|
101
|
+
namedObjectUnionTypes: tsNamedObjectUnionTypes,
|
|
77
102
|
reusables,
|
|
78
103
|
}));
|
|
79
104
|
if (configuration.features.has("GraphQL")) {
|
|
80
|
-
const graphqlNamedObjectTypes =
|
|
81
|
-
const graphqlNamedObjectUnionTypes =
|
|
105
|
+
const graphqlNamedObjectTypes = tsNamedObjectTypes.filter((tsNamedObjectType) => !tsNamedObjectType.synthetic);
|
|
106
|
+
const graphqlNamedObjectUnionTypes = tsNamedObjectUnionTypes.filter((tsNamedObjectUnionType) => !tsNamedObjectUnionType.synthetic);
|
|
82
107
|
if (graphqlNamedObjectTypes.length > 0) {
|
|
83
108
|
declarations.push(new GraphqlSchema({
|
|
84
109
|
configuration,
|
|
@@ -116,7 +141,7 @@ export class TsGenerator {
|
|
|
116
141
|
* Synthesize the $Object union.
|
|
117
142
|
*/
|
|
118
143
|
synthesizeUberObjectUnionType({ configuration, namedObjectTypes, reusables, }) {
|
|
119
|
-
const filteredNamedObjectTypes = namedObjectTypes.filter((namedObjectType) => !namedObjectType.extern);
|
|
144
|
+
const filteredNamedObjectTypes = namedObjectTypes.filter((namedObjectType) => !namedObjectType.extern && !namedObjectType.synthetic);
|
|
120
145
|
invariant(filteredNamedObjectTypes.length > 0);
|
|
121
146
|
const nodeKinds = filteredNamedObjectTypes.reduce((nodeKinds, namedObjectType) => {
|
|
122
147
|
for (const nodeKind of namedObjectType.identifierType.nodeKinds) {
|
|
@@ -49,38 +49,24 @@ export class TypeFactory {
|
|
|
49
49
|
return cachedObjectType;
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
+
const discriminantProperty = astType.name.map((name) => new ObjectType.DiscriminantProperty({
|
|
53
|
+
configuration: this.configuration,
|
|
54
|
+
logger: this.logger,
|
|
55
|
+
name: `${this.configuration.syntheticNamePrefix}type`,
|
|
56
|
+
objectType: { alias: astType.name },
|
|
57
|
+
reusables: this.reusables,
|
|
58
|
+
value: name,
|
|
59
|
+
}));
|
|
52
60
|
const identifierType = this.createIdentifierType(astType.identifierType);
|
|
53
61
|
const objectType = new ObjectType({
|
|
54
62
|
alias: astType.name.map((name) => this.tsName(name, { synthetic: astType.synthetic })),
|
|
63
|
+
discriminantProperty,
|
|
55
64
|
comment: astType.comment,
|
|
56
65
|
configuration: this.configuration,
|
|
57
66
|
extern: astType.extern,
|
|
58
67
|
fromRdfType: astType.fromRdfType,
|
|
59
68
|
identifierType,
|
|
60
69
|
label: astType.label,
|
|
61
|
-
lazyAncestorObjectTypes: () => astType.ancestorObjectTypes.map((astType) => this.createObjectType(astType)),
|
|
62
|
-
lazyChildObjectTypes: () => astType.childObjectTypes.map((astType) => this.createObjectType(astType)),
|
|
63
|
-
lazyDescendantObjectTypes: () => astType.descendantObjectTypes.map((astType) => this.createObjectType(astType)),
|
|
64
|
-
lazyDiscriminantProperty: (objectType) => {
|
|
65
|
-
// Discriminant property
|
|
66
|
-
const discriminantDescendantValues = new Set();
|
|
67
|
-
for (const descendantObjectType of objectType.descendantObjectTypes) {
|
|
68
|
-
discriminantDescendantValues.add(descendantObjectType.discriminantValue);
|
|
69
|
-
}
|
|
70
|
-
return new ObjectType.DiscriminantProperty({
|
|
71
|
-
configuration: this.configuration,
|
|
72
|
-
logger: this.logger,
|
|
73
|
-
name: `${this.configuration.syntheticNamePrefix}type`,
|
|
74
|
-
objectType,
|
|
75
|
-
reusables: this.reusables,
|
|
76
|
-
type: new ObjectType.DiscriminantProperty.Type({
|
|
77
|
-
descendantValues: [...discriminantDescendantValues].sort(),
|
|
78
|
-
mutable: false,
|
|
79
|
-
ownValues: [objectType.discriminantValue],
|
|
80
|
-
}),
|
|
81
|
-
});
|
|
82
|
-
},
|
|
83
|
-
lazyParentObjectTypes: () => astType.parentObjectTypes.map((astType) => this.createObjectType(astType)),
|
|
84
70
|
lazyProperties: (objectType) => {
|
|
85
71
|
const properties = astType.properties
|
|
86
72
|
.toSorted((left, right) => {
|
|
@@ -96,7 +82,9 @@ export class TypeFactory {
|
|
|
96
82
|
astObjectTypeProperty: astProperty,
|
|
97
83
|
objectType,
|
|
98
84
|
}));
|
|
99
|
-
|
|
85
|
+
discriminantProperty.ifJust((discriminantProperty) => {
|
|
86
|
+
properties.splice(0, 0, discriminantProperty);
|
|
87
|
+
});
|
|
100
88
|
properties.splice(0, 0, new ObjectType.IdentifierProperty({
|
|
101
89
|
configuration: this.configuration,
|
|
102
90
|
logger: this.logger,
|
|
@@ -297,7 +285,6 @@ export class TypeFactory {
|
|
|
297
285
|
itemType,
|
|
298
286
|
label: astType.label,
|
|
299
287
|
logger: this.logger,
|
|
300
|
-
minCount: 0n,
|
|
301
288
|
mutable: astType.mutable,
|
|
302
289
|
reusables: this.reusables,
|
|
303
290
|
toRdfTypes: astType.toRdfTypes,
|
|
@@ -38,7 +38,7 @@ export declare class UnionType<MemberTypeT extends Type> extends AbstractType {
|
|
|
38
38
|
get referencesObjectType(): boolean;
|
|
39
39
|
get schemaType(): Code;
|
|
40
40
|
get toRdfResourceValueTypes(): AbstractType["toRdfResourceValueTypes"];
|
|
41
|
-
get
|
|
41
|
+
get jsTypes(): AbstractType["jsTypes"];
|
|
42
42
|
get valueSparqlConstructTriplesFunction(): Code;
|
|
43
43
|
get valueSparqlWherePatternsFunction(): Code;
|
|
44
44
|
protected get inlineEqualsFunction(): Code;
|
|
@@ -84,17 +84,14 @@ type HybridDiscriminant = {
|
|
|
84
84
|
readonly kind: "Hybrid";
|
|
85
85
|
readonly memberValues: readonly {
|
|
86
86
|
readonly kind: "Extrinsic" | "Intrinsic";
|
|
87
|
-
readonly
|
|
87
|
+
readonly values: readonly AbstractType.DiscriminantProperty.Value[];
|
|
88
88
|
}[];
|
|
89
89
|
readonly name: string;
|
|
90
90
|
};
|
|
91
91
|
type IntrinsicDiscriminant = {
|
|
92
92
|
readonly jsonName: string;
|
|
93
93
|
readonly kind: "Intrinsic";
|
|
94
|
-
readonly memberValues: readonly
|
|
95
|
-
readonly descendantValues: readonly AbstractType.DiscriminantProperty.Value[];
|
|
96
|
-
readonly ownValues: readonly AbstractType.DiscriminantProperty.Value[];
|
|
97
|
-
}[];
|
|
94
|
+
readonly memberValues: readonly AbstractType.DiscriminantProperty.Value[];
|
|
98
95
|
readonly name: string;
|
|
99
96
|
};
|
|
100
97
|
type TypeofDiscriminant = {
|