@shaclmate/compiler 2.0.23 → 2.0.24
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 +5 -5
- package/dist/ShapesGraphToAstTransformer.js +5 -5
- package/dist/_ShapesGraphToAstTransformer/InheritableShapeConstraints.d.ts +2 -0
- package/dist/_ShapesGraphToAstTransformer/InheritableShapeConstraints.js +2 -0
- package/dist/_ShapesGraphToAstTransformer/ShapeStack.d.ts +15 -0
- package/dist/_ShapesGraphToAstTransformer/ShapeStack.js +51 -0
- package/dist/_ShapesGraphToAstTransformer/index.d.ts +5 -5
- package/dist/_ShapesGraphToAstTransformer/index.js +5 -5
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +77 -29
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompositeType.d.ts +10 -0
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompositeType.js +185 -0
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstIdentifierType.d.ts +10 -0
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstIdentifierType.js +32 -0
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstLiteralType.d.ts +10 -0
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstLiteralType.js +46 -0
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstTermType.d.ts +12 -0
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstTermType.js +24 -0
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstType.d.ts +13 -0
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstType.js +14 -0
- package/dist/ast/OptionType.d.ts +0 -2
- package/dist/ast/SetType.d.ts +1 -6
- package/dist/ast/index.d.ts +1 -0
- package/dist/ast/index.js +1 -0
- package/dist/generators/json/AstJsonGenerator.js +7 -1
- package/dist/generators/ts/BooleanType.d.ts +1 -1
- package/dist/generators/ts/BooleanType.js +1 -1
- package/dist/generators/ts/DateTimeType.d.ts +1 -1
- package/dist/generators/ts/DateTimeType.js +1 -1
- package/dist/generators/ts/IdentifierType.d.ts +6 -1
- package/dist/generators/ts/IdentifierType.js +20 -14
- package/dist/generators/ts/ListType.js +16 -5
- package/dist/generators/ts/LiteralType.d.ts +9 -2
- package/dist/generators/ts/LiteralType.js +79 -15
- package/dist/generators/ts/NumberType.d.ts +1 -1
- package/dist/generators/ts/NumberType.js +1 -1
- package/dist/generators/ts/ObjectType.d.ts +1 -2
- package/dist/generators/ts/ObjectType.js +4 -5
- package/dist/generators/ts/ObjectUnionType.d.ts +1 -0
- package/dist/generators/ts/ObjectUnionType.js +18 -9
- package/dist/generators/ts/OptionType.d.ts +1 -1
- package/dist/generators/ts/OptionType.js +6 -4
- package/dist/generators/ts/PrimitiveType.d.ts +19 -1
- package/dist/generators/ts/PrimitiveType.js +16 -3
- package/dist/generators/ts/SetType.d.ts +4 -4
- package/dist/generators/ts/SetType.js +15 -12
- package/dist/generators/ts/SnippetDeclarations.d.ts +1 -1
- package/dist/generators/ts/SnippetDeclarations.js +13 -2
- package/dist/generators/ts/StringType.d.ts +1 -1
- package/dist/generators/ts/StringType.js +8 -8
- package/dist/generators/ts/TermType.d.ts +7 -19
- package/dist/generators/ts/TermType.js +44 -51
- package/dist/generators/ts/TsGenerator.js +4 -1
- package/dist/generators/ts/Type.d.ts +12 -2
- package/dist/generators/ts/Type.js +1 -0
- package/dist/generators/ts/TypeFactory.d.ts +8 -0
- package/dist/generators/ts/TypeFactory.js +112 -22
- package/dist/generators/ts/UnionType.js +1 -1
- package/dist/generators/ts/_ObjectType/EagerShaclProperty.js +3 -2
- package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.d.ts +1 -1
- package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.js +15 -1
- package/dist/generators/ts/_ObjectType/IdentifierProperty.d.ts +6 -6
- package/dist/generators/ts/_ObjectType/IdentifierProperty.js +59 -29
- package/dist/generators/ts/_ObjectType/LazyShaclProperty.d.ts +14 -1
- package/dist/generators/ts/_ObjectType/LazyShaclProperty.js +89 -11
- package/dist/generators/ts/_ObjectType/Property.d.ts +9 -3
- package/dist/generators/ts/_ObjectType/ShaclProperty.d.ts +1 -1
- package/dist/generators/ts/_ObjectType/ShaclProperty.js +14 -2
- package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +1 -1
- package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +1 -1
- package/dist/generators/ts/_ObjectType/classDeclaration.js +16 -12
- package/dist/generators/ts/_ObjectType/createFunctionDeclaration.js +22 -10
- package/dist/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.js +3 -1
- package/dist/generators/ts/_ObjectType/graphqlTypeVariableStatement.js +14 -2
- package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.js +71 -79
- package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.js +3 -3
- package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +6 -2
- package/dist/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.js +19 -12
- package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +5 -5
- package/dist/generators/ts/sparqlObjectSetClassDeclaration.js +6 -6
- package/dist/input/PropertyPath.d.ts +1 -2
- package/dist/input/PropertyPath.js +6 -8
- package/dist/input/ShapesGraph.js +4 -8
- package/dist/input/generated.d.ts +96 -54
- package/dist/input/generated.js +1350 -744
- package/package.json +5 -5
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.d.ts +0 -12
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +0 -193
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.d.ts +0 -12
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.js +0 -29
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.d.ts +0 -12
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.js +0 -43
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.d.ts +0 -14
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.js +0 -21
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.d.ts +0 -15
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.js +0 -60
|
@@ -7,23 +7,39 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
import { Maybe } from "purify-ts";
|
|
8
8
|
import "ts-morph";
|
|
9
9
|
import { Memoize } from "typescript-memoize";
|
|
10
|
+
import { invariant } from "ts-invariant";
|
|
10
11
|
import { Import } from "../Import.js";
|
|
11
12
|
import { SnippetDeclarations } from "../SnippetDeclarations.js";
|
|
12
13
|
import { Type as _Type } from "../Type.js";
|
|
13
14
|
import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
|
|
14
15
|
import { ShaclProperty } from "./ShaclProperty.js";
|
|
16
|
+
function stubObjectUnionTypeToResolvedObjectUnionTypeSwitchStatement({ resolvedObjectUnionType, stubObjectUnionType, variables, }) {
|
|
17
|
+
invariant(resolvedObjectUnionType.memberTypes.length ===
|
|
18
|
+
stubObjectUnionType.memberTypes.length);
|
|
19
|
+
const caseBlocks = resolvedObjectUnionType.memberTypes.map((resolvedObjectType, objectTypeI) => {
|
|
20
|
+
return `${resolvedObjectType.discriminatorPropertyValues.map((discriminatorPropertyValue) => `case "${discriminatorPropertyValue}":`).join("\n")} return ${stubObjectUnionType.memberTypes[objectTypeI].newExpression({ parameters: variables.value })};`;
|
|
21
|
+
});
|
|
22
|
+
caseBlocks.push(`default: ${variables.value} satisfies never; throw new Error("unrecognized type");`);
|
|
23
|
+
return `switch (${variables.value}.${resolvedObjectUnionType.discriminatorProperty.unsafeCoerce().name}) { ${caseBlocks.join("\n")} }`;
|
|
24
|
+
}
|
|
15
25
|
export class LazyShaclProperty extends ShaclProperty {
|
|
16
26
|
mutable = false;
|
|
17
27
|
recursive = false;
|
|
18
28
|
get graphqlField() {
|
|
29
|
+
const args = this.type.graphqlArgs;
|
|
30
|
+
const argsVariable = args.isJust() ? "args" : "_args";
|
|
19
31
|
return Maybe.of({
|
|
20
|
-
|
|
32
|
+
args,
|
|
33
|
+
description: this.comment.map(JSON.stringify),
|
|
21
34
|
name: this.name,
|
|
22
|
-
resolve: `async (source) => ${this.type.graphqlResolveExpression({ variables: { value: `source.${this.name}` } })}`,
|
|
35
|
+
resolve: `async (source, ${argsVariable}) => ${this.type.graphqlResolveExpression({ variables: { args: argsVariable, value: `source.${this.name}` } })}`,
|
|
23
36
|
type: this.type.graphqlName.toString(),
|
|
24
37
|
});
|
|
25
38
|
}
|
|
26
39
|
}
|
|
40
|
+
__decorate([
|
|
41
|
+
Memoize()
|
|
42
|
+
], LazyShaclProperty.prototype, "graphqlField", null);
|
|
27
43
|
(function (LazyShaclProperty) {
|
|
28
44
|
class Type extends _Type {
|
|
29
45
|
discriminatorProperty = Maybe.empty();
|
|
@@ -53,9 +69,6 @@ export class LazyShaclProperty extends ShaclProperty {
|
|
|
53
69
|
get graphqlName() {
|
|
54
70
|
return this.resolvedType.graphqlName;
|
|
55
71
|
}
|
|
56
|
-
graphqlResolveExpression({ variables, }) {
|
|
57
|
-
return `(await ${variables.value}.resolve()).unsafeCoerce()`;
|
|
58
|
-
}
|
|
59
72
|
hashStatements({ depth, variables, }) {
|
|
60
73
|
return this.stubType.hashStatements({
|
|
61
74
|
depth: depth + 1,
|
|
@@ -129,7 +142,17 @@ export class LazyShaclProperty extends ShaclProperty {
|
|
|
129
142
|
const conversions = super.conversions.concat();
|
|
130
143
|
if (this.stubType.itemType.kind === "ObjectType") {
|
|
131
144
|
conversions.push({
|
|
132
|
-
conversionExpression: (value) => `new ${this.runtimeClass.name}({ ${this.runtimeClass.stubPropertyName}: ${value}.map(
|
|
145
|
+
conversionExpression: (value) => `new ${this.runtimeClass.name}({ ${this.runtimeClass.stubPropertyName}: ${value}.map(object => ${this.stubType.itemType.newExpression({ parameters: "object" })}), resolver: async () => purify.Either.of(${value} as readonly ${this.resolvedType.itemType.name}[]) })`,
|
|
146
|
+
sourceTypeCheckExpression: (value) => `typeof ${value} === "object"`,
|
|
147
|
+
sourceTypeName: `readonly ${this.resolvedType.itemType.name}[]`,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
else if (this.resolvedType.itemType.kind === "ObjectUnionType" &&
|
|
151
|
+
this.stubType.itemType.kind === "ObjectUnionType" &&
|
|
152
|
+
this.resolvedType.itemType.memberTypes.length ===
|
|
153
|
+
this.stubType.itemType.memberTypes.length) {
|
|
154
|
+
conversions.push({
|
|
155
|
+
conversionExpression: (value) => `new ${this.runtimeClass.name}({ ${this.runtimeClass.stubPropertyName}: ${value}.map(object => { ${stubObjectUnionTypeToResolvedObjectUnionTypeSwitchStatement({ resolvedObjectUnionType: this.resolvedType.itemType, stubObjectUnionType: this.stubType.itemType, variables: { value: "object" } })} }), resolver: async () => purify.Either.of(${value} as readonly ${this.resolvedType.itemType.name}[]) })`,
|
|
133
156
|
sourceTypeCheckExpression: (value) => `typeof ${value} === "object"`,
|
|
134
157
|
sourceTypeName: `readonly ${this.resolvedType.itemType.name}[]`,
|
|
135
158
|
});
|
|
@@ -146,17 +169,39 @@ export class LazyShaclProperty extends ShaclProperty {
|
|
|
146
169
|
}
|
|
147
170
|
fromRdfExpression(parameters) {
|
|
148
171
|
const { variables } = parameters;
|
|
149
|
-
return `${this.stubType.fromRdfExpression(parameters)}.map(${this.runtimeClass.stubPropertyName} => new ${this.runtimeClass.name}({ ${this.runtimeClass.stubPropertyName}, resolver: (identifiers) => ${variables.objectSet}.${this.resolvedType.itemType.objectSetMethodNames.objects}({ where: { identifiers, type: "identifiers" }}) }))`;
|
|
172
|
+
return `${this.stubType.fromRdfExpression(parameters)}.map(values => values.map(${this.runtimeClass.stubPropertyName} => new ${this.runtimeClass.name}({ ${this.runtimeClass.stubPropertyName}, resolver: (identifiers) => ${variables.objectSet}.${this.resolvedType.itemType.objectSetMethodNames.objects}({ where: { identifiers, type: "identifiers" }}) })))`;
|
|
173
|
+
}
|
|
174
|
+
get graphqlArgs() {
|
|
175
|
+
return Maybe.of({
|
|
176
|
+
limit: {
|
|
177
|
+
type: "graphql.GraphQLInt",
|
|
178
|
+
},
|
|
179
|
+
offset: {
|
|
180
|
+
type: "graphql.GraphQLInt",
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
graphqlResolveExpression({ variables, }) {
|
|
185
|
+
return `(await ${variables.value}.resolve({ limit: ${variables.args}.limit, offset: ${variables.args}.offset })).unsafeCoerce()`;
|
|
150
186
|
}
|
|
151
187
|
}
|
|
152
188
|
__decorate([
|
|
153
189
|
Memoize()
|
|
154
190
|
], ObjectSetType.prototype, "conversions", null);
|
|
191
|
+
__decorate([
|
|
192
|
+
Memoize()
|
|
193
|
+
], ObjectSetType.prototype, "graphqlArgs", null);
|
|
155
194
|
LazyShaclProperty.ObjectSetType = ObjectSetType;
|
|
156
195
|
class SingleObjectType extends Type {
|
|
157
196
|
fromJsonExpression(parameters) {
|
|
158
197
|
return `new ${this.runtimeClass.name}({ ${this.runtimeClass.stubPropertyName}: ${this.stubType.fromJsonExpression(parameters)}, resolver: (identifier) => Promise.resolve(purify.Left(new Error(\`unable to resolve identifier \${rdfjsResource.Resource.Identifier.toString(identifier)} deserialized from JSON\`))) })`;
|
|
159
198
|
}
|
|
199
|
+
get graphqlArgs() {
|
|
200
|
+
return Maybe.empty();
|
|
201
|
+
}
|
|
202
|
+
graphqlResolveExpression({ variables, }) {
|
|
203
|
+
return `(await ${variables.value}.resolve()).unsafeCoerce()`;
|
|
204
|
+
}
|
|
160
205
|
}
|
|
161
206
|
class OptionalObjectType extends SingleObjectType {
|
|
162
207
|
constructor({ resolvedType, stubType, }) {
|
|
@@ -175,11 +220,30 @@ export class LazyShaclProperty extends ShaclProperty {
|
|
|
175
220
|
const conversions = super.conversions.concat();
|
|
176
221
|
if (this.stubType.itemType.kind === "ObjectType") {
|
|
177
222
|
conversions.push({
|
|
178
|
-
conversionExpression: (value) => `new ${this.runtimeClass.name}({ ${this.runtimeClass.stubPropertyName}: ${value}.map(
|
|
223
|
+
conversionExpression: (value) => `new ${this.runtimeClass.name}({ ${this.runtimeClass.stubPropertyName}: ${value}.map(object => ${this.stubType.itemType.newExpression({ parameters: "object" })}), resolver: async () => purify.Either.of((${value} as purify.Maybe<${this.resolvedType.itemType.name}>).unsafeCoerce()) })`,
|
|
179
224
|
sourceTypeCheckExpression: (value) => `purify.Maybe.isMaybe(${value})`,
|
|
180
225
|
sourceTypeName: `purify.Maybe<${this.resolvedType.itemType.name}>`,
|
|
181
226
|
}, {
|
|
182
227
|
conversionExpression: (value) => `new ${this.runtimeClass.name}({ ${this.runtimeClass.stubPropertyName}: purify.Maybe.of(${this.stubType.itemType.newExpression({ parameters: value })}), resolver: async () => purify.Either.of(${value} as ${this.resolvedType.itemType.name}) })`,
|
|
228
|
+
// Don't check instanceof value since the ObjectUnionType may be an interface
|
|
229
|
+
// Rely on the fact that this will be the last type check on an object
|
|
230
|
+
sourceTypeCheckExpression: (value) => `typeof ${value} === "object"`,
|
|
231
|
+
sourceTypeName: this.resolvedType.itemType.name,
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
else if (this.resolvedType.itemType.kind === "ObjectUnionType" &&
|
|
235
|
+
this.stubType.itemType.kind === "ObjectUnionType" &&
|
|
236
|
+
this.resolvedType.itemType.memberTypes.length ===
|
|
237
|
+
this.stubType.itemType.memberTypes.length) {
|
|
238
|
+
const maybeMap = `.map(object => { ${stubObjectUnionTypeToResolvedObjectUnionTypeSwitchStatement({ resolvedObjectUnionType: this.resolvedType.itemType, stubObjectUnionType: this.stubType.itemType, variables: { value: "object" } })} })`;
|
|
239
|
+
conversions.push({
|
|
240
|
+
conversionExpression: (value) => `new ${this.runtimeClass.name}({ ${this.runtimeClass.stubPropertyName}: ${value}${maybeMap}, resolver: async () => purify.Either.of((${value} as purify.Maybe<${this.resolvedType.itemType.name}>).unsafeCoerce()) })`,
|
|
241
|
+
sourceTypeCheckExpression: (value) => `purify.Maybe.isMaybe(${value})`,
|
|
242
|
+
sourceTypeName: `purify.Maybe<${this.resolvedType.itemType.name}>`,
|
|
243
|
+
}, {
|
|
244
|
+
conversionExpression: (value) => `new ${this.runtimeClass.name}({ ${this.runtimeClass.stubPropertyName}: purify.Maybe.of(${value})${maybeMap}, resolver: async () => purify.Either.of(${value} as ${this.resolvedType.itemType.name}) })`,
|
|
245
|
+
// Don't check instanceof value since the ObjectUnionType may be an interface
|
|
246
|
+
// Rely on the fact that this will be the last type check on an object
|
|
183
247
|
sourceTypeCheckExpression: (value) => `typeof ${value} === "object"`,
|
|
184
248
|
sourceTypeName: this.resolvedType.itemType.name,
|
|
185
249
|
});
|
|
@@ -193,7 +257,7 @@ export class LazyShaclProperty extends ShaclProperty {
|
|
|
193
257
|
}
|
|
194
258
|
fromRdfExpression(parameters) {
|
|
195
259
|
const { variables } = parameters;
|
|
196
|
-
return `${this.stubType.fromRdfExpression(parameters)}.map(${this.runtimeClass.stubPropertyName} => new ${this.runtimeClass.name}({ ${this.runtimeClass.stubPropertyName}, resolver: (identifier) => ${variables.objectSet}.${this.resolvedType.itemType.objectSetMethodNames.object}(identifier) }))`;
|
|
260
|
+
return `${this.stubType.fromRdfExpression(parameters)}.map(values => values.map(${this.runtimeClass.stubPropertyName} => new ${this.runtimeClass.name}({ ${this.runtimeClass.stubPropertyName}, resolver: (identifier) => ${variables.objectSet}.${this.resolvedType.itemType.objectSetMethodNames.object}(identifier) })))`;
|
|
197
261
|
}
|
|
198
262
|
graphqlResolveExpression(parameters) {
|
|
199
263
|
return `${super.graphqlResolveExpression(parameters)}.extractNullable()`;
|
|
@@ -221,7 +285,21 @@ export class LazyShaclProperty extends ShaclProperty {
|
|
|
221
285
|
if (this.stubType.kind === "ObjectType") {
|
|
222
286
|
conversions.push({
|
|
223
287
|
conversionExpression: (value) => `new ${this.runtimeClass.name}({ ${this.runtimeClass.stubPropertyName}: ${this.stubType.newExpression({ parameters: value })}, resolver: async () => purify.Either.of(${value} as ${this.resolvedType.name}) })`,
|
|
224
|
-
|
|
288
|
+
// Don't check instanceof value since the ObjectType may be an interface
|
|
289
|
+
// Rely on the fact that this will be the last type check on an object
|
|
290
|
+
sourceTypeCheckExpression: (value) => `typeof ${value} === "object"`,
|
|
291
|
+
sourceTypeName: this.resolvedType.name,
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
else if (this.resolvedType.kind === "ObjectUnionType" &&
|
|
295
|
+
this.stubType.kind === "ObjectUnionType" &&
|
|
296
|
+
this.resolvedType.memberTypes.length ===
|
|
297
|
+
this.stubType.memberTypes.length) {
|
|
298
|
+
conversions.push({
|
|
299
|
+
conversionExpression: (value) => `new ${this.runtimeClass.name}({ ${this.runtimeClass.stubPropertyName}: ((object: ${this.resolvedType.name}) => { ${stubObjectUnionTypeToResolvedObjectUnionTypeSwitchStatement({ resolvedObjectUnionType: this.resolvedType, stubObjectUnionType: this.stubType, variables: { value: "object" } })} })(${value}), resolver: async () => purify.Either.of(${value} as ${this.resolvedType.name}) })`,
|
|
300
|
+
// Don't check instanceof value since the ObjectUnionType may be an interface
|
|
301
|
+
// Rely on the fact that this will be the last type check on an object
|
|
302
|
+
sourceTypeCheckExpression: (value) => `typeof ${value} === "object"`,
|
|
225
303
|
sourceTypeName: this.resolvedType.name,
|
|
226
304
|
});
|
|
227
305
|
}
|
|
@@ -229,7 +307,7 @@ export class LazyShaclProperty extends ShaclProperty {
|
|
|
229
307
|
}
|
|
230
308
|
fromRdfExpression(parameters) {
|
|
231
309
|
const { variables } = parameters;
|
|
232
|
-
return `${this.stubType.fromRdfExpression(parameters)}.map(${this.runtimeClass.stubPropertyName} => new ${this.runtimeClass.name}({ ${this.runtimeClass.stubPropertyName}, resolver: (identifier) => ${variables.objectSet}.${this.resolvedType.objectSetMethodNames.object}(identifier) }))`;
|
|
310
|
+
return `${this.stubType.fromRdfExpression(parameters)}.map(values => values.map(${this.runtimeClass.stubPropertyName} => new ${this.runtimeClass.name}({ ${this.runtimeClass.stubPropertyName}, resolver: (identifier) => ${variables.objectSet}.${this.resolvedType.objectSetMethodNames.object}(identifier) })))`;
|
|
233
311
|
}
|
|
234
312
|
}
|
|
235
313
|
LazyShaclProperty.RequiredObjectType = RequiredObjectType;
|
|
@@ -12,7 +12,7 @@ export declare abstract class Property<TypeT extends Pick<Type, "mutable" | "nam
|
|
|
12
12
|
/**
|
|
13
13
|
* Function declaration that takes two values of the property and compares them, returning an $EqualsResult.
|
|
14
14
|
*/
|
|
15
|
-
abstract readonly equalsFunction: string
|
|
15
|
+
abstract readonly equalsFunction: Maybe<string>;
|
|
16
16
|
/**
|
|
17
17
|
* Optional get accessor to include in a class declaration of the object type.
|
|
18
18
|
*/
|
|
@@ -21,8 +21,12 @@ export declare abstract class Property<TypeT extends Pick<Type, "mutable" | "nam
|
|
|
21
21
|
* GraphQL.js field definition.
|
|
22
22
|
*/
|
|
23
23
|
abstract readonly graphqlField: Maybe<{
|
|
24
|
+
args: Maybe<Record<string, {
|
|
25
|
+
type: string;
|
|
26
|
+
}>>;
|
|
27
|
+
description: Maybe<string>;
|
|
24
28
|
name: string;
|
|
25
|
-
|
|
29
|
+
resolve: string;
|
|
26
30
|
type: string;
|
|
27
31
|
}>;
|
|
28
32
|
/**
|
|
@@ -75,6 +79,7 @@ export declare abstract class Property<TypeT extends Pick<Type, "mutable" | "nam
|
|
|
75
79
|
abstract constructorStatements(parameters: {
|
|
76
80
|
variables: {
|
|
77
81
|
parameter: string;
|
|
82
|
+
parameters: string;
|
|
78
83
|
};
|
|
79
84
|
}): readonly string[];
|
|
80
85
|
/**
|
|
@@ -86,7 +91,7 @@ export declare abstract class Property<TypeT extends Pick<Type, "mutable" | "nam
|
|
|
86
91
|
};
|
|
87
92
|
}): readonly string[];
|
|
88
93
|
/**
|
|
89
|
-
* Statements to deserialize
|
|
94
|
+
* Statements to deserialize this property on the given rdfjsResource.Resource to a typed value of the property.
|
|
90
95
|
*/
|
|
91
96
|
abstract fromRdfStatements(parameters: {
|
|
92
97
|
variables: {
|
|
@@ -142,6 +147,7 @@ export declare abstract class Property<TypeT extends Pick<Type, "mutable" | "nam
|
|
|
142
147
|
*/
|
|
143
148
|
abstract sparqlWherePatterns(parameters: {
|
|
144
149
|
variables: {
|
|
150
|
+
languageIn: string;
|
|
145
151
|
subject: string;
|
|
146
152
|
variablePrefix: string;
|
|
147
153
|
};
|
|
@@ -15,7 +15,7 @@ export declare abstract class ShaclProperty<TypeT extends Type> extends Property
|
|
|
15
15
|
label: Maybe<string>;
|
|
16
16
|
path: rdfjs.NamedNode;
|
|
17
17
|
} & ConstructorParameters<typeof Property<TypeT>>[0]);
|
|
18
|
-
get equalsFunction(): string
|
|
18
|
+
get equalsFunction(): Maybe<string>;
|
|
19
19
|
get constructorParametersPropertySignature(): Maybe<OptionalKind<PropertySignatureStructure>>;
|
|
20
20
|
constructorStatements({ variables, }: Parameters<Property<TypeT>["constructorStatements"]>[0]): readonly string[];
|
|
21
21
|
fromJsonStatements({ variables, }: Parameters<Property<TypeT>["fromJsonStatements"]>[0]): readonly string[];
|
|
@@ -23,7 +23,7 @@ export class ShaclProperty extends Property {
|
|
|
23
23
|
this.path = path;
|
|
24
24
|
}
|
|
25
25
|
get equalsFunction() {
|
|
26
|
-
return this.type.equalsFunction;
|
|
26
|
+
return Maybe.of(this.type.equalsFunction);
|
|
27
27
|
}
|
|
28
28
|
get constructorParametersPropertySignature() {
|
|
29
29
|
let hasQuestionToken = false;
|
|
@@ -137,8 +137,16 @@ export class ShaclProperty extends Property {
|
|
|
137
137
|
// Assume the property has the correct range and ignore the object's RDF type.
|
|
138
138
|
// This also accommodates the case where the object of a property is a dangling identifier that's not the
|
|
139
139
|
// subject of any statements.
|
|
140
|
+
const typeFromRdfExpression = this.type.fromRdfExpression({
|
|
141
|
+
variables: {
|
|
142
|
+
...variables,
|
|
143
|
+
ignoreRdfType: true,
|
|
144
|
+
predicate: this.predicate,
|
|
145
|
+
resourceValues: `purify.Either.of<Error, rdfjsResource.Resource.Values<rdfjsResource.Resource.Value>>(${variables.resource}.values(${syntheticNamePrefix}properties.${this.name}["identifier"], { unique: true }))`,
|
|
146
|
+
},
|
|
147
|
+
});
|
|
140
148
|
return [
|
|
141
|
-
`const _${this.name}Either: purify.Either<Error, ${this.type.name}> = ${
|
|
149
|
+
`const _${this.name}Either: purify.Either<Error, ${this.type.name}> = ${typeFromRdfExpression}.chain(values => values.head());`,
|
|
142
150
|
`if (_${this.name}Either.isLeft()) { return _${this.name}Either; }`,
|
|
143
151
|
`const ${this.name} = _${this.name}Either.unsafeCoerce();`,
|
|
144
152
|
];
|
|
@@ -162,6 +170,7 @@ export class ShaclProperty extends Property {
|
|
|
162
170
|
allowIgnoreRdfType: true,
|
|
163
171
|
context: "object",
|
|
164
172
|
variables: {
|
|
173
|
+
languageIn: variables.languageIn,
|
|
165
174
|
object: `dataFactory.variable!(${objectString})`,
|
|
166
175
|
predicate: this.predicate,
|
|
167
176
|
subject: variables.subject,
|
|
@@ -190,6 +199,9 @@ export class ShaclProperty extends Property {
|
|
|
190
199
|
return `${this.objectType.staticModuleName}.${syntheticNamePrefix}properties.${this.name}["identifier"]`;
|
|
191
200
|
}
|
|
192
201
|
}
|
|
202
|
+
__decorate([
|
|
203
|
+
Memoize()
|
|
204
|
+
], ShaclProperty.prototype, "equalsFunction", null);
|
|
193
205
|
__decorate([
|
|
194
206
|
Memoize()
|
|
195
207
|
], ShaclProperty.prototype, "constructorParametersPropertySignature", null);
|
|
@@ -7,7 +7,7 @@ export declare class TypeDiscriminatorProperty extends Property<TypeDiscriminato
|
|
|
7
7
|
private readonly override;
|
|
8
8
|
readonly constructorParametersPropertySignature: Maybe<OptionalKind<PropertySignatureStructure>>;
|
|
9
9
|
readonly declarationImports: readonly Import[];
|
|
10
|
-
readonly equalsFunction
|
|
10
|
+
readonly equalsFunction: Maybe<string>;
|
|
11
11
|
readonly getAccessorDeclaration: Maybe<OptionalKind<GetAccessorDeclarationStructure>>;
|
|
12
12
|
readonly graphqlField: Property<TypeDiscriminatorProperty.Type>["graphqlField"];
|
|
13
13
|
readonly initializer: string;
|
|
@@ -15,7 +15,7 @@ export class TypeDiscriminatorProperty extends Property {
|
|
|
15
15
|
override;
|
|
16
16
|
constructorParametersPropertySignature = Maybe.empty();
|
|
17
17
|
declarationImports = [];
|
|
18
|
-
equalsFunction = `${syntheticNamePrefix}strictEquals
|
|
18
|
+
equalsFunction = Maybe.of(`${syntheticNamePrefix}strictEquals`);
|
|
19
19
|
getAccessorDeclaration = Maybe.empty();
|
|
20
20
|
graphqlField = Maybe.empty();
|
|
21
21
|
initializer;
|
|
@@ -7,22 +7,19 @@ import { hashFunctionOrMethodDeclarations } from "./hashFunctionOrMethodDeclarat
|
|
|
7
7
|
import { toJsonFunctionOrMethodDeclaration } from "./toJsonFunctionOrMethodDeclaration.js";
|
|
8
8
|
import { toRdfFunctionOrMethodDeclaration } from "./toRdfFunctionOrMethodDeclaration.js";
|
|
9
9
|
function constructorDeclaration() {
|
|
10
|
-
const parametersPropertySignatures = this.properties.flatMap((property) => property.constructorParametersPropertySignature
|
|
11
|
-
|
|
12
|
-
.toList());
|
|
13
|
-
let parametersType;
|
|
10
|
+
const parametersPropertySignatures = this.properties.flatMap((property) => property.constructorParametersPropertySignature.toList());
|
|
11
|
+
const parametersType = [];
|
|
14
12
|
if (parametersPropertySignatures.length > 0) {
|
|
15
|
-
parametersType
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
parametersType = "";
|
|
13
|
+
parametersType.push(`{ ${parametersPropertySignatures
|
|
14
|
+
.map((propertySignature) => `readonly ${propertySignature.name}${propertySignature.hasQuestionToken ? "?" : ""}: ${propertySignature.type}`)
|
|
15
|
+
.join(", ")} }`);
|
|
19
16
|
}
|
|
20
17
|
if (this.parentObjectTypes.length > 0) {
|
|
21
18
|
// Pass up parameters
|
|
22
|
-
parametersType
|
|
19
|
+
parametersType.push(`ConstructorParameters<typeof ${this.parentObjectTypes[0].name}>[0]`);
|
|
23
20
|
}
|
|
24
21
|
if (parametersType.length === 0) {
|
|
25
|
-
parametersType
|
|
22
|
+
parametersType.push("object");
|
|
26
23
|
}
|
|
27
24
|
const statements = [];
|
|
28
25
|
if (this.parentObjectTypes.length > 0) {
|
|
@@ -30,8 +27,14 @@ function constructorDeclaration() {
|
|
|
30
27
|
// of trying to sense whether we need to or not.
|
|
31
28
|
statements.push("super(parameters);");
|
|
32
29
|
}
|
|
30
|
+
const parametersHasQuestionToken = this.parentObjectTypes.length === 0 &&
|
|
31
|
+
parametersPropertySignatures.every((propertySignature) => !!propertySignature.hasQuestionToken);
|
|
32
|
+
const parametersVariable = `parameters${parametersHasQuestionToken ? "?" : ""}`;
|
|
33
33
|
const propertyStatements = this.properties.flatMap((property) => property.constructorStatements({
|
|
34
|
-
variables: {
|
|
34
|
+
variables: {
|
|
35
|
+
parameter: `${parametersVariable}.${property.name}`,
|
|
36
|
+
parameters: parametersVariable,
|
|
37
|
+
},
|
|
35
38
|
}));
|
|
36
39
|
statements.push(...propertyStatements);
|
|
37
40
|
return {
|
|
@@ -40,8 +43,9 @@ function constructorDeclaration() {
|
|
|
40
43
|
: undefined,
|
|
41
44
|
parameters: [
|
|
42
45
|
{
|
|
46
|
+
hasQuestionToken: parametersHasQuestionToken,
|
|
43
47
|
name: statements.length > 0 ? "parameters" : "_parameters",
|
|
44
|
-
type: parametersType,
|
|
48
|
+
type: parametersType.join(" & "),
|
|
45
49
|
},
|
|
46
50
|
],
|
|
47
51
|
statements,
|
|
@@ -12,23 +12,34 @@ export function createFunctionDeclaration() {
|
|
|
12
12
|
if (this.extern) {
|
|
13
13
|
return Maybe.empty();
|
|
14
14
|
}
|
|
15
|
-
const parametersPropertySignatures = this.properties.flatMap((property) => property.constructorParametersPropertySignature
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
const parametersPropertySignatures = this.properties.flatMap((property) => property.constructorParametersPropertySignature.toList());
|
|
16
|
+
const parametersType = [];
|
|
17
|
+
if (parametersPropertySignatures.length > 0) {
|
|
18
|
+
parametersType.push(`{ ${parametersPropertySignatures
|
|
19
|
+
.map((propertySignature) => `readonly ${propertySignature.name}${propertySignature.hasQuestionToken ? "?" : ""}: ${propertySignature.type}`)
|
|
20
|
+
.join(", ")} }`);
|
|
21
|
+
}
|
|
22
|
+
for (const parentObjectType of this.parentObjectTypes) {
|
|
23
|
+
parametersType.push(`Parameters<typeof ${parentObjectType.staticModuleName}.${syntheticNamePrefix}create>[0]`);
|
|
24
|
+
}
|
|
25
|
+
if (parametersType.length === 0) {
|
|
26
|
+
parametersType.push("object");
|
|
27
|
+
}
|
|
23
28
|
const propertyInitializers = [];
|
|
24
29
|
const omitPropertyNames = [];
|
|
25
30
|
const propertyStatements = [];
|
|
26
31
|
for (const parentObjectType of this.parentObjectTypes) {
|
|
27
32
|
propertyInitializers.push(`...${parentObjectType.staticModuleName}.${syntheticNamePrefix}create(parameters)`);
|
|
28
33
|
}
|
|
34
|
+
const parametersHasQuestionToken = this.parentObjectTypes.length === 0 &&
|
|
35
|
+
parametersPropertySignatures.every((propertySignature) => !!propertySignature.hasQuestionToken);
|
|
36
|
+
const parametersVariable = `parameters${parametersHasQuestionToken ? "?" : ""}`;
|
|
29
37
|
for (const property of this.properties) {
|
|
30
38
|
const thisPropertyStatements = property.constructorStatements({
|
|
31
|
-
variables: {
|
|
39
|
+
variables: {
|
|
40
|
+
parameter: `${parametersVariable}.${property.name}`,
|
|
41
|
+
parameters: parametersVariable,
|
|
42
|
+
},
|
|
32
43
|
});
|
|
33
44
|
if (thisPropertyStatements.length > 0) {
|
|
34
45
|
propertyInitializers.push(property.name);
|
|
@@ -46,8 +57,9 @@ export function createFunctionDeclaration() {
|
|
|
46
57
|
name: `${syntheticNamePrefix}create`,
|
|
47
58
|
parameters: [
|
|
48
59
|
{
|
|
60
|
+
hasQuestionToken: parametersHasQuestionToken,
|
|
49
61
|
name: "parameters",
|
|
50
|
-
type: parametersType,
|
|
62
|
+
type: parametersType.join(" & "),
|
|
51
63
|
},
|
|
52
64
|
],
|
|
53
65
|
returnType: omitPropertyNames.length === 0
|
|
@@ -38,7 +38,9 @@ export function equalsFunctionOrMethodDeclaration() {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
for (const property of this.ownProperties) {
|
|
41
|
-
|
|
41
|
+
property.equalsFunction.ifJust((equalsFunction) => {
|
|
42
|
+
chain.push(`(${equalsFunction})(${leftVariable}.${property.name}, ${rightVariable}.${property.name}).mapLeft(propertyValuesUnequal => ({ left: ${leftVariable}, right: ${rightVariable}, propertyName: "${property.name}", propertyValuesUnequal, type: "Property" as const }))`);
|
|
43
|
+
});
|
|
42
44
|
}
|
|
43
45
|
return Maybe.of({
|
|
44
46
|
hasOverrideKeyword,
|
|
@@ -22,8 +22,20 @@ export function graphqlTypeVariableStatement() {
|
|
|
22
22
|
description: this.comment.map(JSON.stringify).extract(),
|
|
23
23
|
fields: `() => (${objectInitializer(this.properties.reduce((fields, property) => {
|
|
24
24
|
property.graphqlField.ifJust((field) => {
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
fields[field.name] = objectInitializer({
|
|
26
|
+
args: field.args
|
|
27
|
+
.map((args) => objectInitializer(Object.entries(args).reduce((argObjects, [argName, arg]) => {
|
|
28
|
+
argObjects[argName] = objectInitializer(arg);
|
|
29
|
+
return argObjects;
|
|
30
|
+
}, {})))
|
|
31
|
+
.extract(),
|
|
32
|
+
description: field.description
|
|
33
|
+
.map(JSON.stringify)
|
|
34
|
+
.extract(),
|
|
35
|
+
name: JSON.stringify(field.name),
|
|
36
|
+
resolve: field.resolve,
|
|
37
|
+
type: field.type,
|
|
38
|
+
});
|
|
27
39
|
});
|
|
28
40
|
return fields;
|
|
29
41
|
}, {}))})`,
|