@shaclmate/compiler 2.0.18 → 2.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.js +10 -0
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +1 -0
- package/dist/ast/ObjectType.d.ts +8 -0
- package/dist/enums/IdentifierMintingStrategy.d.ts +1 -1
- package/dist/generators/ts/ListType.js +3 -2
- package/dist/generators/ts/ObjectType.d.ts +4 -0
- package/dist/generators/ts/ObjectType.js +46 -7
- package/dist/generators/ts/ObjectUnionType.js +1 -1
- package/dist/generators/ts/TypeFactory.js +84 -35
- package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.d.ts +34 -0
- package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.js +98 -0
- package/dist/generators/ts/_ObjectType/IdentifierProperty.d.ts +4 -6
- package/dist/generators/ts/_ObjectType/IdentifierProperty.js +53 -71
- package/dist/generators/ts/_ObjectType/Property.d.ts +7 -6
- package/dist/generators/ts/_ObjectType/Property.js +0 -6
- package/dist/generators/ts/_ObjectType/ShaclProperty.d.ts +3 -3
- package/dist/generators/ts/_ObjectType/ShaclProperty.js +7 -7
- package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +6 -4
- package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +12 -9
- package/dist/generators/ts/_ObjectType/classDeclaration.js +4 -9
- package/dist/generators/ts/_ObjectType/fromJsonFunctionDeclarations.js +5 -5
- package/dist/generators/ts/_ObjectType/fromRdfFunctionDeclarations.js +6 -6
- package/dist/generators/ts/_ObjectType/hashFunctionDeclarations.d.ts +4 -0
- package/dist/generators/ts/_ObjectType/hashFunctionDeclarations.js +18 -0
- package/dist/generators/ts/_ObjectType/hashFunctionOrMethodDeclarations.d.ts +13 -0
- package/dist/generators/ts/_ObjectType/hashFunctionOrMethodDeclarations.js +97 -0
- package/dist/generators/ts/_ObjectType/index.d.ts +2 -1
- package/dist/generators/ts/_ObjectType/index.js +2 -1
- package/dist/generators/ts/_ObjectType/interfaceDeclaration.js +1 -1
- package/dist/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.js +5 -5
- package/dist/generators/ts/_ObjectType/toJsonReturnType.js +2 -4
- package/dist/input/NodeShape.d.ts +1 -0
- package/dist/input/NodeShape.js +11 -8
- package/dist/input/Ontology.d.ts +2 -0
- package/dist/input/Ontology.js +8 -2
- package/dist/input/PropertyShape.js +3 -3
- package/dist/input/generated.d.ts +67 -63
- package/dist/input/generated.js +181 -159
- package/dist/input/tsFeatures.d.ts +1 -1
- package/dist/input/tsFeatures.js +14 -14
- package/package.json +7 -7
- package/dist/generators/ts/_ObjectType/hashFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/hashFunctionDeclaration.js +0 -20
- package/dist/generators/ts/_ObjectType/hashFunctionOrMethodDeclaration.d.ts +0 -11
- package/dist/generators/ts/_ObjectType/hashFunctionOrMethodDeclaration.js +0 -64
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Scope, } from "ts-morph";
|
|
2
|
+
import { ObjectType } from "../ObjectType.js";
|
|
3
|
+
const hasherVariable = "_hasher";
|
|
4
|
+
export const hasherTypeConstraint = "{ update: (message: string | number[] | ArrayBuffer | Uint8Array) => void; }";
|
|
5
|
+
export function hashFunctionOrMethodDeclarations() {
|
|
6
|
+
if (!this.features.has("hash")) {
|
|
7
|
+
return [];
|
|
8
|
+
}
|
|
9
|
+
const hashOwnShaclPropertiesStatements = this.ownShaclProperties.flatMap((property) => property.hashStatements({
|
|
10
|
+
depth: 0,
|
|
11
|
+
variables: {
|
|
12
|
+
hasher: hasherVariable,
|
|
13
|
+
value: `${this.thisVariable}.${property.name}`,
|
|
14
|
+
},
|
|
15
|
+
}));
|
|
16
|
+
if (this.declarationType === "class" &&
|
|
17
|
+
this.parentObjectTypes.length > 0 &&
|
|
18
|
+
hashOwnShaclPropertiesStatements.length === 0) {
|
|
19
|
+
// If there's a parent class and no hash statements in this class, can skip overriding hash
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
const parameters = [];
|
|
23
|
+
if (this.declarationType === "interface") {
|
|
24
|
+
parameters.push({
|
|
25
|
+
name: this.thisVariable,
|
|
26
|
+
type: this.name,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
parameters.push({
|
|
30
|
+
name: hasherVariable,
|
|
31
|
+
type: "HasherT",
|
|
32
|
+
});
|
|
33
|
+
const hashShaclPropertiesStatements = [];
|
|
34
|
+
let hasOverrideKeyword = false;
|
|
35
|
+
if (this.parentObjectTypes.length > 0) {
|
|
36
|
+
switch (this.declarationType) {
|
|
37
|
+
case "class": {
|
|
38
|
+
hashShaclPropertiesStatements.push(`super.hashShaclProperties(${hasherVariable});`);
|
|
39
|
+
hasOverrideKeyword = true;
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
case "interface": {
|
|
43
|
+
for (const parentObjectType of this.parentObjectTypes) {
|
|
44
|
+
hashShaclPropertiesStatements.push(`${parentObjectType.name}.${parentObjectType.hashShaclPropertiesFunctionName}(${this.thisVariable}, ${hasherVariable});`);
|
|
45
|
+
}
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
hashShaclPropertiesStatements.push(...hashOwnShaclPropertiesStatements);
|
|
51
|
+
const returnType = "HasherT";
|
|
52
|
+
const typeParameters = [
|
|
53
|
+
{
|
|
54
|
+
name: "HasherT",
|
|
55
|
+
constraint: hasherTypeConstraint,
|
|
56
|
+
},
|
|
57
|
+
];
|
|
58
|
+
return [
|
|
59
|
+
{
|
|
60
|
+
hasOverrideKeyword,
|
|
61
|
+
name: this.declarationType === "class" ? "hash" : this.hashFunctionName,
|
|
62
|
+
parameters,
|
|
63
|
+
returnType,
|
|
64
|
+
statements: [
|
|
65
|
+
...this.ownProperties
|
|
66
|
+
.filter((property) => !(property instanceof ObjectType.ShaclProperty))
|
|
67
|
+
.flatMap((property) => property.hashStatements({
|
|
68
|
+
depth: 0,
|
|
69
|
+
variables: {
|
|
70
|
+
hasher: hasherVariable,
|
|
71
|
+
value: `${this.thisVariable}.${property.name}`,
|
|
72
|
+
},
|
|
73
|
+
})),
|
|
74
|
+
this.declarationType === "class"
|
|
75
|
+
? `this.hashShaclProperties(${hasherVariable});`
|
|
76
|
+
: `${this.name}.${this.hashShaclPropertiesFunctionName}(${this.thisVariable}, ${hasherVariable});`,
|
|
77
|
+
`return ${hasherVariable};`,
|
|
78
|
+
],
|
|
79
|
+
typeParameters,
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
hasOverrideKeyword,
|
|
83
|
+
name: this.declarationType === "class"
|
|
84
|
+
? "hashShaclProperties"
|
|
85
|
+
: this.hashShaclPropertiesFunctionName,
|
|
86
|
+
parameters,
|
|
87
|
+
returnType,
|
|
88
|
+
scope: this.declarationType === "class" ? Scope.Protected : undefined,
|
|
89
|
+
statements: [
|
|
90
|
+
...hashShaclPropertiesStatements,
|
|
91
|
+
`return ${hasherVariable};`,
|
|
92
|
+
],
|
|
93
|
+
typeParameters,
|
|
94
|
+
},
|
|
95
|
+
];
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=hashFunctionOrMethodDeclarations.js.map
|
|
@@ -4,7 +4,8 @@ export * from "./equalsFunctionDeclaration.js";
|
|
|
4
4
|
export * from "./fromJsonFunctionDeclarations.js";
|
|
5
5
|
export * from "./fromRdfFunctionDeclarations.js";
|
|
6
6
|
export * from "./fromRdfTypeVariableStatement.js";
|
|
7
|
-
export * from "./
|
|
7
|
+
export * from "./hashFunctionDeclarations.js";
|
|
8
|
+
export * from "./IdentifierPrefixProperty.js";
|
|
8
9
|
export * from "./IdentifierProperty.js";
|
|
9
10
|
export * from "./interfaceDeclaration.js";
|
|
10
11
|
export * from "./jsonSchemaFunctionDeclaration.js";
|
|
@@ -4,7 +4,8 @@ export * from "./equalsFunctionDeclaration.js";
|
|
|
4
4
|
export * from "./fromJsonFunctionDeclarations.js";
|
|
5
5
|
export * from "./fromRdfFunctionDeclarations.js";
|
|
6
6
|
export * from "./fromRdfTypeVariableStatement.js";
|
|
7
|
-
export * from "./
|
|
7
|
+
export * from "./hashFunctionDeclarations.js";
|
|
8
|
+
export * from "./IdentifierPrefixProperty.js";
|
|
8
9
|
export * from "./IdentifierProperty.js";
|
|
9
10
|
export * from "./interfaceDeclaration.js";
|
|
10
11
|
export * from "./jsonSchemaFunctionDeclaration.js";
|
|
@@ -8,7 +8,7 @@ export function interfaceDeclaration() {
|
|
|
8
8
|
if (this.extern) {
|
|
9
9
|
return Maybe.empty();
|
|
10
10
|
}
|
|
11
|
-
const properties = this.properties.
|
|
11
|
+
const properties = this.properties.flatMap((property) => property.interfacePropertySignature.toList());
|
|
12
12
|
return Maybe.of({
|
|
13
13
|
extends: this.parentObjectTypes.map((parentObjectType) => parentObjectType.name),
|
|
14
14
|
isExported: true,
|
|
@@ -14,7 +14,7 @@ export function jsonZodSchemaFunctionDeclaration() {
|
|
|
14
14
|
}
|
|
15
15
|
if (this.properties.length > 0) {
|
|
16
16
|
mergeZodObjectSchemas.push(`${variables.zod}.object({ ${this.properties
|
|
17
|
-
.
|
|
17
|
+
.flatMap((property) => property.jsonZodSchema({ variables }).toList())
|
|
18
18
|
.map(({ key, schema }) => `"${key}": ${schema}`)
|
|
19
19
|
.join(",")} })`);
|
|
20
20
|
}
|
|
@@ -28,11 +28,11 @@ export function toJsonFunctionOrMethodDeclaration() {
|
|
|
28
28
|
break;
|
|
29
29
|
}
|
|
30
30
|
if (this.ownProperties.length > 0) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
jsonObjectMembers.push(...this.ownProperties.flatMap((property) => property
|
|
32
|
+
.toJsonObjectMember({
|
|
33
|
+
variables: { value: `${this.thisVariable}.${property.name}` },
|
|
34
|
+
})
|
|
35
|
+
.toList()));
|
|
36
36
|
}
|
|
37
37
|
// 20241220: don't add @type until we're doing JSON-LD
|
|
38
38
|
// switch (this.toRdfTypes.length) {
|
|
@@ -2,10 +2,8 @@ export function toJsonReturnType() {
|
|
|
2
2
|
const typeMembers = [];
|
|
3
3
|
if (this.ownProperties.length > 0) {
|
|
4
4
|
typeMembers.push(`{ ${this.ownProperties
|
|
5
|
-
.
|
|
6
|
-
|
|
7
|
-
return `readonly "${propertySignature.name}": ${propertySignature.type}`;
|
|
8
|
-
})
|
|
5
|
+
.flatMap((property) => property.jsonPropertySignature.toList())
|
|
6
|
+
.map((propertySignature) => `readonly "${propertySignature.name}": ${propertySignature.type}`)
|
|
9
7
|
.join("; ")} }`);
|
|
10
8
|
}
|
|
11
9
|
for (const parentObjectType of this.parentObjectTypes) {
|
|
@@ -39,6 +39,7 @@ export declare class NodeShape extends ShaclCoreNodeShape<any, Ontology, Propert
|
|
|
39
39
|
get tsFeatures(): Maybe<Set<TsFeature>>;
|
|
40
40
|
get tsImports(): readonly string[];
|
|
41
41
|
get tsObjectDeclarationType(): Maybe<TsObjectDeclarationType>;
|
|
42
|
+
get tsObjectIdentifierPrefixPropertyName(): Maybe<string>;
|
|
42
43
|
get tsObjectIdentifierPropertyName(): Maybe<string>;
|
|
43
44
|
get tsObjectTypeDiscriminatorPropertyName(): Maybe<string>;
|
|
44
45
|
private get _mintingStrategy();
|
package/dist/input/NodeShape.js
CHANGED
|
@@ -68,7 +68,7 @@ export class NodeShape extends ShaclCoreNodeShape {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
-
return thisMintingStrategy;
|
|
71
|
+
return thisMintingStrategy.altLazy(() => this.nodeKinds.has("BlankNode") ? Maybe.of("blankNode") : Maybe.empty());
|
|
72
72
|
}
|
|
73
73
|
get mutable() {
|
|
74
74
|
return this.generatedShaclmateNodeShape.mutable;
|
|
@@ -139,9 +139,9 @@ export class NodeShape extends ShaclCoreNodeShape {
|
|
|
139
139
|
return this.generatedShaclmateNodeShape.tsObjectDeclarationType
|
|
140
140
|
.map((iri) => {
|
|
141
141
|
switch (iri.value) {
|
|
142
|
-
case "http://
|
|
142
|
+
case "http://purl.org/shaclmate/ontology#_TsObjectDeclarationType_Class":
|
|
143
143
|
return "class";
|
|
144
|
-
case "http://
|
|
144
|
+
case "http://purl.org/shaclmate/ontology#_TsObjectDeclarationType_Interface":
|
|
145
145
|
return "interface";
|
|
146
146
|
default:
|
|
147
147
|
throw new RangeError(iri.value);
|
|
@@ -149,8 +149,11 @@ export class NodeShape extends ShaclCoreNodeShape {
|
|
|
149
149
|
})
|
|
150
150
|
.altLazy(() => this.isDefinedBy.chain((ontology) => ontology.tsObjectDeclarationType));
|
|
151
151
|
}
|
|
152
|
+
get tsObjectIdentifierPrefixPropertyName() {
|
|
153
|
+
return this.generatedShaclmateNodeShape.tsObjectIdentifierPrefixPropertyName.altLazy(() => this.isDefinedBy.chain((ontology) => ontology.tsObjectIdentifierPrefixPropertyName));
|
|
154
|
+
}
|
|
152
155
|
get tsObjectIdentifierPropertyName() {
|
|
153
|
-
return this.generatedShaclmateNodeShape.tsObjectIdentifierPropertyName;
|
|
156
|
+
return this.generatedShaclmateNodeShape.tsObjectIdentifierPrefixPropertyName.altLazy(() => this.isDefinedBy.chain((ontology) => ontology.tsObjectIdentifierPropertyName));
|
|
154
157
|
}
|
|
155
158
|
get tsObjectTypeDiscriminatorPropertyName() {
|
|
156
159
|
return this.generatedShaclmateNodeShape
|
|
@@ -159,12 +162,12 @@ export class NodeShape extends ShaclCoreNodeShape {
|
|
|
159
162
|
get _mintingStrategy() {
|
|
160
163
|
return this.generatedShaclmateNodeShape.identifierMintingStrategy.map((iri) => {
|
|
161
164
|
switch (iri.value) {
|
|
162
|
-
case "http://
|
|
165
|
+
case "http://purl.org/shaclmate/ontology#_IdentifierMintingStrategy_BlankNode":
|
|
166
|
+
return "blankNode";
|
|
167
|
+
case "http://purl.org/shaclmate/ontology#_IdentifierMintingStrategy_SHA256":
|
|
163
168
|
return "sha256";
|
|
164
|
-
case "http://
|
|
169
|
+
case "http://purl.org/shaclmate/ontology#_IdentifierMintingStrategy_UUIDv4":
|
|
165
170
|
return "uuidv4";
|
|
166
|
-
default:
|
|
167
|
-
throw new RangeError(iri.value);
|
|
168
171
|
}
|
|
169
172
|
});
|
|
170
173
|
}
|
package/dist/input/Ontology.d.ts
CHANGED
|
@@ -9,5 +9,7 @@ export declare class Ontology extends OwlOntology {
|
|
|
9
9
|
get tsFeatures(): Maybe<Set<TsFeature>>;
|
|
10
10
|
get tsImports(): readonly string[];
|
|
11
11
|
get tsObjectDeclarationType(): Maybe<TsObjectDeclarationType>;
|
|
12
|
+
get tsObjectIdentifierPrefixPropertyName(): Maybe<string>;
|
|
13
|
+
get tsObjectIdentifierPropertyName(): Maybe<string>;
|
|
12
14
|
}
|
|
13
15
|
//# sourceMappingURL=Ontology.d.ts.map
|
package/dist/input/Ontology.js
CHANGED
|
@@ -18,14 +18,20 @@ export class Ontology extends OwlOntology {
|
|
|
18
18
|
get tsObjectDeclarationType() {
|
|
19
19
|
return this.generatedShaclmateOntology.tsObjectDeclarationType.map((iri) => {
|
|
20
20
|
switch (iri.value) {
|
|
21
|
-
case "http://
|
|
21
|
+
case "http://purl.org/shaclmate/ontology#_TsObjectDeclarationType_Class":
|
|
22
22
|
return "class";
|
|
23
|
-
case "http://
|
|
23
|
+
case "http://purl.org/shaclmate/ontology#_TsObjectDeclarationType_Interface":
|
|
24
24
|
return "interface";
|
|
25
25
|
default:
|
|
26
26
|
throw new RangeError(iri.value);
|
|
27
27
|
}
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
|
+
get tsObjectIdentifierPrefixPropertyName() {
|
|
31
|
+
return this.generatedShaclmateOntology.tsObjectIdentifierPrefixPropertyName;
|
|
32
|
+
}
|
|
33
|
+
get tsObjectIdentifierPropertyName() {
|
|
34
|
+
return this.generatedShaclmateOntology.tsObjectIdentifierPropertyName;
|
|
35
|
+
}
|
|
30
36
|
}
|
|
31
37
|
//# sourceMappingURL=Ontology.js.map
|
|
@@ -19,11 +19,11 @@ export class PropertyShape extends ShaclCorePropertyShape {
|
|
|
19
19
|
return this.generatedShaclmatePropertyShape.visibility
|
|
20
20
|
.map((iri) => {
|
|
21
21
|
switch (iri.value) {
|
|
22
|
-
case "http://
|
|
22
|
+
case "http://purl.org/shaclmate/ontology#_Visibility_Private":
|
|
23
23
|
return "private";
|
|
24
|
-
case "http://
|
|
24
|
+
case "http://purl.org/shaclmate/ontology#_Visibility_Protected":
|
|
25
25
|
return "protected";
|
|
26
|
-
case "http://
|
|
26
|
+
case "http://purl.org/shaclmate/ontology#_Visibility_Public":
|
|
27
27
|
return "public";
|
|
28
28
|
default:
|
|
29
29
|
throw new RangeError(iri.value);
|