@shaclmate/compiler 4.0.65 → 4.0.66
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/generators/ts/DiscriminatedUnionType.d.ts +1 -2
- package/dist/generators/ts/DiscriminatedUnionType.js +1 -3
- package/dist/generators/ts/TsGenerator.d.ts +0 -4
- package/dist/generators/ts/TsGenerator.js +8 -93
- package/dist/generators/ts/_ObjectDiscriminatedUnionType/ObjectDiscriminatedUnionType_graphqlTypeVariableStatement.js +0 -3
- package/dist/generators/ts/_ObjectDiscriminatedUnionType/ObjectDiscriminatedUnionType_typeGuardFunctionDeclaration.js +0 -3
- package/dist/input/input.shaclmate.d.ts +37 -1315
- package/dist/input/input.shaclmate.js +41 -170
- package/package.json +8 -8
|
@@ -12,9 +12,8 @@ export declare class DiscriminatedUnionType<MemberTypeT extends Type> extends Ab
|
|
|
12
12
|
readonly identifierType: Maybe<BlankNodeType | IdentifierType | IriType>;
|
|
13
13
|
readonly kind: "ObjectDiscriminatedUnion" | "DiscriminatedUnion";
|
|
14
14
|
readonly recursive: boolean;
|
|
15
|
-
readonly synthetic: boolean;
|
|
16
15
|
readonly validationFunction: Maybe<Code>;
|
|
17
|
-
constructor({ identifierType, members, recursive,
|
|
16
|
+
constructor({ identifierType, members, recursive, ...superParameters }: {
|
|
18
17
|
identifierType: Maybe<BlankNodeType | IdentifierType | IriType>;
|
|
19
18
|
members: readonly (Pick<DiscriminatedUnionType.Member<MemberTypeT>, "type"> & {
|
|
20
19
|
readonly discriminantValue: Maybe<number | string>;
|
|
@@ -31,15 +31,13 @@ export class DiscriminatedUnionType extends AbstractType {
|
|
|
31
31
|
identifierType;
|
|
32
32
|
kind = "DiscriminatedUnion";
|
|
33
33
|
recursive;
|
|
34
|
-
synthetic;
|
|
35
34
|
validationFunction = Maybe.empty();
|
|
36
|
-
constructor({ identifierType, members, recursive,
|
|
35
|
+
constructor({ identifierType, members, recursive, ...superParameters }) {
|
|
37
36
|
super(superParameters);
|
|
38
37
|
this.identifierType = identifierType;
|
|
39
38
|
invariant(members.length >= 2);
|
|
40
39
|
this.recursive = recursive;
|
|
41
40
|
this.discriminant = DiscriminatedUnionType_inferDiscriminant.call(this, members);
|
|
42
|
-
this.synthetic = synthetic;
|
|
43
41
|
this.lazyMembers = () => members.map((member, memberI) => {
|
|
44
42
|
let discriminantValues;
|
|
45
43
|
switch (this.discriminant.kind) {
|
|
@@ -11,10 +11,6 @@ export declare class TsGenerator implements Generator {
|
|
|
11
11
|
});
|
|
12
12
|
generate(ast_: ast.Ast): string;
|
|
13
13
|
private objectSetTypeDeclarations;
|
|
14
|
-
/**
|
|
15
|
-
* Synthesize the $Object union.
|
|
16
|
-
*/
|
|
17
|
-
private synthesizeUberObjectDiscriminatedUnionType;
|
|
18
14
|
}
|
|
19
15
|
export declare namespace TsGenerator {
|
|
20
16
|
interface Configuration {
|
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
import dataFactory from "@rdfx/data-factory";
|
|
2
|
-
import { Maybe } from "purify-ts";
|
|
3
|
-
import { invariant } from "ts-invariant";
|
|
4
|
-
import { BlankNodeType } from "./BlankNodeType.js";
|
|
5
1
|
import { GraphqlSchema } from "./GraphqlSchema.js";
|
|
6
|
-
import { IdentifierType } from "./IdentifierType.js";
|
|
7
|
-
import { IriType } from "./IriType.js";
|
|
8
|
-
import { ObjectDiscriminatedUnionType } from "./ObjectDiscriminatedUnionType.js";
|
|
9
2
|
import { ObjectSetType } from "./ObjectSetType.js";
|
|
10
3
|
import { RdfjsDatasetObjectSetType } from "./RdfjsDatasetObjectSetType.js";
|
|
11
4
|
import { Reusables } from "./Reusables.js";
|
|
12
5
|
import { SparqlObjectSetType } from "./SparqlObjectSetType.js";
|
|
13
6
|
import { TypeFactory } from "./TypeFactory.js";
|
|
14
7
|
import { code, joinCode } from "./ts-poet-wrapper.js";
|
|
8
|
+
import { UberObjectDiscriminatedUnionType } from "./UberObjectDiscriminatedUnionType.js";
|
|
15
9
|
function compareTsNamedType(left, right) {
|
|
16
10
|
return left.name.unsafeCoerce().localeCompare(right.name.unsafeCoerce());
|
|
17
11
|
}
|
|
@@ -80,22 +74,12 @@ export class TsGenerator {
|
|
|
80
74
|
declarations.push(declaration);
|
|
81
75
|
});
|
|
82
76
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
default: {
|
|
90
|
-
const uberObjectDiscriminatedUnionType = this.synthesizeUberObjectDiscriminatedUnionType({
|
|
91
|
-
configuration,
|
|
92
|
-
namedObjectTypes: tsNamedObjectTypes,
|
|
93
|
-
reusables,
|
|
94
|
-
});
|
|
95
|
-
declarations = declarations.concat(uberObjectDiscriminatedUnionType.declaration.toList());
|
|
96
|
-
tsNamedObjectDiscriminatedUnionTypes.push(uberObjectDiscriminatedUnionType);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
77
|
+
declarations = declarations.concat(new UberObjectDiscriminatedUnionType({
|
|
78
|
+
configuration,
|
|
79
|
+
logger: this.logger,
|
|
80
|
+
members: tsNamedObjectTypes,
|
|
81
|
+
reusables,
|
|
82
|
+
}).declaration.toList());
|
|
99
83
|
declarations.push(...this.objectSetTypeDeclarations({
|
|
100
84
|
configuration,
|
|
101
85
|
namedObjectTypes: tsNamedObjectTypes,
|
|
@@ -104,7 +88,7 @@ export class TsGenerator {
|
|
|
104
88
|
}));
|
|
105
89
|
if (configuration.features.has("GraphQL")) {
|
|
106
90
|
const graphqlNamedObjectTypes = tsNamedObjectTypes.filter((tsNamedObjectType) => !tsNamedObjectType.synthetic);
|
|
107
|
-
const graphqlNamedObjectDiscriminatedUnionTypes = tsNamedObjectDiscriminatedUnionTypes
|
|
91
|
+
const graphqlNamedObjectDiscriminatedUnionTypes = tsNamedObjectDiscriminatedUnionTypes;
|
|
108
92
|
if (graphqlNamedObjectTypes.length > 0) {
|
|
109
93
|
declarations.push(new GraphqlSchema({
|
|
110
94
|
configuration,
|
|
@@ -138,75 +122,6 @@ export class TsGenerator {
|
|
|
138
122
|
}
|
|
139
123
|
return declarations;
|
|
140
124
|
}
|
|
141
|
-
/**
|
|
142
|
-
* Synthesize the $Object union.
|
|
143
|
-
*/
|
|
144
|
-
synthesizeUberObjectDiscriminatedUnionType({ configuration, namedObjectTypes, reusables, }) {
|
|
145
|
-
const filteredNamedObjectTypes = namedObjectTypes.filter((namedObjectType) => !namedObjectType.extern);
|
|
146
|
-
invariant(filteredNamedObjectTypes.length > 0);
|
|
147
|
-
const nodeKinds = filteredNamedObjectTypes.reduce((nodeKinds, namedObjectType) => {
|
|
148
|
-
for (const nodeKind of namedObjectType.identifierType.nodeKinds) {
|
|
149
|
-
nodeKinds.add(nodeKind);
|
|
150
|
-
}
|
|
151
|
-
return nodeKinds;
|
|
152
|
-
}, new Set());
|
|
153
|
-
let identifierType;
|
|
154
|
-
if (nodeKinds.size === 2) {
|
|
155
|
-
identifierType = new IdentifierType({
|
|
156
|
-
name: Maybe.empty(),
|
|
157
|
-
comment: Maybe.empty(),
|
|
158
|
-
configuration,
|
|
159
|
-
label: Maybe.empty(),
|
|
160
|
-
logger: this.logger,
|
|
161
|
-
reusables,
|
|
162
|
-
shapeIdentifier: dataFactory.blankNode(),
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
switch ([...nodeKinds][0]) {
|
|
167
|
-
case "BlankNode":
|
|
168
|
-
identifierType = new BlankNodeType({
|
|
169
|
-
name: Maybe.empty(),
|
|
170
|
-
comment: Maybe.empty(),
|
|
171
|
-
configuration,
|
|
172
|
-
label: Maybe.empty(),
|
|
173
|
-
logger: this.logger,
|
|
174
|
-
reusables,
|
|
175
|
-
shapeIdentifier: dataFactory.blankNode(),
|
|
176
|
-
});
|
|
177
|
-
break;
|
|
178
|
-
case "IRI":
|
|
179
|
-
identifierType = new IriType({
|
|
180
|
-
name: Maybe.empty(),
|
|
181
|
-
comment: Maybe.empty(),
|
|
182
|
-
configuration,
|
|
183
|
-
hasValues: [],
|
|
184
|
-
in_: [],
|
|
185
|
-
label: Maybe.empty(),
|
|
186
|
-
logger: this.logger,
|
|
187
|
-
reusables,
|
|
188
|
-
shapeIdentifier: dataFactory.blankNode(),
|
|
189
|
-
});
|
|
190
|
-
break;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
return new ObjectDiscriminatedUnionType({
|
|
194
|
-
name: Maybe.of(`${configuration.syntheticNamePrefix}Object`),
|
|
195
|
-
comment: Maybe.empty(),
|
|
196
|
-
configuration,
|
|
197
|
-
identifierType: Maybe.of(identifierType),
|
|
198
|
-
label: Maybe.empty(),
|
|
199
|
-
logger: this.logger,
|
|
200
|
-
members: filteredNamedObjectTypes.map((namedObjectType) => ({
|
|
201
|
-
discriminantValue: Maybe.empty(),
|
|
202
|
-
type: namedObjectType,
|
|
203
|
-
})),
|
|
204
|
-
recursive: false,
|
|
205
|
-
reusables,
|
|
206
|
-
shapeIdentifier: dataFactory.blankNode(),
|
|
207
|
-
synthetic: true,
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
125
|
}
|
|
211
126
|
(function (TsGenerator) {
|
|
212
127
|
let Configuration;
|
|
@@ -4,9 +4,6 @@ export function ObjectDiscriminatedUnionType_graphqlTypeVariableStatement() {
|
|
|
4
4
|
if (!this.configuration.features.has("GraphQL")) {
|
|
5
5
|
return {};
|
|
6
6
|
}
|
|
7
|
-
if (this.synthetic) {
|
|
8
|
-
return {};
|
|
9
|
-
}
|
|
10
7
|
const name = this.name.unsafeCoerce();
|
|
11
8
|
return singleEntryRecord(`GraphQL`, code `\
|
|
12
9
|
export const GraphQL = new ${this.reusables.imports.GraphQLUnionType}(${{
|
|
@@ -8,9 +8,6 @@ export function ObjectDiscriminatedUnionType_typeGuardFunctionDeclaration() {
|
|
|
8
8
|
if (!name) {
|
|
9
9
|
return {};
|
|
10
10
|
}
|
|
11
|
-
if (name === `${this.configuration.syntheticNamePrefix}Object`) {
|
|
12
|
-
return {};
|
|
13
|
-
}
|
|
14
11
|
return singleEntryRecord(`is${name}`, code `\
|
|
15
12
|
export function is${name}(object: ${this.configuration.syntheticNamePrefix}Object): object is ${name} {
|
|
16
13
|
return ${joinCode(this.members.map((member) => code `${member.type.name.unsafeCoerce()}.is${member.type.name.unsafeCoerce()}(object)`), { on: " || " })};
|