@shaclmate/compiler 2.0.22 → 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 +6 -5
- package/dist/ShapesGraphToAstTransformer.js +61 -17
- 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/flattenAstObjectCompositeTypeMemberTypes.d.ts +13 -0
- package/dist/_ShapesGraphToAstTransformer/flattenAstObjectCompositeTypeMemberTypes.js +51 -0
- package/dist/_ShapesGraphToAstTransformer/index.d.ts +5 -5
- package/dist/_ShapesGraphToAstTransformer/index.js +5 -5
- package/dist/_ShapesGraphToAstTransformer/shapeAstName.js +53 -12
- package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.d.ts +5 -0
- package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.js +130 -54
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +175 -5
- 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/Ast.d.ts +0 -1
- package/dist/ast/Curie.d.ts +14 -0
- package/dist/ast/Curie.js +21 -0
- package/dist/ast/IdentifierType.d.ts +3 -2
- package/dist/ast/ListType.d.ts +2 -1
- package/dist/ast/LiteralType.d.ts +1 -1
- package/dist/ast/Name.d.ts +40 -5
- package/dist/ast/ObjectCompositeType.d.ts +11 -0
- package/dist/ast/ObjectType.d.ts +18 -13
- package/dist/ast/ObjectUnionType.d.ts +0 -11
- package/dist/ast/OptionType.d.ts +2 -4
- package/dist/ast/SetType.d.ts +2 -7
- package/dist/ast/TermType.d.ts +12 -4
- package/dist/ast/Type.d.ts +1 -1
- package/dist/ast/index.d.ts +1 -0
- package/dist/ast/index.js +1 -0
- package/dist/enums/TsFeature.d.ts +1 -4
- package/dist/enums/TsFeature.js +1 -15
- package/dist/generators/json/AstJsonGenerator.js +26 -4
- package/dist/generators/ts/BooleanType.d.ts +4 -2
- package/dist/generators/ts/BooleanType.js +12 -3
- package/dist/generators/ts/DateTimeType.d.ts +9 -8
- package/dist/generators/ts/DateTimeType.js +32 -8
- package/dist/generators/ts/DateType.d.ts +5 -2
- package/dist/generators/ts/DateType.js +15 -1
- package/dist/generators/ts/DeclaredType.d.ts +2 -2
- package/dist/generators/ts/DeclaredType.js +2 -2
- package/dist/generators/ts/FloatType.d.ts +6 -0
- package/dist/generators/ts/FloatType.js +18 -0
- package/dist/generators/ts/IdentifierType.d.ts +17 -7
- package/dist/generators/ts/IdentifierType.js +112 -18
- package/dist/generators/ts/Import.d.ts +2 -0
- package/dist/generators/ts/Import.js +10 -0
- package/dist/generators/ts/IntType.d.ts +6 -0
- package/dist/generators/ts/IntType.js +18 -0
- package/dist/generators/ts/ListType.d.ts +15 -12
- package/dist/generators/ts/ListType.js +113 -61
- package/dist/generators/ts/LiteralType.d.ts +17 -9
- package/dist/generators/ts/LiteralType.js +92 -17
- package/dist/generators/ts/NumberType.d.ts +3 -2
- package/dist/generators/ts/NumberType.js +8 -3
- package/dist/generators/ts/ObjectType.d.ts +65 -43
- package/dist/generators/ts/ObjectType.js +143 -123
- package/dist/generators/ts/ObjectUnionType.d.ts +50 -8
- package/dist/generators/ts/ObjectUnionType.js +303 -101
- package/dist/generators/ts/OptionType.d.ts +14 -10
- package/dist/generators/ts/OptionType.js +62 -34
- package/dist/generators/ts/PrimitiveType.d.ts +23 -5
- package/dist/generators/ts/PrimitiveType.js +34 -6
- package/dist/generators/ts/SetType.d.ts +17 -13
- package/dist/generators/ts/SetType.js +76 -44
- package/dist/generators/ts/SnippetDeclarations.d.ts +13 -8
- package/dist/generators/ts/SnippetDeclarations.js +226 -101
- package/dist/generators/ts/StringType.d.ts +4 -2
- package/dist/generators/ts/StringType.js +20 -8
- package/dist/generators/ts/TermType.d.ts +29 -33
- package/dist/generators/ts/TermType.js +89 -68
- package/dist/generators/ts/TsGenerator.d.ts +2 -1
- package/dist/generators/ts/TsGenerator.js +26 -12
- package/dist/generators/ts/Type.d.ts +100 -32
- package/dist/generators/ts/Type.js +58 -54
- package/dist/generators/ts/TypeFactory.d.ts +12 -5
- package/dist/generators/ts/TypeFactory.js +380 -226
- package/dist/generators/ts/UnionType.d.ts +14 -10
- package/dist/generators/ts/UnionType.js +319 -142
- package/dist/generators/ts/_ObjectType/EagerShaclProperty.d.ts +12 -0
- package/dist/generators/ts/_ObjectType/EagerShaclProperty.js +31 -0
- package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.d.ts +13 -12
- package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.js +59 -46
- package/dist/generators/ts/_ObjectType/IdentifierProperty.d.ts +20 -13
- package/dist/generators/ts/_ObjectType/IdentifierProperty.js +198 -140
- package/dist/generators/ts/_ObjectType/LazyShaclProperty.d.ts +100 -0
- package/dist/generators/ts/_ObjectType/LazyShaclProperty.js +315 -0
- package/dist/generators/ts/_ObjectType/Property.d.ts +47 -46
- package/dist/generators/ts/_ObjectType/Property.js +1 -10
- package/dist/generators/ts/_ObjectType/ShaclProperty.d.ts +25 -30
- package/dist/generators/ts/_ObjectType/ShaclProperty.js +120 -85
- package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +21 -17
- package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +61 -53
- package/dist/generators/ts/_ObjectType/classDeclaration.js +22 -17
- package/dist/generators/ts/_ObjectType/createFunctionDeclaration.js +26 -13
- package/dist/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.js +8 -5
- package/dist/generators/ts/_ObjectType/fromRdfTypeVariableStatement.d.ts +1 -1
- package/dist/generators/ts/_ObjectType/fromRdfTypeVariableStatement.js +8 -5
- package/dist/generators/ts/_ObjectType/graphqlTypeVariableStatement.d.ts +5 -0
- package/dist/generators/ts/_ObjectType/graphqlTypeVariableStatement.js +49 -0
- package/dist/generators/ts/_ObjectType/hashFunctionOrMethodDeclarations.js +7 -8
- package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.d.ts +7 -0
- package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.js +54 -0
- package/dist/generators/ts/_ObjectType/index.d.ts +9 -7
- package/dist/generators/ts/_ObjectType/index.js +9 -7
- package/dist/generators/ts/_ObjectType/interfaceDeclaration.js +1 -1
- package/dist/generators/ts/_ObjectType/jsonFunctionDeclarations.d.ts +4 -0
- package/dist/generators/ts/_ObjectType/jsonFunctionDeclarations.js +189 -0
- package/dist/generators/ts/_ObjectType/jsonTypeAliasDeclaration.d.ts +5 -0
- package/dist/generators/ts/_ObjectType/jsonTypeAliasDeclaration.js +28 -0
- package/dist/generators/ts/_ObjectType/objectSetMethodNames.d.ts +9 -0
- package/dist/generators/ts/_ObjectType/objectSetMethodNames.js +18 -0
- package/dist/generators/ts/_ObjectType/propertiesVariableStatement.d.ts +5 -0
- package/dist/generators/ts/_ObjectType/propertiesVariableStatement.js +37 -0
- package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.d.ts +4 -0
- package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.js +144 -0
- package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.d.ts +1 -1
- package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.js +6 -5
- package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.d.ts +1 -1
- package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.js +4 -3
- package/dist/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +109 -37
- package/dist/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.js +6 -6
- package/dist/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.js +33 -24
- package/dist/generators/ts/graphqlSchemaVariableStatement.d.ts +9 -0
- package/dist/generators/ts/graphqlSchemaVariableStatement.js +86 -0
- package/dist/generators/ts/objectSetDeclarations.d.ts +8 -0
- package/dist/generators/ts/objectSetDeclarations.js +59 -0
- package/dist/generators/ts/objectSetInterfaceDeclaration.d.ts +8 -0
- package/dist/generators/ts/objectSetInterfaceDeclaration.js +46 -0
- package/dist/generators/ts/objectSetMethodSignatures.d.ts +11 -0
- package/dist/generators/ts/objectSetMethodSignatures.js +52 -0
- package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.d.ts +8 -0
- package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +393 -0
- package/dist/generators/ts/rdfjsTermExpression.d.ts +3 -0
- package/dist/generators/ts/rdfjsTermExpression.js +57 -0
- package/dist/generators/ts/sparqlObjectSetClassDeclaration.d.ts +8 -0
- package/dist/generators/ts/sparqlObjectSetClassDeclaration.js +415 -0
- package/dist/generators/ts/syntheticNamePrefix.d.ts +2 -0
- package/dist/generators/ts/syntheticNamePrefix.js +2 -0
- package/dist/generators/ts/tsName.js +27 -13
- package/dist/generators/ts/unsupportedObjectSetMethodDeclarations.d.ts +10 -0
- package/dist/generators/ts/unsupportedObjectSetMethodDeclarations.js +19 -0
- package/dist/input/NodeShape.d.ts +6 -8
- package/dist/input/NodeShape.js +20 -44
- package/dist/input/Ontology.d.ts +0 -3
- package/dist/input/Ontology.js +0 -9
- package/dist/input/PropertyPath.d.ts +5 -5
- package/dist/input/PropertyPath.js +14 -24
- package/dist/input/PropertyShape.d.ts +3 -1
- package/dist/input/PropertyShape.js +8 -2
- package/dist/input/ShapesGraph.js +4 -8
- package/dist/input/generated.d.ts +967 -107
- package/dist/input/generated.js +2548 -1046
- package/dist/input/tsFeatures.d.ts +3 -2
- package/dist/input/tsFeatures.js +44 -27
- package/package.json +18 -16
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.d.ts +0 -13
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +0 -200
- 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 -16
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.js +0 -60
- package/dist/generators/ts/_ObjectType/fromJsonFunctionDeclarations.d.ts +0 -4
- package/dist/generators/ts/_ObjectType/fromJsonFunctionDeclarations.js +0 -78
- package/dist/generators/ts/_ObjectType/fromRdfFunctionDeclarations.d.ts +0 -4
- package/dist/generators/ts/_ObjectType/fromRdfFunctionDeclarations.js +0 -91
- package/dist/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.js +0 -19
- package/dist/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.js +0 -31
- package/dist/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.js +0 -37
- package/dist/generators/ts/_ObjectType/rdfjsTermExpression.d.ts +0 -6
- package/dist/generators/ts/_ObjectType/rdfjsTermExpression.js +0 -17
- package/dist/generators/ts/_ObjectType/toJsonFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/toJsonFunctionDeclaration.js +0 -19
- package/dist/generators/ts/_ObjectType/toJsonReturnType.d.ts +0 -3
- package/dist/generators/ts/_ObjectType/toJsonReturnType.js +0 -17
- package/dist/generators/ts/_ObjectType/toRdfFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/toRdfFunctionDeclaration.js +0 -19
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { camelCase, trainCase } from "change-case";
|
|
2
|
+
import plur from "plur";
|
|
3
|
+
export function objectSetMethodNames() {
|
|
4
|
+
const prefixSingular = camelCase(this.name);
|
|
5
|
+
const thisNameParts = trainCase(this.name).split("-");
|
|
6
|
+
let prefixPlural = camelCase(`${thisNameParts.slice(0, thisNameParts.length - 1).join("")}${plur(thisNameParts[thisNameParts.length - 1])}`);
|
|
7
|
+
if (prefixPlural === prefixSingular) {
|
|
8
|
+
// Happens with singular-s nouns like "series"
|
|
9
|
+
prefixPlural = `${prefixPlural}s`;
|
|
10
|
+
}
|
|
11
|
+
return {
|
|
12
|
+
object: prefixSingular,
|
|
13
|
+
objectIdentifiers: `${prefixSingular}Identifiers`,
|
|
14
|
+
objects: prefixPlural,
|
|
15
|
+
objectsCount: `${prefixPlural}Count`,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=objectSetMethodNames.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
2
|
+
import { type VariableStatementStructure } from "ts-morph";
|
|
3
|
+
import type { ObjectType } from "../ObjectType.js";
|
|
4
|
+
export declare function propertiesVariableStatement(this: ObjectType): Maybe<VariableStatementStructure>;
|
|
5
|
+
//# sourceMappingURL=propertiesVariableStatement.d.ts.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
2
|
+
import { StructureKind, VariableDeclarationKind, } from "ts-morph";
|
|
3
|
+
import { objectInitializer } from "../objectInitializer.js";
|
|
4
|
+
import { rdfjsTermExpression } from "../rdfjsTermExpression.js";
|
|
5
|
+
import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
|
|
6
|
+
import { ShaclProperty } from "./ShaclProperty.js";
|
|
7
|
+
export function propertiesVariableStatement() {
|
|
8
|
+
if (this.extern) {
|
|
9
|
+
return Maybe.empty();
|
|
10
|
+
}
|
|
11
|
+
const propertiesObject = [];
|
|
12
|
+
for (const parentObjectType of this.parentObjectTypes) {
|
|
13
|
+
propertiesObject.push(`...${parentObjectType.staticModuleName}.${syntheticNamePrefix}properties`);
|
|
14
|
+
}
|
|
15
|
+
for (const property of this.properties) {
|
|
16
|
+
if (!(property instanceof ShaclProperty)) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
const propertyObject = {};
|
|
20
|
+
if (this.features.has("rdf")) {
|
|
21
|
+
propertyObject["identifier"] = rdfjsTermExpression(property.path);
|
|
22
|
+
}
|
|
23
|
+
propertiesObject.push(`${property.name}: ${objectInitializer(propertyObject)}`);
|
|
24
|
+
}
|
|
25
|
+
return Maybe.of({
|
|
26
|
+
declarationKind: VariableDeclarationKind.Const,
|
|
27
|
+
kind: StructureKind.VariableStatement,
|
|
28
|
+
declarations: [
|
|
29
|
+
{
|
|
30
|
+
name: `${syntheticNamePrefix}properties`,
|
|
31
|
+
initializer: `{${propertiesObject.join(", ")}}`,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
isExported: true,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=propertiesVariableStatement.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type FunctionDeclarationStructure } from "ts-morph";
|
|
2
|
+
import type { ObjectType } from "../ObjectType.js";
|
|
3
|
+
export declare function rdfFunctionDeclarations(this: ObjectType): readonly FunctionDeclarationStructure[];
|
|
4
|
+
//# sourceMappingURL=rdfFunctionDeclarations.d.ts.map
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { rdf } from "@tpluscode/rdf-ns-builders";
|
|
2
|
+
import { Maybe } from "purify-ts";
|
|
3
|
+
import { invariant } from "ts-invariant";
|
|
4
|
+
import { StructureKind } from "ts-morph";
|
|
5
|
+
import { rdfjsTermExpression } from "../rdfjsTermExpression.js";
|
|
6
|
+
import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
|
|
7
|
+
import { toRdfFunctionOrMethodDeclaration } from "./toRdfFunctionOrMethodDeclaration.js";
|
|
8
|
+
function fromRdfFunctionDeclaration() {
|
|
9
|
+
const statements = [];
|
|
10
|
+
statements.push("let { ignoreRdfType = false, languageIn, objectSet, ...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, languageIn, objectSet, 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; languageIn?: readonly string[]; objectSet?: ${syntheticNamePrefix}ObjectSet; }`,
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
returnType: `purify.Either<Error, ${this.name}>`,
|
|
58
|
+
statements: statements,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
function propertiesFromRdfFunctionDeclaration() {
|
|
62
|
+
const initializers = [];
|
|
63
|
+
const propertySignatures = [];
|
|
64
|
+
const returnType = [];
|
|
65
|
+
const statements = [];
|
|
66
|
+
this.parentObjectTypes.forEach((parentObjectType, parentObjectTypeI) => {
|
|
67
|
+
statements.push(`const ${syntheticNamePrefix}super${parentObjectTypeI}Either = ${parentObjectType.staticModuleName}.${syntheticNamePrefix}propertiesFromRdf({ ...${variables.context}, ignoreRdfType: true, languageIn: ${variables.languageIn}, objectSet: ${variables.objectSet}, resource: ${variables.resource} });`, `if (${syntheticNamePrefix}super${parentObjectTypeI}Either.isLeft()) { return ${syntheticNamePrefix}super${parentObjectTypeI}Either; }`, `const ${syntheticNamePrefix}super${parentObjectTypeI} = ${syntheticNamePrefix}super${parentObjectTypeI}Either.unsafeCoerce()`);
|
|
68
|
+
initializers.push(`...${syntheticNamePrefix}super${parentObjectTypeI}`);
|
|
69
|
+
returnType.push(`${syntheticNamePrefix}UnwrapR<ReturnType<typeof ${parentObjectType.staticModuleName}.${syntheticNamePrefix}propertiesFromRdf>>`);
|
|
70
|
+
});
|
|
71
|
+
this.fromRdfType.ifJust((rdfType) => {
|
|
72
|
+
const predicate = rdfjsTermExpression(rdf.type);
|
|
73
|
+
statements.push(`\
|
|
74
|
+
if (!${variables.ignoreRdfType} && !${variables.resource}.isInstanceOf(${syntheticNamePrefix}fromRdfType)) {
|
|
75
|
+
return ${variables.resource}.value(${predicate}).chain(actualRdfType => actualRdfType.toIri()).chain((actualRdfType) => purify.Left(new Error(\`\${rdfjsResource.Resource.Identifier.toString(${variables.resource}.identifier)} has unexpected RDF type (actual: \${actualRdfType.value}, expected: ${rdfType.value})\`)));
|
|
76
|
+
}`);
|
|
77
|
+
});
|
|
78
|
+
const propertyFromRdfVariables = {
|
|
79
|
+
context: variables.context,
|
|
80
|
+
languageIn: variables.languageIn,
|
|
81
|
+
objectSet: variables.objectSet,
|
|
82
|
+
resource: variables.resource,
|
|
83
|
+
};
|
|
84
|
+
for (const property of this.properties) {
|
|
85
|
+
const propertyFromRdfStatements = property.fromRdfStatements({
|
|
86
|
+
variables: propertyFromRdfVariables,
|
|
87
|
+
});
|
|
88
|
+
if (propertyFromRdfStatements.length > 0) {
|
|
89
|
+
statements.push(...propertyFromRdfStatements);
|
|
90
|
+
initializers.push(property.name);
|
|
91
|
+
propertySignatures.push(`${property.name}: ${property.type.name};`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
statements.push(`return purify.Either.of({ ${initializers.join(", ")} })`);
|
|
95
|
+
if (propertySignatures.length > 0) {
|
|
96
|
+
returnType.splice(0, 0, `{ ${propertySignatures.join(" ")} }`);
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
isExported: true,
|
|
100
|
+
kind: StructureKind.Function,
|
|
101
|
+
name: `${syntheticNamePrefix}propertiesFromRdf`,
|
|
102
|
+
parameters: [
|
|
103
|
+
{
|
|
104
|
+
name: `{ ignoreRdfType: ${variables.ignoreRdfType}, languageIn: ${variables.languageIn}, objectSet: ${variables.objectSet}, resource: ${variables.resource},\n// @ts-ignore\n...${variables.context} }`,
|
|
105
|
+
type: `{ [_index: string]: any; ignoreRdfType: boolean; languageIn?: readonly string[]; objectSet: ${syntheticNamePrefix}ObjectSet; resource: rdfjsResource.Resource; }`,
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
returnType: `purify.Either<Error, ${returnType.join(" & ")}>`,
|
|
109
|
+
statements: statements,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
export function rdfFunctionDeclarations() {
|
|
113
|
+
if (!this.features.has("rdf")) {
|
|
114
|
+
return [];
|
|
115
|
+
}
|
|
116
|
+
if (this.extern) {
|
|
117
|
+
return [];
|
|
118
|
+
}
|
|
119
|
+
return [
|
|
120
|
+
...fromRdfFunctionDeclaration.bind(this)().toList(),
|
|
121
|
+
propertiesFromRdfFunctionDeclaration.bind(this)(),
|
|
122
|
+
...toRdfFunctionDeclaration.bind(this)().toList(),
|
|
123
|
+
];
|
|
124
|
+
}
|
|
125
|
+
function toRdfFunctionDeclaration() {
|
|
126
|
+
if (this.declarationType !== "interface") {
|
|
127
|
+
return Maybe.empty();
|
|
128
|
+
}
|
|
129
|
+
return toRdfFunctionOrMethodDeclaration
|
|
130
|
+
.bind(this)()
|
|
131
|
+
.map((toRdfFunctionOrMethodDeclaration) => ({
|
|
132
|
+
...toRdfFunctionOrMethodDeclaration,
|
|
133
|
+
isExported: true,
|
|
134
|
+
kind: StructureKind.Function,
|
|
135
|
+
}));
|
|
136
|
+
}
|
|
137
|
+
const variables = {
|
|
138
|
+
context: `${syntheticNamePrefix}context`,
|
|
139
|
+
ignoreRdfType: `${syntheticNamePrefix}ignoreRdfType`,
|
|
140
|
+
languageIn: `${syntheticNamePrefix}languageIn`,
|
|
141
|
+
objectSet: `${syntheticNamePrefix}objectSet`,
|
|
142
|
+
resource: `${syntheticNamePrefix}resource`,
|
|
143
|
+
};
|
|
144
|
+
//# sourceMappingURL=rdfFunctionDeclarations.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type FunctionDeclarationStructure } from "ts-morph";
|
|
2
2
|
export declare function sparqlConstructQueryFunctionDeclaration(this: {
|
|
3
|
-
readonly
|
|
3
|
+
readonly staticModuleName: string;
|
|
4
4
|
}): FunctionDeclarationStructure;
|
|
5
5
|
//# sourceMappingURL=sparqlConstructQueryFunctionDeclaration.d.ts.map
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { StructureKind } from "ts-morph";
|
|
2
|
+
import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
|
|
2
3
|
export function sparqlConstructQueryFunctionDeclaration() {
|
|
3
4
|
return {
|
|
4
|
-
isExported: true,
|
|
5
5
|
kind: StructureKind.Function,
|
|
6
|
-
|
|
6
|
+
isExported: true,
|
|
7
|
+
name: `${syntheticNamePrefix}sparqlConstructQuery`,
|
|
7
8
|
parameters: [
|
|
8
9
|
{
|
|
9
10
|
hasQuestionToken: true,
|
|
10
11
|
name: "parameters",
|
|
11
|
-
type: '{ ignoreRdfType?: boolean; prefixes?: { [prefix: string]: string }; subject?: sparqljs.Triple["subject"]; } & Omit<sparqljs.ConstructQuery, "prefixes" | "queryType" | "type">',
|
|
12
|
+
type: '{ ignoreRdfType?: boolean; languageIn?: readonly string[]; prefixes?: { [prefix: string]: string }; subject?: sparqljs.Triple["subject"]; } & Omit<sparqljs.ConstructQuery, "prefixes" | "queryType" | "type">',
|
|
12
13
|
},
|
|
13
14
|
],
|
|
14
15
|
returnType: "sparqljs.ConstructQuery",
|
|
15
16
|
statements: [
|
|
16
|
-
"const { ignoreRdfType, subject, ...queryParameters } = parameters ?? {}",
|
|
17
|
-
`return { ...queryParameters, prefixes: parameters?.prefixes ?? {}, queryType: "CONSTRUCT", template: (queryParameters.template ?? []).concat(${this.
|
|
17
|
+
"const { ignoreRdfType, languageIn, 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, languageIn, subject })) };`,
|
|
18
19
|
],
|
|
19
20
|
};
|
|
20
21
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type FunctionDeclarationStructure } from "ts-morph";
|
|
2
2
|
export declare function sparqlConstructQueryStringFunctionDeclaration(this: {
|
|
3
|
-
readonly
|
|
3
|
+
readonly staticModuleName: string;
|
|
4
4
|
}): FunctionDeclarationStructure;
|
|
5
5
|
//# sourceMappingURL=sparqlConstructQueryStringFunctionDeclaration.d.ts.map
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { StructureKind } from "ts-morph";
|
|
2
|
+
import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
|
|
2
3
|
export function sparqlConstructQueryStringFunctionDeclaration() {
|
|
3
4
|
return {
|
|
4
5
|
isExported: true,
|
|
5
6
|
kind: StructureKind.Function,
|
|
6
|
-
name:
|
|
7
|
+
name: `${syntheticNamePrefix}sparqlConstructQueryString`,
|
|
7
8
|
parameters: [
|
|
8
9
|
{
|
|
9
10
|
hasQuestionToken: true,
|
|
10
11
|
name: "parameters",
|
|
11
|
-
type: '{ ignoreRdfType?: boolean; subject?: sparqljs.Triple["subject"]; variablePrefix?: string; } & Omit<sparqljs.ConstructQuery, "prefixes" | "queryType" | "type"> & sparqljs.GeneratorOptions',
|
|
12
|
+
type: '{ ignoreRdfType?: boolean; languageIn?: readonly string[]; subject?: sparqljs.Triple["subject"]; variablePrefix?: string; } & Omit<sparqljs.ConstructQuery, "prefixes" | "queryType" | "type"> & sparqljs.GeneratorOptions',
|
|
12
13
|
},
|
|
13
14
|
],
|
|
14
15
|
returnType: "string",
|
|
15
16
|
statements: [
|
|
16
|
-
`return new sparqljs.Generator(parameters).stringify(${this.
|
|
17
|
+
`return new sparqljs.Generator(parameters).stringify(${this.staticModuleName}.${syntheticNamePrefix}sparqlConstructQuery(parameters));`,
|
|
17
18
|
],
|
|
18
19
|
};
|
|
19
20
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { rdf } from "@tpluscode/rdf-ns-builders";
|
|
2
1
|
import { camelCase } from "change-case";
|
|
3
2
|
import { StructureKind } from "ts-morph";
|
|
3
|
+
import { rdf, rdfs } from "@tpluscode/rdf-ns-builders";
|
|
4
|
+
import { rdfjsTermExpression } from "../rdfjsTermExpression.js";
|
|
5
|
+
import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
|
|
4
6
|
import { sparqlConstructQueryFunctionDeclaration } from "./sparqlConstructQueryFunctionDeclaration.js";
|
|
5
7
|
import { sparqlConstructQueryStringFunctionDeclaration } from "./sparqlConstructQueryStringFunctionDeclaration.js";
|
|
6
8
|
export function sparqlFunctionDeclarations() {
|
|
@@ -10,68 +12,138 @@ export function sparqlFunctionDeclarations() {
|
|
|
10
12
|
if (this.extern) {
|
|
11
13
|
return [];
|
|
12
14
|
}
|
|
13
|
-
const variables = {
|
|
14
|
-
|
|
15
|
+
const variables = {
|
|
16
|
+
languageIn: "parameters?.languageIn",
|
|
17
|
+
subject: "subject",
|
|
18
|
+
variablePrefix: "variablePrefix",
|
|
19
|
+
};
|
|
20
|
+
const rdfClassVariable = `dataFactory.variable!(\`\${${variables.variablePrefix}}RdfClass\`)`;
|
|
21
|
+
const rdfTypeVariable = `dataFactory.variable!(\`\${${variables.variablePrefix}}RdfType\`)`;
|
|
15
22
|
const subjectDefault = camelCase(this.name);
|
|
16
|
-
const
|
|
17
|
-
`const subject = parameters?.subject ??
|
|
23
|
+
const sparqlConstructTemplateTriplesStatements = [
|
|
24
|
+
`const subject = parameters?.subject ?? dataFactory.variable!("${subjectDefault}");`,
|
|
25
|
+
"const triples: sparqljs.Triple[] = []",
|
|
18
26
|
`const variablePrefix = parameters?.variablePrefix ?? (subject.termType === "Variable" ? subject.value : "${subjectDefault}");`,
|
|
19
27
|
];
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
: []),
|
|
27
|
-
...this.ownProperties.flatMap((property) => property.sparqlConstructTemplateTriples({ variables })),
|
|
28
|
-
];
|
|
29
|
-
const sparqlWherePatterns = [
|
|
30
|
-
...this.parentObjectTypes.map((parentObjectType) => `...${parentObjectType.name}.sparqlWherePatterns({ ignoreRdfType: true, subject, variablePrefix })`),
|
|
31
|
-
...(this.fromRdfType.isJust()
|
|
32
|
-
? [
|
|
33
|
-
`...(parameters?.ignoreRdfType ? [] : [{ triples: [{ subject, predicate: ${this.rdfjsTermExpression(rdf.type)}, object: ${this.rdfjsTermExpression(this.fromRdfType.unsafeCoerce())} }], type: "bgp" as const }, { triples: [{ subject, predicate: ${this.rdfjsTermExpression(rdf.type)}, object: ${rdfTypeVariable} }], type: "bgp" as const }])`,
|
|
34
|
-
]
|
|
35
|
-
: []),
|
|
36
|
-
...this.ownProperties.flatMap((property) => property.sparqlWherePatterns({ variables })),
|
|
28
|
+
let nop = true;
|
|
29
|
+
const sparqlWherePatternsStatements = [
|
|
30
|
+
"const optionalPatterns: sparqljs.OptionalPattern[] = [];",
|
|
31
|
+
"const requiredPatterns: sparqljs.Pattern[] = [];",
|
|
32
|
+
`const subject = parameters?.subject ?? dataFactory.variable!("${subjectDefault}");`,
|
|
33
|
+
`const variablePrefix = parameters?.variablePrefix ?? (subject.termType === "Variable" ? subject.value : "${subjectDefault}");`,
|
|
37
34
|
];
|
|
35
|
+
for (const parentObjectType of this.parentObjectTypes) {
|
|
36
|
+
sparqlConstructTemplateTriplesStatements.push(`triples.push(...${parentObjectType.staticModuleName}.${syntheticNamePrefix}sparqlConstructTemplateTriples({ ignoreRdfType: true, subject, variablePrefix }));`);
|
|
37
|
+
sparqlWherePatternsStatements.push(`\
|
|
38
|
+
for (const pattern of ${parentObjectType.staticModuleName}.${syntheticNamePrefix}sparqlWherePatterns({ ignoreRdfType: true, subject, variablePrefix })) {
|
|
39
|
+
if (pattern.type === "optional") {
|
|
40
|
+
optionalPatterns.push(pattern);
|
|
41
|
+
} else {
|
|
42
|
+
requiredPatterns.push(pattern);
|
|
43
|
+
}
|
|
44
|
+
}`);
|
|
45
|
+
nop = false;
|
|
46
|
+
}
|
|
47
|
+
if (this.fromRdfType.isJust()) {
|
|
48
|
+
sparqlConstructTemplateTriplesStatements.push(`\
|
|
49
|
+
if (!parameters?.ignoreRdfType) {
|
|
50
|
+
triples.push(
|
|
51
|
+
{ subject, predicate: ${rdfjsTermExpression(rdf.type)}, object: ${rdfTypeVariable} },
|
|
52
|
+
{ subject: ${rdfTypeVariable}, predicate: ${rdfjsTermExpression(rdfs.subClassOf)}, object: ${rdfClassVariable} }
|
|
53
|
+
);
|
|
54
|
+
}`);
|
|
55
|
+
sparqlWherePatternsStatements.push(`\
|
|
56
|
+
if (!parameters?.ignoreRdfType) {
|
|
57
|
+
requiredPatterns.push(${syntheticNamePrefix}sparqlInstancesOfPattern({ rdfType: ${syntheticNamePrefix}fromRdfType, subject }));
|
|
58
|
+
requiredPatterns.push({
|
|
59
|
+
triples: [
|
|
60
|
+
{
|
|
61
|
+
subject,
|
|
62
|
+
predicate: ${rdfjsTermExpression(rdf.type)},
|
|
63
|
+
object: ${rdfTypeVariable}
|
|
64
|
+
}
|
|
65
|
+
],
|
|
66
|
+
type: "bgp" as const
|
|
67
|
+
});
|
|
68
|
+
optionalPatterns.push({
|
|
69
|
+
patterns: [
|
|
70
|
+
{
|
|
71
|
+
triples: [
|
|
72
|
+
{
|
|
73
|
+
subject: ${rdfTypeVariable},
|
|
74
|
+
predicate: {
|
|
75
|
+
items: [${rdfjsTermExpression(rdfs.subClassOf)}],
|
|
76
|
+
pathType: "+" as const,
|
|
77
|
+
type: "path" as const
|
|
78
|
+
},
|
|
79
|
+
object: ${rdfClassVariable}
|
|
80
|
+
}
|
|
81
|
+
],
|
|
82
|
+
type: "bgp" as const
|
|
83
|
+
}
|
|
84
|
+
],
|
|
85
|
+
type: "optional" as const
|
|
86
|
+
});
|
|
87
|
+
}`);
|
|
88
|
+
nop = false;
|
|
89
|
+
}
|
|
90
|
+
const propertySparqlWherePatterns = [];
|
|
91
|
+
for (const property of this.ownProperties) {
|
|
92
|
+
if (property.recursive) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
for (const triple of property.sparqlConstructTemplateTriples({
|
|
96
|
+
variables,
|
|
97
|
+
})) {
|
|
98
|
+
sparqlConstructTemplateTriplesStatements.push(`triples.push(${triple});`);
|
|
99
|
+
nop = false;
|
|
100
|
+
}
|
|
101
|
+
propertySparqlWherePatterns.push(...property.sparqlWherePatterns({ variables }));
|
|
102
|
+
}
|
|
103
|
+
if (propertySparqlWherePatterns.length > 0) {
|
|
104
|
+
sparqlWherePatternsStatements.push(`\
|
|
105
|
+
const propertyPatterns: readonly sparqljs.Pattern[] = [${propertySparqlWherePatterns.join(", ")}];
|
|
106
|
+
for (const pattern of propertyPatterns) {
|
|
107
|
+
if (pattern.type === "optional") {
|
|
108
|
+
optionalPatterns.push(pattern);
|
|
109
|
+
} else {
|
|
110
|
+
requiredPatterns.push(pattern);
|
|
111
|
+
}
|
|
112
|
+
}`);
|
|
113
|
+
nop = false;
|
|
114
|
+
}
|
|
115
|
+
sparqlConstructTemplateTriplesStatements.push("return triples;");
|
|
116
|
+
sparqlWherePatternsStatements.push("return requiredPatterns.concat(optionalPatterns);");
|
|
38
117
|
return [
|
|
39
118
|
sparqlConstructQueryFunctionDeclaration.bind(this)(),
|
|
40
119
|
sparqlConstructQueryStringFunctionDeclaration.bind(this)(),
|
|
41
120
|
{
|
|
42
121
|
isExported: true,
|
|
43
122
|
kind: StructureKind.Function,
|
|
44
|
-
name:
|
|
123
|
+
name: `${syntheticNamePrefix}sparqlConstructTemplateTriples`,
|
|
45
124
|
parameters: [
|
|
46
125
|
{
|
|
47
126
|
hasQuestionToken: true,
|
|
48
|
-
name: `${
|
|
127
|
+
name: `${nop ? "_" : ""}parameters`,
|
|
49
128
|
type: '{ ignoreRdfType?: boolean; subject?: sparqljs.Triple["subject"], variablePrefix?: string }',
|
|
50
129
|
},
|
|
51
130
|
],
|
|
52
131
|
returnType: "readonly sparqljs.Triple[]",
|
|
53
|
-
statements: [
|
|
54
|
-
...(sparqlConstructTemplateTriples.length > 0
|
|
55
|
-
? preambleStatements
|
|
56
|
-
: []),
|
|
57
|
-
`return [${sparqlConstructTemplateTriples.join(", ")}];`,
|
|
58
|
-
],
|
|
132
|
+
statements: nop ? "return [];" : sparqlConstructTemplateTriplesStatements,
|
|
59
133
|
},
|
|
60
134
|
{
|
|
61
135
|
isExported: true,
|
|
62
136
|
kind: StructureKind.Function,
|
|
63
|
-
name:
|
|
137
|
+
name: `${syntheticNamePrefix}sparqlWherePatterns`,
|
|
64
138
|
parameters: [
|
|
65
139
|
{
|
|
66
|
-
|
|
67
|
-
|
|
140
|
+
hasQuestionToken: true,
|
|
141
|
+
name: `${nop ? "_" : ""}parameters`,
|
|
142
|
+
type: '{ ignoreRdfType?: boolean; languageIn?: readonly string[]; subject?: sparqljs.Triple["subject"], variablePrefix?: string }',
|
|
68
143
|
},
|
|
69
144
|
],
|
|
70
145
|
returnType: "readonly sparqljs.Pattern[]",
|
|
71
|
-
statements: [
|
|
72
|
-
...(sparqlWherePatterns.length > 0 ? preambleStatements : []),
|
|
73
|
-
`return [${sparqlWherePatterns.join(", ")}];`,
|
|
74
|
-
],
|
|
146
|
+
statements: nop ? "return [];" : sparqlWherePatternsStatements,
|
|
75
147
|
},
|
|
76
148
|
];
|
|
77
149
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Maybe } from "purify-ts";
|
|
2
|
-
import {
|
|
2
|
+
import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
|
|
3
3
|
export function toJsonFunctionOrMethodDeclaration() {
|
|
4
|
-
if (!this.features.has("
|
|
4
|
+
if (!this.features.has("json")) {
|
|
5
5
|
return Maybe.empty();
|
|
6
6
|
}
|
|
7
7
|
if (this.declarationType === "class" &&
|
|
@@ -14,12 +14,12 @@ export function toJsonFunctionOrMethodDeclaration() {
|
|
|
14
14
|
switch (this.declarationType) {
|
|
15
15
|
case "class":
|
|
16
16
|
if (this.parentObjectTypes.length > 0) {
|
|
17
|
-
jsonObjectMembers.push(
|
|
17
|
+
jsonObjectMembers.push(`...super.${syntheticNamePrefix}toJson()`);
|
|
18
18
|
}
|
|
19
19
|
break;
|
|
20
20
|
case "interface":
|
|
21
21
|
for (const parentObjectType of this.parentObjectTypes) {
|
|
22
|
-
jsonObjectMembers.push(`...${parentObjectType.
|
|
22
|
+
jsonObjectMembers.push(`...${parentObjectType.staticModuleName}.${syntheticNamePrefix}toJson(${this.thisVariable})`);
|
|
23
23
|
}
|
|
24
24
|
parameters.push({
|
|
25
25
|
name: this.thisVariable,
|
|
@@ -48,9 +48,9 @@ export function toJsonFunctionOrMethodDeclaration() {
|
|
|
48
48
|
// break;
|
|
49
49
|
// }
|
|
50
50
|
return Maybe.of({
|
|
51
|
-
name:
|
|
51
|
+
name: `${syntheticNamePrefix}toJson`,
|
|
52
52
|
parameters,
|
|
53
|
-
returnType:
|
|
53
|
+
returnType: this.jsonName.toString(),
|
|
54
54
|
statements: [
|
|
55
55
|
`return JSON.parse(JSON.stringify({ ${jsonObjectMembers.join(",")} } satisfies ${this.jsonName}));`,
|
|
56
56
|
],
|
|
@@ -1,27 +1,38 @@
|
|
|
1
|
-
import { rdf } from "@tpluscode/rdf-ns-builders";
|
|
2
1
|
import { Maybe } from "purify-ts";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
resource: "_resource",
|
|
7
|
-
resourceSet: "resourceSet",
|
|
8
|
-
};
|
|
2
|
+
import { rdf } from "@tpluscode/rdf-ns-builders";
|
|
3
|
+
import { rdfjsTermExpression } from "../rdfjsTermExpression.js";
|
|
4
|
+
import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
|
|
9
5
|
export function toRdfFunctionOrMethodDeclaration() {
|
|
10
|
-
if (!this.features.has("
|
|
6
|
+
if (!this.features.has("rdf")) {
|
|
11
7
|
return Maybe.empty();
|
|
12
8
|
}
|
|
13
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
|
+
});
|
|
14
22
|
let usedIgnoreRdfTypeVariable = false;
|
|
15
|
-
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
|
+
];
|
|
16
27
|
if (this.parentObjectTypes.length > 0) {
|
|
17
28
|
const superToRdfOptions = `{ ${variables.ignoreRdfType}: true, ${variables.mutateGraph}, ${variables.resourceSet} }`;
|
|
18
29
|
let superToRdfCall;
|
|
19
30
|
switch (this.declarationType) {
|
|
20
31
|
case "class":
|
|
21
|
-
superToRdfCall = `super
|
|
32
|
+
superToRdfCall = `super.${syntheticNamePrefix}toRdf(${superToRdfOptions})`;
|
|
22
33
|
break;
|
|
23
34
|
case "interface":
|
|
24
|
-
superToRdfCall = `${this.parentObjectTypes[0].
|
|
35
|
+
superToRdfCall = `${this.parentObjectTypes[0].staticModuleName}.${syntheticNamePrefix}toRdf(${this.thisVariable}, ${superToRdfOptions})`;
|
|
25
36
|
break;
|
|
26
37
|
}
|
|
27
38
|
statements.push(`const ${variables.resource} = ${superToRdfCall};`);
|
|
@@ -34,7 +45,7 @@ export function toRdfFunctionOrMethodDeclaration() {
|
|
|
34
45
|
statements.push(`const ${variables.resource} = ${variables.resourceSet}.mutableResource(${this.thisVariable}.${this.identifierProperty.name}, { ${variables.mutateGraph} });`);
|
|
35
46
|
}
|
|
36
47
|
if (this.toRdfTypes.length > 0) {
|
|
37
|
-
statements.push(`if (!${variables.ignoreRdfType}) { ${this.toRdfTypes.map((toRdfType) => `${variables.resource}.add(${
|
|
48
|
+
statements.push(`if (!${variables.ignoreRdfType}) { ${this.toRdfTypes.map((toRdfType) => `${variables.resource}.add(${rdfjsTermExpression(rdf.type)}, ${variables.resource}.dataFactory.namedNode("${toRdfType.value}"));`).join(" ")} }`);
|
|
38
49
|
usedIgnoreRdfTypeVariable = true;
|
|
39
50
|
}
|
|
40
51
|
for (const property of this.properties) {
|
|
@@ -46,22 +57,20 @@ export function toRdfFunctionOrMethodDeclaration() {
|
|
|
46
57
|
}));
|
|
47
58
|
}
|
|
48
59
|
statements.push(`return ${variables.resource};`);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
parameters.push({
|
|
52
|
-
name: this.thisVariable,
|
|
53
|
-
type: this.name,
|
|
54
|
-
});
|
|
60
|
+
if (usedIgnoreRdfTypeVariable) {
|
|
61
|
+
statements.unshift(`const ${variables.ignoreRdfType} = !!options?.ignoreRdfType;`);
|
|
55
62
|
}
|
|
56
|
-
parameters.push({
|
|
57
|
-
name: `{ ${usedIgnoreRdfTypeVariable ? `${variables.ignoreRdfType}, ` : ""}${variables.mutateGraph}, ${variables.resourceSet} }`,
|
|
58
|
-
type: `{ ${variables.ignoreRdfType}?: boolean; ${variables.mutateGraph}?: rdfjsResource.MutableResource.MutateGraph, ${variables.resourceSet}: rdfjsResource.MutableResourceSet }`,
|
|
59
|
-
});
|
|
60
63
|
return Maybe.of({
|
|
61
|
-
name:
|
|
64
|
+
name: `${syntheticNamePrefix}toRdf`,
|
|
62
65
|
parameters,
|
|
63
|
-
returnType: this.
|
|
66
|
+
returnType: this.toRdfjsResourceType,
|
|
64
67
|
statements,
|
|
65
68
|
});
|
|
66
69
|
}
|
|
70
|
+
const variables = {
|
|
71
|
+
ignoreRdfType: "ignoreRdfType",
|
|
72
|
+
mutateGraph: "mutateGraph",
|
|
73
|
+
resource: "resource",
|
|
74
|
+
resourceSet: "resourceSet",
|
|
75
|
+
};
|
|
67
76
|
//# sourceMappingURL=toRdfFunctionOrMethodDeclaration.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
2
|
+
import type { OptionalKind, VariableStatementStructure } from "ts-morph";
|
|
3
|
+
import type { ObjectType } from "./ObjectType.js";
|
|
4
|
+
import type { ObjectUnionType } from "./ObjectUnionType.js";
|
|
5
|
+
export declare function graphqlSchemaVariableStatement(parameters: {
|
|
6
|
+
objectTypes: readonly ObjectType[];
|
|
7
|
+
objectUnionTypes: ObjectUnionType[];
|
|
8
|
+
}): Maybe<OptionalKind<VariableStatementStructure>>;
|
|
9
|
+
//# sourceMappingURL=graphqlSchemaVariableStatement.d.ts.map
|