@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,29 @@
|
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
2
|
+
import type { GetAccessorDeclarationStructure, OptionalKind, PropertyDeclarationStructure, PropertySignatureStructure } from "ts-morph";
|
|
3
|
+
import { Property } from "./Property.js";
|
|
4
|
+
export declare class TypeDiscriminatorProperty extends Property<TypeDiscriminatorProperty.Type> {
|
|
5
|
+
readonly equalsFunction = "purifyHelpers.Equatable.strictEquals";
|
|
6
|
+
readonly value: string;
|
|
7
|
+
private readonly abstract;
|
|
8
|
+
private readonly override;
|
|
9
|
+
constructor({ abstract, override, value, ...superParameters }: {
|
|
10
|
+
abstract: boolean;
|
|
11
|
+
override: boolean;
|
|
12
|
+
value: string;
|
|
13
|
+
} & ConstructorParameters<typeof Property>[0]);
|
|
14
|
+
get classConstructorParametersPropertySignature(): Maybe<OptionalKind<PropertySignatureStructure>>;
|
|
15
|
+
get classGetAccessorDeclaration(): Maybe<OptionalKind<GetAccessorDeclarationStructure>>;
|
|
16
|
+
get classPropertyDeclaration(): OptionalKind<PropertyDeclarationStructure>;
|
|
17
|
+
get interfacePropertySignature(): OptionalKind<PropertySignatureStructure>;
|
|
18
|
+
classConstructorStatements(): readonly string[];
|
|
19
|
+
fromRdfStatements(): readonly string[];
|
|
20
|
+
hashStatements(): readonly string[];
|
|
21
|
+
sparqlGraphPatternExpression(): Maybe<string>;
|
|
22
|
+
toRdfStatements(): readonly string[];
|
|
23
|
+
}
|
|
24
|
+
export declare namespace TypeDiscriminatorProperty {
|
|
25
|
+
interface Type {
|
|
26
|
+
readonly name: string;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=TypeDiscriminatorProperty.d.ts.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
2
|
+
import { Property } from "./Property.js";
|
|
3
|
+
export class TypeDiscriminatorProperty extends Property {
|
|
4
|
+
constructor({ abstract, override, value, ...superParameters }) {
|
|
5
|
+
super(superParameters);
|
|
6
|
+
this.equalsFunction = "purifyHelpers.Equatable.strictEquals";
|
|
7
|
+
this.abstract = abstract;
|
|
8
|
+
this.override = override;
|
|
9
|
+
this.value = value;
|
|
10
|
+
}
|
|
11
|
+
get classConstructorParametersPropertySignature() {
|
|
12
|
+
return Maybe.empty();
|
|
13
|
+
}
|
|
14
|
+
get classGetAccessorDeclaration() {
|
|
15
|
+
return Maybe.empty();
|
|
16
|
+
}
|
|
17
|
+
get classPropertyDeclaration() {
|
|
18
|
+
return {
|
|
19
|
+
isAbstract: this.abstract,
|
|
20
|
+
hasOverrideKeyword: this.override,
|
|
21
|
+
initializer: !this.abstract ? `"${this.value}"` : undefined,
|
|
22
|
+
isReadonly: true,
|
|
23
|
+
name: this.name,
|
|
24
|
+
type: this.type.name,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
get interfacePropertySignature() {
|
|
28
|
+
return {
|
|
29
|
+
isReadonly: true,
|
|
30
|
+
name: this.name,
|
|
31
|
+
type: this.type.name,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
classConstructorStatements() {
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
fromRdfStatements() {
|
|
38
|
+
return !this.abstract &&
|
|
39
|
+
this.configuration.objectTypeDeclarationType === "interface"
|
|
40
|
+
? [`const ${this.name} = "${this.value}" as const`]
|
|
41
|
+
: [];
|
|
42
|
+
}
|
|
43
|
+
hashStatements() {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
sparqlGraphPatternExpression() {
|
|
47
|
+
return Maybe.empty();
|
|
48
|
+
}
|
|
49
|
+
toRdfStatements() {
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=TypeDiscriminatorProperty.js.map
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { rdf } from "@tpluscode/rdf-ns-builders";
|
|
2
|
+
import { StructureKind, } from "ts-morph";
|
|
3
|
+
import { hasherTypeConstraint } from "./hashFunctionDeclaration.js";
|
|
4
|
+
function constructorDeclaration() {
|
|
5
|
+
if (this.properties.length === 0) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
const statements = [];
|
|
9
|
+
if (this.parentObjectTypes.length > 0) {
|
|
10
|
+
statements.push("super(parameters);");
|
|
11
|
+
}
|
|
12
|
+
for (const property of this.properties) {
|
|
13
|
+
for (const statement of property.classConstructorStatements({
|
|
14
|
+
variables: { parameter: `parameters.${property.name}` },
|
|
15
|
+
})) {
|
|
16
|
+
statements.push(statement);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const constructorParameterPropertySignatures = this.properties.flatMap((property) => property.classConstructorParametersPropertySignature
|
|
20
|
+
.map((propertySignature) => `readonly ${propertySignature.name}${propertySignature.hasQuestionToken ? "?" : ""}: ${propertySignature.type}`)
|
|
21
|
+
.toList());
|
|
22
|
+
if (constructorParameterPropertySignatures.length === 0) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
let constructorParametersType = `{ ${constructorParameterPropertySignatures.join(", ")} }`;
|
|
26
|
+
if (this.parentObjectTypes.length > 0) {
|
|
27
|
+
constructorParametersType = `${constructorParametersType} & ConstructorParameters<typeof ${this.parentObjectTypes[0].name}>[0]`;
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
parameters: [
|
|
31
|
+
{
|
|
32
|
+
name: "parameters",
|
|
33
|
+
type: constructorParametersType,
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
statements,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export function classDeclaration() {
|
|
40
|
+
this.ensureAtMostOneSuperObjectType();
|
|
41
|
+
const constructorDeclaration_ = constructorDeclaration.bind(this)();
|
|
42
|
+
const methods = [];
|
|
43
|
+
if (this.configuration.features.has("equals")) {
|
|
44
|
+
methods.push(equalsMethodDeclaration.bind(this)());
|
|
45
|
+
}
|
|
46
|
+
if (this.configuration.features.has("hash")) {
|
|
47
|
+
methods.push(hashMethodDeclaration.bind(this)());
|
|
48
|
+
}
|
|
49
|
+
if (this.configuration.features.has("toRdf")) {
|
|
50
|
+
methods.push(toRdfMethodDeclaration.bind(this)());
|
|
51
|
+
}
|
|
52
|
+
const getAccessors = [];
|
|
53
|
+
const properties = [];
|
|
54
|
+
for (const property of this.properties) {
|
|
55
|
+
properties.push(property.classPropertyDeclaration);
|
|
56
|
+
property.classGetAccessorDeclaration.ifJust((getAccessor) => getAccessors.push(getAccessor));
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
ctors: constructorDeclaration_ !== null ? [constructorDeclaration_] : undefined,
|
|
60
|
+
extends: this.parentObjectTypes.length > 0
|
|
61
|
+
? this.parentObjectTypes[0].name
|
|
62
|
+
: undefined,
|
|
63
|
+
getAccessors,
|
|
64
|
+
isAbstract: this.abstract,
|
|
65
|
+
kind: StructureKind.Class,
|
|
66
|
+
isExported: this.export_,
|
|
67
|
+
methods,
|
|
68
|
+
name: this.name,
|
|
69
|
+
properties,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function equalsMethodDeclaration() {
|
|
73
|
+
let expression = `purifyHelpers.Equatable.objectEquals(this, other, { ${this.properties
|
|
74
|
+
.map((property) => `${property.name}: ${property.equalsFunction}`)
|
|
75
|
+
.join()} })`;
|
|
76
|
+
if (this.parentObjectTypes.length > 0) {
|
|
77
|
+
expression = `super.equals(other).chain(() => ${expression})`;
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
hasOverrideKeyword: this.parentObjectTypes.length > 0,
|
|
81
|
+
name: "equals",
|
|
82
|
+
parameters: [
|
|
83
|
+
{
|
|
84
|
+
name: "other",
|
|
85
|
+
type: this.name,
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
statements: [`return ${expression};`],
|
|
89
|
+
returnType: "purifyHelpers.Equatable.EqualsResult",
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function hashMethodDeclaration() {
|
|
93
|
+
return {
|
|
94
|
+
hasOverrideKeyword: this.parentObjectTypes.length > 0,
|
|
95
|
+
name: "hash",
|
|
96
|
+
parameters: [
|
|
97
|
+
{
|
|
98
|
+
name: "hasher",
|
|
99
|
+
type: "HasherT",
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
returnType: "HasherT",
|
|
103
|
+
statements: [`return ${this.name}.${this.hashFunctionName}(this, hasher);`],
|
|
104
|
+
typeParameters: [
|
|
105
|
+
{
|
|
106
|
+
name: "HasherT",
|
|
107
|
+
constraint: hasherTypeConstraint,
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function toRdfMethodDeclaration() {
|
|
113
|
+
const variables = {
|
|
114
|
+
ignoreRdfType: "ignoreRdfType",
|
|
115
|
+
mutateGraph: "mutateGraph",
|
|
116
|
+
resource: "resource",
|
|
117
|
+
resourceSet: "resourceSet",
|
|
118
|
+
};
|
|
119
|
+
let usedIgnoreRdfTypeVariable = false;
|
|
120
|
+
const statements = [];
|
|
121
|
+
if (this.parentObjectTypes.length > 0) {
|
|
122
|
+
statements.push(`const ${variables.resource} = super.toRdf({ ${variables.mutateGraph}, ${variables.ignoreRdfType}: true, ${variables.resourceSet} });`);
|
|
123
|
+
usedIgnoreRdfTypeVariable = true;
|
|
124
|
+
}
|
|
125
|
+
else if (this.identifierType.isNamedNodeKind) {
|
|
126
|
+
statements.push(`const ${variables.resource} = ${variables.resourceSet}.mutableNamedResource({ identifier: this.${this.configuration.objectTypeIdentifierPropertyName}, ${variables.mutateGraph} });`);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
statements.push(`const ${variables.resource} = ${variables.resourceSet}.mutableResource({ identifier: this.${this.configuration.objectTypeIdentifierPropertyName}, ${variables.mutateGraph} });`);
|
|
130
|
+
}
|
|
131
|
+
this.rdfType.ifJust((rdfType) => {
|
|
132
|
+
statements.push(`if (!${variables.ignoreRdfType}) { ${variables.resource}.add(${variables.resource}.dataFactory.namedNode("${rdf.type.value}"), ${variables.resource}.dataFactory.namedNode("${rdfType.value}")); }`);
|
|
133
|
+
usedIgnoreRdfTypeVariable = true;
|
|
134
|
+
});
|
|
135
|
+
for (const property of this.properties) {
|
|
136
|
+
statements.push(...property.toRdfStatements({
|
|
137
|
+
variables: { ...variables, value: `this.${property.name}` },
|
|
138
|
+
}));
|
|
139
|
+
}
|
|
140
|
+
statements.push(`return ${variables.resource};`);
|
|
141
|
+
return {
|
|
142
|
+
hasOverrideKeyword: this.parentObjectTypes.length > 0,
|
|
143
|
+
name: "toRdf",
|
|
144
|
+
parameters: [
|
|
145
|
+
{
|
|
146
|
+
name: `{ ${usedIgnoreRdfTypeVariable ? `${variables.ignoreRdfType},` : ""} ${variables.mutateGraph}, ${variables.resourceSet} }`,
|
|
147
|
+
type: `{ ${variables.ignoreRdfType}?: boolean; ${variables.mutateGraph}: rdfjsResource.MutableResource.MutateGraph, ${variables.resourceSet}: rdfjsResource.MutableResourceSet }`,
|
|
148
|
+
},
|
|
149
|
+
],
|
|
150
|
+
returnType: this.rdfjsResourceType({ mutable: true }).name,
|
|
151
|
+
statements,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=classDeclaration.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type FunctionDeclarationStructure } from "ts-morph";
|
|
2
|
+
import type { ObjectType } from "../ObjectType.js";
|
|
3
|
+
export declare function equalsFunctionDeclaration(this: ObjectType): FunctionDeclarationStructure;
|
|
4
|
+
//# sourceMappingURL=equalsFunctionDeclaration.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { StructureKind } from "ts-morph";
|
|
2
|
+
export function equalsFunctionDeclaration() {
|
|
3
|
+
let expression = `purifyHelpers.Equatable.objectEquals(left, right, { ${this.properties
|
|
4
|
+
.map((property) => `${property.name}: ${property.equalsFunction}`)
|
|
5
|
+
.join()} })`;
|
|
6
|
+
for (const parentObjectType of this.parentObjectTypes) {
|
|
7
|
+
expression = `${parentObjectType.name}.equals(left, right).chain(() => ${expression})`;
|
|
8
|
+
}
|
|
9
|
+
return {
|
|
10
|
+
isExported: true,
|
|
11
|
+
kind: StructureKind.Function,
|
|
12
|
+
name: "equals",
|
|
13
|
+
parameters: [
|
|
14
|
+
{
|
|
15
|
+
name: "left",
|
|
16
|
+
type: this.name,
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: "right",
|
|
20
|
+
type: this.name,
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
statements: [`return ${expression};`],
|
|
24
|
+
returnType: "purifyHelpers.Equatable.EqualsResult",
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=equalsFunctionDeclaration.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type FunctionDeclarationStructure } from "ts-morph";
|
|
2
|
+
import type { ObjectType } from "../ObjectType.js";
|
|
3
|
+
export declare function fromRdfFunctionDeclaration(this: ObjectType): FunctionDeclarationStructure;
|
|
4
|
+
//# sourceMappingURL=fromRdfFunctionDeclaration.d.ts.map
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { StructureKind } from "ts-morph";
|
|
2
|
+
import { rdfjsTermExpression } from "../rdfjsTermExpression.js";
|
|
3
|
+
const variables = {
|
|
4
|
+
ignoreRdfType: "ignoreRdfType",
|
|
5
|
+
options: "_options",
|
|
6
|
+
resource: "resource",
|
|
7
|
+
};
|
|
8
|
+
export function fromRdfFunctionDeclaration() {
|
|
9
|
+
this.ensureAtMostOneSuperObjectType();
|
|
10
|
+
const propertiesByName = {};
|
|
11
|
+
let statements = [];
|
|
12
|
+
this.rdfType.ifJust((rdfType) => {
|
|
13
|
+
statements.push(`if (!${variables.options}?.${variables.ignoreRdfType} && !${variables.resource}.isInstanceOf(${rdfjsTermExpression(rdfType, this.configuration)})) { return purify.Left(new rdfjsResource.Resource.ValueError({ focusResource: ${variables.resource}, message: \`\${rdfjsResource.Resource.Identifier.toString(${variables.resource}.identifier)} has unexpected RDF type\`, predicate: ${rdfjsTermExpression(rdfType, this.configuration)} })); }`);
|
|
14
|
+
});
|
|
15
|
+
for (const ancestorObjectType of this.ancestorObjectTypes) {
|
|
16
|
+
for (const property of ancestorObjectType.properties) {
|
|
17
|
+
if (property.fromRdfStatements({ variables }).length > 0) {
|
|
18
|
+
propertiesByName[property.name] = {
|
|
19
|
+
initializer: `_super.${property.name}`,
|
|
20
|
+
type: property.type.name,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
for (const property of this.properties) {
|
|
26
|
+
const propertyFromRdfStatements = property.fromRdfStatements({
|
|
27
|
+
variables,
|
|
28
|
+
});
|
|
29
|
+
if (propertyFromRdfStatements.length > 0) {
|
|
30
|
+
propertiesByName[property.name] = {
|
|
31
|
+
type: property.type.name,
|
|
32
|
+
};
|
|
33
|
+
statements.push(...propertyFromRdfStatements);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
let construction = `{ ${Object.entries(propertiesByName)
|
|
37
|
+
.map(([name, { initializer }]) => initializer ? `${name}: ${initializer}` : name)
|
|
38
|
+
.join(", ")} }`;
|
|
39
|
+
let returnType = `{ ${Object.entries(propertiesByName)
|
|
40
|
+
.map(([name, { type }]) => `${name}: ${type}`)
|
|
41
|
+
.join(", ")} }`;
|
|
42
|
+
if (this.configuration.objectTypeDeclarationType === "class" &&
|
|
43
|
+
!this.abstract) {
|
|
44
|
+
construction = `new ${this.name}(${construction})`;
|
|
45
|
+
returnType = this.name;
|
|
46
|
+
}
|
|
47
|
+
statements.push(`return purify.Either.of(${construction})`);
|
|
48
|
+
if (this.parentObjectTypes.length > 0) {
|
|
49
|
+
statements = [
|
|
50
|
+
`return ${this.parentObjectTypes[0].name}.fromRdf(${variables.resource}, { ${variables.ignoreRdfType}: true }).chain(_super => { ${statements.join("\n")} })`,
|
|
51
|
+
];
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
isExported: true,
|
|
55
|
+
kind: StructureKind.Function,
|
|
56
|
+
name: "fromRdf",
|
|
57
|
+
parameters: [
|
|
58
|
+
{
|
|
59
|
+
name: variables.resource,
|
|
60
|
+
type: this.rdfjsResourceType().name,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
hasQuestionToken: true,
|
|
64
|
+
name: variables.options,
|
|
65
|
+
type: `{ ${variables.ignoreRdfType}?: boolean }`,
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
returnType: `purify.Either<rdfjsResource.Resource.ValueError, ${returnType}>`,
|
|
69
|
+
statements,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=fromRdfFunctionDeclaration.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type FunctionDeclarationStructure } from "ts-morph";
|
|
2
|
+
import type { ObjectType } from "../ObjectType";
|
|
3
|
+
export declare const hasherTypeConstraint = "{ update: (message: string | number[] | ArrayBuffer | Uint8Array) => void; }";
|
|
4
|
+
export declare function hashFunctionDeclaration(this: ObjectType): FunctionDeclarationStructure;
|
|
5
|
+
//# sourceMappingURL=hashFunctionDeclaration.d.ts.map
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { camelCase } from "change-case";
|
|
2
|
+
import { StructureKind } from "ts-morph";
|
|
3
|
+
const hasherVariable = "hasher";
|
|
4
|
+
export const hasherTypeConstraint = "{ update: (message: string | number[] | ArrayBuffer | Uint8Array) => void; }";
|
|
5
|
+
export function hashFunctionDeclaration() {
|
|
6
|
+
const thisVariable = camelCase(this.name);
|
|
7
|
+
const omitPropertyNamesSet = new Set();
|
|
8
|
+
omitPropertyNamesSet.add(this.configuration.objectTypeIdentifierPropertyName);
|
|
9
|
+
omitPropertyNamesSet.add(this.configuration.objectTypeDiscriminatorPropertyName);
|
|
10
|
+
if (this.configuration.objectTypeDeclarationType === "class") {
|
|
11
|
+
omitPropertyNamesSet.add("equals");
|
|
12
|
+
omitPropertyNamesSet.add("hash");
|
|
13
|
+
omitPropertyNamesSet.add("toRdf");
|
|
14
|
+
}
|
|
15
|
+
const statements = [];
|
|
16
|
+
for (const parentObjectType of this.parentObjectTypes) {
|
|
17
|
+
statements.push(`${parentObjectType.name}.${parentObjectType.hashFunctionName}(${thisVariable}, ${hasherVariable})`);
|
|
18
|
+
}
|
|
19
|
+
for (const property of this.properties) {
|
|
20
|
+
const propertyValueVariable = `${thisVariable}.${property.name}`;
|
|
21
|
+
const propertyHashStatements = property.hashStatements({
|
|
22
|
+
variables: {
|
|
23
|
+
hasher: hasherVariable,
|
|
24
|
+
value: propertyValueVariable,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
if (propertyHashStatements.length === 0) {
|
|
28
|
+
omitPropertyNamesSet.add(property.name);
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (property.name === this.configuration.objectTypeIdentifierPropertyName) {
|
|
32
|
+
// Don't hash the identifier since we may be using hash to calculate the identifier, leading to infinite recursion
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
statements.push(...propertyHashStatements);
|
|
36
|
+
}
|
|
37
|
+
const omitPropertyNames = [...omitPropertyNamesSet];
|
|
38
|
+
omitPropertyNames.sort();
|
|
39
|
+
statements.push(`return ${hasherVariable};`);
|
|
40
|
+
return {
|
|
41
|
+
isExported: true,
|
|
42
|
+
kind: StructureKind.Function,
|
|
43
|
+
name: this.hashFunctionName,
|
|
44
|
+
parameters: [
|
|
45
|
+
{
|
|
46
|
+
name: thisVariable,
|
|
47
|
+
type: `Omit<${this.name}, ${omitPropertyNames.map((propertyName) => `"${propertyName}"`).join(" | ")}>`,
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: hasherVariable,
|
|
51
|
+
type: "HasherT",
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
returnType: "HasherT",
|
|
55
|
+
statements,
|
|
56
|
+
typeParameters: [
|
|
57
|
+
{
|
|
58
|
+
name: "HasherT",
|
|
59
|
+
constraint: hasherTypeConstraint,
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=hashFunctionDeclaration.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from "./classDeclaration.js";
|
|
2
|
+
export * from "./equalsFunctionDeclaration.js";
|
|
3
|
+
export * from "./fromRdfFunctionDeclaration.js";
|
|
4
|
+
export * from "./hashFunctionDeclaration.js";
|
|
5
|
+
export * from "./IdentifierProperty.js";
|
|
6
|
+
export * from "./interfaceDeclaration.js";
|
|
7
|
+
export * from "./Property.js";
|
|
8
|
+
export * from "./ShaclProperty.js";
|
|
9
|
+
export * from "./sparqlGraphPatternsClassDeclaration.js";
|
|
10
|
+
export * from "./toRdfFunctionDeclaration.js";
|
|
11
|
+
export * from "./TypeDiscriminatorProperty.js";
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from "./classDeclaration.js";
|
|
2
|
+
export * from "./equalsFunctionDeclaration.js";
|
|
3
|
+
export * from "./fromRdfFunctionDeclaration.js";
|
|
4
|
+
export * from "./hashFunctionDeclaration.js";
|
|
5
|
+
export * from "./IdentifierProperty.js";
|
|
6
|
+
export * from "./interfaceDeclaration.js";
|
|
7
|
+
export * from "./Property.js";
|
|
8
|
+
export * from "./ShaclProperty.js";
|
|
9
|
+
export * from "./sparqlGraphPatternsClassDeclaration.js";
|
|
10
|
+
export * from "./toRdfFunctionDeclaration.js";
|
|
11
|
+
export * from "./TypeDiscriminatorProperty.js";
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { StructureKind, } from "ts-morph";
|
|
2
|
+
export function interfaceDeclaration() {
|
|
3
|
+
const properties = this.properties.map((property) => property.interfacePropertySignature);
|
|
4
|
+
return {
|
|
5
|
+
extends: this.parentObjectTypes.map((parentObjectType) => parentObjectType.name),
|
|
6
|
+
isExported: true,
|
|
7
|
+
kind: StructureKind.Interface,
|
|
8
|
+
name: this.name,
|
|
9
|
+
properties,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=interfaceDeclaration.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type ClassDeclarationStructure } from "ts-morph";
|
|
2
|
+
import type { ObjectType } from "../ObjectType.js";
|
|
3
|
+
export declare function sparqlGraphPatternsClassDeclaration(this: ObjectType): ClassDeclarationStructure;
|
|
4
|
+
//# sourceMappingURL=sparqlGraphPatternsClassDeclaration.d.ts.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { StructureKind } from "ts-morph";
|
|
2
|
+
import { rdfjsTermExpression } from "../rdfjsTermExpression";
|
|
3
|
+
const ignoreRdfTypeVariable = "ignoreRdfType";
|
|
4
|
+
const optionsVariable = "_options";
|
|
5
|
+
const subjectVariable = "subject";
|
|
6
|
+
export function sparqlGraphPatternsClassDeclaration() {
|
|
7
|
+
this.ensureAtMostOneSuperObjectType();
|
|
8
|
+
const constructorStatements = [];
|
|
9
|
+
if (this.parentObjectTypes.length > 0) {
|
|
10
|
+
constructorStatements.push(`super(${subjectVariable}, { ignoreRdfType: true });`);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
constructorStatements.push(`super(${subjectVariable});`);
|
|
14
|
+
}
|
|
15
|
+
this.rdfType.ifJust((rdfType) => constructorStatements.push(`if (!${optionsVariable}?.${ignoreRdfTypeVariable}) { this.add(...new sparqlBuilder.RdfTypeGraphPatterns(${subjectVariable}, ${rdfjsTermExpression(rdfType, this.configuration)})); }`));
|
|
16
|
+
for (const property of this.properties) {
|
|
17
|
+
property
|
|
18
|
+
.sparqlGraphPatternExpression()
|
|
19
|
+
.ifJust((sparqlGraphPattern) => constructorStatements.push(`this.add(${sparqlGraphPattern});`));
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
ctors: [
|
|
23
|
+
{
|
|
24
|
+
parameters: [
|
|
25
|
+
{
|
|
26
|
+
name: subjectVariable,
|
|
27
|
+
type: "sparqlBuilder.ResourceGraphPatterns.SubjectParameter",
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
hasQuestionToken: true,
|
|
31
|
+
name: optionsVariable,
|
|
32
|
+
type: `{ ${ignoreRdfTypeVariable}?: boolean }`,
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
statements: constructorStatements,
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
extends: this.parentObjectTypes.length > 0
|
|
39
|
+
? `${this.parentObjectTypes[0].name}.SparqlGraphPatterns`
|
|
40
|
+
: "sparqlBuilder.ResourceGraphPatterns",
|
|
41
|
+
isExported: true,
|
|
42
|
+
kind: StructureKind.Class,
|
|
43
|
+
name: "SparqlGraphPatterns",
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=sparqlGraphPatternsClassDeclaration.js.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { rdf } from "@tpluscode/rdf-ns-builders";
|
|
2
|
+
import { camelCase } from "change-case";
|
|
3
|
+
import { StructureKind } from "ts-morph";
|
|
4
|
+
const variables = {
|
|
5
|
+
ignoreRdfType: "ignoreRdfType",
|
|
6
|
+
mutateGraph: "mutateGraph",
|
|
7
|
+
resource: "resource",
|
|
8
|
+
resourceSet: "resourceSet",
|
|
9
|
+
};
|
|
10
|
+
export function toRdfFunctionDeclaration() {
|
|
11
|
+
this.ensureAtMostOneSuperObjectType();
|
|
12
|
+
let usedIgnoreRdfTypeVariable = false;
|
|
13
|
+
const thisVariable = camelCase(this.name);
|
|
14
|
+
const statements = [];
|
|
15
|
+
if (this.parentObjectTypes.length > 0) {
|
|
16
|
+
statements.push(`const ${variables.resource} = ${this.parentObjectTypes[0].name}.toRdf(${thisVariable}, { ${variables.mutateGraph}, ${variables.ignoreRdfType}: true, ${variables.resourceSet} });`);
|
|
17
|
+
usedIgnoreRdfTypeVariable = true;
|
|
18
|
+
}
|
|
19
|
+
else if (this.identifierType.isNamedNodeKind) {
|
|
20
|
+
statements.push(`const ${variables.resource} = ${variables.resourceSet}.mutableNamedResource({ identifier: ${thisVariable}.${this.configuration.objectTypeIdentifierPropertyName}, ${variables.mutateGraph} });`);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
statements.push(`const ${variables.resource} = ${variables.resourceSet}.mutableResource({ identifier: ${thisVariable}.${this.configuration.objectTypeIdentifierPropertyName}, ${variables.mutateGraph} });`);
|
|
24
|
+
}
|
|
25
|
+
this.rdfType.ifJust((rdfType) => {
|
|
26
|
+
statements.push(`if (!${variables.ignoreRdfType}) { ${variables.resource}.add(${variables.resource}.dataFactory.namedNode("${rdf.type.value}"), ${variables.resource}.dataFactory.namedNode("${rdfType.value}")); }`);
|
|
27
|
+
usedIgnoreRdfTypeVariable = true;
|
|
28
|
+
});
|
|
29
|
+
for (const property of this.properties) {
|
|
30
|
+
statements.push(...property.toRdfStatements({
|
|
31
|
+
variables: { ...variables, value: `${thisVariable}.${property.name}` },
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
statements.push(`return ${variables.resource};`);
|
|
35
|
+
return {
|
|
36
|
+
isExported: true,
|
|
37
|
+
kind: StructureKind.Function,
|
|
38
|
+
name: "toRdf",
|
|
39
|
+
parameters: [
|
|
40
|
+
{
|
|
41
|
+
name: thisVariable,
|
|
42
|
+
type: this.name,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: `{ ${usedIgnoreRdfTypeVariable ? `${variables.ignoreRdfType},` : ""} ${variables.mutateGraph}, ${variables.resourceSet} }`,
|
|
46
|
+
type: `{ ${variables.ignoreRdfType}?: boolean; ${variables.mutateGraph}: rdfjsResource.MutableResource.MutateGraph, ${variables.resourceSet}: rdfjsResource.MutableResourceSet }`,
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
returnType: this.rdfjsResourceType({ mutable: true }).name,
|
|
50
|
+
statements,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=toRdfFunctionDeclaration.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { BlankNode, Literal, NamedNode } from "@rdfjs/types";
|
|
2
|
+
export declare function rdfjsTermExpression(rdfjsTerm: BlankNode | Literal | NamedNode, { dataFactoryVariable }: {
|
|
3
|
+
dataFactoryVariable: string;
|
|
4
|
+
}): string;
|
|
5
|
+
//# sourceMappingURL=rdfjsTermExpression.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { xsd } from "@tpluscode/rdf-ns-builders";
|
|
2
|
+
export function rdfjsTermExpression(rdfjsTerm, { dataFactoryVariable }) {
|
|
3
|
+
switch (rdfjsTerm.termType) {
|
|
4
|
+
case "BlankNode":
|
|
5
|
+
return `${dataFactoryVariable}.blankNode("${rdfjsTerm.value}")`;
|
|
6
|
+
case "Literal":
|
|
7
|
+
if (rdfjsTerm.datatype.equals(xsd.string)) {
|
|
8
|
+
return `${dataFactoryVariable}.literal("${rdfjsTerm.value}", "${rdfjsTerm.language}")`;
|
|
9
|
+
}
|
|
10
|
+
return `${dataFactoryVariable}.literal("${rdfjsTerm.value}", ${dataFactoryVariable}.namedNode("${rdfjsTerm.datatype.value}"))`;
|
|
11
|
+
case "NamedNode":
|
|
12
|
+
return `${dataFactoryVariable}.namedNode("${rdfjsTerm.value}")`;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=rdfjsTermExpression.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import base62 from "@sindresorhus/base62";
|
|
2
|
+
import reservedTsIdentifiers_ from "reserved-identifiers";
|
|
3
|
+
const reservedTsIdentifiers = reservedTsIdentifiers_({
|
|
4
|
+
includeGlobalProperties: true,
|
|
5
|
+
});
|
|
6
|
+
// Adapted from https://github.com/sindresorhus/to-valid-identifier , MIT license
|
|
7
|
+
export function stringToValidTsIdentifier(value) {
|
|
8
|
+
if (reservedTsIdentifiers.has(value)) {
|
|
9
|
+
// We prefix with underscore to avoid any potential conflicts with the Base62 encoded string.
|
|
10
|
+
return `$_${value}$`;
|
|
11
|
+
}
|
|
12
|
+
return value.replaceAll(/\P{ID_Continue}/gu, (x) => `$${base62.encodeInteger(x.codePointAt(0))}$`);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=stringToValidTsIdentifier.js.map
|