@shaclmate/compiler 2.0.12
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/ShapesGraphToAstTransformer.d.ts +32 -0
- package/ShapesGraphToAstTransformer.js +461 -0
- package/ast/Ast.d.ts +5 -0
- package/ast/Ast.js +2 -0
- package/ast/IdentifierType.d.ts +13 -0
- package/ast/IdentifierType.js +2 -0
- package/ast/IntersectionType.d.ts +9 -0
- package/ast/IntersectionType.js +2 -0
- package/ast/LiteralType.d.ts +13 -0
- package/ast/LiteralType.js +2 -0
- package/ast/MintingStrategy.d.ts +8 -0
- package/ast/MintingStrategy.js +9 -0
- package/ast/Name.d.ts +13 -0
- package/ast/Name.js +2 -0
- package/ast/ObjectType.d.ts +88 -0
- package/ast/ObjectType.js +2 -0
- package/ast/OptionType.d.ts +11 -0
- package/ast/OptionType.js +2 -0
- package/ast/SetType.d.ts +12 -0
- package/ast/SetType.js +2 -0
- package/ast/Type.d.ts +9 -0
- package/ast/Type.js +2 -0
- package/ast/UnionType.d.ts +9 -0
- package/ast/UnionType.js +2 -0
- package/ast/index.d.ts +10 -0
- package/ast/index.js +10 -0
- package/generators/index.d.ts +3 -0
- package/generators/index.js +3 -0
- package/generators/json/AstJsonGenerator.d.ts +7 -0
- package/generators/json/AstJsonGenerator.js +103 -0
- package/generators/json/index.d.ts +2 -0
- package/generators/json/index.js +2 -0
- package/generators/ts/BooleanType.d.ts +7 -0
- package/generators/ts/BooleanType.js +13 -0
- package/generators/ts/Configuration.d.ts +29 -0
- package/generators/ts/Configuration.js +40 -0
- package/generators/ts/IdentifierType.d.ts +23 -0
- package/generators/ts/IdentifierType.js +83 -0
- package/generators/ts/IntersectionType.d.ts +14 -0
- package/generators/ts/IntersectionType.js +26 -0
- package/generators/ts/ListType.d.ts +26 -0
- package/generators/ts/ListType.js +119 -0
- package/generators/ts/LiteralType.d.ts +14 -0
- package/generators/ts/LiteralType.js +61 -0
- package/generators/ts/NumberType.d.ts +7 -0
- package/generators/ts/NumberType.js +13 -0
- package/generators/ts/ObjectType.d.ts +71 -0
- package/generators/ts/ObjectType.js +160 -0
- package/generators/ts/OptionType.d.ts +17 -0
- package/generators/ts/OptionType.js +83 -0
- package/generators/ts/PrimitiveType.d.ts +11 -0
- package/generators/ts/PrimitiveType.js +41 -0
- package/generators/ts/RdfjsTermType.d.ts +25 -0
- package/generators/ts/RdfjsTermType.js +46 -0
- package/generators/ts/SetType.d.ts +19 -0
- package/generators/ts/SetType.js +76 -0
- package/generators/ts/StringType.d.ts +7 -0
- package/generators/ts/StringType.js +13 -0
- package/generators/ts/TsGenerator.d.ts +15 -0
- package/generators/ts/TsGenerator.js +119 -0
- package/generators/ts/Type.d.ts +108 -0
- package/generators/ts/Type.js +83 -0
- package/generators/ts/TypeFactory.d.ts +15 -0
- package/generators/ts/TypeFactory.js +198 -0
- package/generators/ts/UnionType.d.ts +18 -0
- package/generators/ts/UnionType.js +165 -0
- package/generators/ts/_ObjectType/IdentifierProperty.d.ts +23 -0
- package/generators/ts/_ObjectType/IdentifierProperty.js +82 -0
- package/generators/ts/_ObjectType/Property.d.ts +38 -0
- package/generators/ts/_ObjectType/Property.js +11 -0
- package/generators/ts/_ObjectType/ShaclProperty.d.ts +25 -0
- package/generators/ts/_ObjectType/ShaclProperty.js +106 -0
- package/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +29 -0
- package/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +53 -0
- package/generators/ts/_ObjectType/classDeclaration.d.ts +4 -0
- package/generators/ts/_ObjectType/classDeclaration.js +154 -0
- package/generators/ts/_ObjectType/equalsFunctionDeclaration.d.ts +4 -0
- package/generators/ts/_ObjectType/equalsFunctionDeclaration.js +27 -0
- package/generators/ts/_ObjectType/fromRdfFunctionDeclaration.d.ts +4 -0
- package/generators/ts/_ObjectType/fromRdfFunctionDeclaration.js +72 -0
- package/generators/ts/_ObjectType/hashFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/hashFunctionDeclaration.js +64 -0
- package/generators/ts/_ObjectType/index.d.ts +12 -0
- package/generators/ts/_ObjectType/index.js +12 -0
- package/generators/ts/_ObjectType/interfaceDeclaration.d.ts +4 -0
- package/generators/ts/_ObjectType/interfaceDeclaration.js +12 -0
- package/generators/ts/_ObjectType/sparqlGraphPatternsClassDeclaration.d.ts +4 -0
- package/generators/ts/_ObjectType/sparqlGraphPatternsClassDeclaration.js +46 -0
- package/generators/ts/_ObjectType/toRdfFunctionDeclaration.d.ts +4 -0
- package/generators/ts/_ObjectType/toRdfFunctionDeclaration.js +53 -0
- package/generators/ts/index.d.ts +2 -0
- package/generators/ts/index.js +2 -0
- package/generators/ts/rdfjsTermExpression.d.ts +5 -0
- package/generators/ts/rdfjsTermExpression.js +15 -0
- package/generators/ts/stringToValidTsIdentifier.d.ts +2 -0
- package/generators/ts/stringToValidTsIdentifier.js +14 -0
- package/generators/ts/tsName.d.ts +3 -0
- package/generators/ts/tsName.js +22 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/logger.d.ts +2 -0
- package/logger.js +8 -0
- package/package.json +71 -0
- package/vocabularies/dashDataset.d.ts +3 -0
- package/vocabularies/dashDataset.js +2370 -0
- package/vocabularies/index.d.ts +2 -0
- package/vocabularies/index.js +2 -0
- package/vocabularies/shaclmate.d.ts +15 -0
- package/vocabularies/shaclmate.js +6 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Type } from "./Type.js";
|
|
2
|
+
import { rdfjsTermExpression } from "./rdfjsTermExpression";
|
|
3
|
+
/**
|
|
4
|
+
* Abstract base class for IdentifierType and LiteralType.
|
|
5
|
+
*/
|
|
6
|
+
export class RdfjsTermType extends Type {
|
|
7
|
+
constructor({ defaultValue, hasValue, ...superParameters }) {
|
|
8
|
+
super(superParameters);
|
|
9
|
+
this.defaultValue = defaultValue;
|
|
10
|
+
this.hasValue = hasValue;
|
|
11
|
+
}
|
|
12
|
+
equalsFunction() {
|
|
13
|
+
return "purifyHelpers.Equatable.booleanEquals";
|
|
14
|
+
}
|
|
15
|
+
fromRdfExpression({ variables, }) {
|
|
16
|
+
const chain = [`${variables.resourceValues}.head()`];
|
|
17
|
+
this.hasValue.ifJust((hasValue) => {
|
|
18
|
+
chain.push(`chain<rdfjsResource.Resource.ValueError, ${this.name}>(_identifier => _identifier.equals(${rdfjsTermExpression(hasValue, this.configuration)}) ? purify.Either.of(_identifier) : purify.Left(new rdfjsResource.Resource.MistypedValueError({ actualValue: _identifier, expectedValueType: "${hasValue.termType}", focusResource: ${variables.resource}, predicate: ${variables.predicate})))`);
|
|
19
|
+
});
|
|
20
|
+
this.defaultValue.ifJust((defaultValue) => {
|
|
21
|
+
chain.push(`alt(purify.Either.of(new rdfjsResource.Resource.Value({ subject: ${variables.resource}, predicate: ${variables.predicate}, object: ${rdfjsTermExpression(defaultValue, this.configuration)} })))`);
|
|
22
|
+
});
|
|
23
|
+
chain.push(`chain(value => ${this.fromRdfResourceValueExpression({
|
|
24
|
+
variables: { resourceValue: "value" },
|
|
25
|
+
})})`);
|
|
26
|
+
return chain.join(".");
|
|
27
|
+
}
|
|
28
|
+
propertySparqlGraphPatternExpression({ variables, }) {
|
|
29
|
+
let expression = super
|
|
30
|
+
.propertySparqlGraphPatternExpression({
|
|
31
|
+
variables,
|
|
32
|
+
})
|
|
33
|
+
.toSparqlGraphPatternExpression()
|
|
34
|
+
.toString();
|
|
35
|
+
if (this.defaultValue.isJust()) {
|
|
36
|
+
expression = `sparqlBuilder.GraphPattern.optional(${expression})`;
|
|
37
|
+
}
|
|
38
|
+
return new Type.SparqlGraphPatternExpression(expression);
|
|
39
|
+
}
|
|
40
|
+
toRdfExpression({ variables, }) {
|
|
41
|
+
return this.defaultValue
|
|
42
|
+
.map((defaultValue) => `!${variables.value}.equals(${rdfjsTermExpression(defaultValue, this.configuration)}) ? ${variables.value} : undefined`)
|
|
43
|
+
.orDefault(variables.value);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=RdfjsTermType.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Type } from "./Type.js";
|
|
2
|
+
export declare class SetType extends Type {
|
|
3
|
+
readonly itemType: Type;
|
|
4
|
+
readonly kind = "SetType";
|
|
5
|
+
private readonly minCount;
|
|
6
|
+
constructor({ itemType, minCount, ...superParameters }: ConstructorParameters<typeof Type>[0] & {
|
|
7
|
+
itemType: Type;
|
|
8
|
+
minCount: number;
|
|
9
|
+
});
|
|
10
|
+
get conversions(): readonly Type.Conversion[];
|
|
11
|
+
get name(): string;
|
|
12
|
+
chainSparqlGraphPatternExpression(parameters: Parameters<Type["chainSparqlGraphPatternExpression"]>[0]): ReturnType<Type["chainSparqlGraphPatternExpression"]>;
|
|
13
|
+
equalsFunction(): string;
|
|
14
|
+
fromRdfExpression({ variables, }: Parameters<Type["fromRdfExpression"]>[0]): string;
|
|
15
|
+
hashStatements({ variables, }: Parameters<Type["hashStatements"]>[0]): readonly string[];
|
|
16
|
+
propertySparqlGraphPatternExpression(parameters: Parameters<Type["propertySparqlGraphPatternExpression"]>[0]): Type.SparqlGraphPatternExpression | Type.SparqlGraphPatternsExpression;
|
|
17
|
+
toRdfExpression({ variables, }: Parameters<Type["toRdfExpression"]>[0]): string;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=SetType.d.ts.map
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { Memoize } from "typescript-memoize";
|
|
8
|
+
import { Type } from "./Type.js";
|
|
9
|
+
export class SetType extends Type {
|
|
10
|
+
constructor({ itemType, minCount, ...superParameters }) {
|
|
11
|
+
super(superParameters);
|
|
12
|
+
this.kind = "SetType";
|
|
13
|
+
this.itemType = itemType;
|
|
14
|
+
this.minCount = minCount;
|
|
15
|
+
}
|
|
16
|
+
get conversions() {
|
|
17
|
+
return [
|
|
18
|
+
{
|
|
19
|
+
conversionExpression: () => "[]",
|
|
20
|
+
sourceTypeName: "undefined",
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
conversionExpression: (value) => value,
|
|
24
|
+
sourceTypeCheckExpression: (value) => `Array.isArray(${value})`,
|
|
25
|
+
sourceTypeName: this.name,
|
|
26
|
+
},
|
|
27
|
+
];
|
|
28
|
+
}
|
|
29
|
+
get name() {
|
|
30
|
+
return `readonly (${this.itemType.name})[]`;
|
|
31
|
+
}
|
|
32
|
+
chainSparqlGraphPatternExpression(parameters) {
|
|
33
|
+
return this.itemType.chainSparqlGraphPatternExpression(parameters);
|
|
34
|
+
}
|
|
35
|
+
equalsFunction() {
|
|
36
|
+
const itemTypeEqualsFunction = this.itemType.equalsFunction();
|
|
37
|
+
if (itemTypeEqualsFunction === "purifyHelpers.Equatable.equals") {
|
|
38
|
+
return "purifyHelpers.Equatable.arrayEquals";
|
|
39
|
+
}
|
|
40
|
+
return `(left, right) => purifyHelpers.Arrays.equals(left, right, ${itemTypeEqualsFunction})`;
|
|
41
|
+
}
|
|
42
|
+
fromRdfExpression({ variables, }) {
|
|
43
|
+
return `purify.Either.of([...${variables.resourceValues}.flatMap(value => ${this.itemType.fromRdfExpression({ variables: { ...variables, resourceValues: "value.toValues()" } })}.toMaybe().toList())])`;
|
|
44
|
+
}
|
|
45
|
+
hashStatements({ variables, }) {
|
|
46
|
+
return [
|
|
47
|
+
`for (const element of ${variables.value}) { ${this.itemType
|
|
48
|
+
.hashStatements({
|
|
49
|
+
variables: {
|
|
50
|
+
hasher: variables.hasher,
|
|
51
|
+
value: "element",
|
|
52
|
+
},
|
|
53
|
+
})
|
|
54
|
+
.join("\n")} }`,
|
|
55
|
+
];
|
|
56
|
+
}
|
|
57
|
+
propertySparqlGraphPatternExpression(parameters) {
|
|
58
|
+
if (this.minCount === 0) {
|
|
59
|
+
return new Type.SparqlGraphPatternExpression(`sparqlBuilder.GraphPattern.optional(${this.itemType.propertySparqlGraphPatternExpression(parameters).toSparqlGraphPatternExpression()})`);
|
|
60
|
+
}
|
|
61
|
+
return this.itemType.propertySparqlGraphPatternExpression(parameters);
|
|
62
|
+
}
|
|
63
|
+
toRdfExpression({ variables, }) {
|
|
64
|
+
const itemTypeToRdfExpression = this.itemType.toRdfExpression({
|
|
65
|
+
variables: { ...variables, value: "value" },
|
|
66
|
+
});
|
|
67
|
+
if (itemTypeToRdfExpression === "value") {
|
|
68
|
+
return variables.value;
|
|
69
|
+
}
|
|
70
|
+
return `${variables.value}.map((value) => ${itemTypeToRdfExpression})`;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
__decorate([
|
|
74
|
+
Memoize()
|
|
75
|
+
], SetType.prototype, "name", null);
|
|
76
|
+
//# sourceMappingURL=SetType.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PrimitiveType } from "./PrimitiveType.js";
|
|
2
|
+
export declare class StringType extends PrimitiveType {
|
|
3
|
+
get name(): string;
|
|
4
|
+
fromRdfResourceValueExpression({ variables, }: Parameters<PrimitiveType["fromRdfResourceValueExpression"]>[0]): string;
|
|
5
|
+
hashStatements({ variables, }: Parameters<PrimitiveType["hashStatements"]>[0]): readonly string[];
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=StringType.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PrimitiveType } from "./PrimitiveType.js";
|
|
2
|
+
export class StringType extends PrimitiveType {
|
|
3
|
+
get name() {
|
|
4
|
+
return "string";
|
|
5
|
+
}
|
|
6
|
+
fromRdfResourceValueExpression({ variables, }) {
|
|
7
|
+
return `${variables.resourceValue}.toString()`;
|
|
8
|
+
}
|
|
9
|
+
hashStatements({ variables, }) {
|
|
10
|
+
return [`${variables.hasher}.update(${variables.value});`];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=StringType.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type * as ast from "../../ast";
|
|
2
|
+
import { Configuration as GlobalConfiguration } from "./Configuration.js";
|
|
3
|
+
export declare class TsGenerator {
|
|
4
|
+
private ast;
|
|
5
|
+
protected readonly configuration: TsGenerator.Configuration;
|
|
6
|
+
constructor(ast: ast.Ast, configuration?: TsGenerator.Configuration);
|
|
7
|
+
generate(): string;
|
|
8
|
+
private addDeclarations;
|
|
9
|
+
private addImportDeclarations;
|
|
10
|
+
}
|
|
11
|
+
export declare namespace TsGenerator {
|
|
12
|
+
const Configuration: typeof GlobalConfiguration;
|
|
13
|
+
type Configuration = GlobalConfiguration;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=TsGenerator.d.ts.map
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { Project, StructureKind, } from "ts-morph";
|
|
2
|
+
import { Configuration as GlobalConfiguration } from "./Configuration.js";
|
|
3
|
+
import { TypeFactory } from "./TypeFactory.js";
|
|
4
|
+
import { tsName } from "./tsName.js";
|
|
5
|
+
export class TsGenerator {
|
|
6
|
+
constructor(ast, configuration) {
|
|
7
|
+
this.ast = ast;
|
|
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
|
+
});
|
|
24
|
+
const project = new Project({
|
|
25
|
+
useInMemoryFileSystem: true,
|
|
26
|
+
});
|
|
27
|
+
const sourceFile = project.createSourceFile("generated.ts");
|
|
28
|
+
const typeFactory = new TypeFactory({ configuration: this.configuration });
|
|
29
|
+
const objectTypes = astObjectTypes.flatMap((astObjectType) => {
|
|
30
|
+
const type = typeFactory.createTypeFromAstType(astObjectType);
|
|
31
|
+
return type.kind === "ObjectType" ? [type] : [];
|
|
32
|
+
});
|
|
33
|
+
this.addDeclarations(objectTypes, sourceFile);
|
|
34
|
+
sourceFile.saveSync();
|
|
35
|
+
return project.getFileSystem().readFileSync(sourceFile.getFilePath());
|
|
36
|
+
}
|
|
37
|
+
addDeclarations(objectTypes, sourceFile) {
|
|
38
|
+
this.addImportDeclarations(objectTypes, sourceFile);
|
|
39
|
+
for (const objectType of objectTypes) {
|
|
40
|
+
switch (this.configuration.objectTypeDeclarationType) {
|
|
41
|
+
case "class":
|
|
42
|
+
sourceFile.addClass(objectType.classDeclaration());
|
|
43
|
+
break;
|
|
44
|
+
case "interface":
|
|
45
|
+
sourceFile.addInterface(objectType.interfaceDeclaration());
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
const moduleStatements = [];
|
|
49
|
+
if (this.configuration.features.has("equals") &&
|
|
50
|
+
this.configuration.objectTypeDeclarationType === "interface") {
|
|
51
|
+
moduleStatements.push(objectType.equalsFunctionDeclaration());
|
|
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`);
|
|
62
|
+
}
|
|
63
|
+
moduleStatements.push(objectType.sparqlGraphPatternsClassDeclaration());
|
|
64
|
+
}
|
|
65
|
+
if (this.configuration.features.has("toRdf") &&
|
|
66
|
+
this.configuration.objectTypeDeclarationType === "interface") {
|
|
67
|
+
moduleStatements.push(objectType.toRdfFunctionDeclaration());
|
|
68
|
+
}
|
|
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
|
+
}
|
|
94
|
+
if (this.configuration.features.has("fromRdf") ||
|
|
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();
|
|
108
|
+
for (const objectType of objectTypes) {
|
|
109
|
+
for (const importStatement of objectType.importStatements) {
|
|
110
|
+
typeImportStatements.add(importStatement);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
sourceFile.addStatements([...typeImportStatements]);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
(function (TsGenerator) {
|
|
117
|
+
TsGenerator.Configuration = GlobalConfiguration;
|
|
118
|
+
})(TsGenerator || (TsGenerator = {}));
|
|
119
|
+
//# sourceMappingURL=TsGenerator.js.map
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
2
|
+
import type * as ast from "../../ast";
|
|
3
|
+
import type { Configuration } from "./Configuration.js";
|
|
4
|
+
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
|
+
/**
|
|
12
|
+
* Expressions that convert a source type or types to this type. It should include the type itself.
|
|
13
|
+
*/
|
|
14
|
+
get conversions(): readonly Type.Conversion[];
|
|
15
|
+
/**
|
|
16
|
+
* A property that discriminates sub-types of this type e.g., termType on RDF/JS terms.
|
|
17
|
+
*/
|
|
18
|
+
get discriminatorProperty(): Maybe<Type.DiscriminatorProperty>;
|
|
19
|
+
/**
|
|
20
|
+
* Imports used by other methods on this type.
|
|
21
|
+
*/
|
|
22
|
+
get importStatements(): readonly string[];
|
|
23
|
+
/**
|
|
24
|
+
* An optional sparqlBuilder.GraphPattern expression that's chained to the object of another pattern, such as a list item.
|
|
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.
|
|
28
|
+
*/
|
|
29
|
+
chainSparqlGraphPatternExpression(_: {
|
|
30
|
+
variables: {
|
|
31
|
+
subject: string;
|
|
32
|
+
};
|
|
33
|
+
}): Maybe<Type.SparqlGraphPatternExpression | Type.SparqlGraphPatternsExpression>;
|
|
34
|
+
/**
|
|
35
|
+
* A function (reference or declaration) that compares two values of this type, returning a
|
|
36
|
+
* purifyHelpers.Equatable.EqualsResult.
|
|
37
|
+
*/
|
|
38
|
+
abstract equalsFunction(): string;
|
|
39
|
+
/**
|
|
40
|
+
* An expression that converts a rdfjsResource.Resource.Values to an Either of value/values
|
|
41
|
+
* of this type.
|
|
42
|
+
*/
|
|
43
|
+
abstract fromRdfExpression(parameters: {
|
|
44
|
+
variables: {
|
|
45
|
+
predicate: string;
|
|
46
|
+
resource: string;
|
|
47
|
+
resourceValues: string;
|
|
48
|
+
};
|
|
49
|
+
}): string;
|
|
50
|
+
/**
|
|
51
|
+
* Statements that use hasher.update to hash a value of this type.
|
|
52
|
+
*/
|
|
53
|
+
abstract hashStatements(parameters: {
|
|
54
|
+
variables: {
|
|
55
|
+
hasher: string;
|
|
56
|
+
value: string;
|
|
57
|
+
};
|
|
58
|
+
}): readonly string[];
|
|
59
|
+
/**
|
|
60
|
+
* An sparqlBuilder.GraphPattern expression for a property, typically building a basic graph pattern.
|
|
61
|
+
*/
|
|
62
|
+
propertySparqlGraphPatternExpression({ variables, }: {
|
|
63
|
+
variables: {
|
|
64
|
+
object: string;
|
|
65
|
+
predicate: string;
|
|
66
|
+
subject: string;
|
|
67
|
+
};
|
|
68
|
+
}): Type.SparqlGraphPatternExpression | Type.SparqlGraphPatternsExpression;
|
|
69
|
+
/**
|
|
70
|
+
* An expression that converts a value of this type to one that that can be .add'd to
|
|
71
|
+
* an rdfjsResource.Resource.
|
|
72
|
+
*/
|
|
73
|
+
abstract toRdfExpression(parameters: {
|
|
74
|
+
variables: {
|
|
75
|
+
predicate: string;
|
|
76
|
+
mutateGraph: string;
|
|
77
|
+
resource: string;
|
|
78
|
+
resourceSet: string;
|
|
79
|
+
value: string;
|
|
80
|
+
};
|
|
81
|
+
}): string;
|
|
82
|
+
}
|
|
83
|
+
export declare namespace Type {
|
|
84
|
+
interface Conversion {
|
|
85
|
+
readonly conversionExpression: (value: string) => string;
|
|
86
|
+
readonly sourceTypeCheckExpression?: (value: string) => string;
|
|
87
|
+
readonly sourceTypeName: string;
|
|
88
|
+
}
|
|
89
|
+
interface DiscriminatorProperty {
|
|
90
|
+
readonly name: string;
|
|
91
|
+
readonly values: readonly string[];
|
|
92
|
+
}
|
|
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
|
+
}
|
|
108
|
+
//# sourceMappingURL=Type.d.ts.map
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
2
|
+
export class Type {
|
|
3
|
+
constructor({ configuration, }) {
|
|
4
|
+
this.configuration = configuration;
|
|
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
|
+
];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A property that discriminates sub-types of this type e.g., termType on RDF/JS terms.
|
|
19
|
+
*/
|
|
20
|
+
get discriminatorProperty() {
|
|
21
|
+
return Maybe.empty();
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Imports used by other methods on this type.
|
|
25
|
+
*/
|
|
26
|
+
get importStatements() {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* An optional sparqlBuilder.GraphPattern expression that's chained to the object of another pattern, such as a list item.
|
|
31
|
+
*
|
|
32
|
+
* 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
|
|
33
|
+
* method will return nothing.
|
|
34
|
+
*/
|
|
35
|
+
chainSparqlGraphPatternExpression(_) {
|
|
36
|
+
return Maybe.empty();
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* An sparqlBuilder.GraphPattern expression for a property, typically building a basic graph pattern.
|
|
40
|
+
*/
|
|
41
|
+
propertySparqlGraphPatternExpression({ variables, }) {
|
|
42
|
+
let expression = `sparqlBuilder.GraphPattern.basic(${variables.subject}, ${variables.predicate}, ${variables.object})`;
|
|
43
|
+
this.chainSparqlGraphPatternExpression({
|
|
44
|
+
variables: { subject: "object" },
|
|
45
|
+
}).ifJust((chainSparqlGraphPatternExpression) => {
|
|
46
|
+
expression = `sparqlBuilder.GraphPattern.group(${expression}.chainObject(object => ${chainSparqlGraphPatternExpression.toSparqlGraphPatternsExpression()}))`;
|
|
47
|
+
});
|
|
48
|
+
return new Type.SparqlGraphPatternExpression(expression);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
(function (Type) {
|
|
52
|
+
class SparqlGraphPatternExpression {
|
|
53
|
+
constructor(value) {
|
|
54
|
+
this.value = value;
|
|
55
|
+
}
|
|
56
|
+
toSparqlGraphPatternExpression() {
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
toSparqlGraphPatternsExpression() {
|
|
60
|
+
return new SparqlGraphPatternExpression(`[${this.value}]`);
|
|
61
|
+
}
|
|
62
|
+
toString() {
|
|
63
|
+
return this.value;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
Type.SparqlGraphPatternExpression = SparqlGraphPatternExpression;
|
|
67
|
+
class SparqlGraphPatternsExpression {
|
|
68
|
+
constructor(value) {
|
|
69
|
+
this.value = value;
|
|
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
|
+
}
|
|
80
|
+
}
|
|
81
|
+
Type.SparqlGraphPatternsExpression = SparqlGraphPatternsExpression;
|
|
82
|
+
})(Type || (Type = {}));
|
|
83
|
+
//# sourceMappingURL=Type.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type * as ast from "../../ast";
|
|
2
|
+
import type { Configuration } from "./Configuration";
|
|
3
|
+
import type { Type } from "./Type.js";
|
|
4
|
+
export declare class TypeFactory {
|
|
5
|
+
private cachedObjectTypePropertiesByIdentifier;
|
|
6
|
+
private cachedObjectTypesByIdentifier;
|
|
7
|
+
private readonly configuration;
|
|
8
|
+
constructor({ configuration }: {
|
|
9
|
+
configuration: Configuration;
|
|
10
|
+
});
|
|
11
|
+
createTypeFromAstType(astType: ast.Type): Type;
|
|
12
|
+
private createObjectTypeFromAstType;
|
|
13
|
+
private createObjectTypePropertyFromAstProperty;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=TypeFactory.d.ts.map
|