@shaclmate/compiler 2.0.23 → 3.0.0
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 +2 -1
- package/dist/generators/ts/BooleanType.js +9 -4
- package/dist/generators/ts/DateTimeType.d.ts +2 -1
- package/dist/generators/ts/DateTimeType.js +9 -4
- package/dist/generators/ts/IdentifierType.d.ts +1 -1
- package/dist/generators/ts/IdentifierType.js +20 -14
- package/dist/generators/ts/Import.d.ts +2 -1
- package/dist/generators/ts/Import.js +29 -24
- package/dist/generators/ts/ListType.js +16 -5
- package/dist/generators/ts/LiteralType.d.ts +5 -2
- package/dist/generators/ts/LiteralType.js +81 -15
- package/dist/generators/ts/NumberType.d.ts +2 -1
- package/dist/generators/ts/NumberType.js +9 -4
- package/dist/generators/ts/ObjectType.d.ts +3 -2
- package/dist/generators/ts/ObjectType.js +16 -6
- package/dist/generators/ts/ObjectUnionType.d.ts +2 -0
- package/dist/generators/ts/ObjectUnionType.js +21 -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 +1 -1
- package/dist/generators/ts/PrimitiveType.js +6 -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 +3 -2
- package/dist/generators/ts/SnippetDeclarations.js +41 -3
- package/dist/generators/ts/StringType.d.ts +2 -1
- package/dist/generators/ts/StringType.js +14 -7
- package/dist/generators/ts/TermType.d.ts +18 -19
- package/dist/generators/ts/TermType.js +55 -51
- package/dist/generators/ts/TsGenerator.js +24 -12
- package/dist/generators/ts/Type.d.ts +12 -3
- package/dist/generators/ts/Type.js +1 -0
- package/dist/generators/ts/TypeFactory.d.ts +8 -0
- package/dist/generators/ts/TypeFactory.js +114 -23
- 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 +10 -4
- 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/jsonFunctionDeclarations.js +1 -1
- package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.js +95 -84
- 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 +35 -15
- package/dist/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.js +19 -12
- package/dist/generators/ts/forwardingObjectSetClassDeclaration.d.ts +8 -0
- package/dist/generators/ts/forwardingObjectSetClassDeclaration.js +29 -0
- package/dist/generators/ts/objectSetDeclarations.js +2 -0
- package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +26 -19
- package/dist/generators/ts/rdfjsTermExpression.js +3 -3
- package/dist/generators/ts/sparqlObjectSetClassDeclaration.js +6 -6
- package/dist/input/PropertyPath.d.ts +2 -3
- 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 -8
- 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
|
@@ -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
|
}, {}))})`,
|
|
@@ -100,7 +100,7 @@ function jsonSchemaFunctionDeclaration() {
|
|
|
100
100
|
kind: StructureKind.Function,
|
|
101
101
|
name: `${syntheticNamePrefix}jsonSchema`,
|
|
102
102
|
statements: [
|
|
103
|
-
`return
|
|
103
|
+
`return zod.toJSONSchema(${syntheticNamePrefix}jsonZodSchema());`,
|
|
104
104
|
],
|
|
105
105
|
};
|
|
106
106
|
}
|
|
@@ -1,32 +1,102 @@
|
|
|
1
1
|
import { rdf } from "@tpluscode/rdf-ns-builders";
|
|
2
2
|
import { Maybe } from "purify-ts";
|
|
3
|
+
import { invariant } from "ts-invariant";
|
|
3
4
|
import { StructureKind } from "ts-morph";
|
|
4
5
|
import { rdfjsTermExpression } from "../rdfjsTermExpression.js";
|
|
5
6
|
import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
|
|
6
7
|
import { toRdfFunctionOrMethodDeclaration } from "./toRdfFunctionOrMethodDeclaration.js";
|
|
7
|
-
function
|
|
8
|
+
function fromRdfFunctionDeclaration() {
|
|
9
|
+
const statements = [];
|
|
10
|
+
statements.push("let { ignoreRdfType = false, objectSet, preferredLanguages, ...context } = (options ?? {});", `if (!objectSet) { objectSet = new ${syntheticNamePrefix}RdfjsDatasetObjectSet({ dataset: resource.dataset }); }`);
|
|
11
|
+
let returnExpression;
|
|
12
|
+
if (this.childObjectTypes.length > 0) {
|
|
13
|
+
// Can't ignore the RDF type.
|
|
14
|
+
// Similar to an object union type, alt-chain the fromRdf of the different concrete subclasses together
|
|
15
|
+
returnExpression = this.childObjectTypes.reduce((expression, childObjectType) => {
|
|
16
|
+
const childObjectTypeExpression = `(${childObjectType.staticModuleName}.${syntheticNamePrefix}fromRdf(resource, { ...context, ignoreRdfType: false, objectSet }) as purify.Either<Error, ${this.name}>)`;
|
|
17
|
+
return expression.length > 0
|
|
18
|
+
? `${expression}.altLazy(() => ${childObjectTypeExpression})`
|
|
19
|
+
: childObjectTypeExpression;
|
|
20
|
+
}, "");
|
|
21
|
+
}
|
|
22
|
+
if (!this.abstract) {
|
|
23
|
+
let propertiesFromRdfExpression = `${this.staticModuleName}.${syntheticNamePrefix}propertiesFromRdf({ ...context, ignoreRdfType, objectSet, preferredLanguages, resource })`;
|
|
24
|
+
if (this.declarationType === "class") {
|
|
25
|
+
propertiesFromRdfExpression = `${propertiesFromRdfExpression}.map(properties => new ${this.name}(properties))`;
|
|
26
|
+
}
|
|
27
|
+
if (this.childObjectTypes.length > 0) {
|
|
28
|
+
invariant(returnExpression);
|
|
29
|
+
returnExpression = `${returnExpression}.altLazy(() => ${propertiesFromRdfExpression})`;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
invariant(!returnExpression);
|
|
33
|
+
returnExpression = propertiesFromRdfExpression;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (returnExpression) {
|
|
37
|
+
statements.push(`return ${returnExpression};`);
|
|
38
|
+
}
|
|
39
|
+
if (statements.length === 0) {
|
|
40
|
+
return Maybe.empty();
|
|
41
|
+
}
|
|
42
|
+
return Maybe.of({
|
|
43
|
+
isExported: true,
|
|
44
|
+
kind: StructureKind.Function,
|
|
45
|
+
name: `${syntheticNamePrefix}fromRdf`,
|
|
46
|
+
parameters: [
|
|
47
|
+
{
|
|
48
|
+
name: "resource",
|
|
49
|
+
type: "rdfjsResource.Resource",
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
hasQuestionToken: true,
|
|
53
|
+
name: "options",
|
|
54
|
+
type: `{ [_index: string]: any; ignoreRdfType?: boolean; objectSet?: ${syntheticNamePrefix}ObjectSet; preferredLanguages?: readonly string[]; }`,
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
returnType: `purify.Either<Error, ${this.name}>`,
|
|
58
|
+
statements: statements,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
function propertiesFromRdfFunctionDeclaration() {
|
|
8
62
|
const initializers = [];
|
|
9
63
|
const propertySignatures = [];
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
if (this.ownProperties.length > 0 || this.parentObjectTypes.length > 0) {
|
|
13
|
-
propertiesFromRdfStatements.push("// @ts-ignore", `const ${syntheticNamePrefix}objectSet = ${syntheticNamePrefix}objectSetParameter ?? new ${syntheticNamePrefix}RdfjsDatasetObjectSet({ dataset: ${variables.resource}.dataset });`);
|
|
14
|
-
}
|
|
64
|
+
const returnType = [];
|
|
65
|
+
const statements = [];
|
|
15
66
|
this.parentObjectTypes.forEach((parentObjectType, parentObjectTypeI) => {
|
|
16
|
-
|
|
67
|
+
statements.push(`const ${syntheticNamePrefix}super${parentObjectTypeI}Either = ${parentObjectType.staticModuleName}.${syntheticNamePrefix}propertiesFromRdf({ ...${variables.context}, ignoreRdfType: true, objectSet: ${variables.objectSet}, preferredLanguages: ${variables.preferredLanguages}, resource: ${variables.resource} });`, `if (${syntheticNamePrefix}super${parentObjectTypeI}Either.isLeft()) { return ${syntheticNamePrefix}super${parentObjectTypeI}Either; }`, `const ${syntheticNamePrefix}super${parentObjectTypeI} = ${syntheticNamePrefix}super${parentObjectTypeI}Either.unsafeCoerce()`);
|
|
17
68
|
initializers.push(`...${syntheticNamePrefix}super${parentObjectTypeI}`);
|
|
18
|
-
|
|
69
|
+
returnType.push(`${syntheticNamePrefix}UnwrapR<ReturnType<typeof ${parentObjectType.staticModuleName}.${syntheticNamePrefix}propertiesFromRdf>>`);
|
|
19
70
|
});
|
|
20
|
-
this.fromRdfType.ifJust((
|
|
71
|
+
this.fromRdfType.ifJust((fromRdfType) => {
|
|
72
|
+
const fromRdfTypeVariable = this.fromRdfTypeVariable.unsafeCoerce();
|
|
21
73
|
const predicate = rdfjsTermExpression(rdf.type);
|
|
22
|
-
|
|
23
|
-
if (!${variables.ignoreRdfType}
|
|
24
|
-
|
|
74
|
+
statements.push(`\
|
|
75
|
+
if (!${variables.ignoreRdfType}) {
|
|
76
|
+
const ${syntheticNamePrefix}rdfTypeCheck: purify.Either<Error, true> = ${variables.resource}.value(${predicate})
|
|
77
|
+
.chain(actualRdfType => actualRdfType.toIri())
|
|
78
|
+
.chain((actualRdfType) => {
|
|
79
|
+
// Check the expected type and its known subtypes
|
|
80
|
+
switch (actualRdfType.value) {
|
|
81
|
+
${[`case "${fromRdfType.value}":`].concat(this.descendantFromRdfTypes.map((descendantFromRdfType) => `case "${descendantFromRdfType.value}":`)).join("\n")}
|
|
82
|
+
return purify.Either.of(true);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Check arbitrary rdfs:subClassOf's of the expected type
|
|
86
|
+
if (${variables.resource}.isInstanceOf(${fromRdfTypeVariable})) {
|
|
87
|
+
return purify.Either.of(true);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return purify.Left(new Error(\`\${rdfjsResource.Resource.Identifier.toString(${variables.resource}.identifier)} has unexpected RDF type (actual: \${actualRdfType.value}, expected: ${fromRdfType.value})\`));
|
|
91
|
+
});
|
|
92
|
+
if (${syntheticNamePrefix}rdfTypeCheck.isLeft()) {
|
|
93
|
+
return ${syntheticNamePrefix}rdfTypeCheck;
|
|
94
|
+
}
|
|
25
95
|
}`);
|
|
26
96
|
});
|
|
27
97
|
const propertyFromRdfVariables = {
|
|
28
98
|
context: variables.context,
|
|
29
|
-
|
|
99
|
+
preferredLanguages: variables.preferredLanguages,
|
|
30
100
|
objectSet: variables.objectSet,
|
|
31
101
|
resource: variables.resource,
|
|
32
102
|
};
|
|
@@ -35,88 +105,28 @@ if (!${variables.ignoreRdfType} && !${variables.resource}.isInstanceOf(${synthet
|
|
|
35
105
|
variables: propertyFromRdfVariables,
|
|
36
106
|
});
|
|
37
107
|
if (propertyFromRdfStatements.length > 0) {
|
|
38
|
-
|
|
108
|
+
statements.push(...propertyFromRdfStatements);
|
|
39
109
|
initializers.push(property.name);
|
|
40
110
|
propertySignatures.push(`${property.name}: ${property.type.name};`);
|
|
41
111
|
}
|
|
42
112
|
}
|
|
43
|
-
|
|
113
|
+
statements.push(`return purify.Either.of({ ${initializers.join(", ")} })`);
|
|
44
114
|
if (propertySignatures.length > 0) {
|
|
45
|
-
|
|
115
|
+
returnType.splice(0, 0, `{ ${propertySignatures.join(" ")} }`);
|
|
46
116
|
}
|
|
47
|
-
|
|
48
|
-
functionDeclarations.push({
|
|
117
|
+
return {
|
|
49
118
|
isExported: true,
|
|
50
119
|
kind: StructureKind.Function,
|
|
51
120
|
name: `${syntheticNamePrefix}propertiesFromRdf`,
|
|
52
121
|
parameters: [
|
|
53
122
|
{
|
|
54
|
-
name: `{ ignoreRdfType: ${variables.ignoreRdfType},
|
|
55
|
-
type: `{ [_index: string]: any; ignoreRdfType
|
|
123
|
+
name: `{ ignoreRdfType: ${variables.ignoreRdfType}, objectSet: ${variables.objectSet}, preferredLanguages: ${variables.preferredLanguages}, resource: ${variables.resource},\n// @ts-ignore\n...${variables.context} }`,
|
|
124
|
+
type: `{ [_index: string]: any; ignoreRdfType: boolean; objectSet: ${syntheticNamePrefix}ObjectSet; preferredLanguages?: readonly string[]; resource: rdfjsResource.Resource; }`,
|
|
56
125
|
},
|
|
57
126
|
],
|
|
58
|
-
returnType: `purify.Either<Error, ${
|
|
59
|
-
statements:
|
|
60
|
-
}
|
|
61
|
-
const fromRdfStatements = [];
|
|
62
|
-
let fromRdfReturnStatement;
|
|
63
|
-
if (this.abstract) {
|
|
64
|
-
if (this.childObjectTypes.length > 0) {
|
|
65
|
-
// Can't ignore the RDF type if we're doing a union.
|
|
66
|
-
fromRdfStatements.push("const { ignoreRdfType: _, ...otherParameters } = parameters;");
|
|
67
|
-
// Similar to an object union type, alt-chain the fromRdf of the different concrete subclasses together
|
|
68
|
-
fromRdfReturnStatement = `return ${this.childObjectTypes.reduce((expression, childObjectType) => {
|
|
69
|
-
const childObjectTypeExpression = `(${childObjectType.staticModuleName}.${syntheticNamePrefix}fromRdf(otherParameters) as purify.Either<Error, ${this.name}>)`;
|
|
70
|
-
return expression.length > 0
|
|
71
|
-
? `${expression}.altLazy(() => ${childObjectTypeExpression})`
|
|
72
|
-
: childObjectTypeExpression;
|
|
73
|
-
}, "")};`;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
let propertiesFromRdfExpression;
|
|
78
|
-
switch (this.declarationType) {
|
|
79
|
-
case "class":
|
|
80
|
-
propertiesFromRdfExpression = `${this.staticModuleName}.${syntheticNamePrefix}propertiesFromRdf(parameters).map(properties => new ${this.name}(properties))`;
|
|
81
|
-
break;
|
|
82
|
-
case "interface":
|
|
83
|
-
propertiesFromRdfExpression = `${this.staticModuleName}.${syntheticNamePrefix}propertiesFromRdf(parameters)`;
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
if (this.childObjectTypes.length > 0) {
|
|
87
|
-
// Can't ignore the RDF type if we're trying the child object type.
|
|
88
|
-
fromRdfStatements.push("const { ignoreRdfType: _, ...otherParameters } = parameters;");
|
|
89
|
-
fromRdfReturnStatement = `${this.childObjectTypes.reduce((expression, childObjectType) => {
|
|
90
|
-
const childObjectTypeExpression = `(${childObjectType.staticModuleName}.${syntheticNamePrefix}fromRdf(otherParameters) as purify.Either<Error, ${this.name}>)`;
|
|
91
|
-
return expression.length > 0
|
|
92
|
-
? `${expression}.altLazy(() => ${childObjectTypeExpression})`
|
|
93
|
-
: childObjectTypeExpression;
|
|
94
|
-
}, "")}.altLazy(() => ${propertiesFromRdfExpression})`;
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
fromRdfReturnStatement = propertiesFromRdfExpression;
|
|
98
|
-
}
|
|
99
|
-
fromRdfReturnStatement = `return ${fromRdfReturnStatement};`;
|
|
100
|
-
}
|
|
101
|
-
if (fromRdfReturnStatement) {
|
|
102
|
-
fromRdfStatements.push(fromRdfReturnStatement);
|
|
103
|
-
}
|
|
104
|
-
if (fromRdfStatements.length > 0) {
|
|
105
|
-
functionDeclarations.push({
|
|
106
|
-
isExported: true,
|
|
107
|
-
kind: StructureKind.Function,
|
|
108
|
-
name: `${syntheticNamePrefix}fromRdf`,
|
|
109
|
-
parameters: [
|
|
110
|
-
{
|
|
111
|
-
name: "parameters",
|
|
112
|
-
type: `Parameters<typeof ${this.staticModuleName}.${syntheticNamePrefix}propertiesFromRdf>[0]`,
|
|
113
|
-
},
|
|
114
|
-
],
|
|
115
|
-
returnType: `purify.Either<Error, ${this.name}>`,
|
|
116
|
-
statements: fromRdfStatements,
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
return functionDeclarations;
|
|
127
|
+
returnType: `purify.Either<Error, ${returnType.join(" & ")}>`,
|
|
128
|
+
statements: statements,
|
|
129
|
+
};
|
|
120
130
|
}
|
|
121
131
|
export function rdfFunctionDeclarations() {
|
|
122
132
|
if (!this.features.has("rdf")) {
|
|
@@ -126,7 +136,8 @@ export function rdfFunctionDeclarations() {
|
|
|
126
136
|
return [];
|
|
127
137
|
}
|
|
128
138
|
return [
|
|
129
|
-
...
|
|
139
|
+
...fromRdfFunctionDeclaration.bind(this)().toList(),
|
|
140
|
+
propertiesFromRdfFunctionDeclaration.bind(this)(),
|
|
130
141
|
...toRdfFunctionDeclaration.bind(this)().toList(),
|
|
131
142
|
];
|
|
132
143
|
}
|
|
@@ -145,8 +156,8 @@ function toRdfFunctionDeclaration() {
|
|
|
145
156
|
const variables = {
|
|
146
157
|
context: `${syntheticNamePrefix}context`,
|
|
147
158
|
ignoreRdfType: `${syntheticNamePrefix}ignoreRdfType`,
|
|
148
|
-
languageIn: `${syntheticNamePrefix}languageIn`,
|
|
149
159
|
objectSet: `${syntheticNamePrefix}objectSet`,
|
|
160
|
+
preferredLanguages: `${syntheticNamePrefix}preferredLanguages`,
|
|
150
161
|
resource: `${syntheticNamePrefix}resource`,
|
|
151
162
|
};
|
|
152
163
|
//# sourceMappingURL=rdfFunctionDeclarations.js.map
|
|
@@ -9,13 +9,13 @@ export function sparqlConstructQueryFunctionDeclaration() {
|
|
|
9
9
|
{
|
|
10
10
|
hasQuestionToken: true,
|
|
11
11
|
name: "parameters",
|
|
12
|
-
type: '{ ignoreRdfType?: boolean; prefixes?: { [prefix: string]: string }; subject?: sparqljs.Triple["subject"]; } & Omit<sparqljs.ConstructQuery, "prefixes" | "queryType" | "type">',
|
|
12
|
+
type: '{ ignoreRdfType?: boolean; prefixes?: { [prefix: string]: string }; preferredLanguages?: readonly string[]; subject?: sparqljs.Triple["subject"]; } & Omit<sparqljs.ConstructQuery, "prefixes" | "queryType" | "type">',
|
|
13
13
|
},
|
|
14
14
|
],
|
|
15
15
|
returnType: "sparqljs.ConstructQuery",
|
|
16
16
|
statements: [
|
|
17
|
-
"const { ignoreRdfType, subject, ...queryParameters } = parameters ?? {}",
|
|
18
|
-
`return { ...queryParameters, prefixes: parameters?.prefixes ?? {}, queryType: "CONSTRUCT", template: (queryParameters.template ?? []).concat(${this.staticModuleName}.${syntheticNamePrefix}sparqlConstructTemplateTriples({ ignoreRdfType, subject })), type: "query", where: (queryParameters.where ?? []).concat(${this.staticModuleName}.${syntheticNamePrefix}sparqlWherePatterns({ ignoreRdfType, subject })) };`,
|
|
17
|
+
"const { ignoreRdfType, preferredLanguages, subject, ...queryParameters } = parameters ?? {}",
|
|
18
|
+
`return { ...queryParameters, prefixes: parameters?.prefixes ?? {}, queryType: "CONSTRUCT", template: (queryParameters.template ?? []).concat(${this.staticModuleName}.${syntheticNamePrefix}sparqlConstructTemplateTriples({ ignoreRdfType, subject })), type: "query", where: (queryParameters.where ?? []).concat(${this.staticModuleName}.${syntheticNamePrefix}sparqlWherePatterns({ ignoreRdfType, preferredLanguages, subject })) };`,
|
|
19
19
|
],
|
|
20
20
|
};
|
|
21
21
|
}
|
|
@@ -9,7 +9,7 @@ export function sparqlConstructQueryStringFunctionDeclaration() {
|
|
|
9
9
|
{
|
|
10
10
|
hasQuestionToken: true,
|
|
11
11
|
name: "parameters",
|
|
12
|
-
type: '{ ignoreRdfType?: boolean; subject?: sparqljs.Triple["subject"]; variablePrefix?: string; } & Omit<sparqljs.ConstructQuery, "prefixes" | "queryType" | "type"> & sparqljs.GeneratorOptions',
|
|
12
|
+
type: '{ ignoreRdfType?: boolean; preferredLanguages?: readonly string[]; subject?: sparqljs.Triple["subject"]; variablePrefix?: string; } & Omit<sparqljs.ConstructQuery, "prefixes" | "queryType" | "type"> & sparqljs.GeneratorOptions',
|
|
13
13
|
},
|
|
14
14
|
],
|
|
15
15
|
returnType: "string",
|
|
@@ -12,7 +12,11 @@ export function sparqlFunctionDeclarations() {
|
|
|
12
12
|
if (this.extern) {
|
|
13
13
|
return [];
|
|
14
14
|
}
|
|
15
|
-
const variables = {
|
|
15
|
+
const variables = {
|
|
16
|
+
preferredLanguages: "parameters?.preferredLanguages",
|
|
17
|
+
subject: "subject",
|
|
18
|
+
variablePrefix: "variablePrefix",
|
|
19
|
+
};
|
|
16
20
|
const rdfClassVariable = `dataFactory.variable!(\`\${${variables.variablePrefix}}RdfClass\`)`;
|
|
17
21
|
const rdfTypeVariable = `dataFactory.variable!(\`\${${variables.variablePrefix}}RdfType\`)`;
|
|
18
22
|
const subjectDefault = camelCase(this.name);
|
|
@@ -41,6 +45,9 @@ for (const pattern of ${parentObjectType.staticModuleName}.${syntheticNamePrefix
|
|
|
41
45
|
nop = false;
|
|
42
46
|
}
|
|
43
47
|
if (this.fromRdfType.isJust()) {
|
|
48
|
+
const fromRdfTypeVariables = this.fromRdfTypeVariable
|
|
49
|
+
.toList()
|
|
50
|
+
.concat(this.descendantFromRdfTypeVariables);
|
|
44
51
|
sparqlConstructTemplateTriplesStatements.push(`\
|
|
45
52
|
if (!parameters?.ignoreRdfType) {
|
|
46
53
|
triples.push(
|
|
@@ -48,25 +55,38 @@ if (!parameters?.ignoreRdfType) {
|
|
|
48
55
|
{ subject: ${rdfTypeVariable}, predicate: ${rdfjsTermExpression(rdfs.subClassOf)}, object: ${rdfClassVariable} }
|
|
49
56
|
);
|
|
50
57
|
}`);
|
|
51
|
-
sparqlWherePatternsStatements.push(`\
|
|
58
|
+
sparqlWherePatternsStatements.push(`const rdfTypeVariable = ${rdfTypeVariable};`, `\
|
|
52
59
|
if (!parameters?.ignoreRdfType) {
|
|
53
|
-
requiredPatterns.push(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
requiredPatterns.push(
|
|
61
|
+
${fromRdfTypeVariables.length > 1
|
|
62
|
+
? `\
|
|
63
|
+
{
|
|
64
|
+
type: "values" as const,
|
|
65
|
+
values: [${fromRdfTypeVariables.join(", ")}].map((identifier) => {
|
|
66
|
+
const valuePatternRow: sparqljs.ValuePatternRow = {};
|
|
67
|
+
valuePatternRow[\`?\${${variables.variablePrefix}}FromRdfType\`] = identifier as rdfjs.NamedNode;
|
|
68
|
+
return valuePatternRow;
|
|
69
|
+
}),
|
|
70
|
+
},
|
|
71
|
+
${syntheticNamePrefix}sparqlInstancesOfPattern({ rdfType: dataFactory.variable!(\`\${${variables.variablePrefix}}FromRdfType\`), subject }),`
|
|
72
|
+
: `${syntheticNamePrefix}sparqlInstancesOfPattern({ rdfType: ${fromRdfTypeVariables[0]}, subject }),`}
|
|
73
|
+
{
|
|
74
|
+
triples: [
|
|
75
|
+
{
|
|
76
|
+
subject,
|
|
77
|
+
predicate: ${rdfjsTermExpression(rdf.type)},
|
|
78
|
+
object: rdfTypeVariable
|
|
79
|
+
}
|
|
80
|
+
],
|
|
81
|
+
type: "bgp" as const
|
|
82
|
+
}
|
|
83
|
+
);
|
|
64
84
|
optionalPatterns.push({
|
|
65
85
|
patterns: [
|
|
66
86
|
{
|
|
67
87
|
triples: [
|
|
68
88
|
{
|
|
69
|
-
subject:
|
|
89
|
+
subject: rdfTypeVariable,
|
|
70
90
|
predicate: {
|
|
71
91
|
items: [${rdfjsTermExpression(rdfs.subClassOf)}],
|
|
72
92
|
pathType: "+" as const,
|
|
@@ -135,7 +155,7 @@ for (const pattern of propertyPatterns) {
|
|
|
135
155
|
{
|
|
136
156
|
hasQuestionToken: true,
|
|
137
157
|
name: `${nop ? "_" : ""}parameters`,
|
|
138
|
-
type: '{ ignoreRdfType?: boolean; subject?: sparqljs.Triple["subject"], variablePrefix?: string }',
|
|
158
|
+
type: '{ ignoreRdfType?: boolean; preferredLanguages?: readonly string[]; subject?: sparqljs.Triple["subject"], variablePrefix?: string }',
|
|
139
159
|
},
|
|
140
160
|
],
|
|
141
161
|
returnType: "readonly sparqljs.Pattern[]",
|
|
@@ -7,8 +7,23 @@ export function toRdfFunctionOrMethodDeclaration() {
|
|
|
7
7
|
return Maybe.empty();
|
|
8
8
|
}
|
|
9
9
|
this.ensureAtMostOneSuperObjectType();
|
|
10
|
+
const parameters = [];
|
|
11
|
+
if (this.declarationType === "interface") {
|
|
12
|
+
parameters.push({
|
|
13
|
+
name: this.thisVariable,
|
|
14
|
+
type: this.name,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
parameters.push({
|
|
18
|
+
hasQuestionToken: true,
|
|
19
|
+
name: "options",
|
|
20
|
+
type: `{ ${variables.ignoreRdfType}?: boolean; ${variables.mutateGraph}?: rdfjsResource.MutableResource.MutateGraph, ${variables.resourceSet}?: rdfjsResource.MutableResourceSet }`,
|
|
21
|
+
});
|
|
10
22
|
let usedIgnoreRdfTypeVariable = false;
|
|
11
|
-
const statements = [
|
|
23
|
+
const statements = [
|
|
24
|
+
`const ${variables.mutateGraph} = options?.${variables.mutateGraph};`,
|
|
25
|
+
`const ${variables.resourceSet} = options?.${variables.resourceSet} ?? new rdfjsResource.MutableResourceSet({ dataFactory, dataset: datasetFactory.dataset() });`,
|
|
26
|
+
];
|
|
12
27
|
if (this.parentObjectTypes.length > 0) {
|
|
13
28
|
const superToRdfOptions = `{ ${variables.ignoreRdfType}: true, ${variables.mutateGraph}, ${variables.resourceSet} }`;
|
|
14
29
|
let superToRdfCall;
|
|
@@ -42,17 +57,9 @@ export function toRdfFunctionOrMethodDeclaration() {
|
|
|
42
57
|
}));
|
|
43
58
|
}
|
|
44
59
|
statements.push(`return ${variables.resource};`);
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
parameters.push({
|
|
48
|
-
name: this.thisVariable,
|
|
49
|
-
type: this.name,
|
|
50
|
-
});
|
|
60
|
+
if (usedIgnoreRdfTypeVariable) {
|
|
61
|
+
statements.unshift(`const ${variables.ignoreRdfType} = !!options?.ignoreRdfType;`);
|
|
51
62
|
}
|
|
52
|
-
parameters.push({
|
|
53
|
-
name: `{ ${usedIgnoreRdfTypeVariable ? `${variables.ignoreRdfType}, ` : ""}${variables.mutateGraph}, ${variables.resourceSet} }`,
|
|
54
|
-
type: `{ ${variables.ignoreRdfType}?: boolean; ${variables.mutateGraph}?: rdfjsResource.MutableResource.MutateGraph, ${variables.resourceSet}: rdfjsResource.MutableResourceSet }`,
|
|
55
|
-
});
|
|
56
63
|
return Maybe.of({
|
|
57
64
|
name: `${syntheticNamePrefix}toRdf`,
|
|
58
65
|
parameters,
|
|
@@ -63,7 +70,7 @@ export function toRdfFunctionOrMethodDeclaration() {
|
|
|
63
70
|
const variables = {
|
|
64
71
|
ignoreRdfType: "ignoreRdfType",
|
|
65
72
|
mutateGraph: "mutateGraph",
|
|
66
|
-
resource: "
|
|
73
|
+
resource: "resource",
|
|
67
74
|
resourceSet: "resourceSet",
|
|
68
75
|
};
|
|
69
76
|
//# sourceMappingURL=toRdfFunctionOrMethodDeclaration.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ClassDeclarationStructure } from "ts-morph";
|
|
2
|
+
import type { ObjectType } from "./ObjectType.js";
|
|
3
|
+
import type { ObjectUnionType } from "./ObjectUnionType.js";
|
|
4
|
+
export declare function forwardingObjectSetClassDeclaration({ objectTypes, objectUnionTypes, }: {
|
|
5
|
+
objectTypes: readonly ObjectType[];
|
|
6
|
+
objectUnionTypes: readonly ObjectUnionType[];
|
|
7
|
+
}): ClassDeclarationStructure;
|
|
8
|
+
//# sourceMappingURL=forwardingObjectSetClassDeclaration.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Scope, StructureKind } from "ts-morph";
|
|
2
|
+
import { objectSetMethodSignatures } from "./objectSetMethodSignatures.js";
|
|
3
|
+
import { syntheticNamePrefix } from "./syntheticNamePrefix.js";
|
|
4
|
+
export function forwardingObjectSetClassDeclaration({ objectTypes, objectUnionTypes, }) {
|
|
5
|
+
const delegateName = `${syntheticNamePrefix}delegate`;
|
|
6
|
+
return {
|
|
7
|
+
getAccessors: [
|
|
8
|
+
{
|
|
9
|
+
isAbstract: true,
|
|
10
|
+
name: delegateName,
|
|
11
|
+
scope: Scope.Protected,
|
|
12
|
+
returnType: `${syntheticNamePrefix}ObjectSet`,
|
|
13
|
+
},
|
|
14
|
+
],
|
|
15
|
+
implements: [`${syntheticNamePrefix}ObjectSet`],
|
|
16
|
+
isAbstract: true,
|
|
17
|
+
isExported: true,
|
|
18
|
+
kind: StructureKind.Class,
|
|
19
|
+
name: `${syntheticNamePrefix}ForwardingObjectSet`,
|
|
20
|
+
methods: [...objectTypes, ...objectUnionTypes].flatMap((objectType) => Object.values(objectSetMethodSignatures({ objectType })).map((methodSignature) => ({
|
|
21
|
+
...methodSignature,
|
|
22
|
+
kind: StructureKind.Method,
|
|
23
|
+
statements: [
|
|
24
|
+
`return this.${delegateName}.${methodSignature.name}(${methodSignature.parameters.map((parameter) => parameter.name).join(", ")});`,
|
|
25
|
+
],
|
|
26
|
+
}))),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=forwardingObjectSetClassDeclaration.js.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { forwardingObjectSetClassDeclaration } from "./forwardingObjectSetClassDeclaration.js";
|
|
1
2
|
import { objectSetInterfaceDeclaration } from "./objectSetInterfaceDeclaration.js";
|
|
2
3
|
import { rdfjsDatasetObjectSetClassDeclaration } from "./rdfjsDatasetObjectSetClassDeclaration.js";
|
|
3
4
|
import { sparqlObjectSetClassDeclaration } from "./sparqlObjectSetClassDeclaration.js";
|
|
@@ -41,6 +42,7 @@ export function objectSetDeclarations({ objectUnionTypes, ...parameters }) {
|
|
|
41
42
|
objectTypes,
|
|
42
43
|
objectUnionTypes,
|
|
43
44
|
}),
|
|
45
|
+
forwardingObjectSetClassDeclaration({ objectTypes, objectUnionTypes }),
|
|
44
46
|
];
|
|
45
47
|
if (objectTypesWithRdfFeatureCount > 0) {
|
|
46
48
|
statements.push(rdfjsDatasetObjectSetClassDeclaration({
|
|
@@ -13,13 +13,14 @@ export function rdfjsDatasetObjectSetClassDeclaration({ objectTypes, objectUnion
|
|
|
13
13
|
name: "ObjectIdentifierT",
|
|
14
14
|
},
|
|
15
15
|
};
|
|
16
|
-
const fromRdfFunctionType = `(
|
|
16
|
+
const fromRdfFunctionType = `(resource: rdfjsResource.Resource, options: { objectSet: ${syntheticNamePrefix}ObjectSet }) => purify.Either<Error, ${typeParameters.ObjectT.name}>`;
|
|
17
|
+
const objectTypeType = `{ ${syntheticNamePrefix}fromRdf: ${fromRdfFunctionType}; ${syntheticNamePrefix}fromRdfTypes: readonly rdfjs.NamedNode[] }`;
|
|
17
18
|
const reusableMethodDeclarations = [];
|
|
18
19
|
if (objectTypes.length > 0) {
|
|
19
20
|
const parameters = {
|
|
20
21
|
objectType: {
|
|
21
22
|
name: "objectType",
|
|
22
|
-
type:
|
|
23
|
+
type: objectTypeType,
|
|
23
24
|
},
|
|
24
25
|
query: {
|
|
25
26
|
hasQuestionToken: true,
|
|
@@ -84,7 +85,7 @@ if (query?.where) {
|
|
|
84
85
|
|
|
85
86
|
const objects: ${typeParameters.ObjectT.name}[] = [];
|
|
86
87
|
for (const identifier of identifiers) {
|
|
87
|
-
const either = objectType.${syntheticNamePrefix}fromRdf(
|
|
88
|
+
const either = objectType.${syntheticNamePrefix}fromRdf(this.resourceSet.resource(identifier), { objectSet: this });
|
|
88
89
|
if (either.isLeft()) {
|
|
89
90
|
return either;
|
|
90
91
|
}
|
|
@@ -93,18 +94,25 @@ if (query?.where) {
|
|
|
93
94
|
return purify.Either.of(objects);
|
|
94
95
|
}
|
|
95
96
|
|
|
96
|
-
if (
|
|
97
|
+
if (objectType.${syntheticNamePrefix}fromRdfTypes.length === 0) {
|
|
97
98
|
return purify.Either.of([]);
|
|
98
99
|
}
|
|
99
100
|
|
|
100
|
-
const resources = [
|
|
101
|
+
const resources: rdfjsResource.Resource[] = [];
|
|
102
|
+
for (const fromRdfType of objectType.${syntheticNamePrefix}fromRdfTypes) {
|
|
103
|
+
for (const resource of this.resourceSet.instancesOf(fromRdfType)) {
|
|
104
|
+
if (!resources.some(existingResource => existingResource.identifier.equals(resource.identifier))) {
|
|
105
|
+
resources.push(resource);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
101
109
|
// Sort resources by identifier so limit and offset are deterministic
|
|
102
110
|
resources.sort((left, right) => left.identifier.value.localeCompare(right.identifier.value));
|
|
103
111
|
|
|
104
112
|
const objects: ${typeParameters.ObjectT.name}[] = [];
|
|
105
113
|
let objectI = 0;
|
|
106
114
|
for (const resource of resources) {
|
|
107
|
-
const either = objectType.${syntheticNamePrefix}fromRdf({ objectSet: this
|
|
115
|
+
const either = objectType.${syntheticNamePrefix}fromRdf(resource, { objectSet: this });
|
|
108
116
|
if (either.isLeft()) {
|
|
109
117
|
return either;
|
|
110
118
|
}
|
|
@@ -138,7 +146,6 @@ return purify.Either.of(objects);
|
|
|
138
146
|
});
|
|
139
147
|
}
|
|
140
148
|
if (objectUnionTypes.length > 0) {
|
|
141
|
-
const objectTypeType = `{ ${syntheticNamePrefix}fromRdf: ${fromRdfFunctionType}; ${syntheticNamePrefix}fromRdfType?: rdfjs.NamedNode }`;
|
|
142
149
|
const parameters = {
|
|
143
150
|
objectTypes: {
|
|
144
151
|
name: "objectTypes",
|
|
@@ -209,7 +216,7 @@ if (query?.where) {
|
|
|
209
216
|
const resource = this.resourceSet.resource(identifier);
|
|
210
217
|
const lefts: purify.Either<Error, ${typeParameters.ObjectT.name}>[] = [];
|
|
211
218
|
for (const objectType of objectTypes) {
|
|
212
|
-
const either = objectType.${syntheticNamePrefix}fromRdf({ objectSet: this
|
|
219
|
+
const either = objectType.${syntheticNamePrefix}fromRdf(resource, { objectSet: this });
|
|
213
220
|
if (either.isRight()) {
|
|
214
221
|
objects.push(either.unsafeCoerce());
|
|
215
222
|
break;
|
|
@@ -226,22 +233,25 @@ if (query?.where) {
|
|
|
226
233
|
|
|
227
234
|
const resources: { objectType: ${objectTypeType}, resource: rdfjsResource.Resource }[] = [];
|
|
228
235
|
for (const objectType of objectTypes) {
|
|
229
|
-
if (
|
|
236
|
+
if (objectType.${syntheticNamePrefix}fromRdfTypes.length === 0) {
|
|
230
237
|
continue;
|
|
231
238
|
}
|
|
232
239
|
|
|
233
|
-
for (const
|
|
234
|
-
|
|
240
|
+
for (const fromRdfType of objectType.${syntheticNamePrefix}fromRdfTypes) {
|
|
241
|
+
for (const resource of this.resourceSet.instancesOf(fromRdfType)) {
|
|
242
|
+
if (!resources.some(({ resource: existingResource }) => existingResource.identifier.equals(resource.identifier))) {
|
|
243
|
+
resources.push({ objectType, resource });
|
|
244
|
+
}
|
|
245
|
+
}
|
|
235
246
|
}
|
|
236
247
|
}
|
|
237
|
-
|
|
238
248
|
// Sort resources by identifier so limit and offset are deterministic
|
|
239
249
|
resources.sort((left, right) => left.resource.identifier.value.localeCompare(right.resource.identifier.value));
|
|
240
250
|
|
|
241
251
|
let objectI = 0;
|
|
242
252
|
const objects: ${typeParameters.ObjectT.name}[] = [];
|
|
243
253
|
for (const { objectType, resource } of resources) {
|
|
244
|
-
const either = objectType.${syntheticNamePrefix}fromRdf({ objectSet: this
|
|
254
|
+
const either = objectType.${syntheticNamePrefix}fromRdf(resource, { objectSet: this });
|
|
245
255
|
if (either.isLeft()) {
|
|
246
256
|
return either;
|
|
247
257
|
}
|
|
@@ -300,16 +310,13 @@ return purify.Either.of(objects);
|
|
|
300
310
|
}
|
|
301
311
|
const methodSignatures = objectSetMethodSignatures({ objectType });
|
|
302
312
|
let runtimeObjectType;
|
|
313
|
+
const runtimeObjectType_ = (objectType) => `{ ${syntheticNamePrefix}fromRdf: ${objectType.staticModuleName}.${syntheticNamePrefix}fromRdf, ${syntheticNamePrefix}fromRdfTypes: [${objectType.fromRdfTypeVariable.toList().concat(objectType.descendantFromRdfTypeVariables).join(", ")}] }`;
|
|
303
314
|
switch (objectType.kind) {
|
|
304
315
|
case "ObjectType":
|
|
305
|
-
runtimeObjectType = objectType
|
|
306
|
-
? `${objectType.staticModuleName}`
|
|
307
|
-
: `{ ...${objectType.staticModuleName}, ${syntheticNamePrefix}fromRdfType: undefined }`;
|
|
316
|
+
runtimeObjectType = runtimeObjectType_(objectType);
|
|
308
317
|
break;
|
|
309
318
|
case "ObjectUnionType":
|
|
310
|
-
runtimeObjectType = `[${objectType.memberTypes.map((memberType) => memberType.
|
|
311
|
-
? `${memberType.staticModuleName}`
|
|
312
|
-
: `{ ...${memberType.staticModuleName}, ${syntheticNamePrefix}fromRdfType: undefined }`)}]`;
|
|
319
|
+
runtimeObjectType = `[${objectType.memberTypes.map((memberType) => runtimeObjectType_(memberType)).join(", ")}]`;
|
|
313
320
|
break;
|
|
314
321
|
}
|
|
315
322
|
return [
|
|
@@ -8,11 +8,11 @@ export function rdfjsTermExpression(rdfjsTerm) {
|
|
|
8
8
|
case "Literal":
|
|
9
9
|
if (rdfjsTerm.datatype.equals(xsd.string)) {
|
|
10
10
|
if (rdfjsTerm.language.length === 0) {
|
|
11
|
-
return `dataFactory.literal(
|
|
11
|
+
return `dataFactory.literal(${JSON.stringify(rdfjsTerm.value)})`;
|
|
12
12
|
}
|
|
13
|
-
return `dataFactory.literal(
|
|
13
|
+
return `dataFactory.literal(${JSON.stringify(rdfjsTerm.value)}, "${rdfjsTerm.language}")`;
|
|
14
14
|
}
|
|
15
|
-
return `dataFactory.literal(
|
|
15
|
+
return `dataFactory.literal(${JSON.stringify(rdfjsTerm.value)}, ${rdfjsTermExpression(rdfjsTerm.datatype)})`;
|
|
16
16
|
case "NamedNode": {
|
|
17
17
|
if (rdfjsTerm.value.startsWith(rdf[""].value)) {
|
|
18
18
|
const unqualifiedName = rdfjsTerm.value.substring(rdf[""].value.length);
|