@shaclmate/compiler 2.0.13 → 2.0.14
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/Compiler.d.ts +15 -0
- package/Compiler.js +20 -0
- package/ShapesGraphToAstTransformer.d.ts +18 -23
- package/ShapesGraphToAstTransformer.js +21 -447
- package/_ShapesGraphToAstTransformer/NodeShapeAstType.d.ts +3 -0
- package/_ShapesGraphToAstTransformer/NodeShapeAstType.js +2 -0
- package/_ShapesGraphToAstTransformer/index.d.ts +10 -0
- package/_ShapesGraphToAstTransformer/index.js +10 -0
- package/_ShapesGraphToAstTransformer/pickLiteral.d.ts +4 -0
- package/_ShapesGraphToAstTransformer/pickLiteral.js +18 -0
- package/_ShapesGraphToAstTransformer/propertyShapeNodeKinds.d.ts +4 -0
- package/_ShapesGraphToAstTransformer/propertyShapeNodeKinds.js +26 -0
- package/_ShapesGraphToAstTransformer/shapeAstName.d.ts +5 -0
- package/_ShapesGraphToAstTransformer/shapeAstName.js +28 -0
- package/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.d.ts +6 -0
- package/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.js +165 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.d.ts +13 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +198 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.d.ts +12 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.js +29 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.d.ts +12 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.js +43 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.d.ts +6 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +31 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.d.ts +14 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.js +21 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.d.ts +16 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.js +58 -0
- package/ast/Ast.d.ts +5 -0
- package/ast/CompositeType.d.ts +13 -0
- package/ast/CompositeType.js +2 -0
- package/ast/IdentifierType.d.ts +3 -6
- package/ast/IntersectionType.d.ts +2 -2
- package/ast/ListType.d.ts +53 -0
- package/ast/ListType.js +2 -0
- package/ast/LiteralType.d.ts +4 -3
- package/ast/Name.d.ts +1 -0
- package/ast/ObjectCompositeType.d.ts +22 -0
- package/ast/ObjectCompositeType.js +2 -0
- package/ast/ObjectIntersectionType.d.ts +8 -0
- package/ast/ObjectIntersectionType.js +2 -0
- package/ast/ObjectType.d.ts +91 -19
- package/ast/ObjectType.js +26 -1
- package/ast/ObjectUnionType.d.ts +19 -0
- package/ast/ObjectUnionType.js +2 -0
- package/ast/PlaceholderType.d.ts +7 -0
- package/ast/PlaceholderType.js +2 -0
- package/ast/SetType.d.ts +1 -1
- package/ast/TermType.d.ts +11 -0
- package/ast/TermType.js +2 -0
- package/ast/Type.d.ts +11 -3
- package/ast/UnionType.d.ts +3 -3
- package/ast/index.d.ts +6 -3
- package/ast/index.js +6 -3
- package/enums/MintingStrategy.d.ts +5 -0
- package/enums/MintingStrategy.js +2 -0
- package/enums/PropertyVisibility.d.ts +2 -0
- package/enums/PropertyVisibility.js +2 -0
- package/enums/TsFeature.d.ts +5 -0
- package/enums/TsFeature.js +16 -0
- package/enums/TsObjectDeclarationType.d.ts +5 -0
- package/enums/TsObjectDeclarationType.js +2 -0
- package/enums/index.d.ts +5 -0
- package/enums/index.js +5 -0
- package/generators/Generator.d.ts +5 -0
- package/generators/Generator.js +2 -0
- package/generators/index.d.ts +2 -2
- package/generators/index.js +2 -2
- package/generators/json/AstJsonGenerator.d.ts +4 -5
- package/generators/json/AstJsonGenerator.js +31 -22
- package/generators/ts/BooleanType.d.ts +7 -3
- package/generators/ts/BooleanType.js +58 -4
- package/generators/ts/DateTimeType.d.ts +17 -0
- package/generators/ts/DateTimeType.js +58 -0
- package/generators/ts/DeclaredType.d.ts +17 -0
- package/generators/ts/DeclaredType.js +10 -0
- package/generators/ts/IdentifierType.d.ts +7 -17
- package/generators/ts/IdentifierType.js +69 -60
- package/generators/ts/Import.d.ts +18 -0
- package/generators/ts/Import.js +59 -0
- package/generators/ts/ListType.d.ts +18 -8
- package/generators/ts/ListType.js +197 -43
- package/generators/ts/LiteralType.d.ts +13 -11
- package/generators/ts/LiteralType.js +36 -51
- package/generators/ts/NumberType.d.ts +7 -3
- package/generators/ts/NumberType.js +55 -4
- package/generators/ts/ObjectType.d.ts +47 -25
- package/generators/ts/ObjectType.js +222 -49
- package/generators/ts/ObjectUnionType.d.ts +58 -0
- package/generators/ts/ObjectUnionType.js +481 -0
- package/generators/ts/OptionType.d.ts +12 -4
- package/generators/ts/OptionType.js +65 -16
- package/generators/ts/PrimitiveType.d.ts +15 -5
- package/generators/ts/PrimitiveType.js +20 -29
- package/generators/ts/SetType.d.ts +12 -4
- package/generators/ts/SetType.js +103 -29
- package/generators/ts/StringType.d.ts +8 -3
- package/generators/ts/StringType.js +57 -3
- package/generators/ts/TermType.d.ts +52 -0
- package/generators/ts/TermType.js +234 -0
- package/generators/ts/TsGenerator.d.ts +4 -12
- package/generators/ts/TsGenerator.js +44 -100
- package/generators/ts/Type.d.ts +107 -46
- package/generators/ts/Type.js +78 -61
- package/generators/ts/TypeFactory.d.ts +4 -5
- package/generators/ts/TypeFactory.js +212 -89
- package/generators/ts/UnionType.d.ts +19 -6
- package/generators/ts/UnionType.js +230 -120
- package/generators/ts/_ObjectType/IdentifierProperty.d.ts +27 -7
- package/generators/ts/_ObjectType/IdentifierProperty.js +143 -31
- package/generators/ts/_ObjectType/Property.d.ts +125 -9
- package/generators/ts/_ObjectType/Property.js +25 -3
- package/generators/ts/_ObjectType/ShaclProperty.d.ts +23 -5
- package/generators/ts/_ObjectType/ShaclProperty.js +100 -26
- package/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +24 -6
- package/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +75 -13
- package/generators/ts/_ObjectType/classDeclaration.d.ts +2 -1
- package/generators/ts/_ObjectType/classDeclaration.js +79 -111
- package/generators/ts/_ObjectType/createFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/createFunctionDeclaration.js +60 -0
- package/generators/ts/_ObjectType/equalsFunctionDeclaration.d.ts +2 -1
- package/generators/ts/_ObjectType/equalsFunctionDeclaration.js +12 -20
- package/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.d.ts +11 -0
- package/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.js +70 -0
- package/generators/ts/_ObjectType/fromJsonFunctionDeclarations.d.ts +4 -0
- package/generators/ts/_ObjectType/fromJsonFunctionDeclarations.js +78 -0
- package/generators/ts/_ObjectType/fromRdfFunctionDeclarations.d.ts +4 -0
- package/generators/ts/_ObjectType/fromRdfFunctionDeclarations.js +91 -0
- package/generators/ts/_ObjectType/hashFunctionDeclaration.d.ts +3 -3
- package/generators/ts/_ObjectType/hashFunctionDeclaration.js +11 -55
- package/generators/ts/_ObjectType/hashFunctionOrMethodDeclaration.d.ts +11 -0
- package/generators/ts/_ObjectType/hashFunctionOrMethodDeclaration.js +64 -0
- package/generators/ts/_ObjectType/index.d.ts +8 -2
- package/generators/ts/_ObjectType/index.js +8 -2
- package/generators/ts/_ObjectType/interfaceDeclaration.d.ts +3 -2
- package/generators/ts/_ObjectType/interfaceDeclaration.js +11 -2
- package/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.js +19 -0
- package/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.js +31 -0
- package/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.js +37 -0
- package/generators/ts/_ObjectType/rdfjsTermExpression.d.ts +6 -0
- package/generators/ts/{rdfjsTermExpression.js → _ObjectType/rdfjsTermExpression.js} +3 -1
- package/generators/ts/_ObjectType/sparqlFunctionDeclarations.d.ts +4 -0
- package/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +101 -0
- package/generators/ts/_ObjectType/toJsonFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/toJsonFunctionDeclaration.js +19 -0
- package/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.d.ts +10 -0
- package/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.js +59 -0
- package/generators/ts/_ObjectType/toJsonReturnType.d.ts +3 -0
- package/generators/ts/_ObjectType/toJsonReturnType.js +19 -0
- package/generators/ts/_ObjectType/toRdfFunctionDeclaration.d.ts +3 -2
- package/generators/ts/_ObjectType/toRdfFunctionDeclaration.js +11 -45
- package/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.d.ts +10 -0
- package/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.js +67 -0
- package/generators/ts/objectInitializer.d.ts +2 -0
- package/generators/ts/objectInitializer.js +14 -0
- package/generators/ts/tsComment.d.ts +5 -0
- package/generators/ts/tsComment.js +11 -0
- package/generators/ts/tsName.d.ts +1 -1
- package/generators/ts/tsName.js +1 -0
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/input/NodeShape.d.ts +46 -0
- package/input/NodeShape.js +165 -0
- package/input/Ontology.d.ts +13 -0
- package/input/Ontology.js +30 -0
- package/input/PropertyShape.d.ts +15 -0
- package/input/PropertyShape.js +34 -0
- package/input/Shape.d.ts +4 -0
- package/input/Shape.js +2 -0
- package/input/ShapesGraph.d.ts +9 -0
- package/input/ShapesGraph.js +50 -0
- package/input/ancestorClassIris.d.ts +4 -0
- package/input/ancestorClassIris.js +21 -0
- package/input/descendantClassIris.d.ts +4 -0
- package/input/descendantClassIris.js +21 -0
- package/input/generated.d.ts +274 -0
- package/input/generated.js +1420 -0
- package/input/index.d.ts +7 -0
- package/input/index.js +7 -0
- package/input/tsFeatures.d.ts +10 -0
- package/input/tsFeatures.js +42 -0
- package/package.json +14 -8
- package/ast/MintingStrategy.d.ts +0 -8
- package/ast/MintingStrategy.js +0 -9
- package/generators/ts/Configuration.d.ts +0 -29
- package/generators/ts/Configuration.js +0 -40
- package/generators/ts/IntersectionType.d.ts +0 -14
- package/generators/ts/IntersectionType.js +0 -26
- package/generators/ts/RdfjsTermType.d.ts +0 -25
- package/generators/ts/RdfjsTermType.js +0 -46
- package/generators/ts/_ObjectType/fromRdfFunctionDeclaration.d.ts +0 -4
- package/generators/ts/_ObjectType/fromRdfFunctionDeclaration.js +0 -72
- package/generators/ts/_ObjectType/sparqlGraphPatternsClassDeclaration.d.ts +0 -4
- package/generators/ts/_ObjectType/sparqlGraphPatternsClassDeclaration.js +0 -46
- package/generators/ts/rdfjsTermExpression.d.ts +0 -5
- package/vocabularies/dashDataset.d.ts +0 -3
- package/vocabularies/dashDataset.js +0 -2370
- package/vocabularies/index.d.ts +0 -2
- package/vocabularies/index.js +0 -2
- package/vocabularies/shaclmate.d.ts +0 -15
- package/vocabularies/shaclmate.js +0 -6
|
@@ -1,119 +1,63 @@
|
|
|
1
|
-
import { Project,
|
|
2
|
-
import
|
|
1
|
+
import { Project, } from "ts-morph";
|
|
2
|
+
import * as ast from "../../ast/index.js";
|
|
3
|
+
import { ObjectType } from "./ObjectType.js";
|
|
4
|
+
import { ObjectUnionType } from "./ObjectUnionType.js";
|
|
3
5
|
import { TypeFactory } from "./TypeFactory.js";
|
|
4
|
-
import { tsName } from "./tsName.js";
|
|
5
6
|
export class TsGenerator {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
this.configuration = configuration ?? new TsGenerator.Configuration();
|
|
9
|
-
}
|
|
10
|
-
generate() {
|
|
11
|
-
const astObjectTypes = this.ast.objectTypes.concat();
|
|
12
|
-
astObjectTypes.sort((left, right) => {
|
|
13
|
-
if (left.ancestorObjectTypes.some((ancestorObjectType) => ancestorObjectType.name.identifier.equals(right.name.identifier))) {
|
|
14
|
-
// Right is an ancestor of left, right must come first
|
|
15
|
-
return 1;
|
|
16
|
-
}
|
|
17
|
-
if (right.ancestorObjectTypes.some((ancestorObjectType) => ancestorObjectType.name.identifier.equals(left.name.identifier))) {
|
|
18
|
-
// Left is an ancestor of right, left must come first
|
|
19
|
-
return -1;
|
|
20
|
-
}
|
|
21
|
-
// Neither is an ancestor of the other, sort by name
|
|
22
|
-
return tsName(left.name).localeCompare(tsName(right.name));
|
|
23
|
-
});
|
|
7
|
+
generate(ast_) {
|
|
8
|
+
const sortedAstObjectTypes = ast.ObjectType.toposort(ast_.objectTypes);
|
|
24
9
|
const project = new Project({
|
|
25
10
|
useInMemoryFileSystem: true,
|
|
26
11
|
});
|
|
27
12
|
const sourceFile = project.createSourceFile("generated.ts");
|
|
28
|
-
const typeFactory = new TypeFactory({
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
13
|
+
const typeFactory = new TypeFactory({
|
|
14
|
+
dataFactoryVariable: ast_.tsDataFactoryVariable,
|
|
15
|
+
});
|
|
16
|
+
this.addDeclarations({
|
|
17
|
+
objectTypes: sortedAstObjectTypes.flatMap((astObjectType) => {
|
|
18
|
+
const type = typeFactory.createTypeFromAstType(astObjectType);
|
|
19
|
+
return type instanceof ObjectType ? [type] : [];
|
|
20
|
+
}),
|
|
21
|
+
objectUnionTypes: ast_.objectUnionTypes.flatMap((astObjectUnionType) => {
|
|
22
|
+
const type = typeFactory.createTypeFromAstType(astObjectUnionType);
|
|
23
|
+
return type instanceof ObjectUnionType ? [type] : [];
|
|
24
|
+
}),
|
|
25
|
+
sourceFile,
|
|
32
26
|
});
|
|
33
|
-
this.addDeclarations(objectTypes, sourceFile);
|
|
34
27
|
sourceFile.saveSync();
|
|
35
28
|
return project.getFileSystem().readFileSync(sourceFile.getFilePath());
|
|
36
29
|
}
|
|
37
|
-
addDeclarations(objectTypes, sourceFile) {
|
|
38
|
-
this.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
if (this.configuration.features.has("fromRdf")) {
|
|
54
|
-
moduleStatements.push(objectType.fromRdfFunctionDeclaration());
|
|
55
|
-
}
|
|
56
|
-
if (this.configuration.features.has("hash")) {
|
|
57
|
-
moduleStatements.push(objectType.hashFunctionDeclaration());
|
|
58
|
-
}
|
|
59
|
-
if (this.configuration.features.has("sparql-graph-patterns")) {
|
|
60
|
-
if (objectType.parentObjectTypes.length > 1) {
|
|
61
|
-
throw new RangeError(`object type '${objectType.name}' has multiple super object types, can't use with SPARQL graph patterns`);
|
|
30
|
+
addDeclarations({ objectTypes, objectUnionTypes, sourceFile, }) {
|
|
31
|
+
// sourceFile.addStatements(this.configuration.dataFactoryImport);
|
|
32
|
+
sourceFile.addStatements('import { DataFactory as dataFactory } from "n3"');
|
|
33
|
+
// Gather imports
|
|
34
|
+
const imports = [];
|
|
35
|
+
for (const declaredType of [...objectTypes, ...objectUnionTypes]) {
|
|
36
|
+
imports.push(...declaredType.declarationImports);
|
|
37
|
+
}
|
|
38
|
+
// Deduplicate and add imports
|
|
39
|
+
const addedStringImports = new Set();
|
|
40
|
+
const addedStructureImports = [];
|
|
41
|
+
for (const import_ of imports) {
|
|
42
|
+
if (typeof import_ === "string") {
|
|
43
|
+
if (!addedStringImports.has(import_)) {
|
|
44
|
+
sourceFile.addStatements([import_]);
|
|
62
45
|
}
|
|
63
|
-
|
|
46
|
+
addedStringImports.add(import_);
|
|
47
|
+
continue;
|
|
64
48
|
}
|
|
65
|
-
if (
|
|
66
|
-
|
|
67
|
-
|
|
49
|
+
if (!addedStructureImports.find((addedStructureImport) => addedStructureImport.moduleSpecifier === import_.moduleSpecifier)) {
|
|
50
|
+
sourceFile.addStatements([import_]);
|
|
51
|
+
addedStructureImports.push(import_);
|
|
68
52
|
}
|
|
69
|
-
sourceFile.addModule({
|
|
70
|
-
isExported: objectType.export_,
|
|
71
|
-
kind: StructureKind.Module,
|
|
72
|
-
name: objectType.name,
|
|
73
|
-
statements: moduleStatements,
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
addImportDeclarations(objectTypes, sourceFile) {
|
|
78
|
-
sourceFile.addImportDeclaration({
|
|
79
|
-
moduleSpecifier: "purify-ts",
|
|
80
|
-
namespaceImport: "purify",
|
|
81
|
-
});
|
|
82
|
-
sourceFile.addImportDeclaration({
|
|
83
|
-
isTypeOnly: true,
|
|
84
|
-
moduleSpecifier: "@rdfjs/types",
|
|
85
|
-
namespaceImport: "rdfjs",
|
|
86
|
-
});
|
|
87
|
-
sourceFile.addStatements(this.configuration.dataFactoryImport);
|
|
88
|
-
if (this.configuration.features.has("equals")) {
|
|
89
|
-
sourceFile.addImportDeclaration({
|
|
90
|
-
moduleSpecifier: "purify-ts-helpers",
|
|
91
|
-
namespaceImport: "purifyHelpers",
|
|
92
|
-
});
|
|
93
53
|
}
|
|
94
|
-
|
|
95
|
-
this.configuration.features.has("toRdf")) {
|
|
96
|
-
sourceFile.addImportDeclaration({
|
|
97
|
-
moduleSpecifier: "rdfjs-resource",
|
|
98
|
-
namespaceImport: "rdfjsResource",
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
if (this.configuration.features.has("sparql-graph-patterns")) {
|
|
102
|
-
sourceFile.addImportDeclaration({
|
|
103
|
-
moduleSpecifier: "@kos-kit/sparql-builder",
|
|
104
|
-
namespaceImport: "sparqlBuilder",
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
const typeImportStatements = new Set();
|
|
54
|
+
// Add type declarations
|
|
108
55
|
for (const objectType of objectTypes) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
56
|
+
sourceFile.addStatements(objectType.declarations);
|
|
57
|
+
}
|
|
58
|
+
for (const objectUnionType of objectUnionTypes) {
|
|
59
|
+
sourceFile.addStatements(objectUnionType.declarations);
|
|
112
60
|
}
|
|
113
|
-
sourceFile.addStatements([...typeImportStatements]);
|
|
114
61
|
}
|
|
115
62
|
}
|
|
116
|
-
(function (TsGenerator) {
|
|
117
|
-
TsGenerator.Configuration = GlobalConfiguration;
|
|
118
|
-
})(TsGenerator || (TsGenerator = {}));
|
|
119
63
|
//# sourceMappingURL=TsGenerator.js.map
|
package/generators/ts/Type.d.ts
CHANGED
|
@@ -1,73 +1,147 @@
|
|
|
1
|
+
import type { BlankNode, Literal, NamedNode, Variable } from "@rdfjs/types";
|
|
1
2
|
import { Maybe } from "purify-ts";
|
|
2
|
-
import type
|
|
3
|
-
|
|
3
|
+
import type { Import } from "./Import.js";
|
|
4
|
+
/**
|
|
5
|
+
* Abstract base class for generating TypeScript expressions and statemenst in the TypeScript generator.
|
|
6
|
+
*
|
|
7
|
+
* Subclasses are used for both property types (c.f., property* methods) and node/object types.
|
|
8
|
+
*/
|
|
4
9
|
export declare abstract class Type {
|
|
5
|
-
abstract readonly kind: ast.Type["kind"] | "ListType";
|
|
6
|
-
abstract readonly name: string;
|
|
7
|
-
protected readonly configuration: Configuration;
|
|
8
|
-
constructor({ configuration, }: {
|
|
9
|
-
configuration: Configuration;
|
|
10
|
-
});
|
|
11
10
|
/**
|
|
12
11
|
* Expressions that convert a source type or types to this type. It should include the type itself.
|
|
13
12
|
*/
|
|
14
|
-
|
|
13
|
+
abstract readonly conversions: readonly Type.Conversion[];
|
|
15
14
|
/**
|
|
16
|
-
* A
|
|
15
|
+
* A function (reference or declaration) that compares two property values of this type, returning a
|
|
16
|
+
* purifyHelpers.Equatable.EqualsResult.
|
|
17
17
|
*/
|
|
18
|
-
|
|
18
|
+
abstract readonly equalsFunction: string;
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
20
|
+
* JSON-compatible returned by propertyToJsonExpression.
|
|
21
21
|
*/
|
|
22
|
-
|
|
22
|
+
abstract readonly jsonName: string;
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* If the type is e.g., an RDF/JS term it won't have additional graph patterns beyond the basic (s, p, o), and this
|
|
27
|
-
* method will return nothing.
|
|
24
|
+
* Is a value of this type mutable?
|
|
28
25
|
*/
|
|
29
|
-
|
|
30
|
-
variables: {
|
|
31
|
-
subject: string;
|
|
32
|
-
};
|
|
33
|
-
}): Maybe<Type.SparqlGraphPatternExpression | Type.SparqlGraphPatternsExpression>;
|
|
26
|
+
abstract readonly mutable: boolean;
|
|
34
27
|
/**
|
|
35
|
-
*
|
|
36
|
-
|
|
28
|
+
* Name of the type.
|
|
29
|
+
*/
|
|
30
|
+
abstract readonly name: string;
|
|
31
|
+
/**
|
|
32
|
+
* Imports necessary to use this type.
|
|
33
|
+
*/
|
|
34
|
+
abstract readonly useImports: readonly Import[];
|
|
35
|
+
protected readonly dataFactoryVariable: string;
|
|
36
|
+
constructor({ dataFactoryVariable, }: {
|
|
37
|
+
dataFactoryVariable: string;
|
|
38
|
+
});
|
|
39
|
+
/**
|
|
40
|
+
* A property that discriminates sub-types of this type e.g., termType on RDF/JS terms.
|
|
37
41
|
*/
|
|
38
|
-
|
|
42
|
+
get discriminatorProperty(): Maybe<Type.DiscriminatorProperty>;
|
|
43
|
+
/**
|
|
44
|
+
* An expression that converts a JSON object in the same format as the propertyToJsonExpression to a value of this type.
|
|
45
|
+
*/
|
|
46
|
+
abstract fromJsonExpression(parameters: {
|
|
47
|
+
variables: {
|
|
48
|
+
value: string;
|
|
49
|
+
};
|
|
50
|
+
}): string;
|
|
39
51
|
/**
|
|
40
52
|
* An expression that converts a rdfjsResource.Resource.Values to an Either of value/values
|
|
41
|
-
* of this type.
|
|
53
|
+
* of this type for a property.
|
|
42
54
|
*/
|
|
43
55
|
abstract fromRdfExpression(parameters: {
|
|
44
56
|
variables: {
|
|
57
|
+
context: string;
|
|
58
|
+
languageIn: string;
|
|
45
59
|
predicate: string;
|
|
46
60
|
resource: string;
|
|
47
61
|
resourceValues: string;
|
|
48
62
|
};
|
|
49
63
|
}): string;
|
|
50
64
|
/**
|
|
51
|
-
* Statements that use hasher.update to hash a value of this type.
|
|
65
|
+
* Statements that use hasher.update to hash a property value of this type.
|
|
52
66
|
*/
|
|
53
67
|
abstract hashStatements(parameters: {
|
|
68
|
+
depth: number;
|
|
54
69
|
variables: {
|
|
55
70
|
hasher: string;
|
|
56
71
|
value: string;
|
|
57
72
|
};
|
|
58
73
|
}): readonly string[];
|
|
59
74
|
/**
|
|
60
|
-
*
|
|
75
|
+
* Element object for a JSON Forms UI schema.
|
|
61
76
|
*/
|
|
62
|
-
|
|
77
|
+
jsonUiSchemaElement(_parameters: {
|
|
78
|
+
variables: {
|
|
79
|
+
scopePrefix: string;
|
|
80
|
+
};
|
|
81
|
+
}): Maybe<string>;
|
|
82
|
+
/**
|
|
83
|
+
* Zod schema for the JSON version of the type (the result of propertyToJson).
|
|
84
|
+
*/
|
|
85
|
+
abstract jsonZodSchema(parameters: {
|
|
86
|
+
variables: {
|
|
87
|
+
zod: string;
|
|
88
|
+
};
|
|
89
|
+
}): string;
|
|
90
|
+
/**
|
|
91
|
+
* An array of SPARQL.js CONSTRUCT template triples for a value of this type, as strings (so they can incorporate runtime calls).
|
|
92
|
+
*
|
|
93
|
+
* This method is called in two contexts:
|
|
94
|
+
* (1) By an ObjectType.Property. The property expects a basic graph pattern (subject, property path, property object). The property calls this method to get additional triples in which the propertyObject is the subject. For example, if the type is a nested object, it would include (propertyObject, nestedPredicate, nestedObject) triples.
|
|
95
|
+
* (2) By another Type. For example, ListType calls this method to with the item variable as a subject in order to chain additional patterns on items.
|
|
96
|
+
*
|
|
97
|
+
* Term types with no additional properties should return an empty array.
|
|
98
|
+
*/
|
|
99
|
+
sparqlConstructTemplateTriples({ context, variables, }: {
|
|
100
|
+
context: "property";
|
|
63
101
|
variables: {
|
|
64
102
|
object: string;
|
|
65
103
|
predicate: string;
|
|
66
104
|
subject: string;
|
|
105
|
+
variablePrefix: string;
|
|
106
|
+
};
|
|
107
|
+
} | {
|
|
108
|
+
context: "type";
|
|
109
|
+
variables: {
|
|
110
|
+
subject: string;
|
|
111
|
+
variablePrefix: string;
|
|
67
112
|
};
|
|
68
|
-
}):
|
|
113
|
+
}): readonly string[];
|
|
69
114
|
/**
|
|
70
|
-
* An
|
|
115
|
+
* An array of SPARQL.js where patterns for a value of this type, as strings (so they can incorporate runtime calls).
|
|
116
|
+
*
|
|
117
|
+
* See note in sparqlConstructTemplateTriples re: how this method is used.
|
|
118
|
+
*/
|
|
119
|
+
sparqlWherePatterns({ context, variables, }: {
|
|
120
|
+
context: "property";
|
|
121
|
+
variables: {
|
|
122
|
+
object: string;
|
|
123
|
+
predicate: string;
|
|
124
|
+
subject: string;
|
|
125
|
+
variablePrefix: string;
|
|
126
|
+
};
|
|
127
|
+
} | {
|
|
128
|
+
context: "type";
|
|
129
|
+
variables: {
|
|
130
|
+
subject: string;
|
|
131
|
+
variablePrefix: string;
|
|
132
|
+
};
|
|
133
|
+
}): readonly string[];
|
|
134
|
+
/**
|
|
135
|
+
* An expression that converts a value of this type to a JSON-LD compatible value. It can assume the presence
|
|
136
|
+
* of the correct JSON-LD context.
|
|
137
|
+
*/
|
|
138
|
+
abstract toJsonExpression(parameters: {
|
|
139
|
+
variables: {
|
|
140
|
+
value: string;
|
|
141
|
+
};
|
|
142
|
+
}): string;
|
|
143
|
+
/**
|
|
144
|
+
* An expression that converts a property value of this type to one that that can be .add'd to
|
|
71
145
|
* an rdfjsResource.Resource.
|
|
72
146
|
*/
|
|
73
147
|
abstract toRdfExpression(parameters: {
|
|
@@ -79,30 +153,17 @@ export declare abstract class Type {
|
|
|
79
153
|
value: string;
|
|
80
154
|
};
|
|
81
155
|
}): string;
|
|
156
|
+
protected rdfjsTermExpression(rdfjsTerm: Omit<BlankNode, "equals"> | Omit<Literal, "equals"> | Omit<NamedNode, "equals"> | Omit<Variable, "equals">): string;
|
|
82
157
|
}
|
|
83
158
|
export declare namespace Type {
|
|
84
159
|
interface Conversion {
|
|
85
160
|
readonly conversionExpression: (value: string) => string;
|
|
86
|
-
readonly sourceTypeCheckExpression
|
|
161
|
+
readonly sourceTypeCheckExpression: (value: string) => string;
|
|
87
162
|
readonly sourceTypeName: string;
|
|
88
163
|
}
|
|
89
164
|
interface DiscriminatorProperty {
|
|
90
165
|
readonly name: string;
|
|
91
166
|
readonly values: readonly string[];
|
|
92
167
|
}
|
|
93
|
-
class SparqlGraphPatternExpression {
|
|
94
|
-
private readonly value;
|
|
95
|
-
constructor(value: string);
|
|
96
|
-
toSparqlGraphPatternExpression(): this;
|
|
97
|
-
toSparqlGraphPatternsExpression(): SparqlGraphPatternExpression;
|
|
98
|
-
toString(): string;
|
|
99
|
-
}
|
|
100
|
-
class SparqlGraphPatternsExpression {
|
|
101
|
-
private readonly value;
|
|
102
|
-
constructor(value: string);
|
|
103
|
-
toSparqlGraphPatternExpression(): SparqlGraphPatternExpression;
|
|
104
|
-
toSparqlGraphPatternsExpression(): this;
|
|
105
|
-
toString(): string;
|
|
106
|
-
}
|
|
107
168
|
}
|
|
108
169
|
//# sourceMappingURL=Type.d.ts.map
|
package/generators/ts/Type.js
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
import { Maybe } from "purify-ts";
|
|
2
|
+
import { invariant } from "ts-invariant";
|
|
3
|
+
import { rdfjsTermExpression } from "./_ObjectType/rdfjsTermExpression.js";
|
|
4
|
+
import { objectInitializer } from "./objectInitializer.js";
|
|
5
|
+
/**
|
|
6
|
+
* Abstract base class for generating TypeScript expressions and statemenst in the TypeScript generator.
|
|
7
|
+
*
|
|
8
|
+
* Subclasses are used for both property types (c.f., property* methods) and node/object types.
|
|
9
|
+
*/
|
|
2
10
|
export class Type {
|
|
3
|
-
constructor({
|
|
4
|
-
this.
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Expressions that convert a source type or types to this type. It should include the type itself.
|
|
8
|
-
*/
|
|
9
|
-
get conversions() {
|
|
10
|
-
return [
|
|
11
|
-
{
|
|
12
|
-
conversionExpression: (value) => value,
|
|
13
|
-
sourceTypeName: this.name,
|
|
14
|
-
},
|
|
15
|
-
];
|
|
11
|
+
constructor({ dataFactoryVariable, }) {
|
|
12
|
+
this.dataFactoryVariable = dataFactoryVariable;
|
|
16
13
|
}
|
|
17
14
|
/**
|
|
18
15
|
* A property that discriminates sub-types of this type e.g., termType on RDF/JS terms.
|
|
@@ -21,63 +18,83 @@ export class Type {
|
|
|
21
18
|
return Maybe.empty();
|
|
22
19
|
}
|
|
23
20
|
/**
|
|
24
|
-
*
|
|
21
|
+
* Element object for a JSON Forms UI schema.
|
|
25
22
|
*/
|
|
26
|
-
|
|
27
|
-
return
|
|
23
|
+
jsonUiSchemaElement(_parameters) {
|
|
24
|
+
return Maybe.empty();
|
|
28
25
|
}
|
|
29
26
|
/**
|
|
30
|
-
* An
|
|
27
|
+
* An array of SPARQL.js CONSTRUCT template triples for a value of this type, as strings (so they can incorporate runtime calls).
|
|
28
|
+
*
|
|
29
|
+
* This method is called in two contexts:
|
|
30
|
+
* (1) By an ObjectType.Property. The property expects a basic graph pattern (subject, property path, property object). The property calls this method to get additional triples in which the propertyObject is the subject. For example, if the type is a nested object, it would include (propertyObject, nestedPredicate, nestedObject) triples.
|
|
31
|
+
* (2) By another Type. For example, ListType calls this method to with the item variable as a subject in order to chain additional patterns on items.
|
|
31
32
|
*
|
|
32
|
-
*
|
|
33
|
-
* method will return nothing.
|
|
33
|
+
* Term types with no additional properties should return an empty array.
|
|
34
34
|
*/
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
sparqlConstructTemplateTriples({ context, variables, }) {
|
|
36
|
+
switch (context) {
|
|
37
|
+
case "property": {
|
|
38
|
+
const objectPrefix = `${this.dataFactoryVariable}.variable!(`;
|
|
39
|
+
const objectSuffix = ")";
|
|
40
|
+
invariant(variables.object.startsWith(objectPrefix));
|
|
41
|
+
invariant(variables.object.endsWith(objectSuffix));
|
|
42
|
+
return [
|
|
43
|
+
objectInitializer({
|
|
44
|
+
object: variables.object,
|
|
45
|
+
predicate: variables.predicate,
|
|
46
|
+
subject: variables.subject,
|
|
47
|
+
}),
|
|
48
|
+
].concat(this.sparqlConstructTemplateTriples({
|
|
49
|
+
context: "type",
|
|
50
|
+
variables: {
|
|
51
|
+
subject: variables.object,
|
|
52
|
+
variablePrefix: variables.object.substring(objectPrefix.length, variables.object.length - objectSuffix.length),
|
|
53
|
+
},
|
|
54
|
+
}));
|
|
55
|
+
}
|
|
56
|
+
case "type":
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
37
59
|
}
|
|
38
60
|
/**
|
|
39
|
-
* An
|
|
61
|
+
* An array of SPARQL.js where patterns for a value of this type, as strings (so they can incorporate runtime calls).
|
|
62
|
+
*
|
|
63
|
+
* See note in sparqlConstructTemplateTriples re: how this method is used.
|
|
40
64
|
*/
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
65
|
+
sparqlWherePatterns({ context, variables, }) {
|
|
66
|
+
switch (context) {
|
|
67
|
+
case "property": {
|
|
68
|
+
const objectPrefix = `${this.dataFactoryVariable}.variable!(`;
|
|
69
|
+
const objectSuffix = ")";
|
|
70
|
+
invariant(variables.object.startsWith(objectPrefix));
|
|
71
|
+
invariant(variables.object.endsWith(objectSuffix));
|
|
72
|
+
return [
|
|
73
|
+
objectInitializer({
|
|
74
|
+
triples: `[${objectInitializer({
|
|
75
|
+
object: variables.object,
|
|
76
|
+
predicate: variables.predicate,
|
|
77
|
+
subject: variables.subject,
|
|
78
|
+
})}]`,
|
|
79
|
+
type: '"bgp"',
|
|
80
|
+
}),
|
|
81
|
+
].concat(this.sparqlWherePatterns({
|
|
82
|
+
context: "type",
|
|
83
|
+
variables: {
|
|
84
|
+
subject: variables.object,
|
|
85
|
+
variablePrefix: variables.object.substring(objectPrefix.length, variables.object.length - objectSuffix.length),
|
|
86
|
+
},
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
case "type":
|
|
90
|
+
return [];
|
|
64
91
|
}
|
|
65
92
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
toSparqlGraphPatternExpression() {
|
|
72
|
-
return new SparqlGraphPatternExpression(`sparqlBuilder.GraphPattern.group(${this.value})`);
|
|
73
|
-
}
|
|
74
|
-
toSparqlGraphPatternsExpression() {
|
|
75
|
-
return this;
|
|
76
|
-
}
|
|
77
|
-
toString() {
|
|
78
|
-
return this.value;
|
|
79
|
-
}
|
|
93
|
+
rdfjsTermExpression(rdfjsTerm) {
|
|
94
|
+
return rdfjsTermExpression({
|
|
95
|
+
dataFactoryVariable: this.dataFactoryVariable,
|
|
96
|
+
rdfjsTerm,
|
|
97
|
+
});
|
|
80
98
|
}
|
|
81
|
-
|
|
82
|
-
})(Type || (Type = {}));
|
|
99
|
+
}
|
|
83
100
|
//# sourceMappingURL=Type.js.map
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import type * as ast from "../../ast";
|
|
2
|
-
import type { Configuration } from "./Configuration";
|
|
1
|
+
import type * as ast from "../../ast/index.js";
|
|
3
2
|
import type { Type } from "./Type.js";
|
|
4
3
|
export declare class TypeFactory {
|
|
5
4
|
private cachedObjectTypePropertiesByIdentifier;
|
|
6
5
|
private cachedObjectTypesByIdentifier;
|
|
7
|
-
private readonly
|
|
8
|
-
constructor({
|
|
9
|
-
|
|
6
|
+
private readonly dataFactoryVariable;
|
|
7
|
+
constructor({ dataFactoryVariable }: {
|
|
8
|
+
dataFactoryVariable: string;
|
|
10
9
|
});
|
|
11
10
|
createTypeFromAstType(astType: ast.Type): Type;
|
|
12
11
|
private createObjectTypeFromAstType;
|